Skip to contentSkip to conversation

add engine keys keys

PATCH In review James Bottomley 3 participants 8 messages Feb 10, 2018 – Feb 15, 2020

lore
Share & tools
lore
#0 lore raw

v4 cover add engine keys keys

Engine keys are an openssl concept for a key file which can only be understood by an engine (usually because it's been wrapped by the engine itself). We use this for TPM engine keys, so you can either generate them within your TPM or wrap them from existing private keys.
Once wrapped, the keys will only function in the TPM that generated
them, so it means the VPN keys are tied to the physical platform, which is very useful. Engine keys have to be loaded via a specific callback, so use this as a fallback in openvpn if an engine is specified and if the PEM read of the private key fails.

Adding a unit test for this type of key proved particularly
problematic: there's apparently no simple engine you can use to check the functionality, so after a bit of googling, I just wrote one as part of the test. You can see that the unit test converts an existing key to engine format (which is simply changing the PEM guards), tries to start openvpn with the key and verifies that the engine methods are called and the password correctly retrieved. To make the test simple, it relies on openssl detecting a mismatch between the certificate and the key after the key has been loaded rather than going on to bring up an openvpn loop, but I think that's sufficient to test out the engine patch fully.

James Bottomley (2):
openssl: add engine method for loading the key
Add unit tests for engine keys

 configure.ac                                     |   2 +
 src/openvpn/crypto_openssl.c                     |  54 ++++++++++++
 src/openvpn/crypto_openssl.h                     |  12 +++
 src/openvpn/ssl_openssl.c                        |   6 +-
 tests/unit_tests/Makefile.am                     |   6 +-
 tests/unit_tests/engine-key/Makefile.am          |  14 ++++
 tests/unit_tests/engine-key/check_engine_keys.sh |  30 +++++++
 tests/unit_tests/engine-key/libtestengine.c      | 102 +++++++++++++++++++++++
 tests/unit_tests/engine-key/openssl.cnf          |  12 +++
 9 files changed, 236 insertions(+), 2 deletions(-)
 create mode 100644 tests/unit_tests/engine-key/Makefile.am
 create mode 100755 tests/unit_tests/engine-key/check_engine_keys.sh
 create mode 100644 tests/unit_tests/engine-key/libtestengine.c
 create mode 100644 tests/unit_tests/engine-key/openssl.cnf
Signature · 1 line
2.12.3
#1 lore raw

PATCH v4 1/2 openssl: add engine method for loading the key

As well as doing crypto acceleration, engines can also be used to load key files. If the engine is set, and the private key loading fails for bio methods, this patch makes openvpn try to get the engine to load the key. If that succeeds, we end up using an engine based key. This can be used with the openssl tpm engines to make openvpn use a TPM wrapped key file.

---

v2: add better configuration guarding

v4: - use crypto_msg() instead of raw openssl prints
- remove ENGINE_init/finish(). Openvpn already initializes the engine so doing a second initialization is wrong.
- don't clear the openssl errors from the BIO_read failure just in case they might be useful.
- ad ui.h include for openssl 1.1 build failure

---
 src/openvpn/crypto_openssl.c | 53 ++++++++++++++++++++++++++++++++++++++++++++
 src/openvpn/crypto_openssl.h | 12 ++++++++++
 src/openvpn/ssl_openssl.c    |  6 ++++-
 3 files changed, 70 insertions(+), 1 deletion(-)
src/openvpn/crypto_openssl.c +53 -0
index 4fb2f6d6..936cbb0d 100644
@@ -63,6 +63,7 @@
 #endif
 
 #if HAVE_OPENSSL_ENGINE
+#include <openssl/ui.h>
 #include <openssl/engine.h>
 
 static bool engine_initialized = false; /* GLOBAL */
@@ -969,4 +970,56 @@ hmac_ctx_final(HMAC_CTX *ctx, uint8_t *dst)
     HMAC_Final(ctx, dst, &in_hmac_len);
 }
 
