Import failure for passlib.apache for versions later then 1.6.5

Issue #105 new
Connor Wolf created an issue
urr@cr-build:~$ sudo pip3 install "passlib==1.6.5"
Collecting passlib==1.6.5
  Downloading (317kB)
    100% |████████████████████████████████| 327kB 22.0MB/s
Installing collected packages: passlib
  Found existing installation: passlib 1.7.0
    Uninstalling passlib-1.7.0:
      Successfully uninstalled passlib-1.7.0
Successfully installed passlib-1.6.5
durr@cr-build:~$ python3 -c "import passlib.apache;"
durr@cr-build:~$ sudo pip3 install "passlib==1.7.1"
Collecting passlib==1.7.1
  Downloading (498kB)
    100% |████████████████████████████████| 501kB 8.6MB/s
Installing collected packages: passlib
  Found existing installation: passlib 1.6.5
    Uninstalling passlib-1.6.5:
      Successfully uninstalled passlib-1.6.5
Successfully installed passlib-1.7.1
durr@cr-build:~$ python3 -c "import passlib.apache;"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/passlib/", line 475, in <module>
    htpasswd_defaults = _init_default_schemes()
  File "/usr/local/lib/python3.6/dist-packages/passlib/", line 446, in _init_default_schemes
    bcrypt = "bcrypt" if registry.has_backend("bcrypt") else None
  File "/usr/local/lib/python3.6/dist-packages/passlib/", line 481, in has_backend
  File "/usr/local/lib/python3.6/dist-packages/passlib/utils/", line 2055, in get_backend
  File "/usr/local/lib/python3.6/dist-packages/passlib/utils/", line 2130, in set_backend
    return cls.set_backend(name, dryrun=dryrun)
  File "/usr/local/lib/python3.6/dist-packages/passlib/utils/", line 2155, in set_backend
    cls._set_backend(name, dryrun)
  File "/usr/local/lib/python3.6/dist-packages/passlib/utils/", line 2278, in _set_backend
    super(SubclassBackendMixin, cls)._set_backend(name, dryrun)
  File "/usr/local/lib/python3.6/dist-packages/passlib/utils/", line 2191, in _set_backend
    ok = loader(**kwds)
  File "/usr/local/lib/python3.6/dist-packages/passlib/handlers/", line 671, in _load_backend_mixin
    return mixin_cls._finalize_backend_mixin(name, dryrun)
  File "/usr/local/lib/python3.6/dist-packages/passlib/handlers/", line 374, in _finalize_backend_mixin
    result = safe_verify("test", test_hash_20)
  File "/usr/local/lib/python3.6/dist-packages/passlib/handlers/", line 293, in safe_verify
    return verify(secret, hash)
  File "/usr/local/lib/python3.6/dist-packages/passlib/utils/", line 761, in verify
    return consteq(self._calc_checksum(secret), chk)
  File "/usr/local/lib/python3.6/dist-packages/passlib/handlers/", line 688, in _calc_checksum_raw
    hash = _pybcrypt.hashpw(secret, config)
  File "/usr/local/lib/python3.6/dist-packages/bcrypt/", line 61, in hashpw
    raise TypeError("Unicode-objects must be encoded before hashing. Passed: '%s', '%s'" % (password, salt))
TypeError: Unicode-objects must be encoded before hashing. Passed: 'b'test'', '$2$04$5BJqKfqMQvV7nS.yUguNcu'

Basically, it's impossible to import import passlib.apache in the the 1.7.x series. This breaks mitmproxy.

Platform is Ubuntu 18.04 LTS, Python 3.6.7, pip installed from, rather then the ubuntu sources.

The issue is that the salt passed through to _pybcrypt.hashpw() is not ascii encoded. The above output has some debugging I added to /usr/local/lib/python3.6/dist-packages/bcrypt/, where you can see that the password value is a bytestring, but the seed is still a unicode string.

This is very annoying.

Additionally, the issue itself is not consistent. I've touched nothing I can think of (not even rebooted), but this same system was working fine previously.

Comments (1)

  1. Log in to comment