其他分享
首页 > 其他分享> > 使用Android WebView通过客户端证书连接到安全服务器

使用Android WebView通过客户端证书连接到安全服务器

作者:互联网

WebView或更具体的PhoneGaps CordovaWebView可以使用客户端证书对服务器进行身份验证吗?

我知道本机浏览器可以使用客户端证书,但我正在尝试使用PhoneGap Android应用程序与需要客户端证书的服务器通信,并且无法查看如何使用.我尝试了各种我在谷歌上看过的方法,但它们不适用于Android 4.0或更高版本.任何建议都会受到很大的关注.

解决方法:

这不可能. sdk中不提供回答客户端证书质询所需的代码.如果你在android sdk中查看WebViewClient的源代码,你会看到这个方法

/**
 * Notify the host application to handle a SSL client certificate
 * request (display the request to the user and ask whether to
 * proceed with a client certificate or not). The host application
 * has to call either handler.cancel() or handler.proceed() as the
 * connection is suspended and waiting for the response. The
 * default behavior is to cancel, returning no client certificate.
 *
 * @param view The WebView that is initiating the callback.
 * @param handler An ClientCertRequestHandler object that will
 *            handle the user's response.
 * @param host_and_port The host and port of the requesting server.
 *
 * @hide
 */
public void onReceivedClientCertRequest(WebView view,
        ClientCertRequestHandler handler, String host_and_port) {
    handler.cancel();
}

你在doc部分看到了@hide吗?这意味着“不要向公众提供这种服务”.我们需要能够覆盖此方法并使用ClientCertRequestHandler,但我们不能.不确定谷歌何时会打开这个API,但它在JellyBean中不可用.

标签:android,cordova,webview,client-certificates,android-4-0-ice-cream-sandwich
来源: https://codeday.me/bug/20190613/1231568.html