Do not upcase x509-username-field for mixed-case arguments.
A message that is not in the archive (sent off-list or not yet received): [email protected]...
PATCH 1/1 Do not upcase x509-username-field for mixed-case arguments.
Hi,
The patch below is extracted from Andris Kalnozols' version 2 patch in trac ticket #402, annotated with some comments from me.
The functionality this patch provides makes sense to me, and fixes faulty behaviour in both the release/2.3 and master branches. I think a final version of this patch should be applied to both branches.
The options parsing code contains some magic, so I guessed it would be the easiest for everyone if I just proposed a new version myself that takes care of my comments. You'll find that attached. That version skips the string copy at the expense of the reported error, which now only reports the upcased x509-username-field, instead of both the original and upcased value.
Andris, could you maybe test this patch and reports whether it indeed works as expected for you?
Quoted 89 lines · Andris Kalnozols
From: Andris Kalnozols <[email protected]...>
I revisited
options.cto refine its brute-force upcasing behavior. Now, the upcasing is done only if the option argument is all lowercase. Mixed-case arguments and those with the "ext:" prefix are left unchanged. This preserves the original intent of the "helpful" upcasing feature for backwards compatibility while limiting its scope in a straightforward way.Signed-off-by Andris Kalnozols <[email protected]...>--- doc/openvpn.8 | 44 ++++++++++++++++++++++++++++++++++++++------ src/openvpn/options.c | 29 +++++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 10 deletions(-)doc/openvpn.8 +38
-6@@ -4745,12 +4745,44 @@ the tls-verify script returns. The file name used for the certificate is available via the peer_cert environment variable. .\"********************************************************* .TP -.B \-\-x509-username-field fieldname -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 -.B \-\-verify-x509-username -option will match against the chosen fieldname instead of the CN. +.B \-\-x509-username-field [ext:\]fieldname +Field in the X.509 certificate subject to be used as the username (default=CN). +Typically, this option is specified with +.B fieldname +as either of the following: + +.B \-\-x509-username-field +emailAddress +.br +.B \-\-x509-username-field ext:\fRsubjectAltName + +The first example uses the value of the "emailAddress" attribute in the +certificate's Subject field as the username. The second example uses +the +.B ext: +prefix to signify that the X.509 extension +.B fieldname +"subjectAltName" be searched for an rfc822Name (email) field to be used +as the username. In cases where there are multiple email addresses +in +.B ext:fieldname\fR, +the last occurrence is chosen. + +When this option is used, the +.B \-\-verify-x509-name +option will match against the chosen +.B fieldname +instead of the Common Name. + +.B Please note: +This option has a feature which will convert an all-lowercase +.B fieldname +to uppercase characters, e.g., ou -> OU. A mixed-case +.B fieldname +or one having the +.B ext: +prefix will be left as-is. This automatic upcasing feature +is deprecated and will be removed in a future release. .\"********************************************************* .TP .B \-\-tls-remote name (DEPRECATED)src/openvpn/options.c +3
-2@@ -577,8 +577,8 @@ static const char usage_message[] = " and optionally the root CA certificate.\n"#endif #ifdef ENABLE_X509ALTUSERNAME -"--x509-username-field : Field used in x509 certificate to be username.\n" - " Default is CN.\n" +"--x509-username-field : Field in x509 certificate containing the username.\n" + " Default is CN in the Subject field.\n"#endif "--verify-hash : Specify SHA1 fingerprint for level-1 cert.\n" #ifdef WIN32@@ -6875,10 +6875,31 @@ add_option (struct options *options,#ifdef ENABLE_X509ALTUSERNAME else if (streq (p[0], "x509-username-field") && p[1]) { +/* This option also introduced a feature to automatically upcase the
src/openvpn/options.c add_option (struct options *options, · line 6888
Quoted 10 lines
src/openvpn/options.c +9
-0+* fieldname passed as the option argument, e.g., "ou" became "OU". +* Fine-tune this "helpfulness" by only upcasing Subject field +* attribute names which consist of all lower-case characters. +* Mixed-case attributes such as "emailAddress" are left as-is. +* An option parameter having the "ext:" prefix for matching +* X.509v3 extended fields will also remain unchanged. +*/ char *s = p[1 ]; +char *l; +char lowercase_name[OPTION_PARM_SIZE ] = {0 };
Although this seems reasonable, OPTION_PARM_SIZE actually isn't the maximum length of p[1]; parameters supplied on the command line can be larger then this.
src/openvpn/options.c add_option (struct options *options, · line 6893
Quoted 7 lines
src/openvpn/options.c +4
-2+VERIFY_PERMISSION (OPT_P_GENERAL ); -if (strncmp ("ext:" ,s,4 ) !=0 ) -while ((*s =toupper (*s)) !='\0' ) s++;/* Uppercase if necessary */ +if (strncmp ("ext:" , s,4 ) !=0 ) + { +strncpy (lowercase_name, s,strlen (s));
This actually is a strcpy(lowercase_name, s) that doesn't copy the trailing '\0'. In combination with a p[1] that is larger than OPTION_PARM_SIZE, this will still happily do an out-of-bounds write.
src/openvpn/options.c add_option (struct options *options, · line 6905
Quoted 13 lines
src/openvpn/options.c +9
-0+ l = lowercase_name; +while ((*l =tolower (*l)) !='\0' ) l++; +if (strncmp (s, lowercase_name,strlen (s)) ==0 ) + { +while ((*s =toupper (*s)) !='\0' ) s++; +msg (M_WARN ,"DEPRECATED FEATURE: automatically upcased the --x509-username-field parameter from '%s' to '%s'; please update your configuration" , + lowercase_name, p[1 ]); + } + } options->x509_username_field = p[1 ]; }#endif /* ENABLE_X509ALTUSERNAME */
From f2e747b448cb2ae140d0f5c305c07239d1608f86 Mon Sep 17 00:00:00 2001
From: Andris Kalnozols <[email protected]...>
Date: Sat, 28 Jun 2014 19:41:02 +0200
Subject: [PATCH 1/2] Do not upcase x509-username-field for mixed-case
arguments.
I revisited options.c to refine its brute-force upcasing behavior. Now, the upcasing is done only if the option argument is all lowercase. Mixed-case arguments and those with the "ext:" prefix are left unchanged. This preserves the original intent of the "helpful" upcasing feature for backwards compatibility while limiting its scope in a straightforward way.
--- doc/openvpn.8 | 44 ++++++++++++++++++++++++++++++++++++++------ src/openvpn/options.c | 26 ++++++++++++++++++++++---- 2 files changed, 60 insertions(+), 10 deletions(-)
doc/openvpn.8 +38 -6
@@ -4745,12 +4745,44 @@ the tls-verify script returns. The file name used for the certificate is available via the peer_cert environment variable. .\"********************************************************* .TP -.B \-\-x509-username-field fieldname -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 -.B \-\-verify-x509-username -option will match against the chosen fieldname instead of the CN. +.B \-\-x509-username-field [ext:\]fieldname +Field in the X.509 certificate subject to be used as the username (default=CN). +Typically, this option is specified with +.B fieldname +as either of the following: + +.B \-\-x509-username-field +emailAddress +.br +.B \-\-x509-username-field ext:\fRsubjectAltName + +The first example uses the value of the "emailAddress" attribute in the +certificate's Subject field as the username. The second example uses +the +.B ext: +prefix to signify that the X.509 extension +.B fieldname +"subjectAltName" be searched for an rfc822Name (email) field to be used +as the username. In cases where there are multiple email addresses +in +.B ext:fieldname\fR, +the last occurrence is chosen. + +When this option is used, the +.B \-\-verify-x509-name +option will match against the chosen +.B fieldname +instead of the Common Name. + +.B Please note: +This option has a feature which will convert an all-lowercase +.B fieldname +to uppercase characters, e.g., ou -> OU. A mixed-case +.B fieldname +or one having the +.B ext: +prefix will be left as-is. This automatic upcasing feature +is deprecated and will be removed in a future release. .\"********************************************************* .TP .B \-\-tls-remote name (DEPRECATED)
src/openvpn/options.c +22 -4
@@ -577,8 +577,8 @@ static const char usage_message[] = " and optionally the root CA certificate.\n"#endif #ifdef ENABLE_X509ALTUSERNAME -"--x509-username-field : Field used in x509 certificate to be username.\n" - " Default is CN.\n" +"--x509-username-field : Field in x509 certificate containing the username.\n" + " Default is CN in the Subject field.\n"#endif "--verify-hash : Specify SHA1 fingerprint for level-1 cert.\n" #ifdef WIN32
@@ -6875,10 +6875,28 @@ add_option (struct options *options,#ifdef ENABLE_X509ALTUSERNAME else if (streq (p[0], "x509-username-field") && p[1]) { +/* This option used to automatically upcase the fieldname passed as the +* option argument, e.g., "ou" became "OU". Now, this "helpfulness" is +* fine-tuned by only upcasing Subject field attribute names which consist +* of all lower-case characters. Mixed-case attributes such as +* "emailAddress" are left as-is. An option parameter having the "ext:" +* prefix for matching X.509v3 extended fields will also remain unchanged. +*/ char *s = p[1 ]; +VERIFY_PERMISSION (OPT_P_GENERAL ); -if (strncmp ("ext:" ,s,4 ) !=0 ) -while ((*s =toupper (*s)) !='\0' ) s++;/* Uppercase if necessary */ +if (strncmp ("ext:" , s,4 ) !=0 ) + { +size_t i =0 ; +while (s[i] && !isupper (s[i])) i++; +if (strlen (s) == i) + { +while ((*s =toupper (*s)) !='\0' ) s++; +msg (M_WARN ,"DEPRECATED FEATURE: automatically upcased the " +"--x509-username-field parameter to '%s'; please update your" +"configuration" , p[1 ]); + } + } options->x509_username_field = p[1 ]; }#endif /* ENABLE_X509ALTUSERNAME */
Signature · 1 line
1.9.1
Am 30.06.14 21:43, schrieb Steffan Karger:
Quoted 16 lines
Hi,
The patch below is extracted from Andris Kalnozols' version 2 patch in trac ticket #402, annotated with some comments from me.
The functionality this patch provides makes sense to me, and fixes faulty behaviour in both the release/2.3 and master branches. I think a final version of this patch should be applied to both branches.
The options parsing code contains some magic, so I guessed it would be the easiest for everyone if I just proposed a new version myself that takes care of my comments. You'll find that attached. That version skips the string copy at the expense of the reported error, which now only reports the upcased x509-username-field, instead of both the original and upcased value.
Quoted 5 lines
Andris, could you maybe test this patch and reports whether it indeed works as expected for you?
On 28-06-14 21:19, Andris Kalnozols wrote:
ACK. Looks sane.
Arne
Thanks, Steffan, for the comments and code cleanup. Your method is definitely safer and has less clutter. I tested your version and it works as intended.
Regarding the "ext:" argument prefix, I had submitted an enhanced version of extract_x509_extension() mainly for more helpful log messages. If it doesn't pass muster, then I would suggest that this function be at least changed as follows:
}
break;
default:
- msg (D_TLS_ERRORS, "ASN1 ERROR: can not handle field
type %i",
+ msg (D_TLS_DEBUG, "Ignoring name field type %i",
name->type);
break;
}I don't see the need for alarm if an extension field has additional GeneralName field types other than "email".
------
Andris
Quoted 163 lines · Steffan Karger
Hi,
The patch below is extracted from Andris Kalnozols' version 2 patch in trac ticket #402, annotated with some comments from me.
The functionality this patch provides makes sense to me, and fixes faulty behaviour in both the release/2.3 and master branches. I think a final version of this patch should be applied to both branches.
The options parsing code contains some magic, so I guessed it would be the easiest for everyone if I just proposed a new version myself that takes care of my comments. You'll find that attached. That version skips the string copy at the expense of the reported error, which now only reports the upcased x509-username-field, instead of both the original and upcased value.
Andris, could you maybe test this patch and reports whether it indeed works as expected for you?
Quoted 89 lines · Andris Kalnozols
From: Andris Kalnozols <[email protected]...>
I revisited
options.cto refine its brute-force upcasing behavior. Now, the upcasing is done only if the option argument is all lowercase. Mixed-case arguments and those with the "ext:" prefix are left unchanged. This preserves the original intent of the "helpful" upcasing feature for backwards compatibility while limiting its scope in a straightforward way.Signed-off-by Andris Kalnozols <[email protected]...>--- doc/openvpn.8 | 44 ++++++++++++++++++++++++++++++++++++++------ src/openvpn/options.c | 29 +++++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 10 deletions(-)doc/openvpn.8 +38
-6@@ -4745,12 +4745,44 @@ the tls-verify script returns. The file name used for the certificate is available via the peer_cert environment variable. .\"********************************************************* .TP -.B \-\-x509-username-field fieldname -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 -.B \-\-verify-x509-username -option will match against the chosen fieldname instead of the CN. +.B \-\-x509-username-field [ext:\]fieldname +Field in the X.509 certificate subject to be used as the username (default=CN). +Typically, this option is specified with +.B fieldname +as either of the following: + +.B \-\-x509-username-field +emailAddress +.br +.B \-\-x509-username-field ext:\fRsubjectAltName + +The first example uses the value of the "emailAddress" attribute in the +certificate's Subject field as the username. The second example uses +the +.B ext: +prefix to signify that the X.509 extension +.B fieldname +"subjectAltName" be searched for an rfc822Name (email) field to be used +as the username. In cases where there are multiple email addresses +in +.B ext:fieldname\fR, +the last occurrence is chosen. + +When this option is used, the +.B \-\-verify-x509-name +option will match against the chosen +.B fieldname +instead of the Common Name. + +.B Please note: +This option has a feature which will convert an all-lowercase +.B fieldname +to uppercase characters, e.g., ou -> OU. A mixed-case +.B fieldname +or one having the +.B ext: +prefix will be left as-is. This automatic upcasing feature +is deprecated and will be removed in a future release. .\"********************************************************* .TP .B \-\-tls-remote name (DEPRECATED)src/openvpn/options.c +3
-2@@ -577,8 +577,8 @@ static const char usage_message[] = " and optionally the root CA certificate.\n"#endif #ifdef ENABLE_X509ALTUSERNAME -"--x509-username-field : Field used in x509 certificate to be username.\n" - " Default is CN.\n" +"--x509-username-field : Field in x509 certificate containing the username.\n" + " Default is CN in the Subject field.\n"#endif "--verify-hash : Specify SHA1 fingerprint for level-1 cert.\n" #ifdef WIN32@@ -6875,10 +6875,31 @@ add_option (struct options *options,#ifdef ENABLE_X509ALTUSERNAME else if (streq (p[0], "x509-username-field") && p[1]) { +/* This option also introduced a feature to automatically upcase the src/openvpn/options.c add_option (struct options *options, · line 6888
Quoted 10 lines
src/openvpn/options.c +9
-0+* fieldname passed as the option argument, e.g., "ou" became "OU". +* Fine-tune this "helpfulness" by only upcasing Subject field +* attribute names which consist of all lower-case characters. +* Mixed-case attributes such as "emailAddress" are left as-is. +* An option parameter having the "ext:" prefix for matching +* X.509v3 extended fields will also remain unchanged. +*/ char *s = p[1 ]; +char *l; +char lowercase_name[OPTION_PARM_SIZE ] = {0 };Although this seems reasonable,
OPTION_PARM_SIZEactually isn't the maximum length of p[1]; parameters supplied on the command line can be larger then this.src/openvpn/options.c add_option (struct options *options,
Quoted 7 lines
src/openvpn/options.c +4
-2+VERIFY_PERMISSION (OPT_P_GENERAL ); -if (strncmp ("ext:" ,s,4 ) !=0 ) -while ((*s =toupper (*s)) !='\0' ) s++;/* Uppercase if necessary */ +if (strncmp ("ext:" , s,4 ) !=0 ) + { +strncpy (lowercase_name, s,strlen (s));This actually is a
strcpy(lowercase_name, s)that doesn't copy the trailing '\0'. In combination with a p[1] that is larger thanOPTION_PARM_SIZE, this will still happily do an out-of-bounds write.Quoted 27 lines
src/openvpn/options.c +9
-1+ l = lowercase_name; +while ((*l =tolower (*l)) !='\0' ) l++; +if (strncmp (s, lowercase_name,strlen (s)) ==0 ) + { +while ((*s =toupper (*s)) !='\0' ) s++; +msg (M_WARN ,"DEPRECATED FEATURE: automatically upcased the --x509-username-field parameter from '%s' to '%s'; please update your configuration" , + lowercase_name, p[1 ]); + } + } options->x509_username_field = p[1 ]; }#endif /* ENABLE_X509ALTUSERNAME */ ------------------------------------------------------------------------------Open source business process management suite built on Java and Eclipse Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Hi,
Quoted 3 lines · Andris
Thanks, Steffan, for the comments and code cleanup. Your method is definitely safer and has less clutter. I tested your version and it works as intended.
Great, let's get the patch into git then.
Quoted 15 lines
Regarding the "ext:" argument prefix, I had submitted an enhanced version of
extract_x509_extension()mainly for more helpful log messages. If it doesn't pass muster, then I would suggest that this function be at least changed as follows:} break; default: - msg (D_TLS_ERRORS, "ASN1 ERROR: can not handle field type %i", + msg (D_TLS_DEBUG, "Ignoring name field type %i", name->type); break; }
Quoted 2 lines
I don't see the need for alarm if an extension field has additional GeneralName field types other than "email".
Yeah, I simply didn't yet get to reviewing the extract_x509_extension() patch, but I will get to that. I'm all in favour of more helpful log messages. Just pushed it forward because it wasn't needed to fix a bug :) I'll get back to you!
-Steffan
Hi Andris
Quoted 3 lines · Andris
Regarding the "ext:" argument prefix, I had submitted an enhanced version of
extract_x509_extension()mainly for more helpful log messages.
I finally had some time to look at those changes (for other, see
https://community.openvpn.net/openvpn/ticket/402 for the patch), but while figuring out the impact of the changes, I managed to make it segfault by running
openvpn --config sample-config-files/loopback-server --x509-username-field "ext:authorityKeyIdentifier"
and make a client connect using
openvpn --config sample-config-files/loopback-client
The culprit was in i2v_GENERAL_NAMES(), but I decided not to dive in any further and go for your second option:
Quoted 13 lines
If it doesn't pass muster, then I would suggest that this function be at least changed as follows:
} break; default: - msg (D_TLS_ERRORS, "ASN1 ERROR: can not handle field type %i", + msg (D_TLS_DEBUG, "Ignoring name field type %i", name->type); break; }
Quoted 2 lines
I don't see the need for alarm if an extension field has additional GeneralName field types other than "email".
I completely agree. Attached a patch that does just that. I changed the message a bit, but I guess I can still ACK this. So, ACK :)
-Steffan
From 6170243b318cade1ca905e4a3b7a62faaeada755 Mon Sep 17 00:00:00 2001
From: Andris Kalnozols <[email protected]...>
Date: Sun, 10 Aug 2014 00:40:44 +0200
Subject: [PATCH] extract_x509_extension(): hide status message during normal
operation.
For each recognized extension in a certificate, extract_x509_extension() would issue an "ASN1 ERROR: can not handle field type" debug message at verb 2. Reduce that to verb 9 (D_TLS_ERRORS -> D_TLS_DEBUG) and alter the message text accordingly.
--- src/openvpn/ssl_verify_openssl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
src/openvpn/ssl_verify_openssl.c +2 -2
@@ -140,8 +140,8 @@ bool extract_x509_extension(X509 *cert, char *fieldname, char *out, int size) }break ;default : -msg (D_TLS_ERRORS ,"ASN1 ERROR: can not handle field type %i" , - name->type); +msg (D_TLS_DEBUG ,"%s: ignoring general name field type %i" , + __func__, name->type);break ; } }
Signature · 1 line
1.9.1
[Openvpn-devel] [PATCH applied] Re: extract_x509_extension(): hide status message during normal operation.
ACK. (Look sane, and basically it's acked-by: Steffan anyway, but since he decided to put a signed-off-by: on it, I'm now formally ACKing it)
Your patch has been applied to the master branch.
commit ed5a400e138812cd6572845f4299f61e12716f53
Author: Andris Kalnozols Date: Sun Aug 10 00:40:44 2014 +0200
extract_x509_extension(): hide status message during normal operation.
Signed-off-by: Andris Kalnozols <[email protected]...>
Signed-off-by: Steffan Karger <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8981
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Your patch has been applied to the master and release/2.3 branches.
commit f4e0ad82b0eaccce965074c1ceec2b7e3853dc0d (master) commit a2da658ba6aa34043d87226c3f971474942e0bed (release/2.3)
Author: Andris Kalnozols Date: Sat Jun 28 19:41:02 2014 +0200
Do not upcase x509-username-field for mixed-case arguments.
Signed-off-by: Andris Kalnozols <[email protected]...>
Signed-off-by: Steffan Karger <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Message-Id: <[email protected]...>
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering