Compare commits

...

326 Commits

Author SHA1 Message Date
J-Jamet
88ac2ecf98 Merge branch 'release/2.5.0.0beta18' 2018-11-01 17:45:56 +01:00
J-Jamet
227cb078a5 Fix theme warning 2018-11-01 17:37:37 +01:00
J-Jamet
a17582bf6d Merge branch 'translations' into develop 2018-11-01 17:25:25 +01:00
J-Jamet
e8ba5dc6e2 Merge branch 'master' of https://hosted.weblate.org/projects/keepass-dx/strings into translations 2018-11-01 17:20:33 +01:00
J-Jamet
f37d3324e6 Upgrade app to version 18 2018-10-27 21:57:32 +02:00
J-Jamet
fcb06c8c22 Upgrade changelog 2018-10-27 21:42:00 +02:00
J-Jamet
d8bdf4500a Merge branch 'feature/Attachments' into develop 2018-10-27 21:38:57 +02:00
J-Jamet
69ea4d5414 Fix views 2018-10-27 20:46:17 +02:00
J-Jamet
7e9f99e5c8 Change the default icon pack 2018-10-27 20:30:31 +02:00
J-Jamet
95541d99c4 Replace a password sentence 2018-10-27 20:30:08 +02:00
J-Jamet
05ca7e6d69 Merge branch 'comradekingu-patch-2' into develop 2018-10-27 20:13:53 +02:00
J-Jamet
644a4a4886 Update strings 2018-10-27 20:13:15 +02:00
J-Jamet
7eb82ddbea Merge branch 'patch-2' of git://github.com/comradekingu/KeePassDX into comradekingu-patch-2 with corrections 2018-10-27 19:42:42 +02:00
J-Jamet
e721d4ca9e Fix keyboard clear and optimize views 2018-10-27 16:59:16 +02:00
J-Jamet
c72582b679 Update file selection view, title and Changelog 2018-10-27 16:30:36 +02:00
J-Jamet
217f0a82b5 Merge branch 'feature/Magikeyboard' into develop 2018-10-27 14:25:41 +02:00
J-Jamet
1efd172b42 Fix image 2018-10-27 14:17:59 +02:00
J-Jamet
e8d0d03ad9 Add keyboard Timeout 2018-10-27 13:56:08 +02:00
J-Jamet
6cb97de793 Remove keyboard sound and vibration duration settings 2018-10-20 12:57:26 +02:00
J-Jamet
77dbdc235a Add alpha channel to capture_keyboard images 2018-10-20 12:48:44 +02:00
J-Jamet
a9c87ea2b8 Add custom fields selection in keyboard 2018-10-13 16:10:45 +02:00
J-Jamet
232829526c Upgrade grdale 2018-10-13 10:52:04 +02:00
אלקנה בירדוגו
b5d8b2f14c Translated using Weblate (Hebrew)
Currently translated at 33.7% (110 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/he/
2018-09-27 15:31:03 +02:00
C. Rüdinger
c2673a627c Translated using Weblate (German)
Currently translated at 100.0% (326 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-09-24 15:27:48 +02:00
Tatiana Canales
bb49256188 Translated using Weblate (Spanish)
Currently translated at 66.5% (217 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/es/
2018-09-22 11:36:53 +02:00
Allan Nordhøy
1b6a284dd6 "Database name" 2018-09-21 02:42:26 +02:00
Allan Nordhøy
36b35b907e Requested changes implemented 2018-09-21 02:41:40 +02:00
Allan Nordhøy
f61b310ff2 Language rework 2
Transformation rounds
2018-09-19 03:39:04 +02:00
J-Jamet
c1e84b3bf1 Add popup view for custom fields 2018-09-18 21:27:36 +02:00
Pavel Borecki
9971d27ef3 Translated using Weblate (Czech)
Currently translated at 100.0% (326 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/cs/
2018-09-18 20:22:34 +02:00
J-Jamet
3c0835f725 Fix keyboard settings 2018-09-18 15:52:38 +02:00
J-Jamet
023aba2b60 Remove Magikeyboard and Model modules for easier integration 2018-09-18 11:46:37 +02:00
J-Jamet
abc0a14dda Update gradle 2018-09-18 10:14:15 +02:00
J-Jamet
dc23c6a445 Optimize memory pool and revert algo 2018-09-18 10:11:44 +02:00
J-Jamet
161a0ffc59 Change links 2018-09-17 22:38:48 +02:00
J-Jamet
b96436c906 Change small code 2018-09-16 11:40:22 +02:00
J-Jamet
cee7419208 Fix equals and hashcode for ProtectedBinary 2018-09-15 17:36:14 +02:00
J-Jamet
9ff6e7a080 Clear the cache to keep a small memory when the app is down 2018-09-15 17:22:42 +02:00
Lieven Blancke
9112a568d9 Translated using Weblate (Dutch)
Currently translated at 100.0% (326 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/nl/
2018-09-09 15:16:12 +02:00
Heimen Stoffels
8d0c9bc894 Translated using Weblate (Dutch)
Currently translated at 100.0% (326 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/nl/
2018-09-08 12:16:14 +02:00
RainSlide
e7b4e4501e Translated using Weblate (Chinese (Simplified))
Currently translated at 63.8% (208 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/zh_Hans/
2018-09-08 12:14:45 +02:00
J-Jamet
df80084822 Fix attachment recovery 2018-09-06 22:05:31 +02:00
Heimen Stoffels
4df2891b1a Translated using Weblate (Dutch)
Currently translated at 46.9% (153 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/nl/
2018-09-06 13:15:42 +02:00
J-Jamet
d0560677fa Temp commit 2018-09-05 22:02:24 +02:00
J-Jamet
9130a3851f Fix Out of memory for large attachment #115 2018-09-03 20:06:50 +02:00
J-Jamet
bb3fb26847 Update gradle 2018-09-03 12:00:57 +02:00
BO41
8406264138 Translated using Weblate (German)
Currently translated at 100.0% (326 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-08-29 15:30:49 +02:00
ButterflyOfFire
e51f48ebe0 Translated using Weblate (Arabic)
Currently translated at 41.4% (135 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/ar/
2018-08-29 10:34:27 +02:00
Daniel
a0a2aa4c5d Translated using Weblate (German)
Currently translated at 99.3% (324 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-08-24 12:38:48 +02:00
Claus Rüdinger
65cea7b5ec Translated using Weblate (German)
Currently translated at 99.3% (324 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-08-24 12:38:48 +02:00
WaldiS
fb589419de Translated using Weblate (Polish)
Currently translated at 100.0% (326 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/pl/
2018-08-23 18:50:11 +02:00
Allan Nordhøy
ae9844d5a1 Translated using Weblate (Norwegian Bokmål)
Currently translated at 90.1% (294 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/nb_NO/
2018-08-23 08:41:23 +02:00
J-Jamet
645ea21581 Remove warning_read_only 2018-08-23 00:24:18 +02:00
Allan Nordhøy
60fd675dff Translated using Weblate (Norwegian Bokmål)
Currently translated at 79.4% (259 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/nb_NO/
2018-08-22 05:41:35 +02:00
Allan Nordhøy
48903da446 Translated using Weblate (Danish)
Currently translated at 99.6% (325 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/da/
2018-08-22 04:36:29 +02:00
Claus Rüdinger
5399df134c Translated using Weblate (German)
Currently translated at 97.5% (318 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-08-21 21:37:54 +02:00
WaldiS
a858040ace Translated using Weblate (Polish)
Currently translated at 73.9% (241 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/pl/
2018-08-21 20:41:36 +02:00
Allan Nordhøy
d792b7d5ae Added translation using Weblate (Norwegian Bokmål) 2018-08-21 03:27:23 +02:00
Claus Rüdinger
8b3ed1a7dc Translated using Weblate (German)
Currently translated at 97.5% (318 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-08-19 01:38:34 +02:00
jan madsen
47004857ea Translated using Weblate (Danish)
Currently translated at 99.6% (325 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/da/
2018-08-16 18:35:31 +02:00
J-Jamet
82a6b8d7ef Merge branch 'master' into develop 2018-08-15 09:32:13 +02:00
J-Jamet
a30bcf1fa7 Merge branch 'mohammadnaseri-master' into develop 2018-08-15 09:30:55 +02:00
Hosted Weblate
febe978fa1 Merge branch 'origin/master' into Weblate 2018-08-15 09:28:48 +02:00
jan madsen
1eeefcf495 Translated using Weblate (Danish)
Currently translated at 96.6% (315 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/da/
2018-08-15 09:28:48 +02:00
Jérémy JAMET
ff6b0eee6c Merge pull request #167 from tuxayo/patch-1
CHANGELOG: Fix forgotten version bump
2018-08-15 09:28:33 +02:00
Claus Rüdinger
a7c8eaa937 Translated using Weblate (German)
Currently translated at 92.3% (301 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-08-14 23:37:23 +02:00
Telugu Speaker
55545e31e8 Translated using Weblate (Telugu)
Currently translated at 3.3% (11 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/te/
2018-08-14 04:44:56 +02:00
Tobirium
34132c6da7 Translated using Weblate (German)
Currently translated at 91,4% (298 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-08-13 22:53:31 +02:00
Claus Rüdinger
fbafa99a3b Translated using Weblate (German)
Currently translated at 91,4% (298 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-08-13 22:53:31 +02:00
random r
bd63805611 Translated using Weblate (Italian)
Currently translated at 100.0% (326 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/it/
2018-08-13 11:39:07 +02:00
lnxw
ae8398a434 Added translation using Weblate (Telugu) 2018-08-13 03:30:16 +02:00
عادل حسين المطهر
0b9318de88 Translated using Weblate (Arabic)
Currently translated at 37.4% (122 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/ar/
2018-08-12 16:37:49 +02:00
WaldiS
55e4bbf9db Translated using Weblate (Polish)
Currently translated at 53.3% (174 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/pl/
2018-08-11 19:42:59 +02:00
tuxayo
f33a572751 CHANGELOG: Fix forgotten version bump 2018-08-11 14:22:06 +02:00
K
2849cedbd8 Translated using Weblate (Latvian)
Currently translated at 34.6% (113 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/lv/
2018-08-11 09:40:28 +02:00
Mohammad Naseri
041d1b29d1 Passwords should be invisible to the accessibility services 2018-08-10 15:43:49 +02:00
K
cdcdc2fee1 Translated using Weblate (Latvian)
Currently translated at 34.0% (111 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/lv/
2018-08-09 18:39:53 +02:00
Tobirium
8e35d5bc8d Translated using Weblate (German)
Currently translated at 90.4% (295 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-08-08 18:38:37 +02:00
Daniel
f12e368707 Translated using Weblate (German)
Currently translated at 90.4% (295 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-08-08 18:38:36 +02:00
J-Jamet
f01895c7a7 Remove build version from app version (commit TAG = app name) 2018-08-08 12:35:15 +02:00
Aidar Gilmutdinov
4ce0c067e1 Translated using Weblate (Russian)
Currently translated at 100.0% (326 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/ru/
2018-08-07 22:41:35 +02:00
WaldiS
728a2cbfae Translated using Weblate (Polish)
Currently translated at 50.9% (166 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/pl/
2018-08-07 17:41:48 +02:00
Tiago A. Reul
a4aab3b933 Translated using Weblate (Portuguese (Brazil))
Currently translated at 73.6% (240 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/pt_BR/
2018-08-07 16:43:32 +02:00
Aidar Gilmutdinov
11ee0d6544 Translated using Weblate (Russian)
Currently translated at 100.0% (326 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/ru/
2018-08-06 21:52:24 +02:00
Allan Nordhøy
2b80dad47c Translated using Weblate (Norwegian Bokmål)
Currently translated at 2.1% (7 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/nb/
2018-08-06 19:41:56 +02:00
random r
7bb13ec1c2 Translated using Weblate (Italian)
Currently translated at 100,0% (326 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/it/
2018-08-06 11:19:27 +02:00
Ty Moss
344010d2bb Translated using Weblate (Norwegian Bokmål)
Currently translated at 2,1% (7 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/nb/
2018-08-05 18:42:40 +02:00
Ty Moss
ef37ecddc6 Added translation using Weblate (Norwegian Bokmål) 2018-08-05 18:05:54 +02:00
Kunzisoft
91a38e205e Translated using Weblate (French)
Currently translated at 100.0% (326 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/fr/
2018-08-04 11:38:13 +02:00
Kunzisoft
bd4de382e4 Translated using Weblate (English)
Currently translated at 100.0% (326 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/en/
2018-08-04 10:36:42 +02:00
random r
623244c3bd Translated using Weblate (Italian)
Currently translated at 99.6% (325 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/it/
2018-08-03 14:39:19 +02:00
Kunzisoft
7a06ff6dec Translated using Weblate (French)
Currently translated at 100.0% (326 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/fr/
2018-08-03 11:23:15 +02:00
random r
6d735e24ff Translated using Weblate (Italian)
Currently translated at 100,0% (326 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/it/
2018-08-02 14:23:10 +02:00
Hosted Weblate
5c30d544fa Merge branch 'origin/master' into Weblate 2018-08-02 13:11:19 +02:00
random r
54a3876288 Translated using Weblate (Italian)
Currently translated at 88.0% (287 of 326 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/it/
2018-08-02 13:11:19 +02:00
J-Jamet
57f71afb98 Fix font and upgrade version 2018-08-02 13:02:18 +02:00
J-Jamet
d8ec198f6f Fix null pointer 2018-08-02 11:58:15 +02:00
Hosted Weblate
faa6d7c9f6 Merge branch 'origin/master' into Weblate 2018-08-02 11:21:06 +02:00
Kunzisoft
d79a5b17a5 Translated using Weblate (French)
Currently translated at 100.0% (321 of 321 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/fr/
2018-08-02 11:21:05 +02:00
J-Jamet
34deea5d32 Merge tag '2.5.0.0beta16' into develop
2.5.0.0bet16
2018-08-02 11:19:58 +02:00
J-Jamet
edc7324c1d Merge branch 'release/2.5.0.0beta16' 2018-08-02 11:19:41 +02:00
J-Jamet
b9190e8254 Fix translations 2018-08-02 11:18:59 +02:00
J-Jamet
534878ae99 Merge branch 'translations' into develop 2018-08-02 11:04:39 +02:00
J-Jamet
99bfd21ecc Merge branch 'master' of https://hosted.weblate.org/projects/keepass-dx/strings into translations 2018-08-02 11:03:37 +02:00
J-Jamet
cb5c324c9d Fix search / Fix icon - back #138 / Upgrade changelogs 2018-08-02 10:34:04 +02:00
J-Jamet
55dc504f26 Fix visual elements 2018-08-01 15:45:49 +02:00
J-Jamet
ecb0138c90 Add display username settings and rearrange form filling 2018-08-01 12:00:15 +02:00
J-Jamet
0860eeb87f Show website domains if entries given no title #124 and add username 2018-07-31 22:04:41 +02:00
J-Jamet
f08bff61cf Update changelogs 2018-07-31 08:52:58 +02:00
J-Jamet
432aca6465 Fix transparent toolbar 2018-07-30 22:17:23 +02:00
J-Jamet
7cdb8db146 New error message #154 2018-07-30 21:10:11 +02:00
random r
6ba9dedcb8 Translated using Weblate (Italian)
Currently translated at 100,0% (321 of 321 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/it/
2018-07-30 11:59:13 +02:00
random r
6d603608f4 Translated using Weblate (Italian)
Currently translated at 99.3% (319 of 321 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/it/
2018-07-30 11:58:11 +02:00
Kunzisoft
64f4d9fb84 Translated using Weblate (French)
Currently translated at 99.6% (320 of 321 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/fr/
2018-07-29 14:37:40 +02:00
J-Jamet
60ccc450ae Fix read-only education screen 2018-07-29 09:44:01 +02:00
J-Jamet
ddb5f327a3 Add warning dialog on password copy button and sort settings 2018-07-28 18:00:57 +02:00
J-Jamet
df90ea42eb Deleting points in parameter explanations 2018-07-28 16:18:36 +02:00
Jérémy JAMET
a062d648b3 Merge pull request #158 from comradekingu/patch-1
Spelling: Language rework
2018-07-28 15:56:37 +02:00
J-Jamet
a59ae820b5 Add gray copy icon when copy not available 2018-07-28 15:18:34 +02:00
J-Jamet
228831acdd Upgrade version and add changelogs 2018-07-28 14:29:03 +02:00
J-Jamet
bf15ee43da Populate custom fields in search entry 2018-07-28 14:00:49 +02:00
J-Jamet
608f45677c Fix quick search with magikeyboard 2018-07-28 09:37:26 +02:00
Daniel
1cb15f214b Translated using Weblate (German)
Currently translated at 100.0% (321 of 321 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-07-28 00:37:41 +02:00
Claus Rüdinger
cd4a9e9b03 Translated using Weblate (German)
Currently translated at 100.0% (321 of 321 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-07-28 00:37:40 +02:00
J-Jamet
d6eae56d4f Merge branch 'feature/Search' into develop #26 #147 #153 2018-07-27 22:19:43 +02:00
J-Jamet
b5a87a63dc Fix search fragment 2018-07-27 21:39:26 +02:00
Allan Nordhøy
1eb17c4f34 Language rework 2018-07-27 15:11:56 +02:00
Hadrián Candela
8a6ce1f711 Translated using Weblate (Galician)
Currently translated at 7.4% (24 of 321 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/gl/
2018-07-27 13:38:02 +02:00
J-Jamet
0f22f8af45 Add search title 2018-07-27 10:54:58 +02:00
Tobirium
b2e81e6fd9 Translated using Weblate (German)
Currently translated at 100,0% (321 of 321 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-07-26 23:52:55 +02:00
Daniel
f82eab942d Translated using Weblate (German)
Currently translated at 100,0% (321 of 321 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-07-26 23:52:55 +02:00
J-Jamet
aa29aec40f Add search suggestions 2018-07-26 14:08:48 +02:00
Hadrián Candela
181def52ab Added translation using Weblate (Galician) 2018-07-26 13:01:37 +02:00
HybridGlucose
96d2bd63cc Translated using Weblate (Chinese (Traditional))
Currently translated at 44.5% (143 of 321 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/zh_Hant/
2018-07-25 20:36:13 +02:00
Claus Rüdinger
194021a957 Translated using Weblate (German)
Currently translated at 100,0% (321 of 321 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-07-25 18:38:46 +02:00
Daniel
9e307f94ea Translated using Weblate (German)
Currently translated at 100,0% (321 of 321 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-07-25 18:38:45 +02:00
Tobirium
155b2de138 Translated using Weblate (German)
Currently translated at 100,0% (321 of 321 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-07-25 18:38:45 +02:00
J-Jamet
c76c3fd2be Fix fragment duplication 2018-07-25 11:50:18 +02:00
Matheus Gritz
01c5554944 Translated using Weblate (Portuguese (Brazil))
Currently translated at 100.0% (321 of 321 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/pt_BR/
2018-07-24 19:11:13 +02:00
J-Jamet
542cf65b41 Fix timeout and new animation 2018-07-24 18:32:19 +02:00
J-Jamet
f037561a67 Search in fragment 2018-07-24 18:02:08 +02:00
J-Jamet
379263a6d3 Search and Group in one activity 2018-07-24 14:48:03 +02:00
J-Jamet
c420ca01f6 Update Readme 2018-07-23 14:21:46 +02:00
J-Jamet
a1f9db6eee Try to solve the date crash 2018-07-23 14:12:07 +02:00
J-Jamet
c9212174c4 Change text by reset 2018-07-22 12:13:02 +02:00
J-Jamet
0065336377 Merge tag '2.5.0.0beta15' into develop
2.5.0.0beta15
2018-07-19 11:27:47 +02:00
J-Jamet
4f9625a3e1 Merge branch 'release/2.5.0.0beta15' 2018-07-19 11:27:18 +02:00
J-Jamet
7688ebd29b Merge branch 'master' of https://hosted.weblate.org/projects/keepass-dx/strings into translations 2018-07-19 11:15:53 +02:00
Claus Rüdinger
3f2a7f1eb3 Translated using Weblate (German)
Currently translated at 99.3% (313 of 315 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-07-19 11:08:28 +02:00
Veronica Small
b3d067d0c8 Translated using Weblate (Chinese (Simplified))
Currently translated at 41.9% (132 of 315 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/zh_Hans/
2018-07-19 11:08:28 +02:00
Kunzisoft
a3b4ad5ac1 Translated using Weblate (French)
Currently translated at 100.0% (315 of 315 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/fr/
2018-07-19 11:08:28 +02:00
J-Jamet
e3b329d27f Update version and changelog 2018-07-19 11:01:32 +02:00
J-Jamet
7d10c43822 Fix orientation change 2018-07-19 10:40:36 +02:00
J-Jamet
fcb0d45d39 Fix Magikeyboard string 2018-07-19 08:58:20 +02:00
J-Jamet
5492db0223 Merge branch 'feature/ReadOnlyMode' into develop 2018-07-18 18:51:51 +02:00
J-Jamet
2207b05f5f Fix PwDate 2018-07-18 18:12:43 +02:00
J-Jamet
f15a0c2591 Optimize memory 2018-07-18 17:56:32 +02:00
J-Jamet
92fb22129c #77 Add read-only mode to the floating menu 2018-07-18 16:29:18 +02:00
J-Jamet
ccca9c4400 #77 Add read-only mode 2018-07-18 14:37:39 +02:00
J-Jamet
0597cb4416 #148 fix second element to copy 2018-07-16 22:02:24 +02:00
J-Jamet
0602174e50 Merge tag '2.5.0.0beta14' into develop
2.5.0.0beta14
2018-07-15 10:59:01 +02:00
J-Jamet
6fddc92ce7 Merge branch 'release/2.5.0.0beta14' 2018-07-15 10:58:48 +02:00
J-Jamet
aa30df6454 Update version / changelogs 2018-07-15 10:49:45 +02:00
J-Jamet
f6c61ab407 Show error message when sort can't be done 2018-07-15 10:33:54 +02:00
J-Jamet
2ab81ed77c Add parcelables 2018-07-15 10:24:30 +02:00
J-Jamet
0ade035f43 Catch construct element exception 2018-07-14 18:11:20 +02:00
J-Jamet
73b62035d8 Fix MagikIME nullpointer 2018-07-14 16:07:38 +02:00
J-Jamet
28837db308 Fix search and search for keyboard 2018-07-14 14:42:51 +02:00
J-Jamet
85befef260 Merge tag '2.5.0.0beta13' into develop
2.5.0.0beta13
2018-07-14 11:11:49 +02:00
J-Jamet
e7bbb47422 Merge branch 'release/2.5.0.0beta13' 2018-07-14 11:11:36 +02:00
J-Jamet
846bc7edb1 Update Changelogs 2018-07-14 11:01:34 +02:00
J-Jamet
99a9842a1f Fix null pointer on nodeButtonView 2018-07-14 10:47:52 +02:00
J-Jamet
33009138c3 Update version and fix memory crash 2018-07-14 10:23:04 +02:00
J-Jamet
c74b82ebd8 Fix changelogs 2018-07-13 17:06:20 +02:00
J-Jamet
49ea92a4a5 WebDav - Merge branch 'translations' into develop 2018-07-13 14:50:25 +02:00
David Ramiro
6cc4eeaa30 Translated using Weblate (German)
Currently translated at 100,0% (296 of 296 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-07-13 13:53:21 +02:00
David Ramiro
1b89f79888 Translated using Weblate (German)
Currently translated at 100,0% (296 of 296 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/de/
2018-07-13 13:53:21 +02:00
Ale-Ma
07d99de3ea Translated using Weblate (Italian)
Currently translated at 51.6% (153 of 296 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/it/
2018-07-13 13:53:21 +02:00
piegope
ae757affa1 Translated using Weblate (Spanish)
Currently translated at 100.0% (296 of 296 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/es/
2018-07-13 13:53:21 +02:00
Max
482b6296fc Translated using Weblate (Russian)
Currently translated at 57.0% (169 of 296 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/ru/
2018-07-13 13:53:21 +02:00
piegope
d37ce729f0 Translated using Weblate (Español (España))
Currently translated at 100,0% (296 of 296 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/es/
2018-07-13 13:53:21 +02:00
ButterflyOfFire
e92ce232bc Translated using Weblate (Arabic)
Currently translated at 35.1% (104 of 296 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/ar/
2018-07-13 13:53:21 +02:00
piegope
78ae44b160 Translated using Weblate (Spanish)
Currently translated at 87.5% (259 of 296 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/es/
2018-07-13 13:53:21 +02:00
Ale-Ma
49ce87a8e0 Translated using Weblate (Italian)
Currently translated at 51.3% (152 of 296 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/it/
2018-07-13 13:53:21 +02:00
ButterflyOfFire
d2fe5ce884 Translated using Weblate (Arabic)
Currently translated at 34.7% (103 of 296 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/ar/
2018-07-13 13:53:21 +02:00
ButterflyOfFire
5e695756de Added translation using Weblate (Arabe) 2018-07-13 13:53:21 +02:00
Max
0506a75417 Translated using Weblate (Russian)
Currently translated at 57.0% (169 of 296 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/ru/
2018-07-13 13:53:21 +02:00
dienteperro
34e1316144 Translated using Weblate (Spanish)
Currently translated at 57.0% (169 of 296 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/es/
2018-07-13 13:53:21 +02:00
Kunzisoft
18dffa6c75 Translated using Weblate (English)
Currently translated at 100.0% (296 of 296 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/en/
2018-07-13 13:53:21 +02:00
Kunzisoft
03621c378e Translated using Weblate (French)
Currently translated at 100.0% (296 of 296 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/fr/
2018-07-13 13:53:21 +02:00
Kunzisoft
aff9312419 Translated using Weblate (French)
Currently translated at 100.0% (296 of 296 strings)

Translation: KeePass DX/Strings
Translate-URL: https://hosted.weblate.org/projects/keepass-dx/strings/fr/
2018-07-13 13:53:21 +02:00
J-Jamet
4651b1be96 Icons depends now of setting of list items #97 2018-07-13 11:25:02 +02:00
J-Jamet
32497a22d2 Add dialog with a warning to copy, add the setting to copy the protected custom fields #139 2018-07-12 21:53:05 +02:00
J-Jamet
3b5ef56c16 Fix clean clipboard in notification 2018-07-11 18:26:49 +02:00
J-Jamet
d4cc3a58d8 Remove copy menu for group 2018-07-11 12:24:37 +02:00
J-Jamet
afedbb38b2 Merge remote-tracking branch 'origin/develop' into develop 2018-07-11 12:15:26 +02:00
J-Jamet
fe70bf3877 Fix database creation workflow 2018-07-11 12:15:04 +02:00
J-Jamet
f14ee6cf1c Update changelogs 2018-07-10 14:45:56 +02:00
J-Jamet
1791b15f85 Update gradle and remove compatibility mode for FingerPrintManager 2018-07-10 11:24:00 +02:00
J-Jamet
6c5b3b3a0d Fix german translation 2018-07-10 11:24:00 +02:00
J-Jamet
6ea2287679 Update German translation - Merge branch 'davidramiro-develop' into develop 2018-07-09 14:49:32 +02:00
David Ramiro
cad4ec22b4 Update German translation 2018-07-08 22:10:28 +02:00
J-Jamet
f277983caf Merge branch 'develop' of https://github.com/Kunzisoft/KeePassDX into develop 2018-07-06 08:54:14 +02:00
J-Jamet
5e561e5321 Update descriptions 2018-07-06 08:53:54 +02:00
J-Jamet
ef83dbcae2 Fix errors highlight by @gaul fb715950a7 2018-07-04 13:19:06 +02:00
J-Jamet
ab6c69adcb Standardize the slide animation 2018-07-04 12:59:32 +02:00
J-Jamet
1c90747476 Add setting to disable education screens 2018-07-02 11:25:59 +02:00
J-Jamet
c3b3d8482c Update changelog 2018-07-01 21:53:40 +02:00
J-Jamet
86b4d92599 Change DbHeaderV4 number 2018-07-01 21:53:25 +02:00
J-Jamet
1f6786b1f8 Fix null pointer for enableButtonOncheckedChangeListener 2018-07-01 12:50:59 +02:00
J-Jamet
4cd2b153f4 Fix broadcast unregister receiver 2018-07-01 11:54:46 +02:00
J-Jamet
27b0810688 Merge branch 'feature/Magikeyboard' into develop 2018-06-30 16:10:08 +02:00
J-Jamet
94c72a4cf6 Remove Jelly Bean condition 2018-06-30 16:04:03 +02:00
J-Jamet
e634116e71 Fix bugs for Kitkat device 2018-06-30 15:22:16 +02:00
J-Jamet
9021cb5bc8 Add TODO, dev dialog and fix icon bug 2018-06-29 19:02:31 +02:00
J-Jamet
3674900a54 Add receiver to lock the entry in the keyboard 2018-06-29 17:59:58 +02:00
J-Jamet
9855ae79c3 Add keyboard notification 2018-06-29 16:56:13 +02:00
J-Jamet
fe1a4985f1 Add settings bones 2018-06-26 00:25:09 +02:00
J-Jamet
015a368a1d Add keyboard explanation 2018-06-25 17:00:57 +02:00
J-Jamet
07f59e071d Upgrade changelogs 2018-06-25 11:37:06 +02:00
J-Jamet
670e2bfe33 Refining activity animations 2018-06-25 11:25:28 +02:00
J-Jamet
992b6382a3 Fix disabled button 2018-06-25 11:00:50 +02:00
J-Jamet
c3ac550c93 Add setting to disable the open button #126 2018-06-25 10:42:19 +02:00
J-Jamet
acba7fc5de New adaptive icon 2018-06-24 21:22:36 +02:00
J-Jamet
ccb500fdf4 Fix search with Autofill service #130 2018-06-23 11:40:33 +02:00
J-Jamet
44111507e7 Change style of keyboard 2018-06-22 18:27:07 +02:00
J-Jamet
5f14596ed2 Assign entry elements to keys 2018-06-10 21:51:09 +02:00
J-Jamet
4ad65c8f4a Retrieve entry selected in keyboard 2018-06-10 14:03:34 +02:00
J-Jamet
b4b215fe30 Lock since keyboard and refactor 2018-06-08 17:59:18 +02:00
J-Jamet
d8a8005d70 Merge branch 'develop' into feature/Magikeyboard 2018-06-06 19:23:48 +02:00
J-Jamet
37ca15b77c Refactor lock 2018-06-06 19:11:20 +02:00
J-Jamet
6c18fe5591 Fix the spelling error 2018-06-05 19:24:26 +02:00
J-Jamet
fdcb05467c First commit to add Magikeyboard 2018-06-03 16:33:59 +02:00
J-Jamet
ef8db46ae7 Update changelogs 2018-05-31 18:26:03 +02:00
J-Jamet
14f56c77e8 Merge branch 'feature/IconsVector' into develop 2018-05-31 17:37:45 +02:00
J-Jamet
44e21084e4 Change material icons as XML 2018-05-31 17:37:08 +02:00
J-Jamet
b7f1275789 Fix globe icon #125 2018-05-31 15:24:09 +02:00
J-Jamet
b1be05db4d Set folder icon by default for a new group #122 2018-05-31 13:21:38 +02:00
J-Jamet
09c776fd7e Remove "Rounds fix" setting no more used 2018-05-31 11:53:45 +02:00
J-Jamet
e8a24790a5 Upgrade version and changelogs 2018-05-30 11:51:28 +02:00
J-Jamet
8b3be79266 Merge branch 'feature/ListNodesFragment' into develop 2018-05-30 11:16:13 +02:00
J-Jamet
e5f0572c1c Change node menu as XML 2018-05-30 10:03:38 +02:00
J-Jamet
68df3bc6c3 Set messages in threads 2018-05-29 23:04:43 +02:00
J-Jamet
a3da960c26 Fix toolbar paste action and colors 2018-05-29 22:27:38 +02:00
J-Jamet
d9490f9840 Refactor runnable action 2018-05-29 19:58:27 +02:00
J-Jamet
3b24f9d821 Merge branch 'feature/NodeMenu' into feature/ListNodesFragment 2018-05-29 12:18:09 +02:00
J-Jamet
bf35897e92 Add toolbar paste and animations for activities 2018-05-29 12:09:08 +02:00
J-Jamet
977705b42d Fix group title 2018-05-28 20:12:09 +02:00
J-Jamet
459bc40515 Add Move for Entries and Groups 2018-05-28 19:53:45 +02:00
J-Jamet
eb8ca9355c Merge branch 'feature/ListNodesFragment' into feature/NodeMenu 2018-05-28 18:10:06 +02:00
J-Jamet
31f7b0d5be Fix timeout for fragment 2018-05-28 17:54:38 +02:00
J-Jamet
7c54946c4b Fix fragment - Merge branch 'feature/ListNodesFragment' into feature/NodeMenu 2018-05-25 22:09:35 +02:00
J-Jamet
5aaf2c222a Fix fragment during orientation change 2018-05-25 21:52:09 +02:00
J-Jamet
9424feefce Add contextual bar to paste and add move entry 2018-05-24 19:51:28 +02:00
Jérémy JAMET
a3917ccab6 Add translation link in Readme.md 2018-05-24 14:48:28 +02:00
J-Jamet
5286a60142 Group activity with fragment for navigation 2018-05-24 00:11:46 +02:00
J-Jamet
d4459de49b Rename string clipboard cleared 2018-05-23 12:25:08 +02:00
J-Jamet
05dba6668c Change about description string key 2018-05-23 10:25:50 +02:00
J-Jamet
c15a1c6eaa Refactor KDF Engine for v3 2018-05-22 15:22:04 +02:00
J-Jamet
fe8c962f73 Better KDF Exception management 2018-05-22 12:52:12 +02:00
J-Jamet
4192cf2403 Add FAQ store time 2018-05-18 11:02:02 +02:00
J-Jamet
1817f1aa9e Fix extended ASCII in default setting 2018-05-18 09:09:07 +02:00
J-Jamet
afacf352ed Merge branch 'develop' of https://github.com/Kunzisoft/KeePassDX into develop 2018-05-15 15:43:30 +02:00
J-Jamet
d3ebbba2a1 Remove compat methods 2018-05-15 15:43:03 +02:00
J-Jamet
460edf1745 Merge branch 'develop' of https://github.com/Kunzisoft/KeePassDX into develop 2018-05-13 22:22:21 +02:00
J-Jamet
dacb19d412 Add Gimp source for store screens 2018-05-13 22:21:28 +02:00
Jérémy JAMET
fe8158db85 Update FAQ.md 2018-05-13 20:13:24 +02:00
Jérémy JAMET
a36e4fbcd0 Update FAQ link 2018-05-13 20:11:32 +02:00
J-Jamet
9442c7ef07 Merge tag '2.5.0.0beta11' into develop 2018-05-13 18:23:52 +02:00
J-Jamet
d4a0b59eb1 Merge branch 'release/2.5.0.0beta11' 2018-05-13 18:23:37 +02:00
J-Jamet
07600949ab Upgrade version and fix potential null pointer for kdf 2018-05-13 18:14:25 +02:00
J-Jamet
7efaad1818 Fix database creation issue 2018-05-13 17:54:35 +02:00
J-Jamet
e32b0d1c25 Merge tag '2.5.0.0beta10' into develop 2018-05-13 17:05:32 +02:00
J-Jamet
0fdcc29aa2 Merge branch 'release/2.5.0.0beta10' 2018-05-13 17:05:10 +02:00
J-Jamet
37bedbffc9 Fix italian translation for compilation 2018-05-13 16:59:35 +02:00
J-Jamet
46505150c4 New Red Volcano theme and change visual feature message for version libre 2018-05-13 16:47:59 +02:00
J-Jamet
e18c5c90cc Upgrade changelogs 2018-05-13 14:52:59 +02:00
J-Jamet
1f5649d9d2 Merge branch 'feature/ChangeAlgorithms' into develop #9 #29 2018-05-13 14:25:31 +02:00
J-Jamet
7bbd55a9fd Add binary to memory explanation 2018-05-13 14:17:19 +02:00
J-Jamet
92eeccf84e Fix algorithm and kdf function for database V3 and add small trad 2018-05-13 13:55:37 +02:00
J-Jamet
7bcc289518 Upgrade explanations 2018-05-13 13:02:09 +02:00
J-Jamet
507f758c0d Add memory usage and parallelism for Argon2 settings 2018-05-12 23:53:41 +02:00
J-Jamet
6afffb7245 Register UUID of database version in KDF parameter 2018-05-11 19:19:16 +02:00
J-Jamet
c62f4ae0b3 Text if choose only one extension #105 2018-05-11 13:25:33 +02:00
J-Jamet
ee80c614e0 Fix layer error for icon free #113 2018-05-11 12:44:33 +02:00
J-Jamet
fea7af6910 Dynamic creation of KdfEngine, reorganise code 2018-05-09 15:17:55 +02:00
J-Jamet
c72aa0e97d Merge branch 'develop' into feature/ChangeAlgorithms to Fix NDK 2018-05-09 12:01:16 +02:00
J-Jamet
3dd60b5392 Fix ndk filters 2018-05-09 10:59:48 +02:00
J-Jamet
a357267552 #107 Set master password in landscape 2018-05-07 10:47:00 +02:00
J-Jamet
1badeb2eef Change FAQ as markdown and add descriptions 2018-05-07 10:34:27 +02:00
Yhaulez
0bb8d2a417 Create FAQ 2018-05-06 16:26:19 +02:00
J-Jamet
4a215db83c Change toolbar style and password layout 2018-05-05 23:16:39 +02:00
J-Jamet
512e55a170 Fix fingerprint animation and for first init 2018-05-05 20:39:01 +02:00
J-Jamet
1ebe8dc022 Update fingerprint state with checkbox 2018-05-04 21:24:57 +02:00
J-Jamet
cafeabdbc3 Fix search styles 2018-05-02 21:31:04 +02:00
J-Jamet
b342b26409 Update readme 2018-05-02 20:59:05 +02:00
J-Jamet
938c3a07af Fix wait dialog callback 2018-05-02 20:52:16 +02:00
J-Jamet
16288f98f7 Merge branch 'develop' into feature/ChangeAlgorithms 2018-05-02 15:57:47 +02:00
J-Jamet
a932156e85 Remove unused progressbar 2018-05-02 15:26:24 +02:00
J-Jamet
64e9b9fb6d Fix lock orientation change 2018-05-02 14:02:10 +02:00
J-Jamet
7af28550da Merge branch 'feature/RefactorProgress' into develop #98 2018-05-02 13:49:56 +02:00
J-Jamet
60e2d786dd Change progress dialog title, and remove code 2018-05-02 13:49:03 +02:00
J-Jamet
ec08f3430d Add progress bar for all, create database in a single progress dialog 2018-05-02 09:54:55 +02:00
J-Jamet
a50aa0fb95 Fix null pointer for KeyDerivationName 2018-05-02 07:16:55 +02:00
J-Jamet
cf026e8eaa Update progress bar and message progress 2018-05-01 20:03:43 +02:00
J-Jamet
77614d0c4a Upgrade changelogs and version 2018-04-30 19:54:50 +02:00
J-Jamet
e8d71039d7 refactor 2018-04-30 18:18:13 +02:00
J-Jamet
4164b5bd37 Fix crash by locking activity position 2018-04-30 17:47:31 +02:00
J-Jamet
3c66ec82b5 Upgrade French 2018-04-30 17:00:42 +02:00
J-Jamet
b796c16877 Upgrade Italian 2018-04-30 16:57:10 +02:00
J-Jamet
42d34d8f0c Add material icon pack in free version and change texts 2018-04-30 16:10:18 +02:00
J-Jamet
5fbb37df82 Fix german fingerprint error 2018-04-29 14:07:56 +02:00
J-Jamet
52e12d7cbd Upgrade russian translation 2018-04-28 22:34:25 +02:00
J-Jamet
5cf5719e8e Fix education text color 2018-04-28 20:08:33 +02:00
J-Jamet
af3a80143e Fix crash by return blank when Resources$NotFoundException 2018-04-28 19:49:59 +02:00
J-Jamet
90db27c3fe Refactor Master key functions 2018-04-28 18:15:30 +02:00
J-Jamet
3d584b76f7 Choose kdf and encapsulate code 2018-04-28 15:58:04 +02:00
J-Jamet
fbf3dec421 Assign algorithm dynamically 2018-04-28 12:20:18 +02:00
J-Jamet
1d36683128 Remove screens in Readme 2018-04-28 11:11:50 +02:00
J-Jamet
cefc546c0a Upgrade german translation 2018-04-28 11:08:23 +02:00
J-Jamet
7aeb51813c Show algorithm dialog 2018-04-26 23:00:15 +02:00
J-Jamet
d6fc29ec79 Creation of classes and prepare assignment for algorithms 2018-04-26 22:00:11 +02:00
J-Jamet
9af182e0c3 Change dark style 2018-04-26 16:14:22 +02:00
J-Jamet
c7120b997f Fix contribution issue for KeePass DX Pro 2018-04-26 14:39:45 +02:00
J-Jamet
e61571fcec Upgrade fastlane 2018-04-26 12:18:14 +02:00
J-Jamet
9a900b32b2 Merge tag '2.5.0.0beta9' into develop
2.5.0.0beta9
2018-04-25 13:16:14 +02:00
862 changed files with 17726 additions and 6241 deletions

1
.gitignore vendored
View File

@@ -71,6 +71,7 @@ app/app.iml
# Art # Art
art/screen*.png art/screen*.png
art/logo_512.png art/logo_512.png
art/store_screens/
# Dir linux # Dir linux
.directory .directory

View File

@@ -1,3 +1,60 @@
KeepassDX (2.5.0.0beta18)
* New recent databases views
* New information dialog
* Custom fields for the Magikeyboard
* Timeout for the Magikeyboard
* Long press for keyboard selection
* Fix memory when opening the database
* Memory management for attachments
KeepassDX (2.5.0.0beta17)
* Fix font and search
KeepassDX (2.5.0.0beta16)
* New search in a single fragment
* Search suggestions
* Added the display of usernames
* Added translations
* Fix read-only mode
* Fix parcelable / toolbar / back
KeepassDX (2.5.0.0beta15)
* Read only mode
* Best group recovery for the navigation fragment
* Fix copies in notifications
* Fix orientation
* Added translations
KeepassDX (2.5.0.0beta14)
* Optimize all the memory with parcelables / fix search
KeepassDX (2.5.0.0beta13)
* Fix memory issue with parcelable (crash in beta12 version)
KeepassDX (2.5.0.0beta12)
* Added the Magikeyboard to fill the forms (settings still in development)
* Added move and copy for groups and entries
* New navigation in a single screen / new animations between activities
* New icons for the material pack / vectorization
* New adaptive launcher icon
* Icons depends now of setting of list items
* Added a setting to disable the open button when no password is identified
* Added a setting to disable the education screens
* Added a setting to disable the copy of protected custom fields
* Fix the fingerprint recognition (WARNING : The keystore is reinit, you must delete the old keys)
* Fix small bugs
KeepassDX (2.5.0.0beta11)
* Fix crash in beta10 version
KeepassDX (2.5.0.0beta10)
* Dynamically change Algorithm and Key Derivation Function in settings
* Upgrade translations
* New red volcano theme, fix classic dark theme
* Add Material Icon Pack to the Free version
* Update fingerprint state with checkbox
* Fix bugs
KeepassDX (2.5.0.0beta9) KeepassDX (2.5.0.0beta9)
* Education Screens to learn how to use the app * Education Screens to learn how to use the app
* New designs * New designs

View File

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

View File

@@ -2,24 +2,19 @@ apply plugin: 'com.android.application'
android { android {
compileSdkVersion 27 compileSdkVersion 27
buildToolsVersion '27.0.3' buildToolsVersion '28.0.2'
defaultConfig { defaultConfig {
applicationId "com.kunzisoft.keepass" applicationId "com.kunzisoft.keepass"
minSdkVersion 14 minSdkVersion 14
targetSdkVersion 27 targetSdkVersion 27
versionCode = 9 versionCode = 18
versionName = "2.5.0.0beta9" versionName = "2.5.0.0beta18"
multiDexEnabled true multiDexEnabled true
testApplicationId = "com.kunzisoft.keepass.tests" testApplicationId = "com.kunzisoft.keepass.tests"
testInstrumentationRunner = "android.test.InstrumentationTestRunner" testInstrumentationRunner = "android.test.InstrumentationTestRunner"
ndk {
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a',
'arm64-v8a', 'mips', 'mips64'
}
buildConfigField "String[]", "ICON_PACKS", "{\"classic\",\"material\"}" buildConfigField "String[]", "ICON_PACKS", "{\"classic\",\"material\"}"
} }
@@ -44,16 +39,16 @@ android {
productFlavors { productFlavors {
libre { libre {
applicationIdSuffix = ".libre" applicationIdSuffix = ".libre"
versionNameSuffix "-libre" buildConfigField "String", "BUILD_VERSION", "\"libre\""
buildConfigField "boolean", "FULL_VERSION", "true" buildConfigField "boolean", "FULL_VERSION", "true"
buildConfigField "boolean", "CLOSED_STORE", "false" buildConfigField "boolean", "CLOSED_STORE", "false"
buildConfigField "String[]", "STYLES_DISABLED", "{\"KeepassDXStyle_Dark\",\"KeepassDXStyle_Purple\"}" buildConfigField "String[]", "STYLES_DISABLED", "{\"KeepassDXStyle_Dark\",\"KeepassDXStyle_Red\",\"KeepassDXStyle_Purple\"}"
buildConfigField "String[]", "ICON_PACKS_DISABLED", "{}" buildConfigField "String[]", "ICON_PACKS_DISABLED", "{}"
} }
pro { pro {
applicationIdSuffix = ".pro" applicationIdSuffix = ".pro"
versionNameSuffix "-pro" buildConfigField "String", "BUILD_VERSION", "\"pro\""
buildConfigField "boolean", "FULL_VERSION", "true" buildConfigField "boolean", "FULL_VERSION", "true"
buildConfigField "boolean", "CLOSED_STORE", "true" buildConfigField "boolean", "CLOSED_STORE", "true"
buildConfigField "String[]", "STYLES_DISABLED", "{}" buildConfigField "String[]", "STYLES_DISABLED", "{}"
@@ -61,11 +56,11 @@ android {
} }
free { free {
applicationIdSuffix = ".free" applicationIdSuffix = ".free"
versionNameSuffix "-free" buildConfigField "String", "BUILD_VERSION", "\"free\""
buildConfigField "boolean", "FULL_VERSION", "false" buildConfigField "boolean", "FULL_VERSION", "false"
buildConfigField "boolean", "CLOSED_STORE", "true" buildConfigField "boolean", "CLOSED_STORE", "true"
buildConfigField "String[]", "STYLES_DISABLED", "{\"KeepassDXStyle_Dark\",\"KeepassDXStyle_Blue\",\"KeepassDXStyle_Purple\"}" buildConfigField "String[]", "STYLES_DISABLED", "{\"KeepassDXStyle_Dark\",\"KeepassDXStyle_Blue\",\"KeepassDXStyle_Red\",\"KeepassDXStyle_Purple\"}"
buildConfigField "String[]", "ICON_PACKS_DISABLED", "{\"material\"}" buildConfigField "String[]", "ICON_PACKS_DISABLED", "{}"
} }
} }
@@ -99,7 +94,7 @@ dependencies {
implementation 'joda-time:joda-time:2.9.9' implementation 'joda-time:joda-time:2.9.9'
implementation 'org.sufficientlysecure:html-textview:3.5' implementation 'org.sufficientlysecure:html-textview:3.5'
implementation 'com.nononsenseapps:filepicker:4.1.0' implementation 'com.nononsenseapps:filepicker:4.1.0'
implementation 'com.getkeepsafe.taptargetview:taptargetview:1.11.0' implementation 'com.getkeepsafe.taptargetview:taptargetview:1.12.0'
// Permissions // 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 // if you don't use android.app.Fragment you can exclude support for them
@@ -108,11 +103,14 @@ dependencies {
annotationProcessor "com.github.hotchemi:permissionsdispatcher-processor:$permissionDispatcherVersion" annotationProcessor "com.github.hotchemi:permissionsdispatcher-processor:$permissionDispatcherVersion"
// Apache Commons Collections // Apache Commons Collections
implementation 'commons-collections:commons-collections:3.2.1' implementation 'commons-collections:commons-collections:3.2.1'
implementation 'org.apache.commons:commons-io:1.3.2'
// Base64 // Base64
implementation 'biz.source_code:base64coder:2010-12-19' implementation 'biz.source_code:base64coder:2010-12-19'
implementation 'com.google.code.gson:gson:2.8.1' // IO-Extras
implementation 'com.github.davidmoten:io-extras:0.1'
implementation 'com.google.code.gson:gson:2.8.4'
implementation 'com.google.guava:guava:23.0-android' implementation 'com.google.guava:guava:23.0-android'
// Icon pack, classic for all, material for libre and pro // Icon pack
implementation project(path: ':icon-pack-classic') implementation project(path: ':icon-pack-classic')
implementation project(path: ':icon-pack-material') implementation project(path: ':icon-pack-material')
} }

View File

@@ -45,10 +45,10 @@ public class PwEntryTestV4 extends TestCase {
entry.setBackgroupColor("blue"); entry.setBackgroupColor("blue");
entry.putProtectedBinary("key1", new ProtectedBinary(false, new byte[] {0,1})); entry.putProtectedBinary("key1", new ProtectedBinary(false, new byte[] {0,1}));
entry.setCustomIcon(new PwIconCustom(UUID.randomUUID(), new byte[0])); entry.setIconCustom(new PwIconCustom(UUID.randomUUID(), new byte[0]));
entry.setForegroundColor("red"); entry.setForegroundColor("red");
entry.addToHistory(new PwEntryV4()); entry.addToHistory(new PwEntryV4());
entry.setIcon(new PwIconStandard(5)); entry.setIconStandard(new PwIconStandard(5));
entry.setOverrideURL("override"); entry.setOverrideURL("override");
entry.setParent(new PwGroupV4()); entry.setParent(new PwGroupV4());
entry.addExtraField("key2", new ProtectedString(false, "value2")); entry.addExtraField("key2", new ProtectedString(false, "value2"));

View File

@@ -19,8 +19,6 @@
*/ */
package com.kunzisoft.keepass.tests.database; package com.kunzisoft.keepass.tests.database;
import java.util.List;
import android.content.Context; import android.content.Context;
import android.test.AndroidTestCase; import android.test.AndroidTestCase;
@@ -30,8 +28,10 @@ import com.kunzisoft.keepass.database.PwDatabaseV3;
import com.kunzisoft.keepass.database.PwEntry; import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.PwEntryV3; import com.kunzisoft.keepass.database.PwEntryV3;
import com.kunzisoft.keepass.database.PwGroup; import com.kunzisoft.keepass.database.PwGroup;
import com.kunzisoft.keepass.database.edit.DeleteGroup; import com.kunzisoft.keepass.database.action.node.DeleteGroupRunnable;
import com.kunzisoft.keepass.search.SearchDbHelper; import com.kunzisoft.keepass.database.search.SearchDbHelper;
import java.util.List;
public class DeleteEntry extends AndroidTestCase { public class DeleteEntry extends AndroidTestCase {
private static final String GROUP1_NAME = "Group1"; private static final String GROUP1_NAME = "Group1";
@@ -60,7 +60,7 @@ public class DeleteEntry extends AndroidTestCase {
assertNotNull("Could not find group1", group1); assertNotNull("Could not find group1", group1);
// Delete the group // Delete the group
DeleteGroup task = new DeleteGroup(null, db, group1, null, true); DeleteGroupRunnable task = new DeleteGroupRunnable(null, db, group1, null, true);
task.run(); task.run();
// Verify the entries were deleted // Verify the entries were deleted
@@ -72,8 +72,8 @@ public class DeleteEntry extends AndroidTestCase {
// Verify the entries were removed from the search index // Verify the entries were removed from the search index
SearchDbHelper dbHelp = new SearchDbHelper(ctx); SearchDbHelper dbHelp = new SearchDbHelper(ctx);
PwGroup results1 = dbHelp.search(db.getPwDatabase(), ENTRY1_NAME); PwGroup results1 = dbHelp.search(db.getPwDatabase(), ENTRY1_NAME, 100);
PwGroup results2 = dbHelp.search(db.getPwDatabase(), ENTRY2_NAME); PwGroup results2 = dbHelp.search(db.getPwDatabase(), ENTRY2_NAME, 100);
assertEquals("Entry1 was not removed from the search results", 0, results1.numbersOfChildEntries()); assertEquals("Entry1 was not removed from the search results", 0, results1.numbersOfChildEntries());
assertEquals("Entry2 was not removed from the search results", 0, results2.numbersOfChildEntries()); assertEquals("Entry2 was not removed from the search results", 0, results2.numbersOfChildEntries());

View File

@@ -19,11 +19,11 @@
*/ */
package com.kunzisoft.keepass.tests.database; package com.kunzisoft.keepass.tests.database;
import junit.framework.TestCase;
import com.kunzisoft.keepass.database.PwDatabaseV4; import com.kunzisoft.keepass.database.PwDatabaseV4;
import com.kunzisoft.keepass.database.PwEntryV4; import com.kunzisoft.keepass.database.PwEntryV4;
import junit.framework.TestCase;
public class EntryV4 extends TestCase { public class EntryV4 extends TestCase {
public void testBackup() { public void testBackup() {
@@ -46,7 +46,7 @@ public class EntryV4 extends TestCase {
entry.createBackup(db); entry.createBackup(db);
PwEntryV4 backup = entry.getHistory().get(0); PwEntryV4 backup = entry.getHistory().get(0);
entry.endToManageFieldReferences(); entry.stopToManageFieldReferences();
assertEquals("Title2", backup.getTitle()); assertEquals("Title2", backup.getTitle());
assertEquals("User2", backup.getUsername()); assertEquals("User2", backup.getUsername());
} }

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="108"
android:viewportHeight="108"
android:width="108dp"
android:height="108dp">
<group
android:translateY="-332">
<group
android:translateY="332">
<path
android:pathData="M65.728516 32.791016L58.052734 35.904297 56.173828 48.380859 35.306641 69.267578 35.238281 73.759766 69.478516 108 108 108 108 70.810547 73.09375 35.904297 65.728516 32.791016Z"
android:fillColor="@color/long_shadow"
android:strokeLineJoin="round"
android:strokeLineCap="round"
android:strokeMiterLimit="4" />
</group>
<group
android:scaleX="0.3939503"
android:scaleY="0.3939503"
android:translateX="33.66343"
android:translateY="233.998">
<path
android:pathData="M88.76953 339.91602L4.1718754 424.59766 4.0000004 436 15.400391 435.82813 27.240234 424 40 424l0 -12 12 0 0 -12.73438 34.01172 -33.97656A8 8 0 0 1 84 360a8 8 0 0 1 8 -8 8 8 0 0 1 5.296882 2.01367l2.787098 -2.7832 -11.31445 -11.31445z"
android:fillColor="#eaeaea"
android:strokeWidth="1"
android:strokeColor="#58000000" />
</group>
<group
android:scaleX="0.3939503"
android:scaleY="0.3939503"
android:translateX="33.66343"
android:translateY="233.998">
<path
android:pathData="M4.0000004 340L4.1718754 351.40137 88.59863 435.82812 100 436 99.828122 424.59863 15.401367 340.17188Z"
android:fillColor="#81c784" />
</group>
<group
android:scaleX="0.3939503"
android:scaleY="0.3939503"
android:translateX="33.66343"
android:translateY="233.998">
<path
android:pathData="M81.39454 332.00195a27 27 0 0 0 -19.48634 7.90625 27 27 0 0 0 0 38.1836 27 27 0 0 0 38.1836 0 27 27 0 0 0 0 -38.1836 27 27 0 0 0 -18.69726 -7.90625zM92 352a8 8 0 0 1 8 8 8 8 0 0 1 -8 8 8 8 0 0 1 -8 -8 8 8 0 0 1 8 -8z"
android:fillColor="#eaeaea"
android:strokeWidth="1"
android:strokeColor="#58000000" />
</group>
</group>
</vector>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/green" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/green" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="108"
android:viewportHeight="108"
android:width="108dp"
android:height="108dp">
<group
android:translateY="-332">
<group
android:translateY="332">
<path
android:pathData="M65.728516 32.791016L58.052734 35.904297 56.173828 48.380859 35.306641 69.267578 35.238281 73.759766 69.478516 108 108 108 108 70.810547 73.09375 35.904297 65.728516 32.791016Z"
android:fillColor="@color/long_shadow"
android:strokeLineJoin="round"
android:strokeLineCap="round"
android:strokeMiterLimit="4" />
</group>
<group
android:scaleX="0.3939503"
android:scaleY="0.3939503"
android:translateX="33.66343"
android:translateY="233.998">
<path
android:pathData="M88.76953 339.91602L4.1718754 424.59766 4.0000004 436 15.400391 435.82813 27.240234 424 40 424l0 -12 12 0 0 -12.73438 34.01172 -33.97656A8 8 0 0 1 84 360a8 8 0 0 1 8 -8 8 8 0 0 1 5.296882 2.01367l2.787098 -2.7832 -11.31445 -11.31445z"
android:fillColor="#eaeaea"
android:strokeWidth="1"
android:strokeColor="#58000000"/>
</group>
<group
android:scaleX="0.3939503"
android:scaleY="0.3939503"
android:translateX="33.66343"
android:translateY="233.998">
<path
android:pathData="M4.0000004 340L4.1718754 351.40137 88.59863 435.82812 100 436 99.828122 424.59863 15.401367 340.17188Z"
android:fillColor="#64b5f6" />
</group>
<group
android:scaleX="0.3939503"
android:scaleY="0.3939503"
android:translateX="33.66343"
android:translateY="233.998">
<path
android:pathData="M81.39454 332.00195a27 27 0 0 0 -19.48634 7.90625 27 27 0 0 0 0 38.1836 27 27 0 0 0 38.1836 0 27 27 0 0 0 0 -38.1836 27 27 0 0 0 -18.69726 -7.90625zM92 352a8 8 0 0 1 8 8 8 8 0 0 1 -8 8 8 8 0 0 1 -8 -8 8 8 0 0 1 8 -8z"
android:fillColor="#eaeaea"
android:strokeWidth="1"
android:strokeColor="#58000000" />
</group>
</group>
</vector>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/green" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/green" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

View File

@@ -20,8 +20,7 @@
android:allowBackup="true" android:allowBackup="true"
android:fullBackupContent="@xml/backup" android:fullBackupContent="@xml/backup"
android:backupAgent="com.kunzisoft.keepass.backup.SettingsBackupAgent" android:backupAgent="com.kunzisoft.keepass.backup.SettingsBackupAgent"
android:theme="@style/KeepassDXStyle.Night" android:theme="@style/KeepassDXStyle.Night">
tools:replace="android:theme">
<!-- TODO backup API Key --> <!-- TODO backup API Key -->
<meta-data <meta-data
android:name="com.google.android.backup.api_key" android:name="com.google.android.backup.api_key"
@@ -31,7 +30,7 @@
android:name="com.kunzisoft.keepass.fileselect.FileSelectActivity" android:name="com.kunzisoft.keepass.fileselect.FileSelectActivity"
android:theme="@style/KeepassDXStyle.SplashScreen" android:theme="@style/KeepassDXStyle.SplashScreen"
android:label="@string/app_name" android:label="@string/app_name"
android:launchMode="singleTask" android:launchMode="singleTop"
android:configChanges="orientation|keyboardHidden" android:configChanges="orientation|keyboardHidden"
android:windowSoftInputMode="stateHidden" > android:windowSoftInputMode="stateHidden" >
<intent-filter> <intent-filter>
@@ -104,11 +103,19 @@
<activity <activity
android:name="com.kunzisoft.keepass.activities.GroupActivity" android:name="com.kunzisoft.keepass.activities.GroupActivity"
android:configChanges="orientation|keyboardHidden" android:configChanges="orientation|keyboardHidden"
android:windowSoftInputMode="adjustPan"> android:windowSoftInputMode="adjustPan"
android:launchMode="singleTop">
<meta-data <meta-data
android:name="android.app.default_searchable" android:name="android.app.default_searchable"
android:value="com.kunzisoft.keepass.search.SearchResults" android:value="com.kunzisoft.keepass.search.SearchResults"
android:exported="false"/> android:exported="false"/>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity> </activity>
<activity <activity
android:name="com.kunzisoft.keepass.activities.EntryActivity" android:name="com.kunzisoft.keepass.activities.EntryActivity"
@@ -118,27 +125,33 @@
android:name="com.kunzisoft.keepass.activities.EntryEditActivity" android:name="com.kunzisoft.keepass.activities.EntryEditActivity"
android:configChanges="orientation|keyboardHidden" android:configChanges="orientation|keyboardHidden"
android:windowSoftInputMode="stateHidden" /> android:windowSoftInputMode="stateHidden" />
<activity
android:name="com.kunzisoft.keepass.search.SearchResultsActivity"
android:launchMode="standard">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<activity android:name="com.kunzisoft.keepass.settings.SettingsActivity" /> <activity android:name="com.kunzisoft.keepass.settings.SettingsActivity" />
<activity android:name="com.kunzisoft.keepass.autofill.AutoFillAuthActivity" <activity android:name="com.kunzisoft.keepass.autofill.AutoFillAuthActivity"
android:configChanges="orientation|keyboardHidden" /> android:configChanges="orientation|keyboardHidden" />
<activity android:name="com.kunzisoft.keepass.selection.EntrySelectionAuthActivity"
android:configChanges="orientation|keyboardHidden" />
<activity android:name="com.kunzisoft.keepass.settings.SettingsAutofillActivity" /> <activity android:name="com.kunzisoft.keepass.settings.SettingsAutofillActivity" />
<activity android:name="com.kunzisoft.keepass.magikeyboard.EntryRetrieverActivity"
android:label="@string/keyboard_name">
</activity>
<activity android:name="com.kunzisoft.keepass.settings.MagikIMESettings"
android:label="@string/keyboard_setting_label">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
</activity>
<service android:name="com.kunzisoft.keepass.timeout.TimeoutService" />
<!-- Receiver for Keyboard -->
<receiver
android:name="com.kunzisoft.keepass.magikeyboard.receiver.NotificationDeleteBroadcastReceiver"
android:exported="false" >
</receiver>
<service <service
android:name="com.kunzisoft.keepass.notifications.NotificationCopyingService" android:name="com.kunzisoft.keepass.notifications.NotificationCopyingService"
android:enabled="true" android:enabled="true"
android:exported="false" /> android:exported="false" />
<!-- Receiver for Autofill -->
<service <service
android:name="com.kunzisoft.keepass.autofill.KeeAutofillService" android:name="com.kunzisoft.keepass.autofill.KeeAutofillService"
android:label="@string/autofill_service_name" android:label="@string/autofill_service_name"
@@ -146,11 +159,22 @@
<meta-data <meta-data
android:name="android.autofill" android:name="android.autofill"
android:resource="@xml/dataset_service" /> android:resource="@xml/dataset_service" />
<intent-filter> <intent-filter>
<action android:name="android.service.autofill.AutofillService" /> <action android:name="android.service.autofill.AutofillService" />
</intent-filter> </intent-filter>
</service> </service>
<service
android:name="com.kunzisoft.keepass.magikeyboard.MagikIME"
android:label="@string/keyboard_label"
android:permission="android.permission.BIND_INPUT_METHOD" >
<meta-data android:name="android.view.im"
android:resource="@xml/keyboard_method"/>
<intent-filter>
<action android:name="android.view.InputMethod" />
</intent-filter>
</service>
<service android:name="com.kunzisoft.keepass.magikeyboard.KeyboardEntryNotificationService" />
<meta-data android:name="com.sec.android.support.multiwindow" android:value="true" /> <meta-data android:name="com.sec.android.support.multiwindow" android:value="true" />
</application> </application>
</manifest> </manifest>

View File

@@ -19,7 +19,6 @@
*/ */
package com.kunzisoft.keepass.activities; package com.kunzisoft.keepass.activities;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
@@ -27,6 +26,7 @@ import android.util.Log;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.TextView; import android.widget.TextView;
import com.kunzisoft.keepass.BuildConfig;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.stylish.StylishActivity; import com.kunzisoft.keepass.stylish.StylishActivity;
@@ -40,7 +40,7 @@ public class AboutActivity extends StylishActivity {
setContentView(R.layout.about); setContentView(R.layout.about);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle(getString(R.string.menu_about)); toolbar.setTitle(getString(R.string.menu_about));
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
assert getSupportActionBar() != null; assert getSupportActionBar() != null;
@@ -48,18 +48,25 @@ public class AboutActivity extends StylishActivity {
getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true);
String version; String version;
String build;
try { try {
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0); version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
version = packageInfo.versionName; build = BuildConfig.BUILD_VERSION;
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {
Log.w(getClass().getSimpleName(), "Unable to get application version", e); Log.w(getClass().getSimpleName(), "Unable to get the app or the build version", e);
version = "Unable to get application version."; version = "Unable to get the app version";
build = "Unable to get the build version";
} }
version = getString(R.string.version_label) + " " + version; version = getString(R.string.version_label, version);
TextView versionText = (TextView) findViewById(R.id.activity_about_version); TextView versionTextView = findViewById(R.id.activity_about_version);
versionText.setText(version); versionTextView.setText(version);
TextView disclaimerText = (TextView) findViewById(R.id.disclaimer); build = getString(R.string.build_label, build);
TextView buildTextView = findViewById(R.id.activity_about_build);
buildTextView.setText(build);
TextView disclaimerText = findViewById(R.id.disclaimer);
disclaimerText.setText(getString(R.string.disclaimer_formal, new DateTime().getYear())); disclaimerText.setText(getString(R.string.disclaimer_formal, new DateTime().getYear()));
} }

View File

@@ -28,6 +28,7 @@ import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
@@ -46,7 +47,8 @@ import com.kunzisoft.keepass.database.ExtraFields;
import com.kunzisoft.keepass.database.PwDatabase; import com.kunzisoft.keepass.database.PwDatabase;
import com.kunzisoft.keepass.database.PwEntry; import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.security.ProtectedString; import com.kunzisoft.keepass.database.security.ProtectedString;
import com.kunzisoft.keepass.icons.IconPackChooser; import com.kunzisoft.keepass.lock.LockingActivity;
import com.kunzisoft.keepass.lock.LockingHideActivity;
import com.kunzisoft.keepass.notifications.NotificationCopyingService; import com.kunzisoft.keepass.notifications.NotificationCopyingService;
import com.kunzisoft.keepass.notifications.NotificationField; import com.kunzisoft.keepass.notifications.NotificationField;
import com.kunzisoft.keepass.settings.PreferencesUtil; import com.kunzisoft.keepass.settings.PreferencesUtil;
@@ -63,6 +65,7 @@ import java.util.Date;
import java.util.UUID; import java.util.UUID;
import static com.kunzisoft.keepass.settings.PreferencesUtil.isClipboardNotificationsEnable; import static com.kunzisoft.keepass.settings.PreferencesUtil.isClipboardNotificationsEnable;
import static com.kunzisoft.keepass.settings.PreferencesUtil.isFirstTimeAskAllowCopyPasswordAndProtectedFields;
public class EntryActivity extends LockingHideActivity { public class EntryActivity extends LockingHideActivity {
private final static String TAG = EntryActivity.class.getName(); private final static String TAG = EntryActivity.class.getName();
@@ -76,15 +79,17 @@ public class EntryActivity extends LockingHideActivity {
protected PwEntry mEntry; protected PwEntry mEntry;
private boolean mShowPassword; private boolean mShowPassword;
protected boolean readOnly = false;
private ClipboardHelper clipboardHelper; private ClipboardHelper clipboardHelper;
private boolean firstLaunchOfActivity; private boolean firstLaunchOfActivity;
public static void launch(Activity act, PwEntry pw) { private int iconColor;
public static void launch(Activity act, PwEntry pw, boolean readOnly) {
if (LockingActivity.checkTimeIsAllowedOrFinish(act)) { if (LockingActivity.checkTimeIsAllowedOrFinish(act)) {
Intent intent = new Intent(act, EntryActivity.class); Intent intent = new Intent(act, EntryActivity.class);
intent.putExtra(KEY_ENTRY, Types.UUIDtoBytes(pw.getUUID())); intent.putExtra(KEY_ENTRY, Types.UUIDtoBytes(pw.getUUID()));
ReadOnlyHelper.putReadOnlyInIntent(intent, readOnly);
act.startActivityForResult(intent, EntryEditActivity.ADD_OR_UPDATE_ENTRY_REQUEST_CODE); act.startActivityForResult(intent, EntryEditActivity.ADD_OR_UPDATE_ENTRY_REQUEST_CODE);
} }
} }
@@ -108,7 +113,7 @@ public class EntryActivity extends LockingHideActivity {
finish(); finish();
return; return;
} }
readOnly = db.isReadOnly(); readOnly = db.isReadOnly() || readOnly;
mShowPassword = !PreferencesUtil.isPasswordMask(this); mShowPassword = !PreferencesUtil.isPasswordMask(this);
@@ -121,6 +126,11 @@ public class EntryActivity extends LockingHideActivity {
finish(); finish();
return; return;
} }
// Retrieve the textColor to tint the icon
int[] attrs = {R.attr.textColorInverse};
TypedArray ta = getTheme().obtainStyledAttributes(attrs);
iconColor = ta.getColor(0, Color.WHITE);
// Refresh Menu contents in case onCreateMenuOptions was called before mEntry was set // Refresh Menu contents in case onCreateMenuOptions was called before mEntry was set
invalidateOptionsMenu(); invalidateOptionsMenu();
@@ -150,12 +160,28 @@ public class EntryActivity extends LockingHideActivity {
// Start to manage field reference to copy a value from ref // Start to manage field reference to copy a value from ref
mEntry.startToManageFieldReferences(App.getDB().getPwDatabase()); mEntry.startToManageFieldReferences(App.getDB().getPwDatabase());
boolean containsUsernameToCopy =
mEntry.getUsername().length() > 0;
boolean containsPasswordToCopy =
(mEntry.getPassword().length() > 0
&& PreferencesUtil.allowCopyPasswordAndProtectedFields(this));
boolean containsExtraFieldToCopy =
(mEntry.allowExtraFields()
&& ((mEntry.containsCustomFields()
&& mEntry.containsCustomFieldsNotProtected())
|| (mEntry.containsCustomFields()
&& mEntry.containsCustomFieldsProtected()
&& PreferencesUtil.allowCopyPasswordAndProtectedFields(this))
)
);
// If notifications enabled in settings // If notifications enabled in settings
// Don't if application timeout // Don't if application timeout
if (firstLaunchOfActivity && !App.isShutdown() && isClipboardNotificationsEnable(getApplicationContext())) { if (firstLaunchOfActivity && !App.isShutdown() && isClipboardNotificationsEnable(getApplicationContext())) {
if (mEntry.getUsername().length() > 0 if (containsUsernameToCopy
|| (mEntry.getPassword().length() > 0 && PreferencesUtil.allowCopyPassword(this)) || containsPasswordToCopy
|| mEntry.containsCustomFields()) { || containsExtraFieldToCopy
) {
// username already copied, waiting for user's action before copy password. // username already copied, waiting for user's action before copy password.
Intent intent = new Intent(this, NotificationCopyingService.class); Intent intent = new Intent(this, NotificationCopyingService.class);
intent.setAction(NotificationCopyingService.ACTION_NEW_NOTIFICATION); intent.setAction(NotificationCopyingService.ACTION_NEW_NOTIFICATION);
@@ -164,35 +190,37 @@ public class EntryActivity extends LockingHideActivity {
// Construct notification fields // Construct notification fields
ArrayList<NotificationField> notificationFields = new ArrayList<>(); ArrayList<NotificationField> notificationFields = new ArrayList<>();
// Add username if exists to notifications // Add username if exists to notifications
if (mEntry.getUsername().length() > 0) if (containsUsernameToCopy)
notificationFields.add( notificationFields.add(
new NotificationField( new NotificationField(
NotificationField.NotificationFieldId.USERNAME, NotificationField.NotificationFieldId.USERNAME,
mEntry.getUsername(), mEntry.getUsername(),
getResources())); getResources()));
// Add password to notifications // Add password to notifications
if (PreferencesUtil.allowCopyPassword(this)) { if (containsPasswordToCopy) {
if (mEntry.getPassword().length() > 0) notificationFields.add(
notificationFields.add( new NotificationField(
new NotificationField( NotificationField.NotificationFieldId.PASSWORD,
NotificationField.NotificationFieldId.PASSWORD, mEntry.getPassword(),
mEntry.getPassword(), getResources()));
getResources()));
} }
// Add extra fields // Add extra fields
if (mEntry.allowExtraFields()) { if (containsExtraFieldToCopy) {
try { try {
mEntry.getFields().doActionToAllCustomProtectedField(new ExtraFields.ActionProtected() { mEntry.getFields().doActionToAllCustomProtectedField(new ExtraFields.ActionProtected() {
private int anonymousFieldNumber = 0; private int anonymousFieldNumber = 0;
@Override @Override
public void doAction(String key, ProtectedString value) { public void doAction(String key, ProtectedString value) {
notificationFields.add( //If value is not protected or allowed
new NotificationField( if (!value.isProtected() || PreferencesUtil.allowCopyPasswordAndProtectedFields(EntryActivity.this)) {
NotificationField.NotificationFieldId.getAnonymousFieldId()[anonymousFieldNumber], notificationFields.add(
value.toString(), new NotificationField(
key, NotificationField.NotificationFieldId.getAnonymousFieldId()[anonymousFieldNumber],
getResources())); value.toString(),
anonymousFieldNumber++; key,
getResources()));
anonymousFieldNumber++;
}
} }
}); });
} catch (ArrayIndexOutOfBoundsException e) { } catch (ArrayIndexOutOfBoundsException e) {
@@ -205,7 +233,7 @@ public class EntryActivity extends LockingHideActivity {
startService(intent); startService(intent);
} }
mEntry.endToManageFieldReferences(); mEntry.stopToManageFieldReferences();
} }
firstLaunchOfActivity = false; firstLaunchOfActivity = false;
} }
@@ -215,66 +243,70 @@ public class EntryActivity extends LockingHideActivity {
* Displays the explanation for copying a field and editing an entry * Displays the explanation for copying a field and editing an entry
*/ */
private void checkAndPerformedEducation(Menu menu) { private void checkAndPerformedEducation(Menu menu) {
if (PreferencesUtil.isEducationScreensEnabled(this)) {
if (entryContentsView != null && entryContentsView.isUserNamePresent() if (entryContentsView != null && entryContentsView.isUserNamePresent()
&& !PreferencesUtil.isEducationCopyUsernamePerformed(this)) { && !PreferencesUtil.isEducationCopyUsernamePerformed(this)) {
TapTargetView.showFor(this,
TapTarget.forView(findViewById(R.id.entry_user_name_action_image),
getString(R.string.education_field_copy_title),
getString(R.string.education_field_copy_summary))
.tintTarget(false)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
clipboardHelper.timeoutCopyToClipboard(mEntry.getUsername(),
getString(R.string.copy_field, getString(R.string.entry_user_name)));
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
// Launch autofill settings
startActivity(new Intent(EntryActivity.this, SettingsAutofillActivity.class));
}
});
PreferencesUtil.saveEducationPreference(this,
R.string.education_copy_username_key);
} else if (!PreferencesUtil.isEducationEntryEditPerformed(this)) {
try {
TapTargetView.showFor(this, TapTargetView.showFor(this,
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_edit, TapTarget.forView(findViewById(R.id.entry_user_name_action_image),
getString(R.string.education_entry_edit_title), getString(R.string.education_field_copy_title),
getString(R.string.education_entry_edit_summary)) getString(R.string.education_field_copy_summary))
.tintTarget(true) .textColorInt(Color.WHITE)
.tintTarget(false)
.cancelable(true), .cancelable(true),
new TapTargetView.Listener() { new TapTargetView.Listener() {
@Override @Override
public void onTargetClick(TapTargetView view) { public void onTargetClick(TapTargetView view) {
super.onTargetClick(view); super.onTargetClick(view);
MenuItem editItem = menu.findItem(R.id.menu_edit); clipboardHelper.timeoutCopyToClipboard(mEntry.getUsername(),
onOptionsItemSelected(editItem); getString(R.string.copy_field, getString(R.string.entry_user_name)));
} }
@Override @Override
public void onOuterCircleClick(TapTargetView view) { public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view); super.onOuterCircleClick(view);
view.dismiss(false); view.dismiss(false);
// Open Keepass doc to create field references // Launch autofill settings
Intent browserIntent = new Intent(Intent.ACTION_VIEW, startActivity(new Intent(EntryActivity.this, SettingsAutofillActivity.class));
Uri.parse(getString(R.string.field_references_url)));
startActivity(browserIntent);
} }
}); });
PreferencesUtil.saveEducationPreference(this, PreferencesUtil.saveEducationPreference(this,
R.string.education_entry_edit_key); R.string.education_copy_username_key);
} catch (Exception e) {
// If icon not visible } else if (!PreferencesUtil.isEducationEntryEditPerformed(this)) {
Log.w(TAG, "Can't performed education for entry's edition");
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");
}
} }
} }
} }
@@ -286,18 +318,10 @@ public class EntryActivity extends LockingHideActivity {
mEntry.startToManageFieldReferences(pm); mEntry.startToManageFieldReferences(pm);
// Assign title icon // Assign title icon
if (IconPackChooser.getSelectedIconPack(this).tintable()) { db.getDrawFactory().assignDatabaseIconTo(this, titleIconView, mEntry.getIcon(), iconColor);
// 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 // Assign title text
titleView.setText(mEntry.getTitle()); titleView.setText(mEntry.getVisualTitle());
// Assign basic fields // Assign basic fields
entryContentsView.assignUserName(mEntry.getUsername()); entryContentsView.assignUserName(mEntry.getUsername());
@@ -306,12 +330,39 @@ public class EntryActivity extends LockingHideActivity {
getString(R.string.copy_field, getString(R.string.entry_user_name))) getString(R.string.copy_field, getString(R.string.entry_user_name)))
); );
entryContentsView.assignPassword(mEntry.getPassword()); boolean allowCopyPassword = PreferencesUtil.allowCopyPasswordAndProtectedFields(this);
if (PreferencesUtil.allowCopyPassword(this)) { entryContentsView.assignPassword(mEntry.getPassword(), allowCopyPassword);
if (allowCopyPassword) {
entryContentsView.assignPasswordCopyListener(view -> entryContentsView.assignPasswordCopyListener(view ->
clipboardHelper.timeoutCopyToClipboard(mEntry.getPassword(), clipboardHelper.timeoutCopyToClipboard(mEntry.getPassword(),
getString(R.string.copy_field, getString(R.string.entry_password))) getString(R.string.copy_field, getString(R.string.entry_password)))
); );
} else {
// If dialog not already shown
if (isFirstTimeAskAllowCopyPasswordAndProtectedFields(this)) {
entryContentsView.assignPasswordCopyListener(v -> {
String message = getString(R.string.allow_copy_password_warning) +
"\n\n" +
getString(R.string.clipboard_warning);
AlertDialog warningDialog = new AlertDialog.Builder(EntryActivity.this)
.setMessage(message).create();
warningDialog.setButton(AlertDialog.BUTTON1, getText(android.R.string.ok),
(dialog, which) -> {
PreferencesUtil.setAllowCopyPasswordAndProtectedFields(EntryActivity.this, true);
dialog.dismiss();
fillData();
});
warningDialog.setButton(AlertDialog.BUTTON2, getText(android.R.string.cancel),
(dialog, which) -> {
PreferencesUtil.setAllowCopyPasswordAndProtectedFields(EntryActivity.this, false);
dialog.dismiss();
fillData();
});
warningDialog.show();
});
} else {
entryContentsView.assignPasswordCopyListener(null);
}
} }
entryContentsView.assignURL(mEntry.getUrl()); entryContentsView.assignURL(mEntry.getUrl());
@@ -323,14 +374,15 @@ public class EntryActivity extends LockingHideActivity {
if (mEntry.allowExtraFields()) { if (mEntry.allowExtraFields()) {
entryContentsView.clearExtraFields(); entryContentsView.clearExtraFields();
mEntry.getFields().doActionToAllCustomProtectedField((label, value) -> mEntry.getFields().doActionToAllCustomProtectedField((label, value) -> {
boolean showAction = (!value.isProtected() || PreferencesUtil.allowCopyPasswordAndProtectedFields(EntryActivity.this));
entryContentsView.addExtraField(label, value, view -> entryContentsView.addExtraField(label, value, showAction, view ->
clipboardHelper.timeoutCopyToClipboard( clipboardHelper.timeoutCopyToClipboard(
value.toString(), value.toString(),
getString(R.string.copy_field, label) getString(R.string.copy_field, label)
) )
)); );
});
} }
// Assign dates // Assign dates
@@ -344,7 +396,7 @@ public class EntryActivity extends LockingHideActivity {
entryContentsView.assignExpiresDate(getString(R.string.never)); entryContentsView.assignExpiresDate(getString(R.string.never));
} }
mEntry.endToManageFieldReferences(); mEntry.stopToManageFieldReferences();
} }
@Override @Override
@@ -372,7 +424,7 @@ public class EntryActivity extends LockingHideActivity {
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
MenuUtil.donationMenuInflater(inflater, menu); MenuUtil.contributionMenuInflater(inflater, menu);
inflater.inflate(R.menu.entry, menu); inflater.inflate(R.menu.entry, menu);
inflater.inflate(R.menu.database_lock, menu); inflater.inflate(R.menu.database_lock, menu);
@@ -415,8 +467,8 @@ public class EntryActivity extends LockingHideActivity {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch ( item.getItemId() ) { switch ( item.getItemId() ) {
case R.id.menu_donate: case R.id.menu_contribute:
return MenuUtil.onDonationItemSelected(this); return MenuUtil.onContributionItemSelected(this);
case R.id.menu_toggle_pass: case R.id.menu_toggle_pass:
mShowPassword = !mShowPassword; mShowPassword = !mShowPassword;

View File

@@ -24,7 +24,6 @@ import android.content.Intent;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
@@ -49,16 +48,19 @@ import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.PwGroup; import com.kunzisoft.keepass.database.PwGroup;
import com.kunzisoft.keepass.database.PwGroupId; import com.kunzisoft.keepass.database.PwGroupId;
import com.kunzisoft.keepass.database.PwIconStandard; import com.kunzisoft.keepass.database.PwIconStandard;
import com.kunzisoft.keepass.database.edit.AddEntry; import com.kunzisoft.keepass.database.PwNode;
import com.kunzisoft.keepass.database.edit.OnFinish; import com.kunzisoft.keepass.database.action.RunnableOnFinish;
import com.kunzisoft.keepass.database.edit.RunnableOnFinish; import com.kunzisoft.keepass.database.action.node.AddEntryRunnable;
import com.kunzisoft.keepass.database.edit.UpdateEntry; import com.kunzisoft.keepass.database.action.node.AfterActionNodeOnFinish;
import com.kunzisoft.keepass.database.action.node.UpdateEntryRunnable;
import com.kunzisoft.keepass.database.security.ProtectedString; import com.kunzisoft.keepass.database.security.ProtectedString;
import com.kunzisoft.keepass.dialogs.GeneratePasswordDialogFragment; import com.kunzisoft.keepass.dialogs.GeneratePasswordDialogFragment;
import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment; import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment;
import com.kunzisoft.keepass.icons.IconPackChooser; import com.kunzisoft.keepass.lock.LockingActivity;
import com.kunzisoft.keepass.lock.LockingHideActivity;
import com.kunzisoft.keepass.settings.PreferencesUtil; import com.kunzisoft.keepass.settings.PreferencesUtil;
import com.kunzisoft.keepass.tasks.ProgressTask; import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
import com.kunzisoft.keepass.utils.MenuUtil; import com.kunzisoft.keepass.utils.MenuUtil;
import com.kunzisoft.keepass.utils.Types; import com.kunzisoft.keepass.utils.Types;
import com.kunzisoft.keepass.utils.Util; import com.kunzisoft.keepass.utils.Util;
@@ -66,7 +68,9 @@ import com.kunzisoft.keepass.view.EntryEditCustomField;
import java.util.UUID; import java.util.UUID;
import static com.kunzisoft.keepass.dialogs.IconPickerDialogFragment.UNDEFINED_ICON_ID; import javax.annotation.Nullable;
import static com.kunzisoft.keepass.dialogs.IconPickerDialogFragment.KEY_ICON_STANDARD;
public class EntryEditActivity extends LockingHideActivity public class EntryEditActivity extends LockingHideActivity
implements IconPickerDialogFragment.IconPickerListener, implements IconPickerDialogFragment.IconPickerListener,
@@ -84,10 +88,12 @@ public class EntryEditActivity extends LockingHideActivity
public static final int ADD_OR_UPDATE_ENTRY_REQUEST_CODE = 7129; public static final int ADD_OR_UPDATE_ENTRY_REQUEST_CODE = 7129;
public static final String ADD_OR_UPDATE_ENTRY_KEY = "ADD_OR_UPDATE_ENTRY_KEY"; public static final String ADD_OR_UPDATE_ENTRY_KEY = "ADD_OR_UPDATE_ENTRY_KEY";
private Database database;
protected PwEntry mEntry; protected PwEntry mEntry;
protected PwEntry mCallbackNewEntry; protected PwEntry mCallbackNewEntry;
protected boolean mIsNew; protected boolean mIsNew;
protected int mSelectedIconID = UNDEFINED_ICON_ID; protected PwIconStandard mSelectedIconStandard;
// Views // Views
private ScrollView scrollView; private ScrollView scrollView;
@@ -138,7 +144,6 @@ public class EntryEditActivity extends LockingHideActivity
setContentView(R.layout.entry_edit); setContentView(R.layout.entry_edit);
Toolbar toolbar = findViewById(R.id.toolbar); Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle(getString(R.string.app_name));
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
assert getSupportActionBar() != null; assert getSupportActionBar() != null;
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@@ -157,8 +162,8 @@ public class EntryEditActivity extends LockingHideActivity
entryExtraFieldsContainer = findViewById(R.id.advanced_container); entryExtraFieldsContainer = findViewById(R.id.advanced_container);
// Likely the app has been killed exit the activity // Likely the app has been killed exit the activity
Database db = App.getDB(); database = App.getDB();
if ( ! db.getLoaded() ) { if ( ! database.getLoaded() ) {
finish(); finish();
return; return;
} }
@@ -171,18 +176,16 @@ public class EntryEditActivity extends LockingHideActivity
TypedArray ta = getTheme().obtainStyledAttributes(attrs); TypedArray ta = getTheme().obtainStyledAttributes(attrs);
iconColor = ta.getColor(0, Color.WHITE); iconColor = ta.getColor(0, Color.WHITE);
PwDatabase pm = db.getPwDatabase(); mSelectedIconStandard = database.getPwDatabase().getIconFactory().getUnknownIcon();
PwDatabase pm = database.getPwDatabase();
if ( uuidBytes == null ) { if ( uuidBytes == null ) {
PwGroupId parentId = (PwGroupId) intent.getSerializableExtra(KEY_PARENT); PwGroupId parentId = intent.getParcelableExtra(KEY_PARENT);
PwGroup parent = pm.getGroupByGroupId(parentId); PwGroup parent = pm.getGroupByGroupId(parentId);
mEntry = db.createEntry(parent); mEntry = database.createEntry(parent);
mIsNew = true; mIsNew = true;
// Add the default icon // Add the default icon
if (IconPackChooser.getSelectedIconPack(this).tintable()) { database.getDrawFactory().assignDefaultDatabaseIconTo(this, entryIconView, iconColor);
App.getDB().getDrawFactory().assignDefaultDatabaseIconTo(this, entryIconView, true, iconColor);
} else {
App.getDB().getDrawFactory().assignDefaultDatabaseIconTo(this, entryIconView);
}
} else { } else {
UUID uuid = Types.bytestoUUID(uuidBytes); UUID uuid = Types.bytestoUUID(uuidBytes);
mEntry = pm.getEntryByUUIDId(uuid); mEntry = pm.getEntryByUUIDId(uuid);
@@ -190,8 +193,12 @@ public class EntryEditActivity extends LockingHideActivity
fillData(); fillData();
} }
// Assign title
setTitle((mIsNew) ? getString(R.string.add_entry) : getString(R.string.edit_entry));
// Retrieve the icon after an orientation change // Retrieve the icon after an orientation change
if (savedInstanceState != null && savedInstanceState.containsKey(IconPickerDialogFragment.KEY_ICON_ID)) { if (savedInstanceState != null
&& savedInstanceState.containsKey(KEY_ICON_STANDARD)) {
iconPicked(savedInstanceState); iconPicked(savedInstanceState);
} }
@@ -249,16 +256,21 @@ public class EntryEditActivity extends LockingHideActivity
} }
mCallbackNewEntry = populateNewEntry(); mCallbackNewEntry = populateNewEntry();
OnFinish onFinish = new AfterSave(); // Open a progress dialog and save entry
AfterActionNodeOnFinish onFinish = new AfterSave();
EntryEditActivity act = EntryEditActivity.this; EntryEditActivity act = EntryEditActivity.this;
RunnableOnFinish task; RunnableOnFinish task;
if ( mIsNew ) { if ( mIsNew ) {
task = new AddEntry(act, App.getDB(), mCallbackNewEntry, onFinish); task = new AddEntryRunnable(act, database, mCallbackNewEntry, onFinish);
} else { } else {
task = new UpdateEntry(act, App.getDB(), mEntry, mCallbackNewEntry, onFinish); task = new UpdateEntryRunnable(act, database, mEntry, mCallbackNewEntry, onFinish);
} }
ProgressTask pt = new ProgressTask(act, task, R.string.saving_database); task.setUpdateProgressTaskStatus(
pt.run(); new UpdateProgressTaskStatus(this,
SaveDatabaseProgressTaskDialogFragment.start(
getSupportFragmentManager())
));
new Thread(task).start();
} }
/** /**
@@ -266,57 +278,58 @@ public class EntryEditActivity extends LockingHideActivity
* Displays the explanation for the icon selection, the password generator and for a new field * Displays the explanation for the icon selection, the password generator and for a new field
*/ */
private void checkAndPerformedEducation() { private void checkAndPerformedEducation() {
if (PreferencesUtil.isEducationScreensEnabled(this)) {
// TODO Show icon
// TODO Show icon if (!PreferencesUtil.isEducationPasswordGeneratorPerformed(this)) {
TapTargetView.showFor(this,
TapTarget.forView(generatePasswordView,
getString(R.string.education_generate_password_title),
getString(R.string.education_generate_password_summary))
.textColorInt(Color.WHITE)
.tintTarget(false)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
openPasswordGenerator();
}
if (!PreferencesUtil.isEducationPasswordGeneratorPerformed(this)) { @Override
TapTargetView.showFor(this, public void onOuterCircleClick(TapTargetView view) {
TapTarget.forView(generatePasswordView, super.onOuterCircleClick(view);
getString(R.string.education_generate_password_title), view.dismiss(false);
getString(R.string.education_generate_password_summary)) }
.tintTarget(false) });
.cancelable(true), PreferencesUtil.saveEducationPreference(this,
new TapTargetView.Listener() { R.string.education_password_generator_key);
@Override } else if (mEntry.allowExtraFields()
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
openPasswordGenerator();
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
}
});
PreferencesUtil.saveEducationPreference(this,
R.string.education_password_generator_key);
}
else if (mEntry.allowExtraFields()
&& !mEntry.containsCustomFields() && !mEntry.containsCustomFields()
&& !PreferencesUtil.isEducationEntryNewFieldPerformed(this)) { && !PreferencesUtil.isEducationEntryNewFieldPerformed(this)) {
TapTargetView.showFor(this, TapTargetView.showFor(this,
TapTarget.forView(addNewFieldView, TapTarget.forView(addNewFieldView,
getString(R.string.education_entry_new_field_title), getString(R.string.education_entry_new_field_title),
getString(R.string.education_entry_new_field_summary)) getString(R.string.education_entry_new_field_summary))
.tintTarget(false) .textColorInt(Color.WHITE)
.cancelable(true), .tintTarget(false)
new TapTargetView.Listener() { .cancelable(true),
@Override new TapTargetView.Listener() {
public void onTargetClick(TapTargetView view) { @Override
super.onTargetClick(view); public void onTargetClick(TapTargetView view) {
addNewCustomField(); super.onTargetClick(view);
} addNewCustomField();
}
@Override @Override
public void onOuterCircleClick(TapTargetView view) { public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view); super.onOuterCircleClick(view);
view.dismiss(false); view.dismiss(false);
} }
}); });
PreferencesUtil.saveEducationPreference(this, PreferencesUtil.saveEducationPreference(this,
R.string.education_entry_new_field_key); R.string.education_entry_new_field_key);
}
} }
} }
@@ -398,7 +411,7 @@ public class EntryEditActivity extends LockingHideActivity
newEntry.setLastModificationTime(new PwDate()); newEntry.setLastModificationTime(new PwDate());
newEntry.setTitle(entryTitleView.getText().toString()); newEntry.setTitle(entryTitleView.getText().toString());
newEntry.setIcon(retrieveIcon()); newEntry.setIconStandard(retrieveIcon());
newEntry.setUrl(entryUrlView.getText().toString()); newEntry.setUrl(entryUrlView.getText().toString());
newEntry.setUsername(entryUserNameView.getText().toString()); newEntry.setUsername(entryUserNameView.getText().toString());
@@ -418,21 +431,21 @@ public class EntryEditActivity extends LockingHideActivity
} }
} }
newEntry.endToManageFieldReferences(); newEntry.stopToManageFieldReferences();
return newEntry; return newEntry;
} }
/** /**
* Retrieve the icon by the selection, or the first icon in the list if the entry is new or the last one * 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() { private PwIconStandard retrieveIcon() {
if(mSelectedIconID != UNDEFINED_ICON_ID)
return App.getDB().getPwDatabase().getIconFactory().getIcon(mSelectedIconID); if (!mSelectedIconStandard.isUnknown())
return mSelectedIconStandard;
else { else {
if (mIsNew) { if (mIsNew) {
return App.getDB().getPwDatabase().getIconFactory().getFirstIcon(); return database.getPwDatabase().getIconFactory().getKeyIcon();
} }
else { else {
// Keep previous icon, if no new one was selected // Keep previous icon, if no new one was selected
@@ -447,15 +460,15 @@ public class EntryEditActivity extends LockingHideActivity
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
MenuUtil.donationMenuInflater(inflater, menu); MenuUtil.contributionMenuInflater(inflater, menu);
return true; return true;
} }
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch ( item.getItemId() ) { switch ( item.getItemId() ) {
case R.id.menu_donate: case R.id.menu_contribute:
return MenuUtil.onDonationItemSelected(this); return MenuUtil.onContributionItemSelected(this);
case android.R.id.home: case android.R.id.home:
finish(); finish();
@@ -464,16 +477,21 @@ public class EntryEditActivity extends LockingHideActivity
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
private void assignIconView() {
database.getDrawFactory()
.assignDatabaseIconTo(
this,
entryIconView,
mEntry.getIcon(),
iconColor);
}
protected void fillData() { protected void fillData() {
if (IconPackChooser.getSelectedIconPack(this).tintable()) { assignIconView();
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 // Don't start the field reference manager, we want to see the raw ref
mEntry.endToManageFieldReferences(); mEntry.stopToManageFieldReferences();
entryTitleView.setText(mEntry.getTitle()); entryTitleView.setText(mEntry.getTitle());
entryUserNameView.setText(mEntry.getUsername()); entryUserNameView.setText(mEntry.getUsername());
@@ -504,14 +522,15 @@ public class EntryEditActivity extends LockingHideActivity
@Override @Override
public void iconPicked(Bundle bundle) { public void iconPicked(Bundle bundle) {
mSelectedIconID = bundle.getInt(IconPickerDialogFragment.KEY_ICON_ID); mSelectedIconStandard = bundle.getParcelable(KEY_ICON_STANDARD);
entryIconView.setImageResource(IconPackChooser.getSelectedIconPack(this).iconToResId(mSelectedIconID)); mEntry.setIconStandard(mSelectedIconStandard);
assignIconView();
} }
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
if (mSelectedIconID != UNDEFINED_ICON_ID) { if (!mSelectedIconStandard.isUnknown()) {
outState.putInt(IconPickerDialogFragment.KEY_ICON_ID, mSelectedIconID); outState.putParcelable(KEY_ICON_STANDARD, mSelectedIconStandard);
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
} }
} }
@@ -537,7 +556,7 @@ public class EntryEditActivity extends LockingHideActivity
if (mCallbackNewEntry != null) { if (mCallbackNewEntry != null) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
Intent intentEntry = new Intent(); Intent intentEntry = new Intent();
bundle.putSerializable(ADD_OR_UPDATE_ENTRY_KEY, mCallbackNewEntry); bundle.putParcelable(ADD_OR_UPDATE_ENTRY_KEY, mCallbackNewEntry);
intentEntry.putExtras(bundle); intentEntry.putExtras(bundle);
if (mIsNew) { if (mIsNew) {
setResult(ADD_ENTRY_RESULT_CODE, intentEntry); setResult(ADD_ENTRY_RESULT_CODE, intentEntry);
@@ -552,20 +571,20 @@ public class EntryEditActivity extends LockingHideActivity
} }
} }
private final class AfterSave extends OnFinish { private final class AfterSave extends AfterActionNodeOnFinish {
AfterSave() {
super(new Handler());
}
@Override @Override
public void run() { public void run(@Nullable PwNode oldNode, @Nullable PwNode newNode) {
if ( mSuccess ) { runOnUiThread(() -> {
finish(); if ( mSuccess ) {
} else { finish();
displayMessage(EntryEditActivity.this); } else {
} displayMessage(EntryEditActivity.this);
}
SaveDatabaseProgressTaskDialogFragment.stop(EntryEditActivity.this);
});
} }
} }
} }

View File

@@ -0,0 +1,7 @@
package com.kunzisoft.keepass.activities;
import android.content.Intent;
public interface IntentBuildLauncher {
void startActivityForResult(Intent intent);
}

View File

@@ -1,366 +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.activities;
import android.annotation.SuppressLint;
import android.app.assist.AssistStructure;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.adapters.NodeAdapter;
import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.autofill.AutofillHelper;
import com.kunzisoft.keepass.compat.EditorCompat;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwDatabase;
import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.PwGroup;
import com.kunzisoft.keepass.database.PwNode;
import com.kunzisoft.keepass.database.SortNodeEnum;
import com.kunzisoft.keepass.database.edit.AfterActionNodeOnFinish;
import com.kunzisoft.keepass.database.edit.OnFinish;
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
import com.kunzisoft.keepass.dialogs.SortDialogFragment;
import com.kunzisoft.keepass.password.AssignPasswordHelper;
import com.kunzisoft.keepass.settings.PreferencesUtil;
import com.kunzisoft.keepass.tasks.UIToastTask;
import com.kunzisoft.keepass.utils.MenuUtil;
public abstract class ListNodesActivity extends LockingActivity
implements AssignMasterKeyDialogFragment.AssignPasswordDialogListener,
NodeAdapter.OnNodeClickCallback,
SortDialogFragment.SortSelectionListener {
protected PwGroup mCurrentGroup;
protected NodeAdapter mAdapter;
private SharedPreferences prefs;
protected AutofillHelper autofillHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if ( isFinishing() ) {
return;
}
// Likely the app has been killed exit the activity
if ( ! App.getDB().getLoaded() ) {
finish();
return;
}
prefs = PreferenceManager.getDefaultSharedPreferences(this);
invalidateOptionsMenu();
// TODO Move in search
setContentView(R.layout.list_nodes);
mCurrentGroup = initCurrentGroup();
mAdapter = new NodeAdapter(this);
addOptionsToAdapter(mAdapter);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
autofillHelper = new AutofillHelper();
autofillHelper.retrieveAssistStructure(getIntent());
}
}
protected abstract PwGroup initCurrentGroup();
protected abstract RecyclerView defineNodeList();
protected void addOptionsToAdapter(NodeAdapter nodeAdapter) {
mAdapter.setOnNodeClickListener(this);
}
@Override
protected void onResume() {
super.onResume();
// Add elements to the list
mAdapter.rebuildList(mCurrentGroup);
assignListToNodeAdapter(defineNodeList());
}
protected void setGroupTitle() {
if ( mCurrentGroup != null ) {
String name = mCurrentGroup.getName();
TextView tv = findViewById(R.id.group_name);
if ( name != null && name.length() > 0 ) {
if ( tv != null ) {
tv.setText(name);
}
} else {
if ( tv != null ) {
tv.setText(getText(R.string.root));
}
}
}
}
protected void assignListToNodeAdapter(RecyclerView recyclerView) {
recyclerView.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(mAdapter);
}
@Override
public void onNodeClick(PwNode node) {
// Add event when we have Autofill
AssistStructure assistStructure = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
assistStructure = autofillHelper.getAssistStructure();
if (assistStructure != null) {
switch (node.getType()) {
case GROUP:
GroupActivity.launch(this, (PwGroup) node, assistStructure);
break;
case ENTRY:
// Build response with the entry selected
autofillHelper.buildResponseWhenEntrySelected(this, (PwEntry) node);
finish();
break;
}
}
}
if ( assistStructure == null ){
switch (node.getType()) {
case GROUP:
GroupActivity.launch(this, (PwGroup) node);
break;
case ENTRY:
EntryActivity.launch(this, (PwEntry) node);
break;
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
MenuUtil.donationMenuInflater(inflater, menu);
inflater.inflate(R.menu.tree, menu);
inflater.inflate(R.menu.default_menu, menu);
return true;
}
@Override
public void onSortSelected(SortNodeEnum sortNodeEnum, boolean ascending, boolean groupsBefore, boolean recycleBinBottom) {
// Toggle setting
Editor editor = prefs.edit();
editor.putString(getString(R.string.sort_node_key), sortNodeEnum.name());
editor.putBoolean(getString(R.string.sort_ascending_key), ascending);
editor.putBoolean(getString(R.string.sort_group_before_key), groupsBefore);
editor.putBoolean(getString(R.string.sort_recycle_bin_bottom_key), recycleBinBottom);
EditorCompat.apply(editor);
// Tell the adapter to refresh it's list
mAdapter.notifyChangeSort(sortNodeEnum, ascending, groupsBefore);
mAdapter.rebuildList(mCurrentGroup);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch ( item.getItemId() ) {
case R.id.menu_sort:
SortDialogFragment sortDialogFragment;
PwDatabase database = App.getDB().getPwDatabase();
/*
// TODO Recycle bin bottom
if (database.isRecycleBinAvailable() && database.isRecycleBinEnabled()) {
sortDialogFragment =
SortDialogFragment.getInstance(
PrefsUtil.getListSort(this),
PrefsUtil.getAscendingSort(this),
PrefsUtil.getGroupsBeforeSort(this),
PrefsUtil.getRecycleBinBottomSort(this));
} else {
*/
sortDialogFragment =
SortDialogFragment.getInstance(
PreferencesUtil.getListSort(this),
PreferencesUtil.getAscendingSort(this),
PreferencesUtil.getGroupsBeforeSort(this));
//}
sortDialogFragment.show(getSupportFragmentManager(), "sortDialog");
return true;
default:
// Check the time lock before launching settings
MenuUtil.onDefaultMenuOptionsItemSelected(this, item, true);
return super.onOptionsItemSelected(item);
}
}
@Override
public void onAssignKeyDialogPositiveClick(
boolean masterPasswordChecked, String masterPassword,
boolean keyFileChecked, Uri keyFile) {
AssignPasswordHelper assignPasswordHelper =
new AssignPasswordHelper(this,
masterPasswordChecked, masterPassword, keyFileChecked, keyFile);
assignPasswordHelper.assignPasswordInDatabase(null);
}
@Override
public void onAssignKeyDialogNegativeClick(
boolean masterPasswordChecked, String masterPassword,
boolean keyFileChecked, Uri keyFile) {
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case EntryEditActivity.ADD_OR_UPDATE_ENTRY_REQUEST_CODE:
if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE ||
resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE) {
PwNode newNode = (PwNode) data.getSerializableExtra(EntryEditActivity.ADD_OR_UPDATE_ENTRY_KEY);
if (newNode != null) {
if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE)
mAdapter.addNode(newNode);
if (resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE) {
//mAdapter.updateLastNodeRegister(newNode);
mAdapter.rebuildList(mCurrentGroup);
}
} else {
Log.e(this.getClass().getName(), "New node can be retrieve in Activity Result");
}
}
break;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
AutofillHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
}
}
@SuppressLint("RestrictedApi")
@Override
public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
/*
* ACTION_SEARCH automatically forces a new task. This occurs when you open a kdb file in
* another app such as Files or GoogleDrive and then Search for an entry. Here we remove the
* FLAG_ACTIVITY_NEW_TASK flag bit allowing search to open it's activity in the current task.
*/
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
int flags = intent.getFlags();
flags &= ~Intent.FLAG_ACTIVITY_NEW_TASK;
intent.setFlags(flags);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
super.startActivityForResult(intent, requestCode, options);
}
}
class AfterAddNode extends AfterActionNodeOnFinish {
AfterAddNode(Handler handler) {
super(handler);
}
public void run(PwNode oldNode, PwNode newNode) {
super.run();
if (mSuccess) {
mAdapter.addNode(newNode);
} else {
displayMessage(ListNodesActivity.this);
}
}
}
class AfterUpdateNode extends AfterActionNodeOnFinish {
AfterUpdateNode(Handler handler) {
super(handler);
}
public void run(PwNode oldNode, PwNode newNode) {
super.run();
if (mSuccess) {
mAdapter.updateNode(oldNode, newNode);
} else {
displayMessage(ListNodesActivity.this);
}
}
}
class AfterDeleteNode extends OnFinish {
private PwNode pwNode;
AfterDeleteNode(Handler handler, PwNode pwNode) {
super(handler);
this.pwNode = pwNode;
}
@Override
public void run() {
if ( mSuccess) {
mAdapter.removeNode(pwNode);
PwGroup parent = pwNode.getParent();
Database db = App.getDB();
PwDatabase database = db.getPwDatabase();
if (db.isRecycleBinAvailable() &&
db.isRecycleBinEnabled()) {
PwGroup recycleBin = database.getRecycleBin();
// Add trash if it doesn't exists
if (parent.equals(recycleBin)
&& mCurrentGroup != null
&& mCurrentGroup.getParent() == null
&& !mCurrentGroup.equals(recycleBin)) {
mAdapter.addNode(parent);
}
}
} else {
mHandler.post(new UIToastTask(ListNodesActivity.this, "Unrecoverable error: " + mMessage));
App.setShutdown();
finish();
}
}
}
}

View File

@@ -0,0 +1,297 @@
package com.kunzisoft.keepass.activities;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.adapters.NodeAdapter;
import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.database.PwDatabase;
import com.kunzisoft.keepass.database.PwGroup;
import com.kunzisoft.keepass.database.PwNode;
import com.kunzisoft.keepass.database.SortNodeEnum;
import com.kunzisoft.keepass.dialogs.SortDialogFragment;
import com.kunzisoft.keepass.settings.PreferencesUtil;
import com.kunzisoft.keepass.stylish.StylishFragment;
public class ListNodesFragment extends StylishFragment implements
SortDialogFragment.SortSelectionListener {
private static final String TAG = ListNodesFragment.class.getName();
private static final String GROUP_KEY = "GROUP_KEY";
private static final String IS_SEARCH = "IS_SEARCH";
private NodeAdapter.NodeClickCallback nodeClickCallback;
private NodeAdapter.NodeMenuListener nodeMenuListener;
private OnScrollListener onScrollListener;
private RecyclerView listView;
private PwGroup currentGroup;
private NodeAdapter mAdapter;
private View notFoundView;
private boolean isASearchResult;
// Preferences for sorting
private SharedPreferences prefs;
private boolean readOnly;
public static ListNodesFragment newInstance(PwGroup group, boolean readOnly, boolean isASearch) {
Bundle bundle = new Bundle();
if (group != null) {
bundle.putParcelable(GROUP_KEY, group);
}
bundle.putBoolean(IS_SEARCH, isASearch);
ReadOnlyHelper.putReadOnlyInBundle(bundle, readOnly);
ListNodesFragment listNodesFragment = new ListNodesFragment();
listNodesFragment.setArguments(bundle);
return listNodesFragment;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
try {
nodeClickCallback = (NodeAdapter.NodeClickCallback) context;
} catch (ClassCastException e) {
// The activity doesn't implement the interface, throw exception
throw new ClassCastException(context.toString()
+ " must implement " + NodeAdapter.NodeClickCallback.class.getName());
}
try {
nodeMenuListener = (NodeAdapter.NodeMenuListener) context;
} catch (ClassCastException e) {
nodeMenuListener = null;
// Context menu can be omit
Log.w(TAG, context.toString()
+ " must implement " + NodeAdapter.NodeMenuListener.class.getName());
}
try {
onScrollListener = (OnScrollListener) context;
} catch (ClassCastException e) {
onScrollListener = null;
// Context menu can be omit
Log.w(TAG, context.toString()
+ " must implement " + RecyclerView.OnScrollListener.class.getName());
}
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if ( getActivity() != null ) {
setHasOptionsMenu(true);
readOnly = ReadOnlyHelper.retrieveReadOnlyFromInstanceStateOrArguments(savedInstanceState, getArguments());
if (getArguments() != null) {
// Contains all the group in element
if (getArguments().containsKey(GROUP_KEY)) {
currentGroup = getArguments().getParcelable(GROUP_KEY);
}
if (getArguments().containsKey(IS_SEARCH)) {
isASearchResult = getArguments().getBoolean(IS_SEARCH);
}
}
mAdapter = new NodeAdapter(getContextThemed(), getActivity().getMenuInflater());
mAdapter.setReadOnly(readOnly);
mAdapter.setIsASearchResult(isASearchResult);
mAdapter.setOnNodeClickListener(nodeClickCallback);
if (nodeMenuListener != null) {
mAdapter.setActivateContextMenu(true);
mAdapter.setNodeMenuListener(nodeMenuListener);
}
prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
}
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
ReadOnlyHelper.onSaveInstanceState(outState, readOnly);
super.onSaveInstanceState(outState);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
// To apply theme
View rootView = inflater.cloneInContext(getContextThemed())
.inflate(R.layout.list_nodes_fragment, container, false);
listView = rootView.findViewById(R.id.nodes_list);
notFoundView = rootView.findViewById(R.id.not_found_container);
if (onScrollListener != null) {
listView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
onScrollListener.onScrolled(dy);
}
});
}
return rootView;
}
@Override
public void onResume() {
super.onResume();
rebuildList();
if (isASearchResult && mAdapter.isEmpty()) {
// To show the " no search entry found "
listView.setVisibility(View.GONE);
notFoundView.setVisibility(View.VISIBLE);
} else {
listView.setVisibility(View.VISIBLE);
notFoundView.setVisibility(View.GONE);
}
}
public void rebuildList() {
// Add elements to the list
if (currentGroup != null)
mAdapter.rebuildList(currentGroup);
assignListToNodeAdapter(listView);
}
protected void assignListToNodeAdapter(RecyclerView recyclerView) {
recyclerView.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(mAdapter);
}
@Override
public void onSortSelected(SortNodeEnum sortNodeEnum, boolean ascending, boolean groupsBefore, boolean recycleBinBottom) {
// Toggle setting
SharedPreferences.Editor editor = prefs.edit();
editor.putString(getString(R.string.sort_node_key), sortNodeEnum.name());
editor.putBoolean(getString(R.string.sort_ascending_key), ascending);
editor.putBoolean(getString(R.string.sort_group_before_key), groupsBefore);
editor.putBoolean(getString(R.string.sort_recycle_bin_bottom_key), recycleBinBottom);
editor.apply();
// Tell the adapter to refresh it's list
mAdapter.notifyChangeSort(sortNodeEnum, ascending, groupsBefore);
mAdapter.rebuildList(currentGroup);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.tree, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch ( item.getItemId() ) {
case R.id.menu_sort:
SortDialogFragment sortDialogFragment;
PwDatabase database = App.getDB().getPwDatabase();
/*
// TODO Recycle bin bottom
if (database.isRecycleBinAvailable() && database.isRecycleBinEnabled()) {
sortDialogFragment =
SortDialogFragment.getInstance(
PrefsUtil.getListSort(this),
PrefsUtil.getAscendingSort(this),
PrefsUtil.getGroupsBeforeSort(this),
PrefsUtil.getRecycleBinBottomSort(this));
} else {
*/
sortDialogFragment =
SortDialogFragment.getInstance(
PreferencesUtil.getListSort(getContext()),
PreferencesUtil.getAscendingSort(getContext()),
PreferencesUtil.getGroupsBeforeSort(getContext()));
//}
sortDialogFragment.show(getChildFragmentManager(), "sortDialog");
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case EntryEditActivity.ADD_OR_UPDATE_ENTRY_REQUEST_CODE:
if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE ||
resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE) {
PwNode newNode = data.getParcelableExtra(EntryEditActivity.ADD_OR_UPDATE_ENTRY_KEY);
if (newNode != null) {
if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE)
mAdapter.addNode(newNode);
if (resultCode == EntryEditActivity.UPDATE_ENTRY_RESULT_CODE) {
//mAdapter.updateLastNodeRegister(newNode);
mAdapter.rebuildList(currentGroup);
}
} else {
Log.e(this.getClass().getName(), "New node can be retrieve in Activity Result");
}
}
break;
}
}
public boolean isEmpty() {
return mAdapter == null || mAdapter.getItemCount() <= 0;
}
public void addNode(PwNode newNode) {
mAdapter.addNode(newNode);
}
public void updateNode(PwNode oldNode, PwNode newNode) {
mAdapter.updateNode(oldNode, newNode);
}
public void removeNode(PwNode pwNode) {
mAdapter.removeNode(pwNode);
}
public PwGroup getMainGroup() {
return currentGroup;
}
public interface OnScrollListener {
/**
* Callback method to be invoked when the RecyclerView has been scrolled. This will be
* called after the scroll has completed.
*
* @param dy The amount of vertical scroll.
*/
void onScrolled(int dy);
}
}

View File

@@ -0,0 +1,61 @@
package com.kunzisoft.keepass.activities;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.kunzisoft.keepass.settings.PreferencesUtil;
public class ReadOnlyHelper {
public static final String READ_ONLY_KEY = "READ_ONLY_KEY";
public static final boolean READ_ONLY_DEFAULT = false;
public static boolean retrieveReadOnlyFromInstanceStateOrPreference(Context context, Bundle savedInstanceState) {
boolean readOnly;
if (savedInstanceState != null
&& savedInstanceState.containsKey(READ_ONLY_KEY)) {
readOnly = savedInstanceState.getBoolean(READ_ONLY_KEY);
} else {
readOnly = PreferencesUtil.enableReadOnlyDatabase(context);
}
return readOnly;
}
public static boolean retrieveReadOnlyFromInstanceStateOrArguments(Bundle savedInstanceState, Bundle arguments) {
boolean readOnly = READ_ONLY_DEFAULT;
if (savedInstanceState != null
&& savedInstanceState.containsKey(READ_ONLY_KEY)) {
readOnly = savedInstanceState.getBoolean(READ_ONLY_KEY);
} else if (arguments != null
&& arguments.containsKey(READ_ONLY_KEY)) {
readOnly = arguments.getBoolean(READ_ONLY_KEY);
}
return readOnly;
}
public static boolean retrieveReadOnlyFromInstanceStateOrIntent(Bundle savedInstanceState, Intent intent) {
boolean readOnly = READ_ONLY_DEFAULT;
if (savedInstanceState != null
&& savedInstanceState.containsKey(READ_ONLY_KEY)) {
readOnly = savedInstanceState.getBoolean(READ_ONLY_KEY);
} else {
if (intent != null)
readOnly = intent.getBooleanExtra(READ_ONLY_KEY, READ_ONLY_DEFAULT);
}
return readOnly;
}
public static void putReadOnlyInIntent(Intent intent, boolean readOnly) {
intent.putExtra(READ_ONLY_KEY, readOnly);
}
public static void putReadOnlyInBundle(Bundle bundle, boolean readOnly) {
bundle.putBoolean(READ_ONLY_KEY, readOnly);
}
public static void onSaveInstanceState(Bundle outState, boolean readOnly) {
outState.putBoolean(READ_ONLY_KEY, readOnly);
}
}

View File

@@ -29,6 +29,7 @@ abstract class BasicViewHolder extends RecyclerView.ViewHolder {
View container; View container;
ImageView icon; ImageView icon;
TextView text; TextView text;
TextView subText;
BasicViewHolder(View itemView) { BasicViewHolder(View itemView) {
super(itemView); super(itemView);

View File

@@ -20,8 +20,6 @@
package com.kunzisoft.keepass.adapters; package com.kunzisoft.keepass.adapters;
import android.view.View; import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
@@ -30,7 +28,8 @@ class EntryViewHolder extends BasicViewHolder {
EntryViewHolder(View itemView) { EntryViewHolder(View itemView) {
super(itemView); super(itemView);
container = itemView.findViewById(R.id.entry_container); container = itemView.findViewById(R.id.entry_container);
icon = (ImageView) itemView.findViewById(R.id.entry_icon); icon = itemView.findViewById(R.id.entry_icon);
text = (TextView) itemView.findViewById(R.id.entry_text); text = itemView.findViewById(R.id.entry_text);
subText = itemView.findViewById(R.id.entry_subtext);
} }
} }

View File

@@ -20,8 +20,6 @@
package com.kunzisoft.keepass.adapters; package com.kunzisoft.keepass.adapters;
import android.view.View; import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
@@ -30,7 +28,8 @@ class GroupViewHolder extends BasicViewHolder {
GroupViewHolder(View itemView) { GroupViewHolder(View itemView) {
super(itemView); super(itemView);
container = itemView.findViewById(R.id.group_container); container = itemView.findViewById(R.id.group_container);
icon = (ImageView) itemView.findViewById(R.id.group_icon); icon = itemView.findViewById(R.id.group_icon);
text = (TextView) itemView.findViewById(R.id.group_text); text = itemView.findViewById(R.id.group_text);
subText = itemView.findViewById(R.id.group_subtext);
} }
} }

View File

@@ -26,35 +26,49 @@ import android.support.annotation.NonNull;
import android.support.v7.util.SortedList; import android.support.v7.util.SortedList;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.util.SortedListAdapterCallback; import android.support.v7.widget.util.SortedListAdapterCallback;
import android.util.Log;
import android.util.TypedValue;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Toast;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.app.App; import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.PwGroup; import com.kunzisoft.keepass.database.PwGroup;
import com.kunzisoft.keepass.database.PwNode; import com.kunzisoft.keepass.database.PwNode;
import com.kunzisoft.keepass.database.SortNodeEnum; import com.kunzisoft.keepass.database.SortNodeEnum;
import com.kunzisoft.keepass.icons.IconPackChooser;
import com.kunzisoft.keepass.settings.PreferencesUtil; import com.kunzisoft.keepass.settings.PreferencesUtil;
import com.kunzisoft.keepass.utils.Util;
public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> { public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
private static final String TAG = NodeAdapter.class.getName();
private SortedList<PwNode> nodeSortedList; private SortedList<PwNode> nodeSortedList;
private Context context; private Context context;
private LayoutInflater inflater; private LayoutInflater inflater;
private MenuInflater menuInflater;
private float textSize; private float textSize;
private float subtextSize;
private float iconSize;
private SortNodeEnum listSort; private SortNodeEnum listSort;
private boolean groupsBeforeSort; private boolean groupsBeforeSort;
private boolean ascendingSort; private boolean ascendingSort;
private boolean showUsernames;
private OnNodeClickCallback onNodeClickCallback; private NodeClickCallback nodeClickCallback;
private NodeMenuListener nodeMenuListener; private NodeMenuListener nodeMenuListener;
private boolean activateContextMenu; private boolean activateContextMenu;
private boolean readOnly;
private boolean isASearchResult;
private Database database;
private int iconGroupColor; private int iconGroupColor;
private int iconEntryColor; private int iconEntryColor;
@@ -63,14 +77,14 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
* Create node list adapter with contextMenu or not * Create node list adapter with contextMenu or not
* @param context Context to use * @param context Context to use
*/ */
public NodeAdapter(final Context context) { public NodeAdapter(final Context context, MenuInflater menuInflater) {
this.inflater = LayoutInflater.from(context); this.inflater = LayoutInflater.from(context);
this.menuInflater = menuInflater;
this.context = context; this.context = context;
this.textSize = PreferencesUtil.getListTextSize(context); assignPreferences();
this.listSort = PreferencesUtil.getListSort(context);
this.groupsBeforeSort = PreferencesUtil.getGroupsBeforeSort(context);
this.ascendingSort = PreferencesUtil.getAscendingSort(context);
this.activateContextMenu = false; this.activateContextMenu = false;
this.readOnly = false;
this.isASearchResult = false;
this.nodeSortedList = new SortedList<>(PwNode.class, new SortedListAdapterCallback<PwNode>(this) { this.nodeSortedList = new SortedList<>(PwNode.class, new SortedListAdapterCallback<PwNode>(this) {
@Override public int compare(PwNode item1, PwNode item2) { @Override public int compare(PwNode item1, PwNode item2) {
@@ -86,6 +100,9 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
} }
}); });
// Database
this.database = App.getDB();
// Retrieve the color to tint the icon // Retrieve the color to tint the icon
int[] attrTextColorPrimary = {android.R.attr.textColorPrimary}; int[] attrTextColorPrimary = {android.R.attr.textColorPrimary};
TypedArray taTextColorPrimary = context.getTheme().obtainStyledAttributes(attrTextColorPrimary); TypedArray taTextColorPrimary = context.getTheme().obtainStyledAttributes(attrTextColorPrimary);
@@ -97,20 +114,55 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
taTextColor.recycle(); taTextColor.recycle();
} }
public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}
public void setIsASearchResult(boolean isASearchResult) {
this.isASearchResult = isASearchResult;
}
public void setActivateContextMenu(boolean activate) { public void setActivateContextMenu(boolean activate) {
this.activateContextMenu = activate; this.activateContextMenu = activate;
} }
private void assignPreferences() {
float textSizeDefault = Util.getListTextDefaultSize(context);
this.textSize = PreferencesUtil.getListTextSize(context);
this.subtextSize = context.getResources().getInteger(R.integer.list_small_size_default)
* textSize / textSizeDefault;
// Retrieve the icon size
float iconDefaultSize = context.getResources().getDimension(R.dimen.list_icon_size_default);
this.iconSize = iconDefaultSize * textSize / textSizeDefault;
this.listSort = PreferencesUtil.getListSort(context);
this.groupsBeforeSort = PreferencesUtil.getGroupsBeforeSort(context);
this.ascendingSort = PreferencesUtil.getAscendingSort(context);
this.showUsernames = PreferencesUtil.showUsernamesListEntries(context);
}
/** /**
* Rebuild the list by clear and build children from the group * Rebuild the list by clear and build children from the group
*/ */
public void rebuildList(PwGroup group) { public void rebuildList(PwGroup group) {
this.nodeSortedList.clear(); this.nodeSortedList.clear();
if (group != null) { assignPreferences();
// TODO verify sort
try {
this.nodeSortedList.addAll(group.getDirectChildren()); this.nodeSortedList.addAll(group.getDirectChildren());
} catch (Exception e) {
Log.e(TAG, "Can't add node elements to the list", e);
Toast.makeText(context, "Can't add node elements to the list : " + e.getMessage(), Toast.LENGTH_LONG).show();
} }
} }
/**
* Determine if the adapter contains or not any element
* @return true if the list is empty
*/
public boolean isEmpty() {
return nodeSortedList.size() <= 0;
}
/** /**
* Add a node to the list * Add a node to the list
* @param node Node to add * @param node Node to add
@@ -172,32 +224,51 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
public void onBindViewHolder(@NonNull BasicViewHolder holder, int position) { public void onBindViewHolder(@NonNull BasicViewHolder holder, int position) {
PwNode subNode = nodeSortedList.get(position); PwNode subNode = nodeSortedList.get(position);
// Assign image // Assign image
if (IconPackChooser.getSelectedIconPack(context).tintable()) { int iconColor = Color.BLACK;
int iconColor = Color.BLACK; switch (subNode.getType()) {
switch (subNode.getType()) { case GROUP:
case GROUP: iconColor = iconGroupColor;
iconColor = iconGroupColor; break;
break; case ENTRY:
case ENTRY: iconColor = iconEntryColor;
iconColor = iconEntryColor; break;
break;
}
App.getDB().getDrawFactory().assignDatabaseIconTo(context, holder.icon, subNode.getIcon(), true, iconColor);
} else {
App.getDB().getDrawFactory().assignDatabaseIconTo(context, holder.icon, subNode.getIcon());
} }
database.getDrawFactory().assignDatabaseIconTo(context, holder.icon, subNode.getIcon(), iconColor);
// Assign text // Assign text
holder.text.setText(subNode.getDisplayTitle()); holder.text.setText(subNode.getTitle());
// Assign click // Assign click
holder.container.setOnClickListener( holder.container.setOnClickListener(
new OnNodeClickListener(subNode)); new OnNodeClickListener(subNode));
// Context menu // Context menu
if (activateContextMenu) { if (activateContextMenu) {
holder.container.setOnCreateContextMenuListener( holder.container.setOnCreateContextMenuListener(
new ContextMenuBuilder(subNode, nodeMenuListener)); new ContextMenuBuilder(subNode, nodeMenuListener, readOnly));
} }
// Assign text size
// Add username
holder.subText.setText("");
holder.subText.setVisibility(View.GONE);
if (subNode.getType().equals(PwNode.Type.ENTRY)) {
PwEntry entry = (PwEntry) subNode;
entry.startToManageFieldReferences(database.getPwDatabase());
holder.text.setText(entry.getVisualTitle());
String username = entry.getUsername();
if (showUsernames && !username.isEmpty()) {
holder.subText.setVisibility(View.VISIBLE);
holder.subText.setText(username);
}
entry.stopToManageFieldReferences();
}
// Assign image and text size
// Relative size of the icon
holder.icon.getLayoutParams().height = ((int) iconSize);
holder.icon.getLayoutParams().width = ((int) iconSize);
holder.text.setTextSize(textSize); holder.text.setTextSize(textSize);
holder.subText.setTextSize(subtextSize);
} }
@Override @Override
@@ -208,8 +279,8 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
/** /**
* Assign a listener when a node is clicked * Assign a listener when a node is clicked
*/ */
public void setOnNodeClickListener(OnNodeClickCallback onNodeClickCallback) { public void setOnNodeClickListener(NodeClickCallback nodeClickCallback) {
this.onNodeClickCallback = onNodeClickCallback; this.nodeClickCallback = nodeClickCallback;
} }
/** /**
@@ -222,7 +293,7 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
/** /**
* Callback listener to redefine to do an action when a node is click * Callback listener to redefine to do an action when a node is click
*/ */
public interface OnNodeClickCallback { public interface NodeClickCallback {
void onNodeClick(PwNode node); void onNodeClick(PwNode node);
} }
@@ -232,6 +303,8 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
public interface NodeMenuListener { public interface NodeMenuListener {
boolean onOpenMenuClick(PwNode node); boolean onOpenMenuClick(PwNode node);
boolean onEditMenuClick(PwNode node); boolean onEditMenuClick(PwNode node);
boolean onCopyMenuClick(PwNode node);
boolean onMoveMenuClick(PwNode node);
boolean onDeleteMenuClick(PwNode node); boolean onDeleteMenuClick(PwNode node);
} }
@@ -247,8 +320,8 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (onNodeClickCallback != null) if (nodeClickCallback != null)
onNodeClickCallback.onNodeClick(node); nodeClickCallback.onNodeClick(node);
} }
} }
@@ -257,29 +330,60 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
*/ */
private class ContextMenuBuilder implements View.OnCreateContextMenuListener { private class ContextMenuBuilder implements View.OnCreateContextMenuListener {
private static final int MENU_OPEN = Menu.FIRST;
private static final int MENU_EDIT = MENU_OPEN + 1;
private static final int MENU_DELETE = MENU_EDIT + 1;
private PwNode node; private PwNode node;
private NodeMenuListener menuListener; private NodeMenuListener menuListener;
private boolean readOnly;
ContextMenuBuilder(PwNode node, NodeMenuListener menuListener) { ContextMenuBuilder(PwNode node, NodeMenuListener menuListener, boolean readOnly) {
this.menuListener = menuListener; this.menuListener = menuListener;
this.node = node; this.node = node;
this.readOnly = readOnly;
} }
@Override @Override
public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) { public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) {
MenuItem clearMenu = contextMenu.add(Menu.NONE, MENU_OPEN, Menu.NONE, R.string.menu_open); menuInflater.inflate(R.menu.node_menu, contextMenu);
clearMenu.setOnMenuItemClickListener(mOnMyActionClickListener);
if (!App.getDB().isReadOnly() && !node.equals(App.getDB().getPwDatabase().getRecycleBin())) { // Opening
// Edition MenuItem menuItem = contextMenu.findItem(R.id.menu_open);
clearMenu = contextMenu.add(Menu.NONE, MENU_EDIT, Menu.NONE, R.string.menu_edit); menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
clearMenu.setOnMenuItemClickListener(mOnMyActionClickListener);
// Deletion // Edition
clearMenu = contextMenu.add(Menu.NONE, MENU_DELETE, Menu.NONE, R.string.menu_delete); if (readOnly || node.equals(App.getDB().getPwDatabase().getRecycleBin())) {
clearMenu.setOnMenuItemClickListener(mOnMyActionClickListener); contextMenu.removeItem(R.id.menu_edit);
} else {
menuItem = contextMenu.findItem(R.id.menu_edit);
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
}
// Copy (not for group)
if (readOnly
|| isASearchResult
|| node.equals(App.getDB().getPwDatabase().getRecycleBin())
|| node.getType().equals(PwNode.Type.GROUP)) {
// TODO COPY For Group
contextMenu.removeItem(R.id.menu_copy);
} else {
menuItem = contextMenu.findItem(R.id.menu_copy);
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
}
// Move
if (readOnly
|| isASearchResult
|| node.equals(App.getDB().getPwDatabase().getRecycleBin())) {
contextMenu.removeItem(R.id.menu_move);
} else {
menuItem = contextMenu.findItem(R.id.menu_move);
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
}
// Deletion
if (readOnly || node.equals(App.getDB().getPwDatabase().getRecycleBin())) {
contextMenu.removeItem(R.id.menu_delete);
} else {
menuItem = contextMenu.findItem(R.id.menu_delete);
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
} }
} }
@@ -289,11 +393,15 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
if (menuListener == null) if (menuListener == null)
return false; return false;
switch ( item.getItemId() ) { switch ( item.getItemId() ) {
case MENU_OPEN: case R.id.menu_open:
return menuListener.onOpenMenuClick(node); return menuListener.onOpenMenuClick(node);
case MENU_EDIT: case R.id.menu_edit:
return menuListener.onEditMenuClick(node); return menuListener.onEditMenuClick(node);
case MENU_DELETE: case R.id.menu_copy:
return menuListener.onCopyMenuClick(node);
case R.id.menu_move:
return menuListener.onMoveMenuClick(node);
case R.id.menu_delete:
return menuListener.onDeleteMenuClick(node); return menuListener.onDeleteMenuClick(node);
default: default:
return false; return false;

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.adapters;
import android.content.Context;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.Color;
import android.support.v4.widget.CursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.PwIcon;
import com.kunzisoft.keepass.database.PwIconFactory;
import com.kunzisoft.keepass.database.cursor.EntryCursor;
import com.kunzisoft.keepass.settings.PreferencesUtil;
import java.util.UUID;
public class SearchEntryCursorAdapter extends CursorAdapter {
private LayoutInflater cursorInflater;
private Database database;
private boolean displayUsername;
private int iconColor;
public SearchEntryCursorAdapter(Context context, Database database) {
super(context, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
cursorInflater = (LayoutInflater) context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
this.database = database;
// Get the icon color
int[] attrTextColor = {R.attr.textColorInverse};
TypedArray taTextColor = context.getTheme().obtainStyledAttributes(attrTextColor);
this.iconColor = taTextColor.getColor(0, Color.WHITE);
taTextColor.recycle();
reInit(context);
}
public void reInit(Context context) {
this.displayUsername = PreferencesUtil.showUsernamesListEntries(context);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view = cursorInflater.inflate(R.layout.search_entry, parent ,false);
ViewHolder viewHolder = new ViewHolder();
viewHolder.imageViewIcon = view.findViewById(R.id.entry_icon);
viewHolder.textViewTitle = view.findViewById(R.id.entry_text);
viewHolder.textViewSubTitle = view.findViewById(R.id.entry_subtext);
view.setTag(viewHolder);
return view;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
// Retrieve elements from cursor
UUID uuid = new UUID(cursor.getLong(cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_UUID_MOST_SIGNIFICANT_BITS)),
cursor.getLong(cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_UUID_LEAST_SIGNIFICANT_BITS)));
PwIconFactory iconFactory = database.getPwDatabase().getIconFactory();
PwIcon icon = iconFactory.getIcon(
new UUID(cursor.getLong(cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_ICON_CUSTOM_UUID_MOST_SIGNIFICANT_BITS)),
cursor.getLong(cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_ICON_CUSTOM_UUID_LEAST_SIGNIFICANT_BITS))));
if (icon.isUnknown()) {
icon = iconFactory.getIcon(cursor.getInt(cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_ICON_STANDARD)));
if (icon.isUnknown())
icon = iconFactory.getKeyIcon();
}
String title = cursor.getString( cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_TITLE) );
String username = cursor.getString( cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_USERNAME) );
String url = cursor.getString( cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_URL) );
ViewHolder viewHolder = (ViewHolder) view.getTag();
// Assign image
database.getDrawFactory().assignDatabaseIconTo(context, viewHolder.imageViewIcon, icon, iconColor);
// Assign title
String showTitle = PwEntry.getVisualTitle(false, title, username, url, uuid);
viewHolder.textViewTitle.setText(showTitle);
if (displayUsername && !username.isEmpty()) {
viewHolder.textViewSubTitle.setText(String.format("(%s)", username));
} else {
viewHolder.textViewSubTitle.setText("");
}
}
private static class ViewHolder {
ImageView imageViewIcon;
TextView textViewTitle;
TextView textViewSubTitle;
}
@Override
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
return database.searchEntry(constraint.toString());
}
public PwEntry getEntryFromPosition(int position) {
PwEntry pwEntry = null;
Cursor cursor = this.getCursor();
if (cursor.moveToFirst()
&&
cursor.move(position)) {
pwEntry = database.createEntry();
database.populateEntry(pwEntry, (EntryCursor) cursor);
}
return pwEntry;
}
}

View File

@@ -92,7 +92,7 @@ public class App extends MultiDexApplication {
@Override @Override
public void onTerminate() { public void onTerminate() {
if ( db != null ) { if ( db != null ) {
db.clear(); db.clear(getApplicationContext());
} }
super.onTerminate(); super.onTerminate();
} }

View File

@@ -54,7 +54,7 @@ public class AutoFillAuthActivity extends AppCompatActivity {
// Pass extra for Autofill (EXTRA_ASSIST_STRUCTURE) // Pass extra for Autofill (EXTRA_ASSIST_STRUCTURE)
AssistStructure assistStructure = autofillHelper.retrieveAssistStructure(getIntent()); AssistStructure assistStructure = autofillHelper.retrieveAssistStructure(getIntent());
if (assistStructure != null) { if (assistStructure != null) {
FileSelectActivity.launch(this, assistStructure); FileSelectActivity.launchForAutofillResult(this, assistStructure);
} else { } else {
setResult(RESULT_CANCELED); setResult(RESULT_CANCELED);
finish(); finish();

View File

@@ -36,6 +36,7 @@ import android.widget.RemoteViews;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.database.PwEntry; import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.selection.EntrySelectionHelper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -64,6 +65,7 @@ public class AutofillHelper {
public static void addAssistStructureExtraInIntent(Intent intent, AssistStructure assistStructure) { public static void addAssistStructureExtraInIntent(Intent intent, AssistStructure assistStructure) {
if (assistStructure != null) { if (assistStructure != null) {
EntrySelectionHelper.addEntrySelectionModeExtraInIntent(intent);
intent.putExtra(android.view.autofill.AutofillManager.EXTRA_ASSIST_STRUCTURE, assistStructure); intent.putExtra(android.view.autofill.AutofillManager.EXTRA_ASSIST_STRUCTURE, assistStructure);
} }
} }
@@ -144,7 +146,7 @@ public class AutofillHelper {
/** /**
* Utility method to loop and close each activity with return data * Utility method to loop and close each activity with return data
*/ */
public static void onActivityResultSetResult(Activity activity, int requestCode, int resultCode, Intent data) { public static void onActivityResultSetResultAndFinish(Activity activity, int requestCode, int resultCode, Intent data) {
if (requestCode == AUTOFILL_RESPONSE_REQUEST_CODE) { if (requestCode == AUTOFILL_RESPONSE_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
activity.setResult(resultCode, data); activity.setResult(resultCode, data);
@@ -152,15 +154,6 @@ public class AutofillHelper {
if (resultCode == Activity.RESULT_CANCELED) { if (resultCode == Activity.RESULT_CANCELED) {
activity.setResult(Activity.RESULT_CANCELED); activity.setResult(Activity.RESULT_CANCELED);
} }
}
}
/**
* Utility method to loop and close each activity with return data
*/
public static void onActivityResultSetResultAndFinish(Activity activity, int requestCode, int resultCode, Intent data) {
if (requestCode == AUTOFILL_RESPONSE_REQUEST_CODE) {
onActivityResultSetResult(activity, requestCode, resultCode, data);
activity.finish(); activity.finish();
} }
} }

View File

@@ -1,66 +0,0 @@
/*
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.compat;
import android.content.Context;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
@SuppressWarnings({"unchecked", "rawtypes"})
public class BackupManagerCompat {
private static Class classBackupManager;
private static Constructor constructorBackupManager;
private static Method dataChanged;
private Object backupManager;
static {
try {
classBackupManager = Class.forName("android.app.backup.BackupManager");
constructorBackupManager = classBackupManager.getConstructor(Context.class);
dataChanged = classBackupManager.getMethod("dataChanged", (Class[]) null);
} catch (Exception e) {
// Do nothing, class does not exist
}
}
public BackupManagerCompat(Context ctx) {
if (constructorBackupManager != null) {
try {
backupManager = constructorBackupManager.newInstance(ctx);
} catch (Exception e) {
// Do nothing
}
}
}
public void dataChanged() {
if (backupManager != null && dataChanged != null) {
try {
dataChanged.invoke(backupManager, (Object[]) null);
} catch (Exception e) {
// Do nothing
}
}
}
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.compat;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import java.lang.reflect.Constructor;
// This compatiblity hack can go away when support for Android 1.5 api level 3 is dropped
public class BitmapDrawableCompat {
private static Constructor<BitmapDrawable> constResBitmap;
static {
try {
constResBitmap = BitmapDrawable.class.getConstructor(Resources.class, Bitmap.class);
// This constructor is support in this api version
} catch (Exception e) {
// This constructor is not supported
}
}
public static BitmapDrawable getBitmapDrawable(Resources res, Bitmap bitmap) {
if (constResBitmap != null) {
try {
return constResBitmap.newInstance(res, bitmap);
} catch (Exception e) {
// Do nothing, fall through to the safe constructor
}
}
return new BitmapDrawable(bitmap);
}
}

View File

@@ -1,70 +0,0 @@
/*
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.compat;
import android.os.Build;
import java.lang.reflect.Field;
public class BuildCompat {
private static Field manufacturer;
private static String manuText;
public static final int VERSION_CODE_GINGERBREAD = 9;
public static final int VERSION_CODE_ICE_CREAM_SANDWICH = 14;
public static final int VERSION_CODE_JELLY_BEAN = 16;
public static final int VERSION_CODE_JELLY_BEAN_MR2 = 18;
public static final int VERSION_KITKAT = 19;
public static final int VERSION_CODE_M = 23;
private static Field versionSDK;
private static int versionInt;
static {
// MANUFACTURER is only available in API version 4 and later
try {
manufacturer = Build.class.getField("MANUFACTURER");
manuText = (String) manufacturer.get(null);
} catch (Exception e) {
manuText = "";
}
// SDK is only available in API version 4 and later
try {
versionSDK = Build.VERSION.class.getField("SDK_INT");
versionInt = versionSDK.getInt(null);
} catch (Exception e) {
try {
versionInt = Integer.parseInt(Build.VERSION.SDK);
} catch (Exception nfe) {
versionInt = -1;
}
}
}
public static String getManufacturer() {
return manuText;
}
public static int getSdkVersion() {
return versionInt;
}
}

View File

@@ -25,9 +25,6 @@ import android.net.Uri;
import java.lang.reflect.Method; import java.lang.reflect.Method;
public class ClipDataCompat { public class ClipDataCompat {
private static Class clipData;
private static Class clipDataItem;
private static Class clipDescription;
private static Method getClipDataFromIntent; private static Method getClipDataFromIntent;
private static Method getDescription; private static Method getDescription;
private static Method getItemCount; private static Method getItemCount;
@@ -39,14 +36,14 @@ public class ClipDataCompat {
static { static {
try { try {
clipData = Class.forName("android.content.ClipData"); Class clipData = Class.forName("android.content.ClipData");
getDescription = clipData.getMethod("getDescription", (Class[])null); getDescription = clipData.getMethod("getDescription", (Class[])null);
getItemCount = clipData.getMethod("getItemCount", (Class[])null); getItemCount = clipData.getMethod("getItemCount", (Class[])null);
getItemAt = clipData.getMethod("getItemAt", new Class[]{int.class}); getItemAt = clipData.getMethod("getItemAt", new Class[]{int.class});
clipDescription = Class.forName("android.content.ClipDescription"); Class clipDescription = Class.forName("android.content.ClipDescription");
getLabel = clipDescription.getMethod("getLabel", (Class[])null); getLabel = clipDescription.getMethod("getLabel", (Class[])null);
clipDataItem = Class.forName("android.content.ClipData$Item"); Class clipDataItem = Class.forName("android.content.ClipData$Item");
getUri = clipDataItem.getMethod("getUri", (Class[])null); getUri = clipDataItem.getMethod("getUri", (Class[])null);
getClipDataFromIntent = Intent.class.getMethod("getClipData", (Class[])null); getClipDataFromIntent = Intent.class.getMethod("getClipData", (Class[])null);
@@ -58,7 +55,6 @@ public class ClipDataCompat {
} }
public static Uri getUriFromIntent(Intent i, String key) { public static Uri getUriFromIntent(Intent i, String key) {
boolean clipDataSucceeded = false;
if (initSucceded) { if (initSucceded) {
try { try {
Object clip = getClipDataFromIntent.invoke(i); Object clip = getClipDataFromIntent.invoke(i);

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.compat;
import android.content.ContentResolver;
import android.net.Uri;
import java.lang.reflect.Method;
public class ContentResolverCompat {
public static boolean available;
private static Class contentResolver;
private static Method takePersistableUriPermission;
static {
try {
contentResolver = ContentResolver.class;
takePersistableUriPermission = contentResolver.getMethod("takePersistableUriPermission", new Class[]{Uri.class, int.class});
available = true;
} catch (Exception e) {
available = false;
}
}
public static void takePersistableUriPermission(ContentResolver resolver, Uri uri, int modeFlags) {
if (available) {
try {
takePersistableUriPermission.invoke(resolver, new Object[]{uri, modeFlags});
} catch (Exception e) {
// Fail silently
}
}
}
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.compat;
import android.app.Activity;
import android.content.SharedPreferences;
import java.lang.reflect.Method;
public class EditorCompat {
private static Method apply;
static {
try {
apply = Activity.class.getMethod("apply", (Class<SharedPreferences.Editor>[]) null);
} catch (Exception e) {
// Substitute commit for apply when not available (API level < 9)
try {
apply = Activity.class.getMethod("commit", (Class<SharedPreferences.Editor>[]) null);
} catch (Exception f) {
// Should be impossible, but leave apply null in this case
}
}
}
public static void apply(SharedPreferences.Editor edit) {
try {
apply.invoke(edit, (Object[]) null);
} catch (Exception e) {
// Shouldn't be possible, but call commit directly if this happens
edit.commit();
}
}
}

View File

@@ -44,7 +44,6 @@ public final class PRNGFixes {
private static final byte[] BUILD_FINGERPRINT_AND_DEVICE_SERIAL = private static final byte[] BUILD_FINGERPRINT_AND_DEVICE_SERIAL =
getBuildFingerprintAndDeviceSerial(); getBuildFingerprintAndDeviceSerial();
private static int sdkVersion = BuildCompat.getSdkVersion();
/** Hidden constructor to prevent instantiation. */ /** Hidden constructor to prevent instantiation. */
private PRNGFixes() {} private PRNGFixes() {}
@@ -67,11 +66,11 @@ public final class PRNGFixes {
private static boolean supportedOnThisDevice() { private static boolean supportedOnThisDevice() {
// Blacklist on samsung devices // Blacklist on samsung devices
if (StrUtil.indexOfIgnoreCase(BuildCompat.getManufacturer(), "samsung", Locale.ENGLISH) >= 0) { if (StrUtil.indexOfIgnoreCase(Build.MANUFACTURER, "samsung", Locale.ENGLISH) >= 0) {
return false; return false;
} }
if (sdkVersion > BuildCompat.VERSION_CODE_JELLY_BEAN_MR2) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
return false; return false;
} }
@@ -126,8 +125,8 @@ public final class PRNGFixes {
* @throws SecurityException if the fix is needed but could not be applied. * @throws SecurityException if the fix is needed but could not be applied.
*/ */
private static void applyOpenSSLFix() throws SecurityException { private static void applyOpenSSLFix() throws SecurityException {
if ((sdkVersion < BuildCompat.VERSION_CODE_JELLY_BEAN) if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
|| (sdkVersion > BuildCompat.VERSION_CODE_JELLY_BEAN_MR2)) { || (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2)) {
// No need to apply the fix // No need to apply the fix
return; return;
} }
@@ -162,7 +161,7 @@ public final class PRNGFixes {
*/ */
private static void installLinuxPRNGSecureRandom() private static void installLinuxPRNGSecureRandom()
throws SecurityException { throws SecurityException {
if (sdkVersion > BuildCompat.VERSION_CODE_JELLY_BEAN_MR2) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
// No need to apply the fix // No need to apply the fix
return; return;
} }

View File

@@ -22,6 +22,7 @@ package com.kunzisoft.keepass.compat;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Build;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
@@ -45,7 +46,7 @@ public class StorageAF {
} }
} }
public static boolean supportsStorageFramework() { return BuildCompat.getSdkVersion() >= BuildCompat.VERSION_KITKAT; } public static boolean supportsStorageFramework() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; }
public static boolean useStorageFramework(Context ctx) { public static boolean useStorageFramework(Context ctx) {
if (!supportsStorageFramework()) { return false; } if (!supportsStorageFramework()) { return false; }

View File

@@ -19,6 +19,9 @@
*/ */
package com.kunzisoft.keepass.crypto.keyDerivation; package com.kunzisoft.keepass.crypto.keyDerivation;
import android.content.res.Resources;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.crypto.CryptoUtil; import com.kunzisoft.keepass.crypto.CryptoUtil;
import com.kunzisoft.keepass.crypto.finalkey.FinalKey; import com.kunzisoft.keepass.crypto.finalkey.FinalKey;
import com.kunzisoft.keepass.crypto.finalkey.FinalKeyFactory; import com.kunzisoft.keepass.crypto.finalkey.FinalKeyFactory;
@@ -30,8 +33,8 @@ import java.util.UUID;
public class AesKdf extends KdfEngine { public class AesKdf extends KdfEngine {
public static final int DEFAULT_ROUNDS = 6000; private static final int DEFAULT_ROUNDS = 6000;
public static final String DEFAULT_NAME = "AES-KDF"; private static final String DEFAULT_NAME = "AES-KDF";
public static final UUID CIPHER_UUID = Types.bytestoUUID( public static final UUID CIPHER_UUID = Types.bytestoUUID(
new byte[]{(byte) 0xC9, (byte) 0xD9, (byte) 0xF3, (byte) 0x9A, (byte) 0x62, (byte) 0x8A, (byte) 0x44, (byte) 0x60, new byte[]{(byte) 0xC9, (byte) 0xD9, (byte) 0xF3, (byte) 0x9A, (byte) 0x62, (byte) 0x8A, (byte) 0x44, (byte) 0x60,
@@ -41,17 +44,22 @@ public class AesKdf extends KdfEngine {
public static final String ParamRounds = "R"; public static final String ParamRounds = "R";
public static final String ParamSeed = "S"; public static final String ParamSeed = "S";
public AesKdf() { AesKdf() {
uuid = CIPHER_UUID; setUUID(CIPHER_UUID);
} }
public String getName() { @Override
return DEFAULT_NAME; public String getName(Resources resources) {
if (resources == null)
return DEFAULT_NAME;
return resources.getString(R.string.kdf_AES);
} }
@Override @Override
public KdfParameters getDefaultParameters() { public KdfParameters getDefaultParameters() {
KdfParameters p = super.getDefaultParameters(); KdfParameters p = new KdfParameters(uuid);
p.setParamUUID();
p.setUInt32(ParamRounds, DEFAULT_ROUNDS); p.setUInt32(ParamRounds, DEFAULT_ROUNDS);
return p; return p;
@@ -93,4 +101,9 @@ public class AesKdf extends KdfEngine {
public void setKeyRounds(KdfParameters p, long keyRounds) { public void setKeyRounds(KdfParameters p, long keyRounds) {
p.setUInt64(ParamRounds, keyRounds); p.setUInt64(ParamRounds, keyRounds);
} }
@Override
public long getDefaultKeyRounds() {
return DEFAULT_ROUNDS;
}
} }

View File

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

View File

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

View File

@@ -19,31 +19,37 @@
*/ */
package com.kunzisoft.keepass.crypto.keyDerivation; package com.kunzisoft.keepass.crypto.keyDerivation;
import com.kunzisoft.keepass.database.exception.UnknownKDF;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
public class KdfFactory { public class KdfFactory {
public static List<KdfEngine> kdfList = new ArrayList<>(); public static AesKdf aesKdf = new AesKdf();
public static Argon2Kdf argon2Kdf = new Argon2Kdf();
public static List<KdfEngine> kdfListV3 = new ArrayList<>();
public static List<KdfEngine> kdfListV4 = new ArrayList<>();
static { static {
kdfList.add(new AesKdf()); kdfListV3.add(aesKdf);
kdfList.add(new Argon2Kdf());
kdfListV4.add(aesKdf);
kdfListV4.add(argon2Kdf);
} }
public static KdfParameters getDefaultParameters() { public static KdfEngine getEngineV4(KdfParameters kdfParameters) throws UnknownKDF {
return kdfList.get(0).getDefaultParameters(); UnknownKDF unknownKDFException = new UnknownKDF();
} if (kdfParameters == null) {
throw unknownKDFException;
public static KdfEngine get(UUID uuid) { }
for (KdfEngine engine: kdfList) { for (KdfEngine engine: kdfListV4) {
if (engine.uuid.equals(uuid)) { if (engine.getUUID().equals(kdfParameters.getUUID())) {
return engine; return engine;
} }
} }
throw unknownKDFException;
return null;
} }
} }

View File

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

View File

@@ -19,20 +19,57 @@
*/ */
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import java.io.Serializable; import android.os.Parcel;
import android.os.Parcelable;
import com.kunzisoft.keepass.utils.MemUtil;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
public class AutoType implements Cloneable, Serializable { public class AutoType implements Cloneable, Parcelable {
private static final long OBF_OPT_NONE = 0; private static final long OBF_OPT_NONE = 0;
public boolean enabled = true; public boolean enabled = true;
public long obfuscationOptions = OBF_OPT_NONE; public long obfuscationOptions = OBF_OPT_NONE;
public String defaultSequence = ""; public String defaultSequence = "";
private HashMap<String, String> windowSeqPairs = new HashMap<>(); private HashMap<String, String> windowSeqPairs = new HashMap<>();
public AutoType() {}
public AutoType(Parcel in) {
enabled = in.readByte() != 0;
obfuscationOptions = in.readLong();
defaultSequence = in.readString();
windowSeqPairs = MemUtil.readStringParcelableMap(in);
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeByte((byte) (enabled ? 1 : 0));
dest.writeLong(obfuscationOptions);
dest.writeString(defaultSequence);
MemUtil.writeStringParcelableMap(dest, windowSeqPairs);
}
public static final Parcelable.Creator<AutoType> CREATOR = new Parcelable.Creator<AutoType>() {
@Override
public AutoType createFromParcel(Parcel in) {
return new AutoType(in);
}
@Override
public AutoType[] newArray(int size) {
return new AutoType[size];
}
};
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public AutoType clone() { public AutoType clone() {
AutoType auto; AutoType auto;

View File

@@ -51,6 +51,8 @@ public class BinaryPool {
} }
public void clear() { public void clear() {
for (Entry<Integer, ProtectedBinary> entry: pool.entrySet())
entry.getValue().clear();
pool.clear(); pool.clear();
} }
@@ -63,30 +65,36 @@ public class BinaryPool {
@Override @Override
public boolean operate(PwEntryV4 entry) { public boolean operate(PwEntryV4 entry) {
for (PwEntryV4 histEntry : entry.getHistory()) { for (PwEntryV4 histEntry : entry.getHistory()) {
poolAdd(histEntry.getBinaries()); add(histEntry.getBinaries());
} }
poolAdd(entry.getBinaries()); add(entry.getBinaries());
return true; return true;
} }
} }
private void poolAdd(Map<String, ProtectedBinary> dict) { private void add(Map<String, ProtectedBinary> dict) {
for (ProtectedBinary pb : dict.values()) { for (ProtectedBinary pb : dict.values()) {
poolAdd(pb); add(pb);
} }
} }
public void poolAdd(ProtectedBinary pb) { public void add(ProtectedBinary pb) {
assert(pb != null); assert(pb != null);
if (findKey(pb) != -1) return;
if (poolFind(pb) != -1) return; pool.put(findUnusedKey(), pb);
pool.put(pool.size(), pb);
} }
public int findUnusedKey() {
int unusedKey = pool.size();
while(get(unusedKey) != null)
unusedKey++;
return unusedKey;
}
public int poolFind(ProtectedBinary pb) { public int findKey(ProtectedBinary pb) {
for (Entry<Integer, ProtectedBinary> pair : pool.entrySet()) { for (Entry<Integer, ProtectedBinary> pair : pool.entrySet()) {
if (pair.getValue().equals(pb)) return pair.getKey(); if (pair.getValue().equals(pb)) return pair.getKey();
} }

View File

@@ -20,25 +20,27 @@
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.preference.PreferenceManager;
import android.util.Log; 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.cursor.EntryCursor;
import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException; import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException;
import com.kunzisoft.keepass.database.exception.InvalidDBException; import com.kunzisoft.keepass.database.exception.InvalidDBException;
import com.kunzisoft.keepass.database.exception.InvalidPasswordException;
import com.kunzisoft.keepass.database.exception.PwDbOutputException; import com.kunzisoft.keepass.database.exception.PwDbOutputException;
import com.kunzisoft.keepass.database.load.Importer; import com.kunzisoft.keepass.database.load.Importer;
import com.kunzisoft.keepass.database.load.ImporterFactory; import com.kunzisoft.keepass.database.load.ImporterFactory;
import com.kunzisoft.keepass.database.save.PwDbOutput; import com.kunzisoft.keepass.database.save.PwDbOutput;
import com.kunzisoft.keepass.database.search.SearchDbHelper;
import com.kunzisoft.keepass.icons.IconDrawableFactory; import com.kunzisoft.keepass.icons.IconDrawableFactory;
import com.kunzisoft.keepass.search.SearchDbHelper; import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
import com.kunzisoft.keepass.tasks.UpdateStatus;
import com.kunzisoft.keepass.utils.UriUtil; import com.kunzisoft.keepass.utils.UriUtil;
import org.apache.commons.io.FileUtils;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@@ -47,13 +49,18 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.SyncFailedException; import java.io.SyncFailedException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import javax.annotation.Nullable;
public class Database { public class Database {
private static final String TAG = Database.class.getName(); private static final String TAG = Database.class.getName();
private PwDatabase pm; private PwDatabase pwDatabase;
private Uri mUri; private Uri mUri;
private SearchDbHelper searchHelper; private SearchDbHelper searchHelper;
private boolean readOnly = false; private boolean readOnly = false;
@@ -64,11 +71,11 @@ public class Database {
private boolean loaded = false; private boolean loaded = false;
public PwDatabase getPwDatabase() { public PwDatabase getPwDatabase() {
return pm; return pwDatabase;
} }
public void setPwDatabase(PwDatabase pm) { public void setPwDatabase(PwDatabase pm) {
this.pm = pm; this.pwDatabase = pm;
} }
public void setUri(Uri mUri) { public void setUri(Uri mUri) {
@@ -99,19 +106,11 @@ public class Database {
loaded = true; loaded = true;
} }
public void loadData(Context ctx, InputStream is, String password, InputStream keyInputStream) throws IOException, InvalidDBException { public void loadData(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status) throws IOException, FileNotFoundException, InvalidDBException {
loadData(ctx, is, password, keyInputStream, new UpdateStatus(), !Importer.DEBUG);
}
public void loadData(Context ctx, Uri uri, String password, Uri keyfile) throws IOException, FileNotFoundException, InvalidDBException {
loadData(ctx, uri, password, keyfile, new UpdateStatus(), !Importer.DEBUG);
}
public void loadData(Context ctx, Uri uri, String password, Uri keyfile, UpdateStatus status) throws IOException, FileNotFoundException, InvalidDBException {
loadData(ctx, uri, password, keyfile, status, !Importer.DEBUG); loadData(ctx, uri, password, keyfile, status, !Importer.DEBUG);
} }
public void loadData(Context ctx, Uri uri, String password, Uri keyfile, UpdateStatus status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException { private void loadData(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException {
mUri = uri; mUri = uri;
readOnly = false; readOnly = false;
if (uri.getScheme().equals("file")) { if (uri.getScheme().equals("file")) {
@@ -119,26 +118,10 @@ public class Database {
readOnly = !file.canWrite(); readOnly = !file.canWrite();
} }
try { passUrisAsInputStreams(ctx, uri, password, keyfile, status, debug);
passUrisAsInputStreams(ctx, uri, password, keyfile, status, debug, 0);
} catch (InvalidPasswordException e) {
// Retry with rounds fix
try {
passUrisAsInputStreams(ctx, uri, password, keyfile, status, debug, getFixRounds(ctx));
} catch (Exception e2) {
// Rethrow original exception
throw e;
}
}
} }
private long getFixRounds(Context ctx) { private void passUrisAsInputStreams(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
return prefs.getLong(ctx.getString(R.string.roundsFix_key), ctx.getResources().getInteger(R.integer.roundsFix_default));
}
private void passUrisAsInputStreams(Context ctx, Uri uri, String password, Uri keyfile, UpdateStatus status, boolean debug, long roundsFix) throws IOException, FileNotFoundException, InvalidDBException {
InputStream is, kfIs; InputStream is, kfIs;
try { try {
is = UriUtil.getUriInputStream(ctx, uri); is = UriUtil.getUriInputStream(ctx, uri);
@@ -153,18 +136,14 @@ public class Database {
Log.e("KPD", "Database::loadData", e); Log.e("KPD", "Database::loadData", e);
throw ContentFileNotFoundException.getInstance(keyfile); throw ContentFileNotFoundException.getInstance(keyfile);
} }
loadData(ctx, is, password, kfIs, status, debug, roundsFix); loadData(ctx, is, password, kfIs, status, debug);
} }
public void loadData(Context ctx, InputStream is, String password, InputStream kfIs, boolean debug) throws IOException, InvalidDBException { public void loadData(Context ctx, InputStream is, String password, InputStream keyFileInputStream, boolean debug) throws IOException, InvalidDBException {
loadData(ctx, is, password, kfIs, new UpdateStatus(), debug); loadData(ctx, is, password, keyFileInputStream, null, debug);
} }
public void loadData(Context ctx, InputStream is, String password, InputStream kfIs, UpdateStatus status, boolean debug) throws IOException, InvalidDBException { private void loadData(Context ctx, InputStream is, String password, InputStream keyFileInputStream, ProgressTaskUpdater progressTaskUpdater, boolean debug) throws IOException, InvalidDBException {
loadData(ctx, is, password, kfIs, status, debug, 0);
}
public void loadData(Context ctx, InputStream is, String password, InputStream kfIs, UpdateStatus status, boolean debug, long roundsFix) throws IOException, InvalidDBException {
BufferedInputStream bis = new BufferedInputStream(is); BufferedInputStream bis = new BufferedInputStream(is);
if ( ! bis.markSupported() ) { if ( ! bis.markSupported() ) {
@@ -174,24 +153,25 @@ public class Database {
// We'll end up reading 8 bytes to identify the header. Might as well use two extra. // We'll end up reading 8 bytes to identify the header. Might as well use two extra.
bis.mark(10); bis.mark(10);
Importer imp = ImporterFactory.createImporter(bis, debug); // Get the file directory to save the attachments
Importer databaseImporter = ImporterFactory.createImporter(bis, ctx.getFilesDir(), debug);
bis.reset(); // Return to the start bis.reset(); // Return to the start
pm = imp.openDatabase(bis, password, kfIs, status, roundsFix); pwDatabase = databaseImporter.openDatabase(bis, password, keyFileInputStream, progressTaskUpdater);
if ( pm != null ) { if ( pwDatabase != null ) {
try { try {
switch (pm.getVersion()) { switch (pwDatabase.getVersion()) {
case V3: case V3:
PwGroupV3 rootV3 = ((PwDatabaseV3) pm).getRootGroup(); PwGroupV3 rootV3 = ((PwDatabaseV3) pwDatabase).getRootGroup();
((PwDatabaseV3) pm).populateGlobals(rootV3); ((PwDatabaseV3) pwDatabase).populateGlobals(rootV3);
passwordEncodingError = !pm.validatePasswordEncoding(password); passwordEncodingError = !pwDatabase.validatePasswordEncoding(password);
searchHelper = new SearchDbHelper.SearchDbHelperV3(ctx); searchHelper = new SearchDbHelper.SearchDbHelperV3(ctx);
break; break;
case V4: case V4:
PwGroupV4 rootV4 = ((PwDatabaseV4) pm).getRootGroup(); PwGroupV4 rootV4 = ((PwDatabaseV4) pwDatabase).getRootGroup();
((PwDatabaseV4) pm).populateGlobals(rootV4); ((PwDatabaseV4) pwDatabase).populateGlobals(rootV4);
passwordEncodingError = !pm.validatePasswordEncoding(password); passwordEncodingError = !pwDatabase.validatePasswordEncoding(password);
searchHelper = new SearchDbHelper.SearchDbHelperV4(ctx); searchHelper = new SearchDbHelper.SearchDbHelperV4(ctx);
break; break;
} }
@@ -204,13 +184,17 @@ public class Database {
} }
public PwGroup search(String str) { public PwGroup search(String str) {
return search(str, Integer.MAX_VALUE);
}
public PwGroup search(String str, int max) {
if (searchHelper == null) { return null; } if (searchHelper == null) { return null; }
try { try {
switch (pm.getVersion()) { switch (pwDatabase.getVersion()) {
case V3: case V3:
return ((SearchDbHelper.SearchDbHelperV3) searchHelper).search(((PwDatabaseV3) pm), str); return ((SearchDbHelper.SearchDbHelperV3) searchHelper).search(((PwDatabaseV3) pwDatabase), str, max);
case V4: case V4:
return ((SearchDbHelper.SearchDbHelperV4) searchHelper).search(((PwDatabaseV4) pm), str); return ((SearchDbHelper.SearchDbHelperV4) searchHelper).search(((PwDatabaseV4) pwDatabase), str, max);
} }
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Search can't be performed with this SearchHelper", e); Log.e(TAG, "Search can't be performed with this SearchHelper", e);
@@ -218,23 +202,78 @@ public class Database {
return null; return null;
} }
public Cursor searchEntry(String query) {
final EntryCursor cursor = new EntryCursor();
// TODO real content provider
if (!query.isEmpty()) {
PwGroup searchResult = search(query, 6);
PwVersion version = getPwDatabase().getVersion();
if (searchResult != null) {
for (int i = 0; i < searchResult.numbersOfChildEntries(); i++) {
PwEntry entry = searchResult.getChildEntryAt(i);
if (!entry.isMetaStream()) { // TODO metastream
try {
switch (version) {
case V3:
cursor.addEntry((PwEntryV3) entry);
continue;
case V4:
cursor.addEntry((PwEntryV4) entry);
}
} catch (Exception e) {
Log.e(TAG, "Can't add PwEntry to the cursor", e);
}
}
}
}
}
return cursor;
}
public void populateEntry(PwEntry pwEntry, EntryCursor cursor) {
PwIconFactory iconFactory = getPwDatabase().getIconFactory();
try {
switch (getPwDatabase().getVersion()) {
case V3:
cursor.populateEntry((PwEntryV3) pwEntry, iconFactory);
break;
case V4:
// TODO invert field reference manager
pwEntry.startToManageFieldReferences(getPwDatabase());
cursor.populateEntry((PwEntryV4) pwEntry, iconFactory);
pwEntry.stopToManageFieldReferences();
break;
}
} catch (Exception e) {
Log.e(TAG, "This version of PwGroup can't be populated", e);
}
}
public void saveData(Context ctx) throws IOException, PwDbOutputException { public void saveData(Context ctx) throws IOException, PwDbOutputException {
saveData(ctx, mUri); saveData(ctx, mUri);
} }
public void saveData(Context ctx, Uri uri) throws IOException, PwDbOutputException { private void saveData(Context ctx, Uri uri) throws IOException, PwDbOutputException {
String errorMessage = "Failed to store database.";
if (uri.getScheme().equals("file")) { if (uri.getScheme().equals("file")) {
String filename = uri.getPath(); String filename = uri.getPath();
File tempFile = new File(filename + ".tmp"); File tempFile = new File(filename + ".tmp");
FileOutputStream fos = new FileOutputStream(tempFile);
//BufferedOutputStream bos = new BufferedOutputStream(fos);
//PwDbV3Output pmo = new PwDbV3Output(pm, bos, App.getCalendar()); FileOutputStream fos = null;
PwDbOutput pmo = PwDbOutput.getInstance(pm, fos); try {
pmo.output(); fos = new FileOutputStream(tempFile);
//bos.flush(); PwDbOutput pmo = PwDbOutput.getInstance(pwDatabase, fos);
//bos.close(); if (pmo != null)
fos.close(); pmo.output();
} catch (Exception e) {
Log.e(TAG, errorMessage, e);
throw new IOException(errorMessage, e);
} finally {
if (fos != null)
fos.close();
}
// Force data to disk before continuing // Force data to disk before continuing
try { try {
@@ -246,28 +285,41 @@ public class Database {
File orig = new File(filename); File orig = new File(filename);
if (!tempFile.renameTo(orig)) { if (!tempFile.renameTo(orig)) {
throw new IOException("Failed to store database."); throw new IOException(errorMessage);
} }
} }
else { else {
OutputStream os; OutputStream os = null;
try { try {
os = ctx.getContentResolver().openOutputStream(uri); os = ctx.getContentResolver().openOutputStream(uri);
PwDbOutput pmo = PwDbOutput.getInstance(pwDatabase, os);
if (pmo != null)
pmo.output();
} catch (Exception e) { } catch (Exception e) {
throw new IOException("Failed to store database."); Log.e(TAG, errorMessage, e);
throw new IOException(errorMessage, e);
} finally {
if (os != null)
os.close();
} }
PwDbOutput pmo = PwDbOutput.getInstance(pm, os);
pmo.output();
os.close();
} }
mUri = uri; mUri = uri;
} }
public void clear() { // TODO Clear database when lock broadcast is receive in backstage
public void clear(Context context) {
drawFactory.clearCache(); drawFactory.clearCache();
// Delete the cache of the database if present
if (pwDatabase != null)
pwDatabase.clearCache();
// In all cases, delete all the files in the temp dir
try {
FileUtils.cleanDirectory(context.getFilesDir());
} catch (IOException e) {
Log.e(TAG, "Unable to clear the directory cache.", e);
}
pm = null; pwDatabase = null;
mUri = null; mUri = null;
loaded = false; loaded = false;
passwordEncodingError = false; passwordEncodingError = false;
@@ -348,16 +400,88 @@ public class Database {
} }
} }
public PwEncryptionAlgorithm getEncryptionAlgorithm() {
return getPwDatabase().getEncryptionAlgorithm();
}
public List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms() {
switch (getPwDatabase().getVersion()) {
case V4:
return ((PwDatabaseV4) getPwDatabase()).getAvailableEncryptionAlgorithms();
case V3:
return ((PwDatabaseV3) getPwDatabase()).getAvailableEncryptionAlgorithms();
}
return new ArrayList<>();
}
public boolean allowEncryptionAlgorithmModification() {
return getAvailableEncryptionAlgorithms().size() > 1;
}
public void assignEncryptionAlgorithm(PwEncryptionAlgorithm algorithm) {
switch (getPwDatabase().getVersion()) {
case V4:
((PwDatabaseV4) getPwDatabase()).setEncryptionAlgorithm(algorithm);
((PwDatabaseV4) getPwDatabase()).setDataEngine(algorithm.getCipherEngine());
((PwDatabaseV4) getPwDatabase()).setDataCipher(algorithm.getDataCipher());
}
}
public String getEncryptionAlgorithmName(Resources resources) { public String getEncryptionAlgorithmName(Resources resources) {
return getPwDatabase().getEncryptionAlgorithm().getName(resources); return getPwDatabase().getEncryptionAlgorithm().getName(resources);
} }
public String getKeyDerivationName() { public List<KdfEngine> getAvailableKdfEngines() {
return getPwDatabase().getKeyDerivationName(); switch (getPwDatabase().getVersion()) {
case V4:
return KdfFactory.kdfListV4;
case V3:
return KdfFactory.kdfListV3;
}
return new ArrayList<>();
}
public boolean allowKdfModification() {
return getAvailableKdfEngines().size() > 1;
}
public KdfEngine getKdfEngine() {
switch (getPwDatabase().getVersion()) {
case V4:
KdfEngine kdfEngine = ((PwDatabaseV4) getPwDatabase()).getKdfEngine();
if (kdfEngine == null)
return KdfFactory.aesKdf;
return kdfEngine;
default:
case V3:
return KdfFactory.aesKdf;
}
}
public void assignKdfEngine(KdfEngine kdfEngine) {
switch (getPwDatabase().getVersion()) {
case V4:
PwDatabaseV4 db = ((PwDatabaseV4) getPwDatabase());
if (db.getKdfParameters() == null
|| !db.getKdfParameters().getUUID().equals(kdfEngine.getDefaultParameters().getUUID()))
db.setKdfParameters(kdfEngine.getDefaultParameters());
setNumberKeyEncryptionRounds(kdfEngine.getDefaultKeyRounds());
setMemoryUsage(kdfEngine.getDefaultMemoryUsage());
setParallelism(kdfEngine.getDefaultParallelism());
break;
}
}
public String getKeyDerivationName(Resources resources) {
KdfEngine kdfEngine = getKdfEngine();
if (kdfEngine != null) {
return kdfEngine.getName(resources);
}
return "";
} }
public String getNumberKeyEncryptionRoundsAsString() { public String getNumberKeyEncryptionRoundsAsString() {
return Long.toString(getPwDatabase().getNumberKeyEncryptionRounds()); return Long.toString(getNumberKeyEncryptionRounds());
} }
public long getNumberKeyEncryptionRounds() { public long getNumberKeyEncryptionRounds() {
@@ -368,19 +492,60 @@ public class Database {
getPwDatabase().setNumberKeyEncryptionRounds(numberRounds); getPwDatabase().setNumberKeyEncryptionRounds(numberRounds);
} }
public PwEntry createEntry(PwGroup parent) { public String getMemoryUsageAsString() {
PwEntry newPwEntry = null; 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() {
return createEntry(null);
}
public PwEntry createEntry(@Nullable PwGroup parent) {
try { try {
switch (getPwDatabase().getVersion()) { switch (getPwDatabase().getVersion()) {
case V3: case V3:
newPwEntry = new PwEntryV3((PwGroupV3) parent); return new PwEntryV3((PwGroupV3) parent);
case V4: case V4:
newPwEntry = new PwEntryV4((PwGroupV4) parent); return new PwEntryV4((PwGroupV4) parent);
} }
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "This version of PwEntry can't be created", e); Log.e(TAG, "This version of PwEntry can't be created", e);
} }
return newPwEntry; return null;
} }
public PwGroup createGroup(PwGroup parent) { public PwGroup createGroup(PwGroup parent) {
@@ -392,7 +557,7 @@ public class Database {
case V4: case V4:
newPwGroup = new PwGroupV4((PwGroupV4) parent); newPwGroup = new PwGroupV4((PwGroupV4) parent);
} }
newPwGroup.setId(pm.newGroupId()); newPwGroup.setId(pwDatabase.newGroupId());
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "This version of PwGroup can't be created", e); Log.e(TAG, "This version of PwGroup can't be created", e);
} }
@@ -547,6 +712,44 @@ public class Database {
} }
} }
/**
* @return A duplicate entry with the same values, a new UUID,
* @param entryToCopy
* @param newParent
*/
public @Nullable PwEntry copyEntry(PwEntry entryToCopy, PwGroup newParent) {
try {
// TODO encapsulate
switch (getPwDatabase().getVersion()) {
case V3:
PwEntryV3 entryV3Copied = ((PwEntryV3) entryToCopy).clone();
entryV3Copied.setUUID(UUID.randomUUID());
entryV3Copied.setParent((PwGroupV3) newParent);
addEntryTo(entryV3Copied, newParent);
return entryV3Copied;
case V4:
PwEntryV4 entryV4Copied = ((PwEntryV4) entryToCopy).clone();
entryV4Copied.setUUID(UUID.randomUUID());
entryV4Copied.setParent((PwGroupV4) newParent);
addEntryTo(entryV4Copied, newParent);
return entryV4Copied;
}
} catch (Exception e) {
Log.e(TAG, "This version of PwEntry can't be updated", e);
}
return null;
}
public void moveEntry(PwEntry entryToMove, PwGroup newParent) {
removeEntryFrom(entryToMove, entryToMove.parent);
addEntryTo(entryToMove, newParent);
}
public void moveGroup(PwGroup groupToMove, PwGroup newParent) {
removeGroupFrom(groupToMove, groupToMove.parent);
addGroupTo(groupToMove, newParent);
}
public void deleteEntry(PwEntry entry) { public void deleteEntry(PwEntry entry) {
try { try {
switch (getPwDatabase().getVersion()) { switch (getPwDatabase().getVersion()) {

View File

@@ -19,9 +19,12 @@
*/ */
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import com.kunzisoft.keepass.database.security.ProtectedString; import android.os.Parcel;
import android.os.Parcelable;
import com.kunzisoft.keepass.database.security.ProtectedString;
import com.kunzisoft.keepass.utils.MemUtil;
import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
@@ -32,7 +35,7 @@ import static com.kunzisoft.keepass.database.PwEntryV4.STR_TITLE;
import static com.kunzisoft.keepass.database.PwEntryV4.STR_URL; import static com.kunzisoft.keepass.database.PwEntryV4.STR_URL;
import static com.kunzisoft.keepass.database.PwEntryV4.STR_USERNAME; import static com.kunzisoft.keepass.database.PwEntryV4.STR_USERNAME;
public class ExtraFields implements Serializable, Cloneable { public class ExtraFields implements Parcelable, Cloneable {
private Map<String, ProtectedString> fields; private Map<String, ProtectedString> fields;
@@ -40,10 +43,52 @@ public class ExtraFields implements Serializable, Cloneable {
fields = new HashMap<>(); fields = new HashMap<>();
} }
public ExtraFields(Parcel in) {
fields = MemUtil.readStringParcelableMap(in, ProtectedString.class);
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
MemUtil.writeStringParcelableMap(dest, flags, fields);
}
public static final Parcelable.Creator<ExtraFields> CREATOR = new Parcelable.Creator<ExtraFields>() {
@Override
public ExtraFields createFromParcel(Parcel in) {
return new ExtraFields(in);
}
@Override
public ExtraFields[] newArray(int size) {
return new ExtraFields[size];
}
};
public boolean containsCustomFields() { public boolean containsCustomFields() {
return !getCustomProtectedFields().keySet().isEmpty(); return !getCustomProtectedFields().keySet().isEmpty();
} }
public boolean containsCustomFieldsProtected() {
for (Map.Entry<String, ProtectedString> field : getCustomProtectedFields().entrySet()) {
if (field.getValue().isProtected())
return true;
}
return false;
}
public boolean containsCustomFieldsNotProtected() {
for (Map.Entry<String, ProtectedString> field : getCustomProtectedFields().entrySet()) {
if (!field.getValue().isProtected())
return true;
}
return false;
}
public String getProtectedStringValue(String key) { public String getProtectedStringValue(String key) {
ProtectedString value = fields.get(key); ProtectedString value = fields.get(key);
if ( value == null ) return ""; if ( value == null ) return "";

View File

@@ -17,16 +17,13 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.database.edit; package com.kunzisoft.keepass.database;
import android.os.Handler; import android.content.res.Resources;
import com.kunzisoft.keepass.database.PwNode; /**
* Interface to generify items with a name resource, that can be (for example) visible in a list
public abstract class AfterActionNodeOnFinish extends OnFinish { */
public AfterActionNodeOnFinish(Handler handler) { public interface ObjectNameResource {
super(handler); String getName(Resources resources);
}
public abstract void run(PwNode oldNode, PwNode newNode);
} }

View File

@@ -19,19 +19,15 @@
*/ */
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import com.kunzisoft.keepass.crypto.finalkey.FinalKey;
import com.kunzisoft.keepass.crypto.finalkey.FinalKeyFactory;
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException; import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
import com.kunzisoft.keepass.database.exception.KeyFileEmptyException; import com.kunzisoft.keepass.database.exception.KeyFileEmptyException;
import com.kunzisoft.keepass.stream.NullOutputStream; import com.kunzisoft.keepass.utils.MemUtil;
import com.kunzisoft.keepass.utils.Util;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.security.DigestOutputStream;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.HashMap; import java.util.HashMap;
@@ -39,7 +35,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
public abstract class PwDatabase<PwGroupDB extends PwGroup<PwGroupDB, PwGroupDB, PwEntryDB>, public abstract class PwDatabase<PwGroupDB extends PwGroup<PwGroupDB, PwEntryDB>,
PwEntryDB extends PwEntry<PwGroupDB>> { PwEntryDB extends PwEntry<PwGroupDB>> {
public static final UUID UUID_ZERO = new UUID(0,0); public static final UUID UUID_ZERO = new UUID(0,0);
@@ -100,39 +96,9 @@ public abstract class PwDatabase<PwGroupDB extends PwGroup<PwGroupDB, PwGroupDB,
return finalKey; return finalKey;
} }
public void makeFinalKey(byte[] masterSeed, byte[] masterSeed2, long numRounds) throws IOException {
// Write checksum Checksum
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
throw new IOException("SHA-256 not implemented here.");
}
NullOutputStream nos = new NullOutputStream();
DigestOutputStream dos = new DigestOutputStream(nos, md);
byte[] transformedMasterKey = transformMasterKey(masterSeed2, masterKey, numRounds);
dos.write(masterSeed);
dos.write(transformedMasterKey);
finalKey = md.digest();
}
/**
* Encrypt the master key a few times to make brute-force key-search harder
* @throws IOException
*/
protected static byte[] transformMasterKey( byte[] pKeySeed, byte[] pKey, long rounds ) throws IOException {
FinalKey key = FinalKeyFactory.createFinalKey();
return key.transformMasterKey(pKeySeed, pKey, rounds);
}
public abstract byte[] getMasterKey(String key, InputStream keyInputStream) throws InvalidKeyFileException, IOException; public abstract byte[] getMasterKey(String key, InputStream keyInputStream) throws InvalidKeyFileException, IOException;
public void setMasterKey(String key, InputStream keyInputStream) public void retrieveMasterKey(String key, InputStream keyInputStream)
throws InvalidKeyFileException, IOException { throws InvalidKeyFileException, IOException {
masterKey = getMasterKey(key, keyInputStream); masterKey = getMasterKey(key, keyInputStream);
} }
@@ -162,7 +128,7 @@ public abstract class PwDatabase<PwGroupDB extends PwGroup<PwGroupDB, PwGroupDB,
assert(keyInputStream != null); assert(keyInputStream != null);
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
Util.copyStream(keyInputStream, bos); MemUtil.copyStream(keyInputStream, bos);
byte[] keyData = bos.toByteArray(); byte[] keyData = bos.toByteArray();
ByteArrayInputStream bis = new ByteArrayInputStream(keyData); ByteArrayInputStream bis = new ByteArrayInputStream(keyData);
@@ -280,7 +246,7 @@ public abstract class PwDatabase<PwGroupDB extends PwGroup<PwGroupDB, PwGroupDB,
this.algorithm = algorithm; this.algorithm = algorithm;
} }
public abstract String getKeyDerivationName(); public abstract List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms();
public abstract List<PwGroupDB> getGrpRoots(); public abstract List<PwGroupDB> getGrpRoots();
@@ -464,4 +430,6 @@ public abstract class PwDatabase<PwGroupDB extends PwGroup<PwGroupDB, PwGroupDB,
*/ */
public abstract void initNew(String dbPath); public abstract void initNew(String dbPath);
public abstract void clearCache();
} }

View File

@@ -45,11 +45,16 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import com.kunzisoft.keepass.crypto.keyDerivation.AesKdf; import com.kunzisoft.keepass.crypto.finalkey.FinalKey;
import com.kunzisoft.keepass.crypto.finalkey.FinalKeyFactory;
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException; import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
import com.kunzisoft.keepass.stream.NullOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@@ -86,7 +91,7 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
PwGroupV3 group = createGroup(); PwGroupV3 group = createGroup();
group.setId(newGroupId()); group.setId(newGroupId());
group.setName(name); group.setName(name);
group.setIcon(iconFactory.getIcon(iconId)); group.setIconStandard(iconFactory.getIcon(iconId));
addGroupTo(group, parent); addGroupTo(group, parent);
} }
@@ -95,10 +100,12 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
return PwVersion.V3; return PwVersion.V3;
} }
@Override @Override
public String getKeyDerivationName() { public List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms() {
return AesKdf.DEFAULT_NAME; List<PwEncryptionAlgorithm> list = new ArrayList<>();
} list.add(PwEncryptionAlgorithm.AES_Rijndael);
return list;
}
@Override @Override
public List<PwGroupV3> getGroups() { public List<PwGroupV3> getGroups() {
@@ -169,7 +176,7 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
*/ */
for (int i = 0; i < entries.size(); i++) { for (int i = 0; i < entries.size(); i++) {
PwEntryV3 ent = entries.get(i); PwEntryV3 ent = entries.get(i);
if (ent.getGroupId() == parent.getGroupId()) if (ent.getParent().getGroupId() == parent.getGroupId())
kids.add(ent); kids.add(ent);
} }
return kids; return kids;
@@ -250,6 +257,35 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
} }
} }
/**
* Encrypt the master key a few times to make brute-force key-search harder
* @throws IOException
*/
private static byte[] transformMasterKey( byte[] pKeySeed, byte[] pKey, long rounds ) throws IOException {
FinalKey key = FinalKeyFactory.createFinalKey();
return key.transformMasterKey(pKeySeed, pKey, rounds);
}
public void makeFinalKey(byte[] masterSeed, byte[] masterSeed2, long numRounds) throws IOException {
// Write checksum Checksum
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
throw new IOException("SHA-256 not implemented here.");
}
NullOutputStream nos = new NullOutputStream();
DigestOutputStream dos = new DigestOutputStream(nos, md);
byte[] transformedMasterKey = transformMasterKey(masterSeed2, masterKey, numRounds);
dos.write(masterSeed);
dos.write(transformedMasterKey);
finalKey = md.digest();
}
@Override @Override
protected String getPasswordEncoding() { protected String getPasswordEncoding() {
return "ISO-8859-1"; return "ISO-8859-1";
@@ -288,7 +324,6 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
// Add tree to root groups // Add tree to root groups
groups.add(newGroup); groups.add(newGroup);
} }
@Override @Override
@@ -341,4 +376,7 @@ public class PwDatabaseV3 extends PwDatabase<PwGroupV3, PwEntryV3> {
return !(omitBackup && isBackup(group)); return !(omitBackup && isBackup(group));
} }
@Override
public void clearCache() {}
} }

View File

@@ -19,17 +19,18 @@
*/ */
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import android.util.Log;
import android.webkit.URLUtil; import android.webkit.URLUtil;
import com.kunzisoft.keepass.collections.VariantDictionary; import com.kunzisoft.keepass.collections.VariantDictionary;
import com.kunzisoft.keepass.crypto.CryptoUtil; import com.kunzisoft.keepass.crypto.CryptoUtil;
import com.kunzisoft.keepass.crypto.engine.AesEngine; import com.kunzisoft.keepass.crypto.engine.AesEngine;
import com.kunzisoft.keepass.crypto.engine.CipherEngine; import com.kunzisoft.keepass.crypto.engine.CipherEngine;
import com.kunzisoft.keepass.crypto.keyDerivation.AesKdf;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine; import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory; import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfParameters; import com.kunzisoft.keepass.crypto.keyDerivation.KdfParameters;
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException; import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
import com.kunzisoft.keepass.database.exception.UnknownKDF;
import com.kunzisoft.keepass.utils.EmptyUtils; import com.kunzisoft.keepass.utils.EmptyUtils;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@@ -50,6 +51,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import javax.annotation.Nullable;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
@@ -57,6 +59,7 @@ import biz.source_code.base64Coder.Base64Coder;
public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> { public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
private static final String TAG = PwDatabaseV4.class.getName();
private static final int DEFAULT_HISTORY_MAX_ITEMS = 10; // -1 unlimited private static final int DEFAULT_HISTORY_MAX_ITEMS = 10; // -1 unlimited
private static final long DEFAULT_HISTORY_MAX_SIZE = 6 * 1024 * 1024; // -1 unlimited private static final long DEFAULT_HISTORY_MAX_SIZE = 6 * 1024 * 1024; // -1 unlimited
@@ -66,9 +69,10 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
private UUID dataCipher = AesEngine.CIPHER_UUID; private UUID dataCipher = AesEngine.CIPHER_UUID;
private CipherEngine dataEngine = new AesEngine(); private CipherEngine dataEngine = new AesEngine();
private PwCompressionAlgorithm compressionAlgorithm = PwCompressionAlgorithm.Gzip; private PwCompressionAlgorithm compressionAlgorithm = PwCompressionAlgorithm.Gzip;
private KdfEngine kdfEngine; private KdfParameters kdfParameters;
private long numKeyEncRounds;
private VariantDictionary publicCustomData = new VariantDictionary();
private long numKeyEncRounds = AesKdf.DEFAULT_ROUNDS; // By default take the AES rounds
protected String name = "KeePass DX database"; protected String name = "KeePass DX database";
private PwDate nameChanged = new PwDate(); private PwDate nameChanged = new PwDate();
private PwDate settingsChanged = new PwDate(); private PwDate settingsChanged = new PwDate();
@@ -98,9 +102,7 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
private List<PwIconCustom> customIcons = new ArrayList<>(); private List<PwIconCustom> customIcons = new ArrayList<>();
private Map<String, String> customData = new HashMap<>(); private Map<String, String> customData = new HashMap<>();
private KdfParameters kdfParameters = KdfFactory.getDefaultParameters(); private BinaryPool binPool = new BinaryPool();
private VariantDictionary publicCustomData = new VariantDictionary();
private BinaryPool binPool = new BinaryPool();
public String localizedAppName = "KeePassDX"; // TODO resource public String localizedAppName = "KeePassDX"; // TODO resource
@@ -131,9 +133,17 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
public void setDataEngine(CipherEngine dataEngine) { public void setDataEngine(CipherEngine dataEngine) {
this.dataEngine = dataEngine; this.dataEngine = dataEngine;
this.algorithm = dataEngine.getPwEncryptionAlgorithm();
} }
@Override
public List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms() {
List<PwEncryptionAlgorithm> list = new ArrayList<>();
list.add(PwEncryptionAlgorithm.AES_Rijndael);
list.add(PwEncryptionAlgorithm.Twofish);
list.add(PwEncryptionAlgorithm.ChaCha20);
return list;
}
public PwCompressionAlgorithm getCompressionAlgorithm() { public PwCompressionAlgorithm getCompressionAlgorithm() {
return compressionAlgorithm; return compressionAlgorithm;
} }
@@ -142,6 +152,23 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
this.compressionAlgorithm = compressionAlgorithm; this.compressionAlgorithm = compressionAlgorithm;
} }
public @Nullable KdfEngine getKdfEngine() {
try {
return KdfFactory.getEngineV4(kdfParameters);
} catch (UnknownKDF unknownKDF) {
Log.i(TAG, "Unable to retrieve KDF engine", unknownKDF);
return null;
}
}
public KdfParameters getKdfParameters() {
return kdfParameters;
}
public void setKdfParameters(KdfParameters kdfParameters) {
this.kdfParameters = kdfParameters;
}
@Override @Override
public long getNumberKeyEncryptionRounds() { public long getNumberKeyEncryptionRounds() {
if (getKdfEngine() != null && getKdfParameters() != null) if (getKdfEngine() != null && getKdfParameters() != null)
@@ -156,7 +183,31 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
numKeyEncRounds = rounds; numKeyEncRounds = rounds;
} }
public PwDate getNameChanged() { public long getMemoryUsage() {
if (getKdfEngine() != null && getKdfParameters() != null) {
return getKdfEngine().getMemoryUsage(getKdfParameters());
}
return KdfEngine.UNKNOW_VALUE;
}
public void setMemoryUsage(long memory) {
if (getKdfEngine() != null && getKdfParameters() != null)
getKdfEngine().setMemoryUsage(getKdfParameters(), memory);
}
public int getParallelism() {
if (getKdfEngine() != null && getKdfParameters() != null) {
return getKdfEngine().getParallelism(getKdfParameters());
}
return KdfEngine.UNKNOW_VALUE;
}
public void setParallelism(int parallelism) {
if (getKdfEngine() != null && getKdfParameters() != null)
getKdfEngine().setParallelism(getKdfParameters(), parallelism);
}
public PwDate getNameChanged() {
return nameChanged; return nameChanged;
} }
@@ -326,15 +377,6 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
this.customData.put(label, value); this.customData.put(label, value);
} }
public KdfEngine getKdfEngine() {
return kdfEngine;
}
@Override
public String getKeyDerivationName() {
return kdfEngine.getName();
}
@Override @Override
public byte[] getMasterKey(String key, InputStream keyInputStream) public byte[] getMasterKey(String key, InputStream keyInputStream)
throws InvalidKeyFileException, IOException { throws InvalidKeyFileException, IOException {
@@ -359,47 +401,11 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
return md.digest(fKey); return md.digest(fKey);
} }
@Override public void makeFinalKey(byte[] masterSeed) throws IOException {
public void makeFinalKey(byte[] masterSeed, byte[] masterSeed2, long numRounds) throws IOException {
byte[] transformedMasterKey = transformMasterKey(masterSeed2, masterKey, numRounds); KdfEngine kdfEngine = KdfFactory.getEngineV4(kdfParameters);
byte[] transformedMasterKey = kdfEngine.transform(masterKey, kdfParameters);
byte[] cmpKey = new byte[65];
System.arraycopy(masterSeed, 0, cmpKey, 0, 32);
System.arraycopy(transformedMasterKey, 0, cmpKey, 32, 32);
finalKey = CryptoUtil.resizeKey(cmpKey, 0, 64, dataEngine.keyLength());
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-512");
cmpKey[64] = 1;
hmacKey = md.digest(cmpKey);
} catch (NoSuchAlgorithmException e) {
throw new IOException("No SHA-512 implementation");
} finally {
Arrays.fill(cmpKey, (byte)0);
}
}
public void makeFinalKey(byte[] masterSeed, KdfParameters kdfP) throws IOException {
makeFinalKey(masterSeed, kdfP, 0);
}
public void makeFinalKey(byte[] masterSeed, KdfParameters kdfP, long roundsFix)
throws IOException {
kdfEngine = KdfFactory.get(kdfP.kdfUUID);
if (kdfEngine == null) {
throw new IOException("Unknown key derivation function");
}
// Set to 6000 rounds to open corrupted database
if (roundsFix > 0 && kdfP.kdfUUID.equals(AesKdf.CIPHER_UUID)) {
kdfP.setUInt32(AesKdf.ParamRounds, roundsFix);
numKeyEncRounds = roundsFix;
}
byte[] transformedMasterKey = kdfEngine.transform(masterKey, kdfP);
if (transformedMasterKey.length != 32) { if (transformedMasterKey.length != 32) {
transformedMasterKey = CryptoUtil.hashSha256(transformedMasterKey); transformedMasterKey = CryptoUtil.hashSha256(transformedMasterKey);
} }
@@ -549,15 +555,15 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
super.populateGlobals(currentGroup); super.populateGlobals(currentGroup);
} }
/** Ensure that the recycle bin tree exists, if enabled and create it /**
* if it doesn't exist * Ensure that the recycle bin tree exists, if enabled and create it
* * if it doesn't exist
*/ */
private void ensureRecycleBin() { private void ensureRecycleBin() {
if (getRecycleBin() == null) { if (getRecycleBin() == null) {
// Create recycle bin // Create recycle bin
PwGroupV4 recycleBin = new PwGroupV4(RECYCLEBIN_NAME, iconFactory.getIcon(PwIconStandard.TRASH_BIN)); PwGroupV4 recycleBin = new PwGroupV4(RECYCLEBIN_NAME, iconFactory.getTrashIcon());
recycleBin.setEnableAutoType(false); recycleBin.setEnableAutoType(false);
recycleBin.setEnableSearching(false); recycleBin.setEnableSearching(false);
recycleBin.setExpanded(false); recycleBin.setExpanded(false);
@@ -681,8 +687,7 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
@Override @Override
public void undoDeleteEntry(PwEntryV4 entry, PwGroupV4 origParent) { public void undoDeleteEntry(PwEntryV4 entry, PwGroupV4 origParent) {
super.undoDeleteEntry(entry, origParent); super.undoDeleteEntry(entry, origParent);
// TODO undo delete entry deletedObjects.remove(new PwDeletedObject(entry.getUUID()));
deletedObjects.remove(entry);
} }
@Override @Override
@@ -695,14 +700,6 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
return groups.get(recycleId); return groups.get(recycleId);
} }
public KdfParameters getKdfParameters() {
return kdfParameters;
}
public void setKdfParameters(KdfParameters kdfParameters) {
this.kdfParameters = kdfParameters;
}
public VariantDictionary getPublicCustomData() { public VariantDictionary getPublicCustomData() {
return publicCustomData; return publicCustomData;
} }
@@ -739,9 +736,7 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
@Override @Override
public void initNew(String dbPath) { public void initNew(String dbPath) {
String filename = URLUtil.guessFileName(dbPath, null, null); rootGroup = new PwGroupV4(dbNameFromPath(dbPath), iconFactory.getFolderIcon());
rootGroup = new PwGroupV4(dbNameFromPath(dbPath), iconFactory.getIcon(PwIconStandard.FOLDER));
groups.put(rootGroup.getId(), rootGroup); groups.put(rootGroup.getId(), rootGroup);
} }
@@ -759,64 +754,8 @@ public class PwDatabaseV4 extends PwDatabase<PwGroupV4, PwEntryV4> {
return filename.substring(0, lastExtDot); return filename.substring(0, lastExtDot);
} }
private class GroupHasCustomData extends GroupHandler<PwGroupV4> { @Override
public void clearCache() {
public boolean hasCustomData = false; binPool.clear();
}
@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

@@ -19,10 +19,12 @@
*/ */
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import android.os.Parcel;
import android.os.Parcelable;
import com.kunzisoft.keepass.app.App; import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.utils.Types; import com.kunzisoft.keepass.utils.Types;
import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
@@ -33,15 +35,14 @@ import java.util.Date;
* @author bpellin * @author bpellin
* *
*/ */
public class PwDate implements Cloneable, Serializable { public class PwDate implements Cloneable, Parcelable {
private static final int DATE_SIZE = 5; private static final int DATE_SIZE = 5;
private boolean cDateBuilt = false; private Date jDate;
private boolean jDateBuilt = false; private boolean jDateBuilt = false;
transient private byte[] cDate;
private Date jDate; transient private boolean cDateBuilt = false;
private byte[] cDate;
public static final Date NEVER_EXPIRE = getNeverExpire(); public static final Date NEVER_EXPIRE = getNeverExpire();
public static final Date DEFAULT_DATE = getDefaultDate(); public static final Date DEFAULT_DATE = getDefaultDate();
@@ -93,6 +94,35 @@ public class PwDate implements Cloneable, Serializable {
jDate = new Date(); jDate = new Date();
jDateBuilt = true; jDateBuilt = true;
} }
protected PwDate(Parcel in) {
jDate = (Date) in.readSerializable();
jDateBuilt = in.readByte() != 0;
cDateBuilt = false;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeSerializable(getDate());
dest.writeByte((byte) (jDateBuilt ? 1 : 0));
}
public static final Creator<PwDate> CREATOR = new Creator<PwDate>() {
@Override
public PwDate createFromParcel(Parcel in) {
return new PwDate(in);
}
@Override
public PwDate[] newArray(int size) {
return new PwDate[size];
}
};
@Override @Override
public PwDate clone() { public PwDate clone() {

View File

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

View File

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

View File

@@ -19,6 +19,8 @@
*/ */
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import android.os.Parcel;
import com.kunzisoft.keepass.database.iterator.EntrySearchStringIterator; import com.kunzisoft.keepass.database.iterator.EntrySearchStringIterator;
import com.kunzisoft.keepass.database.security.ProtectedString; import com.kunzisoft.keepass.database.security.ProtectedString;
@@ -30,6 +32,19 @@ public abstract class PwEntry<Parent extends PwGroup> extends PwNode<Parent> {
protected UUID uuid = PwDatabase.UUID_ZERO; protected UUID uuid = PwDatabase.UUID_ZERO;
public PwEntry() {}
public PwEntry(Parcel in) {
super(in);
uuid = (UUID) in.readSerializable();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeSerializable(uuid);
}
@Override @Override
protected void construct(Parent parent) { protected void construct(Parent parent) {
super.construct(parent); super.construct(parent);
@@ -61,7 +76,7 @@ public abstract class PwEntry<Parent extends PwGroup> extends PwNode<Parent> {
} }
public void startToManageFieldReferences(PwDatabase db) {} public void startToManageFieldReferences(PwDatabase db) {}
public void endToManageFieldReferences() {} public void stopToManageFieldReferences() {}
public abstract String getTitle(); public abstract String getTitle();
public abstract void setTitle(String title); public abstract void setTitle(String title);
@@ -82,15 +97,31 @@ public abstract class PwEntry<Parent extends PwGroup> extends PwNode<Parent> {
return getTitle().equals(PMS_TAN_ENTRY) && (getUsername().length() > 0); return getTitle().equals(PMS_TAN_ENTRY) && (getUsername().length() > 0);
} }
@Override /**
public String getDisplayTitle() { * {@inheritDoc}
if ( isTan() ) { * Get the display title from an entry, <br />
return PMS_TAN_ENTRY + " " + getUsername(); * {@link #startToManageFieldReferences(PwDatabase)} and {@link #stopToManageFieldReferences()} must be called
} else { * before and after {@link #getVisualTitle()}
return getTitle(); */
} public String getVisualTitle() {
// only used to compare, don't car if it's a reference
return getVisualTitle(isTan(), getTitle(), getUsername(), getUrl(), getUUID());
} }
public static String getVisualTitle(boolean isTAN, String title, String username, String url, UUID uuid) {
if ( isTAN ) {
return PMS_TAN_ENTRY + " " + username;
} else {
if (title.isEmpty())
if (url.isEmpty())
return uuid.toString();
else
return url;
else
return title;
}
}
// TODO encapsulate extra fields // TODO encapsulate extra fields
/** /**
@@ -117,6 +148,22 @@ public abstract class PwEntry<Parent extends PwGroup> extends PwNode<Parent> {
return getFields().containsCustomFields(); return getFields().containsCustomFields();
} }
/**
* If entry contains extra fields that are protected
* @return true if there is extra fields protected
*/
public boolean containsCustomFieldsProtected() {
return getFields().containsCustomFieldsProtected();
}
/**
* If entry contains extra fields that are not protected
* @return true if there is extra fields not protected
*/
public boolean containsCustomFieldsNotProtected() {
return getFields().containsCustomFieldsNotProtected();
}
/** /**
* Add an extra field to the list (standard or custom) * Add an extra field to the list (standard or custom)
* @param label Label of field, must be unique * @param label Label of field, must be unique

View File

@@ -42,6 +42,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import android.os.Parcel;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.UUID; import java.util.UUID;
@@ -75,15 +77,11 @@ public class PwEntryV3 extends PwEntry<PwGroupV3> {
private static final String PMS_ID_USER = "SYSTEM"; private static final String PMS_ID_USER = "SYSTEM";
private static final String PMS_ID_URL = "$"; private static final String PMS_ID_URL = "$";
// TODO Parent ID to remove
private int groupId;
private String title; private String title;
private String username; private String username;
private byte[] password; private byte[] password;
private String url; private String url;
private String additional; private String additional;
/** A string describing what is in pBinaryData */ /** A string describing what is in pBinaryData */
private String binaryDesc; private String binaryDesc;
private byte[] binaryData; private byte[] binaryData;
@@ -94,12 +92,45 @@ public class PwEntryV3 extends PwEntry<PwGroupV3> {
public PwEntryV3(PwGroupV3 p) { public PwEntryV3(PwGroupV3 p) {
construct(p); construct(p);
groupId = ((PwGroupIdV3) this.parent.getId()).getId(); // TODO remove
} }
public PwEntryV3(Parcel in) {
super(in);
title = in.readString();
username = in.readString();
in.readByteArray(password);
url = in.readString();
additional = in.readString();
binaryDesc = in.readString();
in.readByteArray(binaryData);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeString(title);
dest.writeString(username);
dest.writeByteArray(password);
dest.writeString(url);
dest.writeString(additional);
dest.writeString(binaryDesc);
dest.writeByteArray(binaryData);
}
public static final Creator<PwEntryV3> CREATOR = new Creator<PwEntryV3>() {
@Override
public PwEntryV3 createFromParcel(Parcel in) {
return new PwEntryV3(in);
}
@Override
public PwEntryV3[] newArray(int size) {
return new PwEntryV3[size];
}
};
protected void updateWith(PwEntryV3 source) { protected void updateWith(PwEntryV3 source) {
super.assign(source); super.assign(source);
groupId = source.groupId;
title = source.title; title = source.title;
username = source.username; username = source.username;
@@ -145,12 +176,9 @@ public class PwEntryV3 extends PwEntry<PwGroupV3> {
return newEntry; return newEntry;
} }
public int getGroupId() {
return groupId;
}
public void setGroupId(int groupId) { public void setGroupId(int groupId) {
this.groupId = groupId; this.parent = new PwGroupV3();
this.parent.setGroupId(groupId);
} }
@Override @Override
@@ -199,7 +227,7 @@ public class PwEntryV3 extends PwEntry<PwGroupV3> {
public void populateBlankFields(PwDatabaseV3 db) { public void populateBlankFields(PwDatabaseV3 db) {
// TODO verify and remove // TODO verify and remove
if (icon == null) { if (icon == null) {
icon = db.getIconFactory().getFirstIcon(); icon = db.getIconFactory().getKeyIcon();
} }
if (username == null) { if (username == null) {

View File

@@ -19,8 +19,11 @@
*/ */
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import android.os.Parcel;
import com.kunzisoft.keepass.database.security.ProtectedBinary; import com.kunzisoft.keepass.database.security.ProtectedBinary;
import com.kunzisoft.keepass.database.security.ProtectedString; import com.kunzisoft.keepass.database.security.ProtectedString;
import com.kunzisoft.keepass.utils.MemUtil;
import com.kunzisoft.keepass.utils.SprEngineV4; import com.kunzisoft.keepass.utils.SprEngineV4;
import java.util.ArrayList; import java.util.ArrayList;
@@ -37,7 +40,7 @@ public class PwEntryV4 extends PwEntry<PwGroupV4> implements ITimeLogger {
public static final String STR_URL = "URL"; public static final String STR_URL = "URL";
public static final String STR_NOTES = "Notes"; public static final String STR_NOTES = "Notes";
// To decode each field not serializable // To decode each field not parcelable
private transient PwDatabaseV4 mDatabase = null; private transient PwDatabaseV4 mDatabase = null;
private transient boolean mDecodeRef = false; private transient boolean mDecodeRef = false;
@@ -45,7 +48,6 @@ public class PwEntryV4 extends PwEntry<PwGroupV4> implements ITimeLogger {
private long usageCount = 0; private long usageCount = 0;
private PwDate parentGroupLastMod = new PwDate(); private PwDate parentGroupLastMod = new PwDate();
private Map<String, String> customData = new HashMap<>(); private Map<String, String> customData = new HashMap<>();
private ExtraFields fields = new ExtraFields(); private ExtraFields fields = new ExtraFields();
private HashMap<String, ProtectedBinary> binaries = new HashMap<>(); private HashMap<String, ProtectedBinary> binaries = new HashMap<>();
private String foregroundColor = ""; private String foregroundColor = "";
@@ -53,7 +55,6 @@ public class PwEntryV4 extends PwEntry<PwGroupV4> implements ITimeLogger {
private String overrideURL = ""; private String overrideURL = "";
private AutoType autoType = new AutoType(); private AutoType autoType = new AutoType();
private ArrayList<PwEntryV4> history = new ArrayList<>(); private ArrayList<PwEntryV4> history = new ArrayList<>();
private String url = ""; private String url = "";
private String additional = ""; private String additional = "";
private String tags = ""; private String tags = "";
@@ -71,8 +72,8 @@ public class PwEntryV4 extends PwEntry<PwGroupV4> implements ITimeLogger {
customIcon = source.customIcon; customIcon = source.customIcon;
usageCount = source.usageCount; usageCount = source.usageCount;
parentGroupLastMod = source.parentGroupLastMod; parentGroupLastMod = source.parentGroupLastMod;
// TODO customData customData.clear();
customData.putAll(source.customData); // Add all custom elements in map
fields = source.fields; fields = source.fields;
binaries = source.binaries; binaries = source.binaries;
foregroundColor = source.foregroundColor; foregroundColor = source.foregroundColor;
@@ -80,12 +81,60 @@ public class PwEntryV4 extends PwEntry<PwGroupV4> implements ITimeLogger {
overrideURL = source.overrideURL; overrideURL = source.overrideURL;
autoType = source.autoType; autoType = source.autoType;
history = source.history; history = source.history;
url = source.url; url = source.url;
additional = source.additional; additional = source.additional;
tags = source.tags; tags = source.tags;
} }
public PwEntryV4(Parcel in) {
super(in);
customIcon = in.readParcelable(PwIconCustom.class.getClassLoader());
usageCount = in.readLong();
parentGroupLastMod = in.readParcelable(PwDate.class.getClassLoader());
customData = MemUtil.readStringParcelableMap(in);
fields = in.readParcelable(ExtraFields.class.getClassLoader());
binaries = MemUtil.readStringParcelableMap(in, ProtectedBinary.class);
foregroundColor = in.readString();
backgroupColor = in.readString();
overrideURL = in.readString();
autoType = in.readParcelable(AutoType.class.getClassLoader());
history = in.readArrayList(PwEntryV4.class.getClassLoader()); // TODO verify
url = in.readString();
additional = in.readString();
tags = in.readString();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeParcelable(customIcon, flags);
dest.writeLong(usageCount);
dest.writeParcelable(parentGroupLastMod, flags);
MemUtil.writeStringParcelableMap(dest, customData);
dest.writeParcelable(fields, flags);
// TODO MemUtil.writeStringParcelableMap(dest, flags, binaries);
dest.writeString(foregroundColor);
dest.writeString(backgroupColor);
dest.writeString(overrideURL);
dest.writeParcelable(autoType, flags);
dest.writeList(history);
dest.writeString(url);
dest.writeString(additional);
dest.writeString(tags);
}
public static final Creator<PwEntryV4> CREATOR = new Creator<PwEntryV4>() {
@Override
public PwEntryV4 createFromParcel(Parcel in) {
return new PwEntryV4(in);
}
@Override
public PwEntryV4[] newArray(int size) {
return new PwEntryV4[size];
}
};
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public PwEntryV4 clone() { public PwEntryV4 clone() {
@@ -120,7 +169,7 @@ public class PwEntryV4 extends PwEntry<PwGroupV4> implements ITimeLogger {
} }
@Override @Override
public void endToManageFieldReferences() { public void stopToManageFieldReferences() {
this.mDatabase = null; this.mDatabase = null;
this.mDecodeRef = false; this.mDecodeRef = false;
} }
@@ -156,41 +205,31 @@ public class PwEntryV4 extends PwEntry<PwGroupV4> implements ITimeLogger {
@Override @Override
public void setTitle(String title) { public void setTitle(String title) {
PwDatabaseV4 db = mDatabase; boolean protect = (mDatabase != null) && mDatabase.getMemoryProtection().protectTitle;
boolean protect = db.getMemoryProtection().protectTitle;
setProtectedString(STR_TITLE, title, protect); setProtectedString(STR_TITLE, title, protect);
} }
@Override @Override
public void setUsername(String user) { public void setUsername(String user) {
PwDatabaseV4 db = mDatabase; boolean protect = (mDatabase != null) && mDatabase.getMemoryProtection().protectUserName;
boolean protect = db.getMemoryProtection().protectUserName;
setProtectedString(STR_USERNAME, user, protect); setProtectedString(STR_USERNAME, user, protect);
} }
@Override @Override
public void setPassword(String pass) { public void setPassword(String pass) {
PwDatabaseV4 db = mDatabase; boolean protect = (mDatabase != null) && mDatabase.getMemoryProtection().protectPassword;
boolean protect = db.getMemoryProtection().protectPassword;
setProtectedString(STR_PASSWORD, pass, protect); setProtectedString(STR_PASSWORD, pass, protect);
} }
@Override @Override
public void setUrl(String url) { public void setUrl(String url) {
PwDatabaseV4 db = mDatabase; boolean protect = (mDatabase != null) && mDatabase.getMemoryProtection().protectUrl;
boolean protect = db.getMemoryProtection().protectUrl;
setProtectedString(STR_URL, url, protect); setProtectedString(STR_URL, url, protect);
} }
@Override @Override
public void setNotes(String notes) { public void setNotes(String notes) {
PwDatabaseV4 db = mDatabase; boolean protect = (mDatabase != null) && mDatabase.getMemoryProtection().protectNotes;
boolean protect = db.getMemoryProtection().protectNotes;
setProtectedString(STR_NOTES, notes, protect); setProtectedString(STR_NOTES, notes, protect);
} }
@@ -202,14 +241,6 @@ public class PwEntryV4 extends PwEntry<PwGroupV4> implements ITimeLogger {
fields.putProtectedString(key, value, protect); fields.putProtectedString(key, value, protect);
} }
public PwIconCustom getCustomIcon() {
return customIcon;
}
public void setCustomIcon(PwIconCustom icon) {
this.customIcon = icon;
}
public PwDate getLocationChanged() { public PwDate getLocationChanged() {
return parentGroupLastMod; return parentGroupLastMod;
} }
@@ -236,15 +267,28 @@ public class PwEntryV4 extends PwEntry<PwGroupV4> implements ITimeLogger {
return decodeRefKey(mDecodeRef, STR_URL); return decodeRefKey(mDecodeRef, STR_URL);
} }
@Override @Override
public PwIcon getIcon() { public PwIcon getIcon() {
if (customIcon == null || customIcon.uuid.equals(PwDatabase.UUID_ZERO)) { if (customIcon == null || customIcon.isUnknown()) {
return super.getIcon(); return super.getIcon();
} else { } else {
return customIcon; return customIcon;
} }
} }
public void setIconCustom(PwIconCustom icon) {
this.customIcon = icon;
}
public PwIconCustom getIconCustom() {
return customIcon;
}
public void setIconStandard(PwIconStandard icon) {
this.icon = icon;
this.customIcon = PwIconCustom.ZERO;
}
@Override @Override
public boolean allowExtraFields() { public boolean allowExtraFields() {
return true; return true;

View File

@@ -19,16 +19,34 @@
*/ */
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import android.os.Parcel;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public abstract class PwGroup<Parent extends PwGroup, ChildGroup extends PwGroup, ChildEntry extends PwEntry> public abstract class PwGroup<GroupG extends PwGroup, EntryE extends PwEntry>
extends PwNode<Parent> { extends PwNode<GroupG> {
protected String name = ""; protected String name = "";
protected List<ChildGroup> childGroups = new ArrayList<>(); // TODO verify children not needed
protected List<ChildEntry> childEntries = new ArrayList<>(); transient protected List<GroupG> childGroups = new ArrayList<>();
transient protected List<EntryE> childEntries = new ArrayList<>();
protected PwGroup() {
super();
}
protected PwGroup(Parcel in) {
super(in);
name = in.readString();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeString(name);
}
@Override @Override
public PwGroup clone() { public PwGroup clone() {
@@ -36,48 +54,48 @@ public abstract class PwGroup<Parent extends PwGroup, ChildGroup extends PwGroup
return (PwGroup) super.clone(); return (PwGroup) super.clone();
} }
protected void assign(PwGroup<Parent, ChildGroup, ChildEntry> source) { protected void assign(PwGroup<GroupG, EntryE> source) {
super.assign(source); super.assign(source);
name = source.name; name = source.name;
} }
public List<ChildGroup> getChildGroups() { public List<GroupG> getChildGroups() {
return childGroups; return childGroups;
} }
public List<ChildEntry> getChildEntries() { public List<EntryE> getChildEntries() {
return childEntries; return childEntries;
} }
public void setGroups(List<ChildGroup> groups) { public void setGroups(List<GroupG> groups) {
childGroups = groups; childGroups = groups;
} }
public void setEntries(List<ChildEntry> entries) { public void setEntries(List<EntryE> entries) {
childEntries = entries; childEntries = entries;
} }
public void addChildGroup(ChildGroup group) { public void addChildGroup(GroupG group) {
this.childGroups.add(group); this.childGroups.add(group);
} }
public void addChildEntry(ChildEntry entry) { public void addChildEntry(EntryE entry) {
this.childEntries.add(entry); this.childEntries.add(entry);
} }
public ChildGroup getChildGroupAt(int number) { public GroupG getChildGroupAt(int number) {
return this.childGroups.get(number); return this.childGroups.get(number);
} }
public ChildEntry getChildEntryAt(int number) { public EntryE getChildEntryAt(int number) {
return this.childEntries.get(number); return this.childEntries.get(number);
} }
public void removeChildGroup(ChildGroup group) { public void removeChildGroup(GroupG group) {
this.childGroups.remove(group); this.childGroups.remove(group);
} }
public void removeChildEntry(ChildEntry entry) { public void removeChildEntry(EntryE entry) {
this.childEntries.remove(entry); this.childEntries.remove(entry);
} }
@@ -101,7 +119,7 @@ public abstract class PwGroup<Parent extends PwGroup, ChildGroup extends PwGroup
public List<PwNode> getDirectChildren() { public List<PwNode> getDirectChildren() {
List<PwNode> children = new ArrayList<>(); List<PwNode> children = new ArrayList<>();
children.addAll(childGroups); children.addAll(childGroups);
for(ChildEntry child : childEntries) { for(EntryE child : childEntries) {
if (!child.isMetaStream()) if (!child.isMetaStream())
children.add(child); children.add(child);
} }
@@ -112,10 +130,18 @@ public abstract class PwGroup<Parent extends PwGroup, ChildGroup extends PwGroup
public abstract void setId(PwGroupId id); public abstract void setId(PwGroupId id);
@Override @Override
public String getDisplayTitle() { protected String getVisualTitle() {
return getTitle();
}
@Override
public String getTitle() {
return getName(); return getName();
} }
/**
* The same thing as {@link #getTitle()}
*/
public String getName() { public String getName() {
return name; return name;
} }
@@ -128,15 +154,15 @@ public abstract class PwGroup<Parent extends PwGroup, ChildGroup extends PwGroup
return false; return false;
} }
public boolean preOrderTraverseTree(GroupHandler<ChildGroup> groupHandler, public boolean preOrderTraverseTree(GroupHandler<GroupG> groupHandler,
EntryHandler<ChildEntry> entryHandler) { EntryHandler<EntryE> entryHandler) {
if (entryHandler != null) { if (entryHandler != null) {
for (ChildEntry entry : childEntries) { for (EntryE entry : childEntries) {
if (!entryHandler.operate(entry)) return false; if (!entryHandler.operate(entry)) return false;
} }
} }
for (ChildGroup group : childGroups) { for (GroupG group : childGroups) {
if ((groupHandler != null) && !groupHandler.operate(group)) return false; if ((groupHandler != null) && !groupHandler.operate(group)) return false;
group.preOrderTraverseTree(groupHandler, entryHandler); group.preOrderTraverseTree(groupHandler, entryHandler);
} }

View File

@@ -19,8 +19,20 @@
*/ */
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import java.io.Serializable; import android.os.Parcel;
import android.os.Parcelable;
public abstract class PwGroupId implements Serializable { public abstract class PwGroupId implements Parcelable {
public PwGroupId() {}
public PwGroupId(Parcel in) {}
@Override
public void writeToParcel(Parcel dest, int flags) {}
@Override
public int describeContents() {
return 0;
}
} }

View File

@@ -19,13 +19,39 @@
*/ */
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import android.os.Parcel;
public class PwGroupIdV3 extends PwGroupId { public class PwGroupIdV3 extends PwGroupId {
private int id; private int id;
public PwGroupIdV3(int i) { public PwGroupIdV3(int groupId) {
id = i; super();
this.id = groupId;
} }
public PwGroupIdV3(Parcel in) {
super(in);
id = in.readInt();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeInt(id);
}
public static final Creator<PwGroupIdV3> CREATOR = new Creator<PwGroupIdV3>() {
@Override
public PwGroupIdV3 createFromParcel(Parcel in) {
return new PwGroupIdV3(in);
}
@Override
public PwGroupIdV3[] newArray(int size) {
return new PwGroupIdV3[size];
}
};
@Override @Override
public boolean equals(Object compare) { public boolean equals(Object compare) {

View File

@@ -19,15 +19,42 @@
*/ */
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import android.os.Parcel;
import java.util.UUID; import java.util.UUID;
public class PwGroupIdV4 extends PwGroupId { public class PwGroupIdV4 extends PwGroupId {
private UUID uuid; private UUID uuid;
public PwGroupIdV4(UUID u) { public PwGroupIdV4(UUID uuid) {
uuid = u; super();
this.uuid = uuid;
} }
public PwGroupIdV4(Parcel in) {
super(in);
uuid = (UUID) in.readSerializable();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeSerializable(uuid);
}
public static final Creator<PwGroupIdV4> CREATOR = new Creator<PwGroupIdV4>() {
@Override
public PwGroupIdV4 createFromParcel(Parcel in) {
return new PwGroupIdV4(in);
}
@Override
public PwGroupIdV4[] newArray(int size) {
return new PwGroupIdV4[size];
}
};
@Override @Override
public boolean equals(Object id) { public boolean equals(Object id) {
if ( ! (id instanceof PwGroupIdV4) ) { if ( ! (id instanceof PwGroupIdV4) ) {
@@ -36,12 +63,12 @@ public class PwGroupIdV4 extends PwGroupId {
PwGroupIdV4 v4 = (PwGroupIdV4) id; PwGroupIdV4 v4 = (PwGroupIdV4) id;
return uuid.equals(v4.uuid); return uuid.equals(v4.uuid);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return uuid.hashCode(); return uuid.hashCode();
} }
public UUID getId() { public UUID getId() {
return uuid; return uuid;
} }

View File

@@ -20,19 +20,13 @@
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
/** import android.os.Parcel;
* @author Brian Pellin <bpellin@gmail.com>
* @author Naomaru Itoi <nao@phoneid.org> public class PwGroupV3 extends PwGroup<PwGroupV3, PwEntryV3> {
* @author Bill Zwicky <wrzwicky@pobox.com>
* @author Dominik Reichl <dominik.reichl@t-online.de>
*/
public class PwGroupV3 extends PwGroup<PwGroupV3, PwGroupV3, PwEntryV3> {
// for tree traversing // for tree traversing
private int groupId; private int groupId;
private int level = 0; // short private int level = 0; // short
/** Used by KeePass internally, don't use */ /** Used by KeePass internally, don't use */
private int flags; private int flags;
@@ -40,6 +34,33 @@ public class PwGroupV3 extends PwGroup<PwGroupV3, PwGroupV3, PwEntryV3> {
super(); super();
} }
public PwGroupV3(Parcel in) {
super(in);
groupId = in.readInt();
level = in.readInt();
flags = in.readInt();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeInt(groupId);
dest.writeInt(level);
dest.writeInt(flags);
}
public static final Creator<PwGroupV3> CREATOR = new Creator<PwGroupV3>() {
@Override
public PwGroupV3 createFromParcel(Parcel in) {
return new PwGroupV3(in);
}
@Override
public PwGroupV3[] newArray(int size) {
return new PwGroupV3[size];
}
};
public PwGroupV3(PwGroupV3 p) { public PwGroupV3(PwGroupV3 p) {
construct(p); construct(p);
} }
@@ -109,7 +130,7 @@ public class PwGroupV3 extends PwGroup<PwGroupV3, PwGroupV3, PwEntryV3> {
public void populateBlankFields(PwDatabaseV3 db) { public void populateBlankFields(PwDatabaseV3 db) {
// TODO populate blanck field // TODO populate blanck field
if (icon == null) { if (icon == null) {
icon = db.getIconFactory().getFirstIcon(); icon = db.getIconFactory().getFolderIcon();
} }
if (name == null) { if (name == null) {

View File

@@ -19,11 +19,15 @@
*/ */
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import android.os.Parcel;
import com.kunzisoft.keepass.utils.MemUtil;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
public class PwGroupV4 extends PwGroup<PwGroupV4, PwGroupV4, PwEntryV4> implements ITimeLogger { public class PwGroupV4 extends PwGroup<PwGroupV4, PwEntryV4> implements ITimeLogger {
public static final boolean DEFAULT_SEARCHING_ENABLED = true; public static final boolean DEFAULT_SEARCHING_ENABLED = true;
@@ -32,9 +36,7 @@ public class PwGroupV4 extends PwGroup<PwGroupV4, PwGroupV4, PwEntryV4> implemen
private long usageCount = 0; private long usageCount = 0;
private PwDate parentGroupLastMod = new PwDate(); private PwDate parentGroupLastMod = new PwDate();
private Map<String, String> customData = new HashMap<>(); private Map<String, String> customData = new HashMap<>();
private boolean expires = false; private boolean expires = false;
private String notes = ""; private String notes = "";
private boolean isExpanded = true; private boolean isExpanded = true;
private String defaultAutoTypeSequence = ""; private String defaultAutoTypeSequence = "";
@@ -57,6 +59,53 @@ public class PwGroupV4 extends PwGroup<PwGroupV4, PwGroupV4, PwEntryV4> implemen
this.icon = icon; this.icon = icon;
} }
public PwGroupV4(Parcel in) {
super(in);
uuid = (UUID) in.readSerializable();
customIcon = in.readParcelable(PwIconCustom.class.getClassLoader());
usageCount = in.readLong();
parentGroupLastMod = in.readParcelable(PwDate.class.getClassLoader());
// TODO customData = MemUtil.readStringParcelableMap(in);
expires = in.readByte() != 0;
notes = in.readString();
isExpanded = in.readByte() != 0;
defaultAutoTypeSequence = in.readString();
byte autoTypeByte = in.readByte();
enableAutoType = (autoTypeByte == -1) ? null : autoTypeByte != 0;
byte enableSearchingByte = in.readByte();
enableSearching = (enableSearchingByte == -1) ? null : enableSearchingByte != 0;
lastTopVisibleEntry = (UUID) in.readSerializable();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeSerializable(uuid);
dest.writeParcelable(customIcon, flags);
dest.writeLong(usageCount);
dest.writeParcelable(parentGroupLastMod, flags);
// TODO MemUtil.writeStringParcelableMap(dest, customData);
dest.writeByte((byte) (expires ? 1 : 0));
dest.writeString(notes);
dest.writeByte((byte) (isExpanded ? 1 : 0));
dest.writeString(defaultAutoTypeSequence);
dest.writeByte((byte) (enableAutoType == null ? -1 : (enableAutoType ? 1 : 0)));
dest.writeByte((byte) (enableAutoType == null ? -1 : (enableAutoType ? 1 : 0)));
dest.writeSerializable(lastTopVisibleEntry);
}
public static final Creator<PwGroupV4> CREATOR = new Creator<PwGroupV4>() {
@Override
public PwGroupV4 createFromParcel(Parcel in) {
return new PwGroupV4(in);
}
@Override
public PwGroupV4[] newArray(int size) {
return new PwGroupV4[size];
}
};
protected void updateWith(PwGroupV4 source) { protected void updateWith(PwGroupV4 source) {
super.assign(source); super.assign(source);
uuid = source.uuid; uuid = source.uuid;
@@ -120,14 +169,6 @@ public class PwGroupV4 extends PwGroup<PwGroupV4, PwGroupV4, PwEntryV4> implemen
this.uuid = uuid; this.uuid = uuid;
} }
public PwIconCustom getCustomIcon() {
return customIcon;
}
public void setCustomIcon(PwIconCustom icon) {
this.customIcon = icon;
}
@Override @Override
public PwGroupId getId() { public PwGroupId getId() {
return new PwGroupIdV4(uuid); return new PwGroupIdV4(uuid);
@@ -176,13 +217,26 @@ public class PwGroupV4 extends PwGroup<PwGroupV4, PwGroupV4, PwEntryV4> implemen
@Override @Override
public PwIcon getIcon() { public PwIcon getIcon() {
if (customIcon == null || customIcon.uuid.equals(PwDatabase.UUID_ZERO)) { if (customIcon == null || customIcon.getUUID().equals(PwDatabase.UUID_ZERO)) {
return super.getIcon(); return super.getIcon();
} else { } else {
return customIcon; return customIcon;
} }
} }
public PwIconCustom getIconCustom() {
return customIcon;
}
public void setIconCustom(PwIconCustom icon) {
this.customIcon = icon;
}
public void setIconStandard(PwIconStandard icon) { // TODO Encapsulate with PwEntryV4
this.icon = icon;
this.customIcon = PwIconCustom.ZERO;
}
public void putCustomData(String key, String value) { public void putCustomData(String key, String value) {
customData.put(key, value); customData.put(key, value);
} }

View File

@@ -19,11 +19,23 @@
*/ */
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import java.io.Serializable; import android.os.Parcel;
import android.os.Parcelable;
public abstract class PwIcon implements Serializable { public abstract class PwIcon implements Parcelable {
public boolean isMetaStreamIcon() { public boolean isMetaStreamIcon() {
return false; return false;
} }
protected PwIcon() {}
protected PwIcon(Parcel in) {}
public abstract boolean isUnknown();
@Override
public int describeContents() {
return 0;
}
} }

View File

@@ -19,25 +19,71 @@
*/ */
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import android.os.Parcel;
import java.util.UUID; import java.util.UUID;
public class PwIconCustom extends PwIcon { public class PwIconCustom extends PwIcon {
public static final PwIconCustom ZERO = new PwIconCustom(PwDatabase.UUID_ZERO, new byte[0]); public static final PwIconCustom ZERO = new PwIconCustom(PwDatabase.UUID_ZERO, new byte[0]);
public final UUID uuid; private final UUID uuid;
public byte[] imageData; transient private byte[] imageData;
public PwIconCustom(UUID u, byte[] data) { public PwIconCustom(UUID uuid, byte[] data) {
uuid = u; super();
imageData = data; this.uuid = uuid;
this.imageData = data;
} }
public PwIconCustom(PwIconCustom icon) { public PwIconCustom(PwIconCustom icon) {
super();
uuid = icon.uuid; uuid = icon.uuid;
imageData = icon.imageData; imageData = icon.imageData;
} }
protected PwIconCustom(Parcel in) {
super(in);
uuid = (UUID) in.readSerializable();
// TODO Take too much memories
// in.readByteArray(imageData);
}
@Override @Override
public boolean isUnknown() {
return uuid == null || this.equals(ZERO);
}
public UUID getUUID() {
return uuid;
}
public byte[] getImageData() {
return imageData;
}
public void setImageData(byte[] imageData) {
this.imageData = imageData;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeSerializable(uuid);
// Too big for a parcelable dest.writeByteArray(imageData);
}
public static final Creator<PwIconCustom> CREATOR = new Creator<PwIconCustom>() {
@Override
public PwIconCustom createFromParcel(Parcel in) {
return new PwIconCustom(in);
}
@Override
public PwIconCustom[] newArray(int size) {
return new PwIconCustom[size];
}
};
@Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
@@ -55,10 +101,7 @@ public class PwIconCustom extends PwIcon {
return false; return false;
PwIconCustom other = (PwIconCustom) obj; PwIconCustom other = (PwIconCustom) obj;
if (uuid == null) { if (uuid == null) {
if (other.uuid != null) return other.uuid == null;
return false; } else return uuid.equals(other.uuid);
} else if (!uuid.equals(other.uuid))
return false;
return true;
} }
} }

View File

@@ -37,20 +37,27 @@ public class PwIconFactory {
*/ */
private ReferenceMap customCache = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK); private ReferenceMap customCache = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK);
public PwIconStandard getFirstIcon() { public PwIconStandard getUnknownIcon() {
return getIcon(0); return getIcon(PwIconStandard.UNKNOWN);
}
public PwIconStandard getKeyIcon() {
return getIcon(PwIconStandard.KEY);
}
public PwIconStandard getTrashIcon() {
return getIcon(PwIconStandard.TRASH);
}
public PwIconStandard getFolderIcon() {
return getIcon(PwIconStandard.FOLDER);
} }
public PwIconStandard getIcon(int iconId) { public PwIconStandard getIcon(int iconId) {
PwIconStandard icon = (PwIconStandard) cache.get(iconId); PwIconStandard icon = (PwIconStandard) cache.get(iconId);
if (icon == null) { if (icon == null) {
if (iconId == 1) { icon = new PwIconStandard(iconId);
icon = PwIconStandard.FIRST;
}
else {
icon = new PwIconStandard(iconId);
}
cache.put(iconId, icon); cache.put(iconId, icon);
} }
@@ -68,25 +75,8 @@ public class PwIconFactory {
return icon; return icon;
} }
public PwIconCustom getIcon(UUID iconUuid, byte[] data) {
PwIconCustom icon = (PwIconCustom) customCache.get(iconUuid);
if (icon == null) {
icon = new PwIconCustom(iconUuid, data);
customCache.put(iconUuid, icon);
} else {
icon.imageData = data;
}
return icon;
}
public void setIconData(UUID iconUuid, byte[] data) {
getIcon(iconUuid, data);
}
public void put(PwIconCustom icon) { public void put(PwIconCustom icon) {
customCache.put(icon.uuid, icon); customCache.put(icon.getUUID(), icon);
} }
} }

View File

@@ -19,15 +19,20 @@
*/ */
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
public class PwIconStandard extends PwIcon { import android.os.Parcel;
public final int iconId;
// The first is number 0 public class PwIconStandard extends PwIcon {
public static PwIconStandard FIRST = new PwIconStandard(0); private final int iconId;
public static final int TRASH_BIN = 43; public static final int UNKNOWN = -1;
public static final int KEY = 0;
public static final int TRASH = 43;
public static final int FOLDER = 48; public static final int FOLDER = 48;
public PwIconStandard() {
this.iconId = KEY;
}
public PwIconStandard(int iconId) { public PwIconStandard(int iconId) {
this.iconId = iconId; this.iconId = iconId;
} }
@@ -36,6 +41,37 @@ public class PwIconStandard extends PwIcon {
this.iconId = icon.iconId; this.iconId = icon.iconId;
} }
protected PwIconStandard(Parcel in) {
super(in);
iconId = in.readInt();
}
@Override
public boolean isUnknown() {
return iconId == UNKNOWN;
}
public int getIconId() {
return iconId;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(iconId);
}
public static final Creator<PwIconStandard> CREATOR = new Creator<PwIconStandard>() {
@Override
public PwIconStandard createFromParcel(Parcel in) {
return new PwIconStandard(in);
}
@Override
public PwIconStandard[] newArray(int size) {
return new PwIconStandard[size];
}
};
@Override @Override
public boolean isMetaStreamIcon() { public boolean isMetaStreamIcon() {
return iconId == 0; return iconId == 0;

View File

@@ -20,33 +20,69 @@
*/ */
package com.kunzisoft.keepass.database; package com.kunzisoft.keepass.database;
import org.joda.time.LocalDate; import android.os.Parcel;
import android.os.Parcelable;
import java.io.Serializable; import com.kunzisoft.keepass.app.App;
import org.joda.time.LocalDate;
/** /**
* Abstract class who manage Groups and Entries * Abstract class who manage Groups and Entries
*/ */
public abstract class PwNode<Parent extends PwGroup> implements ISmallTimeLogger, Serializable, Cloneable { public abstract class PwNode<Parent extends PwGroup> implements ISmallTimeLogger, Parcelable, Cloneable {
protected Parent parent = null; protected Parent parent = null;
protected PwIconStandard icon = new PwIconStandard();
protected PwIconStandard icon = PwIconStandard.FIRST;
protected PwDate creation = new PwDate(); protected PwDate creation = new PwDate();
protected PwDate lastMod = new PwDate(); protected PwDate lastMod = new PwDate();
protected PwDate lastAccess = new PwDate(); protected PwDate lastAccess = new PwDate();
protected PwDate expireDate = PwDate.PW_NEVER_EXPIRE; protected PwDate expireDate = PwDate.PW_NEVER_EXPIRE;
protected PwNode() {}
protected PwNode(Parcel in) {
// TODO better technique ?
try {
PwGroupId pwGroupId = in.readParcelable(PwGroupId.class.getClassLoader());
parent = (Parent) App.getDB().getPwDatabase().getGroupByGroupId(pwGroupId);
} catch (Exception e) {
e.printStackTrace();
}
icon = in.readParcelable(PwIconStandard.class.getClassLoader());
creation = in.readParcelable(PwDate.class.getClassLoader());
lastMod = in.readParcelable(PwDate.class.getClassLoader());
lastAccess = in.readParcelable(PwDate.class.getClassLoader());
expireDate = in.readParcelable(PwDate.class.getClassLoader());
}
@Override
public void writeToParcel(Parcel dest, int flags) {
PwGroupId parentId = null;
if (parent != null)
parentId = parent.getId();
dest.writeParcelable(parentId, flags);
dest.writeParcelable(icon, flags);
dest.writeParcelable(creation, flags);
dest.writeParcelable(lastMod, flags);
dest.writeParcelable(lastAccess, flags);
dest.writeParcelable(expireDate, flags);
}
@Override
public int describeContents() {
return 0;
}
protected void construct(Parent parent) { protected void construct(Parent parent) {
this.parent = parent; this.parent = parent;
} }
protected void assign(PwNode<Parent> source) { protected void assign(PwNode<Parent> source) {
this.parent = source.parent; this.parent = source.parent;
this.icon = source.icon; this.icon = source.icon;
this.creation = source.creation; this.creation = source.creation;
this.lastMod = source.lastMod; this.lastMod = source.lastMod;
this.lastAccess = source.lastAccess; this.lastAccess = source.lastAccess;
@@ -59,9 +95,7 @@ public abstract class PwNode<Parent extends PwGroup> implements ISmallTimeLogger
try { try {
newNode = (PwNode) super.clone(); newNode = (PwNode) super.clone();
// newNode.parent stay the same in copy // newNode.parent stay the same in copy
newNode.icon = new PwIconStandard(this.icon); newNode.icon = new PwIconStandard(this.icon);
newNode.creation = creation.clone(); newNode.creation = creation.clone();
newNode.lastMod = lastMod.clone(); newNode.lastMod = lastMod.clone();
newNode.lastAccess = lastAccess.clone(); newNode.lastAccess = lastAccess.clone();
@@ -85,22 +119,27 @@ public abstract class PwNode<Parent extends PwGroup> implements ISmallTimeLogger
public abstract Type getType(); public abstract Type getType();
/** /**
* @return Title to display as view * @return Title
*/ */
public abstract String getDisplayTitle(); public abstract String getTitle();
/**
* @return Title to display, typically return alternative title if {@link #getTitle()} is empty
*/
protected abstract String getVisualTitle();
/** /**
* @return Visual icon * @return Visual icon
*/ */
public PwIcon getIcon() { public PwIcon getIcon() {
return icon; return getIconStandard();
} }
public PwIconStandard getIconStandard() { public PwIconStandard getIconStandard() {
return icon; return icon;
} }
public void setIcon(PwIconStandard icon) { public void setIconStandard(PwIconStandard icon) {
this.icon = icon; this.icon = icon;
} }
@@ -119,6 +158,13 @@ public abstract class PwNode<Parent extends PwGroup> implements ISmallTimeLogger
parent = prt; parent = prt;
} }
/**
* @return true if parent is present (can be a root or a detach element)
*/
public boolean containsParent() {
return getParent() != null;
}
public PwDate getCreationTime() { public PwDate getCreationTime() {
return creation; return creation;
} }
@@ -169,7 +215,7 @@ public abstract class PwNode<Parent extends PwGroup> implements ISmallTimeLogger
*/ */
public boolean isContentVisuallyTheSame(PwNode o) { public boolean isContentVisuallyTheSame(PwNode o) {
return getType().equals(o.getType()) return getType().equals(o.getType())
&& getDisplayTitle().equals(o.getDisplayTitle()) && getVisualTitle().equals(o.getVisualTitle())
&& getIcon().equals(o.getIcon()); && getIcon().equals(o.getIcon());
} }

View File

@@ -109,8 +109,8 @@ public enum SortNodeEnum {
new EntryNameComparator(ascending), new EntryNameComparator(ascending),
object1, object1,
object2, object2,
object1.getDisplayTitle() object1.getTitle()
.compareToIgnoreCase(object2.getDisplayTitle())); .compareToIgnoreCase(object2.getTitle()));
} }
} }

View File

@@ -0,0 +1,47 @@
package com.kunzisoft.keepass.database.action;
import android.content.Context;
import com.kunzisoft.keepass.database.Database;
public abstract class ActionWithSaveDatabaseRunnable extends RunnableOnFinish {
protected Context mContext;
protected boolean mDontSave;
protected Database mDatabase;
public ActionWithSaveDatabaseRunnable(Context context, Database database, OnFinishRunnable finish, boolean dontSave) {
super(finish);
this.mDatabase = database;
this.mContext = context;
this.mDontSave = dontSave;
this.mFinish = new AfterActionRunnable(finish);
}
@Override
public void run() {
// Commit to disk
SaveDatabaseRunnable save = new SaveDatabaseRunnable(mContext, mDatabase, mFinish, mDontSave);
save.run();
}
public void runWithoutSaveDatabase() {
mFinish.run();
}
abstract protected void onFinish(boolean success, String message);
private class AfterActionRunnable extends OnFinishRunnable {
AfterActionRunnable(OnFinishRunnable finish) {
super(finish);
}
@Override
public void run() {
onFinish(mSuccess, mMessage);
super.run();
}
}
}

View File

@@ -0,0 +1,91 @@
/*
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.database.action;
import android.content.Context;
import android.net.Uri;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwDatabase;
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
import com.kunzisoft.keepass.utils.UriUtil;
import java.io.IOException;
import java.io.InputStream;
public class AssignPasswordInDatabaseRunnable extends ActionWithSaveDatabaseRunnable {
private String mPassword;
private Uri mKeyfile;
private byte[] mBackupKey;
public AssignPasswordInDatabaseRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish) {
this(ctx, db, password, keyfile, finish, false);
}
public AssignPasswordInDatabaseRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish, boolean dontSave) {
super(ctx, db, finish, dontSave);
this.mPassword = password;
this.mKeyfile = keyfile;
}
@Override
public void run() {
PwDatabase pm = mDatabase.getPwDatabase();
mBackupKey = new byte[pm.getMasterKey().length];
System.arraycopy(pm.getMasterKey(), 0, mBackupKey, 0, mBackupKey.length);
// Set key
try {
InputStream is = UriUtil.getUriInputStream(mContext, mKeyfile);
pm.retrieveMasterKey(mPassword, is);
// Save Database
super.run();
} catch (InvalidKeyFileException|IOException e) {
erase(mBackupKey);
finish(false, e.getMessage());
super.runWithoutSaveDatabase();
}
}
@Override
protected void onFinish(boolean success, String message) {
if (!success) {
// Erase the current master key
erase(mDatabase.getPwDatabase().getMasterKey());
mDatabase.getPwDatabase().setMasterKey(mBackupKey);
}
}
/**
* Overwrite the array as soon as we don't need it to avoid keeping the extra data in memory
*/
private void erase(byte[] array) {
if ( array == null ) return;
for ( int i = 0; i < array.length; i++ ) {
array[i] = 0;
}
}
}

View File

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

View File

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

View File

@@ -17,12 +17,14 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.database.edit; package com.kunzisoft.keepass.database.action;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.StringRes;
import android.util.Log;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.app.App; import com.kunzisoft.keepass.app.App;
@@ -40,78 +42,92 @@ import com.kunzisoft.keepass.database.exception.KeyFileEmptyException;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
public class LoadDB extends RunnableOnFinish { public class LoadDatabaseRunnable extends RunnableOnFinish {
private static final String TAG = LoadDatabaseRunnable.class.getName();
private Context mContext;
private Database mDatabase;
private Uri mUri; private Uri mUri;
private String mPass; private String mPass;
private Uri mKey; private Uri mKey;
private Database mDb;
private Context mCtx;
private boolean mRememberKeyfile; private boolean mRememberKeyfile;
public LoadDB(Database db, Context ctx, Uri uri, String pass, Uri key, OnFinish finish) { public LoadDatabaseRunnable(Context context, Database database, Uri uri, String pass, Uri key, OnFinishRunnable finish) {
super(finish); super(finish);
mDb = db; this.mContext = context;
mCtx = ctx; this.mDatabase = database;
mUri = uri; this.mUri = uri;
mPass = pass; this.mPass = pass;
mKey = key; this.mKey = key;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
mRememberKeyfile = prefs.getBoolean(ctx.getString(R.string.keyfile_key), ctx.getResources().getBoolean(R.bool.keyfile_default)); this.mRememberKeyfile = prefs.getBoolean(context.getString(R.string.keyfile_key), context.getResources().getBoolean(R.bool.keyfile_default));
} }
@Override @Override
public void run() { public void run() {
try { try {
mDb.loadData(mCtx, mUri, mPass, mKey, mStatus); mDatabase.loadData(mContext, mUri, mPass, mKey, mStatus);
saveFileData(mUri, mKey); saveFileData(mUri, mKey);
} catch (ArcFourException e) { } catch (ArcFourException e) {
finish(false, mCtx.getString(R.string.error_arc4)); catchError(e, R.string.error_arc4);
return; return;
} catch (InvalidPasswordException e) { } catch (InvalidPasswordException e) {
finish(false, mCtx.getString(R.string.InvalidPassword)); catchError(e, R.string.invalid_password);
return; return;
} catch (ContentFileNotFoundException e) { } catch (ContentFileNotFoundException e) {
finish(false, mCtx.getString(R.string.file_not_found_content)); catchError(e, R.string.file_not_found_content);
return; return;
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
finish(false, mCtx.getString(R.string.file_not_found)); catchError(e, R.string.file_not_found);
return; return;
} catch (IOException e) { } catch (IOException e) {
finish(false, e.getMessage()); if (e.getMessage().contains("Hash failed with code"))
catchError(e, R.string.error_load_database_KDF_memory, true);
else
catchError(e, R.string.error_load_database, true);
return; return;
} catch (KeyFileEmptyException e) { } catch (KeyFileEmptyException e) {
finish(false, mCtx.getString(R.string.keyfile_is_empty)); catchError(e, R.string.keyfile_is_empty);
return; return;
} catch (InvalidAlgorithmException e) { } catch (InvalidAlgorithmException e) {
finish(false, mCtx.getString(R.string.invalid_algorithm)); catchError(e, R.string.invalid_algorithm);
return; return;
} catch (InvalidKeyFileException e) { } catch (InvalidKeyFileException e) {
finish(false, mCtx.getString(R.string.keyfile_does_not_exist)); catchError(e, R.string.keyfile_does_not_exist);
return; return;
} catch (InvalidDBSignatureException e) { } catch (InvalidDBSignatureException e) {
finish(false, mCtx.getString(R.string.invalid_db_sig)); catchError(e, R.string.invalid_db_sig);
return; return;
} catch (InvalidDBVersionException e) { } catch (InvalidDBVersionException e) {
finish(false, mCtx.getString(R.string.unsupported_db_version)); catchError(e, R.string.unsupported_db_version);
return; return;
} catch (InvalidDBException e) { } catch (InvalidDBException e) {
finish(false, mCtx.getString(R.string.error_invalid_db)); catchError(e, R.string.error_invalid_db);
return; return;
} catch (OutOfMemoryError e) { } catch (OutOfMemoryError e) {
finish(false, mCtx.getString(R.string.error_out_of_memory)); catchError(e, R.string.error_out_of_memory);
return; return;
} catch (Exception e) { } catch (Exception e) {
finish(false, e.getMessage()); catchError(e, R.string.error_load_database, true);
return; return;
} }
finish(true); finish(true);
} }
private void catchError(Throwable e, @StringRes int messageId) {
catchError(e, messageId, false);
}
private void catchError(Throwable e, @StringRes int messageId, boolean addThrowableMessage) {
String errorMessage = mContext.getString(messageId);
Log.e(TAG, errorMessage, e);
if (addThrowableMessage)
errorMessage = errorMessage + " " + e.getLocalizedMessage();
finish(false, errorMessage);
}
private void saveFileData(Uri uri, Uri key) { private void saveFileData(Uri uri, Uri key) {
if ( ! mRememberKeyfile ) { if ( ! mRememberKeyfile ) {
key = null; key = null;
@@ -120,6 +136,4 @@ public class LoadDB extends RunnableOnFinish {
App.getFileHistory().createFile(uri, key); App.getFileHistory().createFile(uri, key);
} }
} }

View File

@@ -17,7 +17,7 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.database.edit; package com.kunzisoft.keepass.database.action;
import android.content.Context; import android.content.Context;
import android.os.Handler; import android.os.Handler;
@@ -29,27 +29,27 @@ import android.widget.Toast;
* @author bpellin * @author bpellin
* *
*/ */
public class OnFinish implements Runnable { public class OnFinishRunnable implements Runnable {
protected boolean mSuccess; protected boolean mSuccess;
protected String mMessage; protected String mMessage;
protected OnFinish mOnFinish; protected OnFinishRunnable mOnFinish;
protected Handler mHandler; protected Handler mHandler;
public OnFinish() { public OnFinishRunnable() {
} }
public OnFinish(Handler handler) { public OnFinishRunnable(Handler handler) {
mOnFinish = null; mOnFinish = null;
mHandler = handler; mHandler = handler;
} }
public OnFinish(OnFinish finish, Handler handler) { public OnFinishRunnable(OnFinishRunnable finish, Handler handler) {
mOnFinish = finish; mOnFinish = finish;
mHandler = handler; mHandler = handler;
} }
public OnFinish(OnFinish finish) { public OnFinishRunnable(OnFinishRunnable finish) {
mOnFinish = finish; mOnFinish = finish;
mHandler = null; mHandler = null;
} }
@@ -75,11 +75,30 @@ public class OnFinish implements Runnable {
} }
} }
} }
/**
* ONLY to use in UIThread, typically in an Activity, Fragment or a Service
* @param ctx Context to show the message
*/
protected void displayMessage(Context ctx) { protected void displayMessage(Context ctx) {
if ( mMessage != null && mMessage.length() > 0 ) { if ( mMessage != null && mMessage.length() > 0 ) {
Toast.makeText(ctx, mMessage, Toast.LENGTH_LONG).show(); Toast.makeText(ctx, mMessage, Toast.LENGTH_LONG).show();
} }
} }
public boolean isSuccess() {
return mSuccess;
}
public void setSuccess(boolean mSuccess) {
this.mSuccess = mSuccess;
}
public String getMessage() {
return mMessage;
}
public void setMessage(String mMessage) {
this.mMessage = mMessage;
}
} }

View File

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

View File

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

View File

@@ -0,0 +1,33 @@
package com.kunzisoft.keepass.database.action.node;
import android.content.Context;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwNode;
import com.kunzisoft.keepass.database.action.ActionWithSaveDatabaseRunnable;
abstract class ActionNodeDatabaseRunnable extends ActionWithSaveDatabaseRunnable {
private AfterActionNodeOnFinish callbackRunnable;
public ActionNodeDatabaseRunnable(Context context, Database db, AfterActionNodeOnFinish finish, boolean dontSave) {
super(context, db, finish, dontSave);
this.callbackRunnable = finish;
}
/**
* Callback method who return the node(s) modified after an action
* - Add : @param oldNode NULL, @param newNode CreatedNode
* - Copy : @param oldNode NodeToCopy, @param newNode NodeCopied
* - Delete : @param oldNode NodeToDelete, @param NULL
* - Move : @param oldNode NULL, @param NodeToMove
* - Update : @param oldNode NodeToUpdate, @param NodeUpdated
*/
protected void callbackNodeAction(boolean success, String message, PwNode oldNode, PwNode newNode) {
if (callbackRunnable != null) {
callbackRunnable.setSuccess(success);
callbackRunnable.setMessage(message);
callbackRunnable.run(oldNode, newNode);
}
}
}

View File

@@ -17,57 +17,40 @@
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. * along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.database.edit; package com.kunzisoft.keepass.database.action.node;
import android.content.Context; import android.content.Context;
import com.kunzisoft.keepass.database.Database; import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwEntry; import com.kunzisoft.keepass.database.PwEntry;
public class AddEntry extends RunnableOnFinish { public class AddEntryRunnable extends ActionNodeDatabaseRunnable {
protected Database mDb; private PwEntry mNewEntry;
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 entryToAdd, AfterActionNodeOnFinish finish) {
this(ctx, db, entry, finish, false); this(ctx, db, entryToAdd, finish, false);
} }
public AddEntry(Context ctx, Database db, PwEntry entry, OnFinish finish, boolean dontSave) { public AddEntryRunnable(Context ctx, Database db, PwEntry entryToAdd, AfterActionNodeOnFinish finish, boolean dontSave) {
super(finish); super(ctx, db, finish, dontSave);
this.mDb = db; this.mNewEntry = entryToAdd;
this.mEntry = entry;
this.ctx = ctx;
this.mDontSave = dontSave;
this.mFinish = new AfterAdd(mFinish);
} }
@Override @Override
public void run() { public void run() {
mDb.addEntryTo(mEntry, mEntry.getParent()); mDatabase.addEntryTo(mNewEntry, mNewEntry.getParent());
// Commit to disk // Commit to disk
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave); super.run();
save.run();
} }
private class AfterAdd extends OnFinish {
AfterAdd(OnFinish finish) { @Override
super(finish); protected void onFinish(boolean success, String message) {
} if ( !success ) {
mDatabase.removeEntryFrom(mNewEntry, mNewEntry.getParent());
@Override
public void run() {
if ( !mSuccess ) {
mDb.removeEntryFrom(mEntry, mEntry.getParent());
}
// TODO if add entry callback
super.run();
} }
callbackNodeAction(success, message, null, mNewEntry);
} }
} }

View File

@@ -0,0 +1,56 @@
/*
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.database.action.node;
import android.content.Context;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwGroup;
public class AddGroupRunnable extends ActionNodeDatabaseRunnable {
private PwGroup mNewGroup;
public AddGroupRunnable(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode) {
this(ctx, db, newGroup, afterAddNode, false);
}
public AddGroupRunnable(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode, boolean dontSave) {
super(ctx, db, afterAddNode, dontSave);
this.mNewGroup = newGroup;
}
@Override
public void run() {
mDatabase.addGroupTo(mNewGroup, mNewGroup.getParent());
// Commit to disk
super.run();
}
@Override
protected void onFinish(boolean success, String message) {
if ( !success ) {
mDatabase.removeGroupFrom(mNewGroup, mNewGroup.getParent());
}
callbackNodeAction(success, message, null, mNewGroup);
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2018 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.database.action.node;
import android.os.Handler;
import com.kunzisoft.keepass.database.PwNode;
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
import javax.annotation.Nullable;
public abstract class AfterActionNodeOnFinish extends OnFinishRunnable {
public AfterActionNodeOnFinish() {
super(new Handler());
}
public abstract void run(@Nullable PwNode oldNode, @Nullable PwNode newNode);
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright 2018 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.database.action.node;
import android.content.Context;
import android.util.Log;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.PwGroup;
public class CopyEntryRunnable extends ActionNodeDatabaseRunnable {
private static final String TAG = CopyEntryRunnable.class.getName();
private PwEntry mEntryToCopy;
private PwEntry mEntryCopied;
private PwGroup mNewParent;
public CopyEntryRunnable(Context context, Database db, PwEntry oldE, PwGroup newParent, AfterActionNodeOnFinish afterAddNode) {
this(context, db, oldE, newParent, afterAddNode, false);
}
public CopyEntryRunnable(Context context, Database db, PwEntry oldE, PwGroup newParent, AfterActionNodeOnFinish afterAddNode, boolean dontSave) {
super(context, db, afterAddNode, dontSave);
this.mEntryToCopy = oldE;
this.mNewParent = newParent;
}
@Override
public void run() {
// Update entry with new values
mEntryCopied = mDatabase.copyEntry(mEntryToCopy, mNewParent);
if (mEntryCopied != null) {
mEntryCopied.touch(true, true);
// Commit to disk
super.run();
} else {
Log.e(TAG, "Unable to create a copy of the entry");
}
}
@Override
protected void onFinish(boolean success, String message) {
if ( !success ) {
// If we fail to save, try to delete the copy
try {
mDatabase.deleteEntry(mEntryCopied);
} catch (Exception e) {
Log.i(TAG, "Unable to delete the copied entry");
}
}
callbackNodeAction(success, message, mEntryToCopy, mEntryCopied);
}
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.database.action.node;
import android.content.Context;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.PwGroup;
public class DeleteEntryRunnable extends ActionNodeDatabaseRunnable {
private PwEntry mEntryToDelete;
private PwGroup mParent;
private boolean mRecycle;
public DeleteEntryRunnable(Context ctx, Database db, PwEntry entry, AfterActionNodeOnFinish finish) {
this(ctx, db, entry, finish, false);
}
public DeleteEntryRunnable(Context ctx, Database db, PwEntry entry, AfterActionNodeOnFinish finish, boolean dontSave) {
super(ctx, db, finish, dontSave);
this.mEntryToDelete = entry;
}
@Override
public void run() {
mParent = mEntryToDelete.getParent();
// Remove Entry from parent
mRecycle = mDatabase.canRecycle(mEntryToDelete);
if (mRecycle) {
mDatabase.recycle(mEntryToDelete);
}
else {
mDatabase.deleteEntry(mEntryToDelete);
}
// Commit database
super.run();
}
@Override
protected void onFinish(boolean success, String message) {
if ( !success ) {
if (mRecycle) {
mDatabase.undoRecycle(mEntryToDelete, mParent);
}
else {
mDatabase.undoDeleteEntry(mEntryToDelete, mParent);
}
}
callbackNodeAction(success, message, mEntryToDelete, null);
}
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.database.action.node;
import android.content.Context;
import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.PwGroup;
import java.util.ArrayList;
import java.util.List;
public class DeleteGroupRunnable extends ActionNodeDatabaseRunnable {
private PwGroup<PwGroup, PwEntry> mGroupToDelete;
private PwGroup mParent;
private boolean mRecycle;
public DeleteGroupRunnable(Context ctx, Database db, PwGroup<PwGroup, PwEntry> group, AfterActionNodeOnFinish finish) {
this(ctx, db, group, finish, false);
}
public DeleteGroupRunnable(Context ctx, Database db, PwGroup<PwGroup, PwEntry> group, AfterActionNodeOnFinish finish, boolean dontSave) {
super(ctx, db, finish, dontSave);
mGroupToDelete = group;
}
@Override
public void run() {
mParent = mGroupToDelete.getParent();
// Remove Group from parent
mRecycle = mDatabase.canRecycle(mGroupToDelete);
if (mRecycle) {
mDatabase.recycle(mGroupToDelete);
}
else {
// TODO tests
// Remove child entries
List<PwEntry> childEnt = new ArrayList<>(mGroupToDelete.getChildEntries()); // TODO new Methods
for ( int i = 0; i < childEnt.size(); i++ ) {
DeleteEntryRunnable task = new DeleteEntryRunnable(mContext, mDatabase, childEnt.get(i), null, true);
task.run();
}
// Remove child groups
List<PwGroup> childGrp = new ArrayList<>(mGroupToDelete.getChildGroups());
for ( int i = 0; i < childGrp.size(); i++ ) {
DeleteGroupRunnable task = new DeleteGroupRunnable(mContext, mDatabase, childGrp.get(i), null, true);
task.run();
}
mDatabase.deleteGroup(mGroupToDelete);
// Remove from PwDatabaseV3
// TODO ENcapsulate
mDatabase.getPwDatabase().getGroups().remove(mGroupToDelete);
}
// Commit Database
super.run();
}
@Override
protected void onFinish(boolean success, String message) {
if ( !success ) {
if (mRecycle) {
mDatabase.undoRecycle(mGroupToDelete, mParent);
}
else {
// Let's not bother recovering from a failure to save a deleted tree. It is too much work.
App.setShutdown();
// TODO TEST pm.undoDeleteGroup(mGroup, mParent);
}
}
callbackNodeAction(success, message, mGroupToDelete, null);
}
}

View File

@@ -0,0 +1,77 @@
/*
* Copyright 2018 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.database.action.node;
import android.content.Context;
import android.util.Log;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.PwGroup;
public class MoveEntryRunnable extends ActionNodeDatabaseRunnable {
private static final String TAG = MoveEntryRunnable.class.getName();
private PwEntry mEntryToMove;
private PwGroup mOldParent;
private PwGroup mNewParent;
public MoveEntryRunnable(Context context, Database db, PwEntry oldE, PwGroup newParent, AfterActionNodeOnFinish afterAddNode) {
this(context, db, oldE, newParent, afterAddNode, false);
}
public MoveEntryRunnable(Context context, Database db, PwEntry oldE, PwGroup newParent, AfterActionNodeOnFinish afterAddNode, boolean dontSave) {
super(context, db, afterAddNode, dontSave);
this.mEntryToMove = oldE;
this.mNewParent = newParent;
}
@Override
public void run() {
// Move entry in new parent
mOldParent = mEntryToMove.getParent();
mDatabase.moveEntry(mEntryToMove, mNewParent);
if (mEntryToMove != null) {
mEntryToMove.touch(true, true);
// Commit to disk
super.run();
} else {
Log.e(TAG, "Unable to create a copy of the entry");
}
}
@Override
protected void onFinish(boolean success, String message) {
if ( !success ) {
// If we fail to save, try to remove in the first place
try {
mDatabase.moveEntry(mEntryToMove, mOldParent);
} catch (Exception e) {
Log.i(TAG, "Unable to replace the entry");
}
}
callbackNodeAction(success, message, null, mEntryToMove);
}
}

View File

@@ -0,0 +1,86 @@
/*
* Copyright 2018 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.database.action.node;
import android.content.Context;
import android.util.Log;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwGroup;
public class MoveGroupRunnable extends ActionNodeDatabaseRunnable {
private static final String TAG = MoveGroupRunnable.class.getName();
private PwGroup mGroupToMove;
private PwGroup mOldParent;
private PwGroup mNewParent;
public MoveGroupRunnable(Context context, Database db, PwGroup groupToMove, PwGroup newParent, AfterActionNodeOnFinish afterAddNode) {
this(context, db, groupToMove, newParent, afterAddNode, false);
}
public MoveGroupRunnable(Context context, Database db, PwGroup groupToMove, PwGroup newParent, AfterActionNodeOnFinish afterAddNode, boolean dontSave) {
super(context, db, afterAddNode, dontSave);
this.mGroupToMove = groupToMove;
this.mNewParent = newParent;
}
@Override
public void run() {
mOldParent = mGroupToMove.getParent();
// Move group in new parent if not in the current group
if (!mGroupToMove.equals(mNewParent)
&& !mNewParent.isContainedIn(mGroupToMove)) {
mDatabase.moveGroup(mGroupToMove, mNewParent);
if (mGroupToMove != null) {
mGroupToMove.touch(true, true);
// Commit to disk
super.run();
} else {
Log.e(TAG, "Unable to create a copy of the group");
}
} else {
// Only finish thread
mFinish.setResult(false);
String message = mContext.getString(R.string.error_move_folder_in_itself);
Log.e(TAG, message);
mFinish.setMessage(message);
mFinish.run();
}
}
@Override
protected void onFinish(boolean success, String message) {
if ( !success ) {
// If we fail to save, try to move in the first place
try {
mDatabase.moveGroup(mGroupToMove, mOldParent);
} catch (Exception e) {
Log.i(TAG, "Unable to replace the group");
}
}
callbackNodeAction(success, message, null, mGroupToMove);
}
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.database.action.node;
import android.content.Context;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwEntry;
public class UpdateEntryRunnable extends ActionNodeDatabaseRunnable {
private PwEntry mOldEntry;
private PwEntry mNewEntry;
private PwEntry mBackupEntry;
public UpdateEntryRunnable(Context ctx, Database db, PwEntry oldE, PwEntry newE, AfterActionNodeOnFinish finish) {
this(ctx, db, oldE, newE, finish, false);
}
public UpdateEntryRunnable(Context ctx, Database db, PwEntry oldE, PwEntry newE, AfterActionNodeOnFinish finish, boolean dontSave) {
super(ctx, db, finish, dontSave);
this.mOldEntry = oldE;
this.mNewEntry = newE;
// Keep backup of original values in case save fails
this.mBackupEntry = mOldEntry.clone();
}
@Override
public void run() {
// Update entry with new values
mDatabase.updateEntry(mOldEntry, mNewEntry);
mOldEntry.touch(true, true);
super.run();
}
@Override
protected void onFinish(boolean success, String message) {
if ( !success ) {
// If we fail to save, back out changes to global structure
mDatabase.updateEntry(mOldEntry, mBackupEntry);
}
callbackNodeAction(success, message, mOldEntry, mNewEntry);
}
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.database.action.node;
import android.content.Context;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwGroup;
public class UpdateGroupRunnable extends ActionNodeDatabaseRunnable {
private PwGroup mOldGroup;
private PwGroup mNewGroup;
private PwGroup mBackupGroup;
public UpdateGroupRunnable(Context ctx, Database db, PwGroup oldGroup, PwGroup newGroup, AfterActionNodeOnFinish finish) {
this(ctx, db, oldGroup, newGroup, finish, false);
}
public UpdateGroupRunnable(Context ctx, Database db, PwGroup oldGroup, PwGroup newGroup, AfterActionNodeOnFinish finish, boolean dontSave) {
super(ctx, db, finish, dontSave);
this.mOldGroup = oldGroup;
this.mNewGroup = newGroup;
// Keep backup of original values in case save fails
this.mBackupGroup = mOldGroup.clone();
}
@Override
public void run() {
// Update group with new values
mDatabase.updateGroup(mOldGroup, mNewGroup);
mOldGroup.touch(true, true);
// Commit to disk
super.run();
}
@Override
protected void onFinish(boolean success, String message) {
if ( !success ) {
// If we fail to save, back out changes to global structure
mDatabase.updateGroup(mOldGroup, mBackupGroup);
}
callbackNodeAction(success, message, mOldGroup, mNewGroup);
}
}

View File

@@ -0,0 +1,125 @@
package com.kunzisoft.keepass.database.cursor;
import android.database.MatrixCursor;
import android.provider.BaseColumns;
import com.kunzisoft.keepass.database.PwDatabase;
import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.PwEntryV3;
import com.kunzisoft.keepass.database.PwEntryV4;
import com.kunzisoft.keepass.database.PwIconCustom;
import com.kunzisoft.keepass.database.PwIconFactory;
import com.kunzisoft.keepass.database.PwIconStandard;
import java.util.UUID;
public class EntryCursor extends MatrixCursor {
private long entryId;
public static final String _ID = BaseColumns._ID;
public static final String COLUMN_INDEX_UUID_MOST_SIGNIFICANT_BITS = "UUID_most_significant_bits";
public static final String COLUMN_INDEX_UUID_LEAST_SIGNIFICANT_BITS = "UUID_least_significant_bits";
public static final String COLUMN_INDEX_TITLE = "title";
public static final String COLUMN_INDEX_ICON_STANDARD = "icon_standard";
public static final String COLUMN_INDEX_ICON_CUSTOM_UUID_MOST_SIGNIFICANT_BITS = "icon_custom_UUID_most_significant_bits";
public static final String COLUMN_INDEX_ICON_CUSTOM_UUID_LEAST_SIGNIFICANT_BITS = "icon_custom_UUID_least_significant_bits";
public static final String COLUMN_INDEX_USERNAME = "username";
public static final String COLUMN_INDEX_PASSWORD = "password";
public static final String COLUMN_INDEX_URL = "URL";
public static final String COLUMN_INDEX_NOTES = "notes";
private ExtraFieldCursor extraFieldCursor;
public EntryCursor() {
super(new String[]{ _ID,
COLUMN_INDEX_UUID_MOST_SIGNIFICANT_BITS,
COLUMN_INDEX_UUID_LEAST_SIGNIFICANT_BITS,
COLUMN_INDEX_TITLE,
COLUMN_INDEX_ICON_STANDARD,
COLUMN_INDEX_ICON_CUSTOM_UUID_MOST_SIGNIFICANT_BITS,
COLUMN_INDEX_ICON_CUSTOM_UUID_LEAST_SIGNIFICANT_BITS,
COLUMN_INDEX_USERNAME,
COLUMN_INDEX_PASSWORD,
COLUMN_INDEX_URL,
COLUMN_INDEX_NOTES});
entryId = 0;
extraFieldCursor = new ExtraFieldCursor();
}
public void addEntry(PwEntryV3 entry) {
addRow(new Object[] {entryId,
entry.getUUID().getMostSignificantBits(),
entry.getUUID().getLeastSignificantBits(),
entry.getTitle(),
entry.getIconStandard().getIconId(),
PwDatabase.UUID_ZERO.getMostSignificantBits(),
PwDatabase.UUID_ZERO.getLeastSignificantBits(),
entry.getUsername(),
entry.getPassword(),
entry.getUrl(),
entry.getNotes()});
entryId++;
}
public void addEntry(PwEntryV4 entry) {
addRow(new Object[] {entryId,
entry.getUUID().getMostSignificantBits(),
entry.getUUID().getLeastSignificantBits(),
entry.getTitle(),
entry.getIconStandard().getIconId(),
entry.getIconCustom().getUUID().getMostSignificantBits(),
entry.getIconCustom().getUUID().getLeastSignificantBits(),
entry.getUsername(),
entry.getPassword(),
entry.getUrl(),
entry.getNotes()});
entry.getFields().doActionToAllCustomProtectedField((key, value) -> {
extraFieldCursor.addExtraField(entryId, key, value);
});
entryId++;
}
private void populateEntryBaseVersion(PwEntry pwEntry, PwIconFactory iconFactory) {
pwEntry.setUUID(
new UUID(getLong(getColumnIndex(EntryCursor.COLUMN_INDEX_UUID_MOST_SIGNIFICANT_BITS)),
getLong(getColumnIndex(EntryCursor.COLUMN_INDEX_UUID_LEAST_SIGNIFICANT_BITS))));
pwEntry.setTitle(getString(getColumnIndex(EntryCursor.COLUMN_INDEX_TITLE)));
PwIconStandard iconStandard = iconFactory.getIcon(getInt(getColumnIndex(EntryCursor.COLUMN_INDEX_ICON_STANDARD)));
pwEntry.setIconStandard(iconStandard);
pwEntry.setUsername(getString(getColumnIndex(EntryCursor.COLUMN_INDEX_USERNAME)));
pwEntry.setPassword(getString(getColumnIndex(EntryCursor.COLUMN_INDEX_PASSWORD)));
pwEntry.setUrl(getString(getColumnIndex(EntryCursor.COLUMN_INDEX_URL)));
pwEntry.setNotes(getString(getColumnIndex(EntryCursor.COLUMN_INDEX_NOTES)));
}
public void populateEntry(PwEntryV3 pwEntry, PwIconFactory iconFactory) {
populateEntryBaseVersion(pwEntry, iconFactory);
}
public void populateEntry(PwEntryV4 pwEntry, PwIconFactory iconFactory) {
populateEntryBaseVersion(pwEntry, iconFactory);
// Retrieve custom icon
PwIconCustom iconCustom = iconFactory.getIcon(
new UUID(getLong(getColumnIndex(EntryCursor.COLUMN_INDEX_ICON_CUSTOM_UUID_MOST_SIGNIFICANT_BITS)),
getLong(getColumnIndex(EntryCursor.COLUMN_INDEX_ICON_CUSTOM_UUID_LEAST_SIGNIFICANT_BITS))));
pwEntry.setIconCustom(iconCustom);
// Retrieve extra fields
if (extraFieldCursor.moveToFirst()) {
while (!extraFieldCursor.isAfterLast()) {
// Add a new extra field only if entryId is the one we want
if (extraFieldCursor.getLong(extraFieldCursor.getColumnIndex(ExtraFieldCursor.FOREIGN_KEY_ENTRY_ID))
== getLong(getColumnIndex(EntryCursor._ID))) {
extraFieldCursor.populateExtraFieldInEntry(pwEntry);
}
extraFieldCursor.moveToNext();
}
}
}
}

View File

@@ -0,0 +1,43 @@
package com.kunzisoft.keepass.database.cursor;
import android.database.MatrixCursor;
import android.provider.BaseColumns;
import com.kunzisoft.keepass.database.PwEntryV4;
import com.kunzisoft.keepass.database.security.ProtectedString;
public class ExtraFieldCursor extends MatrixCursor {
private long fieldId;
public static final String _ID = BaseColumns._ID;
public static final String FOREIGN_KEY_ENTRY_ID = "entry_id";
public static final String COLUMN_LABEL = "label";
public static final String COLUMN_PROTECTION = "protection";
public static final String COLUMN_VALUE = "value";
public ExtraFieldCursor() {
super(new String[]{ _ID,
FOREIGN_KEY_ENTRY_ID,
COLUMN_LABEL,
COLUMN_PROTECTION,
COLUMN_VALUE});
fieldId = 0;
}
public synchronized void addExtraField(long entryId, String label, ProtectedString value) {
addRow(new Object[] {fieldId,
entryId,
label,
(value.isProtected()) ? 1 : 0,
value.toString()});
fieldId++;
}
public void populateExtraFieldInEntry(PwEntryV4 pwEntry) {
pwEntry.addExtraField(getString(getColumnIndex(ExtraFieldCursor.COLUMN_LABEL)),
new ProtectedString((getInt(getColumnIndex(ExtraFieldCursor.COLUMN_PROTECTION)) > 0),
getString(getColumnIndex(ExtraFieldCursor.COLUMN_VALUE))));
}
}

View File

@@ -1,79 +0,0 @@
/*
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.database.edit;
import android.content.Context;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwGroup;
public class AddGroup extends RunnableOnFinish {
protected Database mDb;
private PwGroup mNewGroup;
private Context ctx;
private boolean mDontSave;
public AddGroup(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode) {
this(ctx, db, newGroup, afterAddNode, false);
}
public AddGroup(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode,
boolean dontSave) {
super(afterAddNode);
this.mDb = db;
this.mNewGroup = newGroup;
this.mDontSave = dontSave;
this.ctx = ctx;
this.mFinish = new AfterAdd(mFinish);
}
@Override
public void run() {
mDb.addGroupTo(mNewGroup, mNewGroup.getParent());
// Commit to disk
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave);
save.run();
}
private class AfterAdd extends OnFinish {
AfterAdd(OnFinish finish) {
super(finish);
}
@Override
public void run() {
if ( !mSuccess ) {
mDb.removeGroupFrom(mNewGroup, mNewGroup.getParent());
}
// TODO Better callback
AfterActionNodeOnFinish afterAddNode =
(AfterActionNodeOnFinish) super.mOnFinish;
afterAddNode.mSuccess = mSuccess;
afterAddNode.mMessage = mMessage;
afterAddNode.run(null, mNewGroup);
}
}
}

View File

@@ -1,103 +0,0 @@
/*
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.database.edit;
import android.content.Context;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.PwGroup;
/** Task to delete entries
* @author bpellin
*
*/
public class DeleteEntry extends RunnableOnFinish {
private Database mDb;
private PwEntry mEntry;
private boolean mDontSave;
private Context ctx;
public DeleteEntry(Context ctx, Database db, PwEntry entry, OnFinish finish) {
this(ctx, db, entry, finish, false);
}
public DeleteEntry(Context ctx, Database db, PwEntry entry, OnFinish finish, boolean dontSave) {
super(finish);
this.mDb = db;
this.mEntry = entry;
this.mDontSave = dontSave;
this.ctx = ctx;
}
@Override
public void run() {
PwGroup parent = mEntry.getParent();
// Remove Entry from parent
boolean recycle = mDb.canRecycle(mEntry);
if (recycle) {
mDb.recycle(mEntry);
}
else {
mDb.deleteEntry(mEntry);
}
// Save
mFinish = new AfterDelete(mFinish, parent, mEntry, recycle);
// Commit database
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave);
save.run();
}
private class AfterDelete extends OnFinish {
private PwGroup mParent;
private PwEntry mEntry;
private boolean recycled;
AfterDelete(OnFinish finish, PwGroup parent, PwEntry entry, boolean r) {
super(finish);
mParent = parent;
mEntry = entry;
recycled = r;
}
@Override
public void run() {
if ( !mSuccess ) {
if (recycled) {
mDb.undoRecycle(mEntry, mParent);
}
else {
mDb.undoDeleteEntry(mEntry, mParent);
}
}
// TODO Callback after delete entry
super.run();
}
}
}

View File

@@ -1,125 +0,0 @@
/*
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.database.edit;
import android.content.Context;
import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.database.PwGroup;
import java.util.ArrayList;
import java.util.List;
public class DeleteGroup extends RunnableOnFinish {
private Context mContext;
private Database mDb;
private PwGroup<PwGroup, PwGroup, PwEntry> mGroup;
private boolean mDontSave;
public DeleteGroup(Context ctx, Database db, PwGroup<PwGroup, PwGroup, PwEntry> group, OnFinish finish) {
super(finish);
setMembers(ctx, db, group, false);
}
public DeleteGroup(Context ctx, Database db, PwGroup<PwGroup, PwGroup, PwEntry> group, OnFinish finish, boolean dontSave) {
super(finish);
setMembers(ctx, db, group, dontSave);
}
private void setMembers(Context ctx, Database db, PwGroup<PwGroup, PwGroup, PwEntry> group, boolean dontSave) {
mDb = db;
mGroup = group;
mContext = ctx;
mDontSave = dontSave;
}
@Override
public void run() {
PwGroup parent = mGroup.getParent();
// Remove Group from parent
boolean recycle = mDb.canRecycle(mGroup);
if (recycle) {
mDb.recycle(mGroup);
}
else {
// TODO tests
// Remove child entries
List<PwEntry> childEnt = new ArrayList<>(mGroup.getChildEntries()); // TODO new Methods
for ( int i = 0; i < childEnt.size(); i++ ) {
DeleteEntry task = new DeleteEntry(mContext, mDb, childEnt.get(i), null, true);
task.run();
}
// Remove child groups
List<PwGroup> childGrp = new ArrayList<>(mGroup.getChildGroups());
for ( int i = 0; i < childGrp.size(); i++ ) {
DeleteGroup task = new DeleteGroup(mContext, mDb, childGrp.get(i), null, true);
task.run();
}
mDb.deleteGroup(mGroup);
// Remove from PwDatabaseV3
// TODO ENcapsulate
mDb.getPwDatabase().getGroups().remove(mGroup);
}
// Save
mFinish = new AfterDelete(mFinish, parent, mGroup, recycle);
// Commit Database
SaveDB save = new SaveDB(mContext, mDb, mFinish, mDontSave);
save.run();
}
private class AfterDelete extends OnFinish {
private PwGroup mParent;
private PwGroup mGroup;
private boolean recycled;
AfterDelete(OnFinish finish, PwGroup parent, PwGroup mGroup, boolean recycle) {
super(finish);
this.mParent = parent;
this.mGroup = mGroup;
this.recycled = recycle;
}
public void run() {
if ( !mSuccess ) {
if (recycled) {
mDb.undoRecycle(mGroup, mParent);
}
else {
// Let's not bother recovering from a failure to save a deleted tree. It is too much work.
App.setShutdown();
// TODO TEST pm.undoDeleteGroup(mGroup, mParent);
}
}
// TODO Callback after delete group
super.run();
}
}
}

View File

@@ -1,128 +0,0 @@
/*
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.database.edit;
import android.content.Context;
import android.content.DialogInterface;
import android.net.Uri;
import com.kunzisoft.keepass.database.Database;
import com.kunzisoft.keepass.database.PwDatabase;
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper;
import com.kunzisoft.keepass.utils.UriUtil;
import java.io.IOException;
import java.io.InputStream;
public class SetPassword extends RunnableOnFinish {
private String mPassword;
private Uri mKeyfile;
private Database mDb;
private boolean mDontSave;
private Context ctx;
public SetPassword(Context ctx, Database db, String password, Uri keyfile, OnFinish finish) {
this(ctx, db, password, keyfile, finish, false);
}
public SetPassword(Context ctx, Database db, String password, Uri keyfile, OnFinish finish, boolean dontSave) {
super(finish);
mDb = db;
mPassword = password;
mKeyfile = keyfile;
mDontSave = dontSave;
this.ctx = ctx;
}
public boolean validatePassword(Context ctx, DialogInterface.OnClickListener onclick) {
if (!mDb.getPwDatabase().validatePasswordEncoding(mPassword)) {
PasswordEncodingDialogHelper dialog = new PasswordEncodingDialogHelper();
dialog.show(ctx, onclick, true);
return false;
}
return true;
}
@Override
public void run() {
PwDatabase pm = mDb.getPwDatabase();
byte[] backupKey = new byte[pm.getMasterKey().length];
System.arraycopy(pm.getMasterKey(), 0, backupKey, 0, backupKey.length);
// Set key
try {
InputStream is = UriUtil.getUriInputStream(ctx, mKeyfile);
pm.setMasterKey(mPassword, is);
} catch (InvalidKeyFileException e) {
erase(backupKey);
finish(false, e.getMessage());
return;
} catch (IOException e) {
erase(backupKey);
finish(false, e.getMessage());
return;
}
// Save Database
mFinish = new AfterSave(backupKey, mFinish);
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave);
save.run();
}
private class AfterSave extends OnFinish {
private byte[] mBackup;
public AfterSave(byte[] backup, OnFinish finish) {
super(finish);
mBackup = backup;
}
@Override
public void run() {
if ( ! mSuccess ) {
// Erase the current master key
erase(mDb.getPwDatabase().getMasterKey());
mDb.getPwDatabase().setMasterKey(mBackup);
}
super.run();
}
}
/** Overwrite the array as soon as we don't need it to avoid keeping the extra data in memory
* @param array
*/
private void erase(byte[] array) {
if ( array == null ) return;
for ( int i = 0; i < array.length; i++ ) {
array[i] = 0;
}
}
}

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