2 #include <openssl/bio.h>
3 #include <openssl/pem.h>
6 char* get_cert_valid_before(const char* cert_string, int cert_string_len, char* datebuf, int len)
10 BIO* cert_bio = BIO_new_mem_buf(cert_string, cert_string_len);
12 if (cert_bio == NULL) {
13 return "Error calling PEM_new_mem_buf!";
16 X509 *x = PEM_read_bio_X509(cert_bio, NULL, 0, NULL);
18 return "Error calling PEM_read_bio_X509!";
21 BIO* out_bio = BIO_new(BIO_s_mem());
22 ASN1_TIME* time = X509_get_notAfter(x);
24 if (ASN1_TIME_print(out_bio, time)) {
25 int write = BIO_read(out_bio, datebuf, len - 1);
29 datebuf[len - 1] = '\0';