mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-04 12:20:42 +09:00
tests: Update knownhost tests with reproducer from T110
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
committed by
Andreas Schneider
parent
962bdf806c
commit
eae971c002
@@ -24,6 +24,7 @@
|
||||
#define LIBSSH_STATIC
|
||||
|
||||
#include "torture.h"
|
||||
#include "torture_key.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
@@ -150,6 +151,72 @@ static void torture_knownhosts_port(void **state) {
|
||||
assert_int_equal(rc, SSH_SERVER_KNOWN_OK);
|
||||
}
|
||||
|
||||
static void torture_knownhosts_wildcard(void **state)
|
||||
{
|
||||
struct torture_state *s = *state;
|
||||
ssh_session session = s->ssh.session;
|
||||
char known_hosts_file[1024];
|
||||
const char *key = NULL;
|
||||
FILE *file;
|
||||
int rc;
|
||||
|
||||
snprintf(known_hosts_file,
|
||||
sizeof(known_hosts_file),
|
||||
"%s/%s",
|
||||
s->socket_dir,
|
||||
TORTURE_KNOWN_HOSTS_FILE);
|
||||
|
||||
file = fopen(known_hosts_file, "w");
|
||||
assert_non_null(file);
|
||||
key = torture_get_testkey_pub(SSH_KEYTYPE_RSA);
|
||||
fprintf(file, "[127.0.0.10]:* %s\n", key);
|
||||
fclose(file);
|
||||
|
||||
rc = ssh_options_set(session, SSH_OPTIONS_HOST, TORTURE_SSH_SERVER);
|
||||
assert_ssh_return_code(session, rc);
|
||||
rc = ssh_options_set(session, SSH_OPTIONS_KNOWNHOSTS, known_hosts_file);
|
||||
assert_ssh_return_code(session, rc);
|
||||
|
||||
rc = ssh_connect(session);
|
||||
assert_ssh_return_code(session, rc);
|
||||
|
||||
rc = ssh_is_server_known(session);
|
||||
assert_int_equal(rc, SSH_SERVER_KNOWN_OK);
|
||||
}
|
||||
|
||||
static void torture_knownhosts_standard_port(void **state)
|
||||
{
|
||||
struct torture_state *s = *state;
|
||||
ssh_session session = s->ssh.session;
|
||||
char known_hosts_file[1024];
|
||||
const char *key = NULL;
|
||||
FILE *file;
|
||||
int rc;
|
||||
|
||||
snprintf(known_hosts_file,
|
||||
sizeof(known_hosts_file),
|
||||
"%s/%s",
|
||||
s->socket_dir,
|
||||
TORTURE_KNOWN_HOSTS_FILE);
|
||||
|
||||
file = fopen(known_hosts_file, "w");
|
||||
assert_non_null(file);
|
||||
key = torture_get_testkey_pub(SSH_KEYTYPE_RSA);
|
||||
fprintf(file, "[127.0.0.10]:22 %s\n", key);
|
||||
fclose(file);
|
||||
|
||||
rc = ssh_options_set(session, SSH_OPTIONS_HOST, TORTURE_SSH_SERVER);
|
||||
assert_ssh_return_code(session, rc);
|
||||
rc = ssh_options_set(session, SSH_OPTIONS_KNOWNHOSTS, known_hosts_file);
|
||||
assert_ssh_return_code(session, rc);
|
||||
|
||||
rc = ssh_connect(session);
|
||||
assert_ssh_return_code(session, rc);
|
||||
|
||||
rc = ssh_is_server_known(session);
|
||||
assert_int_equal(rc, SSH_SERVER_KNOWN_OK);
|
||||
}
|
||||
|
||||
static void torture_knownhosts_fail(void **state) {
|
||||
struct torture_state *s = *state;
|
||||
ssh_session session = s->ssh.session;
|
||||
@@ -366,6 +433,12 @@ static void torture_knownhosts_no_hostkeychecking(void **state)
|
||||
int torture_run_tests(void) {
|
||||
int rc;
|
||||
struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(torture_knownhosts_wildcard,
|
||||
session_setup,
|
||||
session_teardown),
|
||||
cmocka_unit_test_setup_teardown(torture_knownhosts_standard_port,
|
||||
session_setup,
|
||||
session_teardown),
|
||||
cmocka_unit_test_setup_teardown(torture_knownhosts_port,
|
||||
session_setup,
|
||||
session_teardown),
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#define LOCALHOST_PORT_ED25519 "[localhost]:2222 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA7M22fXD7OiS7kGMXP+OoIjCa+J+5sq8SgAZfIOmDgM"
|
||||
#define LOCALHOST_PATTERN_ED25519 "local* ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA7M22fXD7OiS7kGMXP+OoIjCa+J+5sq8SgAZfIOmDgM"
|
||||
#define LOCALHOST_HASHED_ED25519 "|1|ayWjmTf9mYgj7PuQNVOa7Lqkj5s=|hkbEh8FN6IkLo6t6GQGuBwamgsM= ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA7M22fXD7OiS7kGMXP+OoIjCa+J+5sq8SgAZfIOmDgM"
|
||||
#define LOCALHOST_PORT_WILDCARD "[localhost]:* ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA7M22fXD7OiS7kGMXP+OoIjCa+J+5sq8SgAZfIOmDgM"
|
||||
#define LOCALHOST_STANDARD_PORT "[localhost]:22 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA7M22fXD7OiS7kGMXP+OoIjCa+J+5sq8SgAZfIOmDgM"
|
||||
|
||||
#define TMP_FILE_NAME "/tmp/known_hosts_XXXXXX"
|
||||
|
||||
@@ -175,6 +177,46 @@ static void torture_knownhosts_parse_line_port_ed25519(void **state) {
|
||||
SSH_KNOWNHOSTS_ENTRY_FREE(entry);
|
||||
}
|
||||
|
||||
static void torture_knownhosts_parse_line_port_wildcard(void **state)
|
||||
{
|
||||
struct ssh_knownhosts_entry *entry = NULL;
|
||||
int rc;
|
||||
|
||||
(void) state;
|
||||
|
||||
rc = ssh_known_hosts_parse_line("localhost",
|
||||
LOCALHOST_PORT_WILDCARD,
|
||||
&entry);
|
||||
assert_int_equal(rc, SSH_OK);
|
||||
|
||||
assert_string_equal(entry->hostname, "localhost");
|
||||
assert_non_null(entry->unparsed);
|
||||
assert_non_null(entry->publickey);
|
||||
assert_int_equal(ssh_key_type(entry->publickey), SSH_KEYTYPE_ED25519);
|
||||
|
||||
SSH_KNOWNHOSTS_ENTRY_FREE(entry);
|
||||
}
|
||||
|
||||
static void torture_knownhosts_parse_line_standard_port(void **state)
|
||||
{
|
||||
struct ssh_knownhosts_entry *entry = NULL;
|
||||
int rc;
|
||||
|
||||
(void) state;
|
||||
|
||||
rc = ssh_known_hosts_parse_line("localhost",
|
||||
LOCALHOST_STANDARD_PORT,
|
||||
&entry);
|
||||
assert_int_equal(rc, SSH_OK);
|
||||
|
||||
assert_string_equal(entry->hostname, "localhost");
|
||||
assert_non_null(entry->unparsed);
|
||||
assert_non_null(entry->publickey);
|
||||
assert_int_equal(ssh_key_type(entry->publickey), SSH_KEYTYPE_ED25519);
|
||||
|
||||
SSH_KNOWNHOSTS_ENTRY_FREE(entry);
|
||||
}
|
||||
|
||||
static void torture_knownhosts_parse_line_pattern_ed25519(void **state) {
|
||||
struct ssh_knownhosts_entry *entry = NULL;
|
||||
int rc;
|
||||
@@ -375,6 +417,8 @@ int torture_run_tests(void) {
|
||||
cmocka_unit_test(torture_knownhosts_parse_line_ecdsa),
|
||||
cmocka_unit_test(torture_knownhosts_parse_line_default_ed25519),
|
||||
cmocka_unit_test(torture_knownhosts_parse_line_port_ed25519),
|
||||
cmocka_unit_test(torture_knownhosts_parse_line_port_wildcard),
|
||||
cmocka_unit_test(torture_knownhosts_parse_line_standard_port),
|
||||
cmocka_unit_test(torture_knownhosts_parse_line_pattern_ed25519),
|
||||
cmocka_unit_test(torture_knownhosts_parse_line_hashed_ed25519),
|
||||
cmocka_unit_test_setup_teardown(torture_knownhosts_read_file,
|
||||
|
||||
Reference in New Issue
Block a user