android4.0以上webview加载SSl证书兼容性问题
来源:互联网 发布:婴儿创意照片软件 编辑:程序博客网 时间:2024/06/05 09:03
下面参考了其他博客获取证书。public class AppConfig{private static WebView mWebView;public static X509Certificate[] mX509Certificates;public static PrivateKey mPrivateKey;public static String CERTFILE_PASSWORD;private static void clearParent(){if (mWebView != null){ViewGroup p = (ViewGroup) mWebView.getParent();if (p != null){p.removeAllViewsInLayout();}}}public static void initPrivateKeyAndX509Certificate(Context c)throws Exception{if (mPrivateKey != null && mX509Certificates != null){return;}KeyStore keyStore = KeyStore.getInstance("PKCS12", "BC");keyStore.load(c.getResources().openRawResource(R.raw.dianshang),CERTFILE_PASSWORD.toCharArray());Enumeration<?> localEnumeration;localEnumeration = keyStore.aliases();while (localEnumeration.hasMoreElements()){String str3 = (String) localEnumeration.nextElement();mPrivateKey =(PrivateKey) keyStore.getKey(str3,CERTFILE_PASSWORD.toCharArray());if (mPrivateKey == null){continue;}else{Certificate[] arrayOfCertificate =keyStore.getCertificateChain(str3);mX509Certificates =new X509Certificate[arrayOfCertificate.length];for (int j = 0; j < mX509Certificates.length; j++){mX509Certificates[j] =((X509Certificate) arrayOfCertificate[j]);}}}}public static void initPrivateKeyAndX509Certificate(Context c,InputStream in) throws Exception{if (mPrivateKey != null && mX509Certificates != null){return;}KeyStore keyStore = KeyStore.getInstance("PKCS12", "BC");keyStore.load(in, CERTFILE_PASSWORD.toCharArray());Enumeration<?> localEnumeration;localEnumeration = keyStore.aliases();while (localEnumeration.hasMoreElements()){String str3 = (String) localEnumeration.nextElement();mPrivateKey =(PrivateKey) keyStore.getKey(str3,CERTFILE_PASSWORD.toCharArray());if (mPrivateKey == null){continue;}else{Certificate[] arrayOfCertificate =keyStore.getCertificateChain(str3);mX509Certificates =new X509Certificate[arrayOfCertificate.length];for (int j = 0; j < mX509Certificates.length; j++){mX509Certificates[j] =((X509Certificate) arrayOfCertificate[j]);}}}}}
下面是复写WebViewClient或者WebViewClientClassicExt()具体兼容性问题可以参考下面类的注释:
/** * 4.0-4.1可以继承WebViewClient类实现下面的方法(4.1以上不兼容,执行不了类里面的加载证书的方法) * 但是在4.1以上上面的方法不可用,必须继承WebViewClientClassicExt方可实现证书加载(4.1以上部分方法的调用放到这个类里面了) * @author dennis * */public class AppWebViewClientEx extends WebViewClientClassicExt{public AppWebViewClientEx(Context c){}public void onReceivedClientCertRequest(WebView view,ClientCertRequestHandler handler, String host_and_port){if ((null != AppConfig.mPrivateKey)&& ((null != AppConfig.mX509Certificates) && (AppConfig.mX509Certificates.length != 0))){handler.proceed(AppConfig.mPrivateKey, AppConfig.mX509Certificates);}else{handler.cancel();}}@Overridepublic void onReceivedSslError(final WebView view, SslErrorHandler handler,SslError error){handler.proceed();}}使用隐藏api:
这个问题弄了好久终于搞定了4.0以上webview加载ssl证书不兼容问题....纠结死了....
2 1
- android4.0以上webview加载SSl证书兼容性问题
- android4.0的一兼容性问题
- android5.0以上webview无法加载图片问题
- android webview 跳过免费ssl证书验证
- Android4.0以上 代码混淆
- android4.4以上 webview加在图片的缩放问题
- 招商银行支付时WebView无法加载证书
- android webview 加载https --忽略证书
- webview的自定义SSL认证配置(p12证书)
- Android静态安全检测 -> WebView忽略SSL证书错误检测
- 用WebView访问证书有问题的SSL网页
- Android APP之WebView如何校验SSL证书
- android4.0以上pad隐藏状态栏
- android4.0以上pad隐藏状态栏
- android4.0以上平板 隐藏状态栏
- android4.0以上pad隐藏状态栏
- Android4.0以上调用设置方法
- android4.0以上实现Mqtt客户端
- 生成指定长度的随机字符串
- Linux数据管理——文件锁定
- Layout_weight详解
- 将模式对话框的返回值回送(PostBack)到服务端
- 给新入职的网络工程师忠告,你和公司要求差得不是一点点!!!
- android4.0以上webview加载SSl证书兼容性问题
- 利用Helix Server的SMIL支持在ASP中生成媒体流的播放列表
- base64 encode decode
- windows调用与dos调用区别
- C++ 虚函数表解析
- windowSoftInputMode属性设置值
- 什么是script语言
- xls文件上传
- Android 使用Service 及 BroadcastReceiver 监听Volume