首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Windows上的SSL证书过期日期

Windows上的SSL证书过期日期
EN

Stack Overflow用户
提问于 2022-06-24 14:22:01
回答 1查看 199关注 0票数 1

谁能给我提供一个C++实现,比较简单,以获得SSL证书到期日期。我已经在网上找了好几个小时了,到目前为止什么都找不到。目前我正在使用libcpr,它似乎没有任何方法来获得它。我试过使用"curl“命令,但在操作系统上的输出中似乎也没有这些特定信息。如果在GitBash中运行,相同的命令在输出中给出“过期日期”,而不是在windows命令提示符中。我是C++的新手。

下面的命令和输出来自GitBash。

代码语言:javascript
运行
复制
$ 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

任何帮助都是徒劳无功的!谢谢

EN

Stack Overflow用户

发布于 2022-06-27 02:34:14

我建议您参考这个问题中的代码

代码语言:javascript
运行
复制
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;
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72745476

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档