在 Android 4 ICS 上使用 SSL 客户端证书的 WebView

WebView with SSL Client Certificate on Android 4 ICS(在 Android 4 ICS 上使用 SSL 客户端证书的 WebView)
本文介绍了在 Android 4 ICS 上使用 SSL 客户端证书的 WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have a problem with the native WebView on Android. I need to authenticate with a site using a SSL Client Certificate. The Android WebView doesn't seem to support this. As a workaround I used a modified version of the WebView:

https://github.com/yonekawa/webview-with-client-certificate

The modified WebView works by injecting a properly configured SslSocketFactory into the standard Android WebView. This works fine on Android 2.x devices. However, with Android 4 ICS it doesn't work anymore. The SslSocketFactory is still there in ICS, however, it seems that it isn't used anymore.

So my question is: has anyone succeeded in configuring the Android WebView on ICS so that it works with a client certificate? Or is there any alternative?

What I already tried:

  • importing the SSL client certificate into the Android keystore and just using the WebView without any modification. This doesn't work, the client certificate is not sent along with the requests. It works in the native browser, though.

  • creating the SSL connection myself using HttpClient, getting the HTML of the site and handing it to the WebView. This basically works, but I need to intercept all requests made by the WebView and handle them myself. However, the WebView doesn't provide the data of POST requests, which makes this approach unusable for me.

解决方案

I think what you want is overriding the following hidden method:

public void onReceivedClientCertRequest(WebView view,
ClientCertRequestHandler handler, String host_and_port) {

By default this will cancle the request.

I have used this method following this example for using hidden APIs: http://devmaze.wordpress.com/2011/01/19/using-com-android-internal-part-5-summary-and-example/

Sorry for the late answer. Just stumbled upon your question... Hope it still helps.

这篇关于在 Android 4 ICS 上使用 SSL 客户端证书的 WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)