8 Commits

Author SHA1 Message Date
Alberto Bertogli
1cf24ba94a Auto-format the Python scripts
We have a few Python scripts which over the years ended up with a
variety of formatting.

This patch auto-formats them using `black -l 79` to make them more
uniform, and easier to read and write.
2025-04-11 14:17:17 +01:00
Alberto Bertogli
723c47d352 test: Update deprecated ssl.wrap_socket() call
ssl.wrap_socket() has been deprecated and is no longer functional in
Python 3.12: https://docs.python.org/3/whatsnew/3.12.html#ssl.

This patch replaces it with the equivalent (in this context)
ssl.SSLContext.
2024-10-31 13:10:14 +00:00
Alberto Bertogli
76a72367ae dkim: Implement internal dkim signing and verification
This patch implements internal DKIM signing and verification.
2024-03-12 20:43:21 +00:00
Alberto Bertogli
a996106eee smtpsrv: Strict CRLF enforcement in DATA contents
The RFCs are very clear that in DATA contents:

> CR and LF MUST only occur together as CRLF; they MUST NOT appear
> independently in the body.

https://www.rfc-editor.org/rfc/rfc5322#section-2.3
https://www.rfc-editor.org/rfc/rfc5321#section-2.3.8

Allowing "independent" CR and LF can cause a number of problems.

In particular, there is a new "SMTP smuggling attack" published recently
that involves the server incorrectly parsing the end of DATA marker
`\r\n.\r\n`, which an attacker can exploit to impersonate a server when
email is transmitted server-to-server.

https://www.postfix.org/smtp-smuggling.html
https://sec-consult.com/blog/detail/smtp-smuggling-spoofing-e-mails-worldwide/

Currently, chasquid is vulnerable to this attack, because Go's standard
libraries net/textproto and net/mail do not enforce CRLF strictly.

This patch fixes the problem by introducing a new "dot reader" function
that strictly enforces CRLF when reading dot-terminated data, used in
the DATA input processing.

When an invalid newline terminator is found, the connection is aborted
immediately because we cannot safely recover from that state.

We still keep the internal representation as LF-terminated for
convenience and simplicity.

However, the MDA courier is changed to pass CRLF-terminated lines, since
that is an external program which could be strict when receiving email
messages.

See https://github.com/albertito/chasquid/issues/47 for more details and
discussion.
2023-12-24 10:43:27 +00:00
Alberto Bertogli
cf81fbee74 dovecot: Add tests for more error cases
This patch adds more tests for the dovecot library, in particular:
 - Protocol errors (invalid versions, etc.).
 - Invalid command (cli-specific test).
 - Connection breakups.
2018-06-04 01:34:32 +01:00
Alberto Bertogli
1b28734e44 test: Make "chamuyero" work in utf8 regardless of the environment
Our chamuyero tests involve reading and writing utf8. This usually
works, but is dependent on the environment: on LC_ALL=POSIX environment,
for example, Python enforces ascii as the default encoding, and the
tests break.

So this patch makes chamuyero explicitly set utf8 encodings in stdout
and all the sockets.
2018-03-26 01:58:47 +01:00
Alberto Bertogli
61d2961ee9 test: Add a new integration test with minor dialogs
This patch adds a new integration test, which executes various small
dialogs, to cover corner cases that are not well covered (according to
our coverage report).

For example, "EHLO" without domain, or invalid DATA.

While we could do them via Go tests, this way is more realistic, and the
tests are easier to write.
2018-03-02 19:37:37 +00:00
Alberto Bertogli
10427d7f49 test: Add "chamuyero", a tool to test line-oriented I/O
This patch adds "chamuyero", a a tool to test and validate line-oriented
commands and servers.

It can launch and communicate with other processes, and follow a script of
line-oriented request-response, validating the dialog as it goes along.

This can be used to test line-oriented network protocols (such as SMTP) or
interactive command-line tools.

It will be used in follow up patches to test new commands and
functionality.
2017-07-13 22:05:45 +01:00