mirror of
https://github.com/signalapp/libsignal.git
synced 2024-09-20 20:03:07 +02:00
Add a test that decryption works after you archive a session state
This commit is contained in:
parent
e8b4474cb9
commit
0184984db5
@ -71,6 +71,37 @@ public class SessionCipherTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testDecryptAfterReset() throws Exception {
|
||||
PairOfSessions sessions = initializeSessionsV3();
|
||||
|
||||
SignalProtocolStore aliceStore = new TestInMemorySignalProtocolStore();
|
||||
SignalProtocolStore bobStore = new TestInMemorySignalProtocolStore();
|
||||
|
||||
SignalProtocolAddress aliceAddress = new SignalProtocolAddress("+14159999999", 1);
|
||||
SignalProtocolAddress bobAddress = new SignalProtocolAddress("+141588888888", 1);
|
||||
|
||||
aliceStore.storeSession(bobAddress, sessions.aliceSession);
|
||||
bobStore.storeSession(aliceAddress, sessions.bobSession);
|
||||
|
||||
SessionCipher aliceCipher = new SessionCipher(aliceStore, bobAddress);
|
||||
SessionCipher bobCipher = new SessionCipher(bobStore, aliceAddress);
|
||||
|
||||
byte[] alicePlaintext = "This is a plaintext message.".getBytes();
|
||||
CiphertextMessage message = aliceCipher.encrypt(alicePlaintext);
|
||||
byte[] bobPlaintext = bobCipher.decrypt(new SignalMessage(message.serialize()));
|
||||
|
||||
assertTrue(Arrays.equals(alicePlaintext, bobPlaintext));
|
||||
|
||||
CiphertextMessage message2 = aliceCipher.encrypt(alicePlaintext);
|
||||
|
||||
SessionRecord bobSession = bobStore.loadSession(aliceAddress);
|
||||
bobSession.archiveCurrentState();
|
||||
bobStore.storeSession(aliceAddress, bobSession);
|
||||
|
||||
byte[] bobPlaintext2 = bobCipher.decrypt(new SignalMessage(message2.serialize()));
|
||||
assertTrue(Arrays.equals(alicePlaintext, bobPlaintext2));
|
||||
}
|
||||
|
||||
private void runInteraction(SessionRecord aliceSessionRecord, SessionRecord bobSessionRecord)
|
||||
throws DuplicateMessageException, LegacyMessageException, InvalidMessageException, NoSuchAlgorithmException, NoSessionException, UntrustedIdentityException {
|
||||
SignalProtocolStore aliceStore = new TestInMemorySignalProtocolStore();
|
||||
|
Loading…
Reference in New Issue
Block a user