Apache-2.2

確定 SSL 證書是否受 SHA-1 淘汰的影響

  • June 23, 2015

在以下情況下,Google瀏覽器會開始警告使用者他們的 SSL 連接不安全:

  1. 證書使用 SHA1 雜湊算法,並且
  2. 證書在 2016-01-01 (或 2017-01-01 不同來源)或之後到期

因此,我正在嘗試編寫一種方法來確定證書是否受到影響。這是我維護的另一台伺服器上的 SHA1 證書的範例,該證書在“安全”時間範圍內到期:

$ curl -v --silent https://example.com/ 2>&1 | grep "expire\|SSL connection using"
* SSL connection using DHE-RSA-AES256-GCM-SHA384
*        expire date: 2015-07-20 00:00:00 GMT

**我怎麼能確定這個證書是字元串中的 SHA1 DHE-RSA-AES256-GCM-SHA384?**字元串中的內容確保它256看起來像是使用 256 位算法,儘管我知道這不是因為我自己使用$ openssl req -new -newkey rsa:2048 -nodes. Google搜尋我找到了這個資源或支持的密碼,但我不知道如何從該文件中確定密碼強度。

如何通過 curl 確定密碼強度,以便編寫腳本?

我怎麼能確定這個證書是來自字元串 DHE-RSA-AES256-GCM-SHA384 的 SHA1

你不能。此字元串僅描述用於加密的密碼套件,並且獨立於證書本身。您必須改為查看證書,如下所示:

openssl s_client -connect example.com:443 | \
openssl x509 -text -noout |\
grep 'Signature Algorithm\|Not After'

請注意,僅驗證證書是否包含 SHA-2 簽名是不夠的。您需要檢查鏈中直到根的所有中間證書都沒有使用 SHA-1 簽名。

NSS具有一個環境變數NSS_HASH_ALG_SUPPORT,可用於控制使用該庫的程序可以使用哪些散列算法。這個環境變數將受到包括 Firefox 在內的許多程序的尊重,curl如果它是在 NSS 支持下編譯的(例如 Red Hat Enterprise Linux 和 Fedora)。

curl -V | fgrep NSS/
env NSS_HASH_ALG_SUPPORT=-SHA-1 curl -v --head https://www.google.com/

如果curl使用 NSS 支持編譯,並且正在使用 SHA-1 證書,則輸出將如下所示:

curl 7.40.0 (x86_64-redhat-linux-gnu) libcurl/7.40.0 NSS/3.18 Basic ECC zlib/1.2.8 libidn/1.29 libssh2/1.5.0
*   Trying 64.233.166.104...
* Connected to www.google.com (64.233.166.104) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
 CApath: none
* Server certificate:
*       subject: CN=www.google.com,O=Google Inc,L=Mountain View,ST=California,C=US
*       start date: Jun 03 09:26:01 2015 GMT
*       expire date: Sep 01 00:00:00 2015 GMT
*       common name: www.google.com
*       issuer: CN=Google Internet Authority G2,O=Google Inc,C=US
* NSS error -8016 (SEC_ERROR_CERT_SIGNATURE_ALGORITHM_DISABLED)
* The certificate was signed using a signature algorithm that is disabled because it is not secure.
* Closing connection 0
curl: (60) The certificate was signed using a signature algorithm that is disabled because it is not secure.
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.
Exit 60

引用自:https://serverfault.com/questions/642464