Compare commits

...

57 Commits

Author SHA1 Message Date
J-Jamet
d4a0b59eb1 Merge branch 'release/2.5.0.0beta11' 2018-05-13 18:23:37 +02:00
J-Jamet
07600949ab Upgrade version and fix potential null pointer for kdf 2018-05-13 18:14:25 +02:00
J-Jamet
7efaad1818 Fix database creation issue 2018-05-13 17:54:35 +02:00
J-Jamet
e32b0d1c25 Merge tag '2.5.0.0beta10' into develop 2018-05-13 17:05:32 +02:00
J-Jamet
0fdcc29aa2 Merge branch 'release/2.5.0.0beta10' 2018-05-13 17:05:10 +02:00
J-Jamet
37bedbffc9 Fix italian translation for compilation 2018-05-13 16:59:35 +02:00
J-Jamet
46505150c4 New Red Volcano theme and change visual feature message for version libre 2018-05-13 16:47:59 +02:00
J-Jamet
e18c5c90cc Upgrade changelogs 2018-05-13 14:52:59 +02:00
J-Jamet
1f5649d9d2 Merge branch 'feature/ChangeAlgorithms' into develop #9 #29 2018-05-13 14:25:31 +02:00
J-Jamet
7bbd55a9fd Add binary to memory explanation 2018-05-13 14:17:19 +02:00
J-Jamet
92eeccf84e Fix algorithm and kdf function for database V3 and add small trad 2018-05-13 13:55:37 +02:00
J-Jamet
7bcc289518 Upgrade explanations 2018-05-13 13:02:09 +02:00
J-Jamet
507f758c0d Add memory usage and parallelism for Argon2 settings 2018-05-12 23:53:41 +02:00
J-Jamet
6afffb7245 Register UUID of database version in KDF parameter 2018-05-11 19:19:16 +02:00
J-Jamet
c62f4ae0b3 Text if choose only one extension #105 2018-05-11 13:25:33 +02:00
J-Jamet
ee80c614e0 Fix layer error for icon free #113 2018-05-11 12:44:33 +02:00
J-Jamet
fea7af6910 Dynamic creation of KdfEngine, reorganise code 2018-05-09 15:17:55 +02:00
J-Jamet
c72aa0e97d Merge branch 'develop' into feature/ChangeAlgorithms to Fix NDK 2018-05-09 12:01:16 +02:00
J-Jamet
3dd60b5392 Fix ndk filters 2018-05-09 10:59:48 +02:00
J-Jamet
a357267552 #107 Set master password in landscape 2018-05-07 10:47:00 +02:00
J-Jamet
1badeb2eef Change FAQ as markdown and add descriptions 2018-05-07 10:34:27 +02:00
Yhaulez
0bb8d2a417 Create FAQ 2018-05-06 16:26:19 +02:00
J-Jamet
4a215db83c Change toolbar style and password layout 2018-05-05 23:16:39 +02:00
J-Jamet
512e55a170 Fix fingerprint animation and for first init 2018-05-05 20:39:01 +02:00
J-Jamet
1ebe8dc022 Update fingerprint state with checkbox 2018-05-04 21:24:57 +02:00
J-Jamet
cafeabdbc3 Fix search styles 2018-05-02 21:31:04 +02:00
J-Jamet
b342b26409 Update readme 2018-05-02 20:59:05 +02:00
J-Jamet
938c3a07af Fix wait dialog callback 2018-05-02 20:52:16 +02:00
J-Jamet
16288f98f7 Merge branch 'develop' into feature/ChangeAlgorithms 2018-05-02 15:57:47 +02:00
J-Jamet
a932156e85 Remove unused progressbar 2018-05-02 15:26:24 +02:00
J-Jamet
64e9b9fb6d Fix lock orientation change 2018-05-02 14:02:10 +02:00
J-Jamet
7af28550da Merge branch 'feature/RefactorProgress' into develop #98 2018-05-02 13:49:56 +02:00
J-Jamet
60e2d786dd Change progress dialog title, and remove code 2018-05-02 13:49:03 +02:00
J-Jamet
ec08f3430d Add progress bar for all, create database in a single progress dialog 2018-05-02 09:54:55 +02:00
J-Jamet
a50aa0fb95 Fix null pointer for KeyDerivationName 2018-05-02 07:16:55 +02:00
J-Jamet
cf026e8eaa Update progress bar and message progress 2018-05-01 20:03:43 +02:00
J-Jamet
77614d0c4a Upgrade changelogs and version 2018-04-30 19:54:50 +02:00
J-Jamet
e8d71039d7 refactor 2018-04-30 18:18:13 +02:00
J-Jamet
4164b5bd37 Fix crash by locking activity position 2018-04-30 17:47:31 +02:00
J-Jamet
3c66ec82b5 Upgrade French 2018-04-30 17:00:42 +02:00
J-Jamet
b796c16877 Upgrade Italian 2018-04-30 16:57:10 +02:00
J-Jamet
42d34d8f0c Add material icon pack in free version and change texts 2018-04-30 16:10:18 +02:00
J-Jamet
5fbb37df82 Fix german fingerprint error 2018-04-29 14:07:56 +02:00
J-Jamet
52e12d7cbd Upgrade russian translation 2018-04-28 22:34:25 +02:00
J-Jamet
5cf5719e8e Fix education text color 2018-04-28 20:08:33 +02:00
J-Jamet
af3a80143e Fix crash by return blank when Resources$NotFoundException 2018-04-28 19:49:59 +02:00
J-Jamet
90db27c3fe Refactor Master key functions 2018-04-28 18:15:30 +02:00
J-Jamet
3d584b76f7 Choose kdf and encapsulate code 2018-04-28 15:58:04 +02:00
J-Jamet
fbf3dec421 Assign algorithm dynamically 2018-04-28 12:20:18 +02:00
J-Jamet
1d36683128 Remove screens in Readme 2018-04-28 11:11:50 +02:00
J-Jamet
cefc546c0a Upgrade german translation 2018-04-28 11:08:23 +02:00
J-Jamet
7aeb51813c Show algorithm dialog 2018-04-26 23:00:15 +02:00
J-Jamet
d6fc29ec79 Creation of classes and prepare assignment for algorithms 2018-04-26 22:00:11 +02:00
J-Jamet
9af182e0c3 Change dark style 2018-04-26 16:14:22 +02:00
J-Jamet
c7120b997f Fix contribution issue for KeePass DX Pro 2018-04-26 14:39:45 +02:00
J-Jamet
e61571fcec Upgrade fastlane 2018-04-26 12:18:14 +02:00
J-Jamet
9a900b32b2 Merge tag '2.5.0.0beta9' into develop
2.5.0.0beta9
2018-04-25 13:16:14 +02:00
137 changed files with 3001 additions and 1303 deletions

View File

