summaryrefslogtreecommitdiff
path: root/passlib
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2020-02-17 11:21:46 -0500
committerEli Collins <elic@assurancetechnologies.com>2020-02-17 11:21:46 -0500
commitec62db38788b1dc0c8f78060f6119cb63bbacfbd (patch)
treea381646403b89d70866e31cc57641cdd14553f77 /passlib
parente53460bc94667aaf29ff0221ba3e44d61b87fd2d (diff)
downloadpasslib-ec62db38788b1dc0c8f78060f6119cb63bbacfbd.tar.gz
passlib.hash.bcrypt: added notes re: final salt character
Diffstat (limited to 'passlib')
-rw-r--r--passlib/handlers/bcrypt.py8
-rw-r--r--passlib/tests/test_handlers_bcrypt.py4
2 files changed, 9 insertions, 3 deletions
diff --git a/passlib/handlers/bcrypt.py b/passlib/handlers/bcrypt.py
index 3c168e9..817416b 100644
--- a/passlib/handlers/bcrypt.py
+++ b/passlib/handlers/bcrypt.py
@@ -128,7 +128,9 @@ class _BcryptCommon(uh.SubclassBackendMixin, uh.TruncateMixin, uh.HasManyIdents,
#--------------------
min_salt_size = max_salt_size = 22
salt_chars = bcrypt64.charmap
- # NOTE: 22nd salt char must be in bcrypt64._padinfo2[1], not full charmap
+
+ # NOTE: 22nd salt char must be in restricted set of ``final_salt_chars``, not full set above.
+ final_salt_chars = ".Oeu" # bcrypt64._padinfo2[1]
#--------------------
# HasRounds
@@ -195,10 +197,12 @@ class _BcryptCommon(uh.SubclassBackendMixin, uh.TruncateMixin, uh.HasManyIdents,
@classmethod
def needs_update(cls, hash, **kwds):
+ # NOTE: can't convert this to use _calc_needs_update() helper,
+ # since _norm_hash() will correct salt padding before we can read it here.
# check for incorrect padding bits (passlib issue 25)
if isinstance(hash, bytes):
hash = hash.decode("ascii")
- if hash.startswith(IDENT_2A) and hash[28] not in bcrypt64._padinfo2[1]:
+ if hash.startswith(IDENT_2A) and hash[28] not in cls.final_salt_chars:
return True
# TODO: try to detect incorrect 8bit/wraparound hashes using kwds.get("secret")
diff --git a/passlib/tests/test_handlers_bcrypt.py b/passlib/tests/test_handlers_bcrypt.py
index 978b68b..8c88935 100644
--- a/passlib/tests/test_handlers_bcrypt.py
+++ b/passlib/tests/test_handlers_bcrypt.py
@@ -402,7 +402,9 @@ class _bcrypt_test(HandlerCase):
bcrypt = self.handler.using(rounds=4)
# PASS1 = "test"
- BAD1 = "$2a$04$yjDgE74RJkeqC0/1NheSScrvKeu9IbKDpcQf/Ox3qsrRS/Kw42qIS"
+ # bad contains invalid 'c' char at end of salt:
+ # \/
+ BAD1 = "$2a$04$yjDgE74RJkeqC0/1NheSScrvKeu9IbKDpcQf/Ox3qsrRS/Kw42qIS"
GOOD1 = "$2a$04$yjDgE74RJkeqC0/1NheSSOrvKeu9IbKDpcQf/Ox3qsrRS/Kw42qIS"
self.assertTrue(bcrypt.needs_update(BAD1))