]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Expose the provider `c_get_params` function via PROV_CTX.
authorViktor Dukhovni <openssl-users@dukhovni.org>
Thu, 23 Jan 2025 04:42:14 +0000 (15:42 +1100)
committerViktor Dukhovni <openssl-users@dukhovni.org>
Fri, 24 Jan 2025 11:51:35 +0000 (22:51 +1100)
This applies to the base, default and FIPS providers, could be added in
principle also to the legacy provider, but there's no compelling reason
to do that at the moment.

Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/26530)

providers/baseprov.c
providers/common/include/prov/provider_ctx.h
providers/common/provider_ctx.c
providers/defltprov.c
providers/fips/fipsprov.c

index 7b068f09334e02b10ca5c3d30e9fa576cb930106..4700be4c782aedef0f387a050667e0a80bfcadc2 100644 (file)
@@ -181,6 +181,7 @@ int ossl_base_provider_init(const OSSL_CORE_HANDLE *handle,
                                        (OSSL_LIB_CTX *)c_get_libctx(handle));
     ossl_prov_ctx_set0_handle(*provctx, handle);
     ossl_prov_ctx_set0_core_bio_method(*provctx, corebiometh);
+    ossl_prov_ctx_set0_core_get_params(*provctx, c_get_params);
 
     *out = base_dispatch_table;
 
index c8126e17616143afc7e3992f1b9b7eaca051d7ca..069ec99a21cc077a499e89a5e39e7c102264a812 100644 (file)
 # include <openssl/crypto.h>
 # include <openssl/bio.h>
 # include <openssl/core.h>
+# include <openssl/core_dispatch.h>
 
 typedef struct prov_ctx_st {
     const OSSL_CORE_HANDLE *handle;
     OSSL_LIB_CTX *libctx;         /* For all provider modules */
     BIO_METHOD *corebiometh;
+    OSSL_FUNC_core_get_params_fn *core_get_params;
 } PROV_CTX;
 
 /*
@@ -33,8 +35,13 @@ void ossl_prov_ctx_free(PROV_CTX *ctx);
 void ossl_prov_ctx_set0_libctx(PROV_CTX *ctx, OSSL_LIB_CTX *libctx);
 void ossl_prov_ctx_set0_handle(PROV_CTX *ctx, const OSSL_CORE_HANDLE *handle);
 void ossl_prov_ctx_set0_core_bio_method(PROV_CTX *ctx, BIO_METHOD *corebiometh);
+void
+ossl_prov_ctx_set0_core_get_params(PROV_CTX *ctx,
+                                   OSSL_FUNC_core_get_params_fn *c_get_params);
 OSSL_LIB_CTX *ossl_prov_ctx_get0_libctx(PROV_CTX *ctx);
 const OSSL_CORE_HANDLE *ossl_prov_ctx_get0_handle(PROV_CTX *ctx);
 BIO_METHOD *ossl_prov_ctx_get0_core_bio_method(PROV_CTX *ctx);
+OSSL_FUNC_core_get_params_fn *ossl_prov_ctx_get0_core_get_params(PROV_CTX *ctx);
+int ossl_prov_ctx_get_bool_param(PROV_CTX *ctx, const char *name, int defval);
 
 #endif
index 9690abfd5776b24be6b47dd738680aba3d97c4b8..4a6cf621e27663762497d3241a6f7075fdd249d3 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include <stdlib.h>
+#include <string.h>
 #include "prov/provider_ctx.h"
 #include "prov/bio.h"
 
@@ -39,6 +40,14 @@ void ossl_prov_ctx_set0_core_bio_method(PROV_CTX *ctx, BIO_METHOD *corebiometh)
         ctx->corebiometh = corebiometh;
 }
 
+void
+ossl_prov_ctx_set0_core_get_params(PROV_CTX *ctx,
+                                   OSSL_FUNC_core_get_params_fn *c_get_params)
+{
+    if (ctx != NULL)
+        ctx->core_get_params = c_get_params;
+}
+
 OSSL_LIB_CTX *ossl_prov_ctx_get0_libctx(PROV_CTX *ctx)
 {
     if (ctx == NULL)
@@ -59,3 +68,44 @@ BIO_METHOD *ossl_prov_ctx_get0_core_bio_method(PROV_CTX *ctx)
         return NULL;
     return ctx->corebiometh;
 }
+
+OSSL_FUNC_core_get_params_fn *ossl_prov_ctx_get0_core_get_params(PROV_CTX *ctx)
+{
+    if (ctx == NULL)
+        return NULL;
+    return ctx->core_get_params;
+}
+
+int ossl_prov_ctx_get_bool_param(PROV_CTX *ctx, const char *name, int defval)
+{
+    char *val = NULL;
+    OSSL_PARAM param[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
+
+    if (ctx == NULL
+        || ctx->handle == NULL
+        || ctx->core_get_params == NULL)
+        return defval;
+
+    param[0].key = (char *)name;
+    param[0].data_type = OSSL_PARAM_UTF8_PTR;
+    param[0].data = (void *) &val;
+    param[0].data_size = sizeof(val);
+    param[0].return_size = OSSL_PARAM_UNMODIFIED;
+
+    /* Errors are ignored, returning the default value */
+    if (ctx->core_get_params(ctx->handle, param)
+        && OSSL_PARAM_modified(param)
+        && val != NULL) {
+        if ((strcmp(val, "1") == 0)
+            || (OPENSSL_strcasecmp(val, "yes") == 0)
+            || (OPENSSL_strcasecmp(val, "true") == 0)
+            || (OPENSSL_strcasecmp(val, "on") == 0))
+            return 1;
+        else if ((strcmp(val, "0") == 0)
+                 || (OPENSSL_strcasecmp(val, "no") == 0)
+                 || (OPENSSL_strcasecmp(val, "false") == 0)
+                 || (OPENSSL_strcasecmp(val, "off") == 0))
+            return 0;
+    }
+    return defval;
+}
index 765ae25a3b0f615c9b3b0b7e6f53bb2aa654eef6..e30256cbaa43e61c945eb9545a4123d1ebc48899 100644 (file)
@@ -661,6 +661,7 @@ int ossl_default_provider_init(const OSSL_CORE_HANDLE *handle,
                                        (OSSL_LIB_CTX *)c_get_libctx(handle));
     ossl_prov_ctx_set0_handle(*provctx, handle);
     ossl_prov_ctx_set0_core_bio_method(*provctx, corebiometh);
+    ossl_prov_ctx_set0_core_get_params(*provctx, c_get_params);
 
     *out = deflt_dispatch_table;
     ossl_prov_cache_exported_algorithms(deflt_ciphers, exported_ciphers);
index ba82435dd9a856d5e7168f77c00a51eef267a256..38d0ae9f7f77aa4f3dc554e0455137d35c2905de 100644 (file)
@@ -816,6 +816,7 @@ int OSSL_provider_init_int(const OSSL_CORE_HANDLE *handle,
     }
 
     ossl_prov_ctx_set0_libctx(*provctx, libctx);
+    ossl_prov_ctx_set0_core_get_params(*provctx, c_get_params);
     ossl_prov_ctx_set0_handle(*provctx, handle);
 
     *out = fips_dispatch_table;