From 395f0707acb9343897a1bea3d594a72a62cb82bd Mon Sep 17 00:00:00 2001 From: Herbert Poul Date: Wed, 18 Mar 2020 13:45:26 +0100 Subject: [PATCH] fixed exception when trying to read binary keyfile. https://github.com/authpass/authpass/issues/59 --- lib/src/kdbx_format.dart | 2 +- test/kdbx4_test.dart | 9 +++++++++ test/keyfile/BinaryKeyFilePasswords.kdbx | Bin 0 -> 1557 bytes test/keyfile/binarykeyfile.key | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 test/keyfile/BinaryKeyFilePasswords.kdbx create mode 100644 test/keyfile/binarykeyfile.key diff --git a/lib/src/kdbx_format.dart b/lib/src/kdbx_format.dart index 05887e7..caf37db 100644 --- a/lib/src/kdbx_format.dart +++ b/lib/src/kdbx_format.dart @@ -65,8 +65,8 @@ abstract class CredentialsPart { class KeyFileCredentials implements CredentialsPart { factory KeyFileCredentials(Uint8List keyFileContents) { - final keyFileAsString = utf8.decode(keyFileContents); try { + final keyFileAsString = utf8.decode(keyFileContents); if (_hexValuePattern.hasMatch(keyFileAsString)) { return KeyFileCredentials._(ProtectedValue.fromBinary( convert.hex.decode(keyFileAsString) as Uint8List)); diff --git a/test/kdbx4_test.dart b/test/kdbx4_test.dart index 378192f..c8b15bb 100644 --- a/test/kdbx4_test.dart +++ b/test/kdbx4_test.dart @@ -79,6 +79,15 @@ void main() { final pwd = firstEntry.getString(KdbxKey('Password')).getText(); expect(pwd, 'def'); }); + test('Binary Keyfile', () async { + final data = + await File('test/keyfile/BinaryKeyFilePasswords.kdbx').readAsBytes(); + final keyFile = + await File('test/keyfile/binarykeyfile.key').readAsBytes(); + final file = kdbxFormat.read(data, + Credentials.composite(ProtectedValue.fromString('asdf'), keyFile)); + expect(file.body.rootGroup.entries, hasLength(1)); + }); }); group('Writing', () { test('Create and save', () { diff --git a/test/keyfile/BinaryKeyFilePasswords.kdbx b/test/keyfile/BinaryKeyFilePasswords.kdbx new file mode 100644 index 0000000000000000000000000000000000000000..8a24dd1992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AJ1mdg| zYT`h1$wH=2pzuNGW-8JQ+-{$3-8-eR|CiG&$?-|yGmeVQb~40&;DStWRTDz8ru7Xv+qD+l4dpVjtT~@q&;n)Q702A7 z8`BcblmwFd9RAIS0v=t=jQ-;zO`nDI8Cl1bnctQB>)$c-i<1UpgwiBI zy2<1X)wnV|N&6Aolam^Qm7V&ym8;x5lA-@Qu-#6tC(Rcc`)Eesl87~o-el-x#$2xV H00000tjf(9 literal 0 HcmV?d00001 diff --git a/test/keyfile/binarykeyfile.key b/test/keyfile/binarykeyfile.key new file mode 100644 index 0000000..7f8d5c8 --- /dev/null +++ b/test/keyfile/binarykeyfile.key @@ -0,0 +1 @@ +À!š¢OÅ“‡¥¿ Å8!Wȸ9É&Å78!AÿÈõûâw5›EÕ|ØŒu£®j™”²sïEòën(ŒØðvó$6?rg‘:Wjºø/¥O­6ÏÝ]“m´Œk…hxWk•ænÍ…"x{¾IÑjêé…vÎõ—ù2 \ No newline at end of file