From: "plaisthos (Code Review)" Date: Thu, 11 Dec 2025 11:37:11 +0000 References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <61a86e8ff6ee7cce0015bc40d3e4e1a3a2b15b71-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="EcyrHo77czA="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Allow test-crypt to work without --secret argument List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: openvpn-devel --EcyrHo77czA= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable plaisthos has uploaded this change for review. ( http://gerrit.openvpn.net/= c/openvpn/+/1435?usp=3Demail ) Change subject: Allow test-crypt to work without --secret argument ...................................................................... Allow test-crypt to work without --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. Change-Id: I72947bd4f0213fd118327f740daeb1d86ae166de Signed-off-by: Arne Schwabe --- 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/options.c M tests/t_lpback.sh 7 files changed, 75 insertions(+), 14 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/35/1435/1 diff --git a/Changes.rst b/Changes.rst index 32efbe7..1a92b94 100644 --- a/Changes.rst +++ b/Changes.rst @@ -338,6 +338,9 @@ (force egress =3D ingress interface) can be achieved with the new ``--multihome same-interface`` sub-option. +- 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 882cf28..b6e513d 100644 --- a/doc/man-sections/generic-options.rst +++ b/doc/man-sections/generic-options.rst @@ -439,13 +439,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 @@ -453,6 +453,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 fc079e1..2b7cfc2 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -2997,6 +2997,33 @@ #endif } + +static void +do_init_crypto_test(struct context *c, const unsigned int flags) +{ + const struct options *options =3D &c->options; + ASSERT(options->test_crypto); + + init_crypto_pre(c, flags); + + /* Initialize packet ID tracking */ + // packet_id_init(&c->c2.crypto_options.packet_id, options->replay_win= dow, options->replay_time, + // "STATIC", 0); + c->c2.crypto_options.flags |=3D CO_PACKET_ID_LONG_FORM; + + 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) */ @@ -3004,7 +3031,7 @@ do_init_crypto_static(struct context *c, const unsigned int flags) { const struct options *options =3D &c->options; - ASSERT(options->shared_secret_file); + ASSERT(options->shared_secret_file || options->test_crypto); init_crypto_pre(c, flags); @@ -3027,10 +3054,18 @@ init_key_type(&c->c1.ks.key_type, options->ciphername, options->au= thname, options->test_crypto, true); - /* Read cipher and hmac keys from shared secret file */ - crypto_read_openvpn_key(&c->c1.ks.key_type, &c->c1.ks.static_key, - options->shared_secret_file, options->shar= ed_secret_file_inline, - options->key_direction, "Static Key Encryp= tion", "secret", NULL); + if (!options->shared_secret_file && options->test_crypto) + { + generate_test_crypto_random_key(&c->c1.ks.key_type, &c->c1.ks.= static_key, + "test crypto key"); + } + else + { + /* Read cipher and hmac keys from shared secret file */ + crypto_read_openvpn_key(&c->c1.ks.key_type, &c->c1.ks.static_k= ey, + options->shared_secret_file, options->= shared_secret_file_inline, + options->key_direction, "Static Key En= cryption", "secret", NULL); + } } else { @@ -3501,6 +3536,10 @@ { do_init_crypto_static(c, flags); } + else if (c->options.test_crypto) + { + do_init_crypto_test(c, flags); + } else if (c->options.tls_server || c->options.tls_client) { do_init_crypto_tls(c, flags); diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 2d1f740..b430065 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -2283,11 +2283,7 @@ =20 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)"); } @@ -2701,7 +2697,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..eb6a72f 100755 --- a/tests/t_lpback.sh +++ b/tests/t_lpback.sh @@ -95,7 +95,7 @@ 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 -- 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: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I72947bd4f0213fd118327f740daeb1d86ae166de Gerrit-Change-Number: 1435 Gerrit-PatchSet: 1 Gerrit-Owner: plaisthos Gerrit-CC: openvpn-devel --EcyrHo77czA= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

plaisthos has upl= oaded this change for review.

View Change

Allow test-crypt to work without --secret argument

The --test-cr= ypto still requires the --secret argument. Since --secret
will be remove= d in OpenVPN 2.8 but we want to keep test-crypt, remove
the dependency o= f test-crypto on --static.

Instead we will just generate a random ke= y for this selftest method.

Change-Id: I72947bd4f0213fd118327f740dae= b1d86ae166de
Signed-off-by: Arne Schwabe <arne@...1227...>
---<= br>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/openvp= n/options.c
M tests/t_lpback.sh
7 files changed, 75 insertions(+), 14= deletions(-)

git pull ssh://gerrit.openvpn.net:=
29418/openvpn refs/changes/35/1435/1
diff --git a/Changes.rst b/Cha=
nges.rst
index 32efbe7..1a92b94 100644
--- = a/Changes.rst
+++ b/Changes.rst
@@ -338,6 += 338,9 @@
(force egress =3D ingress interface) can be ach= ieved with the new
``--multihome same-interface`` sub-op= tion.

+- The ``test-crypto`` option no longer requires a ``--secret`` argument= and
+ will automati= cally 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 882cf28..b6e513d 100644
--- a/doc/man-sections/generic-options.rst
+++ b/doc/man-s= ections/generic-options.rst
@@ -439,13 +439,13 @@ The typical usage of ``--test-crypto`` would be something like th= is:
::

- 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 h= as been ported to a
new platform, or to isolate problems= in the compiler, OpenSSL crypto
@@ -453,6 +453,10 @@

problems with encryption and authentication can be debugged
independently of network and tunnel issues.

+ Older version= s of OpenVPN used the ``--secret`` argument to specify a
+ static key for this test. Newer vers= ion 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/cryp= to.c
index e43bc6c..ddf3c17 100644
--- a/sr= c/openvpn/crypto.c
+++ b/src/openvpn/crypto.c
@@ -1325,6 +1325,18 @@
secure_memzero(&key2, si= zeof(key2));
}

