Skip to content

Commit

Permalink
Rename "pendingPreKey" to "unacknowledgedPreKeyMessage"
Browse files Browse the repository at this point in the history
  • Loading branch information
moxie0 committed Oct 20, 2014
1 parent e0d2398 commit 42cf53e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private void processV3(PreKeyWhisperMessage message)
return;
}

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

AxolotlParameters.Builder parameters = AxolotlParameters.newBuilder();

Expand Down Expand Up @@ -166,7 +166,7 @@ private void processV2(PreKeyWhisperMessage message)
}

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

parameters.setTheirBaseKey(message.getBaseKey());
Expand Down Expand Up @@ -247,7 +247,7 @@ public void process(PreKeyBundle preKey) throws InvalidKeyException, UntrustedId
preKey.getSignedPreKey() == null ? 2 : 3,
parameters.create());

sessionRecord.getSessionState().setPendingPreKey(preKey.getPreKeyId(), preKey.getSignedPreKeyId(), ourBaseKey.getPublicKey());
sessionRecord.getSessionState().setUnacknowledgedPreKeyMessage(preKey.getPreKeyId(), preKey.getSignedPreKeyId(), ourBaseKey.getPublicKey());
sessionRecord.getSessionState().setLocalRegistrationId(identityKeyStore.getLocalRegistrationId());
sessionRecord.getSessionState().setRemoteRegistrationId(preKey.getRegistrationId());

Expand Down Expand Up @@ -389,10 +389,8 @@ public KeyExchangeMessage process() {
sessionRecord.getSessionState().setPendingKeyExchange(sequence, baseKey, ephemeralKey, identityKey);
sessionStore.storeSession(recipientId, deviceId, sessionRecord);

return new KeyExchangeMessage(2, sequence, flags,
baseKey.getPublicKey(), null,
ephemeralKey.getPublicKey(),
identityKey.getPublicKey(), null);
return new KeyExchangeMessage(2, sequence, flags, baseKey.getPublicKey(), null,
ephemeralKey.getPublicKey(), identityKey.getPublicKey(), null);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

import static org.whispersystems.libaxolotl.state.SessionState.UnacknowledgedPreKeyMessageItems;

/**
* The main entry point for Axolotl encrypt/decrypt operations.
*
Expand Down Expand Up @@ -96,15 +98,12 @@ public CiphertextMessage encrypt(byte[] paddedMessage) {
senderEphemeral, chainKey.getIndex(),
previousCounter, ciphertextBody);

if (sessionState.hasPendingPreKey()) {
int pendingPreKeyId = sessionState.getPendingPreKeyId();
int pendingSignedPreKeyId = sessionState.getPendingSignedPreKeyId();
ECPublicKey pendingBaseKey = sessionState.getPendingBaseKey();
int localRegistrationId = sessionState.getLocalRegistrationId();
if (sessionState.hasUnacknowledgedPreKeyMessage()) {
UnacknowledgedPreKeyMessageItems items = sessionState.getUnacknowledgedPreKeyMessageItems();
int localRegistrationId = sessionState.getLocalRegistrationId();

ciphertextMessage = new PreKeyWhisperMessage(sessionVersion,
localRegistrationId, pendingPreKeyId,
pendingSignedPreKeyId, pendingBaseKey,
ciphertextMessage = new PreKeyWhisperMessage(sessionVersion, localRegistrationId, items.getPreKeyId(),
items.getSignedPreKeyId(), items.getBaseKey(),
sessionState.getLocalIdentityKey(),
sessionState.getVerification(),
(WhisperMessage) ciphertextMessage);
Expand Down Expand Up @@ -185,7 +184,7 @@ private byte[] decrypt(SessionState sessionState, byte[] decodedMessage)

byte[] plaintext = getPlaintext(messageKeys, ciphertextMessage.getBody());

sessionState.clearPendingPreKey();
sessionState.clearUnacknowledgedPreKeyMessage();

return plaintext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public boolean hasPendingKeyExchange() {
return sessionStructure.hasPendingKeyExchange();
}

public void setPendingPreKey(int preKeyId, int signedPreKeyId, ECPublicKey baseKey) {
public void setUnacknowledgedPreKeyMessage(int preKeyId, int signedPreKeyId, ECPublicKey baseKey) {
PendingPreKey pending = PendingPreKey.newBuilder()
.setPreKeyId(preKeyId)
.setSignedPreKeyId(signedPreKeyId)
Expand All @@ -435,27 +435,24 @@ public void setPendingPreKey(int preKeyId, int signedPreKeyId, ECPublicKey baseK
.build();
}

public boolean hasPendingPreKey() {
public boolean hasUnacknowledgedPreKeyMessage() {
return this.sessionStructure.hasPendingPreKey();
}

public int getPendingPreKeyId() {
return sessionStructure.getPendingPreKey().getPreKeyId();
}

public int getPendingSignedPreKeyId() {
return sessionStructure.getPendingPreKey().getSignedPreKeyId();
}

public ECPublicKey getPendingBaseKey() {
public UnacknowledgedPreKeyMessageItems getUnacknowledgedPreKeyMessageItems() {
try {
return Curve.decodePoint(sessionStructure.getPendingPreKey().getBaseKey().toByteArray(), 0);
return
new UnacknowledgedPreKeyMessageItems(sessionStructure.getPendingPreKey().getPreKeyId(),
sessionStructure.getPendingPreKey().getSignedPreKeyId(),
Curve.decodePoint(sessionStructure.getPendingPreKey()
.getBaseKey()
.toByteArray(), 0));
} catch (InvalidKeyException e) {
throw new AssertionError(e);
}
}

public void clearPendingPreKey() {
public void clearUnacknowledgedPreKeyMessage() {
this.sessionStructure = this.sessionStructure.toBuilder()
.clearPendingPreKey()
.build();
Expand Down Expand Up @@ -484,4 +481,29 @@ public int getLocalRegistrationId() {
public byte[] serialize() {
return sessionStructure.toByteArray();
}

public static class UnacknowledgedPreKeyMessageItems {
private final int preKeyId;
private final int signedPreKeyId;
private final ECPublicKey baseKey;

public UnacknowledgedPreKeyMessageItems(int preKeyId, int signedPreKeyId, ECPublicKey baseKey) {
this.preKeyId = preKeyId;
this.signedPreKeyId = signedPreKeyId;
this.baseKey = baseKey;
}


public int getPreKeyId() {
return preKeyId;
}

public int getSignedPreKeyId() {
return signedPreKeyId;
}

public ECPublicKey getBaseKey() {
return baseKey;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ private static boolean hasInitiatedSession(Context context, MasterSecret masterS
SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret);
SessionRecord sessionRecord = sessionStore.loadSession(recipient.getRecipientId(), RecipientDevice.DEFAULT_DEVICE_ID);

return sessionRecord.getSessionState().hasPendingPreKey();
return sessionRecord.getSessionState().hasPendingKeyExchange();
}
}

0 comments on commit 42cf53e

Please sign in to comment.