Skip to content

Commit 268326d

Browse files
authored
Merge pull request wolfSSL#8408 from rizlik/ocsp-resp-refactor
OpenSSL Compat Layer: OCSP response improvments
2 parents 597b839 + 7db3c34 commit 268326d

File tree

19 files changed

+3014
-382
lines changed

19 files changed

+3014
-382
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,6 +2510,7 @@ if(WOLFSSL_EXAMPLES)
25102510
tests/api/test_ripemd.c
25112511
tests/api/test_hash.c
25122512
tests/api/test_ascon.c
2513+
tests/api/test_ocsp.c
25132514
tests/hash.c
25142515
tests/srp.c
25152516
tests/suites.c

certs/ocsp/include.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ EXTRA_DIST += \
3636
certs/ocsp/test-response.der \
3737
certs/ocsp/test-response-rsapss.der \
3838
certs/ocsp/test-response-nointern.der \
39-
certs/ocsp/test-multi-response.der
39+
certs/ocsp/test-multi-response.der \
40+
certs/ocsp/test-leaf-response.der

certs/ocsp/renewcerts.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ openssl ocsp -issuer ./root-ca-cert.pem -cert ./intermediate1-ca-cert.pem -cert
100100
kill $PID
101101
wait $PID
102102

103+
# Create a response DER buffer for testing leaf certificate
104+
openssl ocsp -port 22221 -ndays 1000 -index \
105+
./index-intermediate1-ca-issued-certs.txt -rsigner ocsp-responder-cert.pem \
106+
-rkey ocsp-responder-key.pem -CA intermediate1-ca-cert.pem -partial_chain &
107+
PID=$!
108+
sleep 1 # Make sure server is ready
109+
110+
openssl ocsp -issuer ./intermediate1-ca-cert.pem -cert ./server1-cert.pem -url http://localhost:22221/ -respout test-leaf-response.der -noverify
111+
kill $PID
112+
wait $PID
103113

104114
# now start up a responder that signs using rsa-pss
105115
openssl ocsp -port 22221 -ndays 1000 -index index-ca-and-intermediate-cas.txt -rsigner ocsp-responder-cert.pem -rkey ocsp-responder-key.pem -CA root-ca-cert.pem -rsigopt rsa_padding_mode:pss &

certs/ocsp/test-leaf-response.der

1.82 KB
Binary file not shown.

configure.ac

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9163,7 +9163,6 @@ then
91639163
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_PRIORITIZE_PSK"
91649164
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_CHECK_ALERT_ON_ERR"
91659165
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_TICKET_HAVE_ID"
9166-
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_NO_OCSP_ISSUER_CHECK"
91679166
ENABLED_TRUSTED_PEER_CERT=yes
91689167
else
91699168
CFLAGS=$(printf "%s" "$CFLAGS" | sed 's/-DOPENSSL_COMPATIBLE_DEFAULTS//g')

