From bc0f4387fe89893ced397aac35d3d10599e9bb73 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Fri, 12 Feb 2021 09:43:24 -0800 Subject: [PATCH] Backwards compatibility updates for libsignal-client --- preload.js | 12 ++++++++++++ ts/models/conversations.ts | 8 +++++++- ts/models/messages.ts | 4 ++-- ts/textsecure/MessageReceiver.ts | 10 +++++++--- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/preload.js b/preload.js index ff45de54e..581f47e12 100644 --- a/preload.js +++ b/preload.js @@ -534,6 +534,18 @@ try { }, createKeyPair: incomingKey => { const incomingKeyBuffer = Buffer.from(incomingKey); + + if (incomingKeyBuffer.length !== 32) { + throw new Error('key must be 32 bytes long'); + } + + // eslint-disable-next-line no-bitwise + incomingKeyBuffer[0] &= 248; + // eslint-disable-next-line no-bitwise + incomingKeyBuffer[31] &= 127; + // eslint-disable-next-line no-bitwise + incomingKeyBuffer[31] |= 64; + const privKey = client.PrivateKey.deserialize(incomingKeyBuffer); const pubKey = privKey.getPublicKey(); diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index 74b12be21..d24da65d7 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -4023,6 +4023,12 @@ export class ConversationModel extends window.Backbone.Model< async leaveGroup(): Promise { const now = Date.now(); if (this.get('type') === 'group') { + const groupId = this.get('groupId'); + + if (!groupId) { + throw new Error(`leaveGroup/${this.idForLogging()}: No groupId!`); + } + const groupIdentifiers = this.getRecipients(); this.set({ left: true }); window.Signal.Data.updateConversation(this.attributes); @@ -4048,7 +4054,7 @@ export class ConversationModel extends window.Backbone.Model< message.send( this.wrapSend( window.textsecure.messaging.leaveGroup( - this.id, + groupId, groupIdentifiers, options ) diff --git a/ts/models/messages.ts b/ts/models/messages.ts index f2c538471..9c54d33fd 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -1470,11 +1470,11 @@ export class MessageModel extends window.Backbone.Model { // General idForLogging(): string { - const source = this.getSource(); + const account = this.getSourceUuid() || this.getSource(); const device = this.getSourceDevice(); const timestamp = this.get('sent_at'); - return `${source}.${device} ${timestamp}`; + return `${account}.${device} ${timestamp}`; } // eslint-disable-next-line class-methods-use-this diff --git a/ts/textsecure/MessageReceiver.ts b/ts/textsecure/MessageReceiver.ts index 8d07fb0e1..52e9a7892 100644 --- a/ts/textsecure/MessageReceiver.ts +++ b/ts/textsecure/MessageReceiver.ts @@ -622,10 +622,14 @@ class MessageReceiverInner extends EventTarget { } getEnvelopeId(envelope: EnvelopeClass) { + const timestamp = + envelope && envelope.timestamp && envelope.timestamp.toNumber + ? envelope.timestamp.toNumber() + : null; + if (envelope.sourceUuid || envelope.source) { - return `${envelope.sourceUuid || envelope.source}.${ - envelope.sourceDevice - } ${envelope.timestamp.toNumber()} (${envelope.id})`; + const sender = envelope.sourceUuid || envelope.source; + return `${sender}.${envelope.sourceDevice} ${timestamp} (${envelope.id})`; } return envelope.id;