@@ -18,6 +18,7 @@ import app.passwordstore.data.passfile.PasswordEntry
18
18
import app.passwordstore.ui.crypto.BasePGPActivity
19
19
import app.passwordstore.ui.crypto.PasswordDialog
20
20
import app.passwordstore.util.auth.BiometricAuthenticator
21
+ import app.passwordstore.util.auth.BiometricAuthenticator.Result
21
22
import app.passwordstore.util.autofill.AutofillPreferences
22
23
import app.passwordstore.util.autofill.AutofillResponseBuilder
23
24
import app.passwordstore.util.autofill.DirectoryStructure
@@ -70,33 +71,49 @@ class AutofillDecryptActivity : BasePGPActivity() {
70
71
directoryStructure = AutofillPreferences .directoryStructure(this )
71
72
logcat { action.toString() }
72
73
requireKeysExist {
73
- val gpgIdentifiers = getPGPIdentifiers(" " ) ? : return @requireKeysExist
74
74
if (
75
75
features.isEnabled(EnablePGPPassphraseCache ) && BiometricAuthenticator .canAuthenticate(this )
76
76
) {
77
77
BiometricAuthenticator .authenticate(
78
78
this ,
79
79
R .string.biometric_prompt_title_gpg_passphrase_cache,
80
80
) { authResult ->
81
- if (authResult is BiometricAuthenticator .Result .Success ) {
82
- lifecycleScope.launch {
83
- val cachedPassphrase =
84
- passphraseCache.retrieveCachedPassphrase(
85
- this @AutofillDecryptActivity,
86
- gpgIdentifiers.first()
87
- )
88
- if (cachedPassphrase != null ) {
89
- decrypt(File (filePath), clientState, action, cachedPassphrase)
90
- } else {
91
- askPassphrase(filePath, clientState, action)
92
- }
93
- }
81
+ decrypt(filePath, clientState, action, authResult)
82
+ }
83
+ } else {
84
+ decrypt(filePath, clientState, action, Result .Cancelled )
85
+ }
86
+ }
87
+ }
88
+
89
+ private fun decrypt (
90
+ filePath : String ,
91
+ clientState : Bundle ,
92
+ action : AutofillAction ,
93
+ authResult : Result ,
94
+ ) {
95
+ val gpgIdentifiers = getPGPIdentifiers(" " ) ? : return
96
+ lifecycleScope.launch(dispatcherProvider.main()) {
97
+ when (authResult) {
98
+ // Internally handled by the prompt dialog
99
+ is Result .Retry -> {}
100
+ // If the dialog is dismissed for any reason, prompt for passphrase
101
+ is Result .Cancelled ,
102
+ is Result .Failure ,
103
+ is Result .HardwareUnavailableOrDisabled -> askPassphrase(filePath, clientState, action)
104
+ //
105
+ is Result .Success -> {
106
+ val cachedPassphrase =
107
+ passphraseCache.retrieveCachedPassphrase(
108
+ this @AutofillDecryptActivity,
109
+ gpgIdentifiers.first()
110
+ )
111
+ if (cachedPassphrase != null ) {
112
+ decryptWithPassphrase(File (filePath), clientState, action, cachedPassphrase)
94
113
} else {
95
114
askPassphrase(filePath, clientState, action)
96
115
}
97
116
}
98
- } else {
99
- askPassphrase(filePath, clientState, action)
100
117
}
101
118
}
102
119
}
@@ -107,15 +124,15 @@ class AutofillDecryptActivity : BasePGPActivity() {
107
124
withContext(dispatcherProvider.main()) {
108
125
dialog.password.collectLatest { value ->
109
126
if (value != null ) {
110
- decrypt (File (filePath), clientState, action, value)
127
+ decryptWithPassphrase (File (filePath), clientState, action, value)
111
128
}
112
129
}
113
130
}
114
131
}
115
132
dialog.show(supportFragmentManager, " PASSWORD_DIALOG" )
116
133
}
117
134
118
- private suspend fun decrypt (
135
+ private suspend fun decryptWithPassphrase (
119
136
filePath : File ,
120
137
clientState : Bundle ,
121
138
action : AutofillAction ,
0 commit comments