mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-25 19:29:54 +01:00
Add last resort key and signaling key.
This commit is contained in:
@@ -24,6 +24,7 @@ import org.whispersystems.textsecure.crypto.KeyPair;
|
||||
import org.whispersystems.textsecure.crypto.KeyUtil;
|
||||
import org.whispersystems.textsecure.crypto.MasterCipher;
|
||||
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||
import org.whispersystems.textsecure.util.Medium;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -65,7 +66,8 @@ public class LocalKeyRecord extends Record {
|
||||
Log.w("LocalKeyRecord", "Remote client acknowledges receiving key id: " + keyId);
|
||||
if (keyId == localNextKeyPair.getId()) {
|
||||
this.localCurrentKeyPair = this.localNextKeyPair;
|
||||
this.localNextKeyPair = new KeyPair(this.localNextKeyPair.getId()+1, KeyUtil.generateKeyPair(), masterSecret);
|
||||
this.localNextKeyPair = new KeyPair((this.localNextKeyPair.getId()+1) % Medium.MAX_VALUE,
|
||||
KeyUtil.generateKeyPair(), masterSecret);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.util.Log;
|
||||
import org.whispersystems.textsecure.crypto.InvalidKeyException;
|
||||
import org.whispersystems.textsecure.crypto.PublicKey;
|
||||
import org.whispersystems.textsecure.util.Hex;
|
||||
import org.whispersystems.textsecure.util.Medium;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -62,7 +63,7 @@ public class RemoteKeyRecord extends Record {
|
||||
|
||||
public void updateCurrentRemoteKey(PublicKey remoteKey) {
|
||||
Log.w("RemoteKeyRecord", "Updating current remote key: " + remoteKey.getId());
|
||||
if (remoteKey.getId() > remoteKeyCurrent.getId()) {
|
||||
if (isWrappingGreaterThan(remoteKey.getId(), remoteKeyCurrent.getId())) {
|
||||
this.remoteKeyLast = this.remoteKeyCurrent;
|
||||
this.remoteKeyCurrent = remoteKey;
|
||||
}
|
||||
@@ -112,6 +113,20 @@ public class RemoteKeyRecord extends Record {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isWrappingGreaterThan(int receivedValue, int currentValue) {
|
||||
if (receivedValue > currentValue) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (receivedValue == currentValue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int gap = (receivedValue - currentValue) + Medium.MAX_VALUE;
|
||||
|
||||
return (gap >= 0) && (gap < 5);
|
||||
}
|
||||
|
||||
private void loadData() {
|
||||
Log.w("RemoteKeyRecord", "Loading remote key record for recipient: " + this.address);
|
||||
synchronized (FILE_LOCK) {
|
||||
|
||||
Reference in New Issue
Block a user