SSLHandshakeException : 주체 대체 이름이 없습니다.
Java 코드를 통해 HTTPS SOAP 웹 서비스를 호출하고 있습니다. 이미 jre cacerts 키 저장소에서 자체 서명 된 인증서를 가져 왔습니다. 이제 나는 얻고있다 :
com.sun.xml.internal.ws.com.client.ClientTransportException: HTTP transport error: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names present
서비스 URL의 호스트 이름이 cert에 제공된 CN의 호스트 이름과 일치하지 않습니다. 여기 에서 사용자 지정 호스트 이름 확인자를 정의하는 방법에 대해 읽었습니다 . 하지만 내 코드에서 해결 방법을 구현해야 할 곳을 만들 수 없습니다.
public SOAPMessage invokeWS(WSBean bean) throws Exception {
SOAPMessage response=null;
try{
/** Create a service and add at least one port to it. **/
String targetNameSpace = bean.getTargetNameSpace();
String endpointUrl = bean.getEndpointUrl();
QName serviceName = new QName(targetNameSpace, bean.getServiceName());
QName portName = new QName(targetNameSpace, bean.getPortName());
String SOAPAction = bean.getSOAPAction();
HashMap<String, String> map = bean.getParameters();
Service service = Service.create(serviceName);
service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointUrl);
/** Create a Dispatch instance from a service. **/
Dispatch dispatch = service.createDispatch(portName, SOAPMessage.class,
Service.Mode.MESSAGE);
// The soapActionUri is set here. otherwise we get a error on .net based
// services.
dispatch.getRequestContext().put(Dispatch.SOAPACTION_USE_PROPERTY,
new Boolean(true));
dispatch.getRequestContext().put(Dispatch.SOAPACTION_URI_PROPERTY,
SOAPAction);
/** Create SOAPMessage request. **/
// compose a request message
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();
// Create objects for the message parts
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();
SOAPElement bodyElement = body.addChildElement(bean.getInputMethod(),
bean.getPrefix(), bean.getTargetNameSpace());
...more code to form soap body goes here
// Print request
message.writeTo(System.out);
// Save the message
message.saveChanges();
response = (SOAPMessage)dispatch.invoke(message);
}
catch (Exception e) {
log.error("Error in invokeSiebelWS :"+e);
}
return response;
}
네임 스페이스 및 기타 wsdl 속성이이 Bean에서 나오므로 WSBean 매개 변수를 무시하십시오. 이 예외가 몇 가지 다른 해결 방법으로 해결할 수 있다면 pls는 제안합니다.
Thanks,Bruno for giving me heads up on Common Name and Subject Alternative Name. As we figured out certificate was generated with CN with DNS name of network and asked for regeneration of new certificate with Subject Alternative Name entry i.e. san=ip:10.0.0.1. which is the actual solution.
But, we managed to find out a workaround with which we can able to run on development phase. Just add a static block in the class from which we are making ssl connection.
static {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier()
{
public boolean verify(String hostname, SSLSession session)
{
// ip address of the service URL(like.23.28.244.244)
if (hostname.equals("23.28.244.244"))
return true;
return false;
}
});
}
If you happen to be using Java 8, there is a much slicker way of achieving the same result:
static {
HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> hostname.equals("127.0.0.1"));
}
Unlike some browsers, Java follows the HTTPS specification strictly when it comes to the server identity verification (RFC 2818, Section 3.1) and IP addresses.
When using a host name, it's possible to fall back to the Common Name in the Subject DN of the server certificate, instead of using the Subject Alternative Name.
When using an IP address, there must be a Subject Alternative Name entry (of type IP address, not DNS name) in the certificate.
You'll find more details about the specification and how to generate such a certificate in this answer.
ReferenceURL : https://stackoverflow.com/questions/10258101/sslhandshakeexception-no-subject-alternative-names-present
'UFO ET IT' 카테고리의 다른 글
줄의 시작 부분에서만 문자를 일치시키는 정규 표현식 (0) | 2020.12.29 |
---|---|
Eclipse에서 Android를 설정하지만 SDK 디렉토리를 모릅니다. (0) | 2020.12.29 |
JSON 경로에 특정 요소가 포함되어 있지 않거나 요소가 존재하는지 여부를 테스트하는 방법은 null입니까? (0) | 2020.12.29 |
원격 컴퓨터에서 서비스를 다시 시작하는 가장 간단한 방법 (0) | 2020.12.29 |
C #의 기본 클래스에서 파생 된 형식을 얻습니까? (0) | 2020.12.29 |