Compare commits

...

129 Commits

Author SHA1 Message Date
J-Jamet
0fdcc29aa2 Merge branch 'release/2.5.0.0beta10' 2018-05-13 17:05:10 +02:00
J-Jamet
37bedbffc9 Fix italian translation for compilation 2018-05-13 16:59:35 +02:00
J-Jamet
46505150c4 New Red Volcano theme and change visual feature message for version libre 2018-05-13 16:47:59 +02:00
J-Jamet
e18c5c90cc Upgrade changelogs 2018-05-13 14:52:59 +02:00
J-Jamet
1f5649d9d2 Merge branch 'feature/ChangeAlgorithms' into develop #9 #29 2018-05-13 14:25:31 +02:00
J-Jamet
7bbd55a9fd Add binary to memory explanation 2018-05-13 14:17:19 +02:00
J-Jamet
92eeccf84e Fix algorithm and kdf function for database V3 and add small trad 2018-05-13 13:55:37 +02:00
J-Jamet
7bcc289518 Upgrade explanations 2018-05-13 13:02:09 +02:00
J-Jamet
507f758c0d Add memory usage and parallelism for Argon2 settings 2018-05-12 23:53:41 +02:00
J-Jamet
6afffb7245 Register UUID of database version in KDF parameter 2018-05-11 19:19:16 +02:00
J-Jamet
c62f4ae0b3 Text if choose only one extension #105 2018-05-11 13:25:33 +02:00
J-Jamet
ee80c614e0 Fix layer error for icon free #113 2018-05-11 12:44:33 +02:00
J-Jamet
fea7af6910 Dynamic creation of KdfEngine, reorganise code 2018-05-09 15:17:55 +02:00
J-Jamet
c72aa0e97d Merge branch 'develop' into feature/ChangeAlgorithms to Fix NDK 2018-05-09 12:01:16 +02:00
J-Jamet
3dd60b5392 Fix ndk filters 2018-05-09 10:59:48 +02:00
J-Jamet
a357267552 #107 Set master password in landscape 2018-05-07 10:47:00 +02:00
J-Jamet
1badeb2eef Change FAQ as markdown and add descriptions 2018-05-07 10:34:27 +02:00
Yhaulez
0bb8d2a417 Create FAQ 2018-05-06 16:26:19 +02:00
J-Jamet
4a215db83c Change toolbar style and password layout 2018-05-05 23:16:39 +02:00
J-Jamet
512e55a170 Fix fingerprint animation and for first init 2018-05-05 20:39:01 +02:00
J-Jamet
1ebe8dc022 Update fingerprint state with checkbox 2018-05-04 21:24:57 +02:00
J-Jamet
cafeabdbc3 Fix search styles 2018-05-02 21:31:04 +02:00
J-Jamet
b342b26409 Update readme 2018-05-02 20:59:05 +02:00
J-Jamet
938c3a07af Fix wait dialog callback 2018-05-02 20:52:16 +02:00
J-Jamet
16288f98f7 Merge branch 'develop' into feature/ChangeAlgorithms 2018-05-02 15:57:47 +02:00
J-Jamet
a932156e85 Remove unused progressbar 2018-05-02 15:26:24 +02:00
J-Jamet
64e9b9fb6d Fix lock orientation change 2018-05-02 14:02:10 +02:00
J-Jamet
7af28550da Merge branch 'feature/RefactorProgress' into develop #98 2018-05-02 13:49:56 +02:00
J-Jamet
60e2d786dd Change progress dialog title, and remove code 2018-05-02 13:49:03 +02:00
J-Jamet
ec08f3430d Add progress bar for all, create database in a single progress dialog 2018-05-02 09:54:55 +02:00
J-Jamet
a50aa0fb95 Fix null pointer for KeyDerivationName 2018-05-02 07:16:55 +02:00
J-Jamet
cf026e8eaa Update progress bar and message progress 2018-05-01 20:03:43 +02:00
J-Jamet
77614d0c4a Upgrade changelogs and version 2018-04-30 19:54:50 +02:00
J-Jamet
e8d71039d7 refactor 2018-04-30 18:18:13 +02:00
J-Jamet
4164b5bd37 Fix crash by locking activity position 2018-04-30 17:47:31 +02:00
J-Jamet
3c66ec82b5 Upgrade French 2018-04-30 17:00:42 +02:00
J-Jamet
b796c16877 Upgrade Italian 2018-04-30 16:57:10 +02:00
J-Jamet
42d34d8f0c Add material icon pack in free version and change texts 2018-04-30 16:10:18 +02:00
J-Jamet
5fbb37df82 Fix german fingerprint error 2018-04-29 14:07:56 +02:00
J-Jamet
52e12d7cbd Upgrade russian translation 2018-04-28 22:34:25 +02:00
J-Jamet
5cf5719e8e Fix education text color 2018-04-28 20:08:33 +02:00
J-Jamet
af3a80143e Fix crash by return blank when Resources$NotFoundException 2018-04-28 19:49:59 +02:00
J-Jamet
90db27c3fe Refactor Master key functions 2018-04-28 18:15:30 +02:00
J-Jamet
3d584b76f7 Choose kdf and encapsulate code 2018-04-28 15:58:04 +02:00
J-Jamet
fbf3dec421 Assign algorithm dynamically 2018-04-28 12:20:18 +02:00
J-Jamet
1d36683128 Remove screens in Readme 2018-04-28 11:11:50 +02:00
J-Jamet
cefc546c0a Upgrade german translation 2018-04-28 11:08:23 +02:00
J-Jamet
7aeb51813c Show algorithm dialog 2018-04-26 23:00:15 +02:00
J-Jamet
d6fc29ec79 Creation of classes and prepare assignment for algorithms 2018-04-26 22:00:11 +02:00
J-Jamet
9af182e0c3 Change dark style 2018-04-26 16:14:22 +02:00
J-Jamet
c7120b997f Fix contribution issue for KeePass DX Pro 2018-04-26 14:39:45 +02:00
J-Jamet
e61571fcec Upgrade fastlane 2018-04-26 12:18:14 +02:00
J-Jamet
9a900b32b2 Merge tag '2.5.0.0beta9' into develop
2.5.0.0beta9
2018-04-25 13:16:14 +02:00
J-Jamet
1033dd78b0 Merge branch 'release/2.5.0.0beta9' 2018-04-25 13:15:44 +02:00
J-Jamet
4aaae3f59e Upgrade readme and screen 2018-04-25 13:15:13 +02:00
J-Jamet
1424633a58 Update screenshots 2018-04-25 01:36:30 +02:00
J-Jamet
c9b98094e5 Change purple colors 2018-04-24 00:46:31 +02:00
J-Jamet
5707026985 Change fingerprint visual 2018-04-24 00:36:37 +02:00
J-Jamet
bfcfb842fb Fix visual bugs 2018-04-23 20:59:59 +02:00
J-Jamet
8fe2230891 Fix visual bugs 2018-04-23 20:40:17 +02:00
J-Jamet
41cc0b1a5a Fix compilation 2018-04-23 19:20:15 +02:00
J-Jamet
cc8c525dab Upgrade fastlane 2018-04-23 18:55:32 +02:00
J-Jamet
92bc3c2838 Add pro app name 2018-04-23 15:51:13 +02:00
J-Jamet
1d065e7bc5 Fix crash when orientation change after a modification 2018-04-21 15:44:17 +02:00
J-Jamet
fb1b90a281 Add modification 2018-04-21 14:20:43 +02:00
J-Jamet
268f716104 Upgrade fastlane 2018-04-21 07:14:34 +02:00
J-Jamet
b7328875f1 Fix filepicker style 2018-04-20 20:27:34 +02:00
J-Jamet
02ee58efa7 Add dev to crypt settings and comment transition 2018-04-20 19:59:31 +02:00
J-Jamet
6754881847 Add activity animation 2018-04-20 17:57:39 +02:00
J-Jamet
6e4c5d8c26 Add transition for settings 2018-04-20 17:43:08 +02:00
J-Jamet
544648c2eb Remove TODO 2018-04-20 16:03:10 +02:00
J-Jamet
e62f8bf56b Solve empty password issue #2 2018-04-20 15:48:53 +02:00
J-Jamet
7f5138b08b Upgrade Changelogs and versions 2018-04-20 10:44:22 +02:00
J-Jamet
a367aeaf12 Change font by Droid Sans Mono Slashed and activate by default, add it in password generator #86 2018-04-19 11:09:55 +02:00
J-Jamet
fc6453beba Keyboard setting with dev dialog 2018-04-18 22:28:49 +02:00
J-Jamet
8a981b7a79 Move appearance settings 2018-04-18 21:26:42 +02:00
J-Jamet
d7f9a02699 New selection screen 2018-04-18 19:32:51 +02:00
J-Jamet
7c9153ea04 Open button expanded and add small text 2018-04-17 14:09:44 +02:00
J-Jamet
2c16fe3335 Add fab menu 2018-04-16 21:32:56 +02:00
J-Jamet
eb14d27ca5 #88 Fix crash when header can't be write 2018-04-16 19:47:27 +02:00
J-Jamet
7024178069 #88 Open file with kitkat 2018-04-16 19:37:03 +02:00
J-Jamet
c85ce3e0e8 Replace standart by standard 2018-04-16 16:14:27 +02:00
J-Jamet
067c5ff1cf Fix bugs for Icons and Styles, add contribution and pro dialog 2018-04-16 15:27:45 +02:00
J-Jamet
429bd99f1c Upgrade app icons 2018-04-15 23:44:35 +02:00
J-Jamet
7b5bb0fd97 Add ocean theme and fix styles 2018-04-15 21:07:44 +02:00
J-Jamet
ae50f424d3 App icon for each flavor 2018-04-15 19:28:59 +02:00
J-Jamet
53cc1ad673 Disable custom font and clipboard notification by default #86 2018-04-15 12:08:44 +02:00
J-Jamet
ceb80c6cac Remove the first activity, fix colors in Classic theme and fix custom icon tint 2018-04-14 21:54:29 +02:00
J-Jamet
71bd3ab780 Add splashscreen 2018-04-14 20:39:15 +02:00
J-Jamet
8a40a4b3ae Fix visual bugs, add classic theme and pro theme #27 2018-04-14 19:58:26 +02:00
J-Jamet
7772db17ae Change productFlavors names 2018-04-14 15:36:41 +02:00
J-Jamet
11738d807c Merge branch 'feature/IconPackModules' into develop 2018-04-13 20:55:15 +02:00
J-Jamet
80b9a8fa50 List of IconPack as gradle entity 2018-04-13 20:54:05 +02:00
J-Jamet
d619f6581e Fix landscape icon #84 2018-04-13 20:04:11 +02:00
J-Jamet
697e9aa923 Fix visual bugs and save icon pack setting 2018-04-13 19:47:56 +02:00
J-Jamet
15c843fbb9 Add setting to choose an IconPack 2018-04-13 17:08:13 +02:00
J-Jamet
b6b7e61cfb Add tint for icon pack 2018-04-12 19:21:53 +02:00
J-Jamet
d5b0ee9371 Add feather icon and licences for icon packs 2018-04-12 17:32:06 +02:00
J-Jamet
e86807c3d3 Clean code and solve recovered icon 2018-04-11 20:57:04 +02:00
J-Jamet
08fcb119a9 Finish merge material_icon_pack 2018-04-11 19:10:48 +02:00
J-Jamet
edff33afd1 Merge branch 'justintime4tea-53_new-icon-pack' into feature/IconPackModules (Move in module material_icon_pack)
# Conflicts:
#	app/build.gradle
#	icon-pack-classic/src/main/res/drawable-hdpi/classic_64_32dp.png
#	icon-pack-classic/src/main/res/drawable-ldpi/classic_64_32dp.png
#	icon-pack-classic/src/main/res/drawable/classic_64_32dp.png
2018-04-11 19:09:53 +02:00
J-Jamet
bdfa963bed Merge branch '53_new-icon-pack' of git://github.com/justintime4tea/KeePass-Libre into justintime4tea-53_new-icon-pack 2018-04-11 18:23:17 +02:00
J-Jamet
4eff247865 Add icon pack identifier 2018-04-11 18:13:58 +02:00
J-Jamet
3e3d5bd7d8 Merge branch 'feature/Education' into develop 2018-04-11 15:31:18 +02:00
J-Jamet
5a74d1be8f Add links for field reference and autofill setting, add doc, fix glitches, add changelogs 2018-04-10 21:15:05 +02:00
J-Jamet
812eccfe0e Sort_selection as ScrollView #83 2018-04-10 19:01:22 +02:00
J-Jamet
d00c337382 Fix visual issues in education screens 2018-04-10 17:58:17 +02:00
J-Jamet
54dbcc95ab Change education for entries screens 2018-04-10 17:31:22 +02:00
J-Jamet
2e5ddd80ff Change education for group screen 2018-04-10 15:18:27 +02:00
J-Jamet
2c44a4d760 Change education for password screen 2018-04-10 12:44:49 +02:00
J-Jamet
f8561222d5 Change education for database selection 2018-04-10 12:23:41 +02:00
J-Jamet
2c8e3e9c8e Merge branch 'develop' into feature/Education
# Conflicts:
#	app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.java
#	app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.java
#	app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.java
#	app/src/main/java/com/kunzisoft/keepass/fileselect/FileSelectActivity.java
#	app/src/main/java/com/kunzisoft/keepass/password/PasswordActivity.java
#	app/src/main/java/com/kunzisoft/keepass/utils/MenuUtil.java
#	app/src/main/res/values/donottranslate.xml
2018-04-10 10:33:52 +02:00
J-Jamet
ccbc6c07ed Update supportVersion libraries 2018-04-10 09:59:33 +02:00
J-Jamet
47e820e3d8 (Implementation) Merge branch 'justintime4tea-kunzi-develop' into develop 2018-04-10 09:49:24 +02:00
J-Jamet
13dea4b567 New icon pack importer 2018-04-09 21:37:28 +02:00
Justin Gross
70d1ce715e Change compile to implementation 2018-04-08 16:20:07 -04:00
J-Jamet
cc41545c0a create Classic Icon Pack 2018-04-08 12:45:25 +02:00
J-Jamet
aded8fab0a Rebuild classic icons (Add apple icon and remove numbers) 2018-04-07 15:41:52 +02:00
J-Jamet
9cb4d28ad8 Upgrade Readme 2018-04-07 10:31:59 +02:00
J-Jamet
a1b2235fb3 Merge tag '2.5.0.0beta8' into develop
2.5.0.0beta8
2018-04-06 20:29:47 +02:00
Justin Gross
ed7f6e4b68 Update icons to font awesome 2018-04-04 16:49:40 -04:00
Justin Gross
1ebba9d8be Merge pull request #1 from Kunzisoft/develop
Merge upstream changes
2018-04-04 11:00:37 -04:00
J-Jamet
347522b9a6 Add lock, field copy, sort and donation 2018-04-03 20:40:52 +02:00
J-Jamet
918f563faa Change Education for Password layout and fix translations 2018-04-03 17:11:46 +02:00
J-Jamet
041f3eb568 Solve visual bugs and translation 2018-04-02 12:59:02 +02:00
J-Jamet
4a1d97a622 Add entry edit screens preference 2018-04-01 16:34:54 +02:00
J-Jamet
cd0d712f56 Add reset education screens preference 2018-04-01 00:37:30 +02:00
J-Jamet
761d9a1883 Add education to "add button" 2018-03-31 21:59:05 +02:00
J-Jamet
2c9a6d7c26 Add education to database selection 2018-03-31 21:24:39 +02:00
927 changed files with 20064 additions and 2792 deletions

View File

