From: "cron2 (Code Review)" Date: Wed, 18 Oct 2023 15:10:34 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="+vCN4jAISxo="; charset=UTF-8 Subject: [Openvpn-devel] [L] Change in openvpn[master]: Remove openssl engine method for loading the key List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --+vCN4jAISxo= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#3) to the change originally created by= plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/373?usp=3Demail ) Change subject: Remove openssl engine method for loading the key ...................................................................... Remove openssl engine method for loading the key This is a contribution for loading engine key. OpenSSL engine is deprecated since OpenSSL 3.0 and James Bottomley has not agreed to the proposed license chagne. He is also okay with removing the feature from the current code base as it is obsolete with OpenSSL 3.0. The original commit ID was a0a8d801dd0d84e0ec844b9ca4c225df7 (plus subsequent fixes). Change-Id: I2d353a0cea0a62f289b8c1060244df66dd7a14cb Signed-off-by: Arne Schwabe Message-Id: <20231006111910.3541180-1-arne@...1227...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg27= 133.html Signed-off-by: Gert Doering --- M .gitignore M configure.ac M src/openvpn/crypto_openssl.c M src/openvpn/crypto_openssl.h M src/openvpn/ssl_openssl.c M tests/unit_tests/Makefile.am D tests/unit_tests/engine-key/Makefile.am D tests/unit_tests/engine-key/check_engine_keys.sh D tests/unit_tests/engine-key/libtestengine.c D tests/unit_tests/engine-key/openssl.cnf.in 10 files changed, 0 insertions(+), 279 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/73/373/3 diff --git a/.gitignore b/.gitignore index ed03aaa..a1da366 100644 --- a/.gitignore +++ b/.gitignore @@ -57,10 +57,6 @@ t_client.rc t_client_ips.rc tests/unit_tests/**/*_testdriver -tests/unit_tests/engine-key/client.key -tests/unit_tests/engine-key/log.txt -tests/unit_tests/engine-key/openssl.cnf -tests/unit_tests/engine-key/passwd src/openvpn/openvpn include/openvpn-plugin.h diff --git a/configure.ac b/configure.ac index 266b66f..128ab86 100644 --- a/configure.ac +++ b/configure.ac @@ -1532,7 +1532,6 @@ tests/unit_tests/openvpn/Makefile tests/unit_tests/plugins/Makefile tests/unit_tests/plugins/auth-pam/Makefile - tests/unit_tests/engine-key/Makefile sample/Makefile ]) AC_CONFIG_FILES([tests/t_client.sh], [chmod +x tests/t_client.sh]) diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c index 22c6d68..fe1254f 100644 --- a/src/openvpn/crypto_openssl.c +++ b/src/openvpn/crypto_openssl.c @@ -1374,66 +1374,6 @@ return CRYPTO_memcmp(a, b, size); } -#if HAVE_OPENSSL_ENGINE -static int -ui_reader(UI *ui, UI_STRING *uis) -{ - SSL_CTX *ctx =3D UI_get0_user_data(ui); - - if (UI_get_string_type(uis) =3D=3D UIT_PROMPT) - { - pem_password_cb *cb =3D SSL_CTX_get_default_passwd_cb(ctx); - void *d =3D 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 l= oad private key"); - - ui =3D UI_create_method("openvpn"); - if (!ui) - { - crypto_msg(M_FATAL, "Engine UI creation failed"); - return NULL; - } - - UI_method_set_reader(ui, ui_reader); - - ENGINE_init(engine_persist); - pkey =3D ENGINE_load_private_key(engine_persist, file, ui, ctx); - ENGINE_finish(engine_persist); - if (!pkey) - { - crypto_msg(M_FATAL, "Engine could not load key file"); - } - - UI_destroy_method(ui); - return pkey; -#else /* if HAVE_OPENSSL_ENGINE */ - return NULL; -#endif /* if HAVE_OPENSSL_ENGINE */ -} - #if (OPENSSL_VERSION_NUMBER >=3D 0x10100000L) && !defined(LIBRESSL_VERSION= _NUMBER) bool ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *secret, diff --git a/src/openvpn/crypto_openssl.h b/src/openvpn/crypto_openssl.h index 32849fd..c5a5393 100644 --- a/src/openvpn/crypto_openssl.h +++ b/src/openvpn/crypto_openssl.h @@ -118,16 +118,4 @@ 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_ */ diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c index 4c08add..23e7623 100644 --- a/src/openvpn/ssl_openssl.c +++ b/src/openvpn/ssl_openssl.c @@ -1057,10 +1057,6 @@ pkey =3D PEM_read_bio_PrivateKey(in, NULL, SSL_CTX_get_default_passwd_cb(ctx->ctx), SSL_CTX_get_default_passwd_cb_userdata(= ctx->ctx)); - if (!pkey) - { - pkey =3D engine_load_key(priv_key_file, ctx->ctx); - } if (!pkey || !SSL_CTX_use_PrivateKey(ssl_ctx, pkey)) { diff --git a/tests/unit_tests/Makefile.am b/tests/unit_tests/Makefile.am index f27cd90..33fefaa 100644 --- a/tests/unit_tests/Makefile.am +++ b/tests/unit_tests/Makefile.am @@ -2,7 +2,4 @@ if ENABLE_UNITTESTS SUBDIRS =3D example_test openvpn plugins -if OPENSSL_ENGINE -SUBDIRS +=3D engine-key -endif endif diff --git a/tests/unit_tests/engine-key/Makefile.am b/tests/unit_tests/eng= ine-key/Makefile.am deleted file mode 100644 index 0c28885..0000000 --- a/tests/unit_tests/engine-key/Makefile.am +++ /dev/null @@ -1,31 +0,0 @@ -AUTOMAKE_OPTIONS =3D foreign - -check_LTLIBRARIES =3D libtestengine.la -conffiles =3D openssl.cnf -EXTRA_DIST =3D \ - openssl.cnf.in \ - check_engine_keys.sh - -TESTS_ENVIRONMENT =3D srcdir=3D"$(abs_srcdir)"; \ - builddir=3D"$(abs_builddir)"; \ - top_builddir=3D"$(top_builddir)"; \ - top_srcdir=3D"$(top_srcdir)"; \ - export srcdir builddir top_builddir top_srcdir; - -if !CROSS_COMPILING -TESTS =3D check_engine_keys.sh -endif -check_engine_keys.sh: $(conffiles) - -CLEANFILES =3D \ - client.key \ - passwd \ - log.txt \ - $(conffiles) - -openssl.cnf: $(srcdir)/openssl.cnf.in - sed "s|ABSBUILDDIR|$(abs_builddir)|" < $(srcdir)/openssl.cnf.in > $@ - -libtestengine_la_SOURCES =3D libtestengine.c -libtestengine_la_LDFLAGS =3D @TEST_LDFLAGS@ -rpath /lib -shrext .so -libtestengine_la_CFLAGS =3D @TEST_CFLAGS@ -I$(openvpn_srcdir) -I$(compat_s= rcdir) diff --git a/tests/unit_tests/engine-key/check_engine_keys.sh b/tests/unit_= tests/engine-key/check_engine_keys.sh deleted file mode 100755 index 12dd230..0000000 --- a/tests/unit_tests/engine-key/check_engine_keys.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh - -OPENSSL_CONF=3D"${builddir}/openssl.cnf" -export OPENSSL_CONF - -password=3D'AT3S4PASSWD' - -key=3D"${builddir}/client.key" -pwdfile=3D"${builddir}/passwd" - -# create an engine key for us -sed 's/PRIVATE KEY/TEST ENGINE KEY/' < ${top_srcdir}/sample/sample-keys/cl= ient.key > ${key} -echo "$password" > $pwdfile - -# our version of grep to output log.txt on failure in case it's an openssl -# error mismatch and the grep expression needs updating -loggrep() { - egrep -q "$1" log.txt || { echo '---- begin log.txt ----'; cat log.txt= ; echo '--- end log.txt ---'; return 1; } -} - -# 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 sam= ple-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 -loggrep '(x509 certificate routines:(X509_check_private_key)?:key values m= ismatch|func\(128\):reason\(116\))' log.txt || { echo "Key mismatch not det= ected"; exit 1; } - -# now look for the engine prints (these are under our control) -loggrep 'ENGINE: engine_init called' || { echo "Engine initialization not = detected"; exit 1; } -loggrep 'ENGINE: engine_load_key called' || { echo "Key was not loaded fro= m engine"; exit 1; } -loggrep "ENGINE: engine_load_key got password ${password}" || { echo "Key = password was not retrieved by the engine"; exit 1; } -exit 0 diff --git a/tests/unit_tests/engine-key/libtestengine.c b/tests/unit_tests= /engine-key/libtestengine.c deleted file mode 100644 index 8bcfa92..0000000 --- a/tests/unit_tests/engine-key/libtestengine.c +++ /dev/null @@ -1,116 +0,0 @@ -#include -#include -#include -#include - -static char *engine_id =3D "testengine"; -static char *engine_name =3D "Engine for testing openvpn engine key suppor= t"; - -static int is_initialized =3D 0; - -static int -engine_init(ENGINE *e) -{ - is_initialized =3D 1; - fprintf(stderr, "ENGINE: engine_init called\n"); - return 1; -} - -static int -engine_finish(ENGINE *e) -{ - fprintf(stderr, "ENGINE: engine_finsh called\n"); - is_initialized =3D 0; - return 1; -} - -static EVP_PKEY * -engine_load_key(ENGINE *e, const char *key_id, - UI_METHOD *ui_method, void *cb_data) -{ - BIO *b; - EVP_PKEY *pkey; - PKCS8_PRIV_KEY_INFO *p8inf; - UI *ui; - char auth[256]; - - fprintf(stderr, "ENGINE: engine_load_key called\n"); - - if (!is_initialized) - { - fprintf(stderr, "Load Key called without correct initialization\n"= ); - return NULL; - } - b =3D BIO_new_file(key_id, "r"); - if (!b) - { - fprintf(stderr, "File %s does not exist or cannot be read\n", key_= id); - return 0; - } - /* Basically read an EVP_PKEY private key file with different - * PEM guards --- we are a test engine */ - p8inf =3D PEM_ASN1_read_bio((d2i_of_void *)d2i_PKCS8_PRIV_KEY_INFO, - "TEST ENGINE KEY", b, - NULL, NULL, NULL); - BIO_free(b); - if (!p8inf) - { - fprintf(stderr, "Failed to read engine private key\n"); - return NULL; - } - pkey =3D EVP_PKCS82PKEY(p8inf); - - /* now we have a private key, pretend it had a password - * this verifies the password makes it through openvpn OK */ - ui =3D UI_new(); - - if (ui_method) - { - UI_set_method(ui, ui_method); - } - - UI_add_user_data(ui, cb_data); - - if (UI_add_input_string(ui, "enter test engine key", - UI_INPUT_FLAG_DEFAULT_PWD, - auth, 0, sizeof(auth)) =3D=3D 0) - { - fprintf(stderr, "UI_add_input_string failed\n"); - goto out; - } - - if (UI_process(ui)) - { - fprintf(stderr, "UI_process failed\n"); - goto out; - } - - fprintf(stderr, "ENGINE: engine_load_key got password %s\n", auth); - -out: - UI_free(ui); - - return pkey; -} - - -static int -engine_bind_fn(ENGINE *e, const char *id) -{ - if (id && strcmp(id, engine_id) !=3D 0) - { - return 0; - } - if (!ENGINE_set_id(e, engine_id) - || !ENGINE_set_name(e, engine_name) - || !ENGINE_set_init_function(e, engine_init) - || !ENGINE_set_finish_function(e, engine_finish) - || !ENGINE_set_load_privkey_function(e, engine_load_key)) - { - return 0; - } - return 1; -} - -IMPLEMENT_DYNAMIC_CHECK_FN() -IMPLEMENT_DYNAMIC_BIND_FN(engine_bind_fn) diff --git a/tests/unit_tests/engine-key/openssl.cnf.in b/tests/unit_tests/= engine-key/openssl.cnf.in deleted file mode 100644 index 5eda9fa..0000000 --- a/tests/unit_tests/engine-key/openssl.cnf.in +++ /dev/null @@ -1,12 +0,0 @@ -HOME =3D . -openssl_conf =3D openssl_init - -[req] -[openssl_init] -engines =3D engines_section - -[engines_section] -testengine =3D testengine_section - -[testengine_section] -dynamic_path =3D ABSBUILDDIR/.libs/libtestengine.so -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/373?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I2d353a0cea0a62f289b8c1060244df66dd7a14cb Gerrit-Change-Number: 373 Gerrit-PatchSet: 3 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --+vCN4jAISxo= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #3 to the change originally cr= eated by plaisthos.

