@@ -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 */
0 commit comments