From: "cron2 (Code Review)" Date: Mon, 22 Dec 2025 21:47:41 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., max@...2606... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="rI0MSPyeQ8o="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Allow test-crypto to work without the --secret argument List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld , MaxF Cc: openvpn-devel --rI0MSPyeQ8o= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#8) to the change originally created by= plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/1435?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by flichtenheld Change subject: Allow test-crypto to work without the --secret argument ...................................................................... Allow test-crypto to work without the --secret argument The --test-crypto still requires the --secret argument. Since --secret will be removed in OpenVPN 2.8 but we want to keep test-crypt, remove the dependency of test-crypto on --static. Instead we will just generate a random key for this selftest method. This also removes the extra logic that is a leftover from the early multi-thread implementation attempt. Change-Id: I72947bd4f0213fd118327f740daeb1d86ae166de Signed-off-by: Arne Schwabe Acked-by: Frank Lichtenheld Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1435 Message-Id: <20251219135110.166468-1-frank@...2641...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg35= 157.html Signed-off-by: Gert Doering --- M Changes.rst M doc/man-sections/generic-options.rst M src/openvpn/crypto.c M src/openvpn/crypto.h M src/openvpn/init.c M src/openvpn/init.h M src/openvpn/openvpn.c M src/openvpn/options.c M tests/t_lpback.sh 9 files changed, 70 insertions(+), 39 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/35/1435/8 diff --git a/Changes.rst b/Changes.rst index 048434d..c8a3058 100644 --- a/Changes.rst +++ b/Changes.rst @@ -343,6 +343,10 @@ loading for key/cert files with non-ASCII characters in their file names (GH: OpenVPN/openvpn#920). +- The ``test-crypto`` option no longer requires a ``--secret`` argument and + will automatically generate a random key. + + Deprecated features ------------------- ``--opt-verify`` feature removed diff --git a/doc/man-sections/generic-options.rst b/doc/man-sections/generi= c-options.rst index a9232ce..ed581b1 100644 --- a/doc/man-sections/generic-options.rst +++ b/doc/man-sections/generic-options.rst @@ -427,13 +427,13 @@ The typical usage of ``--test-crypto`` would be something like this: :: - openvpn --test-crypto --secret key + openvpn --test-crypto or :: - openvpn --test-crypto --secret key --verb 9 + openvpn --test-crypto --verb 9 This option is very useful to test OpenVPN after it has been ported to a new platform, or to isolate problems in the compiler, OpenSSL crypto @@ -441,6 +441,10 @@ problems with encryption and authentication can be debugged independently of network and tunnel issues. + Older versions of OpenVPN used the ``--secret`` argument to specify a + static key for this test. Newer version generate a random key for the + test. + --tmp-dir dir Specify a directory ``dir`` for temporary files instead of the default :code:`TMPDIR` (or "/tmp" if unset). Note that it must be writable by th= e main diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index e43bc6c..ddf3c17 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -1325,6 +1325,18 @@ secure_memzero(&key2, sizeof(key2)); } +void +generate_test_crypto_random_key(const struct key_type *key_type, struct ke= y_ctx_bi *ctx, + const char *key_name) +{ + struct key2 key2; + key2.n =3D 2; + generate_key_random(&key2.keys[0]); + generate_key_random(&key2.keys[1]); + init_key_ctx_bi(ctx, &key2, KEY_DIRECTION_BIDIRECTIONAL, key_type, key= _name); +} + + /* header and footer for static key file */ static const char static_key_head[] =3D "-----BEGIN OpenVPN Static key V1-= ----"; static const char static_key_foot[] =3D "-----END OpenVPN Static key V1---= --"; diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h index 9424fd7..6670deb 100644 --- a/src/openvpn/crypto.h +++ b/src/openvpn/crypto.h @@ -632,6 +632,13 @@ const char *key_file, bool key_inline, const = int key_direction, const char *key_name, const char *opt_name, s= truct key2 *keydata); +/** + * Generate a random key and initialise ctx to be used the in the crypto r= andom + * test + */ +void generate_test_crypto_random_key(const struct key_type *key_type, stru= ct key_ctx_bi *ctx, + const char *key_name); + /* * Inline functions */ diff --git a/src/openvpn/init.c b/src/openvpn/init.c index ee198ce..c0e4418 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -2998,6 +2998,34 @@ #endif } + +static void +do_init_crypto_test(struct context *c) +{ + const struct options *options =3D &c->options; + ASSERT(options->test_crypto); + + init_crypto_pre(c, 0); + + c->c2.crypto_options.flags |=3D CO_PACKET_ID_LONG_FORM; + + /* Initialize packet ID tracking */ + packet_id_init(&c->c2.crypto_options.packet_id, options->replay_window= , options->replay_time, + "STATIC", 0); + + ASSERT(!key_ctx_bi_defined(&c->c1.ks.static_key)); + + /* Init cipher and hash algorithm */ + init_key_type(&c->c1.ks.key_type, options->ciphername, options->authna= me, + options->test_crypto, true); + + generate_test_crypto_random_key(&c->c1.ks.key_type, &c->c1.ks.static_k= ey, + "test crypto key"); + + /* Get key schedule */ + c->c2.crypto_options.key_ctx_bi =3D c->c1.ks.static_key; +} + /* * Static Key Mode (using a pre-shared key) */ @@ -5003,17 +5031,18 @@ * Do a loopback test * on the crypto subsystem. */ -static void * -test_crypto_thread(void *arg) +void +do_test_crypto(struct context *c) { - struct context *c =3D (struct context *)arg; + /* print version number */ + msg(M_INFO, "%s", title_string); const struct options *options =3D &c->options; ASSERT(options->test_crypto); init_verb_mute(c, IVM_LEVEL_1); context_init_1(c); next_connection_entry(c); - do_init_crypto_static(c, 0); + do_init_crypto_test(c); frame_finalize_options(c, options); @@ -5023,25 +5052,4 @@ packet_id_free(&c->c2.crypto_options.packet_id); context_gc_free(c); - return NULL; -} - -bool -do_test_crypto(const struct options *o) -{ - if (o->test_crypto) - { - struct context c; - - /* print version number */ - msg(M_INFO, "%s", title_string); - - context_clear(&c); - c.options =3D *o; - options_detach(&c.options); - c.first_time =3D true; - test_crypto_thread((void *)&c); - return true; - } - return false; -} +} \ No newline at end of file diff --git a/src/openvpn/init.h b/src/openvpn/init.h index 97318ec..d5c8c04 100644 --- a/src/openvpn/init.h +++ b/src/openvpn/init.h @@ -71,7 +71,7 @@ void close_instance(struct context *c); -bool do_test_crypto(const struct options *o); +void do_test_crypto(struct context *o); void context_gc_free(struct context *c); diff --git a/src/openvpn/openvpn.c b/src/openvpn/openvpn.c index eaaa59b..0c22e27 100644 --- a/src/openvpn/openvpn.c +++ b/src/openvpn/openvpn.c @@ -258,8 +258,9 @@ pre_setup(&c.options); /* test crypto? */ - if (do_test_crypto(&c.options)) + if (c.options.test_crypto) { + do_test_crypto(&c); break; } diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 34af0d3..22ec7fe 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -2276,11 +2276,7 @@ init_options(&defaults, true); - if (options->test_crypto) - { - notnull(options->shared_secret_file, "key file (--secret)"); - } - else + if (!options->test_crypto) { notnull(options->dev, "TUN/TAP device (--dev)"); } @@ -2694,7 +2690,7 @@ msg(M_USAGE, "specify only one of --tls-server, --tls-client, or -= -secret"); } - if (!options->tls_server && !options->tls_client) + if (!options->tls_server && !options->tls_client && !options->test_cry= pto) { msglvl_t msglevel =3D M_USAGE; if (options->allow_deprecated_insecure_static_crypto) diff --git a/tests/t_lpback.sh b/tests/t_lpback.sh index 8ab3973..6802506 100755 --- a/tests/t_lpback.sh +++ b/tests/t_lpback.sh @@ -89,13 +89,12 @@ # Also test cipher 'none' CIPHERS=3D${CIPHERS}$(printf "\nnone") -"${openvpn}" --genkey secret key.$$ set +e for cipher in ${CIPHERS} do test_start "Testing cipher ${cipher}... " - ( "${openvpn}" --test-crypto --secret key.$$ --allow-deprecated-insec= ure-static-crypto --cipher ${cipher} ) >log.$$ 2>&1 + ( "${openvpn}" --test-crypto --cipher ${cipher} ) >log.$$ 2>&1 test_end $? log.$$ done @@ -126,6 +125,6 @@ echo "$0: tests passed: $tests_passed failed: $tests_failed" fi -rm key.$$ tc-server-key.$$ tc-client-key.$$ log.$$ +rm tc-server-key.$$ tc-client-key.$$ log.$$ trap 0 exit $e -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1435?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I72947bd4f0213fd118327f740daeb1d86ae166de Gerrit-Change-Number: 1435 Gerrit-PatchSet: 8 Gerrit-Owner: plaisthos Gerrit-Reviewer: MaxF Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel --rI0MSPyeQ8o= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 upl= oaded patch set #8 to the change originally created by plaisthos.<= /p>

