#include <string.h>
#include <openssl/core.h>
+#include <openssl/core_dispatch.h>
#include <openssl/provider.h>
#include <openssl/crypto.h>
#include "testutil.h"
#include "filterprov.h"
+#include "prov/bio.h"
#define MAX_FILTERS 10
#define MAX_ALG_FILTERS 5
OSSL_PROVIDER_unload(globs->deflt);
OSSL_LIB_CTX_free(globs->libctx);
memset(globs, 0, sizeof(*globs));
+ BIO_meth_free(ossl_prov_ctx_get0_core_bio_method(provctx));
+ ossl_prov_ctx_free(provctx);
}
/* Functions we provide to the core */
const OSSL_DISPATCH **out,
void **provctx)
{
+ OSSL_FUNC_core_get_libctx_fn *c_get_libctx = NULL;
+ BIO_METHOD *corebiometh;
+
+ if (!ossl_prov_bio_from_dispatch(in))
+ return 0;
+ for (; in->function_id != 0; in++) {
+ switch (in->function_id) {
+ case OSSL_FUNC_CORE_GET_LIBCTX:
+ c_get_libctx = OSSL_FUNC_core_get_libctx(in);
+ break;
+ default:
+ /* Just ignore anything we don't understand */
+ break;
+ }
+ }
+
+ if (c_get_libctx == NULL)
+ return 0;
+
memset(&ourglobals, 0, sizeof(ourglobals));
ourglobals.libctx = OSSL_LIB_CTX_new();
if (ourglobals.libctx == NULL)
if (ourglobals.deflt == NULL)
goto err;
- *provctx = OSSL_PROVIDER_get0_provider_ctx(ourglobals.deflt);
+ /*
+ * We want to make sure that all calls from this provider that requires
+ * a library context use the same context as the one used to call our
+ * functions. We do that by passing it along in the provider context.
+ *
+ * This only works for built-in providers. Most providers should
+ * create their own library context.
+ */
+ if ((*provctx = ossl_prov_ctx_new()) == NULL
+ || (corebiometh = ossl_bio_prov_init_bio_method()) == NULL) {
+ ossl_prov_ctx_free(*provctx);
+ *provctx = NULL;
+ goto err;
+ }
+ ossl_prov_ctx_set0_libctx(*provctx, (OSSL_LIB_CTX *)c_get_libctx(handle));
+ ossl_prov_ctx_set0_handle(*provctx, handle);
+ ossl_prov_ctx_set0_core_bio_method(*provctx, corebiometh);
*out = filter_dispatch_table;
return 1;