[英]SSL certificate expiration date on Windows
任何人都可以為我提供一個相當簡單的 C++ 實現來獲取 SSL 證書到期日期。 過去幾個小時我一直在網上尋找,到目前為止找不到任何東西。 目前我正在使用libcpr,它似乎沒有任何辦法得到它。 我嘗試使用“curl”命令,但在Windows操作系統的輸出中似乎也沒有特定信息。 如果我在 GitBash 中運行相同的命令,而不是在 Windows 命令提示符中運行,相同的命令會在輸出中給出“過期日期”。 我是 C++ 新手。
下面的命令和輸出來自 GitBash。
$ curl --insecure -vvI https://www.example.com
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN: server accepted h2
* Server certificate:
* subject: C=US; ST=California; L=Los Angeles;
O=Internet▒Corporation▒for▒Assigned▒Names▒and▒Numbers; CN=www.example.org
* start date: Mar 14 00:00:00 2022 GMT
* expire date: Mar 14 23:59:59 2023 GMT <-------- **********
* issuer: C=US; O=DigiCert Inc; CN=DigiCert TLS RSA SHA256 2020 CA1
* SSL certificate verify result: unable to get local issuer certificate (20),
continuing anyway.
* Using HTTP2, server supports multiplexing
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* h2h3 [:method: HEAD]
* h2h3 [:path: /]
* h2h3 [:scheme: https]
* h2h3 [:authority: www.example.com]
* h2h3 [user-agent: curl/7.83.0]
* h2h3 [accept: */*]
* Using Stream ID: 1 (easy handle 0x16d9a46c1d0)
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* old SSL session ID is stale, removing
* Connection #0 to host www.example.com left intact
任何幫助將不勝感激!! 謝謝
我建議你參考這個問題中的代碼:
ASN1_TIME *expires = X509_get_notAfter(cert.get());
// Construct another ASN1_TIME for the unix epoch, get the difference
// between them and use that to calculate a unix timestamp representing
// when the cert expires
ASN1_TIME_ptr epoch(ASN1_TIME_new(), ASN1_STRING_free);
ASN1_TIME_set_string(epoch.get(), "700101000000");
int days, seconds;
ASN1_TIME_diff(&days, &seconds, epoch.get(), expires);
time_t expire_timestamp = (days * 24 * 60 * 60) + seconds;
std::cout << "Expiration timestamp:" << std::endl;
std::cout << expire_timestamp << std::endl;
std::cout << std::endl;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.