请求开始时出现异常 - ClientAuth SSL

发布于 2024-10-14 21:23:32 字数 1899 浏览 6 评论 0原文

我有一个嵌入 Jetty 的应用程序。我想在 SSL 中使用客户端证书身份验证,并且当我启用它时;我在请求开始时收到以下异常。但此后请求得到了正确的满足。仅当从 IE 或 Chrome 访问时才会出现此异常。从 Firefox 访问时它不会出现。我们有自定义的 SSLConnector 扩展 SslSocketConnector。我正在尝试调试它;但想知道是否有任何特定的地方/代码可以开始检查。

javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake 
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:808) 
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1112) 
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1139) 
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1123) 
        at org.mortbay.jetty.security.SslSocketConnector$SslConnection.run(SslSocketConnector.java:631) 
        at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:451) 
Caused by: java.io.EOFException: SSL peer shut down incorrectly 
        at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:333) 
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:789) 

更新:

我启用了 SSL 调试选项,并在 ServerHelloDone 消息之后立即读取时遇到此异常。我相信这是服务器发送其证书以及客户端证书请求的消息。我不确定第一次阅读时发生了什么。非常感谢任何帮助。

*** ClientHello, TLSv1
****
%% Created:  [Session-1, TLS_RSA_WITH_AES_128_CBC_SHA]
*** ServerHello, TLSv1
*** Certificate chain
***
*** CertificateRequest
Cert Types: RSA, DSS
Cert Authorities:
*** ServerHelloDone
WRITE: TLSv1 Handshake, length = 703
received EOFException: error
handling exception: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

更新: 将 JDK 更新到最新版本 23 并尝试启用/禁用这两个属性。仍然有同样的行为。

更多信息: 所有浏览器均启用 TLSv1 和 SSLv3。在未启用客户端身份验证的情况下,通信正常进行。通过客户端身份验证,我们总是在第一次握手时遇到异常,而下一次握手则正确完成并继续进行,没有异常。在服务器端使用jetty版本6.1.14

I have an application embedding Jetty. I would like to use client cert authentication in SSL and when I enable that; I am getting the following exception at start of request. But the request is getting served properly after that. This exception comes only when accessed from IE or Chrome. It does not come when accessed from Firefox. We have our custom SSLConnector extending SslSocketConnector. I am trying to debug it; but wanted to know if there is any specific place/code where I can start checking.

javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake 
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:808) 
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1112) 
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1139) 
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1123) 
        at org.mortbay.jetty.security.SslSocketConnector$SslConnection.run(SslSocketConnector.java:631) 
        at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:451) 
Caused by: java.io.EOFException: SSL peer shut down incorrectly 
        at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:333) 
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:789) 

Update:

I enabled SSL debug option and was getting this exception on a read immediately after the ServerHelloDone message. This is the message where server sends its cert along with request for client certificate i believe. I am not sure whats happening in first read. Any help is deeply appreciated.

*** ClientHello, TLSv1
****
%% Created:  [Session-1, TLS_RSA_WITH_AES_128_CBC_SHA]
*** ServerHello, TLSv1
*** Certificate chain
***
*** CertificateRequest
Cert Types: RSA, DSS
Cert Authorities:
*** ServerHelloDone
WRITE: TLSv1 Handshake, length = 703
received EOFException: error
handling exception: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

Update:
Updated JDK to latest, 23 and tried with the two properties enabled/disabled. Still gettting the same behavior.

More info:
TLSv1 and SSLv3 are enabled in all browsers. The communication is happening properly without client-auth enabled. With client auth, always we get exception on first handshake and the next is getting properly done and proceeding without exceptions. Using jetty version 6.1.14 at server side

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

迟月 2024-10-21 21:23:32

我在 TLS/SSLv3 协商中遇到过类似的问题。
http://www.oracle.com/technetwork/java/javase /documentation/tlsreadme2-176330.html

在 SSL/TLS 中,任何一方都可以发起重新协商。与第 1 阶段修复一样,应用程序在互操作模式下与未升级的对等方进行通信,并尝试启动重新协商(通过 SSLSocket.startHandshake()SSLEngine.beginHandshake() )将收到 SSLHandshakeException (IOException),并且连接将被关闭 (handshake_failure)。从未升级的对等方接收重新协商请求的应用程序将根据现有的连接类型进行响应:

  • TLSv1:“no_renegotiation(100)”类型的警告 Alert 消息将发送到对等方,并且连接将保持打开状态。旧版本的 SunJSSE 将在收到“no_renegotiation”警报时关闭连接。
  • SSLv3:应用程序将收到 SSLHandshakeException,并且连接将被关闭 (handshake_failure)。 (SSLv3 规范中未定义“no_renegotiation”。)

