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

@@ -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!");
}