comparison dropbearkey.c @ 1355:3fdd8c5a0195 fuzz

merge main to fuzz
author Matt Johnston <matt@ucc.asn.au>
date Thu, 18 May 2017 23:45:10 +0800
parents bbc0a0ee3843
children e8f67918fdc9
comparison
equal deleted inserted replaced
1354:7618759e9327 1355:3fdd8c5a0195
65 /* Print a help message */ 65 /* Print a help message */
66 static void printhelp(char * progname) { 66 static void printhelp(char * progname) {
67 67
68 fprintf(stderr, "Usage: %s -t <type> -f <filename> [-s bits]\n" 68 fprintf(stderr, "Usage: %s -t <type> -f <filename> [-s bits]\n"
69 "-t type Type of key to generate. One of:\n" 69 "-t type Type of key to generate. One of:\n"
70 #ifdef DROPBEAR_RSA 70 #if DROPBEAR_RSA
71 " rsa\n" 71 " rsa\n"
72 #endif 72 #endif
73 #ifdef DROPBEAR_DSS 73 #if DROPBEAR_DSS
74 " dss\n" 74 " dss\n"
75 #endif 75 #endif
76 #ifdef DROPBEAR_ECDSA 76 #if DROPBEAR_ECDSA
77 " ecdsa\n" 77 " ecdsa\n"
78 #endif 78 #endif
79 "-f filename Use filename for the secret key.\n" 79 "-f filename Use filename for the secret key.\n"
80 " ~/.ssh/id_dropbear is recommended for client keys.\n" 80 " ~/.ssh/id_dropbear is recommended for client keys.\n"
81 "-s bits Key size in bits, should be a multiple of 8 (optional)\n" 81 "-s bits Key size in bits, should be a multiple of 8 (optional)\n"
82 #ifdef DROPBEAR_DSS 82 #if DROPBEAR_DSS
83 " DSS has a fixed size of 1024 bits\n" 83 " DSS has a fixed size of 1024 bits\n"
84 #endif 84 #endif
85 #ifdef DROPBEAR_ECDSA 85 #if DROPBEAR_ECDSA
86 " ECDSA has sizes " 86 " ECDSA has sizes "
87 #ifdef DROPBEAR_ECC_256 87 #if DROPBEAR_ECC_256
88 "256 " 88 "256 "
89 #endif 89 #endif
90 #ifdef DROPBEAR_ECC_384 90 #if DROPBEAR_ECC_384
91 "384 " 91 "384 "
92 #endif 92 #endif
93 #ifdef DROPBEAR_ECC_521 93 #if DROPBEAR_ECC_521
94 "521 " 94 "521 "
95 #endif 95 #endif
96 "\n" 96 "\n"
97 #endif 97 #endif
98 "-y Just print the publickey and fingerprint for the\n private key in <filename>.\n" 98 "-y Just print the publickey and fingerprint for the\n private key in <filename>.\n"
99 #ifdef DEBUG_TRACE 99 #if DEBUG_TRACE
100 "-v verbose\n" 100 "-v verbose\n"
101 #endif 101 #endif
102 ,progname); 102 ,progname);
103 } 103 }
104 104
105 /* fails fatally */ 105 /* fails fatally */
106 static void check_signkey_bits(enum signkey_type type, int bits) 106 static void check_signkey_bits(enum signkey_type type, int bits)
107 { 107 {
108 switch (type) { 108 switch (type) {
109 #ifdef DROPBEAR_RSA 109 #if DROPBEAR_RSA
110 case DROPBEAR_SIGNKEY_RSA: 110 case DROPBEAR_SIGNKEY_RSA:
111 if (bits < 512 || bits > 4096 || (bits % 8 != 0)) { 111 if (bits < 512 || bits > 4096 || (bits % 8 != 0)) {
112 dropbear_exit("Bits must satisfy 512 <= bits <= 4096, and be a" 112 dropbear_exit("Bits must satisfy 512 <= bits <= 4096, and be a"
113 " multiple of 8\n"); 113 " multiple of 8\n");
114 } 114 }
124 default: 124 default:
125 (void)0; /* quiet, compiler. ecdsa handles checks itself */ 125 (void)0; /* quiet, compiler. ecdsa handles checks itself */
126 } 126 }
127 } 127 }
128 128
129 #if defined(DBMULTI_dropbearkey) || !defined(DROPBEAR_MULTI) 129 #if defined(DBMULTI_dropbearkey) || !DROPBEAR_MULTI
130 #if defined(DBMULTI_dropbearkey) && defined(DROPBEAR_MULTI) 130 #if defined(DBMULTI_dropbearkey) && DROPBEAR_MULTI
131 int dropbearkey_main(int argc, char ** argv) { 131 int dropbearkey_main(int argc, char ** argv) {
132 #else 132 #else
133 int main(int argc, char ** argv) { 133 int main(int argc, char ** argv) {
134 #endif 134 #endif
135 135
172 break; 172 break;
173 case 'h': 173 case 'h':
174 printhelp(argv[0]); 174 printhelp(argv[0]);
175 exit(EXIT_SUCCESS); 175 exit(EXIT_SUCCESS);
176 break; 176 break;
177 #ifdef DEBUG_TRACE 177 #if DEBUG_TRACE
178 case 'v': 178 case 'v':
179 debug_trace = 1; 179 debug_trace = 1;
180 break; 180 break;
181 #endif 181 #endif
182 default: 182 default:
204 fprintf(stderr, "Must specify key type\n"); 204 fprintf(stderr, "Must specify key type\n");
205 printhelp(argv[0]); 205 printhelp(argv[0]);
206 exit(EXIT_FAILURE); 206 exit(EXIT_FAILURE);
207 } 207 }
208 208
209 #ifdef DROPBEAR_RSA 209 #if DROPBEAR_RSA
210 if (strcmp(typetext, "rsa") == 0) 210 if (strcmp(typetext, "rsa") == 0)
211 { 211 {
212 keytype = DROPBEAR_SIGNKEY_RSA; 212 keytype = DROPBEAR_SIGNKEY_RSA;
213 } 213 }
214 #endif 214 #endif
215 #ifdef DROPBEAR_DSS 215 #if DROPBEAR_DSS
216 if (strcmp(typetext, "dss") == 0) 216 if (strcmp(typetext, "dss") == 0)
217 { 217 {
218 keytype = DROPBEAR_SIGNKEY_DSS; 218 keytype = DROPBEAR_SIGNKEY_DSS;
219 } 219 }
220 #endif 220 #endif
221 #ifdef DROPBEAR_ECDSA 221 #if DROPBEAR_ECDSA
222 if (strcmp(typetext, "ecdsa") == 0) 222 if (strcmp(typetext, "ecdsa") == 0)
223 { 223 {
224 keytype = DROPBEAR_SIGNKEY_ECDSA_KEYGEN; 224 keytype = DROPBEAR_SIGNKEY_ECDSA_KEYGEN;
225 } 225 }
226 #endif 226 #endif
239 239
240 check_signkey_bits(keytype, bits);; 240 check_signkey_bits(keytype, bits);;
241 } 241 }
242 242
243 fprintf(stderr, "Generating key, this may take a while...\n"); 243 fprintf(stderr, "Generating key, this may take a while...\n");
244 if (signkey_generate(keytype, bits, filename) == DROPBEAR_FAILURE) 244 if (signkey_generate(keytype, bits, filename, 0) == DROPBEAR_FAILURE)
245 { 245 {
246 dropbear_exit("Failed to generate key.\n"); 246 dropbear_exit("Failed to generate key.\n");
247 } 247 }
248 248
249 printpubfile(filename); 249 printpubfile(filename);