diff --git a/examples/client/client.c b/examples/client/client.c index cb79a84c8..362f4c8e5 100644 --- a/examples/client/client.c +++ b/examples/client/client.c @@ -3007,6 +3007,16 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args) showPeerEx(ssl, lng_index); +#ifdef HAVE_OCSP + { + struct tm tm; + char date[32]; + ret = wolfSSL_get_ocsp_producedDate(ssl, &tm); + if ((ret == 0) && (strftime(date, sizeof date, "%Y-%m-%d %H:%M:%S %z",&tm) > 0)) + printf("OCSP response timestamp: %s\n",date); + } +#endif + #ifdef OPENSSL_EXTRA printf("Session timeout set to %ld seconds\n", wolfSSL_get_timeout(ssl)); { diff --git a/src/internal.c b/src/internal.c index 9122c43d2..526e94f37 100644 --- a/src/internal.c +++ b/src/internal.c @@ -9857,6 +9857,11 @@ static int ProcessCSR(WOLFSSL* ssl, byte* input, word32* inOutIdx, else if (response->status->status != CERT_GOOD) ret = BAD_CERTIFICATE_STATUS_ERROR; + else { + XMEMCPY(ssl->ocspProducedDate, response->producedDate, sizeof ssl->ocspProducedDate); + ssl->ocspProducedDateFormat = response->producedDateFormat; + } + *inOutIdx += status_length; #ifdef WOLFSSL_SMALL_STACK diff --git a/src/ssl.c b/src/ssl.c index 70574db35..e394c8879 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -44134,6 +44134,24 @@ int wolfSSL_set_ocsp_url(WOLFSSL* ssl, char* url) #endif /* OCSP */ #endif /* OPENSSL_ALL || WOLFSSL_NGINX || WOLFSSL_HAPROXY */ +#ifdef HAVE_OCSP +int wolfSSL_get_ocsp_producedDate(WOLFSSL *ssl, struct tm *producedTime) { + int idx = 0; + + if ((producedTime == NULL) || (ssl->ocspProducedDate == NULL)) + return BAD_FUNC_ARG; + if ((ssl->ocspProducedDateFormat != ASN_UTC_TIME) && + (ssl->ocspProducedDateFormat != ASN_GENERALIZED_TIME)) + return BAD_FUNC_ARG; + + if (ExtractDate(ssl->ocspProducedDate, ssl->ocspProducedDateFormat, producedTime, &idx)) + return 0; + else + return ASN_PARSE_E; +} +#endif + + #if defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \ defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL) int wolfSSL_CTX_get_extra_chain_certs(WOLFSSL_CTX* ctx, WOLF_STACK_OF(X509)** chain) diff --git a/wolfssl/internal.h b/wolfssl/internal.h index c3829fe14..dd9dc36bc 100644 --- a/wolfssl/internal.h +++ b/wolfssl/internal.h @@ -4167,6 +4167,8 @@ struct WOLFSSL { #endif /* HAVE_TLS_EXTENSIONS */ #ifdef HAVE_OCSP void* ocspIOCtx; + byte ocspProducedDate[MAX_DATE_SZ]; + int ocspProducedDateFormat; #ifdef OPENSSL_EXTRA byte* ocspResp; int ocspRespSz; diff --git a/wolfssl/ssl.h b/wolfssl/ssl.h index 9122a783f..2eb91ec85 100644 --- a/wolfssl/ssl.h +++ b/wolfssl/ssl.h @@ -3791,6 +3791,10 @@ WOLFSSL_API int wolfSSL_CTX_set_tlsext_ticket_key_cb(WOLFSSL_CTX *, int (*)( WOLFSSL_EVP_CIPHER_CTX *ectx, WOLFSSL_HMAC_CTX *hctx, int enc)); #endif +#ifdef HAVE_OCSP + WOLFSSL_API int wolfSSL_get_ocsp_producedDate(WOLFSSL *ssl, struct tm *producedTime); +#endif + #if defined(HAVE_OCSP) || defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL) || \ defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) WOLFSSL_API int wolfSSL_CTX_get_extra_chain_certs(WOLFSSL_CTX* ctx,