Передача chachakey и начало нового протокола вложений
This commit is contained in:
@@ -103,7 +103,8 @@ export function Message(props: MessageProps) {
|
|||||||
publicKey: user.publicKey,
|
publicKey: user.publicKey,
|
||||||
message: props.message,
|
message: props.message,
|
||||||
attachments: props.attachments.filter(a => a.type != AttachmentType.MESSAGES),
|
attachments: props.attachments.filter(a => a.type != AttachmentType.MESSAGES),
|
||||||
message_id: props.message_id
|
message_id: props.message_id,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const avatars = useAvatars(user.publicKey);
|
const avatars = useAvatars(user.publicKey);
|
||||||
@@ -214,7 +215,7 @@ export function Message(props: MessageProps) {
|
|||||||
fontSize: '13px',
|
fontSize: '13px',
|
||||||
color: messageStyle == MessageStyle.BUBBLES ? (computedTheme == 'light' ? (props.parent?.from_me ? 'white' : 'black') : 'white') : (computedTheme == 'light' ? 'black' : 'white')
|
color: messageStyle == MessageStyle.BUBBLES ? (computedTheme == 'light' ? (props.parent?.from_me ? 'white' : 'black') : 'white') : (computedTheme == 'light' ? 'black' : 'white')
|
||||||
}} ml={props.avatar_no_render ? 50 : undefined} onDoubleClick={(e) => e.stopPropagation()}>
|
}} ml={props.avatar_no_render ? 50 : undefined} onDoubleClick={(e) => e.stopPropagation()}>
|
||||||
<TextParser performanceEntityLimit={ENTITY_LIMITS_TO_PARSE_IN_MESSAGE} oversizeIfTextSmallerThan={1} text={props.message.trim()}></TextParser>
|
<TextParser performanceEntityLimit={ENTITY_LIMITS_TO_PARSE_IN_MESSAGE} oversizeIfTextSmallerThan={1} text={props.message.trim() + props.chacha_key_plain}></TextParser>
|
||||||
</Box>
|
</Box>
|
||||||
</Flex>
|
</Flex>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|||||||
@@ -66,7 +66,8 @@ export function useAttachment(attachment: Attachment, parentMessage: MessageProp
|
|||||||
if(attachment.type == AttachmentType.FILE){
|
if(attachment.type == AttachmentType.FILE){
|
||||||
/**
|
/**
|
||||||
* Если это файл, то он хранится не в папке медиа,
|
* Если это файл, то он хранится не в папке медиа,
|
||||||
* а в загрузках
|
* а в загрузках, статус скачивания определяем не только по названию файла,
|
||||||
|
* но и по его размеру (если размеры и название совпало, то считаем файл скаченным)
|
||||||
*/
|
*/
|
||||||
const preview = getPreview();
|
const preview = getPreview();
|
||||||
const filesize = parseInt(preview.split("::")[0]);
|
const filesize = parseInt(preview.split("::")[0]);
|
||||||
@@ -76,6 +77,9 @@ export function useAttachment(attachment: Attachment, parentMessage: MessageProp
|
|||||||
const exists = await fileExists(pathInDownloads, false);
|
const exists = await fileExists(pathInDownloads, false);
|
||||||
const existsLength = await size(pathInDownloads, false);
|
const existsLength = await size(pathInDownloads, false);
|
||||||
if(exists && existsLength == filesize){
|
if(exists && existsLength == filesize){
|
||||||
|
/**
|
||||||
|
* Если название файла и его размер совпадают (и он существует), то считаем его скаченным
|
||||||
|
*/
|
||||||
setDownloadStatus(DownloadStatus.DOWNLOADED);
|
setDownloadStatus(DownloadStatus.DOWNLOADED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -216,6 +216,16 @@ export function DialogProvider(props: DialogProviderProps) {
|
|||||||
readUpdated = true;
|
readUpdated = true;
|
||||||
}
|
}
|
||||||
let decryptKey = '';
|
let decryptKey = '';
|
||||||
|
if(message.from_me && message.chacha_key != "" && !message.chacha_key.startsWith("sync:")){
|
||||||
|
/**
|
||||||
|
* Если это сообщение от нас, то проверяем, есть ли внутри chacha_key
|
||||||
|
*/
|
||||||
|
try{
|
||||||
|
decryptKey = Buffer.from(await decodeWithPassword(privatePlain, message.chacha_key), 'binary').toString('utf-8');
|
||||||
|
}catch(e) {
|
||||||
|
decryptKey = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
if(message.from_me && message.chacha_key != "" && message.chacha_key.startsWith("sync:")){
|
if(message.from_me && message.chacha_key != "" && message.chacha_key.startsWith("sync:")){
|
||||||
/**
|
/**
|
||||||
* Если это сообщение от нас, то проверяем, есть ли внутри chacha_key, если есть, значит это
|
* Если это сообщение от нас, то проверяем, есть ли внутри chacha_key, если есть, значит это
|
||||||
@@ -629,7 +639,7 @@ export function DialogProvider(props: DialogProviderProps) {
|
|||||||
blob: attachment.type == AttachmentType.MESSAGES ? await decodeWithPassword(chachaDecryptedKey.toString('utf-8'), attachment.blob) : ""
|
blob: attachment.type == AttachmentType.MESSAGES ? await decodeWithPassword(chachaDecryptedKey.toString('utf-8'), attachment.blob) : ""
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
console.info(attachments);
|
||||||
const newMessage : Message = {
|
const newMessage : Message = {
|
||||||
from_public_key: fromPublicKey,
|
from_public_key: fromPublicKey,
|
||||||
to_public_key: toPublicKey,
|
to_public_key: toPublicKey,
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ export function useDialog() : {
|
|||||||
content: content,
|
content: content,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
readed: publicKey == dialog ? 1 : 0,
|
readed: publicKey == dialog ? 1 : 0,
|
||||||
chacha_key: "",
|
chacha_key: aesChachaKey,
|
||||||
from_me: 1,
|
from_me: 1,
|
||||||
plain_message: message,
|
plain_message: message,
|
||||||
delivered: publicKey == dialog ? DeliveredMessageState.DELIVERED : DeliveredMessageState.WAITING,
|
delivered: publicKey == dialog ? DeliveredMessageState.DELIVERED : DeliveredMessageState.WAITING,
|
||||||
@@ -137,7 +137,7 @@ export function useDialog() : {
|
|||||||
await runQuery(`
|
await runQuery(`
|
||||||
INSERT INTO messages
|
INSERT INTO messages
|
||||||
(from_public_key, to_public_key, content, timestamp, read, chacha_key, from_me, plain_message, account, message_id, delivered, attachments) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
(from_public_key, to_public_key, content, timestamp, read, chacha_key, from_me, plain_message, account, message_id, delivered, attachments) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
`, [publicKey, dialog, content, Date.now(), publicKey == dialog ? 1 : 0, encryptedKey, 1, plainMessage, publicKey, messageId, publicKey == dialog ? DeliveredMessageState.DELIVERED : (
|
`, [publicKey, dialog, content, Date.now(), publicKey == dialog ? 1 : 0, aesChachaKey, 1, plainMessage, publicKey, messageId, publicKey == dialog ? DeliveredMessageState.DELIVERED : (
|
||||||
protocolState != ProtocolState.CONNECTED ? DeliveredMessageState.ERROR : DeliveredMessageState.WAITING
|
protocolState != ProtocolState.CONNECTED ? DeliveredMessageState.ERROR : DeliveredMessageState.WAITING
|
||||||
), JSON.stringify(attachmentsMeta)]);
|
), JSON.stringify(attachmentsMeta)]);
|
||||||
updateDialog(dialog);
|
updateDialog(dialog);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { useDatabase } from "@/app/providers/DatabaseProvider/useDatabase";
|
|||||||
import { usePrivatePlain } from "../AccountProvider/usePrivatePlain";
|
import { usePrivatePlain } from "../AccountProvider/usePrivatePlain";
|
||||||
import { usePublicKey } from "../AccountProvider/usePublicKey";
|
import { usePublicKey } from "../AccountProvider/usePublicKey";
|
||||||
import { chacha20Decrypt, decodeWithPassword, decrypt, encodeWithPassword, generateMd5 } from "@/app/workers/crypto/crypto";
|
import { chacha20Decrypt, decodeWithPassword, decrypt, encodeWithPassword, generateMd5 } from "@/app/workers/crypto/crypto";
|
||||||
import { DeliveredMessageState, Message } from "./DialogProvider";
|
import { AttachmentMeta, DeliveredMessageState, Message } from "./DialogProvider";
|
||||||
import { PacketRead } from "../ProtocolProvider/protocol/packets/packet.read";
|
import { PacketRead } from "../ProtocolProvider/protocol/packets/packet.read";
|
||||||
import { PacketDelivery } from "../ProtocolProvider/protocol/packets/packet.delivery";
|
import { PacketDelivery } from "../ProtocolProvider/protocol/packets/packet.delivery";
|
||||||
import { useConsoleLogger } from "@/app/hooks/useConsoleLogger";
|
import { useConsoleLogger } from "@/app/hooks/useConsoleLogger";
|
||||||
@@ -104,7 +104,7 @@ export function useDialogFiber() {
|
|||||||
decryptedContent = '';
|
decryptedContent = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
let attachmentsMeta: any[] = [];
|
let attachmentsMeta: AttachmentMeta[] = [];
|
||||||
let messageAttachments: Attachment[] = [];
|
let messageAttachments: Attachment[] = [];
|
||||||
for (let i = 0; i < packet.getAttachments().length; i++) {
|
for (let i = 0; i < packet.getAttachments().length; i++) {
|
||||||
const attachment = packet.getAttachments()[i];
|
const attachment = packet.getAttachments()[i];
|
||||||
@@ -129,7 +129,9 @@ export function useDialogFiber() {
|
|||||||
attachmentsMeta.push({
|
attachmentsMeta.push({
|
||||||
id: attachment.id,
|
id: attachment.id,
|
||||||
type: attachment.type,
|
type: attachment.type,
|
||||||
preview: attachment.preview
|
preview: attachment.preview,
|
||||||
|
encoding: attachment.encoding,
|
||||||
|
transport: attachment.transport
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +263,7 @@ export function useDialogFiber() {
|
|||||||
const nonce = chachaDecryptedKey.slice(32);
|
const nonce = chachaDecryptedKey.slice(32);
|
||||||
const decryptedContent = await chacha20Decrypt(content, nonce.toString('hex'), key.toString('hex'));
|
const decryptedContent = await chacha20Decrypt(content, nonce.toString('hex'), key.toString('hex'));
|
||||||
|
|
||||||
let attachmentsMeta: any[] = [];
|
let attachmentsMeta: AttachmentMeta[] = [];
|
||||||
let messageAttachments: Attachment[] = [];
|
let messageAttachments: Attachment[] = [];
|
||||||
for (let i = 0; i < packet.getAttachments().length; i++) {
|
for (let i = 0; i < packet.getAttachments().length; i++) {
|
||||||
const attachment = packet.getAttachments()[i];
|
const attachment = packet.getAttachments()[i];
|
||||||
@@ -286,7 +288,9 @@ export function useDialogFiber() {
|
|||||||
attachmentsMeta.push({
|
attachmentsMeta.push({
|
||||||
id: attachment.id,
|
id: attachment.id,
|
||||||
type: attachment.type,
|
type: attachment.type,
|
||||||
preview: attachment.preview
|
preview: attachment.preview,
|
||||||
|
encoding: attachment.encoding,
|
||||||
|
transport: attachment.transport
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export interface MessageReply {
|
|||||||
message: string;
|
message: string;
|
||||||
attachments: Attachment[];
|
attachments: Attachment[];
|
||||||
message_id: string;
|
message_id: string;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useReplyMessages() {
|
export function useReplyMessages() {
|
||||||
|
|||||||
Reference in New Issue
Block a user