@@ -3148,6 +3148,75 @@ int test_tls13_warning_alert_is_fatal(void)
31483148 return EXPECT_RESULT ();
31493149}
31503150
3151+ /* Test that an unknown extension in a TLS 1.3 server-to-client message is
3152+ * rejected with unsupported_extension (RFC 8446 §4.2). The client MUST abort
3153+ * the handshake when it receives an extension it did not advertise.
3154+ */
3155+ int test_tls13_unknown_ext_rejected (void )
3156+ {
3157+ EXPECT_DECLS ;
3158+ #if defined(WOLFSSL_TLS13 ) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES ) && \
3159+ !defined(NO_WOLFSSL_CLIENT ) && defined(WOLFSSL_AES_128 ) && \
3160+ defined(HAVE_AESGCM ) && !defined(NO_SHA256 ) && \
3161+ !defined(WOLFSSL_TLS13_MIDDLEBOX_COMPAT )
3162+ WOLFSSL_CTX * ctx_c = NULL ;
3163+ WOLFSSL * ssl_c = NULL ;
3164+ struct test_memio_ctx test_ctx ;
3165+ /* HelloRetryRequest carrying TLS_AES_128_GCM_SHA256, supported_versions
3166+ * (TLS 1.3), and an extra unknown extension type 0xFABC.
3167+ *
3168+ * The base HRR (from test_tls13_same_ch) extended with 4 bytes:
3169+ * extensions length: 6 → 10 (0x00,0x0a)
3170+ * handshake body length: 46 → 50 (0x00,0x00,0x32)
3171+ * record body length: 50 → 54 (0x00,0x36)
3172+ * appended: 0xfa,0xbc,0x00,0x00 (unknown type, zero-length value)
3173+ */
3174+ static const unsigned char hrr_unknown_ext [] = {
3175+ /* TLS record header: handshake, TLS 1.2 compat, len=54 */
3176+ 0x16 , 0x03 , 0x03 , 0x00 , 0x36 ,
3177+ /* Handshake header: ServerHello, len=50 */
3178+ 0x02 , 0x00 , 0x00 , 0x32 ,
3179+ /* legacy_version: TLS 1.2 */
3180+ 0x03 , 0x03 ,
3181+ /* HelloRetryRequest magic random */
3182+ 0xcf , 0x21 , 0xad , 0x74 , 0xe5 , 0x9a , 0x61 , 0x11 ,
3183+ 0xbe , 0x1d , 0x8c , 0x02 , 0x1e , 0x65 , 0xb8 , 0x91 ,
3184+ 0xc2 , 0xa2 , 0x11 , 0x16 , 0x7a , 0xbb , 0x8c , 0x5e ,
3185+ 0x07 , 0x9e , 0x09 , 0xe2 , 0xc8 , 0xa8 , 0x33 , 0x9c ,
3186+ /* session ID length: 0 */
3187+ 0x00 ,
3188+ /* cipher suite: TLS_AES_128_GCM_SHA256 */
3189+ 0x13 , 0x01 ,
3190+ /* compression: null */
3191+ 0x00 ,
3192+ /* extensions length: 10 */
3193+ 0x00 , 0x0a ,
3194+ /* supported_versions: TLS 1.3 (0x0304) */
3195+ 0x00 , 0x2b , 0x00 , 0x02 , 0x03 , 0x04 ,
3196+ /* unknown extension type 0xFABC, zero-length value */
3197+ 0xfa , 0xbc , 0x00 , 0x00
3198+ };
3199+
3200+ XMEMSET (& test_ctx , 0 , sizeof (test_ctx ));
3201+ ExpectIntEQ (test_memio_setup (& test_ctx , & ctx_c , NULL , & ssl_c , NULL ,
3202+ wolfTLSv1_3_client_method , NULL ), 0 );
3203+
3204+ /* Inject the crafted HRR before the client starts the handshake.
3205+ * wolfSSL_connect will send the ClientHello and then read this message. */
3206+ ExpectIntEQ (test_memio_inject_message (& test_ctx , 1 ,
3207+ (const char * )hrr_unknown_ext , sizeof (hrr_unknown_ext )), 0 );
3208+
3209+ /* RFC 8446 §4.2: the client MUST abort with unsupported_extension. */
3210+ ExpectIntEQ (wolfSSL_connect (ssl_c ), -1 );
3211+ ExpectIntEQ (wolfSSL_get_error (ssl_c , -1 ),
3212+ WC_NO_ERR_TRACE (UNSUPPORTED_EXTENSION ));
3213+
3214+ wolfSSL_free (ssl_c );
3215+ wolfSSL_CTX_free (ctx_c );
3216+ #endif
3217+ return EXPECT_RESULT ();
3218+ }
3219+
31513220/* Test that wolfSSL_set1_sigalgs_list() is honored in TLS 1.3
31523221 */
31533222int test_tls13_cert_req_sigalgs (void )
0 commit comments