From c0f420bf7d7659ee110432f7cbb0233554dfd32a Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Thu, 12 Apr 2012 21:52:26 -0400 Subject: assorted bugfixes, tweaks, and tests added; based on coverage examination * test os_crypt backend has functional fallback * test handler methods accept all unicode/bytes combinations for secret & hash * fixed some incorrect error messages & types being caught & raised * other minor cleanups --- passlib/handlers/bcrypt.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'passlib/handlers/bcrypt.py') diff --git a/passlib/handlers/bcrypt.py b/passlib/handlers/bcrypt.py index f07a194..89680a2 100644 --- a/passlib/handlers/bcrypt.py +++ b/passlib/handlers/bcrypt.py @@ -186,8 +186,7 @@ class bcrypt(uh.HasManyIdents, uh.HasRounds, uh.HasSalt, uh.HasManyBackends, uh. def _norm_salt(self, salt, **kwds): salt = super(bcrypt, self)._norm_salt(salt, **kwds) - if not salt: - return None + assert salt is not None, "HasSalt didn't generate new salt!" changed, salt = bcrypt64.check_repair_unused(salt) if changed: warn( -- cgit v1.2.1 From ceb7a00ddae502624d609bc63a9048f0de9f1b23 Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Tue, 17 Apr 2012 21:55:38 -0400 Subject: a bunch of bugfixes found during unittesting * bsdi_crypt apparently available on openbsd 4.9 * typo fixes * ConfigParser apparently only uses OrderedDict for >= PY27, adjusted CryptContext test accordingly * fixed test that depended on sha256_crypt.default_rounds * handle os_crypt backend w/ no fallback (bcrypt) * let _norm_rounds accept longs --- passlib/handlers/bcrypt.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'passlib/handlers/bcrypt.py') diff --git a/passlib/handlers/bcrypt.py b/passlib/handlers/bcrypt.py index 89680a2..665a5c9 100644 --- a/passlib/handlers/bcrypt.py +++ b/passlib/handlers/bcrypt.py @@ -249,8 +249,9 @@ class bcrypt(uh.HasManyIdents, uh.HasRounds, uh.HasSalt, uh.HasManyBackends, uh. assert hash.startswith(config) and len(hash) == len(config)+31 return hash[-31:] else: - #NOTE: not checking other backends since this is lowest priority one, - # so they probably aren't available either. + # NOTE: not checking other backends since this is lowest priority one, + # so they probably aren't available either. + # XXX: though could conceivably use builtin 8| raise uh.exc.MissingBackendError( "encoded password can't be handled by os_crypt, " "recommend installing py-bcrypt.", -- cgit v1.2.1 From e81b32667429c6486a63f4a2c2bf446ba2c8ea90 Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Tue, 17 Apr 2012 22:23:35 -0400 Subject: changed bcrypt's os_crypt backend to try alternatives before bailing. --- passlib/handlers/bcrypt.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'passlib/handlers/bcrypt.py') diff --git a/passlib/handlers/bcrypt.py b/passlib/handlers/bcrypt.py index 665a5c9..890c656 100644 --- a/passlib/handlers/bcrypt.py +++ b/passlib/handlers/bcrypt.py @@ -249,11 +249,14 @@ class bcrypt(uh.HasManyIdents, uh.HasRounds, uh.HasSalt, uh.HasManyBackends, uh. assert hash.startswith(config) and len(hash) == len(config)+31 return hash[-31:] else: - # NOTE: not checking other backends since this is lowest priority one, - # so they probably aren't available either. - # XXX: though could conceivably use builtin 8| + # NOTE: it's unlikely any other backend will be available, + # but checking before we bail, just in case. + for name in self.backends: + if name != "os_crypt" and self.has_backend(name): + func = getattr(self, "_calc_checksum_" + name) + return func(secret) raise uh.exc.MissingBackendError( - "encoded password can't be handled by os_crypt, " + "password can't be handled by os_crypt, " "recommend installing py-bcrypt.", ) -- cgit v1.2.1