2 * Copyright 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
12 #include <openssl/err.h>
13 #include <openssl/provider.h>
14 #include <openssl/safestack.h>
16 DEFINE_STACK_OF(OSSL_PROVIDER)
19 * See comments in opt_verify for explanation of this.
21 enum prov_range { OPT_PROV_ENUM };
23 static STACK_OF(OSSL_PROVIDER) *app_providers = NULL;
25 static void provider_free(OSSL_PROVIDER *prov)
27 OSSL_PROVIDER_unload(prov);
30 int app_provider_load(OPENSSL_CTX *libctx, const char *provider_name)
34 prov = OSSL_PROVIDER_load(libctx, provider_name);
36 opt_printf_stderr("%s: unable to load provider %s\n",
37 opt_getprog(), provider_name);
40 if (app_providers == NULL)
41 app_providers = sk_OSSL_PROVIDER_new_null();
42 if (app_providers == NULL
43 || !sk_OSSL_PROVIDER_push(app_providers, prov)) {
44 app_providers_cleanup();
50 void app_providers_cleanup(void)
52 sk_OSSL_PROVIDER_pop_free(app_providers, provider_free);
56 static int opt_provider_path(const char *path)
58 if (path != NULL && *path == '\0')
60 return OSSL_PROVIDER_set_default_search_path(app_get0_libctx(), path);
63 int opt_provider(int opt)
65 switch ((enum prov_range)opt) {
69 case OPT_PROV_PROVIDER:
70 return app_provider_load(app_get0_libctx(), opt_arg());
71 case OPT_PROV_PROVIDER_PATH:
72 return opt_provider_path(opt_arg());