MINOR: ssl: add function to extract X509 notBefore date in time_t

Add x509_get_notbefore_time_t() which returns the notBefore date in
time_t format.
This commit is contained in:
William Lallemand 2025-05-02 14:42:28 +02:00
parent 8a4b3216f9
commit 626de9538e
2 changed files with 16 additions and 0 deletions

View File

@ -50,6 +50,7 @@ const char *x509_get_notafter(X509 *cert);
#ifdef HAVE_ASN1_TIME_TO_TM
time_t ASN1_to_time_t(ASN1_TIME *asn1_time);
time_t x509_get_notafter_time_t(X509 *cert);
time_t x509_get_notbefore_time_t(X509 *cert);
#endif
int curves2nid(const char *curve);
const char *nid2nist(int nid);

View File

@ -779,6 +779,21 @@ time_t x509_get_notafter_time_t(X509 *cert)
ret = ASN1_to_time_t(asn1_time);
error:
return ret;
}
/* return the notBefore date of a X509 certificate in a time_t format */
time_t x509_get_notbefore_time_t(X509 *cert)
{
time_t ret = -1;
ASN1_TIME *asn1_time;
if ((asn1_time = X509_getm_notBefore(cert)) == NULL)
goto error;
ret = ASN1_to_time_t(asn1_time);
error:
return ret;
}