Simplify sticker upload

This commit is contained in:
Fedor Indutny 2022-12-15 13:47:38 -08:00 committed by GitHub
parent 47b0ee6135
commit d608b81292
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 17 deletions

View file

@ -207,7 +207,6 @@ window.encryptAndUpload = async (
const packKey = getRandomBytes(32);
const encryptionKey = deriveStickerPackKey(packKey);
const iv = getRandomBytes(16);
const server = WebAPI.connect({
username,
@ -259,15 +258,14 @@ window.encryptAndUpload = async (
const encryptedManifest = await encrypt(
Proto.StickerPack.encode(manifestProto).finish(),
encryptionKey,
iv
encryptionKey
);
const encryptedStickers = uniqueStickers.map(({ imageData }) => {
if (!imageData?.buffer) {
throw new Error('encryptStickers: Missing image data on sticker');
}
return encrypt(imageData.buffer, encryptionKey, iv);
return encrypt(imageData.buffer, encryptionKey);
});
const packId = await server.putStickers(
@ -283,12 +281,8 @@ window.encryptAndUpload = async (
return { packId, key: hexKey };
};
function encrypt(
data: Uint8Array,
key: Uint8Array,
iv: Uint8Array
): Uint8Array {
const { ciphertext } = encryptAttachment(data, key, iv);
function encrypt(data: Uint8Array, key: Uint8Array): Uint8Array {
const { ciphertext } = encryptAttachment(data, key);
return ciphertext;
}

View file

@ -455,8 +455,7 @@ export function decryptAttachment(
export function encryptAttachment(
plaintext: Uint8Array,
keys: Uint8Array,
iv: Uint8Array
keys: Uint8Array
): EncryptedAttachment {
if (!(plaintext instanceof Uint8Array)) {
throw new TypeError(
@ -467,9 +466,7 @@ export function encryptAttachment(
if (keys.byteLength !== 64) {
throw new Error('Got invalid length attachment keys');
}
if (iv.byteLength !== 16) {
throw new Error('Got invalid length attachment iv');
}
const iv = getRandomBytes(16);
const aesKey = keys.slice(0, 32);
const macKey = keys.slice(32, 64);

View file

@ -700,9 +700,8 @@ export default class MessageSender {
const padded = this.getPaddedAttachment(data);
const key = getRandomBytes(64);
const iv = getRandomBytes(16);
const result = encryptAttachment(padded, key, iv);
const result = encryptAttachment(padded, key);
const id = await this.server.putAttachment(result.ciphertext);
const proto = new Proto.AttachmentPointer();