summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>1999-11-22 13:22:29 +1100
committerDamien Miller <djm@mindrot.org>1999-11-22 13:22:29 +1100
commit83df0693331918f067f7c3501f1229272d2b00e9 (patch)
treedb3af83438955f545a2672c1d136e0b0b3775e1b
parent22218727fdf4ad356b7ad9ec5f4406e31858db1d (diff)
- OpenBSD CVS Changes
- [ssh-keygen.c] 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@
-rw-r--r--ChangeLog7
-rw-r--r--ssh-keygen.c56
2 files changed, 33 insertions, 30 deletions
diff --git a/ChangeLog b/ChangeLog
index 840369f2f..980331711 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,13 @@
119991122 119991122
2 - Make <enter> close gnome-ssh-askpass (Debian bug #50299) 2 - Make <enter> close gnome-ssh-askpass (Debian bug #50299)
3 - OpenBSD CVS Changes
4 - [ssh-keygen.c]
5 don't create ~/.ssh only if the user wants to store the private
6 key there. show fingerprint instead of public-key after
7 keygeneration. ok niels@
3 8
419991121 919991121
5 - OpenBSD CVS Changes 10 - OpenBSD CVS Changes:
6 - [channels.c] 11 - [channels.c]
7 make this compile, bad markus 12 make this compile, bad markus
8 - [log.c readconf.c servconf.c ssh.h] 13 - [log.c readconf.c servconf.c ssh.h]
diff --git a/ssh-keygen.c b/ssh-keygen.c
index 596da76fb..47e1cca07 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -14,7 +14,7 @@ Identity and host key generation and maintenance.
14*/ 14*/
15 15
16#include "includes.h" 16#include "includes.h"
17RCSID("$Id: ssh-keygen.c,v 1.7 1999/11/21 07:31:57 damien Exp $"); 17RCSID("$Id: ssh-keygen.c,v 1.8 1999/11/22 02:22:29 damien Exp $");
18 18
19#include "rsa.h" 19#include "rsa.h"
20#include "ssh.h" 20#include "ssh.h"
@@ -363,7 +363,7 @@ usage(void)
363int 363int
364main(int ac, char **av) 364main(int ac, char **av)
365{ 365{
366 char buf[16384], buf2[1024], *passphrase1, *passphrase2; 366 char dotsshdir[16*1024], comment[1024], *passphrase1, *passphrase2;
367 struct passwd *pw; 367 struct passwd *pw;
368 char *tmpbuf; 368 char *tmpbuf;
369 int opt; 369 int opt;
@@ -391,12 +391,6 @@ main(int ac, char **av)
391 exit(1); 391 exit(1);
392 } 392 }
393 393
394 /* Create ~/.ssh directory if it doesn\'t already exist. */
395 snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir, SSH_USER_DIR);
396 if (stat(buf, &st) < 0)
397 if (mkdir(buf, 0755) < 0)
398 error("Could not create directory '%s'.", buf);
399
400 /* Parse command line arguments. */ 394 /* Parse command line arguments. */
401 while ((opt = getopt(ac, av, "qpclb:f:P:N:C:")) != EOF) 395 while ((opt = getopt(ac, av, "qpclb:f:P:N:C:")) != EOF)
402 { 396 {
@@ -486,15 +480,26 @@ main(int ac, char **av)
486 if (!have_identity) 480 if (!have_identity)
487 ask_filename(pw, "Enter file in which to save the key"); 481 ask_filename(pw, "Enter file in which to save the key");
488 482
489 /* If the file aready exists, ask the user to confirm. */ 483 /* Create ~/.ssh directory if it doesn\'t already exist. */
484 snprintf(dotsshdir, sizeof dotsshdir, "%s/%s", pw->pw_dir, SSH_USER_DIR);
485 if (strstr(identity_file, dotsshdir) != NULL &&
486 stat(dotsshdir, &st) < 0) {
487 if (mkdir(dotsshdir, 0755) < 0)
488 error("Could not create directory '%s'.", dotsshdir);
489 else if(!quiet)
490 printf("Created directory '%s'.\n", dotsshdir);
491 }
492
493 /* If the file already exists, ask the user to confirm. */
490 if (stat(identity_file, &st) >= 0) 494 if (stat(identity_file, &st) >= 0)
491 { 495 {
496 char yesno[3];
492 printf("%s already exists.\n", identity_file); 497 printf("%s already exists.\n", identity_file);
493 printf("Overwrite (y/n)? "); 498 printf("Overwrite (y/n)? ");
494 fflush(stdout); 499 fflush(stdout);
495 if (fgets(buf2, sizeof(buf2), stdin) == NULL) 500 if (fgets(yesno, sizeof(yesno), stdin) == NULL)
496 exit(1); 501 exit(1);
497 if (buf2[0] != 'y' && buf2[0] != 'Y') 502 if (yesno[0] != 'y' && yesno[0] != 'Y')
498 exit(1); 503 exit(1);
499 } 504 }
500 505
@@ -529,7 +534,7 @@ main(int ac, char **av)
529 edit this field. */ 534 edit this field. */
530 if (identity_comment) 535 if (identity_comment)
531 { 536 {
532 strlcpy(buf2, identity_comment, sizeof(buf2)); 537 strlcpy(comment, identity_comment, sizeof(comment));
533 } 538 }
534 else 539 else
535 { 540 {
@@ -538,11 +543,11 @@ main(int ac, char **av)
538 perror("gethostname"); 543 perror("gethostname");
539 exit(1); 544 exit(1);
540 } 545 }
541 snprintf(buf2, sizeof buf2, "%s@%s", pw->pw_name, hostname); 546 snprintf(comment, sizeof comment, "%s@%s", pw->pw_name, hostname);
542 } 547 }
543 548
544 /* Save the key with the given passphrase and comment. */ 549 /* Save the key with the given passphrase and comment. */
545 if (!save_private_key(identity_file, passphrase1, private_key, buf2)) 550 if (!save_private_key(identity_file, passphrase1, private_key, comment))
546 { 551 {
547 printf("Saving the key failed: %s: %s.\n", 552 printf("Saving the key failed: %s: %s.\n",
548 identity_file, strerror(errno)); 553 identity_file, strerror(errno));
@@ -561,18 +566,6 @@ main(int ac, char **av)
561 if (!quiet) 566 if (!quiet)
562 printf("Your identification has been saved in %s.\n", identity_file); 567 printf("Your identification has been saved in %s.\n", identity_file);
563 568
564 /* Display the public key on the screen. */
565 if (!quiet) {
566 printf("Your public key is:\n");
567 printf("%d ", BN_num_bits(public_key->n));
568 tmpbuf = BN_bn2dec(public_key->e);
569 printf("%s ", tmpbuf);
570 free(tmpbuf);
571 tmpbuf = BN_bn2dec(public_key->n);
572 printf("%s %s\n", tmpbuf, buf2);
573 free(tmpbuf);
574 }
575
576 /* Save the public key in text format in a file with the same name but 569 /* Save the public key in text format in a file with the same name but
577 .pub appended. */ 570 .pub appended. */
578 strlcat(identity_file, ".pub", sizeof(identity_file)); 571 strlcat(identity_file, ".pub", sizeof(identity_file));
@@ -587,12 +580,17 @@ main(int ac, char **av)
587 fprintf(f, "%s ", tmpbuf); 580 fprintf(f, "%s ", tmpbuf);
588 free(tmpbuf); 581 free(tmpbuf);
589 tmpbuf = BN_bn2dec(public_key->n); 582 tmpbuf = BN_bn2dec(public_key->n);
590 fprintf(f, "%s %s\n", tmpbuf, buf2); 583 fprintf(f, "%s %s\n", tmpbuf, comment);
591 free(tmpbuf); 584 free(tmpbuf);
592 fclose(f); 585 fclose(f);
593 586
594 if (!quiet) 587 if (!quiet) {
595 printf("Your public key has been saved in %s\n", identity_file); 588 printf("Your public key has been saved in %s.\n", identity_file);
589 printf("The key fingerprint is:\n");
590 printf("%d %s %s\n", BN_num_bits(public_key->n),
591 fingerprint(public_key->e, public_key->n),
592 comment);
593 }
596 594
597 exit(0); 595 exit(0);
598} 596}