@@ -2224,3 +2224,96 @@ int test_tls13_same_ch(void)
22242224#endif
22252225 return EXPECT_RESULT ();
22262226}
2227+
2228+ int test_tls13_hrr_different_cs (void )
2229+ {
2230+ EXPECT_DECLS ;
2231+ #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES ) && \
2232+ defined(WOLFSSL_TLS13 ) && \
2233+ defined(BUILD_TLS_AES_256_GCM_SHA384 ) && \
2234+ defined(BUILD_TLS_CHACHA20_POLY1305_SHA256 ) && \
2235+ defined(HAVE_ECC ) && defined(HAVE_ECC384 )
2236+ /*
2237+ * TLSv1.3 Record Layer: Handshake Protocol: Hello Retry Request
2238+ * Content Type: Handshake (22)
2239+ * Version: TLS 1.2 (0x0303)
2240+ * Length: 56
2241+ * Handshake Protocol: Hello Retry Request
2242+ * Handshake Type: Server Hello (2)
2243+ * Length: 52
2244+ * Version: TLS 1.2 (0x0303)
2245+ * Random: cf21ad74e59a6111be1d8c021e65b891c2a211167abb8c5e079e09e2c8a8339c (HelloRetryRequest magic)
2246+ * Session ID Length: 0
2247+ * Cipher Suite: TLS_AES_256_GCM_SHA384 (0x1302)
2248+ * Compression Method: null (0)
2249+ * Extensions Length: 12
2250+ * Extension: supported_versions (len=2) TLS 1.3
2251+ * Extension: key_share (len=2) secp384r1
2252+ *
2253+ */
2254+ unsigned char hrr [] = {
2255+ 0x16 , 0x03 , 0x03 , 0x00 , 0x38 , 0x02 , 0x00 , 0x00 , 0x34 , 0x03 , 0x03 , 0xcf ,
2256+ 0x21 , 0xad , 0x74 , 0xe5 , 0x9a , 0x61 , 0x11 , 0xbe , 0x1d , 0x8c , 0x02 , 0x1e ,
2257+ 0x65 , 0xb8 , 0x91 , 0xc2 , 0xa2 , 0x11 , 0x16 , 0x7a , 0xbb , 0x8c , 0x5e , 0x07 ,
2258+ 0x9e , 0x09 , 0xe2 , 0xc8 , 0xa8 , 0x33 , 0x9c , 0x00 , 0x13 , 0x02 , 0x00 , 0x00 ,
2259+ 0x0c , 0x00 , 0x2b , 0x00 , 0x02 , 0x03 , 0x04 , 0x00 , 0x33 , 0x00 , 0x02 , 0x00 ,
2260+ 0x18
2261+ };
2262+ /*
2263+ * TLSv1.3 Record Layer: Handshake Protocol: Server Hello
2264+ * Content Type: Handshake (22)
2265+ * Version: TLS 1.2 (0x0303)
2266+ * Length: 155
2267+ * Handshake Protocol: Server Hello
2268+ * Handshake Type: Server Hello (2)
2269+ * Length: 151
2270+ * Version: TLS 1.2 (0x0303)
2271+ * Random: 0101010101010101010101010101010101010101010101010101010101010101
2272+ * Session ID Length: 0
2273+ * Cipher Suite: TLS_CHACHA20_POLY1305_SHA256 (0x1303)
2274+ * Compression Method: null (0)
2275+ * Extensions Length: 111
2276+ * Extension: key_share (len=101) secp384r1
2277+ * Extension: supported_versions (len=2) TLS 1.3
2278+ *
2279+ */
2280+ unsigned char sh [] = {
2281+ 0x16 , 0x03 , 0x03 , 0x00 , 0x9b , 0x02 , 0x00 , 0x00 , 0x97 , 0x03 , 0x03 , 0x01 ,
2282+ 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 ,
2283+ 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 ,
2284+ 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x00 , 0x13 , 0x03 , 0x00 , 0x00 ,
2285+ 0x6f , 0x00 , 0x33 , 0x00 , 0x65 , 0x00 , 0x18 , 0x00 , 0x61 , 0x04 , 0x53 , 0x3e ,
2286+ 0xe5 , 0xbf , 0x40 , 0xec , 0x2d , 0x67 , 0x98 , 0x8b , 0x77 , 0xf3 , 0x17 , 0x48 ,
2287+ 0x9b , 0xb6 , 0xdf , 0x95 , 0x29 , 0x25 , 0xc7 , 0x09 , 0xfc , 0x03 , 0x81 , 0x11 ,
2288+ 0x1a , 0x59 , 0x56 , 0xf2 , 0xd7 , 0x58 , 0x11 , 0x0e , 0x59 , 0xd3 , 0xd7 , 0xc1 ,
2289+ 0x72 , 0x9e , 0x2c , 0x0d , 0x70 , 0xea , 0xf7 , 0x73 , 0xe6 , 0x12 , 0x01 , 0x16 ,
2290+ 0x42 , 0x6d , 0xe2 , 0x43 , 0x6a , 0x2f , 0x5f , 0xdd , 0x7f , 0xe5 , 0x4f , 0xaf ,
2291+ 0x95 , 0x2b , 0x04 , 0xfd , 0x13 , 0xf5 , 0x16 , 0xce , 0x62 , 0x7f , 0x89 , 0xd2 ,
2292+ 0x01 , 0x9d , 0x4c , 0x87 , 0x96 , 0x95 , 0x9e , 0x43 , 0x33 , 0xc7 , 0x06 , 0x5b ,
2293+ 0x49 , 0x6c , 0xa6 , 0x34 , 0xd5 , 0xdc , 0x63 , 0xbd , 0xe9 , 0x1f , 0x00 , 0x2b ,
2294+ 0x00 , 0x02 , 0x03 , 0x04
2295+ };
2296+ WOLFSSL_CTX * ctx_c = NULL ;
2297+ WOLFSSL * ssl_c = NULL ;
2298+ struct test_memio_ctx test_ctx ;
2299+
2300+ XMEMSET (& test_ctx , 0 , sizeof (test_ctx ));
2301+ ExpectIntEQ (test_memio_setup (& test_ctx , & ctx_c , NULL , & ssl_c , NULL ,
2302+ wolfTLSv1_3_client_method , NULL ), 0 );
2303+
2304+ ExpectIntEQ (wolfSSL_connect (ssl_c ), -1 );
2305+ ExpectIntEQ (wolfSSL_get_error (ssl_c , -1 ), WOLFSSL_ERROR_WANT_READ );
2306+ ExpectIntEQ (test_memio_inject_message (& test_ctx , 1 , (char * )hrr ,
2307+ sizeof (hrr )), 0 );
2308+ ExpectIntEQ (wolfSSL_connect (ssl_c ), -1 );
2309+ ExpectIntEQ (wolfSSL_get_error (ssl_c , -1 ), WOLFSSL_ERROR_WANT_READ );
2310+ ExpectIntEQ (test_memio_inject_message (& test_ctx , 1 , (char * )sh ,
2311+ sizeof (sh )), 0 );
2312+ ExpectIntEQ (wolfSSL_connect (ssl_c ), -1 );
2313+ ExpectIntEQ (wolfSSL_get_error (ssl_c , -1 ), INVALID_PARAMETER );
2314+
2315+ wolfSSL_free (ssl_c );
2316+ wolfSSL_CTX_free (ctx_c );
2317+ #endif
2318+ return EXPECT_RESULT ();
2319+ }
0 commit comments