mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-05-02 06:33:38 +01:00
Add initial thumbnail restore for message backup.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user