From 2180d39f685b54f8c17e9312b7b9111d3008bad0 Mon Sep 17 00:00:00 2001 From: Herbert Poul Date: Wed, 4 Mar 2020 20:28:48 +0100 Subject: [PATCH] fix bug loading hex keyfile without newline. https://github.com/authpass/authpass/issues/3 --- lib/src/kdbx_format.dart | 3 ++- test/kdbx_test.dart | 9 +++++++++ test/keyfile/hexkey_no_newline | 1 + test/keyfile/newdatabase2.kdbx | Bin 0 -> 1934 bytes 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/keyfile/hexkey_no_newline create mode 100644 test/keyfile/newdatabase2.kdbx diff --git a/lib/src/kdbx_format.dart b/lib/src/kdbx_format.dart index f462c5f..05887e7 100644 --- a/lib/src/kdbx_format.dart +++ b/lib/src/kdbx_format.dart @@ -87,7 +87,8 @@ class KeyFileCredentials implements CredentialsPart { KeyFileCredentials._(this._keyFileValue); - static final RegExp _hexValuePattern = RegExp(r'/^[a-f\d]{64}$/i'); + static final RegExp _hexValuePattern = + RegExp(r'^[a-f\d]{64}', caseSensitive: false); final ProtectedValue _keyFileValue; diff --git a/test/kdbx_test.dart b/test/kdbx_test.dart index bb7fd12..cf44a2a 100644 --- a/test/kdbx_test.dart +++ b/test/kdbx_test.dart @@ -41,6 +41,15 @@ void main() { final file = kdbxForamt.read(data, cred); expect(file.body.rootGroup.entries, hasLength(2)); }); + test('Read with PW and hex keyfile', () async { + final keyFileBytes = + await File('test/keyfile/hexkey_no_newline').readAsBytes(); + final cred = Credentials.composite( + ProtectedValue.fromString('testing99'), keyFileBytes); + final data = await File('test/keyfile/newdatabase2.kdbx').readAsBytes(); + final file = kdbxForamt.read(data, cred); + expect(file.body.rootGroup.entries, hasLength(3)); + }); }); group('Creating', () { diff --git a/test/keyfile/hexkey_no_newline b/test/keyfile/hexkey_no_newline new file mode 100644 index 0000000..b4e9a91 --- /dev/null +++ b/test/keyfile/hexkey_no_newline @@ -0,0 +1 @@ +033ce6a895f345fdd177c1afcbc6bdbc8047207ba0e58e5231c1ee53f4b40d70 \ No newline at end of file diff --git a/test/keyfile/newdatabase2.kdbx b/test/keyfile/newdatabase2.kdbx new file mode 100644 index 0000000000000000000000000000000000000000..49581fac2a23a697f866d18dac8da82f0da5a18f GIT binary patch literal 1934 zcmV;92XXiV*`k_f`%AR}00RI55CAd3^5(yBLr}h01tDtuTK@wC0096100bZak{pX< zM(iAc$&M17WK10~g)?H;!}YzgM$?;Me(q--1t0*H2p>^*v#GU}o;z;Q<%h^B|JPTD zhl&;MOP~J!FMhxV2moN}00000000LN05d56X?0*>@jtc{G$@=b00K} zuQ+OF3fcYaOh)xus*k_0MOKy6^mT}x3UTXe0>0MwEL8{wjVKlE;L25^>j7upj&pyI zS2ZW=b#>)kA-Um&^7y3E*!uDJ~D1maWC-;k1M}{U1fT zWTtc=FPPviboPzq$7+QWTt49EarSd3e>W`-`c=_))Ys~DuVuz+xtga;=RA05K6Md= zY?)hh_7Ohw>NMu~>g{w>`4%B|i{jF}dSWy>9I z#g1{@dbF`q1z4Gt8~>X4@pf#&fQD}f9);JCLg_qtGv*yhjE;MfJR=&+Wdfo31u$2GMM^IZm7d2Z~=NuAHXF7 zxU2W%shr$=i z-rD7!2s;>CapWeLzjsS&V&77OqRv3%K+up6U#hwLMbLuyNU*GLv>tYX=g&L4VAt)netTGqSs9|5Cj0i7O zoIP@0SsSCLmYp~iMsvFCC%<8S_Wl63HKXpPHl|j->};k<|1D5KP+P@Em8Qw-{s|v{ zab7;ieWD?y0Tpx0=imtt--Gh+FVCvD4E)Zwg|V@Ju|jRsIigL~ZmLVX8hDp~H>u#; z&6DIXu~cG23Q#sJ-$xkpVb^%ttTeVE?ai}bKDjnnupmX%!7OI&Fl0+!oKthC8xgf8 zc{IU$MuNiB%gzi^BLt3DpTJn8`}D$iMEtbD7F77N2Y~kOs36xDWj=U28vma#r_yI`8(m0zU|nJPFSN}90KvG z^vA+)l50zoGRM|jRzm-qzF^mC<>hJ{LUVA5cTHfAQT_TV)qZMYp3uqoDj=_VI!S4hxPqnnNmd5KQ)KDV31pfMr^bk zW$>8D;Mr;d{9KkxVhse;ynsgF2#%f*G=}V=@$#X!zl!`4kjFc~kGLLkP!tKY5