Revert id field and add new url field to be compatible with mobile

pull/561/head
Beaudan Brown 6 years ago
parent 4e85435bf7
commit 5710c1268c

@ -6,6 +6,7 @@
Multibase, Multibase,
TextEncoder, TextEncoder,
TextDecoder, TextDecoder,
crypto,
dcodeIO dcodeIO
*/ */
@ -180,6 +181,8 @@
const snodeCipher = new LokiSnodeChannel(); const snodeCipher = new LokiSnodeChannel();
const sha512 = data => crypto.subtle.digest('SHA-512', data);
window.libloki.crypto = { window.libloki.crypto = {
DHEncrypt, DHEncrypt,
DHDecrypt, DHDecrypt,
@ -190,5 +193,6 @@
// for testing // for testing
_LokiSnodeChannel: LokiSnodeChannel, _LokiSnodeChannel: LokiSnodeChannel,
_decodeSnodeAddressToPubKey: decodeSnodeAddressToPubKey, _decodeSnodeAddressToPubKey: decodeSnodeAddressToPubKey,
sha512,
}; };
})(); })();

@ -1438,7 +1438,7 @@ MessageReceiver.prototype.extend({
}, },
async downloadAttachment(attachment) { async downloadAttachment(attachment) {
// The attachment id is actually just the absolute url of the 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 { key, digest, size } = attachment;
const data = await textsecure.crypto.decryptAttachment( const data = await textsecure.crypto.decryptAttachment(

@ -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 */ /* eslint-disable more/no-then, no-bitwise */
@ -191,8 +191,14 @@ MessageSender.prototype = {
return textsecure.crypto return textsecure.crypto
.encryptAttachment(attachment.data, proto.key, iv) .encryptAttachment(attachment.data, proto.key, iv)
.then(result => .then(result =>
this.server.putAttachment(result.ciphertext).then(url => { this.server.putAttachment(result.ciphertext).then(async url => {
proto.id = 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.contentType = attachment.contentType;
proto.digest = result.digest; proto.digest = result.digest;

@ -309,7 +309,7 @@ message AttachmentPointer {
VOICE_MESSAGE = 1; VOICE_MESSAGE = 1;
} }
optional string id = 1; optional fixed64 id = 1;
optional string contentType = 2; optional string contentType = 2;
optional bytes key = 3; optional bytes key = 3;
optional uint32 size = 4; optional uint32 size = 4;
@ -320,6 +320,7 @@ message AttachmentPointer {
optional uint32 width = 9; optional uint32 width = 9;
optional uint32 height = 10; optional uint32 height = 10;
optional string caption = 11; optional string caption = 11;
optional string url = 12;
} }
message GroupContext { message GroupContext {

Loading…
Cancel
Save