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