Merge branch 'client-feature-bad-encrypted' into 'master'
[Room] Return m.bad.encrypted See merge request famedly/famedlysdk!197
This commit is contained in:
commit
083dd8eb29
|
@ -248,6 +248,8 @@ class Event {
|
||||||
return MessageTypes.Sticker;
|
return MessageTypes.Sticker;
|
||||||
case "m.location":
|
case "m.location":
|
||||||
return MessageTypes.Location;
|
return MessageTypes.Location;
|
||||||
|
case "m.bad.encrypted":
|
||||||
|
return MessageTypes.BadEncrypted;
|
||||||
default:
|
default:
|
||||||
if (type == EventTypes.Message) {
|
if (type == EventTypes.Message) {
|
||||||
return MessageTypes.Text;
|
return MessageTypes.Text;
|
||||||
|
@ -378,7 +380,8 @@ class Event {
|
||||||
/// Searches for the reply event in the given timeline.
|
/// Searches for the reply event in the given timeline.
|
||||||
Future<Event> getReplyEvent(Timeline timeline) async {
|
Future<Event> getReplyEvent(Timeline timeline) async {
|
||||||
if (!isReply) return null;
|
if (!isReply) return null;
|
||||||
final String replyEventId = content['m.relates_to']['m.in_reply_to']['event_id'];
|
final String replyEventId =
|
||||||
|
content['m.relates_to']['m.in_reply_to']['event_id'];
|
||||||
return await timeline.getEventById(replyEventId);
|
return await timeline.getEventById(replyEventId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -394,6 +397,7 @@ enum MessageTypes {
|
||||||
Location,
|
Location,
|
||||||
Reply,
|
Reply,
|
||||||
Sticker,
|
Sticker,
|
||||||
|
BadEncrypted,
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1487,30 +1487,40 @@ class Room {
|
||||||
|
|
||||||
/// Decrypts the given [event] with one of the available ingoingGroupSessions.
|
/// Decrypts the given [event] with one of the available ingoingGroupSessions.
|
||||||
Event decryptGroupMessage(Event event) {
|
Event decryptGroupMessage(Event event) {
|
||||||
if (!client.encryptionEnabled) throw ("Encryption is not enabled");
|
Map<String, dynamic> decryptedPayload;
|
||||||
if (event.content["algorithm"] != "m.megolm.v1.aes-sha2") {
|
try {
|
||||||
throw ("Unknown encryption algorithm");
|
if (!client.encryptionEnabled) throw ("Encryption is not enabled");
|
||||||
}
|
if (event.content["algorithm"] != "m.megolm.v1.aes-sha2") {
|
||||||
final String sessionId = event.content["session_id"];
|
throw ("Unknown encryption algorithm");
|
||||||
if (!sessionKeys.containsKey(sessionId)) {
|
}
|
||||||
throw ("Unknown session id");
|
final String sessionId = event.content["session_id"];
|
||||||
}
|
if (!sessionKeys.containsKey(sessionId)) {
|
||||||
final olm.DecryptResult decryptResult = sessionKeys[sessionId]
|
throw ("Unknown session id");
|
||||||
.inboundGroupSession
|
}
|
||||||
.decrypt(event.content["ciphertext"]);
|
final olm.DecryptResult decryptResult = sessionKeys[sessionId]
|
||||||
final String messageIndexKey =
|
.inboundGroupSession
|
||||||
event.eventId + event.time.millisecondsSinceEpoch.toString();
|
.decrypt(event.content["ciphertext"]);
|
||||||
if (sessionKeys[sessionId].indexes.containsKey(messageIndexKey) &&
|
final String messageIndexKey =
|
||||||
sessionKeys[sessionId].indexes[messageIndexKey] !=
|
event.eventId + event.time.millisecondsSinceEpoch.toString();
|
||||||
decryptResult.message_index) {
|
if (sessionKeys[sessionId].indexes.containsKey(messageIndexKey) &&
|
||||||
throw ("Invalid message index");
|
sessionKeys[sessionId].indexes[messageIndexKey] !=
|
||||||
}
|
decryptResult.message_index) {
|
||||||
sessionKeys[sessionId].indexes[messageIndexKey] =
|
throw ("Invalid message index");
|
||||||
decryptResult.message_index;
|
}
|
||||||
// TODO: The client should check that the sender's fingerprint key matches the keys.ed25519 property of the event which established the Megolm session when marking the event as verified.
|
sessionKeys[sessionId].indexes[messageIndexKey] =
|
||||||
|
decryptResult.message_index;
|
||||||
|
// TODO: The client should check that the sender's fingerprint key matches the keys.ed25519 property of the event which established the Megolm session when marking the event as verified.
|
||||||
|
|
||||||
final Map<String, dynamic> decryptedPayload =
|
decryptedPayload = json.decode(decryptResult.plaintext);
|
||||||
json.decode(decryptResult.plaintext);
|
} catch (exception) {
|
||||||
|
decryptedPayload = {
|
||||||
|
"content": {
|
||||||
|
"msgtype": "m.bad.encrypted",
|
||||||
|
"body": exception.toString(),
|
||||||
|
},
|
||||||
|
"type": "m.room.message",
|
||||||
|
};
|
||||||
|
}
|
||||||
return Event(
|
return Event(
|
||||||
content: decryptedPayload["content"],
|
content: decryptedPayload["content"],
|
||||||
typeKey: decryptedPayload["type"],
|
typeKey: decryptedPayload["type"],
|
||||||
|
|
Loading…
Reference in a new issue