style: Format using dart format

This commit is contained in:
2023-06-12 19:20:43 +02:00
parent f2ec7bd759
commit 65f1daff55
35 changed files with 713 additions and 461 deletions

View File

@@ -16,7 +16,7 @@ void main() {
..pn = 0
..dhPub = List<int>.empty();
final asd = concat([sessionAd, header.writeToBuffer()]);
final ciphertext = await encrypt(
mk,
plaintext,
@@ -55,13 +55,13 @@ void main() {
2: await opkBob.pk.asBase64(),
},
);
// Alice does X3DH
final resultAlice = await x3dhFromBundle(bundleBob, ikAlice);
// Alice sends the inital message to Bob
// ...
// Bob does X3DH
final resultBob = await x3dhFromInitialMessage(
X3DHMessage(
@@ -76,7 +76,6 @@ void main() {
print('X3DH key exchange done');
// Alice and Bob now share sk as a common secret and ad
// Build a session
final alicesRatchet = await OmemoDoubleRatchet.initiateNewSession(
@@ -98,10 +97,11 @@ void main() {
for (var i = 0; i < 100; i++) {
final messageText = 'Hello, dear $i';
if (i.isEven) {
// Alice encrypts a message
final aliceRatchetResult = await alicesRatchet.ratchetEncrypt(utf8.encode(messageText));
final aliceRatchetResult =
await alicesRatchet.ratchetEncrypt(utf8.encode(messageText));
print('Alice sent the message');
// Alice sends it to Bob
@@ -117,7 +117,8 @@ void main() {
expect(utf8.encode(messageText), bobRatchetResult);
} else {
// Bob sends a message to Alice
final bobRatchetResult = await bobsRatchet.ratchetEncrypt(utf8.encode(messageText));
final bobRatchetResult =
await bobsRatchet.ratchetEncrypt(utf8.encode(messageText));
print('Bob sent the message');
// Bobs sends it to Alice

View File

@@ -30,18 +30,18 @@ void main() {
if (!m) opksMatch = false;
}
}
expect(opksMatch, true);
expect(await device.ik.equals(newDevice.ik), true);
expect(await device.spk.equals(newDevice.spk), true);
final oldSpkMatch = device.oldSpk != null ?
await device.oldSpk!.equals(newDevice.oldSpk!) :
newDevice.oldSpk == null;
final oldSpkMatch = device.oldSpk != null
? await device.oldSpk!.equals(newDevice.oldSpk!)
: newDevice.oldSpk == null;
expect(oldSpkMatch, true);
expect(listsEqual(device.spkSignature, newDevice.spkSignature), true);
});
test('Test using OMEMO sessions with only one device per user', () async {
const aliceJid = 'alice@server.example';
const bobJid = 'bob@other.server.example';
@@ -80,7 +80,7 @@ void main() {
],
);
expect(aliceMessage.encryptedKeys.length, 1);
// Alice sends the message to Bob
// ...
@@ -107,9 +107,11 @@ void main() {
);
// Ratchets are acked
await aliceSession.ratchetAcknowledged(bobJid, await bobSession.getDeviceId());
await bobSession.ratchetAcknowledged(aliceJid, await aliceSession.getDeviceId());
await aliceSession.ratchetAcknowledged(
bobJid, await bobSession.getDeviceId());
await bobSession.ratchetAcknowledged(
aliceJid, await aliceSession.getDeviceId());
// Bob responds to Alice
const bobResponseText = 'Oh, hello Alice!';
final bobResponseMessage = await bobSession.encryptToJid(
@@ -131,10 +133,11 @@ void main() {
expect(bobResponseText, aliceReceivedMessage);
});
test('Test using OMEMO sessions with only two devices for the receiver', () async {
test('Test using OMEMO sessions with only two devices for the receiver',
() async {
const aliceJid = 'alice@server.example';
const bobJid = 'bob@other.server.example';
// Alice and Bob generate their sessions
final aliceSession = await OmemoSessionManager.generateNewIdentity(
aliceJid,
@@ -181,9 +184,11 @@ void main() {
expect(messagePlaintext, bobMessage);
// Ratchets are acked
await aliceSession.ratchetAcknowledged(bobJid, await bobSession.getDeviceId());
await bobSession.ratchetAcknowledged(aliceJid, await aliceSession.getDeviceId());
await aliceSession.ratchetAcknowledged(
bobJid, await bobSession.getDeviceId());
await bobSession.ratchetAcknowledged(
aliceJid, await aliceSession.getDeviceId());
// Bob responds to Alice
const bobResponseText = 'Oh, hello Alice!';
final bobResponseMessage = await bobSession.encryptToJid(
@@ -218,7 +223,7 @@ void main() {
test('Test using OMEMO sessions with encrypt to self', () async {
const aliceJid = 'alice@server.example';
const bobJid = 'bob@other.server.example';
// Alice and Bob generate their sessions
final aliceSession1 = await OmemoSessionManager.generateNewIdentity(
aliceJid,
@@ -275,7 +280,7 @@ void main() {
test('Test sending empty OMEMO messages', () async {
const aliceJid = 'alice@server.example';
const bobJid = 'bob@other.server.example';
// Alice and Bob generate their sessions
final aliceSession = await OmemoSessionManager.generateNewIdentity(
aliceJid,
@@ -350,7 +355,7 @@ void main() {
test('Test accepting a session with an old SPK', () async {
const aliceJid = 'alice@server.example';
const bobJid = 'bob@other.server.example';
// Alice and Bob generate their sessions
final aliceSession = await OmemoSessionManager.generateNewIdentity(
aliceJid,
@@ -376,7 +381,7 @@ void main() {
// Alice loses her Internet connection. Bob rotates his SPK.
await bobSession.rotateSignedPrekey();
// Alice regains her Internet connection and sends the message to Bob
// ...
@@ -394,7 +399,7 @@ void main() {
test('Test trust bypassing with empty OMEMO messages', () async {
const aliceJid = 'alice@server.example';
const bobJid = 'bob@other.server.example';
// Alice and Bob generate their sessions
final aliceSession = await OmemoSessionManager.generateNewIdentity(
aliceJid,
@@ -457,9 +462,11 @@ void main() {
);
// Ratchets are acked
await aliceSession.ratchetAcknowledged(bobJid, await bobSession.getDeviceId());
await bobSession.ratchetAcknowledged(aliceJid, await aliceSession.getDeviceId());
await aliceSession.ratchetAcknowledged(
bobJid, await bobSession.getDeviceId());
await bobSession.ratchetAcknowledged(
aliceJid, await aliceSession.getDeviceId());
for (var i = 0; i < 100; i++) {
final messageText = 'Test Message #$i';
// Bob responds to Alice
@@ -597,7 +604,8 @@ void main() {
// ...
// Alice marks the ratchet as acknowledged
await aliceSession.ratchetAcknowledged(bobJid, await bobSession.getDeviceId());
await aliceSession.ratchetAcknowledged(
bobJid, await bobSession.getDeviceId());
expect(
(await aliceSession.getUnacknowledgedRatchets(bobJid))!.isEmpty,
true,
@@ -671,7 +679,7 @@ void main() {
// Both should only have one ratchet
expect(aliceSession.getRatchetMap().length, 1);
expect(bobSession.getRatchetMap().length, 1);
// The ratchets should both be different
expect(await aliceRatchet1.equals(aliceRatchet2), false);
expect(await bobRatchet1.equals(bobRatchet2), false);
@@ -726,9 +734,8 @@ void main() {
msg2.encryptedKeys,
getTimestamp(),
);
});
test('Test receiving old messages including a KEX', () async {
const aliceJid = 'alice@server.example';
const bobJid = 'bob@other.server.example';
@@ -746,7 +753,7 @@ void main() {
final bobsReceivedMessages = List<EncryptionResult>.empty(growable: true);
final bobsReceivedMessagesTimestamps = List<int>.empty(growable: true);
// Alice sends Bob a message
final msg1 = await aliceSession.encryptToJid(
bobJid,
@@ -768,9 +775,11 @@ void main() {
);
// Ratchets are acked
await aliceSession.ratchetAcknowledged(bobJid, await bobSession.getDeviceId());
await bobSession.ratchetAcknowledged(aliceJid, await aliceSession.getDeviceId());
await aliceSession.ratchetAcknowledged(
bobJid, await bobSession.getDeviceId());
await bobSession.ratchetAcknowledged(
aliceJid, await aliceSession.getDeviceId());
// Bob responds
final msg2 = await bobSession.encryptToJid(
aliceJid,
@@ -784,7 +793,7 @@ void main() {
msg2.encryptedKeys,
getTimestamp(),
);
// Send some messages between the two
for (var i = 0; i < 100; i++) {
final msg = await aliceSession.encryptToJid(
@@ -808,8 +817,8 @@ void main() {
// Due to some issue with the transport protocol, the messages to Bob are received
// again.
final ratchetPreError = bobSession
.getRatchet(aliceJid, await aliceSession.getDeviceId())
.clone();
.getRatchet(aliceJid, await aliceSession.getDeviceId())
.clone();
var invalidKex = 0;
var errorCounter = 0;
for (var i = 0; i < bobsReceivedMessages.length; i++) {
@@ -830,15 +839,14 @@ void main() {
}
}
final ratchetPostError = bobSession
.getRatchet(aliceJid, await aliceSession.getDeviceId())
.clone();
.getRatchet(aliceJid, await aliceSession.getDeviceId())
.clone();
// The 100 messages including the initial KEX message
expect(invalidKex, 1);
expect(errorCounter, 100);
expect(await ratchetPreError.equals(ratchetPostError), true);
final msg3 = await aliceSession.encryptToJid(
bobJid,
'Are you okay?',
@@ -903,8 +911,10 @@ void main() {
);
// Now the acks reach us
await aliceSession.ratchetAcknowledged(bobJid, await bobSession.getDeviceId());
await bobSession.ratchetAcknowledged(aliceJid, await aliceSession.getDeviceId());
await aliceSession.ratchetAcknowledged(
bobJid, await bobSession.getDeviceId());
await bobSession.ratchetAcknowledged(
aliceJid, await aliceSession.getDeviceId());
// Alice sends another message
final msg3 = await aliceSession.encryptToJid(

View File

@@ -28,7 +28,8 @@ void main() {
var aliceEmptyMessageSent = 0;
var bobEmptyMessageSent = 0;
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final aliceDevice =
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final aliceManager = OmemoManager(
@@ -39,7 +40,7 @@ void main() {
},
(jid) async {
expect(jid, bobJid);
return [ bobDevice.id ];
return [bobDevice.id];
},
(jid, id) async {
expect(jid, bobJid);
@@ -93,7 +94,7 @@ void main() {
bobJid,
bobDevice.id,
);
// Bob now responds
final bobResult2 = await bobManager.onOutgoingStanza(
const OmemoOutgoingStanza(
@@ -123,7 +124,8 @@ void main() {
var aliceEmptyMessageSent = 0;
var bobEmptyMessageSent = 0;
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final aliceDevice =
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final aliceManager = OmemoManager(
@@ -134,7 +136,7 @@ void main() {
},
(jid) async {
expect(jid, bobJid);
return [ bobDevice.id ];
return [bobDevice.id];
},
(jid, id) async {
expect(jid, bobJid);
@@ -184,7 +186,7 @@ void main() {
// Bob acknowledges the message
await aliceManager.ratchetAcknowledged(bobJid, bobDevice.id);
// Alice now sends 52 messages that Bob decrypts
for (var i = 0; i <= 51; i++) {
final aliceResultLoop = await aliceManager.onOutgoingStanza(
@@ -235,7 +237,8 @@ void main() {
test('Test accessing data without it existing', () async {
const aliceJid = 'alice@server1';
const bobJid = 'bob@server2';
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final aliceDevice =
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final aliceManager = OmemoManager(
aliceDevice,
@@ -264,9 +267,12 @@ void main() {
const bobJid = 'bob@server2';
var oldDevice = true;
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final bobOldDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final bobCurrentDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final aliceDevice =
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final bobOldDevice =
await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final bobCurrentDevice =
await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final aliceManager = OmemoManager(
aliceDevice,
@@ -275,15 +281,13 @@ void main() {
(jid) async {
expect(jid, bobJid);
return oldDevice ?
[ bobOldDevice.id ] :
[ bobCurrentDevice.id ];
return oldDevice ? [bobOldDevice.id] : [bobCurrentDevice.id];
},
(jid, id) async {
expect(jid, bobJid);
return oldDevice ?
bobOldDevice.toBundle() :
bobCurrentDevice.toBundle();
return oldDevice
? bobOldDevice.toBundle()
: bobCurrentDevice.toBundle();
},
(jid) async {},
);
@@ -348,9 +352,12 @@ void main() {
const bobJid = 'bob@server2';
var bothDevices = false;
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final bobDevice1 = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final bobDevice2 = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final aliceDevice =
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final bobDevice1 =
await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final bobDevice2 =
await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final aliceManager = OmemoManager(
aliceDevice,
@@ -361,9 +368,7 @@ void main() {
return [
bobDevice1.id,
if (bothDevices)
bobDevice2.id,
if (bothDevices) bobDevice2.id,
];
},
(jid, id) async {
@@ -456,9 +461,12 @@ void main() {
const bobJid = 'bob@server2';
var bothDevices = false;
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final bobDevice1 = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final bobDevice2 = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final aliceDevice =
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final bobDevice1 =
await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final bobDevice2 =
await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final aliceManager = OmemoManager(
aliceDevice,
@@ -469,9 +477,7 @@ void main() {
return [
bobDevice1.id,
if (bothDevices)
bobDevice2.id,
if (bothDevices) bobDevice2.id,
];
},
(jid, id) async {
@@ -532,7 +538,7 @@ void main() {
// Bob acks the ratchet session
await aliceManager.ratchetAcknowledged(bobJid, bobDevice1.id);
// Bob now publishes a new device
bothDevices = true;
aliceManager.onDeviceListUpdate(
@@ -542,7 +548,7 @@ void main() {
bobDevice2.id,
],
);
// Now Alice encrypts another message
final aliceResult2 = await aliceManager.onOutgoingStanza(
const OmemoOutgoingStanza(
@@ -603,9 +609,11 @@ void main() {
const bobJid = 'bob@server2';
const cocoJid = 'coco@server3';
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final aliceDevice =
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final cocoDevice = await OmemoDevice.generateNewDevice(cocoJid, opkAmount: 1);
final cocoDevice =
await OmemoDevice.generateNewDevice(cocoJid, opkAmount: 1);
final aliceManager = OmemoManager(
aliceDevice,
@@ -687,7 +695,8 @@ void main() {
const bobJid = 'bob@server2';
var failure = false;
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final aliceDevice =
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final aliceManager = OmemoManager(
@@ -697,16 +706,12 @@ void main() {
(jid) async {
expect(jid, bobJid);
return failure ?
null :
[bobDevice.id];
return failure ? null : [bobDevice.id];
},
(jid, id) async {
expect(jid, bobJid);
return failure ?
null :
bobDevice.toBundle();
return failure ? null : bobDevice.toBundle();
},
(jid) async {},
);
@@ -778,7 +783,8 @@ void main() {
const aliceJid = 'alice@server1';
const bobJid = 'bob@server2';
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final aliceDevice =
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final aliceManager = OmemoManager(
aliceDevice,
@@ -806,7 +812,10 @@ void main() {
);
expect(aliceResult.isSuccess(1), false);
expect(aliceResult.jidEncryptionErrors[bobJid] is NoKeyMaterialAvailableException, true);
expect(
aliceResult.jidEncryptionErrors[bobJid]
is NoKeyMaterialAvailableException,
true,);
});
test('Test sending a message two two JIDs with failed lookups', () async {
@@ -814,7 +823,8 @@ void main() {
const bobJid = 'bob@server2';
const cocoJid = 'coco@server3';
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final aliceDevice =
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final aliceManager = OmemoManager(
@@ -855,7 +865,10 @@ void main() {
);
expect(aliceResult.isSuccess(2), true);
expect(aliceResult.jidEncryptionErrors[cocoJid] is NoKeyMaterialAvailableException, true);
expect(
aliceResult.jidEncryptionErrors[cocoJid]
is NoKeyMaterialAvailableException,
true,);
// Bob decrypts it
final bobResult = await bobManager.onIncomingStanza(
@@ -875,7 +888,8 @@ void main() {
const aliceJid = 'alice@server1';
const bobJid = 'bob@server2';
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final aliceDevice =
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final aliceManager = OmemoManager(
@@ -920,7 +934,6 @@ void main() {
aliceMessage.encryptedKeys,
base64.encode(aliceMessage.ciphertext!),
),
);
// Ratchets are acked
@@ -928,7 +941,7 @@ void main() {
bobJid,
bobDevice.id,
);
for (var i = 0; i < 100; i++) {
final messageText = 'Test Message #$i';
// Bob responds to Alice
@@ -939,7 +952,7 @@ void main() {
),
);
expect(bobResponseMessage.isSuccess(1), true);
final aliceReceivedMessage = await aliceManager.onIncomingStanza(
OmemoIncomingStanza(
bobJid,
@@ -954,10 +967,11 @@ void main() {
});
test('Test removing all ratchets and sending a message', () async {
const aliceJid = 'alice@server1';
const aliceJid = 'alice@server1';
const bobJid = 'bob@server2';
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final aliceDevice =
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
EncryptionResult? aliceEmptyMessage;
@@ -1038,7 +1052,7 @@ void main() {
bobJid,
await bobManager.getDeviceId(),
);
// Alice sends another message
final aliceResult3 = await aliceManager.onOutgoingStanza(
const OmemoOutgoingStanza(
@@ -1084,14 +1098,17 @@ void main() {
expect(aliceResult4.payload, "That's okay.");
});
test('Test removing all ratchets and sending a message without post-heartbeat ack', () async {
test(
'Test removing all ratchets and sending a message without post-heartbeat ack',
() async {
// This test is the same as "Test removing all ratchets and sending a message" except
// that bob does not ack the ratchet after Alice's heartbeat after she recreated
// all ratchets.
const aliceJid = 'alice@server1';
const bobJid = 'bob@server2';
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final aliceDevice =
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
EncryptionResult? aliceEmptyMessage;
@@ -1216,7 +1233,8 @@ void main() {
const aliceJid = 'alice@server1';
const bobJid = 'bob@server2';
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final aliceDevice =
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final aliceManager = OmemoManager(
@@ -1225,7 +1243,7 @@ void main() {
(result, recipientJid) async {},
(jid) async {
expect(jid, bobJid);
return [ bobDevice.id ];
return [bobDevice.id];
},
(jid, id) async {
expect(jid, bobJid);
@@ -1247,7 +1265,7 @@ void main() {
},
(jid) async {},
);
// Alice sends Bob a message
final aliceResult1 = await aliceManager.onOutgoingStanza(
const OmemoOutgoingStanza(
@@ -1272,7 +1290,7 @@ void main() {
expect(bobResult1.error, null);
expect(bobResult1.payload, 'Hello World!');
// Alice immediately sends another message
// Alice immediately sends another message
final aliceResult2 = await aliceManager.onOutgoingStanza(
const OmemoOutgoingStanza(
[bobJid],
@@ -1327,8 +1345,8 @@ void main() {
),
);
expect(aliceResult3.error, null);
expect(aliceResult3.payload, 'Hello Alice!');
expect(aliceResult3.payload, 'Hello Alice!');
// Bob now acks the ratchet
await aliceManager.ratchetAcknowledged(
bobJid,

View File

@@ -76,7 +76,7 @@ void main() {
..dhPub = <int>[1, 2, 3];
final serial = pbMessage.writeToBuffer();
final msg = OmemoMessage.fromBuffer(serial);
expect(msg.n, 1);
expect(msg.pn, 5);
expect(msg.dhPub, <int>[1, 2, 3]);
@@ -90,7 +90,7 @@ void main() {
..ciphertext = <int>[4, 5, 6];
final serial = m.writeToBuffer();
final msg = OMEMOMessage.fromBuffer(serial);
expect(msg.n, 1);
expect(msg.pn, 5);
expect(msg.dhPub, <int>[1, 2, 3]);
@@ -169,7 +169,7 @@ void main() {
expect(decoded.pkId, 698);
expect(decoded.spkId, 245);
expect(decoded.ik, <int>[1, 4, 6]);
expect(decoded.ek, <int>[4 ,6 ,7 , 80]);
expect(decoded.ek, <int>[4, 6, 7, 80]);
expect(decoded.message!.mac, <int>[5, 6, 8, 0]);
expect(decoded.message!.message, <int>[4, 5, 7, 3, 2]);

View File

@@ -22,20 +22,22 @@ void main() {
expect(await oldDevice.equals(newDevice), true);
});
test('Test serialising and deserialising the Device after rotating the SPK', () async {
test('Test serialising and deserialising the Device after rotating the SPK',
() async {
// Generate a random session
final oldSession = await OmemoSessionManager.generateNewIdentity(
'user@test.server',
AlwaysTrustingTrustManager(),
opkAmount: 1,
);
final oldDevice = await (await oldSession.getDevice()).replaceSignedPrekey();
final oldDevice =
await (await oldSession.getDevice()).replaceSignedPrekey();
final serialised = jsonify(await oldDevice.toJson());
final newDevice = OmemoDevice.fromJson(serialised);
expect(await oldDevice.equals(newDevice), true);
});
test('Test serialising and deserialising the OmemoDoubleRatchet', () async {
// Generate a random ratchet
const aliceJid = 'alice@server.example';
@@ -64,7 +66,8 @@ void main() {
aliceMessage.encryptedKeys,
getTimestamp(),
);
final aliceOld = aliceSession.getRatchet(bobJid, await bobSession.getDeviceId());
final aliceOld =
aliceSession.getRatchet(bobJid, await bobSession.getDeviceId());
final aliceSerialised = jsonify(await aliceOld.toJson());
final aliceNew = OmemoDoubleRatchet.fromJson(aliceSerialised);
@@ -116,13 +119,14 @@ void main() {
expect(result2.deviceId, test2.deviceId);
});
test('Test serializing and deserializing the components of the BTBV manager', () async {
test('Test serializing and deserializing the components of the BTBV manager',
() async {
// Caroline's BTBV manager
final btbv = MemoryBTBVTrustManager();
// Example data
const aliceJid = 'alice@some.server';
const bobJid = 'bob@other.server';
await btbv.onNewSession(aliceJid, 1);
await btbv.setDeviceTrust(aliceJid, 1, BTBVTrustState.verified);
await btbv.onNewSession(aliceJid, 2);
@@ -130,17 +134,20 @@ void main() {
await btbv.onNewSession(bobJid, 4);
final serialized = jsonify(await btbv.toJson());
final deviceList = BlindTrustBeforeVerificationTrustManager.deviceListFromJson(
final deviceList =
BlindTrustBeforeVerificationTrustManager.deviceListFromJson(
serialized,
);
expect(btbv.devices, deviceList);
final trustCache = BlindTrustBeforeVerificationTrustManager.trustCacheFromJson(
final trustCache =
BlindTrustBeforeVerificationTrustManager.trustCacheFromJson(
serialized,
);
expect(btbv.trustCache, trustCache);
final enableCache = BlindTrustBeforeVerificationTrustManager.enableCacheFromJson(
final enableCache =
BlindTrustBeforeVerificationTrustManager.enableCacheFromJson(
serialized,
);
expect(btbv.enablementCache, enableCache);

View File

@@ -8,7 +8,7 @@ void main() {
// Example data
const aliceJid = 'alice@some.server';
const bobJid = 'bob@other.server';
// Caroline starts a chat a device from Alice
await btbv.onNewSession(aliceJid, 1);
expect(await btbv.isTrusted(aliceJid, 1), true);

View File

@@ -24,13 +24,13 @@ void main() {
2: await opkBob.pk.asBase64(),
},
);
// Alice does X3DH
final resultAlice = await x3dhFromBundle(bundleBob, ikAlice);
// Alice sends the inital message to Bob
// ...
// Bob does X3DH
final resultBob = await x3dhFromInitialMessage(
X3DHMessage(
@@ -42,7 +42,7 @@ void main() {
opkBob,
ikBob,
);
expect(resultAlice.sk, resultBob.sk);
expect(resultAlice.ad, resultBob.ad);
});
@@ -66,14 +66,15 @@ void main() {
2: await opkBob.pk.asBase64(),
},
);
// Alice does X3DH
var exception = false;
try {
await x3dhFromBundle(bundleBob, ikAlice);
} catch(e) {
} catch (e) {
exception = true;
expect(e is InvalidSignatureException, true, reason: 'Expected InvalidSignatureException, but got $e');
expect(e is InvalidSignatureException, true,
reason: 'Expected InvalidSignatureException, but got $e',);
}
expect(exception, true, reason: 'Expected test failure');