summaryrefslogtreecommitdiff
path: root/passlib
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2012-04-17 22:23:35 -0400
committerEli Collins <elic@assurancetechnologies.com>2012-04-17 22:23:35 -0400
commite81b32667429c6486a63f4a2c2bf446ba2c8ea90 (patch)
treee553bcda4481228fe2d953729e3fbb1122d44455 /passlib
parent0cade3487dea5d8117b9f5e045c9fd9425778aec (diff)
downloadpasslib-e81b32667429c6486a63f4a2c2bf446ba2c8ea90.tar.gz
changed bcrypt's os_crypt backend to try alternatives before bailing.
Diffstat (limited to 'passlib')
-rw-r--r--passlib/handlers/bcrypt.py11
-rw-r--r--passlib/tests/test_handlers.py3
-rw-r--r--passlib/tests/utils.py5
3 files changed, 10 insertions, 9 deletions
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.",
)
diff --git a/passlib/tests/test_handlers.py b/passlib/tests/test_handlers.py
index f566b4f..61cdc8f 100644
--- a/passlib/tests/test_handlers.py
+++ b/passlib/tests/test_handlers.py
@@ -59,7 +59,6 @@ class _bcrypt_test(HandlerCase):
"base for BCrypt test cases"
handler = hash.bcrypt
secret_size = 72
- os_crypt_has_fallback = False
known_correct_hashes = [
#
@@ -204,6 +203,8 @@ class _bcrypt_test(HandlerCase):
#===============================================================
def os_supports_ident(self, hash):
"check if OS crypt is expected to support given ident"
+ if hash is None:
+ return True
# most OSes won't support 2x/2y
# XXX: definitely not the BSDs, but what about the linux variants?
if hash.startswith("$2x$") or hash.startswith("$2y$"):
diff --git a/passlib/tests/utils.py b/passlib/tests/utils.py
index 7d7b205..5cbb427 100644
--- a/passlib/tests/utils.py
+++ b/passlib/tests/utils.py
@@ -1795,9 +1795,6 @@ class OsCryptMixin(HandlerCase):
# encodeds as os.platform prefixes.
platform_crypt_support = dict()
- # hack for bcrypt, indicating os_crypt backend has no fallback
- os_crypt_has_fallback = True
-
#=========================================================
# instance attrs
#=========================================================
@@ -1876,7 +1873,7 @@ class OsCryptMixin(HandlerCase):
# set safe_crypt to return None
setter = self._use_mock_crypt()
setter(None)
- if self.os_crypt_has_fallback and _find_alternate_backend(self.handler, "os_crypt"):
+ if _find_alternate_backend(self.handler, "os_crypt"):
# handler should have a fallback to use
h1 = self.do_encrypt("stub")
h2 = self.do_genhash("stub", h1)