diff options
author | Moxie Marlinspike <moxie@thoughtcrime.org> | 2015-03-03 11:20:36 -0800 |
---|---|---|
committer | Moxie Marlinspike <moxie@thoughtcrime.org> | 2015-03-03 11:20:36 -0800 |
commit | 327f82be41058ca1eaf1b501dc91426f8555d892 (patch) | |
tree | 5419b592ced22f595de3423bc72c007ab1c4836a /tests/src/test/java/org/whispersystems/libaxolotl/SessionBuilderTest.java | |
parent | d53ed1bb0037ac8ea9717844ae4ab71e5fb75563 (diff) |
Use more generic AxololAddress for identifying recipients.
Diffstat (limited to '')
-rw-r--r-- | tests/src/test/java/org/whispersystems/libaxolotl/SessionBuilderTest.java | 104 |
1 files changed, 52 insertions, 52 deletions
diff --git a/tests/src/test/java/org/whispersystems/libaxolotl/SessionBuilderTest.java b/tests/src/test/java/org/whispersystems/libaxolotl/SessionBuilderTest.java index 0912493e..539131f0 100644 --- a/tests/src/test/java/org/whispersystems/libaxolotl/SessionBuilderTest.java +++ b/tests/src/test/java/org/whispersystems/libaxolotl/SessionBuilderTest.java @@ -20,13 +20,13 @@ import java.util.Set; public class SessionBuilderTest extends TestCase { - private static final long ALICE_RECIPIENT_ID = 5L; - private static final long BOB_RECIPIENT_ID = 2L; + private static final AxolotlAddress ALICE_ADDRESS = new AxolotlAddress("+14151111111", 1); + private static final AxolotlAddress BOB_ADDRESS = new AxolotlAddress("+14152222222", 1); public void testBasicPreKeyV2() throws InvalidKeyException, InvalidVersionException, InvalidMessageException, InvalidKeyIdException, DuplicateMessageException, LegacyMessageException, UntrustedIdentityException, NoSessionException { AxolotlStore aliceStore = new InMemoryAxolotlStore(); - SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_RECIPIENT_ID, 1); + SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_ADDRESS); AxolotlStore bobStore = new InMemoryAxolotlStore(); ECKeyPair bobPreKeyPair = Curve.generateKeyPair(); @@ -37,11 +37,11 @@ public class SessionBuilderTest extends TestCase { aliceSessionBuilder.process(bobPreKey); - assertTrue(aliceStore.containsSession(BOB_RECIPIENT_ID, 1)); - assertTrue(aliceStore.loadSession(BOB_RECIPIENT_ID, 1).getSessionState().getSessionVersion() == 2); + assertTrue(aliceStore.containsSession(BOB_ADDRESS)); + assertTrue(aliceStore.loadSession(BOB_ADDRESS).getSessionState().getSessionVersion() == 2); String originalMessage = "L'homme est condamné à être libre"; - SessionCipher aliceSessionCipher = new SessionCipher(aliceStore, BOB_RECIPIENT_ID, 1); + SessionCipher aliceSessionCipher = new SessionCipher(aliceStore, BOB_ADDRESS); CiphertextMessage outgoingMessage = aliceSessionCipher.encrypt(originalMessage.getBytes()); assertTrue(outgoingMessage.getType() == CiphertextMessage.PREKEY_TYPE); @@ -49,11 +49,11 @@ public class SessionBuilderTest extends TestCase { PreKeyWhisperMessage incomingMessage = new PreKeyWhisperMessage(outgoingMessage.serialize()); bobStore.storePreKey(31337, new PreKeyRecord(bobPreKey.getPreKeyId(), bobPreKeyPair)); - SessionCipher bobSessionCipher = new SessionCipher(bobStore, ALICE_RECIPIENT_ID, 1); + SessionCipher bobSessionCipher = new SessionCipher(bobStore, ALICE_ADDRESS); byte[] plaintext = bobSessionCipher.decrypt(incomingMessage); - assertTrue(bobStore.containsSession(ALICE_RECIPIENT_ID, 1)); - assertTrue(bobStore.loadSession(ALICE_RECIPIENT_ID, 1).getSessionState().getSessionVersion() == 2); + assertTrue(bobStore.containsSession(ALICE_ADDRESS)); + assertTrue(bobStore.loadSession(ALICE_ADDRESS).getSessionState().getSessionVersion() == 2); assertTrue(originalMessage.equals(new String(plaintext))); CiphertextMessage bobOutgoingMessage = bobSessionCipher.encrypt(originalMessage.getBytes()); @@ -65,8 +65,8 @@ public class SessionBuilderTest extends TestCase { runInteraction(aliceStore, bobStore); aliceStore = new InMemoryAxolotlStore(); - aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_RECIPIENT_ID, 1); - aliceSessionCipher = new SessionCipher(aliceStore, BOB_RECIPIENT_ID, 1); + aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_ADDRESS); + aliceSessionCipher = new SessionCipher(aliceStore, BOB_ADDRESS); bobPreKeyPair = Curve.generateKeyPair(); bobPreKey = new PreKeyBundle(bobStore.getLocalRegistrationId(), @@ -82,7 +82,7 @@ public class SessionBuilderTest extends TestCase { bobSessionCipher.decrypt(new PreKeyWhisperMessage(outgoingMessage.serialize())); throw new AssertionError("shouldn't be trusted!"); } catch (UntrustedIdentityException uie) { - bobStore.saveIdentity(ALICE_RECIPIENT_ID, new PreKeyWhisperMessage(outgoingMessage.serialize()).getIdentityKey()); + bobStore.saveIdentity(ALICE_ADDRESS.getName(), new PreKeyWhisperMessage(outgoingMessage.serialize()).getIdentityKey()); } plaintext = bobSessionCipher.decrypt(new PreKeyWhisperMessage(outgoingMessage.serialize())); @@ -105,7 +105,7 @@ public class SessionBuilderTest extends TestCase { public void testBasicPreKeyV3() throws InvalidKeyException, InvalidVersionException, InvalidMessageException, InvalidKeyIdException, DuplicateMessageException, LegacyMessageException, UntrustedIdentityException, NoSessionException { AxolotlStore aliceStore = new InMemoryAxolotlStore(); - SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_RECIPIENT_ID, 1); + SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_ADDRESS); final AxolotlStore bobStore = new InMemoryAxolotlStore(); ECKeyPair bobPreKeyPair = Curve.generateKeyPair(); @@ -121,11 +121,11 @@ public class SessionBuilderTest extends TestCase { aliceSessionBuilder.process(bobPreKey); - assertTrue(aliceStore.containsSession(BOB_RECIPIENT_ID, 1)); - assertTrue(aliceStore.loadSession(BOB_RECIPIENT_ID, 1).getSessionState().getSessionVersion() == 3); + assertTrue(aliceStore.containsSession(BOB_ADDRESS)); + assertTrue(aliceStore.loadSession(BOB_ADDRESS).getSessionState().getSessionVersion() == 3); final String originalMessage = "L'homme est condamné à être libre"; - SessionCipher aliceSessionCipher = new SessionCipher(aliceStore, BOB_RECIPIENT_ID, 1); + SessionCipher aliceSessionCipher = new SessionCipher(aliceStore, BOB_ADDRESS); CiphertextMessage outgoingMessage = aliceSessionCipher.encrypt(originalMessage.getBytes()); assertTrue(outgoingMessage.getType() == CiphertextMessage.PREKEY_TYPE); @@ -134,18 +134,18 @@ public class SessionBuilderTest extends TestCase { bobStore.storePreKey(31337, new PreKeyRecord(bobPreKey.getPreKeyId(), bobPreKeyPair)); bobStore.storeSignedPreKey(22, new SignedPreKeyRecord(22, System.currentTimeMillis(), bobSignedPreKeyPair, bobSignedPreKeySignature)); - SessionCipher bobSessionCipher = new SessionCipher(bobStore, ALICE_RECIPIENT_ID, 1); + SessionCipher bobSessionCipher = new SessionCipher(bobStore, ALICE_ADDRESS); byte[] plaintext = bobSessionCipher.decrypt(incomingMessage, new SessionCipher.DecryptionCallback() { @Override public void handlePlaintext(byte[] plaintext) { assertTrue(originalMessage.equals(new String(plaintext))); - assertFalse(bobStore.containsSession(ALICE_RECIPIENT_ID, 1)); + assertFalse(bobStore.containsSession(ALICE_ADDRESS)); } }); - assertTrue(bobStore.containsSession(ALICE_RECIPIENT_ID, 1)); - assertTrue(bobStore.loadSession(ALICE_RECIPIENT_ID, 1).getSessionState().getSessionVersion() == 3); - assertTrue(bobStore.loadSession(ALICE_RECIPIENT_ID, 1).getSessionState().getAliceBaseKey() != null); + assertTrue(bobStore.containsSession(ALICE_ADDRESS)); + assertTrue(bobStore.loadSession(ALICE_ADDRESS).getSessionState().getSessionVersion() == 3); + assertTrue(bobStore.loadSession(ALICE_ADDRESS).getSessionState().getAliceBaseKey() != null); assertTrue(originalMessage.equals(new String(plaintext))); CiphertextMessage bobOutgoingMessage = bobSessionCipher.encrypt(originalMessage.getBytes()); @@ -157,8 +157,8 @@ public class SessionBuilderTest extends TestCase { runInteraction(aliceStore, bobStore); aliceStore = new InMemoryAxolotlStore(); - aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_RECIPIENT_ID, 1); - aliceSessionCipher = new SessionCipher(aliceStore, BOB_RECIPIENT_ID, 1); + aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_ADDRESS); + aliceSessionCipher = new SessionCipher(aliceStore, BOB_ADDRESS); bobPreKeyPair = Curve.generateKeyPair(); bobSignedPreKeyPair = Curve.generateKeyPair(); @@ -178,7 +178,7 @@ public class SessionBuilderTest extends TestCase { plaintext = bobSessionCipher.decrypt(new PreKeyWhisperMessage(outgoingMessage.serialize())); throw new AssertionError("shouldn't be trusted!"); } catch (UntrustedIdentityException uie) { - bobStore.saveIdentity(ALICE_RECIPIENT_ID, new PreKeyWhisperMessage(outgoingMessage.serialize()).getIdentityKey()); + bobStore.saveIdentity(ALICE_ADDRESS.getName(), new PreKeyWhisperMessage(outgoingMessage.serialize()).getIdentityKey()); } plaintext = bobSessionCipher.decrypt(new PreKeyWhisperMessage(outgoingMessage.serialize())); @@ -199,7 +199,7 @@ public class SessionBuilderTest extends TestCase { public void testBadSignedPreKeySignature() throws InvalidKeyException, UntrustedIdentityException { AxolotlStore aliceStore = new InMemoryAxolotlStore(); - SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_RECIPIENT_ID, 1); + SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_ADDRESS); IdentityKeyStore bobIdentityKeyStore = new InMemoryIdentityKeyStore(); @@ -238,7 +238,7 @@ public class SessionBuilderTest extends TestCase { public void testRepeatBundleMessageV2() throws InvalidKeyException, UntrustedIdentityException, InvalidVersionException, InvalidMessageException, InvalidKeyIdException, DuplicateMessageException, LegacyMessageException, NoSessionException { AxolotlStore aliceStore = new InMemoryAxolotlStore(); - SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_RECIPIENT_ID, 1); + SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_ADDRESS); AxolotlStore bobStore = new InMemoryAxolotlStore(); @@ -258,7 +258,7 @@ public class SessionBuilderTest extends TestCase { aliceSessionBuilder.process(bobPreKey); String originalMessage = "L'homme est condamné à être libre"; - SessionCipher aliceSessionCipher = new SessionCipher(aliceStore, BOB_RECIPIENT_ID, 1); + SessionCipher aliceSessionCipher = new SessionCipher(aliceStore, BOB_ADDRESS); CiphertextMessage outgoingMessageOne = aliceSessionCipher.encrypt(originalMessage.getBytes()); CiphertextMessage outgoingMessageTwo = aliceSessionCipher.encrypt(originalMessage.getBytes()); @@ -266,7 +266,7 @@ public class SessionBuilderTest extends TestCase { PreKeyWhisperMessage incomingMessage = new PreKeyWhisperMessage(outgoingMessageOne.serialize()); - SessionCipher bobSessionCipher = new SessionCipher(bobStore, ALICE_RECIPIENT_ID, 1); + SessionCipher bobSessionCipher = new SessionCipher(bobStore, ALICE_ADDRESS); byte[] plaintext = bobSessionCipher.decrypt(incomingMessage); assertTrue(originalMessage.equals(new String(plaintext))); @@ -291,7 +291,7 @@ public class SessionBuilderTest extends TestCase { public void testRepeatBundleMessageV3() throws InvalidKeyException, UntrustedIdentityException, InvalidVersionException, InvalidMessageException, InvalidKeyIdException, DuplicateMessageException, LegacyMessageException, NoSessionException { AxolotlStore aliceStore = new InMemoryAxolotlStore(); - SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_RECIPIENT_ID, 1); + SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_ADDRESS); AxolotlStore bobStore = new InMemoryAxolotlStore(); @@ -311,7 +311,7 @@ public class SessionBuilderTest extends TestCase { aliceSessionBuilder.process(bobPreKey); String originalMessage = "L'homme est condamné à être libre"; - SessionCipher aliceSessionCipher = new SessionCipher(aliceStore, BOB_RECIPIENT_ID, 1); + SessionCipher aliceSessionCipher = new SessionCipher(aliceStore, BOB_ADDRESS); CiphertextMessage outgoingMessageOne = aliceSessionCipher.encrypt(originalMessage.getBytes()); CiphertextMessage outgoingMessageTwo = aliceSessionCipher.encrypt(originalMessage.getBytes()); @@ -320,7 +320,7 @@ public class SessionBuilderTest extends TestCase { PreKeyWhisperMessage incomingMessage = new PreKeyWhisperMessage(outgoingMessageOne.serialize()); - SessionCipher bobSessionCipher = new SessionCipher(bobStore, ALICE_RECIPIENT_ID, 1); + SessionCipher bobSessionCipher = new SessionCipher(bobStore, ALICE_ADDRESS); byte[] plaintext = bobSessionCipher.decrypt(incomingMessage); assertTrue(originalMessage.equals(new String(plaintext))); @@ -345,7 +345,7 @@ public class SessionBuilderTest extends TestCase { public void testBadMessageBundle() throws InvalidKeyException, UntrustedIdentityException, InvalidVersionException, InvalidMessageException, DuplicateMessageException, LegacyMessageException, InvalidKeyIdException { AxolotlStore aliceStore = new InMemoryAxolotlStore(); - SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_RECIPIENT_ID, 1); + SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_ADDRESS); AxolotlStore bobStore = new InMemoryAxolotlStore(); @@ -365,7 +365,7 @@ public class SessionBuilderTest extends TestCase { aliceSessionBuilder.process(bobPreKey); String originalMessage = "L'homme est condamné à être libre"; - SessionCipher aliceSessionCipher = new SessionCipher(aliceStore, BOB_RECIPIENT_ID, 1); + SessionCipher aliceSessionCipher = new SessionCipher(aliceStore, BOB_ADDRESS); CiphertextMessage outgoingMessageOne = aliceSessionCipher.encrypt(originalMessage.getBytes()); assertTrue(outgoingMessageOne.getType() == CiphertextMessage.PREKEY_TYPE); @@ -377,7 +377,7 @@ public class SessionBuilderTest extends TestCase { badMessage[badMessage.length-10] ^= 0x01; PreKeyWhisperMessage incomingMessage = new PreKeyWhisperMessage(badMessage); - SessionCipher bobSessionCipher = new SessionCipher(bobStore, ALICE_RECIPIENT_ID, 1); + SessionCipher bobSessionCipher = new SessionCipher(bobStore, ALICE_ADDRESS); byte[] plaintext = new byte[0]; @@ -398,10 +398,10 @@ public class SessionBuilderTest extends TestCase { public void testBasicKeyExchange() throws InvalidKeyException, LegacyMessageException, InvalidMessageException, DuplicateMessageException, UntrustedIdentityException, StaleKeyExchangeException, InvalidVersionException, NoSessionException { AxolotlStore aliceStore = new InMemoryAxolotlStore(); - SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_RECIPIENT_ID, 1); + SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_ADDRESS); AxolotlStore bobStore = new InMemoryAxolotlStore(); - SessionBuilder bobSessionBuilder = new SessionBuilder(bobStore, ALICE_RECIPIENT_ID, 1); + SessionBuilder bobSessionBuilder = new SessionBuilder(bobStore, ALICE_ADDRESS); KeyExchangeMessage aliceKeyExchangeMessage = aliceSessionBuilder.process(); assertTrue(aliceKeyExchangeMessage != null); @@ -415,20 +415,20 @@ public class SessionBuilderTest extends TestCase { KeyExchangeMessage response = aliceSessionBuilder.process(new KeyExchangeMessage(bobKeyExchangeMessageBytes)); assertTrue(response == null); - assertTrue(aliceStore.containsSession(BOB_RECIPIENT_ID, 1)); - assertTrue(bobStore.containsSession(ALICE_RECIPIENT_ID, 1)); + assertTrue(aliceStore.containsSession(BOB_ADDRESS)); + assertTrue(bobStore.containsSession(ALICE_ADDRESS)); runInteraction(aliceStore, bobStore); aliceStore = new InMemoryAxolotlStore(); - aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_RECIPIENT_ID, 1); + aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_ADDRESS); aliceKeyExchangeMessage = aliceSessionBuilder.process(); try { bobKeyExchangeMessage = bobSessionBuilder.process(aliceKeyExchangeMessage); throw new AssertionError("This identity shouldn't be trusted!"); } catch (UntrustedIdentityException uie) { - bobStore.saveIdentity(ALICE_RECIPIENT_ID, aliceKeyExchangeMessage.getIdentityKey()); + bobStore.saveIdentity(ALICE_ADDRESS.getName(), aliceKeyExchangeMessage.getIdentityKey()); bobKeyExchangeMessage = bobSessionBuilder.process(aliceKeyExchangeMessage); } @@ -440,10 +440,10 @@ public class SessionBuilderTest extends TestCase { public void testSimultaneousKeyExchange() throws InvalidKeyException, DuplicateMessageException, LegacyMessageException, InvalidMessageException, UntrustedIdentityException, StaleKeyExchangeException, NoSessionException { AxolotlStore aliceStore = new InMemoryAxolotlStore(); - SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_RECIPIENT_ID, 1); + SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_ADDRESS); AxolotlStore bobStore = new InMemoryAxolotlStore(); - SessionBuilder bobSessionBuilder = new SessionBuilder(bobStore, ALICE_RECIPIENT_ID, 1); + SessionBuilder bobSessionBuilder = new SessionBuilder(bobStore, ALICE_ADDRESS); KeyExchangeMessage aliceKeyExchange = aliceSessionBuilder.process(); KeyExchangeMessage bobKeyExchange = bobSessionBuilder.process(); @@ -468,7 +468,7 @@ public class SessionBuilderTest extends TestCase { public void testOptionalOneTimePreKey() throws Exception { AxolotlStore aliceStore = new InMemoryAxolotlStore(); - SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_RECIPIENT_ID, 1); + SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_ADDRESS); AxolotlStore bobStore = new InMemoryAxolotlStore(); @@ -485,11 +485,11 @@ public class SessionBuilderTest extends TestCase { aliceSessionBuilder.process(bobPreKey); - assertTrue(aliceStore.containsSession(BOB_RECIPIENT_ID, 1)); - assertTrue(aliceStore.loadSession(BOB_RECIPIENT_ID, 1).getSessionState().getSessionVersion() == 3); + assertTrue(aliceStore.containsSession(BOB_ADDRESS)); + assertTrue(aliceStore.loadSession(BOB_ADDRESS).getSessionState().getSessionVersion() == 3); String originalMessage = "L'homme est condamné à être libre"; - SessionCipher aliceSessionCipher = new SessionCipher(aliceStore, BOB_RECIPIENT_ID, 1); + SessionCipher aliceSessionCipher = new SessionCipher(aliceStore, BOB_ADDRESS); CiphertextMessage outgoingMessage = aliceSessionCipher.encrypt(originalMessage.getBytes()); assertTrue(outgoingMessage.getType() == CiphertextMessage.PREKEY_TYPE); @@ -500,12 +500,12 @@ public class SessionBuilderTest extends TestCase { bobStore.storePreKey(31337, new PreKeyRecord(bobPreKey.getPreKeyId(), bobPreKeyPair)); bobStore.storeSignedPreKey(22, new SignedPreKeyRecord(22, System.currentTimeMillis(), bobSignedPreKeyPair, bobSignedPreKeySignature)); - SessionCipher bobSessionCipher = new SessionCipher(bobStore, ALICE_RECIPIENT_ID, 1); + SessionCipher bobSessionCipher = new SessionCipher(bobStore, ALICE_ADDRESS); byte[] plaintext = bobSessionCipher.decrypt(incomingMessage); - assertTrue(bobStore.containsSession(ALICE_RECIPIENT_ID, 1)); - assertTrue(bobStore.loadSession(ALICE_RECIPIENT_ID, 1).getSessionState().getSessionVersion() == 3); - assertTrue(bobStore.loadSession(ALICE_RECIPIENT_ID, 1).getSessionState().getAliceBaseKey() != null); + assertTrue(bobStore.containsSession(ALICE_ADDRESS)); + assertTrue(bobStore.loadSession(ALICE_ADDRESS).getSessionState().getSessionVersion() == 3); + assertTrue(bobStore.loadSession(ALICE_ADDRESS).getSessionState().getAliceBaseKey() != null); assertTrue(originalMessage.equals(new String(plaintext))); } @@ -513,8 +513,8 @@ public class SessionBuilderTest extends TestCase { private void runInteraction(AxolotlStore aliceStore, AxolotlStore bobStore) throws DuplicateMessageException, LegacyMessageException, InvalidMessageException, NoSessionException { - SessionCipher aliceSessionCipher = new SessionCipher(aliceStore, BOB_RECIPIENT_ID, 1); - SessionCipher bobSessionCipher = new SessionCipher(bobStore, ALICE_RECIPIENT_ID, 1); + SessionCipher aliceSessionCipher = new SessionCipher(aliceStore, BOB_ADDRESS); + SessionCipher bobSessionCipher = new SessionCipher(bobStore, ALICE_ADDRESS); String originalMessage = "smert ze smert"; CiphertextMessage aliceMessage = aliceSessionCipher.encrypt(originalMessage.getBytes()); |