OLD | NEW |
1 /* apps/engine.c -*- mode: C; c-file-style: "eay" -*- */ | 1 /* apps/engine.c -*- mode: C; c-file-style: "eay" -*- */ |
2 /* Written by Richard Levitte <richard@levitte.org> for the OpenSSL | 2 /* Written by Richard Levitte <richard@levitte.org> for the OpenSSL |
3 * project 2000. | 3 * project 2000. |
4 */ | 4 */ |
5 /* ==================================================================== | 5 /* ==================================================================== |
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | 6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved. |
7 * | 7 * |
8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
10 * are met: | 10 * are met: |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 " to load it (if -t is used)\n", | 85 " to load it (if -t is used)\n", |
86 " -post <cmd> - runs command 'cmd' against the ENGINE after loading it\n", | 86 " -post <cmd> - runs command 'cmd' against the ENGINE after loading it\n", |
87 " (only used if -t is also provided)\n", | 87 " (only used if -t is also provided)\n", |
88 " NB: -pre and -post will be applied to all ENGINEs supplied on the command\n", | 88 " NB: -pre and -post will be applied to all ENGINEs supplied on the command\n", |
89 " line, or all supported ENGINEs if none are specified.\n", | 89 " line, or all supported ENGINEs if none are specified.\n", |
90 " Eg. '-pre \"SO_PATH:/lib/libdriver.so\"' calls command \"SO_PATH\" with\n", | 90 " Eg. '-pre \"SO_PATH:/lib/libdriver.so\"' calls command \"SO_PATH\" with\n", |
91 " argument \"/lib/libdriver.so\".\n", | 91 " argument \"/lib/libdriver.so\".\n", |
92 NULL | 92 NULL |
93 }; | 93 }; |
94 | 94 |
95 static void identity(void *ptr) | 95 static void identity(char *ptr) |
96 { | 96 { |
97 return; | 97 return; |
98 } | 98 } |
99 | 99 |
100 static int append_buf(char **buf, const char *s, int *size, int step) | 100 static int append_buf(char **buf, const char *s, int *size, int step) |
101 { | 101 { |
102 int l = strlen(s); | 102 int l = strlen(s); |
103 | 103 |
104 if (*buf == NULL) | 104 if (*buf == NULL) |
105 { | 105 { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 } | 141 } |
142 /* If the object is internal, mark it in a way that shows instead of | 142 /* If the object is internal, mark it in a way that shows instead of |
143 * having it part of all the other flags, even if it really is. */ | 143 * having it part of all the other flags, even if it really is. */ |
144 if(flags & ENGINE_CMD_FLAG_INTERNAL) | 144 if(flags & ENGINE_CMD_FLAG_INTERNAL) |
145 { | 145 { |
146 BIO_printf(bio_out, "[Internal] "); | 146 BIO_printf(bio_out, "[Internal] "); |
147 } | 147 } |
148 | 148 |
149 if(flags & ENGINE_CMD_FLAG_NUMERIC) | 149 if(flags & ENGINE_CMD_FLAG_NUMERIC) |
150 { | 150 { |
151 if(started) | |
152 { | |
153 BIO_printf(bio_out, "|"); | |
154 err = 1; | |
155 } | |
156 BIO_printf(bio_out, "NUMERIC"); | 151 BIO_printf(bio_out, "NUMERIC"); |
157 started = 1; | 152 started = 1; |
158 } | 153 } |
159 /* Now we check that no combinations of the mutually exclusive NUMERIC, | 154 /* Now we check that no combinations of the mutually exclusive NUMERIC, |
160 * STRING, and NO_INPUT flags have been used. Future flags that can be | 155 * STRING, and NO_INPUT flags have been used. Future flags that can be |
161 * OR'd together with these would need to added after these to preserve | 156 * OR'd together with these would need to added after these to preserve |
162 * the testing logic. */ | 157 * the testing logic. */ |
163 if(flags & ENGINE_CMD_FLAG_STRING) | 158 if(flags & ENGINE_CMD_FLAG_STRING) |
164 { | 159 { |
165 if(started) | 160 if(started) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 193 |
199 static int util_verbose(ENGINE *e, int verbose, BIO *bio_out, const char *indent
) | 194 static int util_verbose(ENGINE *e, int verbose, BIO *bio_out, const char *indent
) |
200 { | 195 { |
201 static const int line_wrap = 78; | 196 static const int line_wrap = 78; |
202 int num; | 197 int num; |
203 int ret = 0; | 198 int ret = 0; |
204 char *name = NULL; | 199 char *name = NULL; |
205 char *desc = NULL; | 200 char *desc = NULL; |
206 int flags; | 201 int flags; |
207 int xpos = 0; | 202 int xpos = 0; |
208 » STACK *cmds = NULL; | 203 » STACK_OF(OPENSSL_STRING) *cmds = NULL; |
209 if(!ENGINE_ctrl(e, ENGINE_CTRL_HAS_CTRL_FUNCTION, 0, NULL, NULL) || | 204 if(!ENGINE_ctrl(e, ENGINE_CTRL_HAS_CTRL_FUNCTION, 0, NULL, NULL) || |
210 ((num = ENGINE_ctrl(e, ENGINE_CTRL_GET_FIRST_CMD_TYPE, | 205 ((num = ENGINE_ctrl(e, ENGINE_CTRL_GET_FIRST_CMD_TYPE, |
211 0, NULL, NULL)) <= 0)) | 206 0, NULL, NULL)) <= 0)) |
212 { | 207 { |
213 #if 0 | 208 #if 0 |
214 BIO_printf(bio_out, "%s<no control commands>\n", indent); | 209 BIO_printf(bio_out, "%s<no control commands>\n", indent); |
215 #endif | 210 #endif |
216 return 1; | 211 return 1; |
217 } | 212 } |
218 | 213 |
219 » cmds = sk_new_null(); | 214 » cmds = sk_OPENSSL_STRING_new_null(); |
220 | 215 |
221 if(!cmds) | 216 if(!cmds) |
222 goto err; | 217 goto err; |
223 do { | 218 do { |
224 int len; | 219 int len; |
225 /* Get the command input flags */ | 220 /* Get the command input flags */ |
226 if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num, | 221 if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num, |
227 NULL, NULL)) < 0) | 222 NULL, NULL)) < 0) |
228 goto err; | 223 goto err; |
229 if (!(flags & ENGINE_CMD_FLAG_INTERNAL) || verbose >= 4) | 224 if (!(flags & ENGINE_CMD_FLAG_INTERNAL) || verbose >= 4) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 OPENSSL_free(name); name = NULL; | 277 OPENSSL_free(name); name = NULL; |
283 if(desc) { OPENSSL_free(desc); desc = NULL; } | 278 if(desc) { OPENSSL_free(desc); desc = NULL; } |
284 /* Move to the next command */ | 279 /* Move to the next command */ |
285 num = ENGINE_ctrl(e, ENGINE_CTRL_GET_NEXT_CMD_TYPE, | 280 num = ENGINE_ctrl(e, ENGINE_CTRL_GET_NEXT_CMD_TYPE, |
286 num, NULL, NULL); | 281 num, NULL, NULL); |
287 } while(num > 0); | 282 } while(num > 0); |
288 if(xpos > 0) | 283 if(xpos > 0) |
289 BIO_printf(bio_out, "\n"); | 284 BIO_printf(bio_out, "\n"); |
290 ret = 1; | 285 ret = 1; |
291 err: | 286 err: |
292 » if(cmds) sk_pop_free(cmds, identity); | 287 » if(cmds) sk_OPENSSL_STRING_pop_free(cmds, identity); |
293 if(name) OPENSSL_free(name); | 288 if(name) OPENSSL_free(name); |
294 if(desc) OPENSSL_free(desc); | 289 if(desc) OPENSSL_free(desc); |
295 return ret; | 290 return ret; |
296 } | 291 } |
297 | 292 |
298 static void util_do_cmds(ENGINE *e, STACK *cmds, BIO *bio_out, const char *inden
t) | 293 static void util_do_cmds(ENGINE *e, STACK_OF(OPENSSL_STRING) *cmds, |
| 294 » » » BIO *bio_out, const char *indent) |
299 { | 295 { |
300 » int loop, res, num = sk_num(cmds); | 296 » int loop, res, num = sk_OPENSSL_STRING_num(cmds); |
| 297 |
301 if(num < 0) | 298 if(num < 0) |
302 { | 299 { |
303 BIO_printf(bio_out, "[Error]: internal stack error\n"); | 300 BIO_printf(bio_out, "[Error]: internal stack error\n"); |
304 return; | 301 return; |
305 } | 302 } |
306 for(loop = 0; loop < num; loop++) | 303 for(loop = 0; loop < num; loop++) |
307 { | 304 { |
308 char buf[256]; | 305 char buf[256]; |
309 const char *cmd, *arg; | 306 const char *cmd, *arg; |
310 » » cmd = sk_value(cmds, loop); | 307 » » cmd = sk_OPENSSL_STRING_value(cmds, loop); |
311 res = 1; /* assume success */ | 308 res = 1; /* assume success */ |
312 /* Check if this command has no ":arg" */ | 309 /* Check if this command has no ":arg" */ |
313 if((arg = strstr(cmd, ":")) == NULL) | 310 if((arg = strstr(cmd, ":")) == NULL) |
314 { | 311 { |
315 if(!ENGINE_ctrl_cmd_string(e, cmd, NULL, 0)) | 312 if(!ENGINE_ctrl_cmd_string(e, cmd, NULL, 0)) |
316 res = 0; | 313 res = 0; |
317 } | 314 } |
318 else | 315 else |
319 { | 316 { |
320 if((int)(arg - cmd) > 254) | 317 if((int)(arg - cmd) > 254) |
(...skipping 19 matching lines...) Expand all Loading... |
340 } | 337 } |
341 | 338 |
342 int MAIN(int, char **); | 339 int MAIN(int, char **); |
343 | 340 |
344 int MAIN(int argc, char **argv) | 341 int MAIN(int argc, char **argv) |
345 { | 342 { |
346 int ret=1,i; | 343 int ret=1,i; |
347 const char **pp; | 344 const char **pp; |
348 int verbose=0, list_cap=0, test_avail=0, test_avail_noise = 0; | 345 int verbose=0, list_cap=0, test_avail=0, test_avail_noise = 0; |
349 ENGINE *e; | 346 ENGINE *e; |
350 » STACK *engines = sk_new_null(); | 347 » STACK_OF(OPENSSL_STRING) *engines = sk_OPENSSL_STRING_new_null(); |
351 » STACK *pre_cmds = sk_new_null(); | 348 » STACK_OF(OPENSSL_STRING) *pre_cmds = sk_OPENSSL_STRING_new_null(); |
352 » STACK *post_cmds = sk_new_null(); | 349 » STACK_OF(OPENSSL_STRING) *post_cmds = sk_OPENSSL_STRING_new_null(); |
353 int badops=1; | 350 int badops=1; |
354 BIO *bio_out=NULL; | 351 BIO *bio_out=NULL; |
355 const char *indent = " "; | 352 const char *indent = " "; |
356 | 353 |
357 apps_startup(); | 354 apps_startup(); |
358 SSL_load_error_strings(); | 355 SSL_load_error_strings(); |
359 | 356 |
360 if (bio_err == NULL) | 357 if (bio_err == NULL) |
361 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); | 358 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); |
362 | 359 |
(...skipping 26 matching lines...) Expand all Loading... |
389 if(strspn(*argv + 1, "t") < strlen(*argv + 1)) | 386 if(strspn(*argv + 1, "t") < strlen(*argv + 1)) |
390 goto skip_arg_loop; | 387 goto skip_arg_loop; |
391 if((test_avail_noise = strlen(*argv + 1) - 1) > 1) | 388 if((test_avail_noise = strlen(*argv + 1) - 1) > 1) |
392 goto skip_arg_loop; | 389 goto skip_arg_loop; |
393 } | 390 } |
394 else if (strcmp(*argv,"-pre") == 0) | 391 else if (strcmp(*argv,"-pre") == 0) |
395 { | 392 { |
396 argc--; argv++; | 393 argc--; argv++; |
397 if (argc == 0) | 394 if (argc == 0) |
398 goto skip_arg_loop; | 395 goto skip_arg_loop; |
399 » » » sk_push(pre_cmds,*argv); | 396 » » » sk_OPENSSL_STRING_push(pre_cmds,*argv); |
400 } | 397 } |
401 else if (strcmp(*argv,"-post") == 0) | 398 else if (strcmp(*argv,"-post") == 0) |
402 { | 399 { |
403 argc--; argv++; | 400 argc--; argv++; |
404 if (argc == 0) | 401 if (argc == 0) |
405 goto skip_arg_loop; | 402 goto skip_arg_loop; |
406 » » » sk_push(post_cmds,*argv); | 403 » » » sk_OPENSSL_STRING_push(post_cmds,*argv); |
407 } | 404 } |
408 else if ((strncmp(*argv,"-h",2) == 0) || | 405 else if ((strncmp(*argv,"-h",2) == 0) || |
409 (strcmp(*argv,"-?") == 0)) | 406 (strcmp(*argv,"-?") == 0)) |
410 goto skip_arg_loop; | 407 goto skip_arg_loop; |
411 else | 408 else |
412 » » » sk_push(engines,*argv); | 409 » » » sk_OPENSSL_STRING_push(engines,*argv); |
413 argc--; | 410 argc--; |
414 argv++; | 411 argv++; |
415 } | 412 } |
416 /* Looks like everything went OK */ | 413 /* Looks like everything went OK */ |
417 badops = 0; | 414 badops = 0; |
418 skip_arg_loop: | 415 skip_arg_loop: |
419 | 416 |
420 if (badops) | 417 if (badops) |
421 { | 418 { |
422 for (pp=engine_usage; (*pp != NULL); pp++) | 419 for (pp=engine_usage; (*pp != NULL); pp++) |
423 BIO_printf(bio_err,"%s",*pp); | 420 BIO_printf(bio_err,"%s",*pp); |
424 goto end; | 421 goto end; |
425 } | 422 } |
426 | 423 |
427 » if (sk_num(engines) == 0) | 424 » if (sk_OPENSSL_STRING_num(engines) == 0) |
428 { | 425 { |
429 for(e = ENGINE_get_first(); e != NULL; e = ENGINE_get_next(e)) | 426 for(e = ENGINE_get_first(); e != NULL; e = ENGINE_get_next(e)) |
430 { | 427 { |
431 » » » sk_push(engines,(char *)ENGINE_get_id(e)); | 428 » » » sk_OPENSSL_STRING_push(engines,(char *)ENGINE_get_id(e))
; |
432 } | 429 } |
433 } | 430 } |
434 | 431 |
435 » for (i=0; i<sk_num(engines); i++) | 432 » for (i=0; i<sk_OPENSSL_STRING_num(engines); i++) |
436 { | 433 { |
437 » » const char *id = sk_value(engines,i); | 434 » » const char *id = sk_OPENSSL_STRING_value(engines,i); |
438 if ((e = ENGINE_by_id(id)) != NULL) | 435 if ((e = ENGINE_by_id(id)) != NULL) |
439 { | 436 { |
440 const char *name = ENGINE_get_name(e); | 437 const char *name = ENGINE_get_name(e); |
441 /* Do "id" first, then "name". Easier to auto-parse. */ | 438 /* Do "id" first, then "name". Easier to auto-parse. */ |
442 BIO_printf(bio_out, "(%s) %s\n", id, name); | 439 BIO_printf(bio_out, "(%s) %s\n", id, name); |
443 util_do_cmds(e, pre_cmds, bio_out, indent); | 440 util_do_cmds(e, pre_cmds, bio_out, indent); |
444 if (strcmp(ENGINE_get_id(e), id) != 0) | 441 if (strcmp(ENGINE_get_id(e), id) != 0) |
445 { | 442 { |
446 BIO_printf(bio_out, "Loaded: (%s) %s\n", | 443 BIO_printf(bio_out, "Loaded: (%s) %s\n", |
447 ENGINE_get_id(e), ENGINE_get_name(e)); | 444 ENGINE_get_id(e), ENGINE_get_name(e)); |
448 } | 445 } |
449 if (list_cap) | 446 if (list_cap) |
450 { | 447 { |
451 int cap_size = 256; | 448 int cap_size = 256; |
452 char *cap_buf = NULL; | 449 char *cap_buf = NULL; |
453 int k,n; | 450 int k,n; |
454 const int *nids; | 451 const int *nids; |
455 ENGINE_CIPHERS_PTR fn_c; | 452 ENGINE_CIPHERS_PTR fn_c; |
456 ENGINE_DIGESTS_PTR fn_d; | 453 ENGINE_DIGESTS_PTR fn_d; |
| 454 ENGINE_PKEY_METHS_PTR fn_pk; |
457 | 455 |
458 if (ENGINE_get_RSA(e) != NULL | 456 if (ENGINE_get_RSA(e) != NULL |
459 && !append_buf(&cap_buf, "RSA", | 457 && !append_buf(&cap_buf, "RSA", |
460 &cap_size, 256)) | 458 &cap_size, 256)) |
461 goto end; | 459 goto end; |
462 if (ENGINE_get_DSA(e) != NULL | 460 if (ENGINE_get_DSA(e) != NULL |
463 && !append_buf(&cap_buf, "DSA", | 461 && !append_buf(&cap_buf, "DSA", |
464 &cap_size, 256)) | 462 &cap_size, 256)) |
465 goto end; | 463 goto end; |
466 if (ENGINE_get_DH(e) != NULL | 464 if (ENGINE_get_DH(e) != NULL |
(...skipping 18 matching lines...) Expand all Loading... |
485 fn_d = ENGINE_get_digests(e); | 483 fn_d = ENGINE_get_digests(e); |
486 if(!fn_d) goto skip_digests; | 484 if(!fn_d) goto skip_digests; |
487 n = fn_d(e, NULL, &nids, 0); | 485 n = fn_d(e, NULL, &nids, 0); |
488 for(k=0 ; k < n ; ++k) | 486 for(k=0 ; k < n ; ++k) |
489 if(!append_buf(&cap_buf, | 487 if(!append_buf(&cap_buf, |
490 OBJ_nid2sn(nids[k]), | 488 OBJ_nid2sn(nids[k]), |
491 &cap_size, 256)) | 489 &cap_size, 256)) |
492 goto end; | 490 goto end; |
493 | 491 |
494 skip_digests: | 492 skip_digests: |
| 493 fn_pk = ENGINE_get_pkey_meths(e); |
| 494 if(!fn_pk) goto skip_pmeths; |
| 495 n = fn_pk(e, NULL, &nids, 0); |
| 496 for(k=0 ; k < n ; ++k) |
| 497 if(!append_buf(&cap_buf, |
| 498 OBJ_nid2sn(nids[k]), |
| 499 &cap_size, 256)) |
| 500 goto end; |
| 501 skip_pmeths: |
495 if (cap_buf && (*cap_buf != '\0')) | 502 if (cap_buf && (*cap_buf != '\0')) |
496 BIO_printf(bio_out, " [%s]\n", cap_buf); | 503 BIO_printf(bio_out, " [%s]\n", cap_buf); |
497 | 504 |
498 OPENSSL_free(cap_buf); | 505 OPENSSL_free(cap_buf); |
499 } | 506 } |
500 if(test_avail) | 507 if(test_avail) |
501 { | 508 { |
502 BIO_printf(bio_out, "%s", indent); | 509 BIO_printf(bio_out, "%s", indent); |
503 if (ENGINE_init(e)) | 510 if (ENGINE_init(e)) |
504 { | 511 { |
(...skipping 14 matching lines...) Expand all Loading... |
519 ENGINE_free(e); | 526 ENGINE_free(e); |
520 } | 527 } |
521 else | 528 else |
522 ERR_print_errors(bio_err); | 529 ERR_print_errors(bio_err); |
523 } | 530 } |
524 | 531 |
525 ret=0; | 532 ret=0; |
526 end: | 533 end: |
527 | 534 |
528 ERR_print_errors(bio_err); | 535 ERR_print_errors(bio_err); |
529 » sk_pop_free(engines, identity); | 536 » sk_OPENSSL_STRING_pop_free(engines, identity); |
530 » sk_pop_free(pre_cmds, identity); | 537 » sk_OPENSSL_STRING_pop_free(pre_cmds, identity); |
531 » sk_pop_free(post_cmds, identity); | 538 » sk_OPENSSL_STRING_pop_free(post_cmds, identity); |
532 if (bio_out != NULL) BIO_free_all(bio_out); | 539 if (bio_out != NULL) BIO_free_all(bio_out); |
533 apps_shutdown(); | 540 apps_shutdown(); |
534 OPENSSL_EXIT(ret); | 541 OPENSSL_EXIT(ret); |
535 } | 542 } |
536 #else | 543 #else |
537 | 544 |
538 # if PEDANTIC | 545 # if PEDANTIC |
539 static void *dummy=&dummy; | 546 static void *dummy=&dummy; |
540 # endif | 547 # endif |
541 | 548 |
542 #endif | 549 #endif |
OLD | NEW |