Vi= ew Change

The following approvals got outdated and were removed: Code-Review+2 by flichtenheld

Allow test-crypto to work wi=
thout the --secret argument

The --test-crypto still requires the --s= ecret argument. Since --secret
will be removed in OpenVPN 2.8 but we wan= t to keep test-crypt, remove
the dependency of test-crypto on --static.<= br>
Instead we will just generate a random key for this selftest method.=
This also removes the extra logic that is a leftover from the early
= multi-thread implementation attempt.

Change-Id: I72947bd4f0213fd1183= 27f740daeb1d86ae166de
Signed-off-by: Arne Schwabe <arne@...1227...>= ;
Acked-by: Frank Lichtenheld <frank@...2641...>
Gerrit URL: ht= tps://gerrit.openvpn.net/c/openvpn/+/1435
Message-Id: <20251219135110= .166468-1-frank@...2641...>
URL: https://www.mail-archive.com/openvpn= -devel@lists.sourceforge.net/msg35157.html
Signed-off-by: Gert Doering &= lt;gert@...1296...>
---
M Changes.rst
M doc/man-sections/generi= c-options.rst
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/= openvpn/init.c
M src/openvpn/init.h
M src/openvpn/openvpn.c
M src/= openvpn/options.c
M tests/t_lpback.sh
9 files changed, 70 insertions(= +), 39 deletions(-)

