@@ -768,3 +768,75 @@ int test_tls_set_curves_list_ecc_fallback(void)
768768 return EXPECT_RESULT ();
769769}
770770
771+ int test_tls_session_id_resume_downgrade (void )
772+ {
773+ EXPECT_DECLS ;
774+ #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES ) && \
775+ !defined(WOLFSSL_NO_TLS12 ) && !defined(NO_SESSION_CACHE )
776+ struct {
777+ method_provider client_meth_v12 ;
778+ method_provider server_meth ;
779+ method_provider client_meth ;
780+ int expected_version ;
781+ } params [] = {
782+ #ifdef WOLFSSL_TLS13
783+ /* TLS 1.2 client → server, then client resumes at 1.2 */
784+ { wolfTLSv1_2_client_method , wolfTLS_server_method ,
785+ wolfTLS_client_method , TLS1_2_VERSION },
786+ #endif
787+ #if defined(WOLFSSL_DTLS ) && defined (WOLFSSL_DTLS13 )
788+ /* DTLS 1.2 client → server, then client resumes at 1.2 */
789+ { wolfDTLSv1_2_client_method , wolfDTLS_server_method ,
790+ wolfDTLS_client_method , DTLS1_2_VERSION },
791+ #endif
792+ };
793+ size_t i ;
794+
795+ for (i = 0 ; i < sizeof (params )/sizeof (* params ) && !EXPECT_FAIL (); i ++ ) {
796+ struct test_memio_ctx test_ctx ;
797+ WOLFSSL_CTX * ctx_c = NULL , * ctx_s = NULL ;
798+ WOLFSSL * ssl_c = NULL , * ssl_s = NULL ;
799+ WOLFSSL_SESSION * sess = NULL ;
800+
801+ /* --- first connection: v1.2-only client to server --- */
802+ XMEMSET (& test_ctx , 0 , sizeof (test_ctx ));
803+ ExpectIntEQ (test_memio_setup (& test_ctx , & ctx_c , & ctx_s , & ssl_c ,
804+ & ssl_s , params [i ].client_meth_v12 ,
805+ params [i ].server_meth ), 0 );
806+ /* Disable tickets so resumption must use session IDs */
807+ if (EXPECT_SUCCESS ())
808+ wolfSSL_CTX_set_options (ctx_s , WOLFSSL_OP_NO_TICKET );
809+ ExpectIntEQ (test_memio_do_handshake (ssl_c , ssl_s , 10 , NULL ), 0 );
810+ ExpectIntEQ (wolfSSL_version (ssl_c ), params [i ].expected_version );
811+
812+ ExpectNotNull (sess = wolfSSL_get1_session (ssl_c ));
813+ #ifdef HAVE_SESSION_TICKET
814+ ExpectIntEQ (sess -> ticketLen , 0 );
815+ #endif
816+
817+ wolfSSL_free (ssl_c ); ssl_c = NULL ;
818+ wolfSSL_free (ssl_s ); ssl_s = NULL ;
819+ wolfSSL_CTX_free (ctx_c ); ctx_c = NULL ;
820+ /* keep ctx_s so the server session cache is available */
821+
822+ /* --- second connection: client resumes the v1.2 session --- */
823+ XMEMSET (& test_ctx , 0 , sizeof (test_ctx ));
824+ ExpectIntEQ (test_memio_setup (& test_ctx , & ctx_c , & ctx_s , & ssl_c ,
825+ & ssl_s , params [i ].client_meth ,
826+ params [i ].server_meth ), 0 );
827+ ExpectIntEQ (wolfSSL_set_session (ssl_c , sess ), WOLFSSL_SUCCESS );
828+ ExpectIntEQ (test_memio_do_handshake (ssl_c , ssl_s , 10 , NULL ), 0 );
829+
830+ ExpectTrue (wolfSSL_session_reused (ssl_c ));
831+ ExpectIntEQ (wolfSSL_version (ssl_c ), params [i ].expected_version );
832+
833+ wolfSSL_SESSION_free (sess );
834+ wolfSSL_free (ssl_c );
835+ wolfSSL_free (ssl_s );
836+ wolfSSL_CTX_free (ctx_c );
837+ wolfSSL_CTX_free (ctx_s );
838+ }
839+ #endif
840+ return EXPECT_RESULT ();
841+ }
842+
0 commit comments