diff --git a/app/components/MessageAttachments/MessageReplyMessages.tsx b/app/components/MessageAttachments/MessageReplyMessages.tsx
index cf79852..f78a445 100644
--- a/app/components/MessageAttachments/MessageReplyMessages.tsx
+++ b/app/components/MessageAttachments/MessageReplyMessages.tsx
@@ -42,7 +42,7 @@ export function MessageReplyMessages(props: AttachmentProps) {
}
{reply.map((msg : MessageReply, index) => (
-
+
))}
{showAlertInReplyMessages && a.type != AttachmentType.MESSAGES),
message_id: props.message_id,
+ /**
+ * Кодируем в hex чтобы было удобнее передавать по сети
+ */
chacha_key_plain: props.chacha_key_plain
};
diff --git a/app/providers/DialogProvider/DialogProvider.tsx b/app/providers/DialogProvider/DialogProvider.tsx
index 8786ba9..0724a29 100644
--- a/app/providers/DialogProvider/DialogProvider.tsx
+++ b/app/providers/DialogProvider/DialogProvider.tsx
@@ -221,7 +221,7 @@ export function DialogProvider(props: DialogProviderProps) {
* Если это сообщение от нас, то проверяем, есть ли внутри chacha_key
*/
try{
- decryptKey = Buffer.from(await decodeWithPassword(privatePlain, message.chacha_key), 'binary').toString('utf-8');
+ decryptKey = Buffer.from(await decodeWithPassword(privatePlain, message.chacha_key), 'binary').toString('hex');
}catch(e) {
decryptKey = "";
}
@@ -232,7 +232,7 @@ export function DialogProvider(props: DialogProviderProps) {
* сообщение пришло нам в результате синхронизации и его нужно расшифровать, если chacha_key нет,
* значит сообщение отправлено с нашего устройства, и зашифровано на стороне отправки (plain_message)
*/
- decryptKey = Buffer.from(await decodeWithPassword(privatePlain, message.chacha_key.replace("sync:", "")), 'binary').toString('utf-8');
+ decryptKey = Buffer.from(await decodeWithPassword(privatePlain, message.chacha_key.replace("sync:", "")), 'binary').toString('hex');
}
if(hasGroup(props.dialog)){
/**
@@ -245,7 +245,7 @@ export function DialogProvider(props: DialogProviderProps) {
* Если сообщение не от меня и не групповое,
* расшифровываем ключ чачи своим приватным ключом
*/
- decryptKey = Buffer.from(await decrypt(message.chacha_key, privatePlain), "binary").toString('utf-8');
+ decryptKey = Buffer.from(await decrypt(message.chacha_key, privatePlain), "binary").toString('hex');
}
finalMessages.push({
from_public_key: message.from_public_key,
@@ -482,7 +482,7 @@ export function DialogProvider(props: DialogProviderProps) {
const attachment = packet.getAttachments()[i];
attachments.push({
...attachment,
- blob: attachment.type == AttachmentType.MESSAGES ? await decodeWithPassword(chachaDecryptedKey.toString('utf-8'), attachment.blob) : ""
+ blob: attachment.type == AttachmentType.MESSAGES ? await decodeWithPassword(chachaDecryptedKey.toString('hex'), attachment.blob) : ""
});
}
@@ -492,7 +492,7 @@ export function DialogProvider(props: DialogProviderProps) {
content: content,
timestamp: timestamp,
readed: 0, //сообщение прочитано
- chacha_key: chachaDecryptedKey.toString('utf-8'),
+ chacha_key: chachaDecryptedKey.toString('hex'),
from_me: 1, //сообщение от нас
plain_message: (decryptedContent as string),
delivered: DeliveredMessageState.DELIVERED,
@@ -636,7 +636,7 @@ export function DialogProvider(props: DialogProviderProps) {
const attachment = packet.getAttachments()[i];
attachments.push({
...attachment,
- blob: attachment.type == AttachmentType.MESSAGES ? await decodeWithPassword(chachaDecryptedKey.toString('utf-8'), attachment.blob) : ""
+ blob: attachment.type == AttachmentType.MESSAGES ? await decodeWithPassword(chachaDecryptedKey.toString('hex'), attachment.blob) : ""
});
}
console.info(attachments);
@@ -646,7 +646,7 @@ export function DialogProvider(props: DialogProviderProps) {
content: content,
timestamp: timestamp,
readed: idle ? 0 : 1,
- chacha_key: chachaDecryptedKey.toString('utf-8'),
+ chacha_key: chachaDecryptedKey.toString('hex'),
from_me: fromPublicKey == publicKey ? 1 : 0,
plain_message: (decryptedContent as string),
delivered: DeliveredMessageState.DELIVERED,
@@ -798,7 +798,7 @@ export function DialogProvider(props: DialogProviderProps) {
* Если сообщение не от меня и не групповое,
* расшифровываем ключ чачи своим приватным ключом
*/
- decryptKey = Buffer.from(await decrypt(message.chacha_key, privatePlain), "binary").toString('utf-8');
+ decryptKey = Buffer.from(await decrypt(message.chacha_key, privatePlain), "binary").toString('hex');
}
finalMessages.push({
from_public_key: message.from_public_key,
@@ -883,7 +883,7 @@ export function DialogProvider(props: DialogProviderProps) {
* Если сообщение не от меня и не групповое,
* расшифровываем ключ чачи своим приватным ключом
*/
- decryptKey = Buffer.from(await decrypt(message.chacha_key, privatePlain), "binary").toString('utf-8');
+ decryptKey = Buffer.from(await decrypt(message.chacha_key, privatePlain), "binary").toString('hex');
}
finalMessages.push({
from_public_key: message.from_public_key,
diff --git a/app/providers/DialogProvider/useDeattachedSender.ts b/app/providers/DialogProvider/useDeattachedSender.ts
index 6074f3b..8470413 100644
--- a/app/providers/DialogProvider/useDeattachedSender.ts
+++ b/app/providers/DialogProvider/useDeattachedSender.ts
@@ -106,7 +106,9 @@ export function useDeattachedSender() {
attachmentsMeta.push({
id: attachment.id,
type: attachment.type,
- preview: attachment.preview
+ preview: attachment.preview,
+ encoding: attachment.encoding,
+ transport: attachment.transport
});
if(attachment.type == AttachmentType.FILE){
/**
@@ -132,7 +134,7 @@ export function useDeattachedSender() {
|| publicKey == dialog) {
return;
}
- let preparedToNetworkSendAttachements : Attachment[] = await prepareAttachmentsToSend(messageId, dialog, key.toString('utf-8'), attachemnts);
+ let preparedToNetworkSendAttachements : Attachment[] = await prepareAttachmentsToSend(messageId, dialog, key.toString('hex'), attachemnts);
if(attachemnts.length <= 0 && message.trim() == ""){
runQuery("UPDATE messages SET delivered = ? WHERE message_id = ?", [DeliveredMessageState.ERROR, messageId]);
updateDialog(dialog);
diff --git a/app/providers/DialogProvider/useDialog.ts b/app/providers/DialogProvider/useDialog.ts
index c176465..30588c2 100644
--- a/app/providers/DialogProvider/useDialog.ts
+++ b/app/providers/DialogProvider/useDialog.ts
@@ -96,14 +96,13 @@ export function useDialog() : {
* же сообщений (смотреть problem_sync.md)
*/
const aesChachaKey = await encodeWithPassword(privatePlain, key.toString('binary'));
-
setMessages((prev : Message[]) => ([...prev, {
from_public_key: publicKey,
to_public_key: dialog,
content: content,
timestamp: Date.now(),
readed: publicKey == dialog ? 1 : 0,
- chacha_key: key.toString('utf-8'),
+ chacha_key: key.toString('hex'),
from_me: 1,
plain_message: message,
delivered: publicKey == dialog ? DeliveredMessageState.DELIVERED : DeliveredMessageState.WAITING,
@@ -147,9 +146,8 @@ export function useDialog() : {
return;
}
- //98acbbc68f4b2449daf0a39d1b3eab9a3056da5d45b811bbc903e214c21d39643394980231e1a89c811830d870f3354184319665327ca8bd
console.info("Sending key for message ", key.toString('hex'));
- let preparedToNetworkSendAttachements : Attachment[] = await prepareAttachmentsToSend(messageId, dialog, key.toString('utf-8'), attachemnts);
+ let preparedToNetworkSendAttachements : Attachment[] = await prepareAttachmentsToSend(messageId, dialog, key.toString('hex'), attachemnts);
if(attachemnts.length <= 0 && message.trim() == ""){
runQuery("UPDATE messages SET delivered = ? WHERE message_id = ?", [DeliveredMessageState.ERROR, messageId]);
updateDialog(dialog);
diff --git a/app/providers/DialogProvider/useDialogFiber.ts b/app/providers/DialogProvider/useDialogFiber.ts
index b843d86..ea3c8b2 100644
--- a/app/providers/DialogProvider/useDialogFiber.ts
+++ b/app/providers/DialogProvider/useDialogFiber.ts
@@ -279,7 +279,7 @@ export function useDialogFiber() {
* Этот тип вложения приходит сразу в blob и не нуждается
* в последующем скачивании
*/
- const decryptedBlob = await decodeWithPassword(chachaDecryptedKey.toString('utf-8'), attachment.blob);
+ const decryptedBlob = await decodeWithPassword(chachaDecryptedKey.toString('hex'), attachment.blob);
writeFile(`m/${await generateMd5(attachment.id + publicKey)}`,
Buffer.from(await encodeWithPassword(privatePlain, decryptedBlob)).toString('binary'));
messageAttachments[nextLength - 1].blob = decryptedBlob;
@@ -300,7 +300,7 @@ export function useDialogFiber() {
content: content,
timestamp: timestamp,
readed: idle ? 0 : 1,
- chacha_key: chachaDecryptedKey.toString('utf-8'),
+ chacha_key: chachaDecryptedKey.toString('hex'),
from_me: fromPublicKey == publicKey ? 1 : 0,
plain_message: (decryptedContent as string),
delivered: DeliveredMessageState.DELIVERED,
diff --git a/app/providers/DialogProvider/useReplyMessages.ts b/app/providers/DialogProvider/useReplyMessages.ts
index cbdc180..3a2cb85 100644
--- a/app/providers/DialogProvider/useReplyMessages.ts
+++ b/app/providers/DialogProvider/useReplyMessages.ts
@@ -52,10 +52,7 @@ export function useReplyMessages() {
*/
return;
}
- message.chacha_key_plain = Buffer.from(message.chacha_key_plain).toString('hex');
- replyMessages.messages.push(message);
const sortedByTime = replyMessages.messages.sort((a, b) => a.timestamp - b.timestamp);
-
setReplyMessages({
publicKey: dialog,
messages: sortedByTime
diff --git a/app/providers/DialogProvider/useSynchronize.ts b/app/providers/DialogProvider/useSynchronize.ts
index a553b9d..6f77735 100644
--- a/app/providers/DialogProvider/useSynchronize.ts
+++ b/app/providers/DialogProvider/useSynchronize.ts
@@ -181,7 +181,7 @@ export function useSynchronize() {
* Этот тип вложения приходит сразу в blob и не нуждается
* в последующем скачивании
*/
- const decryptedBlob = await decodeWithPassword(chachaDecryptedKey.toString('utf-8'), attachment.blob);
+ const decryptedBlob = await decodeWithPassword(chachaDecryptedKey.toString('hex'), attachment.blob);
writeFile(`m/${await generateMd5(attachment.id + publicKey)}`,
Buffer.from(await encodeWithPassword(privatePlain, decryptedBlob)).toString('binary'));
messageAttachments[nextLength - 1].blob = decryptedBlob;
@@ -202,7 +202,7 @@ export function useSynchronize() {
content: content,
timestamp: timestamp,
readed: 1, //сообщение прочитано
- chacha_key: chachaDecryptedKey.toString('utf-8'),
+ chacha_key: chachaDecryptedKey.toString('hex'),
from_me: 1, //сообщение от нас
plain_message: (decryptedContent as string),
delivered: DeliveredMessageState.DELIVERED,