diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/setupEncryption/SetupEncryptionDialogFragment.kt b/app/src/main/java/com/owncloud/android/ui/dialog/setupEncryption/SetupEncryptionDialogFragment.kt
index 057873270a5e..8b7a89158cf2 100644
--- a/app/src/main/java/com/owncloud/android/ui/dialog/setupEncryption/SetupEncryptionDialogFragment.kt
+++ b/app/src/main/java/com/owncloud/android/ui/dialog/setupEncryption/SetupEncryptionDialogFragment.kt
@@ -115,6 +115,7 @@ class SetupEncryptionDialogFragment :
// Setup layout
viewThemeUtils.material.colorTextInputLayout(binding.encryptionPasswordInputContainer)
+ viewThemeUtils.material.colorProgressBar(binding.progressBar)
val builder = buildMaterialAlertDialog(binding.root)
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(requireContext(), builder)
@@ -158,70 +159,79 @@ class SetupEncryptionDialogFragment :
private fun decryptPrivateKey(dialog: DialogInterface) {
Log_OC.d(TAG, "Decrypt private key")
binding.encryptionStatus.setText(R.string.end_to_end_encryption_decrypting)
+ binding.progressBar.visibility = View.VISIBLE
- try {
- if (downloadKeyResult !is DownloadKeyResult.Success) {
- Log_OC.d(TAG, "DownloadKeyResult is not success")
- return
- }
+ lifecycleScope.launch(Dispatchers.IO) {
+ try {
+ if (downloadKeyResult !is DownloadKeyResult.Success) {
+ Log_OC.d(TAG, "DownloadKeyResult is not success")
+ return@launch
+ }
- val privateKey = (downloadKeyResult as DownloadKeyResult.Success).privateKey
- if (privateKey.isNullOrEmpty()) {
- Log_OC.e(TAG, "privateKey is null or empty")
- return
- }
- val mnemonicUnchanged = binding.encryptionPasswordInput.text.toString().trim()
- val mnemonic =
- binding.encryptionPasswordInput.text.toString().replace("\\s".toRegex(), "")
- .lowercase()
- val decryptedPrivateKey = CryptoHelper.decryptPrivateKey(
- privateKey,
- mnemonic
- )
- val accountName = user?.accountName ?: return
+ val privateKey = (downloadKeyResult as DownloadKeyResult.Success).privateKey
+ if (privateKey.isNullOrEmpty()) {
+ Log_OC.e(TAG, "privateKey is null or empty")
+ return@launch
+ }
+ val mnemonicUnchanged = binding.encryptionPasswordInput.text.toString().trim()
+ val mnemonic =
+ binding.encryptionPasswordInput.text.toString().replace("\\s".toRegex(), "")
+ .lowercase()
+ val decryptedPrivateKey = CryptoHelper.decryptPrivateKey(
+ privateKey,
+ mnemonic
+ )
+ val accountName = user?.accountName ?: return@launch
- arbitraryDataProvider?.storeOrUpdateKeyValue(
- accountName,
- EncryptionUtils.PRIVATE_KEY,
- decryptedPrivateKey
- )
- dialog.dismiss()
+ arbitraryDataProvider?.storeOrUpdateKeyValue(
+ accountName,
+ EncryptionUtils.PRIVATE_KEY,
+ decryptedPrivateKey
+ )
- Log_OC.d(TAG, "Private key successfully decrypted and stored")
+ Log_OC.d(TAG, "Private key successfully decrypted and stored")
- arbitraryDataProvider?.storeOrUpdateKeyValue(
- accountName,
- EncryptionUtils.MNEMONIC,
- mnemonicUnchanged
- )
+ arbitraryDataProvider?.storeOrUpdateKeyValue(
+ accountName,
+ EncryptionUtils.MNEMONIC,
+ mnemonicUnchanged
+ )
- // check if private key and public key match
- val publicKey = arbitraryDataProvider?.getValue(
- accountName,
- EncryptionUtils.PUBLIC_KEY
- )
+ // check if private key and public key match
+ val publicKey = arbitraryDataProvider?.getValue(
+ accountName,
+ EncryptionUtils.PUBLIC_KEY
+ )
- val firstKey = EncryptionUtils.generateKey()
- val base64encodedKey = EncryptionUtils.encodeBytesToBase64String(firstKey)
- val encryptedString = EncryptionUtils.encryptStringAsymmetric(
- base64encodedKey,
- publicKey
- )
- val decryptedString = EncryptionUtils.decryptStringAsymmetric(
- encryptedString,
- decryptedPrivateKey
- )
- val secondKey = EncryptionUtils.decodeStringToBase64Bytes(decryptedString)
+ val firstKey = EncryptionUtils.generateKey()
+ val base64encodedKey = EncryptionUtils.encodeBytesToBase64String(firstKey)
+ val encryptedString = EncryptionUtils.encryptStringAsymmetric(
+ base64encodedKey,
+ publicKey
+ )
+ val decryptedString = EncryptionUtils.decryptStringAsymmetric(
+ encryptedString,
+ decryptedPrivateKey
+ )
+ val secondKey = EncryptionUtils.decodeStringToBase64Bytes(decryptedString)
- if (!firstKey.contentEquals(secondKey)) {
- EncryptionUtils.reportE2eError(arbitraryDataProvider, user)
- throw Exception("Keys do not match")
- }
+ if (!firstKey.contentEquals(secondKey)) {
+ EncryptionUtils.reportE2eError(arbitraryDataProvider, user)
+ throw Exception("Keys do not match")
+ }
- notifyResult()
- } catch (e: Exception) {
- binding.encryptionStatus.setText(R.string.end_to_end_encryption_wrong_password)
- Log_OC.e(TAG, "Error while decrypting private key: " + e.message)
+ withContext(Dispatchers.Main) {
+ dialog.dismiss()
+ notifyResult()
+ }
+ } catch (e: Exception) {
+ Log_OC.e(TAG, "Error while decrypting private key: " + e.message)
+
+ withContext(Dispatchers.Main) {
+ binding.encryptionStatus.setText(R.string.end_to_end_encryption_wrong_password)
+ binding.progressBar.visibility = View.GONE
+ }
+ }
}
}
diff --git a/app/src/main/res/layout/setup_encryption_dialog.xml b/app/src/main/res/layout/setup_encryption_dialog.xml
index 61702a8fb5df..fdd75b65661e 100644
--- a/app/src/main/res/layout/setup_encryption_dialog.xml
+++ b/app/src/main/res/layout/setup_encryption_dialog.xml
@@ -11,6 +11,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
android:gravity="clip_horizontal"
android:orientation="vertical"
android:padding="@dimen/dialog_padding">
@@ -35,6 +36,17 @@
tools:text="@string/placeholder_passphrase"
tools:visibility="visible" />
+
+