Skip to content

Commit

Permalink
Move to the real verify/trust APIs
Browse files Browse the repository at this point in the history
This wires up verification sync messages, verification and trust checks
to the trust store instead of using mocked data.

FREEBIE
  • Loading branch information
scottnonnenberg committed Aug 4, 2017
1 parent 52481d1 commit c43d969
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 38 deletions.
26 changes: 18 additions & 8 deletions js/background.js
Expand Up @@ -119,7 +119,7 @@
messageReceiver.addEventListener('group', onGroupReceived);
messageReceiver.addEventListener('sent', onSentMessage);
messageReceiver.addEventListener('read', onReadReceipt);
messageReceiver.addEventListener('verification', onVerify);
messageReceiver.addEventListener('verification', onVerification);
messageReceiver.addEventListener('error', onError);


Expand Down Expand Up @@ -291,23 +291,33 @@
});
}

var VERIFIED_ENUM = textsecure.storage.protocol.VerifiedStatus;

function onVerify(ev) {
function onVerification(ev) {
var number = ev.destination;
var key = ev.identityKey;
var verified = ev.state;
var state;

console.log('got verification sync for', number, state);

console.log('verification sync message', number, verified);
switch(ev.state) {
case textsecure.protobuf.Verification.State.DEFAULT:
state = 'DEFAULT';
break;
case textsecure.protobuf.Verification.State.VERIFIED:
state = 'VERIFIED';
break;
case textsecure.protobuf.Verification.State.NO_LONGER_VERIFIED:
state = 'UNVERIFIED';
break;
}

var contact = ConversationController.get(number);
if (!contact) {
return;
}

if (verified === VERIFIED_ENUM.DEFAULT) {
if (state === 'DEFAULT') {
contact.setVerifiedDefault({viaSyncMessage: true, key: key});
} else if (verified === VERIFIED_ENUM.VERIFIED) {
} else if (state === 'VERIFIED') {
contact.setVerified({viaSyncMessage: true, key: key});
}
}
Expand Down
38 changes: 8 additions & 30 deletions js/models/conversations.js
Expand Up @@ -38,12 +38,7 @@

initialize: function() {
this.ourNumber = textsecure.storage.user.getNumber();
// this.verifiedEnum = textsecure.storage.protocol.VerifiedStatus;
this.verifiedEnum = {
DEFAULT: 0,
VERIFIED: 1,
UNVERIFIED: 2,
};
this.verifiedEnum = textsecure.storage.protocol.VerifiedStatus;

this.contactCollection = new Backbone.Collection();
this.messageCollection = new Whisper.MessageCollection([], {
Expand All @@ -61,14 +56,9 @@
},

updateVerified: function() {
function checkTrustStore(value) {
return Promise.resolve(value);
}

if (this.isPrivate()) {
return Promise.all([
//textsecure.storage.protocol.getVerified(this.id),
checkTrustStore(this.verifiedEnum.UNVERIFIED),
textsecure.storage.protocol.getVerified(this.id),
this.fetch()
]).then(function(results) {
var trust = results[0];
Expand All @@ -94,11 +84,7 @@
}
var DEFAULT = this.verifiedEnum.DEFAULT;

// return textsecure.storage.protocol.setVerified(this.id, DEFAULT, options.key).then(function() {
function updateTrustStore() {
return Promise.resolve();
}
return updateTrustStore(this.id, DEFAULT, options.key).then(function() {
return textsecure.storage.protocol.setVerified(this.id, DEFAULT, options.key).then(function() {
return this.save({verified: DEFAULT});
}.bind(this)).then(function() {
this.addVerifiedChange(this.id, false);
Expand All @@ -118,11 +104,7 @@
'You must verify individual contacts.');
}

// return textsecure.storage.protocol.setVerified(this.id, VERIFIED, options.key).then(function() {
function updateTrustStore() {
return Promise.resolve();
}
return updateTrustStore(this.id, VERIFIED, options.key).then(function() {
return textsecure.storage.protocol.setVerified(this.id, VERIFIED, options.key).then(function() {
return this.save({verified: VERIFIED});
}.bind(this)).then(function() {
this.addVerifiedChange(this.id, true);
Expand All @@ -132,9 +114,9 @@
}.bind(this));
},
sendVerifySyncMessage: function(number, state) {
// textsecure.storage.protocol.loadIdentityKey(number).then(function(key) {
// textsecure.storage.protocol.sendVerifySync(number, state, key);
// });
textsecure.storage.protocol.loadIdentityKey(number).then(function(key) {
textsecure.storage.protocol.syncVerification(number, state, key);
});
},
isVerified: function() {
if (this.isPrivate()) {
Expand Down Expand Up @@ -186,11 +168,7 @@
},
isUntrusted: function() {
if (this.isPrivate()) {
// return textsecure.storage.protocol.isUntrusted(this.id);
function getFromTrustStore() {
return Promise.resolve(true);
}
return getFromTrustStore(this.id);
return textsecure.storage.protocol.isUntrusted(this.id);
} else {
if (!this.contactCollection.length) {
return Promise.resolve(false);
Expand Down

0 comments on commit c43d969

Please sign in to comment.