diff --git a/js/signal_protocol_store.js b/js/signal_protocol_store.js index 26cbd108..9ef385b9 100644 --- a/js/signal_protocol_store.js +++ b/js/signal_protocol_store.js @@ -250,6 +250,19 @@ }); }, + isTrustedIdentity: function(identifier, publicKey) { + if (identifier === null || identifier === undefined) { + throw new Error("Tried to get identity key for undefined/null key"); + } + var number = textsecure.utils.unencodeNumber(identifier)[0]; + return new Promise(function(resolve) { + var identityKey = new IdentityKey({id: number}); + identityKey.fetch().always(function() { + var oldpublicKey = identityKey.get('publicKey'); + resolve(!oldpublicKey || equalArrayBuffers(oldpublicKey, publicKey)); + }); + }); + }, loadIdentityKey: function(identifier) { if (identifier === null || identifier === undefined) { throw new Error("Tried to get identity key for undefined/null key"); diff --git a/libtextsecure/test/in_memory_signal_protocol_store.js b/libtextsecure/test/in_memory_signal_protocol_store.js index 84039ac9..8cfe2561 100644 --- a/libtextsecure/test/in_memory_signal_protocol_store.js +++ b/libtextsecure/test/in_memory_signal_protocol_store.js @@ -29,6 +29,19 @@ SignalProtocolStore.prototype = { delete this.store[key]; }, + isTrustedIdentity: function(identifier, identityKey) { + if (identifier === null || identifier === undefined) { + throw new error("tried to check identity key for undefined/null key"); + } + if (!(identityKey instanceof ArrayBuffer)) { + throw new error("Expected identityKey to be an ArrayBuffer"); + } + var trusted = this.get('identityKey' + identifier); + if (trusted === undefined) { + return Promise.resolve(true); + } + return Promise.resolve(identityKey === trusted); + }, loadIdentityKey: function(identifier) { if (identifier === null || identifier === undefined) throw new Error("Tried to get identity key for undefined/null key");