Openssl C++ get expiry date

c++, openssl, x509certificate

Solution

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;

Problem

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.

Original source

Related problems