Browse Source

upgrade dependencies, migrate from cryptography package to pointycastle.

null-safety
Herbert Poul 4 years ago
parent
commit
7139b7d2be
  1. 2
      analysis_options.yaml
  2. 1
      bin/kdbx.dart
  3. 26
      lib/src/crypto/protected_salt_generator.dart
  4. 18
      lib/src/kdbx_format.dart
  5. 5
      lib/src/kdbx_object.dart
  6. 15
      pubspec.yaml

2
analysis_options.yaml

@ -140,7 +140,7 @@ linter:
- slash_for_doc_comments - slash_for_doc_comments
# - sort_child_properties_last # not yet tested # - sort_child_properties_last # not yet tested
- sort_constructors_first - sort_constructors_first
- sort_pub_dependencies #- sort_pub_dependencies
- sort_unnamed_constructors_first - sort_unnamed_constructors_first
- test_types_in_equals - test_types_in_equals
- throw_in_finally - throw_in_finally

1
bin/kdbx.dart

@ -7,7 +7,6 @@ import 'package:args/command_runner.dart';
import 'package:kdbx/kdbx.dart'; import 'package:kdbx/kdbx.dart';
import 'package:kdbx/src/crypto/protected_value.dart'; import 'package:kdbx/src/crypto/protected_value.dart';
import 'package:kdbx/src/kdbx_format.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:kdbx/src/utils/print_utils.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:logging_appenders/logging_appenders.dart'; import 'package:logging_appenders/logging_appenders.dart';

26
lib/src/crypto/protected_salt_generator.dart

@ -1,9 +1,8 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:logging/logging.dart';
import 'package:crypto/crypto.dart'; import 'package:crypto/crypto.dart';
import 'package:cryptography/cryptography.dart' as cryptography; import 'package:logging/logging.dart';
import 'package:pointycastle/export.dart'; import 'package:pointycastle/export.dart';
final _logger = Logger('protected_salt_generator'); final _logger = Logger('protected_salt_generator');
@ -50,12 +49,22 @@ class ChachaProtectedSaltGenerator implements ProtectedSaltGenerator {
final secretKey = hash.bytes.sublist(0, 32); final secretKey = hash.bytes.sublist(0, 32);
final nonce = hash.bytes.sublist(32, 32 + 12); final nonce = hash.bytes.sublist(32, 32 + 12);
return ChachaProtectedSaltGenerator._(cryptography.chacha20.newState( // final chaCha = AEADCipher('ChaCha20-Poly1305');
cryptography.SecretKey(secretKey), // ChaCha20Poly1305.factoryConfig.
nonce: cryptography.SecretKey(nonce))); // 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 @override
StreamCipher get _cipher => throw UnimplementedError(); StreamCipher get _cipher => throw UnimplementedError();
@ -67,14 +76,15 @@ class ChachaProtectedSaltGenerator implements ProtectedSaltGenerator {
_logger.warning('decoded base64 data has length 0'); _logger.warning('decoded base64 data has length 0');
return null; return null;
} }
final result = _state.convert(bytes); final result = _state.process(bytes);
// final result = _state.convert(bytes);
return utf8.decode(result); return utf8.decode(result);
} }
@override @override
String encryptToBase64(String plainValue) { String encryptToBase64(String plainValue) {
final input = utf8.encode(plainValue) as Uint8List; final input = utf8.encode(plainValue) as Uint8List;
final encrypted = _state.convert(input); final encrypted = _state.process(input);
return base64.encode(encrypted); return base64.encode(encrypted);
} }
} }

18
lib/src/kdbx_format.dart

