From 6380f7426ffb32cfe7a72244cb16a11e94d0881c Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 22 Jun 2020 15:05:17 +1000 Subject: [PATCH] fix pairing devices bugs since move to new pipeline --- js/modules/data.js | 16 ++++++---------- libtextsecure/account_manager.js | 6 +++--- libtextsecure/message_receiver.js | 2 +- .../content/link/DeviceLinkGrantMessage.ts | 4 ++-- .../content/link/DeviceLinkRequestMessage.ts | 2 +- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/js/modules/data.js b/js/modules/data.js index e4dd3b70e..1d90c4c1a 100644 --- a/js/modules/data.js +++ b/js/modules/data.js @@ -601,17 +601,13 @@ async function removeAllContactSignedPreKeys() { } function signatureToBase64(signature) { - if (signature.constructor === dcodeIO.ByteBuffer) { - return dcodeIO.ByteBuffer.wrap(signature).toString('base64'); - } else if (isArrayBuffer(signature)) { - return arrayBufferToBase64(signature); - } else if (typeof signature === 'string') { - // assume it's already base64 + if (typeof signature === 'string') { return signature; - } - throw new Error( - 'Invalid signature provided in createOrUpdatePairingAuthorisation. Needs to be either ArrayBuffer or ByteBuffer.' - ); +} + +// Ensure signature is ByteBuffer, ArrayBuffer or Uint8Array otherwise throw error +return dcodeIO.ByteBuffer.wrap(signature).toString('base64'); + } async function createOrUpdatePairingAuthorisation(data) { diff --git a/libtextsecure/account_manager.js b/libtextsecure/account_manager.js index aaceea903..963323fa4 100644 --- a/libtextsecure/account_manager.js +++ b/libtextsecure/account_manager.js @@ -590,8 +590,8 @@ const authorisations = await libsession.Protocols.MultiDeviceProtocol.getPairingAuthorisations( secondaryDeviceStr ); - const existingAuthorisation = authorisations.some( - pairing => pairing.secondaryDevicePubKey === secondaryDevicePubKey + const existingAuthorisation = authorisations.find( + pairing => pairing.secondaryDevicePubKey === secondaryDeviceStr ); if (!existingAuthorisation) { throw new Error( @@ -628,7 +628,7 @@ // Try to upload to the file server and then send a message try { await lokiFileServerAPI.updateOurDeviceMapping(); - const requestPairingMessage = new libsession.Messages.Outgoing.DeviceLinkGrantMessageParams( + const requestPairingMessage = new libsession.Messages.Outgoing.DeviceLinkGrantMessage( { timestamp: Date.now(), ...authorisation, diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index e68ab6e8d..5fd442406 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -1175,7 +1175,7 @@ MessageReceiver.prototype.extend({ const device = new libsession.Types.PubKey(envelope.source); await libsession.Protocols.SessionProtocol.onSessionEstablished(device); - // TODO process sending queue for this device now that we have a session + await libsession.getMessageQueue().processPending(device); } if (content.pairingAuthorisation) { diff --git a/ts/session/messages/outgoing/content/link/DeviceLinkGrantMessage.ts b/ts/session/messages/outgoing/content/link/DeviceLinkGrantMessage.ts index 7e608b8d5..a07217104 100644 --- a/ts/session/messages/outgoing/content/link/DeviceLinkGrantMessage.ts +++ b/ts/session/messages/outgoing/content/link/DeviceLinkGrantMessage.ts @@ -35,8 +35,8 @@ export class DeviceLinkGrantMessage extends DeviceLinkRequestMessage { return new SignalService.PairingAuthorisationMessage({ primaryDevicePubKey: this.primaryDevicePubKey, secondaryDevicePubKey: this.secondaryDevicePubKey, - requestSignature: this.requestSignature, - grantSignature: this.grantSignature, + requestSignature: new Uint8Array(this.requestSignature), + grantSignature: new Uint8Array(this.grantSignature), }); } diff --git a/ts/session/messages/outgoing/content/link/DeviceLinkRequestMessage.ts b/ts/session/messages/outgoing/content/link/DeviceLinkRequestMessage.ts index a2c33e8ab..945f9f00e 100644 --- a/ts/session/messages/outgoing/content/link/DeviceLinkRequestMessage.ts +++ b/ts/session/messages/outgoing/content/link/DeviceLinkRequestMessage.ts @@ -31,7 +31,7 @@ export class DeviceLinkRequestMessage extends ContentMessage { return new SignalService.PairingAuthorisationMessage({ primaryDevicePubKey: this.primaryDevicePubKey, secondaryDevicePubKey: this.secondaryDevicePubKey, - requestSignature: this.requestSignature, + requestSignature: new Uint8Array(this.requestSignature), grantSignature: null, }); }