Skip to content

Commit 271eb31

Browse files
authored
Merge pull request #5871 from vector-im/feature/bca/fix_freeze_setup_recovery
fix doing password stretching on main thread
2 parents cd52df5 + a1e980d commit 271eb31

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

changelog.d/5871.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix UX freezing when creating secure backup

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/secrets/DefaultSharedSecretStorageService.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
6666
key: SsssKeySpec?,
6767
keyName: String,
6868
keySigner: KeySigner?): SsssKeyCreationInfo {
69-
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.main) {
69+
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.computation) {
7070
val bytes = (key as? RawBytesKeySpec)?.privateKey
7171
?: ByteArray(32).also {
7272
SecureRandom().nextBytes(it)
@@ -99,7 +99,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
9999
passphrase: String,
100100
keySigner: KeySigner,
101101
progressListener: ProgressListener?): SsssKeyCreationInfo {
102-
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.main) {
102+
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.computation) {
103103
val privatePart = generatePrivateKeyWithPassword(passphrase, progressListener)
104104

105105
val storageKeyContent = SecretStorageKeyContent(
@@ -158,7 +158,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
158158
}
159159

160160
override suspend fun storeSecret(name: String, secretBase64: String, keys: List<SharedSecretStorageService.KeyRef>) {
161-
withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.main) {
161+
withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.computation) {
162162
val encryptedContents = HashMap<String, EncryptedSecretContent>()
163163
keys.forEach {
164164
val keyId = it.keyId
@@ -316,7 +316,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
316316
val algorithm = key.keyInfo.content
317317
if (SSSS_ALGORITHM_CURVE25519_AES_SHA2 == algorithm.algorithm) {
318318
val keySpec = secretKey as? RawBytesKeySpec ?: throw SharedSecretStorageError.BadKeyFormat
319-
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.main) {
319+
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.computation) {
320320
// decrypt from recovery key
321321
withOlmDecryption { olmPkDecryption ->
322322
olmPkDecryption.setPrivateKey(keySpec.privateKey)
@@ -331,7 +331,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
331331
}
332332
} else if (SSSS_ALGORITHM_AES_HMAC_SHA2 == algorithm.algorithm) {
333333
val keySpec = secretKey as? RawBytesKeySpec ?: throw SharedSecretStorageError.BadKeyFormat
334-
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.main) {
334+
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.computation) {
335335
decryptAesHmacSha2(keySpec, name, secretContent)
336336
}
337337
} else {

0 commit comments

Comments
 (0)