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