Skip to content

Commit 0530847

Browse files
committed
Use OCSP verify callback for both 1.2 and 1.3
- Modify test to use the same callbacks for both 1.2 and 1.3 - Remove 1.3 staple accessor
1 parent cad35f6 commit 0530847

6 files changed

Lines changed: 34 additions & 90 deletions

File tree

doc/dox_comments/header_files/ssl.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5559,19 +5559,7 @@ int wolfSSL_set_tlsext_status_ocsp_resp_multi(WOLFSSL* ssl, unsigned char *resp,
55595559
/*!
55605560
\ingroup OCSP
55615561
5562-
\brief Gets the OCSP status response for a specific certificate in TLS 1.3.
5563-
5564-
\param ssl The WOLFSSL session.
5565-
\param idx Index of the certificate chain.
5566-
5567-
\return Pointer to WOLFSSL_BUFFER_INFO containing the response, or NULL on error.
5568-
*/
5569-
WOLFSSL_BUFFER_INFO* wolfSSL_GetTls13OcspStatusResp(const WOLFSSL* ssl, word32 idx);
5570-
5571-
/*!
5572-
\ingroup OCSP
5573-
5574-
\brief Sets a callback to verify the OCSP status response for TLS 1.2.
5562+
\brief Sets a callback to verify the OCSP status response.
55755563
55765564
This callback is only useful when SESSION_CERTS is enabled.
55775565
@@ -5584,10 +5572,10 @@ WOLFSSL_BUFFER_INFO* wolfSSL_GetTls13OcspStatusResp(const WOLFSSL* ssl, word32 i
55845572
_Example_
55855573
\code
55865574
void my_ocsp_verify_cb(WOLFSSL* ssl, int err, byte* resp, word32 respSz, word32 idx, void* arg) { ... }
5587-
wolfSSL_CTX_set_tls12_ocsp_status_verify_cb(ctx, my_ocsp_verify_cb, NULL);
5575+
wolfSSL_CTX_set_ocsp_status_verify_cb(ctx, my_ocsp_verify_cb, NULL);
55885576
\endcode
55895577
*/
5590-
void wolfSSL_CTX_set_tls12_ocsp_status_verify_cb(WOLFSSL_CTX* ctx, ocspVerifyStatusCb cb, void* cbArg);
5578+
void wolfSSL_CTX_set_ocsp_status_verify_cb(WOLFSSL_CTX* ctx, ocspVerifyStatusCb cb, void* cbArg);
55915579

55925580
/*!
55935581
\ingroup Setup

src/internal.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15683,14 +15683,17 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx,
1568315683
#endif
1568415684
}
1568515685

15686-
if (ret == 0) {
1568715686
#ifdef HAVE_OCSP
15687+
{
15688+
/* If we are processing OCSP staples then always
15689+
* initialize the corresponding request. */
15690+
int ocspRet = 0;
1568815691
#ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2
1568915692
addToPendingCAs = 0;
1569015693
if (ssl->options.side == WOLFSSL_CLIENT_END &&
1569115694
ssl->status_request_v2 &&
1569215695
TLSX_CSR2_IsMulti(ssl->extensions)) {
15693-
ret = TLSX_CSR2_InitRequests(ssl->extensions,
15696+
ocspRet = TLSX_CSR2_InitRequests(ssl->extensions,
1569415697
args->dCert, 0, ssl->heap);
1569515698
addToPendingCAs = 1;
1569615699
}
@@ -15704,12 +15707,12 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx,
1570415707
* Server. Server side will check client
1570515708
* certificates by traditional OCSP if enabled
1570615709
*/
15707-
ret = TLSX_CSR_InitRequest_ex(ssl->extensions,
15710+
ocspRet = TLSX_CSR_InitRequest_ex(ssl->extensions,
1570815711
args->dCert, ssl->heap, args->certIdx);
1570915712
}
1571015713
else
1571115714
#endif
15712-
if (SSL_CM(ssl)->ocspEnabled &&
15715+
if (ret == 0 && SSL_CM(ssl)->ocspEnabled &&
1571315716
SSL_CM(ssl)->ocspCheckAll) {
1571415717
WOLFSSL_MSG("Doing Non Leaf OCSP check");
1571515718
ret = CheckCertOCSP_ex(SSL_CM(ssl)->ocsp,
@@ -15725,8 +15728,15 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx,
1572515728
WOLFSSL_MSG("\tOCSP Lookup not ok");
1572615729
}
1572715730
}
15731+
if (ocspRet != 0) {
15732+
ret = ocspRet;
15733+
WOLFSSL_ERROR_VERBOSE(ret);
15734+
goto exit_ppc;
15735+
}
15736+
}
1572815737
#endif /* HAVE_OCSP */
1572915738

15739+
if (ret == 0) {
1573015740
#ifdef HAVE_CRL
1573115741
if (SSL_CM(ssl)->crlEnabled &&
1573215742
SSL_CM(ssl)->crlCheckAll) {
@@ -16035,6 +16045,12 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx,
1603516045
if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
1603616046
goto exit_ppc;
1603716047
#endif
16048+
16049+
/* Do verify callback. Don't call it on error as the callback
16050+
* will still be called later. */
16051+
if (ret != 0)
16052+
ret = DoVerifyCallback(SSL_CM(ssl), ssl, ret, args);
16053+
1603816054
if (ret == 0) {
1603916055
WOLFSSL_MSG("Verified Peer's cert");
1604016056
#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
@@ -16126,28 +16142,20 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx,
1612616142
}
1612716143
#endif
1612816144

16129-
if (ssl->verifyCallback) {
16130-
WOLFSSL_MSG(
16131-
"\tCallback override available, will continue");
16132-
/* check if fatal error */
16133-
args->fatal = (args->verifyErr) ? (word16)(1)
16134-
: (word16)(0);
16135-
if (args->fatal)
16136-
DoCertFatalAlert(ssl, ret);
16137-
}
1613816145
#if defined(__APPLE__) && defined(WOLFSSL_SYS_CA_CERTS)
1613916146
/* Disregard failure to verify peer cert, as we will verify
1614016147
* the whole chain with the native API later */
16141-
else if (ssl->ctx->doAppleNativeCertValidationFlag) {
16148+
if (ssl->ctx->doAppleNativeCertValidationFlag) {
1614216149
WOLFSSL_MSG("\tApple native CA validation override"
1614316150
" available, will continue");
1614416151
/* check if fatal error */
1614516152
args->fatal = (args->verifyErr) ? 1 : 0;
1614616153
if (args->fatal)
1614716154
DoCertFatalAlert(ssl, ret);
1614816155
}
16156+
else
1614916157
#endif/*defined(__APPLE__)&& defined(WOLFSSL_SYS_CA_CERTS)*/
16150-
else {
16158+
{
1615116159
WOLFSSL_MSG("\tNo callback override available, fatal");
1615216160
args->fatal = 1;
1615316161
DoCertFatalAlert(ssl, ret);

src/ssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23045,7 +23045,7 @@ int wolfSSL_set_tlsext_status_ocsp_resp_multi(WOLFSSL* ssl, unsigned char *resp,
2304523045
return WOLFSSL_SUCCESS;
2304623046
}
2304723047

23048-
void wolfSSL_CTX_set_tls12_ocsp_status_verify_cb(WOLFSSL_CTX* ctx,
23048+
void wolfSSL_CTX_set_ocsp_status_verify_cb(WOLFSSL_CTX* ctx,
2304923049
ocspVerifyStatusCb cb, void* cbArg)
2305023050
{
2305123051
if (ctx != NULL) {

src/tls13.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8745,26 +8745,6 @@ static int SetupOcspResp(WOLFSSL* ssl)
87458745
#endif
87468746
return ret;
87478747
}
8748-
8749-
WOLFSSL_BUFFER_INFO* wolfSSL_GetTls13OcspStatusResp(const WOLFSSL* ssl,
8750-
word32 idx)
8751-
{
8752-
TLSX* extension = NULL;
8753-
CertificateStatusRequest* csr = NULL;
8754-
8755-
WOLFSSL_ENTER("wolfSSL_GetTls13OcspStatusResp");
8756-
8757-
if (ssl == NULL || !IsAtLeastTLSv1_3(ssl->version) ||
8758-
idx >= MAX_CERT_EXTENSIONS)
8759-
return NULL;
8760-
8761-
extension = TLSX_Find(ssl->extensions, TLSX_STATUS_REQUEST);
8762-
csr = extension ? (CertificateStatusRequest*)extension->data : NULL;
8763-
if (csr == NULL)
8764-
return NULL;
8765-
8766-
return &csr->responses[idx];
8767-
}
87688748
#endif
87698749

87708750
/* handle generation TLS v1.3 certificate (11) */

tests/api/test_ocsp.c

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,8 @@ int test_ocsp_certid_enc_dec(void)
662662
#if defined(HAVE_OCSP) && defined(WOLFSSL_CERT_SETUP_CB) && \
663663
defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && !defined(NO_RSA) && \
664664
(defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \
665-
defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2))
665+
defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)) && \
666+
defined(SESSION_CERTS)
666667

667668
static struct {
668669
size_t chainLen;
@@ -792,15 +793,9 @@ static int test_ocsp_tls_cert_cb_verify_cb(int preverify,
792793
#endif
793794
) {
794795
WOLFSSL_BUFFER_INFO* bInfo = &store->certs[idx];
795-
#if defined(WOLFSSL_TLS13) && defined(HAVE_CERTIFICATE_STATUS_REQUEST)
796-
WOLFSSL* ssl = (WOLFSSL*)store->userCtx;
797-
WOLFSSL_BUFFER_INFO* ocspStaple =
798-
wolfSSL_GetTls13OcspStatusResp(ssl, (word32)idx);
799-
#endif
800796
WOLFSSL_CERT_MANAGER* cm = NULL;
801797
DecodedCert cert;
802798
byte certInit = 0;
803-
WOLFSSL_OCSP* ocsp = NULL;
804799

805800
ret = 1;
806801
cm = wolfSSL_CertManagerNew();
@@ -824,24 +819,6 @@ static int test_ocsp_tls_cert_cb_verify_cb(int preverify,
824819
if (ret == 1 && wc_ParseCert(&cert, CERT_TYPE, VERIFY, cm) != 0)
825820
ret = 0;
826821

827-
#if defined(WOLFSSL_TLS13) && defined(HAVE_CERTIFICATE_STATUS_REQUEST)
828-
/* In this test we only expect a staple on the leaf cert */
829-
if (wolfSSL_version(ssl) == TLS1_3_VERSION ||
830-
wolfSSL_version(ssl) == DTLS1_3_VERSION) {
831-
/* Verify OCSP with CA */
832-
if (ret == 1 && (ocspStaple == NULL || ocspStaple->buffer == NULL ||
833-
ocspStaple->length == 0))
834-
ret = 0;
835-
if (ret == 1 && (ocsp = wc_NewOCSP(cm)) == NULL)
836-
ret = 0;
837-
if (ret == 1 &&
838-
wc_CheckCertOcspResponse(ocsp, &cert, ocspStaple->buffer,
839-
ocspStaple->length, NULL) != 0)
840-
ret = 0;
841-
}
842-
#endif
843-
844-
wc_FreeOCSP(ocsp);
845822
if (certInit)
846823
wc_FreeDecodedCert(&cert);
847824
wolfSSL_CertManagerFree(cm);
@@ -850,7 +827,6 @@ static int test_ocsp_tls_cert_cb_verify_cb(int preverify,
850827
return ret;
851828
}
852829

853-
#ifdef SESSION_CERTS
854830
static int test_ocsp_tls_cert_cb_ocsp_verify_cb(WOLFSSL* ssl, int err,
855831
byte* staple, word32 stapleSz, word32 idx, void* arg)
856832
{
@@ -899,7 +875,6 @@ static int test_ocsp_tls_cert_cb_ocsp_verify_cb(WOLFSSL* ssl, int err,
899875
}
900876
return err;
901877
}
902-
#endif
903878

904879
static int test_ocsp_tls_cert_cb_ctx_ready(WOLFSSL_CTX* ctx)
905880
{
@@ -931,7 +906,7 @@ int test_ocsp_tls_cert_cb(void)
931906
byte useV2multi:1;
932907
byte maxFail:2;
933908
} params[] = {
934-
#if !defined(WOLFSSL_NO_TLS12) && defined(SESSION_CERTS)
909+
#if !defined(WOLFSSL_NO_TLS12)
935910
{ wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2", 0, 0, 1 },
936911
{ wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2", 1, 0, 1 },
937912
{ wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2", 1, 1, 1 },
@@ -1000,13 +975,9 @@ int test_ocsp_tls_cert_cb(void)
1000975
/* client: request stapling */
1001976
wolfSSL_set_verify(test_ctx.c_ssl, WOLFSSL_VERIFY_DEFAULT,
1002977
test_ocsp_tls_cert_cb_verify_cb);
1003-
#ifdef SESSION_CERTS
1004-
if (wolfSSL_version(test_ctx.c_ssl) == TLS1_2_VERSION ||
1005-
wolfSSL_version(test_ctx.c_ssl) == DTLS1_2_VERSION) {
1006-
wolfSSL_CTX_set_tls12_ocsp_status_verify_cb(test_ctx.c_ctx,
1007-
test_ocsp_tls_cert_cb_ocsp_verify_cb, NULL);
1008-
}
1009-
#endif
978+
wolfSSL_CTX_set_ocsp_status_verify_cb(test_ctx.c_ctx,
979+
test_ocsp_tls_cert_cb_ocsp_verify_cb, NULL);
980+
1010981
/* No way to get ssl from the store without OPENSSL_EXTRA */
1011982
wolfSSL_SetCertCbCtx(test_ctx.c_ssl, test_ctx.c_ssl);
1012983
ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(test_ctx.c_ctx), WOLFSSL_SUCCESS);

wolfssl/ssl.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5657,13 +5657,10 @@ WOLFSSL_API long wolfSSL_get_tlsext_status_ocsp_resp(WOLFSSL *ssl, unsigned char
56575657
WOLFSSL_API long wolfSSL_set_tlsext_status_ocsp_resp(WOLFSSL *ssl, unsigned char *resp, int len);
56585658
WOLFSSL_API int wolfSSL_set_tlsext_status_ocsp_resp_multi(WOLFSSL* ssl, unsigned char *resp,
56595659
int len, word32 idx);
5660-
#ifdef WOLFSSL_TLS13
5661-
WOLFSSL_API WOLFSSL_BUFFER_INFO* wolfSSL_GetTls13OcspStatusResp(const WOLFSSL* ssl, word32 idx);
5662-
#endif
56635660
typedef int(*ocspVerifyStatusCb)(WOLFSSL* ssl, int err, byte* resp, word32 respSz,
56645661
word32 idx, void* arg);
56655662
/* This callback is only useful when SESSION_CERTS is enabled */
5666-
WOLFSSL_API void wolfSSL_CTX_set_tls12_ocsp_status_verify_cb(WOLFSSL_CTX* ctx,
5663+
WOLFSSL_API void wolfSSL_CTX_set_ocsp_status_verify_cb(WOLFSSL_CTX* ctx,
56675664
ocspVerifyStatusCb cb, void* cbArg);
56685665
#endif
56695666

0 commit comments

Comments
 (0)