@@ -141,3 +141,116 @@ int test_tls13_unexpected_ccs(void)
141141#endif
142142 return EXPECT_RESULT ();
143143}
144+ int test_tls12_curve_intersection (void ) {
145+ EXPECT_DECLS ;
146+ #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES ) && \
147+ !defined(WOLFSSL_NO_TLS12 ) && defined(HAVE_ECC ) && \
148+ defined(HAVE_CURVE25519 )
149+ WOLFSSL_CTX * ctx_c = NULL , * ctx_s = NULL ;
150+ WOLFSSL * ssl_c = NULL , * ssl_s = NULL ;
151+ struct test_memio_ctx test_ctx ;
152+ int ret ;
153+ const char * curve_name ;
154+ int test1 [] = {WOLFSSL_ECC_SECP256R1 };
155+ int test2 [] = {WOLFSSL_ECC_SECP384R1 };
156+ int test3 [] = {WOLFSSL_ECC_SECP256R1 , WOLFSSL_ECC_SECP384R1 };
157+ int test4 [] = {WOLFSSL_ECC_SECP384R1 , WOLFSSL_ECC_SECP256R1 };
158+ XMEMSET (& test_ctx , 0 , sizeof (test_ctx ));
159+ ExpectIntEQ (test_memio_setup (& test_ctx , & ctx_c , & ctx_s , & ssl_c , & ssl_s ,
160+ wolfTLSv1_2_client_method , wolfTLSv1_2_server_method ), 0 );
161+ ExpectIntEQ (wolfSSL_set_groups (ssl_c ,
162+ test1 , 1 ), WOLFSSL_SUCCESS );
163+ ExpectIntEQ (test_memio_do_handshake (ssl_c , ssl_s , 10 , NULL ), 0 );
164+
165+ /* Fix: Get curve name and compare with string comparison or use curve
166+ * ID function */
167+ curve_name = wolfSSL_get_curve_name (ssl_s );
168+ /* or use appropriate string comparison */
169+ ExpectStrEQ (curve_name , "SECP256R1" );
170+ curve_name = wolfSSL_get_curve_name (ssl_c );
171+ ExpectStrEQ (curve_name , "SECP256R1" );
172+
173+ wolfSSL_free (ssl_c );
174+ wolfSSL_free (ssl_s );
175+ wolfSSL_CTX_free (ctx_c );
176+ wolfSSL_CTX_free (ctx_s );
177+ ssl_c = NULL ;
178+ ssl_s = NULL ;
179+ ctx_c = NULL ;
180+ ctx_s = NULL ;
181+
182+ XMEMSET (& test_ctx , 0 , sizeof (test_ctx ));
183+ ExpectIntEQ (test_memio_setup (& test_ctx , & ctx_c , & ctx_s , & ssl_c , & ssl_s ,
184+ wolfTLSv1_2_client_method , wolfTLSv1_2_server_method ), 0 );
185+ ExpectIntEQ (wolfSSL_set_groups (ssl_c ,
186+ test2 , 1 ), WOLFSSL_SUCCESS );
187+ ExpectIntEQ (wolfSSL_set_groups (ssl_s ,
188+ test1 , 1 ), WOLFSSL_SUCCESS );
189+ ExpectIntNE (test_memio_do_handshake (ssl_c , ssl_s , 10 , NULL ), 0 );
190+ ret = wolfSSL_get_error (ssl_s , WOLFSSL_FATAL_ERROR );
191+
192+ /* Fix: Use proper constant or define HANDSHAKE_FAILURE */
193+ ExpectTrue (ret == WC_NO_ERR_TRACE (ECC_CURVE_ERROR ));
194+
195+ wolfSSL_free (ssl_c );
196+ wolfSSL_free (ssl_s );
197+ wolfSSL_CTX_free (ctx_c );
198+ wolfSSL_CTX_free (ctx_s );
199+ ssl_c = NULL ;
200+ ssl_s = NULL ;
201+ ctx_c = NULL ;
202+ ctx_s = NULL ;
203+
204+ XMEMSET (& test_ctx , 0 , sizeof (test_ctx ));
205+ ExpectIntEQ (test_memio_setup (& test_ctx , & ctx_c , & ctx_s , & ssl_c , & ssl_s ,
206+ wolfTLSv1_2_client_method , wolfTLSv1_2_server_method ), 0 );
207+ ExpectIntEQ (wolfSSL_set_groups (ssl_c ,
208+ test3 , 2 ),
209+ WOLFSSL_SUCCESS );
210+ ExpectIntEQ (wolfSSL_set_groups (ssl_s ,
211+ test4 , 2 ),
212+ WOLFSSL_SUCCESS );
213+ ExpectIntEQ (test_memio_do_handshake (ssl_c , ssl_s , 10 , NULL ), 0 );
214+
215+ curve_name = wolfSSL_get_curve_name (ssl_s );
216+ ExpectStrEQ (curve_name , "SECP256R1" );
217+ curve_name = wolfSSL_get_curve_name (ssl_c );
218+ ExpectStrEQ (curve_name , "SECP256R1" );
219+
220+ wolfSSL_free (ssl_c );
221+ wolfSSL_free (ssl_s );
222+ wolfSSL_CTX_free (ctx_c );
223+ wolfSSL_CTX_free (ctx_s );
224+ #endif
225+ return EXPECT_RESULT ();
226+ }
227+
228+ int test_tls13_curve_intersection (void ) {
229+ EXPECT_DECLS ;
230+ #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES ) && \
231+ defined(WOLFSSL_TLS13 ) && defined(HAVE_ECC ) && defined(HAVE_CURVE25519 )
232+ WOLFSSL_CTX * ctx_c = NULL , * ctx_s = NULL ;
233+ WOLFSSL * ssl_c = NULL , * ssl_s = NULL ;
234+ struct test_memio_ctx test_ctx ;
235+ const char * curve_name ;
236+ int test1 [] = {WOLFSSL_ECC_SECP256R1 };
237+
238+ XMEMSET (& test_ctx , 0 , sizeof (test_ctx ));
239+ ExpectIntEQ (test_memio_setup (& test_ctx , & ctx_c , & ctx_s , & ssl_c , & ssl_s ,
240+ wolfTLSv1_3_client_method , wolfTLSv1_3_server_method ), 0 );
241+ ExpectIntEQ (wolfSSL_set_groups (ssl_c ,
242+ test1 , 1 ), WOLFSSL_SUCCESS );
243+ ExpectIntEQ (test_memio_do_handshake (ssl_c , ssl_s , 10 , NULL ), 0 );
244+
245+ curve_name = wolfSSL_get_curve_name (ssl_s );
246+ ExpectStrEQ (curve_name , "SECP256R1" );
247+ curve_name = wolfSSL_get_curve_name (ssl_c );
248+ ExpectStrEQ (curve_name , "SECP256R1" );
249+
250+ wolfSSL_free (ssl_c );
251+ wolfSSL_free (ssl_s );
252+ wolfSSL_CTX_free (ctx_c );
253+ wolfSSL_CTX_free (ctx_s );
254+ #endif
255+ return EXPECT_RESULT ();
256+ }
0 commit comments