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