Rename "pendingPreKey" to "unacknowledgedPreKeyMessage"

This commit is contained in:
Moxie Marlinspike 2014-07-18 13:26:55 -07:00
parent e0d2398ca5
commit 42cf53e487
4 changed files with 49 additions and 30 deletions

View File

@ -116,7 +116,7 @@ public class SessionBuilder {
return; return;
} }
boolean simultaneousInitiate = sessionRecord.getSessionState().hasPendingPreKey(); boolean simultaneousInitiate = sessionRecord.getSessionState().hasUnacknowledgedPreKeyMessage();
AxolotlParameters.Builder parameters = AxolotlParameters.newBuilder(); AxolotlParameters.Builder parameters = AxolotlParameters.newBuilder();
@ -166,7 +166,7 @@ public class SessionBuilder {
} }
SessionRecord sessionRecord = sessionStore.loadSession(recipientId, deviceId); SessionRecord sessionRecord = sessionStore.loadSession(recipientId, deviceId);
boolean simultaneousInitiate = sessionRecord.getSessionState().hasPendingPreKey(); boolean simultaneousInitiate = sessionRecord.getSessionState().hasUnacknowledgedPreKeyMessage();
AxolotlParameters.Builder parameters = RatchetingSession.AxolotlParameters.newBuilder(); AxolotlParameters.Builder parameters = RatchetingSession.AxolotlParameters.newBuilder();
parameters.setTheirBaseKey(message.getBaseKey()); parameters.setTheirBaseKey(message.getBaseKey());
@ -247,7 +247,7 @@ public class SessionBuilder {
preKey.getSignedPreKey() == null ? 2 : 3, preKey.getSignedPreKey() == null ? 2 : 3,
parameters.create()); 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().setLocalRegistrationId(identityKeyStore.getLocalRegistrationId());
sessionRecord.getSessionState().setRemoteRegistrationId(preKey.getRegistrationId()); sessionRecord.getSessionState().setRemoteRegistrationId(preKey.getRegistrationId());
@ -389,10 +389,8 @@ public class SessionBuilder {
sessionRecord.getSessionState().setPendingKeyExchange(sequence, baseKey, ephemeralKey, identityKey); sessionRecord.getSessionState().setPendingKeyExchange(sequence, baseKey, ephemeralKey, identityKey);
sessionStore.storeSession(recipientId, deviceId, sessionRecord); sessionStore.storeSession(recipientId, deviceId, sessionRecord);
return new KeyExchangeMessage(2, sequence, flags, return new KeyExchangeMessage(2, sequence, flags, baseKey.getPublicKey(), null,
baseKey.getPublicKey(), null, ephemeralKey.getPublicKey(), identityKey.getPublicKey(), null);
ephemeralKey.getPublicKey(),
identityKey.getPublicKey(), null);
} }

View File

@ -43,6 +43,8 @@ import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import static org.whispersystems.libaxolotl.state.SessionState.UnacknowledgedPreKeyMessageItems;
/** /**
* The main entry point for Axolotl encrypt/decrypt operations. * The main entry point for Axolotl encrypt/decrypt operations.
* *
@ -96,15 +98,12 @@ public class SessionCipher {
senderEphemeral, chainKey.getIndex(), senderEphemeral, chainKey.getIndex(),
previousCounter, ciphertextBody); previousCounter, ciphertextBody);
if (sessionState.hasPendingPreKey()) { if (sessionState.hasUnacknowledgedPreKeyMessage()) {
int pendingPreKeyId = sessionState.getPendingPreKeyId(); UnacknowledgedPreKeyMessageItems items = sessionState.getUnacknowledgedPreKeyMessageItems();
int pendingSignedPreKeyId = sessionState.getPendingSignedPreKeyId(); int localRegistrationId = sessionState.getLocalRegistrationId();
ECPublicKey pendingBaseKey = sessionState.getPendingBaseKey();
int localRegistrationId = sessionState.getLocalRegistrationId();
ciphertextMessage = new PreKeyWhisperMessage(sessionVersion, ciphertextMessage = new PreKeyWhisperMessage(sessionVersion, localRegistrationId, items.getPreKeyId(),
localRegistrationId, pendingPreKeyId, items.getSignedPreKeyId(), items.getBaseKey(),
pendingSignedPreKeyId, pendingBaseKey,
sessionState.getLocalIdentityKey(), sessionState.getLocalIdentityKey(),
sessionState.getVerification(), sessionState.getVerification(),
(WhisperMessage) ciphertextMessage); (WhisperMessage) ciphertextMessage);
@ -185,7 +184,7 @@ public class SessionCipher {
byte[] plaintext = getPlaintext(messageKeys, ciphertextMessage.getBody()); byte[] plaintext = getPlaintext(messageKeys, ciphertextMessage.getBody());
sessionState.clearPendingPreKey(); sessionState.clearUnacknowledgedPreKeyMessage();
return plaintext; return plaintext;

View File

@ -423,7 +423,7 @@ public class SessionState {
return sessionStructure.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() PendingPreKey pending = PendingPreKey.newBuilder()
.setPreKeyId(preKeyId) .setPreKeyId(preKeyId)
.setSignedPreKeyId(signedPreKeyId) .setSignedPreKeyId(signedPreKeyId)
@ -435,27 +435,24 @@ public class SessionState {
.build(); .build();
} }
public boolean hasPendingPreKey() { public boolean hasUnacknowledgedPreKeyMessage() {
return this.sessionStructure.hasPendingPreKey(); return this.sessionStructure.hasPendingPreKey();
} }
public int getPendingPreKeyId() { public UnacknowledgedPreKeyMessageItems getUnacknowledgedPreKeyMessageItems() {
return sessionStructure.getPendingPreKey().getPreKeyId();
}
public int getPendingSignedPreKeyId() {
return sessionStructure.getPendingPreKey().getSignedPreKeyId();
}
public ECPublicKey getPendingBaseKey() {
try { 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) { } catch (InvalidKeyException e) {
throw new AssertionError(e); throw new AssertionError(e);
} }
} }
public void clearPendingPreKey() { public void clearUnacknowledgedPreKeyMessage() {
this.sessionStructure = this.sessionStructure.toBuilder() this.sessionStructure = this.sessionStructure.toBuilder()
.clearPendingPreKey() .clearPendingPreKey()
.build(); .build();
@ -484,4 +481,29 @@ public class SessionState {
public byte[] serialize() { public byte[] serialize() {
return sessionStructure.toByteArray(); 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;
}
}
} }

View File

@ -83,6 +83,6 @@ public class KeyExchangeInitiator {
SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret); SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret);
SessionRecord sessionRecord = sessionStore.loadSession(recipient.getRecipientId(), RecipientDevice.DEFAULT_DEVICE_ID); SessionRecord sessionRecord = sessionStore.loadSession(recipient.getRecipientId(), RecipientDevice.DEFAULT_DEVICE_ID);
return sessionRecord.getSessionState().hasPendingPreKey(); return sessionRecord.getSessionState().hasPendingKeyExchange();
} }
} }