From cc303e0802e9594c349a2f8930dd9c70608d3ab9 Mon Sep 17 00:00:00 2001 From: lilia Date: Mon, 20 Jul 2015 14:13:18 -0700 Subject: [PATCH] Update libaxolotl, handle untrusted identitykey Previously we had no access to the new untrusted identity for verification purposes. // FREEBIE --- js/libtextsecure.js | 13 ++++++++----- libtextsecure/axolotl_wrapper.js | 2 +- libtextsecure/errors.js | 3 ++- libtextsecure/libaxolotl.js | 8 +++++--- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 715d9df7..e063229e 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -44,7 +44,7 @@ return registeredFunctions[this.functionCode].apply(window, this.args); }; - function IncomingIdentityKeyError(number, message) { + function IncomingIdentityKeyError(number, message, key) { ReplayableError.call(this, { functionCode : Type.INIT_SESSION, args : [number, message] @@ -52,6 +52,7 @@ }); this.name = 'IncomingIdentityKeyError'; this.message = "The identity of the sender has changed. This may be malicious, or the sender may have simply reinstalled."; + this.identityKey = key; this.number = number.split('.')[0]; } IncomingIdentityKeyError.prototype = new ReplayableError(); @@ -37278,7 +37279,9 @@ window.axolotl.protocol = function(storage_interface) { closeSession(open_session); // To be returned and saved later } else { // ...otherwise create an error that the UI will pick up and ask the user if they want to re-negotiate - throw new Error('Unknown identity key'); + var e = new Error('Unknown identity key'); + e.identityKey = message.identityKey.toArrayBuffer(); + throw e; } } return initSession(false, preKeyPair, signedPreKeyPair, encodedNumber, axolotlInternal.utils.convertToArrayBuffer(message.identityKey), axolotlInternal.utils.convertToArrayBuffer(message.baseKey), undefined) @@ -37441,8 +37444,8 @@ window.axolotl.protocol = function(storage_interface) { } // Inits a session (maybe) and then decrypts the message - self.handlePreKeyWhisperMessage = function(from, encodedMessage) { - var preKeyProto = axolotlInternal.protobuf.PreKeyWhisperMessage.decode(encodedMessage); + self.handlePreKeyWhisperMessage = function(from, encodedMessage, encoding) { + var preKeyProto = axolotlInternal.protobuf.PreKeyWhisperMessage.decode(encodedMessage, encoding); return initSessionFromPreKeyWhisperMessage(from, preKeyProto).then(function(sessions) { return doDecryptWhisperMessage(from, axolotlInternal.utils.convertToString(preKeyProto.message), sessions[0], preKeyProto.registrationId).then(function(result) { if (sessions[1] !== undefined) @@ -37800,7 +37803,7 @@ axolotlInternal.RecipientRecord = function() { if (e.message === 'Unknown identity key') { // create an error that the UI will pick up and ask the // user if they want to re-negotiate - throw new textsecure.IncomingIdentityKeyError(fromAddress, blob); + throw new textsecure.IncomingIdentityKeyError(fromAddress, blob, e.identityKey); } throw e; }); diff --git a/libtextsecure/axolotl_wrapper.js b/libtextsecure/axolotl_wrapper.js index 63116b13..482a364b 100644 --- a/libtextsecure/axolotl_wrapper.js +++ b/libtextsecure/axolotl_wrapper.js @@ -21,7 +21,7 @@ if (e.message === 'Unknown identity key') { // create an error that the UI will pick up and ask the // user if they want to re-negotiate - throw new textsecure.IncomingIdentityKeyError(fromAddress, blob); + throw new textsecure.IncomingIdentityKeyError(fromAddress, blob, e.identityKey); } throw e; }); diff --git a/libtextsecure/errors.js b/libtextsecure/errors.js index 8091d4a6..907a03ec 100644 --- a/libtextsecure/errors.js +++ b/libtextsecure/errors.js @@ -43,7 +43,7 @@ return registeredFunctions[this.functionCode].apply(window, this.args); }; - function IncomingIdentityKeyError(number, message) { + function IncomingIdentityKeyError(number, message, key) { ReplayableError.call(this, { functionCode : Type.INIT_SESSION, args : [number, message] @@ -51,6 +51,7 @@ }); this.name = 'IncomingIdentityKeyError'; this.message = "The identity of the sender has changed. This may be malicious, or the sender may have simply reinstalled."; + this.identityKey = key; this.number = number.split('.')[0]; } IncomingIdentityKeyError.prototype = new ReplayableError(); diff --git a/libtextsecure/libaxolotl.js b/libtextsecure/libaxolotl.js index 0049b036..ff1fd83c 100644 --- a/libtextsecure/libaxolotl.js +++ b/libtextsecure/libaxolotl.js @@ -37201,7 +37201,9 @@ window.axolotl.protocol = function(storage_interface) { closeSession(open_session); // To be returned and saved later } else { // ...otherwise create an error that the UI will pick up and ask the user if they want to re-negotiate - throw new Error('Unknown identity key'); + var e = new Error('Unknown identity key'); + e.identityKey = message.identityKey.toArrayBuffer(); + throw e; } } return initSession(false, preKeyPair, signedPreKeyPair, encodedNumber, axolotlInternal.utils.convertToArrayBuffer(message.identityKey), axolotlInternal.utils.convertToArrayBuffer(message.baseKey), undefined) @@ -37364,8 +37366,8 @@ window.axolotl.protocol = function(storage_interface) { } // Inits a session (maybe) and then decrypts the message - self.handlePreKeyWhisperMessage = function(from, encodedMessage) { - var preKeyProto = axolotlInternal.protobuf.PreKeyWhisperMessage.decode(encodedMessage); + self.handlePreKeyWhisperMessage = function(from, encodedMessage, encoding) { + var preKeyProto = axolotlInternal.protobuf.PreKeyWhisperMessage.decode(encodedMessage, encoding); return initSessionFromPreKeyWhisperMessage(from, preKeyProto).then(function(sessions) { return doDecryptWhisperMessage(from, axolotlInternal.utils.convertToString(preKeyProto.message), sessions[0], preKeyProto.registrationId).then(function(result) { if (sessions[1] !== undefined)