Fixed inconsistent client cert weirdness

This commit is contained in:
Corewala 2022-05-17 20:45:40 -04:00
parent 5210d8484e
commit 29fe06ba54
2 changed files with 15 additions and 15 deletions

View File

@ -57,10 +57,7 @@ class GeminiDatasource(private val context: Context, val history: BuranHistory):
private fun geminiRequest(uri: URI, onUpdate: (state: GemState) -> Unit, clientCertPassword: String?){ private fun geminiRequest(uri: URI, onUpdate: (state: GemState) -> Unit, clientCertPassword: String?){
val protocol = "TLS" val protocol = "TLS"
//Update factory if operating mode has changed initSSLFactory(protocol!!, clientCertPassword)
when (socketFactory) {
null -> initSSLFactory(protocol!!, clientCertPassword)
}
val socket: SSLSocket? val socket: SSLSocket?
try { try {

View File

@ -77,7 +77,7 @@ class GemActivity : AppCompatActivity() {
override fun openExternal(address: String) = openExternalLink(address) override fun openExternal(address: String) = openExternalLink(address)
}) })
private var decryptedCertPassword: String? = null private var certPassword: String? = null
private var internetStatus: Boolean = false private var internetStatus: Boolean = false
@ -349,7 +349,7 @@ class GemActivity : AppCompatActivity() {
) )
binding.addressEdit.compoundDrawablePadding = 6.toPx().toInt() binding.addressEdit.compoundDrawablePadding = 6.toPx().toInt()
} }
else -> hideClientCertShield() //else -> hideClientCertShield()
} }
val showInlineIcons = prefs.getBoolean( val showInlineIcons = prefs.getBoolean(
@ -417,13 +417,15 @@ class GemActivity : AppCompatActivity() {
if(!prefs.getString(Buran.PREF_KEY_CLIENT_CERT_URI, null).isNullOrEmpty()){ if(!prefs.getString(Buran.PREF_KEY_CLIENT_CERT_URI, null).isNullOrEmpty()){
builder builder
.setPositiveButton(getString(R.string.use_client_certificate).toUpperCase()) { _, _ -> .setPositiveButton(getString(R.string.use_client_certificate).toUpperCase()) { _, _ ->
if(prefs.getBoolean("use_biometrics", false) and !decryptedCertPassword.isNullOrEmpty()){ if(prefs.getBoolean("use_biometrics", false) and certPassword.isNullOrEmpty()){
biometricSecureRequest(state.uri.toString()) biometricSecureRequest(state.uri.toString())
}else{ }else{
decryptedCertPassword = prefs.getString( if(certPassword.isNullOrEmpty()){
Buran.PREF_KEY_CLIENT_CERT_PASSWORD, certPassword = prefs.getString(
null Buran.PREF_KEY_CLIENT_CERT_PASSWORD,
) null
)
}
gemRequest(state.uri.toString()) gemRequest(state.uri.toString())
} }
} }
@ -443,7 +445,7 @@ class GemActivity : AppCompatActivity() {
showAlert("${GeminiResponse.getCodeString(state.header.code)}:\n\n${state.header.meta}") showAlert("${GeminiResponse.getCodeString(state.header.code)}:\n\n${state.header.meta}")
} }
is GemState.ClientCertError -> { is GemState.ClientCertError -> {
hideClientCertShield() //hideClientCertShield()
showAlert("${GeminiResponse.getCodeString(state.header.code)}:\n\n${state.header.meta}") showAlert("${GeminiResponse.getCodeString(state.header.code)}:\n\n${state.header.meta}")
} }
is GemState.ResponseGemtext -> renderGemtext(state) is GemState.ResponseGemtext -> renderGemtext(state)
@ -543,7 +545,7 @@ class GemActivity : AppCompatActivity() {
)!! )!!
) )
decryptedCertPassword = biometricManager.decryptData(ciphertext, result.cryptoObject?.cipher!!) certPassword = biometricManager.decryptData(ciphertext, result.cryptoObject?.cipher!!)
gemRequest(address) gemRequest(address)
} }
} }
@ -755,13 +757,14 @@ class GemActivity : AppCompatActivity() {
private fun gemRequest(address: String){ private fun gemRequest(address: String){
if(address.toURI().host != omniTerm.getCurrent().toURI().host) { if(address.toURI().host != omniTerm.getCurrent().toURI().host) {
decryptedCertPassword = null certPassword = null
} }
println(certPassword)
if(getInternetStatus()){ if(getInternetStatus()){
if(initialised){ if(initialised){
loadingView(true) loadingView(true)
return model.request(address, decryptedCertPassword) model.request(address, certPassword)
}else{ }else{
val intent = baseContext.packageManager.getLaunchIntentForPackage(baseContext.packageName) val intent = baseContext.packageManager.getLaunchIntentForPackage(baseContext.packageName)
intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)