Browse Source

fixed exception when trying to read binary keyfile. https://github.com/authpass/authpass/issues/59

remove-cryptography-dependency
Herbert Poul 5 years ago
parent
commit
395f0707ac
  1. 2
      lib/src/kdbx_format.dart
  2. 9
      test/kdbx4_test.dart
  3. BIN
      test/keyfile/BinaryKeyFilePasswords.kdbx
  4. 1
      test/keyfile/binarykeyfile.key

2
lib/src/kdbx_format.dart

@ -65,8 +65,8 @@ abstract class CredentialsPart {
class KeyFileCredentials implements CredentialsPart { class KeyFileCredentials implements CredentialsPart {
factory KeyFileCredentials(Uint8List keyFileContents) { factory KeyFileCredentials(Uint8List keyFileContents) {
final keyFileAsString = utf8.decode(keyFileContents);
try { try {
final keyFileAsString = utf8.decode(keyFileContents);
if (_hexValuePattern.hasMatch(keyFileAsString)) { if (_hexValuePattern.hasMatch(keyFileAsString)) {
return KeyFileCredentials._(ProtectedValue.fromBinary( return KeyFileCredentials._(ProtectedValue.fromBinary(
convert.hex.decode(keyFileAsString) as Uint8List)); convert.hex.decode(keyFileAsString) as Uint8List));

9
test/kdbx4_test.dart

@ -79,6 +79,15 @@ void main() {
final pwd = firstEntry.getString(KdbxKey('Password')).getText(); final pwd = firstEntry.getString(KdbxKey('Password')).getText();
expect(pwd, 'def'); 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', () { group('Writing', () {
test('Create and save', () { test('Create and save', () {

BIN
test/keyfile/BinaryKeyFilePasswords.kdbx

Binary file not shown.

1
test/keyfile/binarykeyfile.key

@ -0,0 +1 @@
À!š¢OÅ“‡¥¿ Å8!Wȸ9É&Å78!AÿÈõûâw5›EÕ<EFBFBD>|ØŒu£®j™”²sïEòën(ŒØðvó$6?rg‘:Wjºø/¥O­Ý]“m´Œk…hxWk•ænÍ<EFBFBD>…"x{¾IÑjêé…vÎõ—ù2
Loading…
Cancel
Save