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