diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..681f41a --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a8e0bd..0c016f4 100644 --- a/CHANGELOG.md +++ b/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. diff --git a/lib/src/kdbx_format.dart b/lib/src/kdbx_format.dart index 4fd2f12..d5df660 100644 --- a/lib/src/kdbx_format.dart +++ b/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); } diff --git a/lib/src/kdbx_header.dart b/lib/src/kdbx_header.dart index c02ab1d..e3f68cc 100644 --- a/lib/src/kdbx_header.dart +++ b/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 { diff --git a/pubspec.yaml b/pubspec.yaml index e566b10..c43f85b 100644 --- a/pubspec.yaml +++ b/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 environment: sdk: '>=2.4.0 <3.0.0' diff --git a/test/kdbx_test.dart b/test/kdbx_test.dart index f772821..30f27cc 100644 --- a/test/kdbx_test.dart +++ b/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())); + }); + }); } diff --git a/test/keepassxcpasswords.kdbx b/test/keepassxcpasswords.kdbx new file mode 100644 index 0000000..69ad677 Binary files /dev/null and b/test/keepassxcpasswords.kdbx differ