+#if HAVE_OPENSSL_ENGINE
+static int
+ui_reader(UI *ui, UI_STRING *uis)
+{
+    SSL_CTX *ctx = UI_get0_user_data(ui);
+
+    if (UI_get_string_type(uis) == UIT_PROMPT) {
+        pem_password_cb *cb = SSL_CTX_get_default_passwd_cb(ctx);
+        void *d = SSL_CTX_get_default_passwd_cb_userdata(ctx);
+        char password[64];
+
+        cb(password, sizeof(password), 0, d);
+        UI_set_result(ui, uis, password);
+
+        return 1;
+    }
+    return 0;
+}
+#endif
+
+EVP_PKEY *
+engine_load_key(const char *file, SSL_CTX *ctx)
+{
+#if HAVE_OPENSSL_ENGINE
+    UI_METHOD *ui;
+    EVP_PKEY *pkey;
+
+    if (!engine_persist)
+        return NULL;
+
+    /* this will print out the error from BIO_read */
+    crypto_msg(M_INFO, "PEM_read_bio failed, now trying engine method to load private key");
+
+    ui = UI_create_method("openvpn");
+    if (!ui) {
+	crypto_msg(M_FATAL, "Engine UI creation failed");
+        return NULL;
+    }
+
+    UI_method_set_reader(ui, ui_reader);
+
+    pkey = ENGINE_load_private_key(engine_persist, file, ui, ctx);
+    if (!pkey)
+	crypto_msg(M_FATAL, "Engine could not load key file");
+ out:
+    UI_destroy_method(ui);
+    return pkey;
+#else
+    return NULL;
+#endif
+}
+
 #endif /* ENABLE_CRYPTO_OPENSSL */
src/openvpn/crypto_openssl.h +12 -0
index 0a413705..98be36d5 100644
@@ -101,5 +101,17 @@ void crypto_print_openssl_errors(const unsigned int flags);
         msg((flags), __VA_ARGS__); \
     } while (false)
 
+/**
+ * Load a key file from an engine
+ *
+ * @param file	The engine file to load
+ * @param ui	The UI method for the password prompt
+ * @param data	The data to pass to the UI method
+ *
+ * @return	The private key if successful or NULL if not
+ */
+EVP_PKEY *
+engine_load_key(const char *file, SSL_CTX *ctx);
+
 
 #endif /* CRYPTO_OPENSSL_H_ */
src/openvpn/ssl_openssl.c +5 -1
index 26c1e608..76ce6939 100644
@@ -907,7 +907,11 @@ tls_ctx_load_priv_file(struct tls_root_ctx *ctx, const char *priv_key_file,
                                    SSL_CTX_get_default_passwd_cb_userdata(ctx->ctx));
     if (!pkey)
     {
-        goto end;
+        pkey = engine_load_key(priv_key_file, ctx->ctx);
+        if (!pkey)
+        {
+            goto end;
+        }
     }
 
     if (!SSL_CTX_use_PrivateKey(ssl_ctx, pkey))
Signature · 1 line
2.12.3
#2 lore raw

PATCH v4 2/2 Add unit tests for engine keys

In reply to James Bottomley

Testing engines is problematic, so one of the prerequisites built for the tests is a simple openssl engine that reads a non-standard PEM guarded key. The test is simply can we run a client/server configuration with the usual sample key replaced by an engine key. The trivial engine prints out some operations and we check for these in the log to make sure the engine was used to load the key and that it correctly got the password.

---
v4: add OPENSSL_config(NULL) so debian checks will work
v3: added this patch

---
 configure.ac                                     |   2 +
 src/openvpn/crypto_openssl.c                     |   1 +
 tests/unit_tests/Makefile.am                     |   6 +-
 tests/unit_tests/engine-key/Makefile.am          |  14 ++++
 tests/unit_tests/engine-key/check_engine_keys.sh |  30 +++++++
 tests/unit_tests/engine-key/libtestengine.c      | 102 +++++++++++++++++++++++
 tests/unit_tests/engine-key/openssl.cnf          |  12 +++
 7 files changed, 166 insertions(+), 1 deletion(-)
 create mode 100644 tests/unit_tests/engine-key/Makefile.am
 create mode 100755 tests/unit_tests/engine-key/check_engine_keys.sh
 create mode 100644 tests/unit_tests/engine-key/libtestengine.c
 create mode 100644 tests/unit_tests/engine-key/openssl.cnf
configure.ac +2 -0
index 2cbf3358..2f7ef8a0 100644
@@ -1360,6 +1360,7 @@ AM_CONDITIONAL([GIT_CHECKOUT], [test "${GIT_CHECKOUT}" = "yes"])
 AM_CONDITIONAL([ENABLE_PLUGIN_AUTH_PAM], [test "${enable_plugin_auth_pam}" = "yes"])
 AM_CONDITIONAL([ENABLE_PLUGIN_DOWN_ROOT], [test "${enable_plugin_down_root}" = "yes"])
 AM_CONDITIONAL([HAVE_LD_WRAP_SUPPORT], [test "${have_ld_wrap_support}" = "yes"])
