summaryrefslogtreecommitdiffstats
path: root/apps/list.c
diff options
context:
space:
mode:
authorPauli <paul.dale@oracle.com>2020-06-11 09:08:01 +1000
committerPauli <paul.dale@oracle.com>2020-07-30 20:15:22 +1000
commitdfc0857d8191d43be320f4ba472b7c782248a35d (patch)
tree1fc044e3ce75b9f8518461c157f7430725a6ad85 /apps/list.c
parentaa97970c1a69ae15b4191aa58cdb56e016f15922 (diff)
serialisation: Add a built-in base provider.
Move the libcrypto serialisation functionality into a place where it can be provided at some point. The serialisation still remains native in the default provider. Add additional code to the list command to display what kind of serialisation each entry is capable of. Having the FIPS provider auto load the base provider is a future (but necessary) enhancement. Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/12104)
Diffstat (limited to 'apps/list.c')
-rw-r--r--apps/list.c75
1 files changed, 72 insertions, 3 deletions
diff --git a/apps/list.c b/apps/list.c
index b58871b1c5..5b93f7dfed 100644
--- a/apps/list.c
+++ b/apps/list.c
@@ -16,6 +16,8 @@
#include <openssl/provider.h>
#include <openssl/safestack.h>
#include <openssl/kdf.h>
+#include <openssl/serializer.h>
+#include <openssl/core_names.h>
#include "apps.h"
#include "app_params.h"
#include "progs.h"
@@ -351,6 +353,66 @@ static void list_random_generators(void)
sk_EVP_RAND_pop_free(rands, EVP_RAND_free);
}
+/*
+ * Serializers
+ */
+DEFINE_STACK_OF(OSSL_SERIALIZER)
+static int serializer_cmp(const OSSL_SERIALIZER * const *a,
+ const OSSL_SERIALIZER * const *b)
+{
+ int ret = OSSL_SERIALIZER_number(*a) - OSSL_SERIALIZER_number(*b);
+
+ if (ret == 0)
+ ret = strcmp(OSSL_PROVIDER_name(OSSL_SERIALIZER_provider(*a)),
+ OSSL_PROVIDER_name(OSSL_SERIALIZER_provider(*b)));
+ return ret;
+}
+
+static void collect_serializers(OSSL_SERIALIZER *serializer, void *stack)
+{
+ STACK_OF(OSSL_SERIALIZER) *serializer_stack = stack;
+
+ sk_OSSL_SERIALIZER_push(serializer_stack, serializer);
+ OSSL_SERIALIZER_up_ref(serializer);
+}
+
+static void list_serializers(void)
+{
+ STACK_OF(OSSL_SERIALIZER) *serializers;
+ int i;
+
+ serializers = sk_OSSL_SERIALIZER_new(serializer_cmp);
+ if (serializers == NULL) {
+ BIO_printf(bio_err, "ERROR: Memory allocation\n");
+ return;
+ }
+ BIO_printf(bio_out, "Provided SERIALIZERs:\n");
+ OSSL_SERIALIZER_do_all_provided(NULL, collect_serializers, serializers);
+ sk_OSSL_SERIALIZER_sort(serializers);
+
+ for (i = 0; i < sk_OSSL_SERIALIZER_num(serializers); i++) {
+ OSSL_SERIALIZER *k = sk_OSSL_SERIALIZER_value(serializers, i);
+ STACK_OF(OPENSSL_CSTRING) *names =
+ sk_OPENSSL_CSTRING_new(name_cmp);
+
+ OSSL_SERIALIZER_names_do_all(k, collect_names, names);
+
+ BIO_printf(bio_out, " ");
+ print_names(bio_out, names);
+ BIO_printf(bio_out, " @ %s (%s)\n",
+ OSSL_PROVIDER_name(OSSL_SERIALIZER_provider(k)),
+ OSSL_SERIALIZER_properties(k));
+
+ sk_OPENSSL_CSTRING_free(names);
+
+ if (verbose) {
+ print_param_types("settable operation parameters",
+ OSSL_SERIALIZER_settable_ctx_params(k), 4);
+ }
+ }
+ sk_OSSL_SERIALIZER_pop_free(serializers, OSSL_SERIALIZER_free);
+}
+
static void list_missing_help(void)
{
const FUNCTION *fp;
@@ -697,7 +759,8 @@ typedef enum HELPLIST_CHOICE {
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,
- OPT_KDF_ALGORITHMS, OPT_RANDOM_GENERATORS, OPT_MISSING_HELP, OPT_OBJECTS,
+ OPT_KDF_ALGORITHMS, OPT_RANDOM_GENERATORS, OPT_SERIALIZERS,
+ OPT_MISSING_HELP, OPT_OBJECTS,
#ifndef OPENSSL_NO_DEPRECATED_3_0
OPT_ENGINES,
#endif
@@ -727,6 +790,7 @@ const OPTIONS list_options[] = {
{"cipher-commands", OPT_CIPHER_COMMANDS, '-', "List of cipher commands"},
{"cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-',
"List of cipher algorithms"},
+ {"serializers", OPT_SERIALIZERS, '-', "List of serialization methods" },
{"public-key-algorithms", OPT_PK_ALGORITHMS, '-',
"List of public key algorithms"},
#ifndef OPENSSL_NO_DEPRECATED_3_0
@@ -735,8 +799,7 @@ const OPTIONS list_options[] = {
{"engines", OPT_ENGINES, '-',
"List of loaded engines"},
#endif
- {"disabled", OPT_DISABLED, '-',
- "List of disabled features"},
+ {"disabled", OPT_DISABLED, '-', "List of disabled features"},
{"missing-help", OPT_MISSING_HELP, '-',
"List missing detailed help strings"},
{"options", OPT_OPTIONS, 's',
@@ -762,6 +825,7 @@ int list_main(int argc, char **argv)
unsigned int mac_algorithms:1;
unsigned int cipher_commands:1;
unsigned int cipher_algorithms:1;
+ unsigned int serializer_algorithms:1;
unsigned int pk_algorithms:1;
unsigned int pk_method:1;
#ifndef OPENSSL_NO_DEPRECATED_3_0
@@ -813,6 +877,9 @@ opthelp:
case OPT_CIPHER_ALGORITHMS:
todo.cipher_algorithms = 1;
break;
+ case OPT_SERIALIZERS:
+ todo.serializer_algorithms = 1;
+ break;
case OPT_PK_ALGORITHMS:
todo.pk_algorithms = 1;
break;
@@ -867,6 +934,8 @@ opthelp:
list_type(FT_cipher, one);
if (todo.cipher_algorithms)
list_ciphers();
+ if (todo.serializer_algorithms)
+ list_serializers();
if (todo.pk_algorithms)
list_pkey();
#ifndef OPENSSL_NO_DEPRECATED_3_0