Ale*_*man 7 ssl ssl-certificate curl
我正在尝试https://www.lawsociety.com.au在 Windows 10 和 Ubuntu 16.04上使用 curl访问该网站。它适用于 Ubuntu,但在 Windows 上失败并显示消息error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure。我不确定出了什么问题以及如何解决它。
这是 Windows 机器上的 curl 输出:
> curl -i -v -I https://www.lawsociety.com.au
* Rebuilt URL to: https://www.lawsociety.com.au/
* Trying 125.7.104.7...
* TCP_NODELAY set
* Connected to www.lawsociety.com.au (125.7.104.7) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: D:\dev\curl\bin\curl-ca-bundle.crt
CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS alert, Server hello (2):
* error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure
* stopped the pause stream!
* Closing connection 0
curl: (35) error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure
Run Code Online (Sandbox Code Playgroud)
卷曲版本:
curl 7.57.0 (x86_64-pc-win32) libcurl/7.57.0 OpenSSL/1.1.0g (WinSSL) zlib/1.2.11 WinIDN libssh2/1.8.0 nghttp2/1.28.0
Release-Date: 2017-11-29
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile SSPI Kerberos SPNEGO NTLM SSL libz TLS-SRP HTTP2 HTTPS-proxy MultiSSL
Run Code Online (Sandbox Code Playgroud)
Ubuntu 盒子上的相同命令:
$ curl -I -v https://www.lawsociety.com.au
* Rebuilt URL to: https://www.lawsociety.com.au/
* Trying 125.7.104.7...
* Connected to www.lawsociety.com.au (125.7.104.7) port 443 (#0)
* found 148 certificates in /etc/ssl/certs/ca-certificates.crt
* found 594 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* SSL connection using TLS1.0 / RSA_3DES_EDE_CBC_SHA1
* server certificate verification OK
* server certificate status verification SKIPPED
* common name: *.lawsociety.com.au (matched)
* server certificate expiration date OK
* server certificate activation date OK
* certificate public key: RSA
* certificate version: #3
* subject: C=AU,postalCode=2000,ST=NSW,L=Sydney,street=170 Phillip Street,O=THE LAW SOCIETY OF NEW SOUTH WALES,OU=PremiumSSL Wildcard,CN=*.lawsociety.com.au
* start date: Fri, 17 Mar 2017 00:00:00 GMT
* expire date: Mon, 16 Apr 2018 23:59:59 GMT
* issuer: C=GB,ST=Greater Manchester,L=Salford,O=COMODO CA Limited,CN=COMODO RSA Organization Validation Secure Server CA
* compression: NULL
* ALPN, server did not agree to a protocol
> HEAD / HTTP/1.1
> Host: www.lawsociety.com.au
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Date: Tue, 26 Dec 2017 09:04:02 GMT
Date: Tue, 26 Dec 2017 09:04:02 GMT
< Server: Oracle-Application-Server-11g
Server: Oracle-Application-Server-11g
< Cache-Control: no-cache
Cache-Control: no-cache
< Content-Length: 36272
Content-Length: 36272
< Set-Cookie: JSESSIONID=kGs3hCQCW7FPhQ2Lh0JvKn9JvXhhHCK2GQKXvLps308Ww1D70pMp!1826685759; path=/; HttpOnly
Set-Cookie: JSESSIONID=kGs3hCQCW7FPhQ2Lh0JvKn9JvXhhHCK2GQKXvLps308Ww1D70pMp!1826685759; path=/; HttpOnly
< X-ORACLE-DMS-ECID: 005OJeGQSZb9xWGayxQ_MG0007Z60000EU
X-ORACLE-DMS-ECID: 005OJeGQSZb9xWGayxQ_MG0007Z60000EU
< X-Powered-By: Servlet/2.5 JSP/2.1
X-Powered-By: Servlet/2.5 JSP/2.1
< Content-Type: text/html; charset=utf-8
Content-Type: text/html; charset=utf-8
<
* Connection #0 to host www.lawsociety.com.au left intact
Run Code Online (Sandbox Code Playgroud)
我openssl s_client在 Windows 上尝试过命令:
> openssl s_client -connect www.lawsociety.com.au:443
CONNECTED(00000224)
depth=3 C = SE, O = AddTrust AB, OU = AddTrust External TTP Network, CN = AddTrust External CA Root
verify error:num=19:self signed certificate in certificate chain
---
Certificate chain
0 s:/C=AU/postalCode=2000/ST=NSW/L=Sydney/street=170 Phillip Street/O=THE LAW SOCIETY OF NEW SOUTH WALES/OU=PremiumSSL Wildcard/CN=*.lawsociety.com.au
i:/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Organization Validation Secure Server CA
1 s:/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Organization Validation Secure Server CA
i:/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Certification Authority
2 s:/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Certification Authority
i:/C=SE/O=AddTrust AB/OU=AddTrust External TTP Network/CN=AddTrust External CA Root
3 s:/C=SE/O=AddTrust AB/OU=AddTrust External TTP Network/CN=AddTrust External CA Root
i:/C=SE/O=AddTrust AB/OU=AddTrust External TTP Network/CN=AddTrust External CA Root
---
Server certificate
-----BEGIN CERTIFICATE-----
... <removed to save space> ...
-----END CERTIFICATE-----
subject=/C=AU/postalCode=2000/ST=NSW/L=Sydney/street=170 Phillip Street/O=THE LAW SOCIETY OF NEW SOUTH WALES/OU=PremiumSSL Wildcard/CN=*.lawsociety.com.au
issuer=/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Organization Validation Secure Server CA
---
No client certificate CA names sent
---
SSL handshake has read 5683 bytes and written 621 bytes
---
New, TLSv1/SSLv3, Cipher is RC4-SHA
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1
Cipher : RC4-SHA
Session-ID: 8198FE887E4FC12D68E2388D4C052ABF
Session-ID-ctx:
Master-Key: 93688C15A75E3E9F596AF96DFF72B557AD28A3FEF8764401CBD12D1F432EAF4D216595D74338AF24498AB29FF5ABE759
Key-Arg : None
PSK identity: None
PSK identity hint: None
SRP username: None
Start Time: 1514278771
Timeout : 300 (sec)
Verify return code: 19 (self signed certificate in certificate chain)
---
Run Code Online (Sandbox Code Playgroud)
所以连接似乎没问题。在浏览器中打开 URL 也能正常工作。
我错过了什么?
更新
1.可能的问题之一是该网站使用的是过时的 RC4-SHA 密码。我试图用 curl 显式启用它,但 curl 拒绝它:
> curl -i -v -I --ciphers "RC4-SHA" https://www.lawsociety.com.au
* Rebuilt URL to: https://www.lawsociety.com.au/
* Trying 125.7.104.7...
* TCP_NODELAY set
* Connected to www.lawsociety.com.au (125.7.104.7) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* failed setting cipher list: RC4-SHA
* Closing connection 0
curl: (59) failed setting cipher list: RC4-SHA
Run Code Online (Sandbox Code Playgroud)
2.另一个潜在问题是根证书可能不可用。但是,curl 带有最新的 Mozilla CA 包 ( curl-ca-bundle.crt),所以我相信它使用的是正确的证书。
我还将所有公共证书从工作 Ubuntu 机器复制到 Windows 机器,并使用--capath参数指定 curl 的证书路径- 它没有帮助。
3.为了完整起见,我尝试使用最新的 Python 3.6.4:
import urllib.request
with urllib.request.urlopen('https://www.lawsociety.com.au/') as u:
print(u.read())
Run Code Online (Sandbox Code Playgroud)
Python SSL 应该为 HTTPS 使用 Windows 工具。但是,它失败并出现相同的错误:
ssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:777)
...
During handling of the above exception, another exception occurred:
...
urllib.error.URLError: <urlopen error [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:777)>
Run Code Online (Sandbox Code Playgroud)
所以看起来问题不是缺少证书,而是发生在更早的地方。我不是 SSL 专家,所以我可能错了。
解决方案
问题的根本原因是网站使用的 SSL 协议+密码过时。为了使 curl 工作,我将其降级到使用 OpenSSL 1.0.2 的版本,该版本仍然支持 RC4 密码。之后,一切都完美无缺。
对于那些需要 Python 解决方案的人:
import ssl
import urllib.request
ctx = ssl.SSLContext(protocol=ssl.PROTOCOL_SSLv3)
ctx.set_ciphers('SSLv3')
# alternatively, for this particular website:
#ctx.set_ciphers('RC4-SHA:RC4-MD5')
with urllib.request.urlopen('https://www.lawsociety.com.au/', context=ctx) as u:
print(u.read())
Run Code Online (Sandbox Code Playgroud)
我相信这里实际上有两个有些重叠的问题,两者都与服务器显然过时或疯狂操作有关。ssllabs 的分析表明它仅支持 SSLv3 和 TLSv1.0 协议,并且仅支持四种密码套件:
TLS_RSA_WITH_DES_CBC_SHA (0x9) INSECURE 56
TLS_RSA_WITH_3DES_EDE_CBC_SHA (0xa) WEAK 112
TLS_RSA_WITH_RC4_128_MD5 (0x4) INSECURE 128
TLS_RSA_WITH_RC4_128_SHA (0x5) INSECURE 128
Run Code Online (Sandbox Code Playgroud)
(在 OpenSSL 命名方案中是 DES-CBC-SHA、DES-CBC3-SHA、RC4-MD5 和 RC4-SHA)。
首先,正如 SSLLabs 所指出的,服务器是“版本不容忍的”;如果您将 ClientHello 提供的版本高于 1.0的记录发送到 1.0版(以及其他可接受的)记录中,它会协商降低到 1.0,因为它应该*,但是如果您发送此提供的记录版本为 1.1 或 1.2,就像某些软件所做的那样(但不是AFAICT 任何最近的 OpenSSL),服务器会以警告 close_notify 中止(这对于此状态是不正确的)。(*:嗯,因为它应该完全支持 1.0)
其次,它仅支持上述四种密码套件。最新版本的 OpenSSL,特别是 1.1.0g 不再支持单 DES(根本),因为它完全被破坏了,并且由于各种偏见和通用生日攻击,默认情况下不支持 RC4 或三重 DES ;因此,如果使用 OpenSSL,则没有共同的密码套件,并且服务器会正确中止并发出警报握手失败。但是应该可以启用 RC4 和/或 TDES,除非它们是在构建(编译)时配置的。我注意到您的Windows版本的节目,除了对; 我不知道这是否意味着这里使用了 schannel(或根本不使用),在这种情况下,这可能是原因(WinSSL) OpenSSL/1.1.0g--ciphers RC4-SHA (使用 OpenSSL 命名方案)不起作用。
注意 Windows 程序,尤其是像 curl 和 OpenSSL 这样的“导入”,通常不会像在 Unbuntu 和大多数 Linux(和其他 Unix)上那样共享库。您可以尝试openssl version在您的 Windows OpenSSL 上查看它是哪个;我敢打赌它不是最新的,如果您获得最新的,它将从命令行显示相同的问题。
Ubuntu 16.04(我假设 LTS?)并不是最前沿的,它仍然支持最近才被弃用的密码是有意义的。
| 归档时间: |
|
| 查看次数: |
61983 次 |
| 最近记录: |