diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2011-04-25 02:25:36 -0400 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2011-04-25 02:25:36 -0400 |
| commit | 3134fdb5722eab2265e1d2f5bef1a24d3698809c (patch) | |
| tree | 31ee8e1962590edce16bf754b19b95cce95fa9ea | |
| parent | aee81ed64c9efacbbd5ffd780ae2881ec38b840c (diff) | |
| download | passlib-3134fdb5722eab2265e1d2f5bef1a24d3698809c.tar.gz | |
added support for hashes used by Roundup Issue tracker
* ldap_hex_md5, ldap_hex_sha1, roundup_plaintext, roundup_pbkdf2_sha1
* also uses ldap_des_crypt
* need to add docs
| -rw-r--r-- | passlib/apps.py | 15 | ||||
| -rw-r--r-- | passlib/handlers/roundup.py | 34 | ||||
| -rw-r--r-- | passlib/registry.py | 5 | ||||
| -rw-r--r-- | passlib/tests/test_drivers.py | 43 |
4 files changed, 92 insertions, 5 deletions
diff --git a/passlib/apps.py b/passlib/apps.py index d85b52e..e401257 100644 --- a/passlib/apps.py +++ b/passlib/apps.py @@ -53,11 +53,13 @@ std_ldap_schemes = ["ldap_salted_sha1", "ldap_salted_md5", ldap_nocrypt_context = LazyCryptContext(std_ldap_schemes) #create context with all possible std ldap + ldap crypt schemes +def _iter_ldap_crypt_schemes(): + from passlib.utils import unix_crypt_schemes + return ('ldap_' + name for name in unix_crypt_schemes) + def _iter_ldap_schemes(): "helper which iterates over supported std ldap schemes" - from passlib.utils import unix_crypt_schemes - return chain(std_ldap_schemes, - ('ldap_' + name for name in unix_crypt_schemes)) + return chain(std_ldap_schemes, _iter_ldap_crypt_schemes()) ldap_context = LazyCryptContext(_iter_ldap_schemes()) ###create context with all std ldap schemes + crypt schemes for localhost @@ -94,7 +96,12 @@ phpbb3_context = LazyCryptContext(["phpass"], phpass__ident="H") #========================================================= #roundup #========================================================= -#roundup_context + +_std_roundup_schemes = [ "ldap_hex_sha1", "ldap_hex_md5", "ldap_des_crypt", "roundup_plaintext" ] +roundup10 = roundup_context = LazyCryptContext(_std_roundup_schemes) + +#this roundup hasn't been released yet, may have diff version... +#roundup_context = roundup15_context = LazyCryptContext(_std_roundup_schemes + [ "roundup_pbkdf2_sha1" ]) #========================================================= # eof diff --git a/passlib/handlers/roundup.py b/passlib/handlers/roundup.py new file mode 100644 index 0000000..ebc2d5a --- /dev/null +++ b/passlib/handlers/roundup.py @@ -0,0 +1,34 @@ +"""passlib.handlers.roundup - Roundup issue tracker hashes""" +#========================================================= +#imports +#========================================================= +#core +import logging; log = logging.getLogger(__name__) +#site +#libs +from passlib.utils import handlers as uh +#pkg +#local +__all__ = [ + "roundup_plaintext", + "roundup_pbkdf2_sha1", + "ldap_hex_md5", + "ldap_hex_sha1", +] +#========================================================= +# +#========================================================= +roundup_plaintext = uh.PrefixWrapper("roundup_plaintext", "plaintext", + prefix="{plaintext}", lazy=True) + +roundup_pbkdf2_sha1 = uh.PrefixWrapper("roundup_pbkdf2_sha1", "pbkdf2_sha1", + prefix="{PBKDF2}", + orig_prefix="$pbkdf2-sha1$", lazy=True) + +#NOTE: these are here because they're currently only known to be used by roundup +ldap_hex_md5 = uh.PrefixWrapper("ldap_hex_md5", "hex_md5", "{MD5}", lazy=True) +ldap_hex_sha1 = uh.PrefixWrapper("ldap_hex_sha1", "hex_sha1", "{SHA}", lazy=True) + +#========================================================= +#eof +#========================================================= diff --git a/passlib/registry.py b/passlib/registry.py index 49a552c..942f94b 100644 --- a/passlib/registry.py +++ b/passlib/registry.py @@ -92,6 +92,8 @@ _handler_locations = { "ldap_plaintext": ("passlib.handlers.ldap_digests","ldap_plaintext"), "ldap_md5": ("passlib.handlers.ldap_digests","ldap_md5"), "ldap_sha1": ("passlib.handlers.ldap_digests","ldap_sha1"), + "ldap_hex_md5": ("passlib.handlers.roundup", "ldap_hex_md5"), + "ldap_hex_sha1": ("passlib.handlers.roundup", "ldap_hex_sha1"), "ldap_salted_md5": ("passlib.handlers.ldap_digests","ldap_salted_md5"), "ldap_salted_sha1": ("passlib.handlers.ldap_digests","ldap_salted_sha1"), "ldap_des_crypt": ("passlib.handlers.ldap_digests","ldap_des_crypt"), @@ -113,6 +115,9 @@ _handler_locations = { "phpass": ("passlib.handlers.phpass", "phpass"), "plaintext": ("passlib.handlers.misc", "plaintext"), "postgres_md5": ("passlib.handlers.postgres", "postgres_md5"), + "roundup_plaintext":("passlib.handlers.roundup", "roundup_plaintext"), + "roundup_pbkdf2_sha1": + ("passlib.handlers.roundup", "roundup_pbkd2_sha1"), "sha1_crypt": ("passlib.handlers.sha1_crypt", "sha1_crypt"), "sha256_crypt": ("passlib.handlers.sha2_crypt", "sha256_crypt"), "sha512_crypt": ("passlib.handlers.sha2_crypt", "sha512_crypt"), diff --git a/passlib/tests/test_drivers.py b/passlib/tests/test_drivers.py index 479bfb9..907981a 100644 --- a/passlib/tests/test_drivers.py +++ b/passlib/tests/test_drivers.py @@ -9,7 +9,7 @@ import logging; log = logging.getLogger(__name__) import warnings #site #pkg -from passlib.tests.utils import HandlerCase, create_backend_case, enable_option +from passlib.tests.utils import TestCase, HandlerCase, create_backend_case, enable_option #module #========================================================= @@ -657,6 +657,47 @@ class SHA1CryptTest(HandlerCase): ] #========================================================= +#roundup +#========================================================= + +#NOTE: all roundup hashes use PrefixWrapper, +# so there's nothing natively to test. +# so we just have a few quick cases... +from passlib.handlers import roundup + +class RoundupTest(TestCase): + + def _test_pair(self, h, secret, hash): + self.assertTrue(h.verify(secret, hash)) + self.assertFalse(h.verify('x'+secret, hash)) + + def test_pairs(self): + self._test_pair( + roundup.ldap_hex_sha1, + "sekrit", + '{SHA}8d42e738c7adee551324955458b5e2c0b49ee655') + + self._test_pair( + roundup.ldap_hex_md5, + "sekrit", + '{MD5}ccbc53f4464604e714f69dd11138d8b5') + + self._test_pair( + ldap_digests.ldap_des_crypt, + "sekrit", + '{CRYPT}nFia0rj2TT59A') + + self._test_pair( + roundup.roundup_plaintext, + "sekrit", + '{plaintext}sekrit') + + self._test_pair( + roundup.roundup_pbkdf2_sha1, + "sekrit", + '{PBKDF2}5000$7BvbBq.EZzz/O0HuwX3iP.nAG3s$g3oPnFFaga2BJaX5PoPRljl4XIE') + +#========================================================= #sha256-crypt #========================================================= from passlib.handlers.sha2_crypt import sha256_crypt, raw_sha_crypt |
