Make ensureAttachmentIsReencryptable migration resilient to missing attachments

This commit is contained in:
trevor-signal 2024-10-08 17:45:00 -04:00 committed by GitHub
parent a1be616e6f
commit 0e386ef705
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 117 additions and 15 deletions

View file

@ -4,6 +4,7 @@
import { PassThrough } from 'stream';
import {
type EncryptedAttachmentV2,
ReencryptedDigestMismatchError,
type ReencryptionInfo,
decryptAttachmentV2ToSink,
encryptAttachmentV2,
@ -20,6 +21,8 @@ import {
import { strictAssert } from './assert';
import * as logging from '../logging/log';
import { fromBase64, toBase64 } from '../Bytes';
import { redactGenericText } from './privacy';
import { toLogFormat } from '../types/errors';
/**
* Some attachments on desktop are not reencryptable to the digest we received for them.
@ -34,6 +37,7 @@ import { fromBase64, toBase64 } from '../Bytes';
export async function ensureAttachmentIsReencryptable(
attachment: LocallySavedAttachment
): Promise<ReencryptableAttachment> {
const logId = `ensureAttachmentIsReencryptable(digest=${redactGenericText(attachment.digest ?? '')})`;
if (isReencryptableToSameDigest(attachment)) {
return attachment;
}
@ -50,9 +54,12 @@ export async function ensureAttachmentIsReencryptable(
isReencryptableToSameDigest: true,
};
} catch (e) {
logging.info(
'Unable to reencrypt attachment to original digest; must have had non-zero padding'
);
if (e instanceof ReencryptedDigestMismatchError) {
logging.info(
`${logId}: Unable to reencrypt attachment to original digest; must have had non-zero padding`
);
}
logging.error(`${logId}: error when reencrypting`, toLogFormat(e));
}
}