Skip to contentSkip to conversation

revamp X.509 name verification option

PATCH In review Heiko Hund 3 participants 14 messages Feb 22, 2013 – Mar 7, 2013

lore
Share & tools
lore

Heiko Hund

author
#0 lore raw

PATCH 1/1 revamp X.509 name verification option

This patch set tries to do X.509 name verification right. As discussed during FOSDEM 2013, changing --tls-remote to support RFC 2253 style subject DNs only was too radical as it broke more configurations than expected.

This makes --tls-remote work with old configurations again, but deprecates its use. As a replacement it introduces a new option for X.509 name verification that takes RFC 2253 subject DNs only.

[PATCH 1/3] reintroduce --no-name-remapping option [PATCH 2/3] make --tls-remote compatible with pre 2.3 configs [PATCH 3/3] add new option for X.509 name verification

author
#1 lore raw

PATCH 1/3 reintroduce --no-name-remapping option

The option is just an alias for --compat-names no-remapping and is introduced so pre-2.3 server configurations don't break.

---
 doc/openvpn.8         |   32 +++++++++++++++++++++++---------
 src/openvpn/options.c |   21 ++++++++++++++-------
 2 files changed, 37 insertions(+), 16 deletions(-)
doc/openvpn.8 +23 -9
index 829bbd2..998f7ab 100644
@@ -3462,19 +3462,16 @@ characters in the usernames, X.509 Subject fields and Common Name variables and
 it complies to the RFC 2253, UTF\-8 String Representation of Distinguished
 Names.
 
-As a backwards compatibility for the removed \-\-no\-name\-remapping feature in
-older OpenVPN versions, the
+The
 .B no\-remapping
 mode flag can be used with the
 .B
 \-\-compat\-names
-option.
-When this mode flag is used, the Common Name, Subject, and username strings are
-allowed to include any printable character including space, but excluding
-control characters such as tab, newline, and carriage-return. It ensures
-compatibility with the
-.B \-\-no\-name\-remapping
-option of OpenVPN versions before v2.3.
+option to be compatible with the now deprecated \-\-no\-name\-remapping feature
+present in older OpenVPN versions. When this mode flag is used, the Common Name,
+Subject, and username strings are allowed to include any printable character
+including space, but excluding control characters such as tab, newline, and
+carriage-return.
 
 .B Please note:
 This option will not be around for a long time.  It is only implemented
@@ -3483,6 +3480,23 @@ removed either in OpenVPN v2.4 or v2.5.  So please make sure you start
 the process to support the new formatting as soon as possible.
 .\"*********************************************************
 .TP
+.B \-\-no\-name\-remapping (DEPRECATED)
+The
+.B \-\-no\-name\-remapping
+option is an alias for
+.B \-\-compat\-names\ no\-remapping.
+It ensures compatibility with configurations using the
+.B \-\-no\-name\-remapping
+option.
+
+.B Please note:
+This option is now deprecated.  It will be removed either in OpenVPN v2.4
+or v2.5.  So please make sure you support the new X.509 name formatting
+described with the
+.B \-\-compat\-names
+option as soon as possible.
+.\"*********************************************************
+.TP
 .B \-\-port-share host port [dir]
 When run in TCP server mode, share the OpenVPN port with
 another application, such as an HTTPS server.  If OpenVPN
src/openvpn/options.c +14 -7
index 3b5f1e7..dd38bc9 100644
@@ -5561,13 +5561,6 @@ add_option (struct options *options,
       VERIFY_PERMISSION (OPT_P_GENERAL);
       options->ssl_flags |= SSLF_AUTH_USER_PASS_OPTIONAL;
     }
