Ignore digest for downloading archived thumbnails.

This commit is contained in:
Clark
2024-05-17 16:21:02 -04:00
committed by Cody Henthorne
parent 14b917dc7e
commit 7b0d3f36dc
4 changed files with 20 additions and 14 deletions

View File

@@ -246,6 +246,7 @@ class AttachmentDownloadJob private constructor(
pointer,
attachmentFile,
maxReceiveSize,
false,
progressListener
)
} else {

View File

@@ -257,6 +257,7 @@ class RestoreAttachmentJob private constructor(
pointer,
attachmentFile,
maxReceiveSize,
false,
progressListener
)
} else {
@@ -391,16 +392,7 @@ class RestoreAttachmentJob private constructor(
val backupDirectories = BackupRepository.getCdnBackupDirectories().successOrThrow()
return try {
val key = backupKey.deriveThumbnailTransitKey(attachment.getThumbnailMediaName())
if (attachment.remoteDigest != null) {
Log.i(TAG, "Downloading attachment with digest: " + Hex.toString(attachment.remoteDigest))
} else {
Log.i(TAG, "Downloading attachment with no digest...")
}
val mediaId = backupKey.deriveMediaId(attachment.getThumbnailMediaName()).encode()
Log.i(TAG, "Restore: Thumbnail mediaId=$mediaId backupDir=${backupDirectories.backupDir} mediaDir=${backupDirectories.mediaDir}")
SignalServiceAttachmentPointer(
attachment.archiveThumbnailCdn,
SignalServiceAttachmentRemoteId.Backup(
@@ -414,7 +406,7 @@ class RestoreAttachmentJob private constructor(
Optional.empty(),
0,
0,
Optional.ofNullable(attachment.remoteDigest),
Optional.empty(),
Optional.empty(),
attachment.incrementalMacChunkSize,
Optional.empty(),
@@ -471,6 +463,7 @@ class RestoreAttachmentJob private constructor(
pointer,
thumbnailFile,
maxThumbnailSize,
true,
progressListener
)

View File

@@ -190,10 +190,11 @@ public class SignalServiceMessageReceiver {
@Nonnull SignalServiceAttachmentPointer pointer,
@Nonnull File attachmentDestination,
long maxSizeBytes,
boolean ignoreDigest,
@Nullable ProgressListener listener)
throws IOException, InvalidMessageException, MissingConfigurationException
{
if (pointer.getDigest().isEmpty()) {
if (!ignoreDigest && pointer.getDigest().isEmpty()) {
throw new InvalidMessageException("No attachment digest!");
}
@@ -213,9 +214,10 @@ public class SignalServiceMessageReceiver {
return AttachmentCipherInputStream.createForAttachment(attachmentDestination,
pointer.getSize().orElse(0),
pointer.getKey(),
pointer.getDigest().get(),
ignoreDigest ? null : pointer.getDigest().get(),
null,
0);
0,
ignoreDigest);
}
public void retrieveBackup(int cdnNumber, Map<String, String> headers, String cdnPath, File destination, ProgressListener listener) throws MissingConfigurationException, IOException {

View File

@@ -60,6 +60,16 @@ public class AttachmentCipherInputStream extends FilterInputStream {
* Passing in a null incrementalDigest and/or 0 for the chunk size at the call site disables incremental mac validation.
*/
public static InputStream createForAttachment(File file, long plaintextLength, byte[] combinedKeyMaterial, byte[] digest, byte[] incrementalDigest, int incrementalMacChunkSize)
throws InvalidMessageException, IOException {
return createForAttachment(file, plaintextLength, combinedKeyMaterial, digest, incrementalDigest, incrementalMacChunkSize, false);
}
/**
* Passing in a null incrementalDigest and/or 0 for the chunk size at the call site disables incremental mac validation.
*
* Passing in true for ignoreDigest DOES NOT VERIFY THE DIGEST
*/
public static InputStream createForAttachment(File file, long plaintextLength, byte[] combinedKeyMaterial, byte[] digest, byte[] incrementalDigest, int incrementalMacChunkSize, boolean ignoreDigest)
throws InvalidMessageException, IOException
{
byte[][] parts = Util.split(combinedKeyMaterial, CIPHER_KEY_SIZE, MAC_KEY_SIZE);
@@ -69,7 +79,7 @@ public class AttachmentCipherInputStream extends FilterInputStream {
throw new InvalidMessageException("Message shorter than crypto overhead!");
}
if (digest == null) {
if (!ignoreDigest && digest == null) {
throw new InvalidMessageException("Missing digest!");
}