]>
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"
15 #include <openssl/err.h>
16 #include <openssl/evp.h>
17 #include <openssl/safestack.h>
18 #include <openssl/provider.h>
19 #include <openssl/core.h>
20 #include <openssl/core_numbers.h>
22 typedef enum OPTION_choice
{
23 OPT_ERR
= -1, OPT_EOF
= 0, OPT_HELP
,
24 OPT_V
= 100, OPT_VV
, OPT_VVV
27 const OPTIONS provider_options
[] = {
28 {OPT_HELP_STR
, 1, '-', "Usage: %s [options] provider...\n"},
29 {OPT_HELP_STR
, 1, '-', " provider... Providers to load\n"},
30 {"help", OPT_HELP
, '-', "Display this summary"},
31 {"v", OPT_V
, '-', "List the algorithm names of specified provider"},
32 {"vv", OPT_VV
, '-', "List the algorithm names of specified providers,"},
33 {OPT_MORE_STR
, 0, '-', "categorised by operation type"},
34 {"vvv", OPT_VVV
, '-', "List the algorithm names of specified provider"},
35 {OPT_MORE_STR
, 0, '-', "one at a time, and list all known parameters"},
39 typedef struct info_st INFO
;
40 typedef struct meta_st META
;
45 const OSSL_PARAM
*gettable_params
;
46 const OSSL_PARAM
*gettable_ctx_params
;
47 const OSSL_PARAM
*settable_ctx_params
;
51 int first
; /* For prints */
58 void (*fn
)(META
*meta
, INFO
*info
);
61 static void print_caps(META
*meta
, INFO
*info
)
63 switch (meta
->verbose
) {
65 BIO_printf(bio_out
, meta
->first
? "%s" : " %s", info
->name
);
70 BIO_printf(bio_out
, "\n");
71 BIO_printf(bio_out
, "%*s%ss:", meta
->indent
, "", meta
->label
);
73 BIO_printf(bio_out
, " %s", info
->name
);
77 BIO_printf(bio_out
, "%*s%s %s\n", meta
->indent
, "", meta
->label
,
79 print_param_types("retrievable algorithm parameters",
80 info
->gettable_params
, meta
->subindent
);
81 print_param_types("retrievable operation parameters",
82 info
->gettable_ctx_params
, meta
->subindent
);
83 print_param_types("settable operation parameters",
84 info
->settable_ctx_params
, meta
->subindent
);
90 static void do_method(void *method
, const char *name
,
91 const OSSL_PARAM
*gettable_params
,
92 const OSSL_PARAM
*gettable_ctx_params
,
93 const OSSL_PARAM
*settable_ctx_params
,
100 info
.gettable_params
= gettable_params
;
101 info
.gettable_ctx_params
= gettable_ctx_params
;
102 info
.settable_ctx_params
= settable_ctx_params
;
103 meta
->fn(meta
, &info
);
107 static void do_cipher(EVP_CIPHER
*cipher
, void *meta
)
109 do_method(cipher
, EVP_CIPHER_name(cipher
),
110 EVP_CIPHER_gettable_params(cipher
),
111 EVP_CIPHER_CTX_gettable_params(cipher
),
112 EVP_CIPHER_CTX_settable_params(cipher
),
116 static void do_digest(EVP_MD
*digest
, void *meta
)
118 do_method(digest
, EVP_MD_name(digest
),
119 EVP_MD_gettable_params(digest
),
120 EVP_MD_CTX_gettable_params(digest
),
121 EVP_MD_CTX_settable_params(digest
),
125 static void do_mac(EVP_MAC
*mac
, void *meta
)
127 do_method(mac
, EVP_MAC_name(mac
),
128 EVP_MAC_gettable_params(mac
),
129 EVP_MAC_CTX_gettable_params(mac
),
130 EVP_MAC_CTX_settable_params(mac
),
135 * TODO(3.0) Enable when KEYMGMT and KEYEXCH have gettables and settables
138 static void do_keymgmt(EVP_KEYMGMT
*keymgmt
, void *meta
)
140 do_method(keymgmt
, EVP_KEYMGMT_name(keymgmt
),
141 EVP_KEYMGMT_gettable_params(keymgmt
),
142 EVP_KEYMGMT_gettable_ctx_params(keymgmt
),
143 EVP_KEYMGMT_settable_ctx_params(keymgmt
),
147 static void do_keyexch(EVP_KEYEXCH
*keyexch
, void *meta
)
149 do_method(keyexch
, EVP_KEYEXCH_name(keyexch
),
150 EVP_KEYEXCH_gettable_params(keyexch
),
151 EVP_KEYEXCH_gettable_ctx_params(keyexch
),
152 EVP_KEYEXCH_settable_ctx_params(keyexch
),
157 int provider_main(int argc
, char **argv
)
161 STACK_OF(OPENSSL_CSTRING
) *providers
= sk_OPENSSL_CSTRING_new_null();
165 prog
= opt_init(argc
, argv
, provider_options
);
166 while ((o
= opt_next()) != OPT_EOF
) {
168 default: /* Catching OPT_ERR & covering OPT_EOF which isn't possible */
169 BIO_printf(bio_err
, "%s: Use -help for summary.\n", prog
);
172 opt_help(provider_options
);
178 /* Convert to an integer from one to four. */
179 i
= (int)(o
- OPT_V
) + 1;
186 /* Allow any trailing parameters as provider names. */
187 argc
= opt_num_rest();
189 for ( ; *argv
; argv
++) {
191 BIO_printf(bio_err
, "%s: Cannot mix flags and provider names.\n",
193 BIO_printf(bio_err
, "%s: Use -help for summary.\n", prog
);
196 sk_OPENSSL_CSTRING_push(providers
, *argv
);
200 for (i
= 0; i
< sk_OPENSSL_CSTRING_num(providers
); i
++) {
201 const char *name
= sk_OPENSSL_CSTRING_value(providers
, i
);
202 OSSL_PROVIDER
*prov
= OSSL_PROVIDER_load(NULL
, name
);
205 BIO_printf(bio_out
, verbose
== 0 ? "%s\n" : "[ %s ]\n", name
);
212 data
.verbose
= verbose
;
214 data
.fn
= print_caps
;
218 BIO_printf(bio_out
, " ");
232 data
.label
= "Cipher";
234 EVP_CIPHER_do_all_ex(NULL
, do_cipher
, &data
);
237 data
.label
= "Digest";
239 EVP_MD_do_all_ex(NULL
, do_digest
, &data
);
244 EVP_MAC_do_all_ex(NULL
, do_mac
, &data
);
247 * TODO(3.0) Enable when KEYMGMT and KEYEXCH have do_all_ex functions
252 data
.label
= "Key manager";
254 EVP_KEYMGMT_do_all_ex(NULL
, do_keymgmt
, &data
);
257 data
.label
= "Key exchange";
259 EVP_KEYEXCH_do_all_ex(NULL
, do_keyexch
, &data
);
267 BIO_printf(bio_out
, "\n");
271 OSSL_PROVIDER_unload(prov
);
273 ERR_print_errors(bio_err
);
276 * Just because one provider module failed, there's no reason to
277 * stop, if there are more to try.
284 ERR_print_errors(bio_err
);
285 sk_OPENSSL_CSTRING_free(providers
);