@@ -69,6 +69,16 @@ static int dummy_set_encryption_secrets(WOLFSSL *ssl, WOLFSSL_ENCRYPTION_LEVEL l
6969 return 1 ;
7070}
7171
72+ static int dummy_set_encryption_secrets_fail (WOLFSSL * ssl , WOLFSSL_ENCRYPTION_LEVEL level ,
73+ const uint8_t * read_secret ,
74+ const uint8_t * write_secret , size_t secret_len )
75+ {
76+ (void )ssl ;
77+ printf ("QUIC_set_encryption_secrets(level=%d, length=%d, rx=%s, tx=%s)\n" ,
78+ level , (int )secret_len , read_secret ? "yes" : "no" , write_secret ? "yes" : "no" );
79+ return 0 ;
80+ }
81+
7282static int dummy_add_handshake_data (WOLFSSL * ssl , WOLFSSL_ENCRYPTION_LEVEL level ,
7383 const uint8_t * data , size_t len )
7484{
@@ -446,6 +456,13 @@ static WOLFSSL_QUIC_METHOD ctx_method = {
446456 ctx_send_alert ,
447457};
448458
459+ static WOLFSSL_QUIC_METHOD ctx_method_fail = {
460+ dummy_set_encryption_secrets_fail ,
461+ ctx_add_handshake_data ,
462+ ctx_flush_flight ,
463+ ctx_send_alert ,
464+ };
465+
449466static void QuicTestContext_init (QuicTestContext * tctx , WOLFSSL_CTX * ctx ,
450467 const char * name , int verbose )
451468{
@@ -472,6 +489,36 @@ static void QuicTestContext_init(QuicTestContext *tctx, WOLFSSL_CTX *ctx,
472489 wolfSSL_set_quic_transport_version (tctx -> ssl , 0 );
473490 wolfSSL_set_quic_transport_params (tctx -> ssl , tp_params_c , sizeof (tp_params_c ));
474491 }
492+ (void )ctx_method ;
493+ }
494+
495+ static void QuicTestContext_init_fail_cb (QuicTestContext * tctx , WOLFSSL_CTX * ctx ,
496+ const char * name , int verbose )
497+ {
498+ static const byte tp_params_c [] = {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 };
499+ static const byte tp_params_s [] = {7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 , 1 };
500+
501+ AssertNotNull (tctx );
502+ memset (tctx , 0 , sizeof (* tctx ));
503+ tctx -> name = name ;
504+ AssertNotNull ((tctx -> ssl = wolfSSL_new (ctx )));
505+ tctx -> verbose = verbose ;
506+ wolfSSL_set_app_data (tctx -> ssl , tctx );
507+ AssertTrue (wolfSSL_set_quic_method (tctx -> ssl , & ctx_method_fail ) == WOLFSSL_SUCCESS );
508+ wolfSSL_set_verify (tctx -> ssl , SSL_VERIFY_NONE , 0 );
509+ #ifdef HAVE_SESSION_TICKET
510+ wolfSSL_UseSessionTicket (tctx -> ssl );
511+ wolfSSL_set_SessionTicket_cb (tctx -> ssl , ctx_session_ticket_cb , NULL );
512+ #endif
513+ if (wolfSSL_is_server (tctx -> ssl )) {
514+ wolfSSL_set_quic_transport_version (tctx -> ssl , 0 );
515+ wolfSSL_set_quic_transport_params (tctx -> ssl , tp_params_s , sizeof (tp_params_s ));
516+ }
517+ else {
518+ wolfSSL_set_quic_transport_version (tctx -> ssl , 0 );
519+ wolfSSL_set_quic_transport_params (tctx -> ssl , tp_params_c , sizeof (tp_params_c ));
520+ }
521+ (void )ctx_method ;
475522}
476523
477524static void QuicTestContext_free (QuicTestContext * tctx )
@@ -1193,6 +1240,50 @@ static int test_quic_server_hello(int verbose) {
11931240 return ret ;
11941241}
11951242
1243+ static int test_quic_server_hello_fail (int verbose ) {
1244+ WOLFSSL_CTX * ctx_c , * ctx_s ;
1245+ int ret = 0 ;
1246+ QuicTestContext tclient , tserver ;
1247+ QuicConversation conv ;
1248+
1249+ AssertNotNull (ctx_c = wolfSSL_CTX_new (wolfTLSv1_3_client_method ()));
1250+ AssertNotNull (ctx_s = wolfSSL_CTX_new (wolfTLSv1_3_server_method ()));
1251+ AssertTrue (wolfSSL_CTX_use_certificate_file (ctx_s , svrCertFile , WOLFSSL_FILETYPE_PEM ));
1252+ AssertTrue (wolfSSL_CTX_use_PrivateKey_file (ctx_s , svrKeyFile , WOLFSSL_FILETYPE_PEM ));
1253+
1254+ /* setup ssls */
1255+ QuicTestContext_init_fail_cb (& tclient , ctx_c , "client" , verbose );
1256+ QuicTestContext_init (& tserver , ctx_s , "server" , verbose );
1257+
1258+ /* connect */
1259+ QuicConversation_init (& conv , & tclient , & tserver );
1260+ QuicConversation_step (& conv , 0 );
1261+ /* check established/missing secrets */
1262+ check_secrets (& tserver , wolfssl_encryption_initial , 0 , 0 );
1263+ check_secrets (& tserver , wolfssl_encryption_handshake ,
1264+ DEFAULT_TLS_DIGEST_SZ , DEFAULT_TLS_DIGEST_SZ );
1265+ check_secrets (& tserver , wolfssl_encryption_application ,
1266+ DEFAULT_TLS_DIGEST_SZ , DEFAULT_TLS_DIGEST_SZ );
1267+ check_secrets (& tclient , wolfssl_encryption_handshake , 0 , 0 );
1268+ /* feed the server data to the client. This is when the cb will fail */
1269+ QuicConversation_step (& conv , 1 );
1270+ /* confirm failure to generate secrets */
1271+ {
1272+ int idx = (int )wolfssl_encryption_handshake ;
1273+ AssertTrue (idx < 4 );
1274+ AssertIntEQ (tclient .rx_secret_len [idx ], 0 );
1275+ AssertIntEQ (tclient .tx_secret_len [idx ], 0 );
1276+ }
1277+ QuicTestContext_free (& tclient );
1278+ QuicTestContext_free (& tserver );
1279+
1280+ wolfSSL_CTX_free (ctx_c );
1281+ wolfSSL_CTX_free (ctx_s );
1282+ printf (" test_quic_server_hello_fail: %s\n" , (ret == 0 )? passed : failed );
1283+
1284+ return ret ;
1285+ }
1286+
11961287/* This has gotten a bit out of hand. */
11971288#if (defined(OPENSSL_ALL ) || (defined(OPENSSL_EXTRA ) && \
11981289 (defined(HAVE_STUNNEL ) || defined(WOLFSSL_NGINX ) || \
@@ -1653,6 +1744,7 @@ int QuicTest(void)
16531744 if ((ret = test_quic_crypt ()) != 0 ) goto leave ;
16541745 if ((ret = test_quic_client_hello (verbose )) != 0 ) goto leave ;
16551746 if ((ret = test_quic_server_hello (verbose )) != 0 ) goto leave ;
1747+ if ((ret = test_quic_server_hello_fail (verbose )) != 0 ) goto leave ;
16561748#ifdef REALLY_HAVE_ALPN_AND_SNI
16571749 if ((ret = test_quic_alpn (verbose )) != 0 ) goto leave ;
16581750#endif /* REALLY_HAVE_ALPN_AND_SNI */
0 commit comments