Add initial thumbnail restore for message backup.

This commit is contained in:
Clark
2024-05-15 14:58:29 -04:00
committed by Nicholas Tinsley
parent 757c0fd2ea
commit b72d586748
25 changed files with 397 additions and 50 deletions

View File

@@ -156,9 +156,13 @@ class ArchiveApi(
}
}
fun getResumableUploadSpec(uploadForm: AttachmentUploadForm): NetworkResult<ResumableUploadSpec> {
fun getResumableUploadSpec(uploadForm: AttachmentUploadForm, secretKey: ByteArray?): NetworkResult<ResumableUploadSpec> {
return NetworkResult.fromFetch {
pushServiceSocket.getResumableUploadSpec(uploadForm)
if (secretKey == null) {
pushServiceSocket.getResumableUploadSpec(uploadForm)
} else {
pushServiceSocket.getResumableUploadSpecWithKey(uploadForm, secretKey)
}
}
}

View File

@@ -42,6 +42,10 @@ class BackupKey(val value: ByteArray) {
return deriveMediaSecrets(deriveMediaId(mediaName))
}
fun deriveThumbnailTransitKey(thumbnailMediaName: MediaName): ByteArray {
return HKDF.deriveSecrets(value, deriveMediaId(thumbnailMediaName).value, "20240513_Signal_Backups_EncryptThumbnail".toByteArray(), 64)
}
private fun deriveMediaSecrets(mediaId: MediaId): MediaKeyMaterial {
val extendedKey = HKDF.deriveSecrets(this.value, mediaId.value, "20231003_Signal_Backups_EncryptMedia".toByteArray(), 80)

View File

@@ -16,6 +16,7 @@ value class MediaName(val name: String) {
companion object {
fun fromDigest(digest: ByteArray) = MediaName(Base64.encodeWithoutPadding(digest))
fun fromDigestForThumbnail(digest: ByteArray) = MediaName("${Base64.encodeWithoutPadding(digest)}_thumbnail")
fun forThumbnailFromMediaName(mediaName: String) = MediaName("${mediaName}_thumbnail")
}
fun toByteArray(): ByteArray {

View File

@@ -1586,6 +1586,16 @@ public class PushServiceSocket {
uploadForm.headers);
}
public ResumableUploadSpec getResumableUploadSpecWithKey(AttachmentUploadForm uploadForm, byte[] secretKey) throws IOException {
return new ResumableUploadSpec(secretKey,
Util.getSecretBytes(16),
uploadForm.key,
uploadForm.cdn,
getResumableUploadUrl(uploadForm),
System.currentTimeMillis() + CDN2_RESUMABLE_LINK_LIFETIME_MILLIS,
uploadForm.headers);
}
public AttachmentDigest uploadAttachment(PushAttachmentData attachment) throws IOException {
if (attachment.getResumableUploadSpec() == null || attachment.getResumableUploadSpec().getExpirationTimestamp() < System.currentTimeMillis()) {