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

409 Commits

Author SHA1 Message Date
Alberto Bertogli
4abffc9aaa docs: Minor link and wording fixes
Fix a link to letsencrypt in the how-to, and missing wording in the
readme.
2018-03-04 21:01:06 +00:00
Alberto Bertogli
f3b01cb493 docs: Add missing docstrings, adjust wording to match standard style
This patch adds a missing docstrings for exported identifiers, and
adjust some of the existing ones to match the standard style.

In some cases, the identifiers were un-exported after noticing they had
no external users.

Besides improving documentation, it also reduces the linter noise
significantly.
2018-03-04 16:00:06 +00:00
Alberto Bertogli
40ae9b5f69 docs: Minor edits to the README file
This patch includes minor changes to the README file, such as small
rewordings, adding various links, and badges for convenience.
2018-03-03 14:04:21 +00:00
Alberto Bertogli
0f7fb6b8c7 docs: Split install instructions out of the README
To keep documentation more organized, this patch splits the install
instructions to its own file, and references it from the README file.
2018-03-02 19:56:17 +00:00
Alberto Bertogli
12b856a387 docs: Add a how-to guide
This patch adds a brief how-to guide for setting up an email server with
Debian, dovecot and chasquid.

It is incomplete, but has enough information that it's ok to include it.
2018-03-02 19:55:12 +00:00
Alberto Bertogli
407f7cf79a test: Test monitoring HTTP fetching
This patch adds HTTP fetching to the integration tests.

It checks that the URLs are properly exported and that the server
replies reasonably to them. The contents are saved as they might be
useful as a debugging aid.

They're added to t-09-loop as it already was doing other HTTP fetches,
but the changes are not particularly tied to it.

The content of the pages is not checked yet, that might come in
subsequent patches.
2018-03-02 19:37:37 +00:00
Alberto Bertogli
83e40da3f6 test: Fix "run without certificates" test
The test to check that chasquid fails on startup if there are no valid
TLS certificates is passing, but for the wrong reasons: it fails because
there is no logging directory, not because there are no certificates.

This patch fixes the problem by moving the logs directory creation
before the first test.
2018-03-02 19:37:37 +00:00
Alberto Bertogli
f4fb2153b8 protoio: Use keyed fields in composite literal
In the protoio tests, we were using unkeyed fields in some composite
literals. This can cause confusion and makes the code more brittle wrt.
future changes. go vet also complains about this.

This patch fixes the issue by adding the field names to the struct
initializations.
2018-03-02 19:37:37 +00:00
Alberto Bertogli
f629ffefa4 trace: Remove unused SetError function 2018-03-02 19:37:37 +00:00
Alberto Bertogli
420754b0a0 auth, dovecot: Add missing Reload tests
auth.wrapNoErrorBackend.Reload and dovecot.Reload were not being tested;
this patch fixes that by adding a simple test for each.
2018-03-02 19:37:37 +00: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
5ce4ff2602 gitignore: Ignore dovecot-auth-cli binaries 2018-03-02 19:37:37 +00:00
Alberto Bertogli
bb90274edd test: Add tools to generate test coverage information
This patch adds some tooling and scripts to generate test coverage
information.

Unfortunately, this involves some hacks as Go does not have support for
generating coverage-enabled binaries, or merging coverage reports; but
overall it's not very intrusive.
2018-03-02 19:37:37 +00:00
Alberto Bertogli
751fbd4b55 test: Integration test for reload
This patch implements an integration test for reloading; in particular
it exercises reloading aliases and user databases.
2018-03-02 19:37:37 +00:00
Alberto Bertogli
0611b7a7fc test: Add small miscellaneous tests
This patch extends various packages and integration tests, increasing
test coverage. They're small enough that it's not worth splitting them
up, as it would add a lot of noise to the history.
2018-03-02 19:37:37 +00:00
Alberto Bertogli
d80c76f746 envelope: Handle zero-length keys in AddHeader
We don't expect the AddHeader function to be given an empty key;
however, if that were to happen, it currently crashes.

This patch fixes the bug, while also adding tests for that and other
similar cases.
2018-03-02 19:37:28 +00:00
Alberto Bertogli
0ae5798d20 dovecot: Support dovecot-side username changes
Dovecot has options for changing the formatting of usernames; for
example, dropping the domain part, or replacing characters.

chasquid's implementation, however, fails to handle this well, as it
expects the reply to contain the username exactly as requested.

This patch fixes the problem by making chasquid ignoring the returned
username, which is unused anyway. The protocol is unambiguous enough.

Tests are also amended to always exercise this case.
2018-03-02 19:08:00 +00:00
Alberto Bertogli
d39d3aaff4 chasquid: Dovecot support (experimental)
This patch adds dovecot support to the chasquid daemon, using the
internal dovecot library added in previous patches.

