Skip to content

Commit

Permalink
Rename InitializationParameters -> AxolotlParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
moxie0 committed Oct 20, 2014
1 parent 3f29993 commit e0d2398
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.List;
import java.util.Random;

import static org.whispersystems.libaxolotl.ratchet.RatchetingSession.InitializationParameters;
import static org.whispersystems.libaxolotl.ratchet.RatchetingSession.AxolotlParameters;

public class SessionCipherTest extends AndroidTestCase {

Expand Down Expand Up @@ -138,8 +138,8 @@ private void initializeSessionsV2(SessionState aliceSessionState, SessionState b
ECKeyPair bobBaseKey = Curve.generateKeyPair(true);
ECKeyPair bobEphemeralKey = bobBaseKey;

InitializationParameters aliceParameters =
InitializationParameters.newBuilder()
AxolotlParameters aliceParameters =
AxolotlParameters.newBuilder()
.setOurIdentityKey(aliceIdentityKey)
.setOurBaseKey(aliceBaseKey)
.setOurEphemeralKey(aliceEphemeralKey)
Expand All @@ -150,8 +150,8 @@ private void initializeSessionsV2(SessionState aliceSessionState, SessionState b
.setTheirPreKey(Optional.<ECPublicKey>absent())
.create();

InitializationParameters bobParameters =
InitializationParameters.newBuilder()
AxolotlParameters bobParameters =
RatchetingSession.AxolotlParameters.newBuilder()
.setOurIdentityKey(bobIdentityKey)
.setOurBaseKey(bobBaseKey)
.setOurEphemeralKey(bobEphemeralKey)
Expand Down Expand Up @@ -186,8 +186,8 @@ private void initializeSessionsV3(SessionState aliceSessionState, SessionState b

ECKeyPair bobPreKey = Curve.generateKeyPair(true);

InitializationParameters aliceParameters =
InitializationParameters.newBuilder()
AxolotlParameters aliceParameters =
AxolotlParameters.newBuilder()
.setOurIdentityKey(aliceIdentityKey)
.setOurBaseKey(aliceBaseKey)
.setOurEphemeralKey(aliceEphemeralKey)
Expand All @@ -198,8 +198,8 @@ private void initializeSessionsV3(SessionState aliceSessionState, SessionState b
.setTheirPreKey(Optional.of(bobPreKey.getPublicKey()))
.create();

InitializationParameters bobParameters =
InitializationParameters.newBuilder()
AxolotlParameters bobParameters =
AxolotlParameters.newBuilder()
.setOurIdentityKey(bobIdentityKey)
.setOurBaseKey(bobBaseKey)
.setOurEphemeralKey(bobEphemeralKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import java.util.Arrays;

import static org.whispersystems.libaxolotl.ratchet.RatchetingSession.InitializationParameters;
import static org.whispersystems.libaxolotl.ratchet.RatchetingSession.AxolotlParameters;

public class RatchetingSessionTest extends AndroidTestCase {

Expand Down Expand Up @@ -108,7 +108,7 @@ public void testRatchetingSessionAsBob() throws InvalidKeyException {
ECPublicKey aliceEphemeralPublicKey = Curve.decodePoint(aliceEphemeralPublic, 0);
IdentityKey aliceIdentityPublicKey = new IdentityKey(aliceIdentityPublic, 0);

InitializationParameters parameters = InitializationParameters.newBuilder()
AxolotlParameters parameters = AxolotlParameters.newBuilder()
.setOurBaseKey(bobBaseKey)
.setOurEphemeralKey(bobEphemeralKey)
.setOurIdentityKey(bobIdentityKey)
Expand Down Expand Up @@ -217,7 +217,7 @@ public void testRatchetingSessionAsAlice() throws InvalidKeyException {

SessionState session = new SessionState();

InitializationParameters parameters = InitializationParameters.newBuilder()
AxolotlParameters parameters = AxolotlParameters.newBuilder()
.setOurBaseKey(aliceBaseKey)
.setOurEphemeralKey(aliceEphemeralKey)
.setOurIdentityKey(aliceIdentityKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import java.security.MessageDigest;

import static org.whispersystems.libaxolotl.ratchet.RatchetingSession.InitializationParameters;
import static org.whispersystems.libaxolotl.ratchet.RatchetingSession.AxolotlParameters;

/**
* SessionBuilder is responsible for setting up encrypted sessions.
Expand Down Expand Up @@ -118,7 +118,7 @@ private void processV3(PreKeyWhisperMessage message)

boolean simultaneousInitiate = sessionRecord.getSessionState().hasPendingPreKey();

InitializationParameters.Builder parameters = InitializationParameters.newBuilder();
AxolotlParameters.Builder parameters = AxolotlParameters.newBuilder();

parameters.setTheirBaseKey(message.getBaseKey());
parameters.setTheirEphemeralKey(message.getWhisperMessage().getSenderEphemeral());
Expand Down Expand Up @@ -165,10 +165,9 @@ private void processV2(PreKeyWhisperMessage message)
return;
}

SessionRecord sessionRecord = sessionStore.loadSession(recipientId, deviceId);
boolean simultaneousInitiate = sessionRecord.getSessionState().hasPendingPreKey();

InitializationParameters.Builder parameters = InitializationParameters.newBuilder();
SessionRecord sessionRecord = sessionStore.loadSession(recipientId, deviceId);
boolean simultaneousInitiate = sessionRecord.getSessionState().hasPendingPreKey();
AxolotlParameters.Builder parameters = RatchetingSession.AxolotlParameters.newBuilder();

parameters.setTheirBaseKey(message.getBaseKey());
parameters.setTheirEphemeralKey(message.getWhisperMessage().getSenderEphemeral());
Expand Down Expand Up @@ -226,9 +225,9 @@ public void process(PreKeyBundle preKey) throws InvalidKeyException, UntrustedId
throw new InvalidKeyException("Both signed and unsigned prekeys are absent!");
}

SessionRecord sessionRecord = sessionStore.loadSession(recipientId, deviceId);
InitializationParameters.Builder parameters = InitializationParameters.newBuilder();
ECKeyPair ourBaseKey = Curve.generateKeyPair(true);
SessionRecord sessionRecord = sessionStore.loadSession(recipientId, deviceId);
AxolotlParameters.Builder parameters = AxolotlParameters.newBuilder();
ECKeyPair ourBaseKey = Curve.generateKeyPair(true);

parameters.setOurIdentityKey(identityKeyStore.getIdentityKeyPair());
parameters.setOurBaseKey(ourBaseKey);
Expand Down Expand Up @@ -281,9 +280,9 @@ public KeyExchangeMessage process(KeyExchangeMessage message)
}

private KeyExchangeMessage processInitiate(KeyExchangeMessage message) throws InvalidKeyException {
InitializationParameters.Builder parameters = InitializationParameters.newBuilder();
int flags = KeyExchangeMessage.RESPONSE_FLAG;
SessionRecord sessionRecord = sessionStore.loadSession(recipientId, deviceId);
AxolotlParameters.Builder parameters = AxolotlParameters.newBuilder();
int flags = KeyExchangeMessage.RESPONSE_FLAG;
SessionRecord sessionRecord = sessionStore.loadSession(recipientId, deviceId);

if (message.getVersion() >= 3 &&
!Curve.verifySignature(message.getIdentityKey().getPublicKey(),
Expand All @@ -305,7 +304,7 @@ private KeyExchangeMessage processInitiate(KeyExchangeMessage message) throws In
parameters.setOurEphemeralKey(sessionRecord.getSessionState().getPendingKeyExchangeEphemeralKey());
parameters.setOurIdentityKey(sessionRecord.getSessionState().getPendingKeyExchangeIdentityKey());
parameters.setOurPreKey(Optional.<ECKeyPair>absent());
flags |= KeyExchangeMessage.SIMULTAENOUS_INITIATE_FLAG;
flags |= KeyExchangeMessage.SIMULTAENOUS_INITIATE_FLAG;
}

parameters.setTheirBaseKey(message.getBaseKey());
Expand Down Expand Up @@ -344,17 +343,17 @@ private void processResponse(KeyExchangeMessage message)
else return;
}

InitializationParameters parameters =
InitializationParameters.newBuilder()
.setOurBaseKey(sessionRecord.getSessionState().getPendingKeyExchangeBaseKey())
.setOurEphemeralKey(sessionRecord.getSessionState().getPendingKeyExchangeEphemeralKey())
.setOurPreKey(Optional.<ECKeyPair>absent())
.setOurIdentityKey(sessionRecord.getSessionState().getPendingKeyExchangeIdentityKey())
.setTheirBaseKey(message.getBaseKey())
.setTheirEphemeralKey(message.getEphemeralKey())
.setTheirPreKey(Optional.<ECPublicKey>absent())
.setTheirIdentityKey(message.getIdentityKey())
.create();
AxolotlParameters parameters =
AxolotlParameters.newBuilder()
.setOurBaseKey(sessionRecord.getSessionState().getPendingKeyExchangeBaseKey())
.setOurEphemeralKey(sessionRecord.getSessionState().getPendingKeyExchangeEphemeralKey())
.setOurPreKey(Optional.<ECKeyPair>absent())
.setOurIdentityKey(sessionRecord.getSessionState().getPendingKeyExchangeIdentityKey())
.setTheirBaseKey(message.getBaseKey())
.setTheirEphemeralKey(message.getEphemeralKey())
.setTheirPreKey(Optional.<ECPublicKey>absent())
.setTheirIdentityKey(message.getIdentityKey())
.create();

sessionRecord.reset();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class RatchetingSession {

public static void initializeSession(SessionState sessionState,
int sessionVersion,
InitializationParameters parameters)
AxolotlParameters parameters)
throws InvalidKeyException
{
if (isAlice(parameters)) initializeSessionAsAlice(sessionState, sessionVersion, parameters);
Expand All @@ -48,7 +48,7 @@ public static void initializeSession(SessionState sessionState,

private static void initializeSessionAsAlice(SessionState sessionState,
int sessionVersion,
InitializationParameters parameters)
AxolotlParameters parameters)
throws InvalidKeyException
{
sessionState.setRemoteIdentityKey(parameters.getTheirIdentityKey());
Expand All @@ -70,7 +70,7 @@ private static void initializeSessionAsAlice(SessionState sessionState,

private static void initializeSessionAsBob(SessionState sessionState,
int sessionVersion,
InitializationParameters parameters)
AxolotlParameters parameters)
throws InvalidKeyException
{
sessionState.setRemoteIdentityKey(parameters.getTheirIdentityKey());
Expand All @@ -86,7 +86,7 @@ private static void initializeSessionAsBob(SessionState sessionState,
}
}

private static DHEResult calculate4DHE(boolean isAlice, int sessionVersion, InitializationParameters parameters)
private static DHEResult calculate4DHE(boolean isAlice, int sessionVersion, AxolotlParameters parameters)
throws InvalidKeyException
{
try {
Expand Down Expand Up @@ -131,7 +131,7 @@ private static DHEResult calculate4DHE(boolean isAlice, int sessionVersion, Init
}

private static byte[] calculateVerificationTag(boolean isAlice, VerifyKey verifyKey,
InitializationParameters parameters)
AxolotlParameters parameters)
{
if (isAlice) {
return verifyKey.generateVerification(parameters.getOurBaseKey().getPublicKey(),
Expand All @@ -150,7 +150,7 @@ private static byte[] calculateVerificationTag(boolean isAlice, VerifyKey verify
}
}

private static boolean isAlice(InitializationParameters parameters)
private static boolean isAlice(AxolotlParameters parameters)
{
if (parameters.getOurEphemeralKey().equals(parameters.getOurBaseKey())) {
return false;
Expand All @@ -172,7 +172,7 @@ private static Optional<ECPublicKey> getPublicKey(Optional<ECKeyPair> keyPair) {
else return Optional.absent();
}

public static class InitializationParameters {
public static class AxolotlParameters {
private final ECKeyPair ourBaseKey;
private final ECKeyPair ourEphemeralKey;
private final Optional<ECKeyPair> ourPreKey;
Expand All @@ -183,10 +183,10 @@ public static class InitializationParameters {
private final Optional<ECPublicKey> theirPreKey;
private final IdentityKey theirIdentityKey;

public InitializationParameters(ECKeyPair ourBaseKey, ECKeyPair ourEphemeralKey,
Optional<ECKeyPair> ourPreKey, IdentityKeyPair ourIdentityKey,
ECPublicKey theirBaseKey, ECPublicKey theirEphemeralKey,
Optional<ECPublicKey> theirPreKey, IdentityKey theirIdentityKey)
public AxolotlParameters(ECKeyPair ourBaseKey, ECKeyPair ourEphemeralKey,
Optional<ECKeyPair> ourPreKey, IdentityKeyPair ourIdentityKey,
ECPublicKey theirBaseKey, ECPublicKey theirEphemeralKey,
Optional<ECPublicKey> theirPreKey, IdentityKey theirIdentityKey)
{
this.ourBaseKey = ourBaseKey;
this.ourEphemeralKey = ourEphemeralKey;
Expand Down Expand Up @@ -300,17 +300,15 @@ public Builder setTheirIdentityKey(IdentityKey theirIdentityKey) {
return this;
}

public RatchetingSession.InitializationParameters create() {
public AxolotlParameters create() {
if (ourBaseKey == null || ourEphemeralKey == null || ourPreKey == null || ourIdentityKey == null ||
theirBaseKey == null || theirEphemeralKey == null || theirPreKey == null || theirIdentityKey == null)
{
throw new IllegalArgumentException("All parameters not specified!");
}

return new RatchetingSession.InitializationParameters(ourBaseKey, ourEphemeralKey,
ourPreKey, ourIdentityKey,
theirBaseKey, theirEphemeralKey,
theirPreKey, theirIdentityKey);
return new AxolotlParameters(ourBaseKey, ourEphemeralKey, ourPreKey, ourIdentityKey,
theirBaseKey, theirEphemeralKey, theirPreKey, theirIdentityKey);
}
}
}
Expand Down

0 comments on commit e0d2398

Please sign in to comment.