openssl.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. /*
  2. * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <internal/cryptlib.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <openssl/bio.h>
  14. #include <openssl/crypto.h>
  15. #include <openssl/lhash.h>
  16. #include <openssl/conf.h>
  17. #include <openssl/x509.h>
  18. #include <openssl/pem.h>
  19. #include <openssl/ssl.h>
  20. #ifndef OPENSSL_NO_ENGINE
  21. # include <openssl/engine.h>
  22. #endif
  23. #include <openssl/err.h>
  24. /* Needed to get the other O_xxx flags. */
  25. #ifdef OPENSSL_SYS_VMS
  26. # error #include <unixio.h>
  27. #endif
  28. #include "apps.h"
  29. #define INCLUDE_FUNCTION_TABLE
  30. #include "progs.h"
  31. /* Structure to hold the number of columns to be displayed and the
  32. * field width used to display them.
  33. */
  34. typedef struct {
  35. int columns;
  36. int width;
  37. } DISPLAY_COLUMNS;
  38. /* Special sentinel to exit the program. */
  39. #define EXIT_THE_PROGRAM (-1)
  40. /*
  41. * The LHASH callbacks ("hash" & "cmp") have been replaced by functions with
  42. * the base prototypes (we cast each variable inside the function to the
  43. * required type of "FUNCTION*"). This removes the necessity for
  44. * macro-generated wrapper functions.
  45. */
  46. static LHASH_OF(FUNCTION) *prog_init(void);
  47. static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[]);
  48. static void list_pkey(void);
  49. static void list_pkey_meth(void);
  50. static void list_type(FUNC_TYPE ft, int one);
  51. static void list_disabled(void);
  52. char *default_config_file = NULL;
  53. BIO *bio_in = NULL;
  54. BIO *bio_out = NULL;
  55. BIO *bio_err = NULL;
  56. static void calculate_columns(DISPLAY_COLUMNS *dc)
  57. {
  58. FUNCTION *f;
  59. int len, maxlen = 0;
  60. for (f = functions; f->name != NULL; ++f)
  61. if (f->type == FT_general || f->type == FT_md || f->type == FT_cipher)
  62. if ((len = strlen(f->name)) > maxlen)
  63. maxlen = len;
  64. dc->width = maxlen + 2;
  65. dc->columns = (80 - 1) / dc->width;
  66. }
  67. static int apps_startup(void)
  68. {
  69. #ifdef SIGPIPE
  70. signal(SIGPIPE, SIG_IGN);
  71. #endif
  72. /* Set non-default library initialisation settings */
  73. if (!OPENSSL_init_ssl(OPENSSL_INIT_ENGINE_ALL_BUILTIN
  74. | OPENSSL_INIT_LOAD_CONFIG, NULL))
  75. return 0;
  76. setup_ui_method();
  77. return 1;
  78. }
  79. static void apps_shutdown(void)
  80. {
  81. destroy_ui_method();
  82. destroy_prefix_method();
  83. }
  84. static char *make_config_name(void)
  85. {
  86. const char *t;
  87. size_t len;
  88. char *p;
  89. if ((t = getenv("OPENSSL_CONF")) != NULL)
  90. return OPENSSL_strdup(t);
  91. t = X509_get_default_cert_area();
  92. len = strlen(t) + 1 + strlen(OPENSSL_CONF) + 1;
  93. p = app_malloc(len, "config filename buffer");
  94. strcpy(p, t);
  95. #ifndef OPENSSL_SYS_VMS
  96. strcat(p, "/");
  97. #endif
  98. strcat(p, OPENSSL_CONF);
  99. return p;
  100. }
  101. int main(int argc, char *argv[])
  102. {
  103. FUNCTION f, *fp;
  104. LHASH_OF(FUNCTION) *prog = NULL;
  105. char *p, *pname;
  106. char buf[1024];
  107. const char *prompt;
  108. ARGS arg;
  109. int first, n, i, ret = 0;
  110. arg.argv = NULL;
  111. arg.size = 0;
  112. /* Set up some of the environment. */
  113. default_config_file = make_config_name();
  114. bio_in = dup_bio_in(FORMAT_TEXT);
  115. bio_out = dup_bio_out(FORMAT_TEXT);
  116. bio_err = dup_bio_err(FORMAT_TEXT);
  117. #if defined(OPENSSL_SYS_VMS) && defined(__DECC)
  118. argv = copy_argv(&argc, argv);
  119. #elif defined(_WIN32)
  120. /*
  121. * Replace argv[] with UTF-8 encoded strings.
  122. */
  123. win32_utf8argv(&argc, &argv);
  124. #endif
  125. p = getenv("OPENSSL_DEBUG_MEMORY");
  126. if (p != NULL && strcmp(p, "on") == 0)
  127. CRYPTO_set_mem_debug(1);
  128. CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
  129. if (getenv("OPENSSL_FIPS")) {
  130. BIO_printf(bio_err, "FIPS mode not supported.\n");
  131. return 1;
  132. }
  133. if (!apps_startup()) {
  134. BIO_printf(bio_err,
  135. "FATAL: Startup failure (dev note: apps_startup() failed)\n");
  136. ERR_print_errors(bio_err);
  137. ret = 1;
  138. goto end;
  139. }
  140. prog = prog_init();
  141. if (prog == NULL) {
  142. BIO_printf(bio_err,
  143. "FATAL: Startup failure (dev note: prog_init() failed)\n");
  144. ERR_print_errors(bio_err);
  145. ret = 1;
  146. goto end;
  147. }
  148. pname = opt_progname(argv[0]);
  149. /* first check the program name */
  150. f.name = pname;
  151. fp = lh_FUNCTION_retrieve(prog, &f);
  152. if (fp != NULL) {
  153. argv[0] = pname;
  154. ret = fp->func(argc, argv);
  155. goto end;
  156. }
  157. /* If there is stuff on the command line, run with that. */
  158. if (argc != 1) {
  159. argc--;
  160. argv++;
  161. ret = do_cmd(prog, argc, argv);
  162. if (ret < 0)
  163. ret = 0;
  164. goto end;
  165. }
  166. /* ok, lets enter interactive mode */
  167. for (;;) {
  168. ret = 0;
  169. /* Read a line, continue reading if line ends with \ */
  170. for (p = buf, n = sizeof(buf), i = 0, first = 1; n > 0; first = 0) {
  171. prompt = first ? "OpenSSL> " : "> ";
  172. p[0] = '\0';
  173. #ifndef READLINE
  174. fputs(prompt, stdout);
  175. fflush(stdout);
  176. if (!fgets(p, n, stdin))
  177. goto end;
  178. if (p[0] == '\0')
  179. goto end;
  180. i = strlen(p);
  181. if (i <= 1)
  182. break;
  183. if (p[i - 2] != '\\')
  184. break;
  185. i -= 2;
  186. p += i;
  187. n -= i;
  188. #else
  189. {
  190. extern char *readline(const char *);
  191. extern void add_history(const char *cp);
  192. char *text;
  193. text = readline(prompt);
  194. if (text == NULL)
  195. goto end;
  196. i = strlen(text);
  197. if (i == 0 || i > n)
  198. break;
  199. if (text[i - 1] != '\\') {
  200. p += strlen(strcpy(p, text));
  201. free(text);
  202. add_history(buf);
  203. break;
  204. }
  205. text[i - 1] = '\0';
  206. p += strlen(strcpy(p, text));
  207. free(text);
  208. n -= i;
  209. }
  210. #endif
  211. }
  212. if (!chopup_args(&arg, buf)) {
  213. BIO_printf(bio_err, "Can't parse (no memory?)\n");
  214. break;
  215. }
  216. ret = do_cmd(prog, arg.argc, arg.argv);
  217. if (ret == EXIT_THE_PROGRAM) {
  218. ret = 0;
  219. goto end;
  220. }
  221. if (ret != 0)
  222. BIO_printf(bio_err, "error in %s\n", arg.argv[0]);
  223. (void)BIO_flush(bio_out);
  224. (void)BIO_flush(bio_err);
  225. }
  226. ret = 1;
  227. end:
  228. OPENSSL_free(default_config_file);
  229. lh_FUNCTION_free(prog);
  230. OPENSSL_free(arg.argv);
  231. app_RAND_write();
  232. BIO_free(bio_in);
  233. BIO_free_all(bio_out);
  234. apps_shutdown();
  235. #ifndef OPENSSL_NO_CRYPTO_MDEBUG
  236. if (CRYPTO_mem_leaks(bio_err) <= 0)
  237. ret = 1;
  238. #endif
  239. BIO_free(bio_err);
  240. EXIT(ret);
  241. }
  242. static void list_cipher_fn(const EVP_CIPHER *c,
  243. const char *from, const char *to, void *arg)
  244. {
  245. if (c != NULL) {
  246. BIO_printf(arg, "%s\n", EVP_CIPHER_name(c));
  247. } else {
  248. if (from == NULL)
  249. from = "<undefined>";
  250. if (to == NULL)
  251. to = "<undefined>";
  252. BIO_printf(arg, "%s => %s\n", from, to);
  253. }
  254. }
  255. static void list_md_fn(const EVP_MD *m,
  256. const char *from, const char *to, void *arg)
  257. {
  258. if (m != NULL) {
  259. BIO_printf(arg, "%s\n", EVP_MD_name(m));
  260. } else {
  261. if (from == NULL)
  262. from = "<undefined>";
  263. if (to == NULL)
  264. to = "<undefined>";
  265. BIO_printf((BIO *)arg, "%s => %s\n", from, to);
  266. }
  267. }
  268. static void list_missing_help(void)
  269. {
  270. const FUNCTION *fp;
  271. const OPTIONS *o;
  272. for (fp = functions; fp->name != NULL; fp++) {
  273. if ((o = fp->help) != NULL) {
  274. /* If there is help, list what flags are not documented. */
  275. for ( ; o->name != NULL; o++) {
  276. if (o->helpstr == NULL)
  277. BIO_printf(bio_out, "%s %s\n", fp->name, o->name);
  278. }
  279. } else if (fp->func != dgst_main) {
  280. /* If not aliased to the dgst command, */
  281. BIO_printf(bio_out, "%s *\n", fp->name);
  282. }
  283. }
  284. }
  285. static void list_options_for_command(const char *command)
  286. {
  287. const FUNCTION *fp;
  288. const OPTIONS *o;
  289. for (fp = functions; fp->name != NULL; fp++)
  290. if (strcmp(fp->name, command) == 0)
  291. break;
  292. if (fp->name == NULL) {
  293. BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n",
  294. command);
  295. return;
  296. }
  297. if ((o = fp->help) == NULL)
  298. return;
  299. for ( ; o->name != NULL; o++) {
  300. if (o->name == OPT_HELP_STR
  301. || o->name == OPT_MORE_STR
  302. || o->name[0] == '\0')
  303. continue;
  304. BIO_printf(bio_out, "%s %c\n", o->name, o->valtype);
  305. }
  306. }
  307. /* Unified enum for help and list commands. */
  308. typedef enum HELPLIST_CHOICE {
  309. OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_ONE,
  310. OPT_COMMANDS, OPT_DIGEST_COMMANDS, OPT_OPTIONS,
  311. OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS,
  312. OPT_PK_ALGORITHMS, OPT_PK_METHOD, OPT_DISABLED, OPT_MISSING_HELP
  313. } HELPLIST_CHOICE;
  314. const OPTIONS list_options[] = {
  315. {"help", OPT_HELP, '-', "Display this summary"},
  316. {"1", OPT_ONE, '-', "List in one column"},
  317. {"commands", OPT_COMMANDS, '-', "List of standard commands"},
  318. {"digest-commands", OPT_DIGEST_COMMANDS, '-',
  319. "List of message digest commands"},
  320. {"digest-algorithms", OPT_DIGEST_ALGORITHMS, '-',
  321. "List of message digest algorithms"},
  322. {"cipher-commands", OPT_CIPHER_COMMANDS, '-', "List of cipher commands"},
  323. {"cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-',
  324. "List of cipher algorithms"},
  325. {"public-key-algorithms", OPT_PK_ALGORITHMS, '-',
  326. "List of public key algorithms"},
  327. {"public-key-methods", OPT_PK_METHOD, '-',
  328. "List of public key methods"},
  329. {"disabled", OPT_DISABLED, '-',
  330. "List of disabled features"},
  331. {"missing-help", OPT_MISSING_HELP, '-',
  332. "List missing detailed help strings"},
  333. {"options", OPT_OPTIONS, 's',
  334. "List options for specified command"},
  335. {NULL}
  336. };
  337. int list_main(int argc, char **argv)
  338. {
  339. char *prog;
  340. HELPLIST_CHOICE o;
  341. int one = 0, done = 0;
  342. prog = opt_init(argc, argv, list_options);
  343. while ((o = opt_next()) != OPT_EOF) {
  344. switch (o) {
  345. case OPT_EOF: /* Never hit, but suppresses warning */
  346. case OPT_ERR:
  347. opthelp:
  348. BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
  349. return 1;
  350. case OPT_HELP:
  351. opt_help(list_options);
  352. break;
  353. case OPT_ONE:
  354. one = 1;
  355. break;
  356. case OPT_COMMANDS:
  357. list_type(FT_general, one);
  358. break;
  359. case OPT_DIGEST_COMMANDS:
  360. list_type(FT_md, one);
  361. break;
  362. case OPT_DIGEST_ALGORITHMS:
  363. EVP_MD_do_all_sorted(list_md_fn, bio_out);
  364. break;
  365. case OPT_CIPHER_COMMANDS:
  366. list_type(FT_cipher, one);
  367. break;
  368. case OPT_CIPHER_ALGORITHMS:
  369. EVP_CIPHER_do_all_sorted(list_cipher_fn, bio_out);
  370. break;
  371. case OPT_PK_ALGORITHMS:
  372. list_pkey();
  373. break;
  374. case OPT_PK_METHOD:
  375. list_pkey_meth();
  376. break;
  377. case OPT_DISABLED:
  378. list_disabled();
  379. break;
  380. case OPT_MISSING_HELP:
  381. list_missing_help();
  382. break;
  383. case OPT_OPTIONS:
  384. list_options_for_command(opt_arg());
  385. break;
  386. }
  387. done = 1;
  388. }
  389. if (opt_num_rest() != 0) {
  390. BIO_printf(bio_err, "Extra arguments given.\n");
  391. goto opthelp;
  392. }
  393. if (!done)
  394. goto opthelp;
  395. return 0;
  396. }
  397. typedef enum HELP_CHOICE {
  398. OPT_hERR = -1, OPT_hEOF = 0, OPT_hHELP
  399. } HELP_CHOICE;
  400. const OPTIONS help_options[] = {
  401. {OPT_HELP_STR, 1, '-', "Usage: help [options]\n"},
  402. {OPT_HELP_STR, 1, '-', " help [command]\n"},
  403. {"help", OPT_hHELP, '-', "Display this summary"},
  404. {NULL}
  405. };
  406. int help_main(int argc, char **argv)
  407. {
  408. FUNCTION *fp;
  409. int i, nl;
  410. FUNC_TYPE tp;
  411. char *prog;
  412. HELP_CHOICE o;
  413. DISPLAY_COLUMNS dc;
  414. prog = opt_init(argc, argv, help_options);
  415. while ((o = opt_next()) != OPT_hEOF) {
  416. switch (o) {
  417. case OPT_hERR:
  418. case OPT_hEOF:
  419. BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
  420. return 1;
  421. case OPT_hHELP:
  422. opt_help(help_options);
  423. return 0;
  424. }
  425. }
  426. if (opt_num_rest() == 1) {
  427. char *new_argv[3];
  428. new_argv[0] = opt_rest()[0];
  429. new_argv[1] = "--help";
  430. new_argv[2] = NULL;
  431. return do_cmd(prog_init(), 2, new_argv);
  432. }
  433. if (opt_num_rest() != 0) {
  434. BIO_printf(bio_err, "Usage: %s\n", prog);
  435. return 1;
  436. }
  437. calculate_columns(&dc);
  438. BIO_printf(bio_err, "Standard commands");
  439. i = 0;
  440. tp = FT_none;
  441. for (fp = functions; fp->name != NULL; fp++) {
  442. nl = 0;
  443. if (i++ % dc.columns == 0) {
  444. BIO_printf(bio_err, "\n");
  445. nl = 1;
  446. }
  447. if (fp->type != tp) {
  448. tp = fp->type;
  449. if (!nl)
  450. BIO_printf(bio_err, "\n");
  451. if (tp == FT_md) {
  452. i = 1;
  453. BIO_printf(bio_err,
  454. "\nMessage Digest commands (see the `dgst' command for more details)\n");
  455. } else if (tp == FT_cipher) {
  456. i = 1;
  457. BIO_printf(bio_err,
  458. "\nCipher commands (see the `enc' command for more details)\n");
  459. }
  460. }
  461. BIO_printf(bio_err, "%-*s", dc.width, fp->name);
  462. }
  463. BIO_printf(bio_err, "\n\n");
  464. return 0;
  465. }
  466. static void list_type(FUNC_TYPE ft, int one)
  467. {
  468. FUNCTION *fp;
  469. int i = 0;
  470. DISPLAY_COLUMNS dc = {0};
  471. if (!one)
  472. calculate_columns(&dc);
  473. for (fp = functions; fp->name != NULL; fp++) {
  474. if (fp->type != ft)
  475. continue;
  476. if (one) {
  477. BIO_printf(bio_out, "%s\n", fp->name);
  478. } else {
  479. if (i % dc.columns == 0 && i > 0)
  480. BIO_printf(bio_out, "\n");
  481. BIO_printf(bio_out, "%-*s", dc.width, fp->name);
  482. i++;
  483. }
  484. }
  485. if (!one)
  486. BIO_printf(bio_out, "\n\n");
  487. }
  488. static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[])
  489. {
  490. FUNCTION f, *fp;
  491. if (argc <= 0 || argv[0] == NULL)
  492. return 0;
  493. f.name = argv[0];
  494. fp = lh_FUNCTION_retrieve(prog, &f);
  495. if (fp == NULL) {
  496. if (EVP_get_digestbyname(argv[0])) {
  497. f.type = FT_md;
  498. f.func = dgst_main;
  499. fp = &f;
  500. } else if (EVP_get_cipherbyname(argv[0])) {
  501. f.type = FT_cipher;
  502. f.func = enc_main;
  503. fp = &f;
  504. }
  505. }
  506. if (fp != NULL) {
  507. return fp->func(argc, argv);
  508. }
  509. if ((strncmp(argv[0], "no-", 3)) == 0) {
  510. /*
  511. * User is asking if foo is unsupported, by trying to "run" the
  512. * no-foo command. Strange.
  513. */
  514. f.name = argv[0] + 3;
  515. if (lh_FUNCTION_retrieve(prog, &f) == NULL) {
  516. BIO_printf(bio_out, "%s\n", argv[0]);
  517. return 0;
  518. }
  519. BIO_printf(bio_out, "%s\n", argv[0] + 3);
  520. return 1;
  521. }
  522. if (strcmp(argv[0], "quit") == 0 || strcmp(argv[0], "q") == 0 ||
  523. strcmp(argv[0], "exit") == 0 || strcmp(argv[0], "bye") == 0)
  524. /* Special value to mean "exit the program. */
  525. return EXIT_THE_PROGRAM;
  526. BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n",
  527. argv[0]);
  528. return 1;
  529. }
  530. static void list_pkey(void)
  531. {
  532. int i;
  533. for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
  534. const EVP_PKEY_ASN1_METHOD *ameth;
  535. int pkey_id, pkey_base_id, pkey_flags;
  536. const char *pinfo, *pem_str;
  537. ameth = EVP_PKEY_asn1_get0(i);
  538. EVP_PKEY_asn1_get0_info(&pkey_id, &pkey_base_id, &pkey_flags,
  539. &pinfo, &pem_str, ameth);
  540. if (pkey_flags & ASN1_PKEY_ALIAS) {
  541. BIO_printf(bio_out, "Name: %s\n", OBJ_nid2ln(pkey_id));
  542. BIO_printf(bio_out, "\tAlias for: %s\n",
  543. OBJ_nid2ln(pkey_base_id));
  544. } else {
  545. BIO_printf(bio_out, "Name: %s\n", pinfo);
  546. BIO_printf(bio_out, "\tType: %s Algorithm\n",
  547. pkey_flags & ASN1_PKEY_DYNAMIC ?
  548. "External" : "Builtin");
  549. BIO_printf(bio_out, "\tOID: %s\n", OBJ_nid2ln(pkey_id));
  550. if (pem_str == NULL)
  551. pem_str = "(none)";
  552. BIO_printf(bio_out, "\tPEM string: %s\n", pem_str);
  553. }
  554. }
  555. }
  556. static void list_pkey_meth(void)
  557. {
  558. size_t i;
  559. size_t meth_count = EVP_PKEY_meth_get_count();
  560. for (i = 0; i < meth_count; i++) {
  561. const EVP_PKEY_METHOD *pmeth = EVP_PKEY_meth_get0(i);
  562. int pkey_id, pkey_flags;
  563. EVP_PKEY_meth_get0_info(&pkey_id, &pkey_flags, pmeth);
  564. BIO_printf(bio_out, "%s\n", OBJ_nid2ln(pkey_id));
  565. BIO_printf(bio_out, "\tType: %s Algorithm\n",
  566. pkey_flags & ASN1_PKEY_DYNAMIC ? "External" : "Builtin");
  567. }
  568. }
  569. static int function_cmp(const FUNCTION * a, const FUNCTION * b)
  570. {
  571. return strncmp(a->name, b->name, 8);
  572. }
  573. static unsigned long function_hash(const FUNCTION * a)
  574. {
  575. return OPENSSL_LH_strhash(a->name);
  576. }
  577. static int SortFnByName(const void *_f1, const void *_f2)
  578. {
  579. const FUNCTION *f1 = _f1;
  580. const FUNCTION *f2 = _f2;
  581. if (f1->type != f2->type)
  582. return f1->type - f2->type;
  583. return strcmp(f1->name, f2->name);
  584. }
  585. static void list_disabled(void)
  586. {
  587. BIO_puts(bio_out, "Disabled algorithms:\n");
  588. #ifdef OPENSSL_NO_ARIA
  589. BIO_puts(bio_out, "ARIA\n");
  590. #endif
  591. #ifdef OPENSSL_NO_BF
  592. BIO_puts(bio_out, "BF\n");
  593. #endif
  594. #ifdef OPENSSL_NO_BLAKE2
  595. BIO_puts(bio_out, "BLAKE2\n");
  596. #endif
  597. #ifdef OPENSSL_NO_CAMELLIA
  598. BIO_puts(bio_out, "CAMELLIA\n");
  599. #endif
  600. #ifdef OPENSSL_NO_CAST
  601. BIO_puts(bio_out, "CAST\n");
  602. #endif
  603. #ifdef OPENSSL_NO_CMAC
  604. BIO_puts(bio_out, "CMAC\n");
  605. #endif
  606. #ifdef OPENSSL_NO_CMS
  607. BIO_puts(bio_out, "CMS\n");
  608. #endif
  609. #ifdef OPENSSL_NO_COMP
  610. BIO_puts(bio_out, "COMP\n");
  611. #endif
  612. #ifdef OPENSSL_NO_DES
  613. BIO_puts(bio_out, "DES\n");
  614. #endif
  615. #ifdef OPENSSL_NO_DGRAM
  616. BIO_puts(bio_out, "DGRAM\n");
  617. #endif
  618. #ifdef OPENSSL_NO_DH
  619. BIO_puts(bio_out, "DH\n");
  620. #endif
  621. #ifdef OPENSSL_NO_DSA
  622. BIO_puts(bio_out, "DSA\n");
  623. #endif
  624. #if defined(OPENSSL_NO_DTLS)
  625. BIO_puts(bio_out, "DTLS\n");
  626. #endif
  627. #if defined(OPENSSL_NO_DTLS1)
  628. BIO_puts(bio_out, "DTLS1\n");
  629. #endif
  630. #if defined(OPENSSL_NO_DTLS1_2)
  631. BIO_puts(bio_out, "DTLS1_2\n");
  632. #endif
  633. #ifdef OPENSSL_NO_EC
  634. BIO_puts(bio_out, "EC\n");
  635. #endif
  636. #ifdef OPENSSL_NO_EC2M
  637. BIO_puts(bio_out, "EC2M\n");
  638. #endif
  639. #ifdef OPENSSL_NO_ENGINE
  640. BIO_puts(bio_out, "ENGINE\n");
  641. #endif
  642. #ifdef OPENSSL_NO_GOST
  643. BIO_puts(bio_out, "GOST\n");
  644. #endif
  645. #ifdef OPENSSL_NO_HEARTBEATS
  646. BIO_puts(bio_out, "HEARTBEATS\n");
  647. #endif
  648. #ifdef OPENSSL_NO_IDEA
  649. BIO_puts(bio_out, "IDEA\n");
  650. #endif
  651. #ifdef OPENSSL_NO_MD2
  652. BIO_puts(bio_out, "MD2\n");
  653. #endif
  654. #ifdef OPENSSL_NO_MD4
  655. BIO_puts(bio_out, "MD4\n");
  656. #endif
  657. #ifdef OPENSSL_NO_MD5
  658. BIO_puts(bio_out, "MD5\n");
  659. #endif
  660. #ifdef OPENSSL_NO_MDC2
  661. BIO_puts(bio_out, "MDC2\n");
  662. #endif
  663. #ifdef OPENSSL_NO_OCB
  664. BIO_puts(bio_out, "OCB\n");
  665. #endif
  666. #ifdef OPENSSL_NO_OCSP
  667. BIO_puts(bio_out, "OCSP\n");
  668. #endif
  669. #ifdef OPENSSL_NO_PSK
  670. BIO_puts(bio_out, "PSK\n");
  671. #endif
  672. #ifdef OPENSSL_NO_RC2
  673. BIO_puts(bio_out, "RC2\n");
  674. #endif
  675. #ifdef OPENSSL_NO_RC4
  676. BIO_puts(bio_out, "RC4\n");
  677. #endif
  678. #ifdef OPENSSL_NO_RC5
  679. BIO_puts(bio_out, "RC5\n");
  680. #endif
  681. #ifdef OPENSSL_NO_RMD160
  682. BIO_puts(bio_out, "RMD160\n");
  683. #endif
  684. #ifdef OPENSSL_NO_RSA
  685. BIO_puts(bio_out, "RSA\n");
  686. #endif
  687. #ifdef OPENSSL_NO_SCRYPT
  688. BIO_puts(bio_out, "SCRYPT\n");
  689. #endif
  690. #ifdef OPENSSL_NO_SCTP
  691. BIO_puts(bio_out, "SCTP\n");
  692. #endif
  693. #ifdef OPENSSL_NO_SEED
  694. BIO_puts(bio_out, "SEED\n");
  695. #endif
  696. #ifdef OPENSSL_NO_SM2
  697. BIO_puts(bio_out, "SM2\n");
  698. #endif
  699. #ifdef OPENSSL_NO_SM3
  700. BIO_puts(bio_out, "SM3\n");
  701. #endif
  702. #ifdef OPENSSL_NO_SM4
  703. BIO_puts(bio_out, "SM4\n");
  704. #endif
  705. #ifdef OPENSSL_NO_SOCK
  706. BIO_puts(bio_out, "SOCK\n");
  707. #endif
  708. #ifdef OPENSSL_NO_SRP
  709. BIO_puts(bio_out, "SRP\n");
  710. #endif
  711. #ifdef OPENSSL_NO_SRTP
  712. BIO_puts(bio_out, "SRTP\n");
  713. #endif
  714. #ifdef OPENSSL_NO_SSL3
  715. BIO_puts(bio_out, "SSL3\n");
  716. #endif
  717. #ifdef OPENSSL_NO_TLS1
  718. BIO_puts(bio_out, "TLS1\n");
  719. #endif
  720. #ifdef OPENSSL_NO_TLS1_1
  721. BIO_puts(bio_out, "TLS1_1\n");
  722. #endif
  723. #ifdef OPENSSL_NO_TLS1_2
  724. BIO_puts(bio_out, "TLS1_2\n");
  725. #endif
  726. #ifdef OPENSSL_NO_WHIRLPOOL
  727. BIO_puts(bio_out, "WHIRLPOOL\n");
  728. #endif
  729. #ifndef ZLIB
  730. BIO_puts(bio_out, "ZLIB\n");
  731. #endif
  732. }
  733. static LHASH_OF(FUNCTION) *prog_init(void)
  734. {
  735. static LHASH_OF(FUNCTION) *ret = NULL;
  736. static int prog_inited = 0;
  737. FUNCTION *f;
  738. size_t i;
  739. if (prog_inited)
  740. return ret;
  741. prog_inited = 1;
  742. /* Sort alphabetically within category. For nicer help displays. */
  743. for (i = 0, f = functions; f->name != NULL; ++f, ++i)
  744. ;
  745. qsort(functions, i, sizeof(*functions), SortFnByName);
  746. if ((ret = lh_FUNCTION_new(function_hash, function_cmp)) == NULL)
  747. return NULL;
  748. for (f = functions; f->name != NULL; f++)
  749. (void)lh_FUNCTION_insert(ret, f);
  750. return ret;
  751. }