Rename axolotl -> signalProtocol

This commit is contained in:
AsamK 2016-03-25 16:57:40 +01:00
parent b06fafbf62
commit 10719a443a
2 changed files with 22 additions and 21 deletions

View file

@ -14,7 +14,7 @@ import org.whispersystems.libsignal.state.SignedPreKeyRecord;
import java.util.List; import java.util.List;
class JsonAxolotlStore implements SignalProtocolStore { class JsonSignalProtocolStore implements SignalProtocolStore {
@JsonProperty("preKeys") @JsonProperty("preKeys")
@JsonDeserialize(using = JsonPreKeyStore.JsonPreKeyStoreDeserializer.class) @JsonDeserialize(using = JsonPreKeyStore.JsonPreKeyStoreDeserializer.class)
@ -36,17 +36,17 @@ class JsonAxolotlStore implements SignalProtocolStore {
@JsonSerialize(using = JsonIdentityKeyStore.JsonIdentityKeyStoreSerializer.class) @JsonSerialize(using = JsonIdentityKeyStore.JsonIdentityKeyStoreSerializer.class)
protected JsonIdentityKeyStore identityKeyStore; protected JsonIdentityKeyStore identityKeyStore;
public JsonAxolotlStore() { public JsonSignalProtocolStore() {
} }
public JsonAxolotlStore(JsonPreKeyStore preKeyStore, JsonSessionStore sessionStore, JsonSignedPreKeyStore signedPreKeyStore, JsonIdentityKeyStore identityKeyStore) { public JsonSignalProtocolStore(JsonPreKeyStore preKeyStore, JsonSessionStore sessionStore, JsonSignedPreKeyStore signedPreKeyStore, JsonIdentityKeyStore identityKeyStore) {
this.preKeyStore = preKeyStore; this.preKeyStore = preKeyStore;
this.sessionStore = sessionStore; this.sessionStore = sessionStore;
this.signedPreKeyStore = signedPreKeyStore; this.signedPreKeyStore = signedPreKeyStore;
this.identityKeyStore = identityKeyStore; this.identityKeyStore = identityKeyStore;
} }
public JsonAxolotlStore(IdentityKeyPair identityKeyPair, int registrationId) { public JsonSignalProtocolStore(IdentityKeyPair identityKeyPair, int registrationId) {
preKeyStore = new JsonPreKeyStore(); preKeyStore = new JsonPreKeyStore();
sessionStore = new JsonSessionStore(); sessionStore = new JsonSessionStore();
signedPreKeyStore = new JsonSignedPreKeyStore(); signedPreKeyStore = new JsonSignedPreKeyStore();

View file

@ -28,6 +28,7 @@ import org.whispersystems.libsignal.*;
import org.whispersystems.libsignal.ecc.Curve; import org.whispersystems.libsignal.ecc.Curve;
import org.whispersystems.libsignal.ecc.ECKeyPair; import org.whispersystems.libsignal.ecc.ECKeyPair;
import org.whispersystems.libsignal.state.PreKeyRecord; import org.whispersystems.libsignal.state.PreKeyRecord;
import org.whispersystems.libsignal.state.SignalProtocolStore;
import org.whispersystems.libsignal.state.SignedPreKeyRecord; import org.whispersystems.libsignal.state.SignedPreKeyRecord;
import org.whispersystems.libsignal.util.KeyHelper; import org.whispersystems.libsignal.util.KeyHelper;
import org.whispersystems.libsignal.util.Medium; import org.whispersystems.libsignal.util.Medium;
@ -72,7 +73,7 @@ class Manager implements TextSecure {
private boolean registered = false; private boolean registered = false;
private JsonAxolotlStore axolotlStore; private SignalProtocolStore signalProtocolStore;
private SignalServiceAccountManager accountManager; private SignalServiceAccountManager accountManager;
private JsonGroupStore groupStore; private JsonGroupStore groupStore;
@ -99,7 +100,7 @@ class Manager implements TextSecure {
} }
public boolean userHasKeys() { public boolean userHasKeys() {
return axolotlStore != null; return signalProtocolStore != null;
} }
private JsonNode getNotNullNode(JsonNode parent, String name) throws InvalidObjectException { private JsonNode getNotNullNode(JsonNode parent, String name) throws InvalidObjectException {
@ -129,7 +130,7 @@ class Manager implements TextSecure {
} else { } else {
nextSignedPreKeyId = 0; nextSignedPreKeyId = 0;
} }
axolotlStore = jsonProcessot.convertValue(getNotNullNode(rootNode, "axolotlStore"), JsonAxolotlStore.class); //new JsonAxolotlStore(in.getJSONObject("axolotlStore")); signalProtocolStore = jsonProcessot.convertValue(getNotNullNode(rootNode, "axolotlStore"), JsonSignalProtocolStore.class);
registered = getNotNullNode(rootNode, "registered").asBoolean(); registered = getNotNullNode(rootNode, "registered").asBoolean();
JsonNode groupStoreNode = rootNode.get("groupStore"); JsonNode groupStoreNode = rootNode.get("groupStore");
if (groupStoreNode != null) { if (groupStoreNode != null) {
@ -149,7 +150,7 @@ class Manager implements TextSecure {
.put("preKeyIdOffset", preKeyIdOffset) .put("preKeyIdOffset", preKeyIdOffset)
.put("nextSignedPreKeyId", nextSignedPreKeyId) .put("nextSignedPreKeyId", nextSignedPreKeyId)
.put("registered", registered) .put("registered", registered)
.putPOJO("axolotlStore", axolotlStore) .putPOJO("axolotlStore", signalProtocolStore)
.putPOJO("groupStore", groupStore) .putPOJO("groupStore", groupStore)
; ;
try { try {
@ -162,7 +163,7 @@ class Manager implements TextSecure {
public void createNewIdentity() { public void createNewIdentity() {
IdentityKeyPair identityKey = KeyHelper.generateIdentityKeyPair(); IdentityKeyPair identityKey = KeyHelper.generateIdentityKeyPair();
int registrationId = KeyHelper.generateRegistrationId(false); int registrationId = KeyHelper.generateRegistrationId(false);
axolotlStore = new JsonAxolotlStore(identityKey, registrationId); signalProtocolStore = new JsonSignalProtocolStore(identityKey, registrationId);
groupStore = new JsonGroupStore(); groupStore = new JsonGroupStore();
registered = false; registered = false;
save(); save();
@ -196,7 +197,7 @@ class Manager implements TextSecure {
ECKeyPair keyPair = Curve.generateKeyPair(); ECKeyPair keyPair = Curve.generateKeyPair();
PreKeyRecord record = new PreKeyRecord(preKeyId, keyPair); PreKeyRecord record = new PreKeyRecord(preKeyId, keyPair);
axolotlStore.storePreKey(preKeyId, record); signalProtocolStore.storePreKey(preKeyId, record);
records.add(record); records.add(record);
} }
@ -207,18 +208,18 @@ class Manager implements TextSecure {
} }
private PreKeyRecord generateLastResortPreKey() { private PreKeyRecord generateLastResortPreKey() {
if (axolotlStore.containsPreKey(Medium.MAX_VALUE)) { if (signalProtocolStore.containsPreKey(Medium.MAX_VALUE)) {
try { try {
return axolotlStore.loadPreKey(Medium.MAX_VALUE); return signalProtocolStore.loadPreKey(Medium.MAX_VALUE);
} catch (InvalidKeyIdException e) { } catch (InvalidKeyIdException e) {
axolotlStore.removePreKey(Medium.MAX_VALUE); signalProtocolStore.removePreKey(Medium.MAX_VALUE);
} }
} }
ECKeyPair keyPair = Curve.generateKeyPair(); ECKeyPair keyPair = Curve.generateKeyPair();
PreKeyRecord record = new PreKeyRecord(Medium.MAX_VALUE, keyPair); PreKeyRecord record = new PreKeyRecord(Medium.MAX_VALUE, keyPair);
axolotlStore.storePreKey(Medium.MAX_VALUE, record); signalProtocolStore.storePreKey(Medium.MAX_VALUE, record);
save(); save();
return record; return record;
@ -230,7 +231,7 @@ class Manager implements TextSecure {
byte[] signature = Curve.calculateSignature(identityKeyPair.getPrivateKey(), keyPair.getPublicKey().serialize()); byte[] signature = Curve.calculateSignature(identityKeyPair.getPrivateKey(), keyPair.getPublicKey().serialize());
SignedPreKeyRecord record = new SignedPreKeyRecord(nextSignedPreKeyId, System.currentTimeMillis(), keyPair, signature); SignedPreKeyRecord record = new SignedPreKeyRecord(nextSignedPreKeyId, System.currentTimeMillis(), keyPair, signature);
axolotlStore.storeSignedPreKey(nextSignedPreKeyId, record); signalProtocolStore.storeSignedPreKey(nextSignedPreKeyId, record);
nextSignedPreKeyId = (nextSignedPreKeyId + 1) % Medium.MAX_VALUE; nextSignedPreKeyId = (nextSignedPreKeyId + 1) % Medium.MAX_VALUE;
save(); save();
@ -243,7 +244,7 @@ class Manager implements TextSecure {
public void verifyAccount(String verificationCode) throws IOException { public void verifyAccount(String verificationCode) throws IOException {
verificationCode = verificationCode.replace("-", ""); verificationCode = verificationCode.replace("-", "");
signalingKey = Util.getSecret(52); signalingKey = Util.getSecret(52);
accountManager.verifyAccountWithCode(verificationCode, signalingKey, axolotlStore.getLocalRegistrationId(), false, true); accountManager.verifyAccountWithCode(verificationCode, signalingKey, signalProtocolStore.getLocalRegistrationId(), false, true);
//accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID))); //accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID)));
registered = true; registered = true;
@ -252,9 +253,9 @@ class Manager implements TextSecure {
PreKeyRecord lastResortKey = generateLastResortPreKey(); PreKeyRecord lastResortKey = generateLastResortPreKey();
SignedPreKeyRecord signedPreKeyRecord = generateSignedPreKey(axolotlStore.getIdentityKeyPair()); SignedPreKeyRecord signedPreKeyRecord = generateSignedPreKey(signalProtocolStore.getIdentityKeyPair());
accountManager.setPreKeys(axolotlStore.getIdentityKeyPair().getPublicKey(), lastResortKey, signedPreKeyRecord, oneTimePreKeys); accountManager.setPreKeys(signalProtocolStore.getIdentityKeyPair().getPublicKey(), lastResortKey, signedPreKeyRecord, oneTimePreKeys);
save(); save();
} }
@ -397,7 +398,7 @@ class Manager implements TextSecure {
private void sendMessage(SignalServiceDataMessage message, Collection<String> recipients) private void sendMessage(SignalServiceDataMessage message, Collection<String> recipients)
throws IOException, EncapsulatedExceptions { throws IOException, EncapsulatedExceptions {
SignalServiceMessageSender messageSender = new SignalServiceMessageSender(URL, TRUST_STORE, username, password, SignalServiceMessageSender messageSender = new SignalServiceMessageSender(URL, TRUST_STORE, username, password,
axolotlStore, USER_AGENT, Optional.<SignalServiceMessageSender.EventListener>absent()); signalProtocolStore, USER_AGENT, Optional.<SignalServiceMessageSender.EventListener>absent());
Set<SignalServiceAddress> recipientsTS = new HashSet<>(recipients.size()); Set<SignalServiceAddress> recipientsTS = new HashSet<>(recipients.size());
for (String recipient : recipients) { for (String recipient : recipients) {
@ -422,7 +423,7 @@ class Manager implements TextSecure {
} }
private SignalServiceContent decryptMessage(SignalServiceEnvelope envelope) { private SignalServiceContent decryptMessage(SignalServiceEnvelope envelope) {
SignalServiceCipher cipher = new SignalServiceCipher(new SignalServiceAddress(username), axolotlStore); SignalServiceCipher cipher = new SignalServiceCipher(new SignalServiceAddress(username), signalProtocolStore);
try { try {
return cipher.decrypt(envelope); return cipher.decrypt(envelope);
} catch (Exception e) { } catch (Exception e) {
@ -433,7 +434,7 @@ class Manager implements TextSecure {
} }
private void handleEndSession(String source) { private void handleEndSession(String source) {
axolotlStore.deleteAllSessions(source); signalProtocolStore.deleteAllSessions(source);
} }
public interface ReceiveMessageHandler { public interface ReceiveMessageHandler {