Skip to contentSkip to conversation

Revert commit 423ced962d

PATCH In review Arne Schwabe 2 participants 4 messages May 24, 2023 – Jul 18, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Revert commit 423ced962d

This reverts commit 423ced962db3129b4ed551c489624faba4340652, which has Jason A. Donenfeld listed as author as the patch was based on his initial submission.

We have not received permission to relicense the original patch.

Change-Id I8142753928498169032450c56d0497a5042bdc9b
---
 src/openvpn/init.c               |  1 -
 src/openvpn/options.c            | 26 +++++++++++++-------------
 src/openvpn/options.h            |  1 -
 src/openvpn/ssl_common.h         |  1 -
 src/openvpn/ssl_verify_mbedtls.c | 16 ----------------
 src/openvpn/ssl_verify_openssl.c |  2 +-
 6 files changed, 14 insertions(+), 33 deletions(-)
src/openvpn/init.c +0 -1
index d358ad003..c023b33c6 100644
@@ -3347,7 +3347,6 @@ do_init_crypto_tls(struct context *c, const unsigned int flags)
     to.verify_hash = options->verify_hash;
     to.verify_hash_algo = options->verify_hash_algo;
     to.verify_hash_depth = options->verify_hash_depth;
-    to.verify_hash_no_ca = options->verify_hash_no_ca;
 #ifdef ENABLE_X509ALTUSERNAME
     memcpy(to.x509_username_field, options->x509_username_field, sizeof(to.x509_username_field));
 #else