git pull ssh://gerrit.openvp=
n.net:29418/openvpn refs/changes/35/1435/8
diff --git a/Changes.rst=
 b/Changes.rst
index 048434d..c8a3058 100644
--- a/Changes.rst
+++ b/Changes.rst
@@ -3= 43,6 +343,10 @@
loading for key/cert files with non-ASCI= I characters in their file names
(GH: OpenVPN/openvpn#92= 0).

+- The ``test-crypto`` option no longer requires a ``--secret`` argument a= nd
+ will automatica= lly generate a random key.
+
+
<= span> Deprecated features
-------------------
``--opt-verify`` feature removed
diff --git a/doc/man-= sections/generic-options.rst b/doc/man-sections/generic-options.rst<= br>index a9232ce..ed581b1 100644
--- a/doc/man-sectio= ns/generic-options.rst
+++ b/doc/man-sections/generic-optio= ns.rst
@@ -427,13 +427,13 @@
The typical= usage of ``--test-crypto`` would be something like this:
= ::

= - openvpn --test-crypto --secret key
+ openvpn --test-crypto
or

::

- openvpn --test-crypto= --secret key --verb 9
+ Older versions of OpenVPN used the= ``--secret`` argument to specify a
+ static key for this test. Newer version generate a random= key for the
+ test.=
+
-= -tmp-dir dir
Specify a directory ``dir`` for temporary f= iles instead of the default
:code:`TMPDIR` (or "/tm= p" if unset). Note that it must be writable by the main
diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
= index e43bc6c..ddf3c17 100644
--- a/src/openvpn/crypto.c
+++ b/src/openvpn/crypto.c
@@ -1325,6 +1325,1= 8 @@
secure_memzero(&key2, sizeof(key2)); }

