mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-11 18:31:51 +00:00
Simplify/clarify internal interfaces and introduce optional types.
This commit is contained in:
@@ -426,23 +426,23 @@ public class SessionBuilderTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
public void testBadVerificationTagV3() throws InvalidKeyException, UntrustedIdentityException, InvalidVersionException, InvalidMessageException, InvalidKeyIdException, DuplicateMessageException, LegacyMessageException {
|
||||
SessionStore aliceSessionStore = new InMemorySessionStore();
|
||||
SessionStore aliceSessionStore = new InMemorySessionStore();
|
||||
SignedPreKeyStore aliceSignedPreKeyStore = new InMemorySignedPreKeyStore();
|
||||
PreKeyStore alicePreKeyStore = new InMemoryPreKeyStore();
|
||||
IdentityKeyStore aliceIdentityKeyStore = new InMemoryIdentityKeyStore();
|
||||
SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceSessionStore, alicePreKeyStore,
|
||||
aliceSignedPreKeyStore,
|
||||
aliceIdentityKeyStore,
|
||||
BOB_RECIPIENT_ID, 1);
|
||||
PreKeyStore alicePreKeyStore = new InMemoryPreKeyStore();
|
||||
IdentityKeyStore aliceIdentityKeyStore = new InMemoryIdentityKeyStore();
|
||||
SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceSessionStore, alicePreKeyStore,
|
||||
aliceSignedPreKeyStore,
|
||||
aliceIdentityKeyStore,
|
||||
BOB_RECIPIENT_ID, 1);
|
||||
|
||||
SessionStore bobSessionStore = new InMemorySessionStore();
|
||||
PreKeyStore bobPreKeyStore = new InMemoryPreKeyStore();
|
||||
SessionStore bobSessionStore = new InMemorySessionStore();
|
||||
PreKeyStore bobPreKeyStore = new InMemoryPreKeyStore();
|
||||
SignedPreKeyStore bobSignedPreKeyStore = new InMemorySignedPreKeyStore();
|
||||
IdentityKeyStore bobIdentityKeyStore = new InMemoryIdentityKeyStore();
|
||||
SessionBuilder bobSessionBuilder = new SessionBuilder(bobSessionStore, bobPreKeyStore,
|
||||
bobSignedPreKeyStore,
|
||||
bobIdentityKeyStore,
|
||||
ALICE_RECIPIENT_ID, 1);
|
||||
IdentityKeyStore bobIdentityKeyStore = new InMemoryIdentityKeyStore();
|
||||
SessionBuilder bobSessionBuilder = new SessionBuilder(bobSessionStore, bobPreKeyStore,
|
||||
bobSignedPreKeyStore,
|
||||
bobIdentityKeyStore,
|
||||
ALICE_RECIPIENT_ID, 1);
|
||||
|
||||
ECKeyPair bobPreKeyPair = Curve.generateKeyPair(true);
|
||||
ECKeyPair bobSignedPreKeyPair = Curve.generateKeyPair(true);
|
||||
@@ -469,6 +469,7 @@ public class SessionBuilderTest extends AndroidTestCase {
|
||||
|
||||
for (int i=0;i<incomingMessage.getVerification().length * 8;i++) {
|
||||
byte[] modifiedVerification = new byte[incomingMessage.getVerification().length];
|
||||
System.arraycopy(incomingMessage.getVerification(), 0, modifiedVerification, 0, modifiedVerification.length);
|
||||
modifiedVerification[i / 8] ^= (0x01 << i % 8);
|
||||
|
||||
PreKeyWhisperMessage modifiedMessage = new PreKeyWhisperMessage(incomingMessage.getMessageVersion(),
|
||||
|
||||
@@ -11,11 +11,13 @@ import org.whispersystems.libaxolotl.LegacyMessageException;
|
||||
import org.whispersystems.libaxolotl.SessionCipher;
|
||||
import org.whispersystems.libaxolotl.ecc.Curve;
|
||||
import org.whispersystems.libaxolotl.ecc.ECKeyPair;
|
||||
import org.whispersystems.libaxolotl.ecc.ECPublicKey;
|
||||
import org.whispersystems.libaxolotl.protocol.CiphertextMessage;
|
||||
import org.whispersystems.libaxolotl.ratchet.RatchetingSession;
|
||||
import org.whispersystems.libaxolotl.state.SessionRecord;
|
||||
import org.whispersystems.libaxolotl.state.SessionState;
|
||||
import org.whispersystems.libaxolotl.state.SessionStore;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
@@ -24,6 +26,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.whispersystems.libaxolotl.ratchet.RatchetingSession.InitializationParameters;
|
||||
|
||||
public class SessionCipherTest extends AndroidTestCase {
|
||||
|
||||
public void testBasicSessionV2()
|
||||
@@ -134,16 +138,33 @@ public class SessionCipherTest extends AndroidTestCase {
|
||||
ECKeyPair bobBaseKey = Curve.generateKeyPair(true);
|
||||
ECKeyPair bobEphemeralKey = bobBaseKey;
|
||||
|
||||
InitializationParameters aliceParameters =
|
||||
InitializationParameters.newBuilder()
|
||||
.setOurIdentityKey(aliceIdentityKey)
|
||||
.setOurBaseKey(aliceBaseKey)
|
||||
.setOurEphemeralKey(aliceEphemeralKey)
|
||||
.setOurPreKey(Optional.<ECKeyPair>absent())
|
||||
.setTheirIdentityKey(bobIdentityKey.getPublicKey())
|
||||
.setTheirBaseKey(bobBaseKey.getPublicKey())
|
||||
.setTheirEphemeralKey(bobEphemeralKey.getPublicKey())
|
||||
.setTheirPreKey(Optional.<ECPublicKey>absent())
|
||||
.create();
|
||||
|
||||
RatchetingSession.initializeSession(aliceSessionState, 2, aliceBaseKey, bobBaseKey.getPublicKey(),
|
||||
aliceEphemeralKey, bobEphemeralKey.getPublicKey(),
|
||||
null, null,
|
||||
aliceIdentityKey, bobIdentityKey.getPublicKey());
|
||||
InitializationParameters bobParameters =
|
||||
InitializationParameters.newBuilder()
|
||||
.setOurIdentityKey(bobIdentityKey)
|
||||
.setOurBaseKey(bobBaseKey)
|
||||
.setOurEphemeralKey(bobEphemeralKey)
|
||||
.setOurPreKey(Optional.<ECKeyPair>absent())
|
||||
.setTheirIdentityKey(aliceIdentityKey.getPublicKey())
|
||||
.setTheirBaseKey(aliceBaseKey.getPublicKey())
|
||||
.setTheirEphemeralKey(aliceEphemeralKey.getPublicKey())
|
||||
.setTheirPreKey(Optional.<ECPublicKey>absent())
|
||||
.create();
|
||||
|
||||
RatchetingSession.initializeSession(bobSessionState, 2, bobBaseKey, aliceBaseKey.getPublicKey(),
|
||||
bobEphemeralKey, aliceEphemeralKey.getPublicKey(),
|
||||
null, null,
|
||||
bobIdentityKey, aliceIdentityKey.getPublicKey());
|
||||
|
||||
RatchetingSession.initializeSession(aliceSessionState, 2, aliceParameters);
|
||||
RatchetingSession.initializeSession(bobSessionState, 2, bobParameters);
|
||||
}
|
||||
|
||||
private void initializeSessionsV3(SessionState aliceSessionState, SessionState bobSessionState)
|
||||
@@ -165,16 +186,33 @@ public class SessionCipherTest extends AndroidTestCase {
|
||||
|
||||
ECKeyPair bobPreKey = Curve.generateKeyPair(true);
|
||||
|
||||
InitializationParameters aliceParameters =
|
||||
InitializationParameters.newBuilder()
|
||||
.setOurIdentityKey(aliceIdentityKey)
|
||||
.setOurBaseKey(aliceBaseKey)
|
||||
.setOurEphemeralKey(aliceEphemeralKey)
|
||||
.setOurPreKey(Optional.of(alicePreKey))
|
||||
.setTheirIdentityKey(bobIdentityKey.getPublicKey())
|
||||
.setTheirBaseKey(bobBaseKey.getPublicKey())
|
||||
.setTheirEphemeralKey(bobEphemeralKey.getPublicKey())
|
||||
.setTheirPreKey(Optional.of(bobPreKey.getPublicKey()))
|
||||
.create();
|
||||
|
||||
RatchetingSession.initializeSession(aliceSessionState, 3, aliceBaseKey, bobBaseKey.getPublicKey(),
|
||||
aliceEphemeralKey, bobEphemeralKey.getPublicKey(),
|
||||
alicePreKey, bobPreKey.getPublicKey(),
|
||||
aliceIdentityKey, bobIdentityKey.getPublicKey());
|
||||
InitializationParameters bobParameters =
|
||||
InitializationParameters.newBuilder()
|
||||
.setOurIdentityKey(bobIdentityKey)
|
||||
.setOurBaseKey(bobBaseKey)
|
||||
.setOurEphemeralKey(bobEphemeralKey)
|
||||
.setOurPreKey(Optional.of(bobPreKey))
|
||||
.setTheirIdentityKey(aliceIdentityKey.getPublicKey())
|
||||
.setTheirBaseKey(aliceBaseKey.getPublicKey())
|
||||
.setTheirEphemeralKey(aliceEphemeralKey.getPublicKey())
|
||||
.setTheirPreKey(Optional.of(alicePreKey.getPublicKey()))
|
||||
.create();
|
||||
|
||||
RatchetingSession.initializeSession(bobSessionState, 3, bobBaseKey, aliceBaseKey.getPublicKey(),
|
||||
bobEphemeralKey, aliceEphemeralKey.getPublicKey(),
|
||||
bobPreKey, alicePreKey.getPublicKey(),
|
||||
bobIdentityKey, aliceIdentityKey.getPublicKey());
|
||||
|
||||
RatchetingSession.initializeSession(aliceSessionState, 3, aliceParameters);
|
||||
RatchetingSession.initializeSession(bobSessionState, 3, bobParameters);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,12 @@ import org.whispersystems.libaxolotl.ecc.ECPrivateKey;
|
||||
import org.whispersystems.libaxolotl.ecc.ECPublicKey;
|
||||
import org.whispersystems.libaxolotl.ratchet.RatchetingSession;
|
||||
import org.whispersystems.libaxolotl.state.SessionState;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.whispersystems.libaxolotl.ratchet.RatchetingSession.InitializationParameters;
|
||||
|
||||
public class RatchetingSessionTest extends AndroidTestCase {
|
||||
|
||||
public void testRatchetingSessionAsBob() throws InvalidKeyException {
|
||||
@@ -105,12 +108,21 @@ public class RatchetingSessionTest extends AndroidTestCase {
|
||||
ECPublicKey aliceEphemeralPublicKey = Curve.decodePoint(aliceEphemeralPublic, 0);
|
||||
IdentityKey aliceIdentityPublicKey = new IdentityKey(aliceIdentityPublic, 0);
|
||||
|
||||
InitializationParameters parameters = InitializationParameters.newBuilder()
|
||||
.setOurBaseKey(bobBaseKey)
|
||||
.setOurEphemeralKey(bobEphemeralKey)
|
||||
.setOurIdentityKey(bobIdentityKey)
|
||||
.setOurPreKey(Optional.<ECKeyPair>absent())
|
||||
.setTheirBaseKey(aliceBasePublicKey)
|
||||
.setTheirEphemeralKey(aliceEphemeralPublicKey)
|
||||
.setTheirIdentityKey(aliceIdentityPublicKey)
|
||||
.setTheirPreKey(Optional.<ECPublicKey>absent())
|
||||
.create();
|
||||
|
||||
SessionState session = new SessionState();
|
||||
|
||||
RatchetingSession.initializeSession(session, 2, bobBaseKey, aliceBasePublicKey,
|
||||
bobEphemeralKey, aliceEphemeralPublicKey,
|
||||
null, null,
|
||||
bobIdentityKey, aliceIdentityPublicKey);
|
||||
|
||||
RatchetingSession.initializeSession(session, 2, parameters);
|
||||
|
||||
assertTrue(session.getLocalIdentityKey().equals(bobIdentityKey.getPublicKey()));
|
||||
assertTrue(session.getRemoteIdentityKey().equals(aliceIdentityPublicKey));
|
||||
@@ -205,10 +217,18 @@ public class RatchetingSessionTest extends AndroidTestCase {
|
||||
|
||||
SessionState session = new SessionState();
|
||||
|
||||
RatchetingSession.initializeSession(session, 2, aliceBaseKey, bobBasePublicKey,
|
||||
aliceEphemeralKey, bobEphemeralPublicKey,
|
||||
null, null,
|
||||
aliceIdentityKey, bobIdentityKey);
|
||||
InitializationParameters parameters = InitializationParameters.newBuilder()
|
||||
.setOurBaseKey(aliceBaseKey)
|
||||
.setOurEphemeralKey(aliceEphemeralKey)
|
||||
.setOurIdentityKey(aliceIdentityKey)
|
||||
.setOurPreKey(Optional.<ECKeyPair>absent())
|
||||
.setTheirBaseKey(bobBasePublicKey)
|
||||
.setTheirEphemeralKey(bobEphemeralPublicKey)
|
||||
.setTheirIdentityKey(bobIdentityKey)
|
||||
.setTheirPreKey(Optional.<ECPublicKey>absent())
|
||||
.create();
|
||||
|
||||
RatchetingSession.initializeSession(session, 2, parameters);
|
||||
|
||||
assertTrue(session.getLocalIdentityKey().equals(aliceIdentityKey.getPublicKey()));
|
||||
assertTrue(session.getRemoteIdentityKey().equals(bobIdentityKey));
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package org.whispersystems.test.ratchet;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
import android.util.Log;
|
||||
|
||||
import org.whispersystems.libaxolotl.InvalidKeyException;
|
||||
import org.whispersystems.libaxolotl.ecc.Curve;
|
||||
import org.whispersystems.libaxolotl.ecc.ECPublicKey;
|
||||
import org.whispersystems.libaxolotl.ratchet.VerifyKey;
|
||||
import org.whispersystems.libaxolotl.util.Hex;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@@ -62,9 +65,8 @@ public class VerifyKeyTest extends AndroidTestCase {
|
||||
(byte)0x79, (byte)0x00, (byte)0xef, (byte)0x1b, (byte)0x40,
|
||||
(byte)0x0f, (byte)0xdc};
|
||||
|
||||
byte[] expectedTag = {(byte)0x68, (byte)0x64, (byte)0xbf, (byte)0xbf, (byte)0x82,
|
||||
(byte)0x34, (byte)0x20, (byte)0xdc};
|
||||
|
||||
byte[] expectedTag = {(byte)0x2f, (byte)0x77, (byte)0xaf, (byte)0xad, (byte)0x5b,
|
||||
(byte)0x96, (byte)0xf5, (byte)0x3c};
|
||||
|
||||
ECPublicKey aliceBaseKey = Curve.decodePoint(aliceBaseKeyBytes, 0);
|
||||
ECPublicKey alicePreKey = aliceBaseKey;
|
||||
@@ -75,8 +77,9 @@ public class VerifyKeyTest extends AndroidTestCase {
|
||||
ECPublicKey bobIdentityKey = Curve.decodePoint(bobIdentityKeyBytes, 0);
|
||||
|
||||
VerifyKey verifyKey = new VerifyKey(key);
|
||||
byte[] verification = verifyKey.generateVerification(aliceBaseKey, alicePreKey, aliceIdentityKey,
|
||||
bobBaseKey, bobPreKey, bobIdentityKey);
|
||||
byte[] verification = verifyKey.generateVerification(aliceBaseKey, Optional.of(alicePreKey),
|
||||
aliceIdentityKey, bobBaseKey,
|
||||
Optional.of(bobPreKey), bobIdentityKey);
|
||||
|
||||
assertTrue(MessageDigest.isEqual(verification, expectedTag));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user