@@ -609,3 +609,54 @@ int test_TLSX_SNI_GetSize_overflow(void)
609609#endif
610610 return EXPECT_RESULT ();
611611}
612+
613+ /* ECH is only valid in ClientHello, EncryptedExtensions, or
614+ * HelloRetryRequest per RFC 9460. Feeding it in a Certificate message must
615+ * be rejected with EXT_NOT_ALLOWED rather than being silently accepted. */
616+ int test_TLSX_ECH_msg_type_validation (void )
617+ {
618+ EXPECT_DECLS ;
619+ #if defined(WOLFSSL_TLS13 ) && defined(HAVE_ECH ) && \
620+ !defined(NO_WOLFSSL_CLIENT ) && !defined(NO_TLS )
621+ WOLFSSL_CTX * ctx = NULL ;
622+ WOLFSSL * ssl = NULL ;
623+ /* type = TLSX_ECH (0xfe0d), size = 0x0000 */
624+ const byte extBytes [] = { 0xfe , 0x0d , 0x00 , 0x00 };
625+
626+ ExpectNotNull (ctx = wolfSSL_CTX_new (wolfTLSv1_3_client_method ()));
627+ ExpectNotNull (ssl = wolfSSL_new (ctx ));
628+
629+ ExpectIntEQ (TLSX_Parse (ssl , extBytes , (word16 )sizeof (extBytes ),
630+ certificate , NULL ),
631+ WC_NO_ERR_TRACE (EXT_NOT_ALLOWED ));
632+
633+ wolfSSL_free (ssl );
634+ wolfSSL_CTX_free (ctx );
635+ #endif
636+ return EXPECT_RESULT ();
637+ }
638+
639+ /* use_srtp is only valid in ClientHello/ServerHello (pre-TLS 1.3) or
640+ * ClientHello/EncryptedExtensions (TLS 1.3) per RFC 5764. Feeding it in a
641+ * Certificate message must be rejected with EXT_NOT_ALLOWED. */
642+ int test_TLSX_SRTP_msg_type_validation (void )
643+ {
644+ EXPECT_DECLS ;
645+ #if defined(WOLFSSL_SRTP ) && !defined(NO_WOLFSSL_CLIENT ) && !defined(NO_TLS )
646+ WOLFSSL_CTX * ctx = NULL ;
647+ WOLFSSL * ssl = NULL ;
648+ /* type = TLSX_USE_SRTP (0x000e), size = 0x0000 */
649+ const byte extBytes [] = { 0x00 , 0x0e , 0x00 , 0x00 };
650+
651+ ExpectNotNull (ctx = wolfSSL_CTX_new (wolfSSLv23_client_method ()));
652+ ExpectNotNull (ssl = wolfSSL_new (ctx ));
653+
654+ ExpectIntEQ (TLSX_Parse (ssl , extBytes , (word16 )sizeof (extBytes ),
655+ certificate , NULL ),
656+ WC_NO_ERR_TRACE (EXT_NOT_ALLOWED ));
657+
658+ wolfSSL_free (ssl );
659+ wolfSSL_CTX_free (ctx );
660+ #endif
661+ return EXPECT_RESULT ();
662+ }
0 commit comments