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