-  else if (streq (p[0], "compat-names"))
-    {
-      VERIFY_PERMISSION (OPT_P_GENERAL);
-      compat_flag (COMPAT_FLAG_SET | COMPAT_NAMES);
-      if (p[1] && streq (p[1], "no-remapping"))
-        compat_flag (COMPAT_FLAG_SET | COMPAT_NO_NAME_REMAPPING);
-    }
   else if (streq (p[0], "opt-verify"))
     {
       VERIFY_PERMISSION (OPT_P_GENERAL);
@@ -6518,6 +6511,20 @@ add_option (struct options *options,
       options->tls_export_cert = p[1];
     }
 #endif
+  else if (streq (p[0], "compat-names"))
+    {
+      VERIFY_PERMISSION (OPT_P_GENERAL);
+      compat_flag (COMPAT_FLAG_SET | COMPAT_NAMES);
+      if (p[1] && streq (p[1], "no-remapping"))
+        compat_flag (COMPAT_FLAG_SET | COMPAT_NO_NAME_REMAPPING);
+    }
+  else if (streq (p[0], "no-name-remapping"))
+    {
+      VERIFY_PERMISSION (OPT_P_GENERAL);
+      msg (M_WARN, "DEPRECATED OPTION: --no-name-remapping, please update your configuration");
+      compat_flag (COMPAT_FLAG_SET | COMPAT_NAMES);
+      compat_flag (COMPAT_FLAG_SET | COMPAT_NO_NAME_REMAPPING);
+    }
   else if (streq (p[0], "tls-remote") && p[1])
     {
       VERIFY_PERMISSION (OPT_P_GENERAL);
Signature · 1 line
1.7.9.5
#2 lore raw

Re: [Openvpn-devel] [PATCH 1/3] reintroduce --no-name-remapping option

Am 22.02.13 10:44, schrieb Heiko Hund:

Quoted 3 lines

The option is just an alias for --compat-names no-remapping and is introduced so pre-2.3 server configurations don't break.

ACK.

Arne

#3 lore raw

[Openvpn-devel] [PATCH applied] Re: reintroduce --no-name-remapping option

In reply to Heiko Hund

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

commit 26b0433c4a642f8d2197f3fd371759f0047bd0bd (master) commit c86d09c7c115eeda96ea0b2a400c3ce57bd90292 (release/2.3)

Author: Heiko Hund
Date:   Fri Feb 22 10:44:20 2013 +0100
     reintroduce --no-name-remapping option

     Signed-off-by: Heiko Hund <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: [email protected]...
     URL: http://article.gmane.org/gmane.network.openvpn.devel/7364
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

author
#4 lore raw

PATCH 2/3 make --tls-remote compatible with pre 2.3 configs

In reply to Heiko Hund

In openvpn 2.3.0 the semantics of the --tls-remote option changed. That broke more configurations than anticipated. To not break configurations that use --tls-remote with a legacy OpenSSL style DN anymore, it is now detected when such a DN is configured. When necessary the --compat-names option is then automatically enabled.

---
 src/openvpn/options.c |    6 ++++++
 1 file changed, 6 insertions(+)
src/openvpn/options.c +6 -0
index dd38bc9..7fda76f 100644
@@ -6528,6 +6528,12 @@ add_option (struct options *options,
   else if (streq (p[0], "tls-remote") && p[1])
     {
       VERIFY_PERMISSION (OPT_P_GENERAL);
+      /*
+       * Enable legacy openvpn format for DNs that have not been converted
+       * yet and X.509 common names (not containing an '=' or ', ')
+       */
+      if (p[1][0] == '/' || !strchr (p[1], '=') || !strstr (p[1], ", "))
+        compat_flag (COMPAT_FLAG_SET | COMPAT_NAMES);
       options->tls_remote = p[1];
     }
   else if (streq (p[0], "ns-cert-type") && p[1])
Signature · 1 line
1.7.9.5
#5 lore raw

Re: [Openvpn-devel] [PATCH 2/3] make --tls-remote compatible with pre 2.3 configs

Am 22.02.13 10:44, schrieb Heiko Hund:

Quoted 6 lines

In openvpn 2.3.0 the semantics of the --tls-remote option changed. That broke more configurations than anticipated. To not break configurations that use --tls-remote with a legacy OpenSSL style DN anymore, it is now detected when such a DN is configured. When necessary the --compat-names option is then automatically enabled.

Ack.

Arne

#6 lore raw

[Openvpn-devel] [PATCH applied] Re: make --tls-remote compatible with pre 2.3 configs

In reply to Heiko Hund

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

commit ad532bba896875e56488e69ec16212a77787c57b (master) commit 0f92b3b4170dab29aaf5cb4e6a0d00d37bf418b4 (release/2.3)

Author: Heiko Hund
Date:   Fri Feb 22 10:44:21 2013 +0100
     make --tls-remote compatible with pre 2.3 configs

     Signed-off-by: Heiko Hund <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: [email protected]...
     URL: http://article.gmane.org/gmane.network.openvpn.devel/7366
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

author
#7 lore raw

PATCH 3/3 add new option for X.509 name verification

In reply to Heiko Hund

Add the option --verify-x509-name to provide the functionality of the now deprecated --tls-remote.

The new option accepts RFC 2253 subject DNs only and compares RDN or RDN prefix only if configured explicitly.

---
 doc/openvpn.8            |   78 +++++++++++++++++++++++++++++++-------
 src/openvpn/init.c       |    7 ++--
 src/openvpn/options.c    |   94 ++++++++++++++++++++++++++++++++++++++++------
 src/openvpn/options.h    |    3 +-
 src/openvpn/ssl_common.h |    3 +-
 src/openvpn/ssl_verify.c |   15 +++++---
 src/openvpn/ssl_verify.h |    6 +++
 7 files changed, 170 insertions(+), 36 deletions(-)
doc/openvpn.8 +65 -13
index 998f7ab..637fbb4 100644
@@ -3431,7 +3431,7 @@ the authenticated username as the common name,
 rather than the common name from the client cert.
 .\"*********************************************************
 .TP
-.B \-\-compat\-names [no\-remapping]
+.B \-\-compat\-names [no\-remapping] (DEPRECATED)
 Until OpenVPN v2.3 the format of the X.509 Subject fields was formatted
 like this:
 .IP
@@ -3467,17 +3467,20 @@ The
 mode flag can be used with the
 .B
 \-\-compat\-names
-option to be compatible with the now deprecated \-\-no\-name\-remapping feature
-present in older OpenVPN versions. When this mode flag is used, the Common Name,
+option to be compatible with the now deprecated \-\-no\-name\-remapping option.
+It is only available at the server. When this mode flag is used, the Common Name,
 Subject, and username strings are allowed to include any printable character
 including space, but excluding control characters such as tab, newline, and
-carriage-return.
+carriage-return. no-remapping is only available on the server side.
 
 .B Please note:
-This option will not be around for a long time.  It is only implemented
+This option is immediately deprecated.  It is only implemented
 to make the transition to the new formatting less intrusive.  It will be
-removed either in OpenVPN v2.4 or v2.5.  So please make sure you start
-the process to support the new formatting as soon as possible.
+removed either in OpenVPN v2.4 or v2.5.  So please make sure you use the
+.B \-\-verify-x509-name
+option instead of
+.B \-\-tls-remote
+as soon as possible and update your scripts where necessary.
 .\"*********************************************************
 .TP
 .B \-\-no\-name\-remapping (DEPRECATED)
@@ -3485,7 +3488,7 @@ The
 .B \-\-no\-name\-remapping
 option is an alias for
 .B \-\-compat\-names\ no\-remapping.
-It ensures compatibility with configurations using the
+It ensures compatibility with server configurations using the
 .B \-\-no\-name\-remapping
 option.
 
@@ -4671,11 +4674,11 @@ is available via the peer_cert environment variable.
 Field in x509 certificate subject to be used as username (default=CN).
 .B Fieldname
 will be uppercased before matching. When this option is used, the
---tls-remote option will match against the chosen fieldname instead
-of the CN.
+.B \-\-verify-x509-username
+option will match against the chosen fieldname instead of the CN.
 .\"*********************************************************
 .TP
-.B \-\-tls-remote name
+.B \-\-tls-remote name (DEPRECATED)
 Accept connections only from a host with X509 name
 or common name equal to
 .B name.
@@ -4707,6 +4710,55 @@ option to verify the remote host, because
 works in a
 .B \-\-chroot
 environment too.
+
+.B Please also note:
+This option is now deprecated.  It will be removed either in OpenVPN v2.4
+or v2.5.  So please make sure you support the new X.509 name formatting
+described with the
+.B \-\-compat-names
+option as soon as possible by updating your configurations to use
+.B \-\-verify-x509-name
+instead.
+.\"*********************************************************
+.TP
+.B \-\-verify-x509-name name type
+Accept connections only if a host's X.509 name is equal to
+.B name.
+The remote host must also pass all other tests of verification.
+
+Which X.509 name is compared to
+.B name
+depends on the setting of type.
+.B type
+can be "subject" to match the complete subject DN (default),
+"name" to match a subject RDN or "name-prefix" to match a subject RDN prefix.
+Which RDN is verified as name depends on the
+.B \-\-x509-username-field
+option. But it defaults to the common name (CN).
+
+.B \-\-verify-x509-name
+is a useful replacement for the
+.B \-\-tls-verify
+option to verify the remote host, because
+.B \-\-verify-x509-name
+works in a
+.B \-\-chroot
+environment too.
+
+If you want a client to only accept connections
+to "Server-1", "Server-2", etc., you can simply use
+.B \-\-verify-x509-name Server- name-prefix
+
+Using a name prefix is a useful alternative to managing
+a CRL (Certificate Revocation List) on the client, since it allows the client
+to refuse all certificates except for those associated
+with designated servers.
+
+.B NOTE:
+Test against a name prefix only when you are using OpenVPN with
+a custom CA certificate that is under your control.
+Never use this option with type "name-prefix" when your client certificates
+are signed by a third party, such as a commercial web CA.
 .\"*********************************************************
 .TP
 .B \-\-x509-track attribute
@@ -4744,7 +4796,7 @@ a man-in-the-middle attack where an authorized client
 attempts to connect to another client by impersonating the server.
 The attack is easily prevented by having clients verify
 the server certificate using any one of
-.B \-\-ns-cert-type, \-\-tls-remote,
+.B \-\-ns-cert-type, \-\-verify-x509-name,
 or
 .B \-\-tls-verify.
 .\"*********************************************************
@@ -4802,7 +4854,7 @@ a man-in-the-middle attack where an authorized client
 attempts to connect to another client by impersonating the server.
 The attack is easily prevented by having clients verify
 the server certificate using any one of
-.B \-\-remote-cert-tls, \-\-tls-remote,
+.B \-\-remote-cert-tls, \-\-verify-x509-name,
 or
 .B \-\-tls-verify.
 .\"*********************************************************
src/openvpn/init.c +3 -4
index 25d8225..979ba23 100644
@@ -2205,7 +2205,8 @@ do_init_crypto_tls (struct context *c, const unsigned int flags)
 
   to.verify_command = options->tls_verify;
   to.verify_export_cert = options->tls_export_cert;
-  to.verify_x509name = options->tls_remote;
+  to.verify_x509_type = (options->verify_x509_type & 0xff);
+  to.verify_x509_name = options->verify_x509_name;
   to.crl_file = options->crl_file;
   to.ssl_flags = options->ssl_flags;
   to.ns_cert_type = options->ns_cert_type;
@@ -2467,12 +2468,10 @@ do_option_warnings (struct context *c)
     warn_on_use_of_common_subnets ();
   if (o->tls_client
       && !o->tls_verify
-      && !o->tls_remote
+      && o->verify_x509_type == VERIFY_X509_NONE
       && !(o->ns_cert_type & NS_CERT_CHECK_SERVER)
       && !o->remote_cert_eku)
     msg (M_WARN, "WARNING: No server certificate verification method has been enabled.  See http://openvpn.net/howto.html#mitm for more info.");
-  if (o->tls_remote)
-    msg (M_WARN, "WARNING: Make sure you understand the semantics of --tls-remote before using it (see the man page).");
 #endif
 #endif
 
src/openvpn/options.c +82 -12

138 lines not on this page · raw message

src/openvpn/options.h +2 -1
index 306520b..d2ad94c 100644
@@ -506,8 +506,9 @@ struct options
   const char *pkcs12_file;
   const char *cipher_list;
   const char *tls_verify;
+  int verify_x509_type;
+  const char *verify_x509_name;
   const char *tls_export_cert;
-  const char *tls_remote;
   const char *crl_file;
 
   const char *ca_file_inline;
src/openvpn/ssl_common.h +2 -1
index cb259a9..c62294f 100644
@@ -245,7 +245,8 @@ struct tls_options
   /* cert verification parms */
   const char *verify_command;
   const char *verify_export_cert;
-  const char *verify_x509name;
+  int verify_x509_type;
+  const char *verify_x509_name;
   const char *crl_file;
   int ns_cert_type;
   unsigned remote_cert_ku[MAX_PARMS];
src/openvpn/ssl_verify.c +10 -5
index cac46e9..e651a8e 100644
@@ -369,16 +369,21 @@ verify_peer_cert(const struct tls_options *opt, openvpn_x509_cert_t *peer_cert,
 
 #endif /* OPENSSL_VERSION_NUMBER */
 
-  /* verify X509 name or common name against --tls-remote */
-  if (opt->verify_x509name && strlen (opt->verify_x509name) > 0)
+  /* verify X509 name or username against --verify-x509-[user]name */
+  if (opt->verify_x509_type != VERIFY_X509_NONE)
     {
-      if (strcmp (opt->verify_x509name, subject) == 0
-	  || strncmp (opt->verify_x509name, common_name, strlen (opt->verify_x509name)) == 0)
+      if ( (opt->verify_x509_type == VERIFY_X509_SUBJECT_DN
+            && strcmp (opt->verify_x509_name, subject) == 0)
+        || (opt->verify_x509_type == VERIFY_X509_SUBJECT_RDN
+            && strcmp (opt->verify_x509_name, common_name) == 0)
+        || (opt->verify_x509_type == VERIFY_X509_SUBJECT_RDN_PREFIX
+            && strncmp (opt->verify_x509_name, common_name,
+                        strlen (opt->verify_x509_name)) == 0) )
 	msg (D_HANDSHAKE, "VERIFY X509NAME OK: %s", subject);
       else
 	{
 	  msg (D_HANDSHAKE, "VERIFY X509NAME ERROR: %s, must be %s",
-	       subject, opt->verify_x509name);
+	       subject, opt->verify_x509_name);
 	  return FAILURE;		/* Reject connection */
 	}
     }
src/openvpn/ssl_verify.h +6 -0
index 1d20152..e0bcba4 100644
@@ -62,6 +62,12 @@ struct cert_hash_set {
   struct cert_hash *ch[MAX_CERT_DEPTH]; /**< Array of certificate hashes */
 };
 
+#define VERIFY_X509_NONE                0
+#define VERIFY_X509_SUBJECT_DN          1
+#define VERIFY_X509_SUBJECT_RDN         2
+#define VERIFY_X509_SUBJECT_RDN_PREFIX  3
+#define TLS_REMOTE_SUBJECT_DN           1 + 0x100
+#define TLS_REMOTE_SUBJECT_RDN_PREFIX   3 + 0x100
 
 #define TLS_AUTHENTICATION_SUCCEEDED  0
 #define TLS_AUTHENTICATION_FAILED     1
Signature · 1 line
1.7.9.5
#8 lore raw

Re: [Openvpn-devel] [PATCH 3/3] add new option for X.509 name verification

Am 22.02.13 10:44, schrieb Heiko Hund:

Quoted 6 lines

Add the option --verify-x509-name to provide the functionality of the now deprecated --tls-remote.

The new option accepts RFC 2253 subject DNs only and compares RDN or RDN prefix only if configured explicitly.

I looked through these and I think they are okay. Since most users don't know what RDN, RDN prefix and DN are an example like

A certificate with a DN CN=openvpn.example.com, OU=Avian IP Carriers, L=NRW would be matched by:

verify-x509-name "C=DE, OU=BLINKT, CN=openvpn.blinkt.de"

or

verify-x509-name openvpn.blinkt.de subject

or

verify-x509-name openvpn.bl name-prefix

Most user and certificates will probably use the second form with subject. I also think that for standard x509 certificates it may be a good option to also include name-suffix so you can do:

verify-x509-name .blinkt.de name-suffix

+ || (opt->verify_x509_type == VERIFY_X509_SUBJECT_RDN
+ && strcmp (opt->verify_x509_name, common_name) == 0)

+ || (opt->verify_x509_type == VERIFY_X509_SUBJECT_RDN_PREFIX
+ && strncmp (opt->verify_x509_name, common_name,
+ strlen (opt->verify_x509_name)) == 0) )

This is correct but it took me a while to understand that strcmp will compare the 0 btye in opt-verify_x509_name and strncmp with strln as length will not include the 0. The joys of C...

Arne

author
#9 lore raw

Re: [Openvpn-devel] [PATCH 3/3] add new option for X.509 name verification

Hi Arne,

Quoted 2 lines · On Wednesday 06 March 2013 22:38:56 Arne Schwabe wrote:

I looked through these and I think they are okay. Since most users don't know what RDN, RDN prefix and DN are an example like

I just sent a second version of 3/3 including examples in the man page, as you suggested.

Quoted 5 lines

Most user and certificates will probably use the second form with subject. I also think that for standard x509 certificates it may be a good option to also include name-suffix so you can do:

verify-x509-name .blinkt.de name-suffix

While this could be added, I'd rather wait until someone demands it strongly, as I think the "name-prefix" flags is of use for a very limited audience already and included mostly for compatibility with the --tls-remote feature set.

Thanks for the review!

Heiko

author
#10 lore raw

PATCH v2 3/3 add new option for X.509 name verification

In reply to Heiko Hund

Add the option --verify-x509-name to provide the functionality of the now deprecated --tls-remote.

The new option accepts RFC 2253 subject DNs only and compares RDN or RDN prefix only if configured explicitly.

---
 doc/openvpn.8            |   82 +++++++++++++++++++++++++++++++++-------
 src/openvpn/init.c       |    7 ++--
 src/openvpn/options.c    |   94 ++++++++++++++++++++++++++++++++++++++++------
 src/openvpn/options.h    |    3 +-
 src/openvpn/ssl_common.h |    3 +-
 src/openvpn/ssl_verify.c |   15 +++++---
 src/openvpn/ssl_verify.h |    6 +++
 7 files changed, 174 insertions(+), 36 deletions(-)
doc/openvpn.8 +69 -13
index 998f7ab..d590714 100644
@@ -3431,7 +3431,7 @@ the authenticated username as the common name,
 rather than the common name from the client cert.
 .\"*********************************************************
 .TP
-.B \-\-compat\-names [no\-remapping]
+.B \-\-compat\-names [no\-remapping] (DEPRECATED)
 Until OpenVPN v2.3 the format of the X.509 Subject fields was formatted
 like this:
 .IP
@@ -3467,17 +3467,20 @@ The
 mode flag can be used with the
 .B
 \-\-compat\-names
-option to be compatible with the now deprecated \-\-no\-name\-remapping feature
-present in older OpenVPN versions. When this mode flag is used, the Common Name,
+option to be compatible with the now deprecated \-\-no\-name\-remapping option.
+It is only available at the server. When this mode flag is used, the Common Name,
 Subject, and username strings are allowed to include any printable character
 including space, but excluding control characters such as tab, newline, and
-carriage-return.
+carriage-return. no-remapping is only available on the server side.
 
 .B Please note:
-This option will not be around for a long time.  It is only implemented
+This option is immediately deprecated.  It is only implemented
 to make the transition to the new formatting less intrusive.  It will be
-removed either in OpenVPN v2.4 or v2.5.  So please make sure you start
-the process to support the new formatting as soon as possible.
+removed either in OpenVPN v2.4 or v2.5.  So please make sure you use the
+.B \-\-verify-x509-name
+option instead of
+.B \-\-tls-remote
+as soon as possible and update your scripts where necessary.
 .\"*********************************************************
 .TP
 .B \-\-no\-name\-remapping (DEPRECATED)
@@ -3485,7 +3488,7 @@ The
 .B \-\-no\-name\-remapping
 option is an alias for
 .B \-\-compat\-names\ no\-remapping.
-It ensures compatibility with configurations using the
+It ensures compatibility with server configurations using the
 .B \-\-no\-name\-remapping
 option.
 
@@ -4671,11 +4674,11 @@ is available via the peer_cert environment variable.
 Field in x509 certificate subject to be used as username (default=CN).
 .B Fieldname
 will be uppercased before matching. When this option is used, the
---tls-remote option will match against the chosen fieldname instead
-of the CN.
+.B \-\-verify-x509-username
+option will match against the chosen fieldname instead of the CN.
 .\"*********************************************************
 .TP
-.B \-\-tls-remote name
+.B \-\-tls-remote name (DEPRECATED)
 Accept connections only from a host with X509 name
 or common name equal to
 .B name.
@@ -4707,6 +4710,59 @@ option to verify the remote host, because
 works in a
 .B \-\-chroot
 environment too.
+
+.B Please also note:
+This option is now deprecated.  It will be removed either in OpenVPN v2.4
+or v2.5.  So please make sure you support the new X.509 name formatting
+described with the
+.B \-\-compat-names
+option as soon as possible by updating your configurations to use
+.B \-\-verify-x509-name
+instead.
+.\"*********************************************************
+.TP
+.B \-\-verify-x509-name name type
+Accept connections only if a host's X.509 name is equal to
+.B name.
+The remote host must also pass all other tests of verification.
+
+Which X.509 name is compared to
+.B name
+depends on the setting of type.
+.B type
+can be "subject" to match the complete subject DN (default),
+"name" to match a subject RDN or "name-prefix" to match a subject RDN prefix.
+Which RDN is verified as name depends on the
+.B \-\-x509-username-field
+option. But it defaults to the common name (CN), e.g. a certificate with a
+subject DN "C=KG, ST=NA, L=Bishkek, CN=Server-1" would be matched by:
+
+.B \-\-verify-x509-name 'C=KG, ST=NA, L=Bishkek, CN=Server-1'
+and
+.B \-\-verify-x509-name Server-1 name
+or you could use
+.B \-\-verify-x509-name Server- name-prefix
+if you want a client to only accept connections to "Server-1", "Server-2", etc.
+
+.B \-\-verify-x509-name
+is a useful replacement for the
+.B \-\-tls-verify
+option to verify the remote host, because
+.B \-\-verify-x509-name
+works in a
+.B \-\-chroot
+environment without any dependencies.
+
+Using a name prefix is a useful alternative to managing
+a CRL (Certificate Revocation List) on the client, since it allows the client
+to refuse all certificates except for those associated
+with designated servers.
+
+.B NOTE:
+Test against a name prefix only when you are using OpenVPN with
+a custom CA certificate that is under your control.
+Never use this option with type "name-prefix" when your client certificates
+are signed by a third party, such as a commercial web CA.
 .\"*********************************************************
 .TP
 .B \-\-x509-track attribute
@@ -4744,7 +4800,7 @@ a man-in-the-middle attack where an authorized client
 attempts to connect to another client by impersonating the server.
 The attack is easily prevented by having clients verify
 the server certificate using any one of
-.B \-\-ns-cert-type, \-\-tls-remote,
+.B \-\-ns-cert-type, \-\-verify-x509-name,
 or
 .B \-\-tls-verify.
 .\"*********************************************************
@@ -4802,7 +4858,7 @@ a man-in-the-middle attack where an authorized client
 attempts to connect to another client by impersonating the server.
 The attack is easily prevented by having clients verify
 the server certificate using any one of
-.B \-\-remote-cert-tls, \-\-tls-remote,
+.B \-\-remote-cert-tls, \-\-verify-x509-name,
 or
 .B \-\-tls-verify.
 .\"*********************************************************
src/openvpn/init.c +3 -4
index 25d8225..979ba23 100644
@@ -2205,7 +2205,8 @@ do_init_crypto_tls (struct context *c, const unsigned int flags)
 
   to.verify_command = options->tls_verify;
   to.verify_export_cert = options->tls_export_cert;
-  to.verify_x509name = options->tls_remote;
+  to.verify_x509_type = (options->verify_x509_type & 0xff);
+  to.verify_x509_name = options->verify_x509_name;
   to.crl_file = options->crl_file;
   to.ssl_flags = options->ssl_flags;
   to.ns_cert_type = options->ns_cert_type;
@@ -2467,12 +2468,10 @@ do_option_warnings (struct context *c)
     warn_on_use_of_common_subnets ();
   if (o->tls_client
       && !o->tls_verify
-      && !o->tls_remote
+      && o->verify_x509_type == VERIFY_X509_NONE
       && !(o->ns_cert_type & NS_CERT_CHECK_SERVER)
       && !o->remote_cert_eku)
     msg (M_WARN, "WARNING: No server certificate verification method has been enabled.  See http://openvpn.net/howto.html#mitm for more info.");
-  if (o->tls_remote)
-    msg (M_WARN, "WARNING: Make sure you understand the semantics of --tls-remote before using it (see the man page).");
 #endif
 #endif
 
src/openvpn/options.c +82 -12

138 lines not on this page · raw message

src/openvpn/options.h +2 -1
index 306520b..d2ad94c 100644
@@ -506,8 +506,9 @@ struct options
   const char *pkcs12_file;
   const char *cipher_list;
   const char *tls_verify;
+  int verify_x509_type;
+  const char *verify_x509_name;
   const char *tls_export_cert;
-  const char *tls_remote;
   const char *crl_file;
 
   const char *ca_file_inline;
src/openvpn/ssl_common.h +2 -1
index cb259a9..c62294f 100644
@@ -245,7 +245,8 @@ struct tls_options
   /* cert verification parms */
   const char *verify_command;
   const char *verify_export_cert;
-  const char *verify_x509name;
+  int verify_x509_type;
+  const char *verify_x509_name;
   const char *crl_file;
   int ns_cert_type;
   unsigned remote_cert_ku[MAX_PARMS];
src/openvpn/ssl_verify.c +10 -5
index cac46e9..e651a8e 100644
@@ -369,16 +369,21 @@ verify_peer_cert(const struct tls_options *opt, openvpn_x509_cert_t *peer_cert,
 
 #endif /* OPENSSL_VERSION_NUMBER */
 
-  /* verify X509 name or common name against --tls-remote */
-  if (opt->verify_x509name && strlen (opt->verify_x509name) > 0)
+  /* verify X509 name or username against --verify-x509-[user]name */
+  if (opt->verify_x509_type != VERIFY_X509_NONE)
     {
-      if (strcmp (opt->verify_x509name, subject) == 0
-	  || strncmp (opt->verify_x509name, common_name, strlen (opt->verify_x509name)) == 0)
+      if ( (opt->verify_x509_type == VERIFY_X509_SUBJECT_DN
+            && strcmp (opt->verify_x509_name, subject) == 0)
+        || (opt->verify_x509_type == VERIFY_X509_SUBJECT_RDN
+            && strcmp (opt->verify_x509_name, common_name) == 0)
+        || (opt->verify_x509_type == VERIFY_X509_SUBJECT_RDN_PREFIX
+            && strncmp (opt->verify_x509_name, common_name,
+                        strlen (opt->verify_x509_name)) == 0) )
 	msg (D_HANDSHAKE, "VERIFY X509NAME OK: %s", subject);
       else
 	{
 	  msg (D_HANDSHAKE, "VERIFY X509NAME ERROR: %s, must be %s",
-	       subject, opt->verify_x509name);
+	       subject, opt->verify_x509_name);
 	  return FAILURE;		/* Reject connection */
 	}
     }
src/openvpn/ssl_verify.h +6 -0
index 1d20152..e0bcba4 100644
@@ -62,6 +62,12 @@ struct cert_hash_set {
   struct cert_hash *ch[MAX_CERT_DEPTH]; /**< Array of certificate hashes */
 };
 
+#define VERIFY_X509_NONE                0
+#define VERIFY_X509_SUBJECT_DN          1
+#define VERIFY_X509_SUBJECT_RDN         2
+#define VERIFY_X509_SUBJECT_RDN_PREFIX  3
+#define TLS_REMOTE_SUBJECT_DN           1 + 0x100
+#define TLS_REMOTE_SUBJECT_RDN_PREFIX   3 + 0x100
 
 #define TLS_AUTHENTICATION_SUCCEEDED  0
 #define TLS_AUTHENTICATION_FAILED     1
Signature · 1 line
1.7.9.5
#11 lore raw

Re: [Openvpn-devel] [PATCH 3/3 v2] add new option for X.509 name verification

Am 07.03.13 16:36, schrieb Heiko Hund:

Quoted 5 lines

Add the option --verify-x509-name to provide the functionality of the now deprecated --tls-remote.

The new option accepts RFC 2253 subject DNs only and compares RDN or RDN prefix only if configured explicitly.

ACK to man page changes. ACK to the rest of the patch if unchanged.

Arne

#12 lore raw

[Openvpn-devel] [PATCH applied] Re: add new option for X.509 name verification

In reply to Heiko Hund

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

commit 9f0fc745664fd0fc6a1c6785e101bf912088db16 (master) commit f6e12862cefd054eb1a44c18ea1dfb4cba7d007a (release/2.3)

Author: Heiko Hund
Date:   Thu Mar 7 16:36:41 2013 +0100
     add new option for X.509 name verification

     Signed-off-by: Heiko Hund <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: [email protected]...
     URL: http://article.gmane.org/gmane.network.openvpn.devel/7376
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#13 lore raw
In reply to Heiko Hund

Hi,

Quoted 4 lines · Heiko Hund

This patch set tries to do X.509 name verification right. As discussed during FOSDEM 2013, changing --tls-remote to support RFC 2253 style subject DNs only was too radical as it broke more configurations than expected.

Acked by Arne, now all committed and pushed.

(I have reviewed the code as well, and even test compiled the trees before pushing them :-) - so not just relying on the ACK)

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...