|
|
@ -23,7 +23,7 @@ class KdfField<T> { |
|
|
|
final String field; |
|
|
|
final String field; |
|
|
|
final ValueType<T> type; |
|
|
|
final ValueType<T> type; |
|
|
|
|
|
|
|
|
|
|
|
static final uuid = KdfField('\$UUID', ValueType.typeBytes); |
|
|
|
static final uuid = KdfField(r'$UUID', ValueType.typeBytes); |
|
|
|
static final salt = KdfField('S', ValueType.typeBytes); |
|
|
|
static final salt = KdfField('S', ValueType.typeBytes); |
|
|
|
static final parallelism = KdfField('P', ValueType.typeUInt32); |
|
|
|
static final parallelism = KdfField('P', ValueType.typeUInt32); |
|
|
|
static final memory = KdfField('M', ValueType.typeUInt64); |
|
|
|
static final memory = KdfField('M', ValueType.typeUInt64); |
|
|
@ -76,15 +76,25 @@ class KeyEncrypterKdf { |
|
|
|
return KdbxUuid(uuid); |
|
|
|
return KdbxUuid(uuid); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final Argon2 argon2; |
|
|
|
static KdfType kdfTypeFor(VarDictionary kdfParameters) { |
|
|
|
|
|
|
|
final uuid = KdfField.uuid.read(kdfParameters); |
|
|
|
Future<Uint8List> encrypt(Uint8List key, VarDictionary kdfParameters) async { |
|
|
|
|
|
|
|
final uuid = kdfParameters.get(ValueType.typeBytes, '\$UUID'); |
|
|
|
|
|
|
|
if (uuid == null) { |
|
|
|
if (uuid == null) { |
|
|
|
throw KdbxCorruptedFileException('No Kdf UUID'); |
|
|
|
throw KdbxCorruptedFileException('No Kdf UUID'); |
|
|
|
} |
|
|
|
} |
|
|
|
final kdfUuid = base64.encode(uuid); |
|
|
|
final kdfUuid = base64.encode(uuid); |
|
|
|
switch (kdfUuids[kdfUuid]) { |
|
|
|
try { |
|
|
|
|
|
|
|
return kdfUuids[kdfUuid]; |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
throw KdbxCorruptedFileException( |
|
|
|
|
|
|
|
'Invalid KDF UUID ${uuid.encodeBase64()}'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final Argon2 argon2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<Uint8List> encrypt(Uint8List key, VarDictionary kdfParameters) async { |
|
|
|
|
|
|
|
final kdfType = kdfTypeFor(kdfParameters); |
|
|
|
|
|
|
|
switch (kdfType) { |
|
|
|
case KdfType.Argon2: |
|
|
|
case KdfType.Argon2: |
|
|
|
_logger.fine('Must be using argon2'); |
|
|
|
_logger.fine('Must be using argon2'); |
|
|
|
return await encryptArgon2(key, kdfParameters); |
|
|
|
return await encryptArgon2(key, kdfParameters); |
|
|
@ -93,8 +103,7 @@ class KeyEncrypterKdf { |
|
|
|
_logger.fine('Must be using aes'); |
|
|
|
_logger.fine('Must be using aes'); |
|
|
|
return await encryptAes(key, kdfParameters); |
|
|
|
return await encryptAes(key, kdfParameters); |
|
|
|
} |
|
|
|
} |
|
|
|
throw UnsupportedError( |
|
|
|
throw UnsupportedError('unsupported KDF Type $kdfType.'); |
|
|
|
'unsupported KDF Type UUID ${ByteUtils.toHexList(uuid)}.'); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Future<Uint8List> encryptArgon2( |
|
|
|
Future<Uint8List> encryptArgon2( |
|
|
|