@@ -982,3 +982,54 @@ int test_TLSX_SNI_GetSize_overflow(void)
982982#endif
983983 return EXPECT_RESULT ();
984984}
985+
986+ /* ECH is only valid in ClientHello, EncryptedExtensions, or
987+ * HelloRetryRequest per RFC 9460. Feeding it in a Finished message must
988+ * be rejected with EXT_NOT_ALLOWED rather than being silently accepted. */
989+ int test_TLSX_ECH_msg_type_validation (void )
990+ {
991+ EXPECT_DECLS ;
992+ #if defined(WOLFSSL_TLS13 ) && defined(HAVE_ECH ) && \
993+ !defined(NO_WOLFSSL_CLIENT ) && !defined(NO_TLS )
994+ WOLFSSL_CTX * ctx = NULL ;
995+ WOLFSSL * ssl = NULL ;
996+ /* type = TLSX_ECH (0xfe0d), size = 0x0000 */
997+ const byte extBytes [] = { 0xfe , 0x0d , 0x00 , 0x00 };
998+
999+ ExpectNotNull (ctx = wolfSSL_CTX_new (wolfTLSv1_3_client_method ()));
1000+ ExpectNotNull (ssl = wolfSSL_new (ctx ));
1001+
1002+ ExpectIntEQ (TLSX_Parse (ssl , extBytes , (word16 )sizeof (extBytes ),
1003+ finished , NULL ),
1004+ WC_NO_ERR_TRACE (EXT_NOT_ALLOWED ));
1005+
1006+ wolfSSL_free (ssl );
1007+ wolfSSL_CTX_free (ctx );
1008+ #endif
1009+ return EXPECT_RESULT ();
1010+ }
1011+
1012+ /* use_srtp is only valid in ClientHello/ServerHello (pre-TLS 1.3) or
1013+ * ClientHello/EncryptedExtensions (TLS 1.3) per RFC 5764. Feeding it in a
1014+ * Finished message must be rejected with EXT_NOT_ALLOWED. */
1015+ int test_TLSX_SRTP_msg_type_validation (void )
1016+ {
1017+ EXPECT_DECLS ;
1018+ #if defined(WOLFSSL_SRTP ) && !defined(NO_WOLFSSL_CLIENT ) && !defined(NO_TLS )
1019+ WOLFSSL_CTX * ctx = NULL ;
1020+ WOLFSSL * ssl = NULL ;
1021+ /* type = TLSX_USE_SRTP (0x000e), size = 0x0000 */
1022+ const byte extBytes [] = { 0x00 , 0x0e , 0x00 , 0x00 };
1023+
1024+ ExpectNotNull (ctx = wolfSSL_CTX_new (wolfSSLv23_client_method ()));
1025+ ExpectNotNull (ssl = wolfSSL_new (ctx ));
1026+
1027+ ExpectIntEQ (TLSX_Parse (ssl , extBytes , (word16 )sizeof (extBytes ),
1028+ finished , NULL ),
1029+ WC_NO_ERR_TRACE (EXT_NOT_ALLOWED ));
1030+
1031+ wolfSSL_free (ssl );
1032+ wolfSSL_CTX_free (ctx );
1033+ #endif
1034+ return EXPECT_RESULT ();
1035+ }
0 commit comments