@@ -1033,3 +1033,41 @@ int test_TLSX_SRTP_msg_type_validation(void)
10331033#endif
10341034 return EXPECT_RESULT ();
10351035}
1036+
1037+ /* RFC 7301 Section 3.1: the server's ProtocolNameList in its ALPN response
1038+ * MUST contain exactly one ProtocolName. A ServerHello carrying two entries
1039+ * must be rejected rather than silently accepted. */
1040+ int test_TLSX_ALPN_server_response_count (void )
1041+ {
1042+ EXPECT_DECLS ;
1043+ #if defined(HAVE_ALPN ) && !defined(NO_WOLFSSL_CLIENT ) && !defined(NO_TLS ) && \
1044+ !defined(WOLFSSL_NO_TLS12 )
1045+ WOLFSSL_CTX * ctx = NULL ;
1046+ WOLFSSL * ssl = NULL ;
1047+ /* ServerHello-style ALPN extension whose ProtocolNameList contains
1048+ * two entries ("h2" and "http/1.1"). */
1049+ static const byte extBytes [] = {
1050+ 0x00 , 0x10 , /* extension type = ALPN (16) */
1051+ 0x00 , 0x0E , /* extension length = 14 */
1052+ 0x00 , 0x0C , /* ProtocolNameList length */
1053+ 0x02 , 'h' , '2' , /* entry 1: "h2" */
1054+ 0x08 , 'h' , 't' , 't' , 'p' , '/' , '1' , '.' , '1' /* entry 2 */
1055+ };
1056+ static char alpn_h2 [] = "h2" ;
1057+
1058+ ExpectNotNull (ctx = wolfSSL_CTX_new (wolfTLSv1_2_client_method ()));
1059+ ExpectNotNull (ssl = wolfSSL_new (ctx ));
1060+
1061+ ExpectIntEQ (wolfSSL_UseALPN (ssl , alpn_h2 , (unsigned int )XSTRLEN (alpn_h2 ),
1062+ WOLFSSL_ALPN_FAILED_ON_MISMATCH ),
1063+ WOLFSSL_SUCCESS );
1064+
1065+ ExpectIntEQ (TLSX_Parse (ssl , extBytes , (word16 )sizeof (extBytes ),
1066+ server_hello , NULL ),
1067+ WC_NO_ERR_TRACE (BUFFER_ERROR ));
1068+
1069+ wolfSSL_free (ssl );
1070+ wolfSSL_CTX_free (ctx );
1071+ #endif
1072+ return EXPECT_RESULT ();
1073+ }
0 commit comments