version 1.147, 2003/06/29 12:44:38 |
version 1.147.2.2, 2004/08/19 22:37:32 |
|
|
#include "readconf.h" |
#include "readconf.h" |
#include "atomicio.h" |
#include "atomicio.h" |
#include "misc.h" |
#include "misc.h" |
#include "readpass.h" |
|
|
|
#ifdef DNS |
|
#include "dns.h" |
#include "dns.h" |
#endif |
|
|
|
char *client_version_string = NULL; |
char *client_version_string = NULL; |
char *server_version_string = NULL; |
char *server_version_string = NULL; |
|
|
#ifdef DNS |
int matching_host_key_dns = 0; |
int verified_host_key_dns = 0; |
|
#endif |
|
|
|
/* import */ |
/* import */ |
extern Options options; |
extern Options options; |
|
|
extern pid_t proxy_command_pid; |
extern pid_t proxy_command_pid; |
|
|
static int show_other_keys(const char *, Key *); |
static int show_other_keys(const char *, Key *); |
|
static void warn_changed_key(Key *); |
|
|
/* |
/* |
* Connect to the given ssh server using a proxy command. |
* Connect to the given ssh server using a proxy command. |
|
|
* Build the final command string in the buffer by making the |
* Build the final command string in the buffer by making the |
* appropriate substitutions to the given proxy command. |
* appropriate substitutions to the given proxy command. |
* |
* |
* Use "exec" to avoid "sh -c" processes on some platforms |
* Use "exec" to avoid "sh -c" processes on some platforms |
* (e.g. Solaris) |
* (e.g. Solaris) |
*/ |
*/ |
buffer_init(&command); |
buffer_init(&command); |
|
|
if (timeout <= 0) |
if (timeout <= 0) |
return (connect(sockfd, serv_addr, addrlen)); |
return (connect(sockfd, serv_addr, addrlen)); |
|
|
if (fcntl(sockfd, F_SETFL, O_NONBLOCK) < 0) |
set_nonblock(sockfd); |
return (-1); |
|
|
|
rc = connect(sockfd, serv_addr, addrlen); |
rc = connect(sockfd, serv_addr, addrlen); |
if (rc == 0) |
if (rc == 0) { |
|
unset_nonblock(sockfd); |
return (0); |
return (0); |
|
} |
if (errno != EINPROGRESS) |
if (errno != EINPROGRESS) |
return (-1); |
return (-1); |
|
|
|
|
break; |
break; |
case -1: |
case -1: |
/* Select error */ |
/* Select error */ |
debug("select: %s", strerror(errno)); |
debug("select: %s", strerror(errno)); |
break; |
break; |
case 1: |
case 1: |
/* Completed or failed */ |
/* Completed or failed */ |
optval = 0; |
optval = 0; |
optlen = sizeof(optval); |
optlen = sizeof(optval); |
if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &optval, |
if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &optval, |
&optlen) == -1) |
&optlen) == -1) { |
debug("getsockopt: %s", strerror(errno)); |
debug("getsockopt: %s", strerror(errno)); |
break; |
break; |
|
} |
if (optval != 0) { |
if (optval != 0) { |
errno = optval; |
errno = optval; |
break; |
break; |
} |
} |
result = 0; |
result = 0; |
|
unset_nonblock(sockfd); |
break; |
break; |
default: |
default: |
/* Should not occur */ |
/* Should not occur */ |
|
|
|
|
debug("Connection established."); |
debug("Connection established."); |
|
|
/* Set keepalives if requested. */ |
/* Set SO_KEEPALIVE if requested. */ |
if (options.keepalives && |
if (options.tcp_keep_alive && |
setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, |
setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, |
sizeof(on)) < 0) |
sizeof(on)) < 0) |
error("setsockopt SO_KEEPALIVE: %.100s", strerror(errno)); |
error("setsockopt SO_KEEPALIVE: %.100s", strerror(errno)); |
|
|
int readonly, const char *user_hostfile, const char *system_hostfile) |
int readonly, const char *user_hostfile, const char *system_hostfile) |
{ |
{ |
Key *file_key; |
Key *file_key; |
char *type = key_type(host_key); |
const char *type = key_type(host_key); |
char *ip = NULL; |
char *ip = NULL; |
char hostline[1000], *hostp, *fp; |
char hostline[1000], *hostp, *fp; |
HostStatus host_status; |
HostStatus host_status; |
|
|
/* The default */ |
/* The default */ |
fp = key_fingerprint(host_key, SSH_FP_MD5, SSH_FP_HEX); |
fp = key_fingerprint(host_key, SSH_FP_MD5, SSH_FP_HEX); |
msg2[0] = '\0'; |
msg2[0] = '\0'; |
#ifdef DNS |
|
if (options.verify_host_key_dns) { |
if (options.verify_host_key_dns) { |
if (verified_host_key_dns) |
if (matching_host_key_dns) |
snprintf(msg2, sizeof(msg2), |
snprintf(msg2, sizeof(msg2), |
"Matching host key fingerprint" |
"Matching host key fingerprint" |
" found in DNS.\n"); |
" found in DNS.\n"); |
|
|
"No matching host key fingerprint" |
"No matching host key fingerprint" |
" found in DNS.\n"); |
" found in DNS.\n"); |
} |
} |
#endif |
|
snprintf(msg, sizeof(msg), |
snprintf(msg, sizeof(msg), |
"The authenticity of host '%.200s (%s)' can't be " |
"The authenticity of host '%.200s (%s)' can't be " |
"established%s\n" |
"established%s\n" |
|
|
break; |
break; |
case HOST_CHANGED: |
case HOST_CHANGED: |
if (options.check_host_ip && host_ip_differ) { |
if (options.check_host_ip && host_ip_differ) { |
char *msg; |
char *key_msg; |
if (ip_status == HOST_NEW) |
if (ip_status == HOST_NEW) |
msg = "is unknown"; |
key_msg = "is unknown"; |
else if (ip_status == HOST_OK) |
else if (ip_status == HOST_OK) |
msg = "is unchanged"; |
key_msg = "is unchanged"; |
else |
else |
msg = "has a different value"; |
key_msg = "has a different value"; |
error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); |
error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); |
error("@ WARNING: POSSIBLE DNS SPOOFING DETECTED! @"); |
error("@ WARNING: POSSIBLE DNS SPOOFING DETECTED! @"); |
error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); |
error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); |
error("The %s host key for %s has changed,", type, host); |
error("The %s host key for %s has changed,", type, host); |
error("and the key for the according IP address %s", ip); |
error("and the key for the according IP address %s", ip); |
error("%s. This could either mean that", msg); |
error("%s. This could either mean that", key_msg); |
error("DNS SPOOFING is happening or the IP address for the host"); |
error("DNS SPOOFING is happening or the IP address for the host"); |
error("and its host key have changed at the same time."); |
error("and its host key have changed at the same time."); |
if (ip_status != HOST_NEW) |
if (ip_status != HOST_NEW) |
error("Offending key for IP in %s:%d", ip_file, ip_line); |
error("Offending key for IP in %s:%d", ip_file, ip_line); |
} |
} |
/* The host key has changed. */ |
/* The host key has changed. */ |
fp = key_fingerprint(host_key, SSH_FP_MD5, SSH_FP_HEX); |
warn_changed_key(host_key); |
error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); |
|
error("@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @"); |
|
error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); |
|
error("IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!"); |
|
error("Someone could be eavesdropping on you right now (man-in-the-middle attack)!"); |
|
error("It is also possible that the %s host key has just been changed.", type); |
|
error("The fingerprint for the %s key sent by the remote host is\n%s.", |
|
type, fp); |
|
error("Please contact your system administrator."); |
|
error("Add correct host key in %.100s to get rid of this message.", |
error("Add correct host key in %.100s to get rid of this message.", |
user_hostfile); |
user_hostfile); |
error("Offending key in %s:%d", host_file, host_line); |
error("Offending key in %s:%d", host_file, host_line); |
xfree(fp); |
|
|
|
/* |
/* |
* If strict host key checking is in use, the user will have |
* If strict host key checking is in use, the user will have |
|
|
verify_host_key(char *host, struct sockaddr *hostaddr, Key *host_key) |
verify_host_key(char *host, struct sockaddr *hostaddr, Key *host_key) |
{ |
{ |
struct stat st; |
struct stat st; |
|
int flags = 0; |
|
|
#ifdef DNS |
if (options.verify_host_key_dns && |
if (options.verify_host_key_dns) { |
verify_host_key_dns(host, hostaddr, host_key, &flags) == 0) { |
switch(verify_host_key_dns(host, hostaddr, host_key)) { |
|
case DNS_VERIFY_OK: |
if (flags & DNS_VERIFY_FOUND) { |
#ifdef DNSSEC |
|
return 0; |
if (options.verify_host_key_dns == 1 && |
#else |
flags & DNS_VERIFY_MATCH && |
verified_host_key_dns = 1; |
flags & DNS_VERIFY_SECURE) |
break; |
return 0; |
#endif |
|
case DNS_VERIFY_FAILED: |
if (flags & DNS_VERIFY_MATCH) { |
return -1; |
matching_host_key_dns = 1; |
case DNS_VERIFY_ERROR: |
} else { |
break; |
warn_changed_key(host_key); |
default: |
error("Update the SSHFP RR in DNS with the new " |
debug3("bad return value from verify_host_key_dns"); |
"host key to get rid of this message."); |
break; |
} |
} |
} |
} |
} |
#endif /* DNS */ |
|
|
|
/* return ok if the key can be found in an old keyfile */ |
/* return ok if the key can be found in an old keyfile */ |
if (stat(options.system_hostfile2, &st) == 0 || |
if (stat(options.system_hostfile2, &st) == 0 || |
|
|
debug2("no key of type %d for host %s", type[i], host); |
debug2("no key of type %d for host %s", type[i], host); |
} |
} |
return (found); |
return (found); |
|
} |
|
|
|
static void |
|
warn_changed_key(Key *host_key) |
|
{ |
|
char *fp; |
|
const char *type = key_type(host_key); |
|
|
|
fp = key_fingerprint(host_key, SSH_FP_MD5, SSH_FP_HEX); |
|
|
|
error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); |
|
error("@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @"); |
|
error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); |
|
error("IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!"); |
|
error("Someone could be eavesdropping on you right now (man-in-the-middle attack)!"); |
|
error("It is also possible that the %s host key has just been changed.", type); |
|
error("The fingerprint for the %s key sent by the remote host is\n%s.", |
|
type, fp); |
|
error("Please contact your system administrator."); |
|
|
|
xfree(fp); |
} |
} |