]>
git.ipfire.org Git - thirdparty/openssl.git/blob - apps/provider.c
2 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
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
10 #include <openssl/opensslconf.h>
13 #include "app_params.h"
16 #include <openssl/err.h>
17 #include <openssl/evp.h>
18 #include <openssl/safestack.h>
19 #include <openssl/provider.h>
20 #include <openssl/core.h>
21 #include <openssl/core_numbers.h>
23 typedef enum OPTION_choice
{
24 OPT_ERR
= -1, OPT_EOF
= 0, OPT_HELP
,
25 OPT_V
= 100, OPT_VV
, OPT_VVV
28 const OPTIONS provider_options
[] = {
29 {OPT_HELP_STR
, 1, '-', "Usage: %s [options] [provider...]\n"},
31 OPT_SECTION("General"),
32 {"help", OPT_HELP
, '-', "Display this summary"},
34 OPT_SECTION("Output"),
35 {"v", OPT_V
, '-', "List the algorithm names of specified provider"},
36 {"vv", OPT_VV
, '-', "List the algorithm names of specified providers,"},
37 {OPT_MORE_STR
, 0, '-', "categorised by operation type"},
38 {"vvv", OPT_VVV
, '-', "List the algorithm names of specified provider"},
39 {OPT_MORE_STR
, 0, '-', "one at a time, and list all known parameters"},
42 {"provider", 0, 0, "Provider(s) to load"},
46 typedef struct info_st INFO
;
47 typedef struct meta_st META
;
50 void (*collect_names_fn
)(void *method
, STACK_OF(OPENSSL_CSTRING
) *names
);
52 const OSSL_PARAM
*gettable_params
;
53 const OSSL_PARAM
*gettable_ctx_params
;
54 const OSSL_PARAM
*settable_ctx_params
;
58 int first
; /* For prints */
65 void (*fn
)(META
*meta
, INFO
*info
);
68 static void collect_cipher_names(void *method
,
69 STACK_OF(OPENSSL_CSTRING
) *names
)
71 EVP_CIPHER_names_do_all(method
, collect_names
, names
);
74 static void collect_digest_names(void *method
,
75 STACK_OF(OPENSSL_CSTRING
) *names
)
77 EVP_MD_names_do_all(method
, collect_names
, names
);
80 static void collect_mac_names(void *method
,
81 STACK_OF(OPENSSL_CSTRING
) *names
)
83 EVP_MAC_names_do_all(method
, collect_names
, names
);
86 static void collect_keymgmt_names(void *method
,
87 STACK_OF(OPENSSL_CSTRING
) *names
)
89 EVP_KEYMGMT_names_do_all(method
, collect_names
, names
);
92 static void collect_keyexch_names(void *method
,
93 STACK_OF(OPENSSL_CSTRING
) *names
)
95 EVP_KEYEXCH_names_do_all(method
, collect_names
, names
);
98 static void collect_signature_names(void *method
,
99 STACK_OF(OPENSSL_CSTRING
) *names
)
101 EVP_SIGNATURE_names_do_all(method
, collect_names
, names
);
104 static void print_method_names(BIO
*out
, INFO
*info
)
106 STACK_OF(OPENSSL_CSTRING
) *names
= sk_OPENSSL_CSTRING_new(name_cmp
);
108 info
->collect_names_fn(info
->method
, names
);
109 print_names(out
, names
);
110 sk_OPENSSL_CSTRING_free(names
);
113 static void print_caps(META
*meta
, INFO
*info
)
115 switch (meta
->verbose
) {
118 BIO_printf(bio_out
, "; ");
119 print_method_names(bio_out
, info
);
124 BIO_printf(bio_out
, "\n");
125 BIO_printf(bio_out
, "%*s%ss:", meta
->indent
, "", meta
->label
);
127 BIO_printf(bio_out
, " ");
128 print_method_names(bio_out
, info
);
132 BIO_printf(bio_out
, "%*s%s ", meta
->indent
, "", meta
->label
);
133 print_method_names(bio_out
, info
);
134 BIO_printf(bio_out
, "\n");
135 print_param_types("retrievable algorithm parameters",
136 info
->gettable_params
, meta
->subindent
);
137 print_param_types("retrievable operation parameters",
138 info
->gettable_ctx_params
, meta
->subindent
);
139 print_param_types("settable operation parameters",
140 info
->settable_ctx_params
, meta
->subindent
);
146 static void do_method(void *method
,
147 void (*collect_names_fn
)(void *method
,
148 STACK_OF(OPENSSL_CSTRING
) *names
),
149 const OSSL_PARAM
*gettable_params
,
150 const OSSL_PARAM
*gettable_ctx_params
,
151 const OSSL_PARAM
*settable_ctx_params
,
156 info
.collect_names_fn
= collect_names_fn
;
157 info
.method
= method
;
158 info
.gettable_params
= gettable_params
;
159 info
.gettable_ctx_params
= gettable_ctx_params
;
160 info
.settable_ctx_params
= settable_ctx_params
;
161 meta
->fn(meta
, &info
);
165 static void do_cipher(EVP_CIPHER
*cipher
, void *meta
)
167 do_method(cipher
, collect_cipher_names
,
168 EVP_CIPHER_gettable_params(cipher
),
169 EVP_CIPHER_gettable_ctx_params(cipher
),
170 EVP_CIPHER_settable_ctx_params(cipher
),
174 static void do_digest(EVP_MD
*digest
, void *meta
)
176 do_method(digest
, collect_digest_names
,
177 EVP_MD_gettable_params(digest
),
178 EVP_MD_gettable_ctx_params(digest
),
179 EVP_MD_settable_ctx_params(digest
),
183 static void do_mac(EVP_MAC
*mac
, void *meta
)
185 do_method(mac
, collect_mac_names
,
186 EVP_MAC_gettable_params(mac
),
187 EVP_MAC_gettable_ctx_params(mac
),
188 EVP_MAC_settable_ctx_params(mac
),
192 static void do_keymgmt(EVP_KEYMGMT
*keymgmt
, void *meta
)
194 do_method(keymgmt
, collect_keymgmt_names
,
196 * TODO(3.0) Enable when KEYMGMT and KEYEXCH have gettables and settables
199 EVP_KEYMGMT_gettable_params(keymgmt
),
200 EVP_KEYMGMT_gettable_ctx_params(keymgmt
),
201 EVP_KEYMGMT_settable_ctx_params(keymgmt
),
208 static void do_keyexch(EVP_KEYEXCH
*keyexch
, void *meta
)
210 do_method(keyexch
, collect_keyexch_names
,
212 * TODO(3.0) Enable when KEYMGMT and KEYEXCH have gettables and settables
215 EVP_KEYEXCH_gettable_params(keyexch
),
216 EVP_KEYEXCH_gettable_ctx_params(keyexch
),
217 EVP_KEYEXCH_settable_ctx_params(keyexch
),
224 static void do_signature(EVP_SIGNATURE
*signature
, void *meta
)
226 do_method(signature
, collect_signature_names
,
228 * TODO(3.0) Enable when KEYMGMT and SIGNATURE have gettables and settables
231 EVP_SIGNATURE_gettable_params(signature
),
232 EVP_SIGNATURE_gettable_ctx_params(signature
),
233 EVP_SIGNATURE_settable_ctx_params(signature
),
240 int provider_main(int argc
, char **argv
)
244 STACK_OF(OPENSSL_CSTRING
) *providers
= sk_OPENSSL_CSTRING_new_null();
248 prog
= opt_init(argc
, argv
, provider_options
);
249 while ((o
= opt_next()) != OPT_EOF
) {
251 default: /* Catching OPT_ERR & covering OPT_EOF which isn't possible */
252 BIO_printf(bio_err
, "%s: Use -help for summary.\n", prog
);
255 opt_help(provider_options
);
261 /* Convert to an integer from one to four. */
262 i
= (int)(o
- OPT_V
) + 1;
269 /* Allow any trailing parameters as provider names. */
270 argc
= opt_num_rest();
272 for ( ; *argv
; argv
++) {
273 /* This isn't necessary since -- is supported. */
275 BIO_printf(bio_err
, "%s: Cannot mix flags and provider names.\n",
277 BIO_printf(bio_err
, "%s: Use -help for summary.\n", prog
);
280 sk_OPENSSL_CSTRING_push(providers
, *argv
);
284 for (i
= 0; i
< sk_OPENSSL_CSTRING_num(providers
); i
++) {
285 const char *name
= sk_OPENSSL_CSTRING_value(providers
, i
);
286 OSSL_PROVIDER
*prov
= OSSL_PROVIDER_load(NULL
, name
);
289 BIO_printf(bio_out
, verbose
== 0 ? "%s\n" : "[ %s ]\n", name
);
296 data
.verbose
= verbose
;
298 data
.fn
= print_caps
;
302 BIO_printf(bio_out
, " ");
316 data
.label
= "Cipher";
318 EVP_CIPHER_do_all_provided(NULL
, do_cipher
, &data
);
321 data
.label
= "Digest";
323 EVP_MD_do_all_provided(NULL
, do_digest
, &data
);
328 EVP_MAC_do_all_provided(NULL
, do_mac
, &data
);
332 data
.label
= "Key manager";
334 EVP_KEYMGMT_do_all_provided(NULL
, do_keymgmt
, &data
);
337 data
.label
= "Key exchange";
339 EVP_KEYEXCH_do_all_provided(NULL
, do_keyexch
, &data
);
342 data
.label
= "Signature";
344 EVP_SIGNATURE_do_all_provided(NULL
, do_signature
, &data
);
351 BIO_printf(bio_out
, "\n");
355 OSSL_PROVIDER_unload(prov
);
357 ERR_print_errors(bio_err
);
360 * Just because one provider module failed, there's no reason to
361 * stop, if there are more to try.
368 ERR_print_errors(bio_err
);
369 sk_OPENSSL_CSTRING_free(providers
);