diff --git a/analysis_options.yaml b/analysis_options.yaml index 976c29b..ec0dfc9 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -140,7 +140,7 @@ linter: - slash_for_doc_comments # - sort_child_properties_last # not yet tested - sort_constructors_first - - sort_pub_dependencies + #- sort_pub_dependencies - sort_unnamed_constructors_first - test_types_in_equals - throw_in_finally diff --git a/bin/kdbx.dart b/bin/kdbx.dart index 7f7be5e..38dd488 100644 --- a/bin/kdbx.dart +++ b/bin/kdbx.dart @@ -7,7 +7,6 @@ import 'package:args/command_runner.dart'; import 'package:kdbx/kdbx.dart'; import 'package:kdbx/src/crypto/protected_value.dart'; import 'package:kdbx/src/kdbx_format.dart'; -import 'package:kdbx/src/kdbx_group.dart'; import 'package:kdbx/src/utils/print_utils.dart'; import 'package:logging/logging.dart'; import 'package:logging_appenders/logging_appenders.dart'; diff --git a/lib/src/crypto/protected_salt_generator.dart b/lib/src/crypto/protected_salt_generator.dart index a30bf69..43331a8 100644 --- a/lib/src/crypto/protected_salt_generator.dart +++ b/lib/src/crypto/protected_salt_generator.dart @@ -1,9 +1,8 @@ import 'dart:convert'; import 'dart:typed_data'; -import 'package:logging/logging.dart'; import 'package:crypto/crypto.dart'; -import 'package:cryptography/cryptography.dart' as cryptography; +import 'package:logging/logging.dart'; import 'package:pointycastle/export.dart'; final _logger = Logger('protected_salt_generator'); @@ -50,12 +49,22 @@ class ChachaProtectedSaltGenerator implements ProtectedSaltGenerator { final secretKey = hash.bytes.sublist(0, 32); final nonce = hash.bytes.sublist(32, 32 + 12); - return ChachaProtectedSaltGenerator._(cryptography.chacha20.newState( - cryptography.SecretKey(secretKey), - nonce: cryptography.SecretKey(nonce))); + // final chaCha = AEADCipher('ChaCha20-Poly1305'); + // ChaCha20Poly1305.factoryConfig. + // final chaCha = ChaCha20Engine(); + // chaCha.init( + // true, + // AEADParameters(KeyParameter(secretKey as Uint8List), 128, + // nonce as Uint8List, null)); + final chaCha = ChaCha7539Engine(); + chaCha.init( + true, + ParametersWithIV( + KeyParameter(secretKey as Uint8List), nonce as Uint8List)); + return ChachaProtectedSaltGenerator._(chaCha); } - final cryptography.KeyStreamCipherState _state; + final ChaCha7539Engine _state; @override StreamCipher get _cipher => throw UnimplementedError(); @@ -67,14 +76,15 @@ class ChachaProtectedSaltGenerator implements ProtectedSaltGenerator { _logger.warning('decoded base64 data has length 0'); return null; } - final result = _state.convert(bytes); + final result = _state.process(bytes); + // final result = _state.convert(bytes); return utf8.decode(result); } @override String encryptToBase64(String plainValue) { final input = utf8.encode(plainValue) as Uint8List; - final encrypted = _state.convert(input); + final encrypted = _state.process(input); return base64.encode(encrypted); } } diff --git a/lib/src/kdbx_format.dart b/lib/src/kdbx_format.dart index aa6c6ea..7b37a51 100644 --- a/lib/src/kdbx_format.dart +++ b/lib/src/kdbx_format.dart @@ -4,32 +4,31 @@ import 'dart:io'; import 'dart:typed_data'; import 'package:archive/archive.dart'; -import 'package:kdbx/src/kdbx_entry.dart'; -import 'package:supercharged_dart/supercharged_dart.dart'; import 'package:argon2_ffi_base/argon2_ffi_base.dart'; import 'package:convert/convert.dart' as convert; import 'package:crypto/crypto.dart' as crypto; -import 'package:cryptography/cryptography.dart' as cryptography; import 'package:kdbx/kdbx.dart'; import 'package:kdbx/src/crypto/key_encrypter_kdf.dart'; import 'package:kdbx/src/crypto/protected_salt_generator.dart'; import 'package:kdbx/src/crypto/protected_value.dart'; -import 'package:kdbx/src/internal/extension_utils.dart'; -import 'package:kdbx/src/kdbx_deleted_object.dart'; -import 'package:kdbx/src/utils/byte_utils.dart'; import 'package:kdbx/src/internal/consts.dart'; import 'package:kdbx/src/internal/crypto_utils.dart'; +import 'package:kdbx/src/internal/extension_utils.dart'; import 'package:kdbx/src/kdbx_binary.dart'; +import 'package:kdbx/src/kdbx_deleted_object.dart'; +import 'package:kdbx/src/kdbx_entry.dart'; import 'package:kdbx/src/kdbx_file.dart'; import 'package:kdbx/src/kdbx_group.dart'; import 'package:kdbx/src/kdbx_header.dart'; import 'package:kdbx/src/kdbx_meta.dart'; import 'package:kdbx/src/kdbx_object.dart'; import 'package:kdbx/src/kdbx_xml.dart'; +import 'package:kdbx/src/utils/byte_utils.dart'; import 'package:logging/logging.dart'; import 'package:meta/meta.dart'; import 'package:pointycastle/export.dart'; import 'package:quiver/iterables.dart'; +import 'package:supercharged_dart/supercharged_dart.dart'; import 'package:xml/xml.dart' as xml; final _logger = Logger('kdbx.format'); @@ -706,9 +705,10 @@ class KdbxFormat { Uint8List transformContentV4ChaCha20( KdbxHeader header, Uint8List encrypted, Uint8List cipherKey) { final encryptionIv = header.fields[HeaderFields.EncryptionIV].bytes; - final key = cryptography.SecretKey(cipherKey); - final nonce = cryptography.SecretKey(encryptionIv); - return cryptography.chacha20.decrypt(encrypted, key, nonce: nonce); + final chaCha = ChaCha7539Engine() + ..init(true, ParametersWithIV(KeyParameter(cipherKey), encryptionIv)); + return chaCha.process(encrypted); + // return cryptography.chacha20.decrypt(encrypted, key, nonce: nonce); } // Uint8List _transformDataV4Aes() { diff --git a/lib/src/kdbx_object.dart b/lib/src/kdbx_object.dart index 39881cd..dbedcd9 100644 --- a/lib/src/kdbx_object.dart +++ b/lib/src/kdbx_object.dart @@ -229,8 +229,7 @@ abstract class KdbxObject extends KdbxNode { class KdbxUuid { const KdbxUuid(this.uuid); - KdbxUuid.random() - : this(base64.encode(uuidGenerator.parse(uuidGenerator.v4()))); + KdbxUuid.random() : this(base64.encode(Uuid.parse(uuidGenerator.v4()))); KdbxUuid.fromBytes(Uint8List bytes) : this(base64.encode(bytes)); @@ -239,7 +238,7 @@ class KdbxUuid { /// 128 bits set to zero. static const NIL = KdbxUuid('AAAAAAAAAAAAAAAAAAAAAA=='); - static final Uuid uuidGenerator = + static const Uuid uuidGenerator = Uuid(options: {'grng': UuidUtil.cryptoRNG}); /// base64 representation of uuid. diff --git a/pubspec.yaml b/pubspec.yaml index 77b336a..2b86ba1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,19 +10,18 @@ dependencies: # flutter: # sdk: flutter # path: ^1.6.0 - logging: '>=0.11.3+2 <1.0.0' - crypto: '>=2.0.0 <3.0.0' - pointycastle: '>=1.0.1 <2.0.0' - cryptography: ^0.1.2 + logging: '>=0.11.3+2 <2.0.0' + crypto: '>=2.0.0 <4.0.0' + pointycastle: '>=1.0.1 <3.0.0' xml: '>=4.4.0 <5.0.0' - uuid: '>=2.0.0 <3.0.0' + uuid: ">=3.0.0 <5.0.0" meta: '>=1.0.0 <2.0.0' clock: '>=1.0.0 <2.0.0' convert: '>=2.0.0 <3.0.0' isolate: '>=2.0.3 <3.0.0' path: '>=1.6.0 <2.0.0' quiver: '>=2.1.0 <3.0.0' - archive: '>=2.0.13 <3.0.0' + archive: '>=2.0.13 <4.0.0' supercharged_dart: '>=1.2.0 <2.0.0' synchronized: '>=2.2.0 <3.0.0' @@ -31,8 +30,8 @@ dependencies: # required for bin/ args: '>1.5.0 <2.0.0' prompts: '>=1.3.0 <2.0.0' - logging_appenders: '>=0.1.0 <1.0.0' - argon2_ffi_base: '>=0.1.4+6 <1.0.0' + logging_appenders: '>=0.1.0 <2.0.0' + argon2_ffi_base: ^1.0.0 dev_dependencies: pedantic: '>=1.7.0 <2.0.0'