1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-17 14:37:02 +00:00
Commit Graph

167 Commits

Author SHA1 Message Date
Alberto Bertogli
b86463f123 README: Mention Debian and Ubuntu packages 2017-03-25 09:39:30 +00:00
Alberto Bertogli
159aa97e8a Change the default MDA binary to "maildrop"
The current default is "procmail" for historical reasons, but the
program has been unmaintained for years and its use is not generally
advisable.

This patch changes the default MDA binary to "maildrop", which is a more
modern and reasonable MDA to use.

We keep the courier.Procmail name for now, as that's internal, but it
may be changed later.  Its documentation is updated to note that the
name is just for reference but it actually works with almost any binary.
2017-03-08 00:19:45 +00:00
Alberto Bertogli
cb6500b993 sts: Don't use expvar.Int.Value in tests, for Go 1.7 compatibility
expvar.Int.Value appeared in Go 1.8, but we want to keep compatibility
with Go 1.7 at least until the next release.

So this patch replaces the use of expvar.Int.Value in tests, to make
them compatible with Go 1.7 again.
2017-03-01 10:14:39 +00:00
Alberto Bertogli
f1b9d9e68a travis.yml: Add Go 1.8 to the test matrix 2017-03-01 01:03:00 +00:00
Alberto Bertogli
9539cfd34d courier: Consider not finding any MX/A records a permanent error
Currently, if we can't find a mail server for a domain, we consider that
a transient failure (semi-accidentally, as we iterate over the (empty)
list of MXs and fall through the list).

It should be treated as a permanent error, in line with other DNS
issues (which is not ideal but seems to be generally accepted
behaviour).
v0.02
2017-03-01 00:22:49 +00:00
Alberto Bertogli
0eeb964534 sts: Limit the size of the HTTPS reads
To avoid accidents/DoS when we are fetching a very very large policy,
this patch limits the size of the reads to 10k, which should be more
than enough for any reasonable policy as per the current draft.
2017-03-01 00:10:10 +00:00
Alberto Bertogli
e66288e4b4 sts: Make tests more end-to-end, to cover HTTP fetching
The current tests stop short of fetching over HTTP, but that code is
unfortunately not trivial.

This patch changes the testing strategy to use a testing HTTP server,
which we point our URLs to. That way we can cover much more code with the
same tests.
2017-03-01 00:10:10 +00:00
Alberto Bertogli
216cf47ffa courier: Add STS policy checking to the SMTP courier
This patch extends the SMTP courier to (optionally) do STS policy
checking when delivering mail.

As STS support is currently experimental, we gate this behind a flag and
is disabled by default.
2017-02-28 22:27:15 +00:00
Alberto Bertogli
d66b06de51 sts: Add an on-disk cache implementation
This patch adds an on-disk cache for STS policies.

Policies are cached by domain, and stored on files in a single
directory.  The files will have as mtime the time when the policy
expires, this makes the store simpler, as it can avoid keeping
additional metadata.

There is no in-memory caching. This may be added in the future, but for
now disk is good enough for our purposes.
2017-02-28 22:27:15 +00:00
Alberto Bertogli
79c0a17328 safeio: Extend WriteFile to take operations before the final rename
This patch extends WriteFile to allow arbitrary operations to be applied
to the file before it is atomically renamed.

This will be used in upcoming patches to change the mtime of the file
before it is atomically renamed.
2017-02-28 22:27:15 +00:00
Alberto Bertogli
fe00750e39 sts: Treat missing/empty "mx" list as invalid
The "mx" field is required, a policy without it is invalid, so add a
check for it.

See
https://mailarchive.ietf.org/arch/msg/uta/Omqo1Bw6rJbrTMl2Zo69IJr35Qo
for more background, in particular the following paragraph:

> The "mx" field is required, so if it is missing, the policy is invalid
> and should not be honored. (It doesn't make sense to honor the policy
> anyway, I would say, since a policy without allowed MXs is essentially a
> way of saying, "There should be TLS and the server identity should match
> the MX, whatever the MX is." I guess this prevents SSL stripping, but
> doesn't prevent DNS injection, so it's of relatively little value.)
2017-02-28 22:27:15 +00:00
Alberto Bertogli
933ab54cd8 sts: Experimental MTA-STS (Strict Transport Security) implementation
This EXPERIMENTAL patch has a basic implementation of MTA-STS (Strict
Transport Security), based on the current draft at
https://tools.ietf.org/html/draft-ietf-uta-mta-sts-02.