@ -4,32 +4,31 @@ import 'dart:io';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:archive/archive.dart'; 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:argon2_ffi_base/argon2_ffi_base.dart';
import 'package:convert/convert.dart' as convert; import 'package:convert/convert.dart' as convert;
import 'package:crypto/crypto.dart' as crypto; import 'package:crypto/crypto.dart' as crypto;
import 'package:cryptography/cryptography.dart' as cryptography;
import 'package:kdbx/kdbx.dart'; import 'package:kdbx/kdbx.dart';
import 'package:kdbx/src/crypto/key_encrypter_kdf.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_salt_generator.dart';
import 'package:kdbx/src/crypto/protected_value.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/consts.dart';
import 'package:kdbx/src/internal/crypto_utils.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_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_file.dart';
import 'package:kdbx/src/kdbx_group.dart'; import 'package:kdbx/src/kdbx_group.dart';
import 'package:kdbx/src/kdbx_header.dart'; import 'package:kdbx/src/kdbx_header.dart';
import 'package:kdbx/src/kdbx_meta.dart'; import 'package:kdbx/src/kdbx_meta.dart';
import 'package:kdbx/src/kdbx_object.dart'; import 'package:kdbx/src/kdbx_object.dart';
import 'package:kdbx/src/kdbx_xml.dart'; import 'package:kdbx/src/kdbx_xml.dart';
import 'package:kdbx/src/utils/byte_utils.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:pointycastle/export.dart'; import 'package:pointycastle/export.dart';
import 'package:quiver/iterables.dart'; import 'package:quiver/iterables.dart';
import 'package:supercharged_dart/supercharged_dart.dart';
import 'package:xml/xml.dart' as xml; import 'package:xml/xml.dart' as xml;
final _logger = Logger('kdbx.format'); final _logger = Logger('kdbx.format');
@ -706,9 +705,10 @@ class KdbxFormat {
Uint8List transformContentV4ChaCha20( Uint8List transformContentV4ChaCha20(
KdbxHeader header, Uint8List encrypted, Uint8List cipherKey) { KdbxHeader header, Uint8List encrypted, Uint8List cipherKey) {
final encryptionIv = header.fields[HeaderFields.EncryptionIV].bytes; final encryptionIv = header.fields[HeaderFields.EncryptionIV].bytes;
final key = cryptography.SecretKey(cipherKey); final chaCha = ChaCha7539Engine()
final nonce = cryptography.SecretKey(encryptionIv); ..init(true, ParametersWithIV(KeyParameter(cipherKey), encryptionIv));
return cryptography.chacha20.decrypt(encrypted, key, nonce: nonce); return chaCha.process(encrypted);
// return cryptography.chacha20.decrypt(encrypted, key, nonce: nonce);
} }
// Uint8List _transformDataV4Aes() { // Uint8List _transformDataV4Aes() {

5
lib/src/kdbx_object.dart

@ -229,8 +229,7 @@ abstract class KdbxObject extends KdbxNode {
class KdbxUuid { class KdbxUuid {
const KdbxUuid(this.uuid); const KdbxUuid(this.uuid);
KdbxUuid.random() KdbxUuid.random() : this(base64.encode(Uuid.parse(uuidGenerator.v4())));
: this(base64.encode(uuidGenerator.parse(uuidGenerator.v4())));
KdbxUuid.fromBytes(Uint8List bytes) : this(base64.encode(bytes)); KdbxUuid.fromBytes(Uint8List bytes) : this(base64.encode(bytes));
@ -239,7 +238,7 @@ class KdbxUuid {
/// 128 bits set to zero. /// 128 bits set to zero.
static const NIL = KdbxUuid('AAAAAAAAAAAAAAAAAAAAAA=='); static const NIL = KdbxUuid('AAAAAAAAAAAAAAAAAAAAAA==');
static final Uuid uuidGenerator = static const Uuid uuidGenerator =
Uuid(options: <String, dynamic>{'grng': UuidUtil.cryptoRNG}); Uuid(options: <String, dynamic>{'grng': UuidUtil.cryptoRNG});
/// base64 representation of uuid. /// base64 representation of uuid.

15
pubspec.yaml

@ -10,19 +10,18 @@ dependencies:
# flutter: # flutter:
# sdk: flutter # sdk: flutter
# path: ^1.6.0 # path: ^1.6.0
logging: '>=0.11.3+2 <1.0.0' logging: '>=0.11.3+2 <2.0.0'
crypto: '>=2.0.0 <3.0.0' crypto: '>=2.0.0 <4.0.0'
pointycastle: '>=1.0.1 <2.0.0' pointycastle: '>=1.0.1 <3.0.0'
cryptography: ^0.1.2
xml: '>=4.4.0 <5.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' meta: '>=1.0.0 <2.0.0'
clock: '>=1.0.0 <2.0.0' clock: '>=1.0.0 <2.0.0'
convert: '>=2.0.0 <3.0.0' convert: '>=2.0.0 <3.0.0'
isolate: '>=2.0.3 <3.0.0' isolate: '>=2.0.3 <3.0.0'
path: '>=1.6.0 <2.0.0' path: '>=1.6.0 <2.0.0'
quiver: '>=2.1.0 <3.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' supercharged_dart: '>=1.2.0 <2.0.0'
synchronized: '>=2.2.0 <3.0.0' synchronized: '>=2.2.0 <3.0.0'
@ -31,8 +30,8 @@ dependencies:
# required for bin/ # required for bin/
args: '>1.5.0 <2.0.0' args: '>1.5.0 <2.0.0'
prompts: '>=1.3.0 <2.0.0' prompts: '>=1.3.0 <2.0.0'
logging_appenders: '>=0.1.0 <1.0.0' logging_appenders: '>=0.1.0 <2.0.0'
argon2_ffi_base: '>=0.1.4+6 <1.0.0' argon2_ffi_base: ^1.0.0
dev_dependencies: dev_dependencies:
pedantic: '>=1.7.0 <2.0.0' pedantic: '>=1.7.0 <2.0.0'

Loading…
Cancel
Save