=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/ssh-keygen.c,v retrieving revision 1.7 retrieving revision 1.9 diff -u -r1.7 -r1.9 --- src/usr.bin/ssh/ssh-keygen.c 1999/11/16 22:27:54 1.7 +++ src/usr.bin/ssh/ssh-keygen.c 1999/11/20 10:02:53 1.9 @@ -14,11 +14,12 @@ */ #include "includes.h" -RCSID("$Id: ssh-keygen.c,v 1.7 1999/11/16 22:27:54 markus Exp $"); +RCSID("$Id: ssh-keygen.c,v 1.9 1999/11/20 10:02:53 markus Exp $"); #include "rsa.h" #include "ssh.h" #include "xmalloc.h" +#include "fingerprint.h" /* Generated private key. */ RSA *private_key; @@ -40,6 +41,9 @@ 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. */ char *identity_file = NULL; @@ -79,6 +83,56 @@ } 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) { char *file, *comment; @@ -268,6 +322,7 @@ /* Save the public key in text format in a file with the same name but .pub appended. */ + file = xrealloc(file, strlen(file) + 5); strcat(file, ".pub"); f = fopen(file, "w"); if (!f) @@ -330,7 +385,7 @@ error("Could not create directory '%s'.", buf); /* 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) { @@ -343,6 +398,10 @@ } break; + case 'l': + print_fingerprint = 1; + break; + case 'p': change_passphrase = 1; break; @@ -388,6 +447,9 @@ printf("Can only have one of -p and -c.\n"); exit(1); } + + if (print_fingerprint) + do_fingerprint(pw); /* If the user requested to change the passphrase, do it now. This function never returns. */