Commit Graph

360 Commits

Author SHA1 Message Date
Matthew Holt
7eaf4e7a41
Sync writes to storage device
A couple cases reported using AWS EFS have empty lock files. This is unusual, but has now been observed multiple times. Most recent documented case: https://github.com/caddyserver/caddy/issues/3954

We now try to force a sync to the device to see if that helps.
2021-01-04 12:14:41 -07:00
Brad Triebwasser
44c290ec5b
Format error during lock acquisition (#116)
Consistent with line 537
2021-01-04 11:51:14 -07:00
Cameron Elliott
2ce0f6de55
readme: fix dns solver example code (#114)
Co-authored-by: Cameron Elliott <cameron-elliott@users.noreply.github.com>
2020-12-31 11:50:57 -07:00
Matthew Holt
18811087a7
Properly splice invalid accounts
Related to: https://github.com/caddyserver/caddy/issues/3939

Avoids a panic in the event ALL items listed are "terminal" - the linked specific case is surely a bug in the upstream storage implementation, but we shouldn't panic anyway.
2020-12-28 09:05:11 -07:00
Matthew Holt
201f83a060
Improve chain selection options
Simply specifying a common name may not be enough, like in the case of
Let's Encrypt's new alternate chains, where one chain is a superset of
the other, and the difference is the root.
2020-12-15 12:03:46 -07:00
Matthew Holt
b726d1ed13
Strip scope ID from IPv6 addresses
Should fix https://github.com/caddyserver/caddy/issues/3911

CertMagic does a sanity check before obtaining certs by checking names for invalid characters; and % is not a character that is accepted for IP addresses. I don't actually know how clients do validation on TLS connections to scoped IPs, but presumably we should just strip them before applying them to certificates server-side.

Also unexport the needlessly-exported NormalizedName function, which is no longer known to be used by any external libraries. (It used to be used by Caddy but we've since better contained the relevant logic within CertMagic.)
2020-12-09 12:58:41 -07:00
Simon Ser
830df5651c
Implement Config.Unmanage (#106)
Closes: https://github.com/caddyserver/certmagic/issues/92
2020-12-01 10:05:32 -07:00
Matt Holt
0f8a9f6887
Implement multiple issuer support (#109)
* Implement multiple issuer support

This change refactors Config.Issuer to be Config.Issuers, an array of
issuers. Each Issuer will be tried in turn until one succeeds. During
retries, each attempt will try each configured Issuer. When loading
certs from storage, CertMagic will look in each Issuer's storage
location for a qualifying asset. If multiple Issuers have one in storage
then the most-recently-issued cert will be selected.

This is a breaking change in that Config now accepts a slice of Issuers
rather than a single Issuer. The Revoker field is removed, as supporting
it is optional anyway. If the Issuer is also a Revoker, it can be used
implicitly to revoke certificates.

Also added a const for ZeroSSL's ACME endpoint.

* Load matching wildcard on-demand from storage

With this change, a config using on-demand TLS can load a certificate
for "sub.example.com" from storage using a matching  wildcard cert
(i.e. "*.example.com") if no better matching certificate is available.

* Fix distributed solving with tls-alpn challenges

The type assertion in handshake.go was problematic since there's no
guarantee that an ACME issuer would be a concrete ACMEManager type.

Refactored the code to accept IssuerKey values generally, rather than
specific ACMEManager values only.

This fixes solving tls-alpn challenges in distributed settings.

More cleanup can be done, another time.
2020-11-16 10:53:41 -07:00
Matthew Holt
12df2be5a0
Implement alternate chain preferences 2020-11-12 15:00:15 -07:00
Matthew Holt
2b98009606
Improve on-demand logic, logging, error handling
Significantly, on-demand renew operations no longer block unless the
certificate is already expired. It serves existing certs when possible,
and performs renewals in the background.

Also minor improvements to debug and error logging.
2020-11-12 13:12:07 -07:00
Matthew Holt
90d1550af4
Refactor subject qualification logic
This is necessary to support a nuance in Caddy where we have to see if a
subject qualifies for a public certificate but with custom wildcard
checking. So we separate the wildcard check from other checks.
2020-10-21 09:08:19 -06:00
Matthew Holt
81657a2337
Lower max stack trace size
64 MB... what was I thinking?
2020-09-17 12:16:14 -06:00
delthas
3cc8865d3c
dnsutil: Don't error when checking record with preexisting values (#96)
When checking whether a new DNS TXT record is deployed, as part of the
DNS challenge procedure, checkAuthoritativeNss is called in a loop until
the requested TXT value is found in one of the records, or until a
timeout.

Previously, if there were other DNS TXT records for the same FQDN, the
call to checkAuthoritativeNss failed and the whole DNS challenge was
canceled. This means for example that if there was any previous
_acme-challenge TXT for the domain, the DNS challenge would always fail.

This fixes this issue by not returning an error, but instead returning
not ready, when there are other values returned by that DNS TXT record
request.

Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
2020-09-15 12:05:33 -06:00
M. Ángel Jimeno
d45c5b1633
Remove unused method getFirstMatchingCert (#90)
Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
2020-09-14 15:03:39 -06:00
Matthew Holt
8a45463f28
Fix test failing on Windows 2020-09-14 14:08:11 -06:00
Matthew Holt
7e97d39c19
Change tests that relied on accessing mail servers from CI env
Also loosen up substring error checking a bit
2020-09-14 14:01:17 -06:00
Matthew Holt
6b7487bac2
readme: Update CI badge 2020-09-14 13:50:48 -06:00
Matthew Holt
a71b985343 Fix failing test that depends too much on environment 2020-09-14 13:49:16 -06:00
Francis Lavoie
11841c2697
ci: Set up github actions (#99)
* ci: Set up github actions, largely copied from caddy repo

* ci: Drop Azure file
2020-09-14 13:26:01 -06:00
Matthew Holt
3e4c11b75f
Remove HTTP protos from ALPN unless serving HTTP (#97) 2020-09-14 12:10:52 -06:00
Matthew Holt
34fc6bf02a Properly ensure port is added to all nameservers 2020-09-09 13:29:00 -06:00
M. Ángel Jimeno
09acc6bf59
dnsutil: replace fmt.Sprintf() with err.Error() when formatting errors (#87) 2020-08-26 12:57:16 -06:00
M. Ángel Jimeno
0c8b028721
account: handle decodePrivateKey() error in getAccount (#89) 2020-08-26 12:54:29 -06:00
Matthew Holt
4fd8ae48ef
Configure custom DNS resolvers to be preferred over default resolvers
This makes the DNS challenge usable with split-horizon DNS.

Related:
- https://github.com/go-acme/lego/issues/461
- https://github.com/caddyserver/caddy/issues/1580
- https://github.com/go-acme/lego/issues/379/
- https://github.com/go-acme/lego/pull/293/
2020-08-21 20:22:42 -06:00
Matthew Holt
c2f851df75
Synchronize same-name DNS challenges
Wildcard domain names collide with the same subdomain for the ACME TXT
record as the non-wildcard parent domain (for example, example.com and
*.example.com both use _acme-challenge.example.com), so we need to solve
those challenges mutually exclusively.

One potential problem with this current implementation is that we don't
wait for the DNS record to un-propagate after it is deleted; I've found
that re-running it works fine, after waiting just a few seconds. I am
not sure how to generalize this logic in all cases though. It is likely
provider-dependent. (I was testing with Cloudflare.)

Should fix https://github.com/caddyserver/caddy/issues/3474
2020-08-18 16:37:01 -06:00
Matthew Holt
e7f9729bad
Renew managed on-demand certificates at handshake-time if necessary
If the machine goes to sleep or the process gets suspended, background
maintenance won't happen, so we need to check for expiration of all
managed, on-demand certificates at every handshake. Fortunately, this is
pretty cheap because it's simple date math.

https://caddy.community/t/local-certificates-not-renewing-on-demand/9482
2020-08-17 12:14:46 -06:00
Matthew Holt
81e76ea4e7
go.mod: Use latest acmez and libdns 2020-08-17 11:35:34 -06:00
Matthew Holt
10a8b5c723
go.mod: Use latest acmez (better log messages) 2020-08-10 16:06:24 -06:00
Matthew Holt
2e100d6d0b
Add directory to error message
Useful in error logs to know which CA endpoint is being used
2020-08-08 08:38:26 -06:00
Georg Friedrich
d70f961bcd
Retry DNS query with TCP if UDP fails (#81)
* Minor improvement to DNS request handling

Sometimes incoming udp traffic on port 53 is blocked to
prevent DDoS attacks. In those cases only TCP will work
for DNS request as the UDP request will time out. And as
a result the DNS challenge will fail, while the server is
trying to verify if the challenge was propageted through
the NS.

Now instead of returning immidently, if a timeout with UDP was
received, the request will be tried again using TCP.

* Formatting and comment

Co-authored-by: Georg Friedrich <g.friedrich@sonnenwagen.org>
Co-authored-by: Matthew Holt <mholt@users.noreply.github.com>
2020-08-08 08:36:00 -06:00
Matthew Holt
c6afa6e7a2
Minor improvements to logging 2020-08-04 14:55:33 -06:00
Matthew Holt
5fd26543e0
Add NewAccountFunc callback
This is necessary for a downstream requirement where the ACME CA offers
an API key to generate EAB credentials, but each time their API call is
used, new credentials are generated, so we need to be sure to use it
only once (when an account is actually being created). Thus, CertMagic
needs a way to tell the application when the account is actually being
created versus being reused. This allows the application to make an API
call just before account registration and fill the EAB credentials into
the ACMEManager struct.
2020-08-04 14:21:47 -06:00
Matthew Holt
f5ef877ede
Improved logging when serving key auth 2020-08-04 13:30:21 -06:00
Matthew Holt
d0f2d0162f
Carry default EAB through to new managers 2020-08-03 14:48:48 -06:00
Matthew Holt
3a209e20b0
Update readme related to DNS provider improvements 2020-07-31 15:45:06 -06:00
Matthew Holt
7d9dfc3fe6
Add DNS-01 solver implementation that uses acmez and libdns APIs
Before when we used lego as our ACME library, DNS solvers abounded in
the lego repository and they could be used directly. Our new acmez lib
is very lightweight, and "bring-your-own-solvers", let alone your own
DNS provider implementations.

DNS providers are implemented in libdns: https://github.com/libdns

This commit adds an implementation of acmez.Solver that solves the DNS
challenge using libdns providers.

Unlike the other solvers, this one is exported because it is not a
challenge type that is enabled by default, and there is more config
surface.

We borrowed some DNS utility functions and tests from the lego repo.

But this is a very lightweight implementation that has a much, much
simpler API and smaller footprint.
2020-07-30 14:07:04 -06:00
Matthew Holt
27ab38448f
Gracefully transition existing meta assets to new format
The new format is dictated primarily by the ACME spec as implemented by
the new acmez/acme package. It makes a lot more sense.
2020-07-30 12:13:45 -06:00
Matthew Holt
9cc43e5a88
go.mod: Update acmez 2020-07-29 19:47:20 -06:00
Matthew Holt
e6076585c0
Convert (most of the library) to structured logs (closes #19)
Logging is now configurable through setting the Logging field on the
various relevant struct types. This is a more useful, consistent, and
higher-performing experience with logs than the std lib logger we used
before.

This isn't a 100% complete transition because there are some parts of
the code base that don't have obvious or easy access to a logger.
They are mostly fringe/edge cases though, and most are error logs, so
you shouldn't see them under normal circumstances. They still emit to
the std lib logger, so it's not like any errors get hidden: they are
just unstructured until we find a way to give them access to a logger.
2020-07-29 19:38:12 -06:00
Matt Holt
b76b76abfc
Replace lego with ACMEz (close #71) (#78) 2020-07-27 16:50:41 -06:00
Matthew Holt
77f91b9bbe
Don't encode EAB HMAC
Most providers already encode it
2020-06-11 15:30:56 -06:00
Matthew Holt
5b5ac32a85
Only use default test CA if primary CA is also default
Fixes https://github.com/caddyserver/caddy/issues/3466
2020-06-02 11:11:01 -06:00
Matthew Holt
7249bad811
Configurable cache capacity 2020-06-01 15:03:14 -06:00
Matt Holt
82040fdb58
Lock now takes a context and should honor cancellation (#66)
* Lock now takes a context and should honor cancellation

This allows callers to give up if they can't obtain a lock in a certain
timeframe and for resources to be cleaned up, avoiding potential
resource leaks.

Breaking change for any Storage implementations, sorry about that. (It's
why we're not 1.0 yet.) I'll reach out to known implementations; it's a
simple change.

* Rename obtainLock to acquireLock to be less ambiguous

In our package, "obtain" has a more common meaning related to certs
2020-05-27 15:05:53 -06:00
Matthew Holt
fff412bb74
Restart maintenance routine if it panics 2020-05-13 11:11:27 -06:00
x1nchen
69af6a5948
chore: update go version declared in go.mod (#73)
Fucntion handshake.DefaultCertificateSelector use the field
`*tls.ClientHelloInfo.SupportsCertificate` which only supported in go 1.14
2020-05-13 09:55:03 -06:00
Matthew Holt
5ed364019b
Add nil check; recover from all goroutines 2020-05-12 09:28:56 -06:00
AJ ONeal
d43c0e34fd
fix typo in example (#72)
* fix typo in example

needed to move the closing paren one level down

* fix the fix
2020-05-04 21:45:57 -06:00
Success Go
0643091dc5
fix typo (#67) 2020-04-20 16:36:59 -06:00
Matthew Holt
663df05914
Allow duplicate 'obtain' jobs
See https://github.com/caddyserver/caddy/issues/3202
2020-04-14 11:26:24 -06:00