Java 安全 Web 服务

Java 安全 Web 服务

(我正在转发这个问题来自 stackoverflow。如果我能以某种方式加入问题或只是移动问题,请告诉我。谢谢。)

我正在尝试将 http web 服务转换为 https。我已将标签添加到 web 服务。

@SecurityDomain(value = "jbossws-ssl")

@WebContext(contextRoot="/common/ws",  // already here
 urlPattern="/A2",   // already here
    authMethod = "CLIENT-CERT",  // added
    transportGuarantee = "CONFIDENTIAL") // added

但是当我的客户端尝试连接时,https://host:80/path/to/ws我收到一个异常:

Caused by: java.io.IOException: HTTPS hostname wrong: should be <host>

(如下所示)。我怀疑这与正在使用的证书有关。我认为我需要使用 java keytool 来解决这个问题。如果有人能帮我验证一下,我将不胜感激。

javax.xml.soap.SOAPException: java.io.IOException: Could not transmit message
        at org.jboss.ws.core.soap.SOAPConnectionImpl.callInternal(SOAPConnectionImpl.java:115)
        at org.jboss.ws.core.soap.SOAPConnectionImpl.call(SOAPConnectionImpl.java:66)
        at com.alcatel.tpapps.common.utils.SOAPClient.execute(SOAPClient.java:146)
        at com.alcatel.tpapps.common.utils.SOAPClient.main(SOAPClient.java:233)
Caused by: java.io.IOException: Could not transmit message
        at org.jboss.ws.core.client.RemotingConnectionImpl.invoke(RemotingConnectionImpl.java:192)
        at org.jboss.ws.core.client.SOAPRemotingConnection.invoke(SOAPRemotingConnection.java:77)
        at org.jboss.ws.core.soap.SOAPConnectionImpl.callInternal(SOAPConnectionImpl.java:106)
        ... 3 more
Caused by: org.jboss.remoting.CannotConnectException: Can not connect http client invoker. HTTPS hostname wrong:  should be <host>.
        at org.jboss.remoting.transport.http.HTTPClientInvoker.useHttpURLConnection(HTTPClientInvoker.java:368)
        at org.jboss.remoting.transport.http.HTTPClientInvoker.transport(HTTPClientInvoker.java:148)
        at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:141)
        at org.jboss.remoting.Client.invoke(Client.java:1858)
        at org.jboss.remoting.Client.invoke(Client.java:718)
        at org.jboss.ws.core.client.RemotingConnectionImpl.invoke(RemotingConnectionImpl.java:171)
        ... 5 more
Caused by: java.io.IOException: HTTPS hostname wrong:  should be <host>
        at sun.net.www.protocol.https.HttpsClient.checkURLSpoofing(HttpsClient.java:490)
        at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:415)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:170)
        at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:857)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)
        at org.jboss.remoting.transport.http.HTTPClientInvoker.useHttpURLConnection(HTTPClientInvoker.java:288)
        ... 10 more

更新 1

我尝试了以下操作,但对异常没有影响:

host[user:/path][525]% keytool -genkey -keystore server.keystore -alias host
...
...

更新 2

实际上我不确定我在更新 1 中所做的是否正确,因为我不必在那里指定主机名......

答案1

错误消息抱怨您的端口。http 通常在端口 80 上运行,https 在端口 443 上运行。您正在尝试在端口 80 上使用 https。将您的调用从

https://sco-up:80/path/to/ws

https://sco-up/path/to/ws

这将自动使用端口 443 进行 https 连接。

相关内容