This commit is contained in:
Diego Mello 2024-05-22 18:27:07 -03:00
parent b8db541231
commit fb4ba5f4b4
7 changed files with 7 additions and 3813 deletions

View File

@ -76,8 +76,4 @@ export interface IShareAttachment {
canUpload: boolean; canUpload: boolean;
error?: any; error?: any;
uri: string; uri: string;
encryption?: {
key: any;
iv: string;
};
} }

View File

@ -32,10 +32,6 @@ export interface IUploadFile {
tmid?: string; tmid?: string;
description?: string; description?: string;
size: number; size: number;
type: string; type?: string;
// store?: string;
// progress?: number;
msg?: string; msg?: string;
// t?: MessageType;
// e2e?: E2EType;
} }

View File

@ -6,7 +6,7 @@ import parse from 'url-parse';
import { sha256 } from 'js-sha256'; import { sha256 } from 'js-sha256';
import getSingleMessage from '../methods/getSingleMessage'; import getSingleMessage from '../methods/getSingleMessage';
import { IAttachment, IMessage, IShareAttachment, IUpload, IUploadFile, IUser } from '../../definitions'; import { IAttachment, IMessage, IUpload, IUploadFile, IUser } from '../../definitions';
import Deferred from './helpers/deferred'; import Deferred from './helpers/deferred';
import { debounce } from '../methods/helpers'; import { debounce } from '../methods/helpers';
import database from '../database'; import database from '../database';
@ -32,7 +32,7 @@ import { mapMessageFromAPI } from './helpers/mapMessageFromApi';
import { mapMessageFromDB } from './helpers/mapMessageFromDB'; import { mapMessageFromDB } from './helpers/mapMessageFromDB';
import { createQuoteAttachment } from './helpers/createQuoteAttachment'; import { createQuoteAttachment } from './helpers/createQuoteAttachment';
import { getMessageById } from '../database/services/Message'; import { getMessageById } from '../database/services/Message';
import { TEncryptFile, TEncryptFileResult, TGetContent } from './definitions'; import { TEncryptFileResult, TGetContent } from './definitions';
export default class EncryptionRoom { export default class EncryptionRoom {
ready: boolean; ready: boolean;
@ -293,21 +293,21 @@ export default class EncryptionRoom {
iv: bufferToB64(vector) iv: bufferToB64(vector)
} }
}; };
if (/^image\/.+/.test(file.type)) { if (file.type && /^image\/.+/.test(file.type)) {
att = { att = {
...att, ...att,
image_url: fileUrl, image_url: fileUrl,
image_type: file.type, image_type: file.type,
image_size: file.size image_size: file.size
}; };
} else if (/^audio\/.+/.test(file.type)) { } else if (file.type && /^audio\/.+/.test(file.type)) {
att = { att = {
...att, ...att,
audio_url: fileUrl, audio_url: fileUrl,
audio_type: file.type, audio_type: file.type,
audio_size: file.size audio_size: file.size
}; };
} else if (/^video\/.+/.test(file.type)) { } else if (file.type && /^video\/.+/.test(file.type)) {
att = { att = {
...att, ...att,
video_url: fileUrl, video_url: fileUrl,
@ -392,16 +392,10 @@ export default class EncryptionRoom {
tmsg = await this.decryptText(tmsg); tmsg = await this.decryptText(tmsg);
} }
// if (message.attachments?.length) {
// message.attachments[0].description = await this.decryptText(message.attachments[0].description as string);
// }
if (message.content?.ciphertext) { if (message.content?.ciphertext) {
try { try {
const content = await this.decryptContent(message.content?.ciphertext as string); const content = await this.decryptContent(message.content?.ciphertext as string);
console.log('🚀 ~ EncryptionRoom ~ decrypt= ~ content:', content);
message.attachments = content.attachments; message.attachments = content.attachments;
console.log('🚀 ~ EncryptionRoom ~ decrypt= ~ message.attachments:', message.attachments);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }

View File

@ -6,12 +6,6 @@ import { fromByteArray, toByteArray } from './helpers/base64-js';
const BASE64URI = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; const BASE64URI = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
// Use a lookup table to find the index.
const lookup = new Uint8Array(256);
for (let i = 0; i < BASE64URI.length; i++) {
lookup[BASE64URI.charCodeAt(i)] = i;
}
// @ts-ignore // @ts-ignore
export const b64ToBuffer = (base64: string): ArrayBuffer => toByteArray(base64).buffer; export const b64ToBuffer = (base64: string): ArrayBuffer => toByteArray(base64).buffer;
export const utf8ToBuffer = SimpleCrypto.utils.convertUtf8ToArrayBuffer; export const utf8ToBuffer = SimpleCrypto.utils.convertUtf8ToArrayBuffer;
@ -38,32 +32,6 @@ export const bufferToB64URI = (buffer: ArrayBuffer): string => {
return base64; return base64;
}; };
export const b64URIToBuffer = (base64: string): ArrayBuffer => {
const bufferLength = base64.length * 0.75;
const len = base64.length;
let i;
let p = 0;
let encoded1;
let encoded2;
let encoded3;
let encoded4;
const arraybuffer = new ArrayBuffer(bufferLength);
const bytes = new Uint8Array(arraybuffer);
for (i = 0; i < len; i += 4) {
encoded1 = lookup[base64.charCodeAt(i)];
encoded2 = lookup[base64.charCodeAt(i + 1)];
encoded3 = lookup[base64.charCodeAt(i + 2)];
encoded4 = lookup[base64.charCodeAt(i + 3)];
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
}
return arraybuffer;
};
// SimpleCrypto.utils.convertArrayBufferToUtf8 is not working with unicode emoji // SimpleCrypto.utils.convertArrayBufferToUtf8 is not working with unicode emoji
export const bufferToUtf8 = (buffer: ArrayBuffer): string => { export const bufferToUtf8 = (buffer: ArrayBuffer): string => {
const uintArray = new Uint8Array(buffer) as number[] & Uint8Array; const uintArray = new Uint8Array(buffer) as number[] & Uint8Array;

View File

@ -1,12 +1,11 @@
import * as FileSystem from 'expo-file-system'; import * as FileSystem from 'expo-file-system';
import * as mime from 'react-native-mime-types'; import * as mime from 'react-native-mime-types';
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
// import { Base64 } from 'js-base64';
import { sanitizeLikeString } from '../database/utils'; import { sanitizeLikeString } from '../database/utils';
import { store } from '../store/auxStore'; import { store } from '../store/auxStore';
import log from './helpers/log'; import log from './helpers/log';
import { Base64, b64ToBuffer, b64URIToBuffer, base64Decode, decryptAESCTR } from '../encryption/utils'; import { decryptAESCTR } from '../encryption/utils';
export type MediaTypes = 'audio' | 'image' | 'video'; export type MediaTypes = 'audio' | 'image' | 'video';
@ -224,7 +223,6 @@ export function downloadMediaFile({
if (encryption) { if (encryption) {
const decryptedFile = await decryptAESCTR(result.uri, encryption.key.k, encryption.iv); const decryptedFile = await decryptAESCTR(result.uri, encryption.key.k, encryption.iv);
console.log('🚀 ~ returnnewPromise ~ decryptedFile:', decryptedFile);
if (decryptedFile) { if (decryptedFile) {
return resolve(decryptedFile); return resolve(decryptedFile);
} }

View File

@ -266,7 +266,6 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
size, size,
type, type,
path, path,
store: 'Uploads',
msg msg
}, },
thread?.id, thread?.id,

File diff suppressed because it is too large Load Diff