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.
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;
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With