+void
+genera= te_test_crypto_random_key(const struct key_type *key_type, struct key_ctx_b= i *ctx,
+ = const char *key_name)
+{
+ struct key2 key2;
+ key2.n =3D 2;
+ generate_key_random(&key2.keys[0]);
+ generate_key_random(&key2.keys[1]);
+ init_key_ctx_bi(ctx= , &key2, KEY_DIRECTION_BIDIRECTIONAL, key_type, key_name);
+}

+
+
/* header and footer for static key file */<= br> static const char static_key_head[] =3D "-----BEGIN OpenVPN = Static key V1-----";
static const char static_key_foo= t[] =3D "-----END OpenVPN Static key V1-----";
di= ff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h
inde= x 9424fd7..6670deb 100644
--- a/src/openvpn/crypto.h=
+++ b/src/openvpn/crypto.h
@@ -632,6 +632,13 @@
const char *key_file, bool key= _inline, const int key_direction,
= const char *key_name, const char *opt_name, struct key2 *keydata);

+/**
+ * Generate a random = key and initialise ctx to be used the in the crypto random
+ * test
+ */
+void generate_test_crypto_random_key(const struct key_type *key_= type, struct key_ctx_bi *ctx,
+ const char *key_name);
+
/*

* Inline functions
*/
diff = --git a/src/openvpn/init.c b/src/openvpn/init.c
index ee198= ce..c0e4418 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -2998,6 +2998,34 @@
= #endif
}

+
+static void
+do_init_crypto_test(struct context *c)
+{
+ const struct options *options =3D &c->options;
+ ASSERT(options->test_cryp= to);
+
+ init_crypto_pre(c, 0);<= br>+
+ c->c2.crypto_options.flags |=3D CO_PACK= ET_ID_LONG_FORM;
+

+ /* Initialize pack= et ID tracking */
+ = packet_id_init(&c->c2.crypto_options.packet_id, options->replay= _window, options->replay_time,
+ "STATIC", 0);
+
+ ASSERT(!key_ctx_bi_defined(&c->c1.ks.static_ke= y));
+
+ /* Init cipher and hash algori= thm */
+ init_key_= type(&c->c1.ks.key_type, options->ciphername, options->authnam= e,
+ = options->test_crypto, true);
+
+ ge= nerate_test_crypto_random_key(&c->c1.ks.key_type, &c->c1.ks.s= tatic_key,
+ = "test crypto key");
+
+ /* Get key schedule */
+ c->c2.crypto_options.key_ctx_bi =3D c->c= 1.ks.static_key;
+}
+
/*<= /span>
* Static Key Mode (using a pre-shared key)
*/

@@ -5003,17 +5031,18 @@
* Do a loo= pback test
* on the crypto subsystem.
*= /
-static void *=
-test_crypto_thread(void *arg= )
+void
+do_test_crypto(struct context *c)=

{
- = struct context *c =3D (struct context *)arg;
+ /* print version number */
+ msg(M_INFO, "%s", title= _string);
const struct options *options =3D &c->= ;options;

ASSERT(options->test_cr= ypto);
init_verb_mute(c, IVM_LEVEL_1);
context_init_1(c);
next_connection_entry(c);
- do_init_crypto_static= (c, 0);
+ do_init_= crypto_test(c);

frame_finalize_optio= ns(c, options);

@@ -5023,25 +5052,4 @@
packet_id_free(&c->c2.crypto_options.packet_id);<= /span>

context_gc_free(c);
- return NULL;
-}
-
-bool

