1
0
Fork 0
mirror of https://github.com/Kozea/Radicale.git synced 2025-06-26 16:45:52 +00:00

fix for https://github.com/Kozea/Radicale/issues/1350 replacing passlib[bcrypt] with direct call to bcrypt

This commit is contained in:
Peter Bieringer 2024-03-06 22:42:37 +01:00
parent 34612c71f0
commit c4d80fd385
2 changed files with 4 additions and 8 deletions

2
config
View file

@ -60,7 +60,7 @@
# Htpasswd encryption method # Htpasswd encryption method
# Value: plain | bcrypt | md5 # Value: plain | bcrypt | md5
# bcrypt requires the installation of radicale[bcrypt]. # bcrypt requires the installation of 'bcrypt' module.
#htpasswd_encryption = md5 #htpasswd_encryption = md5
# Incorrect authentication delay (seconds) # Incorrect authentication delay (seconds)

View file

@ -73,15 +73,11 @@ class Auth(auth.BaseAuth):
self._verify = self._md5apr1 self._verify = self._md5apr1
elif encryption == "bcrypt": elif encryption == "bcrypt":
try: try:
from passlib.hash import bcrypt import bcrypt
except ImportError as e: except ImportError as e:
raise RuntimeError( raise RuntimeError(
"The htpasswd encryption method 'bcrypt' requires " "The htpasswd encryption method 'bcrypt' requires "
"the passlib[bcrypt] module.") from e "the bcrypt module.") from e
# A call to `encrypt` raises passlib.exc.MissingBackendError with a
# good error message if bcrypt backend is not available. Trigger
# this here.
bcrypt.hash("test-bcrypt-backend")
self._verify = functools.partial(self._bcrypt, bcrypt) self._verify = functools.partial(self._bcrypt, bcrypt)
else: else:
raise RuntimeError("The htpasswd encryption method %r is not " raise RuntimeError("The htpasswd encryption method %r is not "
@ -92,7 +88,7 @@ class Auth(auth.BaseAuth):
return hmac.compare_digest(hash_value.encode(), password.encode()) return hmac.compare_digest(hash_value.encode(), password.encode())
def _bcrypt(self, bcrypt: Any, hash_value: str, password: str) -> bool: def _bcrypt(self, bcrypt: Any, hash_value: str, password: str) -> bool:
return bcrypt.verify(password, hash_value.strip()) return bcrypt.checkpw(password = password.encode('utf-8'), hashed_password = hash_value.encode())
def _md5apr1(self, hash_value: str, password: str) -> bool: def _md5apr1(self, hash_value: str, password: str) -> bool:
return apr_md5_crypt.verify(password, hash_value.strip()) return apr_md5_crypt.verify(password, hash_value.strip())