I am trying to use digital certificate in Android to log in a Webview. In all the devices that I have used I do not find a problem but in the Huawei this exception jumps me:
java.lang.AssertionError: could not bind to KeyChainService
Does anyone sound like it?
Thank you.
API 24 (Android 7.0) EMUI 5.1, Code:
@SuppressLint("WrongConstant")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
override fun onReceivedClientCertRequest(view: WebView, request: ClientCertRequest) {
var keyTypes: Array<String>? = request.keyTypes
if (keyTypes == null)
keyTypes = arrayOf()
KeyChain.choosePrivateKeyAlias(
this@LoginClaveActivity,
KeyChainAliasCallback { alias ->
if (alias == null) {
request.cancel()
return@KeyChainAliasCallback
}
object : AsyncTask<Void, Void, Void>() {
override fun doInBackground(vararg params: Void): Void? {
val privateKey: PrivateKey?
val certificateChain: Array<X509Certificate>?
try {
privateKey = KeyChain.getPrivateKey(this@LoginClaveActivity, alias)
certificateChain = KeyChain.getCertificateChain(this@LoginClaveActivity, alias)
} catch (e: InterruptedException) {
request.ignore()
return null
} catch (e: KeyChainException) {
request.ignore()
return null
}
request.proceed(privateKey, certificateChain)
return null
}
}.execute()
},
keyTypes,
request.principals,
request.host,
request.port, null)
}