From db1145c0ce8f5e725803917806a4eff73ca535b3 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Wed, 21 Nov 2018 15:37:19 +1100 Subject: [PATCH] Fix handling empty content. --- libtextsecure/message_receiver.js | 13 ++++++++++--- protos/SignalService.proto | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index bec5faed1..2ddd81fe1 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -1006,8 +1006,8 @@ MessageReceiver.prototype.extend({ const conversation = window.ConversationController.get(pubKey); if (conversation) { // Update the conversation friend request indicator - conversation.updatePendingFriendRequests(); - conversation.updateTextInputState(); + await conversation.updatePendingFriendRequests(); + await conversation.updateTextInputState(); } // If we accepted an incoming friend request then save the preKeyBundle @@ -1041,7 +1041,12 @@ MessageReceiver.prototype.extend({ if (envelope.type === textsecure.protobuf.Envelope.Type.FRIEND_REQUEST) { return this.handleFriendRequestMessage(envelope, content.dataMessage); - } else if (envelope.type === textsecure.protobuf.Envelope.Type.CIPHERTEXT) { + } else if ( + envelope.type === textsecure.protobuf.Envelope.Type.CIPHERTEXT || + // We also need to check for PREKEY_BUNDLE aswell if the session hasn't started. + // ref: libsignal-protocol.js:36120 + envelope.type === textsecure.protobuf.Envelope.Type.PREKEY_BUNDLE + ) { // If we get a cipher text and we are friends then we can mark keys as exchanged if (conversation && conversation.isFriend()) { await conversation.setKeyExchangeCompleted(true); @@ -1060,6 +1065,8 @@ MessageReceiver.prototype.extend({ } else if (content.receiptMessage) { return this.handleReceiptMessage(envelope, content.receiptMessage); } + if (envelope.preKeyBundleMessage) return null; + throw new Error('Unsupported content message'); }, handleCallMessage(envelope) { diff --git a/protos/SignalService.proto b/protos/SignalService.proto index ecf9743d1..e0de8f732 100644 --- a/protos/SignalService.proto +++ b/protos/SignalService.proto @@ -9,7 +9,7 @@ message Envelope { UNKNOWN = 0; CIPHERTEXT = 1; KEY_EXCHANGE = 2; - PREKEY_BUNDLE = 3; + PREKEY_BUNDLE = 3; //Used By Signal. DO NOT TOUCH! we don't use this at all. RECEIPT = 5; UNIDENTIFIED_SENDER = 6; FRIEND_REQUEST = 101; // contains prekeys + message and is using simple encryption