From 8d11660b137ecf88704e8bb63ebcfff775c51b34 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Fri, 3 Jul 2020 10:08:24 +1000 Subject: [PATCH 1/2] Fix attachments --- libtextsecure/crypto.d.ts | 16 ++++++++++++++++ libtextsecure/index.d.ts | 26 ++++++++++++++++++++++++++ stylesheets/_modules.scss | 1 + ts/receiver/dataMessage.ts | 9 ++++++--- ts/session/utils/Attachments.ts | 2 +- ts/window.d.ts | 3 ++- 6 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 libtextsecure/crypto.d.ts create mode 100644 libtextsecure/index.d.ts diff --git a/libtextsecure/crypto.d.ts b/libtextsecure/crypto.d.ts new file mode 100644 index 000000000..441d59ee5 --- /dev/null +++ b/libtextsecure/crypto.d.ts @@ -0,0 +1,16 @@ +export interface LibTextsecureCryptoInterface { + encryptAttachment( + plaintext: ArrayBuffer, + keys: ArrayBuffer, + iv: ArrayBuffer + ): Promise<{ + digest: ArrayBuffer; + ciphertext: ArrayBuffer; + }>; + decryptAttachment( + encryptedBin: ArrayBuffer, + keys: ArrayBuffer, + theirDigest: ArrayBuffer + ): Promise; + decryptProfile(data: ArrayBuffer, key: ArrayBuffer): Promise; +} diff --git a/libtextsecure/index.d.ts b/libtextsecure/index.d.ts new file mode 100644 index 000000000..88bb6ced5 --- /dev/null +++ b/libtextsecure/index.d.ts @@ -0,0 +1,26 @@ +import { LibTextsecureCryptoInterface } from './crypto'; + +export interface LibTextsecure { + crypto: LibTextsecureCryptoInterface; + storage: any; + SendMessageNetworkError: any; + IncomingIdentityKeyError: any; + OutgoingIdentityKeyError: any; + ReplayableError: any; + OutgoingMessageError: any; + MessageError: any; + SignedPreKeyRotationError: any; + PoWError: any; + EmptySwarmError: any; + SeedNodeError: any; + DNSResolutionError: any; + HTTPError: any; + NotFoundError: any; + WrongSwarmError: any; + WrongDifficultyError: any; + TimestampError: any; + PublicChatError: any; + PublicTokenError: any; + SenderKeyMissing: any; + createTaskWithTimeout(task: any, id: any, options?: any): Promise; +} diff --git a/stylesheets/_modules.scss b/stylesheets/_modules.scss index d355119e3..797094830 100644 --- a/stylesheets/_modules.scss +++ b/stylesheets/_modules.scss @@ -580,6 +580,7 @@ display: inline-block; margin-left: 6px; margin-bottom: 2px; + margin-left: 5px; } .module-message__metadata__status-icon--sending { diff --git a/ts/receiver/dataMessage.ts b/ts/receiver/dataMessage.ts index 2bdf50f06..c4455f321 100644 --- a/ts/receiver/dataMessage.ts +++ b/ts/receiver/dataMessage.ts @@ -13,6 +13,7 @@ import { handleMediumGroupUpdate } from './mediumGroups'; import { handleUnpairRequest } from './multidevice'; import { downloadAttachment } from './attachments'; import _ from 'lodash'; +import { StringUtils } from '../session/utils'; export async function updateProfile( conversation: any, @@ -81,8 +82,10 @@ function cleanAttachment(attachment: any) { return { ..._.omit(attachment, 'thumbnail'), id: attachment.id.toString(), - key: attachment.key ? attachment.key.toString('base64') : null, - digest: attachment.digest ? attachment.digest.toString('base64') : null, + key: attachment.key ? StringUtils.decode(attachment.key, 'base64') : null, + digest: attachment.digest + ? StringUtils.decode(attachment.digest, 'base64') + : null, }; } @@ -508,7 +511,7 @@ function createMessage( } function sendDeliveryReceipt(source: string, timestamp: any) { -// FIXME audric + // FIXME audric // const receiptMessage = new DeliveryReceiptMessage({ // timestamp: Date.now(), // timestamps: [timestamp], diff --git a/ts/session/utils/Attachments.ts b/ts/session/utils/Attachments.ts index a1de04c9a..870c92dce 100644 --- a/ts/session/utils/Attachments.ts +++ b/ts/session/utils/Attachments.ts @@ -90,7 +90,7 @@ export class AttachmentUtils { pointer.key.buffer, iv.buffer ); - pointer.digest = data.digest; + pointer.digest = new Uint8Array(data.digest); attachmentData = data.ciphertext; } diff --git a/ts/window.d.ts b/ts/window.d.ts index a34070a3a..bd50f7e5d 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -7,6 +7,7 @@ import { LokiPublicChatFactoryInterface } from '../js/modules/loki_public_chat_a import { LokiAppDotNetServerInterface } from '../js/modules/loki_app_dot_net_api'; import { LokiMessageInterface } from '../js/modules/loki_message_api'; import { SwarmPolling } from './session/snode_api/swarmPolling'; +import { LibTextsecure } from '../libtextsecure'; /* We declare window stuff here instead of global.d.ts because we are importing other declarations. @@ -70,7 +71,7 @@ declare global { showQRDialog: any; showSeedDialog: any; storage: any; - textsecure: any; + textsecure: LibTextsecure; toggleLinkPreview: any; toggleMediaPermissions: any; toggleMenuBar: any; From 7665ecacfb7c36d54f25cb6873f539a76300076f Mon Sep 17 00:00:00 2001 From: Mikunj Date: Fri, 3 Jul 2020 10:28:33 +1000 Subject: [PATCH 2/2] Fix incorrect sent timestamps --- js/models/conversations.js | 10 +++++----- stylesheets/_modules.scss | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index be10cd40f..ff8769c00 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -1302,7 +1302,7 @@ const chatMessage = new libsession.Messages.Outgoing.ChatMessage({ body: uploads.body, identifier: id, - timestamp: Date.now(), + timestamp: now, attachments: uploads.attachments, expireTimer, preview: uploads.preview, @@ -1322,7 +1322,7 @@ const openGroupParams = { body, - timestamp: Date.now(), + timestamp: now, group: openGroup, attachments: uploads.attachments, preview: uploads.preview, @@ -1821,7 +1821,7 @@ const { chainKey, keyIdx } = senderKey; const createParams = { - timestamp: Date.now(), + timestamp: now, groupId: id, identifier: messageId, groupSecretKey: secretKey, @@ -1849,7 +1849,7 @@ const updateParams = { // if we do set an identifier here, be sure to not sync the message two times in msg.handleMessageSentSuccess() - timestamp: Date.now(), + timestamp: now, groupId: this.id, name: this.get('name'), avatar: this.get('avatar'), @@ -1921,7 +1921,7 @@ // FIXME what about public groups? const quitGroup = { - timestamp: Date.now(), + timestamp: now, groupId: this.id, // if we do set an identifier here, be sure to not sync it a second time in handleMessageSentSuccess() }; diff --git a/stylesheets/_modules.scss b/stylesheets/_modules.scss index 797094830..98a9e62f4 100644 --- a/stylesheets/_modules.scss +++ b/stylesheets/_modules.scss @@ -1630,6 +1630,7 @@ height: 12px; display: inline-block; margin-bottom: 2px; + margin-left: 5px; } .module-message-detail__contact__status-icon--sending {