【问题标题】:Nginx-1.19.6 + Openssl 1.1.1i - Can't do SSL handshakeNginx-1.19.6 + Openssl 1.1.1i - 无法进行 SSL 握手
【发布时间】:2021-05-10 21:55:15
【问题描述】:

我正在尝试使用带有 sslv3 和密码 RC4-SHA:RC4-MD5 支持的 Nginx 运行服务器(我需要这些密码)。 我能够在 Ubuntu 16.04 上使用 Openssl 1.0.2u 源 + 上一个 nginx 版本源 (nginx-1.19.6) 做到这一点。我使用这个命令构建了 Nginx:

./configure --with-http_ssl_module --with-openssl=/path/to/openssl-1.0.2u --with-openssl-opt=enable-ssl3 --with-openssl-opt=enable-ssl3-method --with-openssl-opt=enable-weak-ssl-ciphers

我使用的 Nginx 配置是:

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    ssl_protocols SSLv3;
    ssl_ciphers RC4-SHA:RC4-MD5:@SECLEVEL=0;
    ssl_certificate /path/to/server-chain.crt;
    ssl_certificate_key /path/to/server.key;
    server_name server.name.net;
    underscores_in_headers on;
    proxy_pass_request_headers on;
    location / {    
        proxy_set_header X-Forwarded-Host \$host:\$server_port;
        proxy_set_header X-Forwarded-Server \$host;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:9000;
    }
}

设置 nginx 配置文件后,一切正常。我能够从 Ubuntu 14.04 机器上使用此命令获取 ssl 证书:

openssl s_client -connect MyIP:443 -ssl3 -cipher RC4-SHA:RC4-MD5.

我尝试使用具有相同配置选项的 Openssl 1.1.1i 源代码构建 Nginx,但是在设置 nginx conf 文件后,当我尝试运行 openssl s_client -connect... 命令时,出现此错误:

CONNECTED(00000003)
140420793624224:error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number:s3_pkt.c:339:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 5 bytes and written 7 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : SSLv3
    Cipher    : 0000
    Session-ID: 
    Session-ID-ctx: 
    Master-Key: 
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1612540521
    Timeout   : 7200 (sec)
    Verify return code: 0 (ok)
---

在 Nginx error.log 文件中我得到了这个:

SSL_do_handshake() failed (SSL: error:141FC044:SSL routines:tls_setup_handshake:internal error) while SSL handshaking, client: 192.168.1.10, server: 0.0.0.0:443

openssl 1.1.1 有什么变化吗?我是否缺少启用 SSLv3 + RC4-SHA:RC4-MD5 的任何配置选项? 感谢您的任何提示!

【问题讨论】:

    标签: nginx ssl openssl


    【解决方案1】:

    SSL Ciphers in nginx 需要您的 openSSL 版本支持。来自openSSL Changelog of 1.0.2h and 1.1.0

    基于 RC4 的 libssl 密码套件现在被归类为“弱”密码,默认情况下被禁用。可以使用配置的 enable-weak-ssl-ciphers 选项重新启用它们。

    【讨论】:

    • 我使用 enable-weak-ssl-ciphers 用 openssl 编译了 nginx(上面写了完整的命令)。我还在 ssl_chipers 字符串中添加了 @SECLEVEL=0。我真的不明白我做错了什么
    • 哦,对不起!我不这么认为,因为它在您的命令中链接了 1.0.2,我什至无法使用此标志编译最近的 nginx(由于我的实验室中缺少 pcrezlib)。我刚刚编译了相同的配置(1.19.6 + openssl 1.1.1),也无法从 ubuntu xenial 上的 1.0.2g openssl 中获得 -connect 的结果(最近的版本甚至不接受 -ssl3) - 与SSL 端的错误不同,但 nginx 端的错误相同。还有sslyze 找不到匹配的密码,有什么不寻常的......
    • 要修复 prce 和 zlib,只需运行:sudo apt-get install libpcre3 libpcre3-dev zlib1g zlib1g-dev
    • 我手动链接它们,因为我自己定期编译 nginx。这就是为什么我认为“这可能是一个简单的镜头” - 它不是;)仍然不知道问题可能是什么。
    • 从您在上面链接的 nginx 页面中挖掘,我发现了这个页面:openssl.org/docs/man1.1.1/man3/SSL_CTX_set_security_level.html 在注释中它谈到了 -DOPENSSL_TLS_SECURITY_LEVEL=level 选项。我尝试使用它(=0),但旧密码完全不适用了......
    【解决方案2】:

    最后我能够解决这个问题!

    我下载了最后一个 openssl 源(1.1.1i)和最后一个 nginx 源(1.19.6)。 我使用以下命令编译并安装了 openssl:

    ./config enable-ssl3 enable-ssl3-method enable-weak-ssl-ciphers
    make
    sudo make install
    

    我编辑了 openssl.cnf 文件 (/usr/local/ssl/openssl.cnf) 添加

    openssl_conf = default_conf
    

    在文件开头并添加

    [default_conf]
    ssl_conf = ssl_sect
    
    [ssl_sect]
    system_default = system_default_sect
    
    [system_default_sect]
    CipherString = ALL:@SECLEVEL=0
    

    在文件的底部。这启用了旧密码(我需要 RC4-SHA 和 RC4-MD5)。 然后我使用以下命令编译并安装了 nginx:

    ./configure --with-http_ssl_module --with-ld-opt="-L/usr/local"
    make
    sudo make install
    

    在为 ssl 证书配置 nginx 后,我可以使用 openssl s_client... 命令获取它们!

    【讨论】:

      猜你喜欢
      • 2012-08-09
      • 2015-02-03
      • 2015-12-21
      • 2017-05-02
      • 1970-01-01
      • 2016-12-20
      • 1970-01-01
      • 2015-03-16
      • 1970-01-01
      相关资源
      最近更新 更多