為什麼curl憑證固定測試不能使用sha1摘要工作?

為什麼curl憑證固定測試不能使用sha1摘要工作?

我在憑證固定測試中使用 sha1 摘要時遇到問題。使用 sha256 工作正常,但如果我使用 sha1,它就不起作用。為什麼?

捲曲版本:
 
➜ src ./curl -V
捲曲 7.55.1 (x86_64-apple-darwin16.0.0) libcurl/7.55.1 SecureTransport zlib/1.2.8
發佈日期:2017-08-14
協定: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
功能: 非同步 DNS IPv6 大檔案 NTLM NTLM_WB SSL libz UnixSockets

測試 1 使用沙256   ➜ src openssl s_client -connect uol.com.br:443 | openssl x509 -pubkey -noout | openssl x509 -pubkey -noout | openssl x509 -pubkey -noout | openssl x509 -pubkey -noout openssl rsa -pubin -outform der | openssl rsa -pubin -outform der | openssl rsa -pubin -outform der | openssl dgst sha256 - 二進位 | openssl enc -base64 深度=2 /C=US/O=GeoTrust Inc./CN=GeoTrust Global CA 驗證錯誤:num=19:憑證鏈中的自簽名憑證 驗證返回:0 寫入 RSA 金鑰 d9W9zyq64Gw8JEA/siAixfvoRRwZVpSgbYJV//0CeKM=

➜ src ./curl --head --verbose --pinnedpubkey "sha256//d9W9zyq64Gw8JEA/siAixfvoRRwZVpSgbYJV//0CeKM="https://uol.com.br * 嘗試 200.147.67.142... * TCP_NODELAY設定 * 連接到 uol.com.br (200.147.67.142) 連接埠 443 (#0) * 公鑰雜湊:sha256//d9W9zyq64Gw8JEA/siAixfvoRRwZVpSgbYJV//0CeKM= * 使用 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 的 TLS 1.2 連接 * 伺服器憑證:www.uol.com.br * 伺服器憑證:RapidSSL SHA256 CA * 伺服器憑證:GeoTrust Global CA > 頭 / HTTP/1.1 > 主辦單位:uol.com.br > 用戶代理:curl/7.55.1 > 接受:/ > < HTTP/1.1 302 找到 HTTP/1.1 302 找到 < 日期:2017 年 9 月 29 日星期五 19:32:18 GMT 日期:2017 年 9 月 29 日星期五 19:32:18 GMT <伺服器:阿帕契 伺服器:阿帕契 < 連線:關閉 連線:關閉 < 內容類型:text/html;字符集=iso-8859-1 內容類型:text/html;字符集=iso-8859-1   < * 關閉連線0

測試 2 使用沙1   ➜ src openssl s_client -connect uol.com.br:443 | openssl x509 -pubkey -noout | openssl x509 -pubkey -noout | openssl x509 -pubkey -noout | openssl x509 -pubkey -noout openssl rsa -pubin -outform der | openssl rsa -pubin -outform der | openssl rsa -pubin -outform der | openssl dgst -sha1 -二進位 | openssl enc -base64 深度=2 /C=US/O=GeoTrust Inc./CN=GeoTrust Global CA 驗證錯誤:num=19:憑證鏈中的自簽名憑證 驗證返回:0 寫入 RSA 金鑰 BQr5oEtKUmTzlcelRcWvGvMnQzk=

➜ src ./curl --head --verbose --pinnedpubkey "sha1//BQr5oEtKUmTzlcelRcWvGvMnQzk="https://uol.com.br * 嘗試 200.221.2.45... * TCP_NODELAY設定 * 連接到 uol.com.br (200.221.2.45) 連接埠 443 (#0) * SSL:公鑰與固定公鑰不符! * 關閉連線0 curl:(90)SSL:公鑰與固定的公鑰不符!

答案1

因為curl只檢查 SHA256 雜湊值;不是 SHA1 哈希值。

從手冊頁:

--pinnedpubkey <固定公鑰(哈希)>

          (SSL) Tells curl to  use  the  specified  public  key  file  (or
          hashes)  to  verify the peer. This can be a path to a file which
          contains a single public key in PEM or DER format, or any number
          of base64 encoded sha256 hashes preceded by ´sha256//´ and sepa‐
          rated by ´;´

相關內容