src/openvpn/options.c +13 -13
index e4c596b89..fe9285384 100644
@@ -2991,11 +2991,21 @@ options_postprocess_verify_ce(const struct options *options,
         else
         {
 #ifdef ENABLE_CRYPTO_MBEDTLS
+            if (!(options->ca_file))
+            {
+                msg(M_USAGE, "You must define CA file (--ca)");
+            }
+
             if (options->ca_path)
             {
                 msg(M_USAGE, "Parameter --capath cannot be used with the mbed TLS version version of OpenVPN.");
             }
-#endif  /* ifdef ENABLE_CRYPTO_MBEDTLS */
+#else  /* ifdef ENABLE_CRYPTO_MBEDTLS */
+            if ((!(options->ca_file)) && (!(options->ca_path)))
+            {
+                msg(M_USAGE, "You must define CA file (--ca) or CA path (--capath)");
+            }
+#endif
             if (pull)
             {
 
@@ -3727,13 +3737,6 @@ options_postprocess_mutate(struct options *o, struct env_set *es)
         options_postprocess_http_proxy_override(o);
     }
 #endif
-    if (!o->ca_file && !o->ca_path && o->verify_hash
-        && o->verify_hash_depth == 0)
-    {
-        msg(M_INFO, "Using certificate fingerprint to verify peer (no CA "
-            "option set). ");
-        o->verify_hash_no_ca = true;
-    }
 
     if (o->config && streq(o->config, "stdin") && o->remap_sigusr1 == SIGHUP)
     {
@@ -4029,11 +4032,8 @@ options_postprocess_filechecks(struct options *options)
     errs |= check_file_access_inline(options->dh_file_inline, CHKACC_FILE,
                                      options->dh_file, R_OK, "--dh");
 
-    if (!options->verify_hash_no_ca)
-    {
-        errs |= check_file_access_inline(options->ca_file_inline, CHKACC_FILE,
-                                         options->ca_file, R_OK, "--ca");
-    }
+    errs |= check_file_access_inline(options->ca_file_inline, CHKACC_FILE,
+                                     options->ca_file, R_OK, "--ca");
 
     errs |= check_file_access_chroot(options->chroot_dir, CHKACC_FILE,
                                      options->ca_path, R_OK, "--capath");
src/openvpn/options.h +0 -1
index f5890b90f..95f1158a4 100644
@@ -604,7 +604,6 @@ struct options
     struct verify_hash_list *verify_hash;
     hash_algo_type verify_hash_algo;
     int verify_hash_depth;
-    bool verify_hash_no_ca;
     unsigned int ssl_flags; /* set to SSLF_x flags from ssl.h */
 
 #ifdef ENABLE_PKCS11
src/openvpn/ssl_common.h +0 -1
index 27b029479..c0b3caa71 100644
@@ -345,7 +345,6 @@ struct tls_options
     const char *remote_cert_eku;
     struct verify_hash_list *verify_hash;
     int verify_hash_depth;
-    bool verify_hash_no_ca;
     hash_algo_type verify_hash_algo;
 #ifdef ENABLE_X509ALTUSERNAME
     char *x509_username_field[MAX_PARMS];
src/openvpn/ssl_verify_mbedtls.c +0 -16
index e3437f740..c9ef7a171 100644
@@ -62,22 +62,6 @@ verify_callback(void *session_obj, mbedtls_x509_crt *cert, int cert_depth,
     struct buffer cert_fingerprint = x509_get_sha256_fingerprint(cert, &gc);
     cert_hash_remember(session, cert_depth, &cert_fingerprint);
 
-    if (session->opt->verify_hash_no_ca)
-    {
-        /*
-         * If we decide to verify the peer certificate based on the fingerprint
-         * we ignore wrong dates and the certificate not being trusted.
-         * Any other problem with the certificate (wrong key, bad cert,...)
-         * will still trigger an error.
-         * Clearing these flags relies on verify_cert will later rejecting a
-         * certificate that has no matching fingerprint.
-         */
-        uint32_t flags_ignore = MBEDTLS_X509_BADCERT_NOT_TRUSTED
-                                | MBEDTLS_X509_BADCERT_EXPIRED
-                                | MBEDTLS_X509_BADCERT_FUTURE;
-        *flags = *flags & ~flags_ignore;
-    }
-
     /* did peer present cert which was signed by our root cert? */
     if (*flags != 0)
     {
src/openvpn/ssl_verify_openssl.c +1 -1
index e24ce4e4a..ac36f09db 100644
@@ -67,7 +67,7 @@ verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
     cert_hash_remember(session, X509_STORE_CTX_get_error_depth(ctx), &cert_hash);
 
     /* did peer present cert which was signed by our root cert? */
-    if (!preverify_ok && !session->opt->verify_hash_no_ca)
+    if (!preverify_ok)
     {
         /* get the X509 name */
         char *subject = x509_get_subject(current_cert, &gc);
Signature · 1 line
2.39.2 (Apple Git-143)
#1 lore raw

PATCH 2/2 Implement using --peer-fingerprint without CA certificates

This is implements --peer-fingerprint command to support OpenVPN authentication without involving a PKI.

The current implementation in OpenVPN for peer fingerprint has been already extensively rewritten from the original submission from Jason [1]. The commit preserved the original author since it was based on Jason code/idea.

The current code uses two commits to prepare the --peer-fingerprint solution as which choose to use a simple to use --peer-fingerprint directive instead of using using a --tls-verify script like the v1 of the patch proposed. The two commit preparing this are:

- Extend verify-hash to allow multiple hashes
- Implement peer-fingerprint to check fingerprint of peer certificate

This perparing patches make this actual patch quite short. There are some lines in this patch that bear some similarity to the ones like

    if (!preverify_ok && !session->opt->verify_hash_no_ca)

vs

    if (!preverify_ok && !session->opt->ca_file_none)

But these similarities are one line fragments and dictated by the surrounding style and program flow, so even a complete black box implementation will likely end up with the same lines.

[1] https://www.mail-archive.com/[email protected]/msg16781.html

Change-Id Ie74c3d606c5429455c293c367462244566a936e3
---
 src/openvpn/init.c               |  1 +
 src/openvpn/options.c            | 26 +++++++++++++-------------
 src/openvpn/options.h            |  1 +
 src/openvpn/ssl_common.h         |  1 +
 src/openvpn/ssl_verify_mbedtls.c | 16 ++++++++++++++++
 src/openvpn/ssl_verify_openssl.c |  2 +-
 6 files changed, 33 insertions(+), 14 deletions(-)
src/openvpn/init.c +1 -0
index c023b33c6..d358ad003 100644
@@ -3347,6 +3347,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags)
     to.verify_hash = options->verify_hash;
     to.verify_hash_algo = options->verify_hash_algo;
     to.verify_hash_depth = options->verify_hash_depth;
+    to.verify_hash_no_ca = options->verify_hash_no_ca;
 #ifdef ENABLE_X509ALTUSERNAME
     memcpy(to.x509_username_field, options->x509_username_field, sizeof(to.x509_username_field));
 #else
src/openvpn/options.c +13 -13
index fe9285384..e4c596b89 100644
@@ -2991,21 +2991,11 @@ options_postprocess_verify_ce(const struct options *options,
         else
         {
 #ifdef ENABLE_CRYPTO_MBEDTLS
-            if (!(options->ca_file))
-            {
-                msg(M_USAGE, "You must define CA file (--ca)");
-            }
-
             if (options->ca_path)
             {
                 msg(M_USAGE, "Parameter --capath cannot be used with the mbed TLS version version of OpenVPN.");
             }
-#else  /* ifdef ENABLE_CRYPTO_MBEDTLS */
-            if ((!(options->ca_file)) && (!(options->ca_path)))
-            {
-                msg(M_USAGE, "You must define CA file (--ca) or CA path (--capath)");
-            }
-#endif
+#endif  /* ifdef ENABLE_CRYPTO_MBEDTLS */
             if (pull)
             {
 
@@ -3737,6 +3727,13 @@ options_postprocess_mutate(struct options *o, struct env_set *es)
         options_postprocess_http_proxy_override(o);
     }
 #endif
+    if (!o->ca_file && !o->ca_path && o->verify_hash
+        && o->verify_hash_depth == 0)
+    {
+        msg(M_INFO, "Using certificate fingerprint to verify peer (no CA "
+            "option set). ");
+        o->verify_hash_no_ca = true;
+    }
 
     if (o->config && streq(o->config, "stdin") && o->remap_sigusr1 == SIGHUP)
     {
@@ -4032,8 +4029,11 @@ options_postprocess_filechecks(struct options *options)
     errs |= check_file_access_inline(options->dh_file_inline, CHKACC_FILE,
                                      options->dh_file, R_OK, "--dh");
 
-    errs |= check_file_access_inline(options->ca_file_inline, CHKACC_FILE,
-                                     options->ca_file, R_OK, "--ca");
+    if (!options->verify_hash_no_ca)
+    {
+        errs |= check_file_access_inline(options->ca_file_inline, CHKACC_FILE,
+                                         options->ca_file, R_OK, "--ca");
+    }
 
     errs |= check_file_access_chroot(options->chroot_dir, CHKACC_FILE,
                                      options->ca_path, R_OK, "--capath");
src/openvpn/options.h +1 -0
index 95f1158a4..f5890b90f 100644
@@ -604,6 +604,7 @@ struct options
     struct verify_hash_list *verify_hash;
     hash_algo_type verify_hash_algo;
     int verify_hash_depth;
+    bool verify_hash_no_ca;
     unsigned int ssl_flags; /* set to SSLF_x flags from ssl.h */
 
 #ifdef ENABLE_PKCS11
src/openvpn/ssl_common.h +1 -0
index c0b3caa71..27b029479 100644
@@ -345,6 +345,7 @@ struct tls_options
     const char *remote_cert_eku;
     struct verify_hash_list *verify_hash;
     int verify_hash_depth;
+    bool verify_hash_no_ca;
     hash_algo_type verify_hash_algo;
 #ifdef ENABLE_X509ALTUSERNAME
     char *x509_username_field[MAX_PARMS];
src/openvpn/ssl_verify_mbedtls.c +16 -0
index c9ef7a171..e3437f740 100644
@@ -62,6 +62,22 @@ verify_callback(void *session_obj, mbedtls_x509_crt *cert, int cert_depth,
     struct buffer cert_fingerprint = x509_get_sha256_fingerprint(cert, &gc);
     cert_hash_remember(session, cert_depth, &cert_fingerprint);
 
+    if (session->opt->verify_hash_no_ca)
+    {
+        /*
+         * If we decide to verify the peer certificate based on the fingerprint
+         * we ignore wrong dates and the certificate not being trusted.
+         * Any other problem with the certificate (wrong key, bad cert,...)
+         * will still trigger an error.
+         * Clearing these flags relies on verify_cert will later rejecting a
+         * certificate that has no matching fingerprint.
+         */
+        uint32_t flags_ignore = MBEDTLS_X509_BADCERT_NOT_TRUSTED
+                                | MBEDTLS_X509_BADCERT_EXPIRED
+                                | MBEDTLS_X509_BADCERT_FUTURE;
+        *flags = *flags & ~flags_ignore;
+    }
+
     /* did peer present cert which was signed by our root cert? */
     if (*flags != 0)
     {
src/openvpn/ssl_verify_openssl.c +1 -1
index ac36f09db..e24ce4e4a 100644
@@ -67,7 +67,7 @@ verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
     cert_hash_remember(session, X509_STORE_CTX_get_error_depth(ctx), &cert_hash);
 
     /* did peer present cert which was signed by our root cert? */
-    if (!preverify_ok)
+    if (!preverify_ok && !session->opt->verify_hash_no_ca)
     {
         /* get the X509 name */
         char *subject = x509_get_subject(current_cert, &gc);
Signature · 1 line
2.39.2 (Apple Git-143)
Acked-by on v1 1/2
#3 lore raw
In reply to Arne Schwabe

This is unfortunate, but the only option if we want to get on with the license change. Not tested individually, but tested together with 2/2, and "everything works as before".

Your patch has been applied to the master and release/2.6 branch.

commit 370334828659e205941eecd1c90f085a64ca539d (master) commit e376a00c2884c7cc3f965cdd08a8b66537264999 (release/2.6)

Author: Arne Schwabe
Date:   Wed May 24 15:24:23 2023 +0200
     Revert commit 423ced962d

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg26722.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

Acked-by on v1 2/2
#2 lore raw

[Openvpn-devel] [PATCH applied] Re: Implement using --peer-fingerprint without CA certificates

In reply to Arne Schwabe

Tested that things work as before (the t_server testbed has fp tests, both "should succeed" and "should fail", all pass).

I did some massaging to the text in the commit message to make the "based on two previous commits" part easier to read.

Your patch has been applied to the master and release/2.6 branch.

commit c3746da7f04acf872f251d3673551963380c4d77 (master) commit b241e815f16bd566a4824d26f381e468917c822b (release/2.6)

Author: Arne Schwabe
Date:   Wed May 24 15:24:24 2023 +0200
     Implement using --peer-fingerprint without CA certificates

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg26723.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering