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 https://files.pythonhosted.org/packages/2d/a7/1a3363e5d531d438267a79d43d4b8d224655adef489e98fc96678fe16ed1/passlib-1.6.5-py2.py3-none-any.whl (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 https://files.pythonhosted.org/packages/ee/a7/d6d238d927df355d4e4e000670342ca4705a72f0bf694027cf67d9bcf5af/passlib-1.7.1-py2.py3-none-any.whl (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/apache.py", line 475, in <module>
    htpasswd_defaults = _init_default_schemes()
  File "/usr/local/lib/python3.6/dist-packages/passlib/apache.py", line 446, in _init_default_schemes
    bcrypt = "bcrypt" if registry.has_backend("bcrypt") else None
  File "/usr/local/lib/python3.6/dist-packages/passlib/registry.py", line 481, in has_backend
    hasher.get_backend()
  File "/usr/local/lib/python3.6/dist-packages/passlib/utils/handlers.py", line 2055, in get_backend
    cls.set_backend()
  File "/usr/local/lib/python3.6/dist-packages/passlib/utils/handlers.py", line 2130, in set_backend
    return cls.set_backend(name, dryrun=dryrun)
  File "/usr/local/lib/python3.6/dist-packages/passlib/utils/handlers.py", line 2155, in set_backend
    cls._set_backend(name, dryrun)
  File "/usr/local/lib/python3.6/dist-packages/passlib/utils/handlers.py", line 2278, in _set_backend
    super(SubclassBackendMixin, cls)._set_backend(name, dryrun)
  File "/usr/local/lib/python3.6/dist-packages/passlib/utils/handlers.py", line 2191, in _set_backend
    ok = loader(**kwds)
  File "/usr/local/lib/python3.6/dist-packages/passlib/handlers/bcrypt.py", line 671, in _load_backend_mixin
    return mixin_cls._finalize_backend_mixin(name, dryrun)
  File "/usr/local/lib/python3.6/dist-packages/passlib/handlers/bcrypt.py", line 374, in _finalize_backend_mixin
    result = safe_verify("test", test_hash_20)
  File "/usr/local/lib/python3.6/dist-packages/passlib/handlers/bcrypt.py", line 293, in safe_verify
    return verify(secret, hash)
  File "/usr/local/lib/python3.6/dist-packages/passlib/utils/handlers.py", line 761, in verify
    return consteq(self._calc_checksum(secret), chk)
  File "/usr/local/lib/python3.6/dist-packages/passlib/handlers/bcrypt.py", line 688, in _calc_checksum_raw
    hash = _pybcrypt.hashpw(secret, config)
  File "/usr/local/lib/python3.6/dist-packages/bcrypt/__init__.py", 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 get-pip.py, 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/__init__.py, 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