hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1616688 - in /httpcomponents/httpclient/trunk/httpclient/src: main/java/org/apache/http/conn/ssl/ test/java/org/apache/http/conn/ssl/
Date Fri, 08 Aug 2014 08:30:01 GMT
Author: olegk
Date: Fri Aug  8 08:30:01 2014
New Revision: 1616688

URL: http://svn.apache.org/r1616688
Log:
Reverted r1616137, r1616136, r1615900

Removed:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/DistinguishedNameParser.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/TokenParser.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestDistinguishedNameParser.java
Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/AbstractCommonHostnameVerifier.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestHostnameVerifier.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/AbstractCommonHostnameVerifier.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/AbstractCommonHostnameVerifier.java?rev=1616688&r1=1616687&r2=1616688&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/AbstractCommonHostnameVerifier.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/AbstractCommonHostnameVerifier.java
Fri Aug  8 08:30:01 2014
@@ -38,15 +38,20 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
+import java.util.NoSuchElementException;
 
+import javax.naming.InvalidNameException;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.ldap.LdapName;
+import javax.naming.ldap.Rdn;
 import javax.net.ssl.SSLException;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.http.NameValuePair;
 import org.apache.http.annotation.Immutable;
 import org.apache.http.conn.util.InetAddressUtils;
-import org.apache.http.util.TextUtils;
 
 /**
  * Abstract base class for all standard {@link org.apache.http.conn.ssl.X509HostnameVerifier}
@@ -195,17 +200,26 @@ public abstract class AbstractCommonHost
             return null;
         }
         final List<String> cns = new ArrayList<String>();
-        final List<NameValuePair> nvps = DistinguishedNameParser.INSTANCE.parse(subjectPrincipal);
-        for (int i = 0; i < nvps.size(); i++) {
-            final NameValuePair nvp = nvps.get(i);
-            final String attribName = nvp.getName();
-            final String attribValue = nvp.getValue();
-            if (TextUtils.isBlank(attribValue)) {
-                throw new SSLException(subjectPrincipal + " is not a valid X500 distinguished
name");
-            }
-            if (attribName.equalsIgnoreCase("cn")) {
-                cns.add(attribValue);
+        try {
+            final LdapName subjectDN = new LdapName(subjectPrincipal);
+            final List<Rdn> rdns = subjectDN.getRdns();
+            for (int i = rdns.size() - 1; i >= 0; i--) {
+                final Rdn rds = rdns.get(i);
+                final Attributes attributes = rds.toAttributes();
+                final Attribute cn = attributes.get("cn");
+                if (cn != null) {
+                    try {
+                        final Object value = cn.get();
+                        if (value != null) {
+                            cns.add(value.toString());
+                        }
+                    } catch (NoSuchElementException ignore) {
+                    } catch (NamingException ignore) {
+                    }
+                }
             }
+        } catch (InvalidNameException e) {
+            throw new SSLException(subjectPrincipal + " is not a valid X500 distinguished
name");
         }
         return cns.isEmpty() ? null : cns.toArray(new String[ cns.size() ]);
     }

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestHostnameVerifier.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestHostnameVerifier.java?rev=1616688&r1=1616687&r2=1616688&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestHostnameVerifier.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestHostnameVerifier.java
Fri Aug  8 08:30:01 2014
@@ -360,11 +360,6 @@ public class TestHostnameVerifier {
     }
 
     @Test(expected = SSLException.class)
-    public void testExtractCNEmpty() throws Exception {
-        AbstractCommonHostnameVerifier.extractCNs("cn=   , ou=blah, o=blah");
-    }
-
-    @Test(expected = SSLException.class)
     public void testExtractCNMissing() throws Exception {
         AbstractCommonHostnameVerifier.extractCNs("blah,blah");
     }



Mime
View raw message