comparison dropbearkey.c @ 841:d4ce5269a439 ecc

Fix specifying a keysize for key generation, fix key name arguments
author Matt Johnston <matt@ucc.asn.au>
date Fri, 01 Nov 2013 00:13:09 +0800
parents 5128e525c8fa
children b298bb438625
comparison
equal deleted inserted replaced
840:5128e525c8fa 841:d4ce5269a439
183 fprintf(stderr, "Must specify key type\n"); 183 fprintf(stderr, "Must specify key type\n");
184 printhelp(argv[0]); 184 printhelp(argv[0]);
185 exit(EXIT_FAILURE); 185 exit(EXIT_FAILURE);
186 } 186 }
187 187
188 keytype = signkey_type_from_name(typetext, strlen(typetext)); 188 #ifdef DROPBEAR_RSA
189 if (strcmp(typetext, "rsa") == 0)
190 {
191 keytype = DROPBEAR_SIGNKEY_RSA;
192 }
193 #endif
194 #ifdef DROPBEAR_DSS
195 if (strcmp(typetext, "dss") == 0)
196 {
197 keytype = DROPBEAR_SIGNKEY_DSS;
198 }
199 #endif
200 #ifdef DROPBEAR_ECDSA
201 if (strcmp(typetext, "ecdsa") == 0)
202 {
203 keytype = DROPBEAR_SIGNKEY_ECDSA_KEYGEN;
204 }
205 #endif
189 206
190 if (keytype == DROPBEAR_SIGNKEY_NONE) { 207 if (keytype == DROPBEAR_SIGNKEY_NONE) {
191 fprintf(stderr, "Unknown key type '%s'\n", typetext); 208 fprintf(stderr, "Unknown key type '%s'\n", typetext);
192 printhelp(argv[0]); 209 printhelp(argv[0]);
193 exit(EXIT_FAILURE); 210 exit(EXIT_FAILURE);
219 #endif 236 #endif
220 default: 237 default:
221 (void)0; /* quiet, compiler. ecdsa handles checks itself */ 238 (void)0; /* quiet, compiler. ecdsa handles checks itself */
222 } 239 }
223 240
241 } else {
242 /* default key size */
243
224 switch (keytype) { 244 switch (keytype) {
225 #ifdef DROPBEAR_RSA 245 #ifdef DROPBEAR_RSA
226 case DROPBEAR_SIGNKEY_RSA: 246 case DROPBEAR_SIGNKEY_RSA:
227 bits = RSA_DEFAULT_SIZE; 247 bits = RSA_DEFAULT_SIZE;
228 break; 248 break;
229 #endif 249 #endif
230 #ifdef DROPBEAR_DSS 250 #ifdef DROPBEAR_DSS
231 case DROPBEAR_SIGNKEY_DSS: 251 case DROPBEAR_SIGNKEY_DSS:
232 bits = DSS_DEFAULT_SIZE; 252 bits = DSS_DEFAULT_SIZE;
267 #ifdef DROPBEAR_ECDSA 287 #ifdef DROPBEAR_ECDSA
268 case DROPBEAR_SIGNKEY_ECDSA_KEYGEN: 288 case DROPBEAR_SIGNKEY_ECDSA_KEYGEN:
269 { 289 {
270 ecc_key *ecckey = gen_ecdsa_priv_key(bits); 290 ecc_key *ecckey = gen_ecdsa_priv_key(bits);
271 keytype = ecdsa_signkey_type(ecckey); 291 keytype = ecdsa_signkey_type(ecckey);
272 *signkey_ecc_key_ptr(key, keytype) = ecckey; 292 *signkey_key_ptr(key, keytype) = ecckey;
273 } 293 }
274 break; 294 break;
275 #endif 295 #endif
276 default: 296 default:
277 fprintf(stderr, "Internal error, bad key type\n"); 297 fprintf(stderr, "Internal error, bad key type\n");
297 317
298 static void justprintpub(const char* filename) { 318 static void justprintpub(const char* filename) {
299 319
300 buffer *buf = NULL; 320 buffer *buf = NULL;
301 sign_key *key = NULL; 321 sign_key *key = NULL;
302 int keytype; 322 enum signkey_type keytype;
303 int ret; 323 int ret;
304 int err = DROPBEAR_FAILURE; 324 int err = DROPBEAR_FAILURE;
305 325
306 buf = buf_new(MAX_PRIVKEY_SIZE); 326 buf = buf_new(MAX_PRIVKEY_SIZE);
307 ret = buf_readfile(buf, filename); 327 ret = buf_readfile(buf, filename);