Java SSL handshake alert no_negotiation

2019-09-11 11:06发布

This error happened while communicating with a webservice.

Client reported error:

javax.net.ssl.SSLException: Received fatal alert: unexpected_message
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
    at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1991)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1098)
    at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:903)
    at sun.security.ssl.AppInputStream.read(AppInputStream.java:102)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1324)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:2223)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:2192)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:2036)

and there was an error in server log

javax.net.ssl.SSLProtocolException: handshake_alert

标签: java ssl jsse
1条回答
趁早两清
2楼-- · 2019-09-11 11:42

It looked like server was not updated to RFC 5746.

I stumbled upon https://www.digicert.com/news/2011-06-03-ssl-renego.htm and foud

If the server does not respond in accordance with RFC 5746, the client MUST abort the renegotiation handshake.

Then I found http://www.oracle.com/technetwork/java/javase/overview/tlsreadme2-176330.html

sun.security.ssl.allowUnsafeRenegotiation - Introduced in Phase 1, this controls whether legacy (unsafe) renegotiations are permitted.

A temporary fix was to add System property

-Dsun.security.ssl.allowUnsafeRenegotiation=true

but that turned out not to be the real reason error happened. The real reason was that my client was using old SSL.

tlsClientParameters.setSecureSocketProtocol("SSL");

I commented that line, so the default value is used: "TLS" and after that the communication worked just fine.

查看更多
登录 后发表回答