mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-23 19:26:17 +00:00
Rename 'device key' to 'signed prekey'.
This commit is contained in:
@@ -4,5 +4,4 @@ public class Release {
|
||||
|
||||
public static final String PUSH_URL = "https://textsecure-service.whispersystems.org";
|
||||
// public static final String PUSH_URL = "http://192.168.1.135:8080";
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.thoughtcrime.securesms.sms.OutgoingKeyExchangeMessage;
|
||||
import org.thoughtcrime.securesms.util.Dialogs;
|
||||
import org.whispersystems.libaxolotl.SessionBuilder;
|
||||
import org.whispersystems.libaxolotl.protocol.KeyExchangeMessage;
|
||||
import org.whispersystems.libaxolotl.state.DeviceKeyStore;
|
||||
import org.whispersystems.libaxolotl.state.SignedPreKeyStore;
|
||||
import org.whispersystems.libaxolotl.state.IdentityKeyStore;
|
||||
import org.whispersystems.libaxolotl.state.PreKeyStore;
|
||||
import org.whispersystems.libaxolotl.state.SessionRecord;
|
||||
@@ -61,14 +61,14 @@ public class KeyExchangeInitiator {
|
||||
}
|
||||
|
||||
private static void initiateKeyExchange(Context context, MasterSecret masterSecret, Recipient recipient) {
|
||||
SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret);
|
||||
PreKeyStore preKeyStore = new TextSecurePreKeyStore(context, masterSecret);
|
||||
DeviceKeyStore deviceKeyStore = new TextSecurePreKeyStore(context, masterSecret);
|
||||
IdentityKeyStore identityKeyStore = new TextSecureIdentityKeyStore(context, masterSecret);
|
||||
SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret);
|
||||
PreKeyStore preKeyStore = new TextSecurePreKeyStore(context, masterSecret);
|
||||
SignedPreKeyStore signedPreKeyStore = new TextSecurePreKeyStore(context, masterSecret);
|
||||
IdentityKeyStore identityKeyStore = new TextSecureIdentityKeyStore(context, masterSecret);
|
||||
|
||||
SessionBuilder sessionBuilder = new SessionBuilder(sessionStore, preKeyStore, deviceKeyStore,
|
||||
identityKeyStore, recipient.getRecipientId(),
|
||||
RecipientDevice.DEFAULT_DEVICE_ID);
|
||||
SessionBuilder sessionBuilder = new SessionBuilder(sessionStore, preKeyStore, signedPreKeyStore,
|
||||
identityKeyStore, recipient.getRecipientId(),
|
||||
RecipientDevice.DEFAULT_DEVICE_ID);
|
||||
|
||||
KeyExchangeMessage keyExchangeMessage = sessionBuilder.process();
|
||||
String serializedMessage = Base64.encodeBytesWithoutPadding(keyExchangeMessage.serialize());
|
||||
|
||||
@@ -15,13 +15,12 @@ import org.whispersystems.libaxolotl.StaleKeyExchangeException;
|
||||
import org.whispersystems.libaxolotl.UntrustedIdentityException;
|
||||
import org.whispersystems.libaxolotl.protocol.KeyExchangeMessage;
|
||||
import org.whispersystems.libaxolotl.protocol.PreKeyWhisperMessage;
|
||||
import org.whispersystems.libaxolotl.state.DeviceKeyStore;
|
||||
import org.whispersystems.libaxolotl.state.SignedPreKeyStore;
|
||||
import org.whispersystems.libaxolotl.state.IdentityKeyStore;
|
||||
import org.whispersystems.libaxolotl.state.PreKeyBundle;
|
||||
import org.whispersystems.libaxolotl.state.PreKeyStore;
|
||||
import org.whispersystems.libaxolotl.state.SessionStore;
|
||||
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||
import org.whispersystems.textsecure.push.PreKeyEntity;
|
||||
import org.whispersystems.textsecure.storage.RecipientDevice;
|
||||
import org.whispersystems.textsecure.storage.TextSecurePreKeyStore;
|
||||
import org.whispersystems.textsecure.storage.TextSecureSessionStore;
|
||||
@@ -48,12 +47,12 @@ public class KeyExchangeProcessor {
|
||||
this.recipientDevice = recipientDevice;
|
||||
this.masterSecret = masterSecret;
|
||||
|
||||
IdentityKeyStore identityKeyStore = new TextSecureIdentityKeyStore(context, masterSecret);
|
||||
PreKeyStore preKeyStore = new TextSecurePreKeyStore(context, masterSecret);
|
||||
DeviceKeyStore deviceKeyStore = new TextSecurePreKeyStore(context, masterSecret);
|
||||
SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret);
|
||||
IdentityKeyStore identityKeyStore = new TextSecureIdentityKeyStore(context, masterSecret);
|
||||
PreKeyStore preKeyStore = new TextSecurePreKeyStore(context, masterSecret);
|
||||
SignedPreKeyStore signedPreKeyStore = new TextSecurePreKeyStore(context, masterSecret);
|
||||
SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret);
|
||||
|
||||
this.sessionBuilder = new SessionBuilder(sessionStore, preKeyStore, deviceKeyStore,
|
||||
this.sessionBuilder = new SessionBuilder(sessionStore, preKeyStore, signedPreKeyStore,
|
||||
identityKeyStore, recipientDevice.getRecipientId(),
|
||||
recipientDevice.getDeviceId());
|
||||
}
|
||||
|
||||
@@ -9,10 +9,9 @@ import android.util.Log;
|
||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
||||
import org.thoughtcrime.securesms.push.PushServiceSocketFactory;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.libaxolotl.IdentityKey;
|
||||
import org.whispersystems.libaxolotl.IdentityKeyPair;
|
||||
import org.whispersystems.libaxolotl.state.DeviceKeyRecord;
|
||||
import org.whispersystems.libaxolotl.state.DeviceKeyStore;
|
||||
import org.whispersystems.libaxolotl.state.SignedPreKeyRecord;
|
||||
import org.whispersystems.libaxolotl.state.SignedPreKeyStore;
|
||||
import org.whispersystems.libaxolotl.state.PreKeyRecord;
|
||||
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||
import org.whispersystems.textsecure.crypto.PreKeyUtil;
|
||||
@@ -69,7 +68,7 @@ public class PreKeyService extends Service {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
DeviceKeyRecord deviceKeyRecord = null;
|
||||
SignedPreKeyRecord signedPreKeyRecord = null;
|
||||
|
||||
try {
|
||||
if (!TextSecurePreferences.isPushRegistered(context)) return;
|
||||
@@ -86,38 +85,38 @@ public class PreKeyService extends Service {
|
||||
PreKeyRecord lastResortKeyRecord = PreKeyUtil.generateLastResortKey(context, masterSecret);
|
||||
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context, masterSecret);
|
||||
|
||||
deviceKeyRecord = PreKeyUtil.generateDeviceKey(context, masterSecret, identityKey);
|
||||
signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(context, masterSecret, identityKey);
|
||||
|
||||
Log.w(TAG, "Registering new prekeys...");
|
||||
|
||||
socket.registerPreKeys(identityKey.getPublicKey(), lastResortKeyRecord,
|
||||
deviceKeyRecord, preKeyRecords);
|
||||
signedPreKeyRecord, preKeyRecords);
|
||||
|
||||
removeOldDeviceKeysIfNecessary(deviceKeyRecord);
|
||||
removeOldSignedPreKeysIfNecessary(signedPreKeyRecord);
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
if (deviceKeyRecord != null) {
|
||||
Log.w(TAG, "Remote store failed, removing generated device key: " + deviceKeyRecord.getId());
|
||||
new TextSecurePreKeyStore(context, masterSecret).removeDeviceKey(deviceKeyRecord.getId());
|
||||
if (signedPreKeyRecord != null) {
|
||||
Log.w(TAG, "Remote store failed, removing generated device key: " + signedPreKeyRecord.getId());
|
||||
new TextSecurePreKeyStore(context, masterSecret).removeSignedPreKey(signedPreKeyRecord.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeOldDeviceKeysIfNecessary(DeviceKeyRecord currentDeviceKey) {
|
||||
DeviceKeyStore deviceKeyStore = new TextSecurePreKeyStore(context, masterSecret);
|
||||
List<DeviceKeyRecord> records = deviceKeyStore.loadDeviceKeys();
|
||||
Iterator<DeviceKeyRecord> iterator = records.iterator();
|
||||
private void removeOldSignedPreKeysIfNecessary(SignedPreKeyRecord currentSignedPreKey) {
|
||||
SignedPreKeyStore signedPreKeyStore = new TextSecurePreKeyStore(context, masterSecret);
|
||||
List<SignedPreKeyRecord> records = signedPreKeyStore.loadSignedPreKeys();
|
||||
Iterator<SignedPreKeyRecord> iterator = records.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
if (iterator.next().getId() == currentDeviceKey.getId()) {
|
||||
if (iterator.next().getId() == currentSignedPreKey.getId()) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
DeviceKeyRecord[] recordsArray = (DeviceKeyRecord[])records.toArray();
|
||||
Arrays.sort(recordsArray, new Comparator<DeviceKeyRecord>() {
|
||||
SignedPreKeyRecord[] recordsArray = (SignedPreKeyRecord[])records.toArray();
|
||||
Arrays.sort(recordsArray, new Comparator<SignedPreKeyRecord>() {
|
||||
@Override
|
||||
public int compare(DeviceKeyRecord lhs, DeviceKeyRecord rhs) {
|
||||
public int compare(SignedPreKeyRecord lhs, SignedPreKeyRecord rhs) {
|
||||
if (lhs.getTimestamp() < rhs.getTimestamp()) return -1;
|
||||
else if (lhs.getTimestamp() > rhs.getTimestamp()) return 1;
|
||||
else return 0;
|
||||
@@ -127,15 +126,15 @@ public class PreKeyService extends Service {
|
||||
Log.w(TAG, "Existing device key record count: " + recordsArray.length);
|
||||
|
||||
if (recordsArray.length > 3) {
|
||||
long oldTimestamp = System.currentTimeMillis() - (14 * 24 * 60 * 60 * 1000);
|
||||
DeviceKeyRecord[] oldRecords = Arrays.copyOf(recordsArray, recordsArray.length - 1);
|
||||
long oldTimestamp = System.currentTimeMillis() - (14 * 24 * 60 * 60 * 1000);
|
||||
SignedPreKeyRecord[] oldRecords = Arrays.copyOf(recordsArray, recordsArray.length - 1);
|
||||
|
||||
for (DeviceKeyRecord oldRecord : oldRecords) {
|
||||
for (SignedPreKeyRecord oldRecord : oldRecords) {
|
||||
Log.w(TAG, "Old device key record timestamp: " + oldRecord.getTimestamp());
|
||||
|
||||
if (oldRecord.getTimestamp() <= oldTimestamp) {
|
||||
Log.w(TAG, "Remove device key record: " + oldRecord.getId());
|
||||
deviceKeyStore.removeDeviceKey(oldRecord.getId());
|
||||
signedPreKeyStore.removeSignedPreKey(oldRecord.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import org.thoughtcrime.securesms.push.PushServiceSocketFactory;
|
||||
import org.thoughtcrime.securesms.util.DirectoryHelper;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.libaxolotl.IdentityKeyPair;
|
||||
import org.whispersystems.libaxolotl.state.DeviceKeyRecord;
|
||||
import org.whispersystems.libaxolotl.state.SignedPreKeyRecord;
|
||||
import org.whispersystems.libaxolotl.state.PreKeyRecord;
|
||||
import org.whispersystems.libaxolotl.util.KeyHelper;
|
||||
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||
@@ -228,11 +228,11 @@ public class RegistrationService extends Service {
|
||||
throws IOException
|
||||
{
|
||||
setState(new RegistrationState(RegistrationState.STATE_GENERATING_KEYS, number));
|
||||
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(this, masterSecret);
|
||||
List<PreKeyRecord> records = PreKeyUtil.generatePreKeys(this, masterSecret);
|
||||
PreKeyRecord lastResort = PreKeyUtil.generateLastResortKey(this, masterSecret);
|
||||
DeviceKeyRecord deviceKey = PreKeyUtil.generateDeviceKey(this, masterSecret, identityKey);
|
||||
socket.registerPreKeys(identityKey.getPublicKey(), lastResort, deviceKey, records);
|
||||
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(this, masterSecret);
|
||||
List<PreKeyRecord> records = PreKeyUtil.generatePreKeys(this, masterSecret);
|
||||
PreKeyRecord lastResort = PreKeyUtil.generateLastResortKey(this, masterSecret);
|
||||
SignedPreKeyRecord signedPreKey = PreKeyUtil.generateSignedPreKey(this, masterSecret, identityKey);
|
||||
socket.registerPreKeys(identityKey.getPublicKey(), lastResort, signedPreKey, records);
|
||||
|
||||
setState(new RegistrationState(RegistrationState.STATE_GCM_REGISTERING, number));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user