+AM_CONDITIONAL([OPENSSL_ENGINE], [test "${have_openssl_engine}" = "yes"])
 
 sampledir="\$(docdir)/sample"
 AC_SUBST([plugindir])
@@ -1424,6 +1425,7 @@ AC_CONFIG_FILES([
         tests/unit_tests/openvpn/Makefile
         tests/unit_tests/plugins/Makefile
         tests/unit_tests/plugins/auth-pam/Makefile
+	tests/unit_tests/engine-key/Makefile
         vendor/Makefile
 	sample/Makefile
 ])
src/openvpn/crypto_openssl.c +1 -0
index 936cbb0d..558fdb46 100644
@@ -92,6 +92,7 @@ setup_engine(const char *engine)
 {
     ENGINE *e = NULL;
 
+    OPENSSL_config(NULL);
     ENGINE_load_builtin_engines();
 
     if (engine)
tests/unit_tests/Makefile.am +5 -1
index 31d37b89..648bd7a8 100644
@@ -1,5 +1,9 @@
 AUTOMAKE_OPTIONS = foreign
 
+SUBDIRS =
 if CMOCKA_INITIALIZED
-SUBDIRS = example_test openvpn plugins
+SUBDIRS += example_test openvpn plugins
+endif
+if OPENSSL_ENGINE
+SUBDIRS += engine-key
 endif
tests/unit_tests/engine-key/Makefile.am new file +14 -0
new file mode 100644
index 00000000..f83bf817
@@ -0,0 +1,14 @@
+AUTOMAKE_OPTIONS = foreign
+
+check_LTLIBRARIES = libtestengine.la
+
+TESTS_ENVIRONMENT = srcdir="$(abs_srcdir)"; \
+	top_builddir="$(top_builddir)"; \
+	top_srcdir="$(top_srcdir)"; \
+	export srcdir top_builddir top_srcdir;
+
+TESTS = check_engine_keys.sh
+
+libtestengine_la_SOURCES = libtestengine.c
+libtestengine_la_LDFLAGS = -rpath /lib -avoid-version
+
tests/unit_tests/engine-key/check_engine_keys.sh new file +30 -0
new file mode 100755
index 00000000..c1ae59e6
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+OPENSSL_CONF="${srcdir}/openssl.cnf"
+export OPENSSL_CONF
+
+password='AT3S4PASSWD'
+
+key="${srcdir}/client.key"
+pwdfile="${srcdir}/passwd"
+
+# create an engine key for us
+sed 's/PRIVATE KEY/TEST ENGINE KEY/' < ${top_srcdir}/sample/sample-keys/client.key > ${key}
+echo "$password" > $pwdfile
+
+# note here we've induced a mismatch in the client key and the server
+# cert which openvpn should report and die.  Check that it does.  Note
+# also that this mismatch depends on openssl not openvpn, so it is
+# somewhat fragile
+${top_builddir}/src/openvpn/openvpn --cd ${top_srcdir}/sample --config sample-config-files/loopback-server --engine testengine --key ${key} --askpass $pwdfile > log.txt 2>&1
+
+# first off check we died because of a key mismatch.  If this doesn't
+# pass, suspect openssl of returning different messages and update the
+# test accordingly
+grep -q 'X509_check_private_key:key values mismatch' log.txt || { echo "Key mismatch not detected"; exit 1; }
+
+# now look for the engine prints (these are under our control)
+grep -q 'ENGINE: engine_init called' log.txt || { echo "Engine initialization not detected"; exit 1; }
+grep -q 'ENGINE: engine_load_key called' log.txt || { echo "Key was not loaded from engine"; exit 1; }
+grep -q "ENGINE: engine_load_key got password ${password}" log.txt || { echo "Key password was not retrieved by the engine"; exit 1; }
+exit 0
tests/unit_tests/engine-key/libtestengine.c new file +102 -0

102 lines not on this page · raw message

tests/unit_tests/engine-key/openssl.cnf new file +12 -0
new file mode 100644
index 00000000..53200c46
@@ -0,0 +1,12 @@
+HOME		= .
+openssl_conf	= openssl_init
+
+[req]
+[openssl_init]
+engines		= engines_section
+
+[engines_section]
+testengine	= testengine_section
+
+[testengine_section]
+dynamic_path	= $ENV::srcdir/.libs/libtestengine.so
Signature · 1 line
2.12.3
#3 lore raw

Re: [Openvpn-devel] [PATCH v4 2/2] Add unit tests for engine keys

Am 10.02.18 um 23:50 schrieb James Bottomley:

Quoted 7 lines

Testing engines is problematic, so one of the prerequisites built for the tests is a simple openssl engine that reads a non-standard PEM guarded key. The test is simply can we run a client/server configuration with the usual sample key replaced by an engine key. The trivial engine prints out some operations and we check for these in the log to make sure the engine was used to load the key and that it correctly got the password.

This tests the openssl engine functionality in a sensible way. But I think it is not fully ready to be commited. To get it working I needed to do following changes on my Mac:

commit afa697cec15b4e54e720efe9de39c9b20b13c5c8 (HEAD -> review/enginekeys)

Author: Arne Schwabe <[email protected]...>
Date:   Thu Feb 13 18:13:34 2020 +0100

foo

(quoted diff) +0 -0

b/tests/unit_tests/engine-key/Makefile.am
index 73921965..6d7fc9c5 100644

tests/unit_tests/engine-key/Makefile.am +2 -1
@@ -10,4 +10,6 @@ TESTS_ENVIRONMENT = srcdir="$(abs_srcdir)"; \
 TESTS = check_engine_keys.sh
 
 libtestengine_la_SOURCES = libtestengine.c
-libtestengine_la_LDFLAGS = -rpath /lib -avoid-version
+libtestengine_la_LDFLAGS = @TEST_LDFLAGS@  -rpath /lib
+libtestengine_la_CFLAGS  = @TEST_CFLAGS@ -I$(openvpn_srcdir)

-I$(compat_srcdir)
+

(quoted diff) +0 -0

b/tests/unit_tests/engine-key/libtestengine.c
index fa7f5de1..46ec1e33 100644

tests/unit_tests/engine-key/libtestengine.c +0 -0
@@ -30,7 +30,6 @@ static EVP_PKEY *engine_load_key(ENGINE *e, const char

*key_id,

        PKCS8_PRIV_KEY_INFO *p8inf;
        UI *ui;
        char auth[256];

- int len;

        fprintf(stderr, "ENGINE: engine_load_key called\n");
(quoted diff) +0 -0

b/tests/unit_tests/engine-key/openssl.cnf
index 53200c46..e9513a92 100644

tests/unit_tests/engine-key/openssl.cnf +1 -1
@@ -9,4 +9,4 @@ engines         = engines_section
 testengine     = testengine_section
 
 [testengine_section]
-dynamic_path   = $ENV::srcdir/.libs/libtestengine.so
+dynamic_path   = $ENV::srcdir/.libs/libtestengine.dylib
#4 lore raw

Re: [Openvpn-devel] [PATCH v4 2/2] Add unit tests for engine keys

Quoted 9 lines · Arne Schwabe

Am 10.02.18 um 23:50 schrieb James Bottomley:

Quoted 7 lines

Testing engines is problematic, so one of the prerequisites built for the tests is a simple openssl engine that reads a non-standard PEM guarded key. The test is simply can we run a client/server configuration with the usual sample key replaced by an engine key. The trivial engine prints out some operations and we check for these in the log to make sure the engine was used to load the key and that it correctly got the password.

Quoted 3 lines

This tests the openssl engine functionality in a sensible way. But I think it is not fully ready to be commited. To get it working I needed to do following changes on my Mac:

That could be ... I only have a linux box to try this out on.

Quoted 29 lines

commit afa697cec15b4e54e720efe9de39c9b20b13c5c8 (HEAD -> review/enginekeys)

Author: Arne Schwabe <[email protected]...>
Date:   Thu Feb 13 18:13:34 2020 +0100

foo

tests/unit_tests/engine-key/Makefile.am +3 -2
index 73921965..6d7fc9c5 100644
@@ -10,4 +10,6 @@ TESTS_ENVIRONMENT = srcdir="$(abs_srcdir)"; \
 TESTS = check_engine_keys.sh
 
 libtestengine_la_SOURCES = libtestengine.c
-libtestengine_la_LDFLAGS = -rpath /lib -avoid-version
+libtestengine_la_LDFLAGS = @TEST_LDFLAGS@  -rpath /lib
+libtestengine_la_CFLAGS  = @TEST_CFLAGS@ -I$(openvpn_srcdir)
-I$(compat_srcdir)
+
tests/unit_tests/engine-key/libtestengine.c +0 -0
index fa7f5de1..46ec1e33 100644
@@ -30,7 +30,6 @@ static EVP_PKEY *engine_load_key(ENGINE *e, const

char
*key_id,

Quoted 4 lines
        PKCS8_PRIV_KEY_INFO *p8inf;
        UI *ui;
        char auth[256];

- int len;

the variable is certainly unused and can go.

tests/unit_tests/engine-key/openssl.cnf engines = engines_section · line 12

Quoted 13 lines
        fprintf(stderr, "ENGINE: engine_load_key called\n");
tests/unit_tests/engine-key/openssl.cnf +1 -1
index 53200c46..e9513a92 100644
@@ -9,4 +9,4 @@ engines         = engines_section
 testengine     = testengine_section
 
 [testengine_section]
-dynamic_path   = $ENV::srcdir/.libs/libtestengine.so
+dynamic_path   = $ENV::srcdir/.libs/libtestengine.dylib

This can't really be done though: the .dylib extension won't work on Linux because shared objects are .so files.

There is a way to generate and use .so files on a MAC as well, according to the openssl people (half the mac engines seem to have a .so extension and the other half a .dylib one), I'll see if I can figure out what it is.

James

#5 lore raw

Re: [Openvpn-devel] [PATCH v4 2/2] Add unit tests for engine keys

пт, 14 февр. 2020 г. в 18:05, James Bottomley <
[email protected]...>:

Quoted 62 lines · Arne Schwabe
Quoted 9 lines

Am 10.02.18 um 23:50 schrieb James Bottomley:

Quoted 7 lines

Testing engines is problematic, so one of the prerequisites built for the tests is a simple openssl engine that reads a non-standard PEM guarded key. The test is simply can we run a client/server configuration with the usual sample key replaced by an engine key. The trivial engine prints out some operations and we check for these in the log to make sure the engine was used to load the key and that it correctly got the password.

Quoted 3 lines

This tests the openssl engine functionality in a sensible way. But I think it is not fully ready to be commited. To get it working I needed to do following changes on my Mac:

That could be ... I only have a linux box to try this out on.

Quoted 29 lines

commit afa697cec15b4e54e720efe9de39c9b20b13c5c8 (HEAD -> review/enginekeys)

Author: Arne Schwabe <[email protected]...>
Date:   Thu Feb 13 18:13:34 2020 +0100

foo

tests/unit_tests/engine-key/Makefile.am +3 -2
index 73921965..6d7fc9c5 100644
@@ -10,4 +10,6 @@ TESTS_ENVIRONMENT = srcdir="$(abs_srcdir)"; \
 TESTS = check_engine_keys.sh
 
 libtestengine_la_SOURCES = libtestengine.c
-libtestengine_la_LDFLAGS = -rpath /lib -avoid-version
+libtestengine_la_LDFLAGS = @TEST_LDFLAGS@  -rpath /lib
+libtestengine_la_CFLAGS  = @TEST_CFLAGS@ -I$(openvpn_srcdir)
-I$(compat_srcdir)
+
tests/unit_tests/engine-key/libtestengine.c +0 -0
index fa7f5de1..46ec1e33 100644
@@ -30,7 +30,6 @@ static EVP_PKEY *engine_load_key(ENGINE *e, const

char
*key_id,

Quoted 4 lines
        PKCS8_PRIV_KEY_INFO *p8inf;
        UI *ui;
        char auth[256];

- int len;

the variable is certainly unused and can go.

Quoted 10 lines
        fprintf(stderr, "ENGINE: engine_load_key called\n");
tests/unit_tests/engine-key/openssl.cnf +0 -0
index 53200c46..e9513a92 100644
@@ -9,4 +9,4 @@ engines         = engines_section
 testengine     = testengine_section
 
Quoted 4 lines

tests/unit_tests/engine-key/openssl.cnf engines = engines_section · line 12

Quoted 3 lines
tests/unit_tests/engine-key/openssl.cnf +1 -1
 [testengine_section]
-dynamic_path   = $ENV::srcdir/.libs/libtestengine.so
+dynamic_path   = $ENV::srcdir/.libs/libtestengine.dylib

we use gost-engine (https://github.com/engine/gost-engine)

on both linux and osx.

for some time there was a bug in openssl:

https://github.com/openssl/openssl/issues/8950

however, for now "dylib" is used for osx. and but we do not use "dynamic" path. we use config like that

openssl_conf = openssl_def

[openssl_def]
engines = engine_section

[engine_section]
gost = gost_section

[gost_section]
default_algorithms = ALL
engine_id = gost
CRYPT_PARAMS = id-Gost28147-89-CryptoPro-A-ParamSet

Quoted 15 lines

This can't really be done though: the .dylib extension won't work on Linux because shared objects are .so files.

There is a way to generate and use .so files on a MAC as well, according to the openssl people (half the mac engines seem to have a .so extension and the other half a .dylib one), I'll see if I can figure out what it is.

James
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#6 lore raw

Re: [Openvpn-devel] [PATCH v4 2/2] Add unit tests for engine keys

Quoted 92 lines · Илья Шипицин

пт, 14 февр. 2020 г. в 18:05, James Bottomley <
[email protected]...>:

Quoted 68 lines · Arne Schwabe
Quoted 13 lines

Am 10.02.18 um 23:50 schrieb James Bottomley:

Quoted 11 lines

Testing engines is problematic, so one of the prerequisites built
for the tests is a simple openssl engine that reads a non- standard
PEM guarded key. The test is simply can we run a client/server configuration with the usual sample key replaced by an engine key.
The trivial engine prints out some operations and we check for these in the log to make sure the engine was used to load the key
and that it correctly got the password.

Quoted 4 lines

This tests the openssl engine functionality in a sensible way. But I
think it is not fully ready to be commited. To get it working I needed to do following changes on my Mac:

That could be ... I only have a linux box to try this out on.

Quoted 30 lines

commit afa697cec15b4e54e720efe9de39c9b20b13c5c8 (HEAD -> review/enginekeys)

Author: Arne Schwabe <[email protected]...>
Date:   Thu Feb 13 18:13:34 2020 +0100

foo

tests/unit_tests/engine-key/Makefile.am +3 -2
index 73921965..6d7fc9c5 100644
@@ -10,4 +10,6 @@ TESTS_ENVIRONMENT = srcdir="$(abs_srcdir)"; \
 TESTS = check_engine_keys.sh
 
 libtestengine_la_SOURCES = libtestengine.c
-libtestengine_la_LDFLAGS = -rpath /lib -avoid-version
+libtestengine_la_LDFLAGS = @TEST_LDFLAGS@  -rpath /lib
+libtestengine_la_CFLAGS  = @TEST_CFLAGS@ -I$(openvpn_srcdir)
-I$(compat_srcdir)
+
tests/unit_tests/engine-key/libtestengine.c +0 -0
index fa7f5de1..46ec1e33 100644
@@ -30,7 +30,6 @@ static EVP_PKEY *engine_load_key(ENGINE *e,

const
char
*key_id,

Quoted 4 lines
        PKCS8_PRIV_KEY_INFO *p8inf;
        UI *ui;
        char auth[256];

- int len;

the variable is certainly unused and can go.

Quoted 10 lines
        fprintf(stderr, "ENGINE: engine_load_key called\n");
tests/unit_tests/engine-key/openssl.cnf +0 -0
index 53200c46..e9513a92 100644
@@ -9,4 +9,4 @@ engines         = engines_section
 testengine     = testengine_section
 
Quoted 3 lines

tests/unit_tests/engine-key/openssl.cnf engines = engines_section · line 12

Quoted 3 lines
tests/unit_tests/engine-key/openssl.cnf +1 -1
 [testengine_section]
-dynamic_path   = $ENV::srcdir/.libs/libtestengine.so
+dynamic_path   = $ENV::srcdir/.libs/libtestengine.dylib

we use gost-engine (https://github.com/engine/gost-engine)

on both linux and osx.

for some time there was a bug in openssl:

https://github.com/openssl/openssl/issues/8950

however, for now "dylib" is used for osx. and but we do not use "dynamic" path. we use config like that

openssl_conf = openssl_def

[openssl_def]
engines = engine_section

Quoted 7 lines

[engine_section]
gost = gost_section

[gost_section]
default_algorithms = ALL
engine_id = gost
CRYPT_PARAMS = id-Gost28147-89-CryptoPro-A-ParamSet

Right, that works if the engine is in the correct directory. The problem with this engine is that it's only built as a test demonstration for the openvpn engine code, so it's never installed in the openssl engines directory, so we have to tell openssl exactly where to find it in the openvpn tree ... and that seems to involve naming the whole file and location, including extension.

James

#7 lore raw

Re: [Openvpn-devel] [PATCH v4 2/2] Add unit tests for engine keys

сб, 15 февр. 2020 г. в 19:59, James Bottomley <
[email protected]...>:

Quoted 101 lines · Илья Шипицин
Quoted 92 lines

пт, 14 февр. 2020 г. в 18:05, James Bottomley <
[email protected]...>:

Quoted 68 lines · Arne Schwabe
Quoted 13 lines

Am 10.02.18 um 23:50 schrieb James Bottomley:

Quoted 11 lines

Testing engines is problematic, so one of the prerequisites built
for the tests is a simple openssl engine that reads a non- standard
PEM guarded key. The test is simply can we run a client/server configuration with the usual sample key replaced by an engine key.
The trivial engine prints out some operations and we check for these in the log to make sure the engine was used to load the key
and that it correctly got the password.

Quoted 4 lines

This tests the openssl engine functionality in a sensible way. But I
think it is not fully ready to be commited. To get it working I needed to do following changes on my Mac:

That could be ... I only have a linux box to try this out on.

Quoted 30 lines

commit afa697cec15b4e54e720efe9de39c9b20b13c5c8 (HEAD -> review/enginekeys)

Author: Arne Schwabe <[email protected]...>
Date:   Thu Feb 13 18:13:34 2020 +0100

foo

tests/unit_tests/engine-key/Makefile.am +3 -2
index 73921965..6d7fc9c5 100644
@@ -10,4 +10,6 @@ TESTS_ENVIRONMENT = srcdir="$(abs_srcdir)"; \
 TESTS = check_engine_keys.sh
 
 libtestengine_la_SOURCES = libtestengine.c
-libtestengine_la_LDFLAGS = -rpath /lib -avoid-version
+libtestengine_la_LDFLAGS = @TEST_LDFLAGS@  -rpath /lib
+libtestengine_la_CFLAGS  = @TEST_CFLAGS@ -I$(openvpn_srcdir)
-I$(compat_srcdir)
+
tests/unit_tests/engine-key/libtestengine.c +0 -0
index fa7f5de1..46ec1e33 100644
@@ -30,7 +30,6 @@ static EVP_PKEY *engine_load_key(ENGINE *e,

const
char
*key_id,

Quoted 4 lines
        PKCS8_PRIV_KEY_INFO *p8inf;
        UI *ui;
        char auth[256];

- int len;

the variable is certainly unused and can go.

Quoted 10 lines
        fprintf(stderr, "ENGINE: engine_load_key called\n");
tests/unit_tests/engine-key/openssl.cnf +0 -0
index 53200c46..e9513a92 100644
@@ -9,4 +9,4 @@ engines         = engines_section
 testengine     = testengine_section
 
Quoted 3 lines

tests/unit_tests/engine-key/openssl.cnf engines = engines_section · line 12

Quoted 3 lines
tests/unit_tests/engine-key/openssl.cnf +1 -1
 [testengine_section]
-dynamic_path   = $ENV::srcdir/.libs/libtestengine.so
+dynamic_path   = $ENV::srcdir/.libs/libtestengine.dylib

we use gost-engine (https://github.com/engine/gost-engine)

on both linux and osx.

for some time there was a bug in openssl:

https://github.com/openssl/openssl/issues/8950

however, for now "dylib" is used for osx. and but we do not use "dynamic" path. we use config like that

openssl_conf = openssl_def

[openssl_def]
engines = engine_section

Quoted 7 lines

[engine_section]
gost = gost_section

[gost_section]
default_algorithms = ALL
engine_id = gost
CRYPT_PARAMS = id-Gost28147-89-CryptoPro-A-ParamSet

Quoted 8 lines

Right, that works if the engine is in the correct directory. The problem with this engine is that it's only built as a test demonstration for the openvpn engine code, so it's never installed in the openssl engines directory, so we have to tell openssl exactly where to find it in the openvpn tree ... and that seems to involve naming the whole file and location, including extension.

yes, I understand reasoning.
maybe we should add dynamic path to our tests as well.

Quoted 3 lines

James