-do_test_crypto(const struc= t options *o)
-{=
- if (o->test_crypto)
- {
- struct context c;
-

- /* print version number */
- msg(M_INFO, "%s", title_s= tring);
-
- context_clear(&c);
- c.options =3D *o;<= /span>
- options_detach= (&c.options);
- = c.first_time =3D true;
- test_crypto_thread((void *)&c);
- return true;
- }
- return false;
-}
+}
= \ No newline at end of file
diff --git a/src/openvpn/= init.h b/src/openvpn/init.h
index 97318ec..d5c8c04 100644
--- a/src/openvpn/init.h
+++ b/src/openvpn/i= nit.h
@@ -71,7 +71,7 @@

= void close_instance(struct context *c);

-bool do_test_crypto(const struct option= s *o);
+void do_test_= crypto(struct context *o);

void context_= gc_free(struct context *c);

diff --git a/= src/openvpn/openvpn.c b/src/openvpn/openvpn.c
index eaaa59b= ..0c22e27 100644
--- a/src/openvpn/openvpn.c
+++ b/src/openvpn/openvpn.c

@@ -258,8 +258,9 @@ pre_setup(&c.options);

= /* test crypto? */
- if (do_test_crypto(&c.options))
<= span style=3D"color: hsl(120, 100%, 40%);">+ if (c.options.test_= crypto)

{
+ do_test_crypto(&c);
= break;
}

diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index 34af0d3..22ec7fe 100644
--- a/src/openv= pn/options.c
+++ b/src/openvpn/options.c
@@= -2276,11 +2276,7 @@

init_options(&a= mp;defaults, true);

- if (options->test_crypto)
- {
- notnull(options->shared_secret_file, "key file (= --secret)");
- = }
- else
<= span style=3D"color: hsl(120, 100%, 40%);">+ if (!options->test_crypt= o)

{
notnull(options->dev,= "TUN/TAP device (--dev)");
}
@@ -2694,7 +2690,7 @@

msg(M_USAGE, "specify= only one of --tls-server, --tls-client, or --secret");
}

- if (!options->tls_server && !options->tls_client)
+ if (!options->t= ls_server && !options->tls_client && !options->test_c= rypto)
{
msglvl_t msglevel = =3D M_USAGE;
if (options->allow_deprecated_inse= cure_static_crypto)
diff --git a/tests/t_lpback.sh b/tests/= t_lpback.sh
index 8ab3973..6802506 100755
-= -- a/tests/t_lpback.sh
+++ b/tests/t_lpback.sh
@@ -89,13 +89,12 @@

# Also test cipher 'none'<= /span>
CIPHERS=3D${CIPHERS}$(printf "\nnone")
-"${openv= pn}" --genkey secret key.$$
set +e
<= /span>
for cipher in ${CIPHERS}
do
test_start "Testing cipher ${cipher}... "

- ( "${openvpn}" --test-c= rypto --secret key.$$ --allow-deprecated-insecure-static-crypto --cipher $= {cipher} ) >log.$$ 2>&1

+ ( "${openvpn}" --test-crypto --cipher ${cipher}= ) >log.$$ 2>&1
test_end $? log.$$ done

@@ -126,6 +125,6 @@ echo "$0: tests passed: $tests_passed failed: $tests_fai= led"
fi

-rm key.$$ tc-server-key.$$ tc-client-key.$$ log.$= $
+rm tc-server-key.$= $ tc-client-key.$$ log.$$
trap 0
exit $e<= /span>

To view, visit change 1435. To unsubscribe,= or for help writing mail filters, visit settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I72947bd4f0213fd118327f740da= eb1d86ae166de
Gerrit-Change-Number: 1435
Gerrit-PatchSet: 8
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: MaxF <max@...2606...> <= /div>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --rI0MSPyeQ8o=--