diff options
| -rw-r--r-- | docs/history/1.7.rst | 2 | ||||
| -rw-r--r-- | passlib/handlers/bcrypt.py | 33 | ||||
| -rw-r--r-- | passlib/tests/test_handlers_bcrypt.py | 7 |
3 files changed, 32 insertions, 10 deletions
diff --git a/docs/history/1.7.rst b/docs/history/1.7.rst index 5d8ff44..cb497f2 100644 --- a/docs/history/1.7.rst +++ b/docs/history/1.7.rst @@ -39,7 +39,7 @@ Bugfixes * .. py:currentmodule:: passlib.hash :class:`bcrypt`: OS native backend wasn't being detected under Python 3 on BSD platforms. - This was due to an internal issue in feature-detection code, which has been fixed. + This was due to a few internal issues in feature-detection code, which have been fixed. * :func:`passlib.utils.safe_crypt`: Support :func:`crypt.crypt` unexpectedly returning bytes under Python 3 (:issue:`113`). diff --git a/passlib/handlers/bcrypt.py b/passlib/handlers/bcrypt.py index e54a085..a2b0d27 100644 --- a/passlib/handlers/bcrypt.py +++ b/passlib/handlers/bcrypt.py @@ -323,20 +323,35 @@ class _BcryptCommon(uh.SubclassBackendMixin, uh.TruncateMixin, uh.HasManyIdents, test cases from <http://cvsweb.openwall.com/cgi/cvsweb.cgi/Owl/packages/glibc/crypt_blowfish/wrapper.c.diff?r1=1.9;r2=1.10> reference hash is the incorrectly generated $2x$ hash taken from above url """ - secret = b"\xA3" - bug_hash = ident.encode("ascii") + b"05$/OK.fbVrR/bpIqNJ5ianF.CE5elHaaO4EbggVDjb8P19RukzXSM3e" + # NOTE: passlib 1.7.2 and earlier used the commented-out LATIN-1 test vector to detect + # this bug; but python3's crypt.crypt() only supports unicode inputs (and + # always encodes them as UTF8 before passing to crypt); so passlib 1.7.3 + # switched to the UTF8-compatible test vector below. This one's bug_hash value + # ("$2x$...rcAS") was drawn from the same openwall source (above); and the correct + # hash ("$2a$...X6eu") was generated by passing the raw bytes to python2's + # crypt.crypt() using OpenBSD 6.7 (hash confirmed as same for $2a$ & $2b$). + + # LATIN-1 test vector + # secret = b"\xA3" + # bug_hash = ident.encode("ascii") + b"05$/OK.fbVrR/bpIqNJ5ianF.CE5elHaaO4EbggVDjb8P19RukzXSM3e" + # correct_hash = ident.encode("ascii") + b"05$/OK.fbVrR/bpIqNJ5ianF.Sa7shbm4.OzKpvFnX1pQLmQW96oUlCq" + + # UTF-8 test vector + secret = b"\xd1\x91" # aka "\u0451" + bug_hash = ident.encode("ascii") + b"05$6bNw2HLQYeqHYyBfLMsv/OiwqTymGIGzFsA4hOTWebfehXHNprcAS" + correct_hash = ident.encode("ascii") + b"05$6bNw2HLQYeqHYyBfLMsv/OUcZd0LKP39b87nBw3.S2tVZSqiQX6eu" + if verify(secret, bug_hash): - # NOTE: this only EVER be observed in 2a hashes, - # 2y/2b hashes should have fixed the bug. + # NOTE: this only EVER be observed in (broken) 2a and (backward-compat) 2x hashes + # generated by crypt_blowfish library. 2y/2b hashes should not have the bug # (but we check w/ them anyways). raise PasslibSecurityError( "passlib.hash.bcrypt: Your installation of the %r backend is vulnerable to " - "the crypt_blowfish 8-bit bug (CVE-2011-2483), " - "and should be upgraded or replaced with another backend." % backend) + "the crypt_blowfish 8-bit bug (CVE-2011-2483) under %r hashes, " + "and should be upgraded or replaced with another backend" % (backend, ident)) - # if it doesn't have wraparound bug, make sure it *does* handle things - # correctly -- or we're in some weird third case. - correct_hash = ident.encode("ascii") + b"05$/OK.fbVrR/bpIqNJ5ianF.Sa7shbm4.OzKpvFnX1pQLmQW96oUlCq" + # it doesn't have wraparound bug, but make sure it *does* verify against the correct + # hash, or we're in some weird third case! if not verify(secret, correct_hash): raise RuntimeError("%s backend failed to verify %s 8bit hash" % (backend, ident)) diff --git a/passlib/tests/test_handlers_bcrypt.py b/passlib/tests/test_handlers_bcrypt.py index c493ca9..e9d2280 100644 --- a/passlib/tests/test_handlers_bcrypt.py +++ b/passlib/tests/test_handlers_bcrypt.py @@ -68,6 +68,13 @@ class _bcrypt_test(HandlerCase): '$2y$05$/OK.fbVrR/bpIqNJ5ianF.Sa7shbm4.OzKpvFnX1pQLmQW96oUlCq'), # + # 8bit bug (fixed in 2y/2b) + # + + # NOTE: see assert_lacks_8bit_bug() for origins of this test vector. + (b"\xd1\x91", "$2y$05$6bNw2HLQYeqHYyBfLMsv/OUcZd0LKP39b87nBw3.S2tVZSqiQX6eu"), + + # # bsd wraparound bug (fixed in 2b) # |