src/internal.c

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8690,6 +8690,13 @@ void wolfSSL_ResourceFree(WOLFSSL* ssl)
86908690
#ifdef OPENSSL_EXTRA
86918691
XFREE(ssl->param, ssl->heap, DYNAMIC_TYPE_OPENSSL);
86928692
#endif
8693+
#if defined(HAVE_OCSP) && (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY))
8694+
if (ssl->ocspResp) {
8695+
XFREE(ssl->ocspResp, NULL, 0);
8696+
ssl->ocspResp = NULL;
8697+
ssl->ocspRespSz = 0;
8698+
}
8699+
#endif /* defined(HAVE_OCSP) && (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)) */
86938700
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
86948701
while (ssl->certReqCtx != NULL) {
86958702
CertReqCtx* curr = ssl->certReqCtx;
@@ -9014,6 +9021,14 @@ void FreeHandshakeResources(WOLFSSL* ssl)
90149021
* !WOLFSSL_POST_HANDSHAKE_AUTH */
90159022
#endif /* HAVE_TLS_EXTENSIONS && !NO_TLS */
90169023

9024+
#if defined(HAVE_OCSP) && (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY))
9025+
if (ssl->ocspResp != NULL) {
9026+
XFREE(ssl->ocspResp, NULL, 0);
9027+
ssl->ocspResp = NULL;
9028+
ssl->ocspRespSz = 0;
9029+
}
9030+
#endif /* defined(HAVE_OCSP) && (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)) */
9031+
90179032
#ifdef WOLFSSL_STATIC_MEMORY
90189033
/* when done with handshake decrement current handshake count */
90199034
if (ssl->heap != NULL) {
@@ -13861,7 +13876,7 @@ static int ProcessCSR_ex(WOLFSSL* ssl, byte* input, word32* inOutIdx,
1386113876
/* InitOcspResponse sets single and status to response struct. */
1386213877
InitOcspResponse(response, single, status, input +*inOutIdx, status_length, ssl->heap);
1386313878

13864-
if (OcspResponseDecode(response, SSL_CM(ssl), ssl->heap, 0) != 0)
13879+
if (OcspResponseDecode(response, SSL_CM(ssl), ssl->heap, 0, 0) != 0)
1386513880
ret = BAD_CERTIFICATE_STATUS_ERROR;
1386613881
else if (CompareOcspReqResp(request, response) != 0)
1386713882
ret = BAD_CERTIFICATE_STATUS_ERROR;
@@ -16967,7 +16982,7 @@ static int DoCertificateStatus(WOLFSSL* ssl, byte* input, word32* inOutIdx,
1696716982
status_length, ssl->heap);
1696816983
response->pendingCAs = pendingCAs;
1696916984
if ((OcspResponseDecode(response, SSL_CM(ssl), ssl->heap,
16970-
0) != 0)
16985+
0, 0) != 0)
1697116986
|| (response->responseStatus != OCSP_SUCCESSFUL)
1697216987
|| (response->single->status->status != CERT_GOOD))
1697316988
ret = BAD_CERTIFICATE_STATUS_ERROR;
@@ -24099,7 +24114,7 @@ int CreateOcspRequest(WOLFSSL* ssl, OcspRequest* request,
2409924114
ret = InitOcspRequest(request, cert, 0, ssl->heap);
2410024115
if (ret == 0) {
2410124116
/* make sure ctx OCSP request is updated */
24102-
if (!ssl->buffers.weOwnCert) {
24117+
if (!ssl->buffers.weOwnCert && SSL_CM(ssl) != NULL) {
2410324118
wolfSSL_Mutex* ocspLock = &SSL_CM(ssl)->ocsp_stapling->ocspLock;
2410424119
if (wc_LockMutex(ocspLock) == 0) {
2410524120
if (ssl->ctx->certOcspRequest == NULL) {
@@ -24840,6 +24855,49 @@ static int BuildCertificateStatus(WOLFSSL* ssl, byte type, buffer* status,
2484024855
return ret;
2484124856
}
2484224857
#endif
24858+
24859+
#if defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \
24860+
(defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
24861+
defined(WOLFSSL_HAPROXY))
24862+
static int BuildCertificateStatusWithStatusCB(WOLFSSL* ssl)
24863+
{
24864+
WOLFSSL_OCSP *ocsp;
24865+
void *ioCtx = NULL;
24866+
buffer response;
24867+
int ret;
24868+
24869+
ocsp = SSL_CM(ssl)->ocsp_stapling;
24870+
if (ocsp == NULL || ocsp->statusCb == NULL)
24871+
return BAD_FUNC_ARG;
24872+
ioCtx = (ssl && ssl->ocspIOCtx != NULL) ?
24873+
ssl->ocspIOCtx : ocsp->cm->ocspIOCtx;
24874+
XMEMSET(&response, 0, sizeof(response));
24875+
WOLFSSL_MSG("Calling ocsp->statusCb");
24876+
ret = ocsp->statusCb(ssl, ioCtx);
24877+
switch (ret) {
24878+
case SSL_TLSEXT_ERR_OK:
24879+
if (ssl->ocspResp == NULL || ssl->ocspRespSz == 0) {
24880+
ret = 0;
24881+
break;
24882+
}
24883+
response.buffer = ssl->ocspResp;
24884+
response.length = ssl->ocspRespSz;
24885+
ret = BuildCertificateStatus(ssl, WOLFSSL_CSR_OCSP, &response, 1);
24886+
break;
24887+
case SSL_TLSEXT_ERR_NOACK:
24888+
/* No OCSP response to send */
24889+
ret = 0;
24890+
break;
24891+
case SSL_TLSEXT_ERR_ALERT_FATAL:
24892+
/* fall through */
24893+
default:
24894+
ret = WOLFSSL_FATAL_ERROR;
24895+
break;
24896+
}
24897+
return ret;
24898+
}
24899+
#endif /* HAVE_CERTIFICATE_STATUS_REQUEST && (defined(OPENSSL_ALL) ||
24900+
defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)) */
2484324901
#endif /* NO_WOLFSSL_SERVER */
2484424902

2484524903
/* handle generation of certificate_status (22) */
@@ -24860,6 +24918,20 @@ int SendCertificateStatus(WOLFSSL* ssl)
2486024918
#ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2
2486124919
status_type = status_type ? status_type : ssl->status_request_v2;
2486224920
#endif
24921+
if (ssl == NULL || SSL_CM(ssl) == NULL) {
24922+
WOLFSSL_MSG("SendCertificateStatus bad args");
24923+
return BAD_FUNC_ARG;
24924+
}
24925+
24926+
#if defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \
24927+
(defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
24928+
defined(WOLFSSL_HAPROXY))
24929+
if (SSL_CM(ssl)->ocsp_stapling != NULL &&
24930+
SSL_CM(ssl)->ocsp_stapling->statusCb != NULL) {
24931+
if (ssl->status_request == WOLFSSL_CSR_OCSP)
24932+
return BuildCertificateStatusWithStatusCB(ssl);
24933+
}
24934+
#endif
2486324935

2486424936
switch (status_type) {
2486524937

0 commit comments

Comments
 (0)