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 session = await keyManager.loadInboundGroupSession(
room.id, request.sessionId, request.senderKey);
if (session == null) {
Logs().v("[KeyManager] Not forwarding key we don't have");
return;
}
if (session.inboundGroupSession == null) {
if (session?.inboundGroupSession == null) {
Logs().v("[KeyManager] Not forwarding key we don't have");
return;
}
final message = session.content.copy();
final message = session!.content.copy();
message['forwarding_curve25519_key_chain'] =
List<String>.from(session.forwardingCurve25519KeyChain);

View File

@ -50,7 +50,7 @@ class OlmManager {
Map<String, List<OlmSession>> get olmSessions => _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 {
if (olmAccount == null) {
try {

View File

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

View File

@ -17,6 +17,7 @@
*/
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 '../../matrix.dart';
@ -76,22 +77,23 @@ class SessionKey {
SessionKey.fromDb(StoredInboundGroupSession dbEntry, String key)
: key = key,
content = Event.getMapFromPayload(dbEntry.content),
indexes =
Map<String, String>.from(Event.getMapFromPayload(dbEntry.indexes)),
allowedAtIndex = Map<String, Map<String, int>>.from(
Event.getMapFromPayload(dbEntry.allowedAtIndex)
.map((k, v) => MapEntry(k, Map<String, int>.from(v)))),
indexes = Event.getMapFromPayload(dbEntry.indexes)
.catchMap((k, v) => MapEntry(k, v as String)),
allowedAtIndex = Event.getMapFromPayload(dbEntry.allowedAtIndex)
.catchMap((k, v) => MapEntry(k, Map<String, int>.from(v))),
roomId = dbEntry.roomId,
sessionId = dbEntry.sessionId,
senderKey = dbEntry.senderKey,
inboundGroupSession = olm.InboundGroupSession() {
final parsedSenderClaimedKeys = Map<String, String>.from(
Event.getMapFromPayload(dbEntry.senderClaimedKeys));
final parsedSenderClaimedKeys =
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.
senderClaimedKeys = (parsedSenderClaimedKeys.isNotEmpty)
? parsedSenderClaimedKeys
: (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
? <String, String>{
'ed25519': content['sender_claimed_ed25519_key']

View File

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