Added support for StrictHostKeyChecking and UserKnownHostsFile parameters.

Added OpenSSH parameters to libssh:
  - StrictHostKeyChecking
  - UserKnownHostsFile

This parameters are useful to avoid checking the fingerprint. Eg:

~/.ssh/config:
    Host 192.10.20.30
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null

Signed-off-by: Ruben Garcia Azuara <rubenga@tid.es>
Signed-off-by: Andreas Schneider <mail@cynapses.org>
This commit is contained in:
Ruben Garcia Azuara
2010-04-06 20:07:01 +02:00
committed by Andreas Schneider
parent 14eb593af3
commit 5a2abd34ce
6 changed files with 38 additions and 4 deletions

View File

@@ -269,11 +269,11 @@ enum ssh_options_e {
SSH_OPTIONS_SSH2,
SSH_OPTIONS_LOG_VERBOSITY,
SSH_OPTIONS_LOG_VERBOSITY_STR,
SSH_OPTIONS_CIPHERS_C_S,
SSH_OPTIONS_CIPHERS_S_C,
SSH_OPTIONS_COMPRESSION_C_S,
SSH_OPTIONS_COMPRESSION_S_C
SSH_OPTIONS_COMPRESSION_S_C,
SSH_OPTIONS_HOSTKEYCHECK
};
enum {

View File

@@ -141,7 +141,7 @@ struct ssh_session_struct {
socket_t fd;
int ssh2;
int ssh1;
int StrictHostKeyChecking;
};
int ssh_handle_packets(ssh_session session, int timeout);

View File

@@ -38,7 +38,9 @@ enum ssh_config_opcode_e {
SOC_CIPHERS,
SOC_COMPRESSION,
SOC_TIMEOUT,
SOC_PROTOCOL
SOC_PROTOCOL,
SOC_HOSTKEYCHECK,
SOC_KNOWNHOSTS
};
struct ssh_config_keyword_table_s {
@@ -56,6 +58,8 @@ static struct ssh_config_keyword_table_s ssh_config_keyword_table[] = {
{ "compression", SOC_COMPRESSION },
{ "connecttimeout", SOC_TIMEOUT },
{ "protocol", SOC_PROTOCOL },
{ "stricthostkeychecking", SOC_HOSTKEYCHECK },
{ "userknownhostsfile", SOC_KNOWNHOSTS },
{ NULL, SOC_UNSUPPORTED }
};
@@ -276,6 +280,18 @@ static int ssh_config_parse_line(ssh_session session, const char *line,
ssh_options_set(session, SSH_OPTIONS_TIMEOUT, &i);
}
break;
case SOC_HOSTKEYCHECK:
i = ssh_config_get_yesno(&s, -1);
if (i >= 0 && *parsing) {
ssh_options_set(session, SSH_OPTIONS_HOSTKEYCHECK, &i);
}
break;
case SOC_KNOWNHOSTS:
p = ssh_config_get_str(&s, NULL);
if (p && *parsing) {
ssh_options_set(session, SSH_OPTIONS_KNOWNHOSTS, p);
}
break;
case SOC_UNSUPPORTED:
fprintf(stderr, "Unsupported option: %s, line: %d\n", keyword, count);
break;

View File

@@ -1648,6 +1648,11 @@ int ssh_is_server_known(ssh_session session) {
}
} while (1);
if ( (ret == SSH_SERVER_NOT_KNOWN) && (session->StrictHostKeyChecking == 0) ) {
ssh_write_knownhost(session);
ret = SSH_SERVER_KNOWN_OK;
}
SAFE_FREE(host);
if (file != NULL) {
fclose(file);

View File

@@ -362,6 +362,10 @@ char *dir_expand_dup(ssh_session session, const char *value, int allowsshdir) {
* Set the compression to use for server to client
* communication (string, "none" or "zlib").
*
* - SSH_OPTIONS_HOSTKEYCHECK:
* Set the parameter StrictHostKeyChecking to avoid
* asking about a fingerprint
*
* @param value The value to set. This is a generic pointer and the
* datatype which is used should be set according to the
* type set.
@@ -612,6 +616,14 @@ int ssh_options_set(ssh_session session, enum ssh_options_e type,
return -1;
}
break;
case SSH_OPTIONS_HOSTKEYCHECK:
if (value == NULL) {
ssh_set_error_invalid(session, __FUNCTION__);
return -1;
} else {
session->StrictHostKeyChecking = *(int*)value;
}
break;
default:
ssh_set_error(session, SSH_REQUEST_DENIED, "Unknown ssh option %d", type);
return -1;

View File

@@ -90,6 +90,7 @@ ssh_session ssh_new(void) {
session->maxchannel = FIRST_CHANNEL;
/* options */
session->StrictHostKeyChecking = 1;
session->port = 22;
session->fd = -1;
session->ssh2 = 1;