summaryrefslogtreecommitdiff
path: root/ssh-keygen.c
diff options
context:
space:
mode:
Diffstat (limited to 'ssh-keygen.c')
-rw-r--r--ssh-keygen.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/ssh-keygen.c b/ssh-keygen.c
index e74d3cd37..1156a010a 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -12,7 +12,7 @@
12 */ 12 */
13 13
14#include "includes.h" 14#include "includes.h"
15RCSID("$OpenBSD: ssh-keygen.c,v 1.108 2003/08/14 16:08:58 markus Exp $"); 15RCSID("$OpenBSD: ssh-keygen.c,v 1.113 2003/12/22 09:16:58 djm Exp $");
16 16
17#include <openssl/evp.h> 17#include <openssl/evp.h>
18#include <openssl/pem.h> 18#include <openssl/pem.h>
@@ -32,9 +32,7 @@ RCSID("$OpenBSD: ssh-keygen.c,v 1.108 2003/08/14 16:08:58 markus Exp $");
32#ifdef SMARTCARD 32#ifdef SMARTCARD
33#include "scard.h" 33#include "scard.h"
34#endif 34#endif
35#ifdef DNS
36#include "dns.h" 35#include "dns.h"
37#endif
38 36
39/* Number of bits in the RSA/DSA key. This value can be changed on the command line. */ 37/* Number of bits in the RSA/DSA key. This value can be changed on the command line. */
40int bits = 1024; 38int bits = 1024;
@@ -191,8 +189,8 @@ do_convert_to_ssh2(struct passwd *pw)
191static void 189static void
192buffer_get_bignum_bits(Buffer *b, BIGNUM *value) 190buffer_get_bignum_bits(Buffer *b, BIGNUM *value)
193{ 191{
194 int bits = buffer_get_int(b); 192 u_int bits = buffer_get_int(b);
195 int bytes = (bits + 7) / 8; 193 u_int bytes = (bits + 7) / 8;
196 194
197 if (buffer_len(b) < bytes) 195 if (buffer_len(b) < bytes)
198 fatal("buffer_get_bignum_bits: input buffer too small: " 196 fatal("buffer_get_bignum_bits: input buffer too small: "
@@ -625,7 +623,6 @@ do_change_passphrase(struct passwd *pw)
625 exit(0); 623 exit(0);
626} 624}
627 625
628#ifdef DNS
629/* 626/*
630 * Print the SSHFP RR. 627 * Print the SSHFP RR.
631 */ 628 */
@@ -655,7 +652,6 @@ do_print_resource_record(struct passwd *pw, char *hostname)
655 printf("failed to read v2 public key from %s.\n", identity_file); 652 printf("failed to read v2 public key from %s.\n", identity_file);
656 exit(1); 653 exit(1);
657} 654}
658#endif /* DNS */
659 655
660/* 656/*
661 * Change the comment of a private key file. 657 * Change the comment of a private key file.
@@ -774,9 +770,7 @@ usage(void)
774 fprintf(stderr, " -C comment Provide new comment.\n"); 770 fprintf(stderr, " -C comment Provide new comment.\n");
775 fprintf(stderr, " -N phrase Provide new passphrase.\n"); 771 fprintf(stderr, " -N phrase Provide new passphrase.\n");
776 fprintf(stderr, " -P phrase Provide old passphrase.\n"); 772 fprintf(stderr, " -P phrase Provide old passphrase.\n");
777#ifdef DNS
778 fprintf(stderr, " -r hostname Print DNS resource record.\n"); 773 fprintf(stderr, " -r hostname Print DNS resource record.\n");
779#endif /* DNS */
780#ifdef SMARTCARD 774#ifdef SMARTCARD
781 fprintf(stderr, " -D reader Download public key from smartcard.\n"); 775 fprintf(stderr, " -D reader Download public key from smartcard.\n");
782 fprintf(stderr, " -U reader Upload private key to smartcard.\n"); 776 fprintf(stderr, " -U reader Upload private key to smartcard.\n");
@@ -803,6 +797,7 @@ main(int ac, char **av)
803 int opt, type, fd, download = 0, memory = 0; 797 int opt, type, fd, download = 0, memory = 0;
804 int generator_wanted = 0, trials = 100; 798 int generator_wanted = 0, trials = 100;
805 int do_gen_candidates = 0, do_screen_candidates = 0; 799 int do_gen_candidates = 0, do_screen_candidates = 0;
800 int log_level = SYSLOG_LEVEL_INFO;
806 BIGNUM *start = NULL; 801 BIGNUM *start = NULL;
807 FILE *f; 802 FILE *f;
808 803
@@ -829,7 +824,7 @@ main(int ac, char **av)
829 } 824 }
830 825
831 while ((opt = getopt(ac, av, 826 while ((opt = getopt(ac, av,
832 "degiqpclBRxXyb:f:t:U:D:P:N:C:r:g:T:G:M:S:a:W:")) != -1) { 827 "degiqpclBRvxXyb:f:t:U:D:P:N:C:r:g:T:G:M:S:a:W:")) != -1) {
833 switch (opt) { 828 switch (opt) {
834 case 'b': 829 case 'b':
835 bits = atoi(optarg); 830 bits = atoi(optarg);
@@ -897,6 +892,15 @@ main(int ac, char **av)
897 case 'U': 892 case 'U':
898 reader_id = optarg; 893 reader_id = optarg;
899 break; 894 break;
895 case 'v':
896 if (log_level == SYSLOG_LEVEL_INFO)
897 log_level = SYSLOG_LEVEL_DEBUG1;
898 else {
899 if (log_level >= SYSLOG_LEVEL_DEBUG1 &&
900 log_level < SYSLOG_LEVEL_DEBUG3)
901 log_level++;
902 }
903 break;
900 case 'r': 904 case 'r':
901 resource_record_hostname = optarg; 905 resource_record_hostname = optarg;
902 break; 906 break;
@@ -908,13 +912,13 @@ main(int ac, char **av)
908 case 'a': 912 case 'a':
909 trials = atoi(optarg); 913 trials = atoi(optarg);
910 if (trials < TRIAL_MINIMUM) { 914 if (trials < TRIAL_MINIMUM) {
911 fatal("Minimum primality trials is %d", 915 fatal("Minimum primality trials is %d",
912 TRIAL_MINIMUM); 916 TRIAL_MINIMUM);
913 } 917 }
914 break; 918 break;
915 case 'M': 919 case 'M':
916 memory = atoi(optarg); 920 memory = atoi(optarg);
917 if (memory != 0 && 921 if (memory != 0 &&
918 (memory < LARGE_MINIMUM || memory > LARGE_MAXIMUM)) { 922 (memory < LARGE_MINIMUM || memory > LARGE_MAXIMUM)) {
919 fatal("Invalid memory amount (min %ld, max %ld)", 923 fatal("Invalid memory amount (min %ld, max %ld)",
920 LARGE_MINIMUM, LARGE_MAXIMUM); 924 LARGE_MINIMUM, LARGE_MAXIMUM);
@@ -938,6 +942,10 @@ main(int ac, char **av)
938 usage(); 942 usage();
939 } 943 }
940 } 944 }
945
946 /* reinit */
947 log_init(av[0], log_level, SYSLOG_FACILITY_USER, 1);
948
941 if (optind < ac) { 949 if (optind < ac) {
942 printf("Too many arguments.\n"); 950 printf("Too many arguments.\n");
943 usage(); 951 usage();
@@ -959,11 +967,7 @@ main(int ac, char **av)
959 if (print_public) 967 if (print_public)
960 do_print_public(pw); 968 do_print_public(pw);
961 if (resource_record_hostname != NULL) { 969 if (resource_record_hostname != NULL) {
962#ifdef DNS
963 do_print_resource_record(pw, resource_record_hostname); 970 do_print_resource_record(pw, resource_record_hostname);
964#else /* DNS */
965 fatal("no DNS support.");
966#endif /* DNS */
967 } 971 }
968 if (reader_id != NULL) { 972 if (reader_id != NULL) {
969#ifdef SMARTCARD 973#ifdef SMARTCARD
@@ -978,7 +982,7 @@ main(int ac, char **av)
978 982
979 if (do_gen_candidates) { 983 if (do_gen_candidates) {
980 FILE *out = fopen(out_file, "w"); 984 FILE *out = fopen(out_file, "w");
981 985
982 if (out == NULL) { 986 if (out == NULL) {
983 error("Couldn't open modulus candidate file \"%s\": %s", 987 error("Couldn't open modulus candidate file \"%s\": %s",
984 out_file, strerror(errno)); 988 out_file, strerror(errno));
@@ -997,7 +1001,7 @@ main(int ac, char **av)
997 if (have_identity && strcmp(identity_file, "-") != 0) { 1001 if (have_identity && strcmp(identity_file, "-") != 0) {
998 if ((in = fopen(identity_file, "r")) == NULL) { 1002 if ((in = fopen(identity_file, "r")) == NULL) {
999 fatal("Couldn't open modulus candidate " 1003 fatal("Couldn't open modulus candidate "
1000 "file \"%s\": %s", identity_file, 1004 "file \"%s\": %s", identity_file,
1001 strerror(errno)); 1005 strerror(errno));
1002 } 1006 }
1003 } else 1007 } else