From edcb28aebb90d451892de12f8ebd5c5e82244c12 Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 3 Dec 2015 18:37:45 -0800 Subject: [PATCH] Don't save a MessageCounterError Fixes #446 // FREEBIE --- js/background.js | 5 +++++ js/libtextsecure.js | 4 +++- libtextsecure/libaxolotl.js | 4 +++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/js/background.js b/js/background.js index c8e73c66..06064f41 100644 --- a/js/background.js +++ b/js/background.js @@ -200,6 +200,11 @@ } if (ev.proto) { + if (e.name === 'MessageCounterError') { + // Ignore this message. It is likely a duplicate delivery + // because the server lost our ack the first time. + return; + } var envelope = ev.proto; var message = initIncomingMessage(envelope.source, envelope.timestamp.toNumber()); message.saveErrors(e).then(function() { diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 05fe834a..fdc526b2 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -34806,7 +34806,9 @@ window.axolotl.protocol = function(storage_interface) { return fillMessageKeys(chain, message.counter).then(function() { var messageKey = chain.messageKeys[message.counter]; if (messageKey === undefined) { - throw new Error("Message key not found. The counter was repeated or the key was not filled."); + var e = new Error("Message key not found. The counter was repeated or the key was not filled."); + e.name = 'MessageCounterError'; + throw e; } return HKDF(axolotlInternal.utils.convertToArrayBuffer(messageKey), '', "WhisperMessageKeys").then(function(keys) { return storage_interface.getMyIdentityKey().then(function(ourIdentityKey) { diff --git a/libtextsecure/libaxolotl.js b/libtextsecure/libaxolotl.js index 5b00cea1..1f74c7bd 100644 --- a/libtextsecure/libaxolotl.js +++ b/libtextsecure/libaxolotl.js @@ -34708,7 +34708,9 @@ window.axolotl.protocol = function(storage_interface) { return fillMessageKeys(chain, message.counter).then(function() { var messageKey = chain.messageKeys[message.counter]; if (messageKey === undefined) { - throw new Error("Message key not found. The counter was repeated or the key was not filled."); + var e = new Error("Message key not found. The counter was repeated or the key was not filled."); + e.name = 'MessageCounterError'; + throw e; } return HKDF(axolotlInternal.utils.convertToArrayBuffer(messageKey), '', "WhisperMessageKeys").then(function(keys) { return storage_interface.getMyIdentityKey().then(function(ourIdentityKey) {