Skip to content
Snippets Groups Projects
Commit 819b3a8a authored by Taras's avatar Taras
Browse files

Random key backup for bsspeke

parent ebebf8b9
No related branches found
No related tags found
No related merge requests found
......@@ -129,8 +129,7 @@ interface KeysBackupService {
)
fun prepareBsSpekeKeysBackupVersion(hashedKey:ByteArray,
callback: MatrixCallback<MegolmBackupCreationInfo>)
fun prepareRandomKeyBackupVersion(callback: MatrixCallback<MegolmBackupCreationInfo>)
/**
* Delete a keys backup version. It will delete all backed up keys on the server, and the backup itself.
* If we are backing up to this version. Backup will be stopped.
......
......@@ -145,10 +145,9 @@ interface SharedSecretStorageService {
userName: String
): SsssKeyCreationInfo
suspend fun generateBsSpekeWithPassphrase(
suspend fun generateBsSpekeKeyInfo(
keyId: String,
privateKey: ByteArray,
keySigner: KeySigner,
progressListener: ProgressListener?
keySigner: KeySigner
): SsssKeyCreationInfo
}
......@@ -94,6 +94,7 @@ import org.matrix.olm.OlmPkEncryption
import org.matrix.olm.OlmPkMessage
import timber.log.Timber
import java.security.InvalidParameterException
import java.security.SecureRandom
import javax.inject.Inject
import kotlin.random.Random
......@@ -236,13 +237,14 @@ internal class DefaultKeysBackupService @Inject constructor(
}
}
override fun prepareBsSpekeKeysBackupVersion(hashedKey: ByteArray,
callback: MatrixCallback<MegolmBackupCreationInfo>) {
override fun prepareRandomKeyBackupVersion(callback: MatrixCallback<MegolmBackupCreationInfo>) {
cryptoCoroutineScope.launch(coroutineDispatchers.io) {
try {
val privateKey = ByteArray(32)
SecureRandom().nextBytes(privateKey)
val olmPkDecryption = OlmPkDecryption()
val signalableBackupAuthData = SignalableMegolmBackupAuthData(
publicKey = olmPkDecryption.setPrivateKey(hashedKey),
publicKey = olmPkDecryption.setPrivateKey(privateKey),
privateKeySalt = null,
privateKeyIterations = null
)
......@@ -272,7 +274,7 @@ internal class DefaultKeysBackupService @Inject constructor(
signatures = signatures
)
val creationInfo = MegolmBackupCreationInfo(
algorithm = BSSPEKE_ALGORITHM_BACKUP,
algorithm = MXCRYPTO_ALGORITHM_MEGOLM_BACKUP,
authData = signedBackupAuthData,
recoveryKey = computeRecoveryKey(olmPkDecryption.privateKey())
)
......
......@@ -427,11 +427,10 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
}
}
override suspend fun generateBsSpekeWithPassphrase(
override suspend fun generateBsSpekeKeyInfo(
keyId: String,
privateKey: ByteArray,
keySigner: KeySigner,
progressListener: ProgressListener?
keySigner: KeySigner
): SsssKeyCreationInfo {
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.computation) {
val storageKeyContent = SecretStorageKeyContent(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment