Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/openssl/experimental.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2022-01-11 20:30:20 +0300
committerRichard Levitte <levitte@openssl.org>2022-01-21 16:44:16 +0300
commit8c2e588bcf0de61880ec8a956ef57ad6b8a50163 (patch)
tree9146233ca5b5389c7bfe3425bf6cb8c0eede504e
parentfbe88706a4f93f9e1940a07062d77c81b7fdf04d (diff)
LEGACY PROV: Reimplement the ERR building blocks in upcall termsHEADmaster
This involves the following functions: ERR_new(), ERR_set_debug(), ERR_set_error(), ERR_vset_error(), ERR_set_mark(), ERR_clear_last_mark(), ERR_pop_to_mark(void) Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17474)
-rw-r--r--providers/legacyprov.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/providers/legacyprov.c b/providers/legacyprov.c
index 93c4223a15..ad5d05d739 100644
--- a/providers/legacyprov.c
+++ b/providers/legacyprov.c
@@ -12,6 +12,7 @@
#include <openssl/core.h>
#include <openssl/core_dispatch.h>
#include <openssl/core_names.h>
+#include <openssl/err.h>
#include <openssl/params.h>
#include "prov/provider_ctx.h"
#include "prov/implementations.h"
@@ -33,6 +34,22 @@ OSSL_provider_init_fn ossl_legacy_provider_init;
# define OSSL_provider_init ossl_legacy_provider_init
#endif
+#ifndef STATIC_LEGACY
+/*
+ * Should these function pointers be stored in the provider side provctx?
+ * Could they ever be different from one init to the next? We assume not for
+ * now.
+ */
+
+/* Functions provided by the core */
+static OSSL_FUNC_core_new_error_fn *c_new_error;
+static OSSL_FUNC_core_set_error_debug_fn *c_set_error_debug;
+static OSSL_FUNC_core_vset_error_fn *c_vset_error;
+static OSSL_FUNC_core_set_error_mark_fn *c_set_error_mark;
+static OSSL_FUNC_core_clear_last_error_mark_fn *c_clear_last_error_mark;
+static OSSL_FUNC_core_pop_error_to_mark_fn *c_pop_error_to_mark;
+#endif
+
/* Parameters we provide to the core */
static const OSSL_PARAM legacy_param_types[] = {
OSSL_PARAM_DEFN(OSSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0),
@@ -185,6 +202,41 @@ int OSSL_provider_init(const OSSL_CORE_HANDLE *handle,
void **provctx)
{
OSSL_LIB_CTX *libctx = NULL;
+#ifndef STATIC_LEGACY
+ const OSSL_DISPATCH *tmp;
+#endif
+
+#ifndef STATIC_LEGACY
+ for (tmp = in; tmp->function_id != 0; tmp++) {
+ /*
+ * We do not support the scenario of an application linked against
+ * multiple versions of libcrypto (e.g. one static and one dynamic),
+ * but sharing a single legacy.so. We do a simple sanity check here.
+ */
+#define set_func(c, f) if (c == NULL) c = f; else if (c != f) return 0;
+ switch (tmp->function_id) {
+ case OSSL_FUNC_CORE_NEW_ERROR:
+ set_func(c_new_error, OSSL_FUNC_core_new_error(tmp));
+ break;
+ case OSSL_FUNC_CORE_SET_ERROR_DEBUG:
+ set_func(c_set_error_debug, OSSL_FUNC_core_set_error_debug(tmp));
+ break;
+ case OSSL_FUNC_CORE_VSET_ERROR:
+ set_func(c_vset_error, OSSL_FUNC_core_vset_error(tmp));
+ break;
+ case OSSL_FUNC_CORE_SET_ERROR_MARK:
+ set_func(c_set_error_mark, OSSL_FUNC_core_set_error_mark(tmp));
+ break;
+ case OSSL_FUNC_CORE_CLEAR_LAST_ERROR_MARK:
+ set_func(c_clear_last_error_mark,
+ OSSL_FUNC_core_clear_last_error_mark(tmp));
+ break;
+ case OSSL_FUNC_CORE_POP_ERROR_TO_MARK:
+ set_func(c_pop_error_to_mark, OSSL_FUNC_core_pop_error_to_mark(tmp));
+ break;
+ }
+ }
+#endif
if ((*provctx = ossl_prov_ctx_new()) == NULL
|| (libctx = OSSL_LIB_CTX_new_child(handle, in)) == NULL) {
@@ -200,3 +252,53 @@ int OSSL_provider_init(const OSSL_CORE_HANDLE *handle,
return 1;
}
+
+#ifndef STATIC_LEGACY
+/*
+ * Provider specific implementation of libcrypto functions in terms of
+ * upcalls.
+ */
+
+/*
+ * For ERR functions, we pass a NULL context. This is valid to do as long
+ * as only error codes that the calling libcrypto supports are used.
+ */
+void ERR_new(void)
+{
+ c_new_error(NULL);
+}
+
+void ERR_set_debug(const char *file, int line, const char *func)
+{
+ c_set_error_debug(NULL, file, line, func);
+}
+
+void ERR_set_error(int lib, int reason, const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ c_vset_error(NULL, ERR_PACK(lib, 0, reason), fmt, args);
+ va_end(args);
+}
+
+void ERR_vset_error(int lib, int reason, const char *fmt, va_list args)
+{
+ c_vset_error(NULL, ERR_PACK(lib, 0, reason), fmt, args);
+}
+
+int ERR_set_mark(void)
+{
+ return c_set_error_mark(NULL);
+}
+
+int ERR_clear_last_mark(void)
+{
+ return c_clear_last_error_mark(NULL);
+}
+
+int ERR_pop_to_mark(void)
+{
+ return c_pop_error_to_mark(NULL);
+}
+#endif