我正在尝试使用 Windows 套接字“手动”实现 SSL 3.0(我知道 openSSL 和 MS SSL API 就在那里,但我只是想这样做是为了好玩并从内部视图中学习)
我用来启动新 SSL 会话的第一条消息(记录),我发送到 SSL 服务器(真实服务器,如https://yahoo.com:443)的第一条 TCP 消息完全像这样(以十六进制表示) ) :
"16 03 00 00 19 01 00 00 15 03 00 bb 80 f3 8c 5d db f7 6c 94 56 d8 34 7a b5 9d 02 00 39 00"
Explanation:
16 //-- (22 in decimal) SSL3_RT_HANDSHAKE
03 00 //-- version : 3.0
00 19 //-- length of record excluding 5 bytes of header
01 //-- SSL3_MT_CLIENT_HELLO
00 00 15 //-- length of the following data
03 00 //-- SSL version 3.0
bb 80 f3 8c 5d db f7 6c 94 56 d8 34 7a b5 9d 02 00 //---- Random 16 bytes
39 //-- TLS_DHE_RSA_AES_256_CBC_SHA
00 //-- Compression method : none
Run Code Online (Sandbox Code Playgroud)
但是服务器对我的响应(十进制):
21-3-0-0-2-2-40
Run Code Online (Sandbox Code Playgroud)
通过这个参考,我知道 SSL 握手协议失败了,但没有任何关于原因的线索。出了什么问题?
您的 16 字节数据实际上是17字节,这使得标题中的“后续数据的长度”减一。
$ xxd data.dat
0000000: bb80 f38c 5ddb f76c 9456 d834 7ab5 9d02 ....]..l.V.4z...
0000010: 00 .
$ wc -c data.dat
17 data.dat
Run Code Online (Sandbox Code Playgroud)
00随机数据中的尾随对我来说似乎是罪魁祸首。
如果我可以补充,您可以使用 openssl 测试您的实现,如果只是为了比较您发送的内容和它发送的内容(这就是我自己找到这个的方式)。使用函数的-ssl3和-debug标志s_client,如下所示:
openssl s_client -connect yahoo.com:443 -ssl3 -debug
Run Code Online (Sandbox Code Playgroud)
我使用的 openssl(我自己在 Windows XP 上构建的 1.0.1c)发送的数据比你多,但它可以派上用场。
Loading 'screen' into random state - done
CONNECTED(00000724)
write to 0xac7fc0 [0xad1abb] (152 bytes => 152 (0x98))
0000 - 16 03 00 00 93 01 00 00-8f 03 00 52 58 68 2c 6f ...........RXh,o
0010 - 3b 22 89 66 14 e5 c4 fa-14 81 43 e6 48 31 a4 74 ;".f......C.H1.t
0020 - 96 67 6f a1 86 d0 08 8f-ef 1e bc 00 00 68 c0 14 .go..........h..
0030 - c0 0a c0 22 c0 21 00 39-00 38 00 88 00 87 c0 0f ...".!.9.8......
0040 - c0 05 00 35 00 84 c0 12-c0 08 c0 1c c0 1b 00 16 ...5............
0050 - 00 13 c0 0d c0 03 00 0a-c0 13 c0 09 c0 1f c0 1e ................
0060 - 00 33 00 32 00 9a 00 99-00 45 00 44 c0 0e c0 04 .3.2.....E.D....
0070 - 00 2f 00 96 00 41 00 07-c0 11 c0 07 c0 0c c0 02 ./...A..........
0080 - 00 05 00 04 00 15 00 12-00 09 00 14 00 11 00 08 ................
0090 - 00 06 00 03 00 ff 01 .......
0098 - <SPACES/NULS>
Run Code Online (Sandbox Code Playgroud)
实时解码您的有效负载的一种快速方法是通过Wireshark观看它。
您还可以针对s_server. 使用您的客户端和拥有密钥的 openssl 服务器,您可以向 Wireshark 提供服务器的密钥并实时查看加密流量的内部。
| 归档时间: |
|
| 查看次数: |
2917 次 |
| 最近记录: |