gpt4 book ai didi

Java 安全 Web 服务

转载 作者:行者123 更新时间:2023-11-29 08:18:45 26 4
gpt4 key购买 nike

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

@SecurityDomain(value = "jboss-ssl")

@WebContext(contextRoot="/path/one",  // already here
urlPattern="/X", // already here
authMethod = "CLIENT-CERT", // added
transportGuarantee = "CONFIDENTIAL") // added

但是当我的客户端尝试连接到 https://hostname:80/path/to/ws 时我得到一个异常(exception):

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

(整个内容如下所示)。我怀疑这与正在使用的证书有关。我认为我需要使用 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 <hostname>.
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 <hostname>
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

我尝试了以下但它对异常没有影响:

hostname[username:/path/two/path][525]% keytool -genkey -keystore server.keystore -alias hostname
...
...

更新2

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

更新3

我指定主机名作为别名

What is the name of your organizational unit?
[Unknown]: hostname

但这仍然没有解决我的问题。有添加主机名的具体方法吗?


我很确定这篇文章解决了这个问题,但是它太神秘了,无法理解。回到这个。

http://forums.sun.com/thread.jspa?threadID=5315653

最佳答案

这个解决方案也很有用。

Java's keytool command with IP addresses

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;

HostnameVerifier hv = new HostnameVerifier() {
public boolean verify(String urlHostName, SSLSession session) {
System.out.println("Warning: URL Host: " + urlHostName + " vs. " + session.getPeerHost());
return true;
}
};

HttpsURLConnection.setDefaultHostnameVerifier(hv);

关于Java 安全 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2186543/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com