|
|
5fcfe9 |
--- openldap-2.3.43/libraries/libldap/tls.c.orig 2010-02-08 13:58:47.000000000 +0100
|
|
|
5fcfe9 |
+++ openldap-2.3.43/libraries/libldap/tls.c 2010-02-08 14:10:37.000000000 +0100
|
|
|
5fcfe9 |
@@ -981,7 +981,7 @@ ldap_pvt_tls_check_hostname( LDAP *ld, v
|
|
|
5fcfe9 |
X509 *x;
|
|
|
5fcfe9 |
const char *name;
|
|
|
5fcfe9 |
char *ptr;
|
|
|
5fcfe9 |
- int ntype = IS_DNS;
|
|
|
5fcfe9 |
+ int ntype = IS_DNS, nlen;
|
|
|
5fcfe9 |
#ifdef LDAP_PF_INET6
|
|
|
5fcfe9 |
struct in6_addr addr;
|
|
|
5fcfe9 |
#else
|
|
|
5fcfe9 |
@@ -995,6 +995,7 @@ ldap_pvt_tls_check_hostname( LDAP *ld, v
|
|
|
5fcfe9 |
} else {
|
|
|
5fcfe9 |
name = name_in;
|
|
|
5fcfe9 |
}
|
|
|
5fcfe9 |
+ nlen = strlen(name);
|
|
|
5fcfe9 |
|
|
|
5fcfe9 |
x = tls_get_cert((SSL *)s);
|
|
|
5fcfe9 |
if (!x) {
|
|
|
5fcfe9 |
@@ -1028,15 +1029,14 @@ ldap_pvt_tls_check_hostname( LDAP *ld, v
|
|
|
5fcfe9 |
ex = X509_get_ext(x, i);
|
|
|
5fcfe9 |
alt = X509V3_EXT_d2i(ex);
|
|
|
5fcfe9 |
if (alt) {
|
|
|
5fcfe9 |
- int n, len1 = 0, len2 = 0;
|
|
|
5fcfe9 |
+ int n, len2 = 0;
|
|
|
5fcfe9 |
char *domain = NULL;
|
|
|
5fcfe9 |
GENERAL_NAME *gn;
|
|
|
5fcfe9 |
|
|
|
5fcfe9 |
if (ntype == IS_DNS) {
|
|
|
5fcfe9 |
- len1 = strlen(name);
|
|
|
5fcfe9 |
domain = strchr(name, '.');
|
|
|
5fcfe9 |
if (domain) {
|
|
|
5fcfe9 |
- len2 = len1 - (domain-name);
|
|
|
5fcfe9 |
+ len2 = nlen - (domain-name);
|
|
|
5fcfe9 |
}
|
|
|
5fcfe9 |
}
|
|
|
5fcfe9 |
n = sk_GENERAL_NAME_num(alt);
|
|
|
5fcfe9 |
@@ -1054,7 +1054,7 @@ ldap_pvt_tls_check_hostname( LDAP *ld, v
|
|
|
5fcfe9 |
if (sl == 0) continue;
|
|
|
5fcfe9 |
|
|
|
5fcfe9 |
/* Is this an exact match? */
|
|
|
5fcfe9 |
- if ((len1 == sl) && !strncasecmp(name, sn, len1)) {
|
|
|
5fcfe9 |
+ if ((nlen == sl) && !strncasecmp(name, sn, nlen)) {
|
|
|
5fcfe9 |
break;
|
|
|
5fcfe9 |
}
|
|
|
5fcfe9 |
|
|
|
5fcfe9 |
@@ -1094,13 +1094,28 @@ ldap_pvt_tls_check_hostname( LDAP *ld, v
|
|
|
5fcfe9 |
|
|
|
5fcfe9 |
if (ret != LDAP_SUCCESS) {
|
|
|
5fcfe9 |
X509_NAME *xn;
|
|
|
5fcfe9 |
- char buf[2048];
|
|
|
5fcfe9 |
- buf[0] = '\0';
|
|
|
5fcfe9 |
+ X509_NAME_ENTRY *ne;
|
|
|
5fcfe9 |
+ ASN1_OBJECT *obj;
|
|
|
5fcfe9 |
+ ASN1_STRING *cn = NULL;
|
|
|
5fcfe9 |
+ int navas;
|
|
|
5fcfe9 |
+
|
|
|
5fcfe9 |
+ /* find the last CN */
|
|
|
5fcfe9 |
+ obj = OBJ_nid2obj( NID_commonName );
|
|
|
5fcfe9 |
+ if ( !obj ) goto no_cn; /* should never happen */
|
|
|
5fcfe9 |
|
|
|
5fcfe9 |
xn = X509_get_subject_name(x);
|
|
|
5fcfe9 |
- if( X509_NAME_get_text_by_NID( xn, NID_commonName,
|
|
|
5fcfe9 |
- buf, sizeof(buf)) == -1)
|
|
|
5fcfe9 |
- {
|
|
|
5fcfe9 |
+ navas = X509_NAME_entry_count( xn );
|
|
|
5fcfe9 |
+ for ( i=navas-1; i>=0; i-- ) {
|
|
|
5fcfe9 |
+ ne = X509_NAME_get_entry( xn, i );
|
|
|
5fcfe9 |
+ if ( !OBJ_cmp( ne->object, obj )) {
|
|
|
5fcfe9 |
+ cn = X509_NAME_ENTRY_get_data( ne );
|
|
|
5fcfe9 |
+ break;
|
|
|
5fcfe9 |
+ }
|
|
|
5fcfe9 |
+ }
|
|
|
5fcfe9 |
+
|
|
|
5fcfe9 |
+ if( !cn )
|
|
|
5fcfe9 |
+ {
|
|
|
5fcfe9 |
+no_cn:
|
|
|
5fcfe9 |
Debug( LDAP_DEBUG_ANY,
|
|
|
5fcfe9 |
"TLS: unable to get common name from peer certificate.\n",
|
|
|
5fcfe9 |
0, 0, 0 );
|
|
|
5fcfe9 |
@@ -1111,21 +1126,20 @@ ldap_pvt_tls_check_hostname( LDAP *ld, v
|
|
|
5fcfe9 |
ld->ld_error = LDAP_STRDUP(
|
|
|
5fcfe9 |
_("TLS: unable to get CN from peer certificate"));
|
|
|
5fcfe9 |
|
|
|
5fcfe9 |
- } else if (strcasecmp(name, buf) == 0 ) {
|
|
|
5fcfe9 |
+ } else if ( cn->length == nlen &&
|
|
|
5fcfe9 |
+ strncasecmp( name, (char *) cn->data, nlen ) == 0 ) {
|
|
|
5fcfe9 |
ret = LDAP_SUCCESS;
|
|
|
5fcfe9 |
|
|
|
5fcfe9 |
- } else if (( buf[0] == '*' ) && ( buf[1] == '.' )) {
|
|
|
5fcfe9 |
+ } else if (( cn->data[0] == '*' ) && ( cn->data[1] == '.' )) {
|
|
|
5fcfe9 |
char *domain = strchr(name, '.');
|
|
|
5fcfe9 |
if( domain ) {
|
|
|
5fcfe9 |
- size_t dlen = 0;
|
|
|
5fcfe9 |
- size_t sl;
|
|
|
5fcfe9 |
+ size_t dlen;
|
|
|
5fcfe9 |
|
|
|
5fcfe9 |
- sl = strlen(name);
|
|
|
5fcfe9 |
- dlen = sl - (domain-name);
|
|
|
5fcfe9 |
- sl = strlen(buf);
|
|
|
5fcfe9 |
+ dlen = nlen - (domain-name);
|
|
|
5fcfe9 |
|
|
|
5fcfe9 |
/* Is this a wildcard match? */
|
|
|
5fcfe9 |
- if ((dlen == sl-1) && !strncasecmp(domain, &buf[1], dlen)) {
|
|
|
5fcfe9 |
+ if ((dlen == cn->length-1) &&
|
|
|
5fcfe9 |
+ !strncasecmp(domain, (char *) &cn->data[1], dlen)) {
|
|
|
5fcfe9 |
ret = LDAP_SUCCESS;
|
|
|
5fcfe9 |
}
|
|
|
5fcfe9 |
}
|
|
|
5fcfe9 |
@@ -1133,8 +1147,8 @@ ldap_pvt_tls_check_hostname( LDAP *ld, v
|
|
|
5fcfe9 |
|
|
|
5fcfe9 |
if( ret == LDAP_LOCAL_ERROR ) {
|
|
|
5fcfe9 |
Debug( LDAP_DEBUG_ANY, "TLS: hostname (%s) does not match "
|
|
|
5fcfe9 |
- "common name in certificate (%s).\n",
|
|
|
5fcfe9 |
- name, buf, 0 );
|
|
|
5fcfe9 |
+ "common name in certificate (%.*s).\n",
|
|
|
5fcfe9 |
+ name, cn->length, cn->data );
|
|
|
5fcfe9 |
ret = LDAP_CONNECT_ERROR;
|
|
|
5fcfe9 |
if ( ld->ld_error ) {
|
|
|
5fcfe9 |
LDAP_FREE( ld->ld_error );
|