Merge branch 'master' into soru/cross-signing

This commit is contained in:
Sorunome 2020-06-10 16:25:08 +02:00
commit 5334266529
No known key found for this signature in database
GPG key ID: B19471D07FC9BE9C
4 changed files with 57 additions and 6 deletions

View file

@ -124,8 +124,11 @@ class Encryption {
canRequestSession = true; canRequestSession = true;
throw (DecryptError.UNKNOWN_SESSION); throw (DecryptError.UNKNOWN_SESSION);
} }
// decrypt errors here may mean we have a bad session key - others might have a better one
canRequestSession = true;
final decryptResult = inboundGroupSession.inboundGroupSession final decryptResult = inboundGroupSession.inboundGroupSession
.decrypt(event.content['ciphertext']); .decrypt(event.content['ciphertext']);
canRequestSession = false;
final messageIndexKey = event.eventId + final messageIndexKey = event.eventId +
event.originServerTs.millisecondsSinceEpoch.toString(); event.originServerTs.millisecondsSinceEpoch.toString();
var haveIndex = inboundGroupSession.indexes.containsKey(messageIndexKey); var haveIndex = inboundGroupSession.indexes.containsKey(messageIndexKey);
@ -148,8 +151,6 @@ class Encryption {
roomId, roomId,
sessionId); sessionId);
} }
// decrypt errors here may mean we have a bad session key - others might have a better one
canRequestSession = true;
decryptedPayload = json.decode(decryptResult.plaintext); decryptedPayload = json.decode(decryptResult.plaintext);
} catch (exception) { } catch (exception) {
// alright, if this was actually by our own outbound group session, we might as well clear it // alright, if this was actually by our own outbound group session, we might as well clear it

View file

@ -295,7 +295,7 @@ class Database extends _$Database {
final chatId = eventUpdate.roomID; final chatId = eventUpdate.roomID;
// Get the state_key for state events // Get the state_key for state events
var stateKey = ''; String stateKey;
if (eventContent['state_key'] is String) { if (eventContent['state_key'] is String) {
stateKey = eventContent['state_key']; stateKey = eventContent['state_key'];
} }
@ -353,7 +353,10 @@ class Database extends _$Database {
if (type == 'history') return; if (type == 'history') return;
if (type != 'account_data') { if (type != 'account_data' &&
((stateKey is String) ||
[EventTypes.Message, EventTypes.Sticker, EventTypes.Encrypted]
.contains(eventUpdate.eventType))) {
final now = DateTime.now(); final now = DateTime.now();
await storeRoomState( await storeRoomState(
clientId, clientId,
@ -369,7 +372,7 @@ class Database extends _$Database {
json.encode(eventContent['unsigned'] ?? ''), json.encode(eventContent['unsigned'] ?? ''),
json.encode(eventContent['content']), json.encode(eventContent['content']),
json.encode(eventContent['prev_content'] ?? ''), json.encode(eventContent['prev_content'] ?? ''),
stateKey, stateKey ?? '',
); );
} else if (type == 'account_data') { } else if (type == 'account_data') {
await storeRoomAccountData( await storeRoomAccountData(

View file

@ -115,7 +115,15 @@ class Room {
print('[LibOlm] Could not decrypt room state: ' + e.toString()); print('[LibOlm] Could not decrypt room state: ' + e.toString());
} }
} }
if ((getState(state.type)?.originServerTs?.millisecondsSinceEpoch ?? 0) > if (!(state.stateKey is String) &&
![EventTypes.Message, EventTypes.Sticker, EventTypes.Encrypted]
.contains(state.type)) {
return;
}
if ((getState(state.type, state.stateKey ?? '')
?.originServerTs
?.millisecondsSinceEpoch ??
0) >
(state.originServerTs?.millisecondsSinceEpoch ?? 1)) { (state.originServerTs?.millisecondsSinceEpoch ?? 1)) {
return; return;
} }

View file

@ -447,6 +447,45 @@ void main() {
await room.setHistoryVisibility(HistoryVisibility.joined); await room.setHistoryVisibility(HistoryVisibility.joined);
}); });
test('setState', () async {
// not set non-state-events
room.setState(Event.fromJson({
'content': {'history_visibility': 'shared'},
'event_id': '\$143273582443PhrSn:example.org',
'origin_server_ts': 1432735824653,
'room_id': '!jEsUZKDJdhlrceRyVU:example.org',
'sender': '@example:example.org',
'type': 'm.custom',
'unsigned': {'age': 1234}
}, room));
expect(room.getState('m.custom') != null, false);
// set state events
room.setState(Event.fromJson({
'content': {'history_visibility': 'shared'},
'event_id': '\$143273582443PhrSn:example.org',
'origin_server_ts': 1432735824653,
'room_id': '!jEsUZKDJdhlrceRyVU:example.org',
'sender': '@example:example.org',
'state_key': '',
'type': 'm.custom',
'unsigned': {'age': 1234}
}, room));
expect(room.getState('m.custom') != null, true);
// sets messages as state events
room.setState(Event.fromJson({
'content': {'history_visibility': 'shared'},
'event_id': '\$143273582443PhrSn:example.org',
'origin_server_ts': 1432735824653,
'room_id': '!jEsUZKDJdhlrceRyVU:example.org',
'sender': '@example:example.org',
'type': 'm.room.message',
'unsigned': {'age': 1234}
}, room));
expect(room.getState('m.room.message') != null, true);
});
test('logout', () async { test('logout', () async {
await matrix.logout(); await matrix.logout();
}); });