From 8d11660b137ecf88704e8bb63ebcfff775c51b34 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Fri, 3 Jul 2020 10:08:24 +1000 Subject: [PATCH] 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;