我使用ERROR_Failed_SSL_HANDSHAKE获得onReceivedError().在Webkit中打印日志“无法建立安全连接”.
我已经广泛搜索但找不到答案.有几个帖子但没有结论.
我尝试了 here发布的所有3个解决方案.
可能起作用的解决方案是: –
解决方案1:
无论如何都使用ClIEntcertrequestHandler(它被标记为隐藏,但显然仍然可用):
所以我修改了androID.jar以包含内部API来覆盖onReceivedClIEntcertrequest()
但我没有在运行时获得回调.任何第三方浏览器都是如此.我尝试在标准浏览器中加载相同的网页.我在UI上收到一个回调,要求用户选择一个客户端证书.
所以似乎只有系统浏览器应用程序可以从Webkit获取onReceivedClIEntcertrequest()的回调.
对于iOS平台,WebvIEw也无法直接加载网站.但是使用NSURL进行httpS连接,
将客户端证书保留在内存中一段时间,WebvIEw可以成功加载此页面.
在AndroID上,我通过注册加载客户端和服务器证书的SSLSocketFactory成功设置了httpS通信.
我可以使用它进行REST API调用.但是,与iOS不同,我找不到AndroID webvIEw可以使用客户端证书进行Mutual auth的方法.
我认为平台应该支持在WebvIEw上进行相互认证,这是安全性的基本要求之一.这个问题有没有更新?
编辑1:
根据我在下面给出的答案,我在AndroID 4.0到4.3上工作了.
Hoverer,现在在AndroID 4.4上,似乎WebVIEwClIEntClassicExt类本身被删除了.
知道在这种情况下可以做些什么吗?为什么AndroID不允许在webvIEw中设置ClIEntCertificates?
>在AndroID 4.0和4.1上,通过覆盖扩展WebVIEwClIEnt的类的onReceivedClIEntcertrequest()
>在4.2,4.3中,通过覆盖扩展WebVIEwClIEntClassicExt的类的onReceivedClIEntcertrequest().
我设置了私钥和证书ClIEntcertrequestHandler proceed()方法.
需要AndroID 4.4及更高版本的修补补丁
EDITED
解决方案uptil 4.3如下
WebvIEwClIEntCustom.java
public class WebVIEwClIEntCustom extends WebVIEwClIEnt { private X509Certificate[] certificatesChain; private PrivateKey clIEntCertPrivateKey; private IWebVIEwCallbacks webvIEwCallbacks; public WebVIEwClIEntCustom(IWebVIEwCallbacks webvIEwCallbacks) { this.webvIEwCallbacks = webvIEwCallbacks; } public voID onReceivedClIEntcertrequest(WebVIEw paramWebVIEw,ClIEntcertrequestHandler paramClIEntcertrequestHandler,String paramString) { PrivateKey localPrivateKey = this.clIEntCertPrivateKey; X509Certificate[] arrayOfX509Certificate = this.certificatesChain; paramClIEntcertrequestHandler.proceed(localPrivateKey,arrayOfX509Certificate); } public voID onReceivedError(WebVIEw vIEw,int errorCode,String description,String failingUrl) { webvIEwCallbacks.onReceivedError( vIEw,errorCode,description,failingUrl); super.onReceivedError( vIEw,failingUrl); } public voID setClIEntCertificate(PrivateKey paramPrivateKey,X509Certificate[] paramArrayOfX509Certificate) { this.clIEntCertPrivateKey = paramPrivateKey; this.certificatesChain = paramArrayOfX509Certificate; } public boolean shouldOverrIDeUrlLoading(WebVIEw paramWebVIEw,String paramString) { return webvIEwCallbacks.shouldOverrIDeUrlLoading(paramWebVIEw,paramString); } @OverrIDe public voID onPageStarted(WebVIEw vIEw,String url,Bitmap favicon) { // Todo auto-generated method stub webvIEwCallbacks.onPageStarted(vIEw,url,favicon); super.onPageStarted(vIEw,favicon); } @OverrIDe public voID onPageFinished(WebVIEw vIEw,String url) { // Todo auto-generated method stub webvIEwCallbacks.onPageFinished(vIEw,url); super.onPageFinished(vIEw,url); }}
WebVIEwClIEntCustomExt.java
public class WebVIEwClIEntCustomExt extends WebVIEwClIEntClassicExt { private X509Certificate[] certificatesChain; private PrivateKey clIEntCertPrivateKey; private IWebVIEwCallbacks webvIEwCallbacks; public WebVIEwClIEntCustomExt(IWebVIEwCallbacks webvIEwCallbacks) { this.webvIEwCallbacks = webvIEwCallbacks; } public voID onReceivedClIEntcertrequest(WebVIEw paramWebVIEw,failingUrl); } public voID setClIEntCertificate(PrivateKey paramPrivateKey,paramString); } @OverrIDe public voID onPageStarted(WebVIEw vIEw,Bitmap favicon) { // Todo auto-generated method stub webvIEwCallbacks.onPageStarted(vIEw,url); }}
用法
*/ private voID setCertificateData() { // Todo auto-generated method stub try { KeyStore clIEntCertKeystore = KeyStore.getInstance("pkcs12"); String clIEntCertPkcsPassword = getPkcsPassword(); byte[] pkcs12; pkcs12 = getAuthP12Data(); ByteArrayinputStream pkcs12BAIS = new ByteArrayinputStream(pkcs12); clIEntCertKeystore.load(pkcs12BAIS,clIEntCertPkcsPassword.tochararray()); String alias = (clIEntCertKeystore.aliases().nextElement()); Certificate[] arrayOfCertificate = clIEntCertKeystore .getCertificateChain(alias); X509Certificate[] arrayOfX509Certificate = new X509Certificate[arrayOfCertificate.length]; for (int i = 0; i < arrayOfCertificate.length; i++) { arrayOfX509Certificate[i] = (X509Certificate) arrayOfCertificate[i]; } PrivateKey localPrivateKey = (PrivateKey) clIEntCertKeystore .getKey(alias,clIEntCertPkcsPassword.tochararray()); if (androID.os.Build.VERSION.SDK_INT <= 16) { WebVIEwClIEntCustom webvvIEwClIEnt = new WebVIEwClIEntCustom( myWebVIEwClIEnt); webvvIEwClIEnt.setClIEntCertificate(localPrivateKey,arrayOfX509Certificate); webVIEw.setWebVIEwClIEnt(webvvIEwClIEnt); } else { WebVIEwClIEntCustomExt webvvIEwClIEnt = new WebVIEwClIEntCustomExt( myWebVIEwClIEnt); webvvIEwClIEnt.setClIEntCertificate(localPrivateKey,arrayOfX509Certificate); webVIEw.setWebVIEwClIEnt(webvvIEwClIEnt); } // webVIEw.getSettings().setJavaScriptEnabled(true); } catch (Exception e) { // Todo auto-generated catch block e.printstacktrace(); } }总结
以上是内存溢出为你收集整理的Android Webview客户端证书,相互身份验证,Webview上的SSL全部内容,希望文章能够帮你解决Android Webview客户端证书,相互身份验证,Webview上的SSL所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)