Update isTrustedIdentity for directional trust
// FREEBIE
This commit is contained in:
parent
4e4aedd4ba
commit
1b9eb83422
1 changed files with 43 additions and 16 deletions
|
@ -4,6 +4,10 @@
|
||||||
;(function() {
|
;(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
var TIMESTAMP_THRESHOLD = 5 * 1000; // 5 seconds
|
var TIMESTAMP_THRESHOLD = 5 * 1000; // 5 seconds
|
||||||
|
var Direction = {
|
||||||
|
SENDING: 1,
|
||||||
|
RECEIVING: 2,
|
||||||
|
};
|
||||||
|
|
||||||
var StaticByteBufferProto = new dcodeIO.ByteBuffer().__proto__;
|
var StaticByteBufferProto = new dcodeIO.ByteBuffer().__proto__;
|
||||||
var StaticArrayBufferProto = new ArrayBuffer().__proto__;
|
var StaticArrayBufferProto = new ArrayBuffer().__proto__;
|
||||||
|
@ -281,28 +285,50 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
isTrustedIdentity: function(identifier, publicKey) {
|
isTrustedIdentity: function(identifier, publicKey, direction) {
|
||||||
if (identifier === null || identifier === undefined) {
|
if (identifier === null || identifier === undefined) {
|
||||||
throw new Error("Tried to get identity key for undefined/null key");
|
throw new Error("Tried to get identity key for undefined/null key");
|
||||||
}
|
}
|
||||||
var number = textsecure.utils.unencodeNumber(identifier)[0];
|
var number = textsecure.utils.unencodeNumber(identifier)[0];
|
||||||
return new Promise(function(resolve) {
|
var isOurNumber = number === textsecure.storage.user.getNumber();
|
||||||
var identityKey = new IdentityKey({id: number});
|
var identityKey = new IdentityKey({id: number});
|
||||||
identityKey.fetch().always(function() {
|
return new Promise(function(resolve) {
|
||||||
var oldpublicKey = identityKey.get('publicKey');
|
identityKey.fetch().always(resolve);
|
||||||
if (!oldpublicKey || equalArrayBuffers(oldpublicKey, publicKey)) {
|
}).then(function() {
|
||||||
resolve(true);
|
var existing = identityKey.get('publicKey');
|
||||||
} else if (!storage.get('safety-numbers-approval', true)) {
|
|
||||||
this.saveIdentity(identifier, publicKey).then(function() {
|
if (isOurNumber) {
|
||||||
console.log('Key changed for', identifier);
|
return equalArrayBuffers(existing, publicKey);
|
||||||
this.trigger('keychange', identifier);
|
}
|
||||||
resolve(true);
|
|
||||||
}.bind(this));
|
switch(direction) {
|
||||||
} else {
|
case Direction.SENDING: return this.isTrustedForSending(publicKey, identityKey);
|
||||||
resolve(false);
|
case Direction.RECEIVING: return true;
|
||||||
|
default: throw new Error("Unknown direction: " + direction);
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this));
|
},
|
||||||
|
isTrustedForSending: function(publicKey, identityKey) {
|
||||||
|
var existing = identityKey.get('publicKey');
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
console.log("isTrustedForSending: Nothing here, returning true...");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!equalArrayBuffers(existing, publicKey)) {
|
||||||
|
console.log("isTrustedForSending: Identity keys don't match...");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.isBlockingApprovalRequired(identityKey)) {
|
||||||
|
console.log("isTrustedForSending: Needs blocking approval!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.isNonBlockingApprovalRequired(identityKey)) {
|
||||||
|
console.log("isTrustedForSending: Needs non-blocking approval!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
},
|
},
|
||||||
loadIdentityKey: function(identifier) {
|
loadIdentityKey: function(identifier) {
|
||||||
if (identifier === null || identifier === undefined) {
|
if (identifier === null || identifier === undefined) {
|
||||||
|
@ -424,4 +450,5 @@
|
||||||
_.extend(SignalProtocolStore.prototype, Backbone.Events);
|
_.extend(SignalProtocolStore.prototype, Backbone.Events);
|
||||||
|
|
||||||
window.SignalProtocolStore = SignalProtocolStore;
|
window.SignalProtocolStore = SignalProtocolStore;
|
||||||
|
window.SignalProtocolStore.prototype.Direction = Direction;
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue