list.c 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006
  1. /*
  2. * Copyright 1995-2025 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 "internal/e_os.h"
  12. #include <string.h>
  13. #include <openssl/evp.h>
  14. #include <openssl/err.h>
  15. #include <openssl/provider.h>
  16. #include <openssl/safestack.h>
  17. #include <openssl/kdf.h>
  18. #include <openssl/encoder.h>
  19. #include <openssl/decoder.h>
  20. #include <openssl/store.h>
  21. #include <openssl/core_names.h>
  22. #include <openssl/rand.h>
  23. #include <openssl/safestack.h>
  24. #include <openssl/ssl.h>
  25. #include <openssl/tls1.h>
  26. #include "apps.h"
  27. #include "app_params.h"
  28. #include "progs.h"
  29. #include "opt.h"
  30. #include "names.h"
  31. static int verbose = 0;
  32. static const char *select_name = NULL;
  33. /* Checks to see if algorithms are fetchable */
  34. #define IS_FETCHABLE(type, TYPE) \
  35. static int is_ ## type ## _fetchable(const TYPE *alg) \
  36. { \
  37. TYPE *impl; \
  38. const char *propq = app_get0_propq(); \
  39. OSSL_LIB_CTX *libctx = app_get0_libctx(); \
  40. const char *name = TYPE ## _get0_name(alg); \
  41. \
  42. ERR_set_mark(); \
  43. impl = TYPE ## _fetch(libctx, name, propq); \
  44. ERR_pop_to_mark(); \
  45. if (impl == NULL) \
  46. return 0; \
  47. TYPE ## _free(impl); \
  48. return 1; \
  49. }
  50. IS_FETCHABLE(cipher, EVP_CIPHER)
  51. IS_FETCHABLE(digest, EVP_MD)
  52. IS_FETCHABLE(mac, EVP_MAC)
  53. IS_FETCHABLE(kdf, EVP_KDF)
  54. IS_FETCHABLE(rand, EVP_RAND)
  55. IS_FETCHABLE(keymgmt, EVP_KEYMGMT)
  56. IS_FETCHABLE(skeymgmt, EVP_SKEYMGMT)
  57. IS_FETCHABLE(signature, EVP_SIGNATURE)
  58. IS_FETCHABLE(kem, EVP_KEM)
  59. IS_FETCHABLE(asym_cipher, EVP_ASYM_CIPHER)
  60. IS_FETCHABLE(keyexch, EVP_KEYEXCH)
  61. IS_FETCHABLE(decoder, OSSL_DECODER)
  62. IS_FETCHABLE(encoder, OSSL_ENCODER)
  63. #ifndef OPENSSL_NO_DEPRECATED_3_0
  64. static int include_legacy(void)
  65. {
  66. return app_get0_propq() == NULL;
  67. }
  68. static void legacy_cipher_fn(const EVP_CIPHER *c,
  69. const char *from, const char *to, void *arg)
  70. {
  71. if (select_name != NULL
  72. && (c == NULL
  73. || OPENSSL_strcasecmp(select_name, EVP_CIPHER_get0_name(c)) != 0))
  74. return;
  75. if (c != NULL) {
  76. BIO_printf(arg, " %s\n", EVP_CIPHER_get0_name(c));
  77. } else {
  78. if (from == NULL)
  79. from = "<undefined>";
  80. if (to == NULL)
  81. to = "<undefined>";
  82. BIO_printf(arg, " %s => %s\n", from, to);
  83. }
  84. }
  85. #endif
  86. DEFINE_STACK_OF(EVP_CIPHER)
  87. static int cipher_cmp(const EVP_CIPHER * const *a,
  88. const EVP_CIPHER * const *b)
  89. {
  90. return strcmp(OSSL_PROVIDER_get0_name(EVP_CIPHER_get0_provider(*a)),
  91. OSSL_PROVIDER_get0_name(EVP_CIPHER_get0_provider(*b)));
  92. }
  93. static void collect_ciphers(EVP_CIPHER *cipher, void *stack)
  94. {
  95. STACK_OF(EVP_CIPHER) *cipher_stack = stack;
  96. if (is_cipher_fetchable(cipher)
  97. && EVP_CIPHER_up_ref(cipher)
  98. && sk_EVP_CIPHER_push(cipher_stack, cipher) <= 0)
  99. EVP_CIPHER_free(cipher); /* up-ref successful but push to stack failed */
  100. }
  101. static void list_ciphers(const char *prefix)
  102. {
  103. STACK_OF(EVP_CIPHER) *ciphers = sk_EVP_CIPHER_new(cipher_cmp);
  104. int i;
  105. if (ciphers == NULL) {
  106. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  107. return;
  108. }
  109. #ifndef OPENSSL_NO_DEPRECATED_3_0
  110. if (include_legacy()) {
  111. BIO_printf(bio_out, "%sLegacy:\n", prefix);
  112. EVP_CIPHER_do_all_sorted(legacy_cipher_fn, bio_out);
  113. }
  114. #endif
  115. BIO_printf(bio_out, "%sProvided:\n", prefix);
  116. EVP_CIPHER_do_all_provided(app_get0_libctx(), collect_ciphers, ciphers);
  117. sk_EVP_CIPHER_sort(ciphers);
  118. for (i = 0; i < sk_EVP_CIPHER_num(ciphers); i++) {
  119. const EVP_CIPHER *c = sk_EVP_CIPHER_value(ciphers, i);
  120. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  121. if (select_name != NULL && !EVP_CIPHER_is_a(c, select_name))
  122. continue;
  123. names = sk_OPENSSL_CSTRING_new(name_cmp);
  124. if (names != NULL && EVP_CIPHER_names_do_all(c, collect_names, names)) {
  125. BIO_printf(bio_out, " ");
  126. print_names(bio_out, names);
  127. BIO_printf(bio_out, " @ %s\n",
  128. OSSL_PROVIDER_get0_name(EVP_CIPHER_get0_provider(c)));
  129. if (verbose) {
  130. const char *desc = EVP_CIPHER_get0_description(c);
  131. if (desc != NULL)
  132. BIO_printf(bio_out, " description: %s\n", desc);
  133. print_param_types("retrievable algorithm parameters",
  134. EVP_CIPHER_gettable_params(c), 4);
  135. print_param_types("retrievable operation parameters",
  136. EVP_CIPHER_gettable_ctx_params(c), 4);
  137. print_param_types("settable operation parameters",
  138. EVP_CIPHER_settable_ctx_params(c), 4);
  139. }
  140. }
  141. sk_OPENSSL_CSTRING_free(names);
  142. }
  143. sk_EVP_CIPHER_pop_free(ciphers, EVP_CIPHER_free);
  144. }
  145. #ifndef OPENSSL_NO_DEPRECATED_3_0
  146. static void legacy_md_fn(const EVP_MD *m,
  147. const char *from, const char *to, void *arg)
  148. {
  149. if (m != NULL) {
  150. BIO_printf(arg, " %s\n", EVP_MD_get0_name(m));
  151. } else {
  152. if (from == NULL)
  153. from = "<undefined>";
  154. if (to == NULL)
  155. to = "<undefined>";
  156. BIO_printf((BIO *)arg, " %s => %s\n", from, to);
  157. }
  158. }
  159. #endif
  160. DEFINE_STACK_OF(EVP_MD)
  161. static int md_cmp(const EVP_MD * const *a, const EVP_MD * const *b)
  162. {
  163. return strcmp(OSSL_PROVIDER_get0_name(EVP_MD_get0_provider(*a)),
  164. OSSL_PROVIDER_get0_name(EVP_MD_get0_provider(*b)));
  165. }
  166. static void collect_digests(EVP_MD *digest, void *stack)
  167. {
  168. STACK_OF(EVP_MD) *digest_stack = stack;
  169. if (is_digest_fetchable(digest)
  170. && EVP_MD_up_ref(digest)
  171. && sk_EVP_MD_push(digest_stack, digest) <= 0)
  172. EVP_MD_free(digest); /* up-ref successful but push to stack failed */
  173. }
  174. static void list_digests(const char *prefix)
  175. {
  176. STACK_OF(EVP_MD) *digests = sk_EVP_MD_new(md_cmp);
  177. int i;
  178. if (digests == NULL) {
  179. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  180. return;
  181. }
  182. #ifndef OPENSSL_NO_DEPRECATED_3_0
  183. if (include_legacy()) {
  184. BIO_printf(bio_out, "%sLegacy:\n", prefix);
  185. EVP_MD_do_all_sorted(legacy_md_fn, bio_out);
  186. }
  187. #endif
  188. BIO_printf(bio_out, "%sProvided:\n", prefix);
  189. EVP_MD_do_all_provided(app_get0_libctx(), collect_digests, digests);
  190. sk_EVP_MD_sort(digests);
  191. for (i = 0; i < sk_EVP_MD_num(digests); i++) {
  192. const EVP_MD *m = sk_EVP_MD_value(digests, i);
  193. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  194. if (select_name != NULL && !EVP_MD_is_a(m, select_name))
  195. continue;
  196. names = sk_OPENSSL_CSTRING_new(name_cmp);
  197. if (names != NULL && EVP_MD_names_do_all(m, collect_names, names)) {
  198. BIO_printf(bio_out, " ");
  199. print_names(bio_out, names);
  200. BIO_printf(bio_out, " @ %s\n",
  201. OSSL_PROVIDER_get0_name(EVP_MD_get0_provider(m)));
  202. if (verbose) {
  203. const char *desc = EVP_MD_get0_description(m);
  204. if (desc != NULL)
  205. BIO_printf(bio_out, " description: %s\n", desc);
  206. print_param_types("retrievable algorithm parameters",
  207. EVP_MD_gettable_params(m), 4);
  208. print_param_types("retrievable operation parameters",
  209. EVP_MD_gettable_ctx_params(m), 4);
  210. print_param_types("settable operation parameters",
  211. EVP_MD_settable_ctx_params(m), 4);
  212. }
  213. }
  214. sk_OPENSSL_CSTRING_free(names);
  215. }
  216. sk_EVP_MD_pop_free(digests, EVP_MD_free);
  217. }
  218. DEFINE_STACK_OF(EVP_MAC)
  219. static int mac_cmp(const EVP_MAC * const *a, const EVP_MAC * const *b)
  220. {
  221. return strcmp(OSSL_PROVIDER_get0_name(EVP_MAC_get0_provider(*a)),
  222. OSSL_PROVIDER_get0_name(EVP_MAC_get0_provider(*b)));
  223. }
  224. static void collect_macs(EVP_MAC *mac, void *stack)
  225. {
  226. STACK_OF(EVP_MAC) *mac_stack = stack;
  227. if (is_mac_fetchable(mac)
  228. && sk_EVP_MAC_push(mac_stack, mac) > 0)
  229. EVP_MAC_up_ref(mac);
  230. }
  231. static void list_macs(void)
  232. {
  233. STACK_OF(EVP_MAC) *macs = sk_EVP_MAC_new(mac_cmp);
  234. int i;
  235. if (macs == NULL) {
  236. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  237. return;
  238. }
  239. BIO_printf(bio_out, "Provided MACs:\n");
  240. EVP_MAC_do_all_provided(app_get0_libctx(), collect_macs, macs);
  241. sk_EVP_MAC_sort(macs);
  242. for (i = 0; i < sk_EVP_MAC_num(macs); i++) {
  243. const EVP_MAC *m = sk_EVP_MAC_value(macs, i);
  244. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  245. if (select_name != NULL && !EVP_MAC_is_a(m, select_name))
  246. continue;
  247. names = sk_OPENSSL_CSTRING_new(name_cmp);
  248. if (names != NULL && EVP_MAC_names_do_all(m, collect_names, names)) {
  249. BIO_printf(bio_out, " ");
  250. print_names(bio_out, names);
  251. BIO_printf(bio_out, " @ %s\n",
  252. OSSL_PROVIDER_get0_name(EVP_MAC_get0_provider(m)));
  253. if (verbose) {
  254. const char *desc = EVP_MAC_get0_description(m);
  255. if (desc != NULL)
  256. BIO_printf(bio_out, " description: %s\n", desc);
  257. print_param_types("retrievable algorithm parameters",
  258. EVP_MAC_gettable_params(m), 4);
  259. print_param_types("retrievable operation parameters",
  260. EVP_MAC_gettable_ctx_params(m), 4);
  261. print_param_types("settable operation parameters",
  262. EVP_MAC_settable_ctx_params(m), 4);
  263. }
  264. }
  265. sk_OPENSSL_CSTRING_free(names);
  266. }
  267. sk_EVP_MAC_pop_free(macs, EVP_MAC_free);
  268. }
  269. /*
  270. * KDFs and PRFs
  271. */
  272. DEFINE_STACK_OF(EVP_KDF)
  273. static int kdf_cmp(const EVP_KDF * const *a, const EVP_KDF * const *b)
  274. {
  275. return strcmp(OSSL_PROVIDER_get0_name(EVP_KDF_get0_provider(*a)),
  276. OSSL_PROVIDER_get0_name(EVP_KDF_get0_provider(*b)));
  277. }
  278. static void collect_kdfs(EVP_KDF *kdf, void *stack)
  279. {
  280. STACK_OF(EVP_KDF) *kdf_stack = stack;
  281. if (is_kdf_fetchable(kdf)
  282. && EVP_KDF_up_ref(kdf)
  283. && sk_EVP_KDF_push(kdf_stack, kdf) <= 0)
  284. EVP_KDF_free(kdf); /* up-ref successful but push to stack failed */
  285. }
  286. static void list_kdfs(void)
  287. {
  288. STACK_OF(EVP_KDF) *kdfs = sk_EVP_KDF_new(kdf_cmp);
  289. int i;
  290. if (kdfs == NULL) {
  291. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  292. return;
  293. }
  294. BIO_printf(bio_out, "Provided KDFs and PDFs:\n");
  295. EVP_KDF_do_all_provided(app_get0_libctx(), collect_kdfs, kdfs);
  296. sk_EVP_KDF_sort(kdfs);
  297. for (i = 0; i < sk_EVP_KDF_num(kdfs); i++) {
  298. const EVP_KDF *k = sk_EVP_KDF_value(kdfs, i);
  299. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  300. if (select_name != NULL && !EVP_KDF_is_a(k, select_name))
  301. continue;
  302. names = sk_OPENSSL_CSTRING_new(name_cmp);
  303. if (names != NULL && EVP_KDF_names_do_all(k, collect_names, names)) {
  304. BIO_printf(bio_out, " ");
  305. print_names(bio_out, names);
  306. BIO_printf(bio_out, " @ %s\n",
  307. OSSL_PROVIDER_get0_name(EVP_KDF_get0_provider(k)));
  308. if (verbose) {
  309. const char *desc = EVP_KDF_get0_description(k);
  310. if (desc != NULL)
  311. BIO_printf(bio_out, " description: %s\n", desc);
  312. print_param_types("retrievable algorithm parameters",
  313. EVP_KDF_gettable_params(k), 4);
  314. print_param_types("retrievable operation parameters",
  315. EVP_KDF_gettable_ctx_params(k), 4);
  316. print_param_types("settable operation parameters",
  317. EVP_KDF_settable_ctx_params(k), 4);
  318. }
  319. }
  320. sk_OPENSSL_CSTRING_free(names);
  321. }
  322. sk_EVP_KDF_pop_free(kdfs, EVP_KDF_free);
  323. }
  324. /*
  325. * RANDs
  326. */
  327. DEFINE_STACK_OF(EVP_RAND)
  328. static int rand_cmp(const EVP_RAND * const *a, const EVP_RAND * const *b)
  329. {
  330. int ret = OPENSSL_strcasecmp(EVP_RAND_get0_name(*a), EVP_RAND_get0_name(*b));
  331. if (ret == 0)
  332. ret = strcmp(OSSL_PROVIDER_get0_name(EVP_RAND_get0_provider(*a)),
  333. OSSL_PROVIDER_get0_name(EVP_RAND_get0_provider(*b)));
  334. return ret;
  335. }
  336. static void collect_rands(EVP_RAND *rand, void *stack)
  337. {
  338. STACK_OF(EVP_RAND) *rand_stack = stack;
  339. if (is_rand_fetchable(rand)
  340. && EVP_RAND_up_ref(rand)
  341. && sk_EVP_RAND_push(rand_stack, rand) <= 0)
  342. EVP_RAND_free(rand); /* up-ref successful but push to stack failed */
  343. }
  344. static void list_random_generators(void)
  345. {
  346. STACK_OF(EVP_RAND) *rands = sk_EVP_RAND_new(rand_cmp);
  347. int i;
  348. if (rands == NULL) {
  349. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  350. return;
  351. }
  352. BIO_printf(bio_out, "Provided RNGs and seed sources:\n");
  353. EVP_RAND_do_all_provided(app_get0_libctx(), collect_rands, rands);
  354. sk_EVP_RAND_sort(rands);
  355. for (i = 0; i < sk_EVP_RAND_num(rands); i++) {
  356. const EVP_RAND *m = sk_EVP_RAND_value(rands, i);
  357. if (select_name != NULL
  358. && OPENSSL_strcasecmp(EVP_RAND_get0_name(m), select_name) != 0)
  359. continue;
  360. BIO_printf(bio_out, " %s", EVP_RAND_get0_name(m));
  361. BIO_printf(bio_out, " @ %s\n",
  362. OSSL_PROVIDER_get0_name(EVP_RAND_get0_provider(m)));
  363. if (verbose) {
  364. const char *desc = EVP_RAND_get0_description(m);
  365. if (desc != NULL)
  366. BIO_printf(bio_out, " description: %s\n", desc);
  367. print_param_types("retrievable algorithm parameters",
  368. EVP_RAND_gettable_params(m), 4);
  369. print_param_types("retrievable operation parameters",
  370. EVP_RAND_gettable_ctx_params(m), 4);
  371. print_param_types("settable operation parameters",
  372. EVP_RAND_settable_ctx_params(m), 4);
  373. }
  374. }
  375. sk_EVP_RAND_pop_free(rands, EVP_RAND_free);
  376. }
  377. static void display_random(const char *name, EVP_RAND_CTX *drbg)
  378. {
  379. EVP_RAND *rand;
  380. uint64_t u;
  381. const char *p;
  382. const OSSL_PARAM *gettables;
  383. OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
  384. unsigned char buf[1000];
  385. BIO_printf(bio_out, "%s:\n", name);
  386. if (drbg != NULL) {
  387. rand = EVP_RAND_CTX_get0_rand(drbg);
  388. BIO_printf(bio_out, " %s", EVP_RAND_get0_name(rand));
  389. BIO_printf(bio_out, " @ %s\n",
  390. OSSL_PROVIDER_get0_name(EVP_RAND_get0_provider(rand)));
  391. switch (EVP_RAND_get_state(drbg)) {
  392. case EVP_RAND_STATE_UNINITIALISED:
  393. p = "uninitialised";
  394. break;
  395. case EVP_RAND_STATE_READY:
  396. p = "ready";
  397. break;
  398. case EVP_RAND_STATE_ERROR:
  399. p = "error";
  400. break;
  401. default:
  402. p = "unknown";
  403. break;
  404. }
  405. BIO_printf(bio_out, " state = %s\n", p);
  406. gettables = EVP_RAND_gettable_ctx_params(rand);
  407. if (gettables != NULL)
  408. for (; gettables->key != NULL; gettables++) {
  409. /* State has been dealt with already, so ignore */
  410. if (OPENSSL_strcasecmp(gettables->key, OSSL_RAND_PARAM_STATE) == 0)
  411. continue;
  412. /* Outside of verbose mode, we skip non-string values */
  413. if (gettables->data_type != OSSL_PARAM_UTF8_STRING
  414. && gettables->data_type != OSSL_PARAM_UTF8_PTR
  415. && !verbose)
  416. continue;
  417. params->key = gettables->key;
  418. params->data_type = gettables->data_type;
  419. if (gettables->data_type == OSSL_PARAM_UNSIGNED_INTEGER
  420. || gettables->data_type == OSSL_PARAM_INTEGER) {
  421. params->data = &u;
  422. params->data_size = sizeof(u);
  423. } else {
  424. params->data = buf;
  425. params->data_size = sizeof(buf);
  426. }
  427. params->return_size = 0;
  428. if (EVP_RAND_CTX_get_params(drbg, params))
  429. print_param_value(params, 2);
  430. }
  431. }
  432. }
  433. static void list_random_instances(void)
  434. {
  435. display_random("primary", RAND_get0_primary(NULL));
  436. display_random("public", RAND_get0_public(NULL));
  437. display_random("private", RAND_get0_private(NULL));
  438. }
  439. /*
  440. * Encoders
  441. */
  442. DEFINE_STACK_OF(OSSL_ENCODER)
  443. static int encoder_cmp(const OSSL_ENCODER * const *a,
  444. const OSSL_ENCODER * const *b)
  445. {
  446. return strcmp(OSSL_PROVIDER_get0_name(OSSL_ENCODER_get0_provider(*a)),
  447. OSSL_PROVIDER_get0_name(OSSL_ENCODER_get0_provider(*b)));
  448. }
  449. static void collect_encoders(OSSL_ENCODER *encoder, void *stack)
  450. {
  451. STACK_OF(OSSL_ENCODER) *encoder_stack = stack;
  452. if (is_encoder_fetchable(encoder)
  453. && OSSL_ENCODER_up_ref(encoder)
  454. && sk_OSSL_ENCODER_push(encoder_stack, encoder) <= 0)
  455. OSSL_ENCODER_free(encoder); /* up-ref successful but push to stack failed */
  456. }
  457. static void list_encoders(void)
  458. {
  459. STACK_OF(OSSL_ENCODER) *encoders;
  460. int i;
  461. encoders = sk_OSSL_ENCODER_new(encoder_cmp);
  462. if (encoders == NULL) {
  463. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  464. return;
  465. }
  466. BIO_printf(bio_out, "Provided ENCODERs:\n");
  467. OSSL_ENCODER_do_all_provided(app_get0_libctx(), collect_encoders,
  468. encoders);
  469. sk_OSSL_ENCODER_sort(encoders);
  470. for (i = 0; i < sk_OSSL_ENCODER_num(encoders); i++) {
  471. OSSL_ENCODER *k = sk_OSSL_ENCODER_value(encoders, i);
  472. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  473. if (select_name != NULL && !OSSL_ENCODER_is_a(k, select_name))
  474. continue;
  475. names = sk_OPENSSL_CSTRING_new(name_cmp);
  476. if (names != NULL && OSSL_ENCODER_names_do_all(k, collect_names, names)) {
  477. BIO_printf(bio_out, " ");
  478. print_names(bio_out, names);
  479. BIO_printf(bio_out, " @ %s (%s)\n",
  480. OSSL_PROVIDER_get0_name(OSSL_ENCODER_get0_provider(k)),
  481. OSSL_ENCODER_get0_properties(k));
  482. if (verbose) {
  483. const char *desc = OSSL_ENCODER_get0_description(k);
  484. if (desc != NULL)
  485. BIO_printf(bio_out, " description: %s\n", desc);
  486. print_param_types("settable operation parameters",
  487. OSSL_ENCODER_settable_ctx_params(k), 4);
  488. }
  489. }
  490. sk_OPENSSL_CSTRING_free(names);
  491. }
  492. sk_OSSL_ENCODER_pop_free(encoders, OSSL_ENCODER_free);
  493. }
  494. /*
  495. * Decoders
  496. */
  497. DEFINE_STACK_OF(OSSL_DECODER)
  498. static int decoder_cmp(const OSSL_DECODER * const *a,
  499. const OSSL_DECODER * const *b)
  500. {
  501. return strcmp(OSSL_PROVIDER_get0_name(OSSL_DECODER_get0_provider(*a)),
  502. OSSL_PROVIDER_get0_name(OSSL_DECODER_get0_provider(*b)));
  503. }
  504. static void collect_decoders(OSSL_DECODER *decoder, void *stack)
  505. {
  506. STACK_OF(OSSL_DECODER) *decoder_stack = stack;
  507. if (is_decoder_fetchable(decoder)
  508. && OSSL_DECODER_up_ref(decoder)
  509. && sk_OSSL_DECODER_push(decoder_stack, decoder) <= 0)
  510. OSSL_DECODER_free(decoder); /* up-ref successful but push to stack failed */
  511. }
  512. static void list_decoders(void)
  513. {
  514. STACK_OF(OSSL_DECODER) *decoders;
  515. int i;
  516. decoders = sk_OSSL_DECODER_new(decoder_cmp);
  517. if (decoders == NULL) {
  518. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  519. return;
  520. }
  521. BIO_printf(bio_out, "Provided DECODERs:\n");
  522. OSSL_DECODER_do_all_provided(app_get0_libctx(), collect_decoders,
  523. decoders);
  524. sk_OSSL_DECODER_sort(decoders);
  525. for (i = 0; i < sk_OSSL_DECODER_num(decoders); i++) {
  526. OSSL_DECODER *k = sk_OSSL_DECODER_value(decoders, i);
  527. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  528. if (select_name != NULL && !OSSL_DECODER_is_a(k, select_name))
  529. continue;
  530. names = sk_OPENSSL_CSTRING_new(name_cmp);
  531. if (names != NULL && OSSL_DECODER_names_do_all(k, collect_names, names)) {
  532. BIO_printf(bio_out, " ");
  533. print_names(bio_out, names);
  534. BIO_printf(bio_out, " @ %s (%s)\n",
  535. OSSL_PROVIDER_get0_name(OSSL_DECODER_get0_provider(k)),
  536. OSSL_DECODER_get0_properties(k));
  537. if (verbose) {
  538. const char *desc = OSSL_DECODER_get0_description(k);
  539. if (desc != NULL)
  540. BIO_printf(bio_out, " description: %s\n", desc);
  541. print_param_types("settable operation parameters",
  542. OSSL_DECODER_settable_ctx_params(k), 4);
  543. }
  544. }
  545. sk_OPENSSL_CSTRING_free(names);
  546. }
  547. sk_OSSL_DECODER_pop_free(decoders, OSSL_DECODER_free);
  548. }
  549. DEFINE_STACK_OF(EVP_KEYMGMT)
  550. static int keymanager_cmp(const EVP_KEYMGMT * const *a,
  551. const EVP_KEYMGMT * const *b)
  552. {
  553. return strcmp(OSSL_PROVIDER_get0_name(EVP_KEYMGMT_get0_provider(*a)),
  554. OSSL_PROVIDER_get0_name(EVP_KEYMGMT_get0_provider(*b)));
  555. }
  556. static void collect_keymanagers(EVP_KEYMGMT *km, void *stack)
  557. {
  558. STACK_OF(EVP_KEYMGMT) *km_stack = stack;
  559. if (is_keymgmt_fetchable(km)
  560. && EVP_KEYMGMT_up_ref(km)
  561. && sk_EVP_KEYMGMT_push(km_stack, km) <= 0)
  562. EVP_KEYMGMT_free(km); /* up-ref successful but push to stack failed */
  563. }
  564. static void list_keymanagers(void)
  565. {
  566. int i;
  567. STACK_OF(EVP_KEYMGMT) *km_stack = sk_EVP_KEYMGMT_new(keymanager_cmp);
  568. EVP_KEYMGMT_do_all_provided(app_get0_libctx(), collect_keymanagers,
  569. km_stack);
  570. sk_EVP_KEYMGMT_sort(km_stack);
  571. for (i = 0; i < sk_EVP_KEYMGMT_num(km_stack); i++) {
  572. EVP_KEYMGMT *k = sk_EVP_KEYMGMT_value(km_stack, i);
  573. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  574. if (select_name != NULL && !EVP_KEYMGMT_is_a(k, select_name))
  575. continue;
  576. names = sk_OPENSSL_CSTRING_new(name_cmp);
  577. if (names != NULL && EVP_KEYMGMT_names_do_all(k, collect_names, names)) {
  578. const char *desc = EVP_KEYMGMT_get0_description(k);
  579. BIO_printf(bio_out, " Name: ");
  580. if (desc != NULL)
  581. BIO_printf(bio_out, "%s", desc);
  582. else
  583. BIO_printf(bio_out, "%s", sk_OPENSSL_CSTRING_value(names, 0));
  584. BIO_printf(bio_out, "\n");
  585. BIO_printf(bio_out, " Type: Provider Algorithm\n");
  586. BIO_printf(bio_out, " IDs: ");
  587. print_names(bio_out, names);
  588. BIO_printf(bio_out, " @ %s\n",
  589. OSSL_PROVIDER_get0_name(EVP_KEYMGMT_get0_provider(k)));
  590. if (verbose) {
  591. print_param_types("settable key generation parameters",
  592. EVP_KEYMGMT_gen_settable_params(k), 4);
  593. print_param_types("settable operation parameters",
  594. EVP_KEYMGMT_settable_params(k), 4);
  595. print_param_types("retrievable operation parameters",
  596. EVP_KEYMGMT_gettable_params(k), 4);
  597. }
  598. }
  599. sk_OPENSSL_CSTRING_free(names);
  600. }
  601. sk_EVP_KEYMGMT_pop_free(km_stack, EVP_KEYMGMT_free);
  602. }
  603. DEFINE_STACK_OF(EVP_SKEYMGMT)
  604. static int skeymanager_cmp(const EVP_SKEYMGMT * const *a,
  605. const EVP_SKEYMGMT * const *b)
  606. {
  607. return strcmp(OSSL_PROVIDER_get0_name(EVP_SKEYMGMT_get0_provider(*a)),
  608. OSSL_PROVIDER_get0_name(EVP_SKEYMGMT_get0_provider(*b)));
  609. }
  610. static void collect_skeymanagers(EVP_SKEYMGMT *km, void *stack)
  611. {
  612. STACK_OF(EVP_SKEYMGMT) *km_stack = stack;
  613. if (is_skeymgmt_fetchable(km)
  614. && sk_EVP_SKEYMGMT_push(km_stack, km) > 0)
  615. EVP_SKEYMGMT_up_ref(km);
  616. }
  617. static void list_skeymanagers(void)
  618. {
  619. int i;
  620. STACK_OF(EVP_SKEYMGMT) *km_stack = sk_EVP_SKEYMGMT_new(skeymanager_cmp);
  621. EVP_SKEYMGMT_do_all_provided(app_get0_libctx(), collect_skeymanagers,
  622. km_stack);
  623. sk_EVP_SKEYMGMT_sort(km_stack);
  624. for (i = 0; i < sk_EVP_SKEYMGMT_num(km_stack); i++) {
  625. EVP_SKEYMGMT *k = sk_EVP_SKEYMGMT_value(km_stack, i);
  626. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  627. if (select_name != NULL && !EVP_SKEYMGMT_is_a(k, select_name))
  628. continue;
  629. names = sk_OPENSSL_CSTRING_new(name_cmp);
  630. if (names != NULL && EVP_SKEYMGMT_names_do_all(k, collect_names, names)) {
  631. const char *desc = EVP_SKEYMGMT_get0_description(k);
  632. BIO_printf(bio_out, " Name: ");
  633. if (desc != NULL)
  634. BIO_printf(bio_out, "%s", desc);
  635. else
  636. BIO_printf(bio_out, "%s", sk_OPENSSL_CSTRING_value(names, 0));
  637. BIO_printf(bio_out, "\n");
  638. BIO_printf(bio_out, " Type: Provider Algorithm\n");
  639. BIO_printf(bio_out, " IDs: ");
  640. print_names(bio_out, names);
  641. BIO_printf(bio_out, " @ %s\n",
  642. OSSL_PROVIDER_get0_name(EVP_SKEYMGMT_get0_provider(k)));
  643. }
  644. sk_OPENSSL_CSTRING_free(names);
  645. }
  646. sk_EVP_SKEYMGMT_pop_free(km_stack, EVP_SKEYMGMT_free);
  647. }
  648. DEFINE_STACK_OF(EVP_SIGNATURE)
  649. static int signature_cmp(const EVP_SIGNATURE * const *a,
  650. const EVP_SIGNATURE * const *b)
  651. {
  652. return strcmp(OSSL_PROVIDER_get0_name(EVP_SIGNATURE_get0_provider(*a)),
  653. OSSL_PROVIDER_get0_name(EVP_SIGNATURE_get0_provider(*b)));
  654. }
  655. static void collect_signatures(EVP_SIGNATURE *sig, void *stack)
  656. {
  657. STACK_OF(EVP_SIGNATURE) *sig_stack = stack;
  658. if (is_signature_fetchable(sig)
  659. && EVP_SIGNATURE_up_ref(sig)
  660. && sk_EVP_SIGNATURE_push(sig_stack, sig) <= 0)
  661. EVP_SIGNATURE_free(sig); /* up-ref successful but push to stack failed */
  662. }
  663. static void list_signatures(void)
  664. {
  665. int i, count = 0;
  666. STACK_OF(EVP_SIGNATURE) *sig_stack = sk_EVP_SIGNATURE_new(signature_cmp);
  667. EVP_SIGNATURE_do_all_provided(app_get0_libctx(), collect_signatures,
  668. sig_stack);
  669. sk_EVP_SIGNATURE_sort(sig_stack);
  670. for (i = 0; i < sk_EVP_SIGNATURE_num(sig_stack); i++) {
  671. EVP_SIGNATURE *k = sk_EVP_SIGNATURE_value(sig_stack, i);
  672. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  673. if (select_name != NULL && !EVP_SIGNATURE_is_a(k, select_name))
  674. continue;
  675. names = sk_OPENSSL_CSTRING_new(name_cmp);
  676. if (names != NULL && EVP_SIGNATURE_names_do_all(k, collect_names, names)) {
  677. count++;
  678. BIO_printf(bio_out, " ");
  679. print_names(bio_out, names);
  680. BIO_printf(bio_out, " @ %s\n",
  681. OSSL_PROVIDER_get0_name(EVP_SIGNATURE_get0_provider(k)));
  682. if (verbose) {
  683. const char *desc = EVP_SIGNATURE_get0_description(k);
  684. if (desc != NULL)
  685. BIO_printf(bio_out, " description: %s\n", desc);
  686. print_param_types("settable operation parameters",
  687. EVP_SIGNATURE_settable_ctx_params(k), 4);
  688. print_param_types("retrievable operation parameters",
  689. EVP_SIGNATURE_gettable_ctx_params(k), 4);
  690. }
  691. }
  692. sk_OPENSSL_CSTRING_free(names);
  693. }
  694. sk_EVP_SIGNATURE_pop_free(sig_stack, EVP_SIGNATURE_free);
  695. if (count == 0)
  696. BIO_printf(bio_out, " -\n");
  697. }
  698. static int list_provider_tls_sigalgs(const OSSL_PARAM params[], void *data)
  699. {
  700. const OSSL_PARAM *p;
  701. /* Get registered IANA name */
  702. p = OSSL_PARAM_locate_const(params, OSSL_CAPABILITY_TLS_SIGALG_IANA_NAME);
  703. if (p != NULL && p->data_type == OSSL_PARAM_UTF8_STRING) {
  704. if (*((int *)data) > 0)
  705. BIO_printf(bio_out, ":");
  706. BIO_printf(bio_out, "%s", (char *)(p->data));
  707. /* mark presence of a provider-based sigalg */
  708. *((int *)data) = 2;
  709. }
  710. /* As built-in providers don't have this capability, never error */
  711. return 1;
  712. }
  713. static int list_tls_sigalg_caps(OSSL_PROVIDER *provider, void *cbdata)
  714. {
  715. OSSL_PROVIDER_get_capabilities(provider, "TLS-SIGALG",
  716. list_provider_tls_sigalgs,
  717. cbdata);
  718. /* As built-in providers don't have this capability, never error */
  719. return 1;
  720. }
  721. #if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2)
  722. static void list_tls_groups(int version, int all)
  723. {
  724. SSL_CTX *ctx = NULL;
  725. STACK_OF(OPENSSL_CSTRING) *groups;
  726. size_t i, num;
  727. if ((groups = sk_OPENSSL_CSTRING_new_null()) == NULL) {
  728. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  729. return;
  730. }
  731. if ((ctx = SSL_CTX_new(TLS_method())) == NULL) {
  732. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  733. goto err;
  734. }
  735. if (!SSL_CTX_set_min_proto_version(ctx, version)
  736. || !SSL_CTX_set_max_proto_version(ctx, version)) {
  737. BIO_printf(bio_err, "ERROR: setting TLS protocol version\n");
  738. goto err;
  739. }
  740. if (!SSL_CTX_get0_implemented_groups(ctx, all, groups)) {
  741. BIO_printf(bio_err, "ERROR: getting implemented TLS group list\n");
  742. goto err;
  743. }
  744. num = sk_OPENSSL_CSTRING_num(groups);
  745. for (i = 0; i < num; ++i) {
  746. BIO_printf(bio_out, "%s%c", sk_OPENSSL_CSTRING_value(groups, i),
  747. (i < num - 1) ? ':' : '\n');
  748. }
  749. err:
  750. SSL_CTX_free(ctx);
  751. sk_OPENSSL_CSTRING_free(groups);
  752. return;
  753. }
  754. #endif
  755. static void list_tls_signatures(void)
  756. {
  757. int tls_sigalg_listed = 0;
  758. char *builtin_sigalgs = SSL_get1_builtin_sigalgs(app_get0_libctx());
  759. if (builtin_sigalgs != NULL) {
  760. if (builtin_sigalgs[0] != 0) {
  761. BIO_printf(bio_out, "%s", builtin_sigalgs);
  762. tls_sigalg_listed = 1;
  763. }
  764. OPENSSL_free(builtin_sigalgs);
  765. }
  766. if (!OSSL_PROVIDER_do_all(NULL, list_tls_sigalg_caps, &tls_sigalg_listed))
  767. BIO_printf(bio_err,
  768. "ERROR: could not list all provider signature algorithms\n");
  769. if (tls_sigalg_listed < 2)
  770. BIO_printf(bio_out,
  771. "\nNo TLS sig algs registered by currently active providers");
  772. BIO_printf(bio_out, "\n");
  773. }
  774. DEFINE_STACK_OF(EVP_KEM)
  775. static int kem_cmp(const EVP_KEM * const *a,
  776. const EVP_KEM * const *b)
  777. {
  778. return strcmp(OSSL_PROVIDER_get0_name(EVP_KEM_get0_provider(*a)),
  779. OSSL_PROVIDER_get0_name(EVP_KEM_get0_provider(*b)));
  780. }
  781. static void collect_kem(EVP_KEM *kem, void *stack)
  782. {
  783. STACK_OF(EVP_KEM) *kem_stack = stack;
  784. if (is_kem_fetchable(kem)
  785. && EVP_KEM_up_ref(kem)
  786. && sk_EVP_KEM_push(kem_stack, kem) <= 0)
  787. EVP_KEM_free(kem); /* up-ref successful but push to stack failed */
  788. }
  789. static void list_kems(void)
  790. {
  791. int i, count = 0;
  792. STACK_OF(EVP_KEM) *kem_stack = sk_EVP_KEM_new(kem_cmp);
  793. EVP_KEM_do_all_provided(app_get0_libctx(), collect_kem, kem_stack);
  794. sk_EVP_KEM_sort(kem_stack);
  795. for (i = 0; i < sk_EVP_KEM_num(kem_stack); i++) {
  796. EVP_KEM *k = sk_EVP_KEM_value(kem_stack, i);
  797. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  798. if (select_name != NULL && !EVP_KEM_is_a(k, select_name))
  799. continue;
  800. names = sk_OPENSSL_CSTRING_new(name_cmp);
  801. if (names != NULL && EVP_KEM_names_do_all(k, collect_names, names)) {
  802. count++;
  803. BIO_printf(bio_out, " ");
  804. print_names(bio_out, names);
  805. BIO_printf(bio_out, " @ %s\n",
  806. OSSL_PROVIDER_get0_name(EVP_KEM_get0_provider(k)));
  807. if (verbose) {
  808. const char *desc = EVP_KEM_get0_description(k);
  809. if (desc != NULL)
  810. BIO_printf(bio_out, " description: %s\n", desc);
  811. print_param_types("settable operation parameters",
  812. EVP_KEM_settable_ctx_params(k), 4);
  813. print_param_types("retrievable operation parameters",
  814. EVP_KEM_gettable_ctx_params(k), 4);
  815. }
  816. }
  817. sk_OPENSSL_CSTRING_free(names);
  818. }
  819. sk_EVP_KEM_pop_free(kem_stack, EVP_KEM_free);
  820. if (count == 0)
  821. BIO_printf(bio_out, " -\n");
  822. }
  823. DEFINE_STACK_OF(EVP_ASYM_CIPHER)
  824. static int asymcipher_cmp(const EVP_ASYM_CIPHER * const *a,
  825. const EVP_ASYM_CIPHER * const *b)
  826. {
  827. return strcmp(OSSL_PROVIDER_get0_name(EVP_ASYM_CIPHER_get0_provider(*a)),
  828. OSSL_PROVIDER_get0_name(EVP_ASYM_CIPHER_get0_provider(*b)));
  829. }
  830. static void collect_asymciph(EVP_ASYM_CIPHER *asym_cipher, void *stack)
  831. {
  832. STACK_OF(EVP_ASYM_CIPHER) *asym_cipher_stack = stack;
  833. if (is_asym_cipher_fetchable(asym_cipher)
  834. && EVP_ASYM_CIPHER_up_ref(asym_cipher)
  835. && sk_EVP_ASYM_CIPHER_push(asym_cipher_stack, asym_cipher) <= 0)
  836. EVP_ASYM_CIPHER_free(asym_cipher); /* up-ref successful but push to stack failed */
  837. }
  838. static void list_asymciphers(void)
  839. {
  840. int i, count = 0;
  841. STACK_OF(EVP_ASYM_CIPHER) *asymciph_stack =
  842. sk_EVP_ASYM_CIPHER_new(asymcipher_cmp);
  843. EVP_ASYM_CIPHER_do_all_provided(app_get0_libctx(), collect_asymciph,
  844. asymciph_stack);
  845. sk_EVP_ASYM_CIPHER_sort(asymciph_stack);
  846. for (i = 0; i < sk_EVP_ASYM_CIPHER_num(asymciph_stack); i++) {
  847. EVP_ASYM_CIPHER *k = sk_EVP_ASYM_CIPHER_value(asymciph_stack, i);
  848. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  849. if (select_name != NULL && !EVP_ASYM_CIPHER_is_a(k, select_name))
  850. continue;
  851. names = sk_OPENSSL_CSTRING_new(name_cmp);
  852. if (names != NULL
  853. && EVP_ASYM_CIPHER_names_do_all(k, collect_names, names)) {
  854. count++;
  855. BIO_printf(bio_out, " ");
  856. print_names(bio_out, names);
  857. BIO_printf(bio_out, " @ %s\n",
  858. OSSL_PROVIDER_get0_name(EVP_ASYM_CIPHER_get0_provider(k)));
  859. if (verbose) {
  860. const char *desc = EVP_ASYM_CIPHER_get0_description(k);
  861. if (desc != NULL)
  862. BIO_printf(bio_out, " description: %s\n", desc);
  863. print_param_types("settable operation parameters",
  864. EVP_ASYM_CIPHER_settable_ctx_params(k), 4);
  865. print_param_types("retrievable operation parameters",
  866. EVP_ASYM_CIPHER_gettable_ctx_params(k), 4);
  867. }
  868. }
  869. sk_OPENSSL_CSTRING_free(names);
  870. }
  871. sk_EVP_ASYM_CIPHER_pop_free(asymciph_stack, EVP_ASYM_CIPHER_free);
  872. if (count == 0)
  873. BIO_printf(bio_out, " -\n");
  874. }
  875. DEFINE_STACK_OF(EVP_KEYEXCH)
  876. static int kex_cmp(const EVP_KEYEXCH * const *a,
  877. const EVP_KEYEXCH * const *b)
  878. {
  879. return strcmp(OSSL_PROVIDER_get0_name(EVP_KEYEXCH_get0_provider(*a)),
  880. OSSL_PROVIDER_get0_name(EVP_KEYEXCH_get0_provider(*b)));
  881. }
  882. static void collect_kex(EVP_KEYEXCH *kex, void *stack)
  883. {
  884. STACK_OF(EVP_KEYEXCH) *kex_stack = stack;
  885. if (is_keyexch_fetchable(kex)
  886. && EVP_KEYEXCH_up_ref(kex)
  887. && sk_EVP_KEYEXCH_push(kex_stack, kex) <= 0)
  888. EVP_KEYEXCH_free(kex); /* up-ref successful but push to stack failed */
  889. }
  890. static void list_keyexchanges(void)
  891. {
  892. int i, count = 0;
  893. STACK_OF(EVP_KEYEXCH) *kex_stack = sk_EVP_KEYEXCH_new(kex_cmp);
  894. EVP_KEYEXCH_do_all_provided(app_get0_libctx(), collect_kex, kex_stack);
  895. sk_EVP_KEYEXCH_sort(kex_stack);
  896. for (i = 0; i < sk_EVP_KEYEXCH_num(kex_stack); i++) {
  897. EVP_KEYEXCH *k = sk_EVP_KEYEXCH_value(kex_stack, i);
  898. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  899. if (select_name != NULL && !EVP_KEYEXCH_is_a(k, select_name))
  900. continue;
  901. names = sk_OPENSSL_CSTRING_new(name_cmp);
  902. if (names != NULL && EVP_KEYEXCH_names_do_all(k, collect_names, names)) {
  903. count++;
  904. BIO_printf(bio_out, " ");
  905. print_names(bio_out, names);
  906. BIO_printf(bio_out, " @ %s\n",
  907. OSSL_PROVIDER_get0_name(EVP_KEYEXCH_get0_provider(k)));
  908. if (verbose) {
  909. const char *desc = EVP_KEYEXCH_get0_description(k);
  910. if (desc != NULL)
  911. BIO_printf(bio_out, " description: %s\n", desc);
  912. print_param_types("settable operation parameters",
  913. EVP_KEYEXCH_settable_ctx_params(k), 4);
  914. print_param_types("retrievable operation parameters",
  915. EVP_KEYEXCH_gettable_ctx_params(k), 4);
  916. }
  917. }
  918. sk_OPENSSL_CSTRING_free(names);
  919. }
  920. sk_EVP_KEYEXCH_pop_free(kex_stack, EVP_KEYEXCH_free);
  921. if (count == 0)
  922. BIO_printf(bio_out, " -\n");
  923. }
  924. static void list_objects(void)
  925. {
  926. int max_nid = OBJ_new_nid(0);
  927. int i;
  928. char *oid_buf = NULL;
  929. int oid_size = 0;
  930. /* Skip 0, since that's NID_undef */
  931. for (i = 1; i < max_nid; i++) {
  932. const ASN1_OBJECT *obj = OBJ_nid2obj(i);
  933. const char *sn = OBJ_nid2sn(i);
  934. const char *ln = OBJ_nid2ln(i);
  935. int n = 0;
  936. /*
  937. * If one of the retrieved objects somehow generated an error,
  938. * we ignore it. The check for NID_undef below will detect the
  939. * error and simply skip to the next NID.
  940. */
  941. ERR_clear_error();
  942. if (OBJ_obj2nid(obj) == NID_undef)
  943. continue;
  944. if ((n = OBJ_obj2txt(NULL, 0, obj, 1)) == 0) {
  945. BIO_printf(bio_out, "# None-OID object: %s, %s\n", sn, ln);
  946. continue;
  947. }
  948. if (n < 0)
  949. break; /* Error */
  950. if (n > oid_size) {
  951. oid_buf = OPENSSL_realloc(oid_buf, n + 1);
  952. if (oid_buf == NULL) {
  953. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  954. break; /* Error */
  955. }
  956. oid_size = n + 1;
  957. }
  958. if (OBJ_obj2txt(oid_buf, oid_size, obj, 1) < 0)
  959. break; /* Error */
  960. if (ln == NULL || strcmp(sn, ln) == 0)
  961. BIO_printf(bio_out, "%s = %s\n", sn, oid_buf);
  962. else
  963. BIO_printf(bio_out, "%s = %s, %s\n", sn, ln, oid_buf);
  964. }
  965. OPENSSL_free(oid_buf);
  966. }
  967. static void list_options_for_command(const char *command)
  968. {
  969. const FUNCTION *fp;
  970. const OPTIONS *o;
  971. for (fp = functions; fp->name != NULL; fp++)
  972. if (strcmp(fp->name, command) == 0)
  973. break;
  974. if (fp->name == NULL) {
  975. BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n",
  976. command);
  977. return;
  978. }
  979. if ((o = fp->help) == NULL)
  980. return;
  981. for ( ; o->name != NULL; o++) {
  982. char c = o->valtype;
  983. if (o->name == OPT_PARAM_STR)
  984. break;
  985. if (o->name == OPT_HELP_STR
  986. || o->name == OPT_MORE_STR
  987. || o->name == OPT_SECTION_STR
  988. || o->name[0] == '\0')
  989. continue;
  990. BIO_printf(bio_out, "%s %c\n", o->name, c == '\0' ? '-' : c);
  991. }
  992. /* Always output the -- marker since it is sometimes documented. */
  993. BIO_printf(bio_out, "- -\n");
  994. }
  995. static int is_md_available(const char *name)
  996. {
  997. EVP_MD *md;
  998. const char *propq = app_get0_propq();
  999. /* Look through providers' digests */
  1000. ERR_set_mark();
  1001. md = EVP_MD_fetch(app_get0_libctx(), name, propq);
  1002. ERR_pop_to_mark();
  1003. if (md != NULL) {
  1004. EVP_MD_free(md);
  1005. return 1;
  1006. }
  1007. return propq != NULL || get_digest_from_engine(name) == NULL ? 0 : 1;
  1008. }
  1009. static int is_cipher_available(const char *name)
  1010. {
  1011. EVP_CIPHER *cipher;
  1012. const char *propq = app_get0_propq();
  1013. /* Look through providers' ciphers */
  1014. ERR_set_mark();
  1015. cipher = EVP_CIPHER_fetch(app_get0_libctx(), name, propq);
  1016. ERR_pop_to_mark();
  1017. if (cipher != NULL) {
  1018. EVP_CIPHER_free(cipher);
  1019. return 1;
  1020. }
  1021. return propq != NULL || get_cipher_from_engine(name) == NULL ? 0 : 1;
  1022. }
  1023. static void list_type(FUNC_TYPE ft, int one)
  1024. {
  1025. FUNCTION *fp;
  1026. int i = 0;
  1027. DISPLAY_COLUMNS dc;
  1028. memset(&dc, 0, sizeof(dc));
  1029. if (!one)
  1030. calculate_columns(functions, &dc);
  1031. for (fp = functions; fp->name != NULL; fp++) {
  1032. if (fp->type != ft)
  1033. continue;
  1034. switch (ft) {
  1035. case FT_cipher:
  1036. if (!is_cipher_available(fp->name))
  1037. continue;
  1038. break;
  1039. case FT_md:
  1040. if (!is_md_available(fp->name))
  1041. continue;
  1042. break;
  1043. default:
  1044. break;
  1045. }
  1046. if (one) {
  1047. BIO_printf(bio_out, "%s\n", fp->name);
  1048. } else {
  1049. if (i % dc.columns == 0 && i > 0)
  1050. BIO_printf(bio_out, "\n");
  1051. BIO_printf(bio_out, "%-*s", dc.width, fp->name);
  1052. i++;
  1053. }
  1054. }
  1055. if (!one)
  1056. BIO_printf(bio_out, "\n\n");
  1057. }
  1058. static void list_pkey(void)
  1059. {
  1060. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1061. int i;
  1062. if (select_name == NULL && include_legacy()) {
  1063. BIO_printf(bio_out, "Legacy:\n");
  1064. for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
  1065. const EVP_PKEY_ASN1_METHOD *ameth;
  1066. int pkey_id, pkey_base_id, pkey_flags;
  1067. const char *pinfo, *pem_str;
  1068. ameth = EVP_PKEY_asn1_get0(i);
  1069. EVP_PKEY_asn1_get0_info(&pkey_id, &pkey_base_id, &pkey_flags,
  1070. &pinfo, &pem_str, ameth);
  1071. if (pkey_flags & ASN1_PKEY_ALIAS) {
  1072. BIO_printf(bio_out, " Name: %s\n", OBJ_nid2ln(pkey_id));
  1073. BIO_printf(bio_out, "\tAlias for: %s\n",
  1074. OBJ_nid2ln(pkey_base_id));
  1075. } else {
  1076. BIO_printf(bio_out, " Name: %s\n", pinfo);
  1077. BIO_printf(bio_out, "\tType: %s Algorithm\n",
  1078. pkey_flags & ASN1_PKEY_DYNAMIC ?
  1079. "External" : "Builtin");
  1080. BIO_printf(bio_out, "\tOID: %s\n", OBJ_nid2ln(pkey_id));
  1081. if (pem_str == NULL)
  1082. pem_str = "(none)";
  1083. BIO_printf(bio_out, "\tPEM string: %s\n", pem_str);
  1084. }
  1085. }
  1086. }
  1087. #endif
  1088. BIO_printf(bio_out, "Provided:\n");
  1089. BIO_printf(bio_out, " Key Managers:\n");
  1090. list_keymanagers();
  1091. }
  1092. static void list_pkey_meth(void)
  1093. {
  1094. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1095. size_t i;
  1096. size_t meth_count = EVP_PKEY_meth_get_count();
  1097. if (select_name == NULL && include_legacy()) {
  1098. BIO_printf(bio_out, "Legacy:\n");
  1099. for (i = 0; i < meth_count; i++) {
  1100. const EVP_PKEY_METHOD *pmeth = EVP_PKEY_meth_get0(i);
  1101. int pkey_id, pkey_flags;
  1102. EVP_PKEY_meth_get0_info(&pkey_id, &pkey_flags, pmeth);
  1103. BIO_printf(bio_out, " %s\n", OBJ_nid2ln(pkey_id));
  1104. BIO_printf(bio_out, "\tType: %s Algorithm\n",
  1105. pkey_flags & ASN1_PKEY_DYNAMIC ? "External" : "Builtin");
  1106. }
  1107. }
  1108. #endif
  1109. BIO_printf(bio_out, "Provided:\n");
  1110. BIO_printf(bio_out, " Encryption:\n");
  1111. list_asymciphers();
  1112. BIO_printf(bio_out, " Key Exchange:\n");
  1113. list_keyexchanges();
  1114. BIO_printf(bio_out, " Signatures:\n");
  1115. list_signatures();
  1116. BIO_printf(bio_out, " Key encapsulation:\n");
  1117. list_kems();
  1118. }
  1119. DEFINE_STACK_OF(OSSL_STORE_LOADER)
  1120. static int store_cmp(const OSSL_STORE_LOADER * const *a,
  1121. const OSSL_STORE_LOADER * const *b)
  1122. {
  1123. return strcmp(OSSL_PROVIDER_get0_name(OSSL_STORE_LOADER_get0_provider(*a)),
  1124. OSSL_PROVIDER_get0_name(OSSL_STORE_LOADER_get0_provider(*b)));
  1125. }
  1126. static void collect_store_loaders(OSSL_STORE_LOADER *store, void *stack)
  1127. {
  1128. STACK_OF(OSSL_STORE_LOADER) *store_stack = stack;
  1129. if (OSSL_STORE_LOADER_up_ref(store)
  1130. && sk_OSSL_STORE_LOADER_push(store_stack, store) <= 0)
  1131. OSSL_STORE_LOADER_free(store); /* up-ref successful but push to stack failed */
  1132. }
  1133. static void list_store_loaders(void)
  1134. {
  1135. STACK_OF(OSSL_STORE_LOADER) *stores = sk_OSSL_STORE_LOADER_new(store_cmp);
  1136. int i;
  1137. if (stores == NULL) {
  1138. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  1139. return;
  1140. }
  1141. BIO_printf(bio_out, "Provided STORE LOADERs:\n");
  1142. OSSL_STORE_LOADER_do_all_provided(app_get0_libctx(), collect_store_loaders,
  1143. stores);
  1144. sk_OSSL_STORE_LOADER_sort(stores);
  1145. for (i = 0; i < sk_OSSL_STORE_LOADER_num(stores); i++) {
  1146. const OSSL_STORE_LOADER *m = sk_OSSL_STORE_LOADER_value(stores, i);
  1147. STACK_OF(OPENSSL_CSTRING) *names = NULL;
  1148. if (select_name != NULL && !OSSL_STORE_LOADER_is_a(m, select_name))
  1149. continue;
  1150. names = sk_OPENSSL_CSTRING_new(name_cmp);
  1151. if (names != NULL && OSSL_STORE_LOADER_names_do_all(m, collect_names,
  1152. names)) {
  1153. BIO_printf(bio_out, " ");
  1154. print_names(bio_out, names);
  1155. BIO_printf(bio_out, " @ %s\n",
  1156. OSSL_PROVIDER_get0_name(OSSL_STORE_LOADER_get0_provider(m)));
  1157. }
  1158. sk_OPENSSL_CSTRING_free(names);
  1159. }
  1160. sk_OSSL_STORE_LOADER_pop_free(stores, OSSL_STORE_LOADER_free);
  1161. }
  1162. DEFINE_STACK_OF(OSSL_PROVIDER)
  1163. static int provider_cmp(const OSSL_PROVIDER * const *a,
  1164. const OSSL_PROVIDER * const *b)
  1165. {
  1166. return strcmp(OSSL_PROVIDER_get0_name(*a), OSSL_PROVIDER_get0_name(*b));
  1167. }
  1168. static int collect_providers(OSSL_PROVIDER *provider, void *stack)
  1169. {
  1170. STACK_OF(OSSL_PROVIDER) *provider_stack = stack;
  1171. /*
  1172. * If OK - result is the index of inserted data
  1173. * Error - result is -1 or 0
  1174. */
  1175. return sk_OSSL_PROVIDER_push(provider_stack, provider) > 0 ? 1 : 0;
  1176. }
  1177. static void list_provider_info(void)
  1178. {
  1179. STACK_OF(OSSL_PROVIDER) *providers = sk_OSSL_PROVIDER_new(provider_cmp);
  1180. OSSL_PARAM params[5];
  1181. char *name, *version, *buildinfo;
  1182. int status;
  1183. int i;
  1184. if (providers == NULL) {
  1185. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  1186. return;
  1187. }
  1188. if (OSSL_PROVIDER_do_all(NULL, &collect_providers, providers) != 1) {
  1189. sk_OSSL_PROVIDER_free(providers);
  1190. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  1191. return;
  1192. }
  1193. BIO_printf(bio_out, "Providers:\n");
  1194. sk_OSSL_PROVIDER_sort(providers);
  1195. for (i = 0; i < sk_OSSL_PROVIDER_num(providers); i++) {
  1196. const OSSL_PROVIDER *prov = sk_OSSL_PROVIDER_value(providers, i);
  1197. const char *provname = OSSL_PROVIDER_get0_name(prov);
  1198. BIO_printf(bio_out, " %s\n", provname);
  1199. /* Query the "known" information parameters, the order matches below */
  1200. params[0] = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_NAME,
  1201. &name, 0);
  1202. params[1] = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_VERSION,
  1203. &version, 0);
  1204. params[2] = OSSL_PARAM_construct_int(OSSL_PROV_PARAM_STATUS, &status);
  1205. params[3] = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_BUILDINFO,
  1206. &buildinfo, 0);
  1207. params[4] = OSSL_PARAM_construct_end();
  1208. OSSL_PARAM_set_all_unmodified(params);
  1209. if (!OSSL_PROVIDER_get_params(prov, params)) {
  1210. BIO_printf(bio_err,
  1211. "WARNING: Unable to query provider parameters for %s\n",
  1212. provname);
  1213. } else {
  1214. /* Print out the provider information, the params order matches above */
  1215. if (OSSL_PARAM_modified(params))
  1216. BIO_printf(bio_out, " name: %s\n", name);
  1217. if (OSSL_PARAM_modified(params + 1))
  1218. BIO_printf(bio_out, " version: %s\n", version);
  1219. if (OSSL_PARAM_modified(params + 2))
  1220. BIO_printf(bio_out, " status: %sactive\n", status ? "" : "in");
  1221. if (verbose) {
  1222. if (OSSL_PARAM_modified(params + 3))
  1223. BIO_printf(bio_out, " build info: %s\n", buildinfo);
  1224. print_param_types("gettable provider parameters",
  1225. OSSL_PROVIDER_gettable_params(prov), 4);
  1226. }
  1227. }
  1228. }
  1229. sk_OSSL_PROVIDER_free(providers);
  1230. }
  1231. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1232. static void list_engines(void)
  1233. {
  1234. # ifndef OPENSSL_NO_ENGINE
  1235. ENGINE *e;
  1236. BIO_puts(bio_out, "Engines:\n");
  1237. e = ENGINE_get_first();
  1238. while (e) {
  1239. BIO_printf(bio_out, "%s\n", ENGINE_get_id(e));
  1240. e = ENGINE_get_next(e);
  1241. }
  1242. # else
  1243. BIO_puts(bio_out, "Engine support is disabled.\n");
  1244. # endif
  1245. }
  1246. #endif
  1247. static void list_disabled(void)
  1248. {
  1249. BIO_puts(bio_out, "Disabled algorithms:\n");
  1250. #ifdef OPENSSL_NO_ARGON2
  1251. BIO_puts(bio_out, "ARGON2\n");
  1252. #endif
  1253. #ifdef OPENSSL_NO_ARIA
  1254. BIO_puts(bio_out, "ARIA\n");
  1255. #endif
  1256. #ifdef OPENSSL_NO_BF
  1257. BIO_puts(bio_out, "BF\n");
  1258. #endif
  1259. #ifdef OPENSSL_NO_BLAKE2
  1260. BIO_puts(bio_out, "BLAKE2\n");
  1261. #endif
  1262. #ifdef OPENSSL_NO_CAMELLIA
  1263. BIO_puts(bio_out, "CAMELLIA\n");
  1264. #endif
  1265. #ifdef OPENSSL_NO_CAST
  1266. BIO_puts(bio_out, "CAST\n");
  1267. #endif
  1268. #ifdef OPENSSL_NO_CMAC
  1269. BIO_puts(bio_out, "CMAC\n");
  1270. #endif
  1271. #ifdef OPENSSL_NO_CMS
  1272. BIO_puts(bio_out, "CMS\n");
  1273. #endif
  1274. #ifdef OPENSSL_NO_COMP
  1275. BIO_puts(bio_out, "COMP\n");
  1276. #endif
  1277. #ifdef OPENSSL_NO_DES
  1278. BIO_puts(bio_out, "DES\n");
  1279. #endif
  1280. #ifdef OPENSSL_NO_DGRAM
  1281. BIO_puts(bio_out, "DGRAM\n");
  1282. #endif
  1283. #ifdef OPENSSL_NO_DH
  1284. BIO_puts(bio_out, "DH\n");
  1285. #endif
  1286. #ifdef OPENSSL_NO_DSA
  1287. BIO_puts(bio_out, "DSA\n");
  1288. #endif
  1289. #if defined(OPENSSL_NO_DTLS)
  1290. BIO_puts(bio_out, "DTLS\n");
  1291. #endif
  1292. #if defined(OPENSSL_NO_DTLS1)
  1293. BIO_puts(bio_out, "DTLS1\n");
  1294. #endif
  1295. #if defined(OPENSSL_NO_DTLS1_2)
  1296. BIO_puts(bio_out, "DTLS1_2\n");
  1297. #endif
  1298. #ifdef OPENSSL_NO_EC
  1299. BIO_puts(bio_out, "EC\n");
  1300. #endif
  1301. #ifdef OPENSSL_NO_ECX
  1302. BIO_puts(bio_out, "ECX\n");
  1303. #endif
  1304. #ifdef OPENSSL_NO_EC2M
  1305. BIO_puts(bio_out, "EC2M\n");
  1306. #endif
  1307. #if defined(OPENSSL_NO_ENGINE) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  1308. BIO_puts(bio_out, "ENGINE\n");
  1309. #endif
  1310. #ifdef OPENSSL_NO_GOST
  1311. BIO_puts(bio_out, "GOST\n");
  1312. #endif
  1313. #ifdef OPENSSL_NO_IDEA
  1314. BIO_puts(bio_out, "IDEA\n");
  1315. #endif
  1316. #ifdef OPENSSL_NO_MD2
  1317. BIO_puts(bio_out, "MD2\n");
  1318. #endif
  1319. #ifdef OPENSSL_NO_MD4
  1320. BIO_puts(bio_out, "MD4\n");
  1321. #endif
  1322. #ifdef OPENSSL_NO_MD5
  1323. BIO_puts(bio_out, "MD5\n");
  1324. #endif
  1325. #ifdef OPENSSL_NO_MDC2
  1326. BIO_puts(bio_out, "MDC2\n");
  1327. #endif
  1328. #ifdef OPENSSL_NO_OCB
  1329. BIO_puts(bio_out, "OCB\n");
  1330. #endif
  1331. #ifdef OPENSSL_NO_OCSP
  1332. BIO_puts(bio_out, "OCSP\n");
  1333. #endif
  1334. #ifdef OPENSSL_NO_PSK
  1335. BIO_puts(bio_out, "PSK\n");
  1336. #endif
  1337. #ifdef OPENSSL_NO_RC2
  1338. BIO_puts(bio_out, "RC2\n");
  1339. #endif
  1340. #ifdef OPENSSL_NO_RC4
  1341. BIO_puts(bio_out, "RC4\n");
  1342. #endif
  1343. #ifdef OPENSSL_NO_RC5
  1344. BIO_puts(bio_out, "RC5\n");
  1345. #endif
  1346. #ifdef OPENSSL_NO_RMD160
  1347. BIO_puts(bio_out, "RMD160\n");
  1348. #endif
  1349. #ifdef OPENSSL_NO_SCRYPT
  1350. BIO_puts(bio_out, "SCRYPT\n");
  1351. #endif
  1352. #ifdef OPENSSL_NO_SCTP
  1353. BIO_puts(bio_out, "SCTP\n");
  1354. #endif
  1355. #ifdef OPENSSL_NO_SEED
  1356. BIO_puts(bio_out, "SEED\n");
  1357. #endif
  1358. #ifdef OPENSSL_NO_SM2
  1359. BIO_puts(bio_out, "SM2\n");
  1360. #endif
  1361. #ifdef OPENSSL_NO_SM3
  1362. BIO_puts(bio_out, "SM3\n");
  1363. #endif
  1364. #ifdef OPENSSL_NO_SM4
  1365. BIO_puts(bio_out, "SM4\n");
  1366. #endif
  1367. #ifdef OPENSSL_NO_SOCK
  1368. BIO_puts(bio_out, "SOCK\n");
  1369. #endif
  1370. #ifdef OPENSSL_NO_SRP
  1371. BIO_puts(bio_out, "SRP\n");
  1372. #endif
  1373. #ifdef OPENSSL_NO_SRTP
  1374. BIO_puts(bio_out, "SRTP\n");
  1375. #endif
  1376. #ifdef OPENSSL_NO_SSL3
  1377. BIO_puts(bio_out, "SSL3\n");
  1378. #endif
  1379. #ifdef OPENSSL_NO_TLS1
  1380. BIO_puts(bio_out, "TLS1\n");
  1381. #endif
  1382. #ifdef OPENSSL_NO_TLS1_1
  1383. BIO_puts(bio_out, "TLS1_1\n");
  1384. #endif
  1385. #ifdef OPENSSL_NO_TLS1_2
  1386. BIO_puts(bio_out, "TLS1_2\n");
  1387. #endif
  1388. #ifdef OPENSSL_NO_WHIRLPOOL
  1389. BIO_puts(bio_out, "WHIRLPOOL\n");
  1390. #endif
  1391. #ifdef OPENSSL_NO_ZLIB
  1392. BIO_puts(bio_out, "ZLIB\n");
  1393. #endif
  1394. #ifdef OPENSSL_NO_BROTLI
  1395. BIO_puts(bio_out, "BROTLI\n");
  1396. #endif
  1397. #ifdef OPENSSL_NO_ZSTD
  1398. BIO_puts(bio_out, "ZSTD\n");
  1399. #endif
  1400. }
  1401. /* Unified enum for help and list commands. */
  1402. typedef enum HELPLIST_CHOICE {
  1403. OPT_COMMON,
  1404. OPT_ONE, OPT_VERBOSE,
  1405. OPT_ALL_ARGORITHMS,
  1406. OPT_COMMANDS, OPT_DIGEST_COMMANDS, OPT_MAC_ALGORITHMS, OPT_OPTIONS,
  1407. OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS,
  1408. OPT_PK_ALGORITHMS, OPT_PK_METHOD, OPT_DISABLED,
  1409. OPT_KDF_ALGORITHMS, OPT_RANDOM_INSTANCES, OPT_RANDOM_GENERATORS,
  1410. OPT_ENCODERS, OPT_DECODERS, OPT_KEYMANAGERS, OPT_KEYEXCHANGE_ALGORITHMS,
  1411. OPT_SKEYMANAGERS,
  1412. OPT_KEM_ALGORITHMS, OPT_SIGNATURE_ALGORITHMS,
  1413. OPT_TLS_SIGNATURE_ALGORITHMS, OPT_ASYM_CIPHER_ALGORITHMS,
  1414. OPT_STORE_LOADERS, OPT_PROVIDER_INFO, OPT_OBJECTS,
  1415. OPT_SELECT_NAME,
  1416. #if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2)
  1417. OPT_ALL_TLS_GROUPS, OPT_TLS_GROUPS,
  1418. # if !defined(OPENSSL_NO_TLS1_2)
  1419. OPT_TLS1_2,
  1420. # endif
  1421. # if !defined(OPENSSL_NO_TLS1_3)
  1422. OPT_TLS1_3,
  1423. # endif
  1424. #endif
  1425. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1426. OPT_ENGINES,
  1427. #endif
  1428. OPT_PROV_ENUM
  1429. } HELPLIST_CHOICE;
  1430. const OPTIONS list_options[] = {
  1431. OPT_SECTION("General"),
  1432. {"help", OPT_HELP, '-', "Display this summary"},
  1433. OPT_SECTION("Output"),
  1434. {"1", OPT_ONE, '-', "List in one column"},
  1435. {"verbose", OPT_VERBOSE, '-', "Verbose listing"},
  1436. {"select", OPT_SELECT_NAME, 's', "Select a single algorithm"},
  1437. {"commands", OPT_COMMANDS, '-', "List of standard commands"},
  1438. {"standard-commands", OPT_COMMANDS, '-', "List of standard commands"},
  1439. {"all-algorithms", OPT_ALL_ARGORITHMS, '-', "List of all algorithms"},
  1440. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1441. {"digest-commands", OPT_DIGEST_COMMANDS, '-',
  1442. "List of message digest commands (deprecated)"},
  1443. #endif
  1444. {"digest-algorithms", OPT_DIGEST_ALGORITHMS, '-',
  1445. "List of message digest algorithms"},
  1446. {"kdf-algorithms", OPT_KDF_ALGORITHMS, '-',
  1447. "List of key derivation and pseudo random function algorithms"},
  1448. {"random-instances", OPT_RANDOM_INSTANCES, '-',
  1449. "List the primary, public and private random number generator details"},
  1450. {"random-generators", OPT_RANDOM_GENERATORS, '-',
  1451. "List of random number generators"},
  1452. {"mac-algorithms", OPT_MAC_ALGORITHMS, '-',
  1453. "List of message authentication code algorithms"},
  1454. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1455. {"cipher-commands", OPT_CIPHER_COMMANDS, '-',
  1456. "List of cipher commands (deprecated)"},
  1457. #endif
  1458. {"cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-',
  1459. "List of symmetric cipher algorithms"},
  1460. {"encoders", OPT_ENCODERS, '-', "List of encoding methods" },
  1461. {"decoders", OPT_DECODERS, '-', "List of decoding methods" },
  1462. {"key-managers", OPT_KEYMANAGERS, '-', "List of key managers" },
  1463. {"skey-managers", OPT_SKEYMANAGERS, '-', "List of symmetric key managers" },
  1464. {"key-exchange-algorithms", OPT_KEYEXCHANGE_ALGORITHMS, '-',
  1465. "List of key exchange algorithms" },
  1466. {"kem-algorithms", OPT_KEM_ALGORITHMS, '-',
  1467. "List of key encapsulation mechanism algorithms" },
  1468. {"signature-algorithms", OPT_SIGNATURE_ALGORITHMS, '-',
  1469. "List of signature algorithms" },
  1470. {"tls-signature-algorithms", OPT_TLS_SIGNATURE_ALGORITHMS, '-',
  1471. "List of TLS signature algorithms" },
  1472. {"asymcipher-algorithms", OPT_ASYM_CIPHER_ALGORITHMS, '-',
  1473. "List of asymmetric cipher algorithms" },
  1474. {"public-key-algorithms", OPT_PK_ALGORITHMS, '-',
  1475. "List of public key algorithms"},
  1476. {"public-key-methods", OPT_PK_METHOD, '-',
  1477. "List of public key methods"},
  1478. {"store-loaders", OPT_STORE_LOADERS, '-',
  1479. "List of store loaders"},
  1480. #if !defined(OPENSSL_NO_TLS1_2) || !defined(OPENSSL_NO_TLS1_3)
  1481. {"tls-groups", OPT_TLS_GROUPS, '-',
  1482. "List implemented TLS key exchange 'groups'" },
  1483. {"all-tls-groups", OPT_ALL_TLS_GROUPS, '-',
  1484. "List implemented TLS key exchange 'groups' and all aliases" },
  1485. # ifndef OPENSSL_NO_TLS1_2
  1486. {"tls1_2", OPT_TLS1_2, '-',
  1487. "When listing 'groups', list those compatible with TLS1.2"},
  1488. # endif
  1489. # ifndef OPENSSL_NO_TLS1_3
  1490. {"tls1_3", OPT_TLS1_3, '-',
  1491. "When listing 'groups', list those compatible with TLS1.3"},
  1492. # endif
  1493. #endif
  1494. {"providers", OPT_PROVIDER_INFO, '-',
  1495. "List of provider information"},
  1496. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1497. {"engines", OPT_ENGINES, '-',
  1498. "List of loaded engines"},
  1499. #endif
  1500. {"disabled", OPT_DISABLED, '-', "List of disabled features"},
  1501. {"options", OPT_OPTIONS, 's',
  1502. "List options for specified command"},
  1503. {"objects", OPT_OBJECTS, '-',
  1504. "List built in objects (OID<->name mappings)"},
  1505. OPT_PROV_OPTIONS,
  1506. {NULL}
  1507. };
  1508. int list_main(int argc, char **argv)
  1509. {
  1510. char *prog;
  1511. HELPLIST_CHOICE o;
  1512. int one = 0, done = 0;
  1513. int print_newline = 0;
  1514. #if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2)
  1515. int all_tls_groups = 0;
  1516. # if !defined(OPENSSL_NO_TLS1_3)
  1517. unsigned int tls_version = TLS1_3_VERSION;
  1518. # else
  1519. unsigned int tls_version = TLS1_2_VERSION;
  1520. # endif
  1521. #endif
  1522. struct {
  1523. unsigned int commands:1;
  1524. unsigned int all_algorithms:1;
  1525. unsigned int random_instances:1;
  1526. unsigned int random_generators:1;
  1527. unsigned int digest_commands:1;
  1528. unsigned int digest_algorithms:1;
  1529. unsigned int kdf_algorithms:1;
  1530. unsigned int mac_algorithms:1;
  1531. unsigned int cipher_commands:1;
  1532. unsigned int cipher_algorithms:1;
  1533. unsigned int encoder_algorithms:1;
  1534. unsigned int decoder_algorithms:1;
  1535. unsigned int keymanager_algorithms:1;
  1536. unsigned int skeymanager_algorithms:1;
  1537. unsigned int signature_algorithms:1;
  1538. unsigned int tls_signature_algorithms:1;
  1539. unsigned int keyexchange_algorithms:1;
  1540. unsigned int kem_algorithms:1;
  1541. unsigned int tls_groups:1;
  1542. unsigned int asym_cipher_algorithms:1;
  1543. unsigned int pk_algorithms:1;
  1544. unsigned int pk_method:1;
  1545. unsigned int store_loaders:1;
  1546. unsigned int provider_info:1;
  1547. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1548. unsigned int engines:1;
  1549. #endif
  1550. unsigned int disabled:1;
  1551. unsigned int objects:1;
  1552. unsigned int options:1;
  1553. } todo = { 0, };
  1554. verbose = 0; /* Clear a possible previous call */
  1555. prog = opt_init(argc, argv, list_options);
  1556. while ((o = opt_next()) != OPT_EOF) {
  1557. switch (o) {
  1558. case OPT_EOF: /* Never hit, but suppresses warning */
  1559. case OPT_ERR:
  1560. opthelp:
  1561. BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
  1562. return 1;
  1563. case OPT_HELP:
  1564. opt_help(list_options);
  1565. return 0;
  1566. case OPT_ONE:
  1567. one = 1;
  1568. break;
  1569. case OPT_ALL_ARGORITHMS:
  1570. todo.all_algorithms = 1;
  1571. break;
  1572. case OPT_COMMANDS:
  1573. todo.commands = 1;
  1574. break;
  1575. case OPT_DIGEST_COMMANDS:
  1576. todo.digest_commands = 1;
  1577. break;
  1578. case OPT_DIGEST_ALGORITHMS:
  1579. todo.digest_algorithms = 1;
  1580. break;
  1581. case OPT_KDF_ALGORITHMS:
  1582. todo.kdf_algorithms = 1;
  1583. break;
  1584. case OPT_RANDOM_INSTANCES:
  1585. todo.random_instances = 1;
  1586. break;
  1587. case OPT_RANDOM_GENERATORS:
  1588. todo.random_generators = 1;
  1589. break;
  1590. case OPT_MAC_ALGORITHMS:
  1591. todo.mac_algorithms = 1;
  1592. break;
  1593. case OPT_CIPHER_COMMANDS:
  1594. todo.cipher_commands = 1;
  1595. break;
  1596. case OPT_CIPHER_ALGORITHMS:
  1597. todo.cipher_algorithms = 1;
  1598. break;
  1599. case OPT_ENCODERS:
  1600. todo.encoder_algorithms = 1;
  1601. break;
  1602. case OPT_DECODERS:
  1603. todo.decoder_algorithms = 1;
  1604. break;
  1605. case OPT_KEYMANAGERS:
  1606. todo.keymanager_algorithms = 1;
  1607. break;
  1608. case OPT_SKEYMANAGERS:
  1609. todo.skeymanager_algorithms = 1;
  1610. break;
  1611. case OPT_SIGNATURE_ALGORITHMS:
  1612. todo.signature_algorithms = 1;
  1613. break;
  1614. case OPT_TLS_SIGNATURE_ALGORITHMS:
  1615. todo.tls_signature_algorithms = 1;
  1616. break;
  1617. case OPT_KEYEXCHANGE_ALGORITHMS:
  1618. todo.keyexchange_algorithms = 1;
  1619. break;
  1620. case OPT_KEM_ALGORITHMS:
  1621. todo.kem_algorithms = 1;
  1622. break;
  1623. #if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2)
  1624. case OPT_TLS_GROUPS:
  1625. todo.tls_groups = 1;
  1626. break;
  1627. case OPT_ALL_TLS_GROUPS:
  1628. all_tls_groups = 1;
  1629. todo.tls_groups = 1;
  1630. break;
  1631. # if !defined(OPENSSL_NO_TLS1_2)
  1632. case OPT_TLS1_2:
  1633. tls_version = TLS1_2_VERSION;
  1634. break;
  1635. # endif
  1636. # if !defined(OPENSSL_NO_TLS1_3)
  1637. case OPT_TLS1_3:
  1638. tls_version = TLS1_3_VERSION;
  1639. break;
  1640. # endif
  1641. #endif
  1642. case OPT_ASYM_CIPHER_ALGORITHMS:
  1643. todo.asym_cipher_algorithms = 1;
  1644. break;
  1645. case OPT_PK_ALGORITHMS:
  1646. todo.pk_algorithms = 1;
  1647. break;
  1648. case OPT_PK_METHOD:
  1649. todo.pk_method = 1;
  1650. break;
  1651. case OPT_STORE_LOADERS:
  1652. todo.store_loaders = 1;
  1653. break;
  1654. case OPT_PROVIDER_INFO:
  1655. todo.provider_info = 1;
  1656. break;
  1657. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1658. case OPT_ENGINES:
  1659. todo.engines = 1;
  1660. break;
  1661. #endif
  1662. case OPT_DISABLED:
  1663. todo.disabled = 1;
  1664. break;
  1665. case OPT_OBJECTS:
  1666. todo.objects = 1;
  1667. break;
  1668. case OPT_OPTIONS:
  1669. list_options_for_command(opt_arg());
  1670. break;
  1671. case OPT_VERBOSE:
  1672. verbose = 1;
  1673. break;
  1674. case OPT_SELECT_NAME:
  1675. select_name = opt_arg();
  1676. break;
  1677. case OPT_PROV_CASES:
  1678. if (!opt_provider(o))
  1679. return 1;
  1680. break;
  1681. }
  1682. done = 1;
  1683. }
  1684. /* No extra arguments. */
  1685. if (!opt_check_rest_arg(NULL))
  1686. goto opthelp;
  1687. #define MAYBE_ADD_NL(cmd) \
  1688. do { \
  1689. if (print_newline++) { \
  1690. BIO_printf(bio_out, "\n"); \
  1691. } \
  1692. cmd; \
  1693. } while (0)
  1694. if (todo.commands)
  1695. MAYBE_ADD_NL(list_type(FT_general, one));
  1696. if (todo.all_algorithms) {
  1697. MAYBE_ADD_NL({});
  1698. BIO_printf(bio_out, "Digests:\n");
  1699. list_digests(" ");
  1700. BIO_printf(bio_out, "\nSymmetric Ciphers:\n");
  1701. list_ciphers(" ");
  1702. BIO_printf(bio_out, "\n");
  1703. list_kdfs();
  1704. BIO_printf(bio_out, "\n");
  1705. list_macs();
  1706. BIO_printf(bio_out, "\nProvided Asymmetric Encryption:\n");
  1707. list_asymciphers();
  1708. BIO_printf(bio_out, "\nProvided Key Exchange:\n");
  1709. list_keyexchanges();
  1710. BIO_printf(bio_out, "\nProvided Signatures:\n");
  1711. list_signatures();
  1712. BIO_printf(bio_out, "\nProvided Key encapsulation:\n");
  1713. list_kems();
  1714. BIO_printf(bio_out, "\nProvided Key managers:\n");
  1715. list_keymanagers();
  1716. BIO_printf(bio_out, "\n");
  1717. list_encoders();
  1718. BIO_printf(bio_out, "\n");
  1719. list_decoders();
  1720. BIO_printf(bio_out, "\n");
  1721. list_store_loaders();
  1722. }
  1723. if (todo.random_instances)
  1724. MAYBE_ADD_NL(list_random_instances());
  1725. if (todo.random_generators)
  1726. MAYBE_ADD_NL(list_random_generators());
  1727. if (todo.digest_commands)
  1728. MAYBE_ADD_NL(list_type(FT_md, one));
  1729. if (todo.digest_algorithms)
  1730. MAYBE_ADD_NL(list_digests(""));
  1731. if (todo.kdf_algorithms)
  1732. MAYBE_ADD_NL(list_kdfs());
  1733. if (todo.mac_algorithms)
  1734. MAYBE_ADD_NL(list_macs());
  1735. if (todo.cipher_commands)
  1736. MAYBE_ADD_NL(list_type(FT_cipher, one));
  1737. if (todo.cipher_algorithms)
  1738. MAYBE_ADD_NL(list_ciphers(""));
  1739. if (todo.encoder_algorithms)
  1740. MAYBE_ADD_NL(list_encoders());
  1741. if (todo.decoder_algorithms)
  1742. MAYBE_ADD_NL(list_decoders());
  1743. if (todo.keymanager_algorithms)
  1744. MAYBE_ADD_NL(list_keymanagers());
  1745. if (todo.skeymanager_algorithms)
  1746. MAYBE_ADD_NL(list_skeymanagers());
  1747. if (todo.signature_algorithms)
  1748. MAYBE_ADD_NL(list_signatures());
  1749. if (todo.tls_signature_algorithms)
  1750. MAYBE_ADD_NL(list_tls_signatures());
  1751. if (todo.asym_cipher_algorithms)
  1752. MAYBE_ADD_NL(list_asymciphers());
  1753. if (todo.keyexchange_algorithms)
  1754. MAYBE_ADD_NL(list_keyexchanges());
  1755. if (todo.kem_algorithms)
  1756. MAYBE_ADD_NL(list_kems());
  1757. #if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2)
  1758. if (todo.tls_groups)
  1759. MAYBE_ADD_NL(list_tls_groups(tls_version, all_tls_groups));
  1760. #endif
  1761. if (todo.pk_algorithms)
  1762. MAYBE_ADD_NL(list_pkey());
  1763. if (todo.pk_method)
  1764. MAYBE_ADD_NL(list_pkey_meth());
  1765. if (todo.store_loaders)
  1766. MAYBE_ADD_NL(list_store_loaders());
  1767. if (todo.provider_info)
  1768. MAYBE_ADD_NL(list_provider_info());
  1769. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1770. if (todo.engines)
  1771. MAYBE_ADD_NL(list_engines());
  1772. #endif
  1773. if (todo.disabled)
  1774. MAYBE_ADD_NL(list_disabled());
  1775. if (todo.objects)
  1776. MAYBE_ADD_NL(list_objects());
  1777. #undef MAYBE_ADD_NL
  1778. if (!done)
  1779. goto opthelp;
  1780. return 0;
  1781. }