android - 使用 Android WebView 连接到带有客户端证书的安全服务器

标签 android cordova webview android-4.0-ice-cream-sandwich client-certificates

WebView 或更具体地说,PhoneGaps CordovaWebView 能否使用客户端证书向服务器进行身份验证?

我知道 native 浏览器可以使用客户端证书,但我正在尝试让 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();
}

你在文档部分看到@hide了吗?这意味着“不要将其提供给公众”。我们需要能够覆盖此方法并利用 ClientCertRequestHandler,但我们做不到。不确定谷歌何时会开放此 API,但它在 JellyBean 中不可用。

关于android - 使用 Android WebView 连接到带有客户端证书的安全服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12807742/

相关文章:

c# - 如何保持 Webview 作为 BackgroundTask C# UWP Windows 10 运行

Android 视频 WebView 全屏不工作 - onShowCustomView() 未调用

ios - 如何修复 iOS5 和 iOS6 上有问题的 webkit-text-size-adjust?

android - 关于谷歌最新架构指南的 MVVM 模式,如何将数据(通知)从存储库类传递到模型 View 类

android - MediaCodec-故意向音频轨道添加静音

android - 如何将另一个 Activity 作为主 Activity(启动)

ios - 如何在没有 JQuery Mobile 脚本的情况下在 Cordova 应用程序中的 iOS 中获得平滑快速的滚动

android - iPhone/Android 引入原生下拉选择器

android - 如何从 Assets 文件夹中的图像创建可绘制对象?

android - Phonegap 使用默认阅读器打开 pdf(IOS 和 Android)