要设置这些模式,需要使用两个系统属性:

  • sun.security.ssl.allowUnsafeRenegotiation - 在第 1 阶段引入,它控制是否允许旧版(不安全)重新协商。
  • sun.security.ssl.allowLegacyHelloMessages - 在第 2 阶段引入,这允许对等方无需正确的 RFC 5746 消息即可握手。

如果仍然没有帮助,您可以尝试打开 SSL dedug,并查看握手过程。
-Djavax.net.debug=all

I have seen issues like this with TLS/SSLv3 negotiation.
http://www.oracle.com/technetwork/java/javase/documentation/tlsreadme2-176330.html

In SSL/TLS, renegotiations can be initiated by either side. Like the Phase 1 fix, applications communicating with an un-upgraded peer in Interoperable mode and that attempt to initiate renegotiation (via SSLSocket.startHandshake() or SSLEngine.beginHandshake()) will receive a SSLHandshakeException (IOException) and the connection will be shutdown (handshake_failure). Applications that receive a renegotiation request from a non-upgraded peer will respond according to the type of connection in place:

  • TLSv1: A warning Alert message of type "no_renegotiation(100)" will be sent to the peer and the connection will remain open. Older versions of SunJSSE will shutdown the connection when a "no_renegotiation" Alert is received.
  • SSLv3: The application will receive a SSLHandshakeException, and the connection will be closed (handshake_failure). ("no_renegotiation" is not defined in the SSLv3 spec.)

To set these modes, two system properties are used:

  • sun.security.ssl.allowUnsafeRenegotiation - Introduced in Phase 1, this controls whether legacy (unsafe) renegotiations are permitted.
  • sun.security.ssl.allowLegacyHelloMessages - Introduced in Phase 2, this allows the peer to handshake without requiring the proper RFC 5746 messages.

If that still doesn't help, you can try turning on SSL dedug, and taking a look at the handshaking.
-Djavax.net.debug=all

忘年祭陌 2024-10-21 21:23:32

当我不小心将非 ssl 端口放入 URL 但以 https 开头的 URL 时,我得到了这个信息。哦。

有时,最简单的解决方案就是我们忘记的!

I got this when I accidentally put the non-ssl port in the URL but started the URL with https. Doh.

Sometimes the simplest solutions are the ones that we forget!

难忘№最初的完美 2024-10-21 21:23:32

试试最新的jdk。他们修复了 ssl 握手错误。 http://www.java.net/blogs/kumarjayanti/

Try the newest jdk. They fixed an ssl handshake bug. http://www.java.net/blogs/kumarjayanti/

北音执念 2024-10-21 21:23:32

我仍然认为这是 TLS/SSL 协商问题。

提供调试信息后,它显示您正在执行 TLSv1 握手。

您确定您的浏览器启用了 TLSv1 吗?

铬合金:
要在 Chrome 中启用 TLS 1.0,请执行以下操作:

  1. 单击扳手图标:
  2. 选择选项
  3. 选择“底层”选项卡
  4. 单击更改代理设置
  5. 选择“高级”选项卡
  6. 向下滚动并选中 TLS 1.0
  7. 关闭并重新启动所有打开的浏览器。

IE:

  1. 单击“工具”菜单
  2. 单击“Internet 选项”
  3. 高级选项卡
  4. 滚动到“安全”部分
  5. 启用 TLS 1.0

Firefox:

  1. 单击“工具”
  2. 单击“选项
  3. 高级”选项卡
  4. 加密选项卡
  5. 启用 TLS 1.0

然后您还提到:

这是服务器发出的消息
发送其证书以及请求
我相信客户端证书。

您是否已将客户端证书安装到您正在测试的每个 Web 浏览器中?

确保您可以在没有相互/客户端身份验证的情况下让一切正常工作,然后一旦工作正常,将其添加回来。

I still think this is a TLS/SSL negotiation issue.

After you posed the debug info, it shows you are doing a TLSv1 Handshake.

Are you sure you have TLSv1 enabled in your browsers?

Chrome:
In order to enable TLS 1.0 in chrome do the following:

  1. Click the wrench icon:
  2. Choose Options
  3. Select "Under the Hood" Tab
  4. Click Change proxy settings
  5. Select "Advanced" Tab
  6. Scoll down and check TLS 1.0
  7. Close and restart all open browsers.

IE:

  1. Click the Tools menu
  2. Click Internet Options
  3. Advanced tab
  4. Scroll to the Security section
  5. Enable TLS 1.0

Firefox:

  1. Click Tools
  2. Click Options
  3. Advanced tab
  4. Encryption tab
  5. Enable TLS 1.0

You then also mention that:

This is the message where server
sends its cert along with request for
client certificate i believe.

Have you installed the client certificate into each of the web browsers you are testing from?

Make sure you can get everything working without mutual/client authentication first, and then once its working, add it back in.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文