2010-04-09 107 views
11

我试图使用Apache Commons的HttpClient 3.1通过SSL连接到Web服务,使用此:异常SSLException:HelloRequest其次是一个意外的握手消息

String url = "https://archprod.service.eogs.dk/cvronline/esb/LegalUnitGetSSLServicePort"; 
HttpClient client = new HttpClient(); 
PostMethod post = new PostMethod(url); 
StringRequestEntity entity = new StringRequestEntity(requestXml, "application/soap+xml", "utf-8"); 
post.setRequestEntity(entity); 
client.executeMethod(post); 
String response = post.getResponseBodyAsString(); 

我得到这个异常:

javax.net.ssl.SSLException: HelloRequest followed by an unexpected handshake message 
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:190) 
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1623) 
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:198) 
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:188) 
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverHelloRequest(ClientHandshaker.java:286) 
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:114) 
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:525) 
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:465) 
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:884) 
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:746) 
at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75) 
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218) 
at java.io.BufferedInputStream.read(BufferedInputStream.java:237) 
at org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:78) 
at org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:106) 
at org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1116) 
at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1973) 
at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1735) 
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1098) 
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398) 
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171) 
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397) 
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323) 

使用curl对同一台机器上同一个URL的请求工作正常 - 如果我将URL更改为eg https://www.verisign.com,它在Java中也可以正常工作。所以它似乎是Java和该主机的特定组合,而不是一般问题。

Ubuntu 10.04测试版,Sun JDK 1.6.0_19(在Ubuntu的捆绑OpenJDK 6b18〜pre4中同样的问题)。

任何想法发生了什么问题?谢谢!

+1

请参阅http://www.theregister.co.uk/2009/11/14/ssl_renegotiation_bug_exploited/了解为什么允许不安全的重新协商不是一个长期的解决方案。 – 2011-02-22 12:06:24

+1

我的问题是,这是否意味着JDK 1.6.0.19之前,总是允许不安全的重新协商?现在1.6.0.19我们被迫允许手动进行不安全的重新协商? 感谢您的洞察... – 2011-02-22 12:06:57

+0

是的,它会出现如此。 – mseebach 2011-02-22 12:06:57

回答

5

我们有一个Webstart的应用由于这个问题而失败。在添加时,命令行版本再次工作:

java.lang.System.setProperty(“sun.security.ssl.allowUnsafeRenegotiation”,“true”);

但webstart版本似乎忽略了这一点,直到现在我们还没有找到在webstart版本中设置此属性的方法。

2

至少解决方案适用于这个问题,太:添加“-Dsun.security.ssl.allowUnsafeRenegotiation =真正的”

非常感谢你非常非常的那个! 我试图通过SSL连接使用maven部署,使用证书和我有相同的例外。现在解决了。再次感谢!

1

只是为此添加一些更新 - Oracle has this KB that discusses the problem

我们在Windows 7上遇到了JRE 1.6.0_20,但是升级到1.6.0_25已经解决了这个问题(我意识到有更新的版本,但是为了测试我们正在测试的软件测试版本范围 - 这是我们能够最早开展的)。