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