谁能给我提供一个C++实现,比较简单,以获得SSL证书到期日期。我已经在网上找了好几个小时了,到目前为止什么都找不到。目前我正在使用libcpr,它似乎没有任何方法来获得它。我试过使用"curl“命令,但在操作系统上的输出中似乎也没有这些特定信息。如果在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
任何帮助都是徒劳无功的!谢谢
发布于 2022-06-27 02:34:14
我建议您参考这个问题中的代码
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;
https://stackoverflow.com/questions/72745476
复制相似问题