Add support for new safety numbers, that replace the hex fingerprint

This commit is contained in:
AsamK 2016-10-27 14:09:22 +02:00
parent 086bdb937a
commit f97b0c0faa
2 changed files with 74 additions and 12 deletions

View file

@ -31,6 +31,8 @@ import org.whispersystems.libsignal.*;
import org.whispersystems.libsignal.ecc.Curve;
import org.whispersystems.libsignal.ecc.ECKeyPair;
import org.whispersystems.libsignal.ecc.ECPublicKey;
import org.whispersystems.libsignal.fingerprint.Fingerprint;
import org.whispersystems.libsignal.fingerprint.NumericFingerprintGenerator;
import org.whispersystems.libsignal.state.PreKeyRecord;
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
import org.whispersystems.libsignal.util.KeyHelper;
@ -125,6 +127,10 @@ class Manager implements Signal {
return username;
}
private IdentityKey getIdentity() {
return signalProtocolStore.getIdentityKeyPair().getPublicKey();
}
public int getDeviceId() {
return deviceId;
}
@ -1330,6 +1336,29 @@ class Manager implements Signal {
return false;
}
/**
* Trust this the identity with this safety number
*
* @param name username of the identity
* @param safetyNumber Safety number
*/
public boolean trustIdentityVerifiedSafetyNumber(String name, String safetyNumber) {
List<JsonIdentityKeyStore.Identity> ids = signalProtocolStore.getIdentities(name);
if (ids == null) {
return false;
}
for (JsonIdentityKeyStore.Identity id : ids) {
if (!safetyNumber.equals(computeSafetyNumber(name, id.identityKey))) {
continue;
}
signalProtocolStore.saveIdentity(name, id.identityKey, TrustLevel.TRUSTED_VERIFIED);
save();
return true;
}
return false;
}
/**
* Trust all keys of this identity without verification
*
@ -1348,4 +1377,9 @@ class Manager implements Signal {
save();
return true;
}
public String computeSafetyNumber(String theirUsername, IdentityKey theirIdentityKey) {
Fingerprint fingerprint = new NumericFingerprintGenerator(5200).createFor(username, getIdentity(), theirUsername, theirIdentityKey);
return fingerprint.getDisplayableFingerprint().getDisplayText();
}
}