list.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  1. /*
  2. * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (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. /* We need to use some engine deprecated APIs */
  10. #define OPENSSL_SUPPRESS_DEPRECATED
  11. #include <string.h>
  12. #include <openssl/evp.h>
  13. #include <openssl/err.h>
  14. #include <openssl/provider.h>
  15. #include <openssl/safestack.h>
  16. #include <openssl/kdf.h>
  17. #include "apps.h"
  18. #include "app_params.h"
  19. #include "progs.h"
  20. #include "opt.h"
  21. #include "names.h"
  22. DEFINE_STACK_OF_CSTRING()
  23. static int verbose = 0;
  24. static void legacy_cipher_fn(const EVP_CIPHER *c,
  25. const char *from, const char *to, void *arg)
  26. {
  27. if (c != NULL) {
  28. BIO_printf(arg, " %s\n", EVP_CIPHER_name(c));
  29. } else {
  30. if (from == NULL)
  31. from = "<undefined>";
  32. if (to == NULL)
  33. to = "<undefined>";
  34. BIO_printf(arg, " %s => %s\n", from, to);
  35. }
  36. }
  37. DEFINE_STACK_OF(EVP_CIPHER)
  38. static int cipher_cmp(const EVP_CIPHER * const *a,
  39. const EVP_CIPHER * const *b)
  40. {
  41. int ret = EVP_CIPHER_number(*a) - EVP_CIPHER_number(*b);
  42. if (ret == 0)
  43. ret = strcmp(OSSL_PROVIDER_name(EVP_CIPHER_provider(*a)),
  44. OSSL_PROVIDER_name(EVP_CIPHER_provider(*b)));
  45. return ret;
  46. }
  47. static void collect_ciphers(EVP_CIPHER *cipher, void *stack)
  48. {
  49. STACK_OF(EVP_CIPHER) *cipher_stack = stack;
  50. if (sk_EVP_CIPHER_push(cipher_stack, cipher) > 0)
  51. EVP_CIPHER_up_ref(cipher);
  52. }
  53. static void list_ciphers(void)
  54. {
  55. STACK_OF(EVP_CIPHER) *ciphers = sk_EVP_CIPHER_new(cipher_cmp);
  56. int i;
  57. if (ciphers == NULL) {
  58. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  59. return;
  60. }
  61. BIO_printf(bio_out, "Legacy:\n");
  62. EVP_CIPHER_do_all_sorted(legacy_cipher_fn, bio_out);
  63. BIO_printf(bio_out, "Provided:\n");
  64. EVP_CIPHER_do_all_provided(NULL, collect_ciphers, ciphers);
  65. sk_EVP_CIPHER_sort(ciphers);
  66. for (i = 0; i < sk_EVP_CIPHER_num(ciphers); i++) {
  67. const EVP_CIPHER *c = sk_EVP_CIPHER_value(ciphers, i);
  68. STACK_OF(OPENSSL_CSTRING) *names =
  69. sk_OPENSSL_CSTRING_new(name_cmp);
  70. EVP_CIPHER_names_do_all(c, collect_names, names);
  71. BIO_printf(bio_out, " ");
  72. print_names(bio_out, names);
  73. BIO_printf(bio_out, " @ %s\n",
  74. OSSL_PROVIDER_name(EVP_CIPHER_provider(c)));
  75. sk_OPENSSL_CSTRING_free(names);
  76. if (verbose) {
  77. print_param_types("retrievable algorithm parameters",
  78. EVP_CIPHER_gettable_params(c), 4);
  79. print_param_types("retrievable operation parameters",
  80. EVP_CIPHER_gettable_ctx_params(c), 4);
  81. print_param_types("settable operation parameters",
  82. EVP_CIPHER_settable_ctx_params(c), 4);
  83. }
  84. }
  85. sk_EVP_CIPHER_pop_free(ciphers, EVP_CIPHER_free);
  86. }
  87. static void list_md_fn(const EVP_MD *m,
  88. const char *from, const char *to, void *arg)
  89. {
  90. if (m != NULL) {
  91. BIO_printf(arg, " %s\n", EVP_MD_name(m));
  92. } else {
  93. if (from == NULL)
  94. from = "<undefined>";
  95. if (to == NULL)
  96. to = "<undefined>";
  97. BIO_printf((BIO *)arg, " %s => %s\n", from, to);
  98. }
  99. }
  100. DEFINE_STACK_OF(EVP_MD)
  101. static int md_cmp(const EVP_MD * const *a, const EVP_MD * const *b)
  102. {
  103. int ret = EVP_MD_number(*a) - EVP_MD_number(*b);
  104. if (ret == 0)
  105. ret = strcmp(OSSL_PROVIDER_name(EVP_MD_provider(*a)),
  106. OSSL_PROVIDER_name(EVP_MD_provider(*b)));
  107. return ret;
  108. }
  109. static void collect_digests(EVP_MD *md, void *stack)
  110. {
  111. STACK_OF(EVP_MD) *digest_stack = stack;
  112. if (sk_EVP_MD_push(digest_stack, md) > 0)
  113. EVP_MD_up_ref(md);
  114. }
  115. static void list_digests(void)
  116. {
  117. STACK_OF(EVP_MD) *digests = sk_EVP_MD_new(md_cmp);
  118. int i;
  119. if (digests == NULL) {
  120. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  121. return;
  122. }
  123. BIO_printf(bio_out, "Legacy:\n");
  124. EVP_MD_do_all_sorted(list_md_fn, bio_out);
  125. BIO_printf(bio_out, "Provided:\n");
  126. EVP_MD_do_all_provided(NULL, collect_digests, digests);
  127. sk_EVP_MD_sort(digests);
  128. for (i = 0; i < sk_EVP_MD_num(digests); i++) {
  129. const EVP_MD *m = sk_EVP_MD_value(digests, i);
  130. STACK_OF(OPENSSL_CSTRING) *names =
  131. sk_OPENSSL_CSTRING_new(name_cmp);
  132. EVP_MD_names_do_all(m, collect_names, names);
  133. BIO_printf(bio_out, " ");
  134. print_names(bio_out, names);
  135. BIO_printf(bio_out, " @ %s\n",
  136. OSSL_PROVIDER_name(EVP_MD_provider(m)));
  137. sk_OPENSSL_CSTRING_free(names);
  138. if (verbose) {
  139. print_param_types("retrievable algorithm parameters",
  140. EVP_MD_gettable_params(m), 4);
  141. print_param_types("retrievable operation parameters",
  142. EVP_MD_gettable_ctx_params(m), 4);
  143. print_param_types("settable operation parameters",
  144. EVP_MD_settable_ctx_params(m), 4);
  145. }
  146. }
  147. sk_EVP_MD_pop_free(digests, EVP_MD_free);
  148. }
  149. DEFINE_STACK_OF(EVP_MAC)
  150. static int mac_cmp(const EVP_MAC * const *a, const EVP_MAC * const *b)
  151. {
  152. int ret = EVP_MAC_number(*a) - EVP_MAC_number(*b);
  153. if (ret == 0)
  154. ret = strcmp(OSSL_PROVIDER_name(EVP_MAC_provider(*a)),
  155. OSSL_PROVIDER_name(EVP_MAC_provider(*b)));
  156. return ret;
  157. }
  158. static void collect_macs(EVP_MAC *mac, void *stack)
  159. {
  160. STACK_OF(EVP_MAC) *mac_stack = stack;
  161. if (sk_EVP_MAC_push(mac_stack, mac) > 0)
  162. EVP_MAC_up_ref(mac);
  163. }
  164. static void list_macs(void)
  165. {
  166. STACK_OF(EVP_MAC) *macs = sk_EVP_MAC_new(mac_cmp);
  167. int i;
  168. if (macs == NULL) {
  169. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  170. return;
  171. }
  172. BIO_printf(bio_out, "Provided MACs:\n");
  173. EVP_MAC_do_all_provided(NULL, collect_macs, macs);
  174. sk_EVP_MAC_sort(macs);
  175. for (i = 0; i < sk_EVP_MAC_num(macs); i++) {
  176. const EVP_MAC *m = sk_EVP_MAC_value(macs, i);
  177. STACK_OF(OPENSSL_CSTRING) *names =
  178. sk_OPENSSL_CSTRING_new(name_cmp);
  179. EVP_MAC_names_do_all(m, collect_names, names);
  180. BIO_printf(bio_out, " ");
  181. print_names(bio_out, names);
  182. BIO_printf(bio_out, " @ %s\n",
  183. OSSL_PROVIDER_name(EVP_MAC_provider(m)));
  184. sk_OPENSSL_CSTRING_free(names);
  185. if (verbose) {
  186. print_param_types("retrievable algorithm parameters",
  187. EVP_MAC_gettable_params(m), 4);
  188. print_param_types("retrievable operation parameters",
  189. EVP_MAC_gettable_ctx_params(m), 4);
  190. print_param_types("settable operation parameters",
  191. EVP_MAC_settable_ctx_params(m), 4);
  192. }
  193. }
  194. sk_EVP_MAC_pop_free(macs, EVP_MAC_free);
  195. }
  196. /*
  197. * KDFs and PRFs
  198. */
  199. DEFINE_STACK_OF(EVP_KDF)
  200. static int kdf_cmp(const EVP_KDF * const *a, const EVP_KDF * const *b)
  201. {
  202. int ret = EVP_KDF_number(*a) - EVP_KDF_number(*b);
  203. if (ret == 0)
  204. ret = strcmp(OSSL_PROVIDER_name(EVP_KDF_provider(*a)),
  205. OSSL_PROVIDER_name(EVP_KDF_provider(*b)));
  206. return ret;
  207. }
  208. static void collect_kdfs(EVP_KDF *kdf, void *stack)
  209. {
  210. STACK_OF(EVP_KDF) *kdf_stack = stack;
  211. sk_EVP_KDF_push(kdf_stack, kdf);
  212. EVP_KDF_up_ref(kdf);
  213. }
  214. static void list_kdfs(void)
  215. {
  216. STACK_OF(EVP_KDF) *kdfs = sk_EVP_KDF_new(kdf_cmp);
  217. int i;
  218. if (kdfs == NULL) {
  219. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  220. return;
  221. }
  222. BIO_printf(bio_out, "Provided KDFs and PDFs:\n");
  223. EVP_KDF_do_all_provided(NULL, collect_kdfs, kdfs);
  224. sk_EVP_KDF_sort(kdfs);
  225. for (i = 0; i < sk_EVP_KDF_num(kdfs); i++) {
  226. const EVP_KDF *k = sk_EVP_KDF_value(kdfs, i);
  227. STACK_OF(OPENSSL_CSTRING) *names =
  228. sk_OPENSSL_CSTRING_new(name_cmp);
  229. EVP_KDF_names_do_all(k, collect_names, names);
  230. BIO_printf(bio_out, " ");
  231. print_names(bio_out, names);
  232. BIO_printf(bio_out, " @ %s\n",
  233. OSSL_PROVIDER_name(EVP_KDF_provider(k)));
  234. sk_OPENSSL_CSTRING_free(names);
  235. if (verbose) {
  236. print_param_types("retrievable algorithm parameters",
  237. EVP_KDF_gettable_params(k), 4);
  238. print_param_types("retrievable operation parameters",
  239. EVP_KDF_gettable_ctx_params(k), 4);
  240. print_param_types("settable operation parameters",
  241. EVP_KDF_settable_ctx_params(k), 4);
  242. }
  243. }
  244. sk_EVP_KDF_pop_free(kdfs, EVP_KDF_free);
  245. }
  246. /*
  247. * RANDs
  248. */
  249. DEFINE_STACK_OF(EVP_RAND)
  250. static int rand_cmp(const EVP_RAND * const *a, const EVP_RAND * const *b)
  251. {
  252. int ret = strcasecmp(EVP_RAND_name(*a), EVP_RAND_name(*b));
  253. if (ret == 0)
  254. ret = strcmp(OSSL_PROVIDER_name(EVP_RAND_provider(*a)),
  255. OSSL_PROVIDER_name(EVP_RAND_provider(*b)));
  256. return ret;
  257. }
  258. static void collect_rands(EVP_RAND *rand, void *stack)
  259. {
  260. STACK_OF(EVP_RAND) *rand_stack = stack;
  261. sk_EVP_RAND_push(rand_stack, rand);
  262. EVP_RAND_up_ref(rand);
  263. }
  264. static void list_random_generators(void)
  265. {
  266. STACK_OF(EVP_RAND) *rands = sk_EVP_RAND_new(rand_cmp);
  267. int i;
  268. if (rands == NULL) {
  269. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  270. return;
  271. }
  272. BIO_printf(bio_out, "Provided RNGs and seed sources:\n");
  273. EVP_RAND_do_all_provided(NULL, collect_rands, rands);
  274. sk_EVP_RAND_sort(rands);
  275. for (i = 0; i < sk_EVP_RAND_num(rands); i++) {
  276. const EVP_RAND *m = sk_EVP_RAND_value(rands, i);
  277. BIO_printf(bio_out, " %s", EVP_RAND_name(m));
  278. BIO_printf(bio_out, " @ %s\n",
  279. OSSL_PROVIDER_name(EVP_RAND_provider(m)));
  280. if (verbose) {
  281. print_param_types("retrievable algorithm parameters",
  282. EVP_RAND_gettable_params(m), 4);
  283. print_param_types("retrievable operation parameters",
  284. EVP_RAND_gettable_ctx_params(m), 4);
  285. print_param_types("settable operation parameters",
  286. EVP_RAND_settable_ctx_params(m), 4);
  287. }
  288. }
  289. sk_EVP_RAND_pop_free(rands, EVP_RAND_free);
  290. }
  291. static void list_missing_help(void)
  292. {
  293. const FUNCTION *fp;
  294. const OPTIONS *o;
  295. for (fp = functions; fp->name != NULL; fp++) {
  296. if ((o = fp->help) != NULL) {
  297. /* If there is help, list what flags are not documented. */
  298. for ( ; o->name != NULL; o++) {
  299. if (o->helpstr == NULL)
  300. BIO_printf(bio_out, "%s %s\n", fp->name, o->name);
  301. }
  302. } else if (fp->func != dgst_main) {
  303. /* If not aliased to the dgst command, */
  304. BIO_printf(bio_out, "%s *\n", fp->name);
  305. }
  306. }
  307. }
  308. static void list_objects(void)
  309. {
  310. int max_nid = OBJ_new_nid(0);
  311. int i;
  312. char *oid_buf = NULL;
  313. int oid_size = 0;
  314. /* Skip 0, since that's NID_undef */
  315. for (i = 1; i < max_nid; i++) {
  316. const ASN1_OBJECT *obj = OBJ_nid2obj(i);
  317. const char *sn = OBJ_nid2sn(i);
  318. const char *ln = OBJ_nid2ln(i);
  319. int n = 0;
  320. /*
  321. * If one of the retrieved objects somehow generated an error,
  322. * we ignore it. The check for NID_undef below will detect the
  323. * error and simply skip to the next NID.
  324. */
  325. ERR_clear_error();
  326. if (OBJ_obj2nid(obj) == NID_undef)
  327. continue;
  328. if ((n = OBJ_obj2txt(NULL, 0, obj, 1)) == 0) {
  329. BIO_printf(bio_out, "# None-OID object: %s, %s\n", sn, ln);
  330. continue;
  331. }
  332. if (n < 0)
  333. break; /* Error */
  334. if (n > oid_size) {
  335. oid_buf = OPENSSL_realloc(oid_buf, n + 1);
  336. if (oid_buf == NULL) {
  337. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  338. break; /* Error */
  339. }
  340. oid_size = n + 1;
  341. }
  342. if (OBJ_obj2txt(oid_buf, oid_size, obj, 1) < 0)
  343. break; /* Error */
  344. if (ln == NULL || strcmp(sn, ln) == 0)
  345. BIO_printf(bio_out, "%s = %s\n", sn, oid_buf);
  346. else
  347. BIO_printf(bio_out, "%s = %s, %s\n", sn, ln, oid_buf);
  348. }
  349. OPENSSL_free(oid_buf);
  350. }
  351. static void list_options_for_command(const char *command)
  352. {
  353. const FUNCTION *fp;
  354. const OPTIONS *o;
  355. for (fp = functions; fp->name != NULL; fp++)
  356. if (strcmp(fp->name, command) == 0)
  357. break;
  358. if (fp->name == NULL) {
  359. BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n",
  360. command);
  361. return;
  362. }
  363. if ((o = fp->help) == NULL)
  364. return;
  365. for ( ; o->name != NULL; o++) {
  366. char c = o->valtype;
  367. if (o->name == OPT_PARAM_STR)
  368. break;
  369. if (o->name == OPT_HELP_STR
  370. || o->name == OPT_MORE_STR
  371. || o->name == OPT_SECTION_STR
  372. || o->name[0] == '\0')
  373. continue;
  374. BIO_printf(bio_out, "%s %c\n", o->name, c == '\0' ? '-' : c);
  375. }
  376. /* Always output the -- marker since it is sometimes documented. */
  377. BIO_printf(bio_out, "- -\n");
  378. }
  379. static void list_type(FUNC_TYPE ft, int one)
  380. {
  381. FUNCTION *fp;
  382. int i = 0;
  383. DISPLAY_COLUMNS dc;
  384. memset(&dc, 0, sizeof(dc));
  385. if (!one)
  386. calculate_columns(functions, &dc);
  387. for (fp = functions; fp->name != NULL; fp++) {
  388. if (fp->type != ft)
  389. continue;
  390. if (one) {
  391. BIO_printf(bio_out, "%s\n", fp->name);
  392. } else {
  393. if (i % dc.columns == 0 && i > 0)
  394. BIO_printf(bio_out, "\n");
  395. BIO_printf(bio_out, "%-*s", dc.width, fp->name);
  396. i++;
  397. }
  398. }
  399. if (!one)
  400. BIO_printf(bio_out, "\n\n");
  401. }
  402. static void list_pkey(void)
  403. {
  404. int i;
  405. for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
  406. const EVP_PKEY_ASN1_METHOD *ameth;
  407. int pkey_id, pkey_base_id, pkey_flags;
  408. const char *pinfo, *pem_str;
  409. ameth = EVP_PKEY_asn1_get0(i);
  410. EVP_PKEY_asn1_get0_info(&pkey_id, &pkey_base_id, &pkey_flags,
  411. &pinfo, &pem_str, ameth);
  412. if (pkey_flags & ASN1_PKEY_ALIAS) {
  413. BIO_printf(bio_out, "Name: %s\n", OBJ_nid2ln(pkey_id));
  414. BIO_printf(bio_out, "\tAlias for: %s\n",
  415. OBJ_nid2ln(pkey_base_id));
  416. } else {
  417. BIO_printf(bio_out, "Name: %s\n", pinfo);
  418. BIO_printf(bio_out, "\tType: %s Algorithm\n",
  419. pkey_flags & ASN1_PKEY_DYNAMIC ?
  420. "External" : "Builtin");
  421. BIO_printf(bio_out, "\tOID: %s\n", OBJ_nid2ln(pkey_id));
  422. if (pem_str == NULL)
  423. pem_str = "(none)";
  424. BIO_printf(bio_out, "\tPEM string: %s\n", pem_str);
  425. }
  426. }
  427. }
  428. static void list_pkey_meth(void)
  429. {
  430. size_t i;
  431. size_t meth_count = EVP_PKEY_meth_get_count();
  432. for (i = 0; i < meth_count; i++) {
  433. const EVP_PKEY_METHOD *pmeth = EVP_PKEY_meth_get0(i);
  434. int pkey_id, pkey_flags;
  435. EVP_PKEY_meth_get0_info(&pkey_id, &pkey_flags, pmeth);
  436. BIO_printf(bio_out, "%s\n", OBJ_nid2ln(pkey_id));
  437. BIO_printf(bio_out, "\tType: %s Algorithm\n",
  438. pkey_flags & ASN1_PKEY_DYNAMIC ? "External" : "Builtin");
  439. }
  440. }
  441. #ifndef OPENSSL_NO_DEPRECATED_3_0
  442. static void list_engines(void)
  443. {
  444. # ifndef OPENSSL_NO_ENGINE
  445. ENGINE *e;
  446. BIO_puts(bio_out, "Engines:\n");
  447. e = ENGINE_get_first();
  448. while (e) {
  449. BIO_printf(bio_out, "%s\n", ENGINE_get_id(e));
  450. e = ENGINE_get_next(e);
  451. }
  452. # else
  453. BIO_puts(bio_out, "Engine support is disabled.\n");
  454. # endif
  455. }
  456. #endif
  457. static void list_disabled(void)
  458. {
  459. BIO_puts(bio_out, "Disabled algorithms:\n");
  460. #ifdef OPENSSL_NO_ARIA
  461. BIO_puts(bio_out, "ARIA\n");
  462. #endif
  463. #ifdef OPENSSL_NO_BF
  464. BIO_puts(bio_out, "BF\n");
  465. #endif
  466. #ifdef OPENSSL_NO_BLAKE2
  467. BIO_puts(bio_out, "BLAKE2\n");
  468. #endif
  469. #ifdef OPENSSL_NO_CAMELLIA
  470. BIO_puts(bio_out, "CAMELLIA\n");
  471. #endif
  472. #ifdef OPENSSL_NO_CAST
  473. BIO_puts(bio_out, "CAST\n");
  474. #endif
  475. #ifdef OPENSSL_NO_CMAC
  476. BIO_puts(bio_out, "CMAC\n");
  477. #endif
  478. #ifdef OPENSSL_NO_CMS
  479. BIO_puts(bio_out, "CMS\n");
  480. #endif
  481. #ifdef OPENSSL_NO_COMP
  482. BIO_puts(bio_out, "COMP\n");
  483. #endif
  484. #ifdef OPENSSL_NO_DES
  485. BIO_puts(bio_out, "DES\n");
  486. #endif
  487. #ifdef OPENSSL_NO_DGRAM
  488. BIO_puts(bio_out, "DGRAM\n");
  489. #endif
  490. #ifdef OPENSSL_NO_DH
  491. BIO_puts(bio_out, "DH\n");
  492. #endif
  493. #ifdef OPENSSL_NO_DSA
  494. BIO_puts(bio_out, "DSA\n");
  495. #endif
  496. #if defined(OPENSSL_NO_DTLS)
  497. BIO_puts(bio_out, "DTLS\n");
  498. #endif
  499. #if defined(OPENSSL_NO_DTLS1)
  500. BIO_puts(bio_out, "DTLS1\n");
  501. #endif
  502. #if defined(OPENSSL_NO_DTLS1_2)
  503. BIO_puts(bio_out, "DTLS1_2\n");
  504. #endif
  505. #ifdef OPENSSL_NO_EC
  506. BIO_puts(bio_out, "EC\n");
  507. #endif
  508. #ifdef OPENSSL_NO_EC2M
  509. BIO_puts(bio_out, "EC2M\n");
  510. #endif
  511. #if defined(OPENSSL_NO_ENGINE) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  512. BIO_puts(bio_out, "ENGINE\n");
  513. #endif
  514. #ifdef OPENSSL_NO_GOST
  515. BIO_puts(bio_out, "GOST\n");
  516. #endif
  517. #ifdef OPENSSL_NO_IDEA
  518. BIO_puts(bio_out, "IDEA\n");
  519. #endif
  520. #ifdef OPENSSL_NO_MD2
  521. BIO_puts(bio_out, "MD2\n");
  522. #endif
  523. #ifdef OPENSSL_NO_MD4
  524. BIO_puts(bio_out, "MD4\n");
  525. #endif
  526. #ifdef OPENSSL_NO_MD5
  527. BIO_puts(bio_out, "MD5\n");
  528. #endif
  529. #ifdef OPENSSL_NO_MDC2
  530. BIO_puts(bio_out, "MDC2\n");
  531. #endif
  532. #ifdef OPENSSL_NO_OCB
  533. BIO_puts(bio_out, "OCB\n");
  534. #endif
  535. #ifdef OPENSSL_NO_OCSP
  536. BIO_puts(bio_out, "OCSP\n");
  537. #endif
  538. #ifdef OPENSSL_NO_PSK
  539. BIO_puts(bio_out, "PSK\n");
  540. #endif
  541. #ifdef OPENSSL_NO_RC2
  542. BIO_puts(bio_out, "RC2\n");
  543. #endif
  544. #ifdef OPENSSL_NO_RC4
  545. BIO_puts(bio_out, "RC4\n");
  546. #endif
  547. #ifdef OPENSSL_NO_RC5
  548. BIO_puts(bio_out, "RC5\n");
  549. #endif
  550. #ifdef OPENSSL_NO_RMD160
  551. BIO_puts(bio_out, "RMD160\n");
  552. #endif
  553. #ifdef OPENSSL_NO_RSA
  554. BIO_puts(bio_out, "RSA\n");
  555. #endif
  556. #ifdef OPENSSL_NO_SCRYPT
  557. BIO_puts(bio_out, "SCRYPT\n");
  558. #endif
  559. #ifdef OPENSSL_NO_SCTP
  560. BIO_puts(bio_out, "SCTP\n");
  561. #endif
  562. #ifdef OPENSSL_NO_SEED
  563. BIO_puts(bio_out, "SEED\n");
  564. #endif
  565. #ifdef OPENSSL_NO_SM2
  566. BIO_puts(bio_out, "SM2\n");
  567. #endif
  568. #ifdef OPENSSL_NO_SM3
  569. BIO_puts(bio_out, "SM3\n");
  570. #endif
  571. #ifdef OPENSSL_NO_SM4
  572. BIO_puts(bio_out, "SM4\n");
  573. #endif
  574. #ifdef OPENSSL_NO_SOCK
  575. BIO_puts(bio_out, "SOCK\n");
  576. #endif
  577. #ifdef OPENSSL_NO_SRP
  578. BIO_puts(bio_out, "SRP\n");
  579. #endif
  580. #ifdef OPENSSL_NO_SRTP
  581. BIO_puts(bio_out, "SRTP\n");
  582. #endif
  583. #ifdef OPENSSL_NO_SSL3
  584. BIO_puts(bio_out, "SSL3\n");
  585. #endif
  586. #ifdef OPENSSL_NO_TLS1
  587. BIO_puts(bio_out, "TLS1\n");
  588. #endif
  589. #ifdef OPENSSL_NO_TLS1_1
  590. BIO_puts(bio_out, "TLS1_1\n");
  591. #endif
  592. #ifdef OPENSSL_NO_TLS1_2
  593. BIO_puts(bio_out, "TLS1_2\n");
  594. #endif
  595. #ifdef OPENSSL_NO_WHIRLPOOL
  596. BIO_puts(bio_out, "WHIRLPOOL\n");
  597. #endif
  598. #ifndef ZLIB
  599. BIO_puts(bio_out, "ZLIB\n");
  600. #endif
  601. }
  602. /* Unified enum for help and list commands. */
  603. typedef enum HELPLIST_CHOICE {
  604. OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_ONE, OPT_VERBOSE,
  605. OPT_COMMANDS, OPT_DIGEST_COMMANDS, OPT_MAC_ALGORITHMS, OPT_OPTIONS,
  606. OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS,
  607. OPT_PK_ALGORITHMS, OPT_PK_METHOD, OPT_DISABLED,
  608. OPT_KDF_ALGORITHMS, OPT_RANDOM_GENERATORS, OPT_MISSING_HELP, OPT_OBJECTS,
  609. #ifndef OPENSSL_NO_DEPRECATED_3_0
  610. OPT_ENGINES,
  611. #endif
  612. OPT_PROV_ENUM
  613. } HELPLIST_CHOICE;
  614. const OPTIONS list_options[] = {
  615. OPT_SECTION("General"),
  616. {"help", OPT_HELP, '-', "Display this summary"},
  617. OPT_SECTION("Output"),
  618. {"1", OPT_ONE, '-', "List in one column"},
  619. {"verbose", OPT_VERBOSE, '-', "Verbose listing"},
  620. {"commands", OPT_COMMANDS, '-', "List of standard commands"},
  621. {"standard-commands", OPT_COMMANDS, '-', "List of standard commands"},
  622. {"digest-commands", OPT_DIGEST_COMMANDS, '-',
  623. "List of message digest commands"},
  624. {"digest-algorithms", OPT_DIGEST_ALGORITHMS, '-',
  625. "List of message digest algorithms"},
  626. {"kdf-algorithms", OPT_KDF_ALGORITHMS, '-',
  627. "List of key derivation and pseudo random function algorithms"},
  628. {"random-generators", OPT_RANDOM_GENERATORS, '-',
  629. "List of random number generators"},
  630. {"mac-algorithms", OPT_MAC_ALGORITHMS, '-',
  631. "List of message authentication code algorithms"},
  632. {"cipher-commands", OPT_CIPHER_COMMANDS, '-', "List of cipher commands"},
  633. {"cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-',
  634. "List of cipher algorithms"},
  635. {"public-key-algorithms", OPT_PK_ALGORITHMS, '-',
  636. "List of public key algorithms"},
  637. {"public-key-methods", OPT_PK_METHOD, '-',
  638. "List of public key methods"},
  639. #ifndef OPENSSL_NO_DEPRECATED_3_0
  640. {"engines", OPT_ENGINES, '-',
  641. "List of loaded engines"},
  642. #endif
  643. {"disabled", OPT_DISABLED, '-',
  644. "List of disabled features"},
  645. {"missing-help", OPT_MISSING_HELP, '-',
  646. "List missing detailed help strings"},
  647. {"options", OPT_OPTIONS, 's',
  648. "List options for specified command"},
  649. {"objects", OPT_OBJECTS, '-',
  650. "List built in objects (OID<->name mappings)"},
  651. OPT_PROV_OPTIONS,
  652. {NULL}
  653. };
  654. int list_main(int argc, char **argv)
  655. {
  656. char *prog;
  657. HELPLIST_CHOICE o;
  658. int one = 0, done = 0;
  659. struct {
  660. unsigned int commands:1;
  661. unsigned int random_generators:1;
  662. unsigned int digest_commands:1;
  663. unsigned int digest_algorithms:1;
  664. unsigned int kdf_algorithms:1;
  665. unsigned int mac_algorithms:1;
  666. unsigned int cipher_commands:1;
  667. unsigned int cipher_algorithms:1;
  668. unsigned int pk_algorithms:1;
  669. unsigned int pk_method:1;
  670. #ifndef OPENSSL_NO_DEPRECATED_3_0
  671. unsigned int engines:1;
  672. #endif
  673. unsigned int disabled:1;
  674. unsigned int missing_help:1;
  675. unsigned int objects:1;
  676. unsigned int options:1;
  677. } todo = { 0, };
  678. verbose = 0; /* Clear a possible previous call */
  679. prog = opt_init(argc, argv, list_options);
  680. while ((o = opt_next()) != OPT_EOF) {
  681. switch (o) {
  682. case OPT_EOF: /* Never hit, but suppresses warning */
  683. case OPT_ERR:
  684. opthelp:
  685. BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
  686. return 1;
  687. case OPT_HELP:
  688. opt_help(list_options);
  689. break;
  690. case OPT_ONE:
  691. one = 1;
  692. break;
  693. case OPT_COMMANDS:
  694. todo.commands = 1;
  695. break;
  696. case OPT_DIGEST_COMMANDS:
  697. todo.digest_commands = 1;
  698. break;
  699. case OPT_DIGEST_ALGORITHMS:
  700. todo.digest_algorithms = 1;
  701. break;
  702. case OPT_KDF_ALGORITHMS:
  703. todo.kdf_algorithms = 1;
  704. break;
  705. case OPT_RANDOM_GENERATORS:
  706. todo.random_generators = 1;
  707. break;
  708. case OPT_MAC_ALGORITHMS:
  709. todo.mac_algorithms = 1;
  710. break;
  711. case OPT_CIPHER_COMMANDS:
  712. todo.cipher_commands = 1;
  713. break;
  714. case OPT_CIPHER_ALGORITHMS:
  715. todo.cipher_algorithms = 1;
  716. break;
  717. case OPT_PK_ALGORITHMS:
  718. todo.pk_algorithms = 1;
  719. break;
  720. case OPT_PK_METHOD:
  721. todo.pk_method = 1;
  722. break;
  723. #ifndef OPENSSL_NO_DEPRECATED_3_0
  724. case OPT_ENGINES:
  725. todo.engines = 1;
  726. break;
  727. #endif
  728. case OPT_DISABLED:
  729. todo.disabled = 1;
  730. break;
  731. case OPT_MISSING_HELP:
  732. todo.missing_help = 1;
  733. break;
  734. case OPT_OBJECTS:
  735. todo.objects = 1;
  736. break;
  737. case OPT_OPTIONS:
  738. list_options_for_command(opt_arg());
  739. break;
  740. case OPT_VERBOSE:
  741. verbose = 1;
  742. break;
  743. case OPT_PROV_CASES:
  744. if (!opt_provider(o))
  745. return 1;
  746. break;
  747. }
  748. done = 1;
  749. }
  750. if (opt_num_rest() != 0) {
  751. BIO_printf(bio_err, "Extra arguments given.\n");
  752. goto opthelp;
  753. }
  754. if (todo.commands)
  755. list_type(FT_general, one);
  756. if (todo.random_generators)
  757. list_random_generators();
  758. if (todo.digest_commands)
  759. list_type(FT_md, one);
  760. if (todo.digest_algorithms)
  761. list_digests();
  762. if (todo.kdf_algorithms)
  763. list_kdfs();
  764. if (todo.mac_algorithms)
  765. list_macs();
  766. if (todo.cipher_commands)
  767. list_type(FT_cipher, one);
  768. if (todo.cipher_algorithms)
  769. list_ciphers();
  770. if (todo.pk_algorithms)
  771. list_pkey();
  772. if (todo.pk_method)
  773. list_pkey_meth();
  774. #ifndef OPENSSL_NO_DEPRECATED_3_0
  775. if (todo.engines)
  776. list_engines();
  777. #endif
  778. if (todo.disabled)
  779. list_disabled();
  780. if (todo.missing_help)
  781. list_missing_help();
  782. if (todo.objects)
  783. list_objects();
  784. if (!done)
  785. goto opthelp;
  786. return 0;
  787. }