Dovecot support is still considered EXPERIMENTAL and may be reverted, or
changed in backwards-incompatible ways.

The patch also adds the corresponding integration test, which brings up
a dovecot server with a custom configuration, and tests chasquid's
authentication against it.  If dovecot is not installed, the test is
skipped.
v0.04
2018-02-10 23:18:31 +00:00
Alberto Bertogli
51e7c5c19e dovecot: Dovecot authentication package
This patch adds a new package which implements two basic primitives for
authenticating against dovecot ("user exists", and "check password").

It is still experimental/work in progress.
2018-02-10 23:01:23 +00:00
Alberto Bertogli
d4992ef8c5 auth: Implement an Authenticator type
This patch implements an Authenticator type, which connections use to
do authentication and user existence checks.

It simplifies the abstractions (the server doesn't need to know about
userdb, or keep track of domain-userdb maps), and lays the foundation
for other types of authentication backends which will come in later
patches.
2018-02-10 22:24:39 +00:00
Alberto Bertogli
08e6f57d2e travis.yml: Use generic Go versions and Ubuntu Trusty
This patch updates the travis-ci.org configuration file to use generic Go
versions (instead of hard-coded), and Ubuntu Trusty in container mode, for
faster builds.
2017-12-09 20:14:36 +00:00
Alberto Bertogli
4851b07098 test: Add missing test file in mda-lmtp
The mda-lmtp tests are missing a file in the repository, which causes the
test to fail. This went unnoticed because they are not included in the
automated test suite, which will be fixed in a follow-up patch.

This patch adds the mising test file, with a harder to miss name.
2017-12-09 18:41:27 +00:00
Alberto Bertogli
fcf2cae120 test: Make generate_cert use IDNA for certificate fields
In Go 1.10 the TLS library will start to reject DNS SANs which are not
properly formed; and in particular, if they're not IDNA-encoded. See:
 - https://github.com/golang/go/issues/15196
 - 9e76ce7070

The generate_cert utility will write non-IDNA DNS SANs, which the TLS
library does not like, causing our idna tests to fail.

This patch fixes this incompatibility by making generate_cert IDNA-encode
the host names when adding them to the certificate.
2017-12-08 14:07:42 +00:00
Alberto Bertogli
f7a4fa895c test: Work around wget's logging to files
There's a bug in wget where it logs to files if -q is used:
https://savannah.gnu.org/bugs/?51181

It is harmless to the test, but it clutters the directory and the test
output, so this patch works around the issue by forcing it to log to
/dev/null.
2017-12-08 13:57:25 +00:00
Alberto Bertogli
94c4492862 test/t-01-simple_local: Don't fail if test certificates are missing
The test starts by removing the previous test certificates, which may
or may not exist.

If they don't, currently "rm" fails, causing the whole test to fail.
I am surprised I did not notice this before :(

This patch fixes the bug by using "rm -f" to remove the test certs.
2017-12-08 13:56:04 +00:00
Alberto Bertogli
b3592b7bf9 chasquid: Add package-level documentation 2017-11-19 13:49:54 +00:00
Alberto Bertogli
033a5d657b Use the external log, spf and systemd packages
The log, spf and systemd packages have been externalized; use them
instead of the internal version to avoid having two versions of the same
thing.
2017-09-17 22:17:14 +01:00
Alberto Bertogli
72477c0cfd smtpsrv: Get TLS information for direct connections
For direct TLS connections, such as submission-over-TLS, we currently
don't get the TLS information so it appears in the headers as "plain
text", which is misleading.

This patch fixes the problem by getting the connection information
early. Note it explicitly triggers the handshake, which would otherwise
happen transparently on the first read/write, so we can use the hostname
(if any) in our hello message.
2017-09-10 11:20:57 +01:00
Alberto Bertogli
0972964722 mda-lmtp: Handle "<>" addresses
Either the recipient or from addresses can be "<>" to indicate the null
address. mda-lmtp does not handle that well, as it sends "<<>>" which is
invalid.

This patch fixes that by special-casing them, which is unfortunate but
reasonably common.
2017-08-08 09:12:53 +01:00
Alberto Bertogli
6867859d5c courier: Make the SMTP test not use the network
One of the SMTP tests was doing an external DNS lookup for a
non-existing host, which is reasonably harmless but makes the test less
hermetic.

This patch changes the non-existing host for an invalid address, which
has the same effect but avoids the network lookup.

This is a hack; ideally we would be able to override the resolver, but
Go does not implement that yet, and changing the code is not worth the
additional complexity.
2017-07-16 13:24:40 +01:00
Alberto Bertogli
5426be5aec Add notes for upgrading
This patch adds an UPGRADING.md file containing notes for upgrading
between different versions.
v0.03
2017-07-15 15:24:52 +01:00
Alberto Bertogli
9864f40f3b test: Tidy up creation and removal of test directories
We have many places in our tests where we create temporary directories,
which we later remove (most of the time). We have at least 3 helpers to
do this, and various places where it's done ad-hoc (and the cleanup is
not always present).

