From 9c72523e0c9581f7efe4581c40fd00768c4401fc Mon Sep 17 00:00:00 2001 From: RoyceDa Date: Tue, 17 Feb 2026 15:13:48 +0200 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6?= =?UTF-8?q?=D0=BA=D0=B0=20=D1=81=D0=B8=D0=BD=D1=85=D1=80=D0=BE=D0=BD=D0=B8?= =?UTF-8?q?=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20=D1=81=D0=B2=D0=BE=D0=B8=D1=85?= =?UTF-8?q?=20=D0=B6=D0=B5=20=D0=B2=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/providers/AttachmentProvider/useAttachment.ts | 1 + app/providers/DialogProvider/DialogProvider.tsx | 12 +++++------- app/providers/DialogProvider/useDialogFiber.ts | 8 ++++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/providers/AttachmentProvider/useAttachment.ts b/app/providers/AttachmentProvider/useAttachment.ts index fe25a0a..b532c98 100644 --- a/app/providers/AttachmentProvider/useAttachment.ts +++ b/app/providers/AttachmentProvider/useAttachment.ts @@ -150,6 +150,7 @@ export function useAttachment(attachment: Attachment, keyPlain: string) { } setDownloadStatus(DownloadStatus.DECRYPTING); //console.info("Decrypted attachment ", Buffer.from(keyPlain, 'binary').toString('hex')); + console.info("KP", keyPlain); const decrypted = await decodeWithPassword(keyPlain, downloadedBlob); setDownloadTag(""); if(attachment.type == AttachmentType.FILE) { diff --git a/app/providers/DialogProvider/DialogProvider.tsx b/app/providers/DialogProvider/DialogProvider.tsx index 43f244e..58172fd 100644 --- a/app/providers/DialogProvider/DialogProvider.tsx +++ b/app/providers/DialogProvider/DialogProvider.tsx @@ -184,15 +184,13 @@ export function DialogProvider(props: DialogProviderProps) { readUpdated = true; } let decryptKey = ''; - if(message.from_me){ + if(message.from_me && message.chacha_key != "" && message.chacha_key.startsWith("sync:")){ /** - * Если сообщение от меня, то ключ расшифровки для вложений - * не нужен, передаем пустую строку, так как под капотом - * в MessageAttachment.tsx при расшифровке вложений используется - * локальный ключ, а не тот что в сообщении, так как файл и так находится - * у нас локально + * Если это сообщение от нас, то проверяем, есть ли внутри chacha_key, если есть, значит это + * сообщение пришло нам в результате синхронизации и его нужно расшифровать, если chacha_key нет, + * значит сообщение отправлено с нашего устройства, и зашифровано на стороне отправки (plain_message) */ - decryptKey = ''; + decryptKey = Buffer.from(await decodeWithPassword(privatePlain, message.chacha_key.replace("sync:", "")), 'binary').toString('utf-8'); } if(hasGroup(props.dialog)){ /** diff --git a/app/providers/DialogProvider/useDialogFiber.ts b/app/providers/DialogProvider/useDialogFiber.ts index 4bb598f..0831a27 100644 --- a/app/providers/DialogProvider/useDialogFiber.ts +++ b/app/providers/DialogProvider/useDialogFiber.ts @@ -96,15 +96,15 @@ export function useDialogFiber() { const content = packet.getContent(); const timestamp = packet.getTimestamp(); const messageId = packet.getMessageId(); - - if (fromPublicKey != publicKey) { /** * Игнорируем если это не сообщение от нас */ return; } - const chachaDecryptedKey = Buffer.from(await decodeWithPassword(privatePlain, aesChachaKey), "binary"); + + const chachaKey = await decodeWithPassword(privatePlain, aesChachaKey); + const chachaDecryptedKey = Buffer.from(chachaKey, "binary"); const key = chachaDecryptedKey.slice(0, 32); const nonce = chachaDecryptedKey.slice(32); const decryptedContent = await chacha20Decrypt(content, nonce.toString('hex'), key.toString('hex')); @@ -160,7 +160,7 @@ export function useDialogFiber() { content, timestamp, 0, //по умолчанию не прочитаны - '', + "sync:" + aesChachaKey, 1, //Свои же сообщения всегда от нас await encodeWithPassword(privatePlain, decryptedContent), publicKey,