UTF-8 X.509 distinguished names
PATCH 1/1 UTF-8 X.509 distinguished names
The UTF-8 support that came with commit 2627335 does allow international usernames and passwords. This patch introduces UTF-8 support for X.509 DNs. Additionally, instead of using the legacy openssl format, DNs are now displayed in RFC 2253 format; "/C=ru/L=\xD0\x9C\xD0\xBE\xD1\x81\xD0\xBA\xD0 \xB2\xD0\xB0/O=\xD0\x9A\xD1\x80\xD0\xB5\xD0\xBC\xD0\xBB\xD1\x8C/CN=kreml.ru" becomes "C=ru, L=Москва, O=Кремль, CN=kreml.ru".
Since the specific character classes for X.509 names are removed, the "no-name-remapping" configuration option has no use anymore and is removed as well.
--- openvpn.8 | 23 +---------------------- options.c | 12 +----------- pkcs11_openssl.c | 2 +- sample-scripts/verify-cn | 6 +++--- ssl_verify.c | 45 +++++++++------------------------------------ ssl_verify_openssl.c | 40 ++++++++++++++++++++++++++++++++++++++-- ssl_verify_openssl.h | 2 ++ 7 files changed, 55 insertions(+), 75 deletions(-)
openvpn.8 +1 -22
@@ -3322,27 +3322,6 @@ the authenticated username as the common name, rather than the common name from the client cert. .\"********************************************************* .TP -.B \-\-no-name-remapping -Allow Common Name, X509 Subject, and username strings to include -any printable character including space, but excluding control -characters such as tab, newline, and carriage-return. - -By default, OpenVPN will remap -any character other than alphanumeric, underbar ('_'), dash -('-'), dot ('.'), and slash ('/') to underbar ('_'). The X509 -Subject string as returned by the -.B tls_id -environmental variable, can additionally contain colon (':') or -equal ('='). - -While name remapping is performed for security reasons to reduce -the possibility of introducing string expansion security vulnerabilities -in user-defined authentication -scripts, this option is provided for those cases where it is desirable to -disable the remapping feature. Don't use this option unless you -know what you are doing! -.\"********************************************************* -.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
@@ -4463,7 +4442,7 @@ When .B cmd is executed two arguments are appended, as follows: -.B cmd certificate_depth X509_NAME_oneline +.B cmd certificate_depth subject These arguments are, respectively, the current certificate depth and the X509 common name (cn) of the peer.
options.c +1 -11
@@ -601,7 +601,7 @@ static const char usage_message[] =" pending TLS connection that has otherwise passed all other\n" " tests of certification. cmd should return 0 to allow\n" " TLS handshake to proceed, or 1 to fail. (cmd is\n" -" executed as 'cmd certificate_depth X509_NAME_oneline')\n" +" executed as 'cmd certificate_depth subject')\n" "--tls-export-cert [directory] : Get peer cert in PEM format and store it \n" " in an openvpn temporary file in [directory]. Peer cert is \n" " stored before tls-verify script execution and deleted after.\n"
@@ -2164,9 +2164,6 @@ options_postprocess_verify_ce (const struct options *options, const struct conneif ((options->ssl_flags &SSLF_AUTH_USER_PASS_OPTIONAL ) && !ccnr)msg (M_USAGE ,"--auth-user-pass-optional %s" , postfix); } - -if ((options->ssl_flags &SSLF_NO_NAME_REMAPPING ) && script_method ==SM_SYSTEM ) -msg (M_USAGE ,"--script-security method='system' cannot be combined with --no-name-remapping" ); }else {
@@ -2201,8 +2198,6 @@ options_postprocess_verify_ce (const struct options *options, const struct connemsg (M_USAGE ,"--username-as-common-name requires --mode server" );if (options->ssl_flags &SSLF_AUTH_USER_PASS_OPTIONAL )msg (M_USAGE ,"--auth-user-pass-optional requires --mode server" ); -if (options->ssl_flags &SSLF_NO_NAME_REMAPPING ) -msg (M_USAGE ,"--no-name-remapping requires --mode server" );if (options->ssl_flags &SSLF_OPT_VERIFY )msg (M_USAGE ,"--opt-verify requires --mode server" );if (options->server_flags &SF_TCP_NODELAY_HELPER )
@@ -5581,11 +5576,6 @@ add_option (struct options *options,VERIFY_PERMISSION (OPT_P_GENERAL ); options->ssl_flags |=SSLF_AUTH_USER_PASS_OPTIONAL ; } -else if (streq (p[0 ],"no-name-remapping" )) - { -VERIFY_PERMISSION (OPT_P_GENERAL ); - options->ssl_flags |=SSLF_NO_NAME_REMAPPING ; - }else if (streq (p[0 ],"opt-verify" )) {VERIFY_PERMISSION (OPT_P_GENERAL );
pkcs11_openssl.c +1 -1
@@ -129,7 +129,7 @@ pkcs11_certificate_dn (pkcs11h_certificate_t certificate, char *dn, goto cleanup; } -X509_NAME_oneline (X509_get_subject_name (x509), dn, dn_len); +_openssl_get_subject (x509, dn, dn_len); ret =0 ;
sample-scripts/verify-cn +3 -3
@@ -3,7 +3,7 @@ # verify-cn -- a sample OpenVPN tls-verify script # # Return 0 if cn matches the common name component of -# X509_NAME_oneline, 1 otherwise. +# subject, 1 otherwise. # # For example in OpenVPN, you could use the directive: #
@@ -13,7 +13,7 @@ # the client common name is listed on a line in the # allowed_clients file. -die "usage: verify-cn cnfile certificate_depth X509_NAME_oneline" if (@ARGV != 3); +die "usage: verify-cn cnfile certificate_depth subject" if (@ARGV != 3); # Parse out arguments: # cnfile -- The file containing the list of common names, one per
@@ -37,7 +37,7 @@ if ($depth == 0) { # If so, parse out the common name substring in # the X509 subject string. - if ($x509 =~ /\/CN=([^\/]+)/) { + if ($x509 =~ / CN=([^,]+)/) { $cn = $1; # Accept the connection if the X509 common name # string matches the passed cn argument.
ssl_verify.c +9 -36
128 lines not on this page · raw message
ssl_verify_openssl.c +38 -2
@@ -247,16 +247,52 @@ x509_free_sha1_hash (unsigned char *hash) }char * +_openssl_get_subject (X509 *cert,char *buf,int size) +{ +BIO *subject_bio; +BUF_MEM *subject_mem; +char *subject = buf; +int maxlen = size; + + subject_bio =BIO_new (BIO_s_mem ()); +if (subject_bio ==NULL ) + goto out; + +X509_NAME_print_ex (subject_bio,X509_get_subject_name (cert), +0 ,XN_FLAG_SEP_CPLUS_SPC |XN_FLAG_FN_SN | +ASN1_STRFLGS_UTF8_CONVERT |ASN1_STRFLGS_ESC_CTRL ); + +if (BIO_eof (subject_bio)) + goto out_free; + +BIO_get_mem_ptr (subject_bio, &subject_mem); +if (subject ==NULL ) + { + maxlen = subject_mem->length +1 ; + subject =malloc (maxlen); +check_malloc_return (subject); + } + +memcpy (subject, subject_mem->data, maxlen); + subject[maxlen -1 ] ='\0' ; + +out_free: +BIO_free (subject_bio); +out: +return subject; +} + +char *x509_get_subject (X509 *cert) { -return X509_NAME_oneline (X509_get_subject_name (cert),NULL ,0 ); +return _openssl_get_subject (cert,NULL ,0 ); }void x509_free_subject (char *subject) {if (subject) -OPENSSL_free (subject); +free (subject); }
ssl_verify_openssl.h +2 -0
@@ -69,4 +69,6 @@ int verify_callback (int preverify_ok, X509_STORE_CTX * ctx);/** @} name Function for authenticating a new connection from a remote OpenVPN peer */ +char *_openssl_get_subject (X509 *cert,char *buf,int size); +#endif /* SSL_VERIFY_OPENSSL_H_ */
Signature · 1 line
1.7.8.3
Hi list,
Quoted 6 lines · On Saturday 04 February 2012 12:56:24 Heiko Hund wrote:
The UTF-8 support that came with commit 2627335 does allow international usernames and passwords. This patch introduces UTF-8 support for X.509 DNs. Additionally, instead of using the legacy openssl format, DNs are now displayed in RFC 2253 format; "/C=ru/L=\xD0\x9C\xD0\xBE\xD1\x81\xD0\xBA\xD0 \xB2\xD0\xB0/O=\xD0\x9A\xD1\x80\xD0\xB5\xD0\xBC\xD0\xBB\xD1\x8C/CN=kreml.ru " becomes "C=ru, L=Москва, O=Кремль, CN=kreml.ru".
this is almost an 1:1 repost of this previous one (at
http://thread.gmane.org/gmane.network.openvpn.devel/5112). The only thing that was changed is that openssl_get_subject() was moved to ssl_verify_openssl.[ch] as discussed at the FOSDEM meeting.
Heiko
Signature · 8 lines
Heiko Hund | Software Engineer | Phone +49-721-25516-237 | Fax -200 Astaro a Sophos Company | Amalienbadstr. 41 Bau 52 | 76227 Karlsruhe | Germany Commercial Register: Mannheim HRA 702710 | Headquarter Location: Karlsruhe Represented by the General Partner Astaro Verwaltungs GmbH Amalienbadstraße 41 Bau 52 | 76227 Karlsruhe | Germany Commercial Register: Mannheim HRB 708248 | Executive Board: Gert Hansen, Markus Hennig, Jan Hichert, Günter Junk, Dr. Frank Nellissen
Hi,
Quoted 3 lines · Heiko Hund
Since the specific character classes for X.509 names are removed, the "no-name-remapping" configuration option has no use anymore and is removed as well.
--no-name-remapping appears again somewhat further down in openvpn.8, we should remove it from there as well.
---------------- quote ----------------
String Types and Remapping
In certain cases, OpenVPN will perform remapping of characters in strings. Essentially, any characters outside the set of permitted characters for each string type will be converted to underbar ('_').
Q: Why is string remapping necessary?
A: It's an important security feature to prevent the malicious coding of strings from untrusted sources to be passed as parameters to scripts, saved in the environment, used as a common name, translated to a filename, etc.
Q: Can string remapping be disabled?
A: Yes, by using the --no-name-remapping option, however this should be considered an advanced option.
---------------- quote ----------------
(well, seems the whole section needs to be rewritten to reflect the new remapping rules [if any])
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]...