25 Commits

Author SHA1 Message Date
Alberto Bertogli
5cdbd9ff6e Fix documentation/comment typos
This patch fixes a variety of typos in documentation and comments, found
by running `codespell`.
2023-10-07 12:41:57 +01:00
Alberto Bertogli
a3f7914e29 sts: Remove unused struct member
There is no synchronization needed in the sts cache, because changes are
handled atomically on-disk and there is no in-memory persistence.
2023-07-28 10:05:15 +01:00
Alberto Bertogli
3ebe5c5173 Replace uses of ioutil
ioutil package was deprecated in Go 1.16, replace all uses with their
respective replacements.

This patch was generated with a combination of `gofmt -r`, `eg`, and
manually (for `ioutil.ReadDir`).
2022-11-12 20:06:35 +00:00
Alberto Bertogli
776bdc58ab Update Go doc comments to Go 1.19's format
This patch is the result of running Go 1.19's `gofmt` on the codebase,
which automatically updates all Go doc comments to the new format.

https://tip.golang.org/doc/go1.19#go-doc
2022-09-02 11:11:40 +01:00
Alberto Bertogli
7fe42a368a monitoring: Add OpenMetrics exporter
This patch makes chasquid's monitoring server expose an OpenMetrics
metrics endpoint.

It adds a new package "expvarom" which implements an HTTP handler that
exports expvar variables in the OpenMetrics text format.

Then, the handler is registered by the monitoring server at /metrics
(where most things expect it to be).

The existing exported variables are also extended with descriptions,
which is optional, but improves the readability of the metrics.
2020-08-21 12:07:33 +01:00
Alberto Bertogli
3584441549 test: Use testlib.RemoveIfOk where appropriate
Some tests did not make use of testlib.RemoveIfOk, which resulted in
some duplication; this patch fixes that.

While at it, userdb tests have its own simpler variant, so add some
safety checks to it.
2019-09-10 01:09:44 +01:00
Alberto Bertogli
f63e5bf0b2 sts: Reject policies with max_age > 1y, as per RFC
The MTA-STS standard explicitly says the maximum max_age is 1 year.

This patch adds a check to the STS library to enforce this. Policies
with max_age > 1y will be treated as invalid.

See this email thread for some discussion on the topic:
https://mailarchive.ietf.org/arch/msg/uta/bnUjy9jxM_Va-lDXVtbB32zIkYI
2019-08-31 01:14:56 +01:00
Alberto Bertogli
9821a17d6c sts: Use expvar.Int.Value in tests
Now that we raised the minimum Go version to 1.9, we can make use of
expvar's .Value methods to simplify some of the STS tests.

This patch makes those simplifications, which do not change the logic of
the tests themselves.
2019-07-13 13:52:28 +01:00
Alberto Bertogli
ec95131bb4 Miscellaneous style fixes
This patch has some miscellaneous style fixes to issues found by the
staticcheck tool.

There are no functional changes.
2019-02-10 12:46:15 +00:00
Alberto Bertogli
4db9ffec09 Code style improvements
This patch contains some minor code style improvements, to leave the
linter happier and generally follow best practices in some areas where
things snuck through.
2018-12-01 11:58:50 +00:00
Alberto Bertogli
2dfed059e4 MTA-STS is now RFC 8461
MTA-STS has been published as RFC 8461, with no major changes since the
last draft we updated (-18).

This patch updates the documentation accordingly (no code changes).
2018-09-26 21:42:50 +01:00
Alberto Bertogli
644cd63eff sts: Use keyed fields in io.LimitedReader literal
Flagged by go vet:
internal/sts/sts.go:256: io.LimitedReader composite literal uses unkeyed fields
2018-07-14 10:23:36 +01:00
Alberto Bertogli
0ee7cb4cce sts: Add documentation and fix minor style issues
This patch adds some missing function documentation entries, and fixes
minor style issues caught by the linter.

No functional changes.
2018-07-14 10:08:27 +01:00
Alberto Bertogli
46bce576e8 sts: Add miscellaneous tests
This patch adds a few miscellaneous tests to the sts package, covering
various previously-untested code paths.
2018-07-14 10:08:09 +01:00
Alberto Bertogli
79a8cfc21c sts: DNS TXT record support
This patch adds support for checking the MTA-STS TXT record before
fetching the policy via https.

The content of the record is unused.
2018-07-01 12:19:02 +01:00
Alberto Bertogli
8bf584bd86 sts: Don't pre-filter MX list, but skip them if needed
Instead of pre-filtering the MX list based on STS policy, just check
if it's allowed before each attempt, and skip it if not.

This simplifies the code.
2018-07-01 12:19:02 +01:00
Alberto Bertogli
252ab5d3e3 sts: Update to draft-ietf-uta-mta-sts-18
This patch updates the STS implementation from draft version 02 to 18.

The main changes are:

 - Policy is now in an ad-hoc format instead of JSON (😒).
 - Minor policy well-known URL change (now ends in ".txt").
 - Enforce HTTP media type == text/plain, as with the ad-hoc format this
   becomes much more important.
 - Simplify wildcard mx matching (same algorithm), extend test cases.
 - Valid modes are "enforce" (as before), "testing" (replaces "report"),
   and "none" (new).
2018-07-01 12:19:02 +01:00
Alberto Bertogli
23deaf1f88 Reinstate the MTA-STS (Strict Transport Security) implementation
This commit brings back the experimental MTA-STS (Strict Transport
Security) implementation, removed in commit
7f5bedf4aa.

We will continue development in the "sts" branch, subject to rebase,
until it is ready to be integrated into "next" again.
2018-07-01 12:19:02 +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
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
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
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
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