aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/test
diff options
context:
space:
mode:
authorMoxie Marlinspike <moxie@thoughtcrime.org>2015-03-17 10:57:31 -0700
committerMoxie Marlinspike <moxie@thoughtcrime.org>2015-03-17 10:57:31 -0700
commitbf9c8708e0dc961e01d8901cfd8b290cf0947703 (patch)
treea740b83cf6db615b05c96e3661692ed06031efeb /tests/src/test
parentaa1c41c98075316e691b271e2d5d43d7e18872ae (diff)
Make it possible to deserialize SenderKeyDistributionMessages
Diffstat (limited to 'tests/src/test')
-rw-r--r--tests/src/test/java/org/whispersystems/libaxolotl/groups/GroupCipherTest.java46
1 files changed, 41 insertions, 5 deletions
diff --git a/tests/src/test/java/org/whispersystems/libaxolotl/groups/GroupCipherTest.java b/tests/src/test/java/org/whispersystems/libaxolotl/groups/GroupCipherTest.java
index dd5a306f..32fcc652 100644
--- a/tests/src/test/java/org/whispersystems/libaxolotl/groups/GroupCipherTest.java
+++ b/tests/src/test/java/org/whispersystems/libaxolotl/groups/GroupCipherTest.java
@@ -30,9 +30,9 @@ public class GroupCipherTest extends TestCase {
GroupCipher aliceGroupCipher = new GroupCipher(aliceStore, GROUP_SENDER);
GroupCipher bobGroupCipher = new GroupCipher(bobStore, GROUP_SENDER);
- SenderKeyDistributionMessage aliceDistributionMessage = aliceSessionBuilder.create(GROUP_SENDER);
-
- bobSessionBuilder.process(GROUP_SENDER, aliceDistributionMessage);
+ SenderKeyDistributionMessage sentAliceDistributionMessage = aliceSessionBuilder.create(GROUP_SENDER);
+ SenderKeyDistributionMessage receivedAliceDistributionMessage = new SenderKeyDistributionMessage(sentAliceDistributionMessage.serialize());
+ bobSessionBuilder.process(GROUP_SENDER, receivedAliceDistributionMessage);
byte[] ciphertextFromAlice = aliceGroupCipher.encrypt("smert ze smert".getBytes());
byte[] plaintextFromAlice = bobGroupCipher.decrypt(ciphertextFromAlice);
@@ -54,10 +54,12 @@ public class GroupCipherTest extends TestCase {
GroupCipher aliceGroupCipher = new GroupCipher(aliceStore, aliceName);
GroupCipher bobGroupCipher = new GroupCipher(bobStore, aliceName);
- SenderKeyDistributionMessage aliceDistributionMessage =
+ SenderKeyDistributionMessage sentAliceDistributionMessage =
aliceSessionBuilder.create(aliceName);
+ SenderKeyDistributionMessage receivedAliceDistributionMessage =
+ new SenderKeyDistributionMessage(sentAliceDistributionMessage.serialize());
- bobSessionBuilder.process(aliceName, aliceDistributionMessage);
+ bobSessionBuilder.process(aliceName, receivedAliceDistributionMessage);
byte[] ciphertextFromAlice = aliceGroupCipher.encrypt("smert ze smert".getBytes());
byte[] ciphertextFromAlice2 = aliceGroupCipher.encrypt("smert ze smert2".getBytes());
@@ -80,6 +82,40 @@ public class GroupCipherTest extends TestCase {
assertTrue(new String(plaintextFromAlice3).equals("smert ze smert3"));
}
+ public void testLateJoin() throws NoSessionException, InvalidMessageException, LegacyMessageException, DuplicateMessageException {
+ InMemorySenderKeyStore aliceStore = new InMemorySenderKeyStore();
+ InMemorySenderKeyStore bobStore = new InMemorySenderKeyStore();
+
+ GroupSessionBuilder aliceSessionBuilder = new GroupSessionBuilder(aliceStore);
+
+
+ SenderKeyName aliceName = GROUP_SENDER;
+
+ GroupCipher aliceGroupCipher = new GroupCipher(aliceStore, aliceName);
+
+
+ SenderKeyDistributionMessage aliceDistributionMessage = aliceSessionBuilder.create(aliceName);
+ // Send off to some people.
+
+ for (int i=0;i<100;i++) {
+ aliceGroupCipher.encrypt("up the punks up the punks up the punks".getBytes());
+ }
+
+ // Now Bob Joins.
+ GroupSessionBuilder bobSessionBuilder = new GroupSessionBuilder(bobStore);
+ GroupCipher bobGroupCipher = new GroupCipher(bobStore, aliceName);
+
+
+ SenderKeyDistributionMessage distributionMessageToBob = aliceSessionBuilder.create(aliceName);
+ bobSessionBuilder.process(aliceName, new SenderKeyDistributionMessage(distributionMessageToBob.serialize()));
+
+ byte[] ciphertext = aliceGroupCipher.encrypt("welcome to the group".getBytes());
+ byte[] plaintext = bobGroupCipher.decrypt(ciphertext);
+
+ assertEquals(new String(plaintext), "welcome to the group");
+ }
+
+
public void testOutOfOrder()
throws LegacyMessageException, DuplicateMessageException, InvalidMessageException, NoSessionException
{