version 1.7, 1999/11/16 22:27:54 |
version 1.8, 1999/11/16 22:49:28 |
|
|
#include "rsa.h" |
#include "rsa.h" |
#include "ssh.h" |
#include "ssh.h" |
#include "xmalloc.h" |
#include "xmalloc.h" |
|
#include "fingerprint.h" |
|
|
/* Generated private key. */ |
/* Generated private key. */ |
RSA *private_key; |
RSA *private_key; |
|
|
|
|
int quiet = 0; |
int quiet = 0; |
|
|
|
/* Flag indicating that we just want to see the key fingerprint */ |
|
int print_fingerprint = 0; |
|
|
/* This is set to the identity file name if given on the command line. */ |
/* This is set to the identity file name if given on the command line. */ |
char *identity_file = NULL; |
char *identity_file = NULL; |
|
|
|
|
} |
} |
|
|
void |
void |
|
do_fingerprint(struct passwd *pw) |
|
{ |
|
char *file, *comment; |
|
RSA *public_key; |
|
struct stat st; |
|
|
|
file = get_filename(pw, "Enter file in which the key is"); |
|
if (stat(file, &st) < 0) |
|
{ |
|
perror(file); |
|
exit(1); |
|
} |
|
public_key = RSA_new(); |
|
if (!load_public_key(file, public_key, &comment)) { |
|
char *cp, line[1024]; |
|
BIGNUM *e, *n; |
|
int dummy, invalid = 0; |
|
FILE *f = fopen(file, "r"); |
|
n = BN_new(); |
|
e = BN_new(); |
|
if (f && fgets(line, sizeof(line), f)) { |
|
cp = line; |
|
line[strlen(line)-1] = '\0'; |
|
if (auth_rsa_read_key(&cp, &dummy, e, n)) { |
|
public_key->e = e; |
|
public_key->n = n; |
|
comment = xstrdup(cp ? cp : "no comment"); |
|
} else { |
|
invalid = 1; |
|
} |
|
} else { |
|
invalid = 1; |
|
} |
|
if (invalid) { |
|
printf("%s is not a valid key file.\n", file); |
|
BN_free(e); |
|
BN_free(n); |
|
exit(1); |
|
} |
|
} |
|
|
|
printf("%d %s %s\n", BN_num_bits(public_key->n), |
|
fingerprint(public_key->e, public_key->n), |
|
comment); |
|
RSA_free(public_key); |
|
exit(0); |
|
} |
|
|
|
|
|
void |
do_change_passphrase(struct passwd *pw) |
do_change_passphrase(struct passwd *pw) |
{ |
{ |
char *file, *comment; |
char *file, *comment; |
|
|
error("Could not create directory '%s'.", buf); |
error("Could not create directory '%s'.", buf); |
|
|
/* Parse command line arguments. */ |
/* Parse command line arguments. */ |
while ((opt = getopt(ac, av, "qpcb:f:P:N:C:")) != EOF) |
while ((opt = getopt(ac, av, "qpclb:f:P:N:C:")) != EOF) |
{ |
{ |
switch (opt) |
switch (opt) |
{ |
{ |
|
|
} |
} |
break; |
break; |
|
|
|
case 'l': |
|
print_fingerprint = 1; |
|
break; |
|
|
case 'p': |
case 'p': |
change_passphrase = 1; |
change_passphrase = 1; |
break; |
break; |
|
|
printf("Can only have one of -p and -c.\n"); |
printf("Can only have one of -p and -c.\n"); |
exit(1); |
exit(1); |
} |
} |
|
|
|
if (print_fingerprint) |
|
do_fingerprint(pw); |
|
|
/* If the user requested to change the passphrase, do it now. This |
/* If the user requested to change the passphrase, do it now. This |
function never returns. */ |
function never returns. */ |