use extv3 extensions such as subjectAltName as common_name
Hi,
attached is a patch which allows using the extv3 extension of a certificate as common name with email address.
Email addresses are more likely to be unique than the common name, and the environment forced me to use the subjectAltName extv3 extension for authentication. So, there is already a need for this.
The patch extends the x509_username_field. If the username field is prefixed with ext: the value of the field is not uppercased and the remaining part of the option is used as fieldname for the extv3 extension.
So for example:
x509-username-field ext:subjectAltName
extracts the email address here.
Extending the code to extract other types than GEN_EMAIL from the extensions is possible, so it could even be used to match on other fields than subjectAltName with other data than an email address.
Given we have to use this code anyway, I'd be glad if it could get merged into trunk, so we do not rely on special builds in the long run. Therefore I'm glad to step in, if further final touches are required to get this merged.
MfG
Markus
allow extracting the common name from extrv3 fields, for example altSubjectName for email
options.c +1 -0
@@ -5904,6 +5904,7 @@ {char *s = p[1 ];VERIFY_PERMISSION (OPT_P_GENERAL ); +if (strncmp ("ext:" ,s,4 ) !=0 )while ((*s =toupper (*s)) !='\0' ) s++;/* Uppercase if necessary */ options->x509_username_field = p[1 ]; }
ssl.c +66 -0
78 lines not on this page · raw message
Am 24.11.2010 16:00, schrieb Markus Koetter:
Quoted 8 lines
Hi,
attached is a patch which allows using the extv3 extension of a certificate as common name with email address.
Email addresses are more likely to be unique than the common name, and the environment forced me to use the subjectAltName extv3 extension for authentication.
So, there is already a need for this.
NAK on the patch:
1. unsafe use of strncpy (remember that strncpy does not NUL terminate if there's no room!), and
2. without reading ASN1_STRING_to_UTF8() docs, I do not believe that the ASN extraction is safe in itself. There is no check for embedded NULs, and this needs to be checked whenever you convert between NUL-terminated C-strings and pointer/length strings and vice versa. There have been prior vulnerabilities, such as CVE-2009-2666.
Make sure that the extraction reports failure (aka "return false;") and the caller deals with that in case there are embedded NULs, IOW strlen() != ia5.size.
For safer example code, see, for instance, the strlen vs. length comparison at
<http://gitorious.org/fetchmail/fetchmail/blobs/846ffbb938c7ecf6819a5c3b844adf306bf87f02/socket.c#line682>
Signature · 1 line
Matthias Andree
Am 30.11.2010 16:50, schrieb Matthias Andree:
Quoted 2 lines
Make sure that the extraction reports failure (aka "return false;") and the caller deals with that in case there are embedded NULs, IOW
strlen()!= ia5.size.
That ia5.size should be read as "ia5->length". Sorry for the confusion.
Signature · 1 line
Matthias Andree
Hi,
Quoted 4 lines · Matthias Andree
NAK on the patch:
1. unsafe use of strncpy (remember that strncpy does not NUL terminate if there's no room!), and
You are right, I just noticed the existence of strcpynt for this purpose.
Quoted 5 lines
2. without reading
ASN1_STRING_to_UTF8()docs, I do not believe that the ASN extraction is safe in itself. There is no check for embedded NULs, and this needs to be checked whenever you convert between NUL-terminated C-strings and pointer/length strings and vice versa. There have been prior vulnerabilities, such as CVE-2009-2666.
You are right - same problem holds true for extract_x509_field_ssl, setenv_x509?
http://openvpn.git.sourceforge.net/git/gitweb.cgi?p=openvpn/openvpn-testing.git;a=blob;f=ssl.c;h=a1268ac2a9291dc1512fa28e3ab4efc65085c952;hb=HEAD#l453
Quoted 2 lines
Make sure that the extraction reports failure (aka "return false;") and the caller deals with that in case there are embedded NULs, IOW
strlen()!= ia5.size.
Given the fetchmail ref, seems like the value returned by X509_get_ext_d2i needs to be freed with sk_GENERAL_NAME_free afterwards anyway.
Attached is an updated version of the patch using remotes/origin/feat_misc as base.
Thanks for reviewing.
Markus
From c750625294b4680ac8a8f2c7216f3796631bbbcb Mon Sep 17 00:00:00 2001
From: Markus Koetter <[email protected]...>
Date: Wed, 1 Dec 2010 22:03:27 +0100
Subject: [PATCH] x509-username-field - add extv3 support
- this allows using altSubjectName of the certificate
to be used for authentication. To use, set x509-username-field ext:altSubjectName
--- options.c | 3 +- ssl.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletions(-)
options.c +2 -1
@@ -5647,7 +5647,8 @@ add_option (struct options *options, {char *s = p[1 ];VERIFY_PERMISSION (OPT_P_GENERAL ); -while ((*s =toupper (*s)) !='\0' ) s++;/* Uppercase if necessary */ +if (strncmp ("ext:" ,s,4 ) !=0 ) +while ((*s =toupper (*s)) !='\0' ) s++;/* Uppercase if necessary */ options->x509_username_field = p[1 ]; }#endif /* USE_SSL */
ssl.c +74 -0
86 lines not on this page · raw message
Signature · 1 line
1.6.3.3