Skip to content

Commit 533e9b0

Browse files
authored
Merge pull request #9995 from julek-wolfssl/zd/21341
Handle OCSP_WANT_READ returned from DoTls13HandShakeMsgType
2 parents be7bf60 + 0644369 commit 533e9b0

5 files changed

Lines changed: 102 additions & 5 deletions

File tree

.github/workflows/os-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
'--enable-all CPPFLAGS=''-DNO_WOLFSSL_SERVER -DWOLFSSL_NO_CLIENT_AUTH''',
9292
'--enable-curve25519=nonblock --enable-ecc=nonblock --enable-sp=yes,nonblock CPPFLAGS="-DWOLFSSL_PUBLIC_MP -DWOLFSSL_DEBUG_NONBLOCK"',
9393
'--enable-certreq --enable-certext --enable-certgen --disable-secure-renegotiation-info CPPFLAGS="-DNO_TLS"',
94-
'--enable-ocsp --enable-ocsp-responder --enable-ocspstapling',
94+
'--enable-ocsp --enable-ocsp-responder --enable-ocspstapling CPPFLAGS="-DWOLFSSL_NONBLOCK_OCSP" --enable-maxfragment',
9595
]
9696
name: make check
9797
if: github.repository_owner == 'wolfssl'

src/tls13.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13453,8 +13453,9 @@ int DoTls13HandShakeMsg(WOLFSSL* ssl, byte* input, word32* inOutIdx,
1345313453
&idx, ssl->arrays->pendingMsgType,
1345413454
ssl->arrays->pendingMsgSz - HANDSHAKE_HEADER_SZ,
1345513455
ssl->arrays->pendingMsgSz);
13456-
#ifdef WOLFSSL_ASYNC_CRYPT
13457-
if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
13456+
#if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLFSSL_NONBLOCK_OCSP)
13457+
if (ret == WC_NO_ERR_TRACE(WC_PENDING_E) ||
13458+
ret == WC_NO_ERR_TRACE(OCSP_WANT_READ)) {
1345813459
/* setup to process fragment again */
1345913460
ssl->arrays->pendingMsgOffset -= inputLength;
1346013461
*inOutIdx -= inputLength + ssl->keys.padSz;

tests/api.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4872,7 +4872,8 @@ int test_ssl_memio_do_handshake(test_ssl_memio_ctx* ctx, int max_rounds,
48724872
/* retry non-blocking math */
48734873
}
48744874
else if (err != WOLFSSL_ERROR_WANT_READ &&
4875-
err != WOLFSSL_ERROR_WANT_WRITE) {
4875+
err != WOLFSSL_ERROR_WANT_WRITE &&
4876+
err != WC_NO_ERR_TRACE(OCSP_WANT_READ)) {
48764877
char buff[WOLFSSL_MAX_ERROR_SZ];
48774878
fprintf(stderr, "error = %d, %s\n", err,
48784879
wolfSSL_ERR_error_string((word32)err, buff));
@@ -4897,7 +4898,8 @@ int test_ssl_memio_do_handshake(test_ssl_memio_ctx* ctx, int max_rounds,
48974898
/* retry non-blocking math */
48984899
}
48994900
else if (err != WOLFSSL_ERROR_WANT_READ &&
4900-
err != WOLFSSL_ERROR_WANT_WRITE) {
4901+
err != WOLFSSL_ERROR_WANT_WRITE &&
4902+
err != WC_NO_ERR_TRACE(OCSP_WANT_READ)) {
49014903
char buff[WOLFSSL_MAX_ERROR_SZ];
49024904
fprintf(stderr, "error = %d, %s\n", err,
49034905
wolfSSL_ERR_error_string((word32)err, buff));
@@ -34588,6 +34590,7 @@ TEST_CASE testCases[] = {
3458834590
TEST_DECL(test_ocsp_tls_cert_cb),
3458934591
TEST_DECL(test_ocsp_cert_unknown_crl_fallback),
3459034592
TEST_DECL(test_ocsp_cert_unknown_crl_fallback_nonleaf),
34593+
TEST_DECL(test_tls13_nonblock_ocsp_low_mfl),
3459134594
TEST_DECL(test_ocsp_responder),
3459234595
TEST_TLS_DECLS,
3459334596
TEST_DECL(test_wc_DhSetNamedKey),

tests/api/test_ocsp.c

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,98 @@ int test_ocsp_cert_unknown_crl_fallback_nonleaf(void)
12411241
}
12421242
#endif /* HAVE_OCSP && HAVE_CRL && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
12431243

1244+
#if defined(HAVE_OCSP) && defined(WOLFSSL_TLS13) && \
1245+
defined(WOLFSSL_NONBLOCK_OCSP) && defined(HAVE_MAX_FRAGMENT) && \
1246+
defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
1247+
!defined(NO_RSA) && !defined(NO_SHA)
1248+
1249+
/* Number of times the OCSP IO callback has been called. */
1250+
static int test_tls13_nonblock_ocsp_mfl_cb_cnt;
1251+
1252+
/*
1253+
* OCSP IO callback: simulates a nonblocking responder. Returns WANT_READ
1254+
* a few times before finally returning the OCSP response.
1255+
*/
1256+
static int test_tls13_nonblock_ocsp_mfl_io_cb(void* ioCtx, const char* url,
1257+
int urlSz, unsigned char* req, int reqSz, unsigned char** respBuf)
1258+
{
1259+
(void)ioCtx;
1260+
(void)url;
1261+
(void)urlSz;
1262+
(void)req;
1263+
(void)reqSz;
1264+
1265+
if (test_tls13_nonblock_ocsp_mfl_cb_cnt++ < 5)
1266+
return WOLFSSL_CBIO_ERR_WANT_READ;
1267+
1268+
*respBuf = (unsigned char*)resp_server1_cert;
1269+
return (int)sizeof(resp_server1_cert);
1270+
}
1271+
1272+
/* CTX-ready callback: enable client-side OCSP with URL override. */
1273+
static int test_tls13_nonblock_ocsp_mfl_ctx_ready(WOLFSSL_CTX* ctx)
1274+
{
1275+
EXPECT_DECLS;
1276+
ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx,
1277+
WOLFSSL_OCSP_URL_OVERRIDE | WOLFSSL_OCSP_NO_NONCE),
1278+
WOLFSSL_SUCCESS);
1279+
ExpectIntEQ(wolfSSL_CTX_SetOCSP_OverrideURL(ctx, "http://example.com"),
1280+
WOLFSSL_SUCCESS);
1281+
/* NULL free-callback: resp points to static array, must not be freed. */
1282+
ExpectIntEQ(wolfSSL_CTX_SetOCSP_Cb(ctx,
1283+
test_tls13_nonblock_ocsp_mfl_io_cb, NULL, NULL),
1284+
WOLFSSL_SUCCESS);
1285+
return EXPECT_RESULT();
1286+
}
1287+
1288+
/* SSL-ready callback: cap record payload at 1024 bytes. */
1289+
static int test_tls13_nonblock_ocsp_mfl_ssl_ready(WOLFSSL* ssl)
1290+
{
1291+
EXPECT_DECLS;
1292+
ExpectIntEQ(wolfSSL_UseMaxFragment(ssl, WOLFSSL_MFL_2_10), WOLFSSL_SUCCESS);
1293+
return EXPECT_RESULT();
1294+
}
1295+
1296+
int test_tls13_nonblock_ocsp_low_mfl(void)
1297+
{
1298+
EXPECT_DECLS;
1299+
struct test_ssl_memio_ctx test_ctx;
1300+
1301+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
1302+
test_tls13_nonblock_ocsp_mfl_cb_cnt = 0;
1303+
1304+
/*
1305+
* Server: two-cert chain (server1 + intermediate1, no root).
1306+
* Total DER size ~2534 bytes -> splits into 3 TLS records at MFL=1024.
1307+
*/
1308+
test_ctx.s_cb.certPemFile = "./certs/ocsp/server1-chain-noroot.pem";
1309+
test_ctx.s_cb.keyPemFile = "./certs/ocsp/server1-key.pem";
1310+
test_ctx.s_cb.method = wolfTLSv1_3_server_method;
1311+
1312+
/* Client: trust root-ca, TLS 1.3, OCSP + MFL=1024. */
1313+
test_ctx.c_cb.caPemFile = "./certs/ocsp/root-ca-cert.pem";
1314+
test_ctx.c_cb.method = wolfTLSv1_3_client_method;
1315+
test_ctx.c_cb.ctx_ready = test_tls13_nonblock_ocsp_mfl_ctx_ready;
1316+
test_ctx.c_cb.ssl_ready = test_tls13_nonblock_ocsp_mfl_ssl_ready;
1317+
1318+
ExpectIntEQ(test_ssl_memio_setup(&test_ctx), TEST_SUCCESS);
1319+
ExpectIntEQ(test_ssl_memio_do_handshake(&test_ctx, 10, NULL),
1320+
TEST_SUCCESS);
1321+
1322+
/* The OCSP callback must have been retried (called more than once). */
1323+
ExpectIntGT(test_tls13_nonblock_ocsp_mfl_cb_cnt, 1);
1324+
1325+
test_ssl_memio_cleanup(&test_ctx);
1326+
return EXPECT_RESULT();
1327+
}
1328+
1329+
#else
1330+
int test_tls13_nonblock_ocsp_low_mfl(void)
1331+
{
1332+
return TEST_SKIPPED;
1333+
}
1334+
#endif
1335+
12441336
#if defined(HAVE_OCSP_RESPONDER) && defined(WOLFSSL_ASN_TEMPLATE) && \
12451337
!defined(NO_SHA) && !defined(NO_RSA)
12461338
/* Structure to hold test configuration */

tests/api/test_ocsp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ int test_ocsp_response_parsing(void);
2929
int test_ocsp_tls_cert_cb(void);
3030
int test_ocsp_cert_unknown_crl_fallback(void);
3131
int test_ocsp_cert_unknown_crl_fallback_nonleaf(void);
32+
int test_tls13_nonblock_ocsp_low_mfl(void);
3233
int test_ocsp_responder(void);
3334
#endif /* WOLFSSL_TEST_OCSP_H */
3435

0 commit comments

Comments
 (0)