wget和curl访问https网页报错tlsv1 unrecognized name处理(未解决)

一、问题描述

某次,linux环境使用wget下载软件时,出现报错:

正在解析主机 nginx.org... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5704::6, ...
正在连接 nginx.org|52.58.199.22|:443... 已连接。
OpenSSL: error:14077458:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 unrecognized name
无法建立 SSL 连接。

二、分析处理

1)首先从报错来看,网络是正常的,问题发生在openssl网络安全验证阶段,检查现场环境ssl版本:

openssl version //现场为:1.0.1e-fips 11 Feb 2013

2)使用其他方式尝试

wget --no-check-certificate https://nginx.org/download/nginx-1.16.1.tar.gz
正在解析主机 nginx.org... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5704::6, ...
正在连接 nginx.org|52.58.199.22|:443... 已连接。
OpenSSL: error:14077458:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 unrecognized name
无法建立 SSL 连接。

curl -L -O https://nginx.org/download/nginx-1.16.1.tar.gz
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (35) SSL connect error

均报错:SSL连接类错误。然后直接:

curl -Ik https://nginx.org/   #报错如下
curl: (35) SSL connect error

curl --version

curl 7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
Protocols: tftp ftp telnet dict ldap ldaps http file https ftps scp sftp 
Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz 

3)尝试升级openssl版本到1.1.1k

wget --no-check-certificate -c https://www.openssl.org/source/openssl-1.1.1k.tar.gz
tar xzf openssl-1.1.1k.tar.gz
./config --prefix=/usr/local/ssl1.1.1 -fPIC
make
cp -pr /usr/lib64/libssl.so.1.0.1e /usr/lib64/libssl.so.1.0.1e.bak
cp -pr /usr/lib64/libcrypto.so.1.0.1e /usr/lib64/libcrypto.so.1.0.1e.bak
cp ./openssl-1.1.1k/apps/libcrypto.so.1.1 /usr/lib64/
cp ./openssl-1.1.1k/apps/libssl.so.1.1 /usr/lib64/
ldconfig
./openssl-1.1.1k/apps/openssl --version

4)重新编译安装nginx

nginx -s stop      #重新编译nginx前需要先停服务,如果不停Nginx,会造成nginx的二进制程序无法被替换
#或者不停止替换nginx后,执行
make upgrade
./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module --with-file-aio --add-module=/usr/local/src/echo-nginx-module --with-openssl=/home/software/openssl-1.1.1k    #添加openssl的参数后,指定openssl的源码路径,从新编译
make
./objs/nginx -V  #先验证下,然后将而二进制文件覆盖到/usr/sbin/下的
nginx -V    #验证即可,更新完openssl,旧版本的证书等不需要修改,新版本兼容旧版本,把危险的算法取消使用即可
nginx version: nginx/1.16.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) 
built with OpenSSL 1.1.1k  25 Mar 2021
TLS SNI support enabled

openssl s_client -connect https://nginx.org/download/nginx-1.16.1.tar.gz
139974539454208:error:2008F002:BIO routines:BIO_lookup_ex:system lib:crypto/bio/b_addr.c:730:Servname not supported for ai_socktype
connect:errno=0

curl -v https://nginx.org/download/nginx-1.16.1.tar.gz
* About to connect() to nginx.org port 443 (#0)
*   Trying 3.125.197.172... connected
* Connected to nginx.org (3.125.197.172) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* NSS error -12190
* Error in TLS handshake, trying SSLv3...
> GET /download/nginx-1.16.1.tar.gz HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: nginx.org
> Accept: */*
> 
* Connection died, retrying a fresh connect
* Closing connection #0
* Issue another request to this URL: 'https://nginx.org/download/nginx-1.16.1.tar.gz'
* About to connect() to nginx.org port 443 (#0)
*   Trying 3.125.197.172... connected
* Connected to nginx.org (3.125.197.172) port 443 (#0)
* TLS disabled due to previous handshake failure
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* NSS error -12286
* Closing connection #0
* SSL connect error

rpm -qa | grep nss   #检查nss版本
nss-sysinit-3.15.1-15.el6.x86_64
nss-softokn-freebl-3.14.3-9.el6.x86_64
openssh-5.3p1-94.el6.x86_64
openssh-server-5.3p1-94.el6.x86_64
openssl-devel-1.0.1e-15.el6.x86_64
nss-3.15.1-15.el6.x86_64
nss-tools-3.15.1-15.el6.x86_64
openssl-1.0.1e-15.el6.x86_64
nss-util-3.15.1-3.el6.x86_64
openssh-clients-5.3p1-94.el6.x86_64
nss-softokn-3.14.3-9.el6.x86_64

yum update nss -y #升级nss版本,现场使用NSS/3.14.0.0,

经测试,未果,本次处理失败,相关信息显示该问题是一个bug,参看SSL23_GET_SERVER_HELLO。此问题与 TLS SNI 扩展有关。上诉报错中,错误消息表示 SSL/TLS 握手中的某处存在错误。简而言之,cURL 错误代码 35 表示 SSL 连接错误。该错误可能是由于 cURL 包过时、连接错误或最终服务器的 PHP cURL 和 SSL 协议之间的版本不匹配造成的。

其他参考:SSL 连接错误 35

猜你喜欢

转载自blog.csdn.net/ximenjianxue/article/details/125043738
今日推荐