0

I have a requirement to inform customers that their certificate is going to expire in some days so renew before that time work TLS encryption to work as expected.

How do I retrieve the expiry time of certificates in PEM format?

jww
  • 97,681
  • 90
  • 411
  • 885
user3387347
  • 59
  • 1
  • 6
  • 1
    Possible duplicate of [How to determine SSL cert expiration date from a PEM encoded certificate?](https://stackoverflow.com/questions/21297853/how-to-determine-ssl-cert-expiration-date-from-a-pem-encoded-certificate) – beny23 Jul 04 '17 at 12:48

2 Answers2

1
 #if FROMFILE
 BIO* bio = BIO_new_file(filename, "rb");
 if (bio == null) goto err;
 #else
 BIO* bio = BIO_new(BIO_s_mem());
 BIO_write(bio, data, dataLen);
 #endif

 X509* x509 = PEM_read_bio_X509(bio, NULL, NULL, NULL);
 if (x509 == null) goto err;

 #if OPENSSL_11
 ASN1_TIME* notBefore = X509_get0_notBefore(x509);
 #else
 ASN1_TIME* notBefore = x509->validity->notBefore;
 #endif

 // Choose a time representation and convert the ASN1_TIME to it.

 goto cleanup;

 err:
 // Exercise left to the reader.

 cleanup:
 // Don't free notBefore, since it was obtained via a get0 or interior pointer.
 if (x509) X509_free(x509);
 if (bio) BIO_free(bio);
bartonjs
  • 30,352
  • 2
  • 71
  • 111
0

Copy the content of the PEM certificate to this site and it will display the ssl certificate details including start and expiration dates

https://www.sslshopper.com/certificate-decoder.html

Innocent Anigbo
  • 4,435
  • 1
  • 19
  • 19