2010-04-09 55 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已經解決了這個問題(我意識到有更新的版本,但是爲了測試我們正在測試的軟件測試版本範圍 - 這是我們能夠最早開展的)。