It integrates the policy fetching and checking into the smtp-check tool
for convenience, but not yet in chasquid itself.

This is a proof of concept. Many features and tests are missing; in
particular, there is no caching at all yet.
2017-02-28 22:27:15 +00:00
Alberto Bertogli
b8551729db smtp: Try all entries in MX, not just the first one
Currently, we pick the first host in the MX list, and attempt delivery
there. If it fails, we just report the failure to the queue, which will
wait for some time and then try again.

This is not ideal: we should fall back to the other MXs in the list, as
the first host could be having issues for a long time, and not
attempting with the rest just delays delivery.

This patch implements the fallback, so we try all MXs before deciding to
report a failed delivery (unless, of course, an MX returned a permanent
failure).
2017-02-28 22:27:15 +00:00
Alberto Bertogli
c2ea8a8ef0 test: Use our own netcat implementation :(
Netcat's behaviour after seeing EOF from stdin seems to not be very
portable or consistent, even under the same platform.

This has caused t-05-null_address to break recently under some
conditions, for example depending on the particular Debian version of
netcat-openbsd used, and the current situation is unclear.
See https://bugs.debian.org/854292 and https://bugs.debian.org/849192
for more details.

To stop depending on this brittle behaviour, this patch unfortunately
introduces a simple python3-based netcat for our tests to use.
2017-02-26 01:21:35 +00:00
Alberto Bertogli
700539876b smtp-check: Add a -skip_tls_check flag
This patch adds a -skip_tls_check flag, so smtp-check can still be used
from places where outgoing SMTP connections are blocked.
2017-01-04 13:37:26 -03:00
Alberto Bertogli
6479138c57 log: Add a symbol for Fatal log entries
Currently there is no symbol for Fatal-level log entries, so they appear
with "-2", which is distracting.

This patch makes the Fatal log entries have their own symbol, ☠.
2016-11-24 10:18:04 +00:00
Alberto Bertogli
75cc038e68 smtpsrv: Fail to listen if there are no certificates configured
The server is written assuming there's at least one valid SSL/TLS
certificate. For example, it unconditionally advertises STARTTLS, and
only supports AUTH over TLS.

This patch makes the server fail to listen if there are no certificates
configured, so the users don't accidentally run an unsupported
configuration.
2016-11-24 10:09:11 +00:00
Alberto Bertogli
de09923933 smtpsrv: Disable SPF lookups in tests
When testing, we don't want the server to do SPF lookups, as those cause
real DNS queries which can be problematic and add a dependency on the
environment.

This patch adds an internal boolean to disable the SPF lookups, which is
only set from the tests.
2016-11-22 22:05:07 +00:00
Alberto Bertogli
b1a29d8194 etc: Mention certificate requirements in the documentation
chasquid needs at least one certificate in order to start, to prevent
accidental misconfigurations.

This patch documents this in etc/chasquid/README, and while at it fixes
a minor terminology issue.

Thanks to Martin Ferrari for the bug report!
2016-11-22 20:43:07 +00:00
Alberto Bertogli
7b51ce725b chasquid: Ignore non-directories in certs/
We only care about directories within the certs/, but the code as-is
complains if there are files.

This patch makes the iteration skip non-directories entirely.

Thanks to Martin Ferrari for the bug report!
2016-11-22 20:39:19 +00:00
Alberto Bertogli
170aaaf490 chasquid-util: Create the domain directory when adding a user
When adding a user, chasquid-util should create the domain directory if
it doesn't exist, but currently doesn't do that.

This patch fixes this by adding the missing os.MkdirAll call.

Thanks to Martin Ferrari for the bug report!
2016-11-22 20:25:30 +00:00
Alberto Bertogli
279fff3cf8 systemd: Remove spaces around "="
systemd files should not have spaces around the "=", as apparently that
causes problems due to bad parsers.
2016-11-21 21:57:40 +00:00
Alberto Bertogli
f7cdbae8e3 Fix minor typos and formatting directives
This small patch fixes a typo in a comment, and a missing formatting
directive; both were caught by static analysis tools (misspell and go
vet).
2016-11-20 18:32:26 +00:00
Alberto Bertogli
249831064f courier: Skip test if test/util/exitcode is not found
When building the Debian package, the tests are run in such a way that
test/util/exitcode is not found, which causes them to fail.

This patch is a workaround which skips the test if test/util/exitcode is
not found; for now we should consider it temporary, until either the
Debian packaging is fixed, or we decide that its environment is
reasonably enough to make it permanent.
:
2016-11-20 18:30:30 +00:00
Alberto Bertogli
db130639c2 Add configuration file for https://travis-ci.org/
This commit adds a .travis.yml which configures https://travis-ci.org/, a
continuous integration service.

It only builds and runs "go test" for now because their environment is
unfortunately too old to run the integration tests.
2016-11-04 00:20:26 +00:00
Alberto Bertogli
df673c63fb README: Add missing code block
One of the command sequences was not indented enough, so it appears as
text instead of code.

This patch fixes that by surrounding it with ``` to mark it explicitly
as a code block.
2016-11-03 10:21:13 +00:00
Alberto Bertogli
fea808f8e3 queue: Get the DSN domain from the message
Picking the domain used in the DSN message "From" header is more
complicated than it needs to be, causing confusing code paths and having
different uses for the hostname, which should be purely aesthetic.

This patch makes the queue pick the DSN "From" domain from the message
itself, by looking for a local domain in either the sender or the
original recipients. We should find at least one, otherwise it'd be
relaying.

This allows the code to be simplified, and we can narrow the scope of
the hostname option even further.
v0.01
2016-11-03 00:51:59 +00:00
Alberto Bertogli
2da74c1758 docs: Add some documentation and a README 2016-11-03 00:51:59 +00:00
Alberto Bertogli
bcea74ca81 Add a license
This patch adds the Apache 2.0 license. Just a top level file for now,
but we may include the per-file boilerplate later if needed.
2016-11-03 00:51:59 +00:00
Alberto Bertogli
e4b789971d Makefile: Add targets for installation
This patch adds Makefile targets to install the binaries and the
skeleton configuration.
2016-11-03 00:51:59 +00:00
Alberto Bertogli
f43fd3d3cf gitignore: Fix binaries to only include top-level 2016-11-01 23:56:15 +00:00
Alberto Bertogli
cf2b8ade65 etc: Add a skeleton configuration structure
This patch adds an "etc" directory, with a basic configuration structure
that can be used for an initial installation.
2016-11-01 23:56:04 +00:00
Alberto Bertogli
3865dd0ea4 smtp-check: Check SPF and be verbose about errors 2016-11-01 23:56:04 +00:00
Alberto Bertogli
54cce0c2bf test: Reduce the loop detection threshold from 50 down to 5
The loop test can be quite slow, specially on computers without
cryptography-friendly instructions.

This patch introduces a new flag for testing, so that we can bring the
threshold down to 5. The test is just as useful but now runs in a few
seconds, as opposed to a few minutes.
2016-11-01 23:56:04 +00:00
Alberto Bertogli
8cbc4f9ca6 queue: Use a PRNG to generate IDs
The queue IDs are internal to chasquid, and we don't need them to be
cryptographically secure, so this patch changes the ID generation to use
the PRNG.

This also helps avoid entropy issues.
2016-11-01 23:56:04 +00:00
Alberto Bertogli
1bc111f783 Improve the readability of some log messages
This patch contains a few changes to logging messages, to improve log
readability.

While at it, an obsolete TODO in the SMTP courier is removed.
2016-11-01 23:56:04 +00:00
Alberto Bertogli
60a7932bd3 log: Replace glog with a new logging module
glog works fine and has great features, but it does not play along well
with systemd or standard log rotators (as it does the rotation itself).

So this patch replaces glog with a new logging module "log", which by
default logs to stderr, in a systemd-friendly manner.

Logging to files or syslog is still supported.
2016-11-01 23:56:04 +00:00
Alberto Bertogli
60ed30e95a Add a Makefile
This patch introduces a Makefile to make it easier to build with version
information, and run all the tests together.

It's just for convenience, plain go commands continue to work just fine.
2016-11-01 23:55:56 +00:00
Alberto Bertogli
c87c5ec1bc chasquid: Include build and version information
This patch adds the possibility of setting build and version
information, which will be exported and displayed in the monitoring http
server.
2016-10-26 22:25:12 +01:00
Alberto Bertogli
67fe5b50a5 hooks: Add greylisting to the post-data hook
While greylisting has severe drawbacks, it's reasonably common.
This patch extends the default hook for greylisting, using "greylistd".

Completing authentication or passing SPF will make it skip the greylist
check, to avoid some of the most common issues with it.
2016-10-26 22:25:12 +01:00
Alberto Bertogli
6640c09b9e smtpsrv: Always pass the environment variables to the hook
This patch makes the hooks always have a complete set of environment
varuables, set to 0/1 or whatever is appropriate, to make it easier to
write the checks for them.
2016-10-22 18:55:09 +01:00
Alberto Bertogli
14c48153aa smtpsrv: If the hook exits with code 20, it's a permanent failure
It is can be convenient for hooks to indicate that an error is
permanent; for example if the anti-virus found something.

This patch makes it so that if the hook exits with code 20, then it's
considered permanent. Otherwise it is considered transient, to help
prevent accidental errors cause final delivery issues.
2016-10-22 18:55:02 +01:00
Alberto Bertogli
38b4e76090 spf: Support the "ptr" mechanism
The "ptr" mechanism should not be used, but unfortunately many domains
still do.

This patch extends our SPF implementation to support checking it.

https://tools.ietf.org/html/rfc7208#section-5.5
2016-10-22 00:07:07 +01:00
Alberto Bertogli
c00648b4ae queue: Calculate next delay based on creation time
Calculating the next delay based on the previous delay causes daemon
restarts to start from scratch, as we don't persist it.

This can cause a few server restarts to generate many unnecessary sends.

This patch changes the next delay calculation to use the creation time
instead, and also adds a <=1m random perturbation to avoid all queued
emails to be retried at the exact same time after a restart.
2016-10-21 22:20:49 +01:00
Alberto Bertogli
8e9e4eddc5 queue: Rewrite the aliases test to remove races
TestAliases is unfortunately racy, and cause occasional failures.

This patch rewrites it to be more end-to-end, similar to TestBasic,
which should remove the races while keeping the main objectives of the
test.
2016-10-21 22:20:49 +01:00
Alberto Bertogli
d660f88f67 queue: Send DSN for messages that time out in the queue
The queue currently only considers failed recipients when deciding
whether to send a DSN or not. This is a bug, as recipients that time out
are not taken into account.

This patch fixes that issue by including both failed and pending
recipients in the DSN.

It also adds more comprehensive tests for this case, both in the queue
and in the dsn generation code.
2016-10-21 22:20:49 +01:00
Alberto Bertogli
6f048027a7 test: Readability cleanup
This patch makes a few small changes to the tests for readability, such
as changing the arguments to the add_user function.
2016-10-21 22:20:49 +01:00
Alberto Bertogli
f38ae47164 chasquid-util: Make the commands more user-friendly
This patch changes chasquid-util's subcommands and parameters to
(hopefully) make them more user friendly and intuitive by default.

The changes include defaulting the configuration to /etc/chasquid, and
using full addresses as usernames.

It also adds some shell tests to cover most of the functionality.
2016-10-21 22:20:49 +01:00
Alberto Bertogli
febe96697a maillog: Introduce a special-purpose mail logging package
The default INFO logs are more oriented towards debugging and can be
a bit too verbose when looking for high-level information.

This patch introduces a new "maillog" package, used to log messages of
particular relevance to mail transmission at a higher level.
2016-10-21 22:20:47 +01:00
Alberto Bertogli
cda11e03a5 safeio: Preserve file ownership
This patch makes safeio preserve file ownership. This is specially
useful when using command-line utilities as root, but the files they
change are owned by a different user.
2016-10-21 22:18:53 +01:00