@@ -744,6 +744,92 @@ static void torture_rekey_recv_compression_delayed(void **state)
744744#endif /* WITH_SFTP */
745745#endif /* WITH_ZLIB */
746746
747+ static void setup_server_for_good_guess (void * state )
748+ {
749+ const char * default_sshd_config = "KexAlgorithms curve25519-sha256" ;
750+ const char * fips_sshd_config = "KexAlgorithms ecdh-sha2-nistp256" ;
751+ const char * sshd_config = default_sshd_config ;
752+
753+ if (ssh_fips_mode ()) {
754+ sshd_config = fips_sshd_config ;
755+ }
756+ /* This sets an only supported kex algorithm that we do not have as a first
757+ * option */
758+ torture_update_sshd_config (state , sshd_config );
759+ }
760+
761+ static void torture_rekey_guess_send (void * * state )
762+ {
763+ struct torture_state * s = * state ;
764+
765+ setup_server_for_good_guess (state );
766+
767+ /* Make the client send the first_kex_packet_follows flag during key
768+ * exchange as well as during the rekey */
769+ s -> ssh .session -> send_first_kex_follows = true;
770+
771+ torture_rekey_send (state );
772+ }
773+
774+ static void torture_rekey_guess_wrong_send (void * * state )
775+ {
776+ struct torture_state * s = * state ;
777+ const char * sshd_config = "KexAlgorithms diffie-hellman-group14-sha256" ;
778+
779+ /* This sets an only supported kex algorithm that we do not have as a first
780+ * option */
781+ torture_update_sshd_config (state , sshd_config );
782+
783+ /* Make the client send the first_kex_packet_follows flag during key
784+ * exchange as well as during the rekey */
785+ s -> ssh .session -> send_first_kex_follows = true;
786+
787+ torture_rekey_send (state );
788+ }
789+
790+ #ifdef WITH_SFTP
791+ static void torture_rekey_guess_recv (void * * state )
792+ {
793+ struct torture_state * s = * state ;
794+ int rc ;
795+
796+ setup_server_for_good_guess (state );
797+
798+ /* Make the client send the first_kex_packet_follows flag during key
799+ * exchange as well as during the rekey */
800+ s -> ssh .session -> send_first_kex_follows = true;
801+
802+ rc = ssh_options_set (s -> ssh .session , SSH_OPTIONS_REKEY_DATA , & bytes );
803+ assert_ssh_return_code (s -> ssh .session , rc );
804+
805+ session_setup_sftp (state );
806+
807+ torture_rekey_recv (state );
808+ }
809+
810+ static void torture_rekey_guess_wrong_recv (void * * state )
811+ {
812+ struct torture_state * s = * state ;
813+ const char * sshd_config = "KexAlgorithms diffie-hellman-group14-sha256" ;
814+ int rc ;
815+
816+ /* This sets an only supported kex algorithm that we do not have as a first
817+ * option */
818+ torture_update_sshd_config (state , sshd_config );
819+
820+ /* Make the client send the first_kex_packet_follows flag during key
821+ * exchange as well as during the rekey */
822+ s -> ssh .session -> send_first_kex_follows = true;
823+
824+ rc = ssh_options_set (s -> ssh .session , SSH_OPTIONS_REKEY_DATA , & bytes );
825+ assert_ssh_return_code (s -> ssh .session , rc );
826+
827+ session_setup_sftp (state );
828+
829+ torture_rekey_recv (state );
830+ }
831+ #endif /* WITH_SFTP */
832+
747833int torture_run_tests (void ) {
748834 int rc ;
749835 struct CMUnitTest tests [] = {
@@ -764,18 +850,6 @@ int torture_run_tests(void) {
764850 cmocka_unit_test_setup_teardown (torture_rekey_different_kex ,
765851 session_setup ,
766852 session_teardown ),
767- /* Note, that this modifies the sshd_config */
768- cmocka_unit_test_setup_teardown (torture_rekey_server_send ,
769- session_setup ,
770- session_teardown ),
771- #ifdef WITH_SFTP
772- cmocka_unit_test_setup_teardown (torture_rekey_server_recv ,
773- session_setup_sftp_server ,
774- session_teardown ),
775- #endif /* WITH_SFTP */
776- cmocka_unit_test_setup_teardown (torture_rekey_server_different_kex ,
777- session_setup ,
778- session_teardown ),
779853#ifdef WITH_ZLIB
780854#if (OPENSSH_VERSION_MAJOR == 7 && OPENSSH_VERSION_MINOR < 4 ) || OPENSSH_VERSION_MAJOR < 7
781855 cmocka_unit_test_setup_teardown (torture_rekey_send_compression ,
@@ -797,6 +871,33 @@ int torture_run_tests(void) {
797871#endif /* WITH_SFTP */
798872#endif /* WITH_ZLIB */
799873 /* TODO verify the two rekey are possible and the states are not broken after rekey */
874+
875+ cmocka_unit_test_setup_teardown (torture_rekey_server_different_kex ,
876+ session_setup ,
877+ session_teardown ),
878+ /* Note, that these tests modify the sshd_config so follow-up tests
879+ * might get unexpected behavior if they do not update the server with
880+ * torture_update_sshd_config() too */
881+ cmocka_unit_test_setup_teardown (torture_rekey_server_send ,
882+ session_setup ,
883+ session_teardown ),
884+ cmocka_unit_test_setup_teardown (torture_rekey_guess_send ,
885+ session_setup ,
886+ session_teardown ),
887+ cmocka_unit_test_setup_teardown (torture_rekey_guess_wrong_send ,
888+ session_setup ,
889+ session_teardown ),
890+ #ifdef WITH_SFTP
891+ cmocka_unit_test_setup_teardown (torture_rekey_server_recv ,
892+ session_setup_sftp_server ,
893+ session_teardown ),
894+ cmocka_unit_test_setup_teardown (torture_rekey_guess_recv ,
895+ session_setup ,
896+ session_teardown ),
897+ cmocka_unit_test_setup_teardown (torture_rekey_guess_wrong_recv ,
898+ session_setup ,
899+ session_teardown ),
900+ #endif /* WITH_SFTP */
800901 };
801902
802903 ssh_init ();
0 commit comments