[Jython-checkins] jython: Improve ssl.SSLContext._parse_dn to support quoted names

darjus.loktevic jython-checkins at python.org
Sun Nov 8 17:58:19 EST 2015


https://hg.python.org/jython/rev/c1ff0eb2cec6
changeset:   7793:c1ff0eb2cec6
user:        Darjus Loktevic <darjus at gmail.com>
date:        Mon Nov 09 09:58:09 2015 +1100
summary:
  Improve ssl.SSLContext._parse_dn to support quoted names

files:
  Lib/ssl.py |  21 ++++++++++++++-------
  1 files changed, 14 insertions(+), 7 deletions(-)


diff --git a/Lib/ssl.py b/Lib/ssl.py
--- a/Lib/ssl.py
+++ b/Lib/ssl.py
@@ -7,6 +7,7 @@
 from java.security import KeyStore
 from java.security.cert import CertificateParsingException
 from javax.net.ssl import TrustManagerFactory
+from javax.naming.ldap import LdapName
 import logging
 import os.path
 import textwrap
@@ -38,7 +39,7 @@
 from _sslcerts import SSLContext as _JavaSSLContext
 
 from java.text import SimpleDateFormat
-from java.util import ArrayList, Locale, TimeZone
+from java.util import ArrayList, Locale, TimeZone, NoSuchElementException
 from java.util.concurrent import CountDownLatch
 from javax.naming.ldap import LdapName
 from javax.security.auth.x500 import X500Principal
@@ -588,11 +589,17 @@
 
     @classmethod
     def _parse_dn(cls, dn):
+        dn_lst = []
+
+        ln = LdapName(unicode(dn))
+        ln_iter = ln.getAll()
         try:
-            dn_dct = dict([iss.split('=', 1) for iss in unicode(dn).split(',')])
-        except ValueError:
-            # FIXME CN=Starfield Root Certificate Authority - G2, O="Starfield Technologies, Inc.",
-            log.error("Failed to parse {}".format(dn), exc_info=True)
-            return tuple()
+            ln_value = ln_iter.nextElement()
+            while ln_value:
+                dn_lst.append(tuple(ln_value.split('=', 1)))
 
-        return tuple((cls._DN_TO_CPY.get(key.strip(), 'unk'), val) for key, val in dn_dct.iteritems())
+                ln_value = ln_iter.nextElement()
+        except NoSuchElementException:
+            pass
+
+        return tuple(dn_lst)

-- 
Repository URL: https://hg.python.org/jython


More information about the Jython-checkins mailing list