refactor: Avoid using private types in public api
This commit is contained in:
parent
ea1f340ca9
commit
3976b0f1e2
|
|
@ -771,7 +771,7 @@ class KeyManager {
|
||||||
}
|
}
|
||||||
final args = GenerateUploadKeysArgs(
|
final args = GenerateUploadKeysArgs(
|
||||||
pubkey: backupPubKey,
|
pubkey: backupPubKey,
|
||||||
dbSessions: <_DbInboundGroupSessionBundle>[],
|
dbSessions: <DbInboundGroupSessionBundle>[],
|
||||||
userId: userID,
|
userId: userID,
|
||||||
);
|
);
|
||||||
// we need to calculate verified beforehand, as else we pass a closure to an isolate
|
// we need to calculate verified beforehand, as else we pass a closure to an isolate
|
||||||
|
|
@ -781,7 +781,7 @@ class KeyManager {
|
||||||
for (final dbSession in dbSessions) {
|
for (final dbSession in dbSessions) {
|
||||||
final device =
|
final device =
|
||||||
client.getUserDeviceKeysByCurve25519Key(dbSession.senderKey);
|
client.getUserDeviceKeysByCurve25519Key(dbSession.senderKey);
|
||||||
args.dbSessions.add(_DbInboundGroupSessionBundle(
|
args.dbSessions.add(DbInboundGroupSessionBundle(
|
||||||
dbSession: dbSession,
|
dbSession: dbSession,
|
||||||
verified: device?.verified ?? false,
|
verified: device?.verified ?? false,
|
||||||
));
|
));
|
||||||
|
|
@ -1113,12 +1113,12 @@ RoomKeys generateUploadKeysImplementation(GenerateUploadKeysArgs args) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _DbInboundGroupSessionBundle {
|
class DbInboundGroupSessionBundle {
|
||||||
_DbInboundGroupSessionBundle(
|
DbInboundGroupSessionBundle(
|
||||||
{required this.dbSession, required this.verified});
|
{required this.dbSession, required this.verified});
|
||||||
|
|
||||||
factory _DbInboundGroupSessionBundle.fromJson(Map<dynamic, dynamic> json) =>
|
factory DbInboundGroupSessionBundle.fromJson(Map<dynamic, dynamic> json) =>
|
||||||
_DbInboundGroupSessionBundle(
|
DbInboundGroupSessionBundle(
|
||||||
dbSession:
|
dbSession:
|
||||||
StoredInboundGroupSession.fromJson(Map.from(json['dbSession'])),
|
StoredInboundGroupSession.fromJson(Map.from(json['dbSession'])),
|
||||||
verified: json['verified'],
|
verified: json['verified'],
|
||||||
|
|
@ -1140,7 +1140,7 @@ class GenerateUploadKeysArgs {
|
||||||
GenerateUploadKeysArgs(
|
GenerateUploadKeysArgs(
|
||||||
pubkey: json['pubkey'],
|
pubkey: json['pubkey'],
|
||||||
dbSessions: (json['dbSessions'] as Iterable)
|
dbSessions: (json['dbSessions'] as Iterable)
|
||||||
.map((e) => _DbInboundGroupSessionBundle.fromJson(e))
|
.map((e) => DbInboundGroupSessionBundle.fromJson(e))
|
||||||
.toList(),
|
.toList(),
|
||||||
userId: json['userId'],
|
userId: json['userId'],
|
||||||
);
|
);
|
||||||
|
|
@ -1152,6 +1152,6 @@ class GenerateUploadKeysArgs {
|
||||||
};
|
};
|
||||||
|
|
||||||
String pubkey;
|
String pubkey;
|
||||||
List<_DbInboundGroupSessionBundle> dbSessions;
|
List<DbInboundGroupSessionBundle> dbSessions;
|
||||||
String userId;
|
String userId;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ class SSSS {
|
||||||
_cache.clear();
|
_cache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
static _DerivedKeys deriveKeys(Uint8List key, String name) {
|
static DerivedKeys deriveKeys(Uint8List key, String name) {
|
||||||
final zerosalt = Uint8List(8);
|
final zerosalt = Uint8List(8);
|
||||||
final prk = Hmac(sha256, zerosalt).convert(key);
|
final prk = Hmac(sha256, zerosalt).convert(key);
|
||||||
final b = Uint8List(1);
|
final b = Uint8List(1);
|
||||||
|
|
@ -77,12 +77,13 @@ class SSSS {
|
||||||
b[0] = 2;
|
b[0] = 2;
|
||||||
final hmacKey =
|
final hmacKey =
|
||||||
Hmac(sha256, prk.bytes).convert(aesKey.bytes + utf8.encode(name) + b);
|
Hmac(sha256, prk.bytes).convert(aesKey.bytes + utf8.encode(name) + b);
|
||||||
return _DerivedKeys(
|
return DerivedKeys(
|
||||||
aesKey: Uint8List.fromList(aesKey.bytes),
|
aesKey: Uint8List.fromList(aesKey.bytes),
|
||||||
hmacKey: Uint8List.fromList(hmacKey.bytes));
|
hmacKey: Uint8List.fromList(hmacKey.bytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<_Encrypted> encryptAes(String data, Uint8List key, String name,
|
static Future<EncryptedContent> encryptAes(
|
||||||
|
String data, Uint8List key, String name,
|
||||||
[String? ivStr]) async {
|
[String? ivStr]) async {
|
||||||
Uint8List iv;
|
Uint8List iv;
|
||||||
if (ivStr != null) {
|
if (ivStr != null) {
|
||||||
|
|
@ -100,14 +101,14 @@ class SSSS {
|
||||||
|
|
||||||
final hmac = Hmac(sha256, keys.hmacKey).convert(ciphertext);
|
final hmac = Hmac(sha256, keys.hmacKey).convert(ciphertext);
|
||||||
|
|
||||||
return _Encrypted(
|
return EncryptedContent(
|
||||||
iv: base64.encode(iv),
|
iv: base64.encode(iv),
|
||||||
ciphertext: base64.encode(ciphertext),
|
ciphertext: base64.encode(ciphertext),
|
||||||
mac: base64.encode(hmac.bytes));
|
mac: base64.encode(hmac.bytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String> decryptAes(
|
static Future<String> decryptAes(
|
||||||
_Encrypted data, Uint8List key, String name) async {
|
EncryptedContent data, Uint8List key, String name) async {
|
||||||
final keys = deriveKeys(key, name);
|
final keys = deriveKeys(key, name);
|
||||||
final cipher = base64decodeUnpadded(data.ciphertext);
|
final cipher = base64decodeUnpadded(data.ciphertext);
|
||||||
final hmac = base64
|
final hmac = base64
|
||||||
|
|
@ -318,7 +319,7 @@ class SSSS {
|
||||||
throw Exception('Wrong / unknown key');
|
throw Exception('Wrong / unknown key');
|
||||||
}
|
}
|
||||||
final enc = secretInfo.content['encrypted'][keyId];
|
final enc = secretInfo.content['encrypted'][keyId];
|
||||||
final encryptInfo = _Encrypted(
|
final encryptInfo = EncryptedContent(
|
||||||
iv: enc['iv'], ciphertext: enc['ciphertext'], mac: enc['mac']);
|
iv: enc['iv'], ciphertext: enc['ciphertext'], mac: enc['mac']);
|
||||||
final decrypted = await decryptAes(encryptInfo, key, type);
|
final decrypted = await decryptAes(encryptInfo, key, type);
|
||||||
final db = client.database;
|
final db = client.database;
|
||||||
|
|
@ -604,19 +605,20 @@ class _ShareRequest {
|
||||||
: start = DateTime.now();
|
: start = DateTime.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _Encrypted {
|
class EncryptedContent {
|
||||||
final String iv;
|
final String iv;
|
||||||
final String ciphertext;
|
final String ciphertext;
|
||||||
final String mac;
|
final String mac;
|
||||||
|
|
||||||
_Encrypted({required this.iv, required this.ciphertext, required this.mac});
|
EncryptedContent(
|
||||||
|
{required this.iv, required this.ciphertext, required this.mac});
|
||||||
}
|
}
|
||||||
|
|
||||||
class _DerivedKeys {
|
class DerivedKeys {
|
||||||
final Uint8List aesKey;
|
final Uint8List aesKey;
|
||||||
final Uint8List hmacKey;
|
final Uint8List hmacKey;
|
||||||
|
|
||||||
_DerivedKeys({required this.aesKey, required this.hmacKey});
|
DerivedKeys({required this.aesKey, required this.hmacKey});
|
||||||
}
|
}
|
||||||
|
|
||||||
class OpenSSSS {
|
class OpenSSSS {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue