Attachments: support for incrementalMac and chunkSize

This commit is contained in:
Scott Nonnenberg 2024-10-09 23:13:41 +10:00 committed by GitHub
parent dbf057856f
commit b51a0e0298
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 322 additions and 69 deletions

View file

@ -16,6 +16,7 @@ import { dropNull } from '../util/dropNull';
import { decryptAttachmentV2ToSink } from '../AttachmentCrypto';
import Avatar = Proto.ContactDetails.IAvatar;
import { stringToMIMEType } from '../types/MIME';
const { Reader } = protobuf;
@ -152,9 +153,13 @@ export class ParseContactsTransform extends Transform {
// eslint-disable-next-line no-await-in-loop
await window.Signal.Migrations.writeNewAttachmentData(avatarData);
const contentType = this.activeContact.avatar?.contentType;
const prepared = prepareContact(this.activeContact, {
...this.activeContact.avatar,
...local,
contentType: contentType
? stringToMIMEType(contentType)
: undefined,
hash,
});
if (prepared) {

View file

@ -120,6 +120,8 @@ export type ProcessedAttachment = {
textAttachment?: Omit<TextAttachmentType, 'preview'>;
backupLocator?: AttachmentType['backupLocator'];
downloadPath?: string;
incrementalMac?: string;
chunkSize?: number;
};
export type ProcessedGroupV2Context = {

View file

@ -113,7 +113,7 @@ export async function downloadAttachment(
): Promise<ReencryptedAttachmentV2 & { size?: number }> {
const logId = `downloadAttachment/${options.logPrefix ?? ''}`;
const { digest, key, size } = attachment;
const { chunkSize, digest, incrementalMac, key, size } = attachment;
strictAssert(digest, `${logId}: missing digest`);
strictAssert(key, `${logId}: missing key`);
@ -232,6 +232,10 @@ export async function downloadAttachment(
macKey,
size,
theirDigest: Bytes.fromBase64(digest),
theirIncrementalMac: incrementalMac
? Bytes.fromBase64(incrementalMac)
: undefined,
theirChunkSize: chunkSize,
outerEncryption:
mediaTier === 'backup'
? getBackupMediaOuterEncryptionKeyMaterial(attachment)

View file

@ -54,7 +54,8 @@ export function processAttachment(
const { cdnId } = attachment;
const hasCdnId = Long.isLong(cdnId) ? !cdnId.isZero() : Boolean(cdnId);
const { clientUuid, contentType, digest, key, size } = attachment;
const { clientUuid, contentType, digest, incrementalMac, key, size } =
attachment;
if (!isNumber(size)) {
throw new Error('Missing size on incoming attachment!');
}
@ -63,12 +64,17 @@ export function processAttachment(
...shallowDropNull(attachment),
cdnId: hasCdnId ? String(cdnId) : undefined,
clientUuid: clientUuid ? bytesToUuid(clientUuid) : undefined,
clientUuid: Bytes.isNotEmpty(clientUuid)
? bytesToUuid(clientUuid)
: undefined,
contentType: contentType
? stringToMIMEType(contentType)
: APPLICATION_OCTET_STREAM,
digest: digest ? Bytes.toBase64(digest) : undefined,
key: key ? Bytes.toBase64(key) : undefined,
digest: Bytes.isNotEmpty(digest) ? Bytes.toBase64(digest) : undefined,
incrementalMac: Bytes.isNotEmpty(incrementalMac)
? Bytes.toBase64(incrementalMac)
: undefined,
key: Bytes.isNotEmpty(key) ? Bytes.toBase64(key) : undefined,
size,
};
}