mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-05-01 22:25:46 +01:00
Update file format for backupV2.
This commit is contained in:
committed by
Cody Henthorne
parent
2e7279c72f
commit
34dbd11db0
@@ -184,7 +184,7 @@ public class SignalServiceMessageReceiver {
|
||||
*
|
||||
* @return An InputStream that streams the plaintext attachment contents.
|
||||
*/
|
||||
public InputStream retrieveArchivedAttachment(@Nonnull BackupKey.KeyMaterial<MediaId> archivedMediaKeyMaterial,
|
||||
public InputStream retrieveArchivedAttachment(@Nonnull BackupKey.MediaKeyMaterial archivedMediaKeyMaterial,
|
||||
@Nonnull Map<String, String> readCredentialHeaders,
|
||||
@Nonnull File archiveDestination,
|
||||
@Nonnull SignalServiceAttachmentPointer pointer,
|
||||
|
||||
@@ -22,16 +22,15 @@ class BackupKey(val value: ByteArray) {
|
||||
)
|
||||
}
|
||||
|
||||
fun deriveSecrets(aci: ACI): KeyMaterial<BackupId> {
|
||||
fun deriveBackupSecrets(aci: ACI): BackupKeyMaterial {
|
||||
val backupId = deriveBackupId(aci)
|
||||
|
||||
val extendedKey = HKDF.deriveSecrets(this.value, backupId.value, "20231003_Signal_Backups_EncryptMessageBackup".toByteArray(), 80)
|
||||
|
||||
return KeyMaterial(
|
||||
return BackupKeyMaterial(
|
||||
id = backupId,
|
||||
macKey = extendedKey.copyOfRange(0, 32),
|
||||
cipherKey = extendedKey.copyOfRange(32, 64),
|
||||
iv = extendedKey.copyOfRange(64, 80)
|
||||
cipherKey = extendedKey.copyOfRange(32, 64)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -39,14 +38,14 @@ class BackupKey(val value: ByteArray) {
|
||||
return MediaId(HKDF.deriveSecrets(value, mediaName.toByteArray(), "Media ID".toByteArray(), 15))
|
||||
}
|
||||
|
||||
fun deriveMediaSecrets(mediaName: MediaName): KeyMaterial<MediaId> {
|
||||
fun deriveMediaSecrets(mediaName: MediaName): MediaKeyMaterial {
|
||||
return deriveMediaSecrets(deriveMediaId(mediaName))
|
||||
}
|
||||
|
||||
fun deriveMediaSecrets(mediaId: MediaId): KeyMaterial<MediaId> {
|
||||
private fun deriveMediaSecrets(mediaId: MediaId): MediaKeyMaterial {
|
||||
val extendedKey = HKDF.deriveSecrets(this.value, mediaId.value, "20231003_Signal_Backups_EncryptMedia".toByteArray(), 80)
|
||||
|
||||
return KeyMaterial(
|
||||
return MediaKeyMaterial(
|
||||
id = mediaId,
|
||||
macKey = extendedKey.copyOfRange(0, 32),
|
||||
cipherKey = extendedKey.copyOfRange(32, 64),
|
||||
@@ -54,16 +53,22 @@ class BackupKey(val value: ByteArray) {
|
||||
)
|
||||
}
|
||||
|
||||
class KeyMaterial<Id> (
|
||||
val id: Id,
|
||||
class BackupKeyMaterial(
|
||||
val id: BackupId,
|
||||
val macKey: ByteArray,
|
||||
val cipherKey: ByteArray
|
||||
)
|
||||
|
||||
class MediaKeyMaterial(
|
||||
val id: MediaId,
|
||||
val macKey: ByteArray,
|
||||
val cipherKey: ByteArray,
|
||||
val iv: ByteArray
|
||||
) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun forMedia(id: ByteArray, keyMac: ByteArray, iv: ByteArray): KeyMaterial<MediaId> {
|
||||
return KeyMaterial(
|
||||
fun forMedia(id: ByteArray, keyMac: ByteArray, iv: ByteArray): MediaKeyMaterial {
|
||||
return MediaKeyMaterial(
|
||||
MediaId(id),
|
||||
keyMac.copyOfRange(32, 64),
|
||||
keyMac.copyOfRange(0, 32),
|
||||
|
||||
@@ -110,7 +110,7 @@ public class AttachmentCipherInputStream extends FilterInputStream {
|
||||
/**
|
||||
* Decrypt archived media to it's original attachment encrypted blob.
|
||||
*/
|
||||
public static InputStream createForArchivedMedia(BackupKey.KeyMaterial<MediaId> archivedMediaKeyMaterial, File file, long originalCipherTextLength)
|
||||
public static InputStream createForArchivedMedia(BackupKey.MediaKeyMaterial archivedMediaKeyMaterial, File file, long originalCipherTextLength)
|
||||
throws InvalidMessageException, IOException
|
||||
{
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user