From 676ad04958b53a625a90fb4c15965f47c54ede3c Mon Sep 17 00:00:00 2001 From: lilia Date: Fri, 20 Feb 2015 14:43:22 -0800 Subject: [PATCH] Add device storage method to wipe an identity --- js/libtextsecure.js | 12 +++++++++--- libtextsecure/axolotl_wrapper.js | 3 +-- libtextsecure/sendmessage.js | 2 +- libtextsecure/storage/devices.js | 7 +++++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index d7b9c881..c0a76753 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -170,8 +170,7 @@ var wipeIdentityAndTryMessageAgain = function(from, encodedMessage, message_id) { // Wipe identity key! - //TODO: Encapsuate with the rest of textsecure.storage.devices - textsecure.storage.removeEncrypted("devices" + from.split('.')[0]); + textsecure.storage.devices.removeIdentityKeyForNumber(from.split('.')[0]); //TODO: Probably breaks with a devicecontrol message return axolotl.protocol.handlePreKeyWhisperMessage(from, encodedMessage).then(decodeMessageContents).then( function(pushMessageContent) { @@ -37872,6 +37871,13 @@ window.axolotl.sessions = { throw new Error("Attempted to overwrite a different identity key"); }, + removeIdentityKeyForNumber: function(number) { + var map = textsecure.storage.getEncrypted("devices" + number); + if (map === undefined) + throw new Error("Tried to remove identity for unknown number"); + textsecure.storage.removeEncrypted("devices" + number); + }, + getDeviceObject: function(encodedNumber, returnIdentityKey) { var number = textsecure.utils.unencodeNumber(encodedNumber)[0]; var devices = textsecure.storage.devices.getDeviceObjectsForNumber(number); @@ -39231,7 +39237,7 @@ window.textsecure.messaging = function() { var message = new Whisper.MessageCollection().add({id: message_id}); message.fetch().then(function() { //TODO: Encapsuate with the rest of textsecure.storage.devices - textsecure.storage.removeEncrypted("devices" + number); + textsecure.storage.devices.removeIdentityKeyForNumber(number); var proto = textsecure.protobuf.PushMessageContent.decode(encodedMessage, 'binary'); sendMessageProto(message.get('sent_at'), [number], proto, function(res) { if (res.failure.length > 0) diff --git a/libtextsecure/axolotl_wrapper.js b/libtextsecure/axolotl_wrapper.js index 6d9da8b0..b3440bfb 100644 --- a/libtextsecure/axolotl_wrapper.js +++ b/libtextsecure/axolotl_wrapper.js @@ -93,8 +93,7 @@ var wipeIdentityAndTryMessageAgain = function(from, encodedMessage, message_id) { // Wipe identity key! - //TODO: Encapsuate with the rest of textsecure.storage.devices - textsecure.storage.removeEncrypted("devices" + from.split('.')[0]); + textsecure.storage.devices.removeIdentityKeyForNumber(from.split('.')[0]); //TODO: Probably breaks with a devicecontrol message return axolotl.protocol.handlePreKeyWhisperMessage(from, encodedMessage).then(decodeMessageContents).then( function(pushMessageContent) { diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index cd3c62a0..f6bd000e 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -131,7 +131,7 @@ window.textsecure.messaging = function() { var message = new Whisper.MessageCollection().add({id: message_id}); message.fetch().then(function() { //TODO: Encapsuate with the rest of textsecure.storage.devices - textsecure.storage.removeEncrypted("devices" + number); + textsecure.storage.devices.removeIdentityKeyForNumber(number); var proto = textsecure.protobuf.PushMessageContent.decode(encodedMessage, 'binary'); sendMessageProto(message.get('sent_at'), [number], proto, function(res) { if (res.failure.length > 0) diff --git a/libtextsecure/storage/devices.js b/libtextsecure/storage/devices.js index 1155253e..32f0dd6a 100644 --- a/libtextsecure/storage/devices.js +++ b/libtextsecure/storage/devices.js @@ -74,6 +74,13 @@ throw new Error("Attempted to overwrite a different identity key"); }, + removeIdentityKeyForNumber: function(number) { + var map = textsecure.storage.getEncrypted("devices" + number); + if (map === undefined) + throw new Error("Tried to remove identity for unknown number"); + textsecure.storage.removeEncrypted("devices" + number); + }, + getDeviceObject: function(encodedNumber, returnIdentityKey) { var number = textsecure.utils.unencodeNumber(encodedNumber)[0]; var devices = textsecure.storage.devices.getDeviceObjectsForNumber(number);