Prasanth Madhavan
Prasanth Madhavan

Reputation: 13347

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.

Upvotes: 6

Views: 14376

Answers (2)

Raj
Raj

Reputation: 124

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;

Upvotes: 8

ForEveR
ForEveR

Reputation: 55897

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

Upvotes: 7

Related Questions