list.c 21 KB

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