From b93042f12fc1a4eeac63b8ddca72a5cfd285761e Mon Sep 17 00:00:00 2001 From: lilia Date: Mon, 12 Jun 2017 12:55:16 -0700 Subject: [PATCH] Add verified status // FREEBIE --- js/database.js | 1 + js/signal_protocol_store.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/js/database.js b/js/database.js index 6cb1454fa..1126e62d8 100644 --- a/js/database.js +++ b/js/database.js @@ -233,6 +233,7 @@ attributes.timestamp = 0; attributes.firstUse = false; attributes.nonblockingApproval = false; + attributes.verified = 0; attributes.seen = 0; promises.push(new Promise(function(resolve, reject) { var putRequest = identityKeys.put(attributes, attributes.id); diff --git a/js/signal_protocol_store.js b/js/signal_protocol_store.js index 606f705c6..f3509b216 100644 --- a/js/signal_protocol_store.js +++ b/js/signal_protocol_store.js @@ -9,6 +9,12 @@ RECEIVING: 2, }; + var VerifiedStatus = { + DEFAULT: 0, + VERIFIED: 1, + UNVERIFIED: 2, + }; + var StaticByteBufferProto = new dcodeIO.ByteBuffer().__proto__; var StaticArrayBufferProto = new ArrayBuffer().__proto__; var StaticUint8ArrayProto = new Uint8Array().__proto__; @@ -319,6 +325,10 @@ console.log("isTrustedForSending: Identity keys don't match..."); return false; } + if (identityKey.get('verified') === VerifiedStatus.UNVERIFIED) { + console.log("Needs unverified approval!"); + return false; + } if (this.isNonBlockingApprovalRequired(identityKey)) { console.log("isTrustedForSending: Needs non-blocking approval!"); return false; @@ -357,16 +367,24 @@ publicKey : publicKey, firstUse : true, timestamp : Date.now(), + verified : VerifiedStatus.DEFAULT, nonblockingApproval : nonblockingApproval, }).then(function() { resolve(false); }); } else if (!equalArrayBuffers(oldpublicKey, publicKey)) { console.log("Replacing existing identity..."); + var verifiedStatus; + if (identityKey.get('verified') === VerifiedStatus.VERIFIED) { + verifiedStatus = VerifiedStatus.UNVERIFIED; + } else { + verifiedStatus = VerifiedStatus.DEFAULT; + } identityKey.save({ publicKey : publicKey, firstUse : false, timestamp : Date.now(), + verified : verifiedStatus, nonblockingApproval : nonblockingApproval, }).then(function() { this.trigger('keychange', identifier); @@ -439,4 +457,5 @@ window.SignalProtocolStore = SignalProtocolStore; window.SignalProtocolStore.prototype.Direction = Direction; + window.SignalProtocolStore.prototype.VerifiedStatus = VerifiedStatus; })();