@@ -1,3 +1,20 @@
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
* New custom font for character visibility
* New themes
* New icon pack
* Change setting organisation
* Pro version
KeepassDX (2.5.0.0beta8)
* Hide custom entries protected
* Best management of field references (https://keepass.info/help/base/fieldrefs.html)

50
FAQ.md Normal file
View File

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

View File

@@ -0,0 +1,396 @@
Attribution 4.0 International
=======================================================================
Creative Commons Corporation ("Creative Commons") is not a law firm and
does not provide legal services or legal advice. Distribution of
Creative Commons public licenses does not create a lawyer-client or
other relationship. Creative Commons makes its licenses and related
information available on an "as-is" basis. Creative Commons gives no
warranties regarding its licenses, any material licensed under their
terms and conditions, or any related information. Creative Commons
disclaims all liability for damages resulting from their use to the
fullest extent possible.
Using Creative Commons Public Licenses
Creative Commons public licenses provide a standard set of terms and
conditions that creators and other rights holders may use to share
original works of authorship and other material subject to copyright
and certain other rights specified in the public license below. The
following considerations are for informational purposes only, are not
exhaustive, and do not form part of our licenses.
Considerations for licensors: Our public licenses are
intended for use by those authorized to give the public
permission to use material in ways otherwise restricted by
copyright and certain other rights. Our licenses are
irrevocable. Licensors should read and understand the terms
and conditions of the license they choose before applying it.
Licensors should also secure all rights necessary before
applying our licenses so that the public can reuse the
material as expected. Licensors should clearly mark any
material not subject to the license. This includes other CC-
licensed material, or material used under an exception or
limitation to copyright. More considerations for licensors:
wiki.creativecommons.org/Considerations_for_licensors
Considerations for the public: By using one of our public
licenses, a licensor grants the public permission to use the
licensed material under specified terms and conditions. If
the licensor's permission is not necessary for any reason--for
example, because of any applicable exception or limitation to
copyright--then that use is not regulated by the license. Our
licenses grant only permissions under copyright and certain
other rights that a licensor has authority to grant. Use of
the licensed material may still be restricted for other
reasons, including because others have copyright or other
rights in the material. A licensor may make special requests,
such as asking that all changes be marked or described.
Although not required by our licenses, you are encouraged to
respect those requests where reasonable. More considerations
for the public:
wiki.creativecommons.org/Considerations_for_licensees
=======================================================================
Creative Commons Attribution 4.0 International Public License
By exercising the Licensed Rights (defined below), You accept and agree
to be bound by the terms and conditions of this Creative Commons
Attribution 4.0 International Public License ("Public License"). To the
extent this Public License may be interpreted as a contract, You are
granted the Licensed Rights in consideration of Your acceptance of
these terms and conditions, and the Licensor grants You such rights in
consideration of benefits the Licensor receives from making the
Licensed Material available under these terms and conditions.
Section 1 -- Definitions.
a. Adapted Material means material subject to Copyright and Similar
Rights that is derived from or based upon the Licensed Material
and in which the Licensed Material is translated, altered,
arranged, transformed, or otherwise modified in a manner requiring
permission under the Copyright and Similar Rights held by the
Licensor. For purposes of this Public License, where the Licensed
Material is a musical work, performance, or sound recording,
Adapted Material is always produced where the Licensed Material is
synched in timed relation with a moving image.
b. Adapter's License means the license You apply to Your Copyright
and Similar Rights in Your contributions to Adapted Material in
accordance with the terms and conditions of this Public License.
c. Copyright and Similar Rights means copyright and/or similar rights
closely related to copyright including, without limitation,
performance, broadcast, sound recording, and Sui Generis Database
Rights, without regard to how the rights are labeled or
categorized. For purposes of this Public License, the rights
specified in Section 2(b)(1)-(2) are not Copyright and Similar
Rights.
d. Effective Technological Measures means those measures that, in the
absence of proper authority, may not be circumvented under laws
fulfilling obligations under Article 11 of the WIPO Copyright
Treaty adopted on December 20, 1996, and/or similar international
agreements.
e. Exceptions and Limitations means fair use, fair dealing, and/or
any other exception or limitation to Copyright and Similar Rights
that applies to Your use of the Licensed Material.
f. Licensed Material means the artistic or literary work, database,
or other material to which the Licensor applied this Public
License.
g. Licensed Rights means the rights granted to You subject to the
terms and conditions of this Public License, which are limited to
all Copyright and Similar Rights that apply to Your use of the
Licensed Material and that the Licensor has authority to license.
h. Licensor means the individual(s) or entity(ies) granting rights
under this Public License.
i. Share means to provide material to the public by any means or
process that requires permission under the Licensed Rights, such
as reproduction, public display, public performance, distribution,
dissemination, communication, or importation, and to make material
available to the public including in ways that members of the
public may access the material from a place and at a time
individually chosen by them.
j. Sui Generis Database Rights means rights other than copyright
resulting from Directive 96/9/EC of the European Parliament and of
the Council of 11 March 1996 on the legal protection of databases,
as amended and/or succeeded, as well as other essentially
equivalent rights anywhere in the world.
k. You means the individual or entity exercising the Licensed Rights
under this Public License. Your has a corresponding meaning.
Section 2 -- Scope.
a. License grant.
1. Subject to the terms and conditions of this Public License,
the Licensor hereby grants You a worldwide, royalty-free,
non-sublicensable, non-exclusive, irrevocable license to
exercise the Licensed Rights in the Licensed Material to:
a. reproduce and Share the Licensed Material, in whole or
in part; and
b. produce, reproduce, and Share Adapted Material.
2. Exceptions and Limitations. For the avoidance of doubt, where
Exceptions and Limitations apply to Your use, this Public
License does not apply, and You do not need to comply with
its terms and conditions.
3. Term. The term of this Public License is specified in Section
6(a).
4. Media and formats; technical modifications allowed. The
Licensor authorizes You to exercise the Licensed Rights in
all media and formats whether now known or hereafter created,
and to make technical modifications necessary to do so. The
Licensor waives and/or agrees not to assert any right or
authority to forbid You from making technical modifications
necessary to exercise the Licensed Rights, including
technical modifications necessary to circumvent Effective
Technological Measures. For purposes of this Public License,
simply making modifications authorized by this Section 2(a)
(4) never produces Adapted Material.
5. Downstream recipients.
a. Offer from the Licensor -- Licensed Material. Every
recipient of the Licensed Material automatically
receives an offer from the Licensor to exercise the
Licensed Rights under the terms and conditions of this
Public License.
b. No downstream restrictions. You may not offer or impose
any additional or different terms or conditions on, or
apply any Effective Technological Measures to, the
Licensed Material if doing so restricts exercise of the
Licensed Rights by any recipient of the Licensed
Material.
6. No endorsement. Nothing in this Public License constitutes or
may be construed as permission to assert or imply that You
are, or that Your use of the Licensed Material is, connected
with, or sponsored, endorsed, or granted official status by,
the Licensor or others designated to receive attribution as
provided in Section 3(a)(1)(A)(i).
b. Other rights.
1. Moral rights, such as the right of integrity, are not
licensed under this Public License, nor are publicity,
privacy, and/or other similar personality rights; however, to
the extent possible, the Licensor waives and/or agrees not to
assert any such rights held by the Licensor to the limited
extent necessary to allow You to exercise the Licensed
Rights, but not otherwise.
2. Patent and trademark rights are not licensed under this
Public License.
3. To the extent possible, the Licensor waives any right to
collect royalties from You for the exercise of the Licensed
Rights, whether directly or through a collecting society
under any voluntary or waivable statutory or compulsory
licensing scheme. In all other cases the Licensor expressly
reserves any right to collect such royalties.
Section 3 -- License Conditions.
Your exercise of the Licensed Rights is expressly made subject to the
following conditions.
a. Attribution.
1. If You Share the Licensed Material (including in modified
form), You must:
a. retain the following if it is supplied by the Licensor
with the Licensed Material:
i. identification of the creator(s) of the Licensed
Material and any others designated to receive
attribution, in any reasonable manner requested by
the Licensor (including by pseudonym if
designated);
ii. a copyright notice;
iii. a notice that refers to this Public License;
iv. a notice that refers to the disclaimer of
warranties;
v. a URI or hyperlink to the Licensed Material to the
extent reasonably practicable;
b. indicate if You modified the Licensed Material and
retain an indication of any previous modifications; and
c. indicate the Licensed Material is licensed under this
Public License, and include the text of, or the URI or
hyperlink to, this Public License.
2. You may satisfy the conditions in Section 3(a)(1) in any
reasonable manner based on the medium, means, and context in
which You Share the Licensed Material. For example, it may be
reasonable to satisfy the conditions by providing a URI or
hyperlink to a resource that includes the required
information.
3. If requested by the Licensor, You must remove any of the
information required by Section 3(a)(1)(A) to the extent
reasonably practicable.
4. If You Share Adapted Material You produce, the Adapter's
License You apply must not prevent recipients of the Adapted
Material from complying with this Public License.
Section 4 -- Sui Generis Database Rights.
Where the Licensed Rights include Sui Generis Database Rights that
apply to Your use of the Licensed Material:
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
to extract, reuse, reproduce, and Share all or a substantial
portion of the contents of the database;
b. if You include all or a substantial portion of the database
contents in a database in which You have Sui Generis Database
Rights, then the database in which You have Sui Generis Database
Rights (but not its individual contents) is Adapted Material; and
c. You must comply with the conditions in Section 3(a) if You Share
all or a substantial portion of the contents of the database.
For the avoidance of doubt, this Section 4 supplements and does not
replace Your obligations under this Public License where the Licensed
Rights include other Copyright and Similar Rights.
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
c. The disclaimer of warranties and limitation of liability provided
above shall be interpreted in a manner that, to the extent
possible, most closely approximates an absolute disclaimer and
waiver of all liability.
Section 6 -- Term and Termination.
a. This Public License applies for the term of the Copyright and
Similar Rights licensed here. However, if You fail to comply with
this Public License, then Your rights under this Public License
terminate automatically.
b. Where Your right to use the Licensed Material has terminated under
Section 6(a), it reinstates:
1. automatically as of the date the violation is cured, provided
it is cured within 30 days of Your discovery of the
violation; or
2. upon express reinstatement by the Licensor.
For the avoidance of doubt, this Section 6(b) does not affect any
right the Licensor may have to seek remedies for Your violations
of this Public License.
c. For the avoidance of doubt, the Licensor may also offer the
Licensed Material under separate terms or conditions or stop
distributing the Licensed Material at any time; however, doing so
will not terminate this Public License.
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
License.
Section 7 -- Other Terms and Conditions.
a. The Licensor shall not be bound by any additional or different
terms or conditions communicated by You unless expressly agreed.
b. Any arrangements, understandings, or agreements regarding the
Licensed Material not stated herein are separate from and
independent of the terms and conditions of this Public License.
Section 8 -- Interpretation.
a. For the avoidance of doubt, this Public License does not, and
shall not be interpreted to, reduce, limit, restrict, or impose
conditions on any use of the Licensed Material that could lawfully
be made without permission under this Public License.
b. To the extent possible, if any provision of this Public License is
deemed unenforceable, it shall be automatically reformed to the
minimum extent necessary to make it enforceable. If the provision
cannot be reformed, it shall be severed from this Public License
without affecting the enforceability of the remaining terms and
conditions.
c. No term or condition of this Public License will be waived and no
failure to comply consented to unless expressly agreed to by the
Licensor.
d. Nothing in this Public License constitutes or may be interpreted
as a limitation upon, or waiver of, any privileges and immunities
that apply to the Licensor or You, including from the legal
processes of any jurisdiction or authority.
=======================================================================
Creative Commons is not a party to its public
licenses. Notwithstanding, Creative Commons may elect to apply one of
its public licenses to material it publishes and in those instances
will be considered the “Licensor.” The text of the Creative Commons
public licenses is dedicated to the public domain under the CC0 Public
Domain Dedication. Except for the limited purpose of indicating that
material is shared under a Creative Commons public license or as
otherwise permitted by the Creative Commons policies published at
creativecommons.org/policies, Creative Commons does not authorize the
use of the trademark "Creative Commons" or any other trademark or logo
of Creative Commons without its prior written consent including,
without limitation, in connection with any unauthorized modifications
to any of its public licenses or any other arrangements,
understandings, or agreements concerning use of licensed material. For
the avoidance of doubt, this paragraph does not form part of the
public licenses.
Creative Commons may be contacted at creativecommons.org.

View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -1,43 +1,47 @@
# Android Keepass DX
<img src="https://raw.githubusercontent.com/Kunzisoft/KeePassDX/master/fastlane/metadata/android/en-US/images/icon.png"> Keepass DX is a material design Keepass Client for manage keys and passwords in crypt database for your android device.
<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)
* Open database, copy username / password, open URI / URL
* Fingerprint for fast unlocking
* Material design with themes
* AutoFill and Integration (Development in progress)
* Precise management of settings
* 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**
<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?
## What is KeePass DX?
Today you need to remember many passwords. You need a password for the Windows network logon, 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 is a free open source password manager, 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 (AES and Twofish). For more information, see the features page.
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 is really free, and more than that: it is open source (OSI certified). 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.
## Donation
*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.*
Even if the application is free, to maintain the application, you can make donations.
## Contributions
[![Donation Paypal](https://4.bp.blogspot.com/-ncaIbUGaHOk/WfhaThYUPGI/AAAAAAAAAVQ/_HidNgdB1q4DaC24ujaKNzH64KUUJiQewCLcBGAs/s1600/pay-with-paypal.png)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KM6QMDAXZM3UU "Kunzisoft Paypal Donation")
You can contribute in different ways to help us on our work.
[![Donation Liberapay](https://liberapay.com/assets/widgets/donate.svg)](https://liberapay.com/Kunzisoft/donate "Kunzisoft Liberapay Donation")
<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">
* Add features by a **pull request**.
* Help to **translate** into your language
* **[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
## 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/)
@@ -46,9 +50,19 @@ Even if the application is free, to maintain the application, you can make donat
alt="Get it on Google Play"
height="80">](https://play.google.com/store/apps/details?id=com.kunzisoft.keepass.free)
## F.A.Q.
Other questions? You can read the [F.A.Q.](https://raw.githubusercontent.com/Kunzisoft/KeePassDX/master/FAQ.md)
## Other devices
- [KeePass XC](https://keepassxc.org/) (https://keepassxc.org/) works with **GNU/Linux**, **Mac** and **Windows**, is updated 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.
@@ -65,4 +79,4 @@ Even if the application is free, to maintain the application, you can make donat
You should have received a copy of the GNU General Public License
along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
This project is a fork of [KeepassDroid](https://github.com/bpellin/keepassdroid) by bpellin.
*This project is a fork of [KeepassDroid](https://github.com/bpellin/keepassdroid) by bpellin.*

View File

@@ -1,24 +1,25 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion = 27
buildToolsVersion = '27.0.3'
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.kunzisoft.keepass"
minSdkVersion 14
targetSdkVersion 27
versionCode = 8
versionName = "2.5.0.0beta8"
versionCode = 10
versionName = "2.5.0.0beta10"
multiDexEnabled true
testApplicationId = "com.kunzisoft.keepass.tests"
testInstrumentationRunner = "android.test.InstrumentationTestRunner"
ndk {
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a',
'arm64-v8a', 'mips', 'mips64'
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
}
buildConfigField "String[]", "ICON_PACKS", "{\"classic\",\"material\"}"
}
externalNativeBuild {
@@ -44,28 +45,42 @@ android {
applicationIdSuffix = ".libre"
versionNameSuffix "-libre"
buildConfigField "boolean", "FULL_VERSION", "true"
buildConfigField "boolean", "GOOGLE_PLAY_VERSION", "false"
buildConfigField "boolean", "CLOSED_STORE", "false"
buildConfigField "String[]", "STYLES_DISABLED", "{\"KeepassDXStyle_Dark\",\"KeepassDXStyle_Red\",\"KeepassDXStyle_Purple\"}"
buildConfigField "String[]", "ICON_PACKS_DISABLED", "{}"
}
pro_google {
pro {
applicationIdSuffix = ".pro"
versionNameSuffix "-pro"
buildConfigField "boolean", "FULL_VERSION", "true"
buildConfigField "boolean", "GOOGLE_PLAY_VERSION", "true"
buildConfigField "boolean", "CLOSED_STORE", "true"
buildConfigField "String[]", "STYLES_DISABLED", "{}"
buildConfigField "String[]", "ICON_PACKS_DISABLED", "{}"
}
free_google {
free {
applicationIdSuffix = ".free"
versionNameSuffix "-free"
buildConfigField "boolean", "FULL_VERSION", "false"
buildConfigField "boolean", "GOOGLE_PLAY_VERSION", "true"
buildConfigField "boolean", "CLOSED_STORE", "true"
buildConfigField "String[]", "STYLES_DISABLED", "{\"KeepassDXStyle_Dark\",\"KeepassDXStyle_Blue\",\"KeepassDXStyle_Red\",\"KeepassDXStyle_Purple\"}"
buildConfigField "String[]", "ICON_PACKS_DISABLED", "{}"
}
}
sourceSets {
libre.res.srcDir 'src/libre/res'
pro.res.srcDir 'src/pro/res'
free.res.srcDir 'src/free/res'
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
}
def supportVersion = "27.1.0"
def supportVersion = "27.1.1"
def spongycastleVersion = "1.58.0.0"
def permissionDispatcherVersion = "3.1.0"
@@ -77,20 +92,26 @@ dependencies {
implementation "com.android.support:cardview-v7:$supportVersion"
implementation "com.madgag.spongycastle:core:$spongycastleVersion"
implementation "com.madgag.spongycastle:prov:$spongycastleVersion"
// Expandable view
implementation 'net.cachapa.expandablelayout:expandablelayout:2.9.2'
// Time
implementation "joda-time:joda-time:2.9.9"
implementation "org.sufficientlysecure:html-textview:3.5"
implementation "com.nononsenseapps:filepicker:4.1.0"
implementation 'joda-time:joda-time:2.9.9'
implementation 'org.sufficientlysecure:html-textview:3.5'
implementation 'com.nononsenseapps:filepicker:4.1.0'
implementation 'com.getkeepsafe.taptargetview:taptargetview:1.11.0'
// Permissions
implementation ("com.github.hotchemi:permissionsdispatcher:$permissionDispatcherVersion") {
implementation("com.github.hotchemi:permissionsdispatcher:$permissionDispatcherVersion") {
// if you don't use android.app.Fragment you can exclude support for them
exclude module: "support-v13"
}
// Apache Commons Collections
implementation group: 'commons-collections', name: 'commons-collections', version: '3.2.1'
// Base64
compile group: 'biz.source_code', name: 'base64coder', version: '2010-12-19'
annotationProcessor "com.github.hotchemi:permissionsdispatcher-processor:$permissionDispatcherVersion"
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.1'
implementation group: 'com.google.guava', name: 'guava', version: '23.0-android'
// Apache Commons Collections
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.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')
}

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -20,47 +20,28 @@
android:allowBackup="true"
android:fullBackupContent="@xml/backup"
android:backupAgent="com.kunzisoft.keepass.backup.SettingsBackupAgent"
android:theme="@style/KeepassDXStyle.Light"
android:theme="@style/KeepassDXStyle.Night"
tools:replace="android:theme">
<!-- TODO backup API Key -->
<meta-data
android:name="com.google.android.backup.api_key"
android:value="" />
<!-- Folder picker -->
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/nnf_provider_paths" />
</provider>
<activity
android:name="com.kunzisoft.keepass.fileselect.FilePickerStylishActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".KeePass"
android:label="@string/app_name">
android:name="com.kunzisoft.keepass.fileselect.FileSelectActivity"
android:theme="@style/KeepassDXStyle.SplashScreen"
android:label="@string/app_name"
android:launchMode="singleTask"
android:configChanges="orientation|keyboardHidden"
android:windowSoftInputMode="stateHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.kunzisoft.keepass.fileselect.FileSelectActivity"
android:launchMode="singleInstance"
android:configChanges="orientation|keyboardHidden"
android:windowSoftInputMode="stateHidden" />
<activity
android:name="com.kunzisoft.keepass.activities.AboutActivity"
android:launchMode="singleInstance"
android:launchMode="singleTask"
android:label="@string/menu_about" />
<activity
android:name="com.kunzisoft.keepass.password.PasswordActivity"
@@ -102,6 +83,24 @@
<data android:mimeType="application/octet-stream"/>
</intent-filter>
</activity>
<!-- Folder picker -->
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/nnf_provider_paths" />
</provider>
<activity
android:name="com.kunzisoft.keepass.fileselect.FilePickerStylishActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.kunzisoft.keepass.activities.GroupActivity"
android:configChanges="orientation|keyboardHidden"

Binary file not shown.

View File

@@ -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;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import com.kunzisoft.keepass.fileselect.FileSelectActivity;
public class KeePass extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startFileSelectActivity();
// Delete flickering for kitkat <=
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
overridePendingTransition(0, 0);
}
protected void startFileSelectActivity() {
FileSelectActivity.launch(this);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_CANCELED) {
finish();
}
}
}

View File

@@ -23,8 +23,11 @@ package com.kunzisoft.keepass.activities;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
@@ -34,6 +37,8 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.getkeepsafe.taptargetview.TapTarget;
import com.getkeepsafe.taptargetview.TapTargetView;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.database.Database;
@@ -41,9 +46,11 @@ import com.kunzisoft.keepass.database.ExtraFields;
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.notifications.NotificationCopyingService;
import com.kunzisoft.keepass.notifications.NotificationField;
import com.kunzisoft.keepass.settings.PreferencesUtil;
import com.kunzisoft.keepass.settings.SettingsAutofillActivity;
import com.kunzisoft.keepass.timeout.ClipboardHelper;
import com.kunzisoft.keepass.utils.EmptyUtils;
import com.kunzisoft.keepass.utils.MenuUtil;
@@ -65,6 +72,7 @@ public class EntryActivity extends LockingHideActivity {
private ImageView titleIconView;
private TextView titleView;
private EntryContentsView entryContentsView;
private Toolbar toolbar;
protected PwEntry mEntry;
private boolean mShowPassword;
@@ -87,7 +95,7 @@ public class EntryActivity extends LockingHideActivity {
setContentView(R.layout.entry_view);
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
assert getSupportActionBar() != null;
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_close_white_24dp);
@@ -202,9 +210,75 @@ public class EntryActivity extends LockingHideActivity {
firstLaunchOfActivity = false;
}
private void populateTitle(Drawable drawIcon, String text) {
titleIconView.setImageDrawable(drawIcon);
titleView.setText(text);
/**
* Check and display learning views
* Displays the explanation for copying a field and editing an entry
*/
private void checkAndPerformedEducation(Menu menu) {
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))
.textColorInt(Color.WHITE)
.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 {
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");
}
}
}
protected void fillData() {
@@ -213,9 +287,19 @@ public class EntryActivity extends LockingHideActivity {
mEntry.startToManageFieldReferences(pm);
// Assign title
populateTitle(db.getDrawFactory().getIconDrawable(getResources(), mEntry.getIcon()),
mEntry.getTitle());
// Assign title icon
if (IconPackChooser.getSelectedIconPack(this).tintable()) {
// Retrieve the textColor to tint the icon
int[] attrs = {R.attr.textColorInverse};
TypedArray ta = getTheme().obtainStyledAttributes(attrs);
int iconColor = ta.getColor(0, Color.WHITE);
App.getDB().getDrawFactory().assignDatabaseIconTo(this, titleIconView, mEntry.getIcon(), true, iconColor);
} else {
App.getDB().getDrawFactory().assignDatabaseIconTo(this, titleIconView, mEntry.getIcon());
}
// Assign title text
titleView.setText(mEntry.getTitle());
// Assign basic fields
entryContentsView.assignUserName(mEntry.getUsername());
@@ -290,7 +374,7 @@ public class EntryActivity extends LockingHideActivity {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
MenuUtil.donationMenuInflater(inflater, menu);
MenuUtil.contributionMenuInflater(inflater, menu);
inflater.inflate(R.menu.entry, menu);
inflater.inflate(R.menu.database_lock, menu);
@@ -324,14 +408,17 @@ public class EntryActivity extends LockingHideActivity {
}
}
// Show education views
new Handler().post(() -> checkAndPerformedEducation(menu));
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch ( item.getItemId() ) {
case R.id.menu_donate:
return MenuUtil.onDonationItemSelected(this);
case R.id.menu_contribute:
return MenuUtil.onContributionItemSelected(this);
case R.id.menu_toggle_pass:
mShowPassword = !mShowPassword;

View File

@@ -21,6 +21,8 @@ package com.kunzisoft.keepass.activities;
import android.app.Activity;
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;
@@ -31,11 +33,13 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Toast;
import com.getkeepsafe.taptargetview.TapTarget;
import com.getkeepsafe.taptargetview.TapTargetView;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.database.Database;
@@ -45,16 +49,17 @@ import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.PwGroup;
import com.kunzisoft.keepass.database.PwGroupId;
import com.kunzisoft.keepass.database.PwIconStandard;
import com.kunzisoft.keepass.database.edit.AddEntry;
import com.kunzisoft.keepass.database.edit.OnFinish;
import com.kunzisoft.keepass.database.edit.RunnableOnFinish;
import com.kunzisoft.keepass.database.edit.UpdateEntry;
import com.kunzisoft.keepass.database.action.AddEntryRunnable;
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
import com.kunzisoft.keepass.database.action.RunnableOnFinish;
import com.kunzisoft.keepass.database.action.UpdateEntryRunnable;
import com.kunzisoft.keepass.database.security.ProtectedString;
import com.kunzisoft.keepass.dialogs.GeneratePasswordDialogFragment;
import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment;
import com.kunzisoft.keepass.icons.Icons;
import com.kunzisoft.keepass.icons.IconPackChooser;
import com.kunzisoft.keepass.settings.PreferencesUtil;
import com.kunzisoft.keepass.tasks.ProgressTask;
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
import com.kunzisoft.keepass.utils.MenuUtil;
import com.kunzisoft.keepass.utils.Types;
import com.kunzisoft.keepass.utils.Util;
@@ -62,6 +67,8 @@ import com.kunzisoft.keepass.view.EntryEditCustomField;
import java.util.UUID;
import static com.kunzisoft.keepass.dialogs.IconPickerDialogFragment.UNDEFINED_ICON_ID;
public class EntryEditActivity extends LockingHideActivity
implements IconPickerDialogFragment.IconPickerListener,
GeneratePasswordDialogFragment.GeneratePasswordListener {
@@ -81,20 +88,26 @@ public class EntryEditActivity extends LockingHideActivity
protected PwEntry mEntry;
protected PwEntry mCallbackNewEntry;
protected boolean mIsNew;
protected int mSelectedIconID = -1;
protected int mSelectedIconID = UNDEFINED_ICON_ID;
// Views
private ScrollView scrollView;
private EditText entryTitleView;
private ImageView entryIconView;
private EditText entryUserNameView;
private EditText entryUrlView;
private EditText entryPasswordView;
private EditText entryConfirmationPasswordView;
private View generatePasswordView;
private EditText entryCommentView;
private ViewGroup entryExtraFieldsContainer;
private View addNewFieldView;
private View saveView;
private int iconColor;
/**
* launch EntryEditActivity to update an existing entry
* Launch EntryEditActivity to update an existing entry
*
* @param act from activity
* @param pw Entry to update
*/
@@ -107,7 +120,8 @@ public class EntryEditActivity extends LockingHideActivity
}
/**
* launch EntryEditActivity to add a new entry
* Launch EntryEditActivity to add a new entry
*
* @param act from activity
* @param pwGroup Group who will contains new entry
*/
@@ -135,6 +149,7 @@ public class EntryEditActivity extends LockingHideActivity
scrollView.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
entryTitleView = findViewById(R.id.entry_title);
entryIconView = findViewById(R.id.icon_button);
entryUserNameView = findViewById(R.id.entry_user_name);
entryUrlView = findViewById(R.id.entry_url);
entryPasswordView = findViewById(R.id.entry_password);
@@ -152,12 +167,23 @@ public class EntryEditActivity extends LockingHideActivity
Intent intent = getIntent();
byte[] uuidBytes = intent.getByteArrayExtra(KEY_ENTRY);
// Retrieve the textColor to tint the icon
int[] attrs = {android.R.attr.textColorPrimary};
TypedArray ta = getTheme().obtainStyledAttributes(attrs);
iconColor = ta.getColor(0, Color.WHITE);
PwDatabase pm = db.getPwDatabase();
if ( uuidBytes == null ) {
PwGroupId parentId = (PwGroupId) intent.getSerializableExtra(KEY_PARENT);
PwGroup parent = pm.getGroupByGroupId(parentId);
mEntry = PwEntry.getInstance(parent);
mEntry = db.createEntry(parent);
mIsNew = true;
// Add the default icon
if (IconPackChooser.getSelectedIconPack(this).tintable()) {
App.getDB().getDrawFactory().assignDefaultDatabaseIconTo(this, entryIconView, true, iconColor);
} else {
App.getDB().getDrawFactory().assignDefaultDatabaseIconTo(this, entryIconView);
}
} else {
UUID uuid = Types.bytestoUUID(uuidBytes);
mEntry = pm.getEntryByUUIDId(uuid);
@@ -165,66 +191,179 @@ public class EntryEditActivity extends LockingHideActivity
fillData();
}
View iconButton = findViewById(R.id.icon_button);
iconButton.setOnClickListener(v ->
// Retrieve the icon after an orientation change
if (savedInstanceState != null && savedInstanceState.containsKey(IconPickerDialogFragment.KEY_ICON_ID)) {
iconPicked(savedInstanceState);
}
// Add listener to the icon
entryIconView.setOnClickListener(v ->
IconPickerDialogFragment.launch(EntryEditActivity.this));
// Generate password button
View generatePassword = findViewById(R.id.generate_button);
generatePassword.setOnClickListener(v -> {
GeneratePasswordDialogFragment generatePasswordDialogFragment = new GeneratePasswordDialogFragment();
generatePasswordDialogFragment.show(getSupportFragmentManager(), "PasswordGeneratorFragment");
});
generatePasswordView = findViewById(R.id.generate_button);
generatePasswordView.setOnClickListener(v -> openPasswordGenerator());
// Save button
View save = findViewById(R.id.entry_save);
save.setOnClickListener(v -> {
saveView = findViewById(R.id.entry_save);
saveView.setOnClickListener(v -> saveEntry());
if (mEntry.allowExtraFields()) {
addNewFieldView = findViewById(R.id.add_new_field);
addNewFieldView.setVisibility(View.VISIBLE);
addNewFieldView.setOnClickListener(v -> addNewCustomField());
}
// Verify the education views
checkAndPerformedEducation();
}
/**
* Open the password generator fragment
*/
private void openPasswordGenerator() {
GeneratePasswordDialogFragment generatePasswordDialogFragment = new GeneratePasswordDialogFragment();
generatePasswordDialogFragment.show(getSupportFragmentManager(), "PasswordGeneratorFragment");
}
/**
* Add a new view to fill in the information of the customized field
*/
private void addNewCustomField() {
EntryEditCustomField entryEditCustomField = new EntryEditCustomField(EntryEditActivity.this);
entryEditCustomField.setData("", new ProtectedString(false, ""));
boolean visibilityFontActivated = PreferencesUtil.fieldFontIsInVisibility(this);
entryEditCustomField.setFontVisibility(visibilityFontActivated);
entryExtraFieldsContainer.addView(entryEditCustomField);
// Scroll bottom
scrollView.post(() -> scrollView.fullScroll(ScrollView.FOCUS_DOWN));
}
/**
* Saves the new entry or update an existing entry in the database
*/
private void saveEntry() {
if (!validateBeforeSaving()) {
return;
}
mCallbackNewEntry = populateNewEntry();
OnFinish onFinish = new AfterSave();
// Open a progress dialog and save entry
OnFinishRunnable onFinish = new AfterSave();
EntryEditActivity act = EntryEditActivity.this;
RunnableOnFinish task;
if ( mIsNew ) {
task = new AddEntry(act, App.getDB(), mCallbackNewEntry, onFinish);
task = new AddEntryRunnable(act, App.getDB(), mCallbackNewEntry, onFinish);
} else {
task = new UpdateEntry(act, App.getDB(), mEntry, mCallbackNewEntry, onFinish);
task = new UpdateEntryRunnable(act, App.getDB(), mEntry, mCallbackNewEntry, onFinish);
}
task.setUpdateProgressTaskStatus(
new UpdateProgressTaskStatus(this,
SaveDatabaseProgressTaskDialogFragment.start(
getSupportFragmentManager())
));
new Thread(task).start();
}
/**
* Check and display learning views
* Displays the explanation for the icon selection, the password generator and for a new field
*/
private void checkAndPerformedEducation() {
// 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();
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
}
ProgressTask pt = new ProgressTask(act, task, R.string.saving_database);
pt.run();
});
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))
.textColorInt(Color.WHITE)
.tintTarget(false)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
addNewCustomField();
}
if (mEntry.allowExtraFields()) {
View add = findViewById(R.id.add_new_field);
add.setVisibility(View.VISIBLE);
add.setOnClickListener(v -> {
EntryEditCustomField ees = new EntryEditCustomField(EntryEditActivity.this);
ees.setData("", new ProtectedString(false, ""));
entryExtraFieldsContainer.addView(ees);
// Scroll bottom
scrollView.post(() -> scrollView.fullScroll(ScrollView.FOCUS_DOWN));
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
}
});
PreferencesUtil.saveEducationPreference(this,
R.string.education_entry_new_field_key);
}
}
protected boolean validateBeforeSaving() {
/**
* Utility class to retrieve a validation or an error with a message
*/
private class ErrorValidation {
static final int unknownMessage = -1;
boolean isValidate = false;
int messageId = unknownMessage;
void showValidationErrorIfNeeded() {
if (!isValidate && messageId != unknownMessage)
Toast.makeText(EntryEditActivity.this, messageId, Toast.LENGTH_LONG).show();
}
}
/**
* Validate or not the entry form
*
* @return ErrorValidation An error with a message or a validation without message
*/
protected ErrorValidation validate() {
ErrorValidation errorValidation = new ErrorValidation();
// Require title
String title = entryTitleView.getText().toString();
if ( title.length() == 0 ) {
Toast.makeText(this, R.string.error_title_required, Toast.LENGTH_LONG).show();
return false;
errorValidation.messageId = R.string.error_title_required;
return errorValidation;
}
// Validate password
String pass = entryPasswordView.getText().toString();
String conf = entryConfirmationPasswordView.getText().toString();
if ( ! pass.equals(conf) ) {
Toast.makeText(this, R.string.error_pass_match, Toast.LENGTH_LONG).show();
return false;
errorValidation.messageId = R.string.error_pass_match;
return errorValidation;
}
// Validate extra fields
@@ -233,13 +372,25 @@ public class EntryEditActivity extends LockingHideActivity
EntryEditCustomField entryEditCustomField = (EntryEditCustomField) entryExtraFieldsContainer.getChildAt(i);
String key = entryEditCustomField.getLabel();
if (key == null || key.length() == 0) {
Toast.makeText(this, R.string.error_string_key, Toast.LENGTH_LONG).show();
return false;
errorValidation.messageId = R.string.error_string_key;
return errorValidation;
}
}
}
return true;
errorValidation.isValidate = true;
return errorValidation;
}
/**
* Launch a validation with {@link #validate()} and show the error if present
*
* @return true if the form was validate or false if not
*/
protected boolean validateBeforeSaving() {
ErrorValidation errorValidation = validate();
errorValidation.showValidationErrorIfNeeded();
return errorValidation.isValidate;
}
protected PwEntry populateNewEntry() {
@@ -255,18 +406,8 @@ public class EntryEditActivity extends LockingHideActivity
newEntry.setLastModificationTime(new PwDate());
newEntry.setTitle(entryTitleView.getText().toString());
if(mSelectedIconID != -1)
// or TODO icon factory newEntry.setIcon(App.getDB().pm.iconFactory.getIcon(mSelectedIconID));
newEntry.setIcon(new PwIconStandard(mSelectedIconID));
else {
if (mIsNew) {
newEntry.setIcon(App.getDB().getPwDatabase().getIconFactory().getFirstIcon());
}
else {
// Keep previous icon, if no new one was selected
newEntry.setIcon(mEntry.getIconStandard());
}
}
newEntry.setIcon(retrieveIcon());
newEntry.setUrl(entryUrlView.getText().toString());
newEntry.setUsername(entryUserNameView.getText().toString());
newEntry.setNotes(entryCommentView.getText().toString());
@@ -290,21 +431,39 @@ public class EntryEditActivity extends LockingHideActivity
return newEntry;
}
/**
* Retrieve the icon by the selection, or the first icon in the list if the entry is new or the last one
* @return
*/
private PwIconStandard retrieveIcon() {
if(mSelectedIconID != UNDEFINED_ICON_ID)
return App.getDB().getPwDatabase().getIconFactory().getIcon(mSelectedIconID);
else {
if (mIsNew) {
return App.getDB().getPwDatabase().getIconFactory().getFirstIcon();
}
else {
// Keep previous icon, if no new one was selected
return mEntry.getIconStandard();
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
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();
@@ -314,8 +473,12 @@ public class EntryEditActivity extends LockingHideActivity
}
protected void fillData() {
ImageButton currIconButton = findViewById(R.id.icon_button);
App.getDB().getDrawFactory().assignDrawableTo(currIconButton, getResources(), mEntry.getIcon());
if (IconPackChooser.getSelectedIconPack(this).tintable()) {
App.getDB().getDrawFactory().assignDatabaseIconTo(this, entryIconView, mEntry.getIcon(), true, iconColor);
} else {
App.getDB().getDrawFactory().assignDatabaseIconTo(this, entryIconView, mEntry.getIcon());
}
// Don't start the field reference manager, we want to see the raw ref
mEntry.endToManageFieldReferences();
@@ -330,10 +493,10 @@ public class EntryEditActivity extends LockingHideActivity
boolean visibilityFontActivated = PreferencesUtil.fieldFontIsInVisibility(this);
if (visibilityFontActivated) {
Util.applyFontVisibilityTo(entryUserNameView);
Util.applyFontVisibilityTo(entryPasswordView);
Util.applyFontVisibilityTo(entryConfirmationPasswordView);
Util.applyFontVisibilityTo(entryCommentView);
Util.applyFontVisibilityTo(this, entryUserNameView);
Util.applyFontVisibilityTo(this, entryPasswordView);
Util.applyFontVisibilityTo(this, entryConfirmationPasswordView);
Util.applyFontVisibilityTo(this, entryCommentView);
}
if (mEntry.allowExtraFields()) {
@@ -350,8 +513,15 @@ public class EntryEditActivity extends LockingHideActivity
@Override
public void iconPicked(Bundle bundle) {
mSelectedIconID = bundle.getInt(IconPickerDialogFragment.KEY_ICON_ID);
ImageButton currIconButton = findViewById(R.id.icon_button);
currIconButton.setImageResource(Icons.iconToResId(mSelectedIconID));
entryIconView.setImageResource(IconPackChooser.getSelectedIconPack(this).iconToResId(mSelectedIconID));
}
@Override
protected void onSaveInstanceState(Bundle outState) {
if (mSelectedIconID != UNDEFINED_ICON_ID) {
outState.putInt(IconPickerDialogFragment.KEY_ICON_ID, mSelectedIconID);
super.onSaveInstanceState(outState);
}
}
@Override
@@ -359,6 +529,8 @@ public class EntryEditActivity extends LockingHideActivity
String generatedPassword = bundle.getString(GeneratePasswordDialogFragment.KEY_PASSWORD_ID);
entryPasswordView.setText(generatedPassword);
entryConfirmationPasswordView.setText(generatedPassword);
checkAndPerformedEducation();
}
@Override
@@ -388,7 +560,7 @@ public class EntryEditActivity extends LockingHideActivity
}
}
private final class AfterSave extends OnFinish {
private final class AfterSave extends OnFinishRunnable {
AfterSave() {
super(new Handler());
@@ -396,11 +568,15 @@ public class EntryEditActivity extends LockingHideActivity
@Override
public void run() {
runOnUiThread(() -> {
if ( mSuccess ) {
finish();
} else {
displayMessage(EntryEditActivity.this);
}
SaveDatabaseProgressTaskDialogFragment.stop(EntryEditActivity.this);
});
}
}

View File

@@ -27,6 +27,8 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@@ -41,6 +43,8 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ImageView;
import com.getkeepsafe.taptargetview.TapTarget;
import com.getkeepsafe.taptargetview.TapTargetView;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.adapters.NodeAdapter;
import com.kunzisoft.keepass.app.App;
@@ -49,17 +53,23 @@ import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.PwGroup;
import com.kunzisoft.keepass.database.PwGroupId;
import com.kunzisoft.keepass.database.PwIcon;
import com.kunzisoft.keepass.database.PwIconStandard;
import com.kunzisoft.keepass.database.PwNode;
import com.kunzisoft.keepass.database.SortNodeEnum;
import com.kunzisoft.keepass.database.edit.AddGroup;
import com.kunzisoft.keepass.database.edit.DeleteEntry;
import com.kunzisoft.keepass.database.edit.DeleteGroup;
import com.kunzisoft.keepass.database.action.AddGroupRunnable;
import com.kunzisoft.keepass.database.action.DeleteEntryRunnable;
import com.kunzisoft.keepass.database.action.DeleteGroupRunnable;
import com.kunzisoft.keepass.database.action.UpdateGroupRunnable;
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
import com.kunzisoft.keepass.dialogs.GroupEditDialogFragment;
import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment;
import com.kunzisoft.keepass.dialogs.ReadOnlyDialog;
import com.kunzisoft.keepass.icons.IconPackChooser;
import com.kunzisoft.keepass.search.SearchResultsActivity;
import com.kunzisoft.keepass.tasks.ProgressTask;
import com.kunzisoft.keepass.settings.PreferencesUtil;
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
import com.kunzisoft.keepass.view.AddNodeButtonView;
public class GroupActivity extends ListNodesActivity
@@ -67,20 +77,21 @@ public class GroupActivity extends ListNodesActivity
private static final String GROUP_ID_KEY = "GROUP_ID_KEY";
private Toolbar toolbar;
private ImageView iconView;
private AddNodeButtonView addNodeButtonView;
protected boolean addGroupEnabled = false;
protected boolean addEntryEnabled = false;
protected boolean isRoot = false;
protected boolean readOnly = false;
protected EditGroupDialogAction editGroupDialogAction = EditGroupDialogAction.NONE;
private enum EditGroupDialogAction {
CREATION, UPDATE, NONE
}
private static final String TAG = "Group Activity:";
private static final String OLD_GROUP_TO_UPDATE_KEY = "OLD_GROUP_TO_UPDATE_KEY";
private PwGroup oldGroupToUpdate;
public static void launch(Activity act) {
recordFirstTimeBeforeLaunch(act);
launch(act, (PwGroup) null);
@@ -132,9 +143,15 @@ public class GroupActivity extends ListNodesActivity
return;
}
if (savedInstanceState != null
&& savedInstanceState.containsKey(OLD_GROUP_TO_UPDATE_KEY)) {
oldGroupToUpdate = (PwGroup) savedInstanceState.getSerializable(OLD_GROUP_TO_UPDATE_KEY);
}
// Construct main view
setContentView(getLayoutInflater().inflate(R.layout.list_nodes_with_add_button, null));
iconView = findViewById(R.id.icon);
addNodeButtonView = findViewById(R.id.add_node_button);
addNodeButtonView.enableAddGroup(addGroupEnabled);
addNodeButtonView.enableAddEntry(addEntryEnabled);
@@ -142,7 +159,7 @@ public class GroupActivity extends ListNodesActivity
RecyclerView recyclerView = findViewById(R.id.nodes_list);
recyclerView.addOnScrollListener(addNodeButtonView.hideButtonOnScrollListener());
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar = findViewById(R.id.toolbar);
toolbar.setTitle("");
setSupportActionBar(toolbar);
@@ -150,16 +167,14 @@ public class GroupActivity extends ListNodesActivity
toolbar.setNavigationIcon(R.drawable.ic_arrow_up_white_24dp);
addNodeButtonView.setAddGroupClickListener(v -> {
editGroupDialogAction = EditGroupDialogAction.CREATION;
GroupEditDialogFragment groupEditDialogFragment = new GroupEditDialogFragment();
groupEditDialogFragment.show(getSupportFragmentManager(),
GroupEditDialogFragment.build()
.show(getSupportFragmentManager(),
GroupEditDialogFragment.TAG_CREATE_GROUP);
});
addNodeButtonView.setAddEntryClickListener(v ->
EntryEditActivity.launch(GroupActivity.this, mCurrentGroup));
setGroupTitle();
setGroupIcon();
Log.w(TAG, "Finished creating tree");
@@ -206,7 +221,6 @@ public class GroupActivity extends ListNodesActivity
nodeAdapter.setNodeMenuListener(new NodeAdapter.NodeMenuListener() {
@Override
public boolean onOpenMenuClick(PwNode node) {
mAdapter.registerANodeToUpdate(node);
switch (node.getType()) {
case GROUP:
GroupActivity.launch(GroupActivity.this, (PwGroup) node);
@@ -220,13 +234,11 @@ public class GroupActivity extends ListNodesActivity
@Override
public boolean onEditMenuClick(PwNode node) {
mAdapter.registerANodeToUpdate(node);
switch (node.getType()) {
case GROUP:
editGroupDialogAction = EditGroupDialogAction.UPDATE;
GroupEditDialogFragment groupEditDialogFragment =
GroupEditDialogFragment.build(node);
groupEditDialogFragment.show(getSupportFragmentManager(),
oldGroupToUpdate = (PwGroup) node;
GroupEditDialogFragment.build(node)
.show(getSupportFragmentManager(),
GroupEditDialogFragment.TAG_CREATE_GROUP);
break;
case ENTRY:
@@ -254,10 +266,143 @@ public class GroupActivity extends ListNodesActivity
@Override
protected void onResume() {
super.onResume();
// Refresh the group icon
assignGroupIcon();
// Show button on resume
addNodeButtonView.showButton();
}
/**
* Check and display learning views
* Displays the explanation for a add, search, sort a new node and lock the database
*/
private void checkAndPerformedEducation(Menu menu) {
// If no node, show education to add new one
if (mAdapter.getItemCount() <= 0) {
if (!PreferencesUtil.isEducationNewNodePerformed(this)) {
TapTargetView.showFor(this,
TapTarget.forView(findViewById(R.id.add_button),
getString(R.string.education_new_node_title),
getString(R.string.education_new_node_summary))
.textColorInt(Color.WHITE)
.tintTarget(false)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
addNodeButtonView.openButtonIfClose();
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
}
});
PreferencesUtil.saveEducationPreference(this,
R.string.education_new_node_key);
}
}
// Else show the search education
else if (!PreferencesUtil.isEducationSearchPerformed(this)) {
try {
TapTargetView.showFor(this,
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_search,
getString(R.string.education_search_title),
getString(R.string.education_search_summary))
.textColorInt(Color.WHITE)
.tintTarget(true)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
MenuItem searchItem = menu.findItem(R.id.menu_search);
searchItem.expandActionView();
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
}
});
PreferencesUtil.saveEducationPreference(this,
R.string.education_search_key);
} catch (Exception e) {
// If icon not visible
Log.w(TAG, "Can't performed education for search");
}
}
// Else show the sort education
else if (!PreferencesUtil.isEducationSortPerformed(this)) {
try {
TapTargetView.showFor(this,
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_sort,
getString(R.string.education_sort_title),
getString(R.string.education_sort_summary))
.textColorInt(Color.WHITE)
.tintTarget(true)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
MenuItem sortItem = menu.findItem(R.id.menu_sort);
onOptionsItemSelected(sortItem);
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
}
});
PreferencesUtil.saveEducationPreference(this,
R.string.education_sort_key);
} catch (Exception e) {
Log.w(TAG, "Can't performed education for sort");
}
}
// Else show the lock education
else if (!PreferencesUtil.isEducationLockPerformed(this)) {
try {
TapTargetView.showFor(this,
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_lock,
getString(R.string.education_lock_title),
getString(R.string.education_lock_summary))
.textColorInt(Color.WHITE)
.tintTarget(true)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
MenuItem lockItem = menu.findItem(R.id.menu_lock);
onOptionsItemSelected(lockItem);
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
}
});
PreferencesUtil.saveEducationPreference(this,
R.string.education_lock_key);
} catch (Exception e) {
Log.w(TAG, "Can't performed education for lock");
}
}
}
@Override
protected void onStop() {
super.onStop();
@@ -272,33 +417,50 @@ public class GroupActivity extends ListNodesActivity
addNodeButtonView.showButton();
}
protected void setGroupIcon() {
/**
* Assign the group icon depending of IconPack or custom icon
*/
protected void assignGroupIcon() {
if (mCurrentGroup != null) {
ImageView iv = findViewById(R.id.icon);
App.getDB().getDrawFactory().assignDrawableTo(iv, getResources(), mCurrentGroup.getIcon());
if (IconPackChooser.getSelectedIconPack(this).tintable()) {
// Retrieve the textColor to tint the icon
int[] attrs = {R.attr.textColorInverse};
TypedArray ta = getTheme().obtainStyledAttributes(attrs);
int iconColor = ta.getColor(0, Color.WHITE);
App.getDB().getDrawFactory().assignDatabaseIconTo(this, iconView, mCurrentGroup.getIcon(), true, iconColor);
} else {
App.getDB().getDrawFactory().assignDatabaseIconTo(this, iconView, mCurrentGroup.getIcon());
}
}
}
private void deleteEntry(PwEntry entry) {
Handler handler = new Handler();
DeleteEntry task = new DeleteEntry(this, App.getDB(), entry,
DeleteEntryRunnable task = new DeleteEntryRunnable(this, App.getDB(), entry,
new AfterDeleteNode(handler, entry));
ProgressTask pt = new ProgressTask(this, task, R.string.saving_database);
pt.run();
task.setUpdateProgressTaskStatus(
new UpdateProgressTaskStatus(this,
SaveDatabaseProgressTaskDialogFragment.start(
getSupportFragmentManager())
));
new Thread(task).start();
}
private void deleteGroup(PwGroup group) {
//TODO Verify trash recycle bin
Handler handler = new Handler();
DeleteGroup task = new DeleteGroup(this, App.getDB(), group,
DeleteGroupRunnable task = new DeleteGroupRunnable(this, App.getDB(), group,
new AfterDeleteNode(handler, group));
ProgressTask pt = new ProgressTask(this, task, R.string.saving_database);
pt.run();
task.setUpdateProgressTaskStatus(
new UpdateProgressTaskStatus(this,
SaveDatabaseProgressTaskDialogFragment.start(
getSupportFragmentManager())
));
new Thread(task).start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.search, menu);
@@ -320,6 +482,11 @@ public class GroupActivity extends ListNodesActivity
searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
}
super.onCreateOptionsMenu(menu);
// Launch education screen
new Handler().post(() -> checkAndPerformedEducation(menu));
return true;
}
@@ -376,28 +543,76 @@ public class GroupActivity extends ListNodesActivity
}
@Override
public void approveEditGroup(Bundle bundle) {
String GroupName = bundle.getString(GroupEditDialogFragment.KEY_NAME);
int GroupIconID = bundle.getInt(GroupEditDialogFragment.KEY_ICON_ID);
switch (editGroupDialogAction) {
public void approveEditGroup(GroupEditDialogFragment.EditGroupDialogAction action,
String name,
PwIcon icon) {
Database database = App.getDB();
PwIconStandard iconStandard = database.getPwDatabase().getIconFactory().getFirstIcon();
switch (action) {
case CREATION:
// If edit group creation
Handler handler = new Handler();
AddGroup task = new AddGroup(this, App.getDB(), GroupName, GroupIconID, mCurrentGroup,
new AfterAddNode(handler), false);
ProgressTask pt = new ProgressTask(this, task, R.string.saving_database);
pt.run();
// If group creation
// Build the group
PwGroup newGroup = database.createGroup(mCurrentGroup);
newGroup.setName(name);
try {
iconStandard = (PwIconStandard) icon;
} catch (Exception ignored) {} // TODO custom icon
newGroup.setIcon(iconStandard);
// If group created save it in the database
AddGroupRunnable addGroupRunnable = new AddGroupRunnable(this,
App.getDB(),
newGroup,
new AfterAddNode(new Handler()));
addGroupRunnable.setUpdateProgressTaskStatus(
new UpdateProgressTaskStatus(this,
SaveDatabaseProgressTaskDialogFragment.start(
getSupportFragmentManager())
));
new Thread(addGroupRunnable).start();
break;
case UPDATE:
// If edit group update
// TODO UpdateGroup
// If update add new elements
if (oldGroupToUpdate != null) {
PwGroup updateGroup = oldGroupToUpdate.clone();
updateGroup.setName(name);
try {
iconStandard = (PwIconStandard) icon;
} catch (Exception ignored) {} // TODO custom icon
updateGroup.setIcon(iconStandard);
mAdapter.removeNode(oldGroupToUpdate);
// If group updated save it in the database
UpdateGroupRunnable updateGroupRunnable = new UpdateGroupRunnable(this,
App.getDB(),
oldGroupToUpdate,
updateGroup,
new AfterUpdateNode(new Handler()));
updateGroupRunnable.setUpdateProgressTaskStatus(
new UpdateProgressTaskStatus(this,
SaveDatabaseProgressTaskDialogFragment.start(
getSupportFragmentManager())
));
new Thread(updateGroupRunnable).start();
}
break;
}
editGroupDialogAction = EditGroupDialogAction.NONE;
}
@Override
public void cancelEditGroup(Bundle bundle) {
protected void onSaveInstanceState(Bundle outState) {
outState.putSerializable(OLD_GROUP_TO_UPDATE_KEY, oldGroupToUpdate);
super.onSaveInstanceState(outState);
}
@Override
public void cancelEditGroup(GroupEditDialogFragment.EditGroupDialogAction action,
String name,
PwIcon iconId) {
// Do nothing here
}

View File

@@ -49,12 +49,13 @@ import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.PwGroup;
import com.kunzisoft.keepass.database.PwNode;
import com.kunzisoft.keepass.database.SortNodeEnum;
import com.kunzisoft.keepass.database.edit.AfterAddNodeOnFinish;
import com.kunzisoft.keepass.database.edit.OnFinish;
import com.kunzisoft.keepass.database.action.AfterActionNodeOnFinish;
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
import com.kunzisoft.keepass.dialogs.SortDialogFragment;
import com.kunzisoft.keepass.password.AssignPasswordHelper;
import com.kunzisoft.keepass.settings.PreferencesUtil;
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
import com.kunzisoft.keepass.tasks.UIToastTask;
import com.kunzisoft.keepass.utils.MenuUtil;
@@ -143,8 +144,6 @@ public abstract class ListNodesActivity extends LockingActivity
@Override
public void onNodeClick(PwNode node) {
mAdapter.registerANodeToUpdate(node);
// Add event when we have Autofill
AssistStructure assistStructure = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@@ -179,7 +178,7 @@ public abstract class ListNodesActivity extends LockingActivity
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
MenuUtil.donationMenuInflater(inflater, menu);
MenuUtil.contributionMenuInflater(inflater, menu);
inflater.inflate(R.menu.tree, menu);
inflater.inflate(R.menu.default_menu, menu);
@@ -244,7 +243,7 @@ public abstract class ListNodesActivity extends LockingActivity
AssignPasswordHelper assignPasswordHelper =
new AssignPasswordHelper(this,
masterPassword, keyFile);
masterPasswordChecked, masterPassword, keyFileChecked, keyFile);
assignPasswordHelper.assignPasswordInDatabase(null);
}
@@ -302,22 +301,47 @@ public abstract class ListNodesActivity extends LockingActivity
}
}
class AfterAddNode extends AfterAddNodeOnFinish {
class AfterAddNode extends AfterActionNodeOnFinish {
AfterAddNode(Handler handler) {
super(handler);
}
public void run(PwNode pwNode) {
public void run(PwNode oldNode, PwNode newNode) {
super.run();
runOnUiThread(() -> {
if (mSuccess) {
mAdapter.addNode(pwNode);
mAdapter.addNode(newNode);
} else {
displayMessage(ListNodesActivity.this);
}
SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this);
});
}
}
class AfterDeleteNode extends OnFinish {
class AfterUpdateNode extends AfterActionNodeOnFinish {
AfterUpdateNode(Handler handler) {
super(handler);
}
public void run(PwNode oldNode, PwNode newNode) {
super.run();
runOnUiThread(() -> {
if (mSuccess) {
mAdapter.updateNode(oldNode, newNode);
} else {
displayMessage(ListNodesActivity.this);
}
SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this);
});
}
}
class AfterDeleteNode extends OnFinishRunnable {
private PwNode pwNode;
AfterDeleteNode(Handler handler, PwNode pwNode) {
@@ -327,6 +351,9 @@ public abstract class ListNodesActivity extends LockingActivity
@Override
public void run() {
super.run();
runOnUiThread(() -> {
if ( mSuccess) {
mAdapter.removeNode(pwNode);
PwGroup parent = pwNode.getParent();
@@ -348,6 +375,9 @@ public abstract class ListNodesActivity extends LockingActivity
App.setShutdown();
finish();
}
SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this);
});
}
}
}

View File

@@ -20,10 +20,12 @@
package com.kunzisoft.keepass.adapters;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
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.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -36,6 +38,7 @@ import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.database.PwGroup;
import com.kunzisoft.keepass.database.PwNode;
import com.kunzisoft.keepass.database.SortNodeEnum;
import com.kunzisoft.keepass.icons.IconPackChooser;
import com.kunzisoft.keepass.settings.PreferencesUtil;
public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
@@ -50,10 +53,12 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
private boolean ascendingSort;
private OnNodeClickCallback onNodeClickCallback;
private int nodePositionToUpdate;
private NodeMenuListener nodeMenuListener;
private boolean activateContextMenu;
private int iconGroupColor;
private int iconEntryColor;
/**
* Create node list adapter with contextMenu or not
* @param context Context to use
@@ -66,7 +71,6 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
this.groupsBeforeSort = PreferencesUtil.getGroupsBeforeSort(context);
this.ascendingSort = PreferencesUtil.getAscendingSort(context);
this.activateContextMenu = false;
this.nodePositionToUpdate = -1;
this.nodeSortedList = new SortedList<>(PwNode.class, new SortedListAdapterCallback<PwNode>(this) {
@Override public int compare(PwNode item1, PwNode item2) {
@@ -81,6 +85,16 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
return item1.equals(item2);
}
});
// Retrieve the color to tint the icon
int[] attrTextColorPrimary = {android.R.attr.textColorPrimary};
TypedArray taTextColorPrimary = context.getTheme().obtainStyledAttributes(attrTextColorPrimary);
this.iconGroupColor = taTextColorPrimary.getColor(0, Color.BLACK);
taTextColorPrimary.recycle();
int[] attrTextColor = {android.R.attr.textColor}; // In two times to fix bug compilation
TypedArray taTextColor = context.getTheme().obtainStyledAttributes(attrTextColor);
this.iconEntryColor = taTextColor.getColor(0, Color.BLACK);
taTextColor.recycle();
}
public void setActivateContextMenu(boolean activate) {
@@ -106,43 +120,25 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
}
/**
* Register a node to update before an action
* Call updateLastNodeRegister() after the action to update the node
* @param node Node to register
*/
public void registerANodeToUpdate(PwNode node) {
nodePositionToUpdate = nodeSortedList.indexOf(node);
}
/**
* Update the last Node register in the list
* Work if only registerANodeToUpdate(PwNode node) is called before
*/
public void updateLastNodeRegister(PwNode node) {
// Don't really update here, sorted list knows each original ref, so we just notify a change
try {
if (nodePositionToUpdate != -1) {
// Don't know why but there is a bug to remove a node after this update
nodeSortedList.updateItemAt(nodePositionToUpdate, node);
nodeSortedList.recalculatePositionOfItemAt(nodePositionToUpdate);
nodePositionToUpdate = -1;
}
else {
Log.e(NodeAdapter.class.getName(), "registerANodeToUpdate must be called before updateLastNodeRegister");
}
} catch (IndexOutOfBoundsException e) {
Log.e(NodeAdapter.class.getName(), e.getMessage());
}
}
/**
* Remove node in the list
* Remove a node in the list
* @param node Node to delete
*/
public void removeNode(PwNode node) {
nodeSortedList.remove(node);
}
/**
* Update a node in the list
* @param oldNode Node before the update
* @param newNode Node after the update
*/
public void updateNode(PwNode oldNode, PwNode newNode) {
nodeSortedList.beginBatchedUpdates();
nodeSortedList.remove(oldNode);
nodeSortedList.add(newNode);
nodeSortedList.endBatchedUpdates();
}
/**
* Notify a change sort of the list
*/
@@ -157,8 +153,9 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
return nodeSortedList.get(position).getType().ordinal();
}
@NonNull
@Override
public BasicViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public BasicViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
BasicViewHolder basicViewHolder;
View view;
if (viewType == PwNode.Type.GROUP.ordinal()) {
@@ -172,11 +169,23 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
}
@Override
public void onBindViewHolder(BasicViewHolder holder, int position) {
public void onBindViewHolder(@NonNull BasicViewHolder holder, int position) {
PwNode subNode = nodeSortedList.get(position);
// Assign image
App.getDB().getDrawFactory().assignDrawableTo(holder.icon,
context.getResources(), subNode.getIcon());
if (IconPackChooser.getSelectedIconPack(context).tintable()) {
int iconColor = Color.BLACK;
switch (subNode.getType()) {
case GROUP:
iconColor = iconGroupColor;
break;
case ENTRY:
iconColor = iconEntryColor;
break;
}
App.getDB().getDrawFactory().assignDatabaseIconTo(context, holder.icon, subNode.getIcon(), true, iconColor);
} else {
App.getDB().getDrawFactory().assignDatabaseIconTo(context, holder.icon, subNode.getIcon());
}
// Assign text
holder.text.setText(subNode.getDisplayTitle());
// Assign click
@@ -265,9 +274,10 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
MenuItem clearMenu = contextMenu.add(Menu.NONE, MENU_OPEN, Menu.NONE, R.string.menu_open);
clearMenu.setOnMenuItemClickListener(mOnMyActionClickListener);
if (!App.getDB().isReadOnly() && !node.equals(App.getDB().getPwDatabase().getRecycleBin())) {
// TODO make edit for group
// clearMenu = contextMenu.add(Menu.NONE, MENU_EDIT, Menu.NONE, R.string.menu_edit);
// clearMenu.setOnMenuItemClickListener(mOnMyActionClickListener);
// Edition
clearMenu = contextMenu.add(Menu.NONE, MENU_EDIT, Menu.NONE, R.string.menu_edit);
clearMenu.setOnMenuItemClickListener(mOnMyActionClickListener);
// Deletion
clearMenu = contextMenu.add(Menu.NONE, MENU_DELETE, Menu.NONE, R.string.menu_delete);
clearMenu.setOnMenuItemClickListener(mOnMyActionClickListener);
}

View File

@@ -28,18 +28,19 @@ import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import com.kunzisoft.keepass.KeePass;
import com.kunzisoft.keepass.fileselect.FileSelectActivity;
@RequiresApi(api = Build.VERSION_CODES.O)
public class AutoFillAuthActivity extends KeePass {
public class AutoFillAuthActivity extends AppCompatActivity {
private AutofillHelper autofillHelper;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
autofillHelper = new AutofillHelper();
startFileSelectActivity();
super.onCreate(savedInstanceState);
}
@@ -49,7 +50,6 @@ public class AutoFillAuthActivity extends KeePass {
intent, PendingIntent.FLAG_CANCEL_CURRENT).getIntentSender();
}
@Override
protected void startFileSelectActivity() {
// Pass extra for Autofill (EXTRA_ASSIST_STRUCTURE)
AssistStructure assistStructure = autofillHelper.retrieveAssistStructure(getIntent());

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -27,6 +27,8 @@ import android.preference.PreferenceManager;
import android.util.Log;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory;
import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException;
import com.kunzisoft.keepass.database.exception.InvalidDBException;
import com.kunzisoft.keepass.database.exception.InvalidPasswordException;
@@ -34,9 +36,9 @@ 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.DrawableFactory;
import com.kunzisoft.keepass.icons.IconDrawableFactory;
import com.kunzisoft.keepass.search.SearchDbHelper;
import com.kunzisoft.keepass.tasks.UpdateStatus;
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
import com.kunzisoft.keepass.utils.UriUtil;
import java.io.BufferedInputStream;
@@ -47,6 +49,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.SyncFailedException;
import java.util.ArrayList;
import java.util.List;
public class Database {
@@ -59,7 +63,7 @@ public class Database {
private boolean readOnly = false;
private boolean passwordEncodingError = false;
private DrawableFactory drawFactory = new DrawableFactory();
private IconDrawableFactory drawFactory = new IconDrawableFactory();
private boolean loaded = false;
@@ -87,7 +91,7 @@ public class Database {
return passwordEncodingError;
}
public DrawableFactory getDrawFactory() {
public IconDrawableFactory getDrawFactory() {
return drawFactory;
}
@@ -99,19 +103,11 @@ public class Database {
loaded = true;
}
public void loadData(Context ctx, InputStream is, String password, InputStream keyInputStream) throws IOException, InvalidDBException {
loadData(ctx, is, password, keyInputStream, new UpdateStatus(), !Importer.DEBUG);
}
public void loadData(Context ctx, Uri uri, String password, Uri keyfile) throws IOException, FileNotFoundException, InvalidDBException {
loadData(ctx, uri, password, keyfile, new UpdateStatus(), !Importer.DEBUG);
}
public void loadData(Context ctx, Uri uri, String password, Uri keyfile, UpdateStatus status) throws IOException, FileNotFoundException, InvalidDBException {
public void loadData(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status) throws IOException, FileNotFoundException, InvalidDBException {
loadData(ctx, uri, password, keyfile, status, !Importer.DEBUG);
}
public void loadData(Context ctx, Uri uri, String password, Uri keyfile, UpdateStatus status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException {
public void loadData(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException {
mUri = uri;
readOnly = false;
if (uri.getScheme().equals("file")) {
@@ -138,7 +134,7 @@ public class Database {
}
private void passUrisAsInputStreams(Context ctx, Uri uri, String password, Uri keyfile, UpdateStatus status, boolean debug, long roundsFix) throws IOException, FileNotFoundException, InvalidDBException {
private void passUrisAsInputStreams(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status, boolean debug, long roundsFix) throws IOException, FileNotFoundException, InvalidDBException {
InputStream is, kfIs;
try {
is = UriUtil.getUriInputStream(ctx, uri);
@@ -156,15 +152,11 @@ public class Database {
loadData(ctx, is, password, kfIs, status, debug, roundsFix);
}
public void loadData(Context ctx, InputStream is, String password, InputStream kfIs, boolean debug) throws IOException, InvalidDBException {
loadData(ctx, is, password, kfIs, new UpdateStatus(), debug);
public void loadData(Context ctx, InputStream is, String password, InputStream keyFileInputStream, boolean debug) throws IOException, InvalidDBException {
loadData(ctx, is, password, keyFileInputStream, null, debug, 0);
}
public void loadData(Context ctx, InputStream is, String password, InputStream kfIs, UpdateStatus status, boolean debug) throws IOException, InvalidDBException {
loadData(ctx, is, password, kfIs, status, debug, 0);
}
public void loadData(Context ctx, InputStream is, String password, InputStream kfIs, UpdateStatus status, boolean debug, long roundsFix) throws IOException, InvalidDBException {
private void loadData(Context ctx, InputStream is, String password, InputStream keyFileInputStream, ProgressTaskUpdater progressTaskUpdater, boolean debug, long roundsFix) throws IOException, InvalidDBException {
BufferedInputStream bis = new BufferedInputStream(is);
if ( ! bis.markSupported() ) {
@@ -174,11 +166,11 @@ public class Database {
// We'll end up reading 8 bytes to identify the header. Might as well use two extra.
bis.mark(10);
Importer imp = ImporterFactory.createImporter(bis, debug);
Importer databaseImporter = ImporterFactory.createImporter(bis, debug);
bis.reset(); // Return to the start
pm = imp.openDatabase(bis, password, kfIs, status, roundsFix);
pm = databaseImporter.openDatabase(bis, password, keyFileInputStream, progressTaskUpdater, roundsFix);
if ( pm != null ) {
try {
switch (pm.getVersion()) {
@@ -222,19 +214,23 @@ 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 {
if (uri.getScheme().equals("file")) {
String filename = uri.getPath();
File tempFile = new File(filename + ".tmp");
FileOutputStream fos = new FileOutputStream(tempFile);
//BufferedOutputStream bos = new BufferedOutputStream(fos);
//PwDbV3Output pmo = new PwDbV3Output(pm, bos, App.getCalendar());
FileOutputStream fos = null;
try {
fos = new FileOutputStream(tempFile);
PwDbOutput pmo = PwDbOutput.getInstance(pm, fos);
if (pmo != null)
pmo.output();
//bos.flush();
//bos.close();
} catch (Exception e) {
throw new IOException("Failed to store database.");
} finally {
if (fos != null)
fos.close();
}
// Force data to disk before continuing
try {
@@ -250,22 +246,24 @@ public class Database {
}
}
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.");
}
PwDbOutput pmo = PwDbOutput.getInstance(pm, os);
pmo.output();
} finally {
if (os != null)
os.close();
}
}
mUri = uri;
}
public void clear() {
drawFactory.clear();
drawFactory.clearCache();
pm = null;
mUri = null;
@@ -348,16 +346,78 @@ public class Database {
}
}
public PwEncryptionAlgorithm getEncryptionAlgorithm() {
return getPwDatabase().getEncryptionAlgorithm();
}
public List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms() {
switch (getPwDatabase().getVersion()) {
case V4:
return ((PwDatabaseV4) getPwDatabase()).getAvailableEncryptionAlgorithms();
case V3:
return ((PwDatabaseV3) getPwDatabase()).getAvailableEncryptionAlgorithms();
}
return new ArrayList<>();
}
public boolean allowEncryptionAlgorithmModification() {
return getAvailableEncryptionAlgorithms().size() > 1;
}
public void assignEncryptionAlgorithm(PwEncryptionAlgorithm algorithm) {
switch (getPwDatabase().getVersion()) {
case V4:
((PwDatabaseV4) getPwDatabase()).setEncryptionAlgorithm(algorithm);
((PwDatabaseV4) getPwDatabase()).setDataEngine(algorithm.getCipherEngine());
((PwDatabaseV4) getPwDatabase()).setDataCipher(algorithm.getDataCipher());
}
}
public String getEncryptionAlgorithmName(Resources resources) {
return getPwDatabase().getEncryptionAlgorithm().getName(resources);
}
public String getKeyDerivationName() {
return getPwDatabase().getKeyDerivationName();
public List<KdfEngine> getAvailableKdfEngines() {
switch (getPwDatabase().getVersion()) {
case V4:
return KdfFactory.kdfList;
case V3:
return KdfFactory.kdfListV3;
}
return new ArrayList<>();
}
public boolean allowKdfModification() {
return getAvailableKdfEngines().size() > 1;
}
public KdfEngine getKdfEngine() {
return getPwDatabase().getKdfEngine();
}
public void assignKdfEngine(KdfEngine kdfEngine) {
switch (getPwDatabase().getVersion()) {
case V4:
PwDatabaseV4 db = ((PwDatabaseV4) getPwDatabase());
if (!db.getKdfParameters().kdfUUID.equals(kdfEngine.getDefaultParameters().kdfUUID))
db.setKdfParameters(kdfEngine.getDefaultParameters());
setNumberKeyEncryptionRounds(kdfEngine.getDefaultKeyRounds());
setMemoryUsage(kdfEngine.getDefaultMemoryUsage());
setParallelism(kdfEngine.getDefaultParallelism());
break;
}
}
public String getKeyDerivationName(Resources resources) {
KdfEngine kdfEngine = getPwDatabase().getKdfEngine();
if (kdfEngine != null) {
return kdfEngine.getName(resources);
}
return "";
}
public String getNumberKeyEncryptionRoundsAsString() {
return Long.toString(getPwDatabase().getNumberKeyEncryptionRounds());
return Long.toString(getNumberKeyEncryptionRounds());
}
public long getNumberKeyEncryptionRounds() {
@@ -368,6 +428,75 @@ 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 {
switch (getPwDatabase().getVersion()) {
case V3:
newPwEntry = new PwEntryV3((PwGroupV3) parent);
case V4:
newPwEntry = new PwEntryV4((PwGroupV4) parent);
}
} catch (Exception e) {
Log.e(TAG, "This version of PwEntry can't be created", e);
}
return newPwEntry;
}
public PwGroup createGroup(PwGroup parent) {
PwGroup newPwGroup = null;
try {
switch (getPwDatabase().getVersion()) {
case V3:
newPwGroup = new PwGroupV3((PwGroupV3) parent);
case V4:
newPwGroup = new PwGroupV4((PwGroupV4) parent);
}
newPwGroup.setId(pm.newGroupId());
} catch (Exception e) {
Log.e(TAG, "This version of PwGroup can't be created", e);
}
return newPwGroup;
}
public void addEntryTo(PwEntry entry, PwGroup parent) {
try {
switch (getPwDatabase().getVersion()) {
@@ -501,6 +630,21 @@ public class Database {
}
}
public void updateGroup(PwGroup oldGroup, PwGroup newGroup) {
try {
switch (getPwDatabase().getVersion()) {
case V3:
((PwGroupV3) oldGroup).updateWith((PwGroupV3) newGroup);
break;
case V4:
((PwGroupV4) oldGroup).updateWith((PwGroupV4) newGroup);
break;
}
} catch (Exception e) {
Log.e(TAG, "This version of PwEntry can't be updated", e);
}
}
public void deleteEntry(PwEntry entry) {
try {
switch (getPwDatabase().getVersion()) {

View File

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

View File

@@ -19,11 +19,9 @@
*/
package com.kunzisoft.keepass.database;
import com.kunzisoft.keepass.crypto.finalkey.FinalKey;
import com.kunzisoft.keepass.crypto.finalkey.FinalKeyFactory;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
import com.kunzisoft.keepass.database.exception.KeyFileEmptyException;
import com.kunzisoft.keepass.stream.NullOutputStream;
import com.kunzisoft.keepass.utils.Util;
import java.io.ByteArrayInputStream;
@@ -31,7 +29,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
@@ -100,42 +97,10 @@ 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 {
assert(key != null);
masterKey = getMasterKey(key, keyInputStream);
}
@@ -220,6 +185,9 @@ public abstract class PwDatabase<PwGroupDB extends PwGroup<PwGroupDB, PwGroupDB,
}
public boolean validatePasswordEncoding(String key) {
if (key == null)
return false;
String encoding = getPasswordEncoding();
byte[] bKey;
@@ -243,10 +211,8 @@ public abstract class PwDatabase<PwGroupDB extends PwGroup<PwGroupDB, PwGroupDB,
protected abstract String getPasswordEncoding();
public byte[] getPasswordKey(String key) throws IOException {
assert(key!=null);
if ( key.length() == 0 )
throw new IllegalArgumentException( "Key cannot be empty." );
if ( key == null)
throw new IllegalArgumentException( "Key cannot be empty." ); // TODO
MessageDigest md;
try {
@@ -281,7 +247,9 @@ public abstract class PwDatabase<PwGroupDB extends PwGroup<PwGroupDB, PwGroupDB,
this.algorithm = algorithm;
}
public abstract String getKeyDerivationName();
public abstract List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms();
public abstract KdfEngine getKdfEngine();
public abstract List<PwGroupDB> getGrpRoots();

View File

@@ -45,12 +45,18 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
package com.kunzisoft.keepass.database;
// Java
import com.kunzisoft.keepass.crypto.keyDerivation.AesKdf;
import com.kunzisoft.keepass.crypto.finalkey.FinalKey;
import com.kunzisoft.keepass.crypto.finalkey.FinalKeyFactory;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory;
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
import com.kunzisoft.keepass.stream.NullOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@@ -71,13 +77,6 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
private int numKeyEncRounds;
private void initAndAddGroup(String name, int iconId, PwGroupV3 parent) {
PwGroupV3 group = createGroup();
group.initNewGroup(name, newGroupId());
group.setIcon(iconFactory.getIcon(iconId));
addGroupTo(group, parent);
}
@Override
public void initNew(String dbPath) {
algorithm = PwEncryptionAlgorithm.AES_Rijndael;
@@ -90,14 +89,29 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
initAndAddGroup("eMail", 19, rootGroup);
}
private void initAndAddGroup(String name, int iconId, PwGroupV3 parent) {
PwGroupV3 group = createGroup();
group.setId(newGroupId());
group.setName(name);
group.setIcon(iconFactory.getIcon(iconId));
addGroupTo(group, parent);
}
@Override
public PwVersion getVersion() {
return PwVersion.V3;
}
@Override
public String getKeyDerivationName() {
return AesKdf.DEFAULT_NAME;
public KdfEngine getKdfEngine() {
return KdfFactory.aesKdf;
}
@Override
public List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms() {
List<PwEncryptionAlgorithm> list = new ArrayList<>();
list.add(PwEncryptionAlgorithm.AES_Rijndael);
return list;
}
@Override
@@ -235,20 +249,50 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
return newId;
}
@Override
public byte[] getMasterKey(String key, InputStream keyInputStream)
throws InvalidKeyFileException, IOException {
if (key != null && key.length() > 0 && keyInputStream != null) {
if (key != null && keyInputStream != null) {
return getCompositeKey(key, keyInputStream);
} else if (key != null && key.length() > 0) {
} else if (key != null) { // key.length() >= 0
return getPasswordKey(key);
} else if (keyInputStream != null) {
} else if (keyInputStream != null) { // key == null
return getFileKey(keyInputStream);
} else {
throw new IllegalArgumentException("Key cannot be empty.");
}
}
/**
* 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";
@@ -287,7 +331,6 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
// Add tree to root groups
groups.add(newGroup);
}
@Override

View File

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

View File

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

View File

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

View File

@@ -24,7 +24,7 @@ import com.kunzisoft.keepass.database.security.ProtectedString;
import java.util.UUID;
public abstract class PwEntry<Parent extends PwGroup> extends PwNode<Parent> implements Cloneable {
public abstract class PwEntry<Parent extends PwGroup> extends PwNode<Parent> {
private static final String PMS_TAN_ENTRY = "<TAN>";
@@ -36,33 +36,10 @@ public abstract class PwEntry<Parent extends PwGroup> extends PwNode<Parent> imp
uuid = UUID.randomUUID();
}
public static PwEntry getInstance(PwGroup parent) {
if (parent instanceof PwGroupV3) {
return new PwEntryV3((PwGroupV3)parent);
}
else if (parent instanceof PwGroupV4) {
return new PwEntryV4((PwGroupV4)parent);
}
else {
throw new RuntimeException("Unknown PwGroup instance.");
}
}
@Override
public PwEntry clone() {
PwEntry newEntry;
try {
newEntry = (PwEntry) super.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException("Clone should be supported");
}
return newEntry;
}
@Override
protected void addCloneAttributesToNewEntry(PwEntry newEntry) {
super.addCloneAttributesToNewEntry(newEntry);
// uuid is clone automatically (IMMUTABLE)
return (PwEntry) super.clone();
}
@Override

View File

@@ -98,6 +98,7 @@ public class PwEntryV3 extends PwEntry<PwGroupV3> {
}
protected void updateWith(PwEntryV3 source) {
super.assign(source);
groupId = source.groupId;
title = source.title;
@@ -118,10 +119,8 @@ public class PwEntryV3 extends PwEntry<PwGroupV3> {
@Override
public PwEntryV3 clone() {
PwEntryV3 newEntry = (PwEntryV3) super.clone();
// Attributes in parent
addCloneAttributesToNewEntry(newEntry);
PwEntryV3 newEntry = (PwEntryV3) super.clone();
// Attributes here
// newEntry.parent stay the same in copy

View File

@@ -89,10 +89,8 @@ public class PwEntryV4 extends PwEntry<PwGroupV4> implements ITimeLogger {
@SuppressWarnings("unchecked")
@Override
public PwEntryV4 clone() {
PwEntryV4 newEntry = (PwEntryV4) super.clone();
// Attributes in parent
addCloneAttributesToNewEntry(newEntry);
PwEntryV4 newEntry = (PwEntryV4) super.clone();
// Attributes here
newEntry.customIcon = new PwIconCustom(this.customIcon);

View File

@@ -30,9 +30,15 @@ public abstract class PwGroup<Parent extends PwGroup, ChildGroup extends PwGroup
protected List<ChildGroup> childGroups = new ArrayList<>();
protected List<ChildEntry> childEntries = new ArrayList<>();
public void initNewGroup(String nm, PwGroupId newId) {
setId(newId);
name = nm;
@Override
public PwGroup clone() {
// name is clone automatically (IMMUTABLE)
return (PwGroup) super.clone();
}
protected void assign(PwGroup<Parent, ChildGroup, ChildEntry> source) {
super.assign(source);
name = source.name;
}
public List<ChildGroup> getChildGroups() {

View File

@@ -40,6 +40,26 @@ public class PwGroupV3 extends PwGroup<PwGroupV3, PwGroupV3, PwEntryV3> {
super();
}
public PwGroupV3(PwGroupV3 p) {
construct(p);
}
protected void updateWith(PwGroupV3 source) {
super.assign(source);
groupId = source.groupId;
level = source.level;
flags = source.flags;
}
@SuppressWarnings("unchecked")
@Override
public PwGroupV3 clone() {
// newGroup.groupId stay the same in copy
// newGroup.level stay the same in copy
// newGroup.flags stay the same in copy
return (PwGroupV3) super.clone();
}
@Override
public void setParent(PwGroupV3 parent) {
super.setParent(parent);

View File

@@ -46,16 +46,58 @@ public class PwGroupV4 extends PwGroup<PwGroupV4, PwGroupV4, PwEntryV4> implemen
super();
}
public PwGroupV4(PwGroupV4 p) {
construct(p);
parentGroupLastMod = new PwDate();
}
public PwGroupV4(String name, PwIconStandard icon) {
this.uuid = UUID.randomUUID();
this.name = name;
this.icon = icon;
}
protected void updateWith(PwGroupV4 source) {
super.assign(source);
uuid = source.uuid;
customIcon = source.customIcon;
usageCount = source.usageCount;
parentGroupLastMod = source.parentGroupLastMod;
customData = source.customData;
expires = source.expires;
notes = source.notes;
isExpanded = source.isExpanded;
defaultAutoTypeSequence = source.defaultAutoTypeSequence;
enableAutoType = source.enableAutoType;
enableSearching = source.enableSearching;
lastTopVisibleEntry = source.lastTopVisibleEntry;
}
@SuppressWarnings("unchecked")
@Override
public void initNewGroup(String nm, PwGroupId newId) {
super.initNewGroup(nm, newId);
parentGroupLastMod = new PwDate();
public PwGroupV4 clone() {
// Attributes in parent
PwGroupV4 newGroup = (PwGroupV4) super.clone();
// Attributes here
// newGroup.uuid stay the same in copy
newGroup.customIcon = new PwIconCustom(this.customIcon);
// newGroup.usageCount stay the same in copy
newGroup.parentGroupLastMod = this.parentGroupLastMod.clone();
// TODO customData make copy from hashmap newGroup.customData = (HashMap<String, String>) this.customData.clone();
// newGroup.expires stay the same in copy
// newGroup.notes stay the same in copy
// newGroup.isExpanded stay the same in copy
// newGroup.defaultAutoTypeSequence stay the same in copy
// newGroup.enableAutoType stay the same in copy
// newGroup.enableSearching stay the same in copy
// newGroup.lastTopVisibleEntry stay the same in copy
return newGroup;
}
public void addGroup(PwGroupV4 subGroup) {

View File

@@ -27,7 +27,7 @@ import java.io.Serializable;
/**
* Abstract class who manage Groups and Entries
*/
public abstract class PwNode<Parent extends PwGroup> implements ISmallTimeLogger, Serializable {
public abstract class PwNode<Parent extends PwGroup> implements ISmallTimeLogger, Serializable, Cloneable {
protected Parent parent = null;
@@ -53,15 +53,23 @@ public abstract class PwNode<Parent extends PwGroup> implements ISmallTimeLogger
this.expireDate = source.expireDate;
}
protected void addCloneAttributesToNewEntry(PwEntry newEntry) {
// newEntry.parent stay the same in copy
@Override
public PwNode clone() {
PwNode newNode;
try {
newNode = (PwNode) super.clone();
// newNode.parent stay the same in copy
newEntry.icon = new PwIconStandard(this.icon);
newNode.icon = new PwIconStandard(this.icon);
newEntry.creation = creation.clone();
newEntry.lastMod = lastMod.clone();
newEntry.lastAccess = lastAccess.clone();
newEntry.expireDate = expireDate.clone();
newNode.creation = creation.clone();
newNode.lastMod = lastMod.clone();
newNode.lastAccess = lastAccess.clone();
newNode.expireDate = expireDate.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException("Clone should be supported");
}
return newNode;
}
/**

View File

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

View File

@@ -17,33 +17,30 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.database.edit;
package com.kunzisoft.keepass.database.action;
import android.content.Context;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwDatabase;
import com.kunzisoft.keepass.database.PwGroup;
public class AddGroup extends RunnableOnFinish {
public class AddGroupRunnable extends RunnableOnFinish {
protected Database mDb;
private String mName;
private int mIconID;
private PwGroup mGroup;
private PwGroup mParent;
private PwGroup mNewGroup;
private Context ctx;
private boolean mDontSave;
public AddGroup(Context ctx, Database db, String name, int iconid,
PwGroup parent, AfterAddNodeOnFinish afterAddNode,
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(afterAddNode);
this.mDb = db;
this.mName = name;
this.mIconID = iconid;
this.mParent = parent;
this.mNewGroup = newGroup;
this.mDontSave = dontSave;
this.ctx = ctx;
@@ -52,37 +49,31 @@ public class AddGroup extends RunnableOnFinish {
@Override
public void run() {
PwDatabase pm = mDb.getPwDatabase();
// Generate new group
mGroup = pm.createGroup();
mGroup.initNewGroup(mName, pm.newGroupId());
mGroup.setIcon(pm.getIconFactory().getIcon(mIconID));
mDb.addGroupTo(mGroup, mParent);
mDb.addGroupTo(mNewGroup, mNewGroup.getParent());
// Commit to disk
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave);
SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave);
save.run();
}
private class AfterAdd extends OnFinish {
private class AfterAdd extends OnFinishRunnable {
AfterAdd(OnFinish finish) {
AfterAdd(OnFinishRunnable finish) {
super(finish);
}
@Override
public void run() {
if ( !mSuccess ) {
mDb.removeGroupFrom(mGroup, mParent);
mDb.removeGroupFrom(mNewGroup, mNewGroup.getParent());
}
// TODO Better callback
AfterAddNodeOnFinish afterAddNode =
(AfterAddNodeOnFinish) super.mOnFinish;
AfterActionNodeOnFinish afterAddNode =
(AfterActionNodeOnFinish) super.mOnFinish;
afterAddNode.mSuccess = mSuccess;
afterAddNode.mMessage = mMessage;
afterAddNode.run(mGroup);
afterAddNode.run(null, mNewGroup);
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,88 @@
/*
* 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 com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwGroup;
public class UpdateGroupRunnable extends RunnableOnFinish {
private Database mDb;
private PwGroup mOldGroup;
private PwGroup mNewGroup;
private Context ctx;
private boolean mDontSave;
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(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 SaveDBRunnable(ctx, mDb, mFinish, mDontSave).run();
}
private class AfterUpdate extends OnFinishRunnable {
private PwGroup mBackup;
AfterUpdate(PwGroup backup, OnFinishRunnable 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);
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -55,7 +55,7 @@ public class PwDbHeaderOutputV4 extends PwDbHeaderOutput {
db = d;
header = h;
MessageDigest md = null;
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
@@ -63,7 +63,7 @@ public class PwDbHeaderOutputV4 extends PwDbHeaderOutput {
}
try {
d.makeFinalKey(header.masterSeed, d.getKdfParameters());
d.makeFinalKey(header.masterSeed);
} catch (IOException e) {
throw new PwDbOutputException(e);
}
@@ -88,25 +88,26 @@ 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 {
writeHeaderField(PwDbHeaderV4.PwDbHeaderV4Fields.KdfParameters, KdfParameters.serialize(db.getKdfParameters()));
// TODO verify serialize in all cases
}
if (header.encryptionIV.length > 0) {
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 +140,7 @@ public class PwDbHeaderOutputV4 extends PwDbHeaderOutput {
}
private void writeHeaderFieldSize(int size) throws IOException {
if (header.version < PwDbHeaderV4.FILE_VERSION_32_4) {
if (header.getVersion() < PwDbHeaderV4.FILE_VERSION_32_4) {
los.writeUShort(size);
} else {
los.writeInt(size);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -36,6 +36,7 @@ import android.widget.Toast;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.password.PasswordGenerator;
import com.kunzisoft.keepass.settings.PreferencesUtil;
import com.kunzisoft.keepass.utils.Util;
import java.util.Set;
@@ -46,6 +47,7 @@ public class GeneratePasswordDialogFragment extends DialogFragment {
private GeneratePasswordListener mListener;
private View root;
private EditText lengthTextView;
private EditText passwordView;
private CompoundButton uppercaseBox;
private CompoundButton lowercaseBox;
@@ -75,6 +77,9 @@ public class GeneratePasswordDialogFragment extends DialogFragment {
LayoutInflater inflater = getActivity().getLayoutInflater();
root = inflater.inflate(R.layout.generate_password, null);
passwordView = root.findViewById(R.id.password);
Util.applyFontVisibilityTo(getContext(), passwordView);
lengthTextView = root.findViewById(R.id.length);
uppercaseBox = root.findViewById(R.id.cb_uppercase);
@@ -109,9 +114,8 @@ public class GeneratePasswordDialogFragment extends DialogFragment {
builder.setView(root)
.setPositiveButton(R.string.accept, (dialog, id) -> {
EditText password = root.findViewById(R.id.password);
Bundle bundle = new Bundle();
bundle.putString(KEY_PASSWORD_ID, password.getText().toString());
bundle.putString(KEY_PASSWORD_ID, passwordView.getText().toString());
mListener.acceptPassword(bundle);
dismiss();

View File

@@ -21,41 +21,66 @@ package com.kunzisoft.keepass.dialogs;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.database.PwIcon;
import com.kunzisoft.keepass.database.PwNode;
import com.kunzisoft.keepass.icons.Icons;
import com.kunzisoft.keepass.icons.IconPackChooser;
import static com.kunzisoft.keepass.dialogs.GroupEditDialogFragment.EditGroupDialogAction.CREATION;
import static com.kunzisoft.keepass.dialogs.GroupEditDialogFragment.EditGroupDialogAction.UPDATE;
import static com.kunzisoft.keepass.dialogs.GroupEditDialogFragment.EditGroupDialogAction.getActionFromOrdinal;
public class GroupEditDialogFragment extends DialogFragment
implements IconPickerDialogFragment.IconPickerListener {
public static final String TAG_CREATE_GROUP = "TAG_CREATE_GROUP";
public static final String KEY_NAME = "name";
public static final String KEY_ICON_ID = "icon_id";
public static final String KEY_NAME = "KEY_NAME";
public static final String KEY_ICON_ID = "KEY_ICON_ID";
public static final String KEY_ACTION_ID = "KEY_ACTION_ID";
private EditGroupListener editGroupListener;
private TextView nameField;
private ImageButton iconButton;
private int mSelectedIconID;
private View root;
private EditGroupDialogAction editGroupDialogAction;
private String nameGroup;
private PwIcon iconGroup;
private ImageView iconButton;
public enum EditGroupDialogAction {
CREATION, UPDATE, NONE;
public static EditGroupDialogAction getActionFromOrdinal(int ordinal) {
return EditGroupDialogAction.values()[ordinal];
}
}
public static GroupEditDialogFragment build() {
Bundle bundle = new Bundle();
bundle.putInt(KEY_ACTION_ID, CREATION.ordinal());
GroupEditDialogFragment fragment = new GroupEditDialogFragment();
fragment.setArguments(bundle);
return fragment;
}
public static GroupEditDialogFragment build(PwNode group) {
Bundle bundle = new Bundle();
bundle.putString(KEY_NAME, group.getDisplayTitle());
// TODO Change
bundle.putInt(KEY_ICON_ID, group.getIcon().hashCode());
bundle.putSerializable(KEY_ICON_ID, group.getIcon());
bundle.putInt(KEY_ACTION_ID, UPDATE.ordinal());
GroupEditDialogFragment fragment = new GroupEditDialogFragment();
fragment.setArguments(bundle);
return fragment;
@@ -78,70 +103,115 @@ public class GroupEditDialogFragment extends DialogFragment
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
assert getActivity() != null;
LayoutInflater inflater = getActivity().getLayoutInflater();
root = inflater.inflate(R.layout.group_edit, null);
nameField = (TextView) root.findViewById(R.id.group_name);
iconButton = (ImageButton) root.findViewById(R.id.icon_button);
View root = inflater.inflate(R.layout.group_edit, null);
TextView nameField = root.findViewById(R.id.group_name);
iconButton = root.findViewById(R.id.icon_button);
// Retrieve the textColor to tint the icon
int[] attrs = {android.R.attr.textColorPrimary};
TypedArray ta = getActivity().getTheme().obtainStyledAttributes(attrs);
int iconColor = ta.getColor(0, Color.WHITE);
// Init elements
editGroupDialogAction = EditGroupDialogAction.NONE;
nameGroup = "";
iconGroup = App.getDB().getPwDatabase().getIconFactory().getFirstIcon();
if (savedInstanceState != null
&& savedInstanceState.containsKey(KEY_ACTION_ID)
&& savedInstanceState.containsKey(KEY_NAME)
&& savedInstanceState.containsKey(KEY_ICON_ID)) {
editGroupDialogAction = getActionFromOrdinal(savedInstanceState.getInt(KEY_ACTION_ID));
nameGroup = savedInstanceState.getString(KEY_NAME);
iconGroup = (PwIcon) savedInstanceState.getSerializable(KEY_ICON_ID);
} else {
if (getArguments() != null
&& getArguments().containsKey(KEY_ACTION_ID))
editGroupDialogAction = EditGroupDialogAction.getActionFromOrdinal(getArguments().getInt(KEY_ACTION_ID));
if (getArguments() != null
&& getArguments().containsKey(KEY_NAME)
&& getArguments().containsKey(KEY_ICON_ID)) {
nameField.setText(getArguments().getString(KEY_NAME));
populateIcon(getArguments().getInt(KEY_ICON_ID));
nameGroup = getArguments().getString(KEY_NAME);
iconGroup = (PwIcon) getArguments().getSerializable(KEY_ICON_ID);
}
}
// populate the name
nameField.setText(nameGroup);
// populate the icon
if (IconPackChooser.getSelectedIconPack(getContext()).tintable()) {
App.getDB().getDrawFactory()
.assignDatabaseIconTo(
getContext(),
iconButton,
iconGroup,
true,
iconColor);
} else {
App.getDB().getDrawFactory()
.assignDatabaseIconTo(
getContext(),
iconButton,
iconGroup);
}
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(root)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
.setPositiveButton(android.R.string.ok, (dialog, id) -> {
String name = nameField.getText().toString();
if ( name.length() > 0 ) {
Bundle bundle = new Bundle();
bundle.putString(KEY_NAME, name);
bundle.putInt(KEY_ICON_ID, mSelectedIconID);
editGroupListener.approveEditGroup(bundle);
editGroupListener.approveEditGroup(
editGroupDialogAction,
name,
iconGroup);
GroupEditDialogFragment.this.getDialog().cancel();
}
else {
Toast.makeText(getContext(), R.string.error_no_name, Toast.LENGTH_LONG).show();
}
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Bundle bundle = new Bundle();
editGroupListener.cancelEditGroup(bundle);
.setNegativeButton(R.string.cancel, (dialog, id) -> {
String name = nameField.getText().toString();
editGroupListener.cancelEditGroup(
editGroupDialogAction,
name,
iconGroup);
GroupEditDialogFragment.this.getDialog().cancel();
}
});
final ImageButton iconButton = (ImageButton) root.findViewById(R.id.icon_button);
iconButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
iconButton.setOnClickListener(v -> {
IconPickerDialogFragment iconPickerDialogFragment = new IconPickerDialogFragment();
if (getFragmentManager() != null)
iconPickerDialogFragment.show(getFragmentManager(), "IconPickerDialogFragment");
}
});
return builder.create();
}
private void populateIcon(int iconId) {
iconButton.setImageResource(Icons.iconToResId(iconId));
@Override
public void iconPicked(Bundle bundle) {
int selectedIconID = bundle.getInt(IconPickerDialogFragment.KEY_ICON_ID);
iconButton.setImageResource(IconPackChooser.getSelectedIconPack(getContext()).iconToResId(selectedIconID));
iconGroup = App.getDB().getPwDatabase().getIconFactory().getIcon(selectedIconID);
}
@Override
public void iconPicked(Bundle bundle) {
mSelectedIconID = bundle.getInt(IconPickerDialogFragment.KEY_ICON_ID);
populateIcon(mSelectedIconID);
public void onSaveInstanceState(Bundle outState) {
outState.putInt(KEY_ACTION_ID, editGroupDialogAction.ordinal());
outState.putString(KEY_NAME, nameGroup);
outState.putSerializable(KEY_ICON_ID, iconGroup);
super.onSaveInstanceState(outState);
}
public interface EditGroupListener {
void approveEditGroup(Bundle bundle);
void cancelEditGroup(Bundle bundle);
void approveEditGroup(EditGroupDialogAction action, String name, PwIcon selectedIcon);
void cancelEditGroup(EditGroupDialogAction action, String name, PwIcon selectedIcon);
}
}

View File

@@ -21,34 +21,37 @@ package com.kunzisoft.keepass.dialogs;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v4.widget.ImageViewCompat;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.icons.Icons;
import com.kunzisoft.keepass.icons.IconPack;
import com.kunzisoft.keepass.icons.IconPackChooser;
import com.kunzisoft.keepass.stylish.StylishActivity;
public class IconPickerDialogFragment extends DialogFragment {
public static final String KEY_ICON_ID = "icon_id";
public static final int UNDEFINED_ICON_ID = -1;
private IconPickerListener iconPickerListener;
private IconPack iconPack;
public static void launch(StylishActivity activity) {
// Create an instance of the dialog fragment and show it
IconPickerDialogFragment dialog = new IconPickerDialogFragment();
dialog.show(activity.getSupportFragmentManager(), "NoticeDialogFragment");
dialog.show(activity.getSupportFragmentManager(), "IconPickerDialogFragment");
}
@Override
@@ -70,29 +73,25 @@ public class IconPickerDialogFragment extends DialogFragment {
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
iconPack = IconPackChooser.getSelectedIconPack(getContext());
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
View root = inflater.inflate(R.layout.icon_picker, null);
builder.setView(root);
GridView currIconGridView = (GridView) root.findViewById(R.id.IconGridView);
GridView currIconGridView = root.findViewById(R.id.IconGridView);
currIconGridView.setAdapter(new ImageAdapter(this.getContext()));
currIconGridView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
currIconGridView.setOnItemClickListener((parent, v, position, id) -> {
Bundle bundle = new Bundle();
bundle.putInt(KEY_ICON_ID, position);
iconPickerListener.iconPicked(bundle);
dismiss();
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
IconPickerDialogFragment.this.getDialog().cancel();
}
});
builder.setNegativeButton(R.string.cancel, (dialog, id) ->
IconPickerDialogFragment.this.getDialog().cancel());
return builder.create();
}
@@ -100,22 +99,20 @@ public class IconPickerDialogFragment extends DialogFragment {
public class ImageAdapter extends BaseAdapter {
private Context context;
public ImageAdapter(Context c) {
ImageAdapter(Context c) {
context = c;
}
public int getCount() {
/* Return number of KeePass icons */
return Icons.count();
return iconPack.numberOfIcons();
}
public Object getItem(int position)
{
public Object getItem(int position) {
return null;
}
public long getItemId(int position)
{
public long getItemId(int position) {
return 0;
}
@@ -123,16 +120,24 @@ public class IconPickerDialogFragment extends DialogFragment {
View currView;
if(convertView == null) {
LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
assert li != null;
currView = li.inflate(R.layout.icon, parent, false);
}
else {
currView = convertView;
}
ImageView iv = currView.findViewById(R.id.icon_image);
iv.setImageResource(iconPack.iconToResId(position));
TextView tv = (TextView) currView.findViewById(R.id.icon_text);
tv.setText("" + position);
ImageView iv = (ImageView) currView.findViewById(R.id.icon_image);
iv.setImageResource(Icons.iconToResId(position));
// Assign color if icons are tintable
if (iconPack.tintable()) {
// Retrieve the textColor to tint the icon
int[] attrs = {android.R.attr.textColor};
assert getContext() != null;
TypedArray ta = getContext().getTheme().obtainStyledAttributes(attrs);
int iconColor = ta.getColor(0, Color.BLACK);
ImageViewCompat.setImageTintList(iv, ColorStateList.valueOf(iconColor));
}
return currView;
}

View File

@@ -0,0 +1,74 @@
/*
* 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.dialogs;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.widget.Toast;
import com.kunzisoft.keepass.BuildConfig;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.utils.Util;
/**
* Custom Dialog that asks the user to download the pro version or make a donation.
*/
public class ProFeatureDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
assert getActivity() != null;
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
if (BuildConfig.CLOSED_STORE) {
stringBuilder.append(Html.fromHtml(getString(R.string.html_text_ad_free))).append("\n\n");
stringBuilder.append(Html.fromHtml(getString(R.string.html_text_buy_pro)));
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();
}
});
}
else {
stringBuilder.append(Html.fromHtml(getString(R.string.html_text_feature_generosity))).append("\n\n");
stringBuilder.append(Html.fromHtml(getString(R.string.html_text_donation)));
builder.setPositiveButton(R.string.contribute, (dialog, id) -> {
try {
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.setMessage(stringBuilder);
builder.setNegativeButton(android.R.string.cancel, (dialog, id) -> dismiss());
// Create the AlertDialog object and return it
return builder.create();
}
}

View File

@@ -0,0 +1,85 @@
/*
* 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.dialogs;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.widget.Toast;
import com.kunzisoft.keepass.BuildConfig;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.utils.Util;
/**
* Custom Dialog that asks the user to download the pro version or make a donation.
*/
public class UnderDevelopmentFeatureDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
assert getActivity() != null;
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
if (BuildConfig.CLOSED_STORE) {
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))).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.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);
// Create the AlertDialog object and return it
return builder.create();
}
}

View File

@@ -29,7 +29,9 @@ import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.stylish.Stylish;
import com.nononsenseapps.filepicker.FilePickerActivity;
/**
* FilePickerActivity class with a style compatibility
*/
public class FilePickerStylishActivity extends FilePickerActivity {
private @StyleRes
@@ -51,12 +53,21 @@ public class FilePickerStylishActivity extends FilePickerActivity {
}
}
/**
* Derived from the Stylish class, get the specific FilePickerStyle theme
*/
public static class FilePickerStylish extends Stylish {
public static @StyleRes int getThemeId(Context context) {
if (themeString.equals(context.getString(R.string.list_style_name_night)))
return R.style.KeepassDXStyle_FilePickerStyle_Night;
if (themeString.equals(context.getString(R.string.list_style_name_dark)))
return R.style.KeepassDXStyle_FilePickerStyle_Dark;
else if (themeString.equals(context.getString(R.string.list_style_name_blue)))
return R.style.KeepassDXStyle_FilePickerStyle_Blue;
else if (themeString.equals(context.getString(R.string.list_style_name_red)))
return R.style.KeepassDXStyle_FilePickerStyle_Red;
else if (themeString.equals(context.getString(R.string.list_style_name_purple)))
return R.style.KeepassDXStyle_FilePickerStyle_Purple;
return R.style.KeepassDXStyle_FilePickerStyle_Light;
return R.style.KeepassDXStyle_FilePickerStyle;
}
}
}

View File

@@ -24,6 +24,7 @@ import android.app.Activity;
import android.app.assist.AssistStructure;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@@ -31,6 +32,7 @@ import android.os.Environment;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@@ -40,14 +42,17 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.getkeepsafe.taptargetview.TapTarget;
import com.getkeepsafe.taptargetview.TapTargetView;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.activities.GroupActivity;
import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.autofill.AutofillHelper;
import com.kunzisoft.keepass.database.edit.CreateDB;
import com.kunzisoft.keepass.database.edit.FileOnFinish;
import com.kunzisoft.keepass.database.action.CreateDBRunnable;
import com.kunzisoft.keepass.database.action.FileOnFinishRunnable;
import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException;
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
import com.kunzisoft.keepass.dialogs.CreateFileDialogFragment;
@@ -55,11 +60,13 @@ import com.kunzisoft.keepass.password.AssignPasswordHelper;
import com.kunzisoft.keepass.password.PasswordActivity;
import com.kunzisoft.keepass.settings.PreferencesUtil;
import com.kunzisoft.keepass.stylish.StylishActivity;
import com.kunzisoft.keepass.tasks.ProgressTask;
import com.kunzisoft.keepass.tasks.ProgressTaskDialogFragment;
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
import com.kunzisoft.keepass.utils.EmptyUtils;
import com.kunzisoft.keepass.utils.MenuUtil;
import com.kunzisoft.keepass.utils.UriUtil;
import com.kunzisoft.keepass.view.FileNameView;
import net.cachapa.expandablelayout.ExpandableLayout;
import java.io.File;
import java.io.FileNotFoundException;
@@ -87,6 +94,9 @@ public class FileSelectActivity extends StylishActivity implements
private FileSelectAdapter mAdapter;
private View fileListTitle;
private View createButtonView;
private View browseButtonView;
private View openButtonView;
private RecentFileHistory fileHistory;
@@ -94,8 +104,9 @@ public class FileSelectActivity extends StylishActivity implements
private boolean consultationMode = false;
private AutofillHelper autofillHelper;
private View fileSelectExpandableButton;
private ExpandableLayout fileSelectExpandable;
private EditText openFileNameView;
private FileNameView fileNameView;
private AssignPasswordHelper assignPasswordHelper;
private Uri databaseUri;
@@ -136,11 +147,10 @@ public class FileSelectActivity extends StylishActivity implements
fileListTitle = findViewById(R.id.file_list_title);
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle(getString(R.string.app_name));
toolbar.setTitle("");
setSupportActionBar(toolbar);
openFileNameView = findViewById(R.id.file_filename);
fileNameView = findViewById(R.id.file_select);
// Set the initial value of the filename
defaultPath = Environment.getExternalStorageDirectory().getAbsolutePath()
@@ -149,6 +159,17 @@ public class FileSelectActivity extends StylishActivity implements
+ getString(R.string.database_file_extension_default);
openFileNameView.setHint(R.string.open_link_database);
// Button to expand file selection
fileSelectExpandableButton = findViewById(R.id.file_select_expandable_button);
fileSelectExpandable = findViewById(R.id.file_select_expandable);
fileSelectExpandableButton.setOnClickListener(view -> {
if (fileSelectExpandable.isExpanded())
fileSelectExpandable.collapse();
else
fileSelectExpandable.expand();
});
// History list
RecyclerView mListFiles = findViewById(R.id.file_list);
mListFiles.setLayoutManager(new LinearLayoutManager(this));
@@ -159,8 +180,8 @@ public class FileSelectActivity extends StylishActivity implements
}
// Open button
View openButton = findViewById(R.id.open_database);
openButton.setOnClickListener(v -> {
openButtonView = findViewById(R.id.open_database);
openButtonView.setOnClickListener(v -> {
String fileName = openFileNameView.getText().toString();
if (fileName.isEmpty())
fileName = defaultPath;
@@ -168,15 +189,15 @@ public class FileSelectActivity extends StylishActivity implements
});
// Create button
View createButton = findViewById(R.id.create_database);
createButton.setOnClickListener(v ->
createButtonView = findViewById(R.id.create_database);
createButtonView .setOnClickListener(v ->
FileSelectActivityPermissionsDispatcher
.openCreateFileDialogFragmentWithPermissionCheck(FileSelectActivity.this)
);
keyFileHelper = new KeyFileHelper(this);
View browseButton = findViewById(R.id.browse_button);
browseButton.setOnClickListener(keyFileHelper.getOpenFileOnClickViewListener(
browseButtonView = findViewById(R.id.browse_button);
browseButtonView.setOnClickListener(keyFileHelper.getOpenFileOnClickViewListener(
() -> Uri.parse("file://" + openFileNameView.getText().toString())));
// Construct adapter with listeners
@@ -212,6 +233,9 @@ public class FileSelectActivity extends StylishActivity implements
}
}
}
// For the first time show education
checkAndPerformedEducation();
}
private void launchPasswordActivityWithPath(String path) {
@@ -246,15 +270,139 @@ public class FileSelectActivity extends StylishActivity implements
}
}
private void updateExternalStorageWarning() {
// To show errors
int warning = -1;
String state = Environment.getExternalStorageState();
if (state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
warning = R.string.warning_read_only;
} else if (!state.equals(Environment.MEDIA_MOUNTED)) {
warning = R.string.warning_unmounted;
}
TextView labelWarningView = findViewById(R.id.label_warning);
if (warning != -1) {
labelWarningView.setText(warning);
labelWarningView.setVisibility(View.VISIBLE);
} else {
labelWarningView.setVisibility(View.INVISIBLE);
}
}
@Override
protected void onResume() {
super.onResume();
fileNameView.updateExternalStorageWarning();
updateExternalStorageWarning();
updateTitleFileListView();
mAdapter.notifyDataSetChanged();
}
/**
* Check and display learning views
* Displays the explanation for a database creation then a database selection
*/
private void checkAndPerformedEducation() {
// If no recent files
if ( !fileHistory.hasRecentFiles() ) {
// Try to open the creation base education
if (!PreferencesUtil.isEducationCreateDatabasePerformed(this) ) {
TapTargetView.showFor(this,
TapTarget.forView(createButtonView,
getString(R.string.education_create_database_title),
getString(R.string.education_create_database_summary))
.icon(ContextCompat.getDrawable(this, R.drawable.ic_database_plus_white_24dp))
.textColorInt(Color.WHITE)
.tintTarget(true)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
FileSelectActivityPermissionsDispatcher
.openCreateFileDialogFragmentWithPermissionCheck(FileSelectActivity.this);
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
// But if the user cancel, it can also select a database
checkAndPerformedEducationForSelection();
}
});
PreferencesUtil.saveEducationPreference(FileSelectActivity.this,
R.string.education_create_db_key);
}
}
else
checkAndPerformedEducationForSelection();
}
/**
* Check and display learning views
* Displays the explanation for a database selection
*/
private void checkAndPerformedEducationForSelection() {
if (!PreferencesUtil.isEducationSelectDatabasePerformed(this)
&& browseButtonView != null) {
TapTargetView.showFor(FileSelectActivity.this,
TapTarget.forView(browseButtonView,
getString(R.string.education_select_database_title),
getString(R.string.education_select_database_summary))
.icon(ContextCompat.getDrawable(this, R.drawable.ic_folder_white_24dp))
.textColorInt(Color.WHITE)
.tintTarget(true)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
keyFileHelper.getOpenFileOnClickViewListener().onClick(view);
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
if (!PreferencesUtil.isEducationOpenLinkDatabasePerformed(FileSelectActivity.this)) {
TapTargetView.showFor(FileSelectActivity.this,
TapTarget.forView(fileSelectExpandableButton,
getString(R.string.education_open_link_database_title),
getString(R.string.education_open_link_database_summary))
.icon(ContextCompat.getDrawable(FileSelectActivity.this, R.drawable.ic_link_white_24dp))
.textColorInt(Color.WHITE)
.tintTarget(true)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
// Do nothing here
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
}
});
PreferencesUtil.saveEducationPreference(FileSelectActivity.this,
R.string.education_open_link_db_key);
}
}
});
PreferencesUtil.saveEducationPreference(FileSelectActivity.this,
R.string.education_select_db_key);
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
@@ -368,22 +516,27 @@ public class FileSelectActivity extends StylishActivity implements
// Prep an object to collect a password once the database has
// been created
FileOnFinish launchActivityOnFinish = new FileOnFinish(
FileOnFinishRunnable launchActivityOnFinish = new FileOnFinishRunnable(
new LaunchGroupActivity(databaseFilename));
AssignPasswordOnFinish assignPasswordOnFinish =
new AssignPasswordOnFinish(launchActivityOnFinish);
// Create the new database
CreateDB create = new CreateDB(FileSelectActivity.this,
databaseFilename, assignPasswordOnFinish, true);
// Initialize the password helper assigner to set the password after the database creation
assignPasswordHelper = new AssignPasswordHelper(this,
masterPasswordChecked, masterPassword, keyFileChecked, keyFile);
assignPasswordHelper.setCreateProgressDialog(false);
// Create the new database
CreateDBRunnable createDBTask = new CreateDBRunnable(FileSelectActivity.this,
databaseFilename, assignPasswordOnFinish, true);
createDBTask.setUpdateProgressTaskStatus(
new UpdateProgressTaskStatus(this,
ProgressTaskDialogFragment.start(
getSupportFragmentManager(),
R.string.progress_create)
));
new Thread(createDBTask).start();
ProgressTask createTask = new ProgressTask(
FileSelectActivity.this, create,
R.string.progress_create);
createTask.run();
assignPasswordHelper =
new AssignPasswordHelper(this,
masterPassword, keyFile);
} catch (Exception e) {
String error = "Unable to create database with this password and key file";
Toast.makeText(this, error, Toast.LENGTH_LONG).show();
@@ -398,21 +551,23 @@ public class FileSelectActivity extends StylishActivity implements
}
private class AssignPasswordOnFinish extends FileOnFinish {
private class AssignPasswordOnFinish extends FileOnFinishRunnable {
AssignPasswordOnFinish(FileOnFinish fileOnFinish) {
AssignPasswordOnFinish(FileOnFinishRunnable fileOnFinish) {
super(fileOnFinish);
}
@Override
public void run() {
if (mSuccess) {
assignPasswordHelper.assignPasswordInDatabase(mOnFinish);
// Dont use ProgressTaskDialogFragment.stop(getSupportFragmentManager());
// assignPasswordHelper do it
runOnUiThread(() -> assignPasswordHelper.assignPasswordInDatabase(mOnFinish));
}
}
}
private class LaunchGroupActivity extends FileOnFinish {
private class LaunchGroupActivity extends FileOnFinishRunnable {
private Uri mUri;
LaunchGroupActivity(String filename) {
@@ -494,6 +649,7 @@ public class FileSelectActivity extends StylishActivity implements
if (PreferencesUtil.autoOpenSelectedFile(FileSelectActivity.this)) {
launchPasswordActivityWithPath(uri.toString());
} else {
fileSelectExpandable.expand(false);
openFileNameView.setText(uri.toString());
}
}

View File

@@ -63,7 +63,7 @@ public class FileSelectAdapter extends RecyclerView.Adapter<FileSelectViewHolder
Resources.Theme theme = context.getTheme();
theme.resolveAttribute(R.attr.colorAccentCompat, typedValue, true);
warningColor = typedValue.data;
theme.resolveAttribute(android.R.attr.textColorPrimary, typedValue, true);
theme.resolveAttribute(android.R.attr.textColorHintInverse, typedValue, true);
defaultColor = typedValue.data;
}

View File

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

View File

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

View File

@@ -1,137 +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.icons;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.compat.BitmapDrawableCompat;
import com.kunzisoft.keepass.database.PwIcon;
import com.kunzisoft.keepass.database.PwIconCustom;
import com.kunzisoft.keepass.database.PwIconStandard;
import org.apache.commons.collections.map.AbstractReferenceMap;
import org.apache.commons.collections.map.ReferenceMap;
public class DrawableFactory {
private static Drawable blank = null;
private static int blankWidth = -1;
private static int blankHeight = -1;
/** customIconMap
* Cache for icon drawable.
* Keys: UUID, Values: Drawables
*/
private ReferenceMap customIconMap = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK);
/** standardIconMap
* Cache for icon drawable.
* Keys: Integer, Values: Drawables
*/
private ReferenceMap standardIconMap = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK);
public void assignDrawableTo(ImageView iv, Resources res, PwIcon icon) {
Drawable draw = getIconDrawable(res, icon);
if (iv != null && draw != null)
iv.setImageDrawable(draw);
}
public Drawable getIconDrawable(Resources res, PwIcon icon) {
if (icon instanceof PwIconStandard) {
return getIconDrawable(res, (PwIconStandard) icon);
} else {
return getIconDrawable(res, (PwIconCustom) icon);
}
}
private static void initBlank(Resources res) {
if (blank==null) {
blank = res.getDrawable(R.drawable.ic99_blank);
blankWidth = blank.getIntrinsicWidth();
blankHeight = blank.getIntrinsicHeight();
}
}
public Drawable getIconDrawable(Resources res, PwIconStandard icon) {
int resId = Icons.iconToResId(icon.iconId);
Drawable draw = (Drawable) standardIconMap.get(resId);
if (draw == null) {
draw = res.getDrawable(resId);
standardIconMap.put(resId, draw);
}
return draw;
}
public Drawable getIconDrawable(Resources res, PwIconCustom icon) {
initBlank(res);
if (icon == null) {
return blank;
}
Drawable draw = (Drawable) customIconMap.get(icon.uuid);
if (draw == null) {
if (icon.imageData == null) {
return blank;
}
Bitmap bitmap = BitmapFactory.decodeByteArray(icon.imageData, 0, icon.imageData.length);
// Could not understand custom icon
if (bitmap == null) {
return blank;
}
bitmap = resize(bitmap);
draw = BitmapDrawableCompat.getBitmapDrawable(res, bitmap);
customIconMap.put(icon.uuid, draw);
}
return draw;
}
/** Resize the custom icon to match the built in icons
* @param bitmap
* @return
*/
private Bitmap resize(Bitmap bitmap) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
if (width == blankWidth && height == blankHeight) {
return bitmap;
}
return Bitmap.createScaledBitmap(bitmap, blankWidth, blankHeight, true);
}
public void clear() {
standardIconMap.clear();
customIconMap.clear();
}
}

View File

@@ -0,0 +1,340 @@
/*
* 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.icons;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.ImageViewCompat;
import android.util.Log;
import android.widget.ImageView;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.compat.BitmapDrawableCompat;
import com.kunzisoft.keepass.database.PwIcon;
import com.kunzisoft.keepass.database.PwIconCustom;
import com.kunzisoft.keepass.database.PwIconStandard;
import org.apache.commons.collections.map.AbstractReferenceMap;
import org.apache.commons.collections.map.ReferenceMap;
/**
* Factory class who build database icons dynamically, can assign an icon of IconPack, or a custom icon to an ImageView with a tint
*/
public class IconDrawableFactory {
private static final String TAG = IconDrawableFactory.class.getName();
private static Drawable blank = null;
private static int blankWidth = -1;
private static int blankHeight = -1;
/** customIconMap
* Cache for icon drawable.
* Keys: UUID, Values: Drawables
*/
private ReferenceMap customIconMap = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK);
/** standardIconMap
* Cache for icon drawable.
* Keys: Integer, Values: Drawables
*/
private ReferenceMap standardIconMap = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK);
/**
* Assign a default database icon to an ImageView
*
* @param context Context to build the drawable
* @param iv ImageView that will host the drawable
*/
public void assignDefaultDatabaseIconTo(Context context, ImageView iv) {
assignDefaultDatabaseIconTo(context, iv, false, Color.WHITE);
}
/**
* Assign a default database icon to an ImageView and tint it
*
* @param context Context to build the drawable
* @param iv ImageView that will host the drawable
*/
public void assignDefaultDatabaseIconTo(Context context, ImageView iv, boolean tint, int tintColor) {
assignDrawableTo(context, iv, IconPackChooser.getSelectedIconPack(context).getDefaultIconId(), tint, tintColor);
}
/**
* Assign a database icon to an ImageView
*
* @param context Context to build the drawable
* @param iv ImageView that will host the drawable
* @param icon The icon from the database
*/
public void assignDatabaseIconTo(Context context, ImageView iv, PwIcon icon) {
assignDatabaseIconTo(context, iv, icon, false, Color.WHITE);
}
/**
* Assign a database icon to an ImageView and tint it
*
* @param context Context to build the drawable
* @param imageView ImageView that will host the drawable
* @param icon The icon from the database
* @param tint true will tint the drawable with tintColor
* @param tintColor Use this color if tint is true
*/
public void assignDatabaseIconTo(Context context, ImageView imageView, PwIcon icon, boolean tint, int tintColor) {
assignDrawableToImageView(getIconDrawable(context, icon, tint, tintColor),
imageView,
tint,
tintColor);
}
/**
* Assign an image by its resourceId to an ImageView and tint it
*
* @param context Context to build the drawable
* @param imageView ImageView that will host the drawable
* @param iconId iconId from the resources
* @param tint true will tint the drawable with tintColor
* @param tintColor Use this color if tint is true
*/
public void assignDrawableTo(Context context, ImageView imageView, int iconId, boolean tint, int tintColor) {
assignDrawableToImageView(new SuperDrawable(getIconDrawable(context, iconId, tint, tintColor)),
imageView,
tint,
tintColor);
}
/**
* Utility method to assign a drawable to an ImageView and tint it
*/
private void assignDrawableToImageView(SuperDrawable superDrawable, ImageView imageView, boolean tint, int tintColor) {
if (imageView != null && superDrawable.drawable != null) {
imageView.setImageDrawable(superDrawable.drawable);
if (!superDrawable.custom && tint) {
ImageViewCompat.setImageTintList(imageView, ColorStateList.valueOf(tintColor));
} else {
ImageViewCompat.setImageTintList(imageView, null);
}
}
}
/**
* Get the drawable icon from cache or build it and add it to the cache if not exists yet
*
* @param context Context to build the drawable
* @param icon The icon from database
* @return The build drawable
*/
public Drawable getIconDrawable(Context context, PwIcon icon) {
return getIconDrawable(context, icon, false, Color.WHITE).drawable;
}
/**
* Get the drawable icon from cache or build it and add it to the cache if not exists yet then tint it if needed
*
* @param context Context to build the drawable
* @param icon The icon from database
* @param tint true will tint the drawable with tintColor
* @param tintColor Use this color if tint is true
* @return The build drawable
*/
public SuperDrawable getIconDrawable(Context context, PwIcon icon, boolean tint, int tintColor) {
if (icon instanceof PwIconStandard) {
return new SuperDrawable(getIconDrawable(context.getApplicationContext(), (PwIconStandard) icon, tint, tintColor));
} else {
return new SuperDrawable(getIconDrawable(context, (PwIconCustom) icon), true);
}
}
/**
* Build a blank drawable
* @param res Resource to build the drawable
*/
private static void initBlank(Resources res) {
if (blank==null) {
blankWidth = (int) res.getDimension(R.dimen.icon_size);
blankHeight = (int) res.getDimension(R.dimen.icon_size);
blank = new ColorDrawable(Color.TRANSPARENT);
blank.setBounds(0, 0, blankWidth, blankHeight);
}
}
/**
* Key class to retrieve a Drawable in the cache if it's tinted or not
*/
private class CacheKey {
int resId;
boolean isTint;
int color;
CacheKey(int resId, boolean isTint, int color) {
this.resId = resId;
this.isTint = isTint;
this.color = color;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CacheKey cacheKey = (CacheKey) o;
if (isTint)
return resId == cacheKey.resId &&
cacheKey.isTint &&
color == cacheKey.color;
else
return resId == cacheKey.resId &&
!cacheKey.isTint;
}
}
/**
* Get the drawable icon from cache or build it and add it to the cache if not exists yet
*
* @param context Context to make drawable
* @param icon Icon from database
* @param isTint Tint the drawable if true
* @param tintColor Use this color if tint is true
* @return The drawable
*/
private Drawable getIconDrawable(Context context, PwIconStandard icon, boolean isTint, int tintColor) {
int resId = IconPackChooser.getSelectedIconPack(context).iconToResId(icon.iconId);
return getIconDrawable(context, resId, isTint, tintColor);
}
/**
* Get the drawable icon from cache or build it and add it to the cache if not exists yet
*
* @param context Context to make drawable
* @param iconId iconId from resources
* @param isTint Tint the drawable if true
* @param tintColor Use this color if tint is true
* @return The drawable
*/
private Drawable getIconDrawable(Context context, int iconId, boolean isTint, int tintColor) {
CacheKey newCacheKey = new CacheKey(iconId, isTint, tintColor);
Drawable draw = (Drawable) standardIconMap.get(newCacheKey);
if (draw == null) {
try {
draw = ContextCompat.getDrawable(context, iconId);
} catch (Exception e) {
Log.e(TAG, "Can't get icon", e);
}
if (draw != null) {
standardIconMap.put(newCacheKey, draw);
}
}
if (draw == null) {
if (blank == null)
initBlank(context.getResources());
draw = blank;
}
return draw;
}
/**
* Utility class to prevent a custom icon to be tint
*/
private class SuperDrawable {
Drawable drawable;
boolean custom;
SuperDrawable(Drawable drawable) {
this.drawable = drawable;
this.custom = false;
}
SuperDrawable(Drawable drawable, boolean custom) {
this.drawable = drawable;
this.custom = custom;
}
}
/**
* Build a custom icon from database
* @param context Context to build the drawable
* @param icon Icon from database
* @return The drawable
*/
private Drawable getIconDrawable(Context context, PwIconCustom icon) {
initBlank(context.getResources());
if (icon == null) {
return blank;
}
Drawable draw = (Drawable) customIconMap.get(icon.uuid);
if (draw == null) {
if (icon.imageData == null) {
return blank;
}
Bitmap bitmap = BitmapFactory.decodeByteArray(icon.imageData, 0, icon.imageData.length);
// Could not understand custom icon
if (bitmap == null) {
return blank;
}
bitmap = resize(bitmap);
draw = BitmapDrawableCompat.getBitmapDrawable(context.getResources(), bitmap);
customIconMap.put(icon.uuid, draw);
}
return draw;
}
/**
* Resize the custom icon to match the built in icons
*
* @param bitmap Bitmap to resize
* @return Bitmap resized
*/
private Bitmap resize(Bitmap bitmap) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
if (width == blankWidth && height == blankHeight) {
return bitmap;
}
return Bitmap.createScaledBitmap(bitmap, blankWidth, blankHeight, true);
}
/**
* Clear the cache of icons
*/
public void clearCache() {
standardIconMap.clear();
customIconMap.clear();
}
}

View File

@@ -0,0 +1,159 @@
/*
* 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.icons;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.util.SparseIntArray;
import com.kunzisoft.keepass.R;
import java.text.DecimalFormat;
/**
* Class who construct dynamically database icons contains in a separate library
*
* <p>It only supports icons with specific nomenclature <strong>[stringId]_[%2d]_32dp</strong>
* where [stringId] contains in a string xml attribute with id <strong>resource_id</strong> and
* [%2d] 2 numerical numbers between 00 and 68 included,
* </p>
* <p>See <i>icon-pack-classic</i> module as sample
* </p>
*
*/
public class IconPack {
private static final int NB_ICONS = 68;
private SparseIntArray icons;
private String resourceStringId;
private String name;
private boolean tintable;
private Resources resources;
/**
* Construct dynamically the icon pack provide by the string resource id
*
* @param context Context of the app to retrieve the resources
* @param resourceId String Id of the pack (ex : com.kunzisoft.keepass.icon.classic.R.string.resource_id)
*/
IconPack(Context context, int resourceId) {
resources = context.getResources();
icons = new SparseIntArray();
resourceStringId = context.getString(resourceId);
// If finish with a _ remove it
if (resourceStringId.lastIndexOf('_') == resourceStringId.length() - 1)
resourceStringId = resourceStringId.substring(0, resourceStringId.length() -1);
// Build the list of icons
int num = 0;
while(num <= NB_ICONS) {
// To construct the id with name_ic_XX_32dp (ex : classic_ic_08_32dp )
int resId = resources.getIdentifier(
resourceStringId + "_" + new DecimalFormat("00").format(num) + "_32dp",
"drawable",
context.getPackageName());
icons.put(num, resId);
num++;
}
// Get visual name
name = resources.getString(
resources.getIdentifier(
resourceStringId + "_" + "name",
"string",
context.getPackageName()
)
);
// If icons are tintable
tintable = resources.getBoolean(
resources.getIdentifier(
resourceStringId + "_" + "tintable",
"bool",
context.getPackageName()
)
);
}
/**
* Get the name of the IconPack
*
* @return String visual name of the pack
*/
public String getName() {
return name;
}
/**
* Get the id of the IconPack
*
* @return String id of the pack
*/
public String getId() {
return resourceStringId;
}
/**
* Determine if each icon in the pack can be tint
*
* @return true if icons are tintable
*/
public boolean tintable() {
return tintable;
}
/**
* Get the number of icons in this pack
*
* @return int Number of database icons
*/
public int numberOfIcons() {
return icons.size();
}
/**
* Icon as a resourceId
*
* @param iconId Icon database Id of the icon to retrieve
* @return int resourceId
*/
public int iconToResId(int iconId) {
return icons.get(iconId, R.drawable.ic_blank_32dp);
}
/**
* @return int Get the default icon resource id
*/
public int getDefaultIconId() {
return iconToResId(0);
}
/**
* Icon as a drawable
*
* @param iconId Icon database Id of the icon to retrieve
* @return int resourceId
*/
public Drawable getDrawable(int iconId) {
return resources.getDrawable(iconToResId(iconId));
}
}

View File

@@ -0,0 +1,141 @@
/*
* 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.icons;
import android.content.Context;
import android.util.Log;
import com.kunzisoft.keepass.BuildConfig;
import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.settings.PreferencesUtil;
import java.util.ArrayList;
import java.util.List;
/**
* Utility class to built and select an IconPack dynamically by libraries importation
*
* @author J-Jamet
*/
public class IconPackChooser {
private static final String TAG = IconPackChooser.class.getName();
private static List<IconPack> iconPackList = new ArrayList<>();
private static IconPack iconPackSelected = null;
private static IconPackChooser sIconPackBuilder;
/**
* IconPackChooser as singleton
*/
private IconPackChooser(){
if (sIconPackBuilder != null){
throw new RuntimeException("Use build() method to get the single instance of this class.");
}
}
/**
* Built the icon pack chooser based on imports made in <i>build.gradle</i>
*
* <p>Dynamic import can be done for each flavor by prefixing the 'implementation' command with the name of the flavor.< br/>
* (ex : {@code libreImplementation project(path: ':icon-pack-classic')} <br />
* Each name of icon pack must be in {@code ICON_PACKS} in the build.gradle file</p>
*
* @param context Context to construct each pack with the resources
* @return An unique instance of {@link IconPackChooser}, recall {@link #build(Context)} provide the same instance
*/
@SuppressWarnings("JavaDoc")
public static IconPackChooser build(Context context) {
if (sIconPackBuilder == null) { //if there is no instance available... create new one
synchronized (IconPackChooser.class) {
if (sIconPackBuilder == null) {
sIconPackBuilder = new IconPackChooser();
for (String iconPackString : BuildConfig.ICON_PACKS) {
addOrCatchNewIconPack(context, iconPackString);
}
if (iconPackList.isEmpty()) {
Log.e(TAG, "Icon packs can't be load, retry with one by default");
addDefaultIconPack(context);
}
}
}
}
return sIconPackBuilder;
}
/**
* Construct dynamically the icon pack provide by the default string resource "resource_id"
*/
private static void addDefaultIconPack(Context context) {
int resourceId = context.getResources().getIdentifier("resource_id", "string", context.getPackageName());
iconPackList.add(new IconPack(context, resourceId));
}
/**
* Utility method to add new icon pack or catch exception if not retrieve
*/
private static void addOrCatchNewIconPack(Context context, String iconPackString) {
try {
iconPackList.add(new IconPack(context, context.getResources().getIdentifier(
iconPackString + "_resource_id",
"string",
context.getPackageName())));
} catch (Exception e) {
Log.w(TAG, "Icon pack "+ iconPackString +" can't be load");
}
}
public static void setSelectedIconPack(String iconPackIdString) {
for(IconPack iconPack : iconPackList) {
if (iconPack.getId().equals(iconPackIdString)) {
App.getDB().getDrawFactory().clearCache();
iconPackSelected = iconPack;
break;
}
}
}
/**
* Get the current IconPack used
*
* @param context Context to build the icon pack if not already build
* @return IconPack currently in usage
*/
public static IconPack getSelectedIconPack(Context context) {
build(context);
if (iconPackSelected == null)
setSelectedIconPack(PreferencesUtil.getIconPackSelectedId(context));
return iconPackSelected;
}
/**
* Get the list of IconPack available
*
* @param context Context to build the icon pack if not already build
* @return IconPack available
*/
public static List<IconPack> getIconPackList(Context context) {
build(context);
return iconPackList;
}
}

View File

@@ -0,0 +1,8 @@
package com.kunzisoft.keepass.icons;
public class IconPackUnknownException extends Exception{
IconPackUnknownException() {
super("Icon pack isn't defined");
}
}

View File

@@ -1,74 +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.icons;
import android.util.SparseIntArray;
import com.kunzisoft.keepass.R;
import java.lang.reflect.Field;
public class Icons {
private static SparseIntArray icons = null;
private static void buildList() {
if (icons == null) {
icons = new SparseIntArray();
Class<com.kunzisoft.keepass.R.drawable> c = com.kunzisoft.keepass.R.drawable.class;
Field[] fields = c.getFields();
for (int i = 0; i < fields.length; i++) {
String fieldName = fields[i].getName();
if (fieldName.matches("ic\\d{2}.*")) {
String sNum = fieldName.substring(2, 4);
int num = Integer.parseInt(sNum);
if (num > 69) {
continue;
}
int resId;
try {
resId = fields[i].getInt(null);
} catch (Exception e) {
continue;
}
icons.put(num, resId);
}
}
}
}
public static int iconToResId(int iconId) {
buildList();
return icons.get(iconId, R.drawable.ic99_blank);
}
public static int count() {
buildList();
return icons.size();
}
}

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