version 1.4, 1999/11/02 19:42:36 |
version 1.5, 1999/11/15 20:53:24 |
|
|
but used to have a different host key. */ |
but used to have a different host key. */ |
|
|
HostStatus |
HostStatus |
check_host_in_hostfile(const char *filename, |
check_host_in_hostfile(const char *filename, const char *host, |
const char *host, unsigned int bits, |
BIGNUM *e, BIGNUM *n, BIGNUM *ke, BIGNUM *kn) |
BIGNUM *e, BIGNUM *n, |
|
BIGNUM *ke, BIGNUM *kn) |
|
{ |
{ |
FILE *f; |
FILE *f; |
char line[8192]; |
char line[8192]; |
unsigned int kbits, hostlen; |
int linenum = 0; |
|
unsigned int bits, kbits, hostlen; |
char *cp, *cp2; |
char *cp, *cp2; |
HostStatus end_return; |
HostStatus end_return; |
struct stat st; |
|
|
|
/* Open the file containing the list of known hosts. */ |
/* Open the file containing the list of known hosts. */ |
f = fopen(filename, "r"); |
f = fopen(filename, "r"); |
if (!f) |
if (!f) |
{ |
return HOST_NEW; |
if (stat(filename, &st) >= 0) |
|
{ |
|
packet_send_debug("Could not open %.900s for reading.", filename); |
|
packet_send_debug("If your home directory is on an NFS volume, it may need to be world-readable."); |
|
} |
|
return HOST_NEW; |
|
} |
|
|
|
/* Cache the length of the host name. */ |
/* Cache the length of the host name. */ |
hostlen = strlen(host); |
hostlen = strlen(host); |
|
|
one. */ |
one. */ |
end_return = HOST_NEW; |
end_return = HOST_NEW; |
|
|
|
/* size of modulus 'n' */ |
|
bits = BN_num_bits(n); |
|
|
/* Go trough the file. */ |
/* Go trough the file. */ |
while (fgets(line, sizeof(line), f)) |
while (fgets(line, sizeof(line), f)) |
{ |
{ |
cp = line; |
cp = line; |
|
linenum++; |
|
|
/* Skip any leading whitespace. */ |
/* Skip any leading whitespace. */ |
for (; *cp == ' ' || *cp == '\t'; cp++) |
for (; *cp == ' ' || *cp == '\t'; cp++) |
|
|
if (!auth_rsa_read_key(&cp, &kbits, ke, kn)) |
if (!auth_rsa_read_key(&cp, &kbits, ke, kn)) |
continue; |
continue; |
|
|
/* Check if the current key is the same as the previous one. */ |
if (kbits != BN_num_bits(kn)) { |
|
error("Warning: error in %s, line %d: keysize mismatch for host %s: " |
|
"actual size %d vs. announced %d.", |
|
filename, linenum, host, BN_num_bits(kn), kbits); |
|
error("Warning: replace %d with %d in %s, line %d.", |
|
kbits, BN_num_bits(kn), filename, linenum); |
|
} |
|
|
|
/* Check if the current key is the same as the given key. */ |
if (kbits == bits && BN_cmp(ke, e) == 0 && BN_cmp(kn, n) == 0) |
if (kbits == bits && BN_cmp(ke, e) == 0 && BN_cmp(kn, n) == 0) |
{ |
{ |
/* Ok, they match. */ |
/* Ok, they match. */ |
|
|
|
|
int |
int |
add_host_to_hostfile(const char *filename, const char *host, |
add_host_to_hostfile(const char *filename, const char *host, |
unsigned int bits, BIGNUM *e, BIGNUM *n) |
BIGNUM *e, BIGNUM *n) |
{ |
{ |
FILE *f; |
FILE *f; |
char *buf; |
char *buf; |
|
unsigned int bits; |
|
|
/* Open the file for appending. */ |
/* Open the file for appending. */ |
f = fopen(filename, "a"); |
f = fopen(filename, "a"); |
if (!f) |
if (!f) |
return 0; |
return 0; |
|
|
|
/* size of modulus 'n' */ |
|
bits = BN_num_bits(n); |
|
|
/* Print the host name and key to the file. */ |
/* Print the host name and key to the file. */ |
fprintf(f, "%s %u ", host, bits); |
fprintf(f, "%s %u ", host, bits); |
buf = BN_bn2dec(e); |
buf = BN_bn2dec(e); |
if (buf == NULL) { |
if (buf == NULL) { |
error("add_host_to_hostfile: BN_bn2dec #1 failed"); |
error("add_host_to_hostfile: BN_bn2dec(e) failed"); |
fclose(f); |
fclose(f); |
return 0; |
return 0; |
} |
} |
|
|
free (buf); |
free (buf); |
buf = BN_bn2dec(n); |
buf = BN_bn2dec(n); |
if (buf == NULL) { |
if (buf == NULL) { |
error("add_host_to_hostfile: BN_bn2dec #2 failed"); |
error("add_host_to_hostfile: BN_bn2dec(n) failed"); |
fclose(f); |
fclose(f); |
return 0; |
return 0; |
} |
} |