list: add an option to list all available algorithms
authorPauli <pauli@openssl.org>
Thu, 8 Sep 2022 02:54:23 +0000 (12:54 +1000)
committerPauli <pauli@openssl.org>
Sun, 11 Sep 2022 10:58:40 +0000 (20:58 +1000)
Fixes #19145

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/19168)

apps/list.c
doc/man1/openssl-list.pod.in

index 37d2c788dedcace70f22c089cf98dccba7269442..adcfaa4260ef2033a5d881e7cabaa10c9ab4f2a3 100644 (file)
@@ -102,7 +102,7 @@ static void collect_ciphers(EVP_CIPHER *cipher, void *stack)
         EVP_CIPHER_up_ref(cipher);
 }
 
-static void list_ciphers(void)
+static void list_ciphers(const char *prefix)
 {
     STACK_OF(EVP_CIPHER) *ciphers = sk_EVP_CIPHER_new(cipher_cmp);
     int i;
@@ -113,12 +113,12 @@ static void list_ciphers(void)
     }
 #ifndef OPENSSL_NO_DEPRECATED_3_0
     if (include_legacy()) {
-        BIO_printf(bio_out, "Legacy:\n");
+        BIO_printf(bio_out, "%sLegacy:\n", prefix);
         EVP_CIPHER_do_all_sorted(legacy_cipher_fn, bio_out);
     }
 #endif
 
-    BIO_printf(bio_out, "Provided:\n");
+    BIO_printf(bio_out, "%sProvided:\n", prefix);
     EVP_CIPHER_do_all_provided(app_get0_libctx(), collect_ciphers, ciphers);
     sk_EVP_CIPHER_sort(ciphers);
     for (i = 0; i < sk_EVP_CIPHER_num(ciphers); i++) {
@@ -186,7 +186,7 @@ static void collect_digests(EVP_MD *digest, void *stack)
         EVP_MD_up_ref(digest);
 }
 
-static void list_digests(void)
+static void list_digests(const char *prefix)
 {
     STACK_OF(EVP_MD) *digests = sk_EVP_MD_new(md_cmp);
     int i;
@@ -197,12 +197,12 @@ static void list_digests(void)
     }
 #ifndef OPENSSL_NO_DEPRECATED_3_0
     if (include_legacy()) {
-        BIO_printf(bio_out, "Legacy:\n");
+        BIO_printf(bio_out, "%sLegacy:\n", prefix);
         EVP_MD_do_all_sorted(legacy_md_fn, bio_out);
     }
 #endif
 
-    BIO_printf(bio_out, "Provided:\n");
+    BIO_printf(bio_out, "%sProvided:\n", prefix);
     EVP_MD_do_all_provided(app_get0_libctx(), collect_digests, digests);
     sk_EVP_MD_sort(digests);
     for (i = 0; i < sk_EVP_MD_num(digests); i++) {
@@ -1430,6 +1430,7 @@ static void list_disabled(void)
 typedef enum HELPLIST_CHOICE {
     OPT_COMMON,
     OPT_ONE, OPT_VERBOSE,
+    OPT_ALL_ARGORITHMS,
     OPT_COMMANDS, OPT_DIGEST_COMMANDS, OPT_MAC_ALGORITHMS, OPT_OPTIONS,
     OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS,
     OPT_PK_ALGORITHMS, OPT_PK_METHOD, OPT_DISABLED,
@@ -1455,6 +1456,7 @@ const OPTIONS list_options[] = {
     {"select", OPT_SELECT_NAME, 's', "Select a single algorithm"},
     {"commands", OPT_COMMANDS, '-', "List of standard commands"},
     {"standard-commands", OPT_COMMANDS, '-', "List of standard commands"},
+    {"all-algorithms", OPT_ALL_ARGORITHMS, '-', "List of all algorithms"},
 #ifndef OPENSSL_NO_DEPRECATED_3_0
     {"digest-commands", OPT_DIGEST_COMMANDS, '-',
      "List of message digest commands (deprecated)"},
@@ -1515,6 +1517,7 @@ int list_main(int argc, char **argv)
     int one = 0, done = 0;
     struct {
         unsigned int commands:1;
+        unsigned int all_algorithms:1;
         unsigned int random_instances:1;
         unsigned int random_generators:1;
         unsigned int digest_commands:1;
@@ -1558,6 +1561,9 @@ opthelp:
         case OPT_ONE:
             one = 1;
             break;
+        case OPT_ALL_ARGORITHMS:
+            todo.all_algorithms = 1;
+            break;
         case OPT_COMMANDS:
             todo.commands = 1;
             break;
@@ -1652,6 +1658,29 @@ opthelp:
 
     if (todo.commands)
         list_type(FT_general, one);
+    if (todo.all_algorithms) {
+        BIO_printf(bio_out, "Digests:\n");
+        list_digests(" ");
+        BIO_printf(bio_out, "Symmetric Ciphers:\n");
+        list_ciphers(" ");
+        list_kdfs();
+        list_macs();
+
+        BIO_printf(bio_out, "Provided Asymmetric Encryption:\n");
+        list_asymciphers();
+        BIO_printf(bio_out, "Provided Key Exchange:\n");
+        list_keyexchanges();
+        BIO_printf(bio_out, "Provided Signatures:\n");
+        list_signatures();
+        BIO_printf(bio_out, "Provided Key encapsulation:\n");
+        list_kems();
+        BIO_printf(bio_out, "Provided Key managers:\n");
+        list_keymanagers();
+
+        list_encoders();
+        list_decoders();
+        list_store_loaders();
+    }
     if (todo.random_instances)
         list_random_instances();
     if (todo.random_generators)
@@ -1659,7 +1688,7 @@ opthelp:
     if (todo.digest_commands)
         list_type(FT_md, one);
     if (todo.digest_algorithms)
-        list_digests();
+        list_digests("");
     if (todo.kdf_algorithms)
         list_kdfs();
     if (todo.mac_algorithms)
@@ -1667,7 +1696,7 @@ opthelp:
     if (todo.cipher_commands)
         list_type(FT_cipher, one);
     if (todo.cipher_algorithms)
-        list_ciphers();
+        list_ciphers("");
     if (todo.encoder_algorithms)
         list_encoders();
     if (todo.decoder_algorithms)
index d68454ce7124cb680e178a3a9a60a926a8669dbf..9404637a326e1c6b7dcb45d907713d094440f204 100644 (file)
@@ -12,6 +12,7 @@ B<openssl list>
 [B<-verbose>]
 [B<-select> I<name>]
 [B<-1>]
+[B<-all-algorithms>]
 [B<-commands>]
 [B<-standard-commands>]
 [B<-digest-algorithms>]
@@ -72,6 +73,40 @@ Only list algorithms that match this name.
 List the commands, digest-commands, or cipher-commands in a single column.
 If used, this option must be given first.
 
+=item B<-all-algorithms>
+
+Display lists of all algorithms.  These include:
+
+=over 4
+
+=item Asymmetric ciphers
+
+=item Decoders
+
+=item Digests
+
+=item Encoders
+
+=item Key derivation algorithms (KDF)
+
+=item Key encapsulation methods (KEM)
+
+=item Key exchange algorithms (KEX)
+
+=item Key managers
+
+=item Message authentication code algorithms (MAC)
+
+=item Random number generators (RNG, DRBG)
+
+=item Signature algorithms
+
+=item Store loaders
+
+=item Symmetric ciphers
+
+=back
+
 =item B<-commands>
 
 Display a list of standard commands.