使用稍旧版本的 curl,我有一个方便的批处理文件:
curl --verbose -k https://%1 2>&1 |grep -E "Connected to|subject|expire"
Run Code Online (Sandbox Code Playgroud)
这将向我显示连接到的 IP,以及协商的实际证书的主题和到期日期,即使这不是该域名的正确证书 - 这有时是我们托管的问题(我们实际上托管了数千个域)在我们的多租户应用程序中,大约一半拥有自己的证书)。
具体来说,在 grep 过滤之前,我会在 stderr 输出中看到类似的内容:
* Server certificate:
* subject: CN=academy-fran.chi.v6.pressero.com
* start date: Feb 22 04:55:00 2017 GMT
* expire date: May 23 04:55:00 2017 GMT
* issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
* SSL certificate verify ok.
Run Code Online (Sandbox Code Playgroud)
今天我不得不在我的机器上重新安装操作系统,并重新安装 curl。现在是 7.52.1 (x86_64-w64-mingw32) 版本;上一个似乎是 7.49.1 (i686-pc-cygwin)。无论是否使用 -k,无论 TLS 连接成功与否,Curl 不再显示任何证书信息。
有没有办法把它还给我?
Myl*_*ser 15
对于 OSX 或 Linux 上的其他人,您可以将其添加到您的~/.zshrc文件中:
function seecert () {
nslookup $1
(openssl s_client -showcerts -servername $1 -connect $1:443 <<< "Q" | openssl x509 -text | grep -iA2 "Validity")
}
Run Code Online (Sandbox Code Playgroud)
示例用法,在source ~/.zshrc上述添加后运行 a之后:
% seecert www.google.com
Server: 1.1.1.1
Address: 1.1.1.1#53
Non-authoritative answer:
Name: www.google.com
Address: 172.217.10.100
depth=2 OU = GlobalSign Root CA - R2, O = GlobalSign, CN = GlobalSign
verify return:1
depth=1 C = US, O = Google Trust Services, CN = GTS CA 1O1
verify return:1
depth=0 C = US, ST = California, L = Mountain View, O = Google LLC, CN = www.google.com
verify return:1
DONE
Validity
Not Before: Nov 3 07:39:18 2020 GMT
Not After : Jan 26 07:39:18 2021 GMT
Run Code Online (Sandbox Code Playgroud)
感谢@ross-presser和他对这个功能的灵感的回答。
这是我的替换批处理文件,使用 openssl 而不是curl:
@echo off
nslookup %1
(openssl s_client -showcerts -servername %1 -connect %1:443 <nul |openssl x509 -text |findstr /I "DNS After") 2>nul
Run Code Online (Sandbox Code Playgroud)
这给了我这个输出:
C:\>seecert www.google.com
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
Name: www.google.com
Address: 172.217.10.228
Name: www.google.com
Address: 2607:f8b0:4006:813::2004
Not After : Aug 16 09:49:00 2018 GMT
DNS:www.google.com
Run Code Online (Sandbox Code Playgroud)
小智 5
如果您不想使用 ssl_client,在较新版本的 Windows(服务器和客户端版本)上,默认安装了 curl.exe 但没有可用的 openssl,curl.exe 可以通过使用
-w, --write-out <format>
Run Code Online (Sandbox Code Playgroud)
像这样的选项
-w '\n%{certs}\n'
Run Code Online (Sandbox Code Playgroud)
在结果中你会发现类似这样的行
Subject:CN=<a host name>
Issuer:<an issuer string>
Version:2
Serial Number:<some two digit hex chars>
Signature Algorithm:sha256WithRSAEncryption
Start Date:2023-03-14 00:00:00 GMT
Expire Date:2024-04-13 23:59:59 GMT
Public Key Algorithm:rsaEncryption
RSA Public Key:2048
rsa(n):<lots of two digit hex chars>
rsa(e):0x10001
Signature:<lots of two digit hex chars>
Run Code Online (Sandbox Code Playgroud)
这个答案的来源是通过仔细阅读curl在线手册页找到的。检查版本:
curl.exe --version
curl 8.0.1 (Windows) libcurl/8.0.1 Schannel WinIDN
Release-Date: 2023-03-20
Run Code Online (Sandbox Code Playgroud)
我需要这些信息来检查我们公司代理是否打开了 SSL/TLS 加密,检查其是否存在恶意代码,并在将其发送到客户端之前重新加密,并以如下方式使用它:
curl.exe --ssl-no-revoke -w '\n%{certs}\n' --proxy http://proxy-server:port/ https://target-server:port/path/of/the/resource.ending
Run Code Online (Sandbox Code Playgroud)
编辑:错字已修复
| 归档时间: |
|
| 查看次数: |
21242 次 |
| 最近记录: |