View Change

Remove openssl engine method for loading t=
he key

This is a contribution for loading engine key. OpenSSL engine= is
deprecated since OpenSSL 3.0 and James Bottomley has not agreed tothe proposed license chagne. He is also okay with removing the
feature= from the current code base as it is obsolete with OpenSSL 3.0.

The = original commit ID was a0a8d801dd0d84e0ec844b9ca4c225df7 (plus
subsequen= t fixes).

Change-Id: I2d353a0cea0a62f289b8c1060244df66dd7a14cb
Si= gned-off-by: Arne Schwabe <arne@...1227...>
Message-Id: <202310= 06111910.3541180-1-arne@...1227...>
URL: https://www.mail-archive.com= /openvpn-devel@lists.sourceforge.net/msg27133.html
Signed-off-by: Gert D= oering <gert@...1296...>
---
M .gitignore
M configure.ac
= M src/openvpn/crypto_openssl.c
M src/openvpn/crypto_openssl.h
M src/o= penvpn/ssl_openssl.c
M tests/unit_tests/Makefile.am
D tests/unit_test= s/engine-key/Makefile.am
D tests/unit_tests/engine-key/check_engine_keys= .sh
D tests/unit_tests/engine-key/libtestengine.c
D tests/unit_tests/= engine-key/openssl.cnf.in
10 files changed, 0 insertions(+), 279 deletio= ns(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/change=
s/73/373/3
diff --git a/.gitignore b/.gitignore
ind= ex ed03aaa..a1da366 100644
--- a/.gitignore
+++ b/.gitignore
@@ -57,10 +57,6 @@
t_cli= ent.rc
t_client_ips.rc
tests/unit_tests/*= */*_testdriver
-tests/u= nit_tests/engine-key/client.key
-tests/unit_tests/engine-key/log.txt
-tests/unit_tests/engine-key/openssl.cnf
<= span style=3D"color: hsl(0, 100%, 40%);">-tests/unit_tests/engine-key/passw= d

src/openvpn/openvpn
i= nclude/openvpn-plugin.h
diff --git a/configure.ac b/configu= re.ac
index 266b66f..128ab86 100644
--- a/c= onfigure.ac
+++ b/configure.ac
@@ -1532,7 += 1532,6 @@
tests/unit_tests/openvpn/Makefile=
tests/unit_tests/plugins/Makefile
= tests/unit_tests/plugins/auth-pam/Makefile
- tests/unit_tests/engine-key/Makefile
sample/Makefile
])
AC_CONFIG_FILES([= tests/t_client.sh], [chmod +x tests/t_client.sh])
diff --gi= t a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c
<= span>index 22c6d68..fe1254f 100644
--- a/src/openvpn/crypto= _openssl.c
+++ b/src/openvpn/crypto_openssl.c
@@ -1374,66 +1374,6 @@
return CRYPTO_memcmp(a, b, s= ize);
}

