android 访问https 证书问题 报错javax.net.ssl.SSLHandshakeException
来源:互联网 发布:淘宝商家怎么找到淘客 编辑:程序博客网 时间:2024/06/07 12:53
服务器url 切换为https后所有接口调用报错javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
解决办法:
Android项目中使用 retrofit + rxjava +mvvp 架构
故在RetrofitConfig.java 的配置文件中 初始化
initOkhttp(){}
方法中加入以下代码
OkHttpClient.Builder builder = new OkHttpClient.Builder();int[] certificates = {R.raw.new_dd};String hosts[]= {"*.diandianwaimai.com"};//builder.sslSocketFactory(SslContextFactory.getSSLSocketFactory(DDApplication.getInstance().getContext(), certificates));//builder.hostnameVerifier(SslContextFactory.getHostnameVerifier(hosts));try { CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509"); KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(null); String certificateAlias = Integer.toString(0); keyStore.setCertificateEntry(certificateAlias, certificateFactory. generateCertificate(DDApplication.getInstance().getContext().getResources().openRawResource(R.raw.new_dd))); SSLContext sslContext = SSLContext.getInstance("TLS"); final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); trustManagerFactory.init(keyStore); sslContext.init ( null, trustManagerFactory.getTrustManagers(), new SecureRandom() ); builder.sslSocketFactory(sslContext.getSocketFactory()); builder.hostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String s, SSLSession sslSession) { return true; } });} catch (CertificateException e) { e.printStackTrace();} catch (KeyStoreException e) { e.printStackTrace();} catch (NoSuchAlgorithmException e) { e.printStackTrace();} catch (IOException e) { e.printStackTrace();} catch (KeyManagementException e) { e.printStackTrace();} catch (Exception ex) {}
其中 new_dd 文件是在raw目录下
生成.cer文件的方式给出链接自己去看,我就不重复了
http://blog.csdn.net/shenxiandashu/article/details/46456403
阅读全文
1 0
- android 访问https 证书问题 报错javax.net.ssl.SSLHandshakeException
- android ksoap2 访问https javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorExce
- Android ksoap 访问https SSL Webservice报错 javax.net.ssl.SSLException: Not trusted server certificate
- OkHttp报错javax.net.ssl.SSLHandshakeException: Handshake failed
- 报错javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException
- OkHttp报错javax.net.ssl.SSLHandshakeException: Handshake failed
- OkHttp报错javax.net.ssl.SSLHandshakeException: Handshake failed
- 解决Java调用https服务证书错误javax.net.ssl.SSLHandshakeException
- https请求证书异常javax.net.ssl.SSLHandshakeException sun.security.validator.Validator
- javax.net.ssl.SSLHandshakeException
- javax.net.ssl.SSLHandshakeException
- javax.net.ssl.SSLHandshakeException
- 使用Java访问https接口javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
- 访问https,抛出的异常javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
- javax.net.ssl.SSLHandshakeException(Cas导入证书)
- 使用https出错javax.net.ssl.SSLHandshakeException: Handshake failed
- xUtils3 Https请求报错:javax.net.ssl.SSLPeerUnverifiedException: Hostname ***.****.**not verified,跳过证书检测
- 解决OKHttp3 报OKHTTP javax.net.ssl.SSLHandshakeException错误
- Multiple dex files define Landroid/support/v4/accessibilityservice解决方法
- C++ MFC listcontrol简单例子参考
- iOS之ReactiveCocoa源码及难点分析
- myeclipse的jsp文件如何转换成utf8默认编码
- 正则表达式
- android 访问https 证书问题 报错javax.net.ssl.SSLHandshakeException
- HashMap源码解析(注释版)
- NMake的原理-makefile入门
- XSS攻击与防御
- linux下解决activeMQ访问后台页面报503页面
- Label Propagation算法Giraph实现
- EL表达式jsp页面double小数点后保留两位
- 时间戳修改
- hdu 1075What Are You Talking About(map或trie)