Compare commits

..

14 Commits

Author SHA1 Message Date
missytake
3eae1657de fix lint 2024-06-19 14:42:27 +02:00
Christian Hagenest
736c67ac1f test commit 2024-06-19 14:40:58 +02:00
Christian Hagenest
295072e57b replace § with $ in doveauth 2024-06-19 14:40:58 +02:00
Christian Hagenest
dc17088517 lint 2024-06-19 14:40:58 +02:00
Christian Hagenest
514a063142 black 2024-06-19 14:40:58 +02:00
Christian Hagenest
2b96586e12 import passlib.hash 2024-06-19 14:40:58 +02:00
Christian Hagenest
8fde4d929d Update Changelog 2024-06-19 14:40:58 +02:00
Christian Hagenest
683aefa37c add passlib to the correct pyproject.toml 2024-06-19 14:40:58 +02:00
Christian Hagenest
b951ec12c5 replace crypt with passlib 2024-06-19 14:40:58 +02:00
Christian Hagenest
3d8ac6b598 add changelog 2024-06-19 14:40:57 +02:00
Christian Hagenest
9515a37687 update doveauth hashing 2024-06-19 14:35:19 +02:00
Christian Hagenest
b5d0b0ad9a try generating salt manually 2024-06-19 14:35:19 +02:00
Christian Hagenest
3f4989223d encode to bytes 2024-06-19 14:35:19 +02:00
Christian Hagenest
9be0408ab8 replace crypt with hashlib 2024-06-19 14:35:19 +02:00
6 changed files with 10 additions and 47 deletions

View File

@@ -2,6 +2,9 @@
## untagged
- replace crypt with passlib, as crypt will be deprecated in Python 3.13
([#319](https://github.com/deltachat/chatmail/pull/319))
- Reject DKIM signatures that do not cover the whole message body.
([#321](https://github.com/deltachat/chatmail/pull/321))

View File

@@ -12,6 +12,7 @@ dependencies = [
"deltachat-rpc-client",
"filelock",
"requests",
"passlib",
]
[tool.setuptools]
@@ -26,7 +27,6 @@ chatmail-metadata = "chatmaild.metadata:main"
filtermail = "chatmaild.filtermail:main"
echobot = "chatmaild.echo:main"
chatmail-metrics = "chatmaild.metrics:main"
rm_accounts = "chatmaild.rm_accounts:main"
[project.entry-points.pytest11]
"chatmaild.testplugin" = "chatmaild.tests.plugin"

View File

@@ -13,7 +13,6 @@ class Config:
self.max_user_send_per_minute = int(params["max_user_send_per_minute"])
self.max_mailbox_size = params["max_mailbox_size"]
self.delete_mails_after = params["delete_mails_after"]
self.delete_accounts_after = int(params["delete_accounts_after"])
self.username_min_length = int(params["username_min_length"])
self.username_max_length = int(params["username_max_length"])
self.password_min_length = int(params["password_min_length"])

View File

@@ -1,4 +1,3 @@
import crypt
import json
import logging
import os
@@ -11,6 +10,8 @@ from socketserver import (
UnixStreamServer,
)
import passlib.hash
from .config import Config, read_config
from .database import Database
@@ -23,8 +24,9 @@ class UnknownCommand(ValueError):
def encrypt_password(password: str):
# https://doc.dovecot.org/configuration_manual/authentication/password_schemes/
passhash = crypt.crypt(password, crypt.METHOD_SHA512)
return "{SHA512-CRYPT}" + passhash
pw = passlib.hash.sha512_crypt.hash(password).split("$")
return "{SHA512-CRYPT}$" + pw[1] + "$" + pw[3] + "$" + pw[4]
def is_allowed_to_create(config: Config, user, cleartext_password) -> bool:
@@ -106,8 +108,7 @@ def lookup_passdb(db, config: Config, user, cleartext_password):
if userdata:
# Update last login time.
conn.execute(
"UPDATE users SET last_login=? WHERE addr=?",
(int(time.time() // 86400), user),
"UPDATE users SET last_login=? WHERE addr=?", (int(time.time()), user)
)
userdata["home"] = f"/home/vmail/mail/{config.mail_domain}/{user}"

View File

@@ -20,9 +20,6 @@ max_mailbox_size = 100M
# days after which mails are unconditionally deleted
delete_mails_after = 20
# days after which accounts are deleted if nobody logged in
delete_accounts_after = 25
# minimum length a username must have
username_min_length = 9

View File

@@ -1,37 +0,0 @@
import sys
import time
import shutil
from pathlib import Path
from .config import read_config
from .database import Database
def remove_users(db: Database, cutoff_date: int):
with db.write_transaction() as conn:
delete_query = "DELETE FROM users WHERE last_login <?"
conn.execute(delete_query, (cutoff_date))
def remove_user_data(db: Database, cutoff_date: int, vmail_basedir: Path):
"""Collects all users where last_login < cutoff_date and deletes corresponding directories."""
with db.write_transaction() as conn:
select_query = "SELECT user FROM users WHERE last_login <?"
cursor = conn.execute(select_query, (cutoff_date,))
usernames = cursor.fetchall()
for username in usernames:
user_dir = vmail_basedir / username[0]
if user_dir.exists() and user_dir.is_dir():
shutil.rmtree(user_dir, ignore_errors=True)
print(f"Deleted directory: {user_dir}")
def main():
db = Database(sys.argv[2])
config = read_config(sys.argv[3])
today = int(time.time() // 86400)
cutoff_date = today - config.delete_accounts_after
remove_user_data(db, cutoff_date)