使用SSLEngine(JSSE)与旧客户端进行SSL握手 [英] SSL Handshaking With Older Clients Using SSLEngine (JSSE)

查看:179
本文介绍了使用SSLEngine(JSSE)与旧客户端进行SSL握手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是" SSL握手的后续问题使用自签名证书和SSLEngine(JSSE)".

我已经实现了一个NIO Web服务器,该服务器可以在同一端口上处理SSL和非SSL消息.为了区分SSL消息和非SSL消息,我检查了入站请求的第一个字节,看看它是否是SSL/TLS消息.示例:

I have implemented a NIO Webserver that can process SSL and non-SSL messages on the same port. In order to distinguish between SSL and non-SSL messages, I check the first byte of the inbound request to see if it is a SSL/TLS message. Example:

byte a = read(buf);
if (totalBytesRead==1 && (a>19 && a<25)){
    parseTLS(buf);
}

在parseTLS()方法中,我实例化一个SSLEngine,初始化握手,包装/展开消息等.对于大多数现代Web浏览器(Firefox 10,IE 9,Safari 5等),一切似乎都可以正常工作.

In the parseTLS() method I instantiate an SSLEngine, initiate the handshake, wrap/unwrap messages, etc. Everything seems to work fine for most modern web browsers (Firefox 10, IE 9, Safari 5, etc).

问题在于,较旧的Web浏览器(如IE 6)和库(如Java的URLConnection类)似乎以不同的方式启动SSL/TLS握手.例如,来自IE 6的前几个字节看起来像这样(十六进制值):

Problem is that older web browsers like IE 6 and libraries like Java's URLConnection class seem to initiate the SSL/TLS handshake differently. For example, the first few bytes from IE 6 look something like this (hex values):

80 4F 01 03 00 ...

如果我将消息传递给SSLEngine,它似乎无法识别该消息并引发Exception.

If I pass the message to the SSLEngine, it doesn't seem to recognize the message and throws an Exception.

javax.net.ssl.SSLException: Unsupported record version Unknown-0.0

那么IE 6和Java的URLConnection类到底发送了什么?这是JSSE SSLEngine可以支持的有效SSL/TLS消息吗?我是否需要做一些预处理或与客户端协商以发送不同的消息?

So what exactly is IE 6 and Java's URLConnection class sending over? Is this a valid SSL/TLS message that the JSSE SSLEngine can support? Do I have to do some pre-processing or negotiate with the client to send a different message?

提前谢谢!

更新

感谢Bruno和EJP以及一些进一步的调试,我对发生的事情有了更好的了解.正如Bruno正确指出的那样,IE6和Java 6客户端正在通过SSLv2 ClientHello发送.与我之前的评论之一相反,Java 1.6中的SSLEngine实际上可以解包SSLv2消息并生成有效的响应以发送回客户端.我先前报告的SSLException是我自己的错误,与SSLEngine没有任何关系(我错误地认为客户端已完成发送数据,并且当SSLEngine希望解开更多数据时,我得到了一个空的ByteBuffer).

Thanks to Bruno and EJP and some further debugging I have a much better understanding of what's going on. As Bruno correctly pointed out, the IE6 and Java 6 clients are sending over a SSLv2 ClientHello. Contrary to one of my earlier comments, the SSLEngine in Java 1.6 can in fact unwrap the SSLv2 message and generate a valid response to send back to the client. The SSLException I reported earlier was an error on my side and has nothing to do with the SSLEngine (I incorrectly assumed that the client was done sending data over and I ended up with an empty ByteBuffer when the SSLEngine was expecting more data to unwrap).

推荐答案

这看起来像 SSLv2客户端您好(请参阅TLS规范):

支持SSL 2.0版服务器的TLS 1.1客户端必须发送SSL 2.0版客户端问候消息[SSL2]. TLS服务器应接受 两种客户端问候格式,如果他们希望在以下版本上支持SSL 2.0客户端 相同的连接端口.与版本2.0的唯一差异 规范是指定值为的版本的能力 三种,以及对CipherSpec中更多加密类型的支持.

TLS 1.1 clients that support SSL Version 2.0 servers MUST send SSL Version 2.0 client hello messages [SSL2]. TLS servers SHOULD accept either client hello format if they wish to support SSL 2.0 clients on the same connection port. The only deviations from the Version 2.0 specification are the ability to specify a version with a value of three and the support for more ciphering types in the CipherSpec.

  • 80 4F是长度,高位必须设置为1(请参见 msg_length说明).
  • 01是消息类型(客户端问候)
  • 03 00是受支持的最高版本(此处为SSLv3)
    • 80 4F is the length and the high bit must be set to 1 (see msg_length description).
    • 01 is the message type (Client Hello)
    • 03 00 is the highest supported version (SSLv3 here)
    • 从Java 7开始,此功能现已禁用默认情况下.

      Since Java 7, this is now disabled by default.

      请澄清一下,这实际上不是SSLv2客户端问候,这是SSLv2格式的SSLv3的客户端问候.在这种情况下,服务器将回复一个(正确的)SSLv3服务器Hello(对应于03 00请求的版本号). TLS 1.0、1.1和1.2同样适用,尽管此格式的使用已逐步弃用.

      Just to clarify, this isn't really an SSLv2 Client Hello, this is a Client Hello for SSLv3 in the SSLv2 format. In this case, the server will reply with a (proper) SSLv3 Server Hello (corresponding to the 03 00 requested version number). The same also works for TLS 1.0, 1.1 and 1.2, although the usage of this format is progressively deprecated.

      JSSE 7 SSLServerSocket仍会理解这样的客户端Hello,并使用SSLv3/TLS1.x Server Hello适当地答复.

      A JSSE 7 SSLServerSocket will still understand such a Client Hello and reply appropriately with the SSLv3/TLS1.x Server Hello.

      这篇关于使用SSLEngine(JSSE)与旧客户端进行SSL握手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