错误的密码套件或与OpenSSL服务器没有连接

时间:2015-05-25 21:46:09

标签: c++ openssl server

生成密钥

  

openssl ecparam -param_enc named_curve -name secp521r1 -genkey -outform PEM -out key.pem

生成证书

  

openssl req -x509 -new -key key.pem -keyform PEM -out ca.pem -outform PEM -days 3650

当我使用

<table class="table">
    <tr class="" id="">
        <td><div>People TEST</div></td>
        <td><div>Click to Expand TEST</div></td>
        <td><div>N/A TEST</div></td>
    </tr>
    <tr class="" id="">
        <td><div>People TEST</div></td>
        <td><div>Click to Expand TEST</div></td>
        <td><div>N/A TEST</div></td>
    </tr>
    <tr class="parent" id="row1">
        <td><div>People</div></td>
        <td><div>Click to Expand</div></td>
        <td><div>N/A</div></td>
    </tr>
    <tr class="child-row1-1">
        <td><div>Eve</div></td>
        <td><div>Jackson</div></td>
        <td><div>94</div></td>
    </tr>
    <tr class="child-row1-2">
        <td><div>John</div></td>
        <td><div>Doe</div></td>
        <td><div>80</div></td>
    </tr>
    <tr class="parent" id="row2">
        <td><div>People</div></td>
        <td><div>Click to Expand</div></td>
        <td><div>N/A</div></td>
    </tr>
    <tr class="child-row2-1">
        <td><div>Eve</div></td>
        <td><div>Jackson</div></td>
        <td><div>94</div></td>
    </tr>
    <tr class="child-row2-1">
        <td><div>John</div></td>
        <td><div>Doe</div></td>
        <td><div>80</div></td>
    </tr>
    <tr class="parent" id="row3">
        <td><div>People</div></td>
        <td><div>Click to Expand</div></td>
        <td><div>N/A</div></td>
    </tr>
    <tr class="child-row3-1">
        <td><div>Eve</div></td>
        <td><div>Jackson</div></td>
        <td><div>94</div></td>
    </tr>
    <tr class="child-row3-2">
        <td><div>John</div></td>
        <td><div>Doe</div></td>
        <td><div>80</div></td>
    </tr>
</table>

我可以使用

连接正常
openssl s_server -accept 5000 -key key.pem -cert ca.pem -tls1_2 -www

客户告诉我它使用

  

协议:TLSv1.2       密码:ECDHE-ECDSA-AES256-GCM-SHA384

正是我想要的

当我编译并使用以下c代码启动服务器

编译
  

g ++ Main2.cpp -ldl -lcrypto -lssl -o Main)

&#13;
&#13;
openssl s_client -host 10.8.0.26 -port 5000
&#13;
&#13;
&#13;

当我现在使用openssl s_client进行连接时,就像上面那样使用

  

协议:TLSv1.2       密码:ECDH-ECDSA-AES256-GCM-SHA384

不是ECDHE!为什么?

当我使用chrome / firefox连接到openssl s_server或我的服务器代码时,我得到:

  

140675163166384:错误:1408A0C1:SSL例程:SSL3_GET_CLIENT_HELLO:无共享密码:s3_srvr.c:1396:

为什么没有连接?

1 个答案:

答案 0 :(得分:1)

  

当我现在使用openssl s_client进行连接时就像上面那样使用了   Protocol : TLSv1.2 Cipher : ECDH-ECDSA-AES256-GCM-SHA384

     

不是ECDHE!为什么?

ECDHECDHE是两种不同的Diffie-Hellman。 ECDH使用固定服务器密钥。 ECDHE是短暂的,它使用临时密钥。您应该使用ECDHE

对于ECDHE,您没有使用SSL_CTX_set_tmp_ecdh_callback设置ECDHE回调。

有关详细信息,请参阅Server with ECDHE key and cert not working

相关,这是基于EC的DH密码:

