]>
git.ipfire.org Git - thirdparty/openssl.git/blob - apps/provider.c
2 * Copyright 2019-2020 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_dispatch.h>
23 DEFINE_STACK_OF_CSTRING()
25 typedef enum OPTION_choice
{
26 OPT_ERR
= -1, OPT_EOF
= 0, OPT_HELP
,
27 OPT_V
= 100, OPT_VV
, OPT_VVV
30 const OPTIONS provider_options
[] = {
31 {OPT_HELP_STR
, 1, '-', "Usage: %s [options] [provider...]\n"},
33 OPT_SECTION("General"),
34 {"help", OPT_HELP
, '-', "Display this summary"},
36 OPT_SECTION("Output"),
37 {"v", OPT_V
, '-', "List the algorithm names of specified provider"},
38 {"vv", OPT_VV
, '-', "List the algorithm names of specified providers,"},
39 {OPT_MORE_STR
, 0, '-', "categorised by operation type"},
40 {"vvv", OPT_VVV
, '-', "List the algorithm names of specified provider"},
41 {OPT_MORE_STR
, 0, '-', "one at a time, and list all known parameters"},
44 {"provider", 0, 0, "Provider(s) to load"},
48 typedef struct info_st INFO
;
49 typedef struct meta_st META
;
52 void (*collect_names_fn
)(void *method
, STACK_OF(OPENSSL_CSTRING
) *names
);
54 const OSSL_PARAM
*gettable_params
;
55 const OSSL_PARAM
*settable_params
;
56 const OSSL_PARAM
*gettable_ctx_params
;
57 const OSSL_PARAM
*settable_ctx_params
;
58 const OSSL_PARAM
*gen_settable_params
;
62 int first
; /* For prints */
69 void (*fn
)(META
*meta
, INFO
*info
);
72 static void collect_cipher_names(void *method
,
73 STACK_OF(OPENSSL_CSTRING
) *names
)
75 EVP_CIPHER_names_do_all(method
, collect_names
, names
);
78 static void collect_digest_names(void *method
,
79 STACK_OF(OPENSSL_CSTRING
) *names
)
81 EVP_MD_names_do_all(method
, collect_names
, names
);
84 static void collect_mac_names(void *method
,
85 STACK_OF(OPENSSL_CSTRING
) *names
)
87 EVP_MAC_names_do_all(method
, collect_names
, names
);
90 static void collect_keymgmt_names(void *method
,
91 STACK_OF(OPENSSL_CSTRING
) *names
)
93 EVP_KEYMGMT_names_do_all(method
, collect_names
, names
);
96 static void collect_keyexch_names(void *method
,
97 STACK_OF(OPENSSL_CSTRING
) *names
)
99 EVP_KEYEXCH_names_do_all(method
, collect_names
, names
);
102 static void collect_signature_names(void *method
,
103 STACK_OF(OPENSSL_CSTRING
) *names
)
105 EVP_SIGNATURE_names_do_all(method
, collect_names
, names
);
108 static void print_method_names(BIO
*out
, INFO
*info
)
110 STACK_OF(OPENSSL_CSTRING
) *names
= sk_OPENSSL_CSTRING_new(name_cmp
);
112 info
->collect_names_fn(info
->method
, names
);
113 print_names(out
, names
);
114 sk_OPENSSL_CSTRING_free(names
);
117 static void print_caps(META
*meta
, INFO
*info
)
119 switch (meta
->verbose
) {
122 BIO_printf(bio_out
, "; ");
123 print_method_names(bio_out
, info
);
128 BIO_printf(bio_out
, "\n");
129 BIO_printf(bio_out
, "%*s%ss:", meta
->indent
, "", meta
->label
);
131 BIO_printf(bio_out
, " ");
132 print_method_names(bio_out
, info
);
136 BIO_printf(bio_out
, "%*s%s ", meta
->indent
, "", meta
->label
);
137 print_method_names(bio_out
, info
);
138 BIO_printf(bio_out
, "\n");
139 print_param_types("settable keygen parameters",
140 info
->gen_settable_params
, meta
->subindent
);
141 print_param_types("settable algorithm parameters",
142 info
->settable_params
, meta
->subindent
);
143 print_param_types("retrievable algorithm parameters",
144 info
->gettable_params
, meta
->subindent
);
145 print_param_types("settable operation parameters",
146 info
->settable_ctx_params
, meta
->subindent
);
147 print_param_types("retrievable operation parameters",
148 info
->gettable_ctx_params
, meta
->subindent
);
154 static void do_method(void *method
,
155 void (*collect_names_fn
)(void *method
,
156 STACK_OF(OPENSSL_CSTRING
) *names
),
157 const OSSL_PARAM
*gettable_params
,
158 const OSSL_PARAM
*gettable_ctx_params
,
159 const OSSL_PARAM
*settable_ctx_params
,
164 memset(&info
, 0, sizeof(info
));
165 info
.collect_names_fn
= collect_names_fn
;
166 info
.method
= method
;
167 info
.gettable_params
= gettable_params
;
168 info
.gettable_ctx_params
= gettable_ctx_params
;
169 info
.settable_ctx_params
= settable_ctx_params
;
170 meta
->fn(meta
, &info
);
174 static void do_keymgmt_method(void *method
,
175 void (*collect_names_fn
)(void *method
,
176 STACK_OF(OPENSSL_CSTRING
)
178 const OSSL_PARAM
*gettable_params
,
179 const OSSL_PARAM
*settable_params
,
180 const OSSL_PARAM
*gen_settable_params
,
185 memset(&info
, 0, sizeof(info
));
186 info
.collect_names_fn
= collect_names_fn
;
187 info
.method
= method
;
188 info
.gettable_params
= gettable_params
;
189 info
.settable_params
= settable_params
;
190 info
.gen_settable_params
= gen_settable_params
;
191 meta
->fn(meta
, &info
);
195 static void do_cipher(EVP_CIPHER
*cipher
, void *meta
)
197 do_method(cipher
, collect_cipher_names
,
198 EVP_CIPHER_gettable_params(cipher
),
199 EVP_CIPHER_gettable_ctx_params(cipher
),
200 EVP_CIPHER_settable_ctx_params(cipher
),
204 static void do_digest(EVP_MD
*digest
, void *meta
)
206 do_method(digest
, collect_digest_names
,
207 EVP_MD_gettable_params(digest
),
208 EVP_MD_gettable_ctx_params(digest
),
209 EVP_MD_settable_ctx_params(digest
),
213 static void do_mac(EVP_MAC
*mac
, void *meta
)
215 do_method(mac
, collect_mac_names
,
216 EVP_MAC_gettable_params(mac
),
217 EVP_MAC_gettable_ctx_params(mac
),
218 EVP_MAC_settable_ctx_params(mac
),
222 static void do_keymgmt(EVP_KEYMGMT
*keymgmt
, void *meta
)
224 do_keymgmt_method(keymgmt
, collect_keymgmt_names
,
225 EVP_KEYMGMT_gettable_params(keymgmt
),
226 EVP_KEYMGMT_settable_params(keymgmt
),
227 EVP_KEYMGMT_gen_settable_params(keymgmt
),
231 static void do_keyexch(EVP_KEYEXCH
*keyexch
, void *meta
)
233 do_method(keyexch
, collect_keyexch_names
,
235 EVP_KEYEXCH_gettable_ctx_params(keyexch
),
236 EVP_KEYEXCH_settable_ctx_params(keyexch
),
240 static void do_signature(EVP_SIGNATURE
*signature
, void *meta
)
242 do_method(signature
, collect_signature_names
,
244 EVP_SIGNATURE_gettable_ctx_params(signature
),
245 EVP_SIGNATURE_settable_ctx_params(signature
),
249 int provider_main(int argc
, char **argv
)
253 STACK_OF(OPENSSL_CSTRING
) *providers
= sk_OPENSSL_CSTRING_new_null();
257 prog
= opt_init(argc
, argv
, provider_options
);
258 while ((o
= opt_next()) != OPT_EOF
) {
260 default: /* Catching OPT_ERR & covering OPT_EOF which isn't possible */
261 BIO_printf(bio_err
, "%s: Use -help for summary.\n", prog
);
264 opt_help(provider_options
);
270 /* Convert to an integer from one to four. */
271 i
= (int)(o
- OPT_V
) + 1;
278 /* Allow any trailing parameters as provider names. */
279 argc
= opt_num_rest();
281 for ( ; *argv
; argv
++) {
282 /* This isn't necessary since -- is supported. */
284 BIO_printf(bio_err
, "%s: Cannot mix flags and provider names.\n",
286 BIO_printf(bio_err
, "%s: Use -help for summary.\n", prog
);
289 sk_OPENSSL_CSTRING_push(providers
, *argv
);
293 for (i
= 0; i
< sk_OPENSSL_CSTRING_num(providers
); i
++) {
294 const char *name
= sk_OPENSSL_CSTRING_value(providers
, i
);
295 OSSL_PROVIDER
*prov
= OSSL_PROVIDER_load(NULL
, name
);
298 BIO_printf(bio_out
, verbose
== 0 ? "%s\n" : "[ %s ]\n", name
);
305 data
.verbose
= verbose
;
307 data
.fn
= print_caps
;
311 BIO_printf(bio_out
, " ");
325 data
.label
= "Cipher";
327 EVP_CIPHER_do_all_provided(NULL
, do_cipher
, &data
);
330 data
.label
= "Digest";
332 EVP_MD_do_all_provided(NULL
, do_digest
, &data
);
337 EVP_MAC_do_all_provided(NULL
, do_mac
, &data
);
341 data
.label
= "Key manager";
343 EVP_KEYMGMT_do_all_provided(NULL
, do_keymgmt
, &data
);
346 data
.label
= "Key exchange";
348 EVP_KEYEXCH_do_all_provided(NULL
, do_keyexch
, &data
);
351 data
.label
= "Signature";
353 EVP_SIGNATURE_do_all_provided(NULL
, do_signature
, &data
);
360 BIO_printf(bio_out
, "\n");
364 OSSL_PROVIDER_unload(prov
);
366 ERR_print_errors(bio_err
);
369 * Just because one provider module failed, there's no reason to
370 * stop, if there are more to try.
377 ERR_print_errors(bio_err
);
378 sk_OPENSSL_CSTRING_free(providers
);