list.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541
  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 <openssl/rand.h>
  21. #include "apps.h"
  22. #include "app_params.h"
  23. #include "progs.h"
  24. #include "opt.h"
  25. #include "names.h"
  26. static int verbose = 0;
  27. static const char *select_name = NULL;
  28. static void legacy_cipher_fn(const EVP_CIPHER *c,
  29. const char *from, const char *to, void *arg)
  30. {
  31. if (select_name != NULL
  32. && (c == NULL
  33. || strcasecmp(select_name, EVP_CIPHER_name(c)) != 0))
  34. return;
  35. if (c != NULL) {
  36. BIO_printf(arg, " %s\n", EVP_CIPHER_name(c));
  37. } else {
  38. if (from == NULL)
  39. from = "<undefined>";
  40. if (to == NULL)
  41. to = "<undefined>";
  42. BIO_printf(arg, " %s => %s\n", from, to);
  43. }
  44. }
  45. DEFINE_STACK_OF(EVP_CIPHER)
  46. static int cipher_cmp(const EVP_CIPHER * const *a,
  47. const EVP_CIPHER * const *b)
  48. {
  49. int ret = EVP_CIPHER_number(*a) - EVP_CIPHER_number(*b);
  50. if (ret == 0)
  51. ret = strcmp(OSSL_PROVIDER_name(EVP_CIPHER_provider(*a)),
  52. OSSL_PROVIDER_name(EVP_CIPHER_provider(*b)));
  53. return ret;
  54. }
  55. static void collect_ciphers(EVP_CIPHER *cipher, void *stack)
  56. {
  57. STACK_OF(EVP_CIPHER) *cipher_stack = stack;
  58. if (sk_EVP_CIPHER_push(cipher_stack, cipher) > 0)
  59. EVP_CIPHER_up_ref(cipher);
  60. }
  61. static void list_ciphers(void)
  62. {
  63. STACK_OF(EVP_CIPHER) *ciphers = sk_EVP_CIPHER_new(cipher_cmp);
  64. int i;
  65. if (ciphers == NULL) {
  66. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  67. return;
  68. }
  69. BIO_printf(bio_out, "Legacy:\n");
  70. EVP_CIPHER_do_all_sorted(legacy_cipher_fn, bio_out);
  71. BIO_printf(bio_out, "Provided:\n");
  72. EVP_CIPHER_do_all_provided(NULL, collect_ciphers, ciphers);
  73. sk_EVP_CIPHER_sort(ciphers);
  74. for (i = 0; i < sk_EVP_CIPHER_num(ciphers); i++) {
  75. const EVP_CIPHER *c = sk_EVP_CIPHER_value(ciphers, i);
  76. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  77. if (select_name != NULL && !EVP_CIPHER_is_a(c, select_name))
  78. continue;
  79. names = sk_OPENSSL_CSTRING_new(name_cmp);
  80. EVP_CIPHER_names_do_all(c, collect_names, names);
  81. BIO_printf(bio_out, " ");
  82. print_names(bio_out, names);
  83. sk_OPENSSL_CSTRING_free(names);
  84. BIO_printf(bio_out, " @ %s\n",
  85. OSSL_PROVIDER_name(EVP_CIPHER_provider(c)));
  86. if (verbose) {
  87. print_param_types("retrievable algorithm parameters",
  88. EVP_CIPHER_gettable_params(c), 4);
  89. print_param_types("retrievable operation parameters",
  90. EVP_CIPHER_gettable_ctx_params(c), 4);
  91. print_param_types("settable operation parameters",
  92. EVP_CIPHER_settable_ctx_params(c), 4);
  93. }
  94. }
  95. sk_EVP_CIPHER_pop_free(ciphers, EVP_CIPHER_free);
  96. }
  97. static void list_md_fn(const EVP_MD *m,
  98. const char *from, const char *to, void *arg)
  99. {
  100. if (m != NULL) {
  101. BIO_printf(arg, " %s\n", EVP_MD_name(m));
  102. } else {
  103. if (from == NULL)
  104. from = "<undefined>";
  105. if (to == NULL)
  106. to = "<undefined>";
  107. BIO_printf((BIO *)arg, " %s => %s\n", from, to);
  108. }
  109. }
  110. DEFINE_STACK_OF(EVP_MD)
  111. static int md_cmp(const EVP_MD * const *a, const EVP_MD * const *b)
  112. {
  113. int ret = EVP_MD_number(*a) - EVP_MD_number(*b);
  114. if (ret == 0)
  115. ret = strcmp(OSSL_PROVIDER_name(EVP_MD_provider(*a)),
  116. OSSL_PROVIDER_name(EVP_MD_provider(*b)));
  117. return ret;
  118. }
  119. static void collect_digests(EVP_MD *md, void *stack)
  120. {
  121. STACK_OF(EVP_MD) *digest_stack = stack;
  122. if (sk_EVP_MD_push(digest_stack, md) > 0)
  123. EVP_MD_up_ref(md);
  124. }
  125. static void list_digests(void)
  126. {
  127. STACK_OF(EVP_MD) *digests = sk_EVP_MD_new(md_cmp);
  128. int i;
  129. if (digests == NULL) {
  130. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  131. return;
  132. }
  133. BIO_printf(bio_out, "Legacy:\n");
  134. EVP_MD_do_all_sorted(list_md_fn, bio_out);
  135. BIO_printf(bio_out, "Provided:\n");
  136. EVP_MD_do_all_provided(NULL, collect_digests, digests);
  137. sk_EVP_MD_sort(digests);
  138. for (i = 0; i < sk_EVP_MD_num(digests); i++) {
  139. const EVP_MD *m = sk_EVP_MD_value(digests, i);
  140. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  141. if (select_name != NULL && !EVP_MD_is_a(m, select_name))
  142. continue;
  143. names = sk_OPENSSL_CSTRING_new(name_cmp);
  144. EVP_MD_names_do_all(m, collect_names, names);
  145. BIO_printf(bio_out, " ");
  146. print_names(bio_out, names);
  147. sk_OPENSSL_CSTRING_free(names);
  148. BIO_printf(bio_out, " @ %s\n", OSSL_PROVIDER_name(EVP_MD_provider(m)));
  149. if (verbose) {
  150. print_param_types("retrievable algorithm parameters",
  151. EVP_MD_gettable_params(m), 4);
  152. print_param_types("retrievable operation parameters",
  153. EVP_MD_gettable_ctx_params(m), 4);
  154. print_param_types("settable operation parameters",
  155. EVP_MD_settable_ctx_params(m), 4);
  156. }
  157. }
  158. sk_EVP_MD_pop_free(digests, EVP_MD_free);
  159. }
  160. DEFINE_STACK_OF(EVP_MAC)
  161. static int mac_cmp(const EVP_MAC * const *a, const EVP_MAC * const *b)
  162. {
  163. int ret = EVP_MAC_number(*a) - EVP_MAC_number(*b);
  164. if (ret == 0)
  165. ret = strcmp(OSSL_PROVIDER_name(EVP_MAC_provider(*a)),
  166. OSSL_PROVIDER_name(EVP_MAC_provider(*b)));
  167. return ret;
  168. }
  169. static void collect_macs(EVP_MAC *mac, void *stack)
  170. {
  171. STACK_OF(EVP_MAC) *mac_stack = stack;
  172. if (sk_EVP_MAC_push(mac_stack, mac) > 0)
  173. EVP_MAC_up_ref(mac);
  174. }
  175. static void list_macs(void)
  176. {
  177. STACK_OF(EVP_MAC) *macs = sk_EVP_MAC_new(mac_cmp);
  178. int i;
  179. if (macs == NULL) {
  180. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  181. return;
  182. }
  183. BIO_printf(bio_out, "Provided MACs:\n");
  184. EVP_MAC_do_all_provided(NULL, collect_macs, macs);
  185. sk_EVP_MAC_sort(macs);
  186. for (i = 0; i < sk_EVP_MAC_num(macs); i++) {
  187. const EVP_MAC *m = sk_EVP_MAC_value(macs, i);
  188. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  189. if (select_name != NULL && !EVP_MAC_is_a(m, select_name))
  190. continue;
  191. names = sk_OPENSSL_CSTRING_new(name_cmp);
  192. EVP_MAC_names_do_all(m, collect_names, names);
  193. BIO_printf(bio_out, " ");
  194. print_names(bio_out, names);
  195. sk_OPENSSL_CSTRING_free(names);
  196. BIO_printf(bio_out, " @ %s\n", OSSL_PROVIDER_name(EVP_MAC_provider(m)));
  197. if (verbose) {
  198. print_param_types("retrievable algorithm parameters",
  199. EVP_MAC_gettable_params(m), 4);
  200. print_param_types("retrievable operation parameters",
  201. EVP_MAC_gettable_ctx_params(m), 4);
  202. print_param_types("settable operation parameters",
  203. EVP_MAC_settable_ctx_params(m), 4);
  204. }
  205. }
  206. sk_EVP_MAC_pop_free(macs, EVP_MAC_free);
  207. }
  208. /*
  209. * KDFs and PRFs
  210. */
  211. DEFINE_STACK_OF(EVP_KDF)
  212. static int kdf_cmp(const EVP_KDF * const *a, const EVP_KDF * const *b)
  213. {
  214. int ret = EVP_KDF_number(*a) - EVP_KDF_number(*b);
  215. if (ret == 0)
  216. ret = strcmp(OSSL_PROVIDER_name(EVP_KDF_provider(*a)),
  217. OSSL_PROVIDER_name(EVP_KDF_provider(*b)));
  218. return ret;
  219. }
  220. static void collect_kdfs(EVP_KDF *kdf, void *stack)
  221. {
  222. STACK_OF(EVP_KDF) *kdf_stack = stack;
  223. sk_EVP_KDF_push(kdf_stack, kdf);
  224. EVP_KDF_up_ref(kdf);
  225. }
  226. static void list_kdfs(void)
  227. {
  228. STACK_OF(EVP_KDF) *kdfs = sk_EVP_KDF_new(kdf_cmp);
  229. int i;
  230. if (kdfs == NULL) {
  231. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  232. return;
  233. }
  234. BIO_printf(bio_out, "Provided KDFs and PDFs:\n");
  235. EVP_KDF_do_all_provided(NULL, collect_kdfs, kdfs);
  236. sk_EVP_KDF_sort(kdfs);
  237. for (i = 0; i < sk_EVP_KDF_num(kdfs); i++) {
  238. const EVP_KDF *k = sk_EVP_KDF_value(kdfs, i);
  239. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  240. if (select_name != NULL && !EVP_KDF_is_a(k, select_name))
  241. continue;
  242. names = sk_OPENSSL_CSTRING_new(name_cmp);
  243. EVP_KDF_names_do_all(k, collect_names, names);
  244. BIO_printf(bio_out, " ");
  245. print_names(bio_out, names);
  246. sk_OPENSSL_CSTRING_free(names);
  247. BIO_printf(bio_out, " @ %s\n", OSSL_PROVIDER_name(EVP_KDF_provider(k)));
  248. if (verbose) {
  249. print_param_types("retrievable algorithm parameters",
  250. EVP_KDF_gettable_params(k), 4);
  251. print_param_types("retrievable operation parameters",
  252. EVP_KDF_gettable_ctx_params(k), 4);
  253. print_param_types("settable operation parameters",
  254. EVP_KDF_settable_ctx_params(k), 4);
  255. }
  256. }
  257. sk_EVP_KDF_pop_free(kdfs, EVP_KDF_free);
  258. }
  259. /*
  260. * RANDs
  261. */
  262. DEFINE_STACK_OF(EVP_RAND)
  263. static int rand_cmp(const EVP_RAND * const *a, const EVP_RAND * const *b)
  264. {
  265. int ret = strcasecmp(EVP_RAND_name(*a), EVP_RAND_name(*b));
  266. if (ret == 0)
  267. ret = strcmp(OSSL_PROVIDER_name(EVP_RAND_provider(*a)),
  268. OSSL_PROVIDER_name(EVP_RAND_provider(*b)));
  269. return ret;
  270. }
  271. static void collect_rands(EVP_RAND *rand, void *stack)
  272. {
  273. STACK_OF(EVP_RAND) *rand_stack = stack;
  274. sk_EVP_RAND_push(rand_stack, rand);
  275. EVP_RAND_up_ref(rand);
  276. }
  277. static void list_random_generators(void)
  278. {
  279. STACK_OF(EVP_RAND) *rands = sk_EVP_RAND_new(rand_cmp);
  280. int i;
  281. if (rands == NULL) {
  282. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  283. return;
  284. }
  285. BIO_printf(bio_out, "Provided RNGs and seed sources:\n");
  286. EVP_RAND_do_all_provided(NULL, collect_rands, rands);
  287. sk_EVP_RAND_sort(rands);
  288. for (i = 0; i < sk_EVP_RAND_num(rands); i++) {
  289. const EVP_RAND *m = sk_EVP_RAND_value(rands, i);
  290. if (select_name != NULL
  291. && strcasecmp(EVP_RAND_name(m), select_name) != 0)
  292. continue;
  293. BIO_printf(bio_out, " %s", EVP_RAND_name(m));
  294. BIO_printf(bio_out, " @ %s\n", OSSL_PROVIDER_name(EVP_RAND_provider(m)));
  295. if (verbose) {
  296. print_param_types("retrievable algorithm parameters",
  297. EVP_RAND_gettable_params(m), 4);
  298. print_param_types("retrievable operation parameters",
  299. EVP_RAND_gettable_ctx_params(m), 4);
  300. print_param_types("settable operation parameters",
  301. EVP_RAND_settable_ctx_params(m), 4);
  302. }
  303. }
  304. sk_EVP_RAND_pop_free(rands, EVP_RAND_free);
  305. }
  306. static void display_random(const char *name, EVP_RAND_CTX *drbg)
  307. {
  308. EVP_RAND *rand;
  309. uint64_t u;
  310. const char *p;
  311. const OSSL_PARAM *gettables;
  312. OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
  313. unsigned char buf[1000];
  314. BIO_printf(bio_out, "%s:\n", name);
  315. if (drbg != NULL) {
  316. rand = EVP_RAND_CTX_rand(drbg);
  317. BIO_printf(bio_out, " %s", EVP_RAND_name(rand));
  318. BIO_printf(bio_out, " @ %s\n",
  319. OSSL_PROVIDER_name(EVP_RAND_provider(rand)));
  320. switch (EVP_RAND_state(drbg)) {
  321. case EVP_RAND_STATE_UNINITIALISED:
  322. p = "uninitialised";
  323. break;
  324. case EVP_RAND_STATE_READY:
  325. p = "ready";
  326. break;
  327. case EVP_RAND_STATE_ERROR:
  328. p = "error";
  329. break;
  330. default:
  331. p = "unknown";
  332. break;
  333. }
  334. BIO_printf(bio_out, " state = %s\n", p);
  335. gettables = EVP_RAND_gettable_ctx_params(rand);
  336. if (gettables != NULL)
  337. for (; gettables->key != NULL; gettables++) {
  338. /* State has been dealt with already, so ignore */
  339. if (strcasecmp(gettables->key, OSSL_RAND_PARAM_STATE) == 0)
  340. continue;
  341. /* Outside of verbose mode, we skip non-string values */
  342. if (gettables->data_type != OSSL_PARAM_UTF8_STRING
  343. && gettables->data_type != OSSL_PARAM_UTF8_PTR
  344. && !verbose)
  345. continue;
  346. params->key = gettables->key;
  347. params->data_type = gettables->data_type;
  348. if (gettables->data_type == OSSL_PARAM_UNSIGNED_INTEGER
  349. || gettables->data_type == OSSL_PARAM_INTEGER) {
  350. params->data = &u;
  351. params->data_size = sizeof(u);
  352. } else {
  353. params->data = buf;
  354. params->data_size = sizeof(buf);
  355. }
  356. params->return_size = 0;
  357. if (EVP_RAND_get_ctx_params(drbg, params))
  358. print_param_value(params, 2);
  359. }
  360. }
  361. }
  362. static void list_random_instances(void)
  363. {
  364. display_random("primary", RAND_get0_primary(NULL));
  365. display_random("public", RAND_get0_public(NULL));
  366. display_random("private", RAND_get0_private(NULL));
  367. }
  368. /*
  369. * Encoders
  370. */
  371. DEFINE_STACK_OF(OSSL_ENCODER)
  372. static int encoder_cmp(const OSSL_ENCODER * const *a,
  373. const OSSL_ENCODER * const *b)
  374. {
  375. int ret = OSSL_ENCODER_number(*a) - OSSL_ENCODER_number(*b);
  376. if (ret == 0)
  377. ret = strcmp(OSSL_PROVIDER_name(OSSL_ENCODER_provider(*a)),
  378. OSSL_PROVIDER_name(OSSL_ENCODER_provider(*b)));
  379. return ret;
  380. }
  381. static void collect_encoders(OSSL_ENCODER *encoder, void *stack)
  382. {
  383. STACK_OF(OSSL_ENCODER) *encoder_stack = stack;
  384. sk_OSSL_ENCODER_push(encoder_stack, encoder);
  385. OSSL_ENCODER_up_ref(encoder);
  386. }
  387. static void list_encoders(void)
  388. {
  389. STACK_OF(OSSL_ENCODER) *encoders;
  390. int i;
  391. encoders = sk_OSSL_ENCODER_new(encoder_cmp);
  392. if (encoders == NULL) {
  393. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  394. return;
  395. }
  396. BIO_printf(bio_out, "Provided ENCODERs:\n");
  397. OSSL_ENCODER_do_all_provided(NULL, collect_encoders, encoders);
  398. sk_OSSL_ENCODER_sort(encoders);
  399. for (i = 0; i < sk_OSSL_ENCODER_num(encoders); i++) {
  400. OSSL_ENCODER *k = sk_OSSL_ENCODER_value(encoders, i);
  401. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  402. if (select_name != NULL && !OSSL_ENCODER_is_a(k, select_name))
  403. continue;
  404. names = sk_OPENSSL_CSTRING_new(name_cmp);
  405. OSSL_ENCODER_names_do_all(k, collect_names, names);
  406. BIO_printf(bio_out, " ");
  407. print_names(bio_out, names);
  408. sk_OPENSSL_CSTRING_free(names);
  409. BIO_printf(bio_out, " @ %s (%s)\n",
  410. OSSL_PROVIDER_name(OSSL_ENCODER_provider(k)),
  411. OSSL_ENCODER_properties(k));
  412. if (verbose) {
  413. print_param_types("settable operation parameters",
  414. OSSL_ENCODER_settable_ctx_params(k), 4);
  415. }
  416. }
  417. sk_OSSL_ENCODER_pop_free(encoders, OSSL_ENCODER_free);
  418. }
  419. /*
  420. * Decoders
  421. */
  422. DEFINE_STACK_OF(OSSL_DECODER)
  423. static int decoder_cmp(const OSSL_DECODER * const *a,
  424. const OSSL_DECODER * const *b)
  425. {
  426. int ret = OSSL_DECODER_number(*a) - OSSL_DECODER_number(*b);
  427. if (ret == 0)
  428. ret = strcmp(OSSL_PROVIDER_name(OSSL_DECODER_provider(*a)),
  429. OSSL_PROVIDER_name(OSSL_DECODER_provider(*b)));
  430. return ret;
  431. }
  432. static void collect_decoders(OSSL_DECODER *decoder, void *stack)
  433. {
  434. STACK_OF(OSSL_DECODER) *decoder_stack = stack;
  435. sk_OSSL_DECODER_push(decoder_stack, decoder);
  436. OSSL_DECODER_up_ref(decoder);
  437. }
  438. static void list_decoders(void)
  439. {
  440. STACK_OF(OSSL_DECODER) *decoders;
  441. int i;
  442. decoders = sk_OSSL_DECODER_new(decoder_cmp);
  443. if (decoders == NULL) {
  444. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  445. return;
  446. }
  447. BIO_printf(bio_out, "Provided DECODERs:\n");
  448. OSSL_DECODER_do_all_provided(NULL, collect_decoders,
  449. decoders);
  450. sk_OSSL_DECODER_sort(decoders);
  451. for (i = 0; i < sk_OSSL_DECODER_num(decoders); i++) {
  452. OSSL_DECODER *k = sk_OSSL_DECODER_value(decoders, i);
  453. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  454. if (select_name != NULL && !OSSL_DECODER_is_a(k, select_name))
  455. continue;
  456. names = sk_OPENSSL_CSTRING_new(name_cmp);
  457. OSSL_DECODER_names_do_all(k, collect_names, names);
  458. BIO_printf(bio_out, " ");
  459. print_names(bio_out, names);
  460. sk_OPENSSL_CSTRING_free(names);
  461. BIO_printf(bio_out, " @ %s (%s)\n",
  462. OSSL_PROVIDER_name(OSSL_DECODER_provider(k)),
  463. OSSL_DECODER_properties(k));
  464. if (verbose) {
  465. print_param_types("settable operation parameters",
  466. OSSL_DECODER_settable_ctx_params(k), 4);
  467. }
  468. }
  469. sk_OSSL_DECODER_pop_free(decoders, OSSL_DECODER_free);
  470. }
  471. DEFINE_STACK_OF(EVP_KEYMGMT)
  472. static int keymanager_cmp(const EVP_KEYMGMT * const *a,
  473. const EVP_KEYMGMT * const *b)
  474. {
  475. int ret = EVP_KEYMGMT_number(*a) - EVP_KEYMGMT_number(*b);
  476. if (ret == 0)
  477. ret = strcmp(OSSL_PROVIDER_name(EVP_KEYMGMT_provider(*a)),
  478. OSSL_PROVIDER_name(EVP_KEYMGMT_provider(*b)));
  479. return ret;
  480. }
  481. static void collect_keymanagers(EVP_KEYMGMT *km, void *stack)
  482. {
  483. STACK_OF(EVP_KEYMGMT) *km_stack = stack;
  484. sk_EVP_KEYMGMT_push(km_stack, km);
  485. EVP_KEYMGMT_up_ref(km);
  486. }
  487. static void list_keymanagers(void)
  488. {
  489. int i;
  490. STACK_OF(EVP_KEYMGMT) *km_stack = sk_EVP_KEYMGMT_new(keymanager_cmp);
  491. EVP_KEYMGMT_do_all_provided(NULL, collect_keymanagers, km_stack);
  492. sk_EVP_KEYMGMT_sort(km_stack);
  493. for (i = 0; i < sk_EVP_KEYMGMT_num(km_stack); i++) {
  494. EVP_KEYMGMT *k = sk_EVP_KEYMGMT_value(km_stack, i);
  495. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  496. if (select_name != NULL && !EVP_KEYMGMT_is_a(k, select_name))
  497. continue;
  498. names = sk_OPENSSL_CSTRING_new(name_cmp);
  499. EVP_KEYMGMT_names_do_all(k, collect_names, names);
  500. BIO_printf(bio_out, " ");
  501. print_names(bio_out, names);
  502. sk_OPENSSL_CSTRING_free(names);
  503. BIO_printf(bio_out, " @ %s\n",
  504. OSSL_PROVIDER_name(EVP_KEYMGMT_provider(k)));
  505. if (verbose) {
  506. print_param_types("settable key generation parameters",
  507. EVP_KEYMGMT_gen_settable_params(k), 4);
  508. print_param_types("settable operation parameters",
  509. EVP_KEYMGMT_settable_params(k), 4);
  510. print_param_types("retrievable operation parameters",
  511. EVP_KEYMGMT_gettable_params(k), 4);
  512. }
  513. }
  514. sk_EVP_KEYMGMT_pop_free(km_stack, EVP_KEYMGMT_free);
  515. }
  516. DEFINE_STACK_OF(EVP_SIGNATURE)
  517. static int signature_cmp(const EVP_SIGNATURE * const *a,
  518. const EVP_SIGNATURE * const *b)
  519. {
  520. int ret = EVP_SIGNATURE_number(*a) - EVP_SIGNATURE_number(*b);
  521. if (ret == 0)
  522. ret = strcmp(OSSL_PROVIDER_name(EVP_SIGNATURE_provider(*a)),
  523. OSSL_PROVIDER_name(EVP_SIGNATURE_provider(*b)));
  524. return ret;
  525. }
  526. static void collect_signatures(EVP_SIGNATURE *km, void *stack)
  527. {
  528. STACK_OF(EVP_SIGNATURE) *km_stack = stack;
  529. sk_EVP_SIGNATURE_push(km_stack, km);
  530. EVP_SIGNATURE_up_ref(km);
  531. }
  532. static void list_signatures(void)
  533. {
  534. int i, count = 0;
  535. STACK_OF(EVP_SIGNATURE) *sig_stack = sk_EVP_SIGNATURE_new(signature_cmp);
  536. EVP_SIGNATURE_do_all_provided(NULL, collect_signatures, sig_stack);
  537. sk_EVP_SIGNATURE_sort(sig_stack);
  538. for (i = 0; i < sk_EVP_SIGNATURE_num(sig_stack); i++) {
  539. EVP_SIGNATURE *k = sk_EVP_SIGNATURE_value(sig_stack, i);
  540. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  541. if (select_name != NULL && !EVP_SIGNATURE_is_a(k, select_name))
  542. continue;
  543. names = sk_OPENSSL_CSTRING_new(name_cmp);
  544. EVP_SIGNATURE_names_do_all(k, collect_names, names);
  545. count++;
  546. BIO_printf(bio_out, " ");
  547. print_names(bio_out, names);
  548. sk_OPENSSL_CSTRING_free(names);
  549. BIO_printf(bio_out, " @ %s\n",
  550. OSSL_PROVIDER_name(EVP_SIGNATURE_provider(k)));
  551. if (verbose) {
  552. print_param_types("settable operation parameters",
  553. EVP_SIGNATURE_settable_ctx_params(k), 4);
  554. print_param_types("retrievable operation parameters",
  555. EVP_SIGNATURE_gettable_ctx_params(k), 4);
  556. }
  557. }
  558. sk_EVP_SIGNATURE_pop_free(sig_stack, EVP_SIGNATURE_free);
  559. if (count == 0)
  560. BIO_printf(bio_out, " -\n");
  561. }
  562. DEFINE_STACK_OF(EVP_KEM)
  563. static int kem_cmp(const EVP_KEM * const *a,
  564. const EVP_KEM * const *b)
  565. {
  566. int ret = EVP_KEM_number(*a) - EVP_KEM_number(*b);
  567. if (ret == 0)
  568. ret = strcmp(OSSL_PROVIDER_name(EVP_KEM_provider(*a)),
  569. OSSL_PROVIDER_name(EVP_KEM_provider(*b)));
  570. return ret;
  571. }
  572. static void collect_kem(EVP_KEM *km, void *stack)
  573. {
  574. STACK_OF(EVP_KEM) *km_stack = stack;
  575. sk_EVP_KEM_push(km_stack, km);
  576. EVP_KEM_up_ref(km);
  577. }
  578. static void list_kems(void)
  579. {
  580. int i, count = 0;
  581. STACK_OF(EVP_KEM) *kem_stack = sk_EVP_KEM_new(kem_cmp);
  582. EVP_KEM_do_all_provided(NULL, collect_kem, kem_stack);
  583. sk_EVP_KEM_sort(kem_stack);
  584. for (i = 0; i < sk_EVP_KEM_num(kem_stack); i++) {
  585. EVP_KEM *k = sk_EVP_KEM_value(kem_stack, i);
  586. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  587. if (select_name != NULL && !EVP_KEM_is_a(k, select_name))
  588. continue;
  589. names = sk_OPENSSL_CSTRING_new(name_cmp);
  590. EVP_KEM_names_do_all(k, collect_names, names);
  591. count++;
  592. BIO_printf(bio_out, " ");
  593. print_names(bio_out, names);
  594. sk_OPENSSL_CSTRING_free(names);
  595. BIO_printf(bio_out, " @ %s\n", OSSL_PROVIDER_name(EVP_KEM_provider(k)));
  596. if (verbose) {
  597. print_param_types("settable operation parameters",
  598. EVP_KEM_settable_ctx_params(k), 4);
  599. print_param_types("retrievable operation parameters",
  600. EVP_KEM_gettable_ctx_params(k), 4);
  601. }
  602. }
  603. sk_EVP_KEM_pop_free(kem_stack, EVP_KEM_free);
  604. if (count == 0)
  605. BIO_printf(bio_out, " -\n");
  606. }
  607. DEFINE_STACK_OF(EVP_ASYM_CIPHER)
  608. static int asymcipher_cmp(const EVP_ASYM_CIPHER * const *a,
  609. const EVP_ASYM_CIPHER * const *b)
  610. {
  611. int ret = EVP_ASYM_CIPHER_number(*a) - EVP_ASYM_CIPHER_number(*b);
  612. if (ret == 0)
  613. ret = strcmp(OSSL_PROVIDER_name(EVP_ASYM_CIPHER_provider(*a)),
  614. OSSL_PROVIDER_name(EVP_ASYM_CIPHER_provider(*b)));
  615. return ret;
  616. }
  617. static void collect_asymciph(EVP_ASYM_CIPHER *km, void *stack)
  618. {
  619. STACK_OF(EVP_ASYM_CIPHER) *km_stack = stack;
  620. sk_EVP_ASYM_CIPHER_push(km_stack, km);
  621. EVP_ASYM_CIPHER_up_ref(km);
  622. }
  623. static void list_asymciphers(void)
  624. {
  625. int i, count = 0;
  626. STACK_OF(EVP_ASYM_CIPHER) *asymciph_stack =
  627. sk_EVP_ASYM_CIPHER_new(asymcipher_cmp);
  628. EVP_ASYM_CIPHER_do_all_provided(NULL, collect_asymciph, asymciph_stack);
  629. sk_EVP_ASYM_CIPHER_sort(asymciph_stack);
  630. for (i = 0; i < sk_EVP_ASYM_CIPHER_num(asymciph_stack); i++) {
  631. EVP_ASYM_CIPHER *k = sk_EVP_ASYM_CIPHER_value(asymciph_stack, i);
  632. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  633. if (select_name != NULL && !EVP_ASYM_CIPHER_is_a(k, select_name))
  634. continue;
  635. names = sk_OPENSSL_CSTRING_new(name_cmp);
  636. EVP_ASYM_CIPHER_names_do_all(k, collect_names, names);
  637. count++;
  638. BIO_printf(bio_out, " ");
  639. print_names(bio_out, names);
  640. sk_OPENSSL_CSTRING_free(names);
  641. BIO_printf(bio_out, " @ %s\n",
  642. OSSL_PROVIDER_name(EVP_ASYM_CIPHER_provider(k)));
  643. if (verbose) {
  644. print_param_types("settable operation parameters",
  645. EVP_ASYM_CIPHER_settable_ctx_params(k), 4);
  646. print_param_types("retrievable operation parameters",
  647. EVP_ASYM_CIPHER_gettable_ctx_params(k), 4);
  648. }
  649. }
  650. sk_EVP_ASYM_CIPHER_pop_free(asymciph_stack, EVP_ASYM_CIPHER_free);
  651. if (count == 0)
  652. BIO_printf(bio_out, " -\n");
  653. }
  654. DEFINE_STACK_OF(EVP_KEYEXCH)
  655. static int kex_cmp(const EVP_KEYEXCH * const *a,
  656. const EVP_KEYEXCH * const *b)
  657. {
  658. int ret = EVP_KEYEXCH_number(*a) - EVP_KEYEXCH_number(*b);
  659. if (ret == 0)
  660. ret = strcmp(OSSL_PROVIDER_name(EVP_KEYEXCH_provider(*a)),
  661. OSSL_PROVIDER_name(EVP_KEYEXCH_provider(*b)));
  662. return ret;
  663. }
  664. static void collect_kex(EVP_KEYEXCH *ke, void *stack)
  665. {
  666. STACK_OF(EVP_KEYEXCH) *kex_stack = stack;
  667. sk_EVP_KEYEXCH_push(kex_stack, ke);
  668. EVP_KEYEXCH_up_ref(ke);
  669. }
  670. static void list_keyexchanges(void)
  671. {
  672. int i, count = 0;
  673. STACK_OF(EVP_KEYEXCH) *kex_stack = sk_EVP_KEYEXCH_new(kex_cmp);
  674. EVP_KEYEXCH_do_all_provided(NULL, collect_kex, kex_stack);
  675. sk_EVP_KEYEXCH_sort(kex_stack);
  676. for (i = 0; i < sk_EVP_KEYEXCH_num(kex_stack); i++) {
  677. EVP_KEYEXCH *k = sk_EVP_KEYEXCH_value(kex_stack, i);
  678. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  679. if (select_name != NULL && !EVP_KEYEXCH_is_a(k, select_name))
  680. continue;
  681. names = sk_OPENSSL_CSTRING_new(name_cmp);
  682. EVP_KEYEXCH_names_do_all(k, collect_names, names);
  683. count++;
  684. BIO_printf(bio_out, " ");
  685. print_names(bio_out, names);
  686. sk_OPENSSL_CSTRING_free(names);
  687. BIO_printf(bio_out, " @ %s\n",
  688. OSSL_PROVIDER_name(EVP_KEYEXCH_provider(k)));
  689. if (verbose) {
  690. print_param_types("settable operation parameters",
  691. EVP_KEYEXCH_settable_ctx_params(k), 4);
  692. print_param_types("retrievable operation parameters",
  693. EVP_KEYEXCH_gettable_ctx_params(k), 4);
  694. }
  695. }
  696. sk_EVP_KEYEXCH_pop_free(kex_stack, EVP_KEYEXCH_free);
  697. if (count == 0)
  698. BIO_printf(bio_out, " -\n");
  699. }
  700. static void list_missing_help(void)
  701. {
  702. const FUNCTION *fp;
  703. const OPTIONS *o;
  704. for (fp = functions; fp->name != NULL; fp++) {
  705. if ((o = fp->help) != NULL) {
  706. /* If there is help, list what flags are not documented. */
  707. for ( ; o->name != NULL; o++) {
  708. if (o->helpstr == NULL)
  709. BIO_printf(bio_out, "%s %s\n", fp->name, o->name);
  710. }
  711. } else if (fp->func != dgst_main) {
  712. /* If not aliased to the dgst command, */
  713. BIO_printf(bio_out, "%s *\n", fp->name);
  714. }
  715. }
  716. }
  717. static void list_objects(void)
  718. {
  719. int max_nid = OBJ_new_nid(0);
  720. int i;
  721. char *oid_buf = NULL;
  722. int oid_size = 0;
  723. /* Skip 0, since that's NID_undef */
  724. for (i = 1; i < max_nid; i++) {
  725. const ASN1_OBJECT *obj = OBJ_nid2obj(i);
  726. const char *sn = OBJ_nid2sn(i);
  727. const char *ln = OBJ_nid2ln(i);
  728. int n = 0;
  729. /*
  730. * If one of the retrieved objects somehow generated an error,
  731. * we ignore it. The check for NID_undef below will detect the
  732. * error and simply skip to the next NID.
  733. */
  734. ERR_clear_error();
  735. if (OBJ_obj2nid(obj) == NID_undef)
  736. continue;
  737. if ((n = OBJ_obj2txt(NULL, 0, obj, 1)) == 0) {
  738. BIO_printf(bio_out, "# None-OID object: %s, %s\n", sn, ln);
  739. continue;
  740. }
  741. if (n < 0)
  742. break; /* Error */
  743. if (n > oid_size) {
  744. oid_buf = OPENSSL_realloc(oid_buf, n + 1);
  745. if (oid_buf == NULL) {
  746. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  747. break; /* Error */
  748. }
  749. oid_size = n + 1;
  750. }
  751. if (OBJ_obj2txt(oid_buf, oid_size, obj, 1) < 0)
  752. break; /* Error */
  753. if (ln == NULL || strcmp(sn, ln) == 0)
  754. BIO_printf(bio_out, "%s = %s\n", sn, oid_buf);
  755. else
  756. BIO_printf(bio_out, "%s = %s, %s\n", sn, ln, oid_buf);
  757. }
  758. OPENSSL_free(oid_buf);
  759. }
  760. static void list_options_for_command(const char *command)
  761. {
  762. const FUNCTION *fp;
  763. const OPTIONS *o;
  764. for (fp = functions; fp->name != NULL; fp++)
  765. if (strcmp(fp->name, command) == 0)
  766. break;
  767. if (fp->name == NULL) {
  768. BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n",
  769. command);
  770. return;
  771. }
  772. if ((o = fp->help) == NULL)
  773. return;
  774. for ( ; o->name != NULL; o++) {
  775. char c = o->valtype;
  776. if (o->name == OPT_PARAM_STR)
  777. break;
  778. if (o->name == OPT_HELP_STR
  779. || o->name == OPT_MORE_STR
  780. || o->name == OPT_SECTION_STR
  781. || o->name[0] == '\0')
  782. continue;
  783. BIO_printf(bio_out, "%s %c\n", o->name, c == '\0' ? '-' : c);
  784. }
  785. /* Always output the -- marker since it is sometimes documented. */
  786. BIO_printf(bio_out, "- -\n");
  787. }
  788. static void list_type(FUNC_TYPE ft, int one)
  789. {
  790. FUNCTION *fp;
  791. int i = 0;
  792. DISPLAY_COLUMNS dc;
  793. memset(&dc, 0, sizeof(dc));
  794. if (!one)
  795. calculate_columns(functions, &dc);
  796. for (fp = functions; fp->name != NULL; fp++) {
  797. if (fp->type != ft)
  798. continue;
  799. if (one) {
  800. BIO_printf(bio_out, "%s\n", fp->name);
  801. } else {
  802. if (i % dc.columns == 0 && i > 0)
  803. BIO_printf(bio_out, "\n");
  804. BIO_printf(bio_out, "%-*s", dc.width, fp->name);
  805. i++;
  806. }
  807. }
  808. if (!one)
  809. BIO_printf(bio_out, "\n\n");
  810. }
  811. static void list_pkey(void)
  812. {
  813. #ifndef OPENSSL_NO_DEPRECATED_3_0
  814. int i;
  815. if (select_name == NULL) {
  816. BIO_printf(bio_out, "Legacy:\n");
  817. for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
  818. const EVP_PKEY_ASN1_METHOD *ameth;
  819. int pkey_id, pkey_base_id, pkey_flags;
  820. const char *pinfo, *pem_str;
  821. ameth = EVP_PKEY_asn1_get0(i);
  822. EVP_PKEY_asn1_get0_info(&pkey_id, &pkey_base_id, &pkey_flags,
  823. &pinfo, &pem_str, ameth);
  824. if (pkey_flags & ASN1_PKEY_ALIAS) {
  825. BIO_printf(bio_out, " Name: %s\n", OBJ_nid2ln(pkey_id));
  826. BIO_printf(bio_out, "\tAlias for: %s\n",
  827. OBJ_nid2ln(pkey_base_id));
  828. } else {
  829. BIO_printf(bio_out, " Name: %s\n", pinfo);
  830. BIO_printf(bio_out, "\tType: %s Algorithm\n",
  831. pkey_flags & ASN1_PKEY_DYNAMIC ?
  832. "External" : "Builtin");
  833. BIO_printf(bio_out, "\tOID: %s\n", OBJ_nid2ln(pkey_id));
  834. if (pem_str == NULL)
  835. pem_str = "(none)";
  836. BIO_printf(bio_out, "\tPEM string: %s\n", pem_str);
  837. }
  838. }
  839. }
  840. #endif
  841. BIO_printf(bio_out, "Provided:\n");
  842. BIO_printf(bio_out, " Key Managers:\n");
  843. list_keymanagers();
  844. }
  845. static void list_pkey_meth(void)
  846. {
  847. #ifndef OPENSSL_NO_DEPRECATED_3_0
  848. size_t i;
  849. size_t meth_count = EVP_PKEY_meth_get_count();
  850. if (select_name == NULL) {
  851. BIO_printf(bio_out, "Legacy:\n");
  852. for (i = 0; i < meth_count; i++) {
  853. const EVP_PKEY_METHOD *pmeth = EVP_PKEY_meth_get0(i);
  854. int pkey_id, pkey_flags;
  855. EVP_PKEY_meth_get0_info(&pkey_id, &pkey_flags, pmeth);
  856. BIO_printf(bio_out, " %s\n", OBJ_nid2ln(pkey_id));
  857. BIO_printf(bio_out, "\tType: %s Algorithm\n",
  858. pkey_flags & ASN1_PKEY_DYNAMIC ? "External" : "Builtin");
  859. }
  860. }
  861. #endif
  862. BIO_printf(bio_out, "Provided:\n");
  863. BIO_printf(bio_out, " Encryption:\n");
  864. list_asymciphers();
  865. BIO_printf(bio_out, " Key Exchange:\n");
  866. list_keyexchanges();
  867. BIO_printf(bio_out, " Signatures:\n");
  868. list_signatures();
  869. BIO_printf(bio_out, " Key encapsulation:\n");
  870. list_kems();
  871. }
  872. DEFINE_STACK_OF(OSSL_PROVIDER)
  873. static int provider_cmp(const OSSL_PROVIDER * const *a,
  874. const OSSL_PROVIDER * const *b)
  875. {
  876. return strcmp(OSSL_PROVIDER_name(*a), OSSL_PROVIDER_name(*b));
  877. }
  878. static int collect_providers(OSSL_PROVIDER *provider, void *stack)
  879. {
  880. STACK_OF(OSSL_PROVIDER) *provider_stack = stack;
  881. sk_OSSL_PROVIDER_push(provider_stack, provider);
  882. return 1;
  883. }
  884. static void list_provider_info(void)
  885. {
  886. STACK_OF(OSSL_PROVIDER) *providers = sk_OSSL_PROVIDER_new(provider_cmp);
  887. OSSL_PARAM params[5];
  888. char *name, *version, *buildinfo;
  889. int status;
  890. int i;
  891. if (providers == NULL) {
  892. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  893. return;
  894. }
  895. BIO_printf(bio_out, "Providers:\n");
  896. OSSL_PROVIDER_do_all(NULL, &collect_providers, providers);
  897. sk_OSSL_PROVIDER_sort(providers);
  898. for (i = 0; i < sk_OSSL_PROVIDER_num(providers); i++) {
  899. const OSSL_PROVIDER *prov = sk_OSSL_PROVIDER_value(providers, i);
  900. /* Query the "known" information parameters, the order matches below */
  901. params[0] = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_NAME,
  902. &name, 0);
  903. params[1] = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_VERSION,
  904. &version, 0);
  905. params[2] = OSSL_PARAM_construct_int(OSSL_PROV_PARAM_STATUS, &status);
  906. params[3] = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_BUILDINFO,
  907. &buildinfo, 0);
  908. params[4] = OSSL_PARAM_construct_end();
  909. OSSL_PARAM_set_all_unmodified(params);
  910. if (!OSSL_PROVIDER_get_params(prov, params)) {
  911. BIO_printf(bio_err, "ERROR: Unable to query provider parameters\n");
  912. return;
  913. }
  914. /* Print out the provider information, the params order matches above */
  915. BIO_printf(bio_out, " %s\n", OSSL_PROVIDER_name(prov));
  916. if (OSSL_PARAM_modified(params))
  917. BIO_printf(bio_out, " name: %s\n", name);
  918. if (OSSL_PARAM_modified(params + 1))
  919. BIO_printf(bio_out, " version: %s\n", version);
  920. if (OSSL_PARAM_modified(params + 2))
  921. BIO_printf(bio_out, " status: %sactive\n", status ? "" : "in");
  922. if (verbose) {
  923. if (OSSL_PARAM_modified(params + 3))
  924. BIO_printf(bio_out, " build info: %s\n", buildinfo);
  925. print_param_types("gettable provider parameters",
  926. OSSL_PROVIDER_gettable_params(prov), 4);
  927. }
  928. }
  929. sk_OSSL_PROVIDER_free(providers);
  930. }
  931. #ifndef OPENSSL_NO_DEPRECATED_3_0
  932. static void list_engines(void)
  933. {
  934. # ifndef OPENSSL_NO_ENGINE
  935. ENGINE *e;
  936. BIO_puts(bio_out, "Engines:\n");
  937. e = ENGINE_get_first();
  938. while (e) {
  939. BIO_printf(bio_out, "%s\n", ENGINE_get_id(e));
  940. e = ENGINE_get_next(e);
  941. }
  942. # else
  943. BIO_puts(bio_out, "Engine support is disabled.\n");
  944. # endif
  945. }
  946. #endif
  947. static void list_disabled(void)
  948. {
  949. BIO_puts(bio_out, "Disabled algorithms:\n");
  950. #ifdef OPENSSL_NO_ARIA
  951. BIO_puts(bio_out, "ARIA\n");
  952. #endif
  953. #ifdef OPENSSL_NO_BF
  954. BIO_puts(bio_out, "BF\n");
  955. #endif
  956. #ifdef OPENSSL_NO_BLAKE2
  957. BIO_puts(bio_out, "BLAKE2\n");
  958. #endif
  959. #ifdef OPENSSL_NO_CAMELLIA
  960. BIO_puts(bio_out, "CAMELLIA\n");
  961. #endif
  962. #ifdef OPENSSL_NO_CAST
  963. BIO_puts(bio_out, "CAST\n");
  964. #endif
  965. #ifdef OPENSSL_NO_CMAC
  966. BIO_puts(bio_out, "CMAC\n");
  967. #endif
  968. #ifdef OPENSSL_NO_CMS
  969. BIO_puts(bio_out, "CMS\n");
  970. #endif
  971. #ifdef OPENSSL_NO_COMP
  972. BIO_puts(bio_out, "COMP\n");
  973. #endif
  974. #ifdef OPENSSL_NO_DES
  975. BIO_puts(bio_out, "DES\n");
  976. #endif
  977. #ifdef OPENSSL_NO_DGRAM
  978. BIO_puts(bio_out, "DGRAM\n");
  979. #endif
  980. #ifdef OPENSSL_NO_DH
  981. BIO_puts(bio_out, "DH\n");
  982. #endif
  983. #ifdef OPENSSL_NO_DSA
  984. BIO_puts(bio_out, "DSA\n");
  985. #endif
  986. #if defined(OPENSSL_NO_DTLS)
  987. BIO_puts(bio_out, "DTLS\n");
  988. #endif
  989. #if defined(OPENSSL_NO_DTLS1)
  990. BIO_puts(bio_out, "DTLS1\n");
  991. #endif
  992. #if defined(OPENSSL_NO_DTLS1_2)
  993. BIO_puts(bio_out, "DTLS1_2\n");
  994. #endif
  995. #ifdef OPENSSL_NO_EC
  996. BIO_puts(bio_out, "EC\n");
  997. #endif
  998. #ifdef OPENSSL_NO_EC2M
  999. BIO_puts(bio_out, "EC2M\n");
  1000. #endif
  1001. #if defined(OPENSSL_NO_ENGINE) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  1002. BIO_puts(bio_out, "ENGINE\n");
  1003. #endif
  1004. #ifdef OPENSSL_NO_GOST
  1005. BIO_puts(bio_out, "GOST\n");
  1006. #endif
  1007. #ifdef OPENSSL_NO_IDEA
  1008. BIO_puts(bio_out, "IDEA\n");
  1009. #endif
  1010. #ifdef OPENSSL_NO_MD2
  1011. BIO_puts(bio_out, "MD2\n");
  1012. #endif
  1013. #ifdef OPENSSL_NO_MD4
  1014. BIO_puts(bio_out, "MD4\n");
  1015. #endif
  1016. #ifdef OPENSSL_NO_MD5
  1017. BIO_puts(bio_out, "MD5\n");
  1018. #endif
  1019. #ifdef OPENSSL_NO_MDC2
  1020. BIO_puts(bio_out, "MDC2\n");
  1021. #endif
  1022. #ifdef OPENSSL_NO_OCB
  1023. BIO_puts(bio_out, "OCB\n");
  1024. #endif
  1025. #ifdef OPENSSL_NO_OCSP
  1026. BIO_puts(bio_out, "OCSP\n");
  1027. #endif
  1028. #ifdef OPENSSL_NO_PSK
  1029. BIO_puts(bio_out, "PSK\n");
  1030. #endif
  1031. #ifdef OPENSSL_NO_RC2
  1032. BIO_puts(bio_out, "RC2\n");
  1033. #endif
  1034. #ifdef OPENSSL_NO_RC4
  1035. BIO_puts(bio_out, "RC4\n");
  1036. #endif
  1037. #ifdef OPENSSL_NO_RC5
  1038. BIO_puts(bio_out, "RC5\n");
  1039. #endif
  1040. #ifdef OPENSSL_NO_RMD160
  1041. BIO_puts(bio_out, "RMD160\n");
  1042. #endif
  1043. #ifdef OPENSSL_NO_RSA
  1044. BIO_puts(bio_out, "RSA\n");
  1045. #endif
  1046. #ifdef OPENSSL_NO_SCRYPT
  1047. BIO_puts(bio_out, "SCRYPT\n");
  1048. #endif
  1049. #ifdef OPENSSL_NO_SCTP
  1050. BIO_puts(bio_out, "SCTP\n");
  1051. #endif
  1052. #ifdef OPENSSL_NO_SEED
  1053. BIO_puts(bio_out, "SEED\n");
  1054. #endif
  1055. #ifdef OPENSSL_NO_SM2
  1056. BIO_puts(bio_out, "SM2\n");
  1057. #endif
  1058. #ifdef OPENSSL_NO_SM3
  1059. BIO_puts(bio_out, "SM3\n");
  1060. #endif
  1061. #ifdef OPENSSL_NO_SM4
  1062. BIO_puts(bio_out, "SM4\n");
  1063. #endif
  1064. #ifdef OPENSSL_NO_SOCK
  1065. BIO_puts(bio_out, "SOCK\n");
  1066. #endif
  1067. #ifdef OPENSSL_NO_SRP
  1068. BIO_puts(bio_out, "SRP\n");
  1069. #endif
  1070. #ifdef OPENSSL_NO_SRTP
  1071. BIO_puts(bio_out, "SRTP\n");
  1072. #endif
  1073. #ifdef OPENSSL_NO_SSL3
  1074. BIO_puts(bio_out, "SSL3\n");
  1075. #endif
  1076. #ifdef OPENSSL_NO_TLS1
  1077. BIO_puts(bio_out, "TLS1\n");
  1078. #endif
  1079. #ifdef OPENSSL_NO_TLS1_1
  1080. BIO_puts(bio_out, "TLS1_1\n");
  1081. #endif
  1082. #ifdef OPENSSL_NO_TLS1_2
  1083. BIO_puts(bio_out, "TLS1_2\n");
  1084. #endif
  1085. #ifdef OPENSSL_NO_WHIRLPOOL
  1086. BIO_puts(bio_out, "WHIRLPOOL\n");
  1087. #endif
  1088. #ifndef ZLIB
  1089. BIO_puts(bio_out, "ZLIB\n");
  1090. #endif
  1091. }
  1092. /* Unified enum for help and list commands. */
  1093. typedef enum HELPLIST_CHOICE {
  1094. OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_ONE, OPT_VERBOSE,
  1095. OPT_COMMANDS, OPT_DIGEST_COMMANDS, OPT_MAC_ALGORITHMS, OPT_OPTIONS,
  1096. OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS,
  1097. OPT_PK_ALGORITHMS, OPT_PK_METHOD, OPT_DISABLED,
  1098. OPT_KDF_ALGORITHMS, OPT_RANDOM_INSTANCES, OPT_RANDOM_GENERATORS,
  1099. OPT_ENCODERS, OPT_DECODERS, OPT_KEYMANAGERS, OPT_KEYEXCHANGE_ALGORITHMS,
  1100. OPT_KEM_ALGORITHMS, OPT_SIGNATURE_ALGORITHMS, OPT_ASYM_CIPHER_ALGORITHMS,
  1101. OPT_PROVIDER_INFO,
  1102. OPT_MISSING_HELP, OPT_OBJECTS, OPT_SELECT_NAME,
  1103. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1104. OPT_ENGINES,
  1105. #endif
  1106. OPT_PROV_ENUM
  1107. } HELPLIST_CHOICE;
  1108. const OPTIONS list_options[] = {
  1109. OPT_SECTION("General"),
  1110. {"help", OPT_HELP, '-', "Display this summary"},
  1111. OPT_SECTION("Output"),
  1112. {"1", OPT_ONE, '-', "List in one column"},
  1113. {"verbose", OPT_VERBOSE, '-', "Verbose listing"},
  1114. {"select", OPT_SELECT_NAME, 's', "Select a single algorithm"},
  1115. {"commands", OPT_COMMANDS, '-', "List of standard commands"},
  1116. {"standard-commands", OPT_COMMANDS, '-', "List of standard commands"},
  1117. {"digest-commands", OPT_DIGEST_COMMANDS, '-',
  1118. "List of message digest commands"},
  1119. {"digest-algorithms", OPT_DIGEST_ALGORITHMS, '-',
  1120. "List of message digest algorithms"},
  1121. {"kdf-algorithms", OPT_KDF_ALGORITHMS, '-',
  1122. "List of key derivation and pseudo random function algorithms"},
  1123. {"random-instances", OPT_RANDOM_INSTANCES, '-',
  1124. "List the primary, pubic and private random number generator details"},
  1125. {"random-generators", OPT_RANDOM_GENERATORS, '-',
  1126. "List of random number generators"},
  1127. {"mac-algorithms", OPT_MAC_ALGORITHMS, '-',
  1128. "List of message authentication code algorithms"},
  1129. {"cipher-commands", OPT_CIPHER_COMMANDS, '-', "List of cipher commands"},
  1130. {"cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-',
  1131. "List of cipher algorithms"},
  1132. {"encoders", OPT_ENCODERS, '-', "List of encoding methods" },
  1133. {"decoders", OPT_DECODERS, '-', "List of decoding methods" },
  1134. {"key-managers", OPT_KEYMANAGERS, '-', "List of key managers" },
  1135. {"key-exchange-algorithms", OPT_KEYEXCHANGE_ALGORITHMS, '-',
  1136. "List of key exchange algorithms" },
  1137. {"kem-algorithms", OPT_KEM_ALGORITHMS, '-',
  1138. "List of key encapsulation mechanism algorithms" },
  1139. {"signature-algorithms", OPT_SIGNATURE_ALGORITHMS, '-',
  1140. "List of signature algorithms" },
  1141. { "asymcipher-algorithms", OPT_ASYM_CIPHER_ALGORITHMS, '-',
  1142. "List of asymmetric cipher algorithms" },
  1143. {"public-key-algorithms", OPT_PK_ALGORITHMS, '-',
  1144. "List of public key algorithms"},
  1145. {"public-key-methods", OPT_PK_METHOD, '-',
  1146. "List of public key methods"},
  1147. {"providers", OPT_PROVIDER_INFO, '-',
  1148. "List of provider information"},
  1149. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1150. {"engines", OPT_ENGINES, '-',
  1151. "List of loaded engines"},
  1152. #endif
  1153. {"disabled", OPT_DISABLED, '-', "List of disabled features"},
  1154. {"missing-help", OPT_MISSING_HELP, '-',
  1155. "List missing detailed help strings"},
  1156. {"options", OPT_OPTIONS, 's',
  1157. "List options for specified command"},
  1158. {"objects", OPT_OBJECTS, '-',
  1159. "List built in objects (OID<->name mappings)"},
  1160. OPT_PROV_OPTIONS,
  1161. {NULL}
  1162. };
  1163. int list_main(int argc, char **argv)
  1164. {
  1165. char *prog;
  1166. HELPLIST_CHOICE o;
  1167. int one = 0, done = 0;
  1168. struct {
  1169. unsigned int commands:1;
  1170. unsigned int random_instances:1;
  1171. unsigned int random_generators:1;
  1172. unsigned int digest_commands:1;
  1173. unsigned int digest_algorithms:1;
  1174. unsigned int kdf_algorithms:1;
  1175. unsigned int mac_algorithms:1;
  1176. unsigned int cipher_commands:1;
  1177. unsigned int cipher_algorithms:1;
  1178. unsigned int encoder_algorithms:1;
  1179. unsigned int decoder_algorithms:1;
  1180. unsigned int keymanager_algorithms:1;
  1181. unsigned int signature_algorithms:1;
  1182. unsigned int keyexchange_algorithms:1;
  1183. unsigned int kem_algorithms:1;
  1184. unsigned int asym_cipher_algorithms:1;
  1185. unsigned int pk_algorithms:1;
  1186. unsigned int pk_method:1;
  1187. unsigned int provider_info:1;
  1188. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1189. unsigned int engines:1;
  1190. #endif
  1191. unsigned int disabled:1;
  1192. unsigned int missing_help:1;
  1193. unsigned int objects:1;
  1194. unsigned int options:1;
  1195. } todo = { 0, };
  1196. verbose = 0; /* Clear a possible previous call */
  1197. prog = opt_init(argc, argv, list_options);
  1198. while ((o = opt_next()) != OPT_EOF) {
  1199. switch (o) {
  1200. case OPT_EOF: /* Never hit, but suppresses warning */
  1201. case OPT_ERR:
  1202. opthelp:
  1203. BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
  1204. return 1;
  1205. case OPT_HELP:
  1206. opt_help(list_options);
  1207. break;
  1208. case OPT_ONE:
  1209. one = 1;
  1210. break;
  1211. case OPT_COMMANDS:
  1212. todo.commands = 1;
  1213. break;
  1214. case OPT_DIGEST_COMMANDS:
  1215. todo.digest_commands = 1;
  1216. break;
  1217. case OPT_DIGEST_ALGORITHMS:
  1218. todo.digest_algorithms = 1;
  1219. break;
  1220. case OPT_KDF_ALGORITHMS:
  1221. todo.kdf_algorithms = 1;
  1222. break;
  1223. case OPT_RANDOM_INSTANCES:
  1224. todo.random_instances = 1;
  1225. break;
  1226. case OPT_RANDOM_GENERATORS:
  1227. todo.random_generators = 1;
  1228. break;
  1229. case OPT_MAC_ALGORITHMS:
  1230. todo.mac_algorithms = 1;
  1231. break;
  1232. case OPT_CIPHER_COMMANDS:
  1233. todo.cipher_commands = 1;
  1234. break;
  1235. case OPT_CIPHER_ALGORITHMS:
  1236. todo.cipher_algorithms = 1;
  1237. break;
  1238. case OPT_ENCODERS:
  1239. todo.encoder_algorithms = 1;
  1240. break;
  1241. case OPT_DECODERS:
  1242. todo.decoder_algorithms = 1;
  1243. break;
  1244. case OPT_KEYMANAGERS:
  1245. todo.keymanager_algorithms = 1;
  1246. break;
  1247. case OPT_SIGNATURE_ALGORITHMS:
  1248. todo.signature_algorithms = 1;
  1249. break;
  1250. case OPT_KEYEXCHANGE_ALGORITHMS:
  1251. todo.keyexchange_algorithms = 1;
  1252. break;
  1253. case OPT_KEM_ALGORITHMS:
  1254. todo.kem_algorithms = 1;
  1255. break;
  1256. case OPT_ASYM_CIPHER_ALGORITHMS:
  1257. todo.asym_cipher_algorithms = 1;
  1258. break;
  1259. case OPT_PK_ALGORITHMS:
  1260. todo.pk_algorithms = 1;
  1261. break;
  1262. case OPT_PK_METHOD:
  1263. todo.pk_method = 1;
  1264. break;
  1265. case OPT_PROVIDER_INFO:
  1266. todo.provider_info = 1;
  1267. break;
  1268. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1269. case OPT_ENGINES:
  1270. todo.engines = 1;
  1271. break;
  1272. #endif
  1273. case OPT_DISABLED:
  1274. todo.disabled = 1;
  1275. break;
  1276. case OPT_MISSING_HELP:
  1277. todo.missing_help = 1;
  1278. break;
  1279. case OPT_OBJECTS:
  1280. todo.objects = 1;
  1281. break;
  1282. case OPT_OPTIONS:
  1283. list_options_for_command(opt_arg());
  1284. break;
  1285. case OPT_VERBOSE:
  1286. verbose = 1;
  1287. break;
  1288. case OPT_SELECT_NAME:
  1289. select_name = opt_arg();
  1290. break;
  1291. case OPT_PROV_CASES:
  1292. if (!opt_provider(o))
  1293. return 1;
  1294. break;
  1295. }
  1296. done = 1;
  1297. }
  1298. if (opt_num_rest() != 0) {
  1299. BIO_printf(bio_err, "Extra arguments given.\n");
  1300. goto opthelp;
  1301. }
  1302. if (todo.commands)
  1303. list_type(FT_general, one);
  1304. if (todo.random_instances)
  1305. list_random_instances();
  1306. if (todo.random_generators)
  1307. list_random_generators();
  1308. if (todo.digest_commands)
  1309. list_type(FT_md, one);
  1310. if (todo.digest_algorithms)
  1311. list_digests();
  1312. if (todo.kdf_algorithms)
  1313. list_kdfs();
  1314. if (todo.mac_algorithms)
  1315. list_macs();
  1316. if (todo.cipher_commands)
  1317. list_type(FT_cipher, one);
  1318. if (todo.cipher_algorithms)
  1319. list_ciphers();
  1320. if (todo.encoder_algorithms)
  1321. list_encoders();
  1322. if (todo.decoder_algorithms)
  1323. list_decoders();
  1324. if (todo.keymanager_algorithms)
  1325. list_keymanagers();
  1326. if (todo.signature_algorithms)
  1327. list_signatures();
  1328. if (todo.asym_cipher_algorithms)
  1329. list_asymciphers();
  1330. if (todo.keyexchange_algorithms)
  1331. list_keyexchanges();
  1332. if (todo.kem_algorithms)
  1333. list_kems();
  1334. if (todo.pk_algorithms)
  1335. list_pkey();
  1336. if (todo.pk_method)
  1337. list_pkey_meth();
  1338. if (todo.provider_info)
  1339. list_provider_info();
  1340. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1341. if (todo.engines)
  1342. list_engines();
  1343. #endif
  1344. if (todo.disabled)
  1345. list_disabled();
  1346. if (todo.missing_help)
  1347. list_missing_help();
  1348. if (todo.objects)
  1349. list_objects();
  1350. if (!done)
  1351. goto opthelp;
  1352. return 0;
  1353. }