From 731716856cf2cf329d9a4b8f7c990732d7bd2618 Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Tue, 6 Jan 2026 17:32:24 +0100 Subject: [PATCH] check whether bcrypt is usuable with passlib/libpass version --- radicale/auth/htpasswd.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/radicale/auth/htpasswd.py b/radicale/auth/htpasswd.py index 1c4b2b55..47f01727 100644 --- a/radicale/auth/htpasswd.py +++ b/radicale/auth/htpasswd.py @@ -61,7 +61,7 @@ from typing import Any, Tuple from passlib.hash import apr_md5_crypt, sha256_crypt, sha512_crypt -from radicale import auth, config, logger +from radicale import auth, config, logger, utils class Auth(auth.BaseAuth): @@ -120,12 +120,22 @@ class Auth(auth.BaseAuth): "The htpasswd encryption method 'bcrypt' or 'autodetect' requires " "the bcrypt module (entries found: %d)." % self._htpasswd_bcrypt_use) from e else: - self._has_bcrypt = True + [bcrypt_usable, info] = utils.passlib_libpass_supports_bcrypt() + if bcrypt_usable: + self._has_bcrypt = True + logger.debug(info) + else: + logger.warning(info) if self._encryption == "autodetect": if self._htpasswd_bcrypt_use == 0: logger.info("auth htpasswd encryption is 'radicale.auth.htpasswd_encryption.%s' and bcrypt module found, but currently not required", self._encryption) else: logger.info("auth htpasswd encryption is 'radicale.auth.htpasswd_encryption.%s' and bcrypt module found (bcrypt entries found: %d)", self._encryption, self._htpasswd_bcrypt_use) + if not bcrypt_usable: + raise RuntimeError("The htpasswd encryption 'autodetect' requires the bcrypt module but not usuable") + else: + if not bcrypt_usable: + raise RuntimeError("The htpasswd encryption method 'bcrypt' requires the bcrypt module but not usuable") if self._encryption == "bcrypt": self._verify = functools.partial(self._bcrypt, bcrypt) else: