regression: Not able to check file consistency when encrypted (#32714)

Co-authored-by: Douglas Gubert <douglas.gubert@gmail.com>
pull/32723/head^2
Rodrigo Nascimento 2 years ago committed by GitHub
parent 5af9d44bc9
commit 0eb686fd3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 16
      apps/meteor/app/e2e/client/rocketchat.e2e.room.js
  2. 6
      apps/meteor/client/lib/chats/flows/uploadFiles.ts
  3. 3
      packages/core-typings/src/IMessage/MessageAttachment/MessageAttachmentBase.ts
  4. 3
      packages/core-typings/src/IUpload.ts

@ -359,13 +359,16 @@ export class E2ERoom extends Emitter {
}
}
async sha256Hash(text) {
const encoder = new TextEncoder();
const data = encoder.encode(text);
const hashArray = Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256', data)));
async sha256Hash(arrayBuffer) {
const hashArray = Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256', arrayBuffer)));
return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
}
async sha256HashText(text) {
const encoder = new TextEncoder();
return this.sha256Hash(encoder.encode(text));
}
// Encrypts files before upload. I/O is in arraybuffers.
async encryptFile(file) {
// if (!this.isSupportedRoomType(this.typeOfRoom)) {
@ -374,6 +377,8 @@ export class E2ERoom extends Emitter {
const fileArrayBuffer = await readFileAsArrayBuffer(file);
const hash = await this.sha256Hash(new Uint8Array(fileArrayBuffer));
const vector = crypto.getRandomValues(new Uint8Array(16));
const key = await generateAESCTRKey();
let result;
@ -386,7 +391,7 @@ export class E2ERoom extends Emitter {
const exportedKey = await window.crypto.subtle.exportKey('jwk', key);
const fileName = await this.sha256Hash(file.name);
const fileName = await this.sha256HashText(file.name);
const encryptedFile = new File([toArrayBuffer(result)], fileName);
@ -395,6 +400,7 @@ export class E2ERoom extends Emitter {
key: exportedKey,
iv: Base64.encode(vector),
type: file.type,
hash,
};
}

@ -106,6 +106,9 @@ export const uploadFiles = async (chat: ChatAPI, files: readonly File[], resetFi
key: encryptedFile.key,
iv: encryptedFile.iv,
},
hashes: {
sha256: encryptedFile.hash,
},
};
if (/^image\/.+/.test(file.type)) {
@ -167,6 +170,9 @@ export const uploadFiles = async (chat: ChatAPI, files: readonly File[], resetFi
key: encryptedFile.key,
iv: encryptedFile.iv,
},
hashes: {
sha256: encryptedFile.hash,
},
};
const fileContent = {

@ -17,4 +17,7 @@ export type MessageAttachmentBase = {
iv: string;
key: JsonWebKey;
};
hashes?: {
sha256: string;
};
};

@ -56,6 +56,9 @@ export interface IUpload {
iv: string;
key: JsonWebKey;
};
hashes?: {
sha256: string;
};
}
export type IUploadWithUser = IUpload & { user?: Pick<IUser, '_id' | 'name' | 'username'> };

Loading…
Cancel
Save