From 5710c1268ca8a81b601f9e9b57dedb0c3edf5bdc Mon Sep 17 00:00:00 2001 From: Beaudan Brown Date: Wed, 16 Oct 2019 16:37:31 +1100 Subject: [PATCH] Revert id field and add new url field to be compatible with mobile --- libloki/crypto.js | 4 ++++ libtextsecure/message_receiver.js | 2 +- libtextsecure/sendmessage.js | 12 +++++++++--- protos/SignalService.proto | 3 ++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/libloki/crypto.js b/libloki/crypto.js index f8ad8d7f2..181d8c399 100644 --- a/libloki/crypto.js +++ b/libloki/crypto.js @@ -6,6 +6,7 @@ Multibase, TextEncoder, TextDecoder, + crypto, dcodeIO */ @@ -180,6 +181,8 @@ const snodeCipher = new LokiSnodeChannel(); + const sha512 = data => crypto.subtle.digest('SHA-512', data); + window.libloki.crypto = { DHEncrypt, DHDecrypt, @@ -190,5 +193,6 @@ // for testing _LokiSnodeChannel: LokiSnodeChannel, _decodeSnodeAddressToPubKey: decodeSnodeAddressToPubKey, + sha512, }; })(); diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index 6cbbdc2a1..4a987d6b5 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -1438,7 +1438,7 @@ MessageReceiver.prototype.extend({ }, async downloadAttachment(attachment) { // The attachment id is actually just the absolute url of the attachment - const encrypted = await this.server.getAttachment(attachment.id); + const encrypted = await this.server.getAttachment(attachment.url); const { key, digest, size } = attachment; const data = await textsecure.crypto.decryptAttachment( diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index 7d45c1b8d..d00468f80 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -1,4 +1,4 @@ -/* global _, textsecure, WebAPI, libsignal, OutgoingMessage, window */ +/* global _, textsecure, WebAPI, libsignal, OutgoingMessage, window, dcodeIO, libloki */ /* eslint-disable more/no-then, no-bitwise */ @@ -191,8 +191,14 @@ MessageSender.prototype = { return textsecure.crypto .encryptAttachment(attachment.data, proto.key, iv) .then(result => - this.server.putAttachment(result.ciphertext).then(url => { - proto.id = url; + this.server.putAttachment(result.ciphertext).then(async url => { + const urlBuffer = dcodeIO.ByteBuffer.wrap( + url, + 'utf8' + ).toArrayBuffer(); + const idBuffer = await libloki.crypto.sha512(urlBuffer); + proto.id = dcodeIO.ByteBuffer.wrap(idBuffer).toString('base64'); + proto.url = url; proto.contentType = attachment.contentType; proto.digest = result.digest; diff --git a/protos/SignalService.proto b/protos/SignalService.proto index bee23d4af..e5542947a 100644 --- a/protos/SignalService.proto +++ b/protos/SignalService.proto @@ -309,7 +309,7 @@ message AttachmentPointer { VOICE_MESSAGE = 1; } - optional string id = 1; + optional fixed64 id = 1; optional string contentType = 2; optional bytes key = 3; optional uint32 size = 4; @@ -320,6 +320,7 @@ message AttachmentPointer { optional uint32 width = 9; optional uint32 height = 10; optional string caption = 11; + optional string url = 12; } message GroupContext {