Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix doing password stretching on main thread #5871

Merged
merged 1 commit into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5871.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix UX freezing when creating secure backup
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
key: SsssKeySpec?,
keyName: String,
keySigner: KeySigner?): SsssKeyCreationInfo {
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.main) {
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.computation) {
val bytes = (key as? RawBytesKeySpec)?.privateKey
?: ByteArray(32).also {
SecureRandom().nextBytes(it)
Expand Down Expand Up @@ -99,7 +99,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
passphrase: String,
keySigner: KeySigner,
progressListener: ProgressListener?): SsssKeyCreationInfo {
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.main) {
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.computation) {
val privatePart = generatePrivateKeyWithPassword(passphrase, progressListener)

val storageKeyContent = SecretStorageKeyContent(
Expand Down Expand Up @@ -158,7 +158,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
}

override suspend fun storeSecret(name: String, secretBase64: String, keys: List<SharedSecretStorageService.KeyRef>) {
withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.main) {
withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.computation) {
val encryptedContents = HashMap<String, EncryptedSecretContent>()
keys.forEach {
val keyId = it.keyId
Expand Down Expand Up @@ -316,7 +316,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
val algorithm = key.keyInfo.content
if (SSSS_ALGORITHM_CURVE25519_AES_SHA2 == algorithm.algorithm) {
val keySpec = secretKey as? RawBytesKeySpec ?: throw SharedSecretStorageError.BadKeyFormat
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.main) {
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.computation) {
// decrypt from recovery key
withOlmDecryption { olmPkDecryption ->
olmPkDecryption.setPrivateKey(keySpec.privateKey)
Expand All @@ -331,7 +331,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
}
} else if (SSSS_ALGORITHM_AES_HMAC_SHA2 == algorithm.algorithm) {
val keySpec = secretKey as? RawBytesKeySpec ?: throw SharedSecretStorageError.BadKeyFormat
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.main) {
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.computation) {
decryptAesHmacSha2(keySpec, name, secretContent)
}
} else {
Expand Down