代码之家  ›  专栏  ›  技术社区  ›  Timmmm

OpenSSL ClientHello在最新版本中失败

  •  1
  • Timmmm  · 技术社区  · 10 年前

    我需要连接到SSL服务器。当我使用OpenSSL 1.0.1r连接时,工作正常:

    CONNECTED(00000304)
    write to 0x6e13e8 [0x730a98] (297 bytes => 297 (0x129))
    0000 - 16 03 01 01 24 01 00 01-20 03 03 16 f2 71 5f 26   ....$... ....q_&
    0010 - a5 9b 64 cb 8f 0b 27 65-8d a3 54 e6 de a5 18 7a   ..d...'e..T....z
    0020 - 3c 5a e4 08 ab ff 6a 92-d7 45 f3 00 00 8a c0 30   <Z....j..E.....0
    0030 - c0 2c c0 28 c0 24 c0 14-c0 0a 00 a3 00 9f 00 6b   .,.(.$.........k
    0040 - 00 6a 00 39 00 38 00 88-00 87 c0 32 c0 2e c0 2a   .j.9.8.....2...*
    0050 - c0 26 c0 0f c0 05 00 9d-00 3d 00 35 00 84 c0 2f   .&.......=.5.../
    0060 - c0 2b c0 27 c0 23 c0 13-c0 09 00 a2 00 9e 00 67   .+.'.#.........g
    0070 - 00 40 00 33 00 32 00 9a-00 99 00 45 00 44 c0 31   .@.3.2.....E.D.1
    0080 - c0 2d c0 29 c0 25 c0 0e-c0 04 00 9c 00 3c 00 2f   .-.).%.......<./
    0090 - 00 96 00 41 00 07 c0 11-c0 07 c0 0c c0 02 00 05   ...A............
    00a0 - 00 04 c0 12 c0 08 00 16-00 13 c0 0d c0 03 00 0a   ................
    00b0 - 00 15 00 12 00 09 00 ff-01 00 00 6d 00 0b 00 04   ...........m....
    00c0 - 03 00 01 02 00 0a 00 34-00 32 00 0e 00 0d 00 19   .......4.2......
    00d0 - 00 0b 00 0c 00 18 00 09-00 0a 00 16 00 17 00 08   ................
    00e0 - 00 06 00 07 00 14 00 15-00 04 00 05 00 12 00 13   ................
    00f0 - 00 01 00 02 00 03 00 0f-00 10 00 11 00 23 00 00   .............#..
    0100 - 00 0d 00 20 00 1e 06 01-06 02 06 03 05 01 05 02   ... ............
    0110 - 05 03 04 01 04 02 04 03-03 01 03 02 03 03 02 01   ................
    0120 - 02 02 02 03 00 0f 00 01-01                        .........
    >>> TLS 1.2 Handshake [length 0124], ClientHello
        01 00 01 20 03 03 16 f2 71 5f 26 a5 9b 64 cb 8f
        0b 27 65 8d a3 54 e6 de a5 18 7a 3c 5a e4 08 ab
        ff 6a 92 d7 45 f3 00 00 8a c0 30 c0 2c c0 28 c0
        24 c0 14 c0 0a 00 a3 00 9f 00 6b 00 6a 00 39 00
        38 00 88 00 87 c0 32 c0 2e c0 2a c0 26 c0 0f c0
        05 00 9d 00 3d 00 35 00 84 c0 2f c0 2b c0 27 c0
        23 c0 13 c0 09 00 a2 00 9e 00 67 00 40 00 33 00
        32 00 9a 00 99 00 45 00 44 c0 31 c0 2d c0 29 c0
        25 c0 0e c0 04 00 9c 00 3c 00 2f 00 96 00 41 00
        07 c0 11 c0 07 c0 0c c0 02 00 05 00 04 c0 12 c0
        08 00 16 00 13 c0 0d c0 03 00 0a 00 15 00 12 00
        09 00 ff 01 00 00 6d 00 0b 00 04 03 00 01 02 00
        0a 00 34 00 32 00 0e 00 0d 00 19 00 0b 00 0c 00
        18 00 09 00 0a 00 16 00 17 00 08 00 06 00 07 00
        14 00 15 00 04 00 05 00 12 00 13 00 01 00 02 00
        03 00 0f 00 10 00 11 00 23 00 00 00 0d 00 20 00
        1e 06 01 06 02 06 03 05 01 05 02 05 03 04 01 04
        02 04 03 03 01 03 02 03 03 02 01 02 02 02 03 00
        0f 00 01 01
    read from 0x6e13e8 [0x735ff8] (7 bytes => 7 (0x7))
    0000 - 16 03 03 00 57 02                                 ....W.
    0007 - <SPACES/NULS>
    read from 0x6e13e8 [0x736002] (85 bytes => 85 (0x55))
    0000 - 00 53 03 03 56 bb 11 21-1a ac 49 84 2d be 94 ad   .S..V..!..I.-...
    0010 - a0 c4 57 46 bc 70 d0 84-95 ce 96 c6 8c 92 07 2e   ..WF.p..........
    0020 - 4e 13 d6 f3 20 aa d7 86-ca 48 5e 01 a1 8c d3 f1   N... ....H^.....
    0030 - d7 74 f9 2c 84 48 7d c1-95 6d 22 81 ff 53 ab d3   .t.,.H}..m"..S..
    0040 - 0c 89 81 7d a2 00 3d 00-00 0b 00 0b 00 02 01 00   ...}..=.........
    0050 - ff 01 00 01                                       ....
    0055 - <SPACES/NULS>
    <<< TLS 1.2 Handshake [length 0057], ServerHello
        02 00 00 53 03 03 56 bb 11 21 1a ac 49 84 2d be
        94 ad a0 c4 57 46 bc 70 d0 84 95 ce 96 c6 8c 92
        07 2e 4e 13 d6 f3 20 aa d7 86 ca 48 5e 01 a1 8c
        d3 f1 d7 74 f9 2c 84 48 7d c1 95 6d 22 81 ff 53
        ab d3 0c 89 81 7d a2 00 3d 00 00 0b 00 0b 00 02
        01 00 ff 01 00 01 00
    read from 0x6e13e8 [0x735ffb] (5 bytes => 5 (0x5))
    // etc.
    

    但是,当我使用OpenSSL 1.0.2f连接时,服务器会立即关闭连接:

    CONNECTED(00000300)
    write to 0x7812d0 [0x7ceef0] (317 bytes => 317 (0x13D))
    0000 - 16 03 01 01 38 01 00 01-34 03 03 45 1c 09 c2 2e   ....8...4..E....
    0010 - 46 06 85 a1 01 fd 0a 2c-bb 6f 15 10 42 74 b3 bf   F......,.o..Bt..
    0020 - 9f 2e 5c 00 9f f2 93 8e-c0 18 9c 00 00 b6 c0 30   ..\............0
    0030 - c0 2c c0 28 c0 24 c0 14-c0 0a 00 a5 00 a3 00 a1   .,.(.$..........
    0040 - 00 9f 00 6b 00 6a 00 69-00 68 00 39 00 38 00 37   ...k.j.i.h.9.8.7
    0050 - 00 36 00 88 00 87 00 86-00 85 c0 32 c0 2e c0 2a   .6.........2...*
    0060 - c0 26 c0 0f c0 05 00 9d-00 3d 00 35 00 84 c0 2f   .&.......=.5.../
    0070 - c0 2b c0 27 c0 23 c0 13-c0 09 00 a4 00 a2 00 a0   .+.'.#..........
    0080 - 00 9e 00 67 00 40 00 3f-00 3e 00 33 00 32 00 31   ...g.@.?.>.3.2.1
    0090 - 00 30 00 9a 00 99 00 98-00 97 00 45 00 44 00 43   .0.........E.D.C
    00a0 - 00 42 c0 31 c0 2d c0 29-c0 25 c0 0e c0 04 00 9c   .B.1.-.).%......
    00b0 - 00 3c 00 2f 00 96 00 41-00 07 c0 11 c0 07 c0 0c   .<./...A........
    00c0 - c0 02 00 05 00 04 c0 12-c0 08 00 16 00 13 00 10   ................
    00d0 - 00 0d c0 0d c0 03 00 0a-00 15 00 12 00 0f 00 0c   ................
    00e0 - 00 09 00 ff 01 00 00 55-00 0b 00 04 03 00 01 02   .......U........
    00f0 - 00 0a 00 1c 00 1a 00 17-00 19 00 1c 00 1b 00 18   ................
    0100 - 00 1a 00 16 00 0e 00 0d-00 0b 00 0c 00 09 00 0a   ................
    0110 - 00 23 00 00 00 0d 00 20-00 1e 06 01 06 02 06 03   .#..... ........
    0120 - 05 01 05 02 05 03 04 01-04 02 04 03 03 01 03 02   ................
    0130 - 03 03 02 01 02 02 02 03-00 0f 00 01 01            .............
    >>> TLS 1.2  [length 0005]
        16 03 01 01 38
    >>> TLS 1.2 Handshake [length 0138], ClientHello
        01 00 01 34 03 03 45 1c 09 c2 2e 46 06 85 a1 01
        fd 0a 2c bb 6f 15 10 42 74 b3 bf 9f 2e 5c 00 9f
        f2 93 8e c0 18 9c 00 00 b6 c0 30 c0 2c c0 28 c0
        24 c0 14 c0 0a 00 a5 00 a3 00 a1 00 9f 00 6b 00
        6a 00 69 00 68 00 39 00 38 00 37 00 36 00 88 00
        87 00 86 00 85 c0 32 c0 2e c0 2a c0 26 c0 0f c0
        05 00 9d 00 3d 00 35 00 84 c0 2f c0 2b c0 27 c0
        23 c0 13 c0 09 00 a4 00 a2 00 a0 00 9e 00 67 00
        40 00 3f 00 3e 00 33 00 32 00 31 00 30 00 9a 00
        99 00 98 00 97 00 45 00 44 00 43 00 42 c0 31 c0
        2d c0 29 c0 25 c0 0e c0 04 00 9c 00 3c 00 2f 00
        96 00 41 00 07 c0 11 c0 07 c0 0c c0 02 00 05 00
        04 c0 12 c0 08 00 16 00 13 00 10 00 0d c0 0d c0
        03 00 0a 00 15 00 12 00 0f 00 0c 00 09 00 ff 01
        00 00 55 00 0b 00 04 03 00 01 02 00 0a 00 1c 00
        1a 00 17 00 19 00 1c 00 1b 00 18 00 1a 00 16 00
        0e 00 0d 00 0b 00 0c 00 09 00 0a 00 23 00 00 00
        0d 00 20 00 1e 06 01 06 02 06 03 05 01 05 02 05
        03 04 01 04 02 04 03 03 01 03 02 03 03 02 01 02
        02 02 03 00 0f 00 01 01
    read from 0x7812d0 [0x7d4450] (7 bytes => 0 (0x0))
    10124:error:140790E5:SSL routines:ssl23_write:ssl handshake failure:.\ssl\s23_lib.c:177:
    ---
    no peer certificate available
    ---
    No client certificate CA names sent
    ---
    SSL handshake has read 0 bytes and written 317 bytes
    ---
    New, (NONE), Cipher is (NONE)
    Secure Renegotiation IS NOT supported
    Compression: NONE
    Expansion: NONE
    No ALPN negotiated
    SSL-Session:
        Protocol  : TLSv1.2
        Cipher    : 0000
        Session-ID:
        Session-ID-ctx:
        Master-Key:
        Key-Arg   : None
        PSK identity: None
        PSK identity hint: None
        SRP username: None
        Start Time: 1455100247
        Timeout   : 300 (sec)
        Verify return code: 0 (ok)
    ---
    

    我想没人会说话 ClientHello 很好地告诉我区别是什么,以及如何让OpenSSL 1.0.2f表现得像旧版本一样(即使它不安全;我不控制服务器)。

    我用Wireshark检查了两个跟踪,我能看到的唯一显著区别是OpenSSL 1.0.2的ClientHello数据包被Wireshar识别为“SSL”,记录层是SSL:

    OpenSSL 1.0.2

    而OpenSSL 1.0.1被标识为TLS 1.2。它也有更少的密码套件(我想他们删除了一些不安全的套件?)。

    OpenSSL 1.0.1

    我尝试了以下组合,Wireshark在“协议”列中对它们进行了标记:

    • 1.0.1: <no options> =TLSv1.2; -ssl2 =SSLv2; -ssl3 =SSLv3; -tls1_2 =TLSv1.2
    • 1.0.2: <无选项> =SSL; -ssl2 =SSLv2; -ssl3 =SSLv3; -tls1_2 =SSL

    关于以下方面的任何想法:

    1. 为什么Wireshark对1.0.1和1.0.2的解码方式不同?
    2. 为什么1.0.2连接失败?
    3. 如何使OpenSSL 1.0.2的行为类似于1.0.1?
    2 回复  |  直到 10 年前
        1
  •  2
  •   Community Mohan Dere    9 年前

    为什么Wireshark对1.0.1和1.0.2的解码方式不同?

    看见 SSL Record Layer vs SSLv3 Record Layer 在Wireshark Q&布告栏和 Secure Socket Layer (SSL) 在Wireshark wiki上。

    为什么1.0.2连接失败?

    看起来像是一个有缺陷的服务器,它拒绝了一个不是早期的记录层,就像SSLv3中使用的记录层。

    记录层只是…它指定了记录层的版本,这只是SSL/TLS协议消息的框架。它是 MIN-TLS-VERSION 正如许多人所想。

    TLS协议版本只是…它指定了SSL/TLS协议的版本。它是 MAX-TLS-VERSION 正如许多人所想。

    如何使OpenSSL 1.0.2的行为类似于1.0.1?

    在客户机中使用以下内容,但并不完全相同。OpenSSL客户端将做正确的事情,并选择TLS 1.2(如果可用):

    /* Uses the early record layer for downlevel servers */
    const SSL_METHOD* method = SSLv23_method();
    if(NULL == method) handleFailure();
    
    ctx = SSL_CTX_new(method);
    if(ctx == NULL) handleFailure();
    
    /* Cannot fail ??? */
    const long flags = SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | SSL_OP_NO_COMPRESSION;
    SSL_CTX_set_options(ctx, flags);
    

    我检查了OpenSSL 1.0.2 ssl/ssl.h ,以及两者 SSL_OP_NO_TLSv1 SSL_OP_NO_TLSv1_1 可用。

    对于OpenSSL Master(也称为OpenSSL 1.1.0及以上版本),有一种不同的方法;看见 Working around servers requiring SSL 2/3 record layer, and using TLS 1.2?


    …[OpenSSL 1.0.2]也有更少的密码套件(我想他们删除了一些不安全的套件?)。

    你应该 让密码套件碰碰运气。您应该执行以下操作:

    const char* const PREFERRED_CIPHERS = "HIGH:!aNULL:!kRSA:!PSK:!SRP:!MD5:!RC4";
    res = SSL_set_cipher_list(ssl, PREFERRED_CIPHERS);
    if(res != 1) handleFailure();
    

    这个 !PSK !SRP 简单地删除通常不使用的密码套件。 !MD5 !RC4 为服务器删除,以帮助避免 Obsolete cryptography warning from Browser .

    您甚至可以执行以下操作:

    const char* const PREFERRED_CIPHERS =
        "ECDHE-ECDSA-AES256-GCM-SHA384:"
        "ECDHE-RSA-AES256-GCM-SHA384:"
        "ECDHE-ECDSA-AES128-GCM-SHA256:"
        "ECDHE-RSA-AES128-GCM-SHA256:"
        "DHE-DSS-AES256-GCM-SHA384:"
        "DHE-RSA-AES256-GCM-SHA384:"
        "DHE-DSS-AES128-GCM-SHA256:"
        "DHE-RSA-AES128-GCM-SHA256";
    
    res = SSL_set_cipher_list(ssl, PREFERRED_CIPHERS);
    if(res != 1) handleFailure();
    

    请务必始终提供AES/GCM密码套件,因为随着服务器配置转向仅TLS 1.2配置,这是他们通常选择的密码套件。

    此外,每个密码套件在 ClientHello ,你想 减少 他们的数量。您希望将它们最小化,因为一些较旧的代理和侦听框为客户端使用固定大小的缓冲区 客户端你好 ,并且它们无法处理TLS 1.2中可用的密码套件选项的激增。较旧的盒子包括F5和Ironport中间件。

        2
  •  0
  •   Steffen Ullrich    10 年前

    为什么Wireshark对1.0.1和1.0.2的解码方式不同?

    不知道。

    为什么1.0.2连接失败?

    很难说,但我看到几个服务器在OpenSSL 1.0.2中添加了一些密码,或者给出了太多密码或类似密码时出现了问题。我在最近的LibreSSL版本中看到过类似的问题。在这种情况下,服务器显然破坏了TLS堆栈。

    如何使OpenSSL 1.0.2的行为类似于1.0.1?

    您可以尝试减少密码集,使其只使用与OpenSSL 1.0.1相同的密码。值得注意的是,我曾看到服务器在密码集内发出ChaCha20-Poly1305的声音,可能他们不知道这是什么类型的密码。