[Checkins] SVN: zope.password/trunk/ encode encoded_password to ascii before passing it to urlsafe_b64decode#

Jan-Wijbrand Kolman janwijbrand at gmail.com
Wed May 26 12:01:17 EDT 2010


Log message for revision 112740:
  encode encoded_password to ascii before passing it to urlsafe_b64decode#

Changed:
  U   zope.password/trunk/CHANGES.txt
  U   zope.password/trunk/src/zope/password/password.py

-=-
Modified: zope.password/trunk/CHANGES.txt
===================================================================
--- zope.password/trunk/CHANGES.txt	2010-05-26 15:50:09 UTC (rev 112739)
+++ zope.password/trunk/CHANGES.txt	2010-05-26 16:01:17 UTC (rev 112740)
@@ -5,9 +5,11 @@
 3.6.1 (unreleased)
 ------------------
 
-(none yet)
+- The SSHAPasswordManager.checkPassword() would not handle unicode input
+  (even if the string would only contain ascii characters). Now, the
+  encoded_password input will be encoded to ascii, which is deemed safe as it
+  should not contain non-ascii characters anyway.
 
-
 3.6.0 (2010-05-07)
 ------------------
 
@@ -19,7 +21,6 @@
   former zpasswd script, which used "Plain Text" as default password
   manager, now SSHA is used as default.
 
-
 3.5.1 (2009-03-14)
 ------------------
 

Modified: zope.password/trunk/src/zope/password/password.py
===================================================================
--- zope.password/trunk/src/zope/password/password.py	2010-05-26 15:50:09 UTC (rev 112739)
+++ zope.password/trunk/src/zope/password/password.py	2010-05-26 16:01:17 UTC (rev 112740)
@@ -73,7 +73,7 @@
 
     SSHA is regularly used in LDAP databases and we should be
     compatible with passwords used there.
-    
+
     >>> from zope.interface.verify import verifyObject
 
     >>> manager = SSHAPasswordManager()
@@ -96,13 +96,13 @@
     Our password manager generates the same value when seeded with the
     same salt, so we can be sure, our output is compatible with
     standard LDAP tools that also use SSHA::
-    
+
     >>> from base64 import urlsafe_b64decode
     >>> salt = urlsafe_b64decode('XkOZbw==')
     >>> encoded = manager.encodePassword('secret', salt)
     >>> encoded
     '{SSHA}J4mrr3NQHXzLVaT0h9TuEWoJOrxeQ5lv'
-    
+
     >>> encoded = manager.encodePassword(password)
     >>> manager.checkPassword(encoded, password)
     True
@@ -111,6 +111,15 @@
 
     >>> manager.encodePassword(password) != manager.encodePassword(password)
     True
+
+    The password manager should be able to cope with unicode strings for input::
+
+    >>> passwd = u'foobar\u2211' # sigma-sign.
+    >>> manager.checkPassword(manager.encodePassword(passwd), passwd)
+    True
+    >>> manager.checkPassword(unicode(manager.encodePassword(passwd)), passwd)
+    True
+
     """
 
     implements(IPasswordManager)
@@ -120,10 +129,13 @@
             salt = urandom(4)
         hash = sha1(_encoder(password)[0])
         hash.update(salt)
-        return '{SSHA}' + urlsafe_b64encode(
-            hash.digest() + salt)
+        return '{SSHA}' + urlsafe_b64encode(hash.digest() + salt)
 
     def checkPassword(self, encoded_password, password):
+        # urlsafe_b64decode() cannot handle unicode input string. We
+        # encode to ascii. This is safe as the encoded_password string
+        # should not contain non-ascii characters anyway.
+        encoded_password = encoded_password.encode('ascii')
         byte_string = urlsafe_b64decode(encoded_password[6:])
         salt = byte_string[20:]
         return encoded_password == self.encodePassword(password, salt)
@@ -134,7 +146,7 @@
 
     Note: use of salt in this password manager is purely
     cosmetical. Use SSHA if you want increased security.
-    
+
     >>> from zope.interface.verify import verifyObject
 
     >>> manager = MD5PasswordManager()
@@ -160,7 +172,7 @@
 
     >>> manager.encodePassword(password) != manager.encodePassword(password)
     True
-    
+
     The old version of this password manager didn't add the {MD5} to
     passwords. Let's check if it can work with old stored passwords.
 
@@ -193,7 +205,7 @@
 
     Note: use of salt in this password manager is purely
     cosmetical. Use SSHA if you want increased security.
-    
+
     >>> from zope.interface.verify import verifyObject
 
     >>> manager = SHA1PasswordManager()



More information about the checkins mailing list