From 1614a6f1b8214002e4228b067464d3ec882f2e16 Mon Sep 17 00:00:00 2001 From: lilia Date: Fri, 16 Jun 2017 18:17:38 -0700 Subject: [PATCH] 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 --- js/signal_protocol_store.js | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/js/signal_protocol_store.js b/js/signal_protocol_store.js index c9f186b45..058bb5184 100644 --- a/js/signal_protocol_store.js +++ b/js/signal_protocol_store.js @@ -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");