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": & ...
随机推荐
- RSpec shared examples with template methods
It’s pretty common to have multiple tests that are nearly the same. In one app, we support bidding o ...
- 按Enter键触发事件
1.document.onkeydown=function(e){ var keycode=document.all?event.keyCode:e.which; if(k ...
- URAL1132_Square Root
求解方程,x^2=n (mod P). 解二次同余方程的步骤: 1.首先判断勒让德符号(n,p)是否的等于1,即n^((p-1/2)=1 (mod p)是否成立.不成立显然无解.(略) 2.任取0-( ...
- Ubuntu上安装Minecraft服务器
Minecraft由于其独特的魅力吸引了很多玩家.不过游戏的乐趣只有在和朋友一起玩的时候才最有意思,所以很早以前我就想建设自己的服务器.但由于专业知识欠缺,没有实现. 最近接触了Linux服务器,所以 ...
- POJ 2151 Check the difficulty of problems (概率DP)
题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 ,求每队至少解出一题且冠军队至少解出N道题的概率. 析:概率DP,dp[i][j][k] 表示第 i 个队伍,前 j 个题,解出 ...
- 我与solr(二)--导入mysql数据库
关于solr的搭建详见上一篇的随笔. 步骤1: 在webapps中solrhome下新建一个文件夹名字叫做mynode(名字不固定,可以随便取,但是这个名字在后面的配置中会有所关联.)然后在mynod ...
- gulp-rev-orig
给客户演示项目时,老是会出现由于缓存,造成的最新的样式或者效果出不来的情况,还得需要手动清除缓存操作,一方面呢,会给客户留下不好的印象,而且也会多了清缓存这一过程,和同事商量过后,决定使用在css或者 ...
- html5+css3 制作音乐播放器
//css// body , html{ margin:0; padding:0; font:12px Arial, Helvetica, sans-serif; } .Mus ...
- [置顶]PADS PCB功能使用技巧系列之NO.002- 如何走差分线?
差分信号在高速电路设计中应用越来越广泛,如USB.HDMI.PCI.DDR*等,承载差分信号的差分线主要优势有:抗干扰能力强,能有效抑制EMI.时序定位精确等,对于PCB工程师来说,最关注的是如何确保 ...
- Unity and C#: Game Loop (Awake, Start, Update)
Introduction The central component of any game, from a programming standpoint, is the game loop. It ...