java.security.cert.CertificateException: No subject alternative names present
背景:在开发一个项目中,要调用一个webservice服务,之前设置的是http协议,项目中采用jdk自带的wsimport工具生成的客户端代码;
后来,需求变更要求兼容https协议的webservice,开始以为只需要简单的将服务地址的连接改为https就可以了;但不行,总是报错
javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names present at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(Unknown Source)
at javax.xml.ws.Service.<init>(Unknown Source)
at com.vrv.paw.client.area.VRVRange.<init>(VRVRange.java:48)
at com.vrv.paw.client.area.mainTest.main(mainTest.java:12)
然后就是这种百度查资料,查到以下解释
http://www.nakov.com/blog/2009/07/16/disable-certificate-validation-in-java-ssl-connections/
在开发设计中当我们在java中打开一个SSL连接(比如:java.net.URL.openConnection(“https://….”)),
JSSE实现的SSL协议执行一些验证以确保这个请求的主机不是假的。
这包括用PKIX算法验证服务器的X.509证书和检查主机名称与证书中的subject是否一致。
如果SSL证书不可信或与目标主机不匹配,HTTPS和SSL加密连接就不能建立并且抛出SSLHandshakeException 或 IOException By design when we open an SSL connection in Java (e.g. through java.net.URL.openConnection(“https://….”))
the JSSE implementation of the SSL protocol performs few validations to ensure the requested host is not fake.
This involves validation of the server’s X.509 certificate with the PKIX algorithm and checking the host name agains the certificate subject.
If the SSL certificate is not validates as trusted or does not match the target host,
an HTTPS and other SSL encrypted connection cannot be established and all attempts will result in SSLHandshakeException or IOException.
总得来说就是要将SLL数据证书加入到ketstore中
也按照http://www.cnblogs.com/liaojie970/p/4919485.html总提到的方法生成了证书,并且在代码中
System.setProperty("javax.net.ssl.trustStore", "E:\\vrvcacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
package com.vrv.paw.client.area;public class mainTest {
public static void main(String[] args) {
System.setProperty("javax.net.ssl.trustStore", "E:\\vrvcacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
Gson gson = new Gson();
// 同步数据
VRVRange vrvRange = new VRVRange();
VRVRangeSoap vrvRangeSoap = vrvRange.getVRVRangeSoap();
String cString = vrvRangeSoap.login("admin", "123456");
System.out.println(cString);
}
}
问题依旧存在,最后没有办法,就尝试了在项目中新建wsdl文件,在Eclipse中右键该wsdl文件,web service-->Generate Client生成客户端,具体生成方式见这里
然后再次
package org.tempuri;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;public class TestClient {
public static void main(String[] args) {
try {
System.setProperty("javax.net.ssl.trustStore", "E:\\jssecacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
Gson gson = new Gson();
VRVRange vrvRange = new VRVRangeLocator();
VRVRangeSoap vrvRangeSoap = vrvRange.getVRVRangeSoap();
String login = vrvRangeSoap.login("admin", "123456");
System.out.println(login);
} catch (ServiceException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
结果成了。。。。
具体为什么wsimport生成的客户端代码不行,我也不知道,如果有哪位大神知道,请指教。
java.security.cert.CertificateException: No subject alternative names present的更多相关文章
- java.security.cert.CertificateException: No subject alternative names matching IP address xxx.xxx.xxx.xxx found
https与http不同的是,https加密,需要验证证书,而http不需要. 在连接的代码中加上: static { disableSslVerification(); } private stat ...
- SpringBoot 连接kafka ssl 报 CertificateException: No subject alternative names present 异常解决
当使用较新版本SpringBoot时,对应的 kafka-client 版本也比较新,如果使用了 2.x 以上的 kafka-client ,并且配置了 kafka ssl 连接方式时,可能会报如下异 ...
- JDK安全证书的一个错误消息 No subject alternative names present的解决办法
我使用Java消费某网站一个Restful API时,遇到这个错误: 21:31:16.383 [main] DEBUG org.springframework.web.client.RestTemp ...
- 终极解决方案:java.security.cert.CertificateException: Certificates does not conform to algorithm constraints
报错信息 javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: Certificates does ...
- JAVA 调用https接口, java.security.cert.CertificateException
package com.easycare.store.util; import java.security.cert.CertificateException; import java.securit ...
- 在ssm框架测试中解决javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException
在单元测试发现causeBy:javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException 经发现是db.p ...
- 解決 java.security.cert.CertificateException: Certificates does not conform to algorithm constraints
找到 jre/lib/security/java.security 将 jdk.certpath.disabledAlgorithms=MD2, DSA, RSA keySize < 2048 ...
- Java_解决java.security.cert.CertificateException: Certificates does not conform to algorithm constraints
找到 jre/lib/security/java.security 将 jdk.certpath.disabledAlgorithms=MD2, DSA, RSA keySize < 2048 ...
- 【java细节】Java代码忽略https证书:No subject alternative names present
https://blog.csdn.net/audioo1/article/details/51746333
随机推荐
- MySQL Crash Course #21# Chapter 29.30. Database Maintenance & Improving Performance
终于结束这本书了,最后两章的内容在官方文档中都有详细介绍,简单过一遍.. 首先是数据备份,最简单直接的就是用 mysql 的内置工具 mysqldump MySQL 8.0 Reference Man ...
- windows tomcat web应用以及eclipse console乱码解决方法
在windows下,如果vm文件名为UTF-8格式,则显示乱码(velocity写出的不乱码): 改回GBK,则不再乱码.
- 使用requireJS加载不符合AMD规范的js文件:shim的使用方式和实现原理
原文链接: http://www.bubuko.com/infodetail-671521.html
- 20145327《网络对抗》——注入shellcode并执行和Return-to-libc攻击深入
20145327<网络对抗>--注入shellcode并执行 准备一段Shellcode 老师的shellcode:\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68 ...
- MOV/MOVX/MOVC、RAM/ROM
(一) MOV:访问内部RAM(数据存储器),串行口访问 (对于51单片机来说,内部RAM256bit,00H-FFH) MOVX:访问外部RAM MOVC:访问程序存储器 ROM,(对于51单片机来 ...
- React 回忆录(一)为什么使用 React?
Hi 各位,欢迎来到 React 回忆录!
- SPOJ LAS(BFS)题解
题目:VJ 思路: BFS+回溯,但是要剪枝,看了dalao的题解,超时+WA无数发,终于过了 #include<cstdio> #include<cstring> #incl ...
- 51nod 1284 2 3 5 7的倍数
从1到N 里 是2的倍数 有 N/2 个 然后大概看过这类的blog 所以运用容斥原理 直接计算 是 2 3 5 7 的个数都是多少 然后用N 减去 就是 不是2 3 5 7 的个数了 (离散好像也 ...
- div滚动条时div内容显示一半
本文为博主原创,未经允许不得转载 今天在做页面浏览器适配时,将页面中的一个div进行放大时,出现了滚动条,但滚动条对应div中的 内容只能显示一半. 仔细对应属性样式时,div具有overflow:h ...
- js函数事件对象
每个函数都有4个默认对象 arguments 保存着实际传入的参数,集合列表 return 有两个功能,打断函数和返回函数值 this 谁调用的函数,this就是谁 event 事件对象 事件 box ...