Axis 1 https(SSL) client 证书验证错误ValidatorException workaround
Axis 1.x 编写的client在测试https的webservice的时候, 由于client 代码建立SSL连接的时候没有对truststore进行设置,在与https部署的webservice 连接会在运行时报出:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
这是由于Axis的client用默认的SocketFactory,会对server端的证书进行验证,我们的测试server是自签名的,client检测到后自动断开连接,握手失败。
网上很多解决方案是用sun的keytool生成clientTrustStore和serverTrustStrore并把证书导进去,这些方法都稍显繁琐,我们这种client测试类没必要做一些程序之外的工作,所以综合了一个解决方案,想到这个办法。此方法的灵感来自于axis文档里的dirty solution。
核心思想是自己做一个不对证书做任何检查的SocketFactory,并用这个socket factory来替换Axis本身用的SocketFactory, 为了方便,MySocketFactory直接继承Axis的父类JSSESocketFactory 。并且重写父类方法
protected void initFactory() throws IOException
initFactory方法的内容,很簡單,就是让checkServerTrusted/checkClientTrusted什么都不返回,然后最后一行将这个SslSocketFactory赋给我们自定义类里的sslFactory变量。
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
} public void checkClientTrusted(X509Certificate[] certs, String authType) {
// Trust always
} public void checkServerTrusted(X509Certificate[] certs, String authType) {
// Trust always
}
}
}; // Install the all-trusting trust manager
SSLContext sc = SSLContext.getInstance("SSL");
// Create empty HostnameVerifier
HostnameVerifier hv = new HostnameVerifier() {
public boolean verify(String arg0, SSLSession arg1) {
return true;
}
}; sc.init(null, trustAllCerts, new java.security.SecureRandom());
sslFactory = sc.getSocketFactory;
Axis client测试类中用
AxisProperties.setProperty("axis.socketSecureFactory","my.test.MySocketFactory")来指定Axis类库要调用的SocketFactory,就是之前被我们改写的不对server certificate做任何验证的Factory。
这个解决方式绝对简单,不需要跟其他方式一样用sun的keytool建立导入一些本地证书,并利用了Axis自己的机制处理证书验证问题。
Axis 1 https(SSL) client 证书验证错误ValidatorException workaround的更多相关文章
- [转]浅谈https\ssl\数字证书
浅谈https\ssl\数字证书 http://www.cnblogs.com/P_Chou/archive/2010/12/27/https-ssl-certification.html 全球可信的 ...
- 浅谈https\ssl\数字证书
全球可信的SSL数字证书申请:http://www.shuzizhengshu.com 在互联网安全通信方式上,目前用的最多的就是https配合ssl和数字证书来保证传输和认证安全了.本文追本溯源围绕 ...
- 【转】浅谈https\ssl\数字证书
转载请注明出处:http://www.cnblogs.com/P_Chou/archive/2010/12/27/https-ssl-certification.html 全球可信的SSL数字证书申请 ...
- 三步解决fiddler升级后https无法通过证书验证问题
有时候使用fiddler时,https页面会出现错误提示,我们可以这样设置来避免错误 第一步:去掉https的抓取 Tools>Option 去掉Capture HTTPS CONNECTs 的 ...
- 解决python2.x用urllib2证书验证错误, _create_unverified_context
解决以下错误: 错误1:AttributeError: 'module' object has no attribute '_create_unverified_context', 错误2:URLEr ...
- Xcode中使用svn时,报证书验证错误Error validating server certificate for
转:http://blog.csdn.net/yhawaii/article/details/7511141 今天使用Xcode自带的svn客户端时,总是连接不上服务器,报如下错误: Error va ...
- java连接https时禁用证书验证.
import java.io.File; import java.security.cert.CertificateException; import java.util.List; import j ...
- https(ssl) 免费证书
https://letsencrypt.org/getting-started/ https://certbot.eff.org/lets-encrypt/centosrhel7-nginx http ...
- HTTPS请求 SSL证书验证
import urllib2 url = "https://www.12306.cn/mormhweb/" headers = {"User-Agent": & ...
随机推荐
- python day2 列表的常用操作方法
#创建列表方法一li = ['aa','bb','cc']方法二li = list(['aa','bb','cc'])print(li)返回 ['aa', 'bb', 'cc']----------- ...
- UITabar 设置字体大小/颜色
1.设置被选中字体颜色 [self.tabBarController.tabBar setTintColor:[UIColor blackColor]];
- 面向对象程序设计 第二次作业<1>
Github链接:https://github.com/zora02/object-oriented/tree/master/1001.A%2BB%20Format%20(20) 一.解题 题目 解题 ...
- Vim自动补全神器–YouCompleteMe
YouCompleteMe的特别之处 基于语义补全 总所周知,Vim是一款文本编辑器.也就是说,其最基础的工作就是编辑文本,而不管该文本的内容是什么.在Vim被程序员所使用后,其慢慢的被肩负了与IDE ...
- git push --help
git-push(1) Manual Page NAME git-push - Update remote refs along with associated objects SYNOPSIS gi ...
- c#闭包(转)
出处:http://www.cnblogs.com/birdwudi/archive/2010/08/20/1804342.html --------------------------------- ...
- java 实现多个文件的Zip包的生成
最近在项目中遇到多个文件的达成Zip包,由于对这块不熟,在网上找到一个,现在忘了找的谁的,如果您发现了,请告诉我你的链接,我指明出处 下面是相关代码: package run.utils; impor ...
- Cobbler学习之二--Cobbler的Web管理和维护
Cobbler的Web管理模块和命令行模块是可以分开工作的,没有依赖关系. 1 WebUI的功能 查看所有的对象和配置文件 添加或者删除system,distro, profile 执行“cobble ...
- !important
当你需要确保某元素具有指定的 CSS 时,你可以使用!important. 举例如下: color: pink !important;
- Android密码约束规则例子一
Android常用的一个密码规则 (一)密码必须是8至16位:(二)密码必须包含英文字母和数字:(三)密码不能包含4位连续相同的字符,如0000或AAAA:(四)密码不能包含4位连续递增或连续递减的数 ...