简体   繁体   English

SSL + Java 8 + OpenJDK + SNI + HTTPClient =握手失败

[英]SSL+ Java 8 + OpenJDK + SNI + HTTPClient = Handshake Failure

I have some code that's been working for a long time that gets data from webapps over HTTP. 我有一些代码已经工作了很长时间,通过HTTP从webapps获取数据。 It uses Apache HTTPClient (v. 4.5.2) and works great for sites with and without SSL. 它使用Apache HTTPClient(v.4.5.2),适用于有和没有SSL的站点。

Recently, I've tried to use if for another site that happens to use SNI. 最近,我试图使用if用于其他恰好使用SNI的网站。 Everything works great on my Windows machine, but if I try to run it on an AWS EC2 Linux instance, I get a handshake failure (because of the SNI). 一切都在我的Windows机器上运行良好,但如果我尝试在AWS EC2 Linux实例上运行它,我会得到握手失败(因为SNI)。

Here's what I'm running: 这是我正在运行的:

Windows Java Windows Java

  • java version "1.8.0_101" java版“1.8.0_101”
  • Java(TM) SE Runtime Environment (build 1.8.0_101-b13) Java(TM)SE运行时环境(版本1.8.0_101-b13)
  • Java HotSpot(TM) Client VM (build 25.101-b13, mixed mode, sharing) Java HotSpot(TM)客户端VM(版本25.101-b13,混合模式,共享)

AWS Linux Java AWS Linux Java

  • openjdk version "1.8.0_91" openjdk版本“1.8.0_91”
  • OpenJDK Runtime Environment (build 1.8.0_91-b14) OpenJDK运行时环境(版本1.8.0_91-b14)
  • OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode) OpenJDK 64位服务器VM(内置25.91-b14,混合模式)

I'm not sure which component is ultimately responsible for the failure (Java 8, the runtime environment, HTTPClient). 我不确定哪个组件最终导致失败(Java 8,运行时环境,HTTPClient)。

I have seen this ( https://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/JSSERefGuide.html#SNIExtension ), but I'm not sure how to adapt this for HTTPClient. 我已经看过这个( https://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/JSSERefGuide.html#SNIExtension ),但我不确定如何为HTTPClient调整它。 And besides, if I had to make code changes, why would it work on Windows? 此外,如果我必须更改代码,为什么它可以在Windows上运行?

Anyone have any idea what I should do? 任何人都知道我应该做什么?

Edit : As suggested, I looked into the jsse.enableSNIExtension property. 编辑 :根据建议,我查看了jsse.enableSNIExtension属性。 This seemed wrong because it looks like it's a way to turn SSL off which isn't what I want. 这似乎是错误的,因为它似乎是一种关闭SSL的方法,这不是我想要的。

I tried it turned on/off on Windows, and things only worked with it on. 我尝试在Windows上打开/关闭它,事情只适用于它。 On Linux, when it was turned on I continue to get a handshake failure. 在Linux上,当它打开时,我继续获得握手失败。

Here's the output: 这是输出:

Windows - System.setProperty("jsse.enableSNIExtension", "false");
=================================================================

pool-1-thread-1, WRITE: TLSv1.2 Handshake, length = 189
pool-1-thread-1, READ: TLSv1.2 Alert, length = 2
pool-1-thread-1, RECV TLSv1.2 ALERT:  fatal, internal_error
pool-1-thread-1, called closeSocket()
pool-1-thread-1, handling exception: javax.net.ssl.SSLException: Received fatal alert: internal_error


Windows - System.setProperty("jsse.enableSNIExtension", "true");
================================================================

pool-1-thread-1, WRITE: TLSv1.2 Handshake, length = 215
pool-1-thread-1, READ: TLSv1.2 Handshake, length = 93
*** ServerHello, TLSv1.2


Linux - System.setProperty("jsse.enableSNIExtension", "true");
==============================================================

pool-1-thread-1, WRITE: TLSv1.2 Handshake, length = 143
pool-1-thread-1, READ: TLSv1.2 Alert, length = 2
pool-1-thread-1, RECV TLSv1.2 ALERT:  fatal, handshake_failure
pool-1-thread-1, called closeSocket()
pool-1-thread-1, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

In our case the root cause was that the (Java) client and the server could not agree on a sufficently strong cipher suite. 在我们的例子中,根本原因是(Java)客户端和服务器无法就足够强大的密码套件达成一致。 The solution was to install "Unlimited Strength JCE" from https://www.oracle.com/technetwork/java/javase/downloads/jce-all-download-5170447.html 解决方案是从https://www.oracle.com/technetwork/java/javase/downloads/jce-all-download-5170447.html安装“Unlimited Strength JCE”

This should not be a problem for Java version >= 1.8.0_161 对于Java版本> = 1.8.0_161,这应该不是问题

我有同样的问题,不确定你是否被允许这样做,或者如果你在文档中注意到这一点,但我添加了选项-Djsse.enableSNIExtension=false ,它对我-Djsse.enableSNIExtension=false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM