Browse Source

proper error message for kdbx 4.x files

remove-cryptography-dependency
Herbert Poul 5 years ago
parent
commit
5eb248d4bd
  1. 116
      .idea/codeStyles/Project.xml
  2. 4
      CHANGELOG.md
  3. 6
      lib/src/kdbx_format.dart
  4. 10
      lib/src/kdbx_header.dart
  5. 5
      pubspec.yaml
  6. 9
      test/kdbx_test.dart
  7. BIN
      test/keepassxcpasswords.kdbx

116
.idea/codeStyles/Project.xml

@ -0,0 +1,116 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<codeStyleSettings language="XML">
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
<arrangement>
<rules>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:android</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:id</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>style</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>ANDROID_ATTRIBUTE_ORDER</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>.*</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
</rules>
</arrangement>
</codeStyleSettings>
</code_scheme>
</component>

4
CHANGELOG.md

@ -1,3 +1,7 @@
## 0.2.1
- Throw unsupported exception when trying to read kdbx 4.x files.
## 0.2.0
- Fixed writing of packet index for payload.

6
lib/src/kdbx_format.dart

@ -304,6 +304,12 @@ class KdbxFormat {
static KdbxFile read(Uint8List input, Credentials credentials) {
final reader = ReaderHelper(input);
final header = KdbxHeader.read(reader);
if (header.versionMajor != 3) {
_logger.finer('Unsupported version for $header');
throw KdbxUnsupportedException('Unsupported kdbx version '
'${header.versionMajor}.${header.versionMinor}.'
' Only 3.x is supported.');
}
return _loadV3(header, reader, credentials);
}

10
lib/src/kdbx_header.dart

@ -236,6 +236,11 @@ class KdbxHeader {
ProtectedValueEncryption get innerRandomStreamEncryption =>
ProtectedValueEncryption.values[ReaderHelper.singleUint32(
fields[HeaderFields.InnerRandomStreamID].bytes)];
@override
String toString() {
return 'KdbxHeader{sig1: $sig1, sig2: $sig2, versionMajor: $versionMajor, versionMinor: $versionMinor}';
}
}
class KdbxException implements Exception {}
@ -252,6 +257,11 @@ class KdbxUnsupportedException implements KdbxException {
KdbxUnsupportedException(this.hint);
final String hint;
@override
String toString() {
return 'KdbxUnsupportedException{hint: $hint}';
}
}
class HashedBlockReader {

5
pubspec.yaml

@ -1,8 +1,7 @@
name: kdbx
description: KeepassX format implementation in pure dart. (kdbx 2.x support).
version: 0.2.0
description: KeepassX format implementation in pure dart. (kdbx 3.x support).
version: 0.2.1
homepage: https://github.com/authpass/kdbx.dart
author: Herbert Poul <herbert@poul.at>
environment:
sdk: '>=2.4.0 <3.0.0'

9
test/kdbx_test.dart

@ -91,4 +91,13 @@ void main() {
File('test.kdbx').writeAsBytesSync(saved);
});
});
group('Unsupported version', () {
test('Fails with exception', () async {
final data = await File('test/keepassxcpasswords.kdbx').readAsBytes();
expect(() {
KdbxFormat.read(data, Credentials(ProtectedValue.fromString('asdf')));
}, throwsA(const TypeMatcher<KdbxUnsupportedException>()));
});
});
}

BIN
test/keepassxcpasswords.kdbx

Binary file not shown.
Loading…
Cancel
Save