+void
+generate_test_crypto_random_key(const struct key_type *key_t= ype, struct key_ctx_bi *ctx,
+ const char *key_name)
+{
+ struct key2 key2;
+ key2.n =3D 2;
+ generate_key_random(&key2.keys[0]);=
+ generate_key_random(&a= mp;key2.keys[1]);
+ = init_key_ctx_bi(ctx, &key2, KEY_DIRECTION_BIDIRECTIONAL, key_type, ke= y_name);
+}+
+
/* header and footer for stati= c key file */
static const char static_key_head[] =3D &quo= t;-----BEGIN OpenVPN Static key V1-----";
static cons= t 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/op= envpn/crypto.h
+++ b/src/openvpn/crypto.h
@= @ -632,6 +632,13 @@
const cha= r *key_file, bool key_inline, const int key_direction,
= const char *key_name, const char *opt_name, struc= t key2 *keydata);

+/**
+= * Generate a random key and initialise ctx to be used the in the crypto ra= ndom
+ * test<= br>+ */
+void generate_test_crypto_random_key(cons= t struct key_type *key_type, struct key_ctx_bi *ctx,
+ cons= t char *key_name);
+<= /span>
/*
* Inline functions
= */
diff --git a/src/openvpn/init.c b/src/openvpn/init.c

