fix: apply review feedback

This commit is contained in:
Nicolas Werner 2021-09-29 16:36:49 +02:00
parent 08bbb3f6f5
commit 7dd176c278
6 changed files with 57 additions and 59 deletions

View File

@ -990,16 +990,12 @@ class RoomKeyRequest extends ToDeviceEvent {
final room = this.room; final room = this.room;
final session = await keyManager.loadInboundGroupSession( final session = await keyManager.loadInboundGroupSession(
room.id, request.sessionId, request.senderKey); room.id, request.sessionId, request.senderKey);
if (session == null) { if (session?.inboundGroupSession == null) {
Logs().v("[KeyManager] Not forwarding key we don't have");
return;
}
if (session.inboundGroupSession == null) {
Logs().v("[KeyManager] Not forwarding key we don't have"); Logs().v("[KeyManager] Not forwarding key we don't have");
return; return;
} }
final message = session.content.copy(); final message = session!.content.copy();
message['forwarding_curve25519_key_chain'] = message['forwarding_curve25519_key_chain'] =
List<String>.from(session.forwardingCurve25519KeyChain); List<String>.from(session.forwardingCurve25519KeyChain);

View File

@ -50,7 +50,7 @@ class OlmManager {
Map<String, List<OlmSession>> get olmSessions => _olmSessions; Map<String, List<OlmSession>> get olmSessions => _olmSessions;
final Map<String, List<OlmSession>> _olmSessions = {}; final Map<String, List<OlmSession>> _olmSessions = {};
// NOTE(Nico): Do we really want to create a new account on passing null instead of signing the user out? // NOTE(Nico): On initial login we pass null to create a new account
Future<void> init(String? olmAccount) async { Future<void> init(String? olmAccount) async {
if (olmAccount == null) { if (olmAccount == null) {
try { try {

View File

@ -810,7 +810,7 @@ class _KeyVerificationMethodSas extends _KeyVerificationMethod {
} }
Future<void> _sendAccept() async { Future<void> _sendAccept() async {
final sas = this.sas ??= olm.SAS(); final sas = this.sas = olm.SAS();
commitment = _makeCommitment(sas.get_pubkey(), startCanonicalJson); commitment = _makeCommitment(sas.get_pubkey(), startCanonicalJson);
await request.send(EventTypes.KeyVerificationAccept, { await request.send(EventTypes.KeyVerificationAccept, {
'method': type, 'method': type,

View File

@ -17,6 +17,7 @@
*/ */
import 'package:matrix/encryption/utils/stored_inbound_group_session.dart'; import 'package:matrix/encryption/utils/stored_inbound_group_session.dart';
import 'package:matrix_api_lite/src/utils/filter_map_extension.dart';
import 'package:olm/olm.dart' as olm; import 'package:olm/olm.dart' as olm;
import '../../matrix.dart'; import '../../matrix.dart';
@ -76,22 +77,23 @@ class SessionKey {
SessionKey.fromDb(StoredInboundGroupSession dbEntry, String key) SessionKey.fromDb(StoredInboundGroupSession dbEntry, String key)
: key = key, : key = key,
content = Event.getMapFromPayload(dbEntry.content), content = Event.getMapFromPayload(dbEntry.content),
indexes = indexes = Event.getMapFromPayload(dbEntry.indexes)
Map<String, String>.from(Event.getMapFromPayload(dbEntry.indexes)), .catchMap((k, v) => MapEntry(k, v as String)),
allowedAtIndex = Map<String, Map<String, int>>.from( allowedAtIndex = Event.getMapFromPayload(dbEntry.allowedAtIndex)
Event.getMapFromPayload(dbEntry.allowedAtIndex) .catchMap((k, v) => MapEntry(k, Map<String, int>.from(v))),
.map((k, v) => MapEntry(k, Map<String, int>.from(v)))),
roomId = dbEntry.roomId, roomId = dbEntry.roomId,
sessionId = dbEntry.sessionId, sessionId = dbEntry.sessionId,
senderKey = dbEntry.senderKey, senderKey = dbEntry.senderKey,
inboundGroupSession = olm.InboundGroupSession() { inboundGroupSession = olm.InboundGroupSession() {
final parsedSenderClaimedKeys = Map<String, String>.from( final parsedSenderClaimedKeys =
Event.getMapFromPayload(dbEntry.senderClaimedKeys)); Event.getMapFromPayload(dbEntry.senderClaimedKeys)
.catchMap((k, v) => MapEntry(k, v as String));
// we need to try...catch as the map used to be <String, int> and that will throw an error. // we need to try...catch as the map used to be <String, int> and that will throw an error.
senderClaimedKeys = (parsedSenderClaimedKeys.isNotEmpty) senderClaimedKeys = (parsedSenderClaimedKeys.isNotEmpty)
? parsedSenderClaimedKeys ? parsedSenderClaimedKeys
: (content['sender_claimed_keys'] is Map : (content['sender_claimed_keys'] is Map
? Map<String, String>.from(content['sender_claimed_keys']) ? content['sender_claimed_keys']
.catchMap((k, v) => MapEntry(k, v as String))
: (content['sender_claimed_ed25519_key'] is String : (content['sender_claimed_ed25519_key'] is String
? <String, String>{ ? <String, String>{
'ed25519': content['sender_claimed_ed25519_key'] 'ed25519': content['sender_claimed_ed25519_key']

View File

@ -183,7 +183,7 @@ abstract class SignableKey extends MatrixSignableKey {
return String.fromCharCodes(canonicalJson.encode(data)); return String.fromCharCodes(canonicalJson.encode(data));
} }
bool _verifySignature(String /*!*/ pubKey, String /*!*/ signature, bool _verifySignature(String pubKey, String signature,
{bool isSignatureWithoutLibolmValid = false}) { {bool isSignatureWithoutLibolmValid = false}) {
olm.Utility olmutil; olm.Utility olmutil;
try { try {
@ -321,7 +321,7 @@ abstract class SignableKey extends MatrixSignableKey {
} }
} }
Future<void> /*!*/ setBlocked(bool newBlocked); Future<void> setBlocked(bool newBlocked);
@override @override
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -416,7 +416,7 @@ class DeviceKeys extends SignableKey {
_validSelfSignature ?? _validSelfSignature ??
(_validSelfSignature = (deviceId != null && (_validSelfSignature = (deviceId != null &&
signatures signatures
?.tryGet<Map<String, dynamic>>(userId) ?.tryGetMap<String, dynamic>(userId)
?.tryGet<String>('ed25519:$deviceId') == ?.tryGet<String>('ed25519:$deviceId') ==
null null
? false ? false