Move to the real verify/trust APIs

This wires up verification sync messages, verification and trust checks
to the trust store instead of using mocked data.

FREEBIE
pull/749/head
Scott Nonnenberg 8 years ago
parent 52481d1d13
commit c43d96904d

@ -119,7 +119,7 @@
messageReceiver.addEventListener('group', onGroupReceived); messageReceiver.addEventListener('group', onGroupReceived);
messageReceiver.addEventListener('sent', onSentMessage); messageReceiver.addEventListener('sent', onSentMessage);
messageReceiver.addEventListener('read', onReadReceipt); messageReceiver.addEventListener('read', onReadReceipt);
messageReceiver.addEventListener('verification', onVerify); messageReceiver.addEventListener('verification', onVerification);
messageReceiver.addEventListener('error', onError); messageReceiver.addEventListener('error', onError);
@ -291,23 +291,33 @@
}); });
} }
var VERIFIED_ENUM = textsecure.storage.protocol.VerifiedStatus; function onVerification(ev) {
function onVerify(ev) {
var number = ev.destination; var number = ev.destination;
var key = ev.identityKey; 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); var contact = ConversationController.get(number);
if (!contact) { if (!contact) {
return; return;
} }
if (verified === VERIFIED_ENUM.DEFAULT) { if (state === 'DEFAULT') {
contact.setVerifiedDefault({viaSyncMessage: true, key: key}); contact.setVerifiedDefault({viaSyncMessage: true, key: key});
} else if (verified === VERIFIED_ENUM.VERIFIED) { } else if (state === 'VERIFIED') {
contact.setVerified({viaSyncMessage: true, key: key}); contact.setVerified({viaSyncMessage: true, key: key});
} }
} }

@ -38,12 +38,7 @@
initialize: function() { initialize: function() {
this.ourNumber = textsecure.storage.user.getNumber(); this.ourNumber = textsecure.storage.user.getNumber();
// this.verifiedEnum = textsecure.storage.protocol.VerifiedStatus; this.verifiedEnum = textsecure.storage.protocol.VerifiedStatus;
this.verifiedEnum = {
DEFAULT: 0,
VERIFIED: 1,
UNVERIFIED: 2,
};
this.contactCollection = new Backbone.Collection(); this.contactCollection = new Backbone.Collection();
this.messageCollection = new Whisper.MessageCollection([], { this.messageCollection = new Whisper.MessageCollection([], {
@ -61,14 +56,9 @@
}, },
updateVerified: function() { updateVerified: function() {
function checkTrustStore(value) {
return Promise.resolve(value);
}
if (this.isPrivate()) { if (this.isPrivate()) {
return Promise.all([ return Promise.all([
//textsecure.storage.protocol.getVerified(this.id), textsecure.storage.protocol.getVerified(this.id),
checkTrustStore(this.verifiedEnum.UNVERIFIED),
this.fetch() this.fetch()
]).then(function(results) { ]).then(function(results) {
var trust = results[0]; var trust = results[0];
@ -94,11 +84,7 @@
} }
var DEFAULT = this.verifiedEnum.DEFAULT; var DEFAULT = this.verifiedEnum.DEFAULT;
// return textsecure.storage.protocol.setVerified(this.id, DEFAULT, options.key).then(function() { 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 this.save({verified: DEFAULT}); return this.save({verified: DEFAULT});
}.bind(this)).then(function() { }.bind(this)).then(function() {
this.addVerifiedChange(this.id, false); this.addVerifiedChange(this.id, false);
@ -118,11 +104,7 @@
'You must verify individual contacts.'); 'You must verify individual contacts.');
} }
// return textsecure.storage.protocol.setVerified(this.id, VERIFIED, options.key).then(function() { 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 this.save({verified: VERIFIED}); return this.save({verified: VERIFIED});
}.bind(this)).then(function() { }.bind(this)).then(function() {
this.addVerifiedChange(this.id, true); this.addVerifiedChange(this.id, true);
@ -132,9 +114,9 @@
}.bind(this)); }.bind(this));
}, },
sendVerifySyncMessage: function(number, state) { sendVerifySyncMessage: function(number, state) {
// textsecure.storage.protocol.loadIdentityKey(number).then(function(key) { textsecure.storage.protocol.loadIdentityKey(number).then(function(key) {
// textsecure.storage.protocol.sendVerifySync(number, state, key); textsecure.storage.protocol.syncVerification(number, state, key);
// }); });
}, },
isVerified: function() { isVerified: function() {
if (this.isPrivate()) { if (this.isPrivate()) {
@ -186,11 +168,7 @@
}, },
isUntrusted: function() { isUntrusted: function() {
if (this.isPrivate()) { if (this.isPrivate()) {
// return textsecure.storage.protocol.isUntrusted(this.id); return textsecure.storage.protocol.isUntrusted(this.id);
function getFromTrustStore() {
return Promise.resolve(true);
}
return getFromTrustStore(this.id);
} else { } else {
if (!this.contactCollection.length) { if (!this.contactCollection.length) {
return Promise.resolve(false); return Promise.resolve(false);

Loading…
Cancel
Save