diff options
Diffstat (limited to 'ssh-keygen.c')
-rw-r--r-- | ssh-keygen.c | 126 |
1 files changed, 61 insertions, 65 deletions
diff --git a/ssh-keygen.c b/ssh-keygen.c index 14eee6f87..121f94060 100644 --- a/ssh-keygen.c +++ b/ssh-keygen.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssh-keygen.c,v 1.190 2010/05/20 23:46:02 djm Exp $ */ | 1 | /* $OpenBSD: ssh-keygen.c,v 1.191 2010/06/22 04:32:06 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -414,11 +414,8 @@ do_convert_from_ssh2(struct passwd *pw) | |||
414 | perror(identity_file); | 414 | perror(identity_file); |
415 | exit(1); | 415 | exit(1); |
416 | } | 416 | } |
417 | fp = fopen(identity_file, "r"); | 417 | if ((fp = fopen(identity_file, "r")) == NULL) |
418 | if (fp == NULL) { | 418 | fatal("%s: %s: %s", __progname, identity_file, strerror(errno)); |
419 | perror(identity_file); | ||
420 | exit(1); | ||
421 | } | ||
422 | encoded[0] = '\0'; | 419 | encoded[0] = '\0'; |
423 | while ((blen = get_line(fp, line, sizeof(line))) != -1) { | 420 | while ((blen = get_line(fp, line, sizeof(line))) != -1) { |
424 | if (line[blen - 1] == '\\') | 421 | if (line[blen - 1] == '\\') |
@@ -561,67 +558,68 @@ do_fingerprint(struct passwd *pw) | |||
561 | comment = NULL; | 558 | comment = NULL; |
562 | } | 559 | } |
563 | 560 | ||
564 | f = fopen(identity_file, "r"); | 561 | if ((f = fopen(identity_file, "r")) == NULL) |
565 | if (f != NULL) { | 562 | fatal("%s: %s: %s", __progname, identity_file, strerror(errno)); |
566 | while (fgets(line, sizeof(line), f)) { | ||
567 | if ((cp = strchr(line, '\n')) == NULL) { | ||
568 | error("line %d too long: %.40s...", | ||
569 | num + 1, line); | ||
570 | skip = 1; | ||
571 | continue; | ||
572 | } | ||
573 | num++; | ||
574 | if (skip) { | ||
575 | skip = 0; | ||
576 | continue; | ||
577 | } | ||
578 | *cp = '\0'; | ||
579 | 563 | ||
580 | /* Skip leading whitespace, empty and comment lines. */ | 564 | while (fgets(line, sizeof(line), f)) { |
581 | for (cp = line; *cp == ' ' || *cp == '\t'; cp++) | 565 | if ((cp = strchr(line, '\n')) == NULL) { |
582 | ; | 566 | error("line %d too long: %.40s...", |
583 | if (!*cp || *cp == '\n' || *cp == '#') | 567 | num + 1, line); |
584 | continue; | 568 | skip = 1; |
585 | i = strtol(cp, &ep, 10); | 569 | continue; |
586 | if (i == 0 || ep == NULL || (*ep != ' ' && *ep != '\t')) { | 570 | } |
587 | int quoted = 0; | 571 | num++; |
588 | comment = cp; | 572 | if (skip) { |
589 | for (; *cp && (quoted || (*cp != ' ' && | 573 | skip = 0; |
590 | *cp != '\t')); cp++) { | 574 | continue; |
591 | if (*cp == '\\' && cp[1] == '"') | 575 | } |
592 | cp++; /* Skip both */ | 576 | *cp = '\0'; |
593 | else if (*cp == '"') | 577 | |
594 | quoted = !quoted; | 578 | /* Skip leading whitespace, empty and comment lines. */ |
595 | } | 579 | for (cp = line; *cp == ' ' || *cp == '\t'; cp++) |
596 | if (!*cp) | 580 | ; |
597 | continue; | 581 | if (!*cp || *cp == '\n' || *cp == '#') |
598 | *cp++ = '\0'; | 582 | continue; |
583 | i = strtol(cp, &ep, 10); | ||
584 | if (i == 0 || ep == NULL || (*ep != ' ' && *ep != '\t')) { | ||
585 | int quoted = 0; | ||
586 | comment = cp; | ||
587 | for (; *cp && (quoted || (*cp != ' ' && | ||
588 | *cp != '\t')); cp++) { | ||
589 | if (*cp == '\\' && cp[1] == '"') | ||
590 | cp++; /* Skip both */ | ||
591 | else if (*cp == '"') | ||
592 | quoted = !quoted; | ||
599 | } | 593 | } |
600 | ep = cp; | 594 | if (!*cp) |
601 | public = key_new(KEY_RSA1); | 595 | continue; |
596 | *cp++ = '\0'; | ||
597 | } | ||
598 | ep = cp; | ||
599 | public = key_new(KEY_RSA1); | ||
600 | if (key_read(public, &cp) != 1) { | ||
601 | cp = ep; | ||
602 | key_free(public); | ||
603 | public = key_new(KEY_UNSPEC); | ||
602 | if (key_read(public, &cp) != 1) { | 604 | if (key_read(public, &cp) != 1) { |
603 | cp = ep; | ||
604 | key_free(public); | 605 | key_free(public); |
605 | public = key_new(KEY_UNSPEC); | 606 | continue; |
606 | if (key_read(public, &cp) != 1) { | ||
607 | key_free(public); | ||
608 | continue; | ||
609 | } | ||
610 | } | 607 | } |
611 | comment = *cp ? cp : comment; | ||
612 | fp = key_fingerprint(public, fptype, rep); | ||
613 | ra = key_fingerprint(public, SSH_FP_MD5, SSH_FP_RANDOMART); | ||
614 | printf("%u %s %s (%s)\n", key_size(public), fp, | ||
615 | comment ? comment : "no comment", key_type(public)); | ||
616 | if (log_level >= SYSLOG_LEVEL_VERBOSE) | ||
617 | printf("%s\n", ra); | ||
618 | xfree(ra); | ||
619 | xfree(fp); | ||
620 | key_free(public); | ||
621 | invalid = 0; | ||
622 | } | 608 | } |
623 | fclose(f); | 609 | comment = *cp ? cp : comment; |
610 | fp = key_fingerprint(public, fptype, rep); | ||
611 | ra = key_fingerprint(public, SSH_FP_MD5, SSH_FP_RANDOMART); | ||
612 | printf("%u %s %s (%s)\n", key_size(public), fp, | ||
613 | comment ? comment : "no comment", key_type(public)); | ||
614 | if (log_level >= SYSLOG_LEVEL_VERBOSE) | ||
615 | printf("%s\n", ra); | ||
616 | xfree(ra); | ||
617 | xfree(fp); | ||
618 | key_free(public); | ||
619 | invalid = 0; | ||
624 | } | 620 | } |
621 | fclose(f); | ||
622 | |||
625 | if (invalid) { | 623 | if (invalid) { |
626 | printf("%s is not a public key file.\n", identity_file); | 624 | printf("%s is not a public key file.\n", identity_file); |
627 | exit(1); | 625 | exit(1); |
@@ -676,7 +674,7 @@ do_known_hosts(struct passwd *pw, const char *name) | |||
676 | have_identity = 1; | 674 | have_identity = 1; |
677 | } | 675 | } |
678 | if ((in = fopen(identity_file, "r")) == NULL) | 676 | if ((in = fopen(identity_file, "r")) == NULL) |
679 | fatal("fopen: %s", strerror(errno)); | 677 | fatal("%s: %s: %s", __progname, identity_file, strerror(errno)); |
680 | 678 | ||
681 | /* | 679 | /* |
682 | * Find hosts goes to stdout, hash and deletions happen in-place | 680 | * Find hosts goes to stdout, hash and deletions happen in-place |
@@ -1423,10 +1421,8 @@ do_show_cert(struct passwd *pw) | |||
1423 | 1421 | ||
1424 | if (!have_identity) | 1422 | if (!have_identity) |
1425 | ask_filename(pw, "Enter file in which the key is"); | 1423 | ask_filename(pw, "Enter file in which the key is"); |
1426 | if (stat(identity_file, &st) < 0) { | 1424 | if (stat(identity_file, &st) < 0) |
1427 | perror(identity_file); | 1425 | fatal("%s: %s: %s", __progname, identity_file, strerror(errno)); |
1428 | exit(1); | ||
1429 | } | ||
1430 | if ((key = key_load_public(identity_file, NULL)) == NULL) | 1426 | if ((key = key_load_public(identity_file, NULL)) == NULL) |
1431 | fatal("%s is not a public key", identity_file); | 1427 | fatal("%s is not a public key", identity_file); |
1432 | if (!key_is_cert(key)) | 1428 | if (!key_is_cert(key)) |