-#if HAVE_OPENSSL_ENGINE
-static int
-ui_reader(UI *ui, UI_STRING *uis)
-{
- SSL_CTX *ctx =3D UI_get0_user_data(ui);
-
- if (UI_get_string_type(uis) =3D=3D UIT_PROMPT)
- {
- pem_password_cb *cb =3D SSL_CTX_get_default_passw= d_cb(ctx);
- voi= d *d =3D SSL_CTX_get_default_passwd_cb_userdata(ctx);
- char password[64];
-
- cb(password, sizeof(password), 0, d);
- UI_set_result(ui, uis, pass= word);
-
- 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;
-
- {
- re= turn NULL;
- }

-
- /* this will print out the error from BIO_re= ad */
- crypto_msg(M= _INFO, "PEM_read_bio failed, now trying engine method to load private = key");
-- ui =3D UI_create_method(&qu= ot;openvpn");
- = if (!ui)
- {=
- crypto_msg(M_FATAL, = "Engine UI creation failed");
- return NULL;
- }
= -
- UI_method_set_re= ader(ui, ui_reader);
-<= /span>
- ENGINE_init(engine= _persist);
- pkey = =3D ENGINE_load_private_key(engine_persist, file, ui, ctx);
- ENGINE_finish(engine_persist);
- if (!pkey)- {
- crypto_msg(M_FATAL, "Engine could = not load key file");
- }
-
<= span style=3D"color: hsl(0, 100%, 40%);">- UI_destroy_method(ui);
=
- return pkey;
<= span style=3D"color: hsl(0, 100%, 40%);">-#else /* if HAVE_OPENSSL_ENGINE = */
- return NULL;
-#endif /* if HAVE_OPENSS= L_ENGINE */
-}-
#if (OPENSSL= _VERSION_NUMBER >=3D 0x10100000L) && !defined(LIBRESSL_VERSION_N= UMBER)
bool
ssl_tls1_PRF(const uint8_t *s= eed, int seed_len, const uint8_t *secret,
diff --git a/src/= openvpn/crypto_openssl.h b/src/openvpn/crypto_openssl.h
ind= ex 32849fd..c5a5393 100644
--- a/src/openvpn/crypto_openssl= .h
+++ b/src/openvpn/crypto_openssl.h
@@ -1= 18,16 +118,4 @@
msg((flags), __VA_ARGS__); \
} while (false)

-/**
- * Load a key file from an engine
- *
- * @param ui The UI method for the password prompt<= /span>
- * @param data The da= ta to pass to the UI method
- *
- * @return = The private key if successful or NULL if not
- */
-EVP_PKEY *
-eng= ine_load_key(const char *file, SSL_CTX *ctx);
-
#endif /* CRYPTO_OPENSSL_H_ */
diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_open= ssl.c
index 4c08add..23e7623 100644
--- a/s= rc/openvpn/ssl_openssl.c
+++ b/src/openvpn/ssl_openssl.c
@@ -1057,10 +1057,6 @@
pkey =3D PEM_read= _bio_PrivateKey(in, NULL,
= SSL_CTX_get_default_passwd_cb(ctx->ctx),
= SSL_CTX_get_default_passwd_cb_userdata(ctx->ctx)= );
- if (!pkey)
- {
- pkey =3D engine_load_key(priv_key_= file, ctx->ctx);
- = }

if (!pkey || !SSL_CTX_use_Privat= eKey(ssl_ctx, pkey))
{
diff --git a/te= sts/unit_tests/Makefile.am b/tests/unit_tests/Makefile.am
i= ndex f27cd90..33fefaa 100644
--- a/tests/unit_tests/Makefil= e.am
+++ b/tests/unit_tests/Makefile.am
@@ = -2,7 +2,4 @@

if ENABLE_UNITTESTS<= br> SUBDIRS =3D example_test openvpn plugins
-if OPENSSL_ENGINE
-SUBDIRS +=3D engine-key
-endif
endif
dif= f --git a/tests/unit_tests/engine-key/Makefile.am b/tests/unit_tests/engine= -key/Makefile.am
deleted file mode 100644
i= ndex 0c28885..0000000
--- a/tests/unit_tests/engine-key/Mak= efile.am
+++ /dev/null
@@ -1,31 +0,0 @@
-AUTOMAKE_OPTIONS =3D fore= ign
-
-check_LTLIBRARIES =3D libtestengine.la<= /span>
-conffiles =3D openssl.= cnf
-EXTRA_DIST =3D \
- openssl.cnf.in \
- check_engine_keys.sh
-
-TESTS_ENVIRONMENT =3D srcdir=3D"$(abs_srcdi= r)"; \
- builddir= =3D"$(abs_builddir)"; \
- top_builddir=3D"$(top_builddir)"; \
- top_srcdir=3D"$(top_srcdir)"= ;; \
- export srcdir bu= ilddir top_builddir top_srcdir;
-
-if !CROSS_C= OMPILING
-TESTS =3D che= ck_engine_keys.sh
-endi= f
-check_engine_keys.sh= : $(conffiles)
-=
-CLEANFILES =3D \
<= span style=3D"color: hsl(0, 100%, 40%);">- client.key \

- passwd \
- log.txt \
- $(conffiles)
-openssl.cnf: $(src= dir)/openssl.cnf.in
- s= ed "s|ABSBUILDDIR|$(abs_builddir)|" < $(srcdir)/openssl.cnf.in= > $@
-
-libtestengine_la_SOURCES =3D libte= stengine.c

-libtestengi= ne_la_LDFLAGS =3D @TEST_LDFLAGS@ -rpath /lib -shrext .so
-libtestengine_la_CFLAGS =3D @TEST_CFLAGS= @ -I$(openvpn_srcdir) -I$(compat_srcdir)
diff --git a/tests= /unit_tests/engine-key/check_engine_keys.sh b/tests/unit_tests/engine-key/c= heck_engine_keys.sh
deleted file mode 100755
index 12dd230..0000000

--- a/tests/unit_tests/engine-key/= check_engine_keys.sh
+++ /dev/null
@@ -1,36= +0,0 @@
-#!/bin/sh
-
-OPENSSL_CONF=3D"${builddir}/openssl.cnf&q= uot;
-export OPENSSL_CO= NF
-
-password=3D'AT3S4PASSWD'<= br>-
-key=3D"${builddir}/client.key"-pwdfile=3D"${builddir}/pas= swd"
-
<= span style=3D"color: hsl(0, 100%, 40%);">-# create an engine key for us
-sed 's/PRIVATE KEY/TE= ST ENGINE KEY/' < ${top_srcdir}/sample/sample-keys/client.key > $= {key}
-echo "$pass= word" > $pwdfile
-# our version of g= rep to output log.txt on failure in case it's an openssl
-# error mismatch and the grep expres= sion needs updating

-lo= ggrep() {
- egrep -q= "$1" log.txt || { echo '---- begin log.txt ----'; cat lo= g.txt; echo '--- end log.txt ---'; return 1; }
-}
-
-# note h= ere we've induced a mismatch in the client key and the server-# cert which openvpn should rep= ort and die. Check that it does. Note
-# also that this mismatch depends on openssl not openvpn,= so it is
-# somewhat f= ragile
-${top_builddir}= /src/openvpn/openvpn --cd ${top_srcdir}/sample --config sample-config-files= /loopback-server --engine testengine --key ${key} --askpass $pwdfile > l= og.txt 2>&1
-
-# first off check we die= d because of a key mismatch. If this doesn't
-# pass, suspect openssl of returning different = messages and update the
-# test accordingly
-l= oggrep '(x509 certificate routines:(X509_check_private_key)?:key values= mismatch|func\(128\):reason\(116\))' log.txt || { echo "Key misma= tch not detected"; exit 1; }
-
-# now loo= k for the engine prints (these are under our control)
-loggrep 'ENGINE: engine_init called'= ; || { echo "Engine initialization not detected"; exit 1; }
-loggrep 'ENGINE: engine= _load_key called' || { echo "Key was not loaded from engine";= exit 1; }
-loggrep &qu= ot;ENGINE: engine_load_key got password ${password}" || { echo "K= ey password was not retrieved by the engine"; exit 1; }
-exit 0

diff --git a/= tests/unit_tests/engine-key/libtestengine.c b/tests/unit_tests/engine-key/l= ibtestengine.c
deleted file mode 100644
ind= ex 8bcfa92..0000000
--- a/tests/unit_tests/engine-key/libte= stengine.c
+++ /dev/null
@@ -1,116 +0,0 @@<= /span>
-#include <string.h&= gt;
-#include <opens= sl/engine.h>
-#inclu= de <openssl/evp.h>
-
-static ch= ar *engine_id =3D "testengine";
-static char *engine_name =3D "Engine for testing o= penvpn engine key support";
-
-static int= is_initialized =3D 0;
= -
-static int-engine_init(ENGINE *e)-{
- is_initialized =3D 1;
- fprintf(stderr, "ENGINE: engine_init = called\n");
- r= eturn 1;
-}
<= span style=3D"color: hsl(0, 100%, 40%);">-

-static int
-engine_finish(ENGINE *e)
-{
- fpr= intf(stderr, "ENGINE: engine_finsh called\n");
- is_initialized =3D 0;
- return 1;

-}
-
-static EV= P_PKEY *
-engine_load_k= ey(ENGINE *e, const char *key_id,
- UI_METHOD *ui_method, void *cb_data)
= -{
- BIO *b;
- EVP_PKEY *pkey;
- PKCS8_PRIV_KEY_INFO *p8inf;
- UI *ui;
- char auth[256];
-
- fprintf(= stderr, "ENGINE: engine_load_key called\n");
-
- if (!is_initialized)
- {
- = fprintf(stderr, "Load Key called without correct initialization= \n");
- ret= urn NULL;
- }=
- b =3D BIO_new_file(key_i= d, "r");
- = if (!b)
- {<= br>- fprintf(stderr, "= ;File %s does not exist or cannot be read\n", key_id);
- return 0;

- }
- /* Basically read an EVP_PKEY private key file with d= ifferent
- * PEM gu= ards --- we are a test engine */
- p8inf =3D PEM_ASN1_read_bio((d2i_of_void *)d2i_PKCS8_PRIV_KE= Y_INFO,
- = "TEST ENGINE KEY", b,
- NULL, NULL, NULL);<= /span>
- BIO_free(b);
- if (!p8inf)
<= span style=3D"color: hsl(0, 100%, 40%);">- {

- fprintf(stderr, "Failed to read engi= ne private key\n");
- }
- pkey =3D E= VP_PKCS82PKEY(p8inf);
-=
- /* now we have a = private key, pretend it had a password
- * this verifies the password makes it through openvpn= OK */
- ui =3D UI_n= ew();
-
- if (ui_method)

- {
- UI_set_method(ui, ui_method);
- }
-
- = UI_add_user_data(ui, cb_data);
-
- if (UI= _add_input_string(ui, "enter test engine key",
- UI_INPUT_FLA= G_DEFAULT_PWD,
- = auth, 0, sizeof(auth)) =3D=3D 0)
- {
- fprintf(stderr, "UI_add_input_string failed\n&= quot;);
- goto o= ut;
- }
-

- if (UI_process(ui))
- {
- fprintf(stderr, "UI_process failed\n");
<= span style=3D"color: hsl(0, 100%, 40%);">- goto out;

- }

-
= - fprintf(stderr, "ENGINE: engine_load_key got password %s\n",= auth);
-
-out:

- UI_free(ui);
-
- = return pkey;
-}=
-
-
-static int
-engine= _bind_fn(ENGINE *e, const char *id)
-{
- if= (id && strcmp(id, engine_id) !=3D 0)
- {
- return 0;
- }
- if (!ENG= INE_set_id(e, engine_id)
- || !ENGINE_set_init_function(e, engine_ini= t)
- || !ENGINE_= set_finish_function(e, engine_finish)
- || !ENGINE_set_load_privkey_function(e, engine_load= _key))
- {- return 0;
- }

- return 1;
-}
-
-IMPLEMENT_DYNAMIC_CHECK_F= N()
-IMPLEMENT_DYNAMIC_= BIND_FN(engine_bind_fn)
diff --git a/tests/unit_tests/engin= e-key/openssl.cnf.in b/tests/unit_tests/engine-key/openssl.cnf.indeleted file mode 100644
index 5eda9fa..0000000
--- a/tests/unit_tests/engine-key/openssl.cnf.in
+++ /dev/null

@@ -1,12 +0,0 @@
-HOME =3D .
-openssl_conf =3D openssl_init
-
-[req]
-[openssl_ini= t]
-engines =3D engine= s_section
-
<= span style=3D"color: hsl(0, 100%, 40%);">-[engines_section]

-testengine =3D testengine_section
-
-[testengine_section]
-dynamic_path =3D ABSBUILDDIR/.libs/libtestengin= e.so

To view, visit change 373. To unsubscri= be, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2d353a0cea0a62f289b8c106024= 4df66dd7a14cb
Gerrit-Change-Number: 373
Gerrit-PatchSet: 3
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--+vCN4jAISxo=--