openssl ciphers -v 'ALL:!aNULL' | grep ECDH
ECDHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH     Au=RSA  Enc=AESGCM(256) Mac=AEAD
ECDHE-ECDSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH     Au=ECDSA Enc=AESGCM(256) Mac=AEAD
ECDHE-RSA-AES256-SHA384 TLSv1.2 Kx=ECDH     Au=RSA  Enc=AES(256)  Mac=SHA384
ECDHE-ECDSA-AES256-SHA384 TLSv1.2 Kx=ECDH     Au=ECDSA Enc=AES(256)  Mac=SHA384
ECDHE-RSA-AES256-SHA    SSLv3 Kx=ECDH     Au=RSA  Enc=AES(256)  Mac=SHA1
ECDHE-ECDSA-AES256-SHA  SSLv3 Kx=ECDH     Au=ECDSA Enc=AES(256)  Mac=SHA1
ECDH-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH/RSA Au=ECDH Enc=AESGCM(256) Mac=AEAD
ECDH-ECDSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH/ECDSA Au=ECDH Enc=AESGCM(256) Mac=AEAD
ECDH-RSA-AES256-SHA384  TLSv1.2 Kx=ECDH/RSA Au=ECDH Enc=AES(256)  Mac=SHA384
ECDH-ECDSA-AES256-SHA384 TLSv1.2 Kx=ECDH/ECDSA Au=ECDH Enc=AES(256)  Mac=SHA384
ECDH-RSA-AES256-SHA     SSLv3 Kx=ECDH/RSA Au=ECDH Enc=AES(256)  Mac=SHA1
ECDH-ECDSA-AES256-SHA   SSLv3 Kx=ECDH/ECDSA Au=ECDH Enc=AES(256)  Mac=SHA1
ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH     Au=RSA  Enc=AESGCM(128) Mac=AEAD
ECDHE-ECDSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH     Au=ECDSA Enc=AESGCM(128) Mac=AEAD
ECDHE-RSA-AES128-SHA256 TLSv1.2 Kx=ECDH     Au=RSA  Enc=AES(128)  Mac=SHA256
ECDHE-ECDSA-AES128-SHA256 TLSv1.2 Kx=ECDH     Au=ECDSA Enc=AES(128)  Mac=SHA256
ECDHE-RSA-AES128-SHA    SSLv3 Kx=ECDH     Au=RSA  Enc=AES(128)  Mac=SHA1
ECDHE-ECDSA-AES128-SHA  SSLv3 Kx=ECDH     Au=ECDSA Enc=AES(128)  Mac=SHA1
ECDH-RSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH/RSA Au=ECDH Enc=AESGCM(128) Mac=AEAD
ECDH-ECDSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH/ECDSA Au=ECDH Enc=AESGCM(128) Mac=AEAD
ECDH-RSA-AES128-SHA256  TLSv1.2 Kx=ECDH/RSA Au=ECDH Enc=AES(128)  Mac=SHA256
ECDH-ECDSA-AES128-SHA256 TLSv1.2 Kx=ECDH/ECDSA Au=ECDH Enc=AES(128)  Mac=SHA256
ECDH-RSA-AES128-SHA     SSLv3 Kx=ECDH/RSA Au=ECDH Enc=AES(128)  Mac=SHA1
ECDH-ECDSA-AES128-SHA   SSLv3 Kx=ECDH/ECDSA Au=ECDH Enc=AES(128)  Mac=SHA1
ECDHE-RSA-RC4-SHA       SSLv3 Kx=ECDH     Au=RSA  Enc=RC4(128)  Mac=SHA1
ECDHE-ECDSA-RC4-SHA     SSLv3 Kx=ECDH     Au=ECDSA Enc=RC4(128)  Mac=SHA1
ECDH-RSA-RC4-SHA        SSLv3 Kx=ECDH/RSA Au=ECDH Enc=RC4(128)  Mac=SHA1
ECDH-ECDSA-RC4-SHA      SSLv3 Kx=ECDH/ECDSA Au=ECDH Enc=RC4(128)  Mac=SHA1
ECDHE-RSA-DES-CBC3-SHA  SSLv3 Kx=ECDH     Au=RSA  Enc=3DES(168) Mac=SHA1
ECDHE-ECDSA-DES-CBC3-SHA SSLv3 Kx=ECDH     Au=ECDSA Enc=3DES(168) Mac=SHA1
ECDH-RSA-DES-CBC3-SHA   SSLv3 Kx=ECDH/RSA Au=ECDH Enc=3DES(168) Mac=SHA1
ECDH-ECDSA-DES-CBC3-SHA SSLv3 Kx=ECDH/ECDSA Au=ECDH Enc=3DES(168) Mac=SHA1
  

当我使用chrome / firefox连接到openssl s_server或   我得到的服务器代码:140675163166384:error:1408A0C1:SSL routines:SSL3_GET_CLIENT_HELLO:no shared cipher:s3_srvr.c:1396

     

为什么没有连接?

您使用的是P-521。它应该得到支持,但它可能会造成麻烦。为实现最大的互操作性,请使用P-256:... -param_enc named_curve -name secp256k1

椭圆曲线齿轮在TLS 1.0及更高版本中可用。来自RFC 4492, Elliptic Curve Cryptography (ECC) Cipher Suites for Transport Layer Security (TLS)

  

本文档介绍了对TLS的补充,以支持ECC,适用于TLS版本1.0 [2]和TLS版本1.1 [3] ......

你应该改变这个:

method = TLSv1_2_server_method();

要:

method = SSLv23_method();
ctx = SSL_CTX_new(method);
...

const long flags = SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_COMPRESSION;
SSL_CTX_set_options(ctx, flags);

这会让你“TLS 1.0及更高版本”,它会移除压缩,从而泄露信息。您还应该考虑其他服务器端选项,例如SSL_OP_SAFARI_ECDHE_ECDSA_BUG

TLS 1.2是唯一提供Authenticated Encryption的协议版本,如AES / GCM。但是你通常会在密码套件列表字符串中处理这个细节。

为完整起见,您还应使用以下密码列表字符串SSL_CTX_set_cipher_list

HIGH:!aNULL:!kRSA:!RC4:!MD5

另请参阅Obsolete cryptography warning from Browser了解详情。

最终,您可能会遇到更多浏览器问题。浏览器已经移动了自签名服务器证书。要解决此问题,请参阅How do you sign Certificate Signing Request with your Certification Authority?

修复自签名证书后,由于公用名(CN)中的服务器名称,您的服务器证书可能会出现问题。服务器名称 必须 列在主题备用名称(SAN)中。要解决此问题,请参阅How to create a self-signed certificate with openssl?