'openssl list' and 'openssl provider': adapt display of multiple names
[openssl.git] / apps / list.c
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>
13 #include <openssl/provider.h>
14 #include <openssl/safestack.h>
15 #include <openssl/kdf.h>
16 #include "apps.h"
17 #include "app_params.h"
18 #include "progs.h"
19 #include "opt.h"
20 #include "names.h"
21
22 static int verbose = 0;
23
24 static void legacy_cipher_fn(const EVP_CIPHER *c,
25                              const char *from, const char *to, void *arg)
26 {
27     if (c != NULL) {
28         BIO_printf(arg, "  %s\n", EVP_CIPHER_name(c));
29     } else {
30         if (from == NULL)
31             from = "<undefined>";
32         if (to == NULL)
33             to = "<undefined>";
34         BIO_printf(arg, "  %s => %s\n", from, to);
35     }
36 }
37
38 DEFINE_STACK_OF(EVP_CIPHER)
39 static int cipher_cmp(const EVP_CIPHER * const *a,
40                       const EVP_CIPHER * const *b)
41 {
42     int ret = EVP_CIPHER_number(*a) - EVP_CIPHER_number(*b);
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
51 static void collect_ciphers(EVP_CIPHER *cipher, void *stack)
52 {
53     STACK_OF(EVP_CIPHER) *cipher_stack = stack;
54
55     if (sk_EVP_CIPHER_push(cipher_stack, cipher) > 0)
56         EVP_CIPHER_up_ref(cipher);
57 }
58
59 static 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");
65     EVP_CIPHER_do_all_sorted(legacy_cipher_fn, bio_out);
66
67     BIO_printf(bio_out, "Provided:\n");
68     EVP_CIPHER_do_all_provided(NULL, collect_ciphers, ciphers);
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);
72         STACK_OF(OPENSSL_CSTRING) *names =
73             sk_OPENSSL_CSTRING_new(name_cmp);
74
75         EVP_CIPHER_names_do_all(c, collect_names, names);
76
77         BIO_printf(bio_out, "  ");
78         print_names(bio_out, names);
79         BIO_printf(bio_out, " @ %s\n",
80                    OSSL_PROVIDER_name(EVP_CIPHER_provider(c)));
81
82         sk_OPENSSL_CSTRING_free(names);
83
84         if (verbose) {
85             print_param_types("retrievable algorithm parameters",
86                               EVP_CIPHER_gettable_params(c), 4);
87             print_param_types("retrievable operation parameters",
88                               EVP_CIPHER_gettable_ctx_params(c), 4);
89             print_param_types("settable operation parameters",
90                               EVP_CIPHER_settable_ctx_params(c), 4);
91         }
92     }
93     sk_EVP_CIPHER_pop_free(ciphers, EVP_CIPHER_free);
94 }
95
96 static void list_md_fn(const EVP_MD *m,
97                        const char *from, const char *to, void *arg)
98 {
99     if (m != NULL) {
100         BIO_printf(arg, "  %s\n", EVP_MD_name(m));
101     } else {
102         if (from == NULL)
103             from = "<undefined>";
104         if (to == NULL)
105             to = "<undefined>";
106         BIO_printf((BIO *)arg, "  %s => %s\n", from, to);
107     }
108 }
109
110 DEFINE_STACK_OF(EVP_MD)
111 static int md_cmp(const EVP_MD * const *a, const EVP_MD * const *b)
112 {
113     int ret = EVP_MD_number(*a) - EVP_MD_number(*b);
114
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
122 static void collect_digests(EVP_MD *md, void *stack)
123 {
124     STACK_OF(EVP_MD) *digest_stack = stack;
125
126     if (sk_EVP_MD_push(digest_stack, md) > 0)
127         EVP_MD_up_ref(md);
128 }
129
130 static 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");
139     EVP_MD_do_all_provided(NULL, collect_digests, digests);
140     sk_EVP_MD_sort(digests);
141     for (i = 0; i < sk_EVP_MD_num(digests); i++) {
142         const EVP_MD *m = sk_EVP_MD_value(digests, i);
143         STACK_OF(OPENSSL_CSTRING) *names =
144             sk_OPENSSL_CSTRING_new(name_cmp);
145
146         EVP_MD_names_do_all(m, collect_names, names);
147
148         BIO_printf(bio_out, "  ");
149         print_names(bio_out, names);
150         BIO_printf(bio_out, " @ %s\n",
151                    OSSL_PROVIDER_name(EVP_MD_provider(m)));
152
153         sk_OPENSSL_CSTRING_free(names);
154
155         if (verbose) {
156             print_param_types("retrievable algorithm parameters",
157                               EVP_MD_gettable_params(m), 4);
158             print_param_types("retrievable operation parameters",
159                               EVP_MD_gettable_ctx_params(m), 4);
160             print_param_types("settable operation parameters",
161                               EVP_MD_settable_ctx_params(m), 4);
162         }
163     }
164     sk_EVP_MD_pop_free(digests, EVP_MD_free);
165 }
166
167 DEFINE_STACK_OF(EVP_MAC)
168 static int mac_cmp(const EVP_MAC * const *a, const EVP_MAC * const *b)
169 {
170     int ret = EVP_MAC_number(*a) - EVP_MAC_number(*b);
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
179 static void collect_macs(EVP_MAC *mac, void *stack)
180 {
181     STACK_OF(EVP_MAC) *mac_stack = stack;
182
183     if (sk_EVP_MAC_push(mac_stack, mac) > 0)
184         EVP_MAC_up_ref(mac);
185 }
186
187 static 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");
193     EVP_MAC_do_all_provided(NULL, collect_macs, macs);
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);
197         STACK_OF(OPENSSL_CSTRING) *names =
198             sk_OPENSSL_CSTRING_new(name_cmp);
199
200         EVP_MAC_names_do_all(m, collect_names, names);
201
202         BIO_printf(bio_out, "  ");
203         print_names(bio_out, names);
204         BIO_printf(bio_out, " @ %s\n",
205                    OSSL_PROVIDER_name(EVP_MAC_provider(m)));
206
207         sk_OPENSSL_CSTRING_free(names);
208
209         if (verbose) {
210             print_param_types("retrievable algorithm parameters",
211                               EVP_MAC_gettable_params(m), 4);
212             print_param_types("retrievable operation parameters",
213                               EVP_MAC_gettable_ctx_params(m), 4);
214             print_param_types("settable operation parameters",
215                               EVP_MAC_settable_ctx_params(m), 4);
216         }
217     }
218     sk_EVP_MAC_pop_free(macs, EVP_MAC_free);
219 }
220
221 /*
222  * KDFs and PRFs
223  */
224 DEFINE_STACK_OF(EVP_KDF)
225 static int kdf_cmp(const EVP_KDF * const *a, const EVP_KDF * const *b)
226 {
227     int ret = EVP_KDF_number(*a) - EVP_KDF_number(*b);
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
236 static 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
244 static 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");
250     EVP_KDF_do_all_provided(NULL, collect_kdfs, kdfs);
251     sk_EVP_KDF_sort(kdfs);
252     for (i = 0; i < sk_EVP_KDF_num(kdfs); i++) {
253         const EVP_KDF *k = sk_EVP_KDF_value(kdfs, i);
254         STACK_OF(OPENSSL_CSTRING) *names =
255             sk_OPENSSL_CSTRING_new(name_cmp);
256
257         EVP_KDF_names_do_all(k, collect_names, names);
258
259         BIO_printf(bio_out, "  ");
260         print_names(bio_out, names);
261         BIO_printf(bio_out, " @ %s\n",
262                    OSSL_PROVIDER_name(EVP_KDF_provider(k)));
263
264         sk_OPENSSL_CSTRING_free(names);
265
266         if (verbose) {
267             print_param_types("retrievable algorithm parameters",
268                               EVP_KDF_gettable_params(k), 4);
269             print_param_types("retrievable operation parameters",
270                               EVP_KDF_gettable_ctx_params(k), 4);
271             print_param_types("settable operation parameters",
272                               EVP_KDF_settable_ctx_params(k), 4);
273         }
274     }
275     sk_EVP_KDF_pop_free(kdfs, EVP_KDF_free);
276 }
277
278 static 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
297 static 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
347 static 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++) {
365         char c = o->valtype;
366
367         if (o->name == OPT_HELP_STR
368                 || o->name == OPT_MORE_STR
369                 || o->name[0] == '\0')
370             continue;
371         BIO_printf(bio_out, "%s %c\n", o->name, c == '\0' ? '-' : c);
372     }
373     /* Always output the -- marker since it is sometimes documented. */
374     BIO_printf(bio_out, "- -\n");
375 }
376
377 static void list_type(FUNC_TYPE ft, int one)
378 {
379     FUNCTION *fp;
380     int i = 0;
381     DISPLAY_COLUMNS dc;
382
383     memset(&dc, 0, sizeof(dc));
384     if (!one)
385         calculate_columns(functions, &dc);
386
387     for (fp = functions; fp->name != NULL; fp++) {
388         if (fp->type != ft)
389             continue;
390         if (one) {
391             BIO_printf(bio_out, "%s\n", fp->name);
392         } else {
393             if (i % dc.columns == 0 && i > 0)
394                 BIO_printf(bio_out, "\n");
395             BIO_printf(bio_out, "%-*s", dc.width, fp->name);
396             i++;
397         }
398     }
399     if (!one)
400         BIO_printf(bio_out, "\n\n");
401 }
402
403 static void list_pkey(void)
404 {
405     int i;
406
407     for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
408         const EVP_PKEY_ASN1_METHOD *ameth;
409         int pkey_id, pkey_base_id, pkey_flags;
410         const char *pinfo, *pem_str;
411         ameth = EVP_PKEY_asn1_get0(i);
412         EVP_PKEY_asn1_get0_info(&pkey_id, &pkey_base_id, &pkey_flags,
413                                 &pinfo, &pem_str, ameth);
414         if (pkey_flags & ASN1_PKEY_ALIAS) {
415             BIO_printf(bio_out, "Name: %s\n", OBJ_nid2ln(pkey_id));
416             BIO_printf(bio_out, "\tAlias for: %s\n",
417                        OBJ_nid2ln(pkey_base_id));
418         } else {
419             BIO_printf(bio_out, "Name: %s\n", pinfo);
420             BIO_printf(bio_out, "\tType: %s Algorithm\n",
421                        pkey_flags & ASN1_PKEY_DYNAMIC ?
422                        "External" : "Builtin");
423             BIO_printf(bio_out, "\tOID: %s\n", OBJ_nid2ln(pkey_id));
424             if (pem_str == NULL)
425                 pem_str = "(none)";
426             BIO_printf(bio_out, "\tPEM string: %s\n", pem_str);
427         }
428
429     }
430 }
431
432 static void list_pkey_meth(void)
433 {
434     size_t i;
435     size_t meth_count = EVP_PKEY_meth_get_count();
436
437     for (i = 0; i < meth_count; i++) {
438         const EVP_PKEY_METHOD *pmeth = EVP_PKEY_meth_get0(i);
439         int pkey_id, pkey_flags;
440
441         EVP_PKEY_meth_get0_info(&pkey_id, &pkey_flags, pmeth);
442         BIO_printf(bio_out, "%s\n", OBJ_nid2ln(pkey_id));
443         BIO_printf(bio_out, "\tType: %s Algorithm\n",
444                    pkey_flags & ASN1_PKEY_DYNAMIC ?  "External" : "Builtin");
445     }
446 }
447
448 static void list_engines(void)
449 {
450 #ifndef OPENSSL_NO_ENGINE
451     ENGINE *e;
452
453     BIO_puts(bio_out, "Engines:\n");
454     e = ENGINE_get_first();
455     while (e) {
456         BIO_printf(bio_out, "%s\n", ENGINE_get_id(e));
457         e = ENGINE_get_next(e);
458     }
459 #else
460     BIO_puts(bio_out, "Engine support is disabled.\n");
461 #endif
462 }
463
464 static void list_disabled(void)
465 {
466     BIO_puts(bio_out, "Disabled algorithms:\n");
467 #ifdef OPENSSL_NO_ARIA
468     BIO_puts(bio_out, "ARIA\n");
469 #endif
470 #ifdef OPENSSL_NO_BF
471     BIO_puts(bio_out, "BF\n");
472 #endif
473 #ifdef OPENSSL_NO_BLAKE2
474     BIO_puts(bio_out, "BLAKE2\n");
475 #endif
476 #ifdef OPENSSL_NO_CAMELLIA
477     BIO_puts(bio_out, "CAMELLIA\n");
478 #endif
479 #ifdef OPENSSL_NO_CAST
480     BIO_puts(bio_out, "CAST\n");
481 #endif
482 #ifdef OPENSSL_NO_CMAC
483     BIO_puts(bio_out, "CMAC\n");
484 #endif
485 #ifdef OPENSSL_NO_CMS
486     BIO_puts(bio_out, "CMS\n");
487 #endif
488 #ifdef OPENSSL_NO_COMP
489     BIO_puts(bio_out, "COMP\n");
490 #endif
491 #ifdef OPENSSL_NO_DES
492     BIO_puts(bio_out, "DES\n");
493 #endif
494 #ifdef OPENSSL_NO_DGRAM
495     BIO_puts(bio_out, "DGRAM\n");
496 #endif
497 #ifdef OPENSSL_NO_DH
498     BIO_puts(bio_out, "DH\n");
499 #endif
500 #ifdef OPENSSL_NO_DSA
501     BIO_puts(bio_out, "DSA\n");
502 #endif
503 #if defined(OPENSSL_NO_DTLS)
504     BIO_puts(bio_out, "DTLS\n");
505 #endif
506 #if defined(OPENSSL_NO_DTLS1)
507     BIO_puts(bio_out, "DTLS1\n");
508 #endif
509 #if defined(OPENSSL_NO_DTLS1_2)
510     BIO_puts(bio_out, "DTLS1_2\n");
511 #endif
512 #ifdef OPENSSL_NO_EC
513     BIO_puts(bio_out, "EC\n");
514 #endif
515 #ifdef OPENSSL_NO_EC2M
516     BIO_puts(bio_out, "EC2M\n");
517 #endif
518 #ifdef OPENSSL_NO_ENGINE
519     BIO_puts(bio_out, "ENGINE\n");
520 #endif
521 #ifdef OPENSSL_NO_GOST
522     BIO_puts(bio_out, "GOST\n");
523 #endif
524 #ifdef OPENSSL_NO_IDEA
525     BIO_puts(bio_out, "IDEA\n");
526 #endif
527 #ifdef OPENSSL_NO_MD2
528     BIO_puts(bio_out, "MD2\n");
529 #endif
530 #ifdef OPENSSL_NO_MD4
531     BIO_puts(bio_out, "MD4\n");
532 #endif
533 #ifdef OPENSSL_NO_MD5
534     BIO_puts(bio_out, "MD5\n");
535 #endif
536 #ifdef OPENSSL_NO_MDC2
537     BIO_puts(bio_out, "MDC2\n");
538 #endif
539 #ifdef OPENSSL_NO_OCB
540     BIO_puts(bio_out, "OCB\n");
541 #endif
542 #ifdef OPENSSL_NO_OCSP
543     BIO_puts(bio_out, "OCSP\n");
544 #endif
545 #ifdef OPENSSL_NO_PSK
546     BIO_puts(bio_out, "PSK\n");
547 #endif
548 #ifdef OPENSSL_NO_RC2
549     BIO_puts(bio_out, "RC2\n");
550 #endif
551 #ifdef OPENSSL_NO_RC4
552     BIO_puts(bio_out, "RC4\n");
553 #endif
554 #ifdef OPENSSL_NO_RC5
555     BIO_puts(bio_out, "RC5\n");
556 #endif
557 #ifdef OPENSSL_NO_RMD160
558     BIO_puts(bio_out, "RMD160\n");
559 #endif
560 #ifdef OPENSSL_NO_RSA
561     BIO_puts(bio_out, "RSA\n");
562 #endif
563 #ifdef OPENSSL_NO_SCRYPT
564     BIO_puts(bio_out, "SCRYPT\n");
565 #endif
566 #ifdef OPENSSL_NO_SCTP
567     BIO_puts(bio_out, "SCTP\n");
568 #endif
569 #ifdef OPENSSL_NO_SEED
570     BIO_puts(bio_out, "SEED\n");
571 #endif
572 #ifdef OPENSSL_NO_SM2
573     BIO_puts(bio_out, "SM2\n");
574 #endif
575 #ifdef OPENSSL_NO_SM3
576     BIO_puts(bio_out, "SM3\n");
577 #endif
578 #ifdef OPENSSL_NO_SM4
579     BIO_puts(bio_out, "SM4\n");
580 #endif
581 #ifdef OPENSSL_NO_SOCK
582     BIO_puts(bio_out, "SOCK\n");
583 #endif
584 #ifdef OPENSSL_NO_SRP
585     BIO_puts(bio_out, "SRP\n");
586 #endif
587 #ifdef OPENSSL_NO_SRTP
588     BIO_puts(bio_out, "SRTP\n");
589 #endif
590 #ifdef OPENSSL_NO_SSL3
591     BIO_puts(bio_out, "SSL3\n");
592 #endif
593 #ifdef OPENSSL_NO_TLS1
594     BIO_puts(bio_out, "TLS1\n");
595 #endif
596 #ifdef OPENSSL_NO_TLS1_1
597     BIO_puts(bio_out, "TLS1_1\n");
598 #endif
599 #ifdef OPENSSL_NO_TLS1_2
600     BIO_puts(bio_out, "TLS1_2\n");
601 #endif
602 #ifdef OPENSSL_NO_WHIRLPOOL
603     BIO_puts(bio_out, "WHIRLPOOL\n");
604 #endif
605 #ifndef ZLIB
606     BIO_puts(bio_out, "ZLIB\n");
607 #endif
608 }
609
610 /* Unified enum for help and list commands. */
611 typedef enum HELPLIST_CHOICE {
612     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_ONE, OPT_VERBOSE,
613     OPT_COMMANDS, OPT_DIGEST_COMMANDS, OPT_MAC_ALGORITHMS, OPT_OPTIONS,
614     OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS,
615     OPT_PK_ALGORITHMS, OPT_PK_METHOD, OPT_ENGINES, OPT_DISABLED,
616     OPT_KDF_ALGORITHMS, OPT_MISSING_HELP, OPT_OBJECTS
617 } HELPLIST_CHOICE;
618
619 const OPTIONS list_options[] = {
620     {"help", OPT_HELP, '-', "Display this summary"},
621     {"1", OPT_ONE, '-', "List in one column"},
622     {"verbose", OPT_VERBOSE, '-', "Verbose listing"},
623     {"commands", OPT_COMMANDS, '-', "List of standard commands"},
624     {"digest-commands", OPT_DIGEST_COMMANDS, '-',
625      "List of message digest commands"},
626     {"digest-algorithms", OPT_DIGEST_ALGORITHMS, '-',
627      "List of message digest algorithms"},
628     {"kdf-algorithms", OPT_KDF_ALGORITHMS, '-',
629      "List of key derivation and pseudo random function algorithms"},
630     {"mac-algorithms", OPT_MAC_ALGORITHMS, '-',
631      "List of message authentication code algorithms"},
632     {"cipher-commands", OPT_CIPHER_COMMANDS, '-', "List of cipher commands"},
633     {"cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-',
634      "List of cipher algorithms"},
635     {"public-key-algorithms", OPT_PK_ALGORITHMS, '-',
636      "List of public key algorithms"},
637     {"public-key-methods", OPT_PK_METHOD, '-',
638      "List of public key methods"},
639     {"engines", OPT_ENGINES, '-',
640      "List of loaded engines"},
641     {"disabled", OPT_DISABLED, '-',
642      "List of disabled features"},
643     {"missing-help", OPT_MISSING_HELP, '-',
644      "List missing detailed help strings"},
645     {"options", OPT_OPTIONS, 's',
646      "List options for specified command"},
647     {"objects", OPT_OBJECTS, '-',
648      "List built in objects (OID<->name mappings)"},
649     {NULL}
650 };
651
652 int list_main(int argc, char **argv)
653 {
654     char *prog;
655     HELPLIST_CHOICE o;
656     int one = 0, done = 0;
657     struct {
658         unsigned int commands:1;
659         unsigned int digest_commands:1;
660         unsigned int digest_algorithms:1;
661         unsigned int kdf_algorithms:1;
662         unsigned int mac_algorithms:1;
663         unsigned int cipher_commands:1;
664         unsigned int cipher_algorithms:1;
665         unsigned int pk_algorithms:1;
666         unsigned int pk_method:1;
667         unsigned int engines:1;
668         unsigned int disabled:1;
669         unsigned int missing_help:1;
670         unsigned int objects:1;
671         unsigned int options:1;
672     } todo = { 0, };
673
674     verbose = 0;                 /* Clear a possible previous call */
675
676     prog = opt_init(argc, argv, list_options);
677     while ((o = opt_next()) != OPT_EOF) {
678         switch (o) {
679         case OPT_EOF:  /* Never hit, but suppresses warning */
680         case OPT_ERR:
681 opthelp:
682             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
683             return 1;
684         case OPT_HELP:
685             opt_help(list_options);
686             break;
687         case OPT_ONE:
688             one = 1;
689             break;
690         case OPT_COMMANDS:
691             todo.commands = 1;
692             break;
693         case OPT_DIGEST_COMMANDS:
694             todo.digest_commands = 1;
695             break;
696         case OPT_DIGEST_ALGORITHMS:
697             todo.digest_algorithms = 1;
698             break;
699         case OPT_KDF_ALGORITHMS:
700             todo.kdf_algorithms = 1;
701             break;
702         case OPT_MAC_ALGORITHMS:
703             todo.mac_algorithms = 1;
704             break;
705         case OPT_CIPHER_COMMANDS:
706             todo.cipher_commands = 1;
707             break;
708         case OPT_CIPHER_ALGORITHMS:
709             todo.cipher_algorithms = 1;
710             break;
711         case OPT_PK_ALGORITHMS:
712             todo.pk_algorithms = 1;
713             break;
714         case OPT_PK_METHOD:
715             todo.pk_method = 1;
716             break;
717         case OPT_ENGINES:
718             todo.engines = 1;
719             break;
720         case OPT_DISABLED:
721             todo.disabled = 1;
722             break;
723         case OPT_MISSING_HELP:
724             todo.missing_help = 1;
725             break;
726         case OPT_OBJECTS:
727             todo.objects = 1;
728             break;
729         case OPT_OPTIONS:
730             list_options_for_command(opt_arg());
731             break;
732         case OPT_VERBOSE:
733             verbose = 1;
734             break;
735         }
736         done = 1;
737     }
738     if (opt_num_rest() != 0) {
739         BIO_printf(bio_err, "Extra arguments given.\n");
740         goto opthelp;
741     }
742
743     if (todo.commands)
744         list_type(FT_general, one);
745     if (todo.digest_commands)
746         list_type(FT_md, one);
747     if (todo.digest_algorithms)
748         list_digests();
749     if (todo.kdf_algorithms)
750         list_kdfs();
751     if (todo.mac_algorithms)
752         list_macs();
753     if (todo.cipher_commands)
754         list_type(FT_cipher, one);
755     if (todo.cipher_algorithms)
756         list_ciphers();
757     if (todo.pk_algorithms)
758         list_pkey();
759     if (todo.pk_method)
760         list_pkey_meth();
761     if (todo.engines)
762         list_engines();
763     if (todo.disabled)
764         list_disabled();
765     if (todo.missing_help)
766         list_missing_help();
767     if (todo.objects)
768         list_objects();
769
770     if (!done)
771         goto opthelp;
772
773     return 0;
774 }