Openssl C++获得到期日期

Pra*_*van 3 c++ openssl x509certificate

我应该使用什么功能来获得x509证书的到期日期?我将首先检查证书的有效性.如果它已过期,我需要获得证书的失效日期.

For*_*veR 6

我想你应该用这个.

#define     X509_get_notBefore(x) ((x)->cert_info->validity->notBefore)
#define     X509_get_notAfter(x) ((x)->cert_info->validity->notAfter)
Run Code Online (Sandbox Code Playgroud)

以此为例.示例使用此宏.

http://www.openssl.org/docs/crypto/X509_STORE_CTX_set_verify_cb.html

  • 这些宏在 1.1.0h 中不再有效。如果您针对现代 API 进行了更新,那就太好了。const ASN1_TIME *before = X509_get0_notBefore( x509 ); const ASN1_TIME *after = X509_get0_notAfter( x509 ); (2认同)

小智 5

编辑:在使用X509_get_notAfter和X509_get_notBefore后,您应该执行以下操作,如"Forever"之前的回答.

要转换,ASN1_TIME您可以使用ASN1_TIME_print()asn1.h中声明的例程.

这可以做到这一点:

BIO *bio;
int write = 0;
bio = BIO_new(BIO_s_mem());
if (bio) {
    if (ASN1_TIME_print(bio, tm))
        write = BIO_read(bio, buf, len-1);
    BIO_free(bio);
}
buf[write]='\0';
return write;
Run Code Online (Sandbox Code Playgroud)