diff options
author | Markus Friedl <markus@cvs.openbsd.org> | 1999-11-21 21:58:32 +0000 |
---|---|---|
committer | Markus Friedl <markus@cvs.openbsd.org> | 1999-11-21 21:58:32 +0000 |
commit | 3e3b91deb526d1a5f78e2b18e3fd87c5c37391e5 (patch) | |
tree | 263baf1caa6978194b3a012ea0fbfcaddaee7350 /usr.bin/ssh | |
parent | ebb93c762e57e0136484a6293bd575c91baa8a42 (diff) |
don't create ~/.ssh only if the user wants to store the private key there.
show fingerprint instead of public-key after keygeneration. ok niels@
Diffstat (limited to 'usr.bin/ssh')
-rw-r--r-- | usr.bin/ssh/ssh-keygen.c | 56 |
1 files changed, 27 insertions, 29 deletions
diff --git a/usr.bin/ssh/ssh-keygen.c b/usr.bin/ssh/ssh-keygen.c index 204ea2e65c0..891634da109 100644 --- a/usr.bin/ssh/ssh-keygen.c +++ b/usr.bin/ssh/ssh-keygen.c @@ -14,7 +14,7 @@ Identity and host key generation and maintenance. */ #include "includes.h" -RCSID("$Id: ssh-keygen.c,v 1.10 1999/11/20 19:53:40 markus Exp $"); +RCSID("$Id: ssh-keygen.c,v 1.11 1999/11/21 21:58:31 markus Exp $"); #include "rsa.h" #include "ssh.h" @@ -357,7 +357,7 @@ usage(void) int main(int ac, char **av) { - char buf[16384], buf2[1024], *passphrase1, *passphrase2; + char dotsshdir[16*1024], comment[1024], *passphrase1, *passphrase2; struct passwd *pw; char *tmpbuf; int opt; @@ -385,12 +385,6 @@ main(int ac, char **av) exit(1); } - /* Create ~/.ssh directory if it doesn\'t already exist. */ - snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir, SSH_USER_DIR); - if (stat(buf, &st) < 0) - if (mkdir(buf, 0755) < 0) - error("Could not create directory '%s'.", buf); - /* Parse command line arguments. */ while ((opt = getopt(ac, av, "qpclb:f:P:N:C:")) != EOF) { @@ -480,15 +474,26 @@ main(int ac, char **av) if (!have_identity) ask_filename(pw, "Enter file in which to save the key"); - /* If the file aready exists, ask the user to confirm. */ + /* Create ~/.ssh directory if it doesn\'t already exist. */ + snprintf(dotsshdir, sizeof dotsshdir, "%s/%s", pw->pw_dir, SSH_USER_DIR); + if (strstr(identity_file, dotsshdir) != NULL && + stat(dotsshdir, &st) < 0) { + if (mkdir(dotsshdir, 0755) < 0) + error("Could not create directory '%s'.", dotsshdir); + else if(!quiet) + printf("Created directory '%s'.\n", dotsshdir); + } + + /* If the file already exists, ask the user to confirm. */ if (stat(identity_file, &st) >= 0) { + char yesno[3]; printf("%s already exists.\n", identity_file); printf("Overwrite (y/n)? "); fflush(stdout); - if (fgets(buf2, sizeof(buf2), stdin) == NULL) + if (fgets(yesno, sizeof(yesno), stdin) == NULL) exit(1); - if (buf2[0] != 'y' && buf2[0] != 'Y') + if (yesno[0] != 'y' && yesno[0] != 'Y') exit(1); } @@ -523,7 +528,7 @@ main(int ac, char **av) edit this field. */ if (identity_comment) { - strlcpy(buf2, identity_comment, sizeof(buf2)); + strlcpy(comment, identity_comment, sizeof(comment)); } else { @@ -532,11 +537,11 @@ main(int ac, char **av) perror("gethostname"); exit(1); } - snprintf(buf2, sizeof buf2, "%s@%s", pw->pw_name, hostname); + snprintf(comment, sizeof comment, "%s@%s", pw->pw_name, hostname); } /* Save the key with the given passphrase and comment. */ - if (!save_private_key(identity_file, passphrase1, private_key, buf2)) + if (!save_private_key(identity_file, passphrase1, private_key, comment)) { printf("Saving the key failed: %s: %s.\n", identity_file, strerror(errno)); @@ -555,18 +560,6 @@ main(int ac, char **av) if (!quiet) printf("Your identification has been saved in %s.\n", identity_file); - /* Display the public key on the screen. */ - if (!quiet) { - printf("Your public key is:\n"); - printf("%d ", BN_num_bits(public_key->n)); - tmpbuf = BN_bn2dec(public_key->e); - printf("%s ", tmpbuf); - free(tmpbuf); - tmpbuf = BN_bn2dec(public_key->n); - printf("%s %s\n", tmpbuf, buf2); - free(tmpbuf); - } - /* Save the public key in text format in a file with the same name but .pub appended. */ strlcat(identity_file, ".pub", sizeof(identity_file)); @@ -581,12 +574,17 @@ main(int ac, char **av) fprintf(f, "%s ", tmpbuf); free(tmpbuf); tmpbuf = BN_bn2dec(public_key->n); - fprintf(f, "%s %s\n", tmpbuf, buf2); + fprintf(f, "%s %s\n", tmpbuf, comment); free(tmpbuf); fclose(f); - if (!quiet) - printf("Your public key has been saved in %s\n", identity_file); + if (!quiet) { + printf("Your public key has been saved in %s.\n", identity_file); + printf("The key fingerprint is:\n"); + printf("%d %s %s\n", BN_num_bits(public_key->n), + fingerprint(public_key->e, public_key->n), + comment); + } exit(0); } |