refactor: algorithm types

This commit is contained in:
Christian Pauly 2020-11-30 14:23:49 +01:00
parent 2e3a2d38c0
commit 323b203718
19 changed files with 110 additions and 62 deletions

View File

@ -135,7 +135,7 @@ class Encryption {
Map<String, dynamic> decryptedPayload; Map<String, dynamic> decryptedPayload;
var canRequestSession = false; var canRequestSession = false;
try { try {
if (event.content['algorithm'] != 'm.megolm.v1.aes-sha2') { if (event.content['algorithm'] != AlgorithmTypes.megolmV1AesSha2) {
throw (DecryptError.UNKNOWN_ALGORITHM); throw (DecryptError.UNKNOWN_ALGORITHM);
} }
final String sessionId = event.content['session_id']; final String sessionId = event.content['session_id'];
@ -277,7 +277,7 @@ class Encryption {
if (room == null || !room.encrypted || !enabled) { if (room == null || !room.encrypted || !enabled) {
return payload; return payload;
} }
if (room.encryptionAlgorithm != 'm.megolm.v1.aes-sha2') { if (room.encryptionAlgorithm != AlgorithmTypes.megolmV1AesSha2) {
throw ('Unknown encryption algorithm'); throw ('Unknown encryption algorithm');
} }
if (keyManager.getOutboundGroupSession(roomId) == null) { if (keyManager.getOutboundGroupSession(roomId) == null) {
@ -301,7 +301,7 @@ class Encryption {
'room_id': roomId, 'room_id': roomId,
}; };
var encryptedPayload = <String, dynamic>{ var encryptedPayload = <String, dynamic>{
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'ciphertext': 'ciphertext':
sess.outboundGroupSession.encrypt(json.encode(payloadContent)), sess.outboundGroupSession.encrypt(json.encode(payloadContent)),
'device_id': client.deviceID, 'device_id': client.deviceID,

View File

@ -98,7 +98,7 @@ class KeyManager {
} }
final oldSession = final oldSession =
getInboundGroupSession(roomId, sessionId, senderKey, otherRooms: false); getInboundGroupSession(roomId, sessionId, senderKey, otherRooms: false);
if (content['algorithm'] != 'm.megolm.v1.aes-sha2') { if (content['algorithm'] != AlgorithmTypes.megolmV1AesSha2) {
return; return;
} }
olm.InboundGroupSession inboundGroupSession; olm.InboundGroupSession inboundGroupSession;
@ -344,7 +344,7 @@ class KeyManager {
sess.sentMessages++; sess.sentMessages++;
sess.devices = newDeviceKeyIds; sess.devices = newDeviceKeyIds;
final rawSession = <String, dynamic>{ final rawSession = <String, dynamic>{
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': room.id, 'room_id': room.id,
'session_id': sess.outboundGroupSession.session_id(), 'session_id': sess.outboundGroupSession.session_id(),
'session_key': sess.outboundGroupSession.session_key(), 'session_key': sess.outboundGroupSession.session_key(),
@ -403,7 +403,7 @@ class KeyManager {
return null; return null;
} }
final rawSession = <String, dynamic>{ final rawSession = <String, dynamic>{
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': room.id, 'room_id': room.id,
'session_id': outboundGroupSession.session_id(), 'session_id': outboundGroupSession.session_id(),
'session_key': outboundGroupSession.session_key(), 'session_key': outboundGroupSession.session_key(),
@ -607,7 +607,7 @@ class KeyManager {
{ {
'action': 'request', 'action': 'request',
'body': { 'body': {
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': room.id, 'room_id': room.id,
'sender_key': senderKey, 'sender_key': senderKey,
'session_id': sessionId, 'session_id': sessionId,
@ -949,7 +949,7 @@ RoomKeys _generateUploadKeys(_GenerateUploadKeysArgs args) {
} }
// generate the encrypted content // generate the encrypted content
final payload = <String, dynamic>{ final payload = <String, dynamic>{
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'forwarding_curve25519_key_chain': sess.forwardingCurve25519KeyChain, 'forwarding_curve25519_key_chain': sess.forwardingCurve25519KeyChain,
'sender_key': sess.senderKey, 'sender_key': sess.senderKey,
'sender_clencaimed_keys': sess.senderClaimedKeys, 'sender_clencaimed_keys': sess.senderClaimedKeys,

View File

@ -177,8 +177,8 @@ class OlmManager {
'user_id': client.userID, 'user_id': client.userID,
'device_id': client.deviceID, 'device_id': client.deviceID,
'algorithms': [ 'algorithms': [
'm.olm.v1.curve25519-aes-sha2', AlgorithmTypes.olmV1Curve25519AesSha2,
'm.megolm.v1.aes-sha2' AlgorithmTypes.megolmV1AesSha2
], ],
'keys': <String, dynamic>{}, 'keys': <String, dynamic>{},
}, },
@ -251,7 +251,7 @@ class OlmManager {
if (event.type != EventTypes.Encrypted) { if (event.type != EventTypes.Encrypted) {
return event; return event;
} }
if (event.content['algorithm'] != 'm.olm.v1.curve25519-aes-sha2') { if (event.content['algorithm'] != AlgorithmTypes.olmV1Curve25519AesSha2) {
throw ('Unknown algorithm: ${event.content['algorithm']}'); throw ('Unknown algorithm: ${event.content['algorithm']}');
} }
if (!event.content['ciphertext'].containsKey(identityKey)) { if (!event.content['ciphertext'].containsKey(identityKey)) {
@ -476,7 +476,7 @@ class OlmManager {
final encryptResult = sess.first.session.encrypt(json.encode(fullPayload)); final encryptResult = sess.first.session.encrypt(json.encode(fullPayload));
storeOlmSession(sess.first); storeOlmSession(sess.first);
final encryptedBody = <String, dynamic>{ final encryptedBody = <String, dynamic>{
'algorithm': 'm.olm.v1.curve25519-aes-sha2', 'algorithm': AlgorithmTypes.olmV1Curve25519AesSha2,
'sender_key': identityKey, 'sender_key': identityKey,
'ciphertext': <String, dynamic>{}, 'ciphertext': <String, dynamic>{},
}; };

View File

@ -169,7 +169,7 @@ class SSSS {
bool checkKey(Uint8List key, BasicEvent keyData) { bool checkKey(Uint8List key, BasicEvent keyData) {
final info = keyData.content; final info = keyData.content;
if (info['algorithm'] == 'm.secret_storage.v1.aes-hmac-sha2') { if (info['algorithm'] == AlgorithmTypes.secretStorageV1AesHmcSha2) {
if ((info['mac'] is String) && (info['iv'] is String)) { if ((info['mac'] is String) && (info['iv'] is String)) {
final encrypted = encryptAes(ZERO_STR, key, '', info['iv']); final encrypted = encryptAes(ZERO_STR, key, '', info['iv']);
return info['mac'].replaceAll(RegExp(r'=+$'), '') == return info['mac'].replaceAll(RegExp(r'=+$'), '') ==

View File

@ -19,6 +19,7 @@
library matrix_api; library matrix_api;
export 'matrix_api/matrix_api.dart'; export 'matrix_api/matrix_api.dart';
export 'matrix_api/model/algorithm_types.dart';
export 'matrix_api/model/basic_event.dart'; export 'matrix_api/model/basic_event.dart';
export 'matrix_api/model/basic_event_with_sender.dart'; export 'matrix_api/model/basic_event_with_sender.dart';
export 'matrix_api/model/basic_room_event.dart'; export 'matrix_api/model/basic_room_event.dart';

View File

@ -0,0 +1,26 @@
/*
* Famedly Matrix SDK
* Copyright (C) 2019, 2020 Famedly GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
abstract class AlgorithmTypes {
static const String olmV1Curve25519AesSha2 = 'm.olm.v1.curve25519-aes-sha2';
static const String megolmV1AesSha2 = 'm.megolm.v1.aes-sha2';
static const String secretStorageV1AesHmcSha2 =
'm.secret_storage.v1.aes-hmac-sha2';
static const String megolmBackupV1Curve25519AesSha2 =
'm.megolm_backup.v1.curve25519-aes-sha2';
}

View File

@ -16,13 +16,15 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import '../../matrix_api.dart';
enum RoomKeysAlgorithmType { v1Curve25519AesSha2 } enum RoomKeysAlgorithmType { v1Curve25519AesSha2 }
extension RoomKeysAlgorithmTypeExtension on RoomKeysAlgorithmType { extension RoomKeysAlgorithmTypeExtension on RoomKeysAlgorithmType {
String get algorithmString { String get algorithmString {
switch (this) { switch (this) {
case RoomKeysAlgorithmType.v1Curve25519AesSha2: case RoomKeysAlgorithmType.v1Curve25519AesSha2:
return 'm.megolm_backup.v1.curve25519-aes-sha2'; return AlgorithmTypes.megolmBackupV1Curve25519AesSha2;
default: default:
return null; return null;
} }
@ -30,7 +32,7 @@ extension RoomKeysAlgorithmTypeExtension on RoomKeysAlgorithmType {
static RoomKeysAlgorithmType fromAlgorithmString(String s) { static RoomKeysAlgorithmType fromAlgorithmString(String s) {
switch (s) { switch (s) {
case 'm.megolm_backup.v1.curve25519-aes-sha2': case AlgorithmTypes.megolmBackupV1Curve25519AesSha2:
return RoomKeysAlgorithmType.v1Curve25519AesSha2; return RoomKeysAlgorithmType.v1Curve25519AesSha2;
default: default:
return null; return null;

View File

@ -523,10 +523,10 @@ class Client extends MatrixApi {
'{"room":{"state":{"lazy_load_members":true}}}'; '{"room":{"state":{"lazy_load_members":true}}}';
static const String messagesFilters = '{"lazy_load_members":true}'; static const String messagesFilters = '{"lazy_load_members":true}';
static const List<String> supportedDirectEncryptionAlgorithms = [ static const List<String> supportedDirectEncryptionAlgorithms = [
'm.olm.v1.curve25519-aes-sha2' AlgorithmTypes.olmV1Curve25519AesSha2
]; ];
static const List<String> supportedGroupEncryptionAlgorithms = [ static const List<String> supportedGroupEncryptionAlgorithms = [
'm.megolm.v1.aes-sha2' AlgorithmTypes.megolmV1AesSha2
]; ];
static const int defaultThumbnailSize = 256; static const int defaultThumbnailSize = 256;

View File

@ -357,7 +357,10 @@ void main() {
var deviceKeys = DeviceKeys.fromJson({ var deviceKeys = DeviceKeys.fromJson({
'user_id': '@alice:example.com', 'user_id': '@alice:example.com',
'device_id': 'JLAFKJWSCS', 'device_id': 'JLAFKJWSCS',
'algorithms': ['m.olm.v1.curve25519-aes-sha2', 'm.megolm.v1.aes-sha2'], 'algorithms': [
AlgorithmTypes.olmV1Curve25519AesSha2,
AlgorithmTypes.megolmV1AesSha2
],
'keys': { 'keys': {
'curve25519:JLAFKJWSCS': '3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI', 'curve25519:JLAFKJWSCS': '3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI',
'ed25519:JLAFKJWSCS': 'lEuiRJBit0IG6nUf5pUzWTUEsRVVe/HJkoKuEww9ULI' 'ed25519:JLAFKJWSCS': 'lEuiRJBit0IG6nUf5pUzWTUEsRVVe/HJkoKuEww9ULI'

View File

@ -33,7 +33,10 @@ void main() {
var rawJson = <String, dynamic>{ var rawJson = <String, dynamic>{
'user_id': '@alice:example.com', 'user_id': '@alice:example.com',
'device_id': 'JLAFKJWSCS', 'device_id': 'JLAFKJWSCS',
'algorithms': ['m.olm.v1.curve25519-aes-sha2', 'm.megolm.v1.aes-sha2'], 'algorithms': [
AlgorithmTypes.olmV1Curve25519AesSha2,
AlgorithmTypes.megolmV1AesSha2
],
'keys': { 'keys': {
'curve25519:JLAFKJWSCS': 'curve25519:JLAFKJWSCS':
'3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI', '3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI',

View File

@ -53,7 +53,7 @@ void main() {
'msgtype': 'm.text', 'msgtype': 'm.text',
'text': 'Hello foxies!', 'text': 'Hello foxies!',
}); });
expect(payload['algorithm'], 'm.megolm.v1.aes-sha2'); expect(payload['algorithm'], AlgorithmTypes.megolmV1AesSha2);
expect(payload['ciphertext'] is String, true); expect(payload['ciphertext'] is String, true);
expect(payload['device_id'], client.deviceID); expect(payload['device_id'], client.deviceID);
expect(payload['sender_key'], client.identityKey); expect(payload['sender_key'], client.identityKey);

View File

@ -65,7 +65,10 @@ void main() {
device = DeviceKeys.fromJson({ device = DeviceKeys.fromJson({
'user_id': client.userID, 'user_id': client.userID,
'device_id': client.deviceID, 'device_id': client.deviceID,
'algorithms': ['m.olm.v1.curve25519-aes-sha2', 'm.megolm.v1.aes-sha2'], 'algorithms': [
AlgorithmTypes.olmV1Curve25519AesSha2,
AlgorithmTypes.megolmV1AesSha2
],
'keys': { 'keys': {
'curve25519:${client.deviceID}': client.identityKey, 'curve25519:${client.deviceID}': client.identityKey,
'ed25519:${client.deviceID}': client.fingerprintKey, 'ed25519:${client.deviceID}': client.fingerprintKey,

View File

@ -56,7 +56,7 @@ void main() {
sender: '@alice:example.com', sender: '@alice:example.com',
type: 'm.room_key', type: 'm.room_key',
content: { content: {
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': '!726s6s6q:example.com', 'room_id': '!726s6s6q:example.com',
'session_id': validSessionId, 'session_id': validSessionId,
'session_key': sessionKey, 'session_key': sessionKey,
@ -79,7 +79,7 @@ void main() {
sender: '@alice:example.com', sender: '@alice:example.com',
type: 'm.room_key', type: 'm.room_key',
content: { content: {
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': '!726s6s6q:example.com', 'room_id': '!726s6s6q:example.com',
'session_id': validSessionId, 'session_id': validSessionId,
'session_key': sessionKey, 'session_key': sessionKey,
@ -161,7 +161,10 @@ void main() {
DeviceKeys.fromJson({ DeviceKeys.fromJson({
'user_id': '@alice:example.com', 'user_id': '@alice:example.com',
'device_id': 'NEWDEVICE', 'device_id': 'NEWDEVICE',
'algorithms': ['m.olm.v1.curve25519-aes-sha2', 'm.megolm.v1.aes-sha2'], 'algorithms': [
AlgorithmTypes.olmV1Curve25519AesSha2,
AlgorithmTypes.megolmV1AesSha2
],
'keys': { 'keys': {
'curve25519:JLAFKJWSCS': 'curve25519:JLAFKJWSCS':
'3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI', '3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI',
@ -212,7 +215,7 @@ void main() {
final sessionId = 'ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU'; final sessionId = 'ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU';
final senderKey = 'JBG7ZaPn54OBC7TuIEiylW3BZ+7WcGQhFBPB9pogbAg'; final senderKey = 'JBG7ZaPn54OBC7TuIEiylW3BZ+7WcGQhFBPB9pogbAg';
final sessionContent = <String, dynamic>{ final sessionContent = <String, dynamic>{
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': '!726s6s6q:example.com', 'room_id': '!726s6s6q:example.com',
'session_id': 'ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU', 'session_id': 'ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU',
'session_key': 'session_key':
@ -307,7 +310,7 @@ void main() {
eventId: '12345', eventId: '12345',
originServerTs: DateTime.now(), originServerTs: DateTime.now(),
content: { content: {
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'ciphertext': session.encrypt(json.encode({ 'ciphertext': session.encrypt(json.encode({
'type': 'm.room.message', 'type': 'm.room.message',
'content': {'msgtype': 'm.text', 'body': 'foxies'}, 'content': {'msgtype': 'm.text', 'body': 'foxies'},
@ -322,7 +325,7 @@ void main() {
expect(room.lastEvent.type, 'm.room.encrypted'); expect(room.lastEvent.type, 'm.room.encrypted');
// set a payload... // set a payload...
var sessionPayload = <String, dynamic>{ var sessionPayload = <String, dynamic>{
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': roomId, 'room_id': roomId,
'forwarding_curve25519_key_chain': [client.identityKey], 'forwarding_curve25519_key_chain': [client.identityKey],
'session_id': sessionId, 'session_id': sessionId,
@ -348,7 +351,7 @@ void main() {
// not set one with a higher first known index // not set one with a higher first known index
sessionPayload = <String, dynamic>{ sessionPayload = <String, dynamic>{
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': roomId, 'room_id': roomId,
'forwarding_curve25519_key_chain': [client.identityKey], 'forwarding_curve25519_key_chain': [client.identityKey],
'session_id': sessionId, 'session_id': sessionId,
@ -374,7 +377,7 @@ void main() {
// set one with a lower first known index // set one with a lower first known index
sessionPayload = <String, dynamic>{ sessionPayload = <String, dynamic>{
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': roomId, 'room_id': roomId,
'forwarding_curve25519_key_chain': [client.identityKey], 'forwarding_curve25519_key_chain': [client.identityKey],
'session_id': sessionId, 'session_id': sessionId,
@ -400,7 +403,7 @@ void main() {
// not set one with a longer forwarding chain // not set one with a longer forwarding chain
sessionPayload = <String, dynamic>{ sessionPayload = <String, dynamic>{
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': roomId, 'room_id': roomId,
'forwarding_curve25519_key_chain': [client.identityKey, 'beep'], 'forwarding_curve25519_key_chain': [client.identityKey, 'beep'],
'session_id': sessionId, 'session_id': sessionId,
@ -426,7 +429,7 @@ void main() {
// set one with a shorter forwarding chain // set one with a shorter forwarding chain
sessionPayload = <String, dynamic>{ sessionPayload = <String, dynamic>{
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': roomId, 'room_id': roomId,
'forwarding_curve25519_key_chain': [], 'forwarding_curve25519_key_chain': [],
'session_id': sessionId, 'session_id': sessionId,

View File

@ -98,7 +98,7 @@ void main() {
content: { content: {
'action': 'request', 'action': 'request',
'body': { 'body': {
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': '!726s6s6q:example.com', 'room_id': '!726s6s6q:example.com',
'sender_key': validSenderKey, 'sender_key': validSenderKey,
'session_id': validSessionId, 'session_id': validSessionId,
@ -139,7 +139,7 @@ void main() {
content: { content: {
'action': 'request', 'action': 'request',
'body': { 'body': {
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': '!726s6s6q:example.com', 'room_id': '!726s6s6q:example.com',
'sender_key': validSenderKey, 'sender_key': validSenderKey,
'session_id': validSessionId, 'session_id': validSessionId,
@ -161,7 +161,7 @@ void main() {
content: { content: {
'action': 'request', 'action': 'request',
'body': { 'body': {
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': '!726s6s6q:example.com', 'room_id': '!726s6s6q:example.com',
'sender_key': validSenderKey, 'sender_key': validSenderKey,
'session_id': validSessionId, 'session_id': validSessionId,
@ -183,7 +183,7 @@ void main() {
content: { content: {
'action': 'request', 'action': 'request',
'body': { 'body': {
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': '!invalid:example.com', 'room_id': '!invalid:example.com',
'sender_key': validSenderKey, 'sender_key': validSenderKey,
'session_id': validSessionId, 'session_id': validSessionId,
@ -205,7 +205,7 @@ void main() {
content: { content: {
'action': 'request', 'action': 'request',
'body': { 'body': {
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': '!726s6s6q:example.com', 'room_id': '!726s6s6q:example.com',
'sender_key': validSenderKey, 'sender_key': validSenderKey,
'session_id': 'invalid', 'session_id': 'invalid',
@ -239,7 +239,7 @@ void main() {
sender: '@alice:example.com', sender: '@alice:example.com',
type: 'm.forwarded_room_key', type: 'm.forwarded_room_key',
content: { content: {
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': '!726s6s6q:example.com', 'room_id': '!726s6s6q:example.com',
'session_id': validSessionId, 'session_id': validSessionId,
'session_key': sessionKey, 'session_key': sessionKey,
@ -264,7 +264,7 @@ void main() {
sender: '@alice:example.com', sender: '@alice:example.com',
type: 'm.forwarded_room_key', type: 'm.forwarded_room_key',
content: { content: {
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': '!726s6s6q:example.com', 'room_id': '!726s6s6q:example.com',
'session_id': validSessionId, 'session_id': validSessionId,
'session_key': sessionKey, 'session_key': sessionKey,
@ -290,7 +290,7 @@ void main() {
sender: '@alice:example.com', sender: '@alice:example.com',
type: 'm.forwarded_room_key', type: 'm.forwarded_room_key',
content: { content: {
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': '!726s6s6q:example.com', 'room_id': '!726s6s6q:example.com',
'session_id': validSessionId, 'session_id': validSessionId,
'session_key': sessionKey, 'session_key': sessionKey,
@ -316,7 +316,7 @@ void main() {
sender: '@alice:example.com', sender: '@alice:example.com',
type: 'm.forwarded_room_key', type: 'm.forwarded_room_key',
content: { content: {
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': '!726s6s6q:example.com', 'room_id': '!726s6s6q:example.com',
'session_id': validSessionId, 'session_id': validSessionId,
'session_key': sessionKey, 'session_key': sessionKey,

View File

@ -81,7 +81,7 @@ void main() {
final sessionId = inbound.session_id(); final sessionId = inbound.session_id();
// set a payload... // set a payload...
var sessionPayload = <String, dynamic>{ var sessionPayload = <String, dynamic>{
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'room_id': roomId, 'room_id': roomId,
'forwarding_curve25519_key_chain': [client.identityKey], 'forwarding_curve25519_key_chain': [client.identityKey],
'session_id': sessionId, 'session_id': sessionId,

View File

@ -304,7 +304,7 @@ void main() {
'msgtype': 'm.bad.encrypted', 'msgtype': 'm.bad.encrypted',
'body': DecryptError.UNKNOWN_SESSION, 'body': DecryptError.UNKNOWN_SESSION,
'can_request_session': true, 'can_request_session': true,
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'ciphertext': 'AwgAEnACgAkLmt6qF84IK++J7UDH2Za1YVchHyprqTqsg...', 'ciphertext': 'AwgAEnACgAkLmt6qF84IK++J7UDH2Za1YVchHyprqTqsg...',
'device_id': 'RJYKSTBOIE', 'device_id': 'RJYKSTBOIE',
'sender_key': 'IlRMeOPX2e0MurIyfWEucYBRVOEEUMrOHqn/8mLqMjA', 'sender_key': 'IlRMeOPX2e0MurIyfWEucYBRVOEEUMrOHqn/8mLqMjA',
@ -691,7 +691,7 @@ void main() {
event = Event.fromJson({ event = Event.fromJson({
'content': { 'content': {
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'rotation_period_ms': 604800000, 'rotation_period_ms': 604800000,
'rotation_period_msgs': 100 'rotation_period_msgs': 100
}, },

View File

@ -20,6 +20,7 @@ import 'dart:convert';
import 'dart:core'; import 'dart:core';
import 'dart:math'; import 'dart:math';
import 'package:famedlysdk/matrix_api.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
import 'package:http/testing.dart'; import 'package:http/testing.dart';
@ -198,7 +199,7 @@ class FakeMatrixApi extends MockClient {
'sender': '@alice:example.com', 'sender': '@alice:example.com',
'type': 'm.room.encryption', 'type': 'm.room.encryption',
'state_key': '', 'state_key': '',
'content': {'algorithm': 'm.megolm.v1.aes-sha2'}, 'content': {'algorithm': AlgorithmTypes.megolmV1AesSha2},
'origin_server_ts': 1417731086795, 'origin_server_ts': 1417731086795,
'event_id': '666972737430353:example.com' 'event_id': '666972737430353:example.com'
}, },
@ -543,7 +544,7 @@ class FakeMatrixApi extends MockClient {
{ {
'type': 'm.secret_storage.key.0FajDWYaM6wQ4O60OZnLvwZfsBNu4Bu3', 'type': 'm.secret_storage.key.0FajDWYaM6wQ4O60OZnLvwZfsBNu4Bu3',
'content': { 'content': {
'algorithm': 'm.secret_storage.v1.aes-hmac-sha2', 'algorithm': AlgorithmTypes.secretStorageV1AesHmcSha2,
'passphrase': { 'passphrase': {
'algorithm': 'm.pbkdf2', 'algorithm': 'm.pbkdf2',
'iterations': 500000, 'iterations': 500000,
@ -620,7 +621,7 @@ class FakeMatrixApi extends MockClient {
// { // {
// 'sender': '@othertest:fakeServer.notExisting', // 'sender': '@othertest:fakeServer.notExisting',
// 'content': { // 'content': {
// 'algorithm': 'm.megolm.v1.aes-sha2', // 'algorithm': AlgorithmTypes.megolmV1AesSha2,
// 'room_id': '!726s6s6q:example.com', // 'room_id': '!726s6s6q:example.com',
// 'session_id': 'ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU', // 'session_id': 'ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU',
// 'session_key': // 'session_key':
@ -632,7 +633,7 @@ class FakeMatrixApi extends MockClient {
// this is the commented out m.room_key event - only encrypted // this is the commented out m.room_key event - only encrypted
'sender': '@othertest:fakeServer.notExisting', 'sender': '@othertest:fakeServer.notExisting',
'content': { 'content': {
'algorithm': 'm.olm.v1.curve25519-aes-sha2', 'algorithm': AlgorithmTypes.olmV1Curve25519AesSha2,
'sender_key': 'JBG7ZaPn54OBC7TuIEiylW3BZ+7WcGQhFBPB9pogbAg', 'sender_key': 'JBG7ZaPn54OBC7TuIEiylW3BZ+7WcGQhFBPB9pogbAg',
'ciphertext': { 'ciphertext': {
'7rvl3jORJkBiK4XX1e5TnGnqz068XfYJ0W++Ml63rgk': { '7rvl3jORJkBiK4XX1e5TnGnqz068XfYJ0W++Ml63rgk': {
@ -1551,7 +1552,7 @@ class FakeMatrixApi extends MockClient {
'event_fields': ['type', 'content', 'sender'] 'event_fields': ['type', 'content', 'sender']
}, },
'/client/unstable/room_keys/version': (var req) => { '/client/unstable/room_keys/version': (var req) => {
'algorithm': 'm.megolm_backup.v1.curve25519-aes-sha2', 'algorithm': AlgorithmTypes.megolmBackupV1Curve25519AesSha2,
'auth_data': { 'auth_data': {
'public_key': 'GXYaxqhNhUK28zUdxOmEsFRguz+PzBsDlTLlF0O0RkM', 'public_key': 'GXYaxqhNhUK28zUdxOmEsFRguz+PzBsDlTLlF0O0RkM',
'signatures': {}, 'signatures': {},
@ -1774,8 +1775,8 @@ class FakeMatrixApi extends MockClient {
'user_id': '@alice:example.com', 'user_id': '@alice:example.com',
'device_id': 'JLAFKJWSCS', 'device_id': 'JLAFKJWSCS',
'algorithms': [ 'algorithms': [
'm.olm.v1.curve25519-aes-sha2', AlgorithmTypes.olmV1Curve25519AesSha2,
'm.megolm.v1.aes-sha2' AlgorithmTypes.megolmV1AesSha2
], ],
'keys': { 'keys': {
'curve25519:JLAFKJWSCS': 'curve25519:JLAFKJWSCS':
@ -1795,8 +1796,8 @@ class FakeMatrixApi extends MockClient {
'user_id': '@alice:example.com', 'user_id': '@alice:example.com',
'device_id': 'OTHERDEVICE', 'device_id': 'OTHERDEVICE',
'algorithms': [ 'algorithms': [
'm.olm.v1.curve25519-aes-sha2', AlgorithmTypes.olmV1Curve25519AesSha2,
'm.megolm.v1.aes-sha2' AlgorithmTypes.megolmV1AesSha2
], ],
'keys': { 'keys': {
'curve25519:OTHERDEVICE': 'blah', 'curve25519:OTHERDEVICE': 'blah',
@ -1810,8 +1811,8 @@ class FakeMatrixApi extends MockClient {
'user_id': '@test:fakeServer.notExisting', 'user_id': '@test:fakeServer.notExisting',
'device_id': 'GHTYAJCE', 'device_id': 'GHTYAJCE',
'algorithms': [ 'algorithms': [
'm.olm.v1.curve25519-aes-sha2', AlgorithmTypes.olmV1Curve25519AesSha2,
'm.megolm.v1.aes-sha2' AlgorithmTypes.megolmV1AesSha2
], ],
'keys': { 'keys': {
'curve25519:GHTYAJCE': 'curve25519:GHTYAJCE':
@ -1830,8 +1831,8 @@ class FakeMatrixApi extends MockClient {
'user_id': '@test:fakeServer.notExisting', 'user_id': '@test:fakeServer.notExisting',
'device_id': 'OTHERDEVICE', 'device_id': 'OTHERDEVICE',
'algorithms': [ 'algorithms': [
'm.olm.v1.curve25519-aes-sha2', AlgorithmTypes.olmV1Curve25519AesSha2,
'm.megolm.v1.aes-sha2' AlgorithmTypes.megolmV1AesSha2
], ],
'keys': { 'keys': {
'curve25519:OTHERDEVICE': 'blah', 'curve25519:OTHERDEVICE': 'blah',
@ -1850,8 +1851,8 @@ class FakeMatrixApi extends MockClient {
'user_id': '@othertest:fakeServer.notExisting', 'user_id': '@othertest:fakeServer.notExisting',
'device_id': 'FOXDEVICE', 'device_id': 'FOXDEVICE',
'algorithms': [ 'algorithms': [
'm.olm.v1.curve25519-aes-sha2', AlgorithmTypes.olmV1Curve25519AesSha2,
'm.megolm.v1.aes-sha2' AlgorithmTypes.megolmV1AesSha2
], ],
'keys': { 'keys': {
'curve25519:FOXDEVICE': 'curve25519:FOXDEVICE':

View File

@ -1158,7 +1158,10 @@ void main() {
final key1 = MatrixDeviceKeys.fromJson({ final key1 = MatrixDeviceKeys.fromJson({
'user_id': '@alice:example.com', 'user_id': '@alice:example.com',
'device_id': 'JLAFKJWSCS', 'device_id': 'JLAFKJWSCS',
'algorithms': ['m.olm.v1.curve25519-aes-sha2', 'm.megolm.v1.aes-sha2'], 'algorithms': [
AlgorithmTypes.olmV1Curve25519AesSha2,
AlgorithmTypes.megolmV1AesSha2
],
'keys': { 'keys': {
'curve25519:JLAFKJWSCS': 'curve25519:JLAFKJWSCS':
'3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI', '3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI',
@ -1175,7 +1178,10 @@ void main() {
final key2 = MatrixDeviceKeys.fromJson({ final key2 = MatrixDeviceKeys.fromJson({
'user_id': '@alice:example.com', 'user_id': '@alice:example.com',
'device_id': 'JLAFKJWSCS', 'device_id': 'JLAFKJWSCS',
'algorithms': ['m.olm.v1.curve25519-aes-sha2', 'm.megolm.v1.aes-sha2'], 'algorithms': [
AlgorithmTypes.olmV1Curve25519AesSha2,
AlgorithmTypes.megolmV1AesSha2
],
'keys': { 'keys': {
'curve25519:JLAFKJWSCS': 'curve25519:JLAFKJWSCS':
'3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI', '3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI',

View File

@ -516,14 +516,14 @@ void main() {
eventId: '12345', eventId: '12345',
originServerTs: DateTime.now(), originServerTs: DateTime.now(),
content: { content: {
'algorithm': 'm.megolm.v1.aes-sha2', 'algorithm': AlgorithmTypes.megolmV1AesSha2,
'rotation_period_ms': 604800000, 'rotation_period_ms': 604800000,
'rotation_period_msgs': 100 'rotation_period_msgs': 100
}, },
stateKey: ''), stateKey: ''),
); );
expect(room.encrypted, true); expect(room.encrypted, true);
expect(room.encryptionAlgorithm, 'm.megolm.v1.aes-sha2'); expect(room.encryptionAlgorithm, AlgorithmTypes.megolmV1AesSha2);
}); });
test('setPushRuleState', () async { test('setPushRuleState', () async {