2
0

list.c 29 KB

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