mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 09:20:19 +01:00
Move to separate message and media backup keys.
This commit is contained in:
@@ -17,7 +17,7 @@ import org.thoughtcrime.securesms.net.SignalNetwork
|
||||
import org.thoughtcrime.securesms.providers.BlobProvider
|
||||
import org.thoughtcrime.securesms.registration.secondary.DeviceNameCipher
|
||||
import org.whispersystems.signalservice.api.NetworkResult
|
||||
import org.whispersystems.signalservice.api.backup.BackupKey
|
||||
import org.whispersystems.signalservice.api.backup.MessageBackupKey
|
||||
import org.whispersystems.signalservice.api.link.LinkedDeviceVerificationCodeResponse
|
||||
import org.whispersystems.signalservice.api.link.WaitForLinkedDeviceResponse
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.DeviceInfo
|
||||
@@ -115,9 +115,9 @@ object LinkDeviceRepository {
|
||||
/**
|
||||
* Adds a linked device to the account.
|
||||
*
|
||||
* @param ephemeralBackupKey An ephemeral key to provide the linked device to sync existing message content. Do not set if link+sync is unsupported.
|
||||
* @param ephemeralMessageBackupKey An ephemeral key to provide the linked device to sync existing message content. Do not set if link+sync is unsupported.
|
||||
*/
|
||||
fun addDevice(uri: Uri, ephemeralBackupKey: BackupKey?): LinkDeviceResult {
|
||||
fun addDevice(uri: Uri, ephemeralMessageBackupKey: MessageBackupKey?): LinkDeviceResult {
|
||||
if (!isValidQr(uri)) {
|
||||
Log.w(TAG, "Bad URI! $uri")
|
||||
return LinkDeviceResult.BadCode
|
||||
@@ -155,7 +155,7 @@ object LinkDeviceRepository {
|
||||
profileKey = ProfileKeyUtil.getSelfProfileKey(),
|
||||
masterKey = SignalStore.svr.getOrCreateMasterKey(),
|
||||
code = verificationCodeResult.verificationCode,
|
||||
ephemeralBackupKey = ephemeralBackupKey
|
||||
ephemeralMessageBackupKey = ephemeralMessageBackupKey
|
||||
)
|
||||
|
||||
return when (deviceLinkResult) {
|
||||
@@ -227,13 +227,13 @@ object LinkDeviceRepository {
|
||||
/**
|
||||
* Performs the entire process of creating and uploading an archive for a newly-linked device.
|
||||
*/
|
||||
fun createAndUploadArchive(ephemeralBackupKey: BackupKey, deviceId: Int, deviceCreatedAt: Long): LinkUploadArchiveResult {
|
||||
fun createAndUploadArchive(ephemeralMessageBackupKey: MessageBackupKey, deviceId: Int, deviceCreatedAt: Long): LinkUploadArchiveResult {
|
||||
val stopwatch = Stopwatch("link-archive")
|
||||
val tempBackupFile = BlobProvider.getInstance().forNonAutoEncryptingSingleSessionOnDisk(AppDependencies.application)
|
||||
val outputStream = FileOutputStream(tempBackupFile)
|
||||
|
||||
try {
|
||||
BackupRepository.export(outputStream = outputStream, append = { tempBackupFile.appendBytes(it) }, backupKey = ephemeralBackupKey, mediaBackupEnabled = false)
|
||||
BackupRepository.export(outputStream = outputStream, append = { tempBackupFile.appendBytes(it) }, messageBackupKey = ephemeralMessageBackupKey, mediaBackupEnabled = false)
|
||||
} catch (e: Exception) {
|
||||
return LinkUploadArchiveResult.BackupCreationFailure(e)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import org.thoughtcrime.securesms.linkdevice.LinkDeviceSettingsState.OneTimeEven
|
||||
import org.thoughtcrime.securesms.linkdevice.LinkDeviceSettingsState.QrCodeState
|
||||
import org.thoughtcrime.securesms.util.RemoteConfig
|
||||
import org.thoughtcrime.securesms.util.Util
|
||||
import org.whispersystems.signalservice.api.backup.BackupKey
|
||||
import org.whispersystems.signalservice.api.backup.MessageBackupKey
|
||||
import org.whispersystems.signalservice.api.link.WaitForLinkedDeviceResponse
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
@@ -198,8 +198,8 @@ class LinkDeviceViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
private fun addDeviceWithSync(linkUri: Uri) {
|
||||
val ephemeralBackupKey = BackupKey(Util.getSecretBytes(32))
|
||||
val result = LinkDeviceRepository.addDevice(linkUri, ephemeralBackupKey)
|
||||
val ephemeralMessageBackupKey = MessageBackupKey(Util.getSecretBytes(32))
|
||||
val result = LinkDeviceRepository.addDevice(linkUri, ephemeralMessageBackupKey)
|
||||
|
||||
_state.update {
|
||||
it.copy(
|
||||
@@ -235,7 +235,7 @@ class LinkDeviceViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
Log.i(TAG, "Beginning the archive generation process...")
|
||||
val uploadResult = LinkDeviceRepository.createAndUploadArchive(ephemeralBackupKey, waitResult.id, waitResult.created)
|
||||
val uploadResult = LinkDeviceRepository.createAndUploadArchive(ephemeralMessageBackupKey, waitResult.id, waitResult.created)
|
||||
when (uploadResult) {
|
||||
LinkDeviceRepository.LinkUploadArchiveResult.Success -> {
|
||||
_state.update {
|
||||
@@ -258,7 +258,7 @@ class LinkDeviceViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
private fun addDeviceWithoutSync(linkUri: Uri) {
|
||||
val result = LinkDeviceRepository.addDevice(linkUri, ephemeralBackupKey = null)
|
||||
val result = LinkDeviceRepository.addDevice(linkUri, ephemeralMessageBackupKey = null)
|
||||
|
||||
_state.update {
|
||||
it.copy(
|
||||
|
||||
Reference in New Issue
Block a user