636 Commits

Author SHA1 Message Date
Alberto Bertogli
2f17f570b3 docs: Add references to the Alpine package
Thanks to raspbeguy (https://github.com/raspbeguy) for creating and
maintaining the Alpine package.
2025-01-19 18:18:52 +00:00
Alberto Bertogli
deb2a2f22b docs: v1.15.0 release notes 2025-01-17 18:10:51 +00:00
Alberto Bertogli
19ce435e92 Regenerate auto-generated files
This patch regenerates the auto-generated files. There are no
significant changes.

- Protobuf files updated the comment formatting to match recent changes
  in Go libraries.
- IANA assignment for a AEGIS (currently an IETF draft) has been
  updated.
- The link to the human-readable IANA assignment tables from the
  generator was manually updated.
2024-12-01 22:21:19 +00:00
Alberto Bertogli
7e560aba6e modules: Update Go dependencies 2024-12-01 22:17:40 +00:00
Andreas Deininger
227379ecde cleanup: Remove unused/unnecessary code 2024-12-01 22:03:47 +00:00
Andreas Deininger
eb21e61a4f monitoring: Use _ for unused function arguments 2024-12-01 22:03:10 +00:00
Alberto Bertogli
9dab8f4f04 etc: Add fail2ban filter configuration example
This patch adds a fail2ban filter configuration example for chasquid.

It can be used to configure fail2ban to detect IPs causing connection
churn or high rate of errors.
2024-11-17 10:25:58 +00:00
Alberto Bertogli
41bb7b6f5e normalize: Improve ToCRLF/StringToCRLF performance
The ToCRLF/StringToCRLF functions are not very performance critical, but
we call it for each mail, and the current implementation is very
inefficient (mainly because it goes one byte at a time).

This patch replaces it with a better implementation that goes line by line.

The new implementation of ToCRLF is ~40% faster, and StringToCRLF is ~60%
faster.

```
$ benchstat old.txt new.txt
goos: linux
goarch: amd64
pkg: blitiri.com.ar/go/chasquid/internal/normalize
cpu: 13th Gen Intel(R) Core(TM) i9-13900T
                │    old.txt    │               new.txt                │
                │    sec/op     │    sec/op     vs base                │
ToCRLF-32         162.96µ ±  6%   95.42µ ± 12%  -41.44% (p=0.000 n=10)
StringToCRLF-32   190.70µ ± 14%   76.51µ ±  6%  -59.88% (p=0.000 n=10)
geomean            176.3µ         85.44µ        -51.53%
```
2024-10-31 13:10:14 +00: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
a1b6821ce1 dkim: Make timestamp parsing more robust against overflow
The timestamp string in the t= and x= headers is an "unsigned decimal
integer", but time.Unix takes an int64. Today we parse it as uint64 and
then cast it, but this can cause issues with overflow and type
conversion.

This patch fixes that by parsing the timestamps as signed integers, and
then checking they're positive.
2024-05-10 16:47:22 +01:00
Alberto Bertogli
aae0367c60 Log how many things were loaded for each domain
This patch makes chasquid log how many users, aliases and DKIM keys were
loaded for each domain.

This makes it easier to confirm changes, and troubleshoot problems
related to these per-domain configuration files.
2024-05-10 12:19:49 +01:00
Alberto Bertogli
e6a9410377 Exit if there's an error reading users/aliases files on startup
Today, when starting up, if there's an error reading the users or
aliases files, we only log but do not exit. And then those files will
not be attempted to be read on the periodic reload.

We also treat "file does not exist" as an error for users file, but not
aliases file, resulting in inconsistent behaviour between the two.

All of this makes some classes of problems (like permission errors) more
difficult to spot and troubleshoot. For example,
https://github.com/albertito/chasquid/issues/55.

So this patch makes errors reading users/aliases files on startup a
fatal error, and also unifies the "file does not exist" behaviour to
make it not an error in both cases.

Note that the behaviour on the periodic reload is unchanged: treat these
errors as fatal too. This may be changed in future patches.
2024-05-10 12:09:53 +01:00
Alberto Bertogli
0414af09b4 test: Avoid file with ':' in the name
Unfortunately, `go get` rejects repos that have files with ':':
https://github.com/golang/go/issues/28001.

We have one such file in the tests.

This prevents some of the Go tooling from working on the latest release,
including pkg.go.dev.

So, as a workaround we use a compatible file name in the repository, and
rename it when running the test. This is very hacky, but it's okay for a
single test.
2024-04-27 16:55:07 +01:00
Alberto Bertogli
7dbde5a694 ci: Fix docker push of latest tag
The `latest` tag is meant to track the `main` branch, but I just noticed
it hasn't been pushed out in a while. This is because the conditional
gating the push on the branch being `main` is incorrect.

This patch fixes the problem by using the correct conditional on the
branch name.
2024-04-21 12:05:26 +01:00
Alberto Bertogli
4fbd6fc94a docs: v1.14.0 release notes 2024-04-21 11:24:30 +01:00
Alberto Bertogli
002c2ff59c modules: Update Go dependencies 2024-04-21 11:24:30 +01:00
Alberto Bertogli
1a1befc75a dkim: Update .gitignore pattern for private test cases
The current .gitignore pattern doesn't work when the private test cases
are a symlink, which can be convenient.

This patch fixes it by changing the pattern to match symlinks as well as
directories.
2024-04-21 11:08:08 +01:00
Alberto Bertogli
6ff08b1ec2 ci: Rename master branch to main
These days `main` is more common, and I find it more intuitive.
2024-04-19 18:57:30 +01:00
Alberto Bertogli
7a2e49c849 test/t-21-dkim: Add cross-tool check against driusan/dkimverify
This patch adds a cross-tool integration check that uses
driusan/dkim's dkimverify to confirm it can verify our own DKIM signatures.

It is optional, since the tool may not be present.
2024-03-12 20:43:21 +00:00
Alberto Bertogli
8abed11ede test: Remove obsolete driusan/dkim and dkimpy tests
This patch removes the integration tests that covered using driusan/dkim
and dkimpy's tools in the example hook.

Now that we have internal DKIM support, the example hook doesn't attempt
to use them, so we can remove the tests that cover it.

Those tools, and other DKIM implementations, can still be used in the
post-data hook just as before.
2024-03-12 20:43:21 +00:00
Alberto Bertogli
5eded4edc3 test: Unify (most) SMTP client calls
To send mails, today some tests use msmtp and others our internal smtpc.py.

This works, but msmtp slows down the tests significantly, and smtpc.py
is also not particularly fast, and also has some limitations.

This patch introduces a new SMTP client tool written in Go, and makes
almost all the tests use it.

Some tests still remain on msmtp, mainly for client-check compatibility.
It's likely that this will be moved in later patches to a separate
special-purpose test.

With this patch, integration tests take ~20% less time than before.
2024-03-12 20:43:21 +00:00
Alberto Bertogli
7f44db008d test/t-11-dovecot: Disable authentication penalty
Dovecot applies an authentication penalty, where it delays failed attempts.

Because we intentionally do bad authentications for testing, this slows
downs the tests significantly. So this patch disables it.
2024-03-12 20:43:21 +00:00
Alberto Bertogli
3c3c32e2fb test: Don't run "go build" each time a helper is invoked
Our tests invoke a variety of helpers, some of them are written in Go.
Today, we call "go build" (directly or indirectly via "go run"), which is
a bit wasteful and slows down the tests.

This patch makes the tests only build our Go helpers once every 10s at
most.

The solution is a bit hacky but in the context of these tests, it's
practical.
2024-03-12 20:43:21 +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
f13fdf0ac8 modules: Update Go dependencies 2024-03-10 09:16:42 +00:00
Alberto Bertogli
18b3684756 Update minimum supported Go version 1.18 -> 1.21
Go 1.21 has useful packages and features that will be needed in future
patches, and has been out for > 6 months, since 2023-08.
2024-03-10 09:10:06 +00:00
Alberto Bertogli
1208ea1082 test: Fix generate_cert cache age logic
The generate_cert cache has a bug because it uses the directory's age,
which won't necessarily change, and it was always re-generating
certificates after 10m.

This patch fixes the bug by checking the age of the private key file
instead of the directory.
2024-03-09 13:04:25 +00:00
Alberto Bertogli
3be7cd5160 safeio: Add tests for error conditions
This patch adds tests to verify how safeio behaves when *os.File
operations return various errors.

To do this, we allow the possibility of wrapping os.CreateTemp, so we
can simulate the errors during testing.

This is not pretty, but the code is small enough that the readability
overhead is minimal, and we get a lot of tests from it.
2024-03-07 23:07:37 +00:00
Alberto Bertogli
06aea2f786 chasquid-util: Move tests to chamuyero scripts
We already use chamuyero scripts for some of chasquid-util's tests, this
patch moves most of the rest too, for consistency.
2024-03-07 23:07:37 +00:00
Alberto Bertogli
ac2b037f33 chasquid-util: Include in coverage tests
This patch adds chasquid-util command-line to the coverage tests, so it is
easier to identify testing gaps.
2024-03-07 23:07:37 +00:00
Alberto Bertogli
96fe38c479 coverhtml: Add dark mode support
This patch adds a dark mode support to coverhtml's output.
2024-03-07 23:07:37 +00:00
Alberto Bertogli
b0877f0866 chasquid-util: Print errors to stderr
To make it more difficult to accidentally supress errors, or mistake them
for legitimate output, print errors to stderr.
2024-03-07 23:07:37 +00:00
Alberto Bertogli
8e1fd52442 chasquid-util: Add short descriptions of each subcommand
This patch adds short descriptions of each subcommand, to make the help
message more helpful.
2024-03-07 23:07:36 +00:00
Alberto Bertogli
8b056823e6 docs: Add a "Clients" document
We've had a couple of reported issues about the difficulty of setting up
new clients, or confusion due to using broken clients:

- https://github.com/albertito/chasquid/pull/46
- https://github.com/albertito/chasquid/issues/52

This patch adds the first version of a "Clients" document that includes
requirements for all clients, configuration examples, and a list of
known-problematic client software.

The goal is to help reduce friction and confusion when setting up
clients.

The document needs more polishing and examples, which hopefully will be
added later.

Fixes https://github.com/albertito/chasquid/issues/48.
2024-02-06 00:50:30 +00:00
Alberto Bertogli
a7342fcb1b ci: Bump Github action versions
Nearly all the github actions we rely on have increased their major
version, at least to update the Node.js version they run on, since the
previous one is being deprecated and will eventually become unsupported.

So this patch updates all the versions of the github actions we use.
2024-02-05 00:04:50 +00:00
Alberto Bertogli
2128f354ed ci: Remove Cirrus CI configuration
Unfortunately, but understandably, Cirrus CI no longer offers enough
free compute credits to run our tests reliably.

They're currently only used to run the Go tests on FreeBSD.

In the future, this might be replaced with something else; but until a
proper replacement can be found and tested, remove it to avoid
introducing noise in the CI results.
2024-02-05 00:04:50 +00:00
Alberto Bertogli
b5b06bba92 ci: Make Docker workflows run on tag pushes
Since we moved the Docker workflows to Github (after v1.10), they have
not been running on tags, so there are no tagged docker images for
v1.11, v1.12 and v1.13.

This is (hopefully) because we're not explicitly asking for the workflow
to be run on tag pushes.

This patch (hopefully) fixes that by adding an explicit section in the
config to make it run on tag pushes.

Thanks to Christoph Mewes (xrstf@github) for reporting this in
https://github.com/albertito/chasquid/issues/51.
2024-02-05 00:04:50 +00:00
Alberto Bertogli
a14ba106b1 docs: Add CVE-2023-52354 links to the release notes
The SMTP smuggling vulnerability fixed in 1.13 (and 1.11.1) has been
given a CVE number: CVE-2023-52354
(https://nvd.nist.gov/vuln/detail/CVE-2023-52354).

This patch adds a link to it in the release notes, for ease of reference.
2024-02-05 00:04:50 +00:00
Ernesto Alfonso
36c5139da4 Skip non-directories in the domains/ directory
This prevents chasquid from attempting to look for certs under a
non-directory, e.g. `/etc/chasquid/domains/.gitignore/certs`.

Amended-by: Alberto Bertogli <albertito@blitiri.com.ar>
  Adjusted commit message, applied `go fmt`.
2024-02-05 00:04:37 +00:00
Alberto Bertogli
bb8f16fb97 docs: Add 1.11.1 to the release notes
chasquid v1.11.1 was released on 2023-12-26 with a backport of the
security fixes from 1.13.

This was requested by users of Debian stable, who are on 1.11.
2024-01-21 11:37:40 +00:00
Alberto Bertogli
e28f346313 docs: v1.13 release notes 2023-12-24 21:56:06 +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
e03594a2c7 test: Make mail_diff more strict
This patch makes mail_diff more strict in its parsing, to ensure we
catch any encoding issues that may otherwise be masked by the default
compatibility policy.
2023-12-23 14:10:16 +00:00
Alberto Bertogli
c4c330d7a4 test: Verify mailbox delivery in minor dialogs test
The minor dialogs test covers some very specific SMTP exchanges, and
some of those include delivering email.

Today, we don't verify the final mailbox, we just check the SMTP
exchange. However, it can be very useful for some of the tests to do
end-to-end checking of the final mailbox.

This patch implements that ability in the test itself, and on the
(currently only) email delivering dialog.

Subsequent patches that introduce new tests will make use of this
feature.
2023-12-23 13:21:27 +00:00
Alberto Bertogli
0c02bfbe76 modules: Update Go dependencies 2023-12-21 15:41:20 +00:00
Alberto Bertogli
83ae4c3478 userdb: Add support for receive-only users
Some use cases, like receive-only MTAs, need domain users for receiving
emails, but have no real need for passwords since they will never use
submission.

Today, that is not supported, and those use-cases require the
administrator to come up with a password unnecessarily, adding
complexity and possibly risk.

This patch implements "receive-only users", which don't have a valid
password, thus exist for the purposes of delivering mail, but always
fail authentication.

See https://github.com/albertito/chasquid/issues/44 for more details and
rationale.

Thanks to xavierg who suggested this feature on IRC.
2023-12-03 11:59:26 +00:00
Alberto Bertogli
dbff2f0455 Reject empty listening addresses
Using an empty listening address will result in chasquid listening on a
random port, which is a dangerous misconfiguration.

That is most likely done to prevent it from listening at all.

To prevent this misconfiguration, explicitly reject empty listening
addresses early and with a warning, so there is no ambiguity.

Users can still prevent chasquid from listening by just commenting out
the entry in the config (and not passing any systemd file descriptors).

See https://github.com/albertito/chasquid/issues/45 for more details and
discussion, including alternatives considered.

Thanks to xavierg who reported this via IRC.
2023-12-02 15:08:09 +00:00
Alberto Bertogli
d93d7cae10 config: Quote strings when logging the configuration
When logging the configuration, we currently don't quote the string
values, which can make whitespace-induced problems difficult to identify
and troubleshoot.

This patch changes the formatting to always quote string values when
logging the configuration.
2023-12-02 15:01:31 +00:00
Ernesto Alfonso
a0f09308ed docker/add-user.sh: Don't crash on updating when there is a single user
When a single dovecot user exists and their password is being updated via
docker/add-user.sh, the `grep -v` command intended to remove the user's
old password will not match any lines and exit with error code 1, causing
the entire script to fail.

This patch fixes it by replacing the if-grep logic with a simpler sed
invocation.

https://github.com/albertito/chasquid/pull/43

Amended-by: Alberto Bertogli <albertito@blitiri.com.ar>
  Minor edits to the commit message.
2023-10-29 22:28:08 +00:00
Ernesto Alfonso
0ce84a3b5d docker/add-user.sh: Support getting email and password from env variables
This patch extends docker/add-user.sh to support getting the email and
password from environment variables.

That way, docker/add-user.sh can be used in scripts.

https://github.com/albertito/chasquid/pull/43

Amended-by: Alberto Bertogli <albertito@blitiri.com.ar>
  Minor edits to the commit message.
2023-10-29 22:25:35 +00:00