test: Test 100 rounds of messages between the two ratchets

This commit is contained in:
PapaTutuWawa 2022-08-03 16:32:39 +02:00
parent 2fc2623092
commit 37155d2a87

View File

@ -74,7 +74,9 @@ 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(
spkBob.pk,
resultAlice.sk,
@ -87,38 +89,43 @@ void main() {
);
expect(alicesRatchet.sessionAd, bobsRatchet.sessionAd);
//expect(await alicesRatchet.dhr.getBytes(), await ikBob.pk.getBytes());
for (var i = 0; i < 100; i++) {
final messageText = 'Hello, dear $i';
if (i % 2 == 0) {
// Alice encrypts a message
final aliceRatchetResult1 = await alicesRatchet.ratchetEncrypt(utf8.encode('Hello Bob'));
final aliceRatchetResult = await alicesRatchet.ratchetEncrypt(utf8.encode(messageText));
print('Alice sent the message');
// Alice sends it to Bob
// ...
// Bob tries to decrypt it
final bobRatchetResult1 = await bobsRatchet.ratchetDecrypt(
aliceRatchetResult1.header,
aliceRatchetResult1.ciphertext,
final bobRatchetResult = await bobsRatchet.ratchetDecrypt(
aliceRatchetResult.header,
aliceRatchetResult.ciphertext,
);
print('Bob decrypted the message');
expect(utf8.encode('Hello Bob'), bobRatchetResult1);
expect(utf8.encode(messageText), bobRatchetResult);
} else {
// Bob sends a message to Alice
final bobRatchetResult2 = await bobsRatchet.ratchetEncrypt(utf8.encode('Hello Alice'));
final bobRatchetResult = await bobsRatchet.ratchetEncrypt(utf8.encode(messageText));
print('Bob sent the message');
// Bobs sends it to Alice
// ...
// Alice tries to decrypt it
final aliceRatchetResult2 = await alicesRatchet.ratchetDecrypt(
bobRatchetResult2.header,
bobRatchetResult2.ciphertext,
final aliceRatchetResult = await alicesRatchet.ratchetDecrypt(
bobRatchetResult.header,
bobRatchetResult.ciphertext,
);
print('Alice decrypted the message');
expect(utf8.encode('Hello Alice'), aliceRatchetResult2);
expect(utf8.encode(messageText), aliceRatchetResult);
}
}
});
}