mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 15:17:01 +02:00
MINOR: ssl: add notBefore and notAfter utility functions
Extracting notBefore and notAfter as a string can be bothersome, add 2 utility functions that returns the value in a static buffer.
This commit is contained in:
parent
c3ee4e375b
commit
5454824e31
@ -45,6 +45,8 @@ void exclude_tls_grease(char *input, int len, struct buffer *output);
|
||||
int x509_v_err_str_to_int(const char *str);
|
||||
const char *x509_v_err_int_to_str(int code);
|
||||
long asn1_generalizedtime_to_epoch(ASN1_GENERALIZEDTIME *d);
|
||||
const char *x509_get_notbefore(X509 *cert);
|
||||
const char *x509_get_notafter(X509 *cert);
|
||||
|
||||
#endif /* _HAPROXY_SSL_UTILS_H */
|
||||
#endif /* USE_OPENSSL */
|
||||
|
@ -700,3 +700,56 @@ long asn1_generalizedtime_to_epoch(ASN1_GENERALIZEDTIME *d)
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Return the nofAfter value as as string extracted from an X509 certificate
|
||||
* The returned buffer is static and thread local.
|
||||
*/
|
||||
const char *x509_get_notafter(X509 *cert)
|
||||
{
|
||||
BIO *bio = NULL;
|
||||
int write;
|
||||
static THREAD_LOCAL char buf[256];
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
if ((bio = BIO_new(BIO_s_mem())) == NULL)
|
||||
goto end;
|
||||
if (ASN1_TIME_print(bio, X509_getm_notAfter(cert)) == 0)
|
||||
goto end;
|
||||
write = BIO_read(bio, buf, sizeof(buf)-1);
|
||||
buf[write] = '\0';
|
||||
BIO_free(bio);
|
||||
|
||||
return buf;
|
||||
|
||||
end:
|
||||
BIO_free(bio);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Return the nofBefore value as as string extracted from an X509 certificate
|
||||
* The returned buffer is static and thread local.
|
||||
*/
|
||||
const char *x509_get_notbefore(X509 *cert)
|
||||
{
|
||||
BIO *bio = NULL;
|
||||
int write;
|
||||
static THREAD_LOCAL char buf[256];
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
if ((bio = BIO_new(BIO_s_mem())) == NULL)
|
||||
goto end;
|
||||
if (ASN1_TIME_print(bio, X509_getm_notBefore(cert)) == 0)
|
||||
goto end;
|
||||
write = BIO_read(bio, buf, sizeof(buf)-1);
|
||||
buf[write] = '\0';
|
||||
BIO_free(bio);
|
||||
|
||||
return buf;
|
||||
|
||||
end:
|
||||
BIO_free(bio);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user