From c433ac02bdfb5ec8d9a16074794be587cced59c1 Mon Sep 17 00:00:00 2001 From: Aris Adamantiadis Date: Sat, 1 Feb 2014 16:35:13 +0100 Subject: known_hosts: add ssh_knownhosts_algorithms() Goal of that function is to test the preferred key exchange methods based on what's available in the known_hosts file --- tests/client/torture_knownhosts.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'tests/client') diff --git a/tests/client/torture_knownhosts.c b/tests/client/torture_knownhosts.c index ad8c8114..69f0d7dc 100644 --- a/tests/client/torture_knownhosts.c +++ b/tests/client/torture_knownhosts.c @@ -134,7 +134,6 @@ static void torture_knownhosts_fail(void **state) { rc = ssh_is_server_known(session); assert_true(rc == SSH_SERVER_KNOWN_CHANGED); - } static void torture_knownhosts_other(void **state) { @@ -161,7 +160,6 @@ static void torture_knownhosts_other(void **state) { rc = ssh_is_server_known(session); assert_true(rc == SSH_SERVER_FOUND_OTHER); - } static void torture_knownhosts_conflict(void **state) { @@ -209,16 +207,45 @@ static void torture_knownhosts_conflict(void **state) { rc = ssh_is_server_known(session); assert_true(rc == SSH_SERVER_KNOWN_OK); +} + +static void torture_knownhosts_precheck(void **state) { + ssh_session session = *state; + FILE *file; + int rc; + int dsa; + int rsa; + rc = ssh_options_set(session, SSH_OPTIONS_HOST, "localhost"); + assert_true(rc == SSH_OK); + rc = ssh_options_set(session, SSH_OPTIONS_KNOWNHOSTS, KNOWNHOSTFILES); + assert_true(rc == SSH_OK); + + file = fopen(KNOWNHOSTFILES, "w"); + assert_true(file != NULL); + fprintf(file, "localhost ssh-rsa %s\n", BADRSA); + fprintf(file, "localhost ssh-dss %s\n", BADDSA); + fclose(file); + + rc = ssh_knownhosts_algorithms(session); + assert_true(rc != SSH_ERROR); + dsa = 1 << SSH_KEYTYPE_DSS; + rsa = 1 << SSH_KEYTYPE_RSA; + assert_true(rc & dsa); + assert_true(rc & rsa); + /* nothing else than dsa and rsa */ + assert_true((rc & (dsa | rsa)) == rc); } + int torture_run_tests(void) { int rc; const UnitTest tests[] = { unit_test_setup_teardown(torture_knownhosts_port, setup, teardown), unit_test_setup_teardown(torture_knownhosts_fail, setup, teardown), unit_test_setup_teardown(torture_knownhosts_other, setup, teardown), - unit_test_setup_teardown(torture_knownhosts_conflict, setup, teardown) + unit_test_setup_teardown(torture_knownhosts_conflict, setup, teardown), + unit_test_setup_teardown(torture_knownhosts_precheck, setup, teardown) }; ssh_init(); -- cgit