Merge branch 'release/2.5.0.0beta10'

This commit is contained in:
J-Jamet
2018-05-13 17:05:10 +02:00
135 changed files with 2974 additions and 1301 deletions

View File

@@ -1,3 +1,11 @@
KeepassDX (2.5.0.0beta10)
* Dynamically change Algorithm and Key Derivation Function in settings
* Upgrade translations
* New red volcano theme, fix classic dark theme
* Add Material Icon Pack to the Free version
* Update fingerprint state with checkbox
* Fix bugs
KeepassDX (2.5.0.0beta9) KeepassDX (2.5.0.0beta9)
* Education Screens to learn how to use the app * Education Screens to learn how to use the app
* New designs * New designs

50
FAQ.md Normal file
View File

@@ -0,0 +1,50 @@
# F.A.Q.
## Why KeePass DX?
KeePass DX is an **Android password manager** implemented from Keepass password manager.
KeePass DX was created to meet the security and usability needs of a KeePass application on Android :
- To be easy to use with **secure password management and form filling tools**.
- To use only tools under **open source license** to guarantee the security of the application (With [open source store](https://f-droid.org/en/) and no closed API).
- To be in a **native langage** (java) for weight, security and a better integration of the application.
- To respect **Android design, architecture and ergonomic**.
## What makes KeePass DX stand out from other password managers?
- We **do not recover your sensitive data** on a private server or a closed cloud, you have control of your passwords.
- We respect **KeePass file standards** to maintain compatibility and data porting on different devices (computers and portable devices with different operating system).
- The code is **open source**, which implies increased **security**, you can check how the encryption algorithms are implemented.
- We remain attentive to **your needs** and we can even integrate the features that you have defined.
- We **do not put advertising** even in the free version.
## How am I sure my passwords are safely stored on the application?
- We allow users to save and use passwords, keys and digital identities in a secure way by **integrating the last encryption algorithms** and **Android architecture standards**.
- You can increase the security of your database by increasing the rounds of encryption keys. *(In Settings -> Database Settings when your database is open)* **Warning**: *Increase the number of rounds sparingly to have a reasonable opening time.*
## Can I store my data on a cloud storage?
**Yes** this is possible. Otherwise, we **recommend using cloud with personal server and open source license**, like [NextCloud](https://f-droid.org/en/packages/com.nextcloud.client/) to be sure how your databases are stored.
## Can I recover my passwords on another device if I loose my main device?
**Yes** you can, but you **must first save the .kdb or .kdbx file from your database to an external storage** *(like a hardrive or a cloud)*.
We recommend you save your data after each modification so incase you loose your android device you could retrieve the data and import it into the new KeePass DX installed on the new android device.
## Why not an online version?
The offline and online client concepts only exists with Keepass2Android because the file access network tools are directly integrated into the code of the main application. Which is a very dubious choice knowing that **it is not normally the purpose of a password management application to take care of external file synchronization on clouds** (which can be under closed licensed and recover your data base), it is rather the purpose of the [file management application](https://developer.android.com/guide/topics/providers/document-provider).
## Can I open my database easily other than with a password?
**Yes**, we have integrated a secure openning option of fingerprint for android devices that support this feature, so no one can access the application without scanning his/her fingerprint or fill a master key.
## Can I open my database without my master key (master password and/or key file)?
**No**, you can not open a database file without the master password (and / or) the associated key file. Be sure to remember your master password and save the key file in a safe place.
## Can I suggest features and report bugs for the application?
**Yes**, we welcome this you could go ahead and do that on our github:
https://github.com/Kunzisoft/KeePassDX

View File

@@ -1,34 +1,31 @@
# Android Keepass DX # Android Keepass DX
<img src="https://raw.githubusercontent.com/Kunzisoft/KeePassDX/master/art/icon.png"> Keepass DX is a multi-format KeePass manager for Android devices. The application allows to create keys and passwords in a secure way by integrating with the Android design standards. <img src="https://raw.githubusercontent.com/Kunzisoft/KeePassDX/master/art/icon.png"> Keepass DX is a **multi-format KeePass manager for Android devices**. The application allows to create keys and passwords in a secure way by integrating with the Android design standards.
<img src="https://raw.githubusercontent.com/Kunzisoft/KeePassDX/master/art/screen.jpg" width="220"> <img src="https://raw.githubusercontent.com/Kunzisoft/KeePassDX/master/art/screen.jpg" width="220">
### Features ### Features
* Create database files / entries and groups * Create database files / entries and groups
* Support for .kdb and .kdbx files (version 1 to 4) with AES - Twofish - ChaCha20 - Argon2 algorithm * Support for **.kdb** and **.kdbx** files (version 1 to 4) with AES - Twofish - ChaCha20 - Argon2 algorithm
* Compatible with the majority of alternative programs (KeePass, KeePassX, KeePass XC...) * **Compatible** with the majority of alternative programs (KeePass, KeePassX, KeePass XC...)
* Allows fast copy of fields and opening of URI / URL * Allows **fast copy** of fields and opening of URI / URL
* Fingerprint for fast unlocking * **Fingerprint** for fast unlocking
* Material design with themes * Material design with **themes**
* AutoFill and Integration * **AutoFill** and Integration
* Precise management of settings * Precise management of **settings**
Keepass DX is opensource and ad-free. Keepass DX is **open source** and **ad-free**.
<img src="https://raw.githubusercontent.com/Kunzisoft/KeePassDX/master/fastlane/metadata/android/en-US/images/phoneScreenshots/screen1.jpg" width="220">
<img src="https://raw.githubusercontent.com/Kunzisoft/KeePassDX/master/fastlane/metadata/android/en-US/images/phoneScreenshots/screen2.jpg" width="220">
## What is KeePass DX? ## What is KeePass DX?
Today you need to remember many passwords. You need a password for your e-mail account, your website's FTP password, online passwords (like website member account), etc. etc. etc. The list is endless. Also, you should use different passwords for each account. Because if you use only one password everywhere and someone gets this password you have a problem... A serious problem. The thief would have access to your e-mail account, website, etc. Unimaginable. Today you need to remember many passwords. You need a password for your e-mail account, your website's FTP password, online passwords (like website member account), etc. etc. etc. The list is endless. Also, you **should use different passwords for each account**. Because if you use only one password everywhere and someone gets this password you have a problem... A serious problem. The thief would have access to your e-mail account, website, etc. Unimaginable.
KeePass DX is a free open source password manager for Android, which helps you to manage your passwords in a secure way. You can put all your passwords in one database, which is locked with one master key or a key file. So you only have to remember one single master password or select the key file to unlock the whole database. The databases are encrypted using the best and most secure encryption algorithms currently known. KeePass DX is a **free open source password manager for Android**, which helps you to **manage your passwords in a secure way**. You can put all your passwords in one database, which is locked with one **master key** or a **key file**. So you **only have to remember one single master password or select the key file** to unlock the whole database. The databases are encrypted using the best and **most secure encryption algorithms** currently known.
## Is it really free? ## Is it really free?
Yes, KeePass DX is under free license (OSI certified) and without advertising. You can have a look at its full source and check whether the encryption algorithms are implemented correctly. Yes, KeePass DX is under **free license (OSI certified)** and **without advertising**. You can have a look at its full source and check whether the encryption algorithms are implemented correctly.
*Note : If you access the application from a store, visual features may not be available to incentivize the contribution to the work of open source projects. These optional visuals are accessible after a donation (and a small congratulation message :) or the purchase of an extended version, but do not worry, the main features remain completely free.* *Note : If you access the application from a store, visual features may not be available to incentivize the contribution to the work of open source projects. These optional visuals are accessible after a donation (and a small congratulation message :) or the purchase of an extended version, but do not worry, the main features remain completely free.*
@@ -41,11 +38,10 @@ You can contribute in different ways to help us on our work.
* **[Donate](https://www.kunzisoft.com/donation)** 人◕ ‿‿ ◕人Y for a better service and a quick development of your features. * **[Donate](https://www.kunzisoft.com/donation)** 人◕ ‿‿ ◕人Y for a better service and a quick development of your features.
* Buy the **[Pro version](https://play.google.com/store/apps/details?id=com.kunzisoft.keepass.pro)** of KeePass DX * Buy the **[Pro version](https://play.google.com/store/apps/details?id=com.kunzisoft.keepass.pro)** of KeePass DX
<img src="https://raw.githubusercontent.com/Kunzisoft/KeePassDX/master/fastlane/metadata/android/en-US/images/phoneScreenshots/screen4.jpg" width="220">
<img src="https://raw.githubusercontent.com/Kunzisoft/KeePassDX/master/fastlane/metadata/android/en-US/images/phoneScreenshots/screen5.jpg" width="220">
## Download ## Download
*We recommend the installation from [F-Droid](https://f-droid.org/en/packages/com.kunzisoft.keepass.libre/) which verifies that all libraries and application code are open source.*
[<img src="https://f-droid.org/badge/get-it-on.png" [<img src="https://f-droid.org/badge/get-it-on.png"
alt="Get it on F-Droid" alt="Get it on F-Droid"
height="80">](https://f-droid.org/en/packages/com.kunzisoft.keepass.libre/) height="80">](https://f-droid.org/en/packages/com.kunzisoft.keepass.libre/)
@@ -54,15 +50,19 @@ You can contribute in different ways to help us on our work.
alt="Get it on Google Play" alt="Get it on Google Play"
height="80">](https://play.google.com/store/apps/details?id=com.kunzisoft.keepass.free) height="80">](https://play.google.com/store/apps/details?id=com.kunzisoft.keepass.free)
## F.A.Q.
Other questions? You can read the [F.A.Q.](https://raw.githubusercontent.com/Kunzisoft/KeePassDX/master/FAQ.md)
## Other devices ## Other devices
- [KeePass XC](https://keepassxc.org/) (https://keepassxc.org/) works with **GNU/Linux**, **Mac** and **Windows**, is updated regulary and under the terms of the GNU General Public License. It's the recommended version for computers. - [KeePass XC](https://keepassxc.org/) (https://keepassxc.org/) works with **GNU/Linux**, **Mac** and **Windows**, is updated regularly and under the terms of the GNU General Public License. This is the recommended version for computers.
- [KeePass](https://keepass.info/) (https://keepass.info/) is the historical project, with good technical documentation for standardized database files but only running on **Windows**. - [KeePass](https://keepass.info/) (https://keepass.info/) is the historical project, with good technical documentation for standardized database files but only running on **Windows**.
## License ## License
Copyright (c) 2017 Jeremy Jamet / Kunzisoft. Copyright (c) 2017 Jeremy Jamet / [Kunzisoft](https://www.kunzisoft.com).
This file is part of KeePass DX. This file is part of KeePass DX.
@@ -79,4 +79,4 @@ You can contribute in different ways to help us on our work.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
This project is a fork of [KeepassDroid](https://github.com/bpellin/keepassdroid) by bpellin. *This project is a fork of [KeepassDroid](https://github.com/bpellin/keepassdroid) by bpellin.*

View File

@@ -8,16 +8,15 @@ android {
applicationId "com.kunzisoft.keepass" applicationId "com.kunzisoft.keepass"
minSdkVersion 14 minSdkVersion 14
targetSdkVersion 27 targetSdkVersion 27
versionCode = 9 versionCode = 10
versionName = "2.5.0.0beta9" versionName = "2.5.0.0beta10"
multiDexEnabled true multiDexEnabled true
testApplicationId = "com.kunzisoft.keepass.tests" testApplicationId = "com.kunzisoft.keepass.tests"
testInstrumentationRunner = "android.test.InstrumentationTestRunner" testInstrumentationRunner = "android.test.InstrumentationTestRunner"
ndk { ndk {
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
'arm64-v8a', 'mips', 'mips64'
} }
buildConfigField "String[]", "ICON_PACKS", "{\"classic\",\"material\"}" buildConfigField "String[]", "ICON_PACKS", "{\"classic\",\"material\"}"
@@ -47,7 +46,7 @@ android {
versionNameSuffix "-libre" versionNameSuffix "-libre"
buildConfigField "boolean", "FULL_VERSION", "true" buildConfigField "boolean", "FULL_VERSION", "true"
buildConfigField "boolean", "CLOSED_STORE", "false" buildConfigField "boolean", "CLOSED_STORE", "false"
buildConfigField "String[]", "STYLES_DISABLED", "{\"KeepassDXStyle_Dark\",\"KeepassDXStyle_Purple\"}" buildConfigField "String[]", "STYLES_DISABLED", "{\"KeepassDXStyle_Dark\",\"KeepassDXStyle_Red\",\"KeepassDXStyle_Purple\"}"
buildConfigField "String[]", "ICON_PACKS_DISABLED", "{}" buildConfigField "String[]", "ICON_PACKS_DISABLED", "{}"
} }
@@ -64,8 +63,8 @@ android {
versionNameSuffix "-free" versionNameSuffix "-free"
buildConfigField "boolean", "FULL_VERSION", "false" buildConfigField "boolean", "FULL_VERSION", "false"
buildConfigField "boolean", "CLOSED_STORE", "true" buildConfigField "boolean", "CLOSED_STORE", "true"
buildConfigField "String[]", "STYLES_DISABLED", "{\"KeepassDXStyle_Dark\",\"KeepassDXStyle_Blue\",\"KeepassDXStyle_Purple\"}" buildConfigField "String[]", "STYLES_DISABLED", "{\"KeepassDXStyle_Dark\",\"KeepassDXStyle_Blue\",\"KeepassDXStyle_Red\",\"KeepassDXStyle_Purple\"}"
buildConfigField "String[]", "ICON_PACKS_DISABLED", "{\"material\"}" buildConfigField "String[]", "ICON_PACKS_DISABLED", "{}"
} }
} }

View File

@@ -30,7 +30,7 @@ import com.kunzisoft.keepass.database.PwDatabaseV3;
import com.kunzisoft.keepass.database.PwEntry; import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.PwEntryV3; import com.kunzisoft.keepass.database.PwEntryV3;
import com.kunzisoft.keepass.database.PwGroup; import com.kunzisoft.keepass.database.PwGroup;
import com.kunzisoft.keepass.database.edit.DeleteGroup; import com.kunzisoft.keepass.database.action.DeleteGroupRunnable;
import com.kunzisoft.keepass.search.SearchDbHelper; import com.kunzisoft.keepass.search.SearchDbHelper;
public class DeleteEntry extends AndroidTestCase { public class DeleteEntry extends AndroidTestCase {
@@ -60,7 +60,7 @@ public class DeleteEntry extends AndroidTestCase {
assertNotNull("Could not find group1", group1); assertNotNull("Could not find group1", group1);
// Delete the group // Delete the group
DeleteGroup task = new DeleteGroup(null, db, group1, null, true); DeleteGroupRunnable task = new DeleteGroupRunnable(null, db, group1, null, true);
task.run(); task.run();
// Verify the entries were deleted // Verify the entries were deleted

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -222,6 +222,7 @@ public class EntryActivity extends LockingHideActivity {
TapTarget.forView(findViewById(R.id.entry_user_name_action_image), TapTarget.forView(findViewById(R.id.entry_user_name_action_image),
getString(R.string.education_field_copy_title), getString(R.string.education_field_copy_title),
getString(R.string.education_field_copy_summary)) getString(R.string.education_field_copy_summary))
.textColorInt(Color.WHITE)
.tintTarget(false) .tintTarget(false)
.cancelable(true), .cancelable(true),
new TapTargetView.Listener() { new TapTargetView.Listener() {
@@ -250,6 +251,7 @@ public class EntryActivity extends LockingHideActivity {
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_edit, TapTarget.forToolbarMenuItem(toolbar, R.id.menu_edit,
getString(R.string.education_entry_edit_title), getString(R.string.education_entry_edit_title),
getString(R.string.education_entry_edit_summary)) getString(R.string.education_entry_edit_summary))
.textColorInt(Color.WHITE)
.tintTarget(true) .tintTarget(true)
.cancelable(true), .cancelable(true),
new TapTargetView.Listener() { new TapTargetView.Listener() {
@@ -372,7 +374,7 @@ public class EntryActivity extends LockingHideActivity {
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
MenuUtil.donationMenuInflater(inflater, menu); MenuUtil.contributionMenuInflater(inflater, menu);
inflater.inflate(R.menu.entry, menu); inflater.inflate(R.menu.entry, menu);
inflater.inflate(R.menu.database_lock, menu); inflater.inflate(R.menu.database_lock, menu);
@@ -415,8 +417,8 @@ public class EntryActivity extends LockingHideActivity {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch ( item.getItemId() ) { switch ( item.getItemId() ) {
case R.id.menu_donate: case R.id.menu_contribute:
return MenuUtil.onDonationItemSelected(this); return MenuUtil.onContributionItemSelected(this);
case R.id.menu_toggle_pass: case R.id.menu_toggle_pass:
mShowPassword = !mShowPassword; mShowPassword = !mShowPassword;

View File

@@ -49,16 +49,17 @@ import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.PwGroup; import com.kunzisoft.keepass.database.PwGroup;
import com.kunzisoft.keepass.database.PwGroupId; import com.kunzisoft.keepass.database.PwGroupId;
import com.kunzisoft.keepass.database.PwIconStandard; import com.kunzisoft.keepass.database.PwIconStandard;
import com.kunzisoft.keepass.database.edit.AddEntry; import com.kunzisoft.keepass.database.action.AddEntryRunnable;
import com.kunzisoft.keepass.database.edit.OnFinish; import com.kunzisoft.keepass.database.action.OnFinishRunnable;
import com.kunzisoft.keepass.database.edit.RunnableOnFinish; import com.kunzisoft.keepass.database.action.RunnableOnFinish;
import com.kunzisoft.keepass.database.edit.UpdateEntry; import com.kunzisoft.keepass.database.action.UpdateEntryRunnable;
import com.kunzisoft.keepass.database.security.ProtectedString; import com.kunzisoft.keepass.database.security.ProtectedString;
import com.kunzisoft.keepass.dialogs.GeneratePasswordDialogFragment; import com.kunzisoft.keepass.dialogs.GeneratePasswordDialogFragment;
import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment; import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment;
import com.kunzisoft.keepass.icons.IconPackChooser; import com.kunzisoft.keepass.icons.IconPackChooser;
import com.kunzisoft.keepass.settings.PreferencesUtil; import com.kunzisoft.keepass.settings.PreferencesUtil;
import com.kunzisoft.keepass.tasks.ProgressTask; import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
import com.kunzisoft.keepass.utils.MenuUtil; import com.kunzisoft.keepass.utils.MenuUtil;
import com.kunzisoft.keepass.utils.Types; import com.kunzisoft.keepass.utils.Types;
import com.kunzisoft.keepass.utils.Util; import com.kunzisoft.keepass.utils.Util;
@@ -249,16 +250,21 @@ public class EntryEditActivity extends LockingHideActivity
} }
mCallbackNewEntry = populateNewEntry(); mCallbackNewEntry = populateNewEntry();
OnFinish onFinish = new AfterSave(); // Open a progress dialog and save entry
OnFinishRunnable onFinish = new AfterSave();
EntryEditActivity act = EntryEditActivity.this; EntryEditActivity act = EntryEditActivity.this;
RunnableOnFinish task; RunnableOnFinish task;
if ( mIsNew ) { if ( mIsNew ) {
task = new AddEntry(act, App.getDB(), mCallbackNewEntry, onFinish); task = new AddEntryRunnable(act, App.getDB(), mCallbackNewEntry, onFinish);
} else { } else {
task = new UpdateEntry(act, App.getDB(), mEntry, mCallbackNewEntry, onFinish); task = new UpdateEntryRunnable(act, App.getDB(), mEntry, mCallbackNewEntry, onFinish);
} }
ProgressTask pt = new ProgressTask(act, task, R.string.saving_database); task.setUpdateProgressTaskStatus(
pt.run(); new UpdateProgressTaskStatus(this,
SaveDatabaseProgressTaskDialogFragment.start(
getSupportFragmentManager())
));
new Thread(task).start();
} }
/** /**
@@ -274,6 +280,7 @@ public class EntryEditActivity extends LockingHideActivity
TapTarget.forView(generatePasswordView, TapTarget.forView(generatePasswordView,
getString(R.string.education_generate_password_title), getString(R.string.education_generate_password_title),
getString(R.string.education_generate_password_summary)) getString(R.string.education_generate_password_summary))
.textColorInt(Color.WHITE)
.tintTarget(false) .tintTarget(false)
.cancelable(true), .cancelable(true),
new TapTargetView.Listener() { new TapTargetView.Listener() {
@@ -300,6 +307,7 @@ public class EntryEditActivity extends LockingHideActivity
TapTarget.forView(addNewFieldView, TapTarget.forView(addNewFieldView,
getString(R.string.education_entry_new_field_title), getString(R.string.education_entry_new_field_title),
getString(R.string.education_entry_new_field_summary)) getString(R.string.education_entry_new_field_summary))
.textColorInt(Color.WHITE)
.tintTarget(false) .tintTarget(false)
.cancelable(true), .cancelable(true),
new TapTargetView.Listener() { new TapTargetView.Listener() {
@@ -447,15 +455,15 @@ public class EntryEditActivity extends LockingHideActivity
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
MenuUtil.donationMenuInflater(inflater, menu); MenuUtil.contributionMenuInflater(inflater, menu);
return true; return true;
} }
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch ( item.getItemId() ) { switch ( item.getItemId() ) {
case R.id.menu_donate: case R.id.menu_contribute:
return MenuUtil.onDonationItemSelected(this); return MenuUtil.onContributionItemSelected(this);
case android.R.id.home: case android.R.id.home:
finish(); finish();
@@ -552,7 +560,7 @@ public class EntryEditActivity extends LockingHideActivity
} }
} }
private final class AfterSave extends OnFinish { private final class AfterSave extends OnFinishRunnable {
AfterSave() { AfterSave() {
super(new Handler()); super(new Handler());
@@ -560,11 +568,15 @@ public class EntryEditActivity extends LockingHideActivity
@Override @Override
public void run() { public void run() {
if ( mSuccess ) { runOnUiThread(() -> {
finish(); if ( mSuccess ) {
} else { finish();
displayMessage(EntryEditActivity.this); } else {
} displayMessage(EntryEditActivity.this);
}
SaveDatabaseProgressTaskDialogFragment.stop(EntryEditActivity.this);
});
} }
} }

View File

@@ -57,10 +57,10 @@ import com.kunzisoft.keepass.database.PwIcon;
import com.kunzisoft.keepass.database.PwIconStandard; import com.kunzisoft.keepass.database.PwIconStandard;
import com.kunzisoft.keepass.database.PwNode; import com.kunzisoft.keepass.database.PwNode;
import com.kunzisoft.keepass.database.SortNodeEnum; import com.kunzisoft.keepass.database.SortNodeEnum;
import com.kunzisoft.keepass.database.edit.AddGroup; import com.kunzisoft.keepass.database.action.AddGroupRunnable;
import com.kunzisoft.keepass.database.edit.DeleteEntry; import com.kunzisoft.keepass.database.action.DeleteEntryRunnable;
import com.kunzisoft.keepass.database.edit.DeleteGroup; import com.kunzisoft.keepass.database.action.DeleteGroupRunnable;
import com.kunzisoft.keepass.database.edit.UpdateGroup; import com.kunzisoft.keepass.database.action.UpdateGroupRunnable;
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment; import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
import com.kunzisoft.keepass.dialogs.GroupEditDialogFragment; import com.kunzisoft.keepass.dialogs.GroupEditDialogFragment;
import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment; import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment;
@@ -68,7 +68,8 @@ import com.kunzisoft.keepass.dialogs.ReadOnlyDialog;
import com.kunzisoft.keepass.icons.IconPackChooser; import com.kunzisoft.keepass.icons.IconPackChooser;
import com.kunzisoft.keepass.search.SearchResultsActivity; import com.kunzisoft.keepass.search.SearchResultsActivity;
import com.kunzisoft.keepass.settings.PreferencesUtil; import com.kunzisoft.keepass.settings.PreferencesUtil;
import com.kunzisoft.keepass.tasks.ProgressTask; import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
import com.kunzisoft.keepass.view.AddNodeButtonView; import com.kunzisoft.keepass.view.AddNodeButtonView;
public class GroupActivity extends ListNodesActivity public class GroupActivity extends ListNodesActivity
@@ -285,6 +286,7 @@ public class GroupActivity extends ListNodesActivity
TapTarget.forView(findViewById(R.id.add_button), TapTarget.forView(findViewById(R.id.add_button),
getString(R.string.education_new_node_title), getString(R.string.education_new_node_title),
getString(R.string.education_new_node_summary)) getString(R.string.education_new_node_summary))
.textColorInt(Color.WHITE)
.tintTarget(false) .tintTarget(false)
.cancelable(true), .cancelable(true),
new TapTargetView.Listener() { new TapTargetView.Listener() {
@@ -313,6 +315,7 @@ public class GroupActivity extends ListNodesActivity
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_search, TapTarget.forToolbarMenuItem(toolbar, R.id.menu_search,
getString(R.string.education_search_title), getString(R.string.education_search_title),
getString(R.string.education_search_summary)) getString(R.string.education_search_summary))
.textColorInt(Color.WHITE)
.tintTarget(true) .tintTarget(true)
.cancelable(true), .cancelable(true),
new TapTargetView.Listener() { new TapTargetView.Listener() {
@@ -344,6 +347,7 @@ public class GroupActivity extends ListNodesActivity
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_sort, TapTarget.forToolbarMenuItem(toolbar, R.id.menu_sort,
getString(R.string.education_sort_title), getString(R.string.education_sort_title),
getString(R.string.education_sort_summary)) getString(R.string.education_sort_summary))
.textColorInt(Color.WHITE)
.tintTarget(true) .tintTarget(true)
.cancelable(true), .cancelable(true),
new TapTargetView.Listener() { new TapTargetView.Listener() {
@@ -374,6 +378,7 @@ public class GroupActivity extends ListNodesActivity
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_lock, TapTarget.forToolbarMenuItem(toolbar, R.id.menu_lock,
getString(R.string.education_lock_title), getString(R.string.education_lock_title),
getString(R.string.education_lock_summary)) getString(R.string.education_lock_summary))
.textColorInt(Color.WHITE)
.tintTarget(true) .tintTarget(true)
.cancelable(true), .cancelable(true),
new TapTargetView.Listener() { new TapTargetView.Listener() {
@@ -431,19 +436,27 @@ public class GroupActivity extends ListNodesActivity
private void deleteEntry(PwEntry entry) { private void deleteEntry(PwEntry entry) {
Handler handler = new Handler(); Handler handler = new Handler();
DeleteEntry task = new DeleteEntry(this, App.getDB(), entry, DeleteEntryRunnable task = new DeleteEntryRunnable(this, App.getDB(), entry,
new AfterDeleteNode(handler, entry)); new AfterDeleteNode(handler, entry));
ProgressTask pt = new ProgressTask(this, task, R.string.saving_database); task.setUpdateProgressTaskStatus(
pt.run(); new UpdateProgressTaskStatus(this,
SaveDatabaseProgressTaskDialogFragment.start(
getSupportFragmentManager())
));
new Thread(task).start();
} }
private void deleteGroup(PwGroup group) { private void deleteGroup(PwGroup group) {
//TODO Verify trash recycle bin //TODO Verify trash recycle bin
Handler handler = new Handler(); Handler handler = new Handler();
DeleteGroup task = new DeleteGroup(this, App.getDB(), group, DeleteGroupRunnable task = new DeleteGroupRunnable(this, App.getDB(), group,
new AfterDeleteNode(handler, group)); new AfterDeleteNode(handler, group));
ProgressTask pt = new ProgressTask(this, task, R.string.saving_database); task.setUpdateProgressTaskStatus(
pt.run(); new UpdateProgressTaskStatus(this,
SaveDatabaseProgressTaskDialogFragment.start(
getSupportFragmentManager())
));
new Thread(task).start();
} }
@Override @Override
@@ -544,16 +557,21 @@ public class GroupActivity extends ListNodesActivity
newGroup.setName(name); newGroup.setName(name);
try { try {
iconStandard = (PwIconStandard) icon; iconStandard = (PwIconStandard) icon;
} catch (Exception e) {} // TODO custom icon } catch (Exception ignored) {} // TODO custom icon
newGroup.setIcon(iconStandard); newGroup.setIcon(iconStandard);
new ProgressTask(this, // If group created save it in the database
new AddGroup(this, AddGroupRunnable addGroupRunnable = new AddGroupRunnable(this,
App.getDB(), App.getDB(),
newGroup, newGroup,
new AfterAddNode(new Handler())), new AfterAddNode(new Handler()));
R.string.saving_database) addGroupRunnable.setUpdateProgressTaskStatus(
.run(); new UpdateProgressTaskStatus(this,
SaveDatabaseProgressTaskDialogFragment.start(
getSupportFragmentManager())
));
new Thread(addGroupRunnable).start();
break; break;
case UPDATE: case UPDATE:
// If update add new elements // If update add new elements
@@ -562,20 +580,23 @@ public class GroupActivity extends ListNodesActivity
updateGroup.setName(name); updateGroup.setName(name);
try { try {
iconStandard = (PwIconStandard) icon; iconStandard = (PwIconStandard) icon;
} catch (Exception e) {} // TODO custom icon } catch (Exception ignored) {} // TODO custom icon
updateGroup.setIcon(iconStandard); updateGroup.setIcon(iconStandard);
mAdapter.removeNode(oldGroupToUpdate); mAdapter.removeNode(oldGroupToUpdate);
// If group update
new ProgressTask(this,
new UpdateGroup(this,
App.getDB(),
oldGroupToUpdate,
updateGroup,
new AfterUpdateNode(new Handler())),
R.string.saving_database)
.run();
// If group updated save it in the database
UpdateGroupRunnable updateGroupRunnable = new UpdateGroupRunnable(this,
App.getDB(),
oldGroupToUpdate,
updateGroup,
new AfterUpdateNode(new Handler()));
updateGroupRunnable.setUpdateProgressTaskStatus(
new UpdateProgressTaskStatus(this,
SaveDatabaseProgressTaskDialogFragment.start(
getSupportFragmentManager())
));
new Thread(updateGroupRunnable).start();
} }
break; break;

View File

@@ -49,12 +49,13 @@ import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.PwGroup; import com.kunzisoft.keepass.database.PwGroup;
import com.kunzisoft.keepass.database.PwNode; import com.kunzisoft.keepass.database.PwNode;
import com.kunzisoft.keepass.database.SortNodeEnum; import com.kunzisoft.keepass.database.SortNodeEnum;
import com.kunzisoft.keepass.database.edit.AfterActionNodeOnFinish; import com.kunzisoft.keepass.database.action.AfterActionNodeOnFinish;
import com.kunzisoft.keepass.database.edit.OnFinish; import com.kunzisoft.keepass.database.action.OnFinishRunnable;
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment; import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
import com.kunzisoft.keepass.dialogs.SortDialogFragment; import com.kunzisoft.keepass.dialogs.SortDialogFragment;
import com.kunzisoft.keepass.password.AssignPasswordHelper; import com.kunzisoft.keepass.password.AssignPasswordHelper;
import com.kunzisoft.keepass.settings.PreferencesUtil; import com.kunzisoft.keepass.settings.PreferencesUtil;
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
import com.kunzisoft.keepass.tasks.UIToastTask; import com.kunzisoft.keepass.tasks.UIToastTask;
import com.kunzisoft.keepass.utils.MenuUtil; import com.kunzisoft.keepass.utils.MenuUtil;
@@ -177,7 +178,7 @@ public abstract class ListNodesActivity extends LockingActivity
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
MenuUtil.donationMenuInflater(inflater, menu); MenuUtil.contributionMenuInflater(inflater, menu);
inflater.inflate(R.menu.tree, menu); inflater.inflate(R.menu.tree, menu);
inflater.inflate(R.menu.default_menu, menu); inflater.inflate(R.menu.default_menu, menu);
@@ -307,11 +308,16 @@ public abstract class ListNodesActivity extends LockingActivity
public void run(PwNode oldNode, PwNode newNode) { public void run(PwNode oldNode, PwNode newNode) {
super.run(); super.run();
if (mSuccess) {
mAdapter.addNode(newNode); runOnUiThread(() -> {
} else { if (mSuccess) {
displayMessage(ListNodesActivity.this); mAdapter.addNode(newNode);
} } else {
displayMessage(ListNodesActivity.this);
}
SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this);
});
} }
} }
@@ -322,15 +328,20 @@ public abstract class ListNodesActivity extends LockingActivity
public void run(PwNode oldNode, PwNode newNode) { public void run(PwNode oldNode, PwNode newNode) {
super.run(); super.run();
if (mSuccess) {
mAdapter.updateNode(oldNode, newNode); runOnUiThread(() -> {
} else { if (mSuccess) {
displayMessage(ListNodesActivity.this); mAdapter.updateNode(oldNode, newNode);
} } else {
displayMessage(ListNodesActivity.this);
}
SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this);
});
} }
} }
class AfterDeleteNode extends OnFinish { class AfterDeleteNode extends OnFinishRunnable {
private PwNode pwNode; private PwNode pwNode;
AfterDeleteNode(Handler handler, PwNode pwNode) { AfterDeleteNode(Handler handler, PwNode pwNode) {
@@ -340,27 +351,33 @@ public abstract class ListNodesActivity extends LockingActivity
@Override @Override
public void run() { public void run() {
if ( mSuccess) { super.run();
mAdapter.removeNode(pwNode);
PwGroup parent = pwNode.getParent(); runOnUiThread(() -> {
Database db = App.getDB(); if ( mSuccess) {
PwDatabase database = db.getPwDatabase(); mAdapter.removeNode(pwNode);
if (db.isRecycleBinAvailable() && PwGroup parent = pwNode.getParent();
db.isRecycleBinEnabled()) { Database db = App.getDB();
PwGroup recycleBin = database.getRecycleBin(); PwDatabase database = db.getPwDatabase();
// Add trash if it doesn't exists if (db.isRecycleBinAvailable() &&
if (parent.equals(recycleBin) db.isRecycleBinEnabled()) {
&& mCurrentGroup != null PwGroup recycleBin = database.getRecycleBin();
&& mCurrentGroup.getParent() == null // Add trash if it doesn't exists
&& !mCurrentGroup.equals(recycleBin)) { if (parent.equals(recycleBin)
mAdapter.addNode(parent); && mCurrentGroup != null
&& mCurrentGroup.getParent() == null
&& !mCurrentGroup.equals(recycleBin)) {
mAdapter.addNode(parent);
}
} }
} else {
mHandler.post(new UIToastTask(ListNodesActivity.this, "Unrecoverable error: " + mMessage));
App.setShutdown();
finish();
} }
} else {
mHandler.post(new UIToastTask(ListNodesActivity.this, "Unrecoverable error: " + mMessage)); SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this);
App.setShutdown(); });
finish();
}
} }
} }
} }

View File

@@ -19,6 +19,9 @@
*/ */
package com.kunzisoft.keepass.crypto.keyDerivation; package com.kunzisoft.keepass.crypto.keyDerivation;
import android.content.res.Resources;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.crypto.CryptoUtil; import com.kunzisoft.keepass.crypto.CryptoUtil;
import com.kunzisoft.keepass.crypto.finalkey.FinalKey; import com.kunzisoft.keepass.crypto.finalkey.FinalKey;
import com.kunzisoft.keepass.crypto.finalkey.FinalKeyFactory; import com.kunzisoft.keepass.crypto.finalkey.FinalKeyFactory;
@@ -45,13 +48,18 @@ public class AesKdf extends KdfEngine {
uuid = CIPHER_UUID; uuid = CIPHER_UUID;
} }
public String getName() { @Override
return DEFAULT_NAME; public String getName(Resources resources) {
if (resources == null)
return DEFAULT_NAME;
return resources.getString(R.string.kdf_AES);
} }
@Override @Override
public KdfParameters getDefaultParameters() { public KdfParameters getDefaultParameters() {
KdfParameters p = super.getDefaultParameters(); KdfParameters p = new KdfParameters(uuid);
p.setParamUUID();
p.setUInt32(ParamRounds, DEFAULT_ROUNDS); p.setUInt32(ParamRounds, DEFAULT_ROUNDS);
return p; return p;
@@ -93,4 +101,9 @@ public class AesKdf extends KdfEngine {
public void setKeyRounds(KdfParameters p, long keyRounds) { public void setKeyRounds(KdfParameters p, long keyRounds) {
p.setUInt64(ParamRounds, keyRounds); p.setUInt64(ParamRounds, keyRounds);
} }
@Override
public long getDefaultKeyRounds() {
return DEFAULT_ROUNDS;
}
} }

View File

@@ -19,6 +19,9 @@
*/ */
package com.kunzisoft.keepass.crypto.keyDerivation; package com.kunzisoft.keepass.crypto.keyDerivation;
import android.content.res.Resources;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.utils.Types; import com.kunzisoft.keepass.utils.Types;
import java.io.IOException; import java.io.IOException;
@@ -26,6 +29,7 @@ import java.security.SecureRandom;
import java.util.UUID; import java.util.UUID;
public class Argon2Kdf extends KdfEngine { public class Argon2Kdf extends KdfEngine {
public static final UUID CIPHER_UUID = Types.bytestoUUID( public static final UUID CIPHER_UUID = Types.bytestoUUID(
new byte[]{(byte) 0xEF, (byte) 0x63, (byte) 0x6D, (byte) 0xDF, (byte) 0x8C, (byte) 0x29, (byte) 0x44, (byte) 0x4B, new byte[]{(byte) 0xEF, (byte) 0x63, (byte) 0x6D, (byte) 0xDF, (byte) 0x8C, (byte) 0x29, (byte) 0x44, (byte) 0x4B,
(byte) 0x91, (byte) 0xF7, (byte) 0xA9, (byte) 0xA4, (byte)0x03, (byte) 0xE3, (byte) 0x0A, (byte) 0x0C (byte) 0x91, (byte) 0xF7, (byte) 0xA9, (byte) 0xA4, (byte)0x03, (byte) 0xE3, (byte) 0x0A, (byte) 0x0C
@@ -58,22 +62,28 @@ public class Argon2Kdf extends KdfEngine {
private static final long DefaultMemory = 1024 * 1024; private static final long DefaultMemory = 1024 * 1024;
private static final long DefaultParallelism = 2; private static final long DefaultParallelism = 2;
private static final String DEFAULT_NAME = "Argon2";
public Argon2Kdf() { public Argon2Kdf() {
uuid = CIPHER_UUID; uuid = CIPHER_UUID;
} }
@Override @Override
public String getName() { public String getName(Resources resources) {
return "Argon2"; if (resources == null)
return DEFAULT_NAME;
return resources.getString(R.string.kdf_Argon2);
} }
@Override @Override
public KdfParameters getDefaultParameters() { public KdfParameters getDefaultParameters() {
KdfParameters p = super.getDefaultParameters(); KdfParameters p = new KdfParameters(uuid);
p.setUInt32(ParamVersion, MaxVersion); p.setParamUUID();
p.setUInt64(ParamMemory, DefaultMemory);
p.setUInt32(ParamParallelism, DefaultParallelism); p.setUInt32(ParamParallelism, DefaultParallelism);
p.setUInt64(ParamMemory, DefaultMemory);
p.setUInt64(ParamIterations, DefaultIterations);
p.setUInt32(ParamVersion, MaxVersion);
return p; return p;
} }
@@ -113,4 +123,35 @@ public class Argon2Kdf extends KdfEngine {
p.setUInt64(ParamIterations, keyRounds); p.setUInt64(ParamIterations, keyRounds);
} }
@Override
public long getDefaultKeyRounds() {
return DefaultIterations;
}
@Override
public long getMemoryUsage(KdfParameters p) {
return p.getUInt64(ParamMemory);
}
public void setMemoryUsage(KdfParameters p, long memory) {
p.setUInt64(ParamMemory, memory);
}
public long getDefaultMemoryUsage() {
return DefaultMemory;
}
@Override
public int getParallelism(KdfParameters p) {
return (int) p.getUInt32(ParamParallelism); // TODO Verify
}
public void setParallelism(KdfParameters p, int parallelism) {
p.setUInt32(ParamParallelism, parallelism);
}
public int getDefaultParallelism() {
return (int) DefaultParallelism; // TODO Verify
}
} }

View File

@@ -19,24 +19,51 @@
*/ */
package com.kunzisoft.keepass.crypto.keyDerivation; package com.kunzisoft.keepass.crypto.keyDerivation;
import com.kunzisoft.keepass.database.ObjectNameResource;
import java.io.IOException; import java.io.IOException;
import java.util.UUID; import java.util.UUID;
public abstract class KdfEngine { public abstract class KdfEngine implements ObjectNameResource{
public static final int UNKNOW_VALUE = -1;
public static final String UNKNOW_VALUE_STRING = String.valueOf(-1);
public UUID uuid; public UUID uuid;
public KdfParameters getDefaultParameters() { public abstract KdfParameters getDefaultParameters();
return new KdfParameters(uuid);
}
public abstract byte[] transform(byte[] masterKey, KdfParameters p) throws IOException; public abstract byte[] transform(byte[] masterKey, KdfParameters p) throws IOException;
public abstract void randomize(KdfParameters p); public abstract void randomize(KdfParameters p);
public abstract String getName();
public abstract long getKeyRounds(KdfParameters p); public abstract long getKeyRounds(KdfParameters p);
public abstract void setKeyRounds(KdfParameters p, long keyRounds); public abstract void setKeyRounds(KdfParameters p, long keyRounds);
public abstract long getDefaultKeyRounds();
public long getMemoryUsage(KdfParameters p) {
return UNKNOW_VALUE;
}
public void setMemoryUsage(KdfParameters p, long memory) {
// Do nothing by default
}
public long getDefaultMemoryUsage() {
return UNKNOW_VALUE;
}
public int getParallelism(KdfParameters p) {
return UNKNOW_VALUE;
}
public void setParallelism(KdfParameters p, int parallelism) {
// Do nothing by default
}
public int getDefaultParallelism() {
return UNKNOW_VALUE;
}
} }

View File

@@ -21,28 +21,28 @@ package com.kunzisoft.keepass.crypto.keyDerivation;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
public class KdfFactory { public class KdfFactory {
public static AesKdf aesKdf = new AesKdf();
public static Argon2Kdf argon2Kdf = new Argon2Kdf();
public static List<KdfEngine> kdfListV3 = new ArrayList<>();
public static List<KdfEngine> kdfList = new ArrayList<>(); public static List<KdfEngine> kdfList = new ArrayList<>();
static { static {
kdfList.add(new AesKdf()); kdfListV3.add(aesKdf);
kdfList.add(new Argon2Kdf());
kdfList.add(aesKdf);
kdfList.add(argon2Kdf);
} }
public static KdfParameters getDefaultParameters() { public static KdfEngine get(KdfParameters kdfParameters) {
return kdfList.get(0).getDefaultParameters();
}
public static KdfEngine get(UUID uuid) {
for (KdfEngine engine: kdfList) { for (KdfEngine engine: kdfList) {
if (engine.uuid.equals(uuid)) { if (engine.uuid.equals(kdfParameters.kdfUUID)) {
return engine; return engine;
} }
} }
return null; return null;
} }

View File

@@ -35,30 +35,28 @@ public class KdfParameters extends VariantDictionary {
private static final String ParamUUID = "$UUID"; private static final String ParamUUID = "$UUID";
public KdfParameters(UUID uuid) { KdfParameters(UUID uuid) {
kdfUUID = uuid; kdfUUID = uuid;
} }
protected void setParamUUID() {
setByteArray(ParamUUID, Types.UUIDtoBytes(kdfUUID));
}
public static KdfParameters deserialize(byte[] data) throws IOException { public static KdfParameters deserialize(byte[] data) throws IOException {
ByteArrayInputStream bis = new ByteArrayInputStream(data); ByteArrayInputStream bis = new ByteArrayInputStream(data);
LEDataInputStream lis = new LEDataInputStream(bis); LEDataInputStream lis = new LEDataInputStream(bis);
VariantDictionary d = VariantDictionary.deserialize(lis); VariantDictionary d = VariantDictionary.deserialize(lis);
if (d == null) { if (d == null) {
assert(false);
return null; return null;
} }
UUID uuid = Types.bytestoUUID(d.getByteArray(ParamUUID)); UUID uuid = Types.bytestoUUID(d.getByteArray(ParamUUID));
if (uuid == null) {
assert(false);
return null;
}
KdfParameters kdfP = new KdfParameters(uuid); KdfParameters kdfP = new KdfParameters(uuid);
kdfP.copyTo(d); kdfP.copyTo(d);
return kdfP; return kdfP;
} }
public static byte[] serialize(KdfParameters kdf) throws IOException { public static byte[] serialize(KdfParameters kdf) throws IOException {

View File

@@ -27,6 +27,8 @@ import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory;
import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException; import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException;
import com.kunzisoft.keepass.database.exception.InvalidDBException; import com.kunzisoft.keepass.database.exception.InvalidDBException;
import com.kunzisoft.keepass.database.exception.InvalidPasswordException; import com.kunzisoft.keepass.database.exception.InvalidPasswordException;
@@ -36,7 +38,7 @@ import com.kunzisoft.keepass.database.load.ImporterFactory;
import com.kunzisoft.keepass.database.save.PwDbOutput; import com.kunzisoft.keepass.database.save.PwDbOutput;
import com.kunzisoft.keepass.icons.IconDrawableFactory; import com.kunzisoft.keepass.icons.IconDrawableFactory;
import com.kunzisoft.keepass.search.SearchDbHelper; import com.kunzisoft.keepass.search.SearchDbHelper;
import com.kunzisoft.keepass.tasks.UpdateStatus; import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
import com.kunzisoft.keepass.utils.UriUtil; import com.kunzisoft.keepass.utils.UriUtil;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
@@ -47,6 +49,8 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.SyncFailedException; import java.io.SyncFailedException;
import java.util.ArrayList;
import java.util.List;
public class Database { public class Database {
@@ -99,19 +103,11 @@ public class Database {
loaded = true; loaded = true;
} }
public void loadData(Context ctx, InputStream is, String password, InputStream keyInputStream) throws IOException, InvalidDBException { public void loadData(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status) throws IOException, FileNotFoundException, InvalidDBException {
loadData(ctx, is, password, keyInputStream, new UpdateStatus(), !Importer.DEBUG);
}
public void loadData(Context ctx, Uri uri, String password, Uri keyfile) throws IOException, FileNotFoundException, InvalidDBException {
loadData(ctx, uri, password, keyfile, new UpdateStatus(), !Importer.DEBUG);
}
public void loadData(Context ctx, Uri uri, String password, Uri keyfile, UpdateStatus status) throws IOException, FileNotFoundException, InvalidDBException {
loadData(ctx, uri, password, keyfile, status, !Importer.DEBUG); loadData(ctx, uri, password, keyfile, status, !Importer.DEBUG);
} }
public void loadData(Context ctx, Uri uri, String password, Uri keyfile, UpdateStatus status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException { public void loadData(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException {
mUri = uri; mUri = uri;
readOnly = false; readOnly = false;
if (uri.getScheme().equals("file")) { if (uri.getScheme().equals("file")) {
@@ -138,7 +134,7 @@ public class Database {
} }
private void passUrisAsInputStreams(Context ctx, Uri uri, String password, Uri keyfile, UpdateStatus status, boolean debug, long roundsFix) throws IOException, FileNotFoundException, InvalidDBException { private void passUrisAsInputStreams(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status, boolean debug, long roundsFix) throws IOException, FileNotFoundException, InvalidDBException {
InputStream is, kfIs; InputStream is, kfIs;
try { try {
is = UriUtil.getUriInputStream(ctx, uri); is = UriUtil.getUriInputStream(ctx, uri);
@@ -156,15 +152,11 @@ public class Database {
loadData(ctx, is, password, kfIs, status, debug, roundsFix); loadData(ctx, is, password, kfIs, status, debug, roundsFix);
} }
public void loadData(Context ctx, InputStream is, String password, InputStream kfIs, boolean debug) throws IOException, InvalidDBException { public void loadData(Context ctx, InputStream is, String password, InputStream keyFileInputStream, boolean debug) throws IOException, InvalidDBException {
loadData(ctx, is, password, kfIs, new UpdateStatus(), debug); loadData(ctx, is, password, keyFileInputStream, null, debug, 0);
} }
public void loadData(Context ctx, InputStream is, String password, InputStream kfIs, UpdateStatus status, boolean debug) throws IOException, InvalidDBException { private void loadData(Context ctx, InputStream is, String password, InputStream keyFileInputStream, ProgressTaskUpdater progressTaskUpdater, boolean debug, long roundsFix) throws IOException, InvalidDBException {
loadData(ctx, is, password, kfIs, status, debug, 0);
}
public void loadData(Context ctx, InputStream is, String password, InputStream kfIs, UpdateStatus status, boolean debug, long roundsFix) throws IOException, InvalidDBException {
BufferedInputStream bis = new BufferedInputStream(is); BufferedInputStream bis = new BufferedInputStream(is);
if ( ! bis.markSupported() ) { if ( ! bis.markSupported() ) {
@@ -174,11 +166,11 @@ public class Database {
// We'll end up reading 8 bytes to identify the header. Might as well use two extra. // We'll end up reading 8 bytes to identify the header. Might as well use two extra.
bis.mark(10); bis.mark(10);
Importer imp = ImporterFactory.createImporter(bis, debug); Importer databaseImporter = ImporterFactory.createImporter(bis, debug);
bis.reset(); // Return to the start bis.reset(); // Return to the start
pm = imp.openDatabase(bis, password, kfIs, status, roundsFix); pm = databaseImporter.openDatabase(bis, password, keyFileInputStream, progressTaskUpdater, roundsFix);
if ( pm != null ) { if ( pm != null ) {
try { try {
switch (pm.getVersion()) { switch (pm.getVersion()) {
@@ -222,19 +214,23 @@ public class Database {
saveData(ctx, mUri); saveData(ctx, mUri);
} }
public void saveData(Context ctx, Uri uri) throws IOException, PwDbOutputException { private void saveData(Context ctx, Uri uri) throws IOException, PwDbOutputException {
if (uri.getScheme().equals("file")) { if (uri.getScheme().equals("file")) {
String filename = uri.getPath(); String filename = uri.getPath();
File tempFile = new File(filename + ".tmp"); File tempFile = new File(filename + ".tmp");
FileOutputStream fos = new FileOutputStream(tempFile);
//BufferedOutputStream bos = new BufferedOutputStream(fos);
//PwDbV3Output pmo = new PwDbV3Output(pm, bos, App.getCalendar()); FileOutputStream fos = null;
PwDbOutput pmo = PwDbOutput.getInstance(pm, fos); try {
pmo.output(); fos = new FileOutputStream(tempFile);
//bos.flush(); PwDbOutput pmo = PwDbOutput.getInstance(pm, fos);
//bos.close(); if (pmo != null)
fos.close(); pmo.output();
} catch (Exception e) {
throw new IOException("Failed to store database.");
} finally {
if (fos != null)
fos.close();
}
// Force data to disk before continuing // Force data to disk before continuing
try { try {
@@ -250,16 +246,18 @@ public class Database {
} }
} }
else { else {
OutputStream os; OutputStream os = null;
try { try {
os = ctx.getContentResolver().openOutputStream(uri); os = ctx.getContentResolver().openOutputStream(uri);
PwDbOutput pmo = PwDbOutput.getInstance(pm, os);
if (pmo != null)
pmo.output();
} catch (Exception e) { } catch (Exception e) {
throw new IOException("Failed to store database."); throw new IOException("Failed to store database.");
} finally {
if (os != null)
os.close();
} }
PwDbOutput pmo = PwDbOutput.getInstance(pm, os);
pmo.output();
os.close();
} }
mUri = uri; mUri = uri;
} }
@@ -348,16 +346,78 @@ public class Database {
} }
} }
public PwEncryptionAlgorithm getEncryptionAlgorithm() {
return getPwDatabase().getEncryptionAlgorithm();
}
public List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms() {
switch (getPwDatabase().getVersion()) {
case V4:
return ((PwDatabaseV4) getPwDatabase()).getAvailableEncryptionAlgorithms();
case V3:
return ((PwDatabaseV3) getPwDatabase()).getAvailableEncryptionAlgorithms();
}
return new ArrayList<>();
}
public boolean allowEncryptionAlgorithmModification() {
return getAvailableEncryptionAlgorithms().size() > 1;
}
public void assignEncryptionAlgorithm(PwEncryptionAlgorithm algorithm) {
switch (getPwDatabase().getVersion()) {
case V4:
((PwDatabaseV4) getPwDatabase()).setEncryptionAlgorithm(algorithm);
((PwDatabaseV4) getPwDatabase()).setDataEngine(algorithm.getCipherEngine());
((PwDatabaseV4) getPwDatabase()).setDataCipher(algorithm.getDataCipher());
}
}
public String getEncryptionAlgorithmName(Resources resources) { public String getEncryptionAlgorithmName(Resources resources) {
return getPwDatabase().getEncryptionAlgorithm().getName(resources); return getPwDatabase().getEncryptionAlgorithm().getName(resources);
} }
public String getKeyDerivationName() { public List<KdfEngine> getAvailableKdfEngines() {
return getPwDatabase().getKeyDerivationName(); switch (getPwDatabase().getVersion()) {
case V4:
return KdfFactory.kdfList;
case V3:
return KdfFactory.kdfListV3;
}
return new ArrayList<>();
}
public boolean allowKdfModification() {
return getAvailableKdfEngines().size() > 1;
}
public KdfEngine getKdfEngine() {
return getPwDatabase().getKdfEngine();
}
public void assignKdfEngine(KdfEngine kdfEngine) {
switch (getPwDatabase().getVersion()) {
case V4:
PwDatabaseV4 db = ((PwDatabaseV4) getPwDatabase());
if (!db.getKdfParameters().kdfUUID.equals(kdfEngine.getDefaultParameters().kdfUUID))
db.setKdfParameters(kdfEngine.getDefaultParameters());
setNumberKeyEncryptionRounds(kdfEngine.getDefaultKeyRounds());
setMemoryUsage(kdfEngine.getDefaultMemoryUsage());
setParallelism(kdfEngine.getDefaultParallelism());
break;
}
}
public String getKeyDerivationName(Resources resources) {
KdfEngine kdfEngine = getPwDatabase().getKdfEngine();
if (kdfEngine != null) {
return kdfEngine.getName(resources);
}
return "";
} }
public String getNumberKeyEncryptionRoundsAsString() { public String getNumberKeyEncryptionRoundsAsString() {
return Long.toString(getPwDatabase().getNumberKeyEncryptionRounds()); return Long.toString(getNumberKeyEncryptionRounds());
} }
public long getNumberKeyEncryptionRounds() { public long getNumberKeyEncryptionRounds() {
@@ -368,6 +428,44 @@ public class Database {
getPwDatabase().setNumberKeyEncryptionRounds(numberRounds); getPwDatabase().setNumberKeyEncryptionRounds(numberRounds);
} }
public String getMemoryUsageAsString() {
return Long.toString(getMemoryUsage());
}
public long getMemoryUsage() {
switch (getPwDatabase().getVersion()) {
case V4:
return ((PwDatabaseV4) getPwDatabase()).getMemoryUsage();
}
return KdfEngine.UNKNOW_VALUE;
}
public void setMemoryUsage(long memory) {
switch (getPwDatabase().getVersion()) {
case V4:
((PwDatabaseV4) getPwDatabase()).setMemoryUsage(memory);
}
}
public String getParallelismAsString() {
return Integer.toString(getParallelism());
}
public int getParallelism() {
switch (getPwDatabase().getVersion()) {
case V4:
return ((PwDatabaseV4) getPwDatabase()).getParallelism();
}
return KdfEngine.UNKNOW_VALUE;
}
public void setParallelism(int parallelism) {
switch (getPwDatabase().getVersion()) {
case V4:
((PwDatabaseV4) getPwDatabase()).setParallelism(parallelism);
}
}
public PwEntry createEntry(PwGroup parent) { public PwEntry createEntry(PwGroup parent) {
PwEntry newPwEntry = null; PwEntry newPwEntry = null;
try { try {

View File

@@ -0,0 +1,29 @@
/*
* Copyright 2018 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.database;
import android.content.res.Resources;
/**
* Interface to generify items with a name resource, that can be (for example) visible in a list
*/
public interface ObjectNameResource {
String getName(Resources resources);
}

View File

@@ -19,11 +19,9 @@
*/ */
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import com.kunzisoft.keepass.crypto.finalkey.FinalKey; import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
import com.kunzisoft.keepass.crypto.finalkey.FinalKeyFactory;
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException; import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
import com.kunzisoft.keepass.database.exception.KeyFileEmptyException; import com.kunzisoft.keepass.database.exception.KeyFileEmptyException;
import com.kunzisoft.keepass.stream.NullOutputStream;
import com.kunzisoft.keepass.utils.Util; import com.kunzisoft.keepass.utils.Util;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@@ -31,7 +29,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.security.DigestOutputStream;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.HashMap; import java.util.HashMap;
@@ -100,39 +97,9 @@ public abstract class PwDatabase<PwGroupDB extends PwGroup<PwGroupDB, PwGroupDB,
return finalKey; return finalKey;
} }
public void makeFinalKey(byte[] masterSeed, byte[] masterSeed2, long numRounds) throws IOException {
// Write checksum Checksum
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
throw new IOException("SHA-256 not implemented here.");
}
NullOutputStream nos = new NullOutputStream();
DigestOutputStream dos = new DigestOutputStream(nos, md);
byte[] transformedMasterKey = transformMasterKey(masterSeed2, masterKey, numRounds);
dos.write(masterSeed);
dos.write(transformedMasterKey);
finalKey = md.digest();
}
/**
* Encrypt the master key a few times to make brute-force key-search harder
* @throws IOException
*/
protected static byte[] transformMasterKey( byte[] pKeySeed, byte[] pKey, long rounds ) throws IOException {
FinalKey key = FinalKeyFactory.createFinalKey();
return key.transformMasterKey(pKeySeed, pKey, rounds);
}
public abstract byte[] getMasterKey(String key, InputStream keyInputStream) throws InvalidKeyFileException, IOException; public abstract byte[] getMasterKey(String key, InputStream keyInputStream) throws InvalidKeyFileException, IOException;
public void setMasterKey(String key, InputStream keyInputStream) public void retrieveMasterKey(String key, InputStream keyInputStream)
throws InvalidKeyFileException, IOException { throws InvalidKeyFileException, IOException {
masterKey = getMasterKey(key, keyInputStream); masterKey = getMasterKey(key, keyInputStream);
} }
@@ -280,7 +247,9 @@ public abstract class PwDatabase<PwGroupDB extends PwGroup<PwGroupDB, PwGroupDB,
this.algorithm = algorithm; this.algorithm = algorithm;
} }
public abstract String getKeyDerivationName(); public abstract List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms();
public abstract KdfEngine getKdfEngine();
public abstract List<PwGroupDB> getGrpRoots(); public abstract List<PwGroupDB> getGrpRoots();

View File

@@ -45,11 +45,18 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import com.kunzisoft.keepass.crypto.keyDerivation.AesKdf; import com.kunzisoft.keepass.crypto.finalkey.FinalKey;
import com.kunzisoft.keepass.crypto.finalkey.FinalKeyFactory;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory;
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException; import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
import com.kunzisoft.keepass.stream.NullOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@@ -96,10 +103,17 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
} }
@Override @Override
public String getKeyDerivationName() { public KdfEngine getKdfEngine() {
return AesKdf.DEFAULT_NAME; return KdfFactory.aesKdf;
} }
@Override
public List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms() {
List<PwEncryptionAlgorithm> list = new ArrayList<>();
list.add(PwEncryptionAlgorithm.AES_Rijndael);
return list;
}
@Override @Override
public List<PwGroupV3> getGroups() { public List<PwGroupV3> getGroups() {
return groups; return groups;
@@ -250,6 +264,35 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
} }
} }
/**
* Encrypt the master key a few times to make brute-force key-search harder
* @throws IOException
*/
private static byte[] transformMasterKey( byte[] pKeySeed, byte[] pKey, long rounds ) throws IOException {
FinalKey key = FinalKeyFactory.createFinalKey();
return key.transformMasterKey(pKeySeed, pKey, rounds);
}
public void makeFinalKey(byte[] masterSeed, byte[] masterSeed2, long numRounds) throws IOException {
// Write checksum Checksum
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
throw new IOException("SHA-256 not implemented here.");
}
NullOutputStream nos = new NullOutputStream();
DigestOutputStream dos = new DigestOutputStream(nos, md);
byte[] transformedMasterKey = transformMasterKey(masterSeed2, masterKey, numRounds);
dos.write(masterSeed);
dos.write(transformedMasterKey);
finalKey = md.digest();
}
@Override @Override
protected String getPasswordEncoding() { protected String getPasswordEncoding() {
return "ISO-8859-1"; return "ISO-8859-1";
@@ -288,7 +331,6 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
// Add tree to root groups // Add tree to root groups
groups.add(newGroup); groups.add(newGroup);
} }
@Override @Override

View File

@@ -66,9 +66,10 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
private UUID dataCipher = AesEngine.CIPHER_UUID; private UUID dataCipher = AesEngine.CIPHER_UUID;
private CipherEngine dataEngine = new AesEngine(); private CipherEngine dataEngine = new AesEngine();
private PwCompressionAlgorithm compressionAlgorithm = PwCompressionAlgorithm.Gzip; private PwCompressionAlgorithm compressionAlgorithm = PwCompressionAlgorithm.Gzip;
private KdfEngine kdfEngine; private KdfParameters kdfParameters;
private long numKeyEncRounds;
private VariantDictionary publicCustomData = new VariantDictionary();
private long numKeyEncRounds = AesKdf.DEFAULT_ROUNDS; // By default take the AES rounds
protected String name = "KeePass DX database"; protected String name = "KeePass DX database";
private PwDate nameChanged = new PwDate(); private PwDate nameChanged = new PwDate();
private PwDate settingsChanged = new PwDate(); private PwDate settingsChanged = new PwDate();
@@ -98,9 +99,7 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
private List<PwIconCustom> customIcons = new ArrayList<>(); private List<PwIconCustom> customIcons = new ArrayList<>();
private Map<String, String> customData = new HashMap<>(); private Map<String, String> customData = new HashMap<>();
private KdfParameters kdfParameters = KdfFactory.getDefaultParameters(); private BinaryPool binPool = new BinaryPool();
private VariantDictionary publicCustomData = new VariantDictionary();
private BinaryPool binPool = new BinaryPool();
public String localizedAppName = "KeePassDX"; // TODO resource public String localizedAppName = "KeePassDX"; // TODO resource
@@ -131,9 +130,17 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
public void setDataEngine(CipherEngine dataEngine) { public void setDataEngine(CipherEngine dataEngine) {
this.dataEngine = dataEngine; this.dataEngine = dataEngine;
this.algorithm = dataEngine.getPwEncryptionAlgorithm();
} }
@Override
public List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms() {
List<PwEncryptionAlgorithm> list = new ArrayList<>();
list.add(PwEncryptionAlgorithm.AES_Rijndael);
list.add(PwEncryptionAlgorithm.Twofish);
list.add(PwEncryptionAlgorithm.ChaCha20);
return list;
}
public PwCompressionAlgorithm getCompressionAlgorithm() { public PwCompressionAlgorithm getCompressionAlgorithm() {
return compressionAlgorithm; return compressionAlgorithm;
} }
@@ -142,6 +149,19 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
this.compressionAlgorithm = compressionAlgorithm; this.compressionAlgorithm = compressionAlgorithm;
} }
@Override
public KdfEngine getKdfEngine() {
return KdfFactory.get(getKdfParameters());
}
public KdfParameters getKdfParameters() {
return kdfParameters;
}
public void setKdfParameters(KdfParameters kdfParameters) {
this.kdfParameters = kdfParameters;
}
@Override @Override
public long getNumberKeyEncryptionRounds() { public long getNumberKeyEncryptionRounds() {
if (getKdfEngine() != null && getKdfParameters() != null) if (getKdfEngine() != null && getKdfParameters() != null)
@@ -156,7 +176,31 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
numKeyEncRounds = rounds; numKeyEncRounds = rounds;
} }
public PwDate getNameChanged() { public long getMemoryUsage() {
if (getKdfEngine() != null && getKdfParameters() != null) {
return getKdfEngine().getMemoryUsage(getKdfParameters());
}
return KdfEngine.UNKNOW_VALUE;
}
public void setMemoryUsage(long memory) {
if (getKdfEngine() != null && getKdfParameters() != null)
getKdfEngine().setMemoryUsage(getKdfParameters(), memory);
}
public int getParallelism() {
if (getKdfEngine() != null && getKdfParameters() != null) {
return getKdfEngine().getParallelism(getKdfParameters());
}
return KdfEngine.UNKNOW_VALUE;
}
public void setParallelism(int parallelism) {
if (getKdfEngine() != null && getKdfParameters() != null)
getKdfEngine().setParallelism(getKdfParameters(), parallelism);
}
public PwDate getNameChanged() {
return nameChanged; return nameChanged;
} }
@@ -326,15 +370,6 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
this.customData.put(label, value); this.customData.put(label, value);
} }
public KdfEngine getKdfEngine() {
return kdfEngine;
}
@Override
public String getKeyDerivationName() {
return kdfEngine.getName();
}
@Override @Override
public byte[] getMasterKey(String key, InputStream keyInputStream) public byte[] getMasterKey(String key, InputStream keyInputStream)
throws InvalidKeyFileException, IOException { throws InvalidKeyFileException, IOException {
@@ -359,47 +394,25 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
return md.digest(fKey); return md.digest(fKey);
} }
@Override public void makeFinalKey(byte[] masterSeed) throws IOException {
public void makeFinalKey(byte[] masterSeed, byte[] masterSeed2, long numRounds) throws IOException { makeFinalKey(masterSeed, 0);
byte[] transformedMasterKey = transformMasterKey(masterSeed2, masterKey, numRounds);
byte[] cmpKey = new byte[65];
System.arraycopy(masterSeed, 0, cmpKey, 0, 32);
System.arraycopy(transformedMasterKey, 0, cmpKey, 32, 32);
finalKey = CryptoUtil.resizeKey(cmpKey, 0, 64, dataEngine.keyLength());
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-512");
cmpKey[64] = 1;
hmacKey = md.digest(cmpKey);
} catch (NoSuchAlgorithmException e) {
throw new IOException("No SHA-512 implementation");
} finally {
Arrays.fill(cmpKey, (byte)0);
}
}
public void makeFinalKey(byte[] masterSeed, KdfParameters kdfP) throws IOException {
makeFinalKey(masterSeed, kdfP, 0);
} }
public void makeFinalKey(byte[] masterSeed, KdfParameters kdfP, long roundsFix) public void makeFinalKey(byte[] masterSeed, long roundsFix)
throws IOException { throws IOException {
kdfEngine = KdfFactory.get(kdfP.kdfUUID); KdfEngine kdfEngine = KdfFactory.get(kdfParameters);
if (kdfEngine == null) { if (kdfEngine == null) {
throw new IOException("Unknown key derivation function"); throw new IOException("Unknown key derivation function");
} }
// Set to 6000 rounds to open corrupted database // Set to 6000 rounds to open corrupted database
if (roundsFix > 0 && kdfP.kdfUUID.equals(AesKdf.CIPHER_UUID)) { if (roundsFix > 0 && kdfParameters.kdfUUID.equals(AesKdf.CIPHER_UUID)) {
kdfP.setUInt32(AesKdf.ParamRounds, roundsFix); kdfParameters.setUInt32(AesKdf.ParamRounds, roundsFix);
numKeyEncRounds = roundsFix; numKeyEncRounds = roundsFix;
} }
byte[] transformedMasterKey = kdfEngine.transform(masterKey, kdfP); byte[] transformedMasterKey = kdfEngine.transform(masterKey, kdfParameters);
if (transformedMasterKey.length != 32) { if (transformedMasterKey.length != 32) {
transformedMasterKey = CryptoUtil.hashSha256(transformedMasterKey); transformedMasterKey = CryptoUtil.hashSha256(transformedMasterKey);
} }
@@ -695,14 +708,6 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
return groups.get(recycleId); return groups.get(recycleId);
} }
public KdfParameters getKdfParameters() {
return kdfParameters;
}
public void setKdfParameters(KdfParameters kdfParameters) {
this.kdfParameters = kdfParameters;
}
public VariantDictionary getPublicCustomData() { public VariantDictionary getPublicCustomData() {
return publicCustomData; return publicCustomData;
} }
@@ -739,8 +744,6 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
@Override @Override
public void initNew(String dbPath) { public void initNew(String dbPath) {
String filename = URLUtil.guessFileName(dbPath, null, null);
rootGroup = new PwGroupV4(dbNameFromPath(dbPath), iconFactory.getIcon(PwIconStandard.FOLDER)); rootGroup = new PwGroupV4(dbNameFromPath(dbPath), iconFactory.getIcon(PwIconStandard.FOLDER));
groups.put(rootGroup.getId(), rootGroup); groups.put(rootGroup.getId(), rootGroup);
} }
@@ -759,64 +762,4 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
return filename.substring(0, lastExtDot); return filename.substring(0, lastExtDot);
} }
private class GroupHasCustomData extends GroupHandler<PwGroupV4> {
public boolean hasCustomData = false;
@Override
public boolean operate(PwGroupV4 group) {
if (group == null) {
return true;
}
if (group.containsCustomData()) {
hasCustomData = true;
return false;
}
return true;
}
}
private class EntryHasCustomData extends EntryHandler<PwEntryV4> {
public boolean hasCustomData = false;
@Override
public boolean operate(PwEntryV4 entry) {
if (entry == null) {
return true;
}
if (entry.containsCustomData()) {
hasCustomData = true;
return false;
}
return true;
}
}
public int getMinKdbxVersion() {
if (!AesKdf.CIPHER_UUID.equals(kdfParameters.kdfUUID)) {
return PwDbHeaderV4.FILE_VERSION_32;
}
if (publicCustomData.size() > 0) {
return PwDbHeaderV4.FILE_VERSION_32;
}
EntryHasCustomData entryHandler = new EntryHasCustomData();
GroupHasCustomData groupHandler = new GroupHasCustomData();
if (rootGroup == null ) {
return PwDbHeaderV4.FILE_VERSION_32_3;
}
rootGroup.preOrderTraverseTree(groupHandler, entryHandler);
if (groupHandler.hasCustomData || entryHandler.hasCustomData) {
return PwDbHeaderV4.FILE_VERSION_32;
}
return PwDbHeaderV4.FILE_VERSION_32_3;
}
} }

View File

@@ -20,6 +20,7 @@
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import com.kunzisoft.keepass.crypto.keyDerivation.AesKdf; import com.kunzisoft.keepass.crypto.keyDerivation.AesKdf;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfParameters; import com.kunzisoft.keepass.crypto.keyDerivation.KdfParameters;
import com.kunzisoft.keepass.database.exception.InvalidDBVersionException; import com.kunzisoft.keepass.database.exception.InvalidDBVersionException;
import com.kunzisoft.keepass.stream.CopyInputStream; import com.kunzisoft.keepass.stream.CopyInputStream;
@@ -41,7 +42,7 @@ import javax.crypto.spec.SecretKeySpec;
public class PwDbHeaderV4 extends PwDbHeader { public class PwDbHeaderV4 extends PwDbHeader {
public static final int DBSIG_PRE2 = 0xB54BFB66; public static final int DBSIG_PRE2 = 0xB54BFB66;
public static final int DBSIG_2 = 0xB54BFB67; public static final int DBSIG_2 = 0xB54BFB67;
private static final int FILE_VERSION_CRITICAL_MASK = 0xFFFF0000; private static final int FILE_VERSION_CRITICAL_MASK = 0xFFFF0000;
public static final int FILE_VERSION_32_3 = 0x00030001; public static final int FILE_VERSION_32_3 = 0x00030001;
public static final int FILE_VERSION_32_4 = 0x00040000; public static final int FILE_VERSION_32_4 = 0x00040000;
@@ -91,12 +92,83 @@ public class PwDbHeaderV4 extends PwDbHeader {
public CrsAlgorithm innerRandomStream; public CrsAlgorithm innerRandomStream;
public long version; public long version;
public PwDbHeaderV4(PwDatabaseV4 d) { public PwDbHeaderV4(PwDatabaseV4 databaseV4) {
db = d; this.db = databaseV4;
version = d.getMinKdbxVersion(); this.version = getMinKdbxVersion(databaseV4); // Only for writing
masterSeed = new byte[32]; this.masterSeed = new byte[32];
} }
public long getVersion() {
return version;
}
public void setVersion(long version) {
this.version = version;
}
private class GroupHasCustomData extends GroupHandler<PwGroupV4> {
boolean hasCustomData = false;
@Override
public boolean operate(PwGroupV4 group) {
if (group == null) {
return true;
}
if (group.containsCustomData()) {
hasCustomData = true;
return false;
}
return true;
}
}
private class EntryHasCustomData extends EntryHandler<PwEntryV4> {
boolean hasCustomData = false;
@Override
public boolean operate(PwEntryV4 entry) {
if (entry == null) {
return true;
}
if (entry.containsCustomData()) {
hasCustomData = true;
return false;
}
return true;
}
}
private int getMinKdbxVersion(PwDatabaseV4 databaseV4) {
// Return v4 if AES is not use
if (databaseV4.getKdfParameters() != null
&& !databaseV4.getKdfParameters().kdfUUID.equals(AesKdf.CIPHER_UUID)) {
return PwDbHeaderV4.FILE_VERSION_32;
}
// Return V4 if custom data are present
if (databaseV4.containsPublicCustomData()) {
return PwDbHeaderV4.FILE_VERSION_32;
}
EntryHasCustomData entryHandler = new EntryHasCustomData();
GroupHasCustomData groupHandler = new GroupHasCustomData();
if (databaseV4.getRootGroup() == null ) {
return PwDbHeaderV4.FILE_VERSION_32_3;
}
databaseV4.getRootGroup().preOrderTraverseTree(groupHandler, entryHandler);
if (groupHandler.hasCustomData || entryHandler.hasCustomData) {
return PwDbHeaderV4.FILE_VERSION_32;
}
return PwDbHeaderV4.FILE_VERSION_32_3;
}
/** Assumes the input stream is at the beginning of the .kdbx file /** Assumes the input stream is at the beginning of the .kdbx file
* @param is * @param is
* @throws IOException * @throws IOException
@@ -122,7 +194,7 @@ public class PwDbHeaderV4 extends PwDbHeader {
throw new InvalidDBVersionException(); throw new InvalidDBVersionException();
} }
version = lis.readUInt(); version = lis.readUInt(); // Erase previous value
if ( ! validVersion(version) ) { if ( ! validVersion(version) ) {
throw new InvalidDBVersionException(); throw new InvalidDBVersionException();
} }
@@ -155,7 +227,7 @@ public class PwDbHeaderV4 extends PwDbHeader {
throw new IOException("Header ended early."); throw new IOException("Header ended early.");
} }
} }
switch ( fieldID ) { switch ( fieldID ) {
case PwDbHeaderV4Fields.EndOfHeader: case PwDbHeaderV4Fields.EndOfHeader:
return true; return true;
@@ -173,24 +245,13 @@ public class PwDbHeaderV4 extends PwDbHeader {
break; break;
case PwDbHeaderV4Fields.TransformSeed: case PwDbHeaderV4Fields.TransformSeed:
assert(version < PwDbHeaderV4.FILE_VERSION_32_4); // TODO file > FILEVERSION if(version < PwDbHeaderV4.FILE_VERSION_32_4)
AesKdf kdfS = new AesKdf(); setTransformSeed(fieldData);
if (!db.getKdfParameters().kdfUUID.equals(kdfS.uuid)) {
db.setKdfParameters(kdfS.getDefaultParameters());
}
db.getKdfParameters().setByteArray(AesKdf.ParamSeed, fieldData);
break; break;
case PwDbHeaderV4Fields.TransformRounds: case PwDbHeaderV4Fields.TransformRounds:
assert(version < PwDbHeaderV4.FILE_VERSION_32_4); if(version < PwDbHeaderV4.FILE_VERSION_32_4)
AesKdf kdfR = new AesKdf(); setTransformRound(fieldData);
if (!db.getKdfParameters().kdfUUID.equals(kdfR.uuid)) {
db.setKdfParameters(kdfR.getDefaultParameters());
}
long rounds = LEDataInputStream.readLong(fieldData, 0);
db.getKdfParameters().setUInt64(AesKdf.ParamRounds, rounds);
db.setNumberKeyEncryptionRounds(rounds);
break; break;
case PwDbHeaderV4Fields.EncryptionIV: case PwDbHeaderV4Fields.EncryptionIV:
@@ -198,8 +259,8 @@ public class PwDbHeaderV4 extends PwDbHeader {
break; break;
case PwDbHeaderV4Fields.InnerRandomstreamKey: case PwDbHeaderV4Fields.InnerRandomstreamKey:
assert(version < PwDbHeaderV4.FILE_VERSION_32_4); if(version < PwDbHeaderV4.FILE_VERSION_32_4)
innerRandomStreamKey = fieldData; innerRandomStreamKey = fieldData;
break; break;
case PwDbHeaderV4Fields.StreamStartBytes: case PwDbHeaderV4Fields.StreamStartBytes:
@@ -207,8 +268,8 @@ public class PwDbHeaderV4 extends PwDbHeader {
break; break;
case PwDbHeaderV4Fields.InnerRandomStreamID: case PwDbHeaderV4Fields.InnerRandomStreamID:
assert(version < PwDbHeaderV4.FILE_VERSION_32_4); if(version < PwDbHeaderV4.FILE_VERSION_32_4)
setRandomStreamID(fieldData); setRandomStreamID(fieldData);
break; break;
case PwDbHeaderV4Fields.KdfParameters: case PwDbHeaderV4Fields.KdfParameters:
@@ -224,6 +285,12 @@ public class PwDbHeaderV4 extends PwDbHeader {
return false; return false;
} }
private void assignAesKdfEngineIfNotExists() {
if (db.getKdfParameters() == null || !db.getKdfParameters().kdfUUID.equals(KdfFactory.aesKdf.uuid)) {
db.setKdfParameters(KdfFactory.aesKdf.getDefaultParameters());
}
}
private void setCipher(byte[] pbId) throws IOException { private void setCipher(byte[] pbId) throws IOException {
if ( pbId == null || pbId.length != 16 ) { if ( pbId == null || pbId.length != 16 ) {
@@ -232,6 +299,18 @@ public class PwDbHeaderV4 extends PwDbHeader {
db.setDataCipher(Types.bytestoUUID(pbId)); db.setDataCipher(Types.bytestoUUID(pbId));
} }
private void setTransformSeed(byte[] seed) {
assignAesKdfEngineIfNotExists();
db.getKdfParameters().setByteArray(AesKdf.ParamSeed, seed);
}
private void setTransformRound(byte[] roundsByte) {
assignAesKdfEngineIfNotExists();
long rounds = LEDataInputStream.readLong(roundsByte, 0);
db.getKdfParameters().setUInt64(AesKdf.ParamRounds, rounds);
db.setNumberKeyEncryptionRounds(rounds);
}
private void setCompressionFlags(byte[] pbFlags) throws IOException { private void setCompressionFlags(byte[] pbFlags) throws IOException {
if ( pbFlags == null || pbFlags.length != 4 ) { if ( pbFlags == null || pbFlags.length != 4 ) {
@@ -244,23 +323,6 @@ public class PwDbHeaderV4 extends PwDbHeader {
} }
db.setCompressionAlgorithm(PwCompressionAlgorithm.fromId(flag)); db.setCompressionAlgorithm(PwCompressionAlgorithm.fromId(flag));
}
private void setTransformRounds(byte[] rounds) throws IOException {
if ( rounds == null || rounds.length != 8 ) {
throw new IOException("Invalid rounds.");
}
long rnd = LEDataInputStream.readLong(rounds, 0);
if ( rnd < 0 || rnd > Integer.MAX_VALUE ) {
//TODO: Actually support really large numbers
throw new IOException("Rounds higher than " + Integer.MAX_VALUE + " are not currently supported.");
}
db.setNumberKeyEncryptionRounds(rnd);
} }
public void setRandomStreamID(byte[] streamID) throws IOException { public void setRandomStreamID(byte[] streamID) throws IOException {
@@ -276,25 +338,22 @@ public class PwDbHeaderV4 extends PwDbHeader {
innerRandomStream = CrsAlgorithm.fromId(id); innerRandomStream = CrsAlgorithm.fromId(id);
} }
/** Determines if this is a supported version. /**
* Determines if this is a supported version.
* *
* A long is needed here to represent the unsigned int since we perform * A long is needed here to represent the unsigned int since we perform arithmetic on it.
* arithmetic on it. * @param version Database version
* @param version * @return true if it's a supported version
* @return
*/ */
private boolean validVersion(long version) { private boolean validVersion(long version) {
return ! ((version & FILE_VERSION_CRITICAL_MASK) > (FILE_VERSION_32 & FILE_VERSION_CRITICAL_MASK)); return ! ((version & FILE_VERSION_CRITICAL_MASK) > (FILE_VERSION_32 & FILE_VERSION_CRITICAL_MASK));
} }
public static boolean matchesHeader(int sig1, int sig2) { public static boolean matchesHeader(int sig1, int sig2) {
return (sig1 == PWM_DBSIG_1) && ( (sig2 == DBSIG_2) || (sig2 == DBSIG_2) ); return (sig1 == PWM_DBSIG_1) && ( (sig2 == DBSIG_PRE2) || (sig2 == DBSIG_2) ); // TODO verify add DBSIG_PRE2
} }
public static byte[] computeHeaderHmac(byte[] header, byte[] key) throws IOException{ public static byte[] computeHeaderHmac(byte[] header, byte[] key) throws IOException{
byte[] headerHmac;
byte[] blockKey = HmacBlockStream.GetHmacKey64(key, Types.ULONG_MAX_VALUE); byte[] blockKey = HmacBlockStream.GetHmacKey64(key, Types.ULONG_MAX_VALUE);
Mac hmac; Mac hmac;
@@ -312,8 +371,7 @@ public class PwDbHeaderV4 extends PwDbHeader {
} }
public byte[] getTransformSeed() { public byte[] getTransformSeed() {
assert(version < FILE_VERSION_32_4); // version < FILE_VERSION_32_4)
return db.getKdfParameters().getByteArray(AesKdf.ParamSeed);
return db.getKdfParameters().getByteArray(AesKdf.ParamSeed);
} }
} }

View File

@@ -22,8 +22,14 @@ package com.kunzisoft.keepass.database;
import android.content.res.Resources; import android.content.res.Resources;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.crypto.engine.AesEngine;
import com.kunzisoft.keepass.crypto.engine.ChaCha20Engine;
import com.kunzisoft.keepass.crypto.engine.CipherEngine;
import com.kunzisoft.keepass.crypto.engine.TwofishEngine;
public enum PwEncryptionAlgorithm { import java.util.UUID;
public enum PwEncryptionAlgorithm implements ObjectNameResource {
AES_Rijndael, AES_Rijndael,
Twofish, Twofish,
@@ -33,11 +39,35 @@ public enum PwEncryptionAlgorithm {
switch (this) { switch (this) {
default: default:
case AES_Rijndael: case AES_Rijndael:
return resources.getString(R.string.rijndael); return resources.getString(R.string.encryption_rijndael);
case Twofish: case Twofish:
return resources.getString(R.string.twofish); return resources.getString(R.string.encryption_twofish);
case ChaCha20: case ChaCha20:
return resources.getString(R.string.chacha20); return resources.getString(R.string.encryption_chacha20);
}
}
public CipherEngine getCipherEngine() {
switch (this) {
default:
case AES_Rijndael:
return new AesEngine();
case Twofish:
return new TwofishEngine();
case ChaCha20:
return new ChaCha20Engine();
}
}
public UUID getDataCipher() {
switch (this) {
default:
case AES_Rijndael:
return AesEngine.CIPHER_UUID;
case Twofish:
return TwofishEngine.CIPHER_UUID;
case ChaCha20:
return ChaCha20Engine.CIPHER_UUID;
} }
} }
} }

View File

@@ -17,25 +17,25 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.database.edit; package com.kunzisoft.keepass.database.action;
import android.content.Context; import android.content.Context;
import com.kunzisoft.keepass.database.Database; import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwEntry; import com.kunzisoft.keepass.database.PwEntry;
public class AddEntry extends RunnableOnFinish { public class AddEntryRunnable extends RunnableOnFinish {
protected Database mDb; protected Database mDb;
private PwEntry mEntry; private PwEntry mEntry;
private Context ctx; private Context ctx;
private boolean mDontSave; private boolean mDontSave;
public AddEntry(Context ctx, Database db, PwEntry entry, OnFinish finish) { public AddEntryRunnable(Context ctx, Database db, PwEntry entry, OnFinishRunnable finish) {
this(ctx, db, entry, finish, false); this(ctx, db, entry, finish, false);
} }
public AddEntry(Context ctx, Database db, PwEntry entry, OnFinish finish, boolean dontSave) { public AddEntryRunnable(Context ctx, Database db, PwEntry entry, OnFinishRunnable finish, boolean dontSave) {
super(finish); super(finish);
this.mDb = db; this.mDb = db;
@@ -51,13 +51,13 @@ public class AddEntry extends RunnableOnFinish {
mDb.addEntryTo(mEntry, mEntry.getParent()); mDb.addEntryTo(mEntry, mEntry.getParent());
// Commit to disk // Commit to disk
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave); SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave);
save.run(); save.run();
} }
private class AfterAdd extends OnFinish { private class AfterAdd extends OnFinishRunnable {
AfterAdd(OnFinish finish) { AfterAdd(OnFinishRunnable finish) {
super(finish); super(finish);
} }

View File

@@ -17,26 +17,26 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.database.edit; package com.kunzisoft.keepass.database.action;
import android.content.Context; import android.content.Context;
import com.kunzisoft.keepass.database.Database; import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwGroup; import com.kunzisoft.keepass.database.PwGroup;
public class AddGroup extends RunnableOnFinish { public class AddGroupRunnable extends RunnableOnFinish {
protected Database mDb; protected Database mDb;
private PwGroup mNewGroup; private PwGroup mNewGroup;
private Context ctx; private Context ctx;
private boolean mDontSave; private boolean mDontSave;
public AddGroup(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode) { public AddGroupRunnable(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode) {
this(ctx, db, newGroup, afterAddNode, false); this(ctx, db, newGroup, afterAddNode, false);
} }
public AddGroup(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode, public AddGroupRunnable(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode,
boolean dontSave) { boolean dontSave) {
super(afterAddNode); super(afterAddNode);
this.mDb = db; this.mDb = db;
@@ -52,13 +52,13 @@ public class AddGroup extends RunnableOnFinish {
mDb.addGroupTo(mNewGroup, mNewGroup.getParent()); mDb.addGroupTo(mNewGroup, mNewGroup.getParent());
// Commit to disk // Commit to disk
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave); SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave);
save.run(); save.run();
} }
private class AfterAdd extends OnFinish { private class AfterAdd extends OnFinishRunnable {
AfterAdd(OnFinish finish) { AfterAdd(OnFinishRunnable finish) {
super(finish); super(finish);
} }

View File

@@ -17,13 +17,13 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.database.edit; package com.kunzisoft.keepass.database.action;
import android.os.Handler; import android.os.Handler;
import com.kunzisoft.keepass.database.PwNode; import com.kunzisoft.keepass.database.PwNode;
public abstract class AfterActionNodeOnFinish extends OnFinish { public abstract class AfterActionNodeOnFinish extends OnFinishRunnable {
public AfterActionNodeOnFinish(Handler handler) { public AfterActionNodeOnFinish(Handler handler) {
super(handler); super(handler);
} }

View File

@@ -17,22 +17,20 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.database.edit; package com.kunzisoft.keepass.database.action;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.net.Uri; import android.net.Uri;
import com.kunzisoft.keepass.database.Database; import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwDatabase; import com.kunzisoft.keepass.database.PwDatabase;
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException; import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper;
import com.kunzisoft.keepass.utils.UriUtil; import com.kunzisoft.keepass.utils.UriUtil;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
public class SetPassword extends RunnableOnFinish { public class AssignPasswordInDBRunnable extends RunnableOnFinish {
private String mPassword; private String mPassword;
private Uri mKeyfile; private Uri mKeyfile;
@@ -40,12 +38,12 @@ public class SetPassword extends RunnableOnFinish {
private boolean mDontSave; private boolean mDontSave;
private Context ctx; private Context ctx;
public SetPassword(Context ctx, Database db, String password, Uri keyfile, OnFinish finish) { public AssignPasswordInDBRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish) {
this(ctx, db, password, keyfile, finish, false); this(ctx, db, password, keyfile, finish, false);
} }
public SetPassword(Context ctx, Database db, String password, Uri keyfile, OnFinish finish, boolean dontSave) { public AssignPasswordInDBRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish, boolean dontSave) {
super(finish); super(finish);
mDb = db; mDb = db;
@@ -55,16 +53,6 @@ public class SetPassword extends RunnableOnFinish {
this.ctx = ctx; this.ctx = ctx;
} }
public boolean validatePassword(Context ctx, DialogInterface.OnClickListener onclick) {
if (!mDb.getPwDatabase().validatePasswordEncoding(mPassword)) {
PasswordEncodingDialogHelper dialog = new PasswordEncodingDialogHelper();
dialog.show(ctx, onclick, true);
return false;
}
return true;
}
@Override @Override
public void run() { public void run() {
PwDatabase pm = mDb.getPwDatabase(); PwDatabase pm = mDb.getPwDatabase();
@@ -75,7 +63,7 @@ public class SetPassword extends RunnableOnFinish {
// Set key // Set key
try { try {
InputStream is = UriUtil.getUriInputStream(ctx, mKeyfile); InputStream is = UriUtil.getUriInputStream(ctx, mKeyfile);
pm.setMasterKey(mPassword, is); pm.retrieveMasterKey(mPassword, is);
} catch (InvalidKeyFileException e) { } catch (InvalidKeyFileException e) {
erase(backupKey); erase(backupKey);
finish(false, e.getMessage()); finish(false, e.getMessage());
@@ -88,14 +76,14 @@ public class SetPassword extends RunnableOnFinish {
// Save Database // Save Database
mFinish = new AfterSave(backupKey, mFinish); mFinish = new AfterSave(backupKey, mFinish);
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave); SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave);
save.run(); save.run();
} }
private class AfterSave extends OnFinish { private class AfterSave extends OnFinishRunnable {
private byte[] mBackup; private byte[] mBackup;
public AfterSave(byte[] backup, OnFinish finish) { public AfterSave(byte[] backup, OnFinishRunnable finish) {
super(finish); super(finish);
mBackup = backup; mBackup = backup;

View File

@@ -17,7 +17,7 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.database.edit; package com.kunzisoft.keepass.database.action;
import android.content.Context; import android.content.Context;
@@ -26,13 +26,13 @@ import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwDatabase; import com.kunzisoft.keepass.database.PwDatabase;
import com.kunzisoft.keepass.utils.UriUtil; import com.kunzisoft.keepass.utils.UriUtil;
public class CreateDB extends RunnableOnFinish { public class CreateDBRunnable extends RunnableOnFinish {
private String mFilename; private String mFilename;
private boolean mDontSave; private boolean mDontSave;
private Context ctx; private Context ctx;
public CreateDB(Context ctx, String filename, OnFinish finish, boolean dontSave) { public CreateDBRunnable(Context ctx, String filename, OnFinishRunnable finish, boolean dontSave) {
super(finish); super(finish);
mFilename = filename; mFilename = filename;
@@ -56,7 +56,7 @@ public class CreateDB extends RunnableOnFinish {
App.clearShutdown(); App.clearShutdown();
// Commit changes // Commit changes
SaveDB save = new SaveDB(ctx, db, mFinish, mDontSave); SaveDBRunnable save = new SaveDBRunnable(ctx, db, mFinish, mDontSave);
mFinish = null; mFinish = null;
save.run(); save.run();
} }

View File

@@ -17,7 +17,7 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.database.edit; package com.kunzisoft.keepass.database.action;
import android.content.Context; import android.content.Context;
@@ -29,18 +29,18 @@ import com.kunzisoft.keepass.database.PwGroup;
* @author bpellin * @author bpellin
* *
*/ */
public class DeleteEntry extends RunnableOnFinish { public class DeleteEntryRunnable extends RunnableOnFinish {
private Database mDb; private Database mDb;
private PwEntry mEntry; private PwEntry mEntry;
private boolean mDontSave; private boolean mDontSave;
private Context ctx; private Context ctx;
public DeleteEntry(Context ctx, Database db, PwEntry entry, OnFinish finish) { public DeleteEntryRunnable(Context ctx, Database db, PwEntry entry, OnFinishRunnable finish) {
this(ctx, db, entry, finish, false); this(ctx, db, entry, finish, false);
} }
public DeleteEntry(Context ctx, Database db, PwEntry entry, OnFinish finish, boolean dontSave) { public DeleteEntryRunnable(Context ctx, Database db, PwEntry entry, OnFinishRunnable finish, boolean dontSave) {
super(finish); super(finish);
this.mDb = db; this.mDb = db;
@@ -67,17 +67,17 @@ public class DeleteEntry extends RunnableOnFinish {
mFinish = new AfterDelete(mFinish, parent, mEntry, recycle); mFinish = new AfterDelete(mFinish, parent, mEntry, recycle);
// Commit database // Commit database
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave); SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave);
save.run(); save.run();
} }
private class AfterDelete extends OnFinish { private class AfterDelete extends OnFinishRunnable {
private PwGroup mParent; private PwGroup mParent;
private PwEntry mEntry; private PwEntry mEntry;
private boolean recycled; private boolean recycled;
AfterDelete(OnFinish finish, PwGroup parent, PwEntry entry, boolean r) { AfterDelete(OnFinishRunnable finish, PwGroup parent, PwEntry entry, boolean r) {
super(finish); super(finish);
mParent = parent; mParent = parent;

View File

@@ -17,7 +17,7 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.database.edit; package com.kunzisoft.keepass.database.action;
import android.content.Context; import android.content.Context;
@@ -29,19 +29,19 @@ import com.kunzisoft.keepass.database.PwGroup;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class DeleteGroup extends RunnableOnFinish { public class DeleteGroupRunnable extends RunnableOnFinish {
private Context mContext; private Context mContext;
private Database mDb; private Database mDb;
private PwGroup<PwGroup, PwGroup, PwEntry> mGroup; private PwGroup<PwGroup, PwGroup, PwEntry> mGroup;
private boolean mDontSave; private boolean mDontSave;
public DeleteGroup(Context ctx, Database db, PwGroup<PwGroup, PwGroup, PwEntry> group, OnFinish finish) { public DeleteGroupRunnable(Context ctx, Database db, PwGroup<PwGroup, PwGroup, PwEntry> group, OnFinishRunnable finish) {
super(finish); super(finish);
setMembers(ctx, db, group, false); setMembers(ctx, db, group, false);
} }
public DeleteGroup(Context ctx, Database db, PwGroup<PwGroup, PwGroup, PwEntry> group, OnFinish finish, boolean dontSave) { public DeleteGroupRunnable(Context ctx, Database db, PwGroup<PwGroup, PwGroup, PwEntry> group, OnFinishRunnable finish, boolean dontSave) {
super(finish); super(finish);
setMembers(ctx, db, group, dontSave); setMembers(ctx, db, group, dontSave);
} }
@@ -67,14 +67,14 @@ public class DeleteGroup extends RunnableOnFinish {
// Remove child entries // Remove child entries
List<PwEntry> childEnt = new ArrayList<>(mGroup.getChildEntries()); // TODO new Methods List<PwEntry> childEnt = new ArrayList<>(mGroup.getChildEntries()); // TODO new Methods
for ( int i = 0; i < childEnt.size(); i++ ) { for ( int i = 0; i < childEnt.size(); i++ ) {
DeleteEntry task = new DeleteEntry(mContext, mDb, childEnt.get(i), null, true); DeleteEntryRunnable task = new DeleteEntryRunnable(mContext, mDb, childEnt.get(i), null, true);
task.run(); task.run();
} }
// Remove child groups // Remove child groups
List<PwGroup> childGrp = new ArrayList<>(mGroup.getChildGroups()); List<PwGroup> childGrp = new ArrayList<>(mGroup.getChildGroups());
for ( int i = 0; i < childGrp.size(); i++ ) { for ( int i = 0; i < childGrp.size(); i++ ) {
DeleteGroup task = new DeleteGroup(mContext, mDb, childGrp.get(i), null, true); DeleteGroupRunnable task = new DeleteGroupRunnable(mContext, mDb, childGrp.get(i), null, true);
task.run(); task.run();
} }
mDb.deleteGroup(mGroup); mDb.deleteGroup(mGroup);
@@ -88,17 +88,17 @@ public class DeleteGroup extends RunnableOnFinish {
mFinish = new AfterDelete(mFinish, parent, mGroup, recycle); mFinish = new AfterDelete(mFinish, parent, mGroup, recycle);
// Commit Database // Commit Database
SaveDB save = new SaveDB(mContext, mDb, mFinish, mDontSave); SaveDBRunnable save = new SaveDBRunnable(mContext, mDb, mFinish, mDontSave);
save.run(); save.run();
} }
private class AfterDelete extends OnFinish { private class AfterDelete extends OnFinishRunnable {
private PwGroup mParent; private PwGroup mParent;
private PwGroup mGroup; private PwGroup mGroup;
private boolean recycled; private boolean recycled;
AfterDelete(OnFinish finish, PwGroup parent, PwGroup mGroup, boolean recycle) { AfterDelete(OnFinishRunnable finish, PwGroup parent, PwGroup mGroup, boolean recycle) {
super(finish); super(finish);
this.mParent = parent; this.mParent = parent;

View File

@@ -17,17 +17,17 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.database.edit; package com.kunzisoft.keepass.database.action;
import android.net.Uri; import android.net.Uri;
import java.io.Serializable; import java.io.Serializable;
public class FileOnFinish extends OnFinish implements Serializable { public class FileOnFinishRunnable extends OnFinishRunnable implements Serializable {
private Uri mFilename = null; private Uri mFilename = null;
protected FileOnFinish mOnFinish; protected FileOnFinishRunnable mOnFinish;
public FileOnFinish(FileOnFinish finish) { public FileOnFinishRunnable(FileOnFinishRunnable finish) {
super(finish); super(finish);
mOnFinish = finish; mOnFinish = finish;

View File

@@ -17,12 +17,14 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.database.edit; package com.kunzisoft.keepass.database.action;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.StringRes;
import android.util.Log;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.app.App; import com.kunzisoft.keepass.app.App;
@@ -40,7 +42,9 @@ import com.kunzisoft.keepass.database.exception.KeyFileEmptyException;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
public class LoadDB extends RunnableOnFinish { public class LoadDBRunnable extends RunnableOnFinish {
private static final String TAG = LoadDBRunnable.class.getName();
private Uri mUri; private Uri mUri;
private String mPass; private String mPass;
private Uri mKey; private Uri mKey;
@@ -48,7 +52,7 @@ public class LoadDB extends RunnableOnFinish {
private Context mCtx; private Context mCtx;
private boolean mRememberKeyfile; private boolean mRememberKeyfile;
public LoadDB(Database db, Context ctx, Uri uri, String pass, Uri key, OnFinish finish) { public LoadDBRunnable(Database db, Context ctx, Uri uri, String pass, Uri key, OnFinishRunnable finish) {
super(finish); super(finish);
mDb = db; mDb = db;
@@ -69,42 +73,46 @@ public class LoadDB extends RunnableOnFinish {
saveFileData(mUri, mKey); saveFileData(mUri, mKey);
} catch (ArcFourException e) { } catch (ArcFourException e) {
finish(false, mCtx.getString(R.string.error_arc4)); catchError(e, R.string.error_arc4);
return; return;
} catch (InvalidPasswordException e) { } catch (InvalidPasswordException e) {
finish(false, mCtx.getString(R.string.InvalidPassword)); catchError(e, R.string.InvalidPassword);
return; return;
} catch (ContentFileNotFoundException e) { } catch (ContentFileNotFoundException e) {
finish(false, mCtx.getString(R.string.file_not_found_content)); catchError(e, R.string.file_not_found_content);
return; return;
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
finish(false, mCtx.getString(R.string.file_not_found)); catchError(e, R.string.file_not_found);
return; return;
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Database can't be read", e);
finish(false, e.getMessage()); finish(false, e.getMessage());
return; return;
} catch (KeyFileEmptyException e) { } catch (KeyFileEmptyException e) {
finish(false, mCtx.getString(R.string.keyfile_is_empty)); catchError(e, R.string.keyfile_is_empty);
return; return;
} catch (InvalidAlgorithmException e) { } catch (InvalidAlgorithmException e) {
finish(false, mCtx.getString(R.string.invalid_algorithm)); catchError(e, R.string.invalid_algorithm);
return; return;
} catch (InvalidKeyFileException e) { } catch (InvalidKeyFileException e) {
finish(false, mCtx.getString(R.string.keyfile_does_not_exist)); catchError(e, R.string.keyfile_does_not_exist);
return; return;
} catch (InvalidDBSignatureException e) { } catch (InvalidDBSignatureException e) {
finish(false, mCtx.getString(R.string.invalid_db_sig)); catchError(e, R.string.invalid_db_sig);
return; return;
} catch (InvalidDBVersionException e) { } catch (InvalidDBVersionException e) {
finish(false, mCtx.getString(R.string.unsupported_db_version)); catchError(e, R.string.unsupported_db_version);
return; return;
} catch (InvalidDBException e) { } catch (InvalidDBException e) {
finish(false, mCtx.getString(R.string.error_invalid_db)); catchError(e, R.string.error_invalid_db);
return; return;
} catch (OutOfMemoryError e) { } catch (OutOfMemoryError e) {
finish(false, mCtx.getString(R.string.error_out_of_memory)); String errorMessage = mCtx.getString(R.string.error_out_of_memory);
Log.e(TAG, errorMessage, e);
finish(false, errorMessage);
return; return;
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Database can't be load", e);
finish(false, e.getMessage()); finish(false, e.getMessage());
return; return;
} }
@@ -112,6 +120,12 @@ public class LoadDB extends RunnableOnFinish {
finish(true); finish(true);
} }
private void catchError(Exception e, @StringRes int messageId) {
String errorMessage = mCtx.getString(messageId);
Log.e(TAG, errorMessage, e);
finish(false, errorMessage);
}
private void saveFileData(Uri uri, Uri key) { private void saveFileData(Uri uri, Uri key) {
if ( ! mRememberKeyfile ) { if ( ! mRememberKeyfile ) {
key = null; key = null;

View File

@@ -17,7 +17,7 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.database.edit; package com.kunzisoft.keepass.database.action;
import android.content.Context; import android.content.Context;
import android.os.Handler; import android.os.Handler;
@@ -29,27 +29,27 @@ import android.widget.Toast;
* @author bpellin * @author bpellin
* *
*/ */
public class OnFinish implements Runnable { public class OnFinishRunnable implements Runnable {
protected boolean mSuccess; protected boolean mSuccess;
protected String mMessage; protected String mMessage;
protected OnFinish mOnFinish; protected OnFinishRunnable mOnFinish;
protected Handler mHandler; protected Handler mHandler;
public OnFinish() { public OnFinishRunnable() {
} }
public OnFinish(Handler handler) { public OnFinishRunnable(Handler handler) {
mOnFinish = null; mOnFinish = null;
mHandler = handler; mHandler = handler;
} }
public OnFinish(OnFinish finish, Handler handler) { public OnFinishRunnable(OnFinishRunnable finish, Handler handler) {
mOnFinish = finish; mOnFinish = finish;
mHandler = handler; mHandler = handler;
} }
public OnFinish(OnFinish finish) { public OnFinishRunnable(OnFinishRunnable finish) {
mOnFinish = finish; mOnFinish = finish;
mHandler = null; mHandler = null;
} }
@@ -75,7 +75,8 @@ public class OnFinish implements Runnable {
} }
} }
} }
// TODO Move
protected void displayMessage(Context ctx) { protected void displayMessage(Context ctx) {
if ( mMessage != null && mMessage.length() > 0 ) { if ( mMessage != null && mMessage.length() > 0 ) {
Toast.makeText(ctx, mMessage, Toast.LENGTH_LONG).show(); Toast.makeText(ctx, mMessage, Toast.LENGTH_LONG).show();

View File

@@ -17,17 +17,17 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.database.edit; package com.kunzisoft.keepass.database.action;
import com.kunzisoft.keepass.tasks.UpdateStatus; import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
public abstract class RunnableOnFinish implements Runnable { public abstract class RunnableOnFinish implements Runnable {
public OnFinish mFinish; public OnFinishRunnable mFinish;
public UpdateStatus mStatus; public ProgressTaskUpdater mStatus;
public RunnableOnFinish(OnFinish finish) { public RunnableOnFinish(OnFinishRunnable finish) {
mFinish = finish; mFinish = finish;
} }
@@ -45,7 +45,7 @@ public abstract class RunnableOnFinish implements Runnable {
} }
} }
public void setStatus(UpdateStatus status) { public void setUpdateProgressTaskStatus(ProgressTaskUpdater status) {
mStatus = status; mStatus = status;
} }

View File

@@ -17,7 +17,7 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.database.edit; package com.kunzisoft.keepass.database.action;
import android.content.Context; import android.content.Context;
@@ -26,25 +26,22 @@ import com.kunzisoft.keepass.database.exception.PwDbOutputException;
import java.io.IOException; import java.io.IOException;
public class SaveDB extends RunnableOnFinish { public class SaveDBRunnable extends RunnableOnFinish {
private Context mCtx;
private Database mDb; private Database mDb;
private boolean mDontSave; private boolean mDontSave;
private Context mCtx;
public SaveDB(Context ctx, Database db, OnFinish finish, boolean dontSave) { public SaveDBRunnable(Context ctx, Database db, OnFinishRunnable finish, boolean dontSave) {
super(finish); super(finish);
mDb = db; this.mDb = db;
mDontSave = dontSave; this.mDontSave = dontSave;
mCtx = ctx; this.mCtx = ctx;
} }
public SaveDB(Context ctx, Database db, OnFinish finish) { public SaveDBRunnable(Context ctx, Database db, OnFinishRunnable finish) {
super(finish); this(ctx, db, finish, false);
mDb = db;
mDontSave = false;
mCtx = ctx;
} }
@Override @Override

View File

@@ -17,14 +17,14 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.database.edit; package com.kunzisoft.keepass.database.action;
import android.content.Context; import android.content.Context;
import com.kunzisoft.keepass.database.Database; import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwEntry; import com.kunzisoft.keepass.database.PwEntry;
public class UpdateEntry extends RunnableOnFinish { public class UpdateEntryRunnable extends RunnableOnFinish {
private Database mDb; private Database mDb;
private PwEntry mOldE; private PwEntry mOldE;
@@ -32,11 +32,11 @@ public class UpdateEntry extends RunnableOnFinish {
private Context ctx; private Context ctx;
private boolean mDontSave; private boolean mDontSave;
public UpdateEntry(Context ctx, Database db, PwEntry oldE, PwEntry newE, OnFinish finish) { public UpdateEntryRunnable(Context ctx, Database db, PwEntry oldE, PwEntry newE, OnFinishRunnable finish) {
this(ctx, db, oldE, newE, finish, false); this(ctx, db, oldE, newE, finish, false);
} }
public UpdateEntry(Context ctx, Database db, PwEntry oldE, PwEntry newE, OnFinish finish, boolean dontSave) { public UpdateEntryRunnable(Context ctx, Database db, PwEntry oldE, PwEntry newE, OnFinishRunnable finish, boolean dontSave) {
super(finish); super(finish);
this.mDb = db; this.mDb = db;
@@ -59,14 +59,14 @@ public class UpdateEntry extends RunnableOnFinish {
mOldE.touch(true, true); mOldE.touch(true, true);
// Commit to disk // Commit to disk
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave); SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave);
save.run(); save.run();
} }
private class AfterUpdate extends OnFinish { private class AfterUpdate extends OnFinishRunnable {
private PwEntry mBackup; private PwEntry mBackup;
AfterUpdate(PwEntry backup, OnFinish finish) { AfterUpdate(PwEntry backup, OnFinishRunnable finish) {
super(finish); super(finish);
mBackup = backup; mBackup = backup;
} }

View File

@@ -17,14 +17,14 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.database.edit; package com.kunzisoft.keepass.database.action;
import android.content.Context; import android.content.Context;
import com.kunzisoft.keepass.database.Database; import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwGroup; import com.kunzisoft.keepass.database.PwGroup;
public class UpdateGroup extends RunnableOnFinish { public class UpdateGroupRunnable extends RunnableOnFinish {
private Database mDb; private Database mDb;
private PwGroup mOldGroup; private PwGroup mOldGroup;
@@ -32,11 +32,11 @@ public class UpdateGroup extends RunnableOnFinish {
private Context ctx; private Context ctx;
private boolean mDontSave; private boolean mDontSave;
public UpdateGroup(Context ctx, Database db, PwGroup oldGroup, PwGroup newGroup, AfterActionNodeOnFinish finish) { public UpdateGroupRunnable(Context ctx, Database db, PwGroup oldGroup, PwGroup newGroup, AfterActionNodeOnFinish finish) {
this(ctx, db, oldGroup, newGroup, finish, false); this(ctx, db, oldGroup, newGroup, finish, false);
} }
public UpdateGroup(Context ctx, Database db, PwGroup oldGroup, PwGroup newGroup, AfterActionNodeOnFinish finish, boolean dontSave) { public UpdateGroupRunnable(Context ctx, Database db, PwGroup oldGroup, PwGroup newGroup, AfterActionNodeOnFinish finish, boolean dontSave) {
super(finish); super(finish);
this.mDb = db; this.mDb = db;
@@ -59,13 +59,13 @@ public class UpdateGroup extends RunnableOnFinish {
mOldGroup.touch(true, true); mOldGroup.touch(true, true);
// Commit to disk // Commit to disk
new SaveDB(ctx, mDb, mFinish, mDontSave).run(); new SaveDBRunnable(ctx, mDb, mFinish, mDontSave).run();
} }
private class AfterUpdate extends OnFinish { private class AfterUpdate extends OnFinishRunnable {
private PwGroup mBackup; private PwGroup mBackup;
AfterUpdate(PwGroup backup, OnFinish finish) { AfterUpdate(PwGroup backup, OnFinishRunnable finish) {
super(finish); super(finish);
mBackup = backup; mBackup = backup;
} }

View File

@@ -21,7 +21,7 @@ package com.kunzisoft.keepass.database.load;
import com.kunzisoft.keepass.database.PwDatabase; import com.kunzisoft.keepass.database.PwDatabase;
import com.kunzisoft.keepass.database.exception.InvalidDBException; import com.kunzisoft.keepass.database.exception.InvalidDBException;
import com.kunzisoft.keepass.tasks.UpdateStatus; import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -33,8 +33,7 @@ public abstract class Importer {
public abstract PwDatabase openDatabase(InputStream inStream, String password, InputStream keyInputStream) public abstract PwDatabase openDatabase(InputStream inStream, String password, InputStream keyInputStream)
throws IOException, InvalidDBException; throws IOException, InvalidDBException;
public abstract PwDatabase openDatabase(InputStream inStream, String password, InputStream keyInputStream, UpdateStatus status, long roundsFix) public abstract PwDatabase openDatabase(InputStream inStream, String password, InputStream keyInputStream, ProgressTaskUpdater updater, long roundsFix)
throws IOException, InvalidDBException; throws IOException, InvalidDBException;
} }

View File

@@ -28,13 +28,11 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
public class ImporterFactory { public class ImporterFactory {
public static Importer createImporter(InputStream is) throws InvalidDBSignatureException, IOException public static Importer createImporter(InputStream is) throws InvalidDBSignatureException, IOException {
{
return createImporter(is, false); return createImporter(is, false);
} }
public static Importer createImporter(InputStream is, boolean debug) throws InvalidDBSignatureException, IOException public static Importer createImporter(InputStream is, boolean debug) throws InvalidDBSignatureException, IOException {
{
int sig1 = LEDataInputStream.readInt(is); int sig1 = LEDataInputStream.readInt(is);
int sig2 = LEDataInputStream.readInt(is); int sig2 = LEDataInputStream.readInt(is);
@@ -49,6 +47,5 @@ public class ImporterFactory {
} }
throw new InvalidDBSignatureException(); throw new InvalidDBSignatureException();
} }
} }

View File

@@ -63,9 +63,8 @@ import com.kunzisoft.keepass.database.exception.InvalidDBVersionException;
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException; import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
import com.kunzisoft.keepass.database.exception.InvalidPasswordException; import com.kunzisoft.keepass.database.exception.InvalidPasswordException;
import com.kunzisoft.keepass.stream.LEDataInputStream; import com.kunzisoft.keepass.stream.LEDataInputStream;
import com.kunzisoft.keepass.stream.LEDataOutputStream;
import com.kunzisoft.keepass.stream.NullOutputStream; import com.kunzisoft.keepass.stream.NullOutputStream;
import com.kunzisoft.keepass.tasks.UpdateStatus; import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
import com.kunzisoft.keepass.utils.Types; import com.kunzisoft.keepass.utils.Types;
import java.io.IOException; import java.io.IOException;
@@ -124,22 +123,22 @@ public class ImporterV3 extends Importer {
* @throws InvalidAlgorithmParameterException if error decrypting main file body. * @throws InvalidAlgorithmParameterException if error decrypting main file body.
* @throws ShortBufferException if error decrypting main file body. * @throws ShortBufferException if error decrypting main file body.
*/ */
@Override
public PwDatabaseV3 openDatabase( InputStream inStream, String password, InputStream kfIs) public PwDatabaseV3 openDatabase( InputStream inStream, String password, InputStream kfIs)
throws IOException, InvalidDBException throws IOException, InvalidDBException {
{ return openDatabase(inStream, password, kfIs, null, 0);
return openDatabase(inStream, password, kfIs, new UpdateStatus(), 0);
} }
public PwDatabaseV3 openDatabase( InputStream inStream, String password, InputStream kfIs, UpdateStatus status, long roundsFix) @Override
throws IOException, InvalidDBException public PwDatabaseV3 openDatabase(InputStream inStream, String password, InputStream kfIs, ProgressTaskUpdater progressTaskUpdater, long roundsFix)
{ throws IOException, InvalidDBException {
PwDatabaseV3 newManager;
PwDatabaseV3 databaseToOpen;
// Load entire file, most of it's encrypted. // Load entire file, most of it's encrypted.
int fileSize = inStream.available(); int fileSize = inStream.available();
byte[] filebuf = new byte[fileSize + 16]; // Pad with a blocksize (Twofish uses 128 bits), since Android 4.3 tries to write more to the buffer byte[] filebuf = new byte[fileSize + 16]; // Pad with a blocksize (Twofish uses 128 bits), since Android 4.3 tries to write more to the buffer
inStream.read(filebuf, 0, fileSize); inStream.read(filebuf, 0, fileSize); // TODO remove
inStream.close(); inStream.close();
// Parse header (unencrypted) // Parse header (unencrypted)
@@ -156,34 +155,36 @@ public class ImporterV3 extends Importer {
throw new InvalidDBVersionException(); throw new InvalidDBVersionException();
} }
status.updateMessage(R.string.creating_db_key); if (progressTaskUpdater != null)
newManager = createDB(); progressTaskUpdater.updateMessage(R.string.creating_db_key);
newManager.setMasterKey(password, kfIs); databaseToOpen = createDB();
databaseToOpen.retrieveMasterKey(password, kfIs);
// Select algorithm // Select algorithm
if( (hdr.flags & PwDbHeaderV3.FLAG_RIJNDAEL) != 0 ) { if( (hdr.flags & PwDbHeaderV3.FLAG_RIJNDAEL) != 0 ) {
newManager.setEncryptionAlgorithm(PwEncryptionAlgorithm.AES_Rijndael); databaseToOpen.setEncryptionAlgorithm(PwEncryptionAlgorithm.AES_Rijndael);
} else if( (hdr.flags & PwDbHeaderV3.FLAG_TWOFISH) != 0 ) { } else if( (hdr.flags & PwDbHeaderV3.FLAG_TWOFISH) != 0 ) {
newManager.setEncryptionAlgorithm(PwEncryptionAlgorithm.Twofish); databaseToOpen.setEncryptionAlgorithm(PwEncryptionAlgorithm.Twofish);
} else { } else {
throw new InvalidAlgorithmException(); throw new InvalidAlgorithmException();
} }
// Copy for testing // Copy for testing
newManager.copyHeader(hdr); databaseToOpen.copyHeader(hdr);
newManager.setNumberKeyEncryptionRounds(hdr.numKeyEncRounds); databaseToOpen.setNumberKeyEncryptionRounds(hdr.numKeyEncRounds);
// Generate transformedMasterKey from masterKey // Generate transformedMasterKey from masterKey
newManager.makeFinalKey(hdr.masterSeed, hdr.transformSeed, newManager.getNumberKeyEncryptionRounds()); databaseToOpen.makeFinalKey(hdr.masterSeed, hdr.transformSeed, databaseToOpen.getNumberKeyEncryptionRounds());
status.updateMessage(R.string.decrypting_db); if (progressTaskUpdater != null)
progressTaskUpdater.updateMessage(R.string.decrypting_db);
// Initialize Rijndael algorithm // Initialize Rijndael algorithm
Cipher cipher; Cipher cipher;
try { try {
if ( newManager.getEncryptionAlgorithm() == PwEncryptionAlgorithm.AES_Rijndael) { if ( databaseToOpen.getEncryptionAlgorithm() == PwEncryptionAlgorithm.AES_Rijndael) {
cipher = CipherFactory.getInstance("AES/CBC/PKCS5Padding"); cipher = CipherFactory.getInstance("AES/CBC/PKCS5Padding");
} else if ( newManager.getEncryptionAlgorithm() == PwEncryptionAlgorithm.Twofish ) { } else if ( databaseToOpen.getEncryptionAlgorithm() == PwEncryptionAlgorithm.Twofish ) {
cipher = CipherFactory.getInstance("Twofish/CBC/PKCS7PADDING"); cipher = CipherFactory.getInstance("Twofish/CBC/PKCS7PADDING");
} else { } else {
throw new IOException( "Encryption algorithm is not supported" ); throw new IOException( "Encryption algorithm is not supported" );
@@ -196,7 +197,7 @@ public class ImporterV3 extends Importer {
} }
try { try {
cipher.init( Cipher.DECRYPT_MODE, new SecretKeySpec( newManager.getFinalKey(), "AES" ), new IvParameterSpec( hdr.encryptionIV ) ); cipher.init( Cipher.DECRYPT_MODE, new SecretKeySpec( databaseToOpen.getFinalKey(), "AES" ), new IvParameterSpec( hdr.encryptionIV ) );
} catch (InvalidKeyException e1) { } catch (InvalidKeyException e1) {
throw new IOException("Invalid key"); throw new IOException("Invalid key");
} catch (InvalidAlgorithmParameterException e1) { } catch (InvalidAlgorithmParameterException e1) {
@@ -216,7 +217,7 @@ public class ImporterV3 extends Importer {
} }
// Copy decrypted data for testing // Copy decrypted data for testing
newManager.copyEncrypted(filebuf, PwDbHeaderV3.BUF_SIZE, encryptedPartSize); databaseToOpen.copyEncrypted(filebuf, PwDbHeaderV3.BUF_SIZE, encryptedPartSize);
MessageDigest md = null; MessageDigest md = null;
try { try {
@@ -249,13 +250,13 @@ public class ImporterV3 extends Importer {
if( fieldType == 0xFFFF ) { if( fieldType == 0xFFFF ) {
// End-Group record. Save group and count it. // End-Group record. Save group and count it.
newGrp.populateBlankFields(newManager); newGrp.populateBlankFields(databaseToOpen);
newManager.addGroup(newGrp); databaseToOpen.addGroup(newGrp);
newGrp = new PwGroupV3(); newGrp = new PwGroupV3();
i++; i++;
} }
else { else {
readGroupField(newManager, newGrp, fieldType, filebuf, pos); readGroupField(databaseToOpen, newGrp, fieldType, filebuf, pos);
} }
pos += fieldSize; pos += fieldSize;
} }
@@ -268,65 +269,22 @@ public class ImporterV3 extends Importer {
if( fieldType == 0xFFFF ) { if( fieldType == 0xFFFF ) {
// End-Group record. Save group and count it. // End-Group record. Save group and count it.
newEnt.populateBlankFields(newManager); newEnt.populateBlankFields(databaseToOpen);
newManager.addEntry(newEnt); databaseToOpen.addEntry(newEnt);
newEnt = new PwEntryV3(); newEnt = new PwEntryV3();
i++; i++;
} }
else { else {
readEntryField(newManager, newEnt, filebuf, pos); readEntryField(databaseToOpen, newEnt, filebuf, pos);
} }
pos += 2 + 4 + fieldSize; pos += 2 + 4 + fieldSize;
} }
newManager.constructTree(null); databaseToOpen.constructTree(null);
return newManager; return databaseToOpen;
} }
/**
* KeePass's custom pad style.
*
* @param data buffer to pad.
* @return addtional bytes to append to data[] to make
* a properly padded array.
*/
public static byte[] makePad( byte[] data ) {
//custom pad method
// append 0x80 plus zeros to a multiple of 4 bytes
int thisblk = 32 - data.length % 32; // bytes needed to finish blk
int nextblk = 0; // 32 if we need another block
// need 9 bytes; add new block if no room
if( thisblk < 9 ) {
nextblk = 32;
}
// all bytes are zeroed for free
byte[] pad = new byte[ thisblk + nextblk ];
pad[0] = (byte)0x80;
// write length*8 to end of final block
int ix = thisblk + nextblk - 8;
LEDataOutputStream.writeInt( data.length>>29, pad, ix );
bsw32( pad, ix );
ix += 4;
LEDataOutputStream.writeInt( data.length<<3, pad, ix );
bsw32( pad, ix );
return pad;
}
public static void bsw32( byte[] ary, int offset ) {
byte t = ary[offset];
ary[offset] = ary[offset+3];
ary[offset+3] = t;
t = ary[offset+1];
ary[offset+1] = ary[offset+2];
ary[offset+2] = t;
}
/** /**
* Parse and save one record from binary file. * Parse and save one record from binary file.
* @param buf * @param buf
@@ -334,7 +292,7 @@ public class ImporterV3 extends Importer {
* @return If >0, * @return If >0,
* @throws UnsupportedEncodingException * @throws UnsupportedEncodingException
*/ */
void readGroupField(PwDatabaseV3 db, PwGroupV3 grp, int fieldType, byte[] buf, int offset) throws UnsupportedEncodingException { private void readGroupField(PwDatabaseV3 db, PwGroupV3 grp, int fieldType, byte[] buf, int offset) throws UnsupportedEncodingException {
switch( fieldType ) { switch( fieldType ) {
case 0x0000 : case 0x0000 :
// Ignore field // Ignore field
@@ -371,9 +329,7 @@ public class ImporterV3 extends Importer {
void readEntryField(PwDatabaseV3 db, PwEntryV3 ent, byte[] buf, int offset) private void readEntryField(PwDatabaseV3 db, PwEntryV3 ent, byte[] buf, int offset) throws UnsupportedEncodingException {
throws UnsupportedEncodingException
{
int fieldType = LEDataInputStream.readUShort(buf, offset); int fieldType = LEDataInputStream.readUShort(buf, offset);
offset += 2; offset += 2;
int fieldSize = LEDataInputStream.readInt(buf, offset); int fieldSize = LEDataInputStream.readInt(buf, offset);

View File

@@ -21,7 +21,7 @@ package com.kunzisoft.keepass.database.load;
import com.kunzisoft.keepass.database.PwDatabaseV3Debug; import com.kunzisoft.keepass.database.PwDatabaseV3Debug;
import com.kunzisoft.keepass.database.exception.InvalidDBException; import com.kunzisoft.keepass.database.exception.InvalidDBException;
import com.kunzisoft.keepass.tasks.UpdateStatus; import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -35,7 +35,7 @@ public class ImporterV3Debug extends ImporterV3 {
@Override @Override
public PwDatabaseV3Debug openDatabase(InputStream inStream, String password, public PwDatabaseV3Debug openDatabase(InputStream inStream, String password,
InputStream keyInputStream, UpdateStatus status, long roundsFix) throws IOException, InputStream keyInputStream, ProgressTaskUpdater status, long roundsFix) throws IOException,
InvalidDBException { InvalidDBException {
return (PwDatabaseV3Debug) super.openDatabase(inStream, password, keyInputStream, status, return (PwDatabaseV3Debug) super.openDatabase(inStream, password, keyInputStream, status,
roundsFix); roundsFix);

View File

@@ -19,6 +19,7 @@
*/ */
package com.kunzisoft.keepass.database.load; package com.kunzisoft.keepass.database.load;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.crypto.CipherFactory; import com.kunzisoft.keepass.crypto.CipherFactory;
import com.kunzisoft.keepass.crypto.PwStreamCipherFactory; import com.kunzisoft.keepass.crypto.PwStreamCipherFactory;
import com.kunzisoft.keepass.crypto.engine.CipherEngine; import com.kunzisoft.keepass.crypto.engine.CipherEngine;
@@ -42,7 +43,7 @@ import com.kunzisoft.keepass.stream.BetterCipherInputStream;
import com.kunzisoft.keepass.stream.HashedBlockInputStream; import com.kunzisoft.keepass.stream.HashedBlockInputStream;
import com.kunzisoft.keepass.stream.HmacBlockInputStream; import com.kunzisoft.keepass.stream.HmacBlockInputStream;
import com.kunzisoft.keepass.stream.LEDataInputStream; import com.kunzisoft.keepass.stream.LEDataInputStream;
import com.kunzisoft.keepass.tasks.UpdateStatus; import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
import com.kunzisoft.keepass.utils.DateUtil; import com.kunzisoft.keepass.utils.DateUtil;
import com.kunzisoft.keepass.utils.EmptyUtils; import com.kunzisoft.keepass.utils.EmptyUtils;
import com.kunzisoft.keepass.utils.MemUtil; import com.kunzisoft.keepass.utils.MemUtil;
@@ -81,48 +82,48 @@ public class ImporterV4 extends Importer {
private byte[] hashOfHeader = null; private byte[] hashOfHeader = null;
private byte[] pbHeader = null; private byte[] pbHeader = null;
private long version; private long version;
private int binNum = 0;
Calendar utcCal; Calendar utcCal;
public ImporterV4() { public ImporterV4() {
utcCal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); utcCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
} }
protected PwDatabaseV4 createDB() {
return new PwDatabaseV4();
}
@Override @Override
public PwDatabaseV4 openDatabase(InputStream inStream, String password, public PwDatabaseV4 openDatabase(InputStream inStream, String password,
InputStream keyInputStream) throws IOException, InvalidDBException { InputStream keyInputStream) throws IOException, InvalidDBException {
return openDatabase(inStream, password, keyInputStream, new UpdateStatus(), 0); return openDatabase(inStream, password, keyInputStream, null, 0);
} }
@Override @Override
public PwDatabaseV4 openDatabase(InputStream inStream, String password, public PwDatabaseV4 openDatabase(InputStream inStream, String password,
InputStream keyInputStream, UpdateStatus status, long roundsFix) throws IOException, InputStream keyInputStream, ProgressTaskUpdater progressTaskUpdater, long roundsFix) throws IOException,
InvalidDBException { InvalidDBException {
db = createDB();
if (progressTaskUpdater != null)
progressTaskUpdater.updateMessage(R.string.creating_db_key);
db = new PwDatabaseV4();
PwDbHeaderV4 header = new PwDbHeaderV4(db); PwDbHeaderV4 header = new PwDbHeaderV4(db);
db.getBinPool().clear(); db.getBinPool().clear();
PwDbHeaderV4.HeaderAndHash hh = header.loadFromFile(inStream); PwDbHeaderV4.HeaderAndHash hh = header.loadFromFile(inStream);
version = header.version; version = header.getVersion();
hashOfHeader = hh.hash; hashOfHeader = hh.hash;
pbHeader = hh.header; pbHeader = hh.header;
db.setMasterKey(password, keyInputStream);
db.makeFinalKey(header.masterSeed, db.getKdfParameters(), roundsFix);
db.retrieveMasterKey(password, keyInputStream);
db.makeFinalKey(header.masterSeed, roundsFix);
if (progressTaskUpdater != null)
progressTaskUpdater.updateMessage(R.string.decrypting_db);
CipherEngine engine; CipherEngine engine;
Cipher cipher; Cipher cipher;
try { try {
engine = CipherFactory.getInstance(db.getDataCipher()); engine = CipherFactory.getInstance(db.getDataCipher());
db.setDataEngine(engine); db.setDataEngine(engine);
db.setEncryptionAlgorithm(engine.getPwEncryptionAlgorithm());
cipher = engine.getCipher(Cipher.DECRYPT_MODE, db.getFinalKey(), header.encryptionIV); cipher = engine.getCipher(Cipher.DECRYPT_MODE, db.getFinalKey(), header.encryptionIV);
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
throw new IOException("Invalid algorithm."); throw new IOException("Invalid algorithm.");
@@ -185,7 +186,7 @@ public class ImporterV4 extends Importer {
isXml = isPlain; isXml = isPlain;
} }
if (version >= header.FILE_VERSION_32_4) { if (version >= PwDbHeaderV4.FILE_VERSION_32_4) {
LoadInnerHeader(isXml, header); LoadInnerHeader(isXml, header);
} }

View File

@@ -55,7 +55,7 @@ public class PwDbHeaderOutputV4 extends PwDbHeaderOutput {
db = d; db = d;
header = h; header = h;
MessageDigest md = null; MessageDigest md;
try { try {
md = MessageDigest.getInstance("SHA-256"); md = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
@@ -63,7 +63,7 @@ public class PwDbHeaderOutputV4 extends PwDbHeaderOutput {
} }
try { try {
d.makeFinalKey(header.masterSeed, d.getKdfParameters()); d.makeFinalKey(header.masterSeed);
} catch (IOException e) { } catch (IOException e) {
throw new PwDbOutputException(e); throw new PwDbOutputException(e);
} }
@@ -88,25 +88,26 @@ public class PwDbHeaderOutputV4 extends PwDbHeaderOutput {
los.writeUInt(PwDbHeader.PWM_DBSIG_1); los.writeUInt(PwDbHeader.PWM_DBSIG_1);
los.writeUInt(PwDbHeaderV4.DBSIG_2); los.writeUInt(PwDbHeaderV4.DBSIG_2);
los.writeUInt(header.version); los.writeUInt(header.getVersion());
writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.CipherID, Types.UUIDtoBytes(db.getDataCipher())); writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.CipherID, Types.UUIDtoBytes(db.getDataCipher()));
writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.CompressionFlags, LEDataOutputStream.writeIntBuf(db.getCompressionAlgorithm().id)); writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.CompressionFlags, LEDataOutputStream.writeIntBuf(db.getCompressionAlgorithm().id));
writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.MasterSeed, header.masterSeed); writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.MasterSeed, header.masterSeed);
if (header.version < PwDbHeaderV4.FILE_VERSION_32_4) { if (header.getVersion() < PwDbHeaderV4.FILE_VERSION_32_4) {
writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.TransformSeed, header.getTransformSeed()); writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.TransformSeed, header.getTransformSeed());
writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.TransformRounds, LEDataOutputStream.writeLongBuf(db.getNumberKeyEncryptionRounds())); writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.TransformRounds, LEDataOutputStream.writeLongBuf(db.getNumberKeyEncryptionRounds()));
} else { } else {
writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.KdfParameters, KdfParameters.serialize(db.getKdfParameters())); writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.KdfParameters, KdfParameters.serialize(db.getKdfParameters()));
// TODO verify serialize in all cases
} }
if (header.encryptionIV.length > 0) { if (header.encryptionIV.length > 0) {
writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.EncryptionIV, header.encryptionIV); writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.EncryptionIV, header.encryptionIV);
} }
if (header.version < PwDbHeaderV4.FILE_VERSION_32_4) { if (header.getVersion() < PwDbHeaderV4.FILE_VERSION_32_4) {
writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.InnerRandomstreamKey, header.innerRandomStreamKey); writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.InnerRandomstreamKey, header.innerRandomStreamKey);
writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.StreamStartBytes, header.streamStartBytes); writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.StreamStartBytes, header.streamStartBytes);
writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.InnerRandomStreamID, LEDataOutputStream.writeIntBuf(header.innerRandomStream.id)); writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.InnerRandomStreamID, LEDataOutputStream.writeIntBuf(header.innerRandomStream.id));
@@ -139,7 +140,7 @@ public class PwDbHeaderOutputV4 extends PwDbHeaderOutput {
} }
private void writeHeaderFieldSize(int size) throws IOException { private void writeHeaderFieldSize(int size) throws IOException {
if (header.version < PwDbHeaderV4.FILE_VERSION_32_4) { if (header.getVersion() < PwDbHeaderV4.FILE_VERSION_32_4) {
los.writeUShort(size); los.writeUShort(size);
} else { } else {
los.writeInt(size); los.writeInt(size);

View File

@@ -29,7 +29,7 @@ import java.io.OutputStream;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom; import java.security.SecureRandom;
public abstract class PwDbOutput { public abstract class PwDbOutput<Header extends PwDbHeader> {
protected OutputStream mOS; protected OutputStream mOS;
@@ -47,7 +47,7 @@ public abstract class PwDbOutput {
mOS = os; mOS = os;
} }
protected SecureRandom setIVs(PwDbHeader header) throws PwDbOutputException { protected SecureRandom setIVs(Header header) throws PwDbOutputException {
SecureRandom random; SecureRandom random;
try { try {
random = SecureRandom.getInstance("SHA1PRNG"); random = SecureRandom.getInstance("SHA1PRNG");
@@ -62,6 +62,6 @@ public abstract class PwDbOutput {
public abstract void output() throws PwDbOutputException; public abstract void output() throws PwDbOutputException;
public abstract PwDbHeader outputHeader(OutputStream os) throws PwDbOutputException; public abstract Header outputHeader(OutputStream os) throws PwDbOutputException;
} }

View File

@@ -48,7 +48,7 @@ import javax.crypto.CipherOutputStream;
import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
public class PwDbV3Output extends PwDbOutput { public class PwDbV3Output extends PwDbOutput<PwDbHeaderV3> {
private PwDatabaseV3 mPM; private PwDatabaseV3 mPM;
private byte[] headerHashBlock; private byte[] headerHashBlock;
@@ -111,15 +111,13 @@ public class PwDbV3Output extends PwDbOutput {
} }
@Override @Override
protected SecureRandom setIVs(PwDbHeader header) throws PwDbOutputException { protected SecureRandom setIVs(PwDbHeaderV3 header) throws PwDbOutputException {
SecureRandom random = super.setIVs(header); SecureRandom random = super.setIVs(header);
random.nextBytes(header.transformSeed);
PwDbHeaderV3 h3 = (PwDbHeaderV3) header;
random.nextBytes(h3.transformSeed);
return random; return random;
} }
@Override
public PwDbHeaderV3 outputHeader(OutputStream os) throws PwDbOutputException { public PwDbHeaderV3 outputHeader(OutputStream os) throws PwDbOutputException {
// Build header // Build header
PwDbHeaderV3 header = new PwDbHeaderV3(); PwDbHeaderV3 header = new PwDbHeaderV3();

View File

@@ -21,7 +21,6 @@ package com.kunzisoft.keepass.database.save;
import com.kunzisoft.keepass.database.PwDatabaseV3; import com.kunzisoft.keepass.database.PwDatabaseV3;
import com.kunzisoft.keepass.database.PwDatabaseV3Debug; import com.kunzisoft.keepass.database.PwDatabaseV3Debug;
import com.kunzisoft.keepass.database.PwDbHeader;
import com.kunzisoft.keepass.database.PwDbHeaderV3; import com.kunzisoft.keepass.database.PwDbHeaderV3;
import com.kunzisoft.keepass.database.exception.PwDbOutputException; import com.kunzisoft.keepass.database.exception.PwDbOutputException;
@@ -32,10 +31,6 @@ public class PwDbV3OutputDebug extends PwDbV3Output {
PwDatabaseV3Debug debugDb; PwDatabaseV3Debug debugDb;
private boolean noHeaderHash; private boolean noHeaderHash;
public PwDbV3OutputDebug(PwDatabaseV3 pm, OutputStream os) {
this(pm, os, false);
}
public PwDbV3OutputDebug(PwDatabaseV3 pm, OutputStream os, boolean noHeaderHash) { public PwDbV3OutputDebug(PwDatabaseV3 pm, OutputStream os, boolean noHeaderHash) {
super(pm, os); super(pm, os);
debugDb = (PwDatabaseV3Debug) pm; debugDb = (PwDatabaseV3Debug) pm;
@@ -43,10 +38,7 @@ public class PwDbV3OutputDebug extends PwDbV3Output {
} }
@Override @Override
protected SecureRandom setIVs(PwDbHeader h) throws PwDbOutputException { protected SecureRandom setIVs(PwDbHeaderV3 header) throws PwDbOutputException {
PwDbHeaderV3 header = (PwDbHeaderV3) h;
// Reuse random values to test equivalence in debug mode // Reuse random values to test equivalence in debug mode
PwDbHeaderV3 origHeader = debugDb.getDbHeader(); PwDbHeaderV3 origHeader = debugDb.getDbHeader();
System.arraycopy(origHeader.encryptionIV, 0, header.encryptionIV, 0, origHeader.encryptionIV.length); System.arraycopy(origHeader.encryptionIV, 0, header.encryptionIV, 0, origHeader.encryptionIV.length);

View File

@@ -35,7 +35,6 @@ import com.kunzisoft.keepass.database.MemoryProtectionConfig;
import com.kunzisoft.keepass.database.PwCompressionAlgorithm; import com.kunzisoft.keepass.database.PwCompressionAlgorithm;
import com.kunzisoft.keepass.database.PwDatabaseV4; import com.kunzisoft.keepass.database.PwDatabaseV4;
import com.kunzisoft.keepass.database.PwDatabaseV4XML; import com.kunzisoft.keepass.database.PwDatabaseV4XML;
import com.kunzisoft.keepass.database.PwDbHeader;
import com.kunzisoft.keepass.database.PwDbHeaderV4; import com.kunzisoft.keepass.database.PwDbHeaderV4;
import com.kunzisoft.keepass.database.PwDefsV4; import com.kunzisoft.keepass.database.PwDefsV4;
import com.kunzisoft.keepass.database.PwDeletedObject; import com.kunzisoft.keepass.database.PwDeletedObject;
@@ -74,9 +73,9 @@ import javax.crypto.CipherOutputStream;
import biz.source_code.base64Coder.Base64Coder; import biz.source_code.base64Coder.Base64Coder;
public class PwDbV4Output extends PwDbOutput { public class PwDbV4Output extends PwDbOutput<PwDbHeaderV4> {
PwDatabaseV4 mPM; private PwDatabaseV4 mPM;
private StreamCipher randomStream; private StreamCipher randomStream;
private XmlSerializer xml; private XmlSerializer xml;
private PwDbHeaderV4 header; private PwDbHeaderV4 header;
@@ -86,8 +85,7 @@ public class PwDbV4Output extends PwDbOutput {
protected PwDbV4Output(PwDatabaseV4 pm, OutputStream os) { protected PwDbV4Output(PwDatabaseV4 pm, OutputStream os) {
super(os); super(os);
this.mPM = pm;
mPM = pm;
} }
@Override @Override
@@ -100,15 +98,14 @@ public class PwDbV4Output extends PwDbOutput {
throw new PwDbOutputException("No such cipher", e); throw new PwDbOutputException("No such cipher", e);
} }
header = (PwDbHeaderV4) outputHeader(mOS); header = outputHeader(mOS);
OutputStream osPlain; OutputStream osPlain;
if (header.version < PwDbHeaderV4.FILE_VERSION_32_4) { if (header.getVersion() < PwDbHeaderV4.FILE_VERSION_32_4) {
CipherOutputStream cos = attachStreamEncryptor(header, mOS); CipherOutputStream cos = attachStreamEncryptor(header, mOS);
cos.write(header.streamStartBytes); cos.write(header.streamStartBytes);
HashedBlockOutputStream hashed = new HashedBlockOutputStream(cos); osPlain = new HashedBlockOutputStream(cos);
osPlain = hashed;
} else { } else {
mOS.write(hashOfHeader); mOS.write(hashOfHeader);
mOS.write(headerHmac); mOS.write(headerHmac);
@@ -125,7 +122,7 @@ public class PwDbV4Output extends PwDbOutput {
osXml = osPlain; osXml = osPlain;
} }
if (header.version >= PwDbHeaderV4.FILE_VERSION_32_4) { if (header.getVersion() >= PwDbHeaderV4.FILE_VERSION_32_4) {
PwDbInnerHeaderOutputV4 ihOut = new PwDbInnerHeaderOutputV4(mPM, header, osXml); PwDbInnerHeaderOutputV4 ihOut = new PwDbInnerHeaderOutputV4(mPM, header, osXml);
ihOut.output(); ihOut.output();
} }
@@ -261,7 +258,7 @@ public class PwDbV4Output extends PwDbOutput {
writeObject(PwDatabaseV4XML.ElemLastSelectedGroup, mPM.getLastSelectedGroup()); writeObject(PwDatabaseV4XML.ElemLastSelectedGroup, mPM.getLastSelectedGroup());
writeObject(PwDatabaseV4XML.ElemLastTopVisibleGroup, mPM.getLastTopVisibleGroup()); writeObject(PwDatabaseV4XML.ElemLastTopVisibleGroup, mPM.getLastTopVisibleGroup());
if (header.version < PwDbHeaderV4.FILE_VERSION_32_4) { if (header.getVersion() < PwDbHeaderV4.FILE_VERSION_32_4) {
writeBinPool(); writeBinPool();
} }
writeList(PwDatabaseV4XML.ElemCustomData, mPM.getCustomData()); writeList(PwDatabaseV4XML.ElemCustomData, mPM.getCustomData());
@@ -286,46 +283,44 @@ public class PwDbV4Output extends PwDbOutput {
} }
@Override @Override
protected SecureRandom setIVs(PwDbHeader header) throws PwDbOutputException { protected SecureRandom setIVs(PwDbHeaderV4 header) throws PwDbOutputException {
SecureRandom random = super.setIVs(header); SecureRandom random = super.setIVs(header);
random.nextBytes(header.masterSeed);
PwDbHeaderV4 h = (PwDbHeaderV4) header;
random.nextBytes(h.masterSeed);
int ivLength = engine.ivLength(); int ivLength = engine.ivLength();
if (ivLength != h.encryptionIV.length) { if (ivLength != header.encryptionIV.length) {
h.encryptionIV = new byte[ivLength]; header.encryptionIV = new byte[ivLength];
} }
random.nextBytes(h.encryptionIV); random.nextBytes(header.encryptionIV);
UUID kdfUUID = mPM.getKdfParameters().kdfUUID; KdfEngine kdf = KdfFactory.get(mPM.getKdfParameters());
KdfEngine kdf = KdfFactory.get(kdfUUID);
kdf.randomize(mPM.getKdfParameters()); kdf.randomize(mPM.getKdfParameters());
if (h.version < PwDbHeaderV4.FILE_VERSION_32_4) { if (header.getVersion() < PwDbHeaderV4.FILE_VERSION_32_4) {
h.innerRandomStream = CrsAlgorithm.Salsa20; header.innerRandomStream = CrsAlgorithm.Salsa20;
h.innerRandomStreamKey = new byte[32]; header.innerRandomStreamKey = new byte[32];
} else { } else {
h.innerRandomStream = CrsAlgorithm.ChaCha20; header.innerRandomStream = CrsAlgorithm.ChaCha20;
h.innerRandomStreamKey = new byte[64]; header.innerRandomStreamKey = new byte[64];
} }
random.nextBytes(h.innerRandomStreamKey); random.nextBytes(header.innerRandomStreamKey);
randomStream = PwStreamCipherFactory.getInstance(h.innerRandomStream, h.innerRandomStreamKey); randomStream = PwStreamCipherFactory.getInstance(header.innerRandomStream, header.innerRandomStreamKey);
if (randomStream == null) { if (randomStream == null) {
throw new PwDbOutputException("Invalid random cipher"); throw new PwDbOutputException("Invalid random cipher");
} }
if ( h.version < PwDbHeaderV4.FILE_VERSION_32_4) { if ( header.getVersion() < PwDbHeaderV4.FILE_VERSION_32_4) {
random.nextBytes(h.streamStartBytes); random.nextBytes(header.streamStartBytes);
} }
return random; return random;
} }
@Override @Override
public PwDbHeader outputHeader(OutputStream os) throws PwDbOutputException { public PwDbHeaderV4 outputHeader(OutputStream os) throws PwDbOutputException {
PwDbHeaderV4 header = new PwDbHeaderV4(mPM);
PwDbHeaderV4 header = new PwDbHeaderV4(mPM);
setIVs(header); setIVs(header);
PwDbHeaderOutputV4 pho = new PwDbHeaderOutputV4(mPM, header, os); PwDbHeaderOutputV4 pho = new PwDbHeaderOutputV4(mPM, header, os);
@@ -468,7 +463,7 @@ public class PwDbV4Output extends PwDbOutput {
} }
private void writeObject(String name, Date value) throws IllegalArgumentException, IllegalStateException, IOException { private void writeObject(String name, Date value) throws IllegalArgumentException, IllegalStateException, IOException {
if (header.version < PwDbHeaderV4.FILE_VERSION_32_4) { if (header.getVersion() < PwDbHeaderV4.FILE_VERSION_32_4) {
writeObject(name, PwDatabaseV4XML.dateFormatter.get().format(value)); writeObject(name, PwDatabaseV4XML.dateFormatter.get().format(value));
} else { } else {
DateTime dt = new DateTime(value); DateTime dt = new DateTime(value);

View File

@@ -35,11 +35,13 @@ import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.fileselect.FilePickerStylishActivity; import com.kunzisoft.keepass.fileselect.FilePickerStylishActivity;
@@ -153,6 +155,16 @@ public class CreateFileDialogFragment extends DialogFragment implements AdapterV
ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, fileTypes); ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, fileTypes);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter); spinner.setAdapter(dataAdapter);
// Or text if only one item https://github.com/Kunzisoft/KeePassDX/issues/105
if (fileTypes.length == 1) {
ViewGroup.LayoutParams params = spinner.getLayoutParams();
spinner.setVisibility(View.GONE);
TextView extensionTextView = new TextView(getContext());
extensionTextView.setText(extension);
extensionTextView.setLayoutParams(params);
ViewGroup parentView = (ViewGroup) spinner.getParent();
parentView.addView(extensionTextView);
}
AlertDialog dialog = builder.create(); AlertDialog dialog = builder.create();

View File

@@ -60,7 +60,7 @@ public class ProFeatureDialogFragment extends DialogFragment {
stringBuilder.append(Html.fromHtml(getString(R.string.html_text_donation))); stringBuilder.append(Html.fromHtml(getString(R.string.html_text_donation)));
builder.setPositiveButton(R.string.contribute, (dialog, id) -> { builder.setPositiveButton(R.string.contribute, (dialog, id) -> {
try { try {
Util.gotoUrl(getContext(), R.string.donate_url); Util.gotoUrl(getContext(), R.string.contribution_url);
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
Toast.makeText(getContext(), R.string.error_failed_to_launch_link, Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), R.string.error_failed_to_launch_link, Toast.LENGTH_LONG).show();
} }

View File

@@ -44,31 +44,41 @@ public class UnderDevelopmentFeatureDialogFragment extends DialogFragment {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(); SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
stringBuilder.append(Html.fromHtml(getString(R.string.html_text_dev_feature))).append("\n\n");
if (BuildConfig.CLOSED_STORE) { if (BuildConfig.CLOSED_STORE) {
stringBuilder.append(Html.fromHtml(getString(R.string.html_text_dev_feature_buy_pro))).append(" ") if (BuildConfig.FULL_VERSION) {
.append(Html.fromHtml(getString(R.string.html_text_dev_feature_encourage))); stringBuilder.append(Html.fromHtml(getString(R.string.html_text_dev_feature_thanks))).append("\n\n")
builder.setPositiveButton(R.string.download, (dialog, id) -> { .append(Html.fromHtml(getString(R.string.html_rose))).append("\n\n")
try { .append(Html.fromHtml(getString(R.string.html_text_dev_feature_work_hard))).append("\n")
Util.gotoUrl(getContext(), R.string.app_pro_url); .append(Html.fromHtml(getString(R.string.html_text_dev_feature_upgrade))).append(" ");
} catch (ActivityNotFoundException e) { builder.setPositiveButton(android.R.string.ok, (dialog, id) -> dismiss());
Toast.makeText(getContext(), R.string.error_failed_to_launch_link, Toast.LENGTH_LONG).show(); } else {
} stringBuilder.append(Html.fromHtml(getString(R.string.html_text_dev_feature))).append("\n\n")
}); .append(Html.fromHtml(getString(R.string.html_text_dev_feature_buy_pro))).append("\n")
.append(Html.fromHtml(getString(R.string.html_text_dev_feature_encourage)));
builder.setPositiveButton(R.string.download, (dialog, id) -> {
try {
Util.gotoUrl(getContext(), R.string.app_pro_url);
} catch (ActivityNotFoundException e) {
Toast.makeText(getContext(), R.string.error_failed_to_launch_link, Toast.LENGTH_LONG).show();
}
});
builder.setNegativeButton(android.R.string.cancel, (dialog, id) -> dismiss());
}
} }
else { else {
stringBuilder.append(Html.fromHtml(getString(R.string.html_text_dev_feature_contibute))).append(" ") stringBuilder.append(Html.fromHtml(getString(R.string.html_text_dev_feature))).append("\n\n")
.append(Html.fromHtml(getString(R.string.html_text_dev_feature_encourage))); .append(Html.fromHtml(getString(R.string.html_text_dev_feature_contibute))).append(" ")
.append(Html.fromHtml(getString(R.string.html_text_dev_feature_encourage)));
builder.setPositiveButton(R.string.contribute, (dialog, id) -> { builder.setPositiveButton(R.string.contribute, (dialog, id) -> {
try { try {
Util.gotoUrl(getContext(), R.string.donate_url); Util.gotoUrl(getContext(), R.string.contribution_url);
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
Toast.makeText(getContext(), R.string.error_failed_to_launch_link, Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), R.string.error_failed_to_launch_link, Toast.LENGTH_LONG).show();
} }
}); });
builder.setNegativeButton(android.R.string.cancel, (dialog, id) -> dismiss());
} }
builder.setMessage(stringBuilder); builder.setMessage(stringBuilder);
builder.setNegativeButton(android.R.string.cancel, (dialog, id) -> dismiss());
// Create the AlertDialog object and return it // Create the AlertDialog object and return it
return builder.create(); return builder.create();
} }

View File

@@ -62,6 +62,8 @@ public class FilePickerStylishActivity extends FilePickerActivity {
return R.style.KeepassDXStyle_FilePickerStyle_Dark; return R.style.KeepassDXStyle_FilePickerStyle_Dark;
else if (themeString.equals(context.getString(R.string.list_style_name_blue))) else if (themeString.equals(context.getString(R.string.list_style_name_blue)))
return R.style.KeepassDXStyle_FilePickerStyle_Blue; return R.style.KeepassDXStyle_FilePickerStyle_Blue;
else if (themeString.equals(context.getString(R.string.list_style_name_red)))
return R.style.KeepassDXStyle_FilePickerStyle_Red;
else if (themeString.equals(context.getString(R.string.list_style_name_purple))) else if (themeString.equals(context.getString(R.string.list_style_name_purple)))
return R.style.KeepassDXStyle_FilePickerStyle_Purple; return R.style.KeepassDXStyle_FilePickerStyle_Purple;

View File

@@ -24,6 +24,7 @@ import android.app.Activity;
import android.app.assist.AssistStructure; import android.app.assist.AssistStructure;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@@ -50,8 +51,8 @@ import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.activities.GroupActivity; import com.kunzisoft.keepass.activities.GroupActivity;
import com.kunzisoft.keepass.app.App; import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.autofill.AutofillHelper; import com.kunzisoft.keepass.autofill.AutofillHelper;
import com.kunzisoft.keepass.database.edit.CreateDB; import com.kunzisoft.keepass.database.action.CreateDBRunnable;
import com.kunzisoft.keepass.database.edit.FileOnFinish; import com.kunzisoft.keepass.database.action.FileOnFinishRunnable;
import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException; import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException;
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment; import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
import com.kunzisoft.keepass.dialogs.CreateFileDialogFragment; import com.kunzisoft.keepass.dialogs.CreateFileDialogFragment;
@@ -59,7 +60,8 @@ import com.kunzisoft.keepass.password.AssignPasswordHelper;
import com.kunzisoft.keepass.password.PasswordActivity; import com.kunzisoft.keepass.password.PasswordActivity;
import com.kunzisoft.keepass.settings.PreferencesUtil; import com.kunzisoft.keepass.settings.PreferencesUtil;
import com.kunzisoft.keepass.stylish.StylishActivity; import com.kunzisoft.keepass.stylish.StylishActivity;
import com.kunzisoft.keepass.tasks.ProgressTask; import com.kunzisoft.keepass.tasks.ProgressTaskDialogFragment;
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
import com.kunzisoft.keepass.utils.EmptyUtils; import com.kunzisoft.keepass.utils.EmptyUtils;
import com.kunzisoft.keepass.utils.MenuUtil; import com.kunzisoft.keepass.utils.MenuUtil;
import com.kunzisoft.keepass.utils.UriUtil; import com.kunzisoft.keepass.utils.UriUtil;
@@ -312,6 +314,7 @@ public class FileSelectActivity extends StylishActivity implements
getString(R.string.education_create_database_title), getString(R.string.education_create_database_title),
getString(R.string.education_create_database_summary)) getString(R.string.education_create_database_summary))
.icon(ContextCompat.getDrawable(this, R.drawable.ic_database_plus_white_24dp)) .icon(ContextCompat.getDrawable(this, R.drawable.ic_database_plus_white_24dp))
.textColorInt(Color.WHITE)
.tintTarget(true) .tintTarget(true)
.cancelable(true), .cancelable(true),
new TapTargetView.Listener() { new TapTargetView.Listener() {
@@ -352,6 +355,7 @@ public class FileSelectActivity extends StylishActivity implements
getString(R.string.education_select_database_title), getString(R.string.education_select_database_title),
getString(R.string.education_select_database_summary)) getString(R.string.education_select_database_summary))
.icon(ContextCompat.getDrawable(this, R.drawable.ic_folder_white_24dp)) .icon(ContextCompat.getDrawable(this, R.drawable.ic_folder_white_24dp))
.textColorInt(Color.WHITE)
.tintTarget(true) .tintTarget(true)
.cancelable(true), .cancelable(true),
new TapTargetView.Listener() { new TapTargetView.Listener() {
@@ -373,6 +377,7 @@ public class FileSelectActivity extends StylishActivity implements
getString(R.string.education_open_link_database_title), getString(R.string.education_open_link_database_title),
getString(R.string.education_open_link_database_summary)) getString(R.string.education_open_link_database_summary))
.icon(ContextCompat.getDrawable(FileSelectActivity.this, R.drawable.ic_link_white_24dp)) .icon(ContextCompat.getDrawable(FileSelectActivity.this, R.drawable.ic_link_white_24dp))
.textColorInt(Color.WHITE)
.tintTarget(true) .tintTarget(true)
.cancelable(true), .cancelable(true),
new TapTargetView.Listener() { new TapTargetView.Listener() {
@@ -511,22 +516,26 @@ public class FileSelectActivity extends StylishActivity implements
// Prep an object to collect a password once the database has // Prep an object to collect a password once the database has
// been created // been created
FileOnFinish launchActivityOnFinish = new FileOnFinish( FileOnFinishRunnable launchActivityOnFinish = new FileOnFinishRunnable(
new LaunchGroupActivity(databaseFilename)); new LaunchGroupActivity(databaseFilename));
AssignPasswordOnFinish assignPasswordOnFinish = AssignPasswordOnFinish assignPasswordOnFinish =
new AssignPasswordOnFinish(launchActivityOnFinish); new AssignPasswordOnFinish(launchActivityOnFinish);
// Create the new database // Initialize the password helper assigner to set the password after the database creation
CreateDB create = new CreateDB(FileSelectActivity.this,
databaseFilename, assignPasswordOnFinish, true);
ProgressTask createTask = new ProgressTask(
FileSelectActivity.this, create,
R.string.progress_create);
createTask.run();
assignPasswordHelper = new AssignPasswordHelper(this, assignPasswordHelper = new AssignPasswordHelper(this,
masterPasswordChecked, masterPassword, keyFileChecked, keyFile); masterPasswordChecked, masterPassword, keyFileChecked, keyFile);
assignPasswordHelper.setCreateProgressDialog(false);
// Create the new database
CreateDBRunnable createDBTask = new CreateDBRunnable(FileSelectActivity.this,
databaseFilename, assignPasswordOnFinish, true);
createDBTask.setUpdateProgressTaskStatus(
new UpdateProgressTaskStatus(this,
ProgressTaskDialogFragment.start(
getSupportFragmentManager(),
R.string.progress_create)
));
new Thread(createDBTask).start();
} catch (Exception e) { } catch (Exception e) {
String error = "Unable to create database with this password and key file"; String error = "Unable to create database with this password and key file";
@@ -542,21 +551,23 @@ public class FileSelectActivity extends StylishActivity implements
} }
private class AssignPasswordOnFinish extends FileOnFinish { private class AssignPasswordOnFinish extends FileOnFinishRunnable {
AssignPasswordOnFinish(FileOnFinish fileOnFinish) { AssignPasswordOnFinish(FileOnFinishRunnable fileOnFinish) {
super(fileOnFinish); super(fileOnFinish);
} }
@Override @Override
public void run() { public void run() {
if (mSuccess) { if (mSuccess) {
assignPasswordHelper.assignPasswordInDatabase(mOnFinish); // Dont use ProgressTaskDialogFragment.stop(getSupportFragmentManager());
// assignPasswordHelper do it
runOnUiThread(() -> assignPasswordHelper.assignPasswordInDatabase(mOnFinish));
} }
} }
} }
private class LaunchGroupActivity extends FileOnFinish { private class LaunchGroupActivity extends FileOnFinishRunnable {
private Uri mUri; private Uri mUri;
LaunchGroupActivity(String filename) { LaunchGroupActivity(String filename) {

View File

@@ -42,13 +42,17 @@ public class FingerPrintAnimatedVector {
public void startScan() { public void startScan() {
scanFingerprint.registerAnimationCallback(new Animatable2.AnimationCallback() { scanFingerprint.registerAnimationCallback(new Animatable2.AnimationCallback() {
public void onAnimationEnd(Drawable drawable) { public void onAnimationEnd(Drawable drawable) {
scanFingerprint.start(); if (!scanFingerprint.isRunning())
scanFingerprint.start();
} }
}); });
scanFingerprint.start();
if (!scanFingerprint.isRunning())
scanFingerprint.start();
} }
public void stopScan() { public void stopScan() {
scanFingerprint.stop(); if (scanFingerprint.isRunning())
scanFingerprint.stop();
} }
} }

View File

@@ -131,7 +131,7 @@ public class FingerPrintHelper {
return isFingerprintInitialized(true); return isFingerprintInitialized(true);
} }
public boolean isFingerprintInitialized(boolean throwException) { private boolean isFingerprintInitialized(boolean throwException) {
boolean isFingerprintInit = hasEnrolledFingerprints() && initOk; boolean isFingerprintInit = hasEnrolledFingerprints() && initOk;
if (!isFingerprintInit && fingerPrintCallback != null) { if (!isFingerprintInit && fingerPrintCallback != null) {
if(throwException) if(throwException)
@@ -336,7 +336,7 @@ public class FingerPrintHelper {
} }
public enum Mode { public enum Mode {
NOT_CONFIGURED_MODE, STORE_MODE, OPEN_MODE NOT_CONFIGURED_MODE, WAITING_PASSWORD_MODE, STORE_MODE, OPEN_MODE
} }
} }

View File

@@ -29,6 +29,7 @@ import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.widget.ImageViewCompat; import android.support.v4.widget.ImageViewCompat;
import android.util.Log;
import android.widget.ImageView; import android.widget.ImageView;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
@@ -44,6 +45,9 @@ import org.apache.commons.collections.map.ReferenceMap;
* Factory class who build database icons dynamically, can assign an icon of IconPack, or a custom icon to an ImageView with a tint * Factory class who build database icons dynamically, can assign an icon of IconPack, or a custom icon to an ImageView with a tint
*/ */
public class IconDrawableFactory { public class IconDrawableFactory {
private static final String TAG = IconDrawableFactory.class.getName();
private static Drawable blank = null; private static Drawable blank = null;
private static int blankWidth = -1; private static int blankWidth = -1;
private static int blankHeight = -1; private static int blankHeight = -1;
@@ -236,12 +240,22 @@ public class IconDrawableFactory {
Drawable draw = (Drawable) standardIconMap.get(newCacheKey); Drawable draw = (Drawable) standardIconMap.get(newCacheKey);
if (draw == null) { if (draw == null) {
draw = ContextCompat.getDrawable(context, iconId); try {
draw = ContextCompat.getDrawable(context, iconId);
} catch (Exception e) {
Log.e(TAG, "Can't get icon", e);
}
if (draw != null) { if (draw != null) {
standardIconMap.put(newCacheKey, draw); standardIconMap.put(newCacheKey, draw);
} }
} }
if (draw == null) {
if (blank == null)
initBlank(context.getResources());
draw = blank;
}
return draw; return draw;
} }

View File

@@ -19,25 +19,30 @@
*/ */
package com.kunzisoft.keepass.password; package com.kunzisoft.keepass.password;
import android.content.Context;
import android.net.Uri; import android.net.Uri;
import android.os.Handler; import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.app.App; import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.database.edit.FileOnFinish; import com.kunzisoft.keepass.database.action.AssignPasswordInDBRunnable;
import com.kunzisoft.keepass.database.edit.OnFinish; import com.kunzisoft.keepass.database.action.FileOnFinishRunnable;
import com.kunzisoft.keepass.database.edit.SetPassword; import com.kunzisoft.keepass.database.action.OnFinishRunnable;
import com.kunzisoft.keepass.tasks.ProgressTask; import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper;
import com.kunzisoft.keepass.tasks.ProgressTaskDialogFragment;
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
public class AssignPasswordHelper { public class AssignPasswordHelper {
private Context context; private AppCompatActivity context;
private String masterPassword = null; private String masterPassword = null;
private Uri keyfile = null; private Uri keyfile = null;
public AssignPasswordHelper(Context context, private boolean createProgressDialog;
public AssignPasswordHelper(AppCompatActivity context,
boolean withMasterPassword, boolean withMasterPassword,
String masterPassword, String masterPassword,
boolean withKeyFile, boolean withKeyFile,
@@ -47,36 +52,66 @@ public class AssignPasswordHelper {
this.masterPassword = masterPassword; this.masterPassword = masterPassword;
if (withKeyFile) if (withKeyFile)
this.keyfile = keyfile; this.keyfile = keyfile;
createProgressDialog = true;
} }
public void assignPasswordInDatabase(FileOnFinish fileOnFinish) { public void setCreateProgressDialog(boolean createProgressDialog) {
SetPassword sp = new SetPassword(context, App.getDB(), masterPassword, keyfile, new AfterSave(fileOnFinish, new Handler())); this.createProgressDialog = createProgressDialog;
final ProgressTask pt = new ProgressTask(context, sp, R.string.saving_database); }
boolean valid = sp.validatePassword(context, (dialog, which) -> pt.run());
if (valid) { public void assignPasswordInDatabase(FileOnFinishRunnable fileOnFinish) {
pt.run(); AssignPasswordInDBRunnable assignPasswordInDBRunnable = new AssignPasswordInDBRunnable(
context,
App.getDB(),
masterPassword,
keyfile,
new AfterSave(fileOnFinish, new Handler())
);
if (createProgressDialog) {
assignPasswordInDBRunnable.setUpdateProgressTaskStatus(
new UpdateProgressTaskStatus(context,
SaveDatabaseProgressTaskDialogFragment.start(
context.getSupportFragmentManager())
));
}
Thread taskThread = new Thread(assignPasswordInDBRunnable);
// Show the progress dialog now or after dialog confirmation
if (App.getDB().getPwDatabase().validatePasswordEncoding(masterPassword)) {
taskThread.start();
} else {
PasswordEncodingDialogHelper dialog = new PasswordEncodingDialogHelper();
dialog.show(context, (newDialog, which) -> taskThread.start(), true);
} }
} }
private class AfterSave extends OnFinish { private class AfterSave extends OnFinishRunnable {
private FileOnFinish mFinish; private FileOnFinishRunnable mFinish;
public AfterSave(FileOnFinish finish, Handler handler) { AfterSave(FileOnFinishRunnable finish, Handler handler) {
super(finish, handler); super(finish, handler);
mFinish = finish; mFinish = finish;
} }
@Override @Override
public void run() { public void run() {
if ( mSuccess ) {
if ( mFinish != null ) {
mFinish.setFilename(keyfile);
}
} else {
displayMessage(context);
}
super.run(); super.run();
context.runOnUiThread(() -> {
if ( mSuccess ) {
if ( mFinish != null ) {
mFinish.setFilename(keyfile);
}
} else {
if ( mMessage != null && mMessage.length() > 0 ) {
Toast.makeText(context, mMessage, Toast.LENGTH_LONG).show();
}
}
// To remove progress task
ProgressTaskDialogFragment.stop(context);
});
} }
} }
} }

View File

@@ -24,6 +24,7 @@ import android.app.Activity;
import android.app.assist.AssistStructure; import android.app.assist.AssistStructure;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
@@ -61,8 +62,8 @@ import com.kunzisoft.keepass.compat.BackupManagerCompat;
import com.kunzisoft.keepass.compat.ClipDataCompat; import com.kunzisoft.keepass.compat.ClipDataCompat;
import com.kunzisoft.keepass.compat.EditorCompat; import com.kunzisoft.keepass.compat.EditorCompat;
import com.kunzisoft.keepass.database.Database; import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.edit.LoadDB; import com.kunzisoft.keepass.database.action.LoadDBRunnable;
import com.kunzisoft.keepass.database.edit.OnFinish; import com.kunzisoft.keepass.database.action.OnFinishRunnable;
import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper; import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper;
import com.kunzisoft.keepass.fileselect.KeyFileHelper; import com.kunzisoft.keepass.fileselect.KeyFileHelper;
import com.kunzisoft.keepass.fingerprint.FingerPrintAnimatedVector; import com.kunzisoft.keepass.fingerprint.FingerPrintAnimatedVector;
@@ -70,7 +71,8 @@ import com.kunzisoft.keepass.fingerprint.FingerPrintDialog;
import com.kunzisoft.keepass.fingerprint.FingerPrintHelper; import com.kunzisoft.keepass.fingerprint.FingerPrintHelper;
import com.kunzisoft.keepass.settings.PreferencesUtil; import com.kunzisoft.keepass.settings.PreferencesUtil;
import com.kunzisoft.keepass.stylish.StylishActivity; import com.kunzisoft.keepass.stylish.StylishActivity;
import com.kunzisoft.keepass.tasks.ProgressTask; import com.kunzisoft.keepass.tasks.ProgressTaskDialogFragment;
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
import com.kunzisoft.keepass.utils.EmptyUtils; import com.kunzisoft.keepass.utils.EmptyUtils;
import com.kunzisoft.keepass.utils.MenuUtil; import com.kunzisoft.keepass.utils.MenuUtil;
import com.kunzisoft.keepass.utils.UriUtil; import com.kunzisoft.keepass.utils.UriUtil;
@@ -289,6 +291,7 @@ public class PasswordActivity extends StylishActivity
fingerprintTextView = findViewById(R.id.fingerprint_label); fingerprintTextView = findViewById(R.id.fingerprint_label);
fingerprintImageView = findViewById(R.id.fingerprint_image); fingerprintImageView = findViewById(R.id.fingerprint_image);
initForFingerprint(); initForFingerprint();
// Init the fingerprint animation
fingerPrintAnimatedVector = new FingerPrintAnimatedVector(this, fingerPrintAnimatedVector = new FingerPrintAnimatedVector(this,
fingerprintImageView); fingerprintImageView);
} }
@@ -320,6 +323,19 @@ public class PasswordActivity extends StylishActivity
// For check shutdown // For check shutdown
super.onResume(); super.onResume();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Check if fingerprint well init (be called the first time the fingerprint is configured
// and the activity still active)
if (fingerPrintHelper == null || !fingerPrintHelper.isFingerprintInitialized()) {
initForFingerprint();
}
// Start the animation in all cases
if (fingerPrintAnimatedVector != null) {
fingerPrintAnimatedVector.startScan();
}
}
new UriIntentInitTask(this, mRememberKeyfile) new UriIntentInitTask(this, mRememberKeyfile)
.execute(getIntent()); .execute(getIntent());
} }
@@ -337,6 +353,7 @@ public class PasswordActivity extends StylishActivity
getString(R.string.education_unlock_summary)) getString(R.string.education_unlock_summary))
.dimColor(R.color.green) .dimColor(R.color.green)
.icon(ContextCompat.getDrawable(this, R.mipmap.ic_launcher_round)) .icon(ContextCompat.getDrawable(this, R.mipmap.ic_launcher_round))
.textColorInt(Color.WHITE)
.tintTarget(false) .tintTarget(false)
.cancelable(true), .cancelable(true),
new TapTargetView.Listener() { new TapTargetView.Listener() {
@@ -369,6 +386,7 @@ public class PasswordActivity extends StylishActivity
TapTarget.forView(fingerprintImageView, TapTarget.forView(fingerprintImageView,
getString(R.string.education_fingerprint_title), getString(R.string.education_fingerprint_title),
getString(R.string.education_fingerprint_summary)) getString(R.string.education_fingerprint_summary))
.textColorInt(Color.WHITE)
.tintTarget(false) .tintTarget(false)
.cancelable(true), .cancelable(true),
new TapTargetView.Listener() { new TapTargetView.Listener() {
@@ -427,9 +445,6 @@ public class PasswordActivity extends StylishActivity
// checks if fingerprint is available, will also start listening for fingerprints when available // checks if fingerprint is available, will also start listening for fingerprints when available
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
checkFingerprintAvailability(); checkFingerprintAvailability();
if (fingerPrintAnimatedVector != null) {
fingerPrintAnimatedVector.startScan();
}
} }
// If Activity is launch with a password and want to open directly // If Activity is launch with a password and want to open directly
@@ -483,32 +498,18 @@ public class PasswordActivity extends StylishActivity
fingerPrintHelper = new FingerPrintHelper(this, this); fingerPrintHelper = new FingerPrintHelper(this, this);
// when text entered we can enable the logon/purchase button and if required update encryption/decryption mode checkboxPasswordView.setOnCheckedChangeListener((compoundButton, checked) -> {
passwordView.addTextChangedListener(new TextWatcher() { if ( !fingerprintMustBeConfigured ) {
@Override // encrypt or decrypt mode based on how much input or not
public void beforeTextChanged( if (checked) {
final CharSequence s, toggleFingerprintMode(FingerPrintHelper.Mode.STORE_MODE);
final int start, } else {
final int count, if (!prefsNoBackup.contains(getPreferenceKeyValue())) {
final int after) {} // This happens when no fingerprints are registered.
toggleFingerprintMode(FingerPrintHelper.Mode.WAITING_PASSWORD_MODE);
@Override } else {
public void onTextChanged(
final CharSequence s,
final int start,
final int before,
final int count) {}
@Override
public void afterTextChanged(final Editable s) {
if ( !fingerprintMustBeConfigured ) {
final boolean validInput = s.length() > 0;
// encrypt or decrypt mode based on how much input or not
setFingerPrintView(validInput ? R.string.store_with_fingerprint : R.string.scanning_fingerprint);
if (validInput)
toggleFingerprintMode(FingerPrintHelper.Mode.STORE_MODE);
else
toggleFingerprintMode(FingerPrintHelper.Mode.OPEN_MODE); toggleFingerprintMode(FingerPrintHelper.Mode.OPEN_MODE);
}
} }
} }
}); });
@@ -593,8 +594,25 @@ public class PasswordActivity extends StylishActivity
} }
} }
@RequiresApi(api = Build.VERSION_CODES.M)
private void initWaitData() {
setFingerPrintView(R.string.no_password_stored, true);
fingerPrintMode = FingerPrintHelper.Mode.WAITING_PASSWORD_MODE;
}
@RequiresApi(api = Build.VERSION_CODES.M) @RequiresApi(api = Build.VERSION_CODES.M)
private synchronized void toggleFingerprintMode(final FingerPrintHelper.Mode newMode) { private synchronized void toggleFingerprintMode(final FingerPrintHelper.Mode newMode) {
switch (newMode) {
case WAITING_PASSWORD_MODE:
setFingerPrintView(R.string.no_password_stored, true);
break;
case STORE_MODE:
setFingerPrintView(R.string.store_with_fingerprint);
break;
case OPEN_MODE:
setFingerPrintView(R.string.scanning_fingerprint);
break;
}
if( !newMode.equals(fingerPrintMode) ) { if( !newMode.equals(fingerPrintMode) ) {
fingerPrintMode = newMode; fingerPrintMode = newMode;
reInitWithFingerprintMode(); reInitWithFingerprintMode();
@@ -607,6 +625,9 @@ public class PasswordActivity extends StylishActivity
case STORE_MODE: case STORE_MODE:
initEncryptData(); initEncryptData();
break; break;
case WAITING_PASSWORD_MODE:
initWaitData();
break;
case OPEN_MODE: case OPEN_MODE:
initDecryptData(); initDecryptData();
break; break;
@@ -638,10 +659,6 @@ public class PasswordActivity extends StylishActivity
setFingerPrintView(textId, false); setFingerPrintView(textId, false);
} }
private void setFingerPrintView(final CharSequence text) {
setFingerPrintView(text, false);
}
private void setFingerPrintView(final int textId, boolean lock) { private void setFingerPrintView(final int textId, boolean lock) {
setFingerPrintView(getString(textId), lock); setFingerPrintView(getString(textId), lock);
} }
@@ -649,7 +666,7 @@ public class PasswordActivity extends StylishActivity
private void setFingerPrintView(final CharSequence text, boolean lock) { private void setFingerPrintView(final CharSequence text, boolean lock) {
runOnUiThread(() -> { runOnUiThread(() -> {
if (lock) { if (lock) {
fingerprintContainerView.setAlpha(0.6f); fingerprintContainerView.setAlpha(0.8f);
} else } else
fingerprintContainerView.setAlpha(1f); fingerprintContainerView.setAlpha(1f);
fingerprintTextView.setText(text); fingerprintTextView.setText(text);
@@ -683,9 +700,13 @@ public class PasswordActivity extends StylishActivity
// fingerprint available but no stored password found yet for this DB so show info don't listen // fingerprint available but no stored password found yet for this DB so show info don't listen
if (!prefsNoBackup.contains(getPreferenceKeyValue())) { if (!prefsNoBackup.contains(getPreferenceKeyValue())) {
setFingerPrintView(R.string.no_password_stored); if (checkboxPasswordView.isChecked()) {
// listen for encryption // listen for encryption
initEncryptData(); initEncryptData();
} else {
// wait for typing
initWaitData();
}
} }
// all is set here so we can confirm to user and start listening for fingerprints // all is set here so we can confirm to user and start listening for fingerprints
else { else {
@@ -734,7 +755,9 @@ public class PasswordActivity extends StylishActivity
@RequiresApi(api = Build.VERSION_CODES.M) @RequiresApi(api = Build.VERSION_CODES.M)
@Override @Override
public void onFingerPrintException(Exception e) { public void onFingerPrintException(Exception e) {
showError(getString(R.string.fingerprint_error, e.getMessage())); // Don't show error here;
// showError(getString(R.string.fingerprint_error, e.getMessage()));
// Can be uninit in Activity and init in fragment
setFingerPrintView(e.getLocalizedMessage(), true); setFingerPrintView(e.getLocalizedMessage(), true);
} }
@@ -805,20 +828,86 @@ public class PasswordActivity extends StylishActivity
loadDatabase(password, keyUri); loadDatabase(password, keyUri);
} }
private void loadDatabase(String pass, Uri keyfile) { private void loadDatabase(String password, Uri keyfile) {
// Clear before we load // Clear before we load
Database db = App.getDB(); Database database = App.getDB();
db.clear(); database.clear();
// Clear the shutdown flag // Clear the shutdown flag
App.clearShutdown(); App.clearShutdown();
// Show the progress dialog
Handler handler = new Handler(); Handler handler = new Handler();
AfterLoad afterLoad = new AfterLoad(handler, db); AfterLoadingDatabase afterLoad = new AfterLoadingDatabase(handler, database);
LoadDBRunnable databaseLoadingTask = new LoadDBRunnable(
database,
PasswordActivity.this,
mDbUri,
password,
keyfile,
afterLoad);
databaseLoadingTask.setUpdateProgressTaskStatus(
new UpdateProgressTaskStatus(this,
handler,
ProgressTaskDialogFragment.start(
getSupportFragmentManager(),
R.string.loading_database)
));
Thread t = new Thread(databaseLoadingTask);
t.start();
}
LoadDB task = new LoadDB(db, PasswordActivity.this, mDbUri, pass, keyfile, afterLoad); /**
ProgressTask pt = new ProgressTask(PasswordActivity.this, task, R.string.loading_database); * Called after verify and try to opening the database
pt.run(); */
private final class AfterLoadingDatabase extends OnFinishRunnable {
protected Database db;
AfterLoadingDatabase(
Handler handler,
Database db) {
super(handler);
this.db = db;
}
@Override
public void run() {
runOnUiThread(() -> {
// Recheck fingerprint if error
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Stay with the same mode
reInitWithFingerprintMode();
}
if (db.isPasswordEncodingError()) {
PasswordEncodingDialogHelper dialog = new PasswordEncodingDialogHelper();
dialog.show(PasswordActivity.this, (dialog1, which) -> launchGroupActivity());
} else if (mSuccess) {
launchGroupActivity();
} else {
if ( mMessage != null && mMessage.length() > 0 ) {
Toast.makeText(PasswordActivity.this, mMessage, Toast.LENGTH_LONG).show();
}
}
// To remove progress task
ProgressTaskDialogFragment.stop(PasswordActivity.this);
});
}
}
private void launchGroupActivity() {
AssistStructure assistStructure = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
assistStructure = autofillHelper.getAssistStructure();
if (assistStructure != null) {
GroupActivity.launch(PasswordActivity.this, assistStructure);
}
}
if (assistStructure == null) {
GroupActivity.launch(PasswordActivity.this);
}
} }
@Override @Override
@@ -860,54 +949,6 @@ public class PasswordActivity extends StylishActivity
PasswordActivityPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults); PasswordActivityPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults);
} }
/**
* Called after verify and try to opening the database
*/
private final class AfterLoad extends OnFinish {
protected Database db;
AfterLoad(
Handler handler,
Database db) {
super(handler);
this.db = db;
}
@Override
public void run() {
// Recheck fingerprint if error
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Stay with the same mode
reInitWithFingerprintMode();
}
if (db.isPasswordEncodingError()) {
PasswordEncodingDialogHelper dialog = new PasswordEncodingDialogHelper();
dialog.show(PasswordActivity.this, (dialog1, which) -> launchGroupActivity());
} else if (mSuccess) {
launchGroupActivity();
} else {
displayMessage(PasswordActivity.this);
}
}
}
private void launchGroupActivity() {
AssistStructure assistStructure = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
assistStructure = autofillHelper.getAssistStructure();
if (assistStructure != null) {
GroupActivity.launch(PasswordActivity.this, assistStructure);
}
}
if (assistStructure == null) {
GroupActivity.launch(PasswordActivity.this);
}
}
private static class UriIntentInitTask extends AsyncTask<Intent, Void, Integer> { private static class UriIntentInitTask extends AsyncTask<Intent, Void, Integer> {
static final String KEY_FILENAME = "fileName"; static final String KEY_FILENAME = "fileName";

View File

@@ -86,7 +86,7 @@ public class SearchResultsActivity extends ListNodesActivity {
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
MenuUtil.donationMenuInflater(inflater, menu); MenuUtil.contributionMenuInflater(inflater, menu);
inflater.inflate(R.menu.tree, menu); inflater.inflate(R.menu.tree, menu);
inflater.inflate(R.menu.default_menu, menu); inflater.inflate(R.menu.default_menu, menu);

View File

@@ -29,7 +29,7 @@ import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.app.App; import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.database.Database; import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.settings.preferenceDialogFragment.RoundsFixPreferenceDialogFragmentCompat; import com.kunzisoft.keepass.settings.preferenceDialogFragment.RoundsFixPreferenceDialogFragmentCompat;
import com.kunzisoft.keepass.settings.preference.RoundsPreference; import com.kunzisoft.keepass.settings.preference.InputNumberPreference;
public class MainPreferenceFragment extends PreferenceFragmentCompat implements Preference.OnPreferenceClickListener { public class MainPreferenceFragment extends PreferenceFragmentCompat implements Preference.OnPreferenceClickListener {
@@ -71,7 +71,7 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat implements
@Override @Override
public void onDisplayPreferenceDialog(Preference preference) { public void onDisplayPreferenceDialog(Preference preference) {
// Try if the preference is one of our custom Preferences // Try if the preference is one of our custom Preferences
if (preference instanceof RoundsPreference) { if (preference instanceof InputNumberPreference) {
assert getFragmentManager() != null; assert getFragmentManager() != null;
DialogFragment dialogFragment = RoundsFixPreferenceDialogFragmentCompat.newInstance(preference.getKey()); DialogFragment dialogFragment = RoundsFixPreferenceDialogFragmentCompat.newInstance(preference.getKey());
dialogFragment.setTargetFragment(this, 0); dialogFragment.setTargetFragment(this, 0);

View File

@@ -51,8 +51,12 @@ import com.kunzisoft.keepass.dialogs.UnavailableFeatureDialogFragment;
import com.kunzisoft.keepass.dialogs.UnderDevelopmentFeatureDialogFragment; import com.kunzisoft.keepass.dialogs.UnderDevelopmentFeatureDialogFragment;
import com.kunzisoft.keepass.fingerprint.FingerPrintHelper; import com.kunzisoft.keepass.fingerprint.FingerPrintHelper;
import com.kunzisoft.keepass.icons.IconPackChooser; import com.kunzisoft.keepass.icons.IconPackChooser;
import com.kunzisoft.keepass.settings.preferenceDialogFragment.DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat;
import com.kunzisoft.keepass.settings.preferenceDialogFragment.DatabaseDescriptionPreferenceDialogFragmentCompat; import com.kunzisoft.keepass.settings.preferenceDialogFragment.DatabaseDescriptionPreferenceDialogFragmentCompat;
import com.kunzisoft.keepass.settings.preferenceDialogFragment.DatabaseKeyDerivationPreferenceDialogFragmentCompat;
import com.kunzisoft.keepass.settings.preferenceDialogFragment.DatabaseNamePreferenceDialogFragmentCompat; import com.kunzisoft.keepass.settings.preferenceDialogFragment.DatabaseNamePreferenceDialogFragmentCompat;
import com.kunzisoft.keepass.settings.preferenceDialogFragment.MemoryUsagePreferenceDialogFragmentCompat;
import com.kunzisoft.keepass.settings.preferenceDialogFragment.ParallelismPreferenceDialogFragmentCompat;
import com.kunzisoft.keepass.settings.preferenceDialogFragment.RoundsPreferenceDialogFragmentCompat; import com.kunzisoft.keepass.settings.preferenceDialogFragment.RoundsPreferenceDialogFragmentCompat;
import com.kunzisoft.keepass.stylish.Stylish; import com.kunzisoft.keepass.stylish.Stylish;
@@ -69,6 +73,10 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat
private int count = 0; private int count = 0;
private Preference roundPref;
private Preference memoryPref;
private Preference parallelismPref;
public static NestedSettingsFragment newInstance(Screen key) { public static NestedSettingsFragment newInstance(Screen key) {
NestedSettingsFragment fragment = new NestedSettingsFragment(); NestedSettingsFragment fragment = new NestedSettingsFragment();
// supply arguments to bundle. // supply arguments to bundle.
@@ -317,17 +325,23 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat
// Encryption Algorithm // Encryption Algorithm
Preference algorithmPref = findPreference(getString(R.string.encryption_algorithm_key)); Preference algorithmPref = findPreference(getString(R.string.encryption_algorithm_key));
algorithmPref.setSummary(db.getEncryptionAlgorithmName(getResources())); algorithmPref.setSummary(db.getEncryptionAlgorithmName(getResources()));
preferenceInDevelopment(algorithmPref);
// Key derivation function // Key derivation function
Preference kdfPref = findPreference(getString(R.string.key_derivation_function_key)); Preference kdfPref = findPreference(getString(R.string.key_derivation_function_key));
kdfPref.setSummary(db.getKeyDerivationName()); kdfPref.setSummary(db.getKeyDerivationName(getResources()));
preferenceInDevelopment(kdfPref);
// Round encryption // Round encryption
Preference roundPref = findPreference(getString(R.string.transform_rounds_key)); roundPref = findPreference(getString(R.string.transform_rounds_key));
roundPref.setSummary(db.getNumberKeyEncryptionRoundsAsString()); roundPref.setSummary(db.getNumberKeyEncryptionRoundsAsString());
// Memory Usage
memoryPref = findPreference(getString(R.string.memory_usage_key));
memoryPref.setSummary(db.getMemoryUsageAsString());
// Parallelism
parallelismPref = findPreference(getString(R.string.parallelism_key));
parallelismPref.setSummary(db.getParallelismAsString());
} else { } else {
Log.e(getClass().getName(), "Database isn't ready"); Log.e(getClass().getName(), "Database isn't ready");
} }
@@ -402,7 +416,7 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat
assert fragmentManager != null; assert fragmentManager != null;
try { // don't check if we can try { // don't check if we can
((SwitchPreference) preference).setChecked(false); ((SwitchPreference) preference).setChecked(false);
} catch (Exception e) {} } catch (Exception ignored) {}
new UnderDevelopmentFeatureDialogFragment().show(getFragmentManager(), "underDevFeatureDialog"); new UnderDevelopmentFeatureDialogFragment().show(getFragmentManager(), "underDevFeatureDialog");
return false; return false;
}); });
@@ -428,12 +442,32 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat
if (preference.getKey().equals(getString(R.string.database_name_key))) { if (preference.getKey().equals(getString(R.string.database_name_key))) {
dialogFragment = DatabaseNamePreferenceDialogFragmentCompat.newInstance(preference.getKey()); dialogFragment = DatabaseNamePreferenceDialogFragmentCompat.newInstance(preference.getKey());
} }
if (preference.getKey().equals(getString(R.string.database_description_key))) { else if (preference.getKey().equals(getString(R.string.database_description_key))) {
dialogFragment = DatabaseDescriptionPreferenceDialogFragmentCompat.newInstance(preference.getKey()); dialogFragment = DatabaseDescriptionPreferenceDialogFragmentCompat.newInstance(preference.getKey());
} }
if (preference.getKey().equals(getString(R.string.transform_rounds_key))) { else if (preference.getKey().equals(getString(R.string.encryption_algorithm_key))) {
dialogFragment = DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat.newInstance(preference.getKey());
}
else if (preference.getKey().equals(getString(R.string.key_derivation_function_key))) {
DatabaseKeyDerivationPreferenceDialogFragmentCompat keyDerivationDialogFragment = DatabaseKeyDerivationPreferenceDialogFragmentCompat.newInstance(preference.getKey());
// Add other prefs to manage
if (roundPref != null)
keyDerivationDialogFragment.setRoundPreference(roundPref);
if (memoryPref != null)
keyDerivationDialogFragment.setMemoryPreference(memoryPref);
if (parallelismPref != null)
keyDerivationDialogFragment.setParallelismPreference(parallelismPref);
dialogFragment = keyDerivationDialogFragment;
}
else if (preference.getKey().equals(getString(R.string.transform_rounds_key))) {
dialogFragment = RoundsPreferenceDialogFragmentCompat.newInstance(preference.getKey()); dialogFragment = RoundsPreferenceDialogFragmentCompat.newInstance(preference.getKey());
} }
else if (preference.getKey().equals(getString(R.string.memory_usage_key))) {
dialogFragment = MemoryUsagePreferenceDialogFragmentCompat.newInstance(preference.getKey());
}
else if (preference.getKey().equals(getString(R.string.parallelism_key))) {
dialogFragment = ParallelismPreferenceDialogFragmentCompat.newInstance(preference.getKey());
}
if (dialogFragment != null) { if (dialogFragment != null) {
dialogFragment.setTargetFragment(this, 0); dialogFragment.setTargetFragment(this, 0);

View File

@@ -0,0 +1,31 @@
package com.kunzisoft.keepass.settings.preference;
import android.content.Context;
import android.support.v7.preference.DialogPreference;
import android.util.AttributeSet;
import com.kunzisoft.keepass.R;
public class DialogListExplanationPreference extends DialogPreference {
public DialogListExplanationPreference(Context context) {
this(context, null);
}
public DialogListExplanationPreference(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.dialogPreferenceStyle);
}
public DialogListExplanationPreference(Context context, AttributeSet attrs, int defStyleAttr) {
this(context, attrs, defStyleAttr, defStyleAttr);
}
public DialogListExplanationPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public int getDialogLayoutResource() {
return R.layout.pref_dialog_list_explanation;
}
}

View File

@@ -24,40 +24,54 @@ import android.content.res.TypedArray;
import android.util.AttributeSet; import android.util.AttributeSet;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
public class RoundsPreference extends InputTextExplanationPreference { public class InputNumberPreference extends InputTextExplanationPreference {
private long mRounds; private long mNumber;
public RoundsPreference(Context context) { public InputNumberPreference(Context context) {
this(context, null); this(context, null);
} }
public RoundsPreference(Context context, AttributeSet attrs) { public InputNumberPreference(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.dialogPreferenceStyle); this(context, attrs, R.attr.dialogPreferenceStyle);
} }
public RoundsPreference(Context context, AttributeSet attrs, int defStyleAttr) { public InputNumberPreference(Context context, AttributeSet attrs, int defStyleAttr) {
this(context, attrs, defStyleAttr, defStyleAttr); this(context, attrs, defStyleAttr, defStyleAttr);
} }
public RoundsPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { public InputNumberPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes); super(context, attrs, defStyleAttr, defStyleRes);
} }
@Override @Override
public int getDialogLayoutResource() { public int getDialogLayoutResource() {
return R.layout.pref_dialog_rounds; return R.layout.pref_dialog_numbers;
} }
public long getRounds() { public long getNumber() {
return mRounds; return mNumber;
} }
public void setRounds(long rounds) { public void setNumber(long number) {
this.mRounds = rounds; this.mNumber = number;
// Save to Shared Preferences // Save to Shared Preferences
persistLong(rounds); persistLong(number);
}
@Override
public void setSummary(CharSequence summary) {
if (summary.equals(KdfEngine.UNKNOW_VALUE_STRING)) {
setEnabled(false);
super.setSummary("");
}
else {
setEnabled(true);
super.setSummary(summary);
}
} }
@Override @Override
@@ -69,25 +83,25 @@ public class RoundsPreference extends InputTextExplanationPreference {
protected void onSetInitialValue(boolean restorePersistedValue, protected void onSetInitialValue(boolean restorePersistedValue,
Object defaultValue) { Object defaultValue) {
// Read the value. Use the default value if it is not possible. // Read the value. Use the default value if it is not possible.
long rounds; long number;
if (!restorePersistedValue) { if (!restorePersistedValue) {
rounds = 100000; number = 100000;
if (defaultValue instanceof String) { if (defaultValue instanceof String) {
rounds = Long.parseLong((String) defaultValue); number = Long.parseLong((String) defaultValue);
} }
if (defaultValue instanceof Integer) { if (defaultValue instanceof Integer) {
rounds = (Integer) defaultValue; number = (Integer) defaultValue;
} }
try { try {
rounds = (long) defaultValue; number = (long) defaultValue;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} else { } else {
rounds = getPersistedLong(mRounds); number = getPersistedLong(mNumber);
} }
setRounds(rounds); setNumber(number);
} }
} }

View File

@@ -1,13 +1,33 @@
/*
* Copyright 2018 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.settings.preferenceDialogFragment; package com.kunzisoft.keepass.settings.preferenceDialogFragment;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View; import android.view.View;
import com.kunzisoft.keepass.database.edit.OnFinish; import com.kunzisoft.keepass.database.action.OnFinishRunnable;
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
public class DatabaseDescriptionPreferenceDialogFragmentCompat extends DatabaseSavePreferenceDialogFragmentCompat { public class DatabaseDescriptionPreferenceDialogFragmentCompat extends InputDatabaseSavePreferenceDialogFragmentCompat {
public static DatabaseDescriptionPreferenceDialogFragmentCompat newInstance( public static DatabaseDescriptionPreferenceDialogFragmentCompat newInstance(
String key) { String key) {
@@ -32,43 +52,47 @@ public class DatabaseDescriptionPreferenceDialogFragmentCompat extends DatabaseS
if ( positiveResult ) { if ( positiveResult ) {
assert getContext() != null; assert getContext() != null;
String dbDescription = getInputText(); String newDescription = getInputText();
String oldDescription = database.getDescription(); String oldDescription = database.getDescription();
database.assignDescription(dbDescription); database.assignDescription(newDescription);
Handler handler = new Handler(); Handler handler = new Handler();
setAfterSaveDatabase(new AfterDescriptionSave(getContext(), handler, dbDescription, oldDescription)); setAfterSaveDatabase(new AfterDescriptionSave((AppCompatActivity) getActivity(), handler, newDescription, oldDescription));
} }
super.onDialogClosed(positiveResult); super.onDialogClosed(positiveResult);
} }
private class AfterDescriptionSave extends OnFinish { private class AfterDescriptionSave extends OnFinishRunnable {
private AppCompatActivity mActivity;
private String mNewDescription; private String mNewDescription;
private String mOldDescription; private String mOldDescription;
private Context mCtx;
AfterDescriptionSave(Context ctx, Handler handler, String newDescription, String oldDescription) { AfterDescriptionSave(AppCompatActivity ctx, Handler handler, String newDescription, String oldDescription) {
super(handler); super(handler);
mCtx = ctx; mActivity = ctx;
mNewDescription = newDescription; mNewDescription = newDescription;
mOldDescription = oldDescription; mOldDescription = oldDescription;
} }
@Override @Override
public void run() { public void run() {
String descriptionToShow = mNewDescription; if (mActivity != null) {
mActivity.runOnUiThread(() -> {
String descriptionToShow = mNewDescription;
if (!mSuccess) { if (!mSuccess) {
displayMessage(mCtx); displayMessage(mActivity);
database.assignDescription(mOldDescription); database.assignDescription(mOldDescription);
database.assignDescription(mOldDescription); }
getPreference().setSummary(descriptionToShow);
SaveDatabaseProgressTaskDialogFragment.stop(mActivity);
});
} }
getPreference().setSummary(descriptionToShow);
super.run(); super.run();
} }
} }

View File

@@ -0,0 +1,123 @@
/*
* Copyright 2018 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.settings.preferenceDialogFragment;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.database.PwEncryptionAlgorithm;
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
import com.kunzisoft.keepass.settings.preferenceDialogFragment.adapter.ListRadioItemAdapter;
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
public class DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat extends DatabaseSavePreferenceDialogFragmentCompat
implements ListRadioItemAdapter.RadioItemSelectedCallback<PwEncryptionAlgorithm> {
private PwEncryptionAlgorithm algorithmSelected;
public static DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat newInstance(
String key) {
final DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat
fragment = new DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat();
final Bundle b = new Bundle(1);
b.putString(ARG_KEY, key);
fragment.setArguments(b);
return fragment;
}
@Override
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
setExplanationText(R.string.encryption_explanation);
RecyclerView recyclerView = view.findViewById(R.id.pref_dialog_list);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
ListRadioItemAdapter<PwEncryptionAlgorithm> encryptionAlgorithmAdapter = new ListRadioItemAdapter<>(getActivity());
encryptionAlgorithmAdapter.setRadioItemSelectedCallback(this);
recyclerView.setAdapter(encryptionAlgorithmAdapter);
algorithmSelected = database.getEncryptionAlgorithm();
encryptionAlgorithmAdapter.setItems(database.getAvailableEncryptionAlgorithms(), algorithmSelected);
}
@Override
public void onDialogClosed(boolean positiveResult) {
if ( positiveResult
&& database.allowEncryptionAlgorithmModification()) {
assert getContext() != null;
if (algorithmSelected != null) {
PwEncryptionAlgorithm newAlgorithm = algorithmSelected;
PwEncryptionAlgorithm oldAlgorithm = database.getEncryptionAlgorithm();
database.assignEncryptionAlgorithm(newAlgorithm);
Handler handler = new Handler();
setAfterSaveDatabase(new AfterDescriptionSave((AppCompatActivity) getActivity(), handler, newAlgorithm, oldAlgorithm));
}
}
super.onDialogClosed(positiveResult);
}
@Override
public void onItemSelected(PwEncryptionAlgorithm item) {
this.algorithmSelected = item;
}
private class AfterDescriptionSave extends OnFinishRunnable {
private PwEncryptionAlgorithm mNewAlgorithm;
private PwEncryptionAlgorithm mOldAlgorithm;
private AppCompatActivity mActivity;
AfterDescriptionSave(AppCompatActivity activity, Handler handler, PwEncryptionAlgorithm newAlgorithm, PwEncryptionAlgorithm oldAlgorithm) {
super(handler);
mActivity = activity;
mNewAlgorithm = newAlgorithm;
mOldAlgorithm = oldAlgorithm;
}
@Override
public void run() {
if (mActivity != null) {
mActivity.runOnUiThread(() -> {
PwEncryptionAlgorithm algorithmToShow = mNewAlgorithm;
if (!mSuccess) {
displayMessage(mActivity);
database.assignEncryptionAlgorithm(mOldAlgorithm);
}
getPreference().setSummary(algorithmToShow.getName(mActivity.getResources()));
SaveDatabaseProgressTaskDialogFragment.stop(mActivity);
});
}
super.run();
}
}
}

View File

@@ -0,0 +1,150 @@
/*
* Copyright 2018 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.settings.preferenceDialogFragment;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.preference.Preference;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
import com.kunzisoft.keepass.settings.preferenceDialogFragment.adapter.ListRadioItemAdapter;
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
public class DatabaseKeyDerivationPreferenceDialogFragmentCompat extends DatabaseSavePreferenceDialogFragmentCompat
implements ListRadioItemAdapter.RadioItemSelectedCallback<KdfEngine> {
private KdfEngine kdfEngineSelected;
private Preference roundPreference;
private Preference memoryPreference;
private Preference parallelismPreference;
public static DatabaseKeyDerivationPreferenceDialogFragmentCompat newInstance(
String key) {
final DatabaseKeyDerivationPreferenceDialogFragmentCompat
fragment = new DatabaseKeyDerivationPreferenceDialogFragmentCompat();
final Bundle b = new Bundle(1);
b.putString(ARG_KEY, key);
fragment.setArguments(b);
return fragment;
}
@Override
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
setExplanationText(R.string.kdf_explanation);
RecyclerView recyclerView = view.findViewById(R.id.pref_dialog_list);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
ListRadioItemAdapter<KdfEngine> kdfAdapter = new ListRadioItemAdapter<>(getActivity());
kdfAdapter.setRadioItemSelectedCallback(this);
recyclerView.setAdapter(kdfAdapter);
kdfEngineSelected = database.getKdfEngine();
kdfAdapter.setItems(database.getAvailableKdfEngines(), kdfEngineSelected);
}
@Override
public void onDialogClosed(boolean positiveResult) {
if ( positiveResult
&& database.allowKdfModification()) {
assert getContext() != null;
if (kdfEngineSelected != null) {
KdfEngine newKdfEngine = kdfEngineSelected;
KdfEngine oldKdfEngine = database.getKdfEngine();
database.assignKdfEngine(newKdfEngine);
Handler handler = new Handler();
setAfterSaveDatabase(new AfterDescriptionSave((AppCompatActivity) getActivity(), handler, newKdfEngine, oldKdfEngine));
}
}
super.onDialogClosed(positiveResult);
}
public void setRoundPreference(Preference preference) {
this.roundPreference = preference;
}
public void setMemoryPreference(Preference preference) {
this.memoryPreference = preference;
}
public void setParallelismPreference(Preference preference) {
this.parallelismPreference = preference;
}
@Override
public void onItemSelected(KdfEngine item) {
kdfEngineSelected = item;
}
private class AfterDescriptionSave extends OnFinishRunnable {
private KdfEngine mNewKdfEngine;
private KdfEngine mOldKdfEngine;
private AppCompatActivity mActivity;
AfterDescriptionSave(AppCompatActivity activity, Handler handler, KdfEngine newKdfEngine, KdfEngine oldKdfEngine) {
super(handler);
this.mActivity = activity;
this.mNewKdfEngine = newKdfEngine;
this.mOldKdfEngine = oldKdfEngine;
}
@Override
public void run() {
if (mActivity != null) {
mActivity.runOnUiThread(() -> {
KdfEngine kdfEngineToShow = mNewKdfEngine;
if (!mSuccess) {
displayMessage(mActivity);
database.assignKdfEngine(mOldKdfEngine);
}
getPreference().setSummary(kdfEngineToShow.getName(mActivity.getResources()));
if (roundPreference != null)
roundPreference.setSummary(String.valueOf(kdfEngineToShow.getDefaultKeyRounds()));
// Disable memory and parallelism if not available
if (memoryPreference != null) {
memoryPreference.setSummary(String.valueOf(kdfEngineToShow.getDefaultMemoryUsage()));
}
if (parallelismPreference != null) {
parallelismPreference.setSummary(String.valueOf(kdfEngineToShow.getDefaultParallelism()));
}
SaveDatabaseProgressTaskDialogFragment.stop(mActivity);
});
}
super.run();
}
}
}

View File

@@ -1,13 +1,33 @@
/*
* Copyright 2018 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.settings.preferenceDialogFragment; package com.kunzisoft.keepass.settings.preferenceDialogFragment;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View; import android.view.View;
import com.kunzisoft.keepass.database.edit.OnFinish; import com.kunzisoft.keepass.database.action.OnFinishRunnable;
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
public class DatabaseNamePreferenceDialogFragmentCompat extends DatabaseSavePreferenceDialogFragmentCompat { public class DatabaseNamePreferenceDialogFragmentCompat extends InputDatabaseSavePreferenceDialogFragmentCompat {
public static DatabaseNamePreferenceDialogFragmentCompat newInstance( public static DatabaseNamePreferenceDialogFragmentCompat newInstance(
String key) { String key) {
@@ -32,42 +52,47 @@ public class DatabaseNamePreferenceDialogFragmentCompat extends DatabaseSavePref
if ( positiveResult ) { if ( positiveResult ) {
assert getContext() != null; assert getContext() != null;
String dbName = getInputText(); String newName = getInputText();
String oldName = database.getName(); String oldName = database.getName();
database.assignName(dbName); database.assignName(newName);
Handler handler = new Handler(); Handler handler = new Handler();
setAfterSaveDatabase(new AfterNameSave(getContext(), handler, dbName, oldName)); setAfterSaveDatabase(new AfterNameSave((AppCompatActivity) getActivity(), handler, newName, oldName));
} }
super.onDialogClosed(positiveResult); super.onDialogClosed(positiveResult);
} }
private class AfterNameSave extends OnFinish { private class AfterNameSave extends OnFinishRunnable {
private String mNewName; private String mNewName;
private String mOldName; private String mOldName;
private Context mCtx; private AppCompatActivity mActivity;
AfterNameSave(Context ctx, Handler handler, String newName, String oldName) { AfterNameSave(AppCompatActivity ctx, Handler handler, String newName, String oldName) {
super(handler); super(handler);
mCtx = ctx; mActivity = ctx;
mNewName = newName; mNewName = newName;
mOldName = oldName; mOldName = oldName;
} }
@Override @Override
public void run() { public void run() {
String nameToShow = mNewName; if (mActivity != null) {
mActivity.runOnUiThread(() -> {
String nameToShow = mNewName;
if (!mSuccess) { if (!mSuccess) {
displayMessage(mCtx); displayMessage(mActivity);
database.assignName(mOldName); database.assignName(mOldName);
}
getPreference().setSummary(nameToShow);
SaveDatabaseProgressTaskDialogFragment.stop(mActivity);
});
} }
getPreference().setSummary(nameToShow);
super.run(); super.run();
} }
} }

View File

@@ -1,41 +1,66 @@
/*
* Copyright 2018 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.settings.preferenceDialogFragment; package com.kunzisoft.keepass.settings.preferenceDialogFragment;
import android.view.View; import android.view.View;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.app.App; import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.database.Database; import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.edit.OnFinish; import com.kunzisoft.keepass.database.action.OnFinishRunnable;
import com.kunzisoft.keepass.database.edit.SaveDB; import com.kunzisoft.keepass.database.action.SaveDBRunnable;
import com.kunzisoft.keepass.tasks.ProgressTask; import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
public abstract class DatabaseSavePreferenceDialogFragmentCompat extends InputPreferenceDialogFragmentCompat { public abstract class DatabaseSavePreferenceDialogFragmentCompat extends InputPreferenceDialogFragmentCompat {
protected Database database; protected Database database;
private OnFinish afterSaveDatabase; private OnFinishRunnable afterSaveDatabase;
@Override @Override
protected void onBindDialogView(View view) { protected void onBindDialogView(View view) {
super.onBindDialogView(view); super.onBindDialogView(view);
database = App.getDB(); this.database = App.getDB();
} }
@Override @Override
public void onDialogClosed(boolean positiveResult) { public void onDialogClosed(boolean positiveResult) {
if ( positiveResult ) { if ( positiveResult ) {
assert getContext() != null; assert getActivity() != null;
if (database != null && afterSaveDatabase != null) { if (database != null && afterSaveDatabase != null) {
SaveDB save = new SaveDB(getContext(), database, afterSaveDatabase); SaveDBRunnable saveDBRunnable = new SaveDBRunnable(getContext(),
ProgressTask pt = new ProgressTask(getContext(), save, R.string.saving_database); database,
pt.run(); afterSaveDatabase);
saveDBRunnable.setUpdateProgressTaskStatus(
new UpdateProgressTaskStatus(getContext(),
SaveDatabaseProgressTaskDialogFragment.start(
getActivity().getSupportFragmentManager())
));
new Thread(saveDBRunnable).start();
} }
} }
} }
public void setAfterSaveDatabase(OnFinish afterSaveDatabase) { public void setAfterSaveDatabase(OnFinishRunnable afterSaveDatabase) {
this.afterSaveDatabase = afterSaveDatabase; this.afterSaveDatabase = afterSaveDatabase;
} }
} }

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2018 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.settings.preferenceDialogFragment;
import android.view.View;
import android.widget.EditText;
import com.kunzisoft.keepass.R;
public class InputDatabaseSavePreferenceDialogFragmentCompat extends DatabaseSavePreferenceDialogFragmentCompat {
private EditText inputTextView;
@Override
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
inputTextView = view.findViewById(R.id.input_text);
}
public String getInputText() {
return this.inputTextView.getText().toString();
}
public void setInputText(String inputText) {
if (inputTextView != null && inputText != null) {
this.inputTextView.setText(inputText);
this.inputTextView.setSelection(this.inputTextView.getText().length());
}
}
}

View File

@@ -1,34 +1,42 @@
/*
* Copyright 2018 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.settings.preferenceDialogFragment; package com.kunzisoft.keepass.settings.preferenceDialogFragment;
import android.support.annotation.StringRes;
import android.support.v7.preference.PreferenceDialogFragmentCompat; import android.support.v7.preference.PreferenceDialogFragmentCompat;
import android.view.View; import android.view.View;
import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
public abstract class InputPreferenceDialogFragmentCompat extends PreferenceDialogFragmentCompat { public abstract class InputPreferenceDialogFragmentCompat extends PreferenceDialogFragmentCompat {
private EditText inputTextView;
private TextView textExplanationView; private TextView textExplanationView;
@Override @Override
protected void onBindDialogView(View view) { protected void onBindDialogView(View view) {
super.onBindDialogView(view); super.onBindDialogView(view);
inputTextView = view.findViewById(R.id.input_text);
textExplanationView = view.findViewById(R.id.explanation_text); textExplanationView = view.findViewById(R.id.explanation_text);
} }
public String getInputText() {
return this.inputTextView.getText().toString();
}
public void setInputText(String inputText) {
this.inputTextView.setText(inputText);
this.inputTextView.setSelection(this.inputTextView.getText().length());
}
public String getExplanationText() { public String getExplanationText() {
if (textExplanationView != null) if (textExplanationView != null)
return textExplanationView.getText().toString(); return textExplanationView.getText().toString();
@@ -38,6 +46,16 @@ public abstract class InputPreferenceDialogFragmentCompat extends PreferenceDial
public void setExplanationText(String explanationText) { public void setExplanationText(String explanationText) {
if (textExplanationView != null) if (textExplanationView != null)
this.textExplanationView.setText(explanationText); if (explanationText != null && !explanationText.isEmpty()) {
textExplanationView.setText(explanationText);
textExplanationView.setVisibility(View.VISIBLE);
} else {
textExplanationView.setText(explanationText);
textExplanationView.setVisibility(View.VISIBLE);
}
}
public void setExplanationText(@StringRes int explanationTextId) {
setExplanationText(getString(explanationTextId));
} }
} }

View File

@@ -0,0 +1,114 @@
/*
* Copyright 2018 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.settings.preferenceDialogFragment;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
public class MemoryUsagePreferenceDialogFragmentCompat extends InputDatabaseSavePreferenceDialogFragmentCompat {
public static MemoryUsagePreferenceDialogFragmentCompat newInstance(
String key) {
final MemoryUsagePreferenceDialogFragmentCompat
fragment = new MemoryUsagePreferenceDialogFragmentCompat();
final Bundle b = new Bundle(1);
b.putString(ARG_KEY, key);
fragment.setArguments(b);
return fragment;
}
@Override
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
setExplanationText(R.string.memory_usage_explanation);
setInputText(database.getMemoryUsageAsString());
}
@Override
public void onDialogClosed(boolean positiveResult) {
if ( positiveResult ) {
assert getContext() != null;
long memoryUsage;
try {
String stringMemory = getInputText();
memoryUsage = Long.parseLong(stringMemory);
} catch (NumberFormatException e) {
Toast.makeText(getContext(), R.string.error_rounds_not_number, Toast.LENGTH_LONG).show(); // TODO change error
return;
}
if ( memoryUsage < 1 ) {
memoryUsage = 1;
}
long oldMemoryUsage = database.getMemoryUsage();
database.setMemoryUsage(memoryUsage);
Handler handler = new Handler();
setAfterSaveDatabase(new AfterMemorySave((AppCompatActivity) getActivity(), handler, memoryUsage, oldMemoryUsage));
}
super.onDialogClosed(positiveResult);
}
private class AfterMemorySave extends OnFinishRunnable {
private long mNewMemory;
private long mOldMemory;
private AppCompatActivity mActivity;
AfterMemorySave(AppCompatActivity ctx, Handler handler, long newMemory, long oldMemory) {
super(handler);
mActivity = ctx;
mNewMemory = newMemory;
mOldMemory = oldMemory;
}
@Override
public void run() {
if (mActivity != null) {
mActivity.runOnUiThread(() -> {
long memoryToShow = mNewMemory;
if (!mSuccess) {
displayMessage(mActivity);
database.setMemoryUsage(mOldMemory);
}
getPreference().setSummary(String.valueOf(memoryToShow));
SaveDatabaseProgressTaskDialogFragment.stop(mActivity);
});
}
super.run();
}
}
}

View File

@@ -0,0 +1,114 @@
/*
* Copyright 2018 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.settings.preferenceDialogFragment;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
public class ParallelismPreferenceDialogFragmentCompat extends InputDatabaseSavePreferenceDialogFragmentCompat {
public static ParallelismPreferenceDialogFragmentCompat newInstance(
String key) {
final ParallelismPreferenceDialogFragmentCompat
fragment = new ParallelismPreferenceDialogFragmentCompat();
final Bundle b = new Bundle(1);
b.putString(ARG_KEY, key);
fragment.setArguments(b);
return fragment;
}
@Override
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
setExplanationText(R.string.parallelism_explanation);
setInputText(database.getParallelismAsString());
}
@Override
public void onDialogClosed(boolean positiveResult) {
if ( positiveResult ) {
assert getContext() != null;
int parallelism;
try {
String stringParallelism = getInputText();
parallelism = Integer.parseInt(stringParallelism);
} catch (NumberFormatException e) {
Toast.makeText(getContext(), R.string.error_rounds_not_number, Toast.LENGTH_LONG).show(); // TODO change error
return;
}
if ( parallelism < 1 ) {
parallelism = 1;
}
int oldParallelism = database.getParallelism();
database.setParallelism(parallelism);
Handler handler = new Handler();
setAfterSaveDatabase(new AfterParallelismSave((AppCompatActivity) getActivity(), handler, parallelism, oldParallelism));
}
super.onDialogClosed(positiveResult);
}
private class AfterParallelismSave extends OnFinishRunnable {
private int mNewParallelism;
private int mOldParallelism;
private AppCompatActivity mActivity;
AfterParallelismSave(AppCompatActivity ctx, Handler handler, int newParallelism, int oldParallelism) {
super(handler);
mActivity = ctx;
mNewParallelism = newParallelism;
mOldParallelism = oldParallelism;
}
@Override
public void run() {
if (mActivity != null) {
mActivity.runOnUiThread(() -> {
int parallelismToShow = mNewParallelism;
if (!mSuccess) {
displayMessage(mActivity);
database.setParallelism(mOldParallelism);
}
getPreference().setSummary(String.valueOf(parallelismToShow));
SaveDatabaseProgressTaskDialogFragment.stop(mActivity);
});
}
super.run();
}
}
}

View File

@@ -22,13 +22,16 @@ package com.kunzisoft.keepass.settings.preferenceDialogFragment;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.preference.DialogPreference; import android.support.v7.preference.DialogPreference;
import android.view.View; import android.view.View;
import android.widget.EditText;
import android.widget.Toast; import android.widget.Toast;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.settings.preference.RoundsPreference; import com.kunzisoft.keepass.settings.preference.InputNumberPreference;
public class RoundsFixPreferenceDialogFragmentCompat extends InputPreferenceDialogFragmentCompat { public class RoundsFixPreferenceDialogFragmentCompat extends InputPreferenceDialogFragmentCompat {
private EditText inputTextView;
public static RoundsFixPreferenceDialogFragmentCompat newInstance( public static RoundsFixPreferenceDialogFragmentCompat newInstance(
String key) { String key) {
final RoundsFixPreferenceDialogFragmentCompat final RoundsFixPreferenceDialogFragmentCompat
@@ -44,10 +47,12 @@ public class RoundsFixPreferenceDialogFragmentCompat extends InputPreferenceDial
protected void onBindDialogView(View view) { protected void onBindDialogView(View view) {
super.onBindDialogView(view); super.onBindDialogView(view);
inputTextView = view.findViewById(R.id.input_text);
DialogPreference preference = getPreference(); DialogPreference preference = getPreference();
if (preference instanceof RoundsPreference) { if (preference instanceof InputNumberPreference) {
setExplanationText(((RoundsPreference) preference).getExplanation()); setExplanationText(((InputNumberPreference) preference).getExplanation());
long numRounds = ((RoundsPreference) preference).getRounds(); long numRounds = ((InputNumberPreference) preference).getNumber();
setInputText(String.valueOf(numRounds)); setInputText(String.valueOf(numRounds));
} }
} }
@@ -65,14 +70,23 @@ public class RoundsFixPreferenceDialogFragmentCompat extends InputPreferenceDial
} }
DialogPreference preference = getPreference(); DialogPreference preference = getPreference();
if (preference instanceof RoundsPreference) { if (preference instanceof InputNumberPreference) {
RoundsPreference roundsPreference = (RoundsPreference) preference; InputNumberPreference roundsPreference = (InputNumberPreference) preference;
// This allows the client to ignore the user value. // This allows the client to ignore the user value.
if (roundsPreference.callChangeListener(rounds)) { if (roundsPreference.callChangeListener(rounds)) {
// Save the value // Save the value
roundsPreference.setRounds(rounds); roundsPreference.setNumber(rounds);
} }
} }
} }
} }
public String getInputText() {
return this.inputTextView.getText().toString();
}
public void setInputText(String inputText) {
this.inputTextView.setText(inputText);
this.inputTextView.setSelection(this.inputTextView.getText().length());
}
} }

View File

@@ -19,16 +19,17 @@
*/ */
package com.kunzisoft.keepass.settings.preferenceDialogFragment; package com.kunzisoft.keepass.settings.preferenceDialogFragment;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View; import android.view.View;
import android.widget.Toast; import android.widget.Toast;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.database.edit.OnFinish; import com.kunzisoft.keepass.database.action.OnFinishRunnable;
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
public class RoundsPreferenceDialogFragmentCompat extends DatabaseSavePreferenceDialogFragmentCompat { public class RoundsPreferenceDialogFragmentCompat extends InputDatabaseSavePreferenceDialogFragmentCompat {
public static RoundsPreferenceDialogFragmentCompat newInstance( public static RoundsPreferenceDialogFragmentCompat newInstance(
String key) { String key) {
@@ -76,37 +77,42 @@ public class RoundsPreferenceDialogFragmentCompat extends DatabaseSavePreference
} }
Handler handler = new Handler(); Handler handler = new Handler();
setAfterSaveDatabase(new AfterRoundSave(getContext(), handler, rounds, oldRounds)); setAfterSaveDatabase(new AfterRoundSave((AppCompatActivity) getActivity(), handler, rounds, oldRounds));
} }
super.onDialogClosed(positiveResult); super.onDialogClosed(positiveResult);
} }
private class AfterRoundSave extends OnFinish { private class AfterRoundSave extends OnFinishRunnable {
private long mNewRounds; private long mNewRounds;
private long mOldRounds; private long mOldRounds;
private Context mCtx; private AppCompatActivity mActivity;
AfterRoundSave(Context ctx, Handler handler, long newRounds, long oldRounds) { AfterRoundSave(AppCompatActivity ctx, Handler handler, long newRounds, long oldRounds) {
super(handler); super(handler);
mCtx = ctx; mActivity = ctx;
mNewRounds = newRounds; mNewRounds = newRounds;
mOldRounds = oldRounds; mOldRounds = oldRounds;
} }
@Override @Override
public void run() { public void run() {
long roundsToShow = mNewRounds; if (mActivity != null) {
mActivity.runOnUiThread(() -> {
long roundsToShow = mNewRounds;
if (!mSuccess) { if (!mSuccess) {
displayMessage(mCtx); displayMessage(mActivity);
database.setNumberKeyEncryptionRounds(mOldRounds); database.setNumberKeyEncryptionRounds(mOldRounds);
}
getPreference().setSummary(String.valueOf(roundsToShow));
SaveDatabaseProgressTaskDialogFragment.stop(mActivity);
});
} }
getPreference().setSummary(String.valueOf(roundsToShow));
super.run(); super.run();
} }
} }

View File

@@ -0,0 +1,109 @@
/*
* Copyright 2018 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.settings.preferenceDialogFragment.adapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.database.ObjectNameResource;
import java.util.ArrayList;
import java.util.List;
public class ListRadioItemAdapter<T extends ObjectNameResource> extends RecyclerView.Adapter<ListRadioViewHolder> {
private Context context;
private LayoutInflater inflater;
private List<T> radioItemList;
private T radioItemUsed;
private RadioItemSelectedCallback<T> radioItemSelectedCallback;
public ListRadioItemAdapter(Context context) {
this.context = context;
this.inflater = LayoutInflater.from(context);
this.radioItemList = new ArrayList<>();
this.radioItemUsed = null;
}
@NonNull
@Override
public ListRadioViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.pref_dialog_list_radio_item, parent, false);
return new ListRadioViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ListRadioViewHolder holder, int position) {
T item = this.radioItemList.get(position);
holder.radioButton.setText(item.getName(context.getResources()));
if (radioItemUsed != null && radioItemUsed.equals(item))
holder.radioButton.setChecked(true);
else
holder.radioButton.setChecked(false);
holder.radioButton.setOnClickListener(new OnItemClickListener(item));
}
@Override
public int getItemCount() {
return radioItemList.size();
}
public void setItems(List<T> algorithms, T algorithmUsed) {
this.radioItemList.clear();
this.radioItemList.addAll(algorithms);
this.radioItemUsed = algorithmUsed;
}
private void setRadioItemUsed(T radioItemUsed) {
this.radioItemUsed = radioItemUsed;
}
private class OnItemClickListener implements View.OnClickListener {
private T itemClicked;
OnItemClickListener(T item) {
this.itemClicked = item;
}
@Override
public void onClick(View view) {
if (radioItemSelectedCallback != null)
radioItemSelectedCallback.onItemSelected(itemClicked);
setRadioItemUsed(itemClicked);
notifyDataSetChanged();
}
}
public void setRadioItemSelectedCallback(RadioItemSelectedCallback<T> radioItemSelectedCallback) {
this.radioItemSelectedCallback = radioItemSelectedCallback;
}
public interface RadioItemSelectedCallback<T> {
void onItemSelected(T item);
}
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2018 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.settings.preferenceDialogFragment.adapter;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.RadioButton;
import com.kunzisoft.keepass.R;
public class ListRadioViewHolder extends RecyclerView.ViewHolder {
public RadioButton radioButton;
public ListRadioViewHolder(View itemView) {
super(itemView);
radioButton = itemView.findViewById(R.id.pref_dialog_list_radio);
}
}

View File

@@ -64,6 +64,8 @@ public class Stylish {
return R.style.KeepassDXStyle_Dark; return R.style.KeepassDXStyle_Dark;
else if (themeString.equals(context.getString(R.string.list_style_name_blue))) else if (themeString.equals(context.getString(R.string.list_style_name_blue)))
return R.style.KeepassDXStyle_Blue; return R.style.KeepassDXStyle_Blue;
else if (themeString.equals(context.getString(R.string.list_style_name_red)))
return R.style.KeepassDXStyle_Red;
else if (themeString.equals(context.getString(R.string.list_style_name_purple))) else if (themeString.equals(context.getString(R.string.list_style_name_purple)))
return R.style.KeepassDXStyle_Purple; return R.style.KeepassDXStyle_Purple;

View File

@@ -1,92 +0,0 @@
/*
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.tasks;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Handler;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.database.edit.OnFinish;
import com.kunzisoft.keepass.database.edit.RunnableOnFinish;
/** Designed to Pop up a progress dialog, run a thread in the background,
* run cleanup in the current thread, close the dialog. Without blocking
* the current thread.
*
* @author bpellin
*
*/
public class ProgressTask implements Runnable {
private Context mCtx;
private Handler mHandler;
private RunnableOnFinish mTask;
private ProgressDialog mPd;
public ProgressTask(Context ctx, RunnableOnFinish task, int messageId) {
mCtx = ctx;
mTask = task;
mHandler = new Handler();
// Show process dialog
mPd = new ProgressDialog(mCtx);
mPd.setCanceledOnTouchOutside(false);
mPd.setTitle(ctx.getText(R.string.progress_title));
mPd.setMessage(ctx.getText(messageId));
// Set code to run when this is finished
mTask.setStatus(new UpdateStatus(ctx, mHandler, mPd));
mTask.mFinish = new AfterTask(task.mFinish, mHandler);
}
public void run() {
// Show process dialog
mPd.show();
// Start Thread to Run task
Thread t = new Thread(mTask);
t.start();
}
private class AfterTask extends OnFinish {
public AfterTask(OnFinish finish, Handler handler) {
super(finish, handler);
}
@Override
public void run() {
super.run();
// Remove the progress dialog
mHandler.post(new CloseProcessDialog());
}
}
private class CloseProcessDialog implements Runnable {
public void run() {
if (mPd != null && mPd.isShowing()) {
mPd.dismiss();
}
}
}
}

View File

@@ -0,0 +1,129 @@
/*
* Copyright 2018 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.tasks;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.utils.Util;
public class ProgressTaskDialogFragment extends DialogFragment implements ProgressTaskUpdater{
public static final String PROGRESS_TASK_DIALOG_TAG = "progressDialogFragment";
private static final int UNDEFINED = -1;
private @StringRes int title = UNDEFINED;
private @StringRes int message = UNDEFINED;
private TextView titleView;
private TextView messageView;
private ProgressBar progressView;
public static ProgressTaskDialogFragment start(FragmentManager fragmentManager, @StringRes int titleId) {
// Create an instance of the dialog fragment and show it
ProgressTaskDialogFragment dialog = new ProgressTaskDialogFragment();
dialog.updateTitle(titleId);
dialog.show(fragmentManager, PROGRESS_TASK_DIALOG_TAG);
return dialog;
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
assert getActivity() != null;
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
@SuppressLint("InflateParams")
View root = inflater.inflate(R.layout.progress_dialog, null);
builder.setView(root);
titleView = root.findViewById(R.id.progress_dialog_title);
messageView = root.findViewById(R.id.progress_dialog_message);
progressView = root.findViewById(R.id.progress_dialog_bar);
updateTitle(title);
updateMessage(message);
setCancelable(false);
Util.lockScreenOrientation(getActivity());
return builder.create();
}
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
Util.unlockScreenOrientation(getActivity());
}
public static void stop(AppCompatActivity activity) {
Fragment fragmentTask = activity.getSupportFragmentManager().findFragmentByTag(PROGRESS_TASK_DIALOG_TAG);
if (fragmentTask != null) {
ProgressTaskDialogFragment loadingDatabaseDialog = (ProgressTaskDialogFragment) fragmentTask;
loadingDatabaseDialog.dismissAllowingStateLoss();
Util.unlockScreenOrientation(activity);
}
}
public void setTitle(@StringRes int titleId) {
this.title = titleId;
}
private void updateView(TextView textView, @StringRes int resId) {
if (textView != null) {
if (resId == UNDEFINED) {
textView.setVisibility(View.GONE);
} else {
textView.setText(resId);
textView.setVisibility(View.VISIBLE);
}
}
}
public void updateTitle(int resId) {
this.title = resId;
updateView(titleView, title);
}
@Override
public void updateMessage(int resId) {
this.message = resId;
updateView(messageView, message);
}
}

View File

@@ -0,0 +1,24 @@
/*
* Copyright 2018 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.tasks;
public interface ProgressTaskUpdater {
void updateMessage(int resId);
}

View File

@@ -0,0 +1,16 @@
package com.kunzisoft.keepass.tasks;
import android.support.v4.app.FragmentManager;
import com.kunzisoft.keepass.R;
public class SaveDatabaseProgressTaskDialogFragment extends ProgressTaskDialogFragment {
public static SaveDatabaseProgressTaskDialogFragment start(FragmentManager fragmentManager) {
// Create an instance of the dialog fragment and show it
SaveDatabaseProgressTaskDialogFragment dialog = new SaveDatabaseProgressTaskDialogFragment();
dialog.updateTitle(R.string.saving_database);
dialog.show(fragmentManager, PROGRESS_TASK_DIALOG_TAG);
return dialog;
}
}

View File

@@ -19,27 +19,27 @@
*/ */
package com.kunzisoft.keepass.tasks; package com.kunzisoft.keepass.tasks;
import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
import android.os.Handler; import android.os.Handler;
public class UpdateStatus { public class UpdateProgressTaskStatus implements ProgressTaskUpdater {
private ProgressDialog mPD; private Context mContext;
private Context mCtx; private ProgressTaskUpdater mProgressTaskUpdater;
private Handler mHandler; private Handler mHandler;
public UpdateStatus() { public UpdateProgressTaskStatus(Context context, ProgressTaskUpdater progressTaskUpdater) {
this(context, new Handler(), progressTaskUpdater);
} }
public UpdateStatus(Context ctx, Handler handler, ProgressDialog pd) { public UpdateProgressTaskStatus(Context context, Handler handler, ProgressTaskUpdater progressTaskUpdater) {
mCtx = ctx; this.mContext = context;
mPD = pd; this.mProgressTaskUpdater = progressTaskUpdater;
mHandler = handler; this.mHandler = handler;
} }
@Override
public void updateMessage(int resId) { public void updateMessage(int resId) {
if ( mCtx != null && mPD != null && mHandler != null ) { if ( mContext != null && mProgressTaskUpdater != null && mHandler != null ) {
mHandler.post(new UpdateMessage(resId)); mHandler.post(new UpdateMessage(resId));
} }
} }
@@ -47,13 +47,12 @@ public class UpdateStatus {
private class UpdateMessage implements Runnable { private class UpdateMessage implements Runnable {
private int mResId; private int mResId;
public UpdateMessage(int resId) { UpdateMessage(int resId) {
mResId = resId; mResId = resId;
} }
public void run() { public void run() {
mPD.setMessage(mCtx.getString(mResId)); mProgressTaskUpdater.updateMessage(mResId);
} }
} }
} }

View File

@@ -21,49 +21,33 @@ package com.kunzisoft.keepass.utils;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.Intent; import android.content.Intent;
import android.support.v7.widget.Toolbar;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.Toast; import android.widget.Toast;
import com.getkeepsafe.taptargetview.TapTarget;
import com.kunzisoft.keepass.BuildConfig; import com.kunzisoft.keepass.BuildConfig;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.activities.AboutActivity; import com.kunzisoft.keepass.activities.AboutActivity;
import com.kunzisoft.keepass.settings.SettingsActivity; import com.kunzisoft.keepass.settings.SettingsActivity;
import com.kunzisoft.keepass.stylish.StylishActivity; import com.kunzisoft.keepass.stylish.StylishActivity;
import java.util.List;
public class MenuUtil { public class MenuUtil {
public static void donationMenuInflater(MenuInflater inflater, Menu menu) { public static void contributionMenuInflater(MenuInflater inflater, Menu menu) {
if(!(BuildConfig.FULL_VERSION && BuildConfig.CLOSED_STORE)) if(!(BuildConfig.FULL_VERSION && BuildConfig.CLOSED_STORE))
inflater.inflate(R.menu.donation, menu); inflater.inflate(R.menu.contribution, menu);
}
public static void addDonationTapTargetIfAllowed(List<TapTarget> tapTargets,
Toolbar toolbar,
String title,
String summary) {
if (!(BuildConfig.FULL_VERSION && BuildConfig.CLOSED_STORE)) {
tapTargets.add(TapTarget.forToolbarMenuItem(toolbar,
R.id.menu_donate,
title,
summary));
}
} }
public static void defaultMenuInflater(MenuInflater inflater, Menu menu) { public static void defaultMenuInflater(MenuInflater inflater, Menu menu) {
donationMenuInflater(inflater, menu); contributionMenuInflater(inflater, menu);
inflater.inflate(R.menu.default_menu, menu); inflater.inflate(R.menu.default_menu, menu);
} }
public static boolean onDonationItemSelected(StylishActivity activity) { public static boolean onContributionItemSelected(StylishActivity activity) {
try { try {
Util.gotoUrl(activity, R.string.donate_url); Util.gotoUrl(activity, R.string.contribution_url);
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
Toast.makeText(activity, R.string.error_failed_to_launch_link, Toast.LENGTH_LONG).show(); Toast.makeText(activity, R.string.error_failed_to_launch_link, Toast.LENGTH_LONG).show();
return false; return false;
@@ -80,8 +64,8 @@ public class MenuUtil {
*/ */
public static boolean onDefaultMenuOptionsItemSelected(StylishActivity activity, MenuItem item, boolean checkLock) { public static boolean onDefaultMenuOptionsItemSelected(StylishActivity activity, MenuItem item, boolean checkLock) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.menu_donate: case R.id.menu_contribute:
return onDonationItemSelected(activity); return onContributionItemSelected(activity);
case R.id.menu_app_settings: case R.id.menu_app_settings:
// To avoid flickering when launch settings in a LockingActivity // To avoid flickering when launch settings in a LockingActivity

View File

@@ -19,9 +19,12 @@
*/ */
package com.kunzisoft.keepass.utils; package com.kunzisoft.keepass.utils;
import android.app.Activity;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.net.Uri; import android.net.Uri;
import android.widget.EditText; import android.widget.EditText;
@@ -70,4 +73,20 @@ public class Util {
public static void applyFontVisibilityTo(final Context context, final EditText editText) { public static void applyFontVisibilityTo(final Context context, final EditText editText) {
applyFontVisibilityTo(context, (TextView) editText); applyFontVisibilityTo(context, (TextView) editText);
} }
public static void lockScreenOrientation(Activity activity) {
if (activity != null) {
int currentOrientation = activity.getResources().getConfiguration().orientation;
if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
}
public static void unlockScreenOrientation(Activity activity) {
if (activity != null)
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
} }

View File

@@ -4,27 +4,34 @@
android:id="@+id/fingerprint_container" android:id="@+id/fingerprint_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="@dimen/default_margin"
tools:visibility="gone"> tools:visibility="gone">
<!-- added these 2 fingerprint related views --> <View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/colorPrimaryDark"/>
<android.support.v7.widget.AppCompatImageView <android.support.v7.widget.AppCompatImageView
android:id="@+id/fingerprint_image" android:id="@+id/fingerprint_image"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_margin="4dp" android:layout_marginTop="@dimen/default_margin"
android:layout_marginBottom="@dimen/default_margin"
android:layout_marginStart="4dp"
android:layout_marginEnd="@dimen/default_margin"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:elevation="4dp" android:elevation="8dp"
android:src="@drawable/fingerprint" android:src="@drawable/fingerprint"
android:background="@drawable/circle" android:background="@drawable/circle"
android:backgroundTint="?attr/colorAccent" /> android:backgroundTint="?attr/colorAccent" />
<TextView <TextView
android:id="@+id/fingerprint_label" android:id="@+id/fingerprint_label"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_marginEnd="12dp" android:layout_marginStart="24dp"
android:layout_marginEnd="18dp"
android:layout_toStartOf="@+id/fingerprint_image" android:layout_toStartOf="@+id/fingerprint_image"
style="@style/KeepassDXStyle.TextAppearance.DefaultTextOnPrimary" style="@style/KeepassDXStyle.TextAppearance.DefaultTextOnPrimary"
android:gravity="center_vertical|end" /> android:gravity="center_vertical|start" />
</RelativeLayout> </RelativeLayout>

View File

@@ -49,8 +49,8 @@
android:id="@+id/filename_input_layout" android:id="@+id/filename_input_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/file_types" android:layout_toLeftOf="@+id/container_file_type"
android:layout_toStartOf="@+id/file_types"> android:layout_toStartOf="@+id/container_file_type">
<android.support.design.widget.TextInputEditText <android.support.design.widget.TextInputEditText
android:id="@+id/filename" android:id="@+id/filename"
@@ -63,14 +63,21 @@
android:singleLine="true"/> android:singleLine="true"/>
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
<android.support.v7.widget.AppCompatSpinner <!-- To add text view for one item -->
android:id="@+id/file_types" <FrameLayout
android:id="@+id/container_file_type"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignBottom="@+id/filename_input_layout" android:layout_alignBottom="@+id/filename_input_layout"
android:layout_marginBottom="8dp"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" /> android:layout_alignParentEnd="true" >
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/file_types"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"/>
</FrameLayout>
</RelativeLayout> </RelativeLayout>
<TextView <TextView

View File

@@ -48,6 +48,18 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"> android:layout_marginTop="?attr/actionBarSize">
<android.support.v7.widget.SwitchCompat
android:id="@+id/default_database"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/KeepassDXStyle.TextAppearance.Small"
android:textColor="?android:attr/textColorHintInverse"
android:layout_marginLeft="24dp"
android:layout_marginStart="24dp"
android:layout_marginRight="12dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="6dp"
android:text="@string/default_checkbox" />
<include <include
layout="@layout/fingerprint_show" /> layout="@layout/fingerprint_show" />
</LinearLayout> </LinearLayout>
@@ -172,18 +184,6 @@
android:tint="?attr/colorAccentCompat" /> android:tint="?attr/colorAccentCompat" />
</RelativeLayout> </RelativeLayout>
<android.support.v7.widget.SwitchCompat
android:id="@+id/default_database"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/KeepassDXStyle.TextAppearance.Small"
android:layout_marginTop="24dp"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_marginRight="12dp"
android:layout_marginEnd="12dp"
android:text="@string/default_checkbox" />
</LinearLayout> </LinearLayout>
</android.support.v4.widget.NestedScrollView> </android.support.v4.widget.NestedScrollView>

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2018 Jeremy Jamet / Kunzisoft.
This file is part of KeePass DX.
KeePass DX is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
KeePass DX is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:padding="20dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:importantForAutofill="noExcludeDescendants"
tools:targetApi="o">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/explanation_text"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center"
android:layout_marginBottom="8dp"
android:visibility="gone"
style="@style/KeepassDXStyle.TextAppearance.SmallTitle"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/pref_dialog_list"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</LinearLayout>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pref_dialog_list_container"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp">
<RadioButton
android:id="@+id/pref_dialog_list_radio"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

View File

@@ -35,7 +35,6 @@
style="@style/KeepassDXStyle.TextAppearance.SmallTitle"/> style="@style/KeepassDXStyle.TextAppearance.SmallTitle"/>
<android.support.v7.widget.AppCompatEditText <android.support.v7.widget.AppCompatEditText
android:id="@+id/input_text" android:id="@+id/input_text"
android:hint="@string/rounds_hint"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:digits="0123456789" android:digits="0123456789"

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/progress_dialog_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
style="@style/KeepassDXStyle.TextAppearance.Title"
android:textColor="?android:attr/textColor"/>
<TextView
android:id="@+id/progress_dialog_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
style="@style/KeepassDXStyle.TextAppearance.SmallTitle"/>
<ProgressBar
android:id="@+id/progress_dialog_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:indeterminate="true"
android:max="100"/>
</LinearLayout>

View File

@@ -17,112 +17,114 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
--> -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:padding="@dimen/default_margin"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:importantForAutofill="noExcludeDescendants" <LinearLayout
tools:targetApi="o"> android:padding="@dimen/default_margin"
<android.support.v7.widget.CardView android:orientation="vertical"
android:id="@+id/card_view_master_password"
android:layout_margin="4dp"
android:layout_gravity="center"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:cardCornerRadius="4dp"> android:importantForAutofill="noExcludeDescendants"
<LinearLayout tools:targetApi="o">
<android.support.v7.widget.CardView
android:id="@+id/card_view_master_password"
android:layout_margin="4dp"
android:layout_gravity="center"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="@dimen/default_margin" app:cardCornerRadius="4dp">
android:orientation="vertical"> <LinearLayout
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/password_checkbox"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/password"/> android:layout_margin="@dimen/default_margin"
android:orientation="vertical">
<!-- Password Input --> <android.support.v7.widget.AppCompatCheckBox
<android.support.design.widget.TextInputLayout android:id="@+id/password_checkbox"
android:id="@+id/password_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true"
app:passwordToggleTint="?attr/colorAccent">
<android.support.design.widget.TextInputEditText
android:id="@+id/pass_password"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="textPassword" android:text="@string/password"/>
android:maxLines="1"
android:hint="@string/hint_pass"/> <!-- Password Input -->
</android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputLayout
<android.support.design.widget.TextInputLayout android:id="@+id/password_input_layout"
android:id="@+id/password_repeat_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true"
app:passwordToggleTint="?attr/colorAccent">
<EditText android:id="@+id/pass_conf_password"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="textPassword" app:passwordToggleEnabled="true"
android:maxLines="1" app:passwordToggleTint="?attr/colorAccent">
android:hint="@string/hint_conf_pass"/> <android.support.design.widget.TextInputEditText
</android.support.design.widget.TextInputLayout> android:id="@+id/pass_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:maxLines="1"
android:hint="@string/hint_pass"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/password_repeat_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true"
app:passwordToggleTint="?attr/colorAccent">
<EditText android:id="@+id/pass_conf_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:maxLines="1"
android:hint="@string/hint_conf_pass"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout> </LinearLayout>
</android.support.v7.widget.CardView> </android.support.v7.widget.CardView>
<android.support.v7.widget.CardView <android.support.v7.widget.CardView
android:id="@+id/card_view_key_file" android:id="@+id/card_view_key_file"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
app:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="@dimen/default_margin" android:layout_margin="4dp"
android:orientation="vertical"> app:cardCornerRadius="4dp">
<LinearLayout
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/keyfile_checkox"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/entry_keyfile"/> android:layout_margin="@dimen/default_margin"
android:orientation="vertical">
<RelativeLayout <android.support.v7.widget.AppCompatCheckBox
android:layout_width="match_parent" android:id="@+id/keyfile_checkox"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatImageView
android:id="@+id/browse_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:padding="12dp"
android:src="@drawable/ic_folder_white_24dp"
android:tint="?attr/colorAccentCompat" />
<android.support.v7.widget.AppCompatEditText
android:id="@+id/pass_keyfile"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/browse_button" android:text="@string/entry_keyfile"/>
android:layout_toStartOf="@+id/browse_button"
android:hint="@string/hint_keyfile"
android:maxLines="1"
android:singleLine="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout> <android.support.v7.widget.AppCompatImageView
</android.support.v7.widget.CardView> android:id="@+id/browse_button"
</LinearLayout> android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:padding="12dp"
android:src="@drawable/ic_folder_white_24dp"
android:tint="?attr/colorAccentCompat" />
<android.support.v7.widget.AppCompatEditText
android:id="@+id/pass_keyfile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/browse_button"
android:layout_toStartOf="@+id/browse_button"
android:hint="@string/hint_keyfile"
android:maxLines="1"
android:singleLine="true"/>
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>

View File

@@ -19,9 +19,9 @@
--> -->
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/menu_donate" <item android:id="@+id/menu_contribute"
android:icon="@drawable/ic_heart_white_24dp" android:icon="@drawable/ic_heart_white_24dp"
android:title="@string/menu_donate" android:title="@string/contribute"
android:orderInCategory="95" android:orderInCategory="95"
app:showAsAction="ifRoom" /> app:showAsAction="ifRoom" />
</menu> </menu>

View File

@@ -123,7 +123,7 @@
<string name="remember_keyfile_summary">Recorda la localització d\'arxius clau</string> <string name="remember_keyfile_summary">Recorda la localització d\'arxius clau</string>
<string name="remember_keyfile_title">Guarda arxiu clau</string> <string name="remember_keyfile_title">Guarda arxiu clau</string>
<string name="remove_from_filelist">Elimina</string> <string name="remove_from_filelist">Elimina</string>
<string name="rijndael">Rijndael (AES)</string> <string name="encryption_rijndael">Rijndael (AES)</string>
<string name="root">Arrel</string> <string name="root">Arrel</string>
<string name="rounds">Passades d\'encriptació</string> <string name="rounds">Passades d\'encriptació</string>
<string name="rounds_explanation">Més passades d\'encriptació dónen protecció adicional contra atacs de força bruta, però poden alentir molt carregar i guardar la base de dades.</string> <string name="rounds_explanation">Més passades d\'encriptació dónen protecció adicional contra atacs de força bruta, però poden alentir molt carregar i guardar la base de dades.</string>
@@ -135,7 +135,7 @@
<string name="special">Especial</string> <string name="special">Especial</string>
<string name="search">Títol/descripció d\'entrada</string> <string name="search">Títol/descripció d\'entrada</string>
<string name="search_results">Resultats de cerca</string> <string name="search_results">Resultats de cerca</string>
<string name="twofish">Twofish</string> <string name="encryption_twofish">Twofish</string>
<string name="underline">Subratllat</string> <string name="underline">Subratllat</string>
<string name="unsupported_db_version">Versió de la base de dades no suportada.</string> <string name="unsupported_db_version">Versió de la base de dades no suportada.</string>
<string name="uppercase">Majúscules</string> <string name="uppercase">Majúscules</string>

View File

@@ -139,7 +139,7 @@
<string name="remember_keyfile_summary">Pamatovat si umístění klíčového souboru</string> <string name="remember_keyfile_summary">Pamatovat si umístění klíčového souboru</string>
<string name="remember_keyfile_title">Uložit klíčový soubor</string> <string name="remember_keyfile_title">Uložit klíčový soubor</string>
<string name="remove_from_filelist">Odstranit</string> <string name="remove_from_filelist">Odstranit</string>
<string name="rijndael">Rijndael (AES)</string> <string name="encryption_rijndael">Rijndael (AES)</string>
<string name="root">Kořen</string> <string name="root">Kořen</string>
<string name="rounds">Počet zašifrování</string> <string name="rounds">Počet zašifrování</string>
<string name="rounds_explanation">Vyšší počet opakování šifrování zvýší bezpečnost proti hrubému útoku, ale může výrazně zpomalit načítání a ukládání.</string> <string name="rounds_explanation">Vyšší počet opakování šifrování zvýší bezpečnost proti hrubému útoku, ale může výrazně zpomalit načítání a ukládání.</string>
@@ -151,7 +151,7 @@
<string name="special">Speciální</string> <string name="special">Speciální</string>
<string name="search">Zadejte název/popis</string> <string name="search">Zadejte název/popis</string>
<string name="search_results">Výsledky hledání</string> <string name="search_results">Výsledky hledání</string>
<string name="twofish">Twofish</string> <string name="encryption_twofish">Twofish</string>
<string name="underline">Podtrženo</string> <string name="underline">Podtrženo</string>
<string name="unsupported_db_version">Nepodporovaná verze databáze.</string> <string name="unsupported_db_version">Nepodporovaná verze databáze.</string>
<string name="uppercase">Velká písmena</string> <string name="uppercase">Velká písmena</string>

View File

@@ -138,7 +138,7 @@
<string name="remember_keyfile_summary">Husker placeringen af nøglefiler</string> <string name="remember_keyfile_summary">Husker placeringen af nøglefiler</string>
<string name="remember_keyfile_title">Gem nøglefil</string> <string name="remember_keyfile_title">Gem nøglefil</string>
<string name="remove_from_filelist">Fjern</string> <string name="remove_from_filelist">Fjern</string>
<string name="rijndael">Rijndael (AES)</string> <string name="encryption_rijndael">Rijndael (AES)</string>
<string name="root">Root</string> <string name="root">Root</string>
<string name="rounds">Krypterings-gentagelser</string> <string name="rounds">Krypterings-gentagelser</string>
<string name="rounds_explanation">Højere krypterings-gentagelser giver øget beskyttelse imod brute-force angreb, men kan påvirke læsnings- og skrivehastigheden betydentligt.</string> <string name="rounds_explanation">Højere krypterings-gentagelser giver øget beskyttelse imod brute-force angreb, men kan påvirke læsnings- og skrivehastigheden betydentligt.</string>
@@ -150,7 +150,7 @@
<string name="special">Speciel</string> <string name="special">Speciel</string>
<string name="search">Post titel/beskrivelse</string> <string name="search">Post titel/beskrivelse</string>
<string name="search_results">Søgeresultater</string> <string name="search_results">Søgeresultater</string>
<string name="twofish">Twofish</string> <string name="encryption_twofish">Twofish</string>
<string name="underline">Understreget</string> <string name="underline">Understreget</string>
<string name="unsupported_db_version">Database-versionen er ikke understøttet.</string> <string name="unsupported_db_version">Database-versionen er ikke understøttet.</string>
<string name="uppercase">Store bogstaver</string> <string name="uppercase">Store bogstaver</string>

View File

@@ -144,7 +144,7 @@
<string name="remember_keyfile_summary">Den Pfad der Schlüsseldatei merken.</string> <string name="remember_keyfile_summary">Den Pfad der Schlüsseldatei merken.</string>
<string name="remember_keyfile_title">Schlüsselquelle merken</string> <string name="remember_keyfile_title">Schlüsselquelle merken</string>
<string name="remove_from_filelist">Löschen</string> <string name="remove_from_filelist">Löschen</string>
<string name="rijndael">Rijndael (AES)</string> <string name="encryption_rijndael">Rijndael (AES)</string>
<string name="root">Start</string> <string name="root">Start</string>
<string name="rounds">Schlüsseltransformationen</string> <string name="rounds">Schlüsseltransformationen</string>
<string name="rounds_explanation">Je höher die Anzahl der Schlüsseltransformationen, desto besser ist der Schutz gegen Wörterbuch- oder Brute-Force-Angriffe. Allerdings dauert dann auch das Laden und Speichern der Datenbank entsprechend länger.</string> <string name="rounds_explanation">Je höher die Anzahl der Schlüsseltransformationen, desto besser ist der Schutz gegen Wörterbuch- oder Brute-Force-Angriffe. Allerdings dauert dann auch das Laden und Speichern der Datenbank entsprechend länger.</string>
@@ -159,14 +159,14 @@
<string name="special">Spezialsymbole</string> <string name="special">Spezialsymbole</string>
<string name="search">Titel/Beschreibung des Eintrags</string> <string name="search">Titel/Beschreibung des Eintrags</string>
<string name="search_results">Suchergebnisse</string> <string name="search_results">Suchergebnisse</string>
<string name="twofish">Twofish</string> <string name="encryption_twofish">Twofish</string>
<string name="underline">Unterstrichen</string> <string name="underline">Unterstrichen</string>
<string name="unsupported_db_version">Datenbankversion wird nicht unterstützt.</string> <string name="unsupported_db_version">Datenbankversion wird nicht unterstützt.</string>
<string name="uppercase">Großbuchstaben</string> <string name="uppercase">Großbuchstaben</string>
<string name="use_saf_summary">Storage Access Framework als Dateimanager verwenden (Android KitKat und später)</string> <string name="use_saf_summary">Storage Access Framework als Dateimanager verwenden (Android KitKat und später)</string>
<string name="use_saf_title">Storage Access Framework</string> <string name="use_saf_title">Storage Access Framework</string>
<string name="warning">Warnung</string> <string name="warning">Warnung</string>
<string name="warning_password_encoding">Das .kdb Format unterstützt nur den Latin1 Zeichensatz. Ihr Passwort enthällt andere Zeichen. Diese Zeichen werden umgewandelt. Dies reduziert die Sicherheit des Passwortes. Es wird empfohen ihr Passwort zu ändern.</string> <string name="warning_password_encoding">Das .kdb Format unterstützt nur den Latin1 Zeichensatz. Ihr Passwort enthält andere Zeichen. Diese Zeichen werden umgewandelt. Dies reduziert die Sicherheit des Passwortes. Es wird empfohlen ihr Passwort zu ändern.</string>
<string name="warning_read_only">Die SD-Karte ist schreibgeschützt. Etwaige Änderungen in den Datensätzen können daher nicht in der Datenbank gespeichert werden.</string> <string name="warning_read_only">Die SD-Karte ist schreibgeschützt. Etwaige Änderungen in den Datensätzen können daher nicht in der Datenbank gespeichert werden.</string>
<string name="warning_unmounted">Keine SD-Karte vorhanden oder derzeit nicht im Gerät eingebunden. Daher kann weder eine Datenbank geöffnet, noch erstellt werden.</string> <string name="warning_unmounted">Keine SD-Karte vorhanden oder derzeit nicht im Gerät eingebunden. Daher kann weder eine Datenbank geöffnet, noch erstellt werden.</string>
<string name="version_label">Version:</string> <string name="version_label">Version:</string>
@@ -217,6 +217,8 @@
<string name="configure_fingerprint">Fingerabruck unterstützt, jedoch nicht für dieses Gerät konfiguriert</string> <string name="configure_fingerprint">Fingerabruck unterstützt, jedoch nicht für dieses Gerät konfiguriert</string>
<string name="scanning_fingerprint">Fingerabdruck wird gescannt</string> <string name="scanning_fingerprint">Fingerabdruck wird gescannt</string>
<string name="encrypted_value_stored">Verschlüsseltes Passwort wurde gespeichert</string> <string name="encrypted_value_stored">Verschlüsseltes Passwort wurde gespeichert</string>
<string name="fingerprint_invalid_key">Ungültiger Schlüssel</string>
<string name="fingerprint_error">Probleme mit dem Fingerabdruck : %1$s</string>
<string name="history">Verlauf</string> <string name="history">Verlauf</string>
<string name="fingerprint_quick_unlock_title">Wie richte ich den Fingerabdruckscanner ein ?</string> <string name="fingerprint_quick_unlock_title">Wie richte ich den Fingerabdruckscanner ein ?</string>
<string name="fingerprint_setting_text">Speichern sie ihren persönlichen Fingerabruck in</string> <string name="fingerprint_setting_text">Speichern sie ihren persönlichen Fingerabruck in</string>

Some files were not shown because too many files have changed in this diff Show More