@@ -1,3 +1,14 @@
KeepassDX (2.5.0.0beta11)
* Fix crash in beta10 version
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)
* Education Screens to learn how to use the app
* 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
<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">
### Features
* Create database files / entries and groups
* 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...)
* Allows fast copy of fields and opening of URI / URL
* Fingerprint for fast unlocking
* Material design with themes
* AutoFill and Integration
* Precise management of settings
* 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...)
* Allows **fast copy** of fields and opening of URI / URL
* **Fingerprint** for fast unlocking
* Material design with **themes**
* **AutoFill** and Integration
* Precise management of **settings**
Keepass DX is opensource 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">
Keepass DX is **open source** and **ad-free**.
## 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?
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.*
@@ -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.
* 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
*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"
alt="Get it on F-Droid"
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"
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
- [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**.
## License
Copyright (c) 2017 Jeremy Jamet / Kunzisoft.
Copyright (c) 2017 Jeremy Jamet / [Kunzisoft](https://www.kunzisoft.com).
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
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"
minSdkVersion 14
targetSdkVersion 27
versionCode = 9
versionName = "2.5.0.0beta9"
versionCode = 11
versionName = "2.5.0.0beta11"
multiDexEnabled true
testApplicationId = "com.kunzisoft.keepass.tests"
testInstrumentationRunner = "android.test.InstrumentationTestRunner"
ndk {
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a',
'arm64-v8a', 'mips', 'mips64'
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
}
buildConfigField "String[]", "ICON_PACKS", "{\"classic\",\"material\"}"
@@ -47,7 +46,7 @@ android {
versionNameSuffix "-libre"
buildConfigField "boolean", "FULL_VERSION", "true"
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", "{}"
}
@@ -64,8 +63,8 @@ android {
versionNameSuffix "-free"
buildConfigField "boolean", "FULL_VERSION", "false"
buildConfigField "boolean", "CLOSED_STORE", "true"
buildConfigField "String[]", "STYLES_DISABLED", "{\"KeepassDXStyle_Dark\",\"KeepassDXStyle_Blue\",\"KeepassDXStyle_Purple\"}"
buildConfigField "String[]", "ICON_PACKS_DISABLED", "{\"material\"}"
buildConfigField "String[]", "STYLES_DISABLED", "{\"KeepassDXStyle_Dark\",\"KeepassDXStyle_Blue\",\"KeepassDXStyle_Red\",\"KeepassDXStyle_Purple\"}"
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.PwEntryV3;
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;
public class DeleteEntry extends AndroidTestCase {
@@ -60,7 +60,7 @@ public class DeleteEntry extends AndroidTestCase {
assertNotNull("Could not find group1", group1);
// Delete the group
DeleteGroup task = new DeleteGroup(null, db, group1, null, true);
DeleteGroupRunnable task = new DeleteGroupRunnable(null, db, group1, null, true);
task.run();
// 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),
getString(R.string.education_field_copy_title),
getString(R.string.education_field_copy_summary))
.textColorInt(Color.WHITE)
.tintTarget(false)
.cancelable(true),
new TapTargetView.Listener() {
@@ -250,6 +251,7 @@ public class EntryActivity extends LockingHideActivity {
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_edit,
getString(R.string.education_entry_edit_title),
getString(R.string.education_entry_edit_summary))
.textColorInt(Color.WHITE)
.tintTarget(true)
.cancelable(true),
new TapTargetView.Listener() {
@@ -372,7 +374,7 @@ public class EntryActivity extends LockingHideActivity {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
MenuUtil.donationMenuInflater(inflater, menu);
MenuUtil.contributionMenuInflater(inflater, menu);
inflater.inflate(R.menu.entry, menu);
inflater.inflate(R.menu.database_lock, menu);
@@ -415,8 +417,8 @@ public class EntryActivity extends LockingHideActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch ( item.getItemId() ) {
case R.id.menu_donate:
return MenuUtil.onDonationItemSelected(this);
case R.id.menu_contribute:
return MenuUtil.onContributionItemSelected(this);
case R.id.menu_toggle_pass:
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.PwGroupId;
import com.kunzisoft.keepass.database.PwIconStandard;
import com.kunzisoft.keepass.database.edit.AddEntry;
import com.kunzisoft.keepass.database.edit.OnFinish;
import com.kunzisoft.keepass.database.edit.RunnableOnFinish;
import com.kunzisoft.keepass.database.edit.UpdateEntry;
import com.kunzisoft.keepass.database.action.AddEntryRunnable;
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
import com.kunzisoft.keepass.database.action.RunnableOnFinish;
import com.kunzisoft.keepass.database.action.UpdateEntryRunnable;
import com.kunzisoft.keepass.database.security.ProtectedString;
import com.kunzisoft.keepass.dialogs.GeneratePasswordDialogFragment;
import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment;
import com.kunzisoft.keepass.icons.IconPackChooser;
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.Types;
import com.kunzisoft.keepass.utils.Util;
@@ -249,16 +250,21 @@ public class EntryEditActivity extends LockingHideActivity
}
mCallbackNewEntry = populateNewEntry();
OnFinish onFinish = new AfterSave();
// Open a progress dialog and save entry
OnFinishRunnable onFinish = new AfterSave();
EntryEditActivity act = EntryEditActivity.this;
RunnableOnFinish task;
if ( mIsNew ) {
task = new AddEntry(act, App.getDB(), mCallbackNewEntry, onFinish);
task = new AddEntryRunnable(act, App.getDB(), mCallbackNewEntry, onFinish);
} 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);
pt.run();
task.setUpdateProgressTaskStatus(
new UpdateProgressTaskStatus(this,
SaveDatabaseProgressTaskDialogFragment.start(
getSupportFragmentManager())
));
new Thread(task).start();
}
/**
@@ -274,6 +280,7 @@ public class EntryEditActivity extends LockingHideActivity
TapTarget.forView(generatePasswordView,
getString(R.string.education_generate_password_title),
getString(R.string.education_generate_password_summary))
.textColorInt(Color.WHITE)
.tintTarget(false)
.cancelable(true),
new TapTargetView.Listener() {
@@ -300,6 +307,7 @@ public class EntryEditActivity extends LockingHideActivity
TapTarget.forView(addNewFieldView,
getString(R.string.education_entry_new_field_title),
getString(R.string.education_entry_new_field_summary))
.textColorInt(Color.WHITE)
.tintTarget(false)
.cancelable(true),
new TapTargetView.Listener() {
@@ -447,15 +455,15 @@ public class EntryEditActivity extends LockingHideActivity
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
MenuUtil.donationMenuInflater(inflater, menu);
MenuUtil.contributionMenuInflater(inflater, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch ( item.getItemId() ) {
case R.id.menu_donate:
return MenuUtil.onDonationItemSelected(this);
case R.id.menu_contribute:
return MenuUtil.onContributionItemSelected(this);
case android.R.id.home:
finish();
@@ -552,7 +560,7 @@ public class EntryEditActivity extends LockingHideActivity
}
}
private final class AfterSave extends OnFinish {
private final class AfterSave extends OnFinishRunnable {
AfterSave() {
super(new Handler());
@@ -560,11 +568,15 @@ public class EntryEditActivity extends LockingHideActivity
@Override
public void run() {
runOnUiThread(() -> {
if ( mSuccess ) {
finish();
} 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.PwNode;
import com.kunzisoft.keepass.database.SortNodeEnum;
import com.kunzisoft.keepass.database.edit.AddGroup;
import com.kunzisoft.keepass.database.edit.DeleteEntry;
import com.kunzisoft.keepass.database.edit.DeleteGroup;
import com.kunzisoft.keepass.database.edit.UpdateGroup;
import com.kunzisoft.keepass.database.action.AddGroupRunnable;
import com.kunzisoft.keepass.database.action.DeleteEntryRunnable;
import com.kunzisoft.keepass.database.action.DeleteGroupRunnable;
import com.kunzisoft.keepass.database.action.UpdateGroupRunnable;
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
import com.kunzisoft.keepass.dialogs.GroupEditDialogFragment;
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.search.SearchResultsActivity;
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;
public class GroupActivity extends ListNodesActivity
@@ -285,6 +286,7 @@ public class GroupActivity extends ListNodesActivity
TapTarget.forView(findViewById(R.id.add_button),
getString(R.string.education_new_node_title),
getString(R.string.education_new_node_summary))
.textColorInt(Color.WHITE)
.tintTarget(false)
.cancelable(true),
new TapTargetView.Listener() {
@@ -313,6 +315,7 @@ public class GroupActivity extends ListNodesActivity
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_search,
getString(R.string.education_search_title),
getString(R.string.education_search_summary))
.textColorInt(Color.WHITE)
.tintTarget(true)
.cancelable(true),
new TapTargetView.Listener() {
@@ -344,6 +347,7 @@ public class GroupActivity extends ListNodesActivity
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_sort,
getString(R.string.education_sort_title),
getString(R.string.education_sort_summary))
.textColorInt(Color.WHITE)
.tintTarget(true)
.cancelable(true),
new TapTargetView.Listener() {
@@ -374,6 +378,7 @@ public class GroupActivity extends ListNodesActivity
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_lock,
getString(R.string.education_lock_title),
getString(R.string.education_lock_summary))
.textColorInt(Color.WHITE)
.tintTarget(true)
.cancelable(true),
new TapTargetView.Listener() {
@@ -431,19 +436,27 @@ public class GroupActivity extends ListNodesActivity
private void deleteEntry(PwEntry entry) {
Handler handler = new Handler();
DeleteEntry task = new DeleteEntry(this, App.getDB(), entry,
DeleteEntryRunnable task = new DeleteEntryRunnable(this, App.getDB(), entry,
new AfterDeleteNode(handler, entry));
ProgressTask pt = new ProgressTask(this, task, R.string.saving_database);
pt.run();
task.setUpdateProgressTaskStatus(
new UpdateProgressTaskStatus(this,
SaveDatabaseProgressTaskDialogFragment.start(
getSupportFragmentManager())
));
new Thread(task).start();
}
private void deleteGroup(PwGroup group) {
//TODO Verify trash recycle bin
Handler handler = new Handler();
DeleteGroup task = new DeleteGroup(this, App.getDB(), group,
DeleteGroupRunnable task = new DeleteGroupRunnable(this, App.getDB(), group,
new AfterDeleteNode(handler, group));
ProgressTask pt = new ProgressTask(this, task, R.string.saving_database);
pt.run();
task.setUpdateProgressTaskStatus(
new UpdateProgressTaskStatus(this,
SaveDatabaseProgressTaskDialogFragment.start(
getSupportFragmentManager())
));
new Thread(task).start();
}
@Override
@@ -544,16 +557,21 @@ public class GroupActivity extends ListNodesActivity
newGroup.setName(name);
try {
iconStandard = (PwIconStandard) icon;
} catch (Exception e) {} // TODO custom icon
} catch (Exception ignored) {} // TODO custom icon
newGroup.setIcon(iconStandard);
new ProgressTask(this,
new AddGroup(this,
// If group created save it in the database
AddGroupRunnable addGroupRunnable = new AddGroupRunnable(this,
App.getDB(),
newGroup,
new AfterAddNode(new Handler())),
R.string.saving_database)
.run();
new AfterAddNode(new Handler()));
addGroupRunnable.setUpdateProgressTaskStatus(
new UpdateProgressTaskStatus(this,
SaveDatabaseProgressTaskDialogFragment.start(
getSupportFragmentManager())
));
new Thread(addGroupRunnable).start();
break;
case UPDATE:
// If update add new elements
@@ -562,20 +580,23 @@ public class GroupActivity extends ListNodesActivity
updateGroup.setName(name);
try {
iconStandard = (PwIconStandard) icon;
} catch (Exception e) {} // TODO custom icon
} catch (Exception ignored) {} // TODO custom icon
updateGroup.setIcon(iconStandard);
mAdapter.removeNode(oldGroupToUpdate);
// If group update
new ProgressTask(this,
new UpdateGroup(this,
// If group updated save it in the database
UpdateGroupRunnable updateGroupRunnable = new UpdateGroupRunnable(this,
App.getDB(),
oldGroupToUpdate,
updateGroup,
new AfterUpdateNode(new Handler())),
R.string.saving_database)
.run();
new AfterUpdateNode(new Handler()));
updateGroupRunnable.setUpdateProgressTaskStatus(
new UpdateProgressTaskStatus(this,
SaveDatabaseProgressTaskDialogFragment.start(
getSupportFragmentManager())
));
new Thread(updateGroupRunnable).start();
}
break;

View File

@@ -49,12 +49,13 @@ import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.PwGroup;
import com.kunzisoft.keepass.database.PwNode;
import com.kunzisoft.keepass.database.SortNodeEnum;
import com.kunzisoft.keepass.database.edit.AfterActionNodeOnFinish;
import com.kunzisoft.keepass.database.edit.OnFinish;
import com.kunzisoft.keepass.database.action.AfterActionNodeOnFinish;
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
import com.kunzisoft.keepass.dialogs.SortDialogFragment;
import com.kunzisoft.keepass.password.AssignPasswordHelper;
import com.kunzisoft.keepass.settings.PreferencesUtil;
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
import com.kunzisoft.keepass.tasks.UIToastTask;
import com.kunzisoft.keepass.utils.MenuUtil;
@@ -177,7 +178,7 @@ public abstract class ListNodesActivity extends LockingActivity
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
MenuUtil.donationMenuInflater(inflater, menu);
MenuUtil.contributionMenuInflater(inflater, menu);
inflater.inflate(R.menu.tree, 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) {
super.run();
runOnUiThread(() -> {
if (mSuccess) {
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) {
super.run();
runOnUiThread(() -> {
if (mSuccess) {
mAdapter.updateNode(oldNode, newNode);
} else {
displayMessage(ListNodesActivity.this);
}
SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this);
});
}
}
class AfterDeleteNode extends OnFinish {
class AfterDeleteNode extends OnFinishRunnable {
private PwNode pwNode;
AfterDeleteNode(Handler handler, PwNode pwNode) {
@@ -340,6 +351,9 @@ public abstract class ListNodesActivity extends LockingActivity
@Override
public void run() {
super.run();
runOnUiThread(() -> {
if ( mSuccess) {
mAdapter.removeNode(pwNode);
PwGroup parent = pwNode.getParent();
@@ -361,6 +375,9 @@ public abstract class ListNodesActivity extends LockingActivity
App.setShutdown();
finish();
}
SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this);
});
}
}
}

View File

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

View File

@@ -19,6 +19,9 @@
*/
package com.kunzisoft.keepass.crypto.keyDerivation;
import android.content.res.Resources;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.utils.Types;
import java.io.IOException;
@@ -26,6 +29,7 @@ import java.security.SecureRandom;
import java.util.UUID;
public class Argon2Kdf extends KdfEngine {
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,
(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 DefaultParallelism = 2;
private static final String DEFAULT_NAME = "Argon2";
public Argon2Kdf() {
uuid = CIPHER_UUID;
}
@Override
public String getName() {
return "Argon2";
public String getName(Resources resources) {
if (resources == null)
return DEFAULT_NAME;
return resources.getString(R.string.kdf_Argon2);
}
@Override
public KdfParameters getDefaultParameters() {
KdfParameters p = super.getDefaultParameters();
KdfParameters p = new KdfParameters(uuid);
p.setUInt32(ParamVersion, MaxVersion);
p.setUInt64(ParamMemory, DefaultMemory);
p.setParamUUID();
p.setUInt32(ParamParallelism, DefaultParallelism);
p.setUInt64(ParamMemory, DefaultMemory);
p.setUInt64(ParamIterations, DefaultIterations);
p.setUInt32(ParamVersion, MaxVersion);
return p;
}
@@ -113,4 +123,35 @@ public class Argon2Kdf extends KdfEngine {
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;
import com.kunzisoft.keepass.database.ObjectNameResource;
import java.io.IOException;
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 KdfParameters getDefaultParameters() {
return new KdfParameters(uuid);
}
public abstract KdfParameters getDefaultParameters();
public abstract byte[] transform(byte[] masterKey, KdfParameters p) throws IOException;
public abstract void randomize(KdfParameters p);
public abstract String getName();
public abstract long getKeyRounds(KdfParameters p);
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.List;
import java.util.UUID;
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<>();
static {
kdfList.add(new AesKdf());
kdfList.add(new Argon2Kdf());
kdfListV3.add(aesKdf);
kdfList.add(aesKdf);
kdfList.add(argon2Kdf);
}
public static KdfParameters getDefaultParameters() {
return kdfList.get(0).getDefaultParameters();
}
public static KdfEngine get(UUID uuid) {
public static KdfEngine get(KdfParameters kdfParameters) {
for (KdfEngine engine: kdfList) {
if (engine.uuid.equals(uuid)) {
if (engine.uuid.equals(kdfParameters.kdfUUID)) {
return engine;
}
}
return null;
}

View File

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

View File

@@ -27,6 +27,8 @@ import android.preference.PreferenceManager;
import android.util.Log;
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.InvalidDBException;
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.icons.IconDrawableFactory;
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 java.io.BufferedInputStream;
@@ -47,6 +49,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.SyncFailedException;
import java.util.ArrayList;
import java.util.List;
public class Database {
@@ -99,19 +103,11 @@ public class Database {
loaded = true;
}
public void loadData(Context ctx, InputStream is, String password, InputStream keyInputStream) throws IOException, 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 {
public void loadData(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status) throws IOException, FileNotFoundException, InvalidDBException {
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;
readOnly = false;
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;
try {
is = UriUtil.getUriInputStream(ctx, uri);
@@ -156,15 +152,11 @@ public class Database {
loadData(ctx, is, password, kfIs, status, debug, roundsFix);
}
public void loadData(Context ctx, InputStream is, String password, InputStream kfIs, boolean debug) throws IOException, InvalidDBException {
loadData(ctx, is, password, kfIs, new UpdateStatus(), debug);
public void loadData(Context ctx, InputStream is, String password, InputStream keyFileInputStream, boolean debug) throws IOException, InvalidDBException {
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 {
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 {
private void loadData(Context ctx, InputStream is, String password, InputStream keyFileInputStream, ProgressTaskUpdater progressTaskUpdater, boolean debug, long roundsFix) throws IOException, InvalidDBException {
BufferedInputStream bis = new BufferedInputStream(is);
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.
bis.mark(10);
Importer imp = ImporterFactory.createImporter(bis, debug);
Importer databaseImporter = ImporterFactory.createImporter(bis, debug);
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 ) {
try {
switch (pm.getVersion()) {
@@ -222,19 +214,26 @@ public class Database {
saveData(ctx, mUri);
}
public void saveData(Context ctx, Uri uri) throws IOException, PwDbOutputException {
private void saveData(Context ctx, Uri uri) throws IOException, PwDbOutputException {
String errorMessage = "Failed to store database.";
if (uri.getScheme().equals("file")) {
String filename = uri.getPath();
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;
try {
fos = new FileOutputStream(tempFile);
PwDbOutput pmo = PwDbOutput.getInstance(pm, fos);
if (pmo != null)
pmo.output();
//bos.flush();
//bos.close();
} catch (Exception e) {
Log.e(TAG, errorMessage, e);
throw new IOException(errorMessage, e);
} finally {
if (fos != null)
fos.close();
}
// Force data to disk before continuing
try {
@@ -246,21 +245,24 @@ public class Database {
File orig = new File(filename);
if (!tempFile.renameTo(orig)) {
throw new IOException("Failed to store database.");
throw new IOException(errorMessage);
}
}
else {
OutputStream os;
OutputStream os = null;
try {
os = ctx.getContentResolver().openOutputStream(uri);
} catch (Exception e) {
throw new IOException("Failed to store database.");
}
PwDbOutput pmo = PwDbOutput.getInstance(pm, os);
if (pmo != null)
pmo.output();
} catch (Exception e) {
Log.e(TAG, errorMessage, e);
throw new IOException(errorMessage, e);
} finally {
if (os != null)
os.close();
}
}
mUri = uri;
}
@@ -348,16 +350,82 @@ 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) {
return getPwDatabase().getEncryptionAlgorithm().getName(resources);
}
public String getKeyDerivationName() {
return getPwDatabase().getKeyDerivationName();
public List<KdfEngine> getAvailableKdfEngines() {
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() {
KdfEngine kdfEngine = getPwDatabase().getKdfEngine();
if (kdfEngine == null)
return KdfFactory.aesKdf;
return kdfEngine;
}
public void assignKdfEngine(KdfEngine kdfEngine) {
switch (getPwDatabase().getVersion()) {
case V4:
PwDatabaseV4 db = ((PwDatabaseV4) getPwDatabase());
if (db.getKdfParameters() == null
|| !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() {
return Long.toString(getPwDatabase().getNumberKeyEncryptionRounds());
return Long.toString(getNumberKeyEncryptionRounds());
}
public long getNumberKeyEncryptionRounds() {
@@ -368,6 +436,44 @@ public class Database {
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) {
PwEntry newPwEntry = null;
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;
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.database.exception.InvalidKeyFileException;
import com.kunzisoft.keepass.database.exception.KeyFileEmptyException;
import com.kunzisoft.keepass.stream.NullOutputStream;
import com.kunzisoft.keepass.utils.Util;
import java.io.ByteArrayInputStream;
@@ -31,7 +29,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
@@ -100,39 +97,9 @@ public abstract class PwDatabase<PwGroupDB extends PwGroup<PwGroupDB, PwGroupDB,
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 void setMasterKey(String key, InputStream keyInputStream)
public void retrieveMasterKey(String key, InputStream keyInputStream)
throws InvalidKeyFileException, IOException {
masterKey = getMasterKey(key, keyInputStream);
}
@@ -280,7 +247,9 @@ public abstract class PwDatabase<PwGroupDB extends PwGroup<PwGroupDB, PwGroupDB,
this.algorithm = algorithm;
}
public abstract String getKeyDerivationName();
public abstract List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms();
public abstract KdfEngine getKdfEngine();
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;
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.stream.NullOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@@ -96,8 +103,15 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
}
@Override
public String getKeyDerivationName() {
return AesKdf.DEFAULT_NAME;
public KdfEngine getKdfEngine() {
return KdfFactory.aesKdf;
}
@Override
public List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms() {
List<PwEncryptionAlgorithm> list = new ArrayList<>();
list.add(PwEncryptionAlgorithm.AES_Rijndael);
return list;
}
@Override
@@ -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
protected String getPasswordEncoding() {
return "ISO-8859-1";
@@ -288,7 +331,6 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
// Add tree to root groups
groups.add(newGroup);
}
@Override

View File

@@ -66,9 +66,10 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
private UUID dataCipher = AesEngine.CIPHER_UUID;
private CipherEngine dataEngine = new AesEngine();
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";
private PwDate nameChanged = new PwDate();
private PwDate settingsChanged = new PwDate();
@@ -98,8 +99,6 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
private List<PwIconCustom> customIcons = new ArrayList<>();
private Map<String, String> customData = new HashMap<>();
private KdfParameters kdfParameters = KdfFactory.getDefaultParameters();
private VariantDictionary publicCustomData = new VariantDictionary();
private BinaryPool binPool = new BinaryPool();
public String localizedAppName = "KeePassDX"; // TODO resource
@@ -131,7 +130,15 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
public void setDataEngine(CipherEngine 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() {
@@ -142,6 +149,19 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
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
public long getNumberKeyEncryptionRounds() {
if (getKdfEngine() != null && getKdfParameters() != null)
@@ -156,6 +176,30 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
numKeyEncRounds = rounds;
}
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;
}
@@ -326,15 +370,6 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
this.customData.put(label, value);
}
public KdfEngine getKdfEngine() {
return kdfEngine;
}
@Override
public String getKeyDerivationName() {
return kdfEngine.getName();
}
@Override
public byte[] getMasterKey(String key, InputStream keyInputStream)
throws InvalidKeyFileException, IOException {
@@ -359,47 +394,25 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
return md.digest(fKey);
}
@Override
public void makeFinalKey(byte[] masterSeed, byte[] masterSeed2, long numRounds) throws IOException {
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) throws IOException {
makeFinalKey(masterSeed, 0);
}
public void makeFinalKey(byte[] masterSeed, KdfParameters kdfP, long roundsFix)
public void makeFinalKey(byte[] masterSeed, long roundsFix)
throws IOException {
kdfEngine = KdfFactory.get(kdfP.kdfUUID);
KdfEngine kdfEngine = KdfFactory.get(kdfParameters);
if (kdfEngine == null) {
throw new IOException("Unknown key derivation function");
}
// Set to 6000 rounds to open corrupted database
if (roundsFix > 0 && kdfP.kdfUUID.equals(AesKdf.CIPHER_UUID)) {
kdfP.setUInt32(AesKdf.ParamRounds, roundsFix);
if (roundsFix > 0 && kdfParameters.kdfUUID.equals(AesKdf.CIPHER_UUID)) {
kdfParameters.setUInt32(AesKdf.ParamRounds, roundsFix);
numKeyEncRounds = roundsFix;
}
byte[] transformedMasterKey = kdfEngine.transform(masterKey, kdfP);
byte[] transformedMasterKey = kdfEngine.transform(masterKey, kdfParameters);
if (transformedMasterKey.length != 32) {
transformedMasterKey = CryptoUtil.hashSha256(transformedMasterKey);
}
@@ -695,14 +708,6 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
return groups.get(recycleId);
}
public KdfParameters getKdfParameters() {
return kdfParameters;
}
public void setKdfParameters(KdfParameters kdfParameters) {
this.kdfParameters = kdfParameters;
}
public VariantDictionary getPublicCustomData() {
return publicCustomData;
}
@@ -739,8 +744,6 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
@Override
public void initNew(String dbPath) {
String filename = URLUtil.guessFileName(dbPath, null, null);
rootGroup = new PwGroupV4(dbNameFromPath(dbPath), iconFactory.getIcon(PwIconStandard.FOLDER));
groups.put(rootGroup.getId(), rootGroup);
}
@@ -759,64 +762,4 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
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;
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.database.exception.InvalidDBVersionException;
import com.kunzisoft.keepass.stream.CopyInputStream;
@@ -91,10 +92,81 @@ public class PwDbHeaderV4 extends PwDbHeader {
public CrsAlgorithm innerRandomStream;
public long version;
public PwDbHeaderV4(PwDatabaseV4 d) {
db = d;
version = d.getMinKdbxVersion();
masterSeed = new byte[32];
public PwDbHeaderV4(PwDatabaseV4 databaseV4) {
this.db = databaseV4;
this.version = getMinKdbxVersion(databaseV4); // Only for writing
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
@@ -122,7 +194,7 @@ public class PwDbHeaderV4 extends PwDbHeader {
throw new InvalidDBVersionException();
}
version = lis.readUInt();
version = lis.readUInt(); // Erase previous value
if ( ! validVersion(version) ) {
throw new InvalidDBVersionException();
}
@@ -173,24 +245,13 @@ public class PwDbHeaderV4 extends PwDbHeader {
break;
case PwDbHeaderV4Fields.TransformSeed:
assert(version < PwDbHeaderV4.FILE_VERSION_32_4); // TODO file > FILEVERSION
AesKdf kdfS = new AesKdf();
if (!db.getKdfParameters().kdfUUID.equals(kdfS.uuid)) {
db.setKdfParameters(kdfS.getDefaultParameters());
}
db.getKdfParameters().setByteArray(AesKdf.ParamSeed, fieldData);
if(version < PwDbHeaderV4.FILE_VERSION_32_4)
setTransformSeed(fieldData);
break;
case PwDbHeaderV4Fields.TransformRounds:
assert(version < PwDbHeaderV4.FILE_VERSION_32_4);
AesKdf kdfR = new AesKdf();
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);
if(version < PwDbHeaderV4.FILE_VERSION_32_4)
setTransformRound(fieldData);
break;
case PwDbHeaderV4Fields.EncryptionIV:
@@ -198,7 +259,7 @@ public class PwDbHeaderV4 extends PwDbHeader {
break;
case PwDbHeaderV4Fields.InnerRandomstreamKey:
assert(version < PwDbHeaderV4.FILE_VERSION_32_4);
if(version < PwDbHeaderV4.FILE_VERSION_32_4)
innerRandomStreamKey = fieldData;
break;
@@ -207,7 +268,7 @@ public class PwDbHeaderV4 extends PwDbHeader {
break;
case PwDbHeaderV4Fields.InnerRandomStreamID:
assert(version < PwDbHeaderV4.FILE_VERSION_32_4);
if(version < PwDbHeaderV4.FILE_VERSION_32_4)
setRandomStreamID(fieldData);
break;
@@ -225,6 +286,12 @@ public class PwDbHeaderV4 extends PwDbHeader {
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 {
if ( pbId == null || pbId.length != 16 ) {
throw new IOException("Invalid cipher ID.");
@@ -233,6 +300,18 @@ public class PwDbHeaderV4 extends PwDbHeader {
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 {
if ( pbFlags == null || pbFlags.length != 4 ) {
throw new IOException("Invalid compression flags.");
@@ -244,23 +323,6 @@ public class PwDbHeaderV4 extends PwDbHeader {
}
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 {
@@ -276,25 +338,22 @@ public class PwDbHeaderV4 extends PwDbHeader {
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
* arithmetic on it.
* @param version
* @return
* A long is needed here to represent the unsigned int since we perform arithmetic on it.
* @param version Database version
* @return true if it's a supported version
*/
private boolean validVersion(long version) {
return ! ((version & FILE_VERSION_CRITICAL_MASK) > (FILE_VERSION_32 & FILE_VERSION_CRITICAL_MASK));
}
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{
byte[] headerHmac;
byte[] blockKey = HmacBlockStream.GetHmacKey64(key, Types.ULONG_MAX_VALUE);
Mac hmac;
@@ -312,8 +371,7 @@ public class PwDbHeaderV4 extends PwDbHeader {
}
public byte[] getTransformSeed() {
assert(version < FILE_VERSION_32_4);
// version < FILE_VERSION_32_4)
return db.getKdfParameters().getByteArray(AesKdf.ParamSeed);
}
}

View File

@@ -22,8 +22,14 @@ package com.kunzisoft.keepass.database;
import android.content.res.Resources;
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,
Twofish,
@@ -33,11 +39,35 @@ public enum PwEncryptionAlgorithm {
switch (this) {
default:
case AES_Rijndael:
return resources.getString(R.string.rijndael);
return resources.getString(R.string.encryption_rijndael);
case Twofish:
return resources.getString(R.string.twofish);
return resources.getString(R.string.encryption_twofish);
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/>.
*
*/
package com.kunzisoft.keepass.database.edit;
package com.kunzisoft.keepass.database.action;
import android.content.Context;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwEntry;
public class AddEntry extends RunnableOnFinish {
public class AddEntryRunnable extends RunnableOnFinish {
protected Database mDb;
private PwEntry mEntry;
private Context ctx;
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);
}
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);
this.mDb = db;
@@ -51,13 +51,13 @@ public class AddEntry extends RunnableOnFinish {
mDb.addEntryTo(mEntry, mEntry.getParent());
// Commit to disk
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave);
SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave);
save.run();
}
private class AfterAdd extends OnFinish {
private class AfterAdd extends OnFinishRunnable {
AfterAdd(OnFinish finish) {
AfterAdd(OnFinishRunnable finish) {
super(finish);
}

View File

@@ -17,25 +17,25 @@
* 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 com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwGroup;
public class AddGroup extends RunnableOnFinish {
public class AddGroupRunnable extends RunnableOnFinish {
protected Database mDb;
private PwGroup mNewGroup;
private Context ctx;
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);
}
public AddGroup(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode,
public AddGroupRunnable(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode,
boolean dontSave) {
super(afterAddNode);
@@ -52,13 +52,13 @@ public class AddGroup extends RunnableOnFinish {
mDb.addGroupTo(mNewGroup, mNewGroup.getParent());
// Commit to disk
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave);
SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave);
save.run();
}
private class AfterAdd extends OnFinish {
private class AfterAdd extends OnFinishRunnable {
AfterAdd(OnFinish finish) {
AfterAdd(OnFinishRunnable finish) {
super(finish);
}

View File

@@ -17,13 +17,13 @@
* 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 com.kunzisoft.keepass.database.PwNode;
public abstract class AfterActionNodeOnFinish extends OnFinish {
public abstract class AfterActionNodeOnFinish extends OnFinishRunnable {
public AfterActionNodeOnFinish(Handler handler) {
super(handler);
}

View File

@@ -17,22 +17,20 @@
* 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.DialogInterface;
import android.net.Uri;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwDatabase;
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper;
import com.kunzisoft.keepass.utils.UriUtil;
import java.io.IOException;
import java.io.InputStream;
public class SetPassword extends RunnableOnFinish {
public class AssignPasswordInDBRunnable extends RunnableOnFinish {
private String mPassword;
private Uri mKeyfile;
@@ -40,12 +38,12 @@ public class SetPassword extends RunnableOnFinish {
private boolean mDontSave;
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);
}
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);
mDb = db;
@@ -55,16 +53,6 @@ public class SetPassword extends RunnableOnFinish {
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
public void run() {
PwDatabase pm = mDb.getPwDatabase();
@@ -75,7 +63,7 @@ public class SetPassword extends RunnableOnFinish {
// Set key
try {
InputStream is = UriUtil.getUriInputStream(ctx, mKeyfile);
pm.setMasterKey(mPassword, is);
pm.retrieveMasterKey(mPassword, is);
} catch (InvalidKeyFileException e) {
erase(backupKey);
finish(false, e.getMessage());
@@ -88,14 +76,14 @@ public class SetPassword extends RunnableOnFinish {
// Save Database
mFinish = new AfterSave(backupKey, mFinish);
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave);
SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave);
save.run();
}
private class AfterSave extends OnFinish {
private class AfterSave extends OnFinishRunnable {
private byte[] mBackup;
public AfterSave(byte[] backup, OnFinish finish) {
public AfterSave(byte[] backup, OnFinishRunnable finish) {
super(finish);
mBackup = backup;

View File

@@ -17,7 +17,7 @@
* 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;
@@ -26,13 +26,13 @@ import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwDatabase;
import com.kunzisoft.keepass.utils.UriUtil;
public class CreateDB extends RunnableOnFinish {
public class CreateDBRunnable extends RunnableOnFinish {
private String mFilename;
private boolean mDontSave;
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);
mFilename = filename;
@@ -56,7 +56,7 @@ public class CreateDB extends RunnableOnFinish {
App.clearShutdown();
// Commit changes
SaveDB save = new SaveDB(ctx, db, mFinish, mDontSave);
SaveDBRunnable save = new SaveDBRunnable(ctx, db, mFinish, mDontSave);
mFinish = null;
save.run();
}

View File

@@ -17,7 +17,7 @@
* 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;
@@ -29,18 +29,18 @@ import com.kunzisoft.keepass.database.PwGroup;
* @author bpellin
*
*/
public class DeleteEntry extends RunnableOnFinish {
public class DeleteEntryRunnable extends RunnableOnFinish {
private Database mDb;
private PwEntry mEntry;
private boolean mDontSave;
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);
}
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);
this.mDb = db;
@@ -67,17 +67,17 @@ public class DeleteEntry extends RunnableOnFinish {
mFinish = new AfterDelete(mFinish, parent, mEntry, recycle);
// Commit database
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave);
SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave);
save.run();
}
private class AfterDelete extends OnFinish {
private class AfterDelete extends OnFinishRunnable {
private PwGroup mParent;
private PwEntry mEntry;
private boolean recycled;
AfterDelete(OnFinish finish, PwGroup parent, PwEntry entry, boolean r) {
AfterDelete(OnFinishRunnable finish, PwGroup parent, PwEntry entry, boolean r) {
super(finish);
mParent = parent;

View File

@@ -17,7 +17,7 @@
* 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;
@@ -29,19 +29,19 @@ import com.kunzisoft.keepass.database.PwGroup;
import java.util.ArrayList;
import java.util.List;
public class DeleteGroup extends RunnableOnFinish {
public class DeleteGroupRunnable extends RunnableOnFinish {
private Context mContext;
private Database mDb;
private PwGroup<PwGroup, PwGroup, PwEntry> mGroup;
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);
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);
setMembers(ctx, db, group, dontSave);
}
@@ -67,14 +67,14 @@ public class DeleteGroup extends RunnableOnFinish {
// Remove child entries
List<PwEntry> childEnt = new ArrayList<>(mGroup.getChildEntries()); // TODO new Methods
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();
}
// Remove child groups
List<PwGroup> childGrp = new ArrayList<>(mGroup.getChildGroups());
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();
}
mDb.deleteGroup(mGroup);
@@ -88,17 +88,17 @@ public class DeleteGroup extends RunnableOnFinish {
mFinish = new AfterDelete(mFinish, parent, mGroup, recycle);
// Commit Database
SaveDB save = new SaveDB(mContext, mDb, mFinish, mDontSave);
SaveDBRunnable save = new SaveDBRunnable(mContext, mDb, mFinish, mDontSave);
save.run();
}
private class AfterDelete extends OnFinish {
private class AfterDelete extends OnFinishRunnable {
private PwGroup mParent;
private PwGroup mGroup;
private boolean recycled;
AfterDelete(OnFinish finish, PwGroup parent, PwGroup mGroup, boolean recycle) {
AfterDelete(OnFinishRunnable finish, PwGroup parent, PwGroup mGroup, boolean recycle) {
super(finish);
this.mParent = parent;

View File

@@ -17,17 +17,17 @@
* 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 java.io.Serializable;
public class FileOnFinish extends OnFinish implements Serializable {
public class FileOnFinishRunnable extends OnFinishRunnable implements Serializable {
private Uri mFilename = null;
protected FileOnFinish mOnFinish;
protected FileOnFinishRunnable mOnFinish;
public FileOnFinish(FileOnFinish finish) {
public FileOnFinishRunnable(FileOnFinishRunnable finish) {
super(finish);
mOnFinish = finish;

View File

@@ -17,12 +17,14 @@
* 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.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.support.annotation.StringRes;
import android.util.Log;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.app.App;
@@ -40,7 +42,9 @@ import com.kunzisoft.keepass.database.exception.KeyFileEmptyException;
import java.io.FileNotFoundException;
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 String mPass;
private Uri mKey;
@@ -48,7 +52,7 @@ public class LoadDB extends RunnableOnFinish {
private Context mCtx;
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);
mDb = db;
@@ -69,42 +73,46 @@ public class LoadDB extends RunnableOnFinish {
saveFileData(mUri, mKey);
} catch (ArcFourException e) {
finish(false, mCtx.getString(R.string.error_arc4));
catchError(e, R.string.error_arc4);
return;
} catch (InvalidPasswordException e) {
finish(false, mCtx.getString(R.string.InvalidPassword));
catchError(e, R.string.InvalidPassword);
return;
} catch (ContentFileNotFoundException e) {
finish(false, mCtx.getString(R.string.file_not_found_content));
catchError(e, R.string.file_not_found_content);
return;
} catch (FileNotFoundException e) {
finish(false, mCtx.getString(R.string.file_not_found));
catchError(e, R.string.file_not_found);
return;
} catch (IOException e) {
Log.e(TAG, "Database can't be read", e);
finish(false, e.getMessage());
return;
} catch (KeyFileEmptyException e) {
finish(false, mCtx.getString(R.string.keyfile_is_empty));
catchError(e, R.string.keyfile_is_empty);
return;
} catch (InvalidAlgorithmException e) {
finish(false, mCtx.getString(R.string.invalid_algorithm));
catchError(e, R.string.invalid_algorithm);
return;
} catch (InvalidKeyFileException e) {
finish(false, mCtx.getString(R.string.keyfile_does_not_exist));
catchError(e, R.string.keyfile_does_not_exist);
return;
} catch (InvalidDBSignatureException e) {
finish(false, mCtx.getString(R.string.invalid_db_sig));
catchError(e, R.string.invalid_db_sig);
return;
} catch (InvalidDBVersionException e) {
finish(false, mCtx.getString(R.string.unsupported_db_version));
catchError(e, R.string.unsupported_db_version);
return;
} catch (InvalidDBException e) {
finish(false, mCtx.getString(R.string.error_invalid_db));
catchError(e, R.string.error_invalid_db);
return;
} 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;
} catch (Exception e) {
Log.e(TAG, "Database can't be load", e);
finish(false, e.getMessage());
return;
}
@@ -112,6 +120,12 @@ public class LoadDB extends RunnableOnFinish {
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) {
if ( ! mRememberKeyfile ) {
key = null;

View File

@@ -17,7 +17,7 @@
* 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.os.Handler;
@@ -29,27 +29,27 @@ import android.widget.Toast;
* @author bpellin
*
*/
public class OnFinish implements Runnable {
public class OnFinishRunnable implements Runnable {
protected boolean mSuccess;
protected String mMessage;
protected OnFinish mOnFinish;
protected OnFinishRunnable mOnFinish;
protected Handler mHandler;
public OnFinish() {
public OnFinishRunnable() {
}
public OnFinish(Handler handler) {
public OnFinishRunnable(Handler handler) {
mOnFinish = null;
mHandler = handler;
}
public OnFinish(OnFinish finish, Handler handler) {
public OnFinishRunnable(OnFinishRunnable finish, Handler handler) {
mOnFinish = finish;
mHandler = handler;
}
public OnFinish(OnFinish finish) {
public OnFinishRunnable(OnFinishRunnable finish) {
mOnFinish = finish;
mHandler = null;
}
@@ -76,6 +76,7 @@ public class OnFinish implements Runnable {
}
}
// TODO Move
protected void displayMessage(Context ctx) {
if ( mMessage != null && mMessage.length() > 0 ) {
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/>.
*
*/
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 OnFinish mFinish;
public UpdateStatus mStatus;
public OnFinishRunnable mFinish;
public ProgressTaskUpdater mStatus;
public RunnableOnFinish(OnFinish finish) {
public RunnableOnFinish(OnFinishRunnable 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;
}

View File

@@ -17,7 +17,7 @@
* 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;
@@ -26,25 +26,22 @@ import com.kunzisoft.keepass.database.exception.PwDbOutputException;
import java.io.IOException;
public class SaveDB extends RunnableOnFinish {
public class SaveDBRunnable extends RunnableOnFinish {
private Context mCtx;
private Database mDb;
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);
mDb = db;
mDontSave = dontSave;
mCtx = ctx;
this.mDb = db;
this.mDontSave = dontSave;
this.mCtx = ctx;
}
public SaveDB(Context ctx, Database db, OnFinish finish) {
super(finish);
mDb = db;
mDontSave = false;
mCtx = ctx;
public SaveDBRunnable(Context ctx, Database db, OnFinishRunnable finish) {
this(ctx, db, finish, false);
}
@Override

View File

@@ -17,14 +17,14 @@
* 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 com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwEntry;
public class UpdateEntry extends RunnableOnFinish {
public class UpdateEntryRunnable extends RunnableOnFinish {
private Database mDb;
private PwEntry mOldE;
@@ -32,11 +32,11 @@ public class UpdateEntry extends RunnableOnFinish {
private Context ctx;
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);
}
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);
this.mDb = db;
@@ -59,14 +59,14 @@ public class UpdateEntry extends RunnableOnFinish {
mOldE.touch(true, true);
// Commit to disk
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave);
SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave);
save.run();
}
private class AfterUpdate extends OnFinish {
private class AfterUpdate extends OnFinishRunnable {
private PwEntry mBackup;
AfterUpdate(PwEntry backup, OnFinish finish) {
AfterUpdate(PwEntry backup, OnFinishRunnable finish) {
super(finish);
mBackup = backup;
}

View File

@@ -17,14 +17,14 @@
* 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 com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwGroup;
public class UpdateGroup extends RunnableOnFinish {
public class UpdateGroupRunnable extends RunnableOnFinish {
private Database mDb;
private PwGroup mOldGroup;
@@ -32,11 +32,11 @@ public class UpdateGroup extends RunnableOnFinish {
private Context ctx;
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);
}
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);
this.mDb = db;
@@ -59,13 +59,13 @@ public class UpdateGroup extends RunnableOnFinish {
mOldGroup.touch(true, true);
// 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;
AfterUpdate(PwGroup backup, OnFinish finish) {
AfterUpdate(PwGroup backup, OnFinishRunnable finish) {
super(finish);
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.exception.InvalidDBException;
import com.kunzisoft.keepass.tasks.UpdateStatus;
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
import java.io.IOException;
import java.io.InputStream;
@@ -33,8 +33,7 @@ public abstract class Importer {
public abstract PwDatabase openDatabase(InputStream inStream, String password, InputStream keyInputStream)
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;
}

View File

@@ -28,13 +28,11 @@ import java.io.IOException;
import java.io.InputStream;
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);
}
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 sig2 = LEDataInputStream.readInt(is);
@@ -49,6 +47,5 @@ public class ImporterFactory {
}
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.InvalidPasswordException;
import com.kunzisoft.keepass.stream.LEDataInputStream;
import com.kunzisoft.keepass.stream.LEDataOutputStream;
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 java.io.IOException;
@@ -124,22 +123,22 @@ public class ImporterV3 extends Importer {
* @throws InvalidAlgorithmParameterException if error decrypting main file body.
* @throws ShortBufferException if error decrypting main file body.
*/
@Override
public PwDatabaseV3 openDatabase( InputStream inStream, String password, InputStream kfIs)
throws IOException, InvalidDBException
{
return openDatabase(inStream, password, kfIs, new UpdateStatus(), 0);
throws IOException, InvalidDBException {
return openDatabase(inStream, password, kfIs, null, 0);
}
public PwDatabaseV3 openDatabase( InputStream inStream, String password, InputStream kfIs, UpdateStatus status, long roundsFix)
throws IOException, InvalidDBException
{
PwDatabaseV3 newManager;
@Override
public PwDatabaseV3 openDatabase(InputStream inStream, String password, InputStream kfIs, ProgressTaskUpdater progressTaskUpdater, long roundsFix)
throws IOException, InvalidDBException {
PwDatabaseV3 databaseToOpen;
// Load entire file, most of it's encrypted.
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
inStream.read(filebuf, 0, fileSize);
inStream.read(filebuf, 0, fileSize); // TODO remove
inStream.close();
// Parse header (unencrypted)
@@ -156,34 +155,36 @@ public class ImporterV3 extends Importer {
throw new InvalidDBVersionException();
}
status.updateMessage(R.string.creating_db_key);
newManager = createDB();
newManager.setMasterKey(password, kfIs);
if (progressTaskUpdater != null)
progressTaskUpdater.updateMessage(R.string.creating_db_key);
databaseToOpen = createDB();
databaseToOpen.retrieveMasterKey(password, kfIs);
// Select algorithm
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 ) {
newManager.setEncryptionAlgorithm(PwEncryptionAlgorithm.Twofish);
databaseToOpen.setEncryptionAlgorithm(PwEncryptionAlgorithm.Twofish);
} else {
throw new InvalidAlgorithmException();
}
// Copy for testing
newManager.copyHeader(hdr);
databaseToOpen.copyHeader(hdr);
newManager.setNumberKeyEncryptionRounds(hdr.numKeyEncRounds);
databaseToOpen.setNumberKeyEncryptionRounds(hdr.numKeyEncRounds);
// 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
Cipher cipher;
try {
if ( newManager.getEncryptionAlgorithm() == PwEncryptionAlgorithm.AES_Rijndael) {
if ( databaseToOpen.getEncryptionAlgorithm() == PwEncryptionAlgorithm.AES_Rijndael) {
cipher = CipherFactory.getInstance("AES/CBC/PKCS5Padding");
} else if ( newManager.getEncryptionAlgorithm() == PwEncryptionAlgorithm.Twofish ) {
} else if ( databaseToOpen.getEncryptionAlgorithm() == PwEncryptionAlgorithm.Twofish ) {
cipher = CipherFactory.getInstance("Twofish/CBC/PKCS7PADDING");
} else {
throw new IOException( "Encryption algorithm is not supported" );
@@ -196,7 +197,7 @@ public class ImporterV3 extends Importer {
}
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) {
throw new IOException("Invalid key");
} catch (InvalidAlgorithmParameterException e1) {
@@ -216,7 +217,7 @@ public class ImporterV3 extends Importer {
}
// Copy decrypted data for testing
newManager.copyEncrypted(filebuf, PwDbHeaderV3.BUF_SIZE, encryptedPartSize);
databaseToOpen.copyEncrypted(filebuf, PwDbHeaderV3.BUF_SIZE, encryptedPartSize);
MessageDigest md = null;
try {
@@ -249,13 +250,13 @@ public class ImporterV3 extends Importer {
if( fieldType == 0xFFFF ) {
// End-Group record. Save group and count it.
newGrp.populateBlankFields(newManager);
newManager.addGroup(newGrp);
newGrp.populateBlankFields(databaseToOpen);
databaseToOpen.addGroup(newGrp);
newGrp = new PwGroupV3();
i++;
}
else {
readGroupField(newManager, newGrp, fieldType, filebuf, pos);
readGroupField(databaseToOpen, newGrp, fieldType, filebuf, pos);
}
pos += fieldSize;
}
@@ -268,65 +269,22 @@ public class ImporterV3 extends Importer {
if( fieldType == 0xFFFF ) {
// End-Group record. Save group and count it.
newEnt.populateBlankFields(newManager);
newManager.addEntry(newEnt);
newEnt.populateBlankFields(databaseToOpen);
databaseToOpen.addEntry(newEnt);
newEnt = new PwEntryV3();
i++;
}
else {
readEntryField(newManager, newEnt, filebuf, pos);
readEntryField(databaseToOpen, newEnt, filebuf, pos);
}
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.
* @param buf
@@ -334,7 +292,7 @@ public class ImporterV3 extends Importer {
* @return If >0,
* @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 ) {
case 0x0000 :
// Ignore field
@@ -371,9 +329,7 @@ public class ImporterV3 extends Importer {
void readEntryField(PwDatabaseV3 db, PwEntryV3 ent, byte[] buf, int offset)
throws UnsupportedEncodingException
{
private void readEntryField(PwDatabaseV3 db, PwEntryV3 ent, byte[] buf, int offset) throws UnsupportedEncodingException {
int fieldType = LEDataInputStream.readUShort(buf, offset);
offset += 2;
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.exception.InvalidDBException;
import com.kunzisoft.keepass.tasks.UpdateStatus;
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
import java.io.IOException;
import java.io.InputStream;
@@ -35,7 +35,7 @@ public class ImporterV3Debug extends ImporterV3 {
@Override
public PwDatabaseV3Debug openDatabase(InputStream inStream, String password,
InputStream keyInputStream, UpdateStatus status, long roundsFix) throws IOException,
InputStream keyInputStream, ProgressTaskUpdater status, long roundsFix) throws IOException,
InvalidDBException {
return (PwDatabaseV3Debug) super.openDatabase(inStream, password, keyInputStream, status,
roundsFix);

View File

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

View File

@@ -55,7 +55,7 @@ public class PwDbHeaderOutputV4 extends PwDbHeaderOutput {
db = d;
header = h;
MessageDigest md = null;
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
@@ -63,7 +63,7 @@ public class PwDbHeaderOutputV4 extends PwDbHeaderOutput {
}
try {
d.makeFinalKey(header.masterSeed, d.getKdfParameters());
d.makeFinalKey(header.masterSeed);
} catch (IOException e) {
throw new PwDbOutputException(e);
}
@@ -88,14 +88,14 @@ public class PwDbHeaderOutputV4 extends PwDbHeaderOutput {
los.writeUInt(PwDbHeader.PWM_DBSIG_1);
los.writeUInt(PwDbHeaderV4.DBSIG_2);
los.writeUInt(header.version);
los.writeUInt(header.getVersion());
writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.CipherID, Types.UUIDtoBytes(db.getDataCipher()));
writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.CompressionFlags, LEDataOutputStream.writeIntBuf(db.getCompressionAlgorithm().id));
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.TransformRounds, LEDataOutputStream.writeLongBuf(db.getNumberKeyEncryptionRounds()));
} else {
@@ -106,7 +106,7 @@ public class PwDbHeaderOutputV4 extends PwDbHeaderOutput {
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.StreamStartBytes, header.streamStartBytes);
writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.InnerRandomStreamID, LEDataOutputStream.writeIntBuf(header.innerRandomStream.id));
@@ -139,7 +139,7 @@ public class PwDbHeaderOutputV4 extends PwDbHeaderOutput {
}
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);
} else {
los.writeInt(size);

View File

@@ -29,7 +29,7 @@ import java.io.OutputStream;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
public abstract class PwDbOutput {
public abstract class PwDbOutput<Header extends PwDbHeader> {
protected OutputStream mOS;
@@ -47,7 +47,7 @@ public abstract class PwDbOutput {
mOS = os;
}
protected SecureRandom setIVs(PwDbHeader header) throws PwDbOutputException {
protected SecureRandom setIVs(Header header) throws PwDbOutputException {
SecureRandom random;
try {
random = SecureRandom.getInstance("SHA1PRNG");
@@ -62,6 +62,6 @@ public abstract class PwDbOutput {
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.SecretKeySpec;
public class PwDbV3Output extends PwDbOutput {
public class PwDbV3Output extends PwDbOutput<PwDbHeaderV3> {
private PwDatabaseV3 mPM;
private byte[] headerHashBlock;
@@ -111,15 +111,13 @@ public class PwDbV3Output extends PwDbOutput {
}
@Override
protected SecureRandom setIVs(PwDbHeader header) throws PwDbOutputException {
protected SecureRandom setIVs(PwDbHeaderV3 header) throws PwDbOutputException {
SecureRandom random = super.setIVs(header);
PwDbHeaderV3 h3 = (PwDbHeaderV3) header;
random.nextBytes(h3.transformSeed);
random.nextBytes(header.transformSeed);
return random;
}
@Override
public PwDbHeaderV3 outputHeader(OutputStream os) throws PwDbOutputException {
// Build header
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.PwDatabaseV3Debug;
import com.kunzisoft.keepass.database.PwDbHeader;
import com.kunzisoft.keepass.database.PwDbHeaderV3;
import com.kunzisoft.keepass.database.exception.PwDbOutputException;
@@ -32,10 +31,6 @@ public class PwDbV3OutputDebug extends PwDbV3Output {
PwDatabaseV3Debug debugDb;
private boolean noHeaderHash;
public PwDbV3OutputDebug(PwDatabaseV3 pm, OutputStream os) {
this(pm, os, false);
}
public PwDbV3OutputDebug(PwDatabaseV3 pm, OutputStream os, boolean noHeaderHash) {
super(pm, os);
debugDb = (PwDatabaseV3Debug) pm;
@@ -43,10 +38,7 @@ public class PwDbV3OutputDebug extends PwDbV3Output {
}
@Override
protected SecureRandom setIVs(PwDbHeader h) throws PwDbOutputException {
PwDbHeaderV3 header = (PwDbHeaderV3) h;
protected SecureRandom setIVs(PwDbHeaderV3 header) throws PwDbOutputException {
// Reuse random values to test equivalence in debug mode
PwDbHeaderV3 origHeader = debugDb.getDbHeader();
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.PwDatabaseV4;
import com.kunzisoft.keepass.database.PwDatabaseV4XML;
import com.kunzisoft.keepass.database.PwDbHeader;
import com.kunzisoft.keepass.database.PwDbHeaderV4;
import com.kunzisoft.keepass.database.PwDefsV4;
import com.kunzisoft.keepass.database.PwDeletedObject;
@@ -74,9 +73,9 @@ import javax.crypto.CipherOutputStream;
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 XmlSerializer xml;
private PwDbHeaderV4 header;
@@ -86,8 +85,7 @@ public class PwDbV4Output extends PwDbOutput {
protected PwDbV4Output(PwDatabaseV4 pm, OutputStream os) {
super(os);
mPM = pm;
this.mPM = pm;
}
@Override
@@ -100,15 +98,14 @@ public class PwDbV4Output extends PwDbOutput {
throw new PwDbOutputException("No such cipher", e);
}
header = (PwDbHeaderV4) outputHeader(mOS);
header = outputHeader(mOS);
OutputStream osPlain;
if (header.version < PwDbHeaderV4.FILE_VERSION_32_4) {
if (header.getVersion() < PwDbHeaderV4.FILE_VERSION_32_4) {
CipherOutputStream cos = attachStreamEncryptor(header, mOS);
cos.write(header.streamStartBytes);
HashedBlockOutputStream hashed = new HashedBlockOutputStream(cos);
osPlain = hashed;
osPlain = new HashedBlockOutputStream(cos);
} else {
mOS.write(hashOfHeader);
mOS.write(headerHmac);
@@ -125,7 +122,7 @@ public class PwDbV4Output extends PwDbOutput {
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);
ihOut.output();
}
@@ -261,7 +258,7 @@ public class PwDbV4Output extends PwDbOutput {
writeObject(PwDatabaseV4XML.ElemLastSelectedGroup, mPM.getLastSelectedGroup());
writeObject(PwDatabaseV4XML.ElemLastTopVisibleGroup, mPM.getLastTopVisibleGroup());
if (header.version < PwDbHeaderV4.FILE_VERSION_32_4) {
if (header.getVersion() < PwDbHeaderV4.FILE_VERSION_32_4) {
writeBinPool();
}
writeList(PwDatabaseV4XML.ElemCustomData, mPM.getCustomData());
@@ -286,45 +283,46 @@ public class PwDbV4Output extends PwDbOutput {
}
@Override
protected SecureRandom setIVs(PwDbHeader header) throws PwDbOutputException {
protected SecureRandom setIVs(PwDbHeaderV4 header) throws PwDbOutputException {
SecureRandom random = super.setIVs(header);
PwDbHeaderV4 h = (PwDbHeaderV4) header;
random.nextBytes(h.masterSeed);
random.nextBytes(header.masterSeed);
int ivLength = engine.ivLength();
if (ivLength != h.encryptionIV.length) {
h.encryptionIV = new byte[ivLength];
if (ivLength != header.encryptionIV.length) {
header.encryptionIV = new byte[ivLength];
}
random.nextBytes(h.encryptionIV);
random.nextBytes(header.encryptionIV);
UUID kdfUUID = mPM.getKdfParameters().kdfUUID;
KdfEngine kdf = KdfFactory.get(kdfUUID);
if (mPM.getKdfParameters() == null) {
mPM.setKdfParameters(KdfFactory.aesKdf.getDefaultParameters());
}
KdfEngine kdf = KdfFactory.get(mPM.getKdfParameters());
kdf.randomize(mPM.getKdfParameters());
if (h.version < PwDbHeaderV4.FILE_VERSION_32_4) {
h.innerRandomStream = CrsAlgorithm.Salsa20;
h.innerRandomStreamKey = new byte[32];
if (header.getVersion() < PwDbHeaderV4.FILE_VERSION_32_4) {
header.innerRandomStream = CrsAlgorithm.Salsa20;
header.innerRandomStreamKey = new byte[32];
} else {
h.innerRandomStream = CrsAlgorithm.ChaCha20;
h.innerRandomStreamKey = new byte[64];
header.innerRandomStream = CrsAlgorithm.ChaCha20;
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) {
throw new PwDbOutputException("Invalid random cipher");
}
if ( h.version < PwDbHeaderV4.FILE_VERSION_32_4) {
random.nextBytes(h.streamStartBytes);
if ( header.getVersion() < PwDbHeaderV4.FILE_VERSION_32_4) {
random.nextBytes(header.streamStartBytes);
}
return random;
}
@Override
public PwDbHeader outputHeader(OutputStream os) throws PwDbOutputException {
public PwDbHeaderV4 outputHeader(OutputStream os) throws PwDbOutputException {
PwDbHeaderV4 header = new PwDbHeaderV4(mPM);
setIVs(header);
@@ -468,7 +466,7 @@ public class PwDbV4Output extends PwDbOutput {
}
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));
} else {
DateTime dt = new DateTime(value);

View File

@@ -35,11 +35,13 @@ import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import com.kunzisoft.keepass.R;
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);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
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();

View File

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

View File

@@ -44,9 +44,16 @@ public class UnderDevelopmentFeatureDialogFragment extends DialogFragment {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
stringBuilder.append(Html.fromHtml(getString(R.string.html_text_dev_feature))).append("\n\n");
if (BuildConfig.CLOSED_STORE) {
stringBuilder.append(Html.fromHtml(getString(R.string.html_text_dev_feature_buy_pro))).append(" ")
if (BuildConfig.FULL_VERSION) {
stringBuilder.append(Html.fromHtml(getString(R.string.html_text_dev_feature_thanks))).append("\n\n")
.append(Html.fromHtml(getString(R.string.html_rose))).append("\n\n")
.append(Html.fromHtml(getString(R.string.html_text_dev_feature_work_hard))).append("\n")
.append(Html.fromHtml(getString(R.string.html_text_dev_feature_upgrade))).append(" ");
builder.setPositiveButton(android.R.string.ok, (dialog, id) -> dismiss());
} 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 {
@@ -55,20 +62,23 @@ public class UnderDevelopmentFeatureDialogFragment extends DialogFragment {
Toast.makeText(getContext(), R.string.error_failed_to_launch_link, Toast.LENGTH_LONG).show();
}
});
builder.setNegativeButton(android.R.string.cancel, (dialog, id) -> dismiss());
}
}
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_contibute))).append(" ")
.append(Html.fromHtml(getString(R.string.html_text_dev_feature_encourage)));
builder.setPositiveButton(R.string.contribute, (dialog, id) -> {
try {
Util.gotoUrl(getContext(), R.string.donate_url);
Util.gotoUrl(getContext(), R.string.contribution_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());
}
builder.setMessage(stringBuilder);
builder.setNegativeButton(android.R.string.cancel, (dialog, id) -> dismiss());
// Create the AlertDialog object and return it
return builder.create();
}

View File

@@ -62,6 +62,8 @@ public class FilePickerStylishActivity extends FilePickerActivity {
return R.style.KeepassDXStyle_FilePickerStyle_Dark;
else if (themeString.equals(context.getString(R.string.list_style_name_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)))
return R.style.KeepassDXStyle_FilePickerStyle_Purple;

View File

@@ -24,6 +24,7 @@ import android.app.Activity;
import android.app.assist.AssistStructure;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@@ -50,8 +51,8 @@ import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.activities.GroupActivity;
import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.autofill.AutofillHelper;
import com.kunzisoft.keepass.database.edit.CreateDB;
import com.kunzisoft.keepass.database.edit.FileOnFinish;
import com.kunzisoft.keepass.database.action.CreateDBRunnable;
import com.kunzisoft.keepass.database.action.FileOnFinishRunnable;
import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException;
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
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.settings.PreferencesUtil;
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.MenuUtil;
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_summary))
.icon(ContextCompat.getDrawable(this, R.drawable.ic_database_plus_white_24dp))
.textColorInt(Color.WHITE)
.tintTarget(true)
.cancelable(true),
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_summary))
.icon(ContextCompat.getDrawable(this, R.drawable.ic_folder_white_24dp))
.textColorInt(Color.WHITE)
.tintTarget(true)
.cancelable(true),
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_summary))
.icon(ContextCompat.getDrawable(FileSelectActivity.this, R.drawable.ic_link_white_24dp))
.textColorInt(Color.WHITE)
.tintTarget(true)
.cancelable(true),
new TapTargetView.Listener() {
@@ -511,22 +516,26 @@ public class FileSelectActivity extends StylishActivity implements
// Prep an object to collect a password once the database has
// been created
FileOnFinish launchActivityOnFinish = new FileOnFinish(
FileOnFinishRunnable launchActivityOnFinish = new FileOnFinishRunnable(
new LaunchGroupActivity(databaseFilename));
AssignPasswordOnFinish assignPasswordOnFinish =
new AssignPasswordOnFinish(launchActivityOnFinish);
// Create the new database
CreateDB create = new CreateDB(FileSelectActivity.this,
databaseFilename, assignPasswordOnFinish, true);
ProgressTask createTask = new ProgressTask(
FileSelectActivity.this, create,
R.string.progress_create);
createTask.run();
// Initialize the password helper assigner to set the password after the database creation
assignPasswordHelper = new AssignPasswordHelper(this,
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) {
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);
}
@Override
public void run() {
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;
LaunchGroupActivity(String filename) {

View File

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

View File

@@ -131,7 +131,7 @@ public class FingerPrintHelper {
return isFingerprintInitialized(true);
}
public boolean isFingerprintInitialized(boolean throwException) {
private boolean isFingerprintInitialized(boolean throwException) {
boolean isFingerprintInit = hasEnrolledFingerprints() && initOk;
if (!isFingerprintInit && fingerPrintCallback != null) {
if(throwException)
@@ -336,7 +336,7 @@ public class FingerPrintHelper {
}
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.support.v4.content.ContextCompat;
import android.support.v4.widget.ImageViewCompat;
import android.util.Log;
import android.widget.ImageView;
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
*/
public class IconDrawableFactory {
private static final String TAG = IconDrawableFactory.class.getName();
private static Drawable blank = null;
private static int blankWidth = -1;
private static int blankHeight = -1;
@@ -236,12 +240,22 @@ public class IconDrawableFactory {
Drawable draw = (Drawable) standardIconMap.get(newCacheKey);
if (draw == null) {
try {
draw = ContextCompat.getDrawable(context, iconId);
} catch (Exception e) {
Log.e(TAG, "Can't get icon", e);
}
if (draw != null) {
standardIconMap.put(newCacheKey, draw);
}
}
if (draw == null) {
if (blank == null)
initBlank(context.getResources());
draw = blank;
}
return draw;
}

View File

@@ -19,25 +19,30 @@
*/
package com.kunzisoft.keepass.password;
import android.content.Context;
import android.net.Uri;
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.database.edit.FileOnFinish;
import com.kunzisoft.keepass.database.edit.OnFinish;
import com.kunzisoft.keepass.database.edit.SetPassword;
import com.kunzisoft.keepass.tasks.ProgressTask;
import com.kunzisoft.keepass.database.action.AssignPasswordInDBRunnable;
import com.kunzisoft.keepass.database.action.FileOnFinishRunnable;
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
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 {
private Context context;
private AppCompatActivity context;
private String masterPassword = null;
private Uri keyfile = null;
public AssignPasswordHelper(Context context,
private boolean createProgressDialog;
public AssignPasswordHelper(AppCompatActivity context,
boolean withMasterPassword,
String masterPassword,
boolean withKeyFile,
@@ -47,36 +52,66 @@ public class AssignPasswordHelper {
this.masterPassword = masterPassword;
if (withKeyFile)
this.keyfile = keyfile;
createProgressDialog = true;
}
public void assignPasswordInDatabase(FileOnFinish fileOnFinish) {
SetPassword sp = new SetPassword(context, App.getDB(), masterPassword, keyfile, new AfterSave(fileOnFinish, new Handler()));
final ProgressTask pt = new ProgressTask(context, sp, R.string.saving_database);
boolean valid = sp.validatePassword(context, (dialog, which) -> pt.run());
public void setCreateProgressDialog(boolean createProgressDialog) {
this.createProgressDialog = createProgressDialog;
}
if (valid) {
pt.run();
public void assignPasswordInDatabase(FileOnFinishRunnable fileOnFinish) {
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 FileOnFinish mFinish;
private class AfterSave extends OnFinishRunnable {
private FileOnFinishRunnable mFinish;
public AfterSave(FileOnFinish finish, Handler handler) {
AfterSave(FileOnFinishRunnable finish, Handler handler) {
super(finish, handler);
mFinish = finish;
}
@Override
public void run() {
super.run();
context.runOnUiThread(() -> {
if ( mSuccess ) {
if ( mFinish != null ) {
mFinish.setFilename(keyfile);
}
} else {
displayMessage(context);
if ( mMessage != null && mMessage.length() > 0 ) {
Toast.makeText(context, mMessage, Toast.LENGTH_LONG).show();
}
super.run();
}
// To remove progress task
ProgressTaskDialogFragment.stop(context);
});
}
}
}

View File

@@ -24,6 +24,7 @@ import android.app.Activity;
import android.app.assist.AssistStructure;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri;
import android.os.AsyncTask;
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.EditorCompat;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.edit.LoadDB;
import com.kunzisoft.keepass.database.edit.OnFinish;
import com.kunzisoft.keepass.database.action.LoadDBRunnable;
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper;
import com.kunzisoft.keepass.fileselect.KeyFileHelper;
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.settings.PreferencesUtil;
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.MenuUtil;
import com.kunzisoft.keepass.utils.UriUtil;
@@ -289,6 +291,7 @@ public class PasswordActivity extends StylishActivity
fingerprintTextView = findViewById(R.id.fingerprint_label);
fingerprintImageView = findViewById(R.id.fingerprint_image);
initForFingerprint();
// Init the fingerprint animation
fingerPrintAnimatedVector = new FingerPrintAnimatedVector(this,
fingerprintImageView);
}
@@ -320,6 +323,19 @@ public class PasswordActivity extends StylishActivity
// For check shutdown
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)
.execute(getIntent());
}
@@ -337,6 +353,7 @@ public class PasswordActivity extends StylishActivity
getString(R.string.education_unlock_summary))
.dimColor(R.color.green)
.icon(ContextCompat.getDrawable(this, R.mipmap.ic_launcher_round))
.textColorInt(Color.WHITE)
.tintTarget(false)
.cancelable(true),
new TapTargetView.Listener() {
@@ -369,6 +386,7 @@ public class PasswordActivity extends StylishActivity
TapTarget.forView(fingerprintImageView,
getString(R.string.education_fingerprint_title),
getString(R.string.education_fingerprint_summary))
.textColorInt(Color.WHITE)
.tintTarget(false)
.cancelable(true),
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
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
checkFingerprintAvailability();
if (fingerPrintAnimatedVector != null) {
fingerPrintAnimatedVector.startScan();
}
}
// If Activity is launch with a password and want to open directly
@@ -483,34 +498,20 @@ public class PasswordActivity extends StylishActivity
fingerPrintHelper = new FingerPrintHelper(this, this);
// when text entered we can enable the logon/purchase button and if required update encryption/decryption mode
passwordView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(
final CharSequence s,
final int start,
final int count,
final int after) {}
@Override
public void onTextChanged(
final CharSequence s,
final int start,
final int before,
final int count) {}
@Override
public void afterTextChanged(final Editable s) {
checkboxPasswordView.setOnCheckedChangeListener((compoundButton, checked) -> {
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)
if (checked) {
toggleFingerprintMode(FingerPrintHelper.Mode.STORE_MODE);
else
} else {
if (!prefsNoBackup.contains(getPreferenceKeyValue())) {
// This happens when no fingerprints are registered.
toggleFingerprintMode(FingerPrintHelper.Mode.WAITING_PASSWORD_MODE);
} else {
toggleFingerprintMode(FingerPrintHelper.Mode.OPEN_MODE);
}
}
}
});
// callback for fingerprint findings
@@ -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)
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) ) {
fingerPrintMode = newMode;
reInitWithFingerprintMode();
@@ -607,6 +625,9 @@ public class PasswordActivity extends StylishActivity
case STORE_MODE:
initEncryptData();
break;
case WAITING_PASSWORD_MODE:
initWaitData();
break;
case OPEN_MODE:
initDecryptData();
break;
@@ -638,10 +659,6 @@ public class PasswordActivity extends StylishActivity
setFingerPrintView(textId, false);
}
private void setFingerPrintView(final CharSequence text) {
setFingerPrintView(text, false);
}
private void setFingerPrintView(final int textId, boolean lock) {
setFingerPrintView(getString(textId), lock);
}
@@ -649,7 +666,7 @@ public class PasswordActivity extends StylishActivity
private void setFingerPrintView(final CharSequence text, boolean lock) {
runOnUiThread(() -> {
if (lock) {
fingerprintContainerView.setAlpha(0.6f);
fingerprintContainerView.setAlpha(0.8f);
} else
fingerprintContainerView.setAlpha(1f);
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
if (!prefsNoBackup.contains(getPreferenceKeyValue())) {
setFingerPrintView(R.string.no_password_stored);
if (checkboxPasswordView.isChecked()) {
// listen for encryption
initEncryptData();
} else {
// wait for typing
initWaitData();
}
}
// all is set here so we can confirm to user and start listening for fingerprints
else {
@@ -734,7 +755,9 @@ public class PasswordActivity extends StylishActivity
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
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);
}
@@ -805,20 +828,86 @@ public class PasswordActivity extends StylishActivity
loadDatabase(password, keyUri);
}
private void loadDatabase(String pass, Uri keyfile) {
private void loadDatabase(String password, Uri keyfile) {
// Clear before we load
Database db = App.getDB();
db.clear();
Database database = App.getDB();
database.clear();
// Clear the shutdown flag
App.clearShutdown();
// Show the progress dialog
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);
pt.run();
/**
* Called after verify and try to opening the database
*/
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
@@ -860,54 +949,6 @@ public class PasswordActivity extends StylishActivity
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> {
static final String KEY_FILENAME = "fileName";

View File

@@ -86,7 +86,7 @@ public class SearchResultsActivity extends ListNodesActivity {
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
MenuUtil.donationMenuInflater(inflater, menu);
MenuUtil.contributionMenuInflater(inflater, menu);
inflater.inflate(R.menu.tree, 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.database.Database;
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 {
@@ -71,7 +71,7 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat implements
@Override
public void onDisplayPreferenceDialog(Preference preference) {
// Try if the preference is one of our custom Preferences
if (preference instanceof RoundsPreference) {
if (preference instanceof InputNumberPreference) {
assert getFragmentManager() != null;
DialogFragment dialogFragment = RoundsFixPreferenceDialogFragmentCompat.newInstance(preference.getKey());
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.fingerprint.FingerPrintHelper;
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.DatabaseKeyDerivationPreferenceDialogFragmentCompat;
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.stylish.Stylish;
@@ -69,6 +73,10 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat
private int count = 0;
private Preference roundPref;
private Preference memoryPref;
private Preference parallelismPref;
public static NestedSettingsFragment newInstance(Screen key) {
NestedSettingsFragment fragment = new NestedSettingsFragment();
// supply arguments to bundle.
@@ -317,17 +325,23 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat
// Encryption Algorithm
Preference algorithmPref = findPreference(getString(R.string.encryption_algorithm_key));
algorithmPref.setSummary(db.getEncryptionAlgorithmName(getResources()));
preferenceInDevelopment(algorithmPref);
// Key derivation function
Preference kdfPref = findPreference(getString(R.string.key_derivation_function_key));
kdfPref.setSummary(db.getKeyDerivationName());
preferenceInDevelopment(kdfPref);
kdfPref.setSummary(db.getKeyDerivationName(getResources()));
// Round encryption
Preference roundPref = findPreference(getString(R.string.transform_rounds_key));
roundPref = findPreference(getString(R.string.transform_rounds_key));
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 {
Log.e(getClass().getName(), "Database isn't ready");
}
@@ -402,7 +416,7 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat
assert fragmentManager != null;
try { // don't check if we can
((SwitchPreference) preference).setChecked(false);
} catch (Exception e) {}
} catch (Exception ignored) {}
new UnderDevelopmentFeatureDialogFragment().show(getFragmentManager(), "underDevFeatureDialog");
return false;
});
@@ -428,12 +442,32 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat
if (preference.getKey().equals(getString(R.string.database_name_key))) {
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());
}
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());
}
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) {
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 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);
}
public RoundsPreference(Context context, AttributeSet attrs) {
public InputNumberPreference(Context context, AttributeSet attrs) {
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);
}
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);
}
@Override
public int getDialogLayoutResource() {
return R.layout.pref_dialog_rounds;
return R.layout.pref_dialog_numbers;
}
public long getRounds() {
return mRounds;
public long getNumber() {
return mNumber;
}
public void setRounds(long rounds) {
this.mRounds = rounds;
public void setNumber(long number) {
this.mNumber = number;
// 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
@@ -69,25 +83,25 @@ public class RoundsPreference extends InputTextExplanationPreference {
protected void onSetInitialValue(boolean restorePersistedValue,
Object defaultValue) {
// Read the value. Use the default value if it is not possible.
long rounds;
long number;
if (!restorePersistedValue) {
rounds = 100000;
number = 100000;
if (defaultValue instanceof String) {
rounds = Long.parseLong((String) defaultValue);
number = Long.parseLong((String) defaultValue);
}
if (defaultValue instanceof Integer) {
rounds = (Integer) defaultValue;
number = (Integer) defaultValue;
}
try {
rounds = (long) defaultValue;
number = (long) defaultValue;
} catch (Exception e) {
e.printStackTrace();
}
} 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;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
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(
String key) {
@@ -32,42 +52,46 @@ public class DatabaseDescriptionPreferenceDialogFragmentCompat extends DatabaseS
if ( positiveResult ) {
assert getContext() != null;
String dbDescription = getInputText();
String newDescription = getInputText();
String oldDescription = database.getDescription();
database.assignDescription(dbDescription);
database.assignDescription(newDescription);
Handler handler = new Handler();
setAfterSaveDatabase(new AfterDescriptionSave(getContext(), handler, dbDescription, oldDescription));
setAfterSaveDatabase(new AfterDescriptionSave((AppCompatActivity) getActivity(), handler, newDescription, oldDescription));
}
super.onDialogClosed(positiveResult);
}
private class AfterDescriptionSave extends OnFinish {
private class AfterDescriptionSave extends OnFinishRunnable {
private AppCompatActivity mActivity;
private String mNewDescription;
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);
mCtx = ctx;
mActivity = ctx;
mNewDescription = newDescription;
mOldDescription = oldDescription;
}
@Override
public void run() {
if (mActivity != null) {
mActivity.runOnUiThread(() -> {
String descriptionToShow = mNewDescription;
if (!mSuccess) {
displayMessage(mCtx);
database.assignDescription(mOldDescription);
displayMessage(mActivity);
database.assignDescription(mOldDescription);
}
getPreference().setSummary(descriptionToShow);
SaveDatabaseProgressTaskDialogFragment.stop(mActivity);
});
}
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;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
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(
String key) {
@@ -32,41 +52,46 @@ public class DatabaseNamePreferenceDialogFragmentCompat extends DatabaseSavePref
if ( positiveResult ) {
assert getContext() != null;
String dbName = getInputText();
String newName = getInputText();
String oldName = database.getName();
database.assignName(dbName);
database.assignName(newName);
Handler handler = new Handler();
setAfterSaveDatabase(new AfterNameSave(getContext(), handler, dbName, oldName));
setAfterSaveDatabase(new AfterNameSave((AppCompatActivity) getActivity(), handler, newName, oldName));
}
super.onDialogClosed(positiveResult);
}
private class AfterNameSave extends OnFinish {
private class AfterNameSave extends OnFinishRunnable {
private String mNewName;
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);
mCtx = ctx;
mActivity = ctx;
mNewName = newName;
mOldName = oldName;
}
@Override
public void run() {
if (mActivity != null) {
mActivity.runOnUiThread(() -> {
String nameToShow = mNewName;
if (!mSuccess) {
displayMessage(mCtx);
displayMessage(mActivity);
database.assignName(mOldName);
}
getPreference().setSummary(nameToShow);
SaveDatabaseProgressTaskDialogFragment.stop(mActivity);
});
}
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;
import android.view.View;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.edit.OnFinish;
import com.kunzisoft.keepass.database.edit.SaveDB;
import com.kunzisoft.keepass.tasks.ProgressTask;
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
import com.kunzisoft.keepass.database.action.SaveDBRunnable;
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
public abstract class DatabaseSavePreferenceDialogFragmentCompat extends InputPreferenceDialogFragmentCompat {
protected Database database;
private OnFinish afterSaveDatabase;
private OnFinishRunnable afterSaveDatabase;
@Override
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
database = App.getDB();
this.database = App.getDB();
}
@Override
public void onDialogClosed(boolean positiveResult) {
if ( positiveResult ) {
assert getContext() != null;
assert getActivity() != null;
if (database != null && afterSaveDatabase != null) {
SaveDB save = new SaveDB(getContext(), database, afterSaveDatabase);
ProgressTask pt = new ProgressTask(getContext(), save, R.string.saving_database);
pt.run();
SaveDBRunnable saveDBRunnable = new SaveDBRunnable(getContext(),
database,
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;
}
}

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;
import android.support.annotation.StringRes;
import android.support.v7.preference.PreferenceDialogFragmentCompat;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.kunzisoft.keepass.R;
public abstract class InputPreferenceDialogFragmentCompat extends PreferenceDialogFragmentCompat {
private EditText inputTextView;
private TextView textExplanationView;
@Override
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
inputTextView = view.findViewById(R.id.input_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() {
if (textExplanationView != null)
return textExplanationView.getText().toString();
@@ -38,6 +46,16 @@ public abstract class InputPreferenceDialogFragmentCompat extends PreferenceDial
public void setExplanationText(String explanationText) {
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.support.v7.preference.DialogPreference;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.settings.preference.RoundsPreference;
import com.kunzisoft.keepass.settings.preference.InputNumberPreference;
public class RoundsFixPreferenceDialogFragmentCompat extends InputPreferenceDialogFragmentCompat {
private EditText inputTextView;
public static RoundsFixPreferenceDialogFragmentCompat newInstance(
String key) {
final RoundsFixPreferenceDialogFragmentCompat
@@ -44,10 +47,12 @@ public class RoundsFixPreferenceDialogFragmentCompat extends InputPreferenceDial
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
inputTextView = view.findViewById(R.id.input_text);
DialogPreference preference = getPreference();
if (preference instanceof RoundsPreference) {
setExplanationText(((RoundsPreference) preference).getExplanation());
long numRounds = ((RoundsPreference) preference).getRounds();
if (preference instanceof InputNumberPreference) {
setExplanationText(((InputNumberPreference) preference).getExplanation());
long numRounds = ((InputNumberPreference) preference).getNumber();
setInputText(String.valueOf(numRounds));
}
}
@@ -65,14 +70,23 @@ public class RoundsFixPreferenceDialogFragmentCompat extends InputPreferenceDial
}
DialogPreference preference = getPreference();
if (preference instanceof RoundsPreference) {
RoundsPreference roundsPreference = (RoundsPreference) preference;
if (preference instanceof InputNumberPreference) {
InputNumberPreference roundsPreference = (InputNumberPreference) preference;
// This allows the client to ignore the user value.
if (roundsPreference.callChangeListener(rounds)) {
// 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;
import android.content.Context;
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.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(
String key) {
@@ -76,36 +77,41 @@ public class RoundsPreferenceDialogFragmentCompat extends DatabaseSavePreference
}
Handler handler = new Handler();
setAfterSaveDatabase(new AfterRoundSave(getContext(), handler, rounds, oldRounds));
setAfterSaveDatabase(new AfterRoundSave((AppCompatActivity) getActivity(), handler, rounds, oldRounds));
}
super.onDialogClosed(positiveResult);
}
private class AfterRoundSave extends OnFinish {
private class AfterRoundSave extends OnFinishRunnable {
private long mNewRounds;
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);
mCtx = ctx;
mActivity = ctx;
mNewRounds = newRounds;
mOldRounds = oldRounds;
}
@Override
public void run() {
if (mActivity != null) {
mActivity.runOnUiThread(() -> {
long roundsToShow = mNewRounds;
if (!mSuccess) {
displayMessage(mCtx);
displayMessage(mActivity);
database.setNumberKeyEncryptionRounds(mOldRounds);
}
getPreference().setSummary(String.valueOf(roundsToShow));
SaveDatabaseProgressTaskDialogFragment.stop(mActivity);
});
}
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;
else if (themeString.equals(context.getString(R.string.list_style_name_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)))
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;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Handler;
public class UpdateStatus {
private ProgressDialog mPD;
private Context mCtx;
public class UpdateProgressTaskStatus implements ProgressTaskUpdater {
private Context mContext;
private ProgressTaskUpdater mProgressTaskUpdater;
private Handler mHandler;
public UpdateStatus() {
public UpdateProgressTaskStatus(Context context, ProgressTaskUpdater progressTaskUpdater) {
this(context, new Handler(), progressTaskUpdater);
}
public UpdateStatus(Context ctx, Handler handler, ProgressDialog pd) {
mCtx = ctx;
mPD = pd;
mHandler = handler;
public UpdateProgressTaskStatus(Context context, Handler handler, ProgressTaskUpdater progressTaskUpdater) {
this.mContext = context;
this.mProgressTaskUpdater = progressTaskUpdater;
this.mHandler = handler;
}
@Override
public void updateMessage(int resId) {
if ( mCtx != null && mPD != null && mHandler != null ) {
if ( mContext != null && mProgressTaskUpdater != null && mHandler != null ) {
mHandler.post(new UpdateMessage(resId));
}
}
@@ -47,13 +47,12 @@ public class UpdateStatus {
private class UpdateMessage implements Runnable {
private int mResId;
public UpdateMessage(int resId) {
UpdateMessage(int resId) {
mResId = resId;
}
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.Intent;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
import com.getkeepsafe.taptargetview.TapTarget;
import com.kunzisoft.keepass.BuildConfig;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.activities.AboutActivity;
import com.kunzisoft.keepass.settings.SettingsActivity;
import com.kunzisoft.keepass.stylish.StylishActivity;
import java.util.List;
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))
inflater.inflate(R.menu.donation, 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));
}
inflater.inflate(R.menu.contribution, menu);
}
public static void defaultMenuInflater(MenuInflater inflater, Menu menu) {
donationMenuInflater(inflater, menu);
contributionMenuInflater(inflater, menu);
inflater.inflate(R.menu.default_menu, menu);
}
public static boolean onDonationItemSelected(StylishActivity activity) {
public static boolean onContributionItemSelected(StylishActivity activity) {
try {
Util.gotoUrl(activity, R.string.donate_url);
Util.gotoUrl(activity, R.string.contribution_url);
} catch (ActivityNotFoundException e) {
Toast.makeText(activity, R.string.error_failed_to_launch_link, Toast.LENGTH_LONG).show();
return false;
@@ -80,8 +64,8 @@ public class MenuUtil {
*/
public static boolean onDefaultMenuOptionsItemSelected(StylishActivity activity, MenuItem item, boolean checkLock) {
switch (item.getItemId()) {
case R.id.menu_donate:
return onDonationItemSelected(activity);
case R.id.menu_contribute:
return onContributionItemSelected(activity);
case R.id.menu_app_settings:
// To avoid flickering when launch settings in a LockingActivity

View File

@@ -19,9 +19,12 @@
*/
package com.kunzisoft.keepass.utils;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Typeface;
import android.net.Uri;
import android.widget.EditText;
@@ -70,4 +73,20 @@ public class Util {
public static void applyFontVisibilityTo(final Context context, final EditText 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:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/default_margin"
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:id="@+id/fingerprint_image"
android:layout_width="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:elevation="4dp"
android:elevation="8dp"
android:src="@drawable/fingerprint"
android:background="@drawable/circle"
android:backgroundTint="?attr/colorAccent" />
<TextView
android:id="@+id/fingerprint_label"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="12dp"
android:layout_marginStart="24dp"
android:layout_marginEnd="18dp"
android:layout_toStartOf="@+id/fingerprint_image"
style="@style/KeepassDXStyle.TextAppearance.DefaultTextOnPrimary"
android:gravity="center_vertical|end" />
android:gravity="center_vertical|start" />
</RelativeLayout>

View File

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

View File

@@ -48,6 +48,18 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
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
layout="@layout/fingerprint_show" />
</LinearLayout>
@@ -172,18 +184,6 @@
android:tint="?attr/colorAccentCompat" />
</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>
</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"/>
<android.support.v7.widget.AppCompatEditText
android:id="@+id/input_text"
android:hint="@string/rounds_hint"
android:layout_height="wrap_content"
android:layout_width="match_parent"
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,13 +17,16 @@
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"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:padding="@dimen/default_margin"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:importantForAutofill="noExcludeDescendants"
tools:targetApi="o">
<android.support.v7.widget.CardView
@@ -121,8 +124,7 @@
android:maxLines="1"
android:singleLine="true"/>
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
</ScrollView>

View File

@@ -19,9 +19,9 @@
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android"
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:title="@string/menu_donate"
android:title="@string/contribute"
android:orderInCategory="95"
app:showAsAction="ifRoom" />
</menu>

View File

@@ -123,7 +123,7 @@
<string name="remember_keyfile_summary">Recorda la localització d\'arxius clau</string>
<string name="remember_keyfile_title">Guarda arxiu clau</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="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>
@@ -135,7 +135,7 @@
<string name="special">Especial</string>
<string name="search">Títol/descripció d\'entrada</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="unsupported_db_version">Versió de la base de dades no suportada.</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_title">Uložit klíčový soubor</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="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>
@@ -151,7 +151,7 @@
<string name="special">Speciální</string>
<string name="search">Zadejte název/popis</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="unsupported_db_version">Nepodporovaná verze databáze.</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_title">Gem nøglefil</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="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>
@@ -150,7 +150,7 @@
<string name="special">Speciel</string>
<string name="search">Post titel/beskrivelse</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="unsupported_db_version">Database-versionen er ikke understøttet.</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_title">Schlüsselquelle merken</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="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>
@@ -159,14 +159,14 @@
<string name="special">Spezialsymbole</string>
<string name="search">Titel/Beschreibung des Eintrags</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="unsupported_db_version">Datenbankversion wird nicht unterstützt.</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_title">Storage Access Framework</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_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>
@@ -217,6 +217,8 @@
<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="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="fingerprint_quick_unlock_title">Wie richte ich den Fingerabdruckscanner ein ?</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