Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Openssl C++ get expiry date

What is the function that I should use to get the x509 certificate expiry date? I will first check the validity of the certificate. If it has expired, I need to get the expiry date of the certificate.

like image 611
Prasanth Madhavan Avatar asked Dec 12 '22 23:12

Prasanth Madhavan


2 Answers

Edit: You should be doing the below after using X509_get_notAfter and X509_get_notBefore as answered previously by "Forever".

To convert the ASN1_TIME you can use ASN1_TIME_print() routine declared in asn1.h.

This would do the job:

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;
like image 108
Raj Avatar answered Dec 14 '22 13:12

Raj


I think you should use this.

#define     X509_get_notBefore(x) ((x)->cert_info->validity->notBefore)
#define     X509_get_notAfter(x) ((x)->cert_info->validity->notAfter)

Look at this for example. Examples use this macro.

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

like image 25
ForEveR Avatar answered Dec 14 '22 11:12

ForEveR