@@ -3100,6 +3100,53 @@ int test_tls13_plaintext_alert(void)
31003100 return EXPECT_RESULT ();
31013101}
31023102
3103+ /* Test that TLS 1.3 warning-level alerts are treated as fatal (RFC 8446 §6.2).
3104+ * A peer sending e.g. {alert_warning, handshake_failure} must still cause the
3105+ * connection to be terminated, not silently continued.
3106+ */
3107+ int test_tls13_warning_alert_is_fatal (void )
3108+ {
3109+ EXPECT_DECLS ;
3110+ #if defined(WOLFSSL_TLS13 ) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES ) && \
3111+ !defined(NO_WOLFSSL_CLIENT )
3112+ WOLFSSL_CTX * ctx_c = NULL ;
3113+ WOLFSSL * ssl_c = NULL ;
3114+ struct test_memio_ctx test_ctx ;
3115+ WOLFSSL_ALERT_HISTORY h ;
3116+ /* TLS record: content_type=alert(0x15), version=TLS1.2(0x0303), len=2,
3117+ * level=warning(0x01), code=handshake_failure(0x28=40) */
3118+ static const unsigned char warn_alert [] =
3119+ { 0x15 , 0x03 , 0x03 , 0x00 , 0x02 , 0x01 , 0x28 };
3120+
3121+ XMEMSET (& test_ctx , 0 , sizeof (test_ctx ));
3122+ ExpectIntEQ (test_memio_setup (& test_ctx , & ctx_c , NULL , & ssl_c , NULL ,
3123+ wolfTLSv1_3_client_method , NULL ), 0 );
3124+
3125+ /* Client sends ClientHello, then waits for the server response. */
3126+ ExpectIntEQ (wolfSSL_connect (ssl_c ), -1 );
3127+ ExpectIntEQ (wolfSSL_get_error (ssl_c , -1 ), WOLFSSL_ERROR_WANT_READ );
3128+
3129+ /* Inject a warning-level handshake_failure alert as if from the server.
3130+ * RFC 8446 §6.2: In TLS 1.3, all error alerts MUST be treated as fatal
3131+ * regardless of the AlertLevel byte. */
3132+ ExpectIntEQ (test_memio_inject_message (& test_ctx , 1 ,
3133+ (const char * )warn_alert , sizeof (warn_alert )), 0 );
3134+
3135+ /* Expect the connection to be terminated, not silently continued. */
3136+ ExpectIntEQ (wolfSSL_connect (ssl_c ), -1 );
3137+ ExpectIntEQ (wolfSSL_get_error (ssl_c , -1 ), WC_NO_ERR_TRACE (FATAL_ERROR ));
3138+
3139+ /* The alert details should be recorded correctly. */
3140+ ExpectIntEQ (wolfSSL_get_alert_history (ssl_c , & h ), WOLFSSL_SUCCESS );
3141+ ExpectIntEQ (h .last_rx .code , handshake_failure );
3142+ ExpectIntEQ (h .last_rx .level , alert_warning );
3143+
3144+ wolfSSL_free (ssl_c );
3145+ wolfSSL_CTX_free (ctx_c );
3146+ #endif
3147+ return EXPECT_RESULT ();
3148+ }
3149+
31033150/* Test that wolfSSL_set1_sigalgs_list() is honored in TLS 1.3
31043151 */
31053152int test_tls13_cert_req_sigalgs (void )
0 commit comments