0
我需要为Webview执行公钥/证书锁定。我看到有已API21 被引入作为每Android文档的API, http://developer.android.com/reference/android/webkit/WebViewClient.html#onReceivedClientCertRequest(android.webkit.WebView,android.webkit.ClientCertRequest)未在Webview中获取onReceivedClientCertRequest的回调
onReceivedClientCertRequest()
在API 21中添加的,但我没有得到回调,当我加载任何URL。任何人都可以请帮忙?
@Override
public void onReceivedClientCertRequest(WebView view, final ClientCertRequest request) {
Log.e("ClientCertRequest", "===> certificate required!");
KeyChain.choosePrivateKeyAlias(WebViewActivity.this, new KeyChainAliasCallback(){
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void alias(String alias) {
Log.e(getClass().getSimpleName(), "===>Key alias is: " + alias);
try {
PrivateKey changPrivateKey = KeyChain.getPrivateKey(WebViewActivity.this, alias);
X509Certificate[] certificates = KeyChain.getCertificateChain(WebViewActivity.this, alias);
Log.v(getClass().getSimpleName(), "===>Getting Private Key Success!");
request.proceed(changPrivateKey, certificates);
} catch (KeyChainException e) {
Log.e(getClass().getSimpleName(), Util.printException(e));
} catch (InterruptedException e) {
Log.e(getClass().getSimpleName(), Util.printException(e));
}
}
},new String[]{"RSA"}, null, null, -1, null);
super.onReceivedClientCertRequest(view,request);
}