mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 18:50:28 +09:00
knownhosts: Take StrictHostKeyChecking option into account
Signed-off-by: Sanne Raymaekers <sraymaek@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 67f418218b)
This commit is contained in:
committed by
Andreas Schneider
parent
5102b16cf1
commit
69cb3c5835
@@ -883,6 +883,9 @@ ssh_session_get_known_hosts_entry(ssh_session session,
|
|||||||
|
|
||||||
/* If we did not find any match at all: we report the previous result */
|
/* If we did not find any match at all: we report the previous result */
|
||||||
if (rv == SSH_KNOWN_HOSTS_UNKNOWN) {
|
if (rv == SSH_KNOWN_HOSTS_UNKNOWN) {
|
||||||
|
if (session->opts.StrictHostKeyChecking == 0) {
|
||||||
|
return SSH_KNOWN_HOSTS_OK;
|
||||||
|
}
|
||||||
return old_rv;
|
return old_rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -328,6 +328,41 @@ static void torture_knownhosts_conflict(void **state) {
|
|||||||
/* session will be freed by session_teardown() */
|
/* session will be freed by session_teardown() */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void torture_knownhosts_no_hostkeychecking(void **state)
|
||||||
|
{
|
||||||
|
|
||||||
|
struct torture_state *s = *state;
|
||||||
|
ssh_session session = s->ssh.session;
|
||||||
|
char known_hosts_file[1024] = {0};
|
||||||
|
enum ssh_known_hosts_e found;
|
||||||
|
int strict_host_key_checking = 0;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
snprintf(known_hosts_file,
|
||||||
|
sizeof(known_hosts_file),
|
||||||
|
"%s/%s",
|
||||||
|
s->socket_dir,
|
||||||
|
TORTURE_KNOWN_HOSTS_FILE);
|
||||||
|
|
||||||
|
rc = ssh_options_set(session, SSH_OPTIONS_KNOWNHOSTS, known_hosts_file);
|
||||||
|
assert_ssh_return_code(session, rc);
|
||||||
|
|
||||||
|
rc = ssh_options_set(session, SSH_OPTIONS_HOSTKEYS, "ssh-ed25519");
|
||||||
|
assert_ssh_return_code(session, rc);
|
||||||
|
|
||||||
|
rc = ssh_connect(session);
|
||||||
|
assert_ssh_return_code(session, rc);
|
||||||
|
|
||||||
|
found = ssh_session_is_known_server(session);
|
||||||
|
assert_int_equal(found, SSH_KNOWN_HOSTS_UNKNOWN);
|
||||||
|
|
||||||
|
rc = ssh_options_set(session, SSH_OPTIONS_STRICTHOSTKEYCHECK, &strict_host_key_checking);
|
||||||
|
assert_ssh_return_code(session, rc);
|
||||||
|
|
||||||
|
found = ssh_session_is_known_server(session);
|
||||||
|
assert_int_equal(found, SSH_KNOWN_HOSTS_OK);
|
||||||
|
}
|
||||||
|
|
||||||
int torture_run_tests(void) {
|
int torture_run_tests(void) {
|
||||||
int rc;
|
int rc;
|
||||||
struct CMUnitTest tests[] = {
|
struct CMUnitTest tests[] = {
|
||||||
@@ -346,6 +381,9 @@ int torture_run_tests(void) {
|
|||||||
cmocka_unit_test_setup_teardown(torture_knownhosts_conflict,
|
cmocka_unit_test_setup_teardown(torture_knownhosts_conflict,
|
||||||
session_setup,
|
session_setup,
|
||||||
session_teardown),
|
session_teardown),
|
||||||
|
cmocka_unit_test_setup_teardown(torture_knownhosts_no_hostkeychecking,
|
||||||
|
session_setup,
|
||||||
|
session_teardown),
|
||||||
};
|
};
|
||||||
|
|
||||||
ssh_init();
|
ssh_init();
|
||||||
|
|||||||
Reference in New Issue
Block a user