Skip to content

Commit 8562ccc

Browse files
committed
Require STARTTLS for incoming port 25 connections
We already require that outgoing connections use STARTTLS so other servers need a valid TLS certificate to accept messages from us. It is then very unlikely that they cannot use TLS to send messages to us. Conversely, if they only can send messages to use without TLS, it likely does not have STARTLS on its port 25 and then we don't want to accept messages from them because we will likely not be able to reply.
1 parent fa9aa5b commit 8562ccc

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
- Require TLS 1.2 for outgoing SMTP connections
66
([#685](https://github.com/chatmail/relay/pull/685))
77

8+
- require STARTTLS for incoming port 25 connections
9+
([#684](https://github.com/chatmail/relay/pull/684))
10+
811
- filtermail: run CPU-intensive handle_DATA in a thread pool executor
912
([#676](https://github.com/chatmail/relay/pull/676))
1013

cmdeploy/src/cmdeploy/postfix/master.cf.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ smtp inet n - y - - smtpd -v
1414
{%- else %}
1515
smtp inet n - y - - smtpd
1616
{%- endif %}
17+
-o smtpd_tls_security_level=encrypt
1718
-o smtpd_proxy_filter=127.0.0.1:{{ config.filtermail_smtp_port_incoming }}
1819
submission inet n - y - 5000 smtpd
1920
-o syslog_name=postfix/submission

cmdeploy/src/cmdeploy/tests/online/test_0_login.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import queue
2-
import socket
2+
import smtplib
33
import threading
44

55
import pytest
@@ -91,25 +91,23 @@ def login_smtp_imap(smtp, imap):
9191

9292
def test_no_vrfy(chatmail_config):
9393
domain = chatmail_config.mail_domain
94-
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
95-
sock.settimeout(10)
96-
try:
97-
sock.connect((domain, 25))
98-
except socket.timeout:
99-
pytest.skip(f"port 25 not reachable for {domain}")
100-
banner = sock.recv(1024)
101-
print(banner)
102-
sock.send(b"VRFY wrongaddress@%s\r\n" % (chatmail_config.mail_domain.encode(),))
103-
result = sock.recv(1024)
94+
95+
s = smtplib.SMTP(domain)
96+
s.starttls()
97+
98+
s.putcmd("vrfy", f"wrongaddress@{chatmail_config.mail_domain}")
99+
result = s.getreply()
104100
print(result)
105-
sock.send(b"VRFY echo@%s\r\n" % (chatmail_config.mail_domain.encode(),))
106-
result2 = sock.recv(1024)
101+
s.putcmd("vrfy", f"echo@{chatmail_config.mail_domain}")
102+
result2 = s.getreply()
107103
print(result2)
108-
assert result[0:10] == result2[0:10]
109-
sock.send(b"VRFY wrongaddress\r\n")
110-
result = sock.recv(1024)
104+
assert result[0] == result2[0] == 252
105+
assert result[1][0:6] == result2[1][0:6] == b"2.0.0 "
106+
s.putcmd("vrfy", "wrongaddress")
107+
result = s.getreply()
111108
print(result)
112-
sock.send(b"VRFY echo\r\n")
113-
result2 = sock.recv(1024)
109+
s.putcmd("vrfy", "echo")
110+
result2 = s.getreply()
114111
print(result2)
115-
assert result[0:10] == result2[0:10] == b"252 2.0.0 "
112+
assert result[0] == result2[0] == 252
113+
assert result[1][0:6] == result2[1][0:6] == b"2.0.0 "

0 commit comments

Comments
 (0)