To try to reduce the clutter, and make the tests more uniform and
readable, this patch introduces two helpers in a new "testutil" package:
one for creating and one for removing temporary directories.

These new functions are safer, better tested, and make the tests more
consistent.  All the tests are updated to use them.
2017-07-14 02:02:43 +01:00
Alberto Bertogli
9388b396ee aliases: Normalize right-hand side addresses
The right-hand side addresses of an alias should be normalized, to
maintain the internal invariant that we always deal with normalized
addresses.

Otherwise, strange situations may arise, such as the same domain having
two different domaininfo structures depending on case.
2017-07-14 01:06:09 +01:00
Alberto Bertogli
a016d78515 courier: Fix SMTP outgoing security level check
The outgoing security level checks are not being performed, because of a
bug: the courier thinks the "to"'s domain is always empty.

This patch fixes the bug by simplifying the logic, as there's no need
for the conditional (there is always a domain in the "to" address if it
got to the SMTP courier).
2017-07-14 01:06:09 +01:00
Alberto Bertogli
a85ba1252b test: Remove nc.py
The nc.py script is only used in a single test, and for waiting for a
TCP port to be opened for listening.

This patch replaces it entirely, by using chamuyero for the test, and
bash for waiting on a TCP port.
2017-07-13 22:05:45 +01:00
Alberto Bertogli
82a1e4597f mda-lmtp: Add a very basic MDA that uses LMTP to do the mail delivery.
mda-lmtp is a very basic MDA that uses LMTP to do the mail delivery.

It takes command line arguments similar to maildrop or procmail, reads an
email via standard input, and sends it over the given LMTP server.
Supports connecting to LMTP servers over UNIX sockets and TCP.

Since chasquid does not support direct LMTP local delivery, this can be
used as a workaround instead.

Example of use:
$ mda-lmtp --addr localhost:1234 -f juan@casa -d jose < email
2017-07-13 22:05:45 +01: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
Alberto Bertogli
2caaec3d8b userdb: Use a constant-time byte comparison in PasswordMatches
PasswordMatches calculates the proposed derived key, and then compares
it with the actual derived key. That comparison is done using
bytes.Equal, which is not in constant time.

In theory, users with knowledge of the salt could use timing to extract
information about the actual derived key.

In practice, the salt is not being exposed to users, and the caller of
PasswordMatches will add a delay to password checks, so it should not be
easy to exploit via chasquid.

But just to be safe and more future-proof, this patch changes the
comparison to be in constant time.
2017-04-26 10:26:54 +01:00
Alberto Bertogli
17eff21279 Only fail if there is no address to listen on at all, regardless of mode
Currently, chasquid exits if any mode (SMTP/submission/submission+tls)
has no addresses to listen on. This means that chasquid must be given
addresses for all three.

While that's generally the expected configuration, there are cases where
users may not want to have all three.

So this patch replaces that fatal error with a warning, and only makes
chasquid exit if there are no addresses to listen on at all.
2017-04-12 10:32:41 +01:00
Alberto Bertogli
7f5bedf4aa Remove the MTA-STS (Strict Transport Security) implementation
This commit removes the experimental MTA-STS (Strict Transport Security)
implementation for now, as it's not up to date with the latest draft.

Development will continue on the "sts" branch, but this way it won't
block releases until it is ready.

Commits reverted:
 - cb6500b993
 - 0eeb964534
 - e66288e4b4
 - 216cf47ffa
 - d66b06de51
 - fe00750e39
 - 933ab54cd8
2017-04-11 00:58:59 +01:00
Alberto Bertogli
213bc63a95 Support submission (directly) over TLS (submissions/smtps/port 465)
This patch adds support for TLS-wrapped submission connections.

Instead of clients establishing a connection over plain text and then
using STARTTLS to switch over a TLS connection, this new mode allows the
clients to connect directly over TLS, like it's done in HTTPS.

This is not an official standard yet, but it's reasonably common in
practice, and provides some advantages over the traditional submission
port.

The default port is 465, commonly used for this; chasquid defaults to
systemd file descriptor passing as for the other protocols (for now).
2017-04-10 19:59:04 +01:00
Alberto Bertogli
c4255933bd chasquid-util: Handle usernames without domain
Usernames must be of the form user@domain. When the domain is missing,
this patch makes chasquid-util emit a friendly error (instead of
crashing).
2017-04-10 19:48:35 +01:00
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