Replace Argon with Python3 crypt
Vessels don't have the resources for Argon...
This commit is contained in:
parent
226fd75a55
commit
92568140f7
2 changed files with 10 additions and 18 deletions
|
@ -1,9 +1,10 @@
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
from socket import gethostname
|
from socket import gethostname
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from hmac import compare_digest
|
||||||
|
|
||||||
from argon2 import PasswordHasher
|
import crypt
|
||||||
from argon2.exceptions import InvalidHash
|
import re
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
|
@ -15,25 +16,17 @@ class Config:
|
||||||
self.hash_passwords()
|
self.hash_passwords()
|
||||||
|
|
||||||
def hash_passwords(self):
|
def hash_passwords(self):
|
||||||
hasher = PasswordHasher()
|
|
||||||
|
|
||||||
for user, password in self.config.items("USERS"):
|
for user, password in self.config.items("USERS"):
|
||||||
try:
|
if not re.match(r"\$\d\$", string):
|
||||||
hasher.check_needs_rehash(password)
|
self.config["USERS"][user] = crypt.crypt(
|
||||||
except InvalidHash:
|
password, crypt.mksalt())
|
||||||
self.config["USERS"][user] = hasher.hash(password)
|
|
||||||
|
|
||||||
with open(self.path, "w") as configfile:
|
with open(self.path, "w") as configfile:
|
||||||
self.config.write(configfile)
|
self.config.write(configfile)
|
||||||
|
|
||||||
def verify_password(self, user, password):
|
def verify_password(self, user, password):
|
||||||
hasher = PasswordHasher()
|
hashed = self.config["USERS"][user]
|
||||||
|
return compare_digest(hashed, crypt.crypt(password, hashed))
|
||||||
try:
|
|
||||||
hasher.verify(self.config["USERS"][user], password)
|
|
||||||
return True
|
|
||||||
except:
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hostname(self):
|
def hostname(self):
|
||||||
|
@ -47,4 +40,4 @@ class Config:
|
||||||
def maildir(self):
|
def maildir(self):
|
||||||
path = self.config.get("SERVER", "maildir", fallback="maildir")
|
path = self.config.get("SERVER", "maildir", fallback="maildir")
|
||||||
Path(path).mkdir(parents=True, exist_ok=True)
|
Path(path).mkdir(parents=True, exist_ok=True)
|
||||||
return path
|
return path
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
aiosmtpd
|
aiosmtpd
|
||||||
argon2-cffi
|
|
Loading…
Reference in a new issue