diff options
author | Jeremy Harris <jgh146exb@wizmail.org> | 2014-05-13 23:50:13 +0100 |
---|---|---|
committer | Jeremy Harris <jgh146exb@wizmail.org> | 2014-05-13 23:50:13 +0100 |
commit | 25ba25448b55c2fd5ea9b1aeed82e02d59816a07 (patch) | |
tree | b0c452f6c205f5788f02cddbc2fc947014701e52 /src | |
parent | 812a604525eef4993d6ed165d455c8309ae72c36 (diff) |
Extractors for certificate time fields support integer output modifier
Diffstat (limited to 'src')
-rw-r--r-- | src/src/tlscert-gnu.c | 21 | ||||
-rw-r--r-- | src/src/tlscert-openssl.c | 23 |
2 files changed, 34 insertions, 10 deletions
diff --git a/src/src/tlscert-gnu.c b/src/src/tlscert-gnu.c index 085e05689..9b9c83d8b 100644 --- a/src/src/tlscert-gnu.c +++ b/src/src/tlscert-gnu.c @@ -84,11 +84,18 @@ return NULL; static uschar * -time_copy(time_t t) +time_copy(time_t t, uschar * mod) { -uschar * cp = store_get(32); -struct tm * tp = gmtime(&t); -size_t len = strftime(CS cp, 32, "%b %e %T %Y %Z", tp); +uschar * cp; +struct tm * tp; +size_t len; + +if (mod && Ustrcmp(mod, "int") == 0) + return string_sprintf("%u", (unsigned)t); + +cp = store_get(32); +tp = gmtime(&t); +len = strftime(CS cp, 32, "%b %e %T %Y %Z", tp); return len > 0 ? cp : NULL; } @@ -116,14 +123,16 @@ uschar * tls_cert_not_after(void * cert, uschar * mod) { return time_copy( - gnutls_x509_crt_get_expiration_time((gnutls_x509_crt_t)cert)); + gnutls_x509_crt_get_expiration_time((gnutls_x509_crt_t)cert), + mod); } uschar * tls_cert_not_before(void * cert, uschar * mod) { return time_copy( - gnutls_x509_crt_get_activation_time((gnutls_x509_crt_t)cert)); + gnutls_x509_crt_get_activation_time((gnutls_x509_crt_t)cert), + mod); } uschar * diff --git a/src/src/tlscert-openssl.c b/src/src/tlscert-openssl.c index 00a3cb555..29095782a 100644 --- a/src/src/tlscert-openssl.c +++ b/src/src/tlscert-openssl.c @@ -89,11 +89,26 @@ return cp; } static uschar * -asn1_time_copy(const ASN1_TIME * time) +bio_string_time_to_int(BIO * bp, int len) +{ +uschar * cp = US""; +struct tm t; +len = len > 0 ? (int) BIO_get_mem_data(bp, &cp) : 0; +/*XXX %Z might be glibc-specific? */ +(void) strptime(CS cp, "%b%t%e%t%T%t%Y%t%Z", &t); +BIO_free(bp); +/*XXX timegm might not be portable? */ +return string_sprintf("%u", (unsigned) timegm(&t)); +} + +static uschar * +asn1_time_copy(const ASN1_TIME * time, uschar * mod) { BIO * bp = BIO_new(BIO_s_mem()); int len = ASN1_TIME_print(bp, time); -return bio_string_copy(bp, len); +return mod && Ustrcmp(mod, "int") == 0 + ? bio_string_time_to_int(bp, len) + : bio_string_copy(bp, len); } static uschar * @@ -118,13 +133,13 @@ return mod ? tls_field_from_dn(cp, mod) : cp; uschar * tls_cert_not_before(void * cert, uschar * mod) { -return asn1_time_copy(X509_get_notBefore((X509 *)cert)); +return asn1_time_copy(X509_get_notBefore((X509 *)cert), mod); } uschar * tls_cert_not_after(void * cert, uschar * mod) { -return asn1_time_copy(X509_get_notAfter((X509 *)cert)); +return asn1_time_copy(X509_get_notAfter((X509 *)cert), mod); } uschar * |