【发布时间】:2016-03-08 15:25:14
【问题描述】:
我需要为 Webview 进行公钥/证书固定。我看到API21中已经引入了一个api 根据 Android 文档, http://developer.android.com/reference/android/webkit/WebViewClient.html#onReceivedClientCertRequest(android.webkit.WebView, android.webkit.ClientCertRequest)
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);
}
【问题讨论】:
标签: android ssl webview ssl-certificate webclient