Compare commits
157 Commits
2.5.0.0bet
...
2.5.0.0bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7bbb47422 | ||
|
|
846bc7edb1 | ||
|
|
99a9842a1f | ||
|
|
33009138c3 | ||
|
|
c74b82ebd8 | ||
|
|
49ea92a4a5 | ||
|
|
6cc4eeaa30 | ||
|
|
1b89f79888 | ||
|
|
07d99de3ea | ||
|
|
ae757affa1 | ||
|
|
482b6296fc | ||
|
|
d37ce729f0 | ||
|
|
e92ce232bc | ||
|
|
78ae44b160 | ||
|
|
49ce87a8e0 | ||
|
|
d2fe5ce884 | ||
|
|
5e695756de | ||
|
|
0506a75417 | ||
|
|
34e1316144 | ||
|
|
18dffa6c75 | ||
|
|
03621c378e | ||
|
|
aff9312419 | ||
|
|
4651b1be96 | ||
|
|
32497a22d2 | ||
|
|
3b5ef56c16 | ||
|
|
d4cc3a58d8 | ||
|
|
afedbb38b2 | ||
|
|
fe70bf3877 | ||
|
|
f14ee6cf1c | ||
|
|
1791b15f85 | ||
|
|
6c5b3b3a0d | ||
|
|
6ea2287679 | ||
|
|
cad4ec22b4 | ||
|
|
f277983caf | ||
|
|
5e561e5321 | ||
|
|
ef83dbcae2 | ||
|
|
ab6c69adcb | ||
|
|
1c90747476 | ||
|
|
c3b3d8482c | ||
|
|
86b4d92599 | ||
|
|
1f6786b1f8 | ||
|
|
4cd2b153f4 | ||
|
|
27b0810688 | ||
|
|
94c72a4cf6 | ||
|
|
e634116e71 | ||
|
|
9021cb5bc8 | ||
|
|
3674900a54 | ||
|
|
9855ae79c3 | ||
|
|
fe1a4985f1 | ||
|
|
015a368a1d | ||
|
|
07f59e071d | ||
|
|
670e2bfe33 | ||
|
|
992b6382a3 | ||
|
|
c3ac550c93 | ||
|
|
acba7fc5de | ||
|
|
ccb500fdf4 | ||
|
|
44111507e7 | ||
|
|
5f14596ed2 | ||
|
|
4ad65c8f4a | ||
|
|
b4b215fe30 | ||
|
|
d8a8005d70 | ||
|
|
37ca15b77c | ||
|
|
6c18fe5591 | ||
|
|
fdcb05467c | ||
|
|
ef8db46ae7 | ||
|
|
14f56c77e8 | ||
|
|
44e21084e4 | ||
|
|
b7f1275789 | ||
|
|
b1be05db4d | ||
|
|
09c776fd7e | ||
|
|
e8a24790a5 | ||
|
|
8b3be79266 | ||
|
|
e5f0572c1c | ||
|
|
68df3bc6c3 | ||
|
|
a3da960c26 | ||
|
|
d9490f9840 | ||
|
|
3b24f9d821 | ||
|
|
bf35897e92 | ||
|
|
977705b42d | ||
|
|
459bc40515 | ||
|
|
eb8ca9355c | ||
|
|
31f7b0d5be | ||
|
|
7c54946c4b | ||
|
|
5aaf2c222a | ||
|
|
9424feefce | ||
|
|
a3917ccab6 | ||
|
|
5286a60142 | ||
|
|
d4459de49b | ||
|
|
05dba6668c | ||
|
|
c15a1c6eaa | ||
|
|
fe8c962f73 | ||
|
|
4192cf2403 | ||
|
|
1817f1aa9e | ||
|
|
afacf352ed | ||
|
|
d3ebbba2a1 | ||
|
|
460edf1745 | ||
|
|
dacb19d412 | ||
|
|
fe8158db85 | ||
|
|
a36e4fbcd0 | ||
|
|
9442c7ef07 | ||
|
|
d4a0b59eb1 | ||
|
|
07600949ab | ||
|
|
7efaad1818 | ||
|
|
e32b0d1c25 | ||
|
|
0fdcc29aa2 | ||
|
|
37bedbffc9 | ||
|
|
46505150c4 | ||
|
|
e18c5c90cc | ||
|
|
1f5649d9d2 | ||
|
|
7bbd55a9fd | ||
|
|
92eeccf84e | ||
|
|
7bcc289518 | ||
|
|
507f758c0d | ||
|
|
6afffb7245 | ||
|
|
c62f4ae0b3 | ||
|
|
ee80c614e0 | ||
|
|
fea7af6910 | ||
|
|
c72aa0e97d | ||
|
|
3dd60b5392 | ||
|
|
a357267552 | ||
|
|
1badeb2eef | ||
|
|
0bb8d2a417 | ||
|
|
4a215db83c | ||
|
|
512e55a170 | ||
|
|
1ebe8dc022 | ||
|
|
cafeabdbc3 | ||
|
|
b342b26409 | ||
|
|
938c3a07af | ||
|
|
16288f98f7 | ||
|
|
a932156e85 | ||
|
|
64e9b9fb6d | ||
|
|
7af28550da | ||
|
|
60e2d786dd | ||
|
|
ec08f3430d | ||
|
|
a50aa0fb95 | ||
|
|
cf026e8eaa | ||
|
|
77614d0c4a | ||
|
|
e8d71039d7 | ||
|
|
4164b5bd37 | ||
|
|
3c66ec82b5 | ||
|
|
b796c16877 | ||
|
|
42d34d8f0c | ||
|
|
5fbb37df82 | ||
|
|
52e12d7cbd | ||
|
|
5cf5719e8e | ||
|
|
af3a80143e | ||
|
|
90db27c3fe | ||
|
|
3d584b76f7 | ||
|
|
fbf3dec421 | ||
|
|
1d36683128 | ||
|
|
cefc546c0a | ||
|
|
7aeb51813c | ||
|
|
d6fc29ec79 | ||
|
|
9af182e0c3 | ||
|
|
c7120b997f | ||
|
|
e61571fcec | ||
|
|
9a900b32b2 |
1
.gitignore
vendored
@@ -71,6 +71,7 @@ app/app.iml
|
||||
# Art
|
||||
art/screen*.png
|
||||
art/logo_512.png
|
||||
art/store_screens/
|
||||
|
||||
# Dir linux
|
||||
.directory
|
||||
|
||||
27
CHANGELOG
@@ -1,3 +1,30 @@
|
||||
KeepassDX (2.5.0.0beta11)
|
||||
* Fix memory issue with parcelable (crash in beta12 version)
|
||||
|
||||
KeepassDX (2.5.0.0beta12)
|
||||
* Added the Magikeyboard to fill the forms (settings still in development)
|
||||
* Added move and copy for groups and entries
|
||||
* New navigation in a single screen / new animations between activities
|
||||
* New icons for the material pack / vectorization
|
||||
* New adaptive launcher icon
|
||||
* Icons depends now of setting of list items
|
||||
* Added a setting to disable the open button when no password is identified
|
||||
* Added a setting to disable the education screens
|
||||
* Added a setting to disable the copy of protected custom fields
|
||||
* Fix the fingerprint recognition (WARNING : The keystore is reinit, you must delete the old keys)
|
||||
* Fix small bugs
|
||||
|
||||
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
|
||||
|
||||
55
FAQ.md
Normal file
@@ -0,0 +1,55 @@
|
||||
# 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 are updates not available at the same time on all stores?
|
||||
|
||||
- **PlayStore** only needs an APK generated and manually signed to be available on the store, it usually takes **20 minutes** to be available because it is deployed with fastlane. But the management of the APK and its data by the google servers is obscure.
|
||||
- **F-Droid**, to **ensure that the code is open source**, checks the sources directly on git repository (by checking the presence of new tags) and builds itself the APK that the server signs during the compilation of code and dependencies. Updating the project will take **1-10 days** for F-Droid to analyze all available repositories, build sources and deploy the generated APK. So F-Droid is slower for deployment but it is run by **volunteers** and guaranteed a **clean APK**. :)
|
||||
|
||||
## 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
|
||||
47
ReadMe.md
@@ -1,34 +1,32 @@
|
||||
# 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
|
||||
* Field filling **keyboard**
|
||||
* 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.*
|
||||
|
||||
@@ -36,16 +34,15 @@ Yes, KeePass DX is under free license (OSI certified) and without advertising. Y
|
||||
|
||||
You can contribute in different ways to help us on our work.
|
||||
|
||||
* Add features by a **pull request**.
|
||||
* Help to **translate** into your language
|
||||
* Add features by a **[pull request](https://help.github.com/articles/about-pull-requests/)**.
|
||||
* Help to **[translate](https://hosted.weblate.org/projects/keepass-dx/strings/)** into your language (By using [Weblate](https://hosted.weblate.org/projects/keepass-dx/) or with a manual [pull request](https://help.github.com/articles/about-pull-requests/))
|
||||
* **[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 +51,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://github.com/Kunzisoft/KeePassDX/blob/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 +80,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.*
|
||||
|
||||
@@ -6,20 +6,15 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.kunzisoft.keepass"
|
||||
minSdkVersion 14
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 27
|
||||
versionCode = 9
|
||||
versionName = "2.5.0.0beta9"
|
||||
versionCode = 13
|
||||
versionName = "2.5.0.0beta13"
|
||||
multiDexEnabled true
|
||||
|
||||
testApplicationId = "com.kunzisoft.keepass.tests"
|
||||
testInstrumentationRunner = "android.test.InstrumentationTestRunner"
|
||||
|
||||
ndk {
|
||||
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a',
|
||||
'arm64-v8a', 'mips', 'mips64'
|
||||
}
|
||||
|
||||
buildConfigField "String[]", "ICON_PACKS", "{\"classic\",\"material\"}"
|
||||
}
|
||||
|
||||
@@ -47,7 +42,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 +59,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", "{}"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,9 +105,11 @@ dependencies {
|
||||
implementation 'commons-collections:commons-collections:3.2.1'
|
||||
// Base64
|
||||
implementation 'biz.source_code:base64coder:2010-12-19'
|
||||
implementation 'com.google.code.gson:gson:2.8.1'
|
||||
implementation 'com.google.code.gson:gson:2.8.4'
|
||||
implementation 'com.google.guava:guava:23.0-android'
|
||||
// Icon pack, classic for all, material for libre and pro
|
||||
implementation project(path: ':icon-pack-classic')
|
||||
implementation project(path: ':icon-pack-material')
|
||||
implementation project(path: ':magikeyboard')
|
||||
implementation project(path: ':keepass-model')
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.tests.database;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import android.content.Context;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
@@ -30,9 +28,11 @@ 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.node.DeleteGroupRunnable;
|
||||
import com.kunzisoft.keepass.search.SearchDbHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DeleteEntry extends AndroidTestCase {
|
||||
private static final String GROUP1_NAME = "Group1";
|
||||
private static final String ENTRY1_NAME = "Test1";
|
||||
@@ -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
|
||||
|
||||
50
app/src/free/res/drawable-v24/ic_launcher_foreground.xml
Normal file
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108"
|
||||
android:width="108dp"
|
||||
android:height="108dp">
|
||||
<group
|
||||
android:translateY="-332">
|
||||
<group
|
||||
android:translateY="332">
|
||||
<path
|
||||
android:pathData="M65.728516 32.791016L58.052734 35.904297 56.173828 48.380859 35.306641 69.267578 35.238281 73.759766 69.478516 108 108 108 108 70.810547 73.09375 35.904297 65.728516 32.791016Z"
|
||||
android:fillColor="@color/long_shadow"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeMiterLimit="4" />
|
||||
</group>
|
||||
<group
|
||||
android:scaleX="0.3939503"
|
||||
android:scaleY="0.3939503"
|
||||
android:translateX="33.66343"
|
||||
android:translateY="233.998">
|
||||
<path
|
||||
android:pathData="M88.76953 339.91602L4.1718754 424.59766 4.0000004 436 15.400391 435.82813 27.240234 424 40 424l0 -12 12 0 0 -12.73438 34.01172 -33.97656A8 8 0 0 1 84 360a8 8 0 0 1 8 -8 8 8 0 0 1 5.296882 2.01367l2.787098 -2.7832 -11.31445 -11.31445z"
|
||||
android:fillColor="#eaeaea"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#58000000" />
|
||||
</group>
|
||||
<group
|
||||
android:scaleX="0.3939503"
|
||||
android:scaleY="0.3939503"
|
||||
android:translateX="33.66343"
|
||||
android:translateY="233.998">
|
||||
<path
|
||||
android:pathData="M4.0000004 340L4.1718754 351.40137 88.59863 435.82812 100 436 99.828122 424.59863 15.401367 340.17188Z"
|
||||
android:fillColor="#81c784" />
|
||||
</group>
|
||||
<group
|
||||
android:scaleX="0.3939503"
|
||||
android:scaleY="0.3939503"
|
||||
android:translateX="33.66343"
|
||||
android:translateY="233.998">
|
||||
<path
|
||||
android:pathData="M81.39454 332.00195a27 27 0 0 0 -19.48634 7.90625 27 27 0 0 0 0 38.1836 27 27 0 0 0 38.1836 0 27 27 0 0 0 0 -38.1836 27 27 0 0 0 -18.69726 -7.90625zM92 352a8 8 0 0 1 8 8 8 8 0 0 1 -8 8 8 8 0 0 1 -8 -8 8 8 0 0 1 8 -8z"
|
||||
android:fillColor="#eaeaea"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#58000000" />
|
||||
</group>
|
||||
</group>
|
||||
</vector>
|
||||
5
app/src/free/res/mipmap-anydpi-v26/ic_launcher.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/green" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
5
app/src/free/res/mipmap-anydpi-v26/ic_launcher_round.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/green" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 7.3 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 17 KiB |
50
app/src/libre/res/drawable-v24/ic_launcher_foreground.xml
Normal file
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108"
|
||||
android:width="108dp"
|
||||
android:height="108dp">
|
||||
<group
|
||||
android:translateY="-332">
|
||||
<group
|
||||
android:translateY="332">
|
||||
<path
|
||||
android:pathData="M65.728516 32.791016L58.052734 35.904297 56.173828 48.380859 35.306641 69.267578 35.238281 73.759766 69.478516 108 108 108 108 70.810547 73.09375 35.904297 65.728516 32.791016Z"
|
||||
android:fillColor="@color/long_shadow"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeMiterLimit="4" />
|
||||
</group>
|
||||
<group
|
||||
android:scaleX="0.3939503"
|
||||
android:scaleY="0.3939503"
|
||||
android:translateX="33.66343"
|
||||
android:translateY="233.998">
|
||||
<path
|
||||
android:pathData="M88.76953 339.91602L4.1718754 424.59766 4.0000004 436 15.400391 435.82813 27.240234 424 40 424l0 -12 12 0 0 -12.73438 34.01172 -33.97656A8 8 0 0 1 84 360a8 8 0 0 1 8 -8 8 8 0 0 1 5.296882 2.01367l2.787098 -2.7832 -11.31445 -11.31445z"
|
||||
android:fillColor="#eaeaea"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#58000000"/>
|
||||
</group>
|
||||
<group
|
||||
android:scaleX="0.3939503"
|
||||
android:scaleY="0.3939503"
|
||||
android:translateX="33.66343"
|
||||
android:translateY="233.998">
|
||||
<path
|
||||
android:pathData="M4.0000004 340L4.1718754 351.40137 88.59863 435.82812 100 436 99.828122 424.59863 15.401367 340.17188Z"
|
||||
android:fillColor="#64b5f6" />
|
||||
</group>
|
||||
<group
|
||||
android:scaleX="0.3939503"
|
||||
android:scaleY="0.3939503"
|
||||
android:translateX="33.66343"
|
||||
android:translateY="233.998">
|
||||
<path
|
||||
android:pathData="M81.39454 332.00195a27 27 0 0 0 -19.48634 7.90625 27 27 0 0 0 0 38.1836 27 27 0 0 0 38.1836 0 27 27 0 0 0 0 -38.1836 27 27 0 0 0 -18.69726 -7.90625zM92 352a8 8 0 0 1 8 8 8 8 0 0 1 -8 8 8 8 0 0 1 -8 -8 8 8 0 0 1 8 -8z"
|
||||
android:fillColor="#eaeaea"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#58000000" />
|
||||
</group>
|
||||
</group>
|
||||
</vector>
|
||||
5
app/src/libre/res/mipmap-anydpi-v26/ic_launcher.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/green" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/green" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
@@ -31,7 +31,7 @@
|
||||
android:name="com.kunzisoft.keepass.fileselect.FileSelectActivity"
|
||||
android:theme="@style/KeepassDXStyle.SplashScreen"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTask"
|
||||
android:launchMode="singleTop"
|
||||
android:configChanges="orientation|keyboardHidden"
|
||||
android:windowSoftInputMode="stateHidden" >
|
||||
<intent-filter>
|
||||
@@ -132,13 +132,15 @@
|
||||
<activity android:name="com.kunzisoft.keepass.settings.SettingsActivity" />
|
||||
<activity android:name="com.kunzisoft.keepass.autofill.AutoFillAuthActivity"
|
||||
android:configChanges="orientation|keyboardHidden" />
|
||||
<activity android:name="com.kunzisoft.keepass.selection.EntrySelectionAuthActivity"
|
||||
android:configChanges="orientation|keyboardHidden" />
|
||||
<activity android:name="com.kunzisoft.keepass.settings.SettingsAutofillActivity" />
|
||||
|
||||
<service android:name="com.kunzisoft.keepass.timeout.TimeoutService" />
|
||||
<service
|
||||
android:name="com.kunzisoft.keepass.notifications.NotificationCopyingService"
|
||||
android:enabled="true"
|
||||
android:exported="false" />
|
||||
<!-- Receiver for Autofill -->
|
||||
<service
|
||||
android:name="com.kunzisoft.keepass.autofill.KeeAutofillService"
|
||||
android:label="@string/autofill_service_name"
|
||||
@@ -146,11 +148,11 @@
|
||||
<meta-data
|
||||
android:name="android.autofill"
|
||||
android:resource="@xml/dataset_service" />
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.service.autofill.AutofillService" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<meta-data android:name="com.sec.android.support.multiwindow" android:value="true" />
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
@@ -47,6 +47,8 @@ import com.kunzisoft.keepass.database.PwDatabase;
|
||||
import com.kunzisoft.keepass.database.PwEntry;
|
||||
import com.kunzisoft.keepass.database.security.ProtectedString;
|
||||
import com.kunzisoft.keepass.icons.IconPackChooser;
|
||||
import com.kunzisoft.keepass.lock.LockingActivity;
|
||||
import com.kunzisoft.keepass.lock.LockingHideActivity;
|
||||
import com.kunzisoft.keepass.notifications.NotificationCopyingService;
|
||||
import com.kunzisoft.keepass.notifications.NotificationField;
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
||||
@@ -150,12 +152,28 @@ public class EntryActivity extends LockingHideActivity {
|
||||
// Start to manage field reference to copy a value from ref
|
||||
mEntry.startToManageFieldReferences(App.getDB().getPwDatabase());
|
||||
|
||||
boolean containsUsernameToCopy =
|
||||
mEntry.getUsername().length() > 0;
|
||||
boolean containsPasswordToCopy =
|
||||
(mEntry.getPassword().length() > 0
|
||||
&& PreferencesUtil.allowCopyPasswordAndProtectedFields(this));
|
||||
boolean containsExtraFieldToCopy =
|
||||
(mEntry.allowExtraFields()
|
||||
&& ((mEntry.containsCustomFields()
|
||||
&& mEntry.containsCustomFieldsNotProtected())
|
||||
|| (mEntry.containsCustomFields()
|
||||
&& mEntry.containsCustomFieldsProtected()
|
||||
&& PreferencesUtil.allowCopyPasswordAndProtectedFields(this))
|
||||
)
|
||||
);
|
||||
|
||||
// If notifications enabled in settings
|
||||
// Don't if application timeout
|
||||
if (firstLaunchOfActivity && !App.isShutdown() && isClipboardNotificationsEnable(getApplicationContext())) {
|
||||
if (mEntry.getUsername().length() > 0
|
||||
|| (mEntry.getPassword().length() > 0 && PreferencesUtil.allowCopyPassword(this))
|
||||
|| mEntry.containsCustomFields()) {
|
||||
if (containsUsernameToCopy
|
||||
|| containsPasswordToCopy
|
||||
|| containsExtraFieldToCopy
|
||||
) {
|
||||
// username already copied, waiting for user's action before copy password.
|
||||
Intent intent = new Intent(this, NotificationCopyingService.class);
|
||||
intent.setAction(NotificationCopyingService.ACTION_NEW_NOTIFICATION);
|
||||
@@ -164,35 +182,37 @@ public class EntryActivity extends LockingHideActivity {
|
||||
// Construct notification fields
|
||||
ArrayList<NotificationField> notificationFields = new ArrayList<>();
|
||||
// Add username if exists to notifications
|
||||
if (mEntry.getUsername().length() > 0)
|
||||
if (containsUsernameToCopy)
|
||||
notificationFields.add(
|
||||
new NotificationField(
|
||||
NotificationField.NotificationFieldId.USERNAME,
|
||||
mEntry.getUsername(),
|
||||
getResources()));
|
||||
// Add password to notifications
|
||||
if (PreferencesUtil.allowCopyPassword(this)) {
|
||||
if (mEntry.getPassword().length() > 0)
|
||||
notificationFields.add(
|
||||
new NotificationField(
|
||||
NotificationField.NotificationFieldId.PASSWORD,
|
||||
mEntry.getPassword(),
|
||||
getResources()));
|
||||
if (containsPasswordToCopy) {
|
||||
notificationFields.add(
|
||||
new NotificationField(
|
||||
NotificationField.NotificationFieldId.PASSWORD,
|
||||
mEntry.getPassword(),
|
||||
getResources()));
|
||||
}
|
||||
// Add extra fields
|
||||
if (mEntry.allowExtraFields()) {
|
||||
if (containsExtraFieldToCopy) {
|
||||
try {
|
||||
mEntry.getFields().doActionToAllCustomProtectedField(new ExtraFields.ActionProtected() {
|
||||
private int anonymousFieldNumber = 0;
|
||||
@Override
|
||||
public void doAction(String key, ProtectedString value) {
|
||||
notificationFields.add(
|
||||
new NotificationField(
|
||||
NotificationField.NotificationFieldId.getAnonymousFieldId()[anonymousFieldNumber],
|
||||
value.toString(),
|
||||
key,
|
||||
getResources()));
|
||||
anonymousFieldNumber++;
|
||||
//If value is not protected or allowed
|
||||
if (!value.isProtected() || PreferencesUtil.allowCopyPasswordAndProtectedFields(EntryActivity.this)) {
|
||||
notificationFields.add(
|
||||
new NotificationField(
|
||||
NotificationField.NotificationFieldId.getAnonymousFieldId()[anonymousFieldNumber],
|
||||
value.toString(),
|
||||
key,
|
||||
getResources()));
|
||||
anonymousFieldNumber++;
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
@@ -215,66 +235,70 @@ public class EntryActivity extends LockingHideActivity {
|
||||
* Displays the explanation for copying a field and editing an entry
|
||||
*/
|
||||
private void checkAndPerformedEducation(Menu menu) {
|
||||
if (PreferencesUtil.isEducationScreensEnabled(this)) {
|
||||
|
||||
if (entryContentsView != null && entryContentsView.isUserNamePresent()
|
||||
&& !PreferencesUtil.isEducationCopyUsernamePerformed(this)) {
|
||||
TapTargetView.showFor(this,
|
||||
TapTarget.forView(findViewById(R.id.entry_user_name_action_image),
|
||||
getString(R.string.education_field_copy_title),
|
||||
getString(R.string.education_field_copy_summary))
|
||||
.tintTarget(false)
|
||||
.cancelable(true),
|
||||
new TapTargetView.Listener() {
|
||||
@Override
|
||||
public void onTargetClick(TapTargetView view) {
|
||||
super.onTargetClick(view);
|
||||
clipboardHelper.timeoutCopyToClipboard(mEntry.getUsername(),
|
||||
getString(R.string.copy_field, getString(R.string.entry_user_name)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOuterCircleClick(TapTargetView view) {
|
||||
super.onOuterCircleClick(view);
|
||||
view.dismiss(false);
|
||||
// Launch autofill settings
|
||||
startActivity(new Intent(EntryActivity.this, SettingsAutofillActivity.class));
|
||||
}
|
||||
});
|
||||
PreferencesUtil.saveEducationPreference(this,
|
||||
R.string.education_copy_username_key);
|
||||
|
||||
} else if (!PreferencesUtil.isEducationEntryEditPerformed(this)) {
|
||||
|
||||
try {
|
||||
if (entryContentsView != null && entryContentsView.isUserNamePresent()
|
||||
&& !PreferencesUtil.isEducationCopyUsernamePerformed(this)) {
|
||||
TapTargetView.showFor(this,
|
||||
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_edit,
|
||||
getString(R.string.education_entry_edit_title),
|
||||
getString(R.string.education_entry_edit_summary))
|
||||
.tintTarget(true)
|
||||
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() {
|
||||
@Override
|
||||
public void onTargetClick(TapTargetView view) {
|
||||
super.onTargetClick(view);
|
||||
MenuItem editItem = menu.findItem(R.id.menu_edit);
|
||||
onOptionsItemSelected(editItem);
|
||||
clipboardHelper.timeoutCopyToClipboard(mEntry.getUsername(),
|
||||
getString(R.string.copy_field, getString(R.string.entry_user_name)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOuterCircleClick(TapTargetView view) {
|
||||
super.onOuterCircleClick(view);
|
||||
view.dismiss(false);
|
||||
// Open Keepass doc to create field references
|
||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW,
|
||||
Uri.parse(getString(R.string.field_references_url)));
|
||||
startActivity(browserIntent);
|
||||
// Launch autofill settings
|
||||
startActivity(new Intent(EntryActivity.this, SettingsAutofillActivity.class));
|
||||
}
|
||||
});
|
||||
PreferencesUtil.saveEducationPreference(this,
|
||||
R.string.education_entry_edit_key);
|
||||
} catch (Exception e) {
|
||||
// If icon not visible
|
||||
Log.w(TAG, "Can't performed education for entry's edition");
|
||||
R.string.education_copy_username_key);
|
||||
|
||||
} else if (!PreferencesUtil.isEducationEntryEditPerformed(this)) {
|
||||
|
||||
try {
|
||||
TapTargetView.showFor(this,
|
||||
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() {
|
||||
@Override
|
||||
public void onTargetClick(TapTargetView view) {
|
||||
super.onTargetClick(view);
|
||||
MenuItem editItem = menu.findItem(R.id.menu_edit);
|
||||
onOptionsItemSelected(editItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOuterCircleClick(TapTargetView view) {
|
||||
super.onOuterCircleClick(view);
|
||||
view.dismiss(false);
|
||||
// Open Keepass doc to create field references
|
||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW,
|
||||
Uri.parse(getString(R.string.field_references_url)));
|
||||
startActivity(browserIntent);
|
||||
}
|
||||
});
|
||||
PreferencesUtil.saveEducationPreference(this,
|
||||
R.string.education_entry_edit_key);
|
||||
} catch (Exception e) {
|
||||
// If icon not visible
|
||||
Log.w(TAG, "Can't performed education for entry's edition");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -307,7 +331,7 @@ public class EntryActivity extends LockingHideActivity {
|
||||
);
|
||||
|
||||
entryContentsView.assignPassword(mEntry.getPassword());
|
||||
if (PreferencesUtil.allowCopyPassword(this)) {
|
||||
if (PreferencesUtil.allowCopyPasswordAndProtectedFields(this)) {
|
||||
entryContentsView.assignPasswordCopyListener(view ->
|
||||
clipboardHelper.timeoutCopyToClipboard(mEntry.getPassword(),
|
||||
getString(R.string.copy_field, getString(R.string.entry_password)))
|
||||
@@ -323,14 +347,15 @@ public class EntryActivity extends LockingHideActivity {
|
||||
if (mEntry.allowExtraFields()) {
|
||||
entryContentsView.clearExtraFields();
|
||||
|
||||
mEntry.getFields().doActionToAllCustomProtectedField((label, value) ->
|
||||
|
||||
entryContentsView.addExtraField(label, value, view ->
|
||||
mEntry.getFields().doActionToAllCustomProtectedField((label, value) -> {
|
||||
boolean showAction = (!value.isProtected() || PreferencesUtil.allowCopyPasswordAndProtectedFields(EntryActivity.this));
|
||||
entryContentsView.addExtraField(label, value, showAction, view ->
|
||||
clipboardHelper.timeoutCopyToClipboard(
|
||||
value.toString(),
|
||||
getString(R.string.copy_field, label)
|
||||
)
|
||||
));
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// Assign dates
|
||||
@@ -372,7 +397,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 +440,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;
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.content.Intent;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
@@ -49,16 +48,20 @@ 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.PwNode;
|
||||
import com.kunzisoft.keepass.database.action.RunnableOnFinish;
|
||||
import com.kunzisoft.keepass.database.action.node.AddEntryRunnable;
|
||||
import com.kunzisoft.keepass.database.action.node.AfterActionNodeOnFinish;
|
||||
import com.kunzisoft.keepass.database.action.node.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.lock.LockingActivity;
|
||||
import com.kunzisoft.keepass.lock.LockingHideActivity;
|
||||
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;
|
||||
@@ -66,6 +69,8 @@ import com.kunzisoft.keepass.view.EntryEditCustomField;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.kunzisoft.keepass.dialogs.IconPickerDialogFragment.UNDEFINED_ICON_ID;
|
||||
|
||||
public class EntryEditActivity extends LockingHideActivity
|
||||
@@ -249,16 +254,21 @@ public class EntryEditActivity extends LockingHideActivity
|
||||
}
|
||||
mCallbackNewEntry = populateNewEntry();
|
||||
|
||||
OnFinish onFinish = new AfterSave();
|
||||
// Open a progress dialog and save entry
|
||||
AfterActionNodeOnFinish 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();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -266,57 +276,58 @@ public class EntryEditActivity extends LockingHideActivity
|
||||
* Displays the explanation for the icon selection, the password generator and for a new field
|
||||
*/
|
||||
private void checkAndPerformedEducation() {
|
||||
if (PreferencesUtil.isEducationScreensEnabled(this)) {
|
||||
// TODO Show icon
|
||||
|
||||
// TODO Show icon
|
||||
if (!PreferencesUtil.isEducationPasswordGeneratorPerformed(this)) {
|
||||
TapTargetView.showFor(this,
|
||||
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() {
|
||||
@Override
|
||||
public void onTargetClick(TapTargetView view) {
|
||||
super.onTargetClick(view);
|
||||
openPasswordGenerator();
|
||||
}
|
||||
|
||||
if (!PreferencesUtil.isEducationPasswordGeneratorPerformed(this)) {
|
||||
TapTargetView.showFor(this,
|
||||
TapTarget.forView(generatePasswordView,
|
||||
getString(R.string.education_generate_password_title),
|
||||
getString(R.string.education_generate_password_summary))
|
||||
.tintTarget(false)
|
||||
.cancelable(true),
|
||||
new TapTargetView.Listener() {
|
||||
@Override
|
||||
public void onTargetClick(TapTargetView view) {
|
||||
super.onTargetClick(view);
|
||||
openPasswordGenerator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOuterCircleClick(TapTargetView view) {
|
||||
super.onOuterCircleClick(view);
|
||||
view.dismiss(false);
|
||||
}
|
||||
});
|
||||
PreferencesUtil.saveEducationPreference(this,
|
||||
R.string.education_password_generator_key);
|
||||
}
|
||||
|
||||
else if (mEntry.allowExtraFields()
|
||||
@Override
|
||||
public void onOuterCircleClick(TapTargetView view) {
|
||||
super.onOuterCircleClick(view);
|
||||
view.dismiss(false);
|
||||
}
|
||||
});
|
||||
PreferencesUtil.saveEducationPreference(this,
|
||||
R.string.education_password_generator_key);
|
||||
} else if (mEntry.allowExtraFields()
|
||||
&& !mEntry.containsCustomFields()
|
||||
&& !PreferencesUtil.isEducationEntryNewFieldPerformed(this)) {
|
||||
TapTargetView.showFor(this,
|
||||
TapTarget.forView(addNewFieldView,
|
||||
getString(R.string.education_entry_new_field_title),
|
||||
getString(R.string.education_entry_new_field_summary))
|
||||
.tintTarget(false)
|
||||
.cancelable(true),
|
||||
new TapTargetView.Listener() {
|
||||
@Override
|
||||
public void onTargetClick(TapTargetView view) {
|
||||
super.onTargetClick(view);
|
||||
addNewCustomField();
|
||||
}
|
||||
TapTargetView.showFor(this,
|
||||
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() {
|
||||
@Override
|
||||
public void onTargetClick(TapTargetView view) {
|
||||
super.onTargetClick(view);
|
||||
addNewCustomField();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOuterCircleClick(TapTargetView view) {
|
||||
super.onOuterCircleClick(view);
|
||||
view.dismiss(false);
|
||||
}
|
||||
});
|
||||
PreferencesUtil.saveEducationPreference(this,
|
||||
R.string.education_entry_new_field_key);
|
||||
@Override
|
||||
public void onOuterCircleClick(TapTargetView view) {
|
||||
super.onOuterCircleClick(view);
|
||||
view.dismiss(false);
|
||||
}
|
||||
});
|
||||
PreferencesUtil.saveEducationPreference(this,
|
||||
R.string.education_entry_new_field_key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -432,7 +443,7 @@ public class EntryEditActivity extends LockingHideActivity
|
||||
return App.getDB().getPwDatabase().getIconFactory().getIcon(mSelectedIconID);
|
||||
else {
|
||||
if (mIsNew) {
|
||||
return App.getDB().getPwDatabase().getIconFactory().getFirstIcon();
|
||||
return App.getDB().getPwDatabase().getIconFactory().getKeyIcon();
|
||||
}
|
||||
else {
|
||||
// Keep previous icon, if no new one was selected
|
||||
@@ -447,15 +458,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,20 +563,20 @@ public class EntryEditActivity extends LockingHideActivity
|
||||
}
|
||||
}
|
||||
|
||||
private final class AfterSave extends OnFinish {
|
||||
|
||||
AfterSave() {
|
||||
super(new Handler());
|
||||
}
|
||||
private final class AfterSave extends AfterActionNodeOnFinish {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if ( mSuccess ) {
|
||||
finish();
|
||||
} else {
|
||||
displayMessage(EntryEditActivity.this);
|
||||
}
|
||||
public void run(@Nullable PwNode oldNode, @Nullable PwNode newNode) {
|
||||
runOnUiThread(() -> {
|
||||
if ( mSuccess ) {
|
||||
finish();
|
||||
} else {
|
||||
displayMessage(EntryEditActivity.this);
|
||||
}
|
||||
|
||||
SaveDatabaseProgressTaskDialogFragment.stop(EntryEditActivity.this);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,52 +22,44 @@ package com.kunzisoft.keepass.activities;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.assist.AssistStructure;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.adapters.NodeAdapter;
|
||||
import com.kunzisoft.keepass.app.App;
|
||||
import com.kunzisoft.keepass.autofill.AutofillHelper;
|
||||
import com.kunzisoft.keepass.compat.EditorCompat;
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwDatabase;
|
||||
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.dialogs.AssignMasterKeyDialogFragment;
|
||||
import com.kunzisoft.keepass.dialogs.SortDialogFragment;
|
||||
import com.kunzisoft.keepass.selection.EntrySelectionHelper;
|
||||
import com.kunzisoft.keepass.lock.LockingActivity;
|
||||
import com.kunzisoft.keepass.password.AssignPasswordHelper;
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
||||
import com.kunzisoft.keepass.tasks.UIToastTask;
|
||||
import com.kunzisoft.keepass.utils.MenuUtil;
|
||||
|
||||
public abstract class ListNodesActivity extends LockingActivity
|
||||
implements AssignMasterKeyDialogFragment.AssignPasswordDialogListener,
|
||||
NodeAdapter.OnNodeClickCallback,
|
||||
NodeAdapter.NodeClickCallback,
|
||||
SortDialogFragment.SortSelectionListener {
|
||||
|
||||
protected PwGroup mCurrentGroup;
|
||||
protected NodeAdapter mAdapter;
|
||||
|
||||
private SharedPreferences prefs;
|
||||
protected static final String GROUP_ID_KEY = "GROUP_ID_KEY";
|
||||
|
||||
protected static final String LIST_NODES_FRAGMENT_TAG = "LIST_NODES_FRAGMENT_TAG";
|
||||
protected ListNodesFragment listNodesFragment;
|
||||
|
||||
protected PwGroup mCurrentGroup;
|
||||
protected TextView groupNameView;
|
||||
|
||||
protected boolean entrySelectionMode;
|
||||
protected AutofillHelper autofillHelper;
|
||||
|
||||
@Override
|
||||
@@ -83,61 +75,85 @@ public abstract class ListNodesActivity extends LockingActivity
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
invalidateOptionsMenu();
|
||||
invalidateOptionsMenu();
|
||||
|
||||
// TODO Move in search
|
||||
setContentView(R.layout.list_nodes);
|
||||
mCurrentGroup = retrieveCurrentGroup(savedInstanceState);
|
||||
|
||||
mCurrentGroup = initCurrentGroup();
|
||||
|
||||
mAdapter = new NodeAdapter(this);
|
||||
addOptionsToAdapter(mAdapter);
|
||||
initializeListNodesFragment(mCurrentGroup);
|
||||
|
||||
entrySelectionMode = EntrySelectionHelper.isIntentInEntrySelectionMode(getIntent());
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
autofillHelper = new AutofillHelper();
|
||||
autofillHelper.retrieveAssistStructure(getIntent());
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract PwGroup initCurrentGroup();
|
||||
|
||||
protected abstract RecyclerView defineNodeList();
|
||||
|
||||
protected void addOptionsToAdapter(NodeAdapter nodeAdapter) {
|
||||
mAdapter.setOnNodeClickListener(this);
|
||||
}
|
||||
protected abstract PwGroup retrieveCurrentGroup(@Nullable Bundle savedInstanceState);
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
// Add elements to the list
|
||||
mAdapter.rebuildList(mCurrentGroup);
|
||||
assignListToNodeAdapter(defineNodeList());
|
||||
// Refresh the title
|
||||
assignToolbarElements();
|
||||
}
|
||||
|
||||
protected void setGroupTitle() {
|
||||
if ( mCurrentGroup != null ) {
|
||||
String name = mCurrentGroup.getName();
|
||||
TextView tv = findViewById(R.id.group_name);
|
||||
if ( name != null && name.length() > 0 ) {
|
||||
if ( tv != null ) {
|
||||
tv.setText(name);
|
||||
}
|
||||
} else {
|
||||
if ( tv != null ) {
|
||||
tv.setText(getText(R.string.root));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void initializeListNodesFragment(PwGroup currentGroup) {
|
||||
listNodesFragment = (ListNodesFragment) getSupportFragmentManager()
|
||||
.findFragmentByTag(LIST_NODES_FRAGMENT_TAG);
|
||||
if (listNodesFragment == null)
|
||||
listNodesFragment = ListNodesFragment.newInstance(currentGroup.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach the fragment's list of node.
|
||||
* <br />
|
||||
* <strong>R.id.nodes_list_fragment_container</strong> must be the id of the container
|
||||
*/
|
||||
protected void attachFragmentToContentView() {
|
||||
getSupportFragmentManager().beginTransaction().replace(
|
||||
R.id.nodes_list_fragment_container,
|
||||
listNodesFragment,
|
||||
LIST_NODES_FRAGMENT_TAG)
|
||||
.commit();
|
||||
}
|
||||
|
||||
public void assignToolbarElements() {
|
||||
if (mCurrentGroup != null) {
|
||||
String title = mCurrentGroup.getName();
|
||||
if (title != null && title.length() > 0) {
|
||||
if (groupNameView != null) {
|
||||
groupNameView.setText(title);
|
||||
groupNameView.invalidate();
|
||||
}
|
||||
} else {
|
||||
if (groupNameView != null) {
|
||||
groupNameView.setText(getText(R.string.root));
|
||||
groupNameView.invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
MenuUtil.contributionMenuInflater(inflater, menu);
|
||||
inflater.inflate(R.menu.default_menu, menu);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void assignListToNodeAdapter(RecyclerView recyclerView) {
|
||||
recyclerView.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch ( item.getItemId() ) {
|
||||
default:
|
||||
// Check the time lock before launching settings
|
||||
MenuUtil.onDefaultMenuOptionsItemSelected(this, item, true);
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -150,7 +166,7 @@ public abstract class ListNodesActivity extends LockingActivity
|
||||
if (assistStructure != null) {
|
||||
switch (node.getType()) {
|
||||
case GROUP:
|
||||
GroupActivity.launch(this, (PwGroup) node, assistStructure);
|
||||
openGroup((PwGroup) node);
|
||||
break;
|
||||
case ENTRY:
|
||||
// Build response with the entry selected
|
||||
@@ -161,80 +177,49 @@ public abstract class ListNodesActivity extends LockingActivity
|
||||
}
|
||||
}
|
||||
if ( assistStructure == null ){
|
||||
switch (node.getType()) {
|
||||
case GROUP:
|
||||
GroupActivity.launch(this, (PwGroup) node);
|
||||
break;
|
||||
case ENTRY:
|
||||
EntryActivity.launch(this, (PwEntry) node);
|
||||
break;
|
||||
if (entrySelectionMode) {
|
||||
switch (node.getType()) {
|
||||
case GROUP:
|
||||
openGroup((PwGroup) node);
|
||||
break;
|
||||
case ENTRY:
|
||||
EntrySelectionHelper.buildResponseWhenEntrySelected(this, (PwEntry) node);
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (node.getType()) {
|
||||
case GROUP:
|
||||
openGroup((PwGroup) node);
|
||||
break;
|
||||
case ENTRY:
|
||||
EntryActivity.launch(this, (PwEntry) node);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
MenuUtil.donationMenuInflater(inflater, menu);
|
||||
inflater.inflate(R.menu.tree, menu);
|
||||
inflater.inflate(R.menu.default_menu, menu);
|
||||
protected void openGroup(PwGroup group) {
|
||||
// Check Timeout
|
||||
if (checkTimeIsAllowedOrFinish(this)) {
|
||||
startRecordTime(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSortSelected(SortNodeEnum sortNodeEnum, boolean ascending, boolean groupsBefore, boolean recycleBinBottom) {
|
||||
// Toggle setting
|
||||
Editor editor = prefs.edit();
|
||||
editor.putString(getString(R.string.sort_node_key), sortNodeEnum.name());
|
||||
editor.putBoolean(getString(R.string.sort_ascending_key), ascending);
|
||||
editor.putBoolean(getString(R.string.sort_group_before_key), groupsBefore);
|
||||
editor.putBoolean(getString(R.string.sort_recycle_bin_bottom_key), recycleBinBottom);
|
||||
EditorCompat.apply(editor);
|
||||
|
||||
// Tell the adapter to refresh it's list
|
||||
mAdapter.notifyChangeSort(sortNodeEnum, ascending, groupsBefore);
|
||||
mAdapter.rebuildList(mCurrentGroup);
|
||||
ListNodesFragment newListNodeFragment = ListNodesFragment.newInstance(group.getId());
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left,
|
||||
R.anim.slide_in_left, R.anim.slide_out_right)
|
||||
.replace(R.id.nodes_list_fragment_container,
|
||||
newListNodeFragment,
|
||||
LIST_NODES_FRAGMENT_TAG)
|
||||
.addToBackStack(LIST_NODES_FRAGMENT_TAG)
|
||||
.commit();
|
||||
listNodesFragment = newListNodeFragment;
|
||||
mCurrentGroup = group;
|
||||
assignToolbarElements();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch ( item.getItemId() ) {
|
||||
|
||||
case R.id.menu_sort:
|
||||
SortDialogFragment sortDialogFragment;
|
||||
|
||||
PwDatabase database = App.getDB().getPwDatabase();
|
||||
/*
|
||||
// TODO Recycle bin bottom
|
||||
if (database.isRecycleBinAvailable() && database.isRecycleBinEnabled()) {
|
||||
sortDialogFragment =
|
||||
SortDialogFragment.getInstance(
|
||||
PrefsUtil.getListSort(this),
|
||||
PrefsUtil.getAscendingSort(this),
|
||||
PrefsUtil.getGroupsBeforeSort(this),
|
||||
PrefsUtil.getRecycleBinBottomSort(this));
|
||||
} else {
|
||||
*/
|
||||
sortDialogFragment =
|
||||
SortDialogFragment.getInstance(
|
||||
PreferencesUtil.getListSort(this),
|
||||
PreferencesUtil.getAscendingSort(this),
|
||||
PreferencesUtil.getGroupsBeforeSort(this));
|
||||
//}
|
||||
|
||||
sortDialogFragment.show(getSupportFragmentManager(), "sortDialog");
|
||||
return true;
|
||||
|
||||
default:
|
||||
// Check the time lock before launching settings
|
||||
MenuUtil.onDefaultMenuOptionsItemSelected(this, item, true);
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAssignKeyDialogPositiveClick(
|
||||
boolean masterPasswordChecked, String masterPassword,
|
||||
@@ -253,29 +238,17 @@ public abstract class ListNodesActivity extends LockingActivity
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSortSelected(SortNodeEnum sortNodeEnum, boolean ascending, boolean groupsBefore, boolean recycleBinBottom) {
|
||||
if (listNodesFragment != null)
|
||||
listNodesFragment.onSortSelected(sortNodeEnum, ascending, groupsBefore, recycleBinBottom);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
switch (requestCode) {
|
||||
case EntryEditActivity.ADD_OR_UPDATE_ENTRY_REQUEST_CODE:
|
||||
if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE ||
|
||||
resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE) {
|
||||
PwNode newNode = (PwNode) data.getSerializableExtra(EntryEditActivity.ADD_OR_UPDATE_ENTRY_KEY);
|
||||
if (newNode != null) {
|
||||
if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE)
|
||||
mAdapter.addNode(newNode);
|
||||
if (resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE) {
|
||||
//mAdapter.updateLastNodeRegister(newNode);
|
||||
mAdapter.rebuildList(mCurrentGroup);
|
||||
}
|
||||
} else {
|
||||
Log.e(this.getClass().getName(), "New node can be retrieve in Activity Result");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
EntrySelectionHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
AutofillHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
|
||||
}
|
||||
@@ -300,67 +273,18 @@ public abstract class ListNodesActivity extends LockingActivity
|
||||
}
|
||||
}
|
||||
|
||||
class AfterAddNode extends AfterActionNodeOnFinish {
|
||||
AfterAddNode(Handler handler) {
|
||||
super(handler);
|
||||
}
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (checkTimeIsAllowedOrFinish(this)) {
|
||||
startRecordTime(this);
|
||||
|
||||
public void run(PwNode oldNode, PwNode newNode) {
|
||||
super.run();
|
||||
if (mSuccess) {
|
||||
mAdapter.addNode(newNode);
|
||||
} else {
|
||||
displayMessage(ListNodesActivity.this);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.onBackPressed();
|
||||
|
||||
class AfterUpdateNode extends AfterActionNodeOnFinish {
|
||||
AfterUpdateNode(Handler handler) {
|
||||
super(handler);
|
||||
}
|
||||
|
||||
public void run(PwNode oldNode, PwNode newNode) {
|
||||
super.run();
|
||||
if (mSuccess) {
|
||||
mAdapter.updateNode(oldNode, newNode);
|
||||
} else {
|
||||
displayMessage(ListNodesActivity.this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AfterDeleteNode extends OnFinish {
|
||||
private PwNode pwNode;
|
||||
|
||||
AfterDeleteNode(Handler handler, PwNode pwNode) {
|
||||
super(handler);
|
||||
this.pwNode = pwNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if ( mSuccess) {
|
||||
mAdapter.removeNode(pwNode);
|
||||
PwGroup parent = pwNode.getParent();
|
||||
Database db = App.getDB();
|
||||
PwDatabase database = db.getPwDatabase();
|
||||
if (db.isRecycleBinAvailable() &&
|
||||
db.isRecycleBinEnabled()) {
|
||||
PwGroup recycleBin = database.getRecycleBin();
|
||||
// Add trash if it doesn't exists
|
||||
if (parent.equals(recycleBin)
|
||||
&& mCurrentGroup != null
|
||||
&& mCurrentGroup.getParent() == null
|
||||
&& !mCurrentGroup.equals(recycleBin)) {
|
||||
mAdapter.addNode(parent);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mHandler.post(new UIToastTask(ListNodesActivity.this, "Unrecoverable error: " + mMessage));
|
||||
App.setShutdown();
|
||||
finish();
|
||||
}
|
||||
listNodesFragment = (ListNodesFragment) getSupportFragmentManager().findFragmentByTag(LIST_NODES_FRAGMENT_TAG);
|
||||
// to refresh fragment
|
||||
listNodesFragment.rebuildList();
|
||||
mCurrentGroup = listNodesFragment.getMainGroup();
|
||||
assignToolbarElements();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
package com.kunzisoft.keepass.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.adapters.NodeAdapter;
|
||||
import com.kunzisoft.keepass.app.App;
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwDatabase;
|
||||
import com.kunzisoft.keepass.database.PwGroup;
|
||||
import com.kunzisoft.keepass.database.PwGroupId;
|
||||
import com.kunzisoft.keepass.database.PwNode;
|
||||
import com.kunzisoft.keepass.database.SortNodeEnum;
|
||||
import com.kunzisoft.keepass.dialogs.SortDialogFragment;
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
||||
import com.kunzisoft.keepass.stylish.StylishFragment;
|
||||
|
||||
public class ListNodesFragment extends StylishFragment implements
|
||||
SortDialogFragment.SortSelectionListener {
|
||||
|
||||
private static final String TAG = ListNodesFragment.class.getName();
|
||||
|
||||
private static final String GROUP_ID_KEY = "GROUP_ID_KEY";
|
||||
|
||||
private NodeAdapter.NodeClickCallback nodeClickCallback;
|
||||
private NodeAdapter.NodeMenuListener nodeMenuListener;
|
||||
private OnScrollListener onScrollListener;
|
||||
|
||||
private RecyclerView listView;
|
||||
protected PwGroup mCurrentGroup;
|
||||
protected NodeAdapter mAdapter;
|
||||
|
||||
// Preferences for sorting
|
||||
private SharedPreferences prefs;
|
||||
|
||||
public static ListNodesFragment newInstance(PwGroupId groupId) {
|
||||
Bundle bundle=new Bundle();
|
||||
if (groupId != null) {
|
||||
bundle.putSerializable(GROUP_ID_KEY, groupId);
|
||||
}
|
||||
ListNodesFragment listNodesFragment = new ListNodesFragment();
|
||||
listNodesFragment.setArguments(bundle);
|
||||
return listNodesFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
try {
|
||||
nodeClickCallback = (NodeAdapter.NodeClickCallback) context;
|
||||
} catch (ClassCastException e) {
|
||||
// The activity doesn't implement the interface, throw exception
|
||||
throw new ClassCastException(context.toString()
|
||||
+ " must implement " + NodeAdapter.NodeClickCallback.class.getName());
|
||||
}
|
||||
try {
|
||||
nodeMenuListener = (NodeAdapter.NodeMenuListener) context;
|
||||
} catch (ClassCastException e) {
|
||||
nodeMenuListener = null;
|
||||
// Context menu can be omit
|
||||
Log.w(TAG, context.toString()
|
||||
+ " must implement " + NodeAdapter.NodeMenuListener.class.getName());
|
||||
}
|
||||
try {
|
||||
onScrollListener = (OnScrollListener) context;
|
||||
} catch (ClassCastException e) {
|
||||
onScrollListener = null;
|
||||
// Context menu can be omit
|
||||
Log.w(TAG, context.toString()
|
||||
+ " must implement " + RecyclerView.OnScrollListener.class.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
mCurrentGroup = initCurrentGroup();
|
||||
if (getActivity() != null) {
|
||||
mAdapter = new NodeAdapter(getContextThemed(), getActivity().getMenuInflater());
|
||||
mAdapter.setOnNodeClickListener(nodeClickCallback);
|
||||
|
||||
if (nodeMenuListener != null) {
|
||||
mAdapter.setActivateContextMenu(true);
|
||||
mAdapter.setNodeMenuListener(nodeMenuListener);
|
||||
}
|
||||
}
|
||||
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
}
|
||||
|
||||
protected PwGroup initCurrentGroup() { // TODO Change by parcelable
|
||||
|
||||
Database db = App.getDB();
|
||||
PwGroup root = db.getPwDatabase().getRootGroup();
|
||||
|
||||
PwGroup currentGroup = null;
|
||||
if (getArguments() != null) {
|
||||
// Contains only the group id, so the group must be retrieve
|
||||
if (getArguments().containsKey(GROUP_ID_KEY)) {
|
||||
PwGroupId pwGroupId = (PwGroupId) getArguments().getSerializable(GROUP_ID_KEY);
|
||||
if ( pwGroupId != null )
|
||||
currentGroup = db.getPwDatabase().getGroupByGroupId(pwGroupId);
|
||||
}
|
||||
}
|
||||
|
||||
if ( currentGroup == null ) {
|
||||
currentGroup = root;
|
||||
}
|
||||
|
||||
return currentGroup;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
||||
// To apply theme
|
||||
View rootView = inflater.cloneInContext(getContextThemed())
|
||||
.inflate(R.layout.list_nodes_fragment, container, false);
|
||||
listView = rootView.findViewById(R.id.nodes_list);
|
||||
|
||||
if (onScrollListener != null) {
|
||||
listView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
onScrollListener.onScrolled(dy);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
rebuildList();
|
||||
}
|
||||
|
||||
public void rebuildList() {
|
||||
// Add elements to the list
|
||||
mAdapter.rebuildList(mCurrentGroup);
|
||||
assignListToNodeAdapter(listView);
|
||||
}
|
||||
|
||||
protected void assignListToNodeAdapter(RecyclerView recyclerView) {
|
||||
recyclerView.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSortSelected(SortNodeEnum sortNodeEnum, boolean ascending, boolean groupsBefore, boolean recycleBinBottom) {
|
||||
// Toggle setting
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putString(getString(R.string.sort_node_key), sortNodeEnum.name());
|
||||
editor.putBoolean(getString(R.string.sort_ascending_key), ascending);
|
||||
editor.putBoolean(getString(R.string.sort_group_before_key), groupsBefore);
|
||||
editor.putBoolean(getString(R.string.sort_recycle_bin_bottom_key), recycleBinBottom);
|
||||
editor.apply();
|
||||
|
||||
// Tell the adapter to refresh it's list
|
||||
mAdapter.notifyChangeSort(sortNodeEnum, ascending, groupsBefore);
|
||||
mAdapter.rebuildList(mCurrentGroup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.tree, menu);
|
||||
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch ( item.getItemId() ) {
|
||||
|
||||
case R.id.menu_sort:
|
||||
SortDialogFragment sortDialogFragment;
|
||||
|
||||
PwDatabase database = App.getDB().getPwDatabase();
|
||||
/*
|
||||
// TODO Recycle bin bottom
|
||||
if (database.isRecycleBinAvailable() && database.isRecycleBinEnabled()) {
|
||||
sortDialogFragment =
|
||||
SortDialogFragment.getInstance(
|
||||
PrefsUtil.getListSort(this),
|
||||
PrefsUtil.getAscendingSort(this),
|
||||
PrefsUtil.getGroupsBeforeSort(this),
|
||||
PrefsUtil.getRecycleBinBottomSort(this));
|
||||
} else {
|
||||
*/
|
||||
sortDialogFragment =
|
||||
SortDialogFragment.getInstance(
|
||||
PreferencesUtil.getListSort(getContext()),
|
||||
PreferencesUtil.getAscendingSort(getContext()),
|
||||
PreferencesUtil.getGroupsBeforeSort(getContext()));
|
||||
//}
|
||||
|
||||
sortDialogFragment.show(getChildFragmentManager(), "sortDialog");
|
||||
return true;
|
||||
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
switch (requestCode) {
|
||||
case EntryEditActivity.ADD_OR_UPDATE_ENTRY_REQUEST_CODE:
|
||||
if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE ||
|
||||
resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE) {
|
||||
PwNode newNode = (PwNode) data.getSerializableExtra(EntryEditActivity.ADD_OR_UPDATE_ENTRY_KEY);
|
||||
if (newNode != null) {
|
||||
if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE)
|
||||
mAdapter.addNode(newNode);
|
||||
if (resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE) {
|
||||
//mAdapter.updateLastNodeRegister(newNode);
|
||||
mAdapter.rebuildList(mCurrentGroup);
|
||||
}
|
||||
} else {
|
||||
Log.e(this.getClass().getName(), "New node can be retrieve in Activity Result");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return mAdapter == null || mAdapter.getItemCount() <= 0;
|
||||
}
|
||||
|
||||
public void addNode(PwNode newNode) {
|
||||
mAdapter.addNode(newNode);
|
||||
}
|
||||
|
||||
public void updateNode(PwNode oldNode, PwNode newNode) {
|
||||
mAdapter.updateNode(oldNode, newNode);
|
||||
}
|
||||
|
||||
public void removeNode(PwNode pwNode) {
|
||||
mAdapter.removeNode(pwNode);
|
||||
}
|
||||
|
||||
public PwGroup getMainGroup() {
|
||||
return mCurrentGroup;
|
||||
}
|
||||
|
||||
public interface OnScrollListener {
|
||||
|
||||
/**
|
||||
* Callback method to be invoked when the RecyclerView has been scrolled. This will be
|
||||
* called after the scroll has completed.
|
||||
*
|
||||
* @param dy The amount of vertical scroll.
|
||||
*/
|
||||
void onScrolled(int dy);
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,6 @@
|
||||
package com.kunzisoft.keepass.adapters;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
|
||||
@@ -30,7 +28,7 @@ class EntryViewHolder extends BasicViewHolder {
|
||||
EntryViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
container = itemView.findViewById(R.id.entry_container);
|
||||
icon = (ImageView) itemView.findViewById(R.id.entry_icon);
|
||||
text = (TextView) itemView.findViewById(R.id.entry_text);
|
||||
icon = itemView.findViewById(R.id.entry_icon);
|
||||
text = itemView.findViewById(R.id.entry_text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
package com.kunzisoft.keepass.adapters;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
|
||||
@@ -30,7 +28,7 @@ class GroupViewHolder extends BasicViewHolder {
|
||||
GroupViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
container = itemView.findViewById(R.id.group_container);
|
||||
icon = (ImageView) itemView.findViewById(R.id.group_icon);
|
||||
text = (TextView) itemView.findViewById(R.id.group_text);
|
||||
icon = itemView.findViewById(R.id.group_icon);
|
||||
text = itemView.findViewById(R.id.group_text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,9 +26,10 @@ import android.support.annotation.NonNull;
|
||||
import android.support.v7.util.SortedList;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.util.SortedListAdapterCallback;
|
||||
import android.util.TypedValue;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -47,12 +48,14 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
|
||||
private Context context;
|
||||
private LayoutInflater inflater;
|
||||
private MenuInflater menuInflater;
|
||||
private float textSize;
|
||||
private float iconSize;
|
||||
private SortNodeEnum listSort;
|
||||
private boolean groupsBeforeSort;
|
||||
private boolean ascendingSort;
|
||||
|
||||
private OnNodeClickCallback onNodeClickCallback;
|
||||
private NodeClickCallback nodeClickCallback;
|
||||
private NodeMenuListener nodeMenuListener;
|
||||
private boolean activateContextMenu;
|
||||
|
||||
@@ -63,13 +66,11 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
* Create node list adapter with contextMenu or not
|
||||
* @param context Context to use
|
||||
*/
|
||||
public NodeAdapter(final Context context) {
|
||||
public NodeAdapter(final Context context, MenuInflater menuInflater) {
|
||||
this.inflater = LayoutInflater.from(context);
|
||||
this.menuInflater = menuInflater;
|
||||
this.context = context;
|
||||
this.textSize = PreferencesUtil.getListTextSize(context);
|
||||
this.listSort = PreferencesUtil.getListSort(context);
|
||||
this.groupsBeforeSort = PreferencesUtil.getGroupsBeforeSort(context);
|
||||
this.ascendingSort = PreferencesUtil.getAscendingSort(context);
|
||||
assignPreferences();
|
||||
this.activateContextMenu = false;
|
||||
|
||||
this.nodeSortedList = new SortedList<>(PwNode.class, new SortedListAdapterCallback<PwNode>(this) {
|
||||
@@ -101,11 +102,26 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
this.activateContextMenu = activate;
|
||||
}
|
||||
|
||||
private void assignPreferences() {
|
||||
this.textSize = PreferencesUtil.getListTextSize(context);
|
||||
// Retrieve the icon size
|
||||
int iconDefaultSize = (int) TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP,
|
||||
context.getResources().getInteger(R.integer.list_icon_size_default),
|
||||
context.getResources().getDisplayMetrics()
|
||||
);
|
||||
this.iconSize = iconDefaultSize * textSize / Float.parseFloat(context.getString(R.string.list_size_default));
|
||||
this.listSort = PreferencesUtil.getListSort(context);
|
||||
this.groupsBeforeSort = PreferencesUtil.getGroupsBeforeSort(context);
|
||||
this.ascendingSort = PreferencesUtil.getAscendingSort(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild the list by clear and build children from the group
|
||||
*/
|
||||
public void rebuildList(PwGroup group) {
|
||||
this.nodeSortedList.clear();
|
||||
assignPreferences();
|
||||
if (group != null) {
|
||||
this.nodeSortedList.addAll(group.getDirectChildren());
|
||||
}
|
||||
@@ -196,7 +212,10 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
holder.container.setOnCreateContextMenuListener(
|
||||
new ContextMenuBuilder(subNode, nodeMenuListener));
|
||||
}
|
||||
// Assign text size
|
||||
// Assign image and text size
|
||||
// Relative size of the icon
|
||||
holder.icon.getLayoutParams().height = ((int) iconSize);
|
||||
holder.icon.getLayoutParams().width = ((int) iconSize);
|
||||
holder.text.setTextSize(textSize);
|
||||
}
|
||||
|
||||
@@ -208,8 +227,8 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
/**
|
||||
* Assign a listener when a node is clicked
|
||||
*/
|
||||
public void setOnNodeClickListener(OnNodeClickCallback onNodeClickCallback) {
|
||||
this.onNodeClickCallback = onNodeClickCallback;
|
||||
public void setOnNodeClickListener(NodeClickCallback nodeClickCallback) {
|
||||
this.nodeClickCallback = nodeClickCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,7 +241,7 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
/**
|
||||
* Callback listener to redefine to do an action when a node is click
|
||||
*/
|
||||
public interface OnNodeClickCallback {
|
||||
public interface NodeClickCallback {
|
||||
void onNodeClick(PwNode node);
|
||||
}
|
||||
|
||||
@@ -232,6 +251,8 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
public interface NodeMenuListener {
|
||||
boolean onOpenMenuClick(PwNode node);
|
||||
boolean onEditMenuClick(PwNode node);
|
||||
boolean onCopyMenuClick(PwNode node);
|
||||
boolean onMoveMenuClick(PwNode node);
|
||||
boolean onDeleteMenuClick(PwNode node);
|
||||
}
|
||||
|
||||
@@ -247,8 +268,8 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (onNodeClickCallback != null)
|
||||
onNodeClickCallback.onNodeClick(node);
|
||||
if (nodeClickCallback != null)
|
||||
nodeClickCallback.onNodeClick(node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,10 +278,6 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
*/
|
||||
private class ContextMenuBuilder implements View.OnCreateContextMenuListener {
|
||||
|
||||
private static final int MENU_OPEN = Menu.FIRST;
|
||||
private static final int MENU_EDIT = MENU_OPEN + 1;
|
||||
private static final int MENU_DELETE = MENU_EDIT + 1;
|
||||
|
||||
private PwNode node;
|
||||
private NodeMenuListener menuListener;
|
||||
|
||||
@@ -271,15 +288,30 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) {
|
||||
MenuItem clearMenu = contextMenu.add(Menu.NONE, MENU_OPEN, Menu.NONE, R.string.menu_open);
|
||||
clearMenu.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
menuInflater.inflate(R.menu.node_menu, contextMenu);
|
||||
|
||||
// TODO COPY For Group
|
||||
if (node.getType().equals(PwNode.Type.GROUP)) {
|
||||
contextMenu.removeItem(R.id.menu_copy);
|
||||
}
|
||||
|
||||
MenuItem menuItem = contextMenu.findItem(R.id.menu_open);
|
||||
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
if (!App.getDB().isReadOnly() && !node.equals(App.getDB().getPwDatabase().getRecycleBin())) {
|
||||
// Edition
|
||||
clearMenu = contextMenu.add(Menu.NONE, MENU_EDIT, Menu.NONE, R.string.menu_edit);
|
||||
clearMenu.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
menuItem = contextMenu.findItem(R.id.menu_edit);
|
||||
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
// Copy (not for group)
|
||||
if (node.getType().equals(PwNode.Type.ENTRY)) {
|
||||
menuItem = contextMenu.findItem(R.id.menu_copy);
|
||||
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
}
|
||||
// Move
|
||||
menuItem = contextMenu.findItem(R.id.menu_move);
|
||||
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
// Deletion
|
||||
clearMenu = contextMenu.add(Menu.NONE, MENU_DELETE, Menu.NONE, R.string.menu_delete);
|
||||
clearMenu.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
menuItem = contextMenu.findItem(R.id.menu_delete);
|
||||
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,11 +321,15 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
if (menuListener == null)
|
||||
return false;
|
||||
switch ( item.getItemId() ) {
|
||||
case MENU_OPEN:
|
||||
case R.id.menu_open:
|
||||
return menuListener.onOpenMenuClick(node);
|
||||
case MENU_EDIT:
|
||||
case R.id.menu_edit:
|
||||
return menuListener.onEditMenuClick(node);
|
||||
case MENU_DELETE:
|
||||
case R.id.menu_copy:
|
||||
return menuListener.onCopyMenuClick(node);
|
||||
case R.id.menu_move:
|
||||
return menuListener.onMoveMenuClick(node);
|
||||
case R.id.menu_delete:
|
||||
return menuListener.onDeleteMenuClick(node);
|
||||
default:
|
||||
return false;
|
||||
|
||||
@@ -54,7 +54,7 @@ public class AutoFillAuthActivity extends AppCompatActivity {
|
||||
// Pass extra for Autofill (EXTRA_ASSIST_STRUCTURE)
|
||||
AssistStructure assistStructure = autofillHelper.retrieveAssistStructure(getIntent());
|
||||
if (assistStructure != null) {
|
||||
FileSelectActivity.launch(this, assistStructure);
|
||||
FileSelectActivity.launchForAutofillResult(this, assistStructure);
|
||||
} else {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
|
||||
@@ -36,6 +36,7 @@ import android.widget.RemoteViews;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.database.PwEntry;
|
||||
import com.kunzisoft.keepass.selection.EntrySelectionHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -64,6 +65,7 @@ public class AutofillHelper {
|
||||
|
||||
public static void addAssistStructureExtraInIntent(Intent intent, AssistStructure assistStructure) {
|
||||
if (assistStructure != null) {
|
||||
EntrySelectionHelper.addEntrySelectionModeExtraInIntent(intent);
|
||||
intent.putExtra(android.view.autofill.AutofillManager.EXTRA_ASSIST_STRUCTURE, assistStructure);
|
||||
}
|
||||
}
|
||||
@@ -144,7 +146,7 @@ public class AutofillHelper {
|
||||
/**
|
||||
* Utility method to loop and close each activity with return data
|
||||
*/
|
||||
public static void onActivityResultSetResult(Activity activity, int requestCode, int resultCode, Intent data) {
|
||||
public static void onActivityResultSetResultAndFinish(Activity activity, int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == AUTOFILL_RESPONSE_REQUEST_CODE) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
activity.setResult(resultCode, data);
|
||||
@@ -152,15 +154,6 @@ public class AutofillHelper {
|
||||
if (resultCode == Activity.RESULT_CANCELED) {
|
||||
activity.setResult(Activity.RESULT_CANCELED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to loop and close each activity with return data
|
||||
*/
|
||||
public static void onActivityResultSetResultAndFinish(Activity activity, int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == AUTOFILL_RESPONSE_REQUEST_CODE) {
|
||||
onActivityResultSetResult(activity, requestCode, resultCode, data);
|
||||
activity.finish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,66 +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.compat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public class BackupManagerCompat {
|
||||
private static Class classBackupManager;
|
||||
private static Constructor constructorBackupManager;
|
||||
private static Method dataChanged;
|
||||
|
||||
private Object backupManager;
|
||||
|
||||
static {
|
||||
try {
|
||||
classBackupManager = Class.forName("android.app.backup.BackupManager");
|
||||
constructorBackupManager = classBackupManager.getConstructor(Context.class);
|
||||
dataChanged = classBackupManager.getMethod("dataChanged", (Class[]) null);
|
||||
} catch (Exception e) {
|
||||
// Do nothing, class does not exist
|
||||
}
|
||||
}
|
||||
|
||||
public BackupManagerCompat(Context ctx) {
|
||||
if (constructorBackupManager != null) {
|
||||
try {
|
||||
backupManager = constructorBackupManager.newInstance(ctx);
|
||||
} catch (Exception e) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void dataChanged() {
|
||||
if (backupManager != null && dataChanged != null) {
|
||||
try {
|
||||
dataChanged.invoke(backupManager, (Object[]) null);
|
||||
} catch (Exception e) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,53 +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.compat;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
// This compatiblity hack can go away when support for Android 1.5 api level 3 is dropped
|
||||
public class BitmapDrawableCompat {
|
||||
private static Constructor<BitmapDrawable> constResBitmap;
|
||||
|
||||
static {
|
||||
try {
|
||||
constResBitmap = BitmapDrawable.class.getConstructor(Resources.class, Bitmap.class);
|
||||
// This constructor is support in this api version
|
||||
} catch (Exception e) {
|
||||
// This constructor is not supported
|
||||
}
|
||||
}
|
||||
|
||||
public static BitmapDrawable getBitmapDrawable(Resources res, Bitmap bitmap) {
|
||||
if (constResBitmap != null) {
|
||||
try {
|
||||
return constResBitmap.newInstance(res, bitmap);
|
||||
} catch (Exception e) {
|
||||
// Do nothing, fall through to the safe constructor
|
||||
}
|
||||
}
|
||||
|
||||
return new BitmapDrawable(bitmap);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,70 +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.compat;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class BuildCompat {
|
||||
private static Field manufacturer;
|
||||
private static String manuText;
|
||||
|
||||
public static final int VERSION_CODE_GINGERBREAD = 9;
|
||||
public static final int VERSION_CODE_ICE_CREAM_SANDWICH = 14;
|
||||
public static final int VERSION_CODE_JELLY_BEAN = 16;
|
||||
public static final int VERSION_CODE_JELLY_BEAN_MR2 = 18;
|
||||
public static final int VERSION_KITKAT = 19;
|
||||
public static final int VERSION_CODE_M = 23;
|
||||
|
||||
private static Field versionSDK;
|
||||
private static int versionInt;
|
||||
|
||||
static {
|
||||
// MANUFACTURER is only available in API version 4 and later
|
||||
try {
|
||||
manufacturer = Build.class.getField("MANUFACTURER");
|
||||
manuText = (String) manufacturer.get(null);
|
||||
} catch (Exception e) {
|
||||
manuText = "";
|
||||
}
|
||||
|
||||
// SDK is only available in API version 4 and later
|
||||
try {
|
||||
versionSDK = Build.VERSION.class.getField("SDK_INT");
|
||||
versionInt = versionSDK.getInt(null);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
versionInt = Integer.parseInt(Build.VERSION.SDK);
|
||||
} catch (Exception nfe) {
|
||||
versionInt = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getManufacturer() {
|
||||
return manuText;
|
||||
}
|
||||
|
||||
public static int getSdkVersion() {
|
||||
return versionInt;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,9 +25,6 @@ import android.net.Uri;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ClipDataCompat {
|
||||
private static Class clipData;
|
||||
private static Class clipDataItem;
|
||||
private static Class clipDescription;
|
||||
private static Method getClipDataFromIntent;
|
||||
private static Method getDescription;
|
||||
private static Method getItemCount;
|
||||
@@ -39,14 +36,14 @@ public class ClipDataCompat {
|
||||
|
||||
static {
|
||||
try {
|
||||
clipData = Class.forName("android.content.ClipData");
|
||||
Class clipData = Class.forName("android.content.ClipData");
|
||||
getDescription = clipData.getMethod("getDescription", (Class[])null);
|
||||
getItemCount = clipData.getMethod("getItemCount", (Class[])null);
|
||||
getItemAt = clipData.getMethod("getItemAt", new Class[]{int.class});
|
||||
clipDescription = Class.forName("android.content.ClipDescription");
|
||||
Class clipDescription = Class.forName("android.content.ClipDescription");
|
||||
getLabel = clipDescription.getMethod("getLabel", (Class[])null);
|
||||
|
||||
clipDataItem = Class.forName("android.content.ClipData$Item");
|
||||
Class clipDataItem = Class.forName("android.content.ClipData$Item");
|
||||
getUri = clipDataItem.getMethod("getUri", (Class[])null);
|
||||
|
||||
getClipDataFromIntent = Intent.class.getMethod("getClipData", (Class[])null);
|
||||
@@ -58,7 +55,6 @@ public class ClipDataCompat {
|
||||
}
|
||||
|
||||
public static Uri getUriFromIntent(Intent i, String key) {
|
||||
boolean clipDataSucceeded = false;
|
||||
if (initSucceded) {
|
||||
try {
|
||||
Object clip = getClipDataFromIntent.invoke(i);
|
||||
|
||||
@@ -1,52 +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.compat;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.net.Uri;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ContentResolverCompat {
|
||||
public static boolean available;
|
||||
private static Class contentResolver;
|
||||
private static Method takePersistableUriPermission;
|
||||
|
||||
static {
|
||||
try {
|
||||
contentResolver = ContentResolver.class;
|
||||
takePersistableUriPermission = contentResolver.getMethod("takePersistableUriPermission", new Class[]{Uri.class, int.class});
|
||||
|
||||
available = true;
|
||||
} catch (Exception e) {
|
||||
available = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void takePersistableUriPermission(ContentResolver resolver, Uri uri, int modeFlags) {
|
||||
if (available) {
|
||||
try {
|
||||
takePersistableUriPermission.invoke(resolver, new Object[]{uri, modeFlags});
|
||||
} catch (Exception e) {
|
||||
// Fail silently
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +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.compat;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class EditorCompat {
|
||||
private static Method apply;
|
||||
|
||||
static {
|
||||
try {
|
||||
apply = Activity.class.getMethod("apply", (Class<SharedPreferences.Editor>[]) null);
|
||||
} catch (Exception e) {
|
||||
// Substitute commit for apply when not available (API level < 9)
|
||||
try {
|
||||
apply = Activity.class.getMethod("commit", (Class<SharedPreferences.Editor>[]) null);
|
||||
} catch (Exception f) {
|
||||
// Should be impossible, but leave apply null in this case
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void apply(SharedPreferences.Editor edit) {
|
||||
try {
|
||||
apply.invoke(edit, (Object[]) null);
|
||||
} catch (Exception e) {
|
||||
// Shouldn't be possible, but call commit directly if this happens
|
||||
edit.commit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -44,7 +44,6 @@ public final class PRNGFixes {
|
||||
|
||||
private static final byte[] BUILD_FINGERPRINT_AND_DEVICE_SERIAL =
|
||||
getBuildFingerprintAndDeviceSerial();
|
||||
private static int sdkVersion = BuildCompat.getSdkVersion();
|
||||
|
||||
/** Hidden constructor to prevent instantiation. */
|
||||
private PRNGFixes() {}
|
||||
@@ -67,11 +66,11 @@ public final class PRNGFixes {
|
||||
|
||||
private static boolean supportedOnThisDevice() {
|
||||
// Blacklist on samsung devices
|
||||
if (StrUtil.indexOfIgnoreCase(BuildCompat.getManufacturer(), "samsung", Locale.ENGLISH) >= 0) {
|
||||
if (StrUtil.indexOfIgnoreCase(Build.MANUFACTURER, "samsung", Locale.ENGLISH) >= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sdkVersion > BuildCompat.VERSION_CODE_JELLY_BEAN_MR2) {
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -126,8 +125,8 @@ public final class PRNGFixes {
|
||||
* @throws SecurityException if the fix is needed but could not be applied.
|
||||
*/
|
||||
private static void applyOpenSSLFix() throws SecurityException {
|
||||
if ((sdkVersion < BuildCompat.VERSION_CODE_JELLY_BEAN)
|
||||
|| (sdkVersion > BuildCompat.VERSION_CODE_JELLY_BEAN_MR2)) {
|
||||
if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
|
||||
|| (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2)) {
|
||||
// No need to apply the fix
|
||||
return;
|
||||
}
|
||||
@@ -162,7 +161,7 @@ public final class PRNGFixes {
|
||||
*/
|
||||
private static void installLinuxPRNGSecureRandom()
|
||||
throws SecurityException {
|
||||
if (sdkVersion > BuildCompat.VERSION_CODE_JELLY_BEAN_MR2) {
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
// No need to apply the fix
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ package com.kunzisoft.keepass.compat;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
@@ -45,7 +46,7 @@ public class StorageAF {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean supportsStorageFramework() { return BuildCompat.getSdkVersion() >= BuildCompat.VERSION_KITKAT; }
|
||||
public static boolean supportsStorageFramework() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; }
|
||||
|
||||
public static boolean useStorageFramework(Context ctx) {
|
||||
if (!supportsStorageFramework()) { return false; }
|
||||
|
||||
@@ -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;
|
||||
@@ -30,8 +33,8 @@ import java.util.UUID;
|
||||
|
||||
public class AesKdf extends KdfEngine {
|
||||
|
||||
public static final int DEFAULT_ROUNDS = 6000;
|
||||
public static final String DEFAULT_NAME = "AES-KDF";
|
||||
private static final int DEFAULT_ROUNDS = 6000;
|
||||
private static final String DEFAULT_NAME = "AES-KDF";
|
||||
|
||||
public static final UUID CIPHER_UUID = Types.bytestoUUID(
|
||||
new byte[]{(byte) 0xC9, (byte) 0xD9, (byte) 0xF3, (byte) 0x9A, (byte) 0x62, (byte) 0x8A, (byte) 0x44, (byte) 0x60,
|
||||
@@ -41,17 +44,22 @@ public class AesKdf extends KdfEngine {
|
||||
public static final String ParamRounds = "R";
|
||||
public static final String ParamSeed = "S";
|
||||
|
||||
public AesKdf() {
|
||||
uuid = CIPHER_UUID;
|
||||
AesKdf() {
|
||||
setUUID(CIPHER_UUID);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return DEFAULT_NAME;
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,21 +29,22 @@ 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
|
||||
});
|
||||
|
||||
public static final String ParamSalt = "S"; // byte[]
|
||||
public static final String ParamParallelism = "P"; // UInt32
|
||||
public static final String ParamMemory = "M"; // UInt64
|
||||
public static final String ParamIterations = "I"; // UInt64
|
||||
public static final String ParamVersion = "V"; // UInt32
|
||||
public static final String ParamSecretKey = "K"; // byte[]
|
||||
public static final String ParamAssocData = "A"; // byte[]
|
||||
private static final String ParamSalt = "S"; // byte[]
|
||||
private static final String ParamParallelism = "P"; // UInt32
|
||||
private static final String ParamMemory = "M"; // UInt64
|
||||
private static final String ParamIterations = "I"; // UInt64
|
||||
private static final String ParamVersion = "V"; // UInt32
|
||||
private static final String ParamSecretKey = "K"; // byte[]
|
||||
private static final String ParamAssocData = "A"; // byte[]
|
||||
|
||||
public static final long MinVersion = 0x10;
|
||||
public static final long MaxVersion = 0x13;
|
||||
private static final long MinVersion = 0x10;
|
||||
private static final long MaxVersion = 0x13;
|
||||
|
||||
private static final int MinSalt = 8;
|
||||
private static final int MaxSalt = Integer.MAX_VALUE;
|
||||
@@ -58,22 +62,28 @@ public class Argon2Kdf extends KdfEngine {
|
||||
private static final long DefaultMemory = 1024 * 1024;
|
||||
private static final long DefaultParallelism = 2;
|
||||
|
||||
public Argon2Kdf() {
|
||||
uuid = CIPHER_UUID;
|
||||
private static final String DEFAULT_NAME = "Argon2";
|
||||
|
||||
Argon2Kdf() {
|
||||
setUUID(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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,24 +19,59 @@
|
||||
*/
|
||||
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 UUID uuid;
|
||||
public abstract class KdfEngine implements ObjectNameResource{
|
||||
|
||||
public KdfParameters getDefaultParameters() {
|
||||
return new KdfParameters(uuid);
|
||||
public static final int UNKNOW_VALUE = -1;
|
||||
public static final String UNKNOW_VALUE_STRING = String.valueOf(-1);
|
||||
|
||||
protected UUID uuid;
|
||||
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUUID(UUID uuid) {
|
||||
this.uuid = 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,31 +19,37 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto.keyDerivation;
|
||||
|
||||
import com.kunzisoft.keepass.database.exception.UnknownKDF;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class KdfFactory {
|
||||
|
||||
public static List<KdfEngine> kdfList = new ArrayList<>();
|
||||
public static AesKdf aesKdf = new AesKdf();
|
||||
public static Argon2Kdf argon2Kdf = new Argon2Kdf();
|
||||
|
||||
public static List<KdfEngine> kdfListV3 = new ArrayList<>();
|
||||
public static List<KdfEngine> kdfListV4 = new ArrayList<>();
|
||||
|
||||
static {
|
||||
kdfList.add(new AesKdf());
|
||||
kdfList.add(new Argon2Kdf());
|
||||
kdfListV3.add(aesKdf);
|
||||
|
||||
kdfListV4.add(aesKdf);
|
||||
kdfListV4.add(argon2Kdf);
|
||||
}
|
||||
|
||||
public static KdfParameters getDefaultParameters() {
|
||||
return kdfList.get(0).getDefaultParameters();
|
||||
}
|
||||
|
||||
public static KdfEngine get(UUID uuid) {
|
||||
for (KdfEngine engine: kdfList) {
|
||||
if (engine.uuid.equals(uuid)) {
|
||||
public static KdfEngine getEngineV4(KdfParameters kdfParameters) throws UnknownKDF {
|
||||
UnknownKDF unknownKDFException = new UnknownKDF();
|
||||
if (kdfParameters == null) {
|
||||
throw unknownKDFException;
|
||||
}
|
||||
for (KdfEngine engine: kdfListV4) {
|
||||
if (engine.getUUID().equals(kdfParameters.getUUID())) {
|
||||
return engine;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
throw unknownKDFException;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,34 +31,36 @@ import java.util.UUID;
|
||||
|
||||
public class KdfParameters extends VariantDictionary {
|
||||
|
||||
public UUID kdfUUID;
|
||||
private UUID kdfUUID;
|
||||
|
||||
private static final String ParamUUID = "$UUID";
|
||||
|
||||
public KdfParameters(UUID uuid) {
|
||||
KdfParameters(UUID uuid) {
|
||||
kdfUUID = uuid;
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return kdfUUID;
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
@@ -20,23 +20,21 @@
|
||||
package com.kunzisoft.keepass.database;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
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;
|
||||
import com.kunzisoft.keepass.database.exception.PwDbOutputException;
|
||||
import com.kunzisoft.keepass.database.load.Importer;
|
||||
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 +45,11 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.SyncFailedException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
public class Database {
|
||||
@@ -99,19 +102,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 {
|
||||
private 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")) {
|
||||
@@ -119,26 +114,10 @@ public class Database {
|
||||
readOnly = !file.canWrite();
|
||||
}
|
||||
|
||||
try {
|
||||
passUrisAsInputStreams(ctx, uri, password, keyfile, status, debug, 0);
|
||||
} catch (InvalidPasswordException e) {
|
||||
// Retry with rounds fix
|
||||
try {
|
||||
passUrisAsInputStreams(ctx, uri, password, keyfile, status, debug, getFixRounds(ctx));
|
||||
} catch (Exception e2) {
|
||||
// Rethrow original exception
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
passUrisAsInputStreams(ctx, uri, password, keyfile, status, debug);
|
||||
}
|
||||
|
||||
private long getFixRounds(Context ctx) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||
return prefs.getLong(ctx.getString(R.string.roundsFix_key), ctx.getResources().getInteger(R.integer.roundsFix_default));
|
||||
}
|
||||
|
||||
|
||||
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) throws IOException, FileNotFoundException, InvalidDBException {
|
||||
InputStream is, kfIs;
|
||||
try {
|
||||
is = UriUtil.getUriInputStream(ctx, uri);
|
||||
@@ -153,18 +132,14 @@ public class Database {
|
||||
Log.e("KPD", "Database::loadData", e);
|
||||
throw ContentFileNotFoundException.getInstance(keyfile);
|
||||
}
|
||||
loadData(ctx, is, password, kfIs, status, debug, roundsFix);
|
||||
loadData(ctx, is, password, kfIs, status, debug);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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) throws IOException, InvalidDBException {
|
||||
BufferedInputStream bis = new BufferedInputStream(is);
|
||||
|
||||
if ( ! bis.markSupported() ) {
|
||||
@@ -174,11 +149,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);
|
||||
if ( pm != null ) {
|
||||
try {
|
||||
switch (pm.getVersion()) {
|
||||
@@ -222,19 +197,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());
|
||||
PwDbOutput pmo = PwDbOutput.getInstance(pm, fos);
|
||||
pmo.output();
|
||||
//bos.flush();
|
||||
//bos.close();
|
||||
fos.close();
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new FileOutputStream(tempFile);
|
||||
PwDbOutput pmo = PwDbOutput.getInstance(pm, fos);
|
||||
if (pmo != null)
|
||||
pmo.output();
|
||||
} 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,24 +228,28 @@ 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);
|
||||
PwDbOutput pmo = PwDbOutput.getInstance(pm, os);
|
||||
if (pmo != null)
|
||||
pmo.output();
|
||||
} catch (Exception e) {
|
||||
throw new IOException("Failed to store database.");
|
||||
Log.e(TAG, errorMessage, e);
|
||||
throw new IOException(errorMessage, e);
|
||||
} finally {
|
||||
if (os != null)
|
||||
os.close();
|
||||
}
|
||||
|
||||
PwDbOutput pmo = PwDbOutput.getInstance(pm, os);
|
||||
pmo.output();
|
||||
os.close();
|
||||
}
|
||||
mUri = uri;
|
||||
}
|
||||
|
||||
// TODO Clear database when lock broadcast is receive in backstage
|
||||
public void clear() {
|
||||
drawFactory.clearCache();
|
||||
|
||||
@@ -348,16 +334,88 @@ 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.kdfListV4;
|
||||
case V3:
|
||||
return KdfFactory.kdfListV3;
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public boolean allowKdfModification() {
|
||||
return getAvailableKdfEngines().size() > 1;
|
||||
}
|
||||
|
||||
public KdfEngine getKdfEngine() {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
case V4:
|
||||
KdfEngine kdfEngine = ((PwDatabaseV4) getPwDatabase()).getKdfEngine();
|
||||
if (kdfEngine == null)
|
||||
return KdfFactory.aesKdf;
|
||||
return kdfEngine;
|
||||
default:
|
||||
case V3:
|
||||
return KdfFactory.aesKdf;
|
||||
}
|
||||
}
|
||||
|
||||
public void assignKdfEngine(KdfEngine kdfEngine) {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
case V4:
|
||||
PwDatabaseV4 db = ((PwDatabaseV4) getPwDatabase());
|
||||
if (db.getKdfParameters() == null
|
||||
|| !db.getKdfParameters().getUUID().equals(kdfEngine.getDefaultParameters().getUUID()))
|
||||
db.setKdfParameters(kdfEngine.getDefaultParameters());
|
||||
setNumberKeyEncryptionRounds(kdfEngine.getDefaultKeyRounds());
|
||||
setMemoryUsage(kdfEngine.getDefaultMemoryUsage());
|
||||
setParallelism(kdfEngine.getDefaultParallelism());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public String getKeyDerivationName(Resources resources) {
|
||||
KdfEngine kdfEngine = 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 +426,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 {
|
||||
@@ -547,6 +643,44 @@ public class Database {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A duplicate entry with the same values, a new UUID,
|
||||
* @param entryToCopy
|
||||
* @param newParent
|
||||
*/
|
||||
public @Nullable PwEntry copyEntry(PwEntry entryToCopy, PwGroup newParent) {
|
||||
try {
|
||||
// TODO encapsulate
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
case V3:
|
||||
PwEntryV3 entryV3Copied = ((PwEntryV3) entryToCopy).clone();
|
||||
entryV3Copied.setUUID(UUID.randomUUID());
|
||||
entryV3Copied.setParent((PwGroupV3) newParent);
|
||||
addEntryTo(entryV3Copied, newParent);
|
||||
return entryV3Copied;
|
||||
case V4:
|
||||
PwEntryV4 entryV4Copied = ((PwEntryV4) entryToCopy).clone();
|
||||
entryV4Copied.setUUID(UUID.randomUUID());
|
||||
entryV4Copied.setParent((PwGroupV4) newParent);
|
||||
addEntryTo(entryV4Copied, newParent);
|
||||
return entryV4Copied;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "This version of PwEntry can't be updated", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void moveEntry(PwEntry entryToMove, PwGroup newParent) {
|
||||
removeEntryFrom(entryToMove, entryToMove.parent);
|
||||
addEntryTo(entryToMove, newParent);
|
||||
}
|
||||
|
||||
public void moveGroup(PwGroup groupToMove, PwGroup newParent) {
|
||||
removeGroupFrom(groupToMove, groupToMove.parent);
|
||||
addGroupTo(groupToMove, newParent);
|
||||
}
|
||||
|
||||
public void deleteEntry(PwEntry entry) {
|
||||
try {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
|
||||
@@ -57,7 +57,7 @@ public class EntrySearchV4 {
|
||||
|
||||
boolean negate = false;
|
||||
if (sp.searchString.startsWith("-")) {
|
||||
sp.searchString.substring(1); // TODO Verify bug or no need ?
|
||||
sp.searchString = sp.searchString.substring(1);
|
||||
negate = sp.searchString.length() > 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,22 @@ public class ExtraFields implements Serializable, Cloneable {
|
||||
return !getCustomProtectedFields().keySet().isEmpty();
|
||||
}
|
||||
|
||||
public boolean containsCustomFieldsProtected() {
|
||||
for (Map.Entry<String, ProtectedString> field : getCustomProtectedFields().entrySet()) {
|
||||
if (field.getValue().isProtected())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containsCustomFieldsNotProtected() {
|
||||
for (Map.Entry<String, ProtectedString> field : getCustomProtectedFields().entrySet()) {
|
||||
if (!field.getValue().isProtected())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getProtectedStringValue(String key) {
|
||||
ProtectedString value = fields.get(key);
|
||||
if ( value == null ) return "";
|
||||
|
||||
@@ -17,16 +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;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import com.kunzisoft.keepass.database.PwNode;
|
||||
|
||||
public abstract class AfterActionNodeOnFinish extends OnFinish {
|
||||
public AfterActionNodeOnFinish(Handler handler) {
|
||||
super(handler);
|
||||
}
|
||||
|
||||
public abstract void run(PwNode oldNode, PwNode newNode);
|
||||
/**
|
||||
* Interface to generify items with a name resource, that can be (for example) visible in a list
|
||||
*/
|
||||
public interface ObjectNameResource {
|
||||
String getName(Resources resources);
|
||||
}
|
||||
@@ -19,11 +19,8 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.database;
|
||||
|
||||
import com.kunzisoft.keepass.crypto.finalkey.FinalKey;
|
||||
import com.kunzisoft.keepass.crypto.finalkey.FinalKeyFactory;
|
||||
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 +28,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 +96,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 +246,7 @@ public abstract class PwDatabase<PwGroupDB extends PwGroup<PwGroupDB, PwGroupDB,
|
||||
this.algorithm = algorithm;
|
||||
}
|
||||
|
||||
public abstract String getKeyDerivationName();
|
||||
public abstract List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms();
|
||||
|
||||
public abstract List<PwGroupDB> getGrpRoots();
|
||||
|
||||
|
||||
@@ -45,11 +45,16 @@ 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.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;
|
||||
@@ -95,10 +100,12 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
|
||||
return PwVersion.V3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKeyDerivationName() {
|
||||
return AesKdf.DEFAULT_NAME;
|
||||
}
|
||||
@Override
|
||||
public List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms() {
|
||||
List<PwEncryptionAlgorithm> list = new ArrayList<>();
|
||||
list.add(PwEncryptionAlgorithm.AES_Rijndael);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PwGroupV3> getGroups() {
|
||||
@@ -250,6 +257,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 +324,6 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
|
||||
|
||||
// Add tree to root groups
|
||||
groups.add(newGroup);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,17 +19,18 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.database;
|
||||
|
||||
import android.util.Log;
|
||||
import android.webkit.URLUtil;
|
||||
|
||||
import com.kunzisoft.keepass.collections.VariantDictionary;
|
||||
import com.kunzisoft.keepass.crypto.CryptoUtil;
|
||||
import com.kunzisoft.keepass.crypto.engine.AesEngine;
|
||||
import com.kunzisoft.keepass.crypto.engine.CipherEngine;
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.AesKdf;
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory;
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfParameters;
|
||||
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
|
||||
import com.kunzisoft.keepass.database.exception.UnknownKDF;
|
||||
import com.kunzisoft.keepass.utils.EmptyUtils;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
@@ -50,6 +51,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
@@ -57,6 +59,7 @@ import biz.source_code.base64Coder.Base64Coder;
|
||||
|
||||
|
||||
public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
|
||||
private static final String TAG = PwDatabaseV4.class.getName();
|
||||
|
||||
private static final int DEFAULT_HISTORY_MAX_ITEMS = 10; // -1 unlimited
|
||||
private static final long DEFAULT_HISTORY_MAX_SIZE = 6 * 1024 * 1024; // -1 unlimited
|
||||
@@ -66,9 +69,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,9 +102,7 @@ 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();
|
||||
private BinaryPool binPool = new BinaryPool();
|
||||
|
||||
public String localizedAppName = "KeePassDX"; // TODO resource
|
||||
|
||||
@@ -131,9 +133,17 @@ 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() {
|
||||
return compressionAlgorithm;
|
||||
}
|
||||
@@ -142,6 +152,23 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
|
||||
this.compressionAlgorithm = compressionAlgorithm;
|
||||
}
|
||||
|
||||
public @Nullable KdfEngine getKdfEngine() {
|
||||
try {
|
||||
return KdfFactory.getEngineV4(kdfParameters);
|
||||
} catch (UnknownKDF unknownKDF) {
|
||||
Log.i(TAG, "Unable to retrieve KDF engine", unknownKDF);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public KdfParameters getKdfParameters() {
|
||||
return kdfParameters;
|
||||
}
|
||||
|
||||
public void setKdfParameters(KdfParameters kdfParameters) {
|
||||
this.kdfParameters = kdfParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getNumberKeyEncryptionRounds() {
|
||||
if (getKdfEngine() != null && getKdfParameters() != null)
|
||||
@@ -156,7 +183,31 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
|
||||
numKeyEncRounds = rounds;
|
||||
}
|
||||
|
||||
public PwDate getNameChanged() {
|
||||
public long getMemoryUsage() {
|
||||
if (getKdfEngine() != null && getKdfParameters() != null) {
|
||||
return getKdfEngine().getMemoryUsage(getKdfParameters());
|
||||
}
|
||||
return KdfEngine.UNKNOW_VALUE;
|
||||
}
|
||||
|
||||
public void setMemoryUsage(long memory) {
|
||||
if (getKdfEngine() != null && getKdfParameters() != null)
|
||||
getKdfEngine().setMemoryUsage(getKdfParameters(), memory);
|
||||
}
|
||||
|
||||
public int getParallelism() {
|
||||
if (getKdfEngine() != null && getKdfParameters() != null) {
|
||||
return getKdfEngine().getParallelism(getKdfParameters());
|
||||
}
|
||||
return KdfEngine.UNKNOW_VALUE;
|
||||
}
|
||||
|
||||
public void setParallelism(int parallelism) {
|
||||
if (getKdfEngine() != null && getKdfParameters() != null)
|
||||
getKdfEngine().setParallelism(getKdfParameters(), parallelism);
|
||||
}
|
||||
|
||||
public PwDate getNameChanged() {
|
||||
return nameChanged;
|
||||
}
|
||||
|
||||
@@ -326,15 +377,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 +401,11 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
|
||||
return md.digest(fKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void makeFinalKey(byte[] masterSeed, byte[] masterSeed2, long numRounds) throws IOException {
|
||||
public void makeFinalKey(byte[] masterSeed) throws IOException {
|
||||
|
||||
byte[] transformedMasterKey = transformMasterKey(masterSeed2, masterKey, numRounds);
|
||||
KdfEngine kdfEngine = KdfFactory.getEngineV4(kdfParameters);
|
||||
|
||||
|
||||
byte[] cmpKey = new byte[65];
|
||||
System.arraycopy(masterSeed, 0, cmpKey, 0, 32);
|
||||
System.arraycopy(transformedMasterKey, 0, cmpKey, 32, 32);
|
||||
finalKey = CryptoUtil.resizeKey(cmpKey, 0, 64, dataEngine.keyLength());
|
||||
|
||||
MessageDigest md;
|
||||
try {
|
||||
md = MessageDigest.getInstance("SHA-512");
|
||||
cmpKey[64] = 1;
|
||||
hmacKey = md.digest(cmpKey);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new IOException("No SHA-512 implementation");
|
||||
} finally {
|
||||
Arrays.fill(cmpKey, (byte)0);
|
||||
}
|
||||
}
|
||||
public void makeFinalKey(byte[] masterSeed, KdfParameters kdfP) throws IOException {
|
||||
makeFinalKey(masterSeed, kdfP, 0);
|
||||
}
|
||||
|
||||
public void makeFinalKey(byte[] masterSeed, KdfParameters kdfP, long roundsFix)
|
||||
throws IOException {
|
||||
|
||||
kdfEngine = KdfFactory.get(kdfP.kdfUUID);
|
||||
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);
|
||||
numKeyEncRounds = roundsFix;
|
||||
}
|
||||
|
||||
byte[] transformedMasterKey = kdfEngine.transform(masterKey, kdfP);
|
||||
byte[] transformedMasterKey = kdfEngine.transform(masterKey, kdfParameters);
|
||||
if (transformedMasterKey.length != 32) {
|
||||
transformedMasterKey = CryptoUtil.hashSha256(transformedMasterKey);
|
||||
}
|
||||
@@ -549,15 +555,15 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
|
||||
super.populateGlobals(currentGroup);
|
||||
}
|
||||
|
||||
/** Ensure that the recycle bin tree exists, if enabled and create it
|
||||
* if it doesn't exist
|
||||
*
|
||||
/**
|
||||
* Ensure that the recycle bin tree exists, if enabled and create it
|
||||
* if it doesn't exist
|
||||
*/
|
||||
private void ensureRecycleBin() {
|
||||
if (getRecycleBin() == null) {
|
||||
// Create recycle bin
|
||||
|
||||
PwGroupV4 recycleBin = new PwGroupV4(RECYCLEBIN_NAME, iconFactory.getIcon(PwIconStandard.TRASH_BIN));
|
||||
PwGroupV4 recycleBin = new PwGroupV4(RECYCLEBIN_NAME, iconFactory.getTrashIcon());
|
||||
recycleBin.setEnableAutoType(false);
|
||||
recycleBin.setEnableSearching(false);
|
||||
recycleBin.setExpanded(false);
|
||||
@@ -681,8 +687,7 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
|
||||
@Override
|
||||
public void undoDeleteEntry(PwEntryV4 entry, PwGroupV4 origParent) {
|
||||
super.undoDeleteEntry(entry, origParent);
|
||||
// TODO undo delete entry
|
||||
deletedObjects.remove(entry);
|
||||
deletedObjects.remove(new PwDeletedObject(entry.getUUID()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -695,14 +700,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,9 +736,7 @@ 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));
|
||||
rootGroup = new PwGroupV4(dbNameFromPath(dbPath), iconFactory.getFolderIcon());
|
||||
groups.put(rootGroup.getId(), rootGroup);
|
||||
}
|
||||
|
||||
@@ -759,64 +754,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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
@@ -41,11 +42,10 @@ import javax.crypto.spec.SecretKeySpec;
|
||||
public class PwDbHeaderV4 extends PwDbHeader {
|
||||
public static final int DBSIG_PRE2 = 0xB54BFB66;
|
||||
public static final int DBSIG_2 = 0xB54BFB67;
|
||||
|
||||
|
||||
private static final int FILE_VERSION_CRITICAL_MASK = 0xFFFF0000;
|
||||
public static final int FILE_VERSION_32_3 = 0x00030001;
|
||||
public static final int FILE_VERSION_32_4 = 0x00040000;
|
||||
public static final int FILE_VERSION_32 = FILE_VERSION_32_4;
|
||||
|
||||
public class PwDbHeaderV4Fields {
|
||||
public static final byte EndOfHeader = 0;
|
||||
@@ -91,12 +91,83 @@ 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().getUUID().equals(AesKdf.CIPHER_UUID)) {
|
||||
return PwDbHeaderV4.FILE_VERSION_32_4;
|
||||
}
|
||||
|
||||
// Return V4 if custom data are present
|
||||
if (databaseV4.containsPublicCustomData()) {
|
||||
return PwDbHeaderV4.FILE_VERSION_32_4;
|
||||
}
|
||||
|
||||
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_4;
|
||||
}
|
||||
|
||||
return PwDbHeaderV4.FILE_VERSION_32_3;
|
||||
}
|
||||
|
||||
/** Assumes the input stream is at the beginning of the .kdbx file
|
||||
* @param is
|
||||
* @throws IOException
|
||||
@@ -122,7 +193,7 @@ public class PwDbHeaderV4 extends PwDbHeader {
|
||||
throw new InvalidDBVersionException();
|
||||
}
|
||||
|
||||
version = lis.readUInt();
|
||||
version = lis.readUInt(); // Erase previous value
|
||||
if ( ! validVersion(version) ) {
|
||||
throw new InvalidDBVersionException();
|
||||
}
|
||||
@@ -138,7 +209,7 @@ public class PwDbHeaderV4 extends PwDbHeader {
|
||||
|
||||
private boolean readHeaderField(LEDataInputStream dis) throws IOException {
|
||||
byte fieldID = (byte) dis.read();
|
||||
|
||||
|
||||
int fieldSize;
|
||||
if (version < FILE_VERSION_32_4) {
|
||||
fieldSize = dis.readUShort();
|
||||
@@ -149,13 +220,13 @@ public class PwDbHeaderV4 extends PwDbHeader {
|
||||
byte[] fieldData = null;
|
||||
if ( fieldSize > 0 ) {
|
||||
fieldData = new byte[fieldSize];
|
||||
|
||||
|
||||
int readSize = dis.read(fieldData);
|
||||
if ( readSize != fieldSize ) {
|
||||
throw new IOException("Header ended early.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch ( fieldID ) {
|
||||
case PwDbHeaderV4Fields.EndOfHeader:
|
||||
return true;
|
||||
@@ -173,24 +244,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,8 +258,8 @@ public class PwDbHeaderV4 extends PwDbHeader {
|
||||
break;
|
||||
|
||||
case PwDbHeaderV4Fields.InnerRandomstreamKey:
|
||||
assert(version < PwDbHeaderV4.FILE_VERSION_32_4);
|
||||
innerRandomStreamKey = fieldData;
|
||||
if(version < PwDbHeaderV4.FILE_VERSION_32_4)
|
||||
innerRandomStreamKey = fieldData;
|
||||
break;
|
||||
|
||||
case PwDbHeaderV4Fields.StreamStartBytes:
|
||||
@@ -207,8 +267,8 @@ public class PwDbHeaderV4 extends PwDbHeader {
|
||||
break;
|
||||
|
||||
case PwDbHeaderV4Fields.InnerRandomStreamID:
|
||||
assert(version < PwDbHeaderV4.FILE_VERSION_32_4);
|
||||
setRandomStreamID(fieldData);
|
||||
if(version < PwDbHeaderV4.FILE_VERSION_32_4)
|
||||
setRandomStreamID(fieldData);
|
||||
break;
|
||||
|
||||
case PwDbHeaderV4Fields.KdfParameters:
|
||||
@@ -224,6 +284,12 @@ public class PwDbHeaderV4 extends PwDbHeader {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void assignAesKdfEngineIfNotExists() {
|
||||
if (db.getKdfParameters() == null || !db.getKdfParameters().getUUID().equals(KdfFactory.aesKdf.getUUID())) {
|
||||
db.setKdfParameters(KdfFactory.aesKdf.getDefaultParameters());
|
||||
}
|
||||
}
|
||||
|
||||
private void setCipher(byte[] pbId) throws IOException {
|
||||
if ( pbId == null || pbId.length != 16 ) {
|
||||
@@ -232,6 +298,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 ) {
|
||||
@@ -244,23 +322,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 +337,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));
|
||||
|
||||
return ! ((version & FILE_VERSION_CRITICAL_MASK) > (FILE_VERSION_32_4 & 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) );
|
||||
}
|
||||
|
||||
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 +370,7 @@ public class PwDbHeaderV4 extends PwDbHeader {
|
||||
}
|
||||
|
||||
public byte[] getTransformSeed() {
|
||||
assert(version < FILE_VERSION_32_4);
|
||||
|
||||
return db.getKdfParameters().getByteArray(AesKdf.ParamSeed);
|
||||
// version < FILE_VERSION_32_4)
|
||||
return db.getKdfParameters().getByteArray(AesKdf.ParamSeed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,6 +117,22 @@ public abstract class PwEntry<Parent extends PwGroup> extends PwNode<Parent> {
|
||||
return getFields().containsCustomFields();
|
||||
}
|
||||
|
||||
/**
|
||||
* If entry contains extra fields that are protected
|
||||
* @return true if there is extra fields protected
|
||||
*/
|
||||
public boolean containsCustomFieldsProtected() {
|
||||
return getFields().containsCustomFieldsProtected();
|
||||
}
|
||||
|
||||
/**
|
||||
* If entry contains extra fields that are not protected
|
||||
* @return true if there is extra fields not protected
|
||||
*/
|
||||
public boolean containsCustomFieldsNotProtected() {
|
||||
return getFields().containsCustomFieldsNotProtected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an extra field to the list (standard or custom)
|
||||
* @param label Label of field, must be unique
|
||||
|
||||
@@ -199,7 +199,7 @@ public class PwEntryV3 extends PwEntry<PwGroupV3> {
|
||||
public void populateBlankFields(PwDatabaseV3 db) {
|
||||
// TODO verify and remove
|
||||
if (icon == null) {
|
||||
icon = db.getIconFactory().getFirstIcon();
|
||||
icon = db.getIconFactory().getKeyIcon();
|
||||
}
|
||||
|
||||
if (username == null) {
|
||||
|
||||
@@ -109,7 +109,7 @@ public class PwGroupV3 extends PwGroup<PwGroupV3, PwGroupV3, PwEntryV3> {
|
||||
public void populateBlankFields(PwDatabaseV3 db) {
|
||||
// TODO populate blanck field
|
||||
if (icon == null) {
|
||||
icon = db.getIconFactory().getFirstIcon();
|
||||
icon = db.getIconFactory().getFolderIcon();
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
|
||||
@@ -37,20 +37,23 @@ public class PwIconFactory {
|
||||
*/
|
||||
private ReferenceMap customCache = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK);
|
||||
|
||||
public PwIconStandard getFirstIcon() {
|
||||
return getIcon(0);
|
||||
public PwIconStandard getKeyIcon() {
|
||||
return getIcon(PwIconStandard.KEY);
|
||||
}
|
||||
|
||||
public PwIconStandard getTrashIcon() {
|
||||
return getIcon(PwIconStandard.TRASH);
|
||||
}
|
||||
|
||||
public PwIconStandard getFolderIcon() {
|
||||
return getIcon(PwIconStandard.FOLDER);
|
||||
}
|
||||
|
||||
public PwIconStandard getIcon(int iconId) {
|
||||
PwIconStandard icon = (PwIconStandard) cache.get(iconId);
|
||||
|
||||
if (icon == null) {
|
||||
if (iconId == 1) {
|
||||
icon = PwIconStandard.FIRST;
|
||||
}
|
||||
else {
|
||||
icon = new PwIconStandard(iconId);
|
||||
}
|
||||
icon = new PwIconStandard(iconId);
|
||||
cache.put(iconId, icon);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,12 +22,10 @@ package com.kunzisoft.keepass.database;
|
||||
public class PwIconStandard extends PwIcon {
|
||||
public final int iconId;
|
||||
|
||||
// The first is number 0
|
||||
public static PwIconStandard FIRST = new PwIconStandard(0);
|
||||
|
||||
public static final int TRASH_BIN = 43;
|
||||
public static final int KEY = 0;
|
||||
public static final int TRASH = 43;
|
||||
public static final int FOLDER = 48;
|
||||
|
||||
|
||||
public PwIconStandard(int iconId) {
|
||||
this.iconId = iconId;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public abstract class PwNode<Parent extends PwGroup> implements ISmallTimeLogger
|
||||
|
||||
protected Parent parent = null;
|
||||
|
||||
protected PwIconStandard icon = PwIconStandard.FIRST;
|
||||
protected PwIconStandard icon = new PwIconStandard(0);
|
||||
|
||||
protected PwDate creation = new PwDate();
|
||||
protected PwDate lastMod = new PwDate();
|
||||
@@ -119,6 +119,13 @@ public abstract class PwNode<Parent extends PwGroup> implements ISmallTimeLogger
|
||||
parent = prt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if parent is present (can be a root or a detach element)
|
||||
*/
|
||||
public boolean containsParent() {
|
||||
return getParent() != null;
|
||||
}
|
||||
|
||||
public PwDate getCreationTime() {
|
||||
return creation;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.kunzisoft.keepass.database.action;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
|
||||
public abstract class ActionWithSaveDatabaseRunnable extends RunnableOnFinish {
|
||||
|
||||
protected Context mContext;
|
||||
protected boolean mDontSave;
|
||||
protected Database mDatabase;
|
||||
|
||||
public ActionWithSaveDatabaseRunnable(Context context, Database database, OnFinishRunnable finish, boolean dontSave) {
|
||||
super(finish);
|
||||
|
||||
this.mDatabase = database;
|
||||
this.mContext = context;
|
||||
this.mDontSave = dontSave;
|
||||
this.mFinish = new AfterActionRunnable(finish);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// Commit to disk
|
||||
SaveDatabaseRunnable save = new SaveDatabaseRunnable(mContext, mDatabase, mFinish, mDontSave);
|
||||
save.run();
|
||||
}
|
||||
|
||||
public void runWithoutSaveDatabase() {
|
||||
mFinish.run();
|
||||
}
|
||||
|
||||
abstract protected void onFinish(boolean success, String message);
|
||||
|
||||
private class AfterActionRunnable extends OnFinishRunnable {
|
||||
|
||||
AfterActionRunnable(OnFinishRunnable finish) {
|
||||
super(finish);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
onFinish(mSuccess, mMessage);
|
||||
super.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.database.action;
|
||||
|
||||
import android.content.Context;
|
||||
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.utils.UriUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class AssignPasswordInDatabaseRunnable extends ActionWithSaveDatabaseRunnable {
|
||||
|
||||
private String mPassword;
|
||||
private Uri mKeyfile;
|
||||
private byte[] mBackupKey;
|
||||
|
||||
public AssignPasswordInDatabaseRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish) {
|
||||
this(ctx, db, password, keyfile, finish, false);
|
||||
}
|
||||
|
||||
public AssignPasswordInDatabaseRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish, boolean dontSave) {
|
||||
super(ctx, db, finish, dontSave);
|
||||
|
||||
this.mPassword = password;
|
||||
this.mKeyfile = keyfile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
PwDatabase pm = mDatabase.getPwDatabase();
|
||||
|
||||
mBackupKey = new byte[pm.getMasterKey().length];
|
||||
System.arraycopy(pm.getMasterKey(), 0, mBackupKey, 0, mBackupKey.length);
|
||||
|
||||
// Set key
|
||||
try {
|
||||
InputStream is = UriUtil.getUriInputStream(mContext, mKeyfile);
|
||||
pm.retrieveMasterKey(mPassword, is);
|
||||
// Save Database
|
||||
super.run();
|
||||
} catch (InvalidKeyFileException|IOException e) {
|
||||
erase(mBackupKey);
|
||||
finish(false, e.getMessage());
|
||||
super.runWithoutSaveDatabase();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if (!success) {
|
||||
// Erase the current master key
|
||||
erase(mDatabase.getPwDatabase().getMasterKey());
|
||||
mDatabase.getPwDatabase().setMasterKey(mBackupKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite the array as soon as we don't need it to avoid keeping the extra data in memory
|
||||
*/
|
||||
private void erase(byte[] array) {
|
||||
if ( array == null ) return;
|
||||
|
||||
for ( int i = 0; i < array.length; i++ ) {
|
||||
array[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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,18 +26,18 @@ import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwDatabase;
|
||||
import com.kunzisoft.keepass.utils.UriUtil;
|
||||
|
||||
public class CreateDB extends RunnableOnFinish {
|
||||
|
||||
private String mFilename;
|
||||
private boolean mDontSave;
|
||||
private Context ctx;
|
||||
public class CreateDatabaseRunnable extends RunnableOnFinish {
|
||||
|
||||
public CreateDB(Context ctx, String filename, OnFinish finish, boolean dontSave) {
|
||||
private Context mContext;
|
||||
private boolean mDontSave;
|
||||
private String mFilename;
|
||||
|
||||
public CreateDatabaseRunnable(Context mContext, String filename, OnFinishRunnable finish, boolean dontSave) {
|
||||
super(finish);
|
||||
|
||||
mFilename = filename;
|
||||
mDontSave = dontSave;
|
||||
this.ctx = ctx;
|
||||
this.mContext = mContext;
|
||||
this.mDontSave = dontSave;
|
||||
this.mFilename = filename;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,8 +56,9 @@ public class CreateDB extends RunnableOnFinish {
|
||||
App.clearShutdown();
|
||||
|
||||
// Commit changes
|
||||
SaveDB save = new SaveDB(ctx, db, mFinish, mDontSave);
|
||||
SaveDatabaseRunnable save = new SaveDatabaseRunnable(mContext, db, mFinish, mDontSave);
|
||||
mFinish = null;
|
||||
|
||||
save.run();
|
||||
}
|
||||
}
|
||||
@@ -17,17 +17,18 @@
|
||||
* 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;
|
||||
@@ -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,71 +42,77 @@ import com.kunzisoft.keepass.database.exception.KeyFileEmptyException;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
public class LoadDB extends RunnableOnFinish {
|
||||
public class LoadDatabaseRunnable extends RunnableOnFinish {
|
||||
private static final String TAG = LoadDatabaseRunnable.class.getName();
|
||||
|
||||
private Context mContext;
|
||||
private Database mDatabase;
|
||||
private Uri mUri;
|
||||
private String mPass;
|
||||
private Uri mKey;
|
||||
private Database mDb;
|
||||
private Context mCtx;
|
||||
private boolean mRememberKeyfile;
|
||||
|
||||
public LoadDB(Database db, Context ctx, Uri uri, String pass, Uri key, OnFinish finish) {
|
||||
public LoadDatabaseRunnable(Context context, Database database, Uri uri, String pass, Uri key, OnFinishRunnable finish) {
|
||||
super(finish);
|
||||
|
||||
mDb = db;
|
||||
mCtx = ctx;
|
||||
mUri = uri;
|
||||
mPass = pass;
|
||||
mKey = key;
|
||||
this.mContext = context;
|
||||
this.mDatabase = database;
|
||||
this.mUri = uri;
|
||||
this.mPass = pass;
|
||||
this.mKey = key;
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||
mRememberKeyfile = prefs.getBoolean(ctx.getString(R.string.keyfile_key), ctx.getResources().getBoolean(R.bool.keyfile_default));
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
this.mRememberKeyfile = prefs.getBoolean(context.getString(R.string.keyfile_key), context.getResources().getBoolean(R.bool.keyfile_default));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
mDb.loadData(mCtx, mUri, mPass, mKey, mStatus);
|
||||
mDatabase.loadData(mContext, mUri, mPass, mKey, mStatus);
|
||||
|
||||
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 = mContext.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 = mContext.getString(messageId);
|
||||
Log.e(TAG, errorMessage, e);
|
||||
finish(false, errorMessage);
|
||||
}
|
||||
|
||||
private void saveFileData(Uri uri, Uri key) {
|
||||
if ( ! mRememberKeyfile ) {
|
||||
key = null;
|
||||
@@ -120,6 +134,4 @@ public class LoadDB extends RunnableOnFinish {
|
||||
App.getFileHistory().createFile(uri, key);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -75,11 +75,30 @@ public class OnFinish implements Runnable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ONLY to use in UIThread, typically in an Activity, Fragment or a Service
|
||||
* @param ctx Context to show the message
|
||||
*/
|
||||
protected void displayMessage(Context ctx) {
|
||||
if ( mMessage != null && mMessage.length() > 0 ) {
|
||||
Toast.makeText(ctx, mMessage, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return mSuccess;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean mSuccess) {
|
||||
this.mSuccess = mSuccess;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return mMessage;
|
||||
}
|
||||
|
||||
public void setMessage(String mMessage) {
|
||||
this.mMessage = mMessage;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
private Database mDb;
|
||||
private boolean mDontSave;
|
||||
private Context mCtx;
|
||||
public class SaveDatabaseRunnable extends RunnableOnFinish {
|
||||
|
||||
public SaveDB(Context ctx, Database db, OnFinish finish, boolean dontSave) {
|
||||
private Context mContext;
|
||||
private Database mDatabase;
|
||||
private boolean mDontSave;
|
||||
|
||||
public SaveDatabaseRunnable(Context context, Database database, OnFinishRunnable finish, boolean dontSave) {
|
||||
super(finish);
|
||||
|
||||
mDb = db;
|
||||
mDontSave = dontSave;
|
||||
mCtx = ctx;
|
||||
|
||||
this.mContext = context;
|
||||
this.mDatabase = database;
|
||||
this.mDontSave = dontSave;
|
||||
}
|
||||
|
||||
public SaveDB(Context ctx, Database db, OnFinish finish) {
|
||||
super(finish);
|
||||
|
||||
mDb = db;
|
||||
mDontSave = false;
|
||||
mCtx = ctx;
|
||||
public SaveDatabaseRunnable(Context ctx, Database db, OnFinishRunnable finish) {
|
||||
this(ctx, db, finish, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -52,7 +49,7 @@ public class SaveDB extends RunnableOnFinish {
|
||||
|
||||
if ( ! mDontSave ) {
|
||||
try {
|
||||
mDb.saveData(mCtx);
|
||||
mDatabase.saveData(mContext);
|
||||
} catch (IOException e) {
|
||||
finish(false, e.getMessage());
|
||||
return;
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.kunzisoft.keepass.database.action.node;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwNode;
|
||||
import com.kunzisoft.keepass.database.action.ActionWithSaveDatabaseRunnable;
|
||||
|
||||
abstract class ActionNodeDatabaseRunnable extends ActionWithSaveDatabaseRunnable {
|
||||
|
||||
private AfterActionNodeOnFinish callbackRunnable;
|
||||
|
||||
public ActionNodeDatabaseRunnable(Context context, Database db, AfterActionNodeOnFinish finish, boolean dontSave) {
|
||||
super(context, db, finish, dontSave);
|
||||
this.callbackRunnable = finish;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback method who return the node(s) modified after an action
|
||||
* - Add : @param oldNode NULL, @param newNode CreatedNode
|
||||
* - Copy : @param oldNode NodeToCopy, @param newNode NodeCopied
|
||||
* - Delete : @param oldNode NodeToDelete, @param NULL
|
||||
* - Move : @param oldNode NULL, @param NodeToMove
|
||||
* - Update : @param oldNode NodeToUpdate, @param NodeUpdated
|
||||
*/
|
||||
protected void callbackNodeAction(boolean success, String message, PwNode oldNode, PwNode newNode) {
|
||||
if (callbackRunnable != null) {
|
||||
callbackRunnable.setSuccess(success);
|
||||
callbackRunnable.setMessage(message);
|
||||
callbackRunnable.run(oldNode, newNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,57 +17,40 @@
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.edit;
|
||||
package com.kunzisoft.keepass.database.action.node;
|
||||
|
||||
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 ActionNodeDatabaseRunnable {
|
||||
|
||||
protected Database mDb;
|
||||
private PwEntry mEntry;
|
||||
private Context ctx;
|
||||
private boolean mDontSave;
|
||||
private PwEntry mNewEntry;
|
||||
|
||||
public AddEntry(Context ctx, Database db, PwEntry entry, OnFinish finish) {
|
||||
this(ctx, db, entry, finish, false);
|
||||
public AddEntryRunnable(Context ctx, Database db, PwEntry entryToAdd, AfterActionNodeOnFinish finish) {
|
||||
this(ctx, db, entryToAdd, finish, false);
|
||||
}
|
||||
|
||||
public AddEntry(Context ctx, Database db, PwEntry entry, OnFinish finish, boolean dontSave) {
|
||||
super(finish);
|
||||
|
||||
this.mDb = db;
|
||||
this.mEntry = entry;
|
||||
this.ctx = ctx;
|
||||
this.mDontSave = dontSave;
|
||||
|
||||
this.mFinish = new AfterAdd(mFinish);
|
||||
public AddEntryRunnable(Context ctx, Database db, PwEntry entryToAdd, AfterActionNodeOnFinish finish, boolean dontSave) {
|
||||
super(ctx, db, finish, dontSave);
|
||||
|
||||
this.mNewEntry = entryToAdd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mDb.addEntryTo(mEntry, mEntry.getParent());
|
||||
mDatabase.addEntryTo(mNewEntry, mNewEntry.getParent());
|
||||
|
||||
// Commit to disk
|
||||
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave);
|
||||
save.run();
|
||||
super.run();
|
||||
}
|
||||
|
||||
private class AfterAdd extends OnFinish {
|
||||
|
||||
AfterAdd(OnFinish finish) {
|
||||
super(finish);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if ( !mSuccess ) {
|
||||
mDb.removeEntryFrom(mEntry, mEntry.getParent());
|
||||
}
|
||||
// TODO if add entry callback
|
||||
super.run();
|
||||
@Override
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
mDatabase.removeEntryFrom(mNewEntry, mNewEntry.getParent());
|
||||
}
|
||||
callbackNodeAction(success, message, null, mNewEntry);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.database.action.node;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwGroup;
|
||||
|
||||
public class AddGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||
|
||||
private PwGroup mNewGroup;
|
||||
|
||||
public AddGroupRunnable(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode) {
|
||||
this(ctx, db, newGroup, afterAddNode, false);
|
||||
}
|
||||
|
||||
public AddGroupRunnable(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode, boolean dontSave) {
|
||||
super(ctx, db, afterAddNode, dontSave);
|
||||
|
||||
this.mNewGroup = newGroup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mDatabase.addGroupTo(mNewGroup, mNewGroup.getParent());
|
||||
|
||||
// Commit to disk
|
||||
super.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
mDatabase.removeGroupFrom(mNewGroup, mNewGroup.getParent());
|
||||
}
|
||||
callbackNodeAction(success, message, null, mNewGroup);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.action.node;
|
||||
|
||||
import android.os.Handler;
|
||||
|
||||
import com.kunzisoft.keepass.database.PwNode;
|
||||
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public abstract class AfterActionNodeOnFinish extends OnFinishRunnable {
|
||||
|
||||
public AfterActionNodeOnFinish() {
|
||||
super(new Handler());
|
||||
}
|
||||
|
||||
public abstract void run(@Nullable PwNode oldNode, @Nullable PwNode newNode);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.action.node;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwEntry;
|
||||
import com.kunzisoft.keepass.database.PwGroup;
|
||||
|
||||
public class CopyEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
|
||||
private static final String TAG = CopyEntryRunnable.class.getName();
|
||||
|
||||
private PwEntry mEntryToCopy;
|
||||
private PwEntry mEntryCopied;
|
||||
private PwGroup mNewParent;
|
||||
|
||||
public CopyEntryRunnable(Context context, Database db, PwEntry oldE, PwGroup newParent, AfterActionNodeOnFinish afterAddNode) {
|
||||
this(context, db, oldE, newParent, afterAddNode, false);
|
||||
}
|
||||
|
||||
public CopyEntryRunnable(Context context, Database db, PwEntry oldE, PwGroup newParent, AfterActionNodeOnFinish afterAddNode, boolean dontSave) {
|
||||
super(context, db, afterAddNode, dontSave);
|
||||
|
||||
this.mEntryToCopy = oldE;
|
||||
this.mNewParent = newParent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// Update entry with new values
|
||||
mEntryCopied = mDatabase.copyEntry(mEntryToCopy, mNewParent);
|
||||
|
||||
if (mEntryCopied != null) {
|
||||
mEntryCopied.touch(true, true);
|
||||
|
||||
// Commit to disk
|
||||
super.run();
|
||||
} else {
|
||||
Log.e(TAG, "Unable to create a copy of the entry");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
// If we fail to save, try to delete the copy
|
||||
try {
|
||||
mDatabase.deleteEntry(mEntryCopied);
|
||||
} catch (Exception e) {
|
||||
Log.i(TAG, "Unable to delete the copied entry");
|
||||
}
|
||||
}
|
||||
callbackNodeAction(success, message, mEntryToCopy, mEntryCopied);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.database.action.node;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwEntry;
|
||||
import com.kunzisoft.keepass.database.PwGroup;
|
||||
|
||||
public class DeleteEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
|
||||
private PwEntry mEntryToDelete;
|
||||
private PwGroup mParent;
|
||||
private boolean mRecycle;
|
||||
|
||||
public DeleteEntryRunnable(Context ctx, Database db, PwEntry entry, AfterActionNodeOnFinish finish) {
|
||||
this(ctx, db, entry, finish, false);
|
||||
}
|
||||
|
||||
public DeleteEntryRunnable(Context ctx, Database db, PwEntry entry, AfterActionNodeOnFinish finish, boolean dontSave) {
|
||||
super(ctx, db, finish, dontSave);
|
||||
|
||||
this.mEntryToDelete = entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mParent = mEntryToDelete.getParent();
|
||||
|
||||
// Remove Entry from parent
|
||||
mRecycle = mDatabase.canRecycle(mEntryToDelete);
|
||||
if (mRecycle) {
|
||||
mDatabase.recycle(mEntryToDelete);
|
||||
}
|
||||
else {
|
||||
mDatabase.deleteEntry(mEntryToDelete);
|
||||
}
|
||||
|
||||
// Commit database
|
||||
super.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
if (mRecycle) {
|
||||
mDatabase.undoRecycle(mEntryToDelete, mParent);
|
||||
}
|
||||
else {
|
||||
mDatabase.undoDeleteEntry(mEntryToDelete, mParent);
|
||||
}
|
||||
}
|
||||
callbackNodeAction(success, message, mEntryToDelete, null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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.database.action.node;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.kunzisoft.keepass.app.App;
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwEntry;
|
||||
import com.kunzisoft.keepass.database.PwGroup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeleteGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||
|
||||
private PwGroup<PwGroup, PwGroup, PwEntry> mGroupToDelete;
|
||||
private PwGroup mParent;
|
||||
private boolean mRecycle;
|
||||
|
||||
public DeleteGroupRunnable(Context ctx, Database db, PwGroup<PwGroup, PwGroup, PwEntry> group, AfterActionNodeOnFinish finish) {
|
||||
this(ctx, db, group, finish, false);
|
||||
}
|
||||
|
||||
public DeleteGroupRunnable(Context ctx, Database db, PwGroup<PwGroup, PwGroup, PwEntry> group, AfterActionNodeOnFinish finish, boolean dontSave) {
|
||||
super(ctx, db, finish, dontSave);
|
||||
mGroupToDelete = group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mParent = mGroupToDelete.getParent();
|
||||
|
||||
// Remove Group from parent
|
||||
mRecycle = mDatabase.canRecycle(mGroupToDelete);
|
||||
if (mRecycle) {
|
||||
mDatabase.recycle(mGroupToDelete);
|
||||
}
|
||||
else {
|
||||
// TODO tests
|
||||
// Remove child entries
|
||||
List<PwEntry> childEnt = new ArrayList<>(mGroupToDelete.getChildEntries()); // TODO new Methods
|
||||
for ( int i = 0; i < childEnt.size(); i++ ) {
|
||||
DeleteEntryRunnable task = new DeleteEntryRunnable(mContext, mDatabase, childEnt.get(i), null, true);
|
||||
task.run();
|
||||
}
|
||||
|
||||
// Remove child groups
|
||||
List<PwGroup> childGrp = new ArrayList<>(mGroupToDelete.getChildGroups());
|
||||
for ( int i = 0; i < childGrp.size(); i++ ) {
|
||||
DeleteGroupRunnable task = new DeleteGroupRunnable(mContext, mDatabase, childGrp.get(i), null, true);
|
||||
task.run();
|
||||
}
|
||||
mDatabase.deleteGroup(mGroupToDelete);
|
||||
|
||||
// Remove from PwDatabaseV3
|
||||
// TODO ENcapsulate
|
||||
mDatabase.getPwDatabase().getGroups().remove(mGroupToDelete);
|
||||
}
|
||||
|
||||
// Commit Database
|
||||
super.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
if (mRecycle) {
|
||||
mDatabase.undoRecycle(mGroupToDelete, mParent);
|
||||
}
|
||||
else {
|
||||
// Let's not bother recovering from a failure to save a deleted tree. It is too much work.
|
||||
App.setShutdown();
|
||||
// TODO TEST pm.undoDeleteGroup(mGroup, mParent);
|
||||
}
|
||||
}
|
||||
callbackNodeAction(success, message, mGroupToDelete, null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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.action.node;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwEntry;
|
||||
import com.kunzisoft.keepass.database.PwGroup;
|
||||
|
||||
public class MoveEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
|
||||
private static final String TAG = MoveEntryRunnable.class.getName();
|
||||
|
||||
private PwEntry mEntryToMove;
|
||||
private PwGroup mOldParent;
|
||||
private PwGroup mNewParent;
|
||||
|
||||
public MoveEntryRunnable(Context context, Database db, PwEntry oldE, PwGroup newParent, AfterActionNodeOnFinish afterAddNode) {
|
||||
this(context, db, oldE, newParent, afterAddNode, false);
|
||||
}
|
||||
|
||||
public MoveEntryRunnable(Context context, Database db, PwEntry oldE, PwGroup newParent, AfterActionNodeOnFinish afterAddNode, boolean dontSave) {
|
||||
super(context, db, afterAddNode, dontSave);
|
||||
|
||||
this.mEntryToMove = oldE;
|
||||
this.mNewParent = newParent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// Move entry in new parent
|
||||
|
||||
mOldParent = mEntryToMove.getParent();
|
||||
mDatabase.moveEntry(mEntryToMove, mNewParent);
|
||||
|
||||
if (mEntryToMove != null) {
|
||||
mEntryToMove.touch(true, true);
|
||||
|
||||
// Commit to disk
|
||||
super.run();
|
||||
} else {
|
||||
Log.e(TAG, "Unable to create a copy of the entry");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
// If we fail to save, try to remove in the first place
|
||||
try {
|
||||
mDatabase.moveEntry(mEntryToMove, mOldParent);
|
||||
} catch (Exception e) {
|
||||
Log.i(TAG, "Unable to replace the entry");
|
||||
}
|
||||
}
|
||||
callbackNodeAction(success, message, null, mEntryToMove);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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.action.node;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwGroup;
|
||||
|
||||
public class MoveGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||
|
||||
private static final String TAG = MoveGroupRunnable.class.getName();
|
||||
|
||||
private PwGroup mGroupToMove;
|
||||
private PwGroup mOldParent;
|
||||
private PwGroup mNewParent;
|
||||
|
||||
public MoveGroupRunnable(Context context, Database db, PwGroup groupToMove, PwGroup newParent, AfterActionNodeOnFinish afterAddNode) {
|
||||
this(context, db, groupToMove, newParent, afterAddNode, false);
|
||||
}
|
||||
|
||||
public MoveGroupRunnable(Context context, Database db, PwGroup groupToMove, PwGroup newParent, AfterActionNodeOnFinish afterAddNode, boolean dontSave) {
|
||||
super(context, db, afterAddNode, dontSave);
|
||||
|
||||
this.mGroupToMove = groupToMove;
|
||||
this.mNewParent = newParent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mOldParent = mGroupToMove.getParent();
|
||||
// Move group in new parent if not in the current group
|
||||
if (!mGroupToMove.equals(mNewParent)
|
||||
&& !mNewParent.isContainedIn(mGroupToMove)) {
|
||||
mDatabase.moveGroup(mGroupToMove, mNewParent);
|
||||
|
||||
if (mGroupToMove != null) {
|
||||
mGroupToMove.touch(true, true);
|
||||
|
||||
// Commit to disk
|
||||
super.run();
|
||||
} else {
|
||||
Log.e(TAG, "Unable to create a copy of the group");
|
||||
}
|
||||
} else {
|
||||
// Only finish thread
|
||||
mFinish.setResult(false);
|
||||
String message = mContext.getString(R.string.error_move_folder_in_itself);
|
||||
Log.e(TAG, message);
|
||||
mFinish.setMessage(message);
|
||||
mFinish.run();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
// If we fail to save, try to move in the first place
|
||||
try {
|
||||
mDatabase.moveGroup(mGroupToMove, mOldParent);
|
||||
} catch (Exception e) {
|
||||
Log.i(TAG, "Unable to replace the group");
|
||||
}
|
||||
}
|
||||
callbackNodeAction(success, message, null, mGroupToMove);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.database.action.node;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwEntry;
|
||||
|
||||
public class UpdateEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
|
||||
private PwEntry mOldEntry;
|
||||
private PwEntry mNewEntry;
|
||||
private PwEntry mBackupEntry;
|
||||
|
||||
public UpdateEntryRunnable(Context ctx, Database db, PwEntry oldE, PwEntry newE, AfterActionNodeOnFinish finish) {
|
||||
this(ctx, db, oldE, newE, finish, false);
|
||||
}
|
||||
|
||||
public UpdateEntryRunnable(Context ctx, Database db, PwEntry oldE, PwEntry newE, AfterActionNodeOnFinish finish, boolean dontSave) {
|
||||
super(ctx, db, finish, dontSave);
|
||||
|
||||
this.mOldEntry = oldE;
|
||||
this.mNewEntry = newE;
|
||||
// Keep backup of original values in case save fails
|
||||
this.mBackupEntry = mOldEntry.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// Update entry with new values
|
||||
mDatabase.updateEntry(mOldEntry, mNewEntry);
|
||||
mOldEntry.touch(true, true);
|
||||
|
||||
super.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
// If we fail to save, back out changes to global structure
|
||||
mDatabase.updateEntry(mOldEntry, mBackupEntry);
|
||||
}
|
||||
callbackNodeAction(success, message, mOldEntry, mNewEntry);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.database.action.node;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwGroup;
|
||||
|
||||
public class UpdateGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||
|
||||
private PwGroup mOldGroup;
|
||||
private PwGroup mNewGroup;
|
||||
private PwGroup mBackupGroup;
|
||||
|
||||
public UpdateGroupRunnable(Context ctx, Database db, PwGroup oldGroup, PwGroup newGroup, AfterActionNodeOnFinish finish) {
|
||||
this(ctx, db, oldGroup, newGroup, finish, false);
|
||||
}
|
||||
|
||||
public UpdateGroupRunnable(Context ctx, Database db, PwGroup oldGroup, PwGroup newGroup, AfterActionNodeOnFinish finish, boolean dontSave) {
|
||||
super(ctx, db, finish, dontSave);
|
||||
|
||||
this.mOldGroup = oldGroup;
|
||||
this.mNewGroup = newGroup;
|
||||
// Keep backup of original values in case save fails
|
||||
this.mBackupGroup = mOldGroup.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// Update group with new values
|
||||
mDatabase.updateGroup(mOldGroup, mNewGroup);
|
||||
mOldGroup.touch(true, true);
|
||||
|
||||
// Commit to disk
|
||||
super.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
// If we fail to save, back out changes to global structure
|
||||
mDatabase.updateGroup(mOldGroup, mBackupGroup);
|
||||
}
|
||||
callbackNodeAction(success, message, mOldGroup, mNewGroup);
|
||||
}
|
||||
}
|
||||
@@ -1,79 +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.database.edit;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwGroup;
|
||||
|
||||
public class AddGroup extends RunnableOnFinish {
|
||||
|
||||
protected Database mDb;
|
||||
private PwGroup mNewGroup;
|
||||
private Context ctx;
|
||||
private boolean mDontSave;
|
||||
|
||||
public AddGroup(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode) {
|
||||
this(ctx, db, newGroup, afterAddNode, false);
|
||||
}
|
||||
|
||||
public AddGroup(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode,
|
||||
boolean dontSave) {
|
||||
super(afterAddNode);
|
||||
|
||||
this.mDb = db;
|
||||
this.mNewGroup = newGroup;
|
||||
this.mDontSave = dontSave;
|
||||
this.ctx = ctx;
|
||||
|
||||
this.mFinish = new AfterAdd(mFinish);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mDb.addGroupTo(mNewGroup, mNewGroup.getParent());
|
||||
|
||||
// Commit to disk
|
||||
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave);
|
||||
save.run();
|
||||
}
|
||||
|
||||
private class AfterAdd extends OnFinish {
|
||||
|
||||
AfterAdd(OnFinish finish) {
|
||||
super(finish);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if ( !mSuccess ) {
|
||||
mDb.removeGroupFrom(mNewGroup, mNewGroup.getParent());
|
||||
}
|
||||
|
||||
// TODO Better callback
|
||||
AfterActionNodeOnFinish afterAddNode =
|
||||
(AfterActionNodeOnFinish) super.mOnFinish;
|
||||
afterAddNode.mSuccess = mSuccess;
|
||||
afterAddNode.mMessage = mMessage;
|
||||
afterAddNode.run(null, mNewGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,103 +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.database.edit;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwEntry;
|
||||
import com.kunzisoft.keepass.database.PwGroup;
|
||||
|
||||
/** Task to delete entries
|
||||
* @author bpellin
|
||||
*
|
||||
*/
|
||||
public class DeleteEntry extends RunnableOnFinish {
|
||||
|
||||
private Database mDb;
|
||||
private PwEntry mEntry;
|
||||
private boolean mDontSave;
|
||||
private Context ctx;
|
||||
|
||||
public DeleteEntry(Context ctx, Database db, PwEntry entry, OnFinish finish) {
|
||||
this(ctx, db, entry, finish, false);
|
||||
}
|
||||
|
||||
public DeleteEntry(Context ctx, Database db, PwEntry entry, OnFinish finish, boolean dontSave) {
|
||||
super(finish);
|
||||
|
||||
this.mDb = db;
|
||||
this.mEntry = entry;
|
||||
this.mDontSave = dontSave;
|
||||
this.ctx = ctx;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
PwGroup parent = mEntry.getParent();
|
||||
|
||||
// Remove Entry from parent
|
||||
boolean recycle = mDb.canRecycle(mEntry);
|
||||
if (recycle) {
|
||||
mDb.recycle(mEntry);
|
||||
}
|
||||
else {
|
||||
mDb.deleteEntry(mEntry);
|
||||
}
|
||||
|
||||
// Save
|
||||
mFinish = new AfterDelete(mFinish, parent, mEntry, recycle);
|
||||
|
||||
// Commit database
|
||||
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave);
|
||||
save.run();
|
||||
}
|
||||
|
||||
private class AfterDelete extends OnFinish {
|
||||
|
||||
private PwGroup mParent;
|
||||
private PwEntry mEntry;
|
||||
private boolean recycled;
|
||||
|
||||
AfterDelete(OnFinish finish, PwGroup parent, PwEntry entry, boolean r) {
|
||||
super(finish);
|
||||
|
||||
mParent = parent;
|
||||
mEntry = entry;
|
||||
recycled = r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if ( !mSuccess ) {
|
||||
if (recycled) {
|
||||
mDb.undoRecycle(mEntry, mParent);
|
||||
}
|
||||
else {
|
||||
mDb.undoDeleteEntry(mEntry, mParent);
|
||||
}
|
||||
}
|
||||
// TODO Callback after delete entry
|
||||
|
||||
super.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,125 +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.database.edit;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.kunzisoft.keepass.app.App;
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwEntry;
|
||||
import com.kunzisoft.keepass.database.PwGroup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeleteGroup 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) {
|
||||
super(finish);
|
||||
setMembers(ctx, db, group, false);
|
||||
}
|
||||
|
||||
public DeleteGroup(Context ctx, Database db, PwGroup<PwGroup, PwGroup, PwEntry> group, OnFinish finish, boolean dontSave) {
|
||||
super(finish);
|
||||
setMembers(ctx, db, group, dontSave);
|
||||
}
|
||||
|
||||
private void setMembers(Context ctx, Database db, PwGroup<PwGroup, PwGroup, PwEntry> group, boolean dontSave) {
|
||||
mDb = db;
|
||||
mGroup = group;
|
||||
mContext = ctx;
|
||||
mDontSave = dontSave;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
PwGroup parent = mGroup.getParent();
|
||||
|
||||
// Remove Group from parent
|
||||
boolean recycle = mDb.canRecycle(mGroup);
|
||||
if (recycle) {
|
||||
mDb.recycle(mGroup);
|
||||
}
|
||||
else {
|
||||
// TODO tests
|
||||
// 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);
|
||||
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);
|
||||
task.run();
|
||||
}
|
||||
mDb.deleteGroup(mGroup);
|
||||
|
||||
// Remove from PwDatabaseV3
|
||||
// TODO ENcapsulate
|
||||
mDb.getPwDatabase().getGroups().remove(mGroup);
|
||||
}
|
||||
|
||||
// Save
|
||||
mFinish = new AfterDelete(mFinish, parent, mGroup, recycle);
|
||||
|
||||
// Commit Database
|
||||
SaveDB save = new SaveDB(mContext, mDb, mFinish, mDontSave);
|
||||
save.run();
|
||||
}
|
||||
|
||||
private class AfterDelete extends OnFinish {
|
||||
|
||||
private PwGroup mParent;
|
||||
private PwGroup mGroup;
|
||||
private boolean recycled;
|
||||
|
||||
AfterDelete(OnFinish finish, PwGroup parent, PwGroup mGroup, boolean recycle) {
|
||||
super(finish);
|
||||
|
||||
this.mParent = parent;
|
||||
this.mGroup = mGroup;
|
||||
this.recycled = recycle;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if ( !mSuccess ) {
|
||||
if (recycled) {
|
||||
mDb.undoRecycle(mGroup, mParent);
|
||||
}
|
||||
else {
|
||||
// Let's not bother recovering from a failure to save a deleted tree. It is too much work.
|
||||
App.setShutdown();
|
||||
// TODO TEST pm.undoDeleteGroup(mGroup, mParent);
|
||||
}
|
||||
}
|
||||
// TODO Callback after delete group
|
||||
|
||||
super.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,128 +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.database.edit;
|
||||
|
||||
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 {
|
||||
|
||||
private String mPassword;
|
||||
private Uri mKeyfile;
|
||||
private Database mDb;
|
||||
private boolean mDontSave;
|
||||
private Context ctx;
|
||||
|
||||
public SetPassword(Context ctx, Database db, String password, Uri keyfile, OnFinish finish) {
|
||||
this(ctx, db, password, keyfile, finish, false);
|
||||
|
||||
}
|
||||
|
||||
public SetPassword(Context ctx, Database db, String password, Uri keyfile, OnFinish finish, boolean dontSave) {
|
||||
super(finish);
|
||||
|
||||
mDb = db;
|
||||
mPassword = password;
|
||||
mKeyfile = keyfile;
|
||||
mDontSave = dontSave;
|
||||
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();
|
||||
|
||||
byte[] backupKey = new byte[pm.getMasterKey().length];
|
||||
System.arraycopy(pm.getMasterKey(), 0, backupKey, 0, backupKey.length);
|
||||
|
||||
// Set key
|
||||
try {
|
||||
InputStream is = UriUtil.getUriInputStream(ctx, mKeyfile);
|
||||
pm.setMasterKey(mPassword, is);
|
||||
} catch (InvalidKeyFileException e) {
|
||||
erase(backupKey);
|
||||
finish(false, e.getMessage());
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
erase(backupKey);
|
||||
finish(false, e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
// Save Database
|
||||
mFinish = new AfterSave(backupKey, mFinish);
|
||||
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave);
|
||||
save.run();
|
||||
}
|
||||
|
||||
private class AfterSave extends OnFinish {
|
||||
private byte[] mBackup;
|
||||
|
||||
public AfterSave(byte[] backup, OnFinish finish) {
|
||||
super(finish);
|
||||
|
||||
mBackup = backup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if ( ! mSuccess ) {
|
||||
// Erase the current master key
|
||||
erase(mDb.getPwDatabase().getMasterKey());
|
||||
mDb.getPwDatabase().setMasterKey(mBackup);
|
||||
}
|
||||
|
||||
super.run();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Overwrite the array as soon as we don't need it to avoid keeping the extra data in memory
|
||||
* @param array
|
||||
*/
|
||||
private void erase(byte[] array) {
|
||||
if ( array == null ) return;
|
||||
|
||||
for ( int i = 0; i < array.length; i++ ) {
|
||||
array[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,84 +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.database.edit;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwEntry;
|
||||
|
||||
public class UpdateEntry extends RunnableOnFinish {
|
||||
|
||||
private Database mDb;
|
||||
private PwEntry mOldE;
|
||||
private PwEntry mNewE;
|
||||
private Context ctx;
|
||||
private boolean mDontSave;
|
||||
|
||||
public UpdateEntry(Context ctx, Database db, PwEntry oldE, PwEntry newE, OnFinish finish) {
|
||||
this(ctx, db, oldE, newE, finish, false);
|
||||
}
|
||||
|
||||
public UpdateEntry(Context ctx, Database db, PwEntry oldE, PwEntry newE, OnFinish finish, boolean dontSave) {
|
||||
super(finish);
|
||||
|
||||
this.mDb = db;
|
||||
this.mOldE = oldE;
|
||||
this.mNewE = newE;
|
||||
this.ctx = ctx;
|
||||
this.mDontSave = dontSave;
|
||||
|
||||
// Keep backup of original values in case save fails
|
||||
PwEntry backup;
|
||||
backup = mOldE.clone();
|
||||
|
||||
mFinish = new AfterUpdate(backup, finish);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// Update entry with new values
|
||||
mDb.updateEntry(mOldE, mNewE);
|
||||
mOldE.touch(true, true);
|
||||
|
||||
// Commit to disk
|
||||
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave);
|
||||
save.run();
|
||||
}
|
||||
|
||||
private class AfterUpdate extends OnFinish {
|
||||
private PwEntry mBackup;
|
||||
|
||||
AfterUpdate(PwEntry backup, OnFinish finish) {
|
||||
super(finish);
|
||||
mBackup = backup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if ( !mSuccess ) {
|
||||
// If we fail to save, back out changes to global structure
|
||||
mDb.updateEntry(mOldE, mBackup);
|
||||
}
|
||||
// TODO Callback for update entry
|
||||
super.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,88 +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.database.edit;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwGroup;
|
||||
|
||||
public class UpdateGroup extends RunnableOnFinish {
|
||||
|
||||
private Database mDb;
|
||||
private PwGroup mOldGroup;
|
||||
private PwGroup mNewGroup;
|
||||
private Context ctx;
|
||||
private boolean mDontSave;
|
||||
|
||||
public UpdateGroup(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) {
|
||||
super(finish);
|
||||
|
||||
this.mDb = db;
|
||||
this.mOldGroup = oldGroup;
|
||||
this.mNewGroup = newGroup;
|
||||
this.ctx = ctx;
|
||||
this.mDontSave = dontSave;
|
||||
|
||||
// Keep backup of original values in case save fails
|
||||
PwGroup backup;
|
||||
backup = mOldGroup.clone();
|
||||
|
||||
this.mFinish = new AfterUpdate(backup, finish);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// Update group with new values
|
||||
mDb.updateGroup(mOldGroup, mNewGroup);
|
||||
mOldGroup.touch(true, true);
|
||||
|
||||
// Commit to disk
|
||||
new SaveDB(ctx, mDb, mFinish, mDontSave).run();
|
||||
}
|
||||
|
||||
private class AfterUpdate extends OnFinish {
|
||||
private PwGroup mBackup;
|
||||
|
||||
AfterUpdate(PwGroup backup, OnFinish finish) {
|
||||
super(finish);
|
||||
mBackup = backup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if ( !mSuccess ) {
|
||||
// If we fail to save, back out changes to global structure
|
||||
mDb.updateGroup(mOldGroup, mBackup);
|
||||
}
|
||||
|
||||
// TODO Better callback
|
||||
AfterActionNodeOnFinish afterActionNodeOnFinish =
|
||||
(AfterActionNodeOnFinish) super.mOnFinish;
|
||||
afterActionNodeOnFinish.mSuccess = mSuccess;
|
||||
afterActionNodeOnFinish.mMessage = mMessage;
|
||||
afterActionNodeOnFinish.run(mOldGroup, mNewGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.kunzisoft.keepass.database.exception;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class UnknownKDF extends IOException {
|
||||
|
||||
private static String message = "Unknown key derivation function";
|
||||
|
||||
public UnknownKDF() {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public UnknownKDF(Exception e) {
|
||||
super(message, e);
|
||||
}
|
||||
}
|
||||
@@ -76,15 +76,19 @@ public class EntrySearchStringIteratorV3 extends EntrySearchStringIterator {
|
||||
switch (current) {
|
||||
case title:
|
||||
found = sp.searchInTitles;
|
||||
break;
|
||||
|
||||
case url:
|
||||
found = sp.searchInUrls;
|
||||
break;
|
||||
|
||||
case username:
|
||||
found = sp.searchInUserNames;
|
||||
found = sp.searchInUserNames;
|
||||
break;
|
||||
|
||||
case comment:
|
||||
found = sp.searchInNotes;
|
||||
break;
|
||||
|
||||
default:
|
||||
found = true;
|
||||
|
||||
@@ -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)
|
||||
throws IOException, InvalidDBException;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
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)
|
||||
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);
|
||||
|
||||
@@ -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,10 +35,9 @@ 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) throws IOException,
|
||||
InvalidDBException {
|
||||
return (PwDatabaseV3Debug) super.openDatabase(inStream, password, keyInputStream, status,
|
||||
roundsFix);
|
||||
return (PwDatabaseV3Debug) super.openDatabase(inStream, password, keyInputStream, status);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,57 +82,51 @@ 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PwDatabaseV4 openDatabase(InputStream inStream, String password,
|
||||
InputStream keyInputStream, UpdateStatus status, long roundsFix) throws IOException,
|
||||
InputStream keyInputStream, ProgressTaskUpdater progressTaskUpdater) 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);
|
||||
|
||||
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.");
|
||||
} catch (NoSuchPaddingException e) {
|
||||
throw new IOException("Invalid algorithm.");
|
||||
} catch (InvalidKeyException e) {
|
||||
throw new IOException("Invalid algorithm.");
|
||||
} catch (InvalidAlgorithmParameterException e) {
|
||||
throw new IOException("Invalid algorithm.");
|
||||
} catch (NoSuchAlgorithmException|NoSuchPaddingException|InvalidKeyException|InvalidAlgorithmParameterException e) {
|
||||
throw new IOException("Invalid algorithm.", e);
|
||||
}
|
||||
|
||||
InputStream isPlain;
|
||||
@@ -185,7 +180,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);
|
||||
}
|
||||
|
||||
@@ -962,7 +957,7 @@ public class ImporterV4 extends Importer {
|
||||
ReadUnknown(xpp);
|
||||
}
|
||||
|
||||
assert(xpp.getName() == unknownName);
|
||||
assert(xpp.getName().equals(unknownName));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -63,7 +63,7 @@ public class PwDbV3Output extends PwDbOutput {
|
||||
mPM.makeFinalKey(h3.masterSeed, h3.transformSeed, mPM.getNumberKeyEncryptionRounds());
|
||||
return mPM.getFinalKey();
|
||||
} catch (IOException e) {
|
||||
throw new PwDbOutputException("Key creation failed: " + e.getMessage());
|
||||
throw new PwDbOutputException("Key creation failed.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public class PwDbV3Output extends PwDbOutput {
|
||||
throw new Exception();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new PwDbOutputException("Algorithm not supported.");
|
||||
throw new PwDbOutputException("Algorithm not supported.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -97,11 +97,11 @@ public class PwDbV3Output extends PwDbOutput {
|
||||
bos.close();
|
||||
|
||||
} catch (InvalidKeyException e) {
|
||||
throw new PwDbOutputException("Invalid key");
|
||||
throw new PwDbOutputException("Invalid key", e);
|
||||
} catch (InvalidAlgorithmParameterException e) {
|
||||
throw new PwDbOutputException("Invalid algorithm parameter.");
|
||||
throw new PwDbOutputException("Invalid algorithm parameter.", e);
|
||||
} catch (IOException e) {
|
||||
throw new PwDbOutputException("Failed to output final encrypted part.");
|
||||
throw new PwDbOutputException("Failed to output final encrypted part.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
@@ -147,7 +145,7 @@ public class PwDbV3Output extends PwDbOutput {
|
||||
try {
|
||||
md = MessageDigest.getInstance("SHA-256");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new PwDbOutputException("SHA-256 not implemented here.");
|
||||
throw new PwDbOutputException("SHA-256 not implemented here.", e);
|
||||
}
|
||||
|
||||
// Header checksum
|
||||
@@ -155,7 +153,7 @@ public class PwDbV3Output extends PwDbOutput {
|
||||
try {
|
||||
headerDigest = MessageDigest.getInstance("SHA-256");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new PwDbOutputException("SHA-256 not implemented here.");
|
||||
throw new PwDbOutputException("SHA-256 not implemented here.", e);
|
||||
}
|
||||
NullOutputStream nos;
|
||||
nos = new NullOutputStream();
|
||||
@@ -182,7 +180,7 @@ public class PwDbV3Output extends PwDbOutput {
|
||||
bos.flush();
|
||||
bos.close();
|
||||
} catch (IOException e) {
|
||||
throw new PwDbOutputException("Failed to generate checksum.");
|
||||
throw new PwDbOutputException("Failed to generate checksum.", e);
|
||||
}
|
||||
|
||||
header.contentsHash = md.digest();
|
||||
@@ -212,7 +210,7 @@ public class PwDbV3Output extends PwDbOutput {
|
||||
los.writeInt(headerHashBlock.length);
|
||||
los.write(headerHashBlock);
|
||||
} catch (IOException e) {
|
||||
throw new PwDbOutputException("Failed to output header hash: " + e.getMessage());
|
||||
throw new PwDbOutputException("Failed to output header hash.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +222,7 @@ public class PwDbV3Output extends PwDbOutput {
|
||||
try {
|
||||
pgo.output();
|
||||
} catch (IOException e) {
|
||||
throw new PwDbOutputException("Failed to output a tree: " + e.getMessage());
|
||||
throw new PwDbOutputException("Failed to output a tree", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,7 +233,7 @@ public class PwDbV3Output extends PwDbOutput {
|
||||
try {
|
||||
peo.output();
|
||||
} catch (IOException e) {
|
||||
throw new PwDbOutputException("Failed to output an entry.");
|
||||
throw new PwDbOutputException("Failed to output an entry.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.save;
|
||||
|
||||
import android.util.Log;
|
||||
import android.util.Xml;
|
||||
|
||||
import com.kunzisoft.keepass.crypto.CipherFactory;
|
||||
@@ -35,7 +36,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;
|
||||
@@ -43,6 +43,7 @@ import com.kunzisoft.keepass.database.PwEntryV4;
|
||||
import com.kunzisoft.keepass.database.PwGroupV4;
|
||||
import com.kunzisoft.keepass.database.PwIconCustom;
|
||||
import com.kunzisoft.keepass.database.exception.PwDbOutputException;
|
||||
import com.kunzisoft.keepass.database.exception.UnknownKDF;
|
||||
import com.kunzisoft.keepass.database.security.ProtectedBinary;
|
||||
import com.kunzisoft.keepass.database.security.ProtectedString;
|
||||
import com.kunzisoft.keepass.stream.HashedBlockOutputStream;
|
||||
@@ -74,9 +75,10 @@ import javax.crypto.CipherOutputStream;
|
||||
|
||||
import biz.source_code.base64Coder.Base64Coder;
|
||||
|
||||
public class PwDbV4Output extends PwDbOutput {
|
||||
public class PwDbV4Output extends PwDbOutput<PwDbHeaderV4> {
|
||||
private static final String TAG = PwDbV4Output.class.getName();
|
||||
|
||||
PwDatabaseV4 mPM;
|
||||
private PwDatabaseV4 mPM;
|
||||
private StreamCipher randomStream;
|
||||
private XmlSerializer xml;
|
||||
private PwDbHeaderV4 header;
|
||||
@@ -86,8 +88,7 @@ public class PwDbV4Output extends PwDbOutput {
|
||||
|
||||
protected PwDbV4Output(PwDatabaseV4 pm, OutputStream os) {
|
||||
super(os);
|
||||
|
||||
mPM = pm;
|
||||
this.mPM = pm;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,15 +101,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 +125,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 +261,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());
|
||||
@@ -279,53 +279,57 @@ public class PwDbV4Output extends PwDbOutput {
|
||||
} catch (Exception e) {
|
||||
throw new PwDbOutputException("Invalid algorithm.", e);
|
||||
}
|
||||
|
||||
CipherOutputStream cos = new CipherOutputStream(os, cipher);
|
||||
|
||||
return cos;
|
||||
|
||||
return new CipherOutputStream(os, cipher);
|
||||
}
|
||||
|
||||
@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);
|
||||
kdf.randomize(mPM.getKdfParameters());
|
||||
if (mPM.getKdfParameters() == null) {
|
||||
mPM.setKdfParameters(KdfFactory.aesKdf.getDefaultParameters());
|
||||
}
|
||||
|
||||
if (h.version < PwDbHeaderV4.FILE_VERSION_32_4) {
|
||||
h.innerRandomStream = CrsAlgorithm.Salsa20;
|
||||
h.innerRandomStreamKey = new byte[32];
|
||||
try {
|
||||
KdfEngine kdf = KdfFactory.getEngineV4(mPM.getKdfParameters());
|
||||
kdf.randomize(mPM.getKdfParameters());
|
||||
} catch (UnknownKDF unknownKDF) {
|
||||
Log.e(TAG, "Unable to retrieve header", unknownKDF);
|
||||
}
|
||||
|
||||
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 {
|
||||
PwDbHeaderV4 header = new PwDbHeaderV4(mPM);
|
||||
public PwDbHeaderV4 outputHeader(OutputStream os) throws PwDbOutputException {
|
||||
|
||||
PwDbHeaderV4 header = new PwDbHeaderV4(mPM);
|
||||
setIVs(header);
|
||||
|
||||
PwDbHeaderOutputV4 pho = new PwDbHeaderOutputV4(mPM, header, os);
|
||||
@@ -468,7 +472,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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ public class GroupEditDialogFragment extends DialogFragment
|
||||
// Init elements
|
||||
editGroupDialogAction = EditGroupDialogAction.NONE;
|
||||
nameGroup = "";
|
||||
iconGroup = App.getDB().getPwDatabase().getIconFactory().getFirstIcon();
|
||||
iconGroup = App.getDB().getPwDatabase().getIconFactory().getFolderIcon();
|
||||
|
||||
if (savedInstanceState != null
|
||||
&& savedInstanceState.containsKey(KEY_ACTION_ID)
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
package com.kunzisoft.keepass.dialogs;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.compat.BuildCompat;
|
||||
|
||||
public class ReadOnlyDialog extends WarningDialog {
|
||||
|
||||
@@ -31,7 +31,7 @@ public class ReadOnlyDialog extends WarningDialog {
|
||||
|
||||
warning = context.getString(R.string.read_only_warning);
|
||||
|
||||
if (BuildCompat.getSdkVersion() >= BuildCompat.VERSION_KITKAT) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
warning = warning.concat("\n\n").concat(context.getString(R.string.read_only_kitkat_warning));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +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.dialogs;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
|
||||
public class StorageAccessFrameworkDialog extends AlertDialog {
|
||||
|
||||
public StorageAccessFrameworkDialog(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public StorageAccessFrameworkDialog(@NonNull Context context, int themeResId) {
|
||||
super(context, themeResId);
|
||||
}
|
||||
|
||||
public StorageAccessFrameworkDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
|
||||
super(context, cancelable, cancelListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
Context ctx = getContext();
|
||||
setMessage(ctx.getString(R.string.warning_disabling_storage_access_framework));
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
}
|
||||
@@ -44,31 +44,41 @@ 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(" ")
|
||||
.append(Html.fromHtml(getString(R.string.html_text_dev_feature_encourage)));
|
||||
builder.setPositiveButton(R.string.download, (dialog, id) -> {
|
||||
try {
|
||||
Util.gotoUrl(getContext(), R.string.app_pro_url);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Toast.makeText(getContext(), R.string.error_failed_to_launch_link, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
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 {
|
||||
Util.gotoUrl(getContext(), R.string.app_pro_url);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Toast.makeText(getContext(), R.string.error_failed_to_launch_link, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(android.R.string.cancel, (dialog, id) -> dismiss());
|
||||
}
|
||||
}
|
||||
else {
|
||||
stringBuilder.append(Html.fromHtml(getString(R.string.html_text_dev_feature_contibute))).append(" ")
|
||||
.append(Html.fromHtml(getString(R.string.html_text_dev_feature_encourage)));
|
||||
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();
|
||||
}
|
||||
|
||||