Handle UNVERIFIED sync verification messages (via contact sync)

FREEBIE
This commit is contained in:
Scott Nonnenberg 2017-06-28 16:39:55 -10:00
parent 20451cc827
commit f654532fa8
4 changed files with 267 additions and 114 deletions

View file

@ -321,10 +321,12 @@
key: key
};
if (state === 'DEFAULT') {
contact.setVerifiedDefault(options);
} else if (state === 'VERIFIED') {
if (state === 'VERIFIED') {
contact.setVerified(options);
} else if (state === 'DEFAULT') {
contact.setVerifiedDefault(options);
} else {
contact.setUnverified(options);
}
}

View file

@ -92,12 +92,19 @@
return this._setVerified(VERIFIED, options);
}.bind(this));
},
setUnverified: function(options) {
var UNVERIFIED = this.verifiedEnum.UNVERIFIED;
return this.queueJob(function() {
return this._setVerified(UNVERIFIED, options);
}.bind(this));
},
_setVerified: function(verified, options) {
options = options || {};
_.defaults(options, {viaSyncMessage: false, viaContactSync: false, key: null});
var VERIFIED = this.verifiedEnum.VERIFIED;
var DEFAULT = this.verifiedEnum.DEFAULT;
var VERIFIED = this.verifiedEnum.VERIFIED;
var UNVERIFIED = this.verifiedEnum.UNVERIFIED;
if (!this.isPrivate()) {
throw new Error('You cannot verify a group conversation. ' +
@ -127,12 +134,13 @@
// 1) The message came from an explicit verification in another client (not
// a contact sync)
// 2) The verification value received by the contact sync is different
// from what we have on record
// 3) Our local verification status is not DEFAULT and it hasn't changed,
// but the key did change (say from Key1/Verified to Key2/Verified)
// from what we have on record (and it's not a transition to UNVERIFIED)
// 3) Our local verification status is VERIFIED and it hasn't changed,
// but the key did change (Key1/VERIFIED to Key2/VERIFIED - but we don't
// want to show DEFAULT->DEFAULT or UNVERIFIED->UNVERIFIED)
if (!options.viaContactSync
|| beginningVerified !== verified
|| (keychange && verified !== DEFAULT)) {
|| (beginningVerified !== verified && verified !== UNVERIFIED)
|| (keychange && verified === VERIFIED)) {
var local = !options.viaSyncMessage && !options.viaContactSync;
this.addVerifiedChange(this.id, verified === VERIFIED, {local: local});

View file

@ -579,6 +579,7 @@
});
});
},
// Resolves to true if a new identity key was saved
processVerifiedMessage: function(identifier, verifiedStatus, publicKey) {
if (identifier === null || identifier === undefined) {
throw new Error("Tried to set verified for undefined/null key");
@ -599,26 +600,37 @@
isEqual = equalArrayBuffers(publicKey, identityRecord.get('publicKey'));
}
}).always(function() {
// Because new keys always start as DEFAULT, we don't need to create new record here
if (!isPresent && verifiedStatus === VerifiedStatus.DEFAULT) {
console.log('No existing record for default status');
resolve();
return resolve();
}
// If we had a key before and it's the same, and we're not changing to
// VERIFIED, then it's a simple update of the verified flag.
if (isPresent && isEqual
&& identityRecord.get('verified') !== VerifiedStatus.DEFAULT
&& verifiedStatus === VerifiedStatus.DEFAULT) {
&& identityRecord.get('verified') !== verifiedStatus
&& verifiedStatus !== VerifiedStatus.VERIFIED) {
textsecure.storage.protocol.setVerified(
return textsecure.storage.protocol.setVerified(
identifier, verifiedStatus, publicKey
).then(resolve, reject);
}
if (verifiedStatus === VerifiedStatus.VERIFIED
&& (!isPresent
|| (isPresent && !isEqual)
|| (isPresent && identityRecord.get('verified') !== VerifiedStatus.VERIFIED))) {
// We need to create a new record in three cases:
// 1. We had no key previously (checks above ensure that this is
// either VERIFIED/UNVERIFIED)
// 2. We had a key before, but we got a new key
// (no matter the VERIFIED state)
// 3. It's the same key, but we weren't VERIFIED before and are now
// (checks above handle the situation when 'state != VERIFIED')
if (!isPresent
|| (isPresent && !isEqual)
|| (isPresent
&& identityRecord.get('verified') !== verifiedStatus
&& verifiedStatus === VerifiedStatus.VERIFIED)) {
textsecure.storage.protocol.saveIdentityWithAttributes(identifier, {
return textsecure.storage.protocol.saveIdentityWithAttributes(identifier, {
publicKey : publicKey,
verified : verifiedStatus,
firstUse : false,
@ -636,6 +648,12 @@
return resolve();
}.bind(this), reject);
}
// The situation which could get us here is:
// 1. had a previous key
// 2. new key is the same
// 3. desired new status is same as what we had before
return resolve();
}.bind(this));
}.bind(this));
},