fix doing password stretching on main thread
This commit is contained in:
parent
cd52df5d2e
commit
a1e980d103
1
changelog.d/5871.bugfix
Normal file
1
changelog.d/5871.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix UX freezing when creating secure backup
|
@ -66,7 +66,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
|
|||||||
key: SsssKeySpec?,
|
key: SsssKeySpec?,
|
||||||
keyName: String,
|
keyName: String,
|
||||||
keySigner: KeySigner?): SsssKeyCreationInfo {
|
keySigner: KeySigner?): SsssKeyCreationInfo {
|
||||||
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.main) {
|
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.computation) {
|
||||||
val bytes = (key as? RawBytesKeySpec)?.privateKey
|
val bytes = (key as? RawBytesKeySpec)?.privateKey
|
||||||
?: ByteArray(32).also {
|
?: ByteArray(32).also {
|
||||||
SecureRandom().nextBytes(it)
|
SecureRandom().nextBytes(it)
|
||||||
@ -99,7 +99,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
|
|||||||
passphrase: String,
|
passphrase: String,
|
||||||
keySigner: KeySigner,
|
keySigner: KeySigner,
|
||||||
progressListener: ProgressListener?): SsssKeyCreationInfo {
|
progressListener: ProgressListener?): SsssKeyCreationInfo {
|
||||||
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.main) {
|
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.computation) {
|
||||||
val privatePart = generatePrivateKeyWithPassword(passphrase, progressListener)
|
val privatePart = generatePrivateKeyWithPassword(passphrase, progressListener)
|
||||||
|
|
||||||
val storageKeyContent = SecretStorageKeyContent(
|
val storageKeyContent = SecretStorageKeyContent(
|
||||||
@ -158,7 +158,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun storeSecret(name: String, secretBase64: String, keys: List<SharedSecretStorageService.KeyRef>) {
|
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>()
|
val encryptedContents = HashMap<String, EncryptedSecretContent>()
|
||||||
keys.forEach {
|
keys.forEach {
|
||||||
val keyId = it.keyId
|
val keyId = it.keyId
|
||||||
@ -316,7 +316,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
|
|||||||
val algorithm = key.keyInfo.content
|
val algorithm = key.keyInfo.content
|
||||||
if (SSSS_ALGORITHM_CURVE25519_AES_SHA2 == algorithm.algorithm) {
|
if (SSSS_ALGORITHM_CURVE25519_AES_SHA2 == algorithm.algorithm) {
|
||||||
val keySpec = secretKey as? RawBytesKeySpec ?: throw SharedSecretStorageError.BadKeyFormat
|
val keySpec = secretKey as? RawBytesKeySpec ?: throw SharedSecretStorageError.BadKeyFormat
|
||||||
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.main) {
|
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.computation) {
|
||||||
// decrypt from recovery key
|
// decrypt from recovery key
|
||||||
withOlmDecryption { olmPkDecryption ->
|
withOlmDecryption { olmPkDecryption ->
|
||||||
olmPkDecryption.setPrivateKey(keySpec.privateKey)
|
olmPkDecryption.setPrivateKey(keySpec.privateKey)
|
||||||
@ -331,7 +331,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
|
|||||||
}
|
}
|
||||||
} else if (SSSS_ALGORITHM_AES_HMAC_SHA2 == algorithm.algorithm) {
|
} else if (SSSS_ALGORITHM_AES_HMAC_SHA2 == algorithm.algorithm) {
|
||||||
val keySpec = secretKey as? RawBytesKeySpec ?: throw SharedSecretStorageError.BadKeyFormat
|
val keySpec = secretKey as? RawBytesKeySpec ?: throw SharedSecretStorageError.BadKeyFormat
|
||||||
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.main) {
|
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.computation) {
|
||||||
decryptAesHmacSha2(keySpec, name, secretContent)
|
decryptAesHmacSha2(keySpec, name, secretContent)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user