Add special handling for verification sync
processVerifiedMessage checks the current state of the database against the identity key from an incoming verification sync message to determine whether or how to update our local record. When syncing a DEFAULT status and we have no local record, it's a no-op, but we'll log it. When syncing a DEFAULT status and we have non-default record with the same key, mark it as default. When syncing a VERIFIED status and either: 1. we have no key on record, 2. we have have a different key on record, or 3. we have the same key on record, but not verified mark it as verified. Otherwise do nothing. References: https://github.com/WhisperSystems/Signal-Android/blob/master/src/org/thoughtcrime/securesms/util/IdentityUtil.java#L129 // FREEBIE Ensure processVerified resolves
This commit is contained in:
parent
c60919ca0e
commit
1614a6f1b8
1 changed files with 50 additions and 0 deletions
|
@ -555,6 +555,56 @@
|
|||
});
|
||||
});
|
||||
},
|
||||
processVerifiedMessage: function(identifier, verifiedStatus, publicKey) {
|
||||
if (identifier === null || identifier === undefined) {
|
||||
throw new Error("Tried to set verified for undefined/null key");
|
||||
}
|
||||
if (!validateVerifiedStatus(verifiedStatus)) {
|
||||
throw new Error("Invalid verified status");
|
||||
}
|
||||
if (publicKey !== undefined && !(publicKey instanceof ArrayBuffer)) {
|
||||
throw new Error("Invalid public key");
|
||||
}
|
||||
return new Promise(function(resolve, reject) {
|
||||
var identityRecord = new IdentityRecord({id: identifier});
|
||||
var isPresent = false;
|
||||
var isEqual = false;
|
||||
identityRecord.fetch().then(function() {
|
||||
isPresent = true;
|
||||
if (publicKey) {
|
||||
isEqual = equalArrayBuffers(publicKey, identityRecord.get('publicKey'));
|
||||
}
|
||||
}).always(function() {
|
||||
if (!isPresent && verifiedStatus === VerifiedStatus.DEFAULT) {
|
||||
console.log('No existing record for default status');
|
||||
resolve();
|
||||
}
|
||||
|
||||
if (isPresent && isEqual
|
||||
&& identityRecord.get('verified') !== VerifiedStatus.DEFAULT
|
||||
&& verifiedStatus === VerifiedStatus.DEFAULT) {
|
||||
|
||||
textsecure.storage.protocol.setVerified(
|
||||
identifier, verifiedStatus, publicKey
|
||||
).then(resolve, reject);
|
||||
}
|
||||
|
||||
if (verifiedStatus === VerifiedStatus.VERIFIED
|
||||
&& (!isPresent
|
||||
|| (isPresent && !isEqual)
|
||||
|| (isPresent && identityRecord.get('verified') !== VerifiedStatus.VERIFIED))) {
|
||||
|
||||
textsecure.storage.protocol.saveIdentityWithAttributes(identifier, {
|
||||
publicKey : publicKey,
|
||||
verified : verifiedStatus,
|
||||
firstUse : false,
|
||||
timestamp : Date.now(),
|
||||
nonblockingApproval : true
|
||||
}).then(resolve, reject);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
isUntrusted: function(identifier) {
|
||||
if (identifier === null || identifier === undefined) {
|
||||
throw new Error("Tried to set verified for undefined/null key");
|
||||
|
|
Loading…
Add table
Reference in a new issue