index fc079e1..2b7cfc2 100644
--- a/src/openvp= n/init.c
+++ b/src/openvpn/init.c
@@ -2997,= 6 +2997,33 @@
#endif
}
<= /span>
+
+static void
+do_init_crypto_test(struct context *c, const un= signed int flags)
+{<= /span>
+ const struct opt= ions *options =3D &c->options;
+ ASSERT(options->test_crypto);
+
+ init_crypto_pre(c, flags);
+
+ /* Initialize packet ID tracking */
+ // packet_id_init(&c->c2.crypto_opti= ons.packet_id, options->replay_window, options->replay_time,+ // "= STATIC", 0);
+ = c->c2.crypto_options.flags |=3D CO_PACKET_ID_LONG_FORM;
+

+ ASSERT(!key_ctx_bi_defined(&c->c1.ks.stati= c_key));
+
= + /* Init cipher and hash al= gorithm */
+ init_= key_type(&c->c1.ks.key_type, options->ciphername, options->aut= hname,
+ = options->test_crypto, true);
+
+ = generate_test_crypto_random_key(&c->c1.ks.key_type, &c->c1.= ks.static_key,
+ = "test crypto key");
+

+ /* Get key schedule */
+ c->c2.crypto_options.key_ctx_bi =3D c-&= gt;c1.ks.static_key;
= +}
+
= /*
* Static Key Mode (using a pre-shared key)
= */
@@ -3004,7 +3031,7 @@
do_init_c= rypto_static(struct context *c, const unsigned int flags)
= {
const struct options *options =3D &c->options= ;
- ASSERT(options-&= gt;shared_secret_file);
+ ASSERT(options->shared_secret_file || options->test_crypto);<= /span>

init_crypto_pre(c, flags);
@@ -3027,10 +3054,18 @@
i= nit_key_type(&c->c1.ks.key_type, options->ciphername, options->= ;authname,
options->test_crypto, = true);

- crypto_read_openvpn_ke= y(&c->c1.ks.key_type, &c->c1.ks.static_key,
- options= ->shared_secret_file, options->shared_secret_file_inline,
<= span style=3D"color: hsl(0, 100%, 40%);">- o= ptions->key_direction, "Static Key Encryption", "secret&q= uot;, NULL);

+ = if (!options->shared_secret_file && options->test_crypto)
+ {
+ generate_test_crypto= _random_key(&c->c1.ks.key_type, &c->c1.ks.static_key,
<= br>+ = "test crypto key");
+ }
+ else
+ {
+= /* Read cipher and hmac keys from shared secret file */<= br>+ crypto_read_ope= nvpn_key(&c->c1.ks.key_type, &c->c1.ks.static_key,
= + = options->shared_secret_file, options->shared_secret_file_inline= ,
+ = options->key_direction, "Static Key Encryption&qu= ot;, "secret", NULL);
+ }
}
else
{
@@ -3501,6 +3536,10 @@
= {
do_init_crypto_static(c, flags);
<= span> }

+ else= if (c->options.test_crypto)
+ {
+ = do_init_crypto_test(c, flags);
+ }
else if (c->options.tls_serv= er || c->options.tls_client)
{
= do_init_crypto_tls(c, flags);
diff --git a/src/openvpn= /options.c b/src/openvpn/options.c
index 2d1f740..b430065 1= 00644
--- a/src/openvpn/options.c
+++ b/src= /openvpn/options.c
@@ -2283,11 +2283,7 @@
=
init_options(&defaults, true);
<= /span>
- if (options->te= st_crypto)
- {
- notnull(options->= ;shared_secret_file, "key file (--secret)");
- }
- else
+ if (!options->test_crypto)
{
notnull(options->dev, "TUN/TAP device (--dev)");<= /span>
}
@@ -2701,7 +2697,7 @@
msg(M_USAGE, "specify only one of --tls-server, --tls-clien= t, or --secret");

}

<= span style=3D"color: hsl(0, 100%, 40%);">- if (!options->tls_server &= amp;& !options->tls_client)

+ if (!options->tls_server && !options->tls_= client && !options->test_crypto)
{ 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 8ab397= 3..eb6a72f 100755
--- a/tests/t_lpback.sh
+= ++ b/tests/t_lpback.sh
@@ -95,7 +95,7 @@
f= or cipher in ${CIPHERS}
do
test_start= "Testing cipher ${cipher}... "
- ( "${openvpn}" --test-crypto --secret key= .$$ --allow-deprecated-insecure-static-crypto --cipher ${cipher} ) >log= .$$ 2>&1
+ = ( "${openvpn}" --test-crypto --cipher ${cipher} ) >log.$$ 2>= ;&1
test_end $? log.$$
done


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

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I72947bd4f0213fd118327f740da= eb1d86ae166de
Gerrit-Change-Number: 1435
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --EcyrHo77czA=--