mirror of
https://github.com/chatmail/relay.git
synced 2026-05-10 16:04:37 +00:00
Compare commits
2 Commits
link2xt/se
...
global-deb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b441891d1f | ||
|
|
1c37d1f59b |
@@ -9,8 +9,9 @@ from aiosmtpd.controller import UnixSocketController
|
||||
from smtplib import SMTP as SMTPClient
|
||||
|
||||
|
||||
def check_encrypted(message):
|
||||
def check_encrypted(content):
|
||||
"""Check that the message is an OpenPGP-encrypted message."""
|
||||
message = BytesParser(policy=policy.default).parsebytes(content)
|
||||
if not message.is_multipart():
|
||||
return False
|
||||
if message.get("subject") != "...":
|
||||
@@ -46,8 +47,7 @@ class ExampleHandler:
|
||||
|
||||
valid_recipients = []
|
||||
|
||||
message = BytesParser(policy=policy.default).parsebytes(envelope.content)
|
||||
mail_encrypted = check_encrypted(message)
|
||||
mail_encrypted = check_encrypted(envelope.content)
|
||||
|
||||
res = []
|
||||
for recipient in envelope.rcpt_tos:
|
||||
@@ -68,13 +68,7 @@ class ExampleHandler:
|
||||
continue
|
||||
|
||||
is_outgoing = recipient_local_domain[1] != my_local_domain[1]
|
||||
|
||||
if (
|
||||
is_outgoing
|
||||
and not mail_encrypted
|
||||
and message.get("secure-join") != "vc-request"
|
||||
and message.get("secure-join") != "vg-request"
|
||||
):
|
||||
if is_outgoing and not mail_encrypted:
|
||||
res += ["500 Outgoing mail must be encrypted"]
|
||||
continue
|
||||
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
import pytest
|
||||
|
||||
from .filtermail import check_encrypted
|
||||
from email.parser import BytesParser
|
||||
from email import policy
|
||||
|
||||
|
||||
def test_filtermail():
|
||||
def check_encrypted_bstr(content):
|
||||
message = BytesParser(policy=policy.default).parsebytes(content)
|
||||
return check_encrypted(message)
|
||||
assert not check_encrypted(b"foo")
|
||||
|
||||
assert not check_encrypted_bstr(b"foo")
|
||||
|
||||
assert not check_encrypted_bstr(
|
||||
assert not check_encrypted(
|
||||
"\r\n".join(
|
||||
[
|
||||
"Subject: =?utf-8?q?Message_from_foobar=40c2=2Etestrun=2Eorg?=",
|
||||
@@ -40,7 +36,7 @@ def test_filtermail():
|
||||
).encode()
|
||||
)
|
||||
|
||||
assert not check_encrypted_bstr(
|
||||
assert not check_encrypted(
|
||||
"\r\n".join(
|
||||
[
|
||||
"Subject: =?utf-8?q?Message_from_foobar=40c2=2Etestrun=2Eorg?=",
|
||||
@@ -71,7 +67,7 @@ def test_filtermail():
|
||||
)
|
||||
|
||||
# https://xkcd.com/1181/
|
||||
assert not check_encrypted_bstr(
|
||||
assert not check_encrypted(
|
||||
"\r\n".join(
|
||||
[
|
||||
"Subject: =?utf-8?q?Message_from_foobar=40c2=2Etestrun=2Eorg?=",
|
||||
@@ -103,7 +99,7 @@ def test_filtermail():
|
||||
).encode()
|
||||
)
|
||||
|
||||
assert check_encrypted_bstr(
|
||||
assert check_encrypted(
|
||||
"\r\n".join(
|
||||
[
|
||||
"Subject: ...",
|
||||
@@ -176,7 +172,7 @@ def test_filtermail():
|
||||
).encode()
|
||||
)
|
||||
|
||||
assert not check_encrypted_bstr(
|
||||
assert not check_encrypted(
|
||||
"\r\n".join(
|
||||
[
|
||||
"Subject: Buy Penis Enlargement at www.malicious-domain.com",
|
||||
@@ -249,7 +245,7 @@ def test_filtermail():
|
||||
).encode()
|
||||
)
|
||||
|
||||
assert not check_encrypted_bstr(
|
||||
assert not check_encrypted(
|
||||
"\r\n".join(
|
||||
[
|
||||
"Subject: Message opened",
|
||||
|
||||
@@ -110,7 +110,7 @@ def _configure_opendkim(domain: str, dkim_selector: str) -> bool:
|
||||
return need_restart
|
||||
|
||||
|
||||
def _configure_postfix(domain: str) -> bool:
|
||||
def _configure_postfix(domain: str, debug: bool = False) -> bool:
|
||||
"""Configures Postfix SMTP server."""
|
||||
need_restart = False
|
||||
|
||||
@@ -124,21 +124,20 @@ def _configure_postfix(domain: str) -> bool:
|
||||
)
|
||||
need_restart |= main_config.changed
|
||||
|
||||
master_config = files.put(
|
||||
src=importlib.resources.files(__package__)
|
||||
.joinpath("postfix/master.cf")
|
||||
.open("rb"),
|
||||
master_config = files.template(
|
||||
src=importlib.resources.files(__package__).joinpath("postfix/master.cf.j2"),
|
||||
dest="/etc/postfix/master.cf",
|
||||
user="root",
|
||||
group="root",
|
||||
mode="644",
|
||||
debug=debug,
|
||||
)
|
||||
need_restart |= master_config.changed
|
||||
|
||||
return need_restart
|
||||
|
||||
|
||||
def _configure_dovecot(mail_server: str) -> bool:
|
||||
def _configure_dovecot(mail_server: str, debug: bool = False) -> bool:
|
||||
"""Configures Dovecot IMAP server."""
|
||||
need_restart = False
|
||||
|
||||
@@ -149,6 +148,7 @@ def _configure_dovecot(mail_server: str) -> bool:
|
||||
group="root",
|
||||
mode="644",
|
||||
config={"hostname": mail_server},
|
||||
debug=debug,
|
||||
)
|
||||
need_restart |= main_config.changed
|
||||
auth_config = files.put(
|
||||
@@ -215,8 +215,9 @@ def deploy_chatmail(mail_domain: str, mail_server: str, dkim_selector: str) -> N
|
||||
)
|
||||
|
||||
_install_chatmaild()
|
||||
dovecot_need_restart = _configure_dovecot(mail_server)
|
||||
postfix_need_restart = _configure_postfix(mail_domain)
|
||||
debug = False
|
||||
dovecot_need_restart = _configure_dovecot(mail_server, debug=debug)
|
||||
postfix_need_restart = _configure_postfix(mail_domain, debug=debug)
|
||||
opendkim_need_restart = _configure_opendkim(mail_domain, dkim_selector)
|
||||
|
||||
systemd.service(
|
||||
|
||||
@@ -4,13 +4,17 @@ protocols = imap lmtp
|
||||
|
||||
auth_mechanisms = plain
|
||||
|
||||
{% if debug == true %}
|
||||
auth_verbose = yes
|
||||
auth_debug = yes
|
||||
auth_debug_passwords = yes
|
||||
auth_verbose_passwords = plain
|
||||
auth_cache_size = 100M
|
||||
mail_plugins = quota
|
||||
mail_debug = yes
|
||||
{% endif %}
|
||||
|
||||
|
||||
mail_plugins = quota
|
||||
|
||||
# Authentication for system users.
|
||||
passdb {
|
||||
|
||||
@@ -9,7 +9,11 @@
|
||||
# service type private unpriv chroot wakeup maxproc command + args
|
||||
# (yes) (yes) (no) (never) (100)
|
||||
# ==========================================================================
|
||||
smtp inet n - y - - smtpd -v
|
||||
{% if debug == true %}
|
||||
smtp inet n - y - - smtpd -v
|
||||
{% else %}
|
||||
smtp inet n - y - - smtpd
|
||||
{% endif %}
|
||||
#smtp inet n - y - 1 postscreen
|
||||
#smtpd pass - - y - - smtpd
|
||||
#dnsblog unix - - y - 0 dnsblog
|
||||
@@ -67,17 +67,3 @@ class TestEndToEndDeltaChat:
|
||||
break
|
||||
|
||||
pytest.fail("sending succeeded although messages should exceed quota")
|
||||
|
||||
def test_securejoin(self, cmfactory, lp, maildomain2):
|
||||
ac1 = cmfactory.new_online_configuring_account(cache=False)
|
||||
cmfactory.switch_maildomain(maildomain2)
|
||||
ac2 = cmfactory.new_online_configuring_account(cache=False)
|
||||
cmfactory.bring_accounts_online()
|
||||
|
||||
lp.sec("ac1: create QR code and let ac2 scan it, starting the securejoin")
|
||||
qr = ac1.get_setup_contact_qr()
|
||||
|
||||
lp.sec("ac2: start QR-code based setup contact protocol")
|
||||
ch = ac2.qr_setup_contact(qr)
|
||||
assert ch.id >= 10
|
||||
ac1._evtracker.wait_securejoin_inviter_progress(1000)
|
||||
|
||||
6
plan.txt
6
plan.txt
@@ -8,6 +8,12 @@
|
||||
- limit: configure max-connections per account
|
||||
|
||||
|
||||
## Filtermail
|
||||
|
||||
- (alex, Only allow (outgoing) mails if secure-join or autocrypt-pgp-encrypted format.
|
||||
TODO: mime-parse mails and check/add tests
|
||||
|
||||
|
||||
## nami: send out rate limit / rspamd
|
||||
|
||||
- basic outgoing send rate/limits (depending on "account-rating")
|
||||
|
||||
@@ -4,4 +4,4 @@ pushd chatmaild/src/chatmaild
|
||||
../../venv/bin/pytest
|
||||
popd
|
||||
|
||||
online-tests/venv/bin/pytest online-tests/ -vrx --durations=5
|
||||
online-tests/venv/bin/pytest online-tests/ -vrx --durations=5 --slow
|
||||
|
||||
Reference in New Issue
Block a user