Commit Graph

360 Commits

Author SHA1 Message Date
dependabot[bot]
890fe65f86
Bump golang.org/x/text from 0.3.7 to 0.3.8 (#216)
Bumps [golang.org/x/text](https://github.com/golang/text) from 0.3.7 to 0.3.8.
- [Release notes](https://github.com/golang/text/releases)
- [Commits](https://github.com/golang/text/compare/v0.3.7...v0.3.8)

---
updated-dependencies:
- dependency-name: golang.org/x/text
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-23 08:56:13 -07:00
Matthew Holt
c0dc63288a
Synchronize caching of managed certs
Should prevent stampedes to storage. See #185

Also minor fixes elsewhere.
2023-01-16 21:48:46 -07:00
pwilloughby
91cbe17781
Allow the default cache logger to be set (#213) 2023-01-10 11:43:50 -07:00
Matthew Holt
0c6c025ccc Enhance logs
Add remote IP and User-Agent (for HTTP challenge) when error getting
challenge info
2023-01-04 22:17:21 -07:00
Georg Müller
7d6aa77b24
Allow specifying http proxy via acme issuer template (#212) 2022-12-14 10:55:29 -07:00
Matthew Holt
a46420babd
Merge tags when reusing cert (fix #211) 2022-12-05 12:34:37 -07:00
Matthew Holt
2e8dd4496a
Upgrade a couple dependencies 2022-09-30 13:33:37 -06:00
Matthew Holt
79babffe28
Treat empty lockfiles as stale
Had this happen when testing something in Caddy. A crash at startup left
a lockfile created but empty.
(This was not a production crash, just dev.)

Empty lockfiles have been reported before. I think we should
treat them as stale.
It's not perfect but it's best-effort.
2022-09-29 10:11:32 -06:00
Matthew Holt
5deb7c2fb0 Make logger values required
Eliminates a bajillion nil checks and footguns
(except in tests, which bypass exported APIs, but that is expected)

Most recent #207

Logging can still be disabled via zap.NewNop(), if necessary.
(But disabling logging in CertMagic is a really bad idea.)
2022-09-26 10:19:30 -06:00
Antonio Mika
93fd493922
Nil check before logging (#207) 2022-09-23 10:53:05 -06:00
Andreas Kohn
55fc6a9f76
Avoid nil dereferencing on errors (#206)
This merges #204 to a similar place in config.go.
2022-09-23 10:52:42 -06:00
Matthew Holt
9826a4c354
SERVFAIL should be forgivable
Let the poller retry after a SERVFAIL
2022-09-08 14:11:38 -06:00
Matthew Holt
3f145a93b7
readme: Document events 2022-09-05 12:58:01 -06:00
Matthew Holt
2e22c6fa8c
Report issuers tried on cert_failed (fix #204)
Instead of assuming issuerUsed is non-nil in the error case
2022-09-01 11:21:27 -06:00
Matthew Holt
ab3db7526d
If DecisionFunc errors, log it and return currentCert 2022-08-31 14:37:06 -06:00
Matthew Holt
cef8e27f1f
Add error to cert_failed events 2022-08-31 11:25:57 -06:00
Matthew Holt
1cc3fe8c91
Rename cert_renewing -> cert_obtaining
The data field "renewal" can be used to distinguish them.
I figure most users won't care to distinguish them.
2022-08-31 11:20:35 -06:00
Matthew Holt
585ecc11ac
events: Remove cert_renewed, add cert_ocsp_revoked 2022-08-31 11:13:09 -06:00
Matthew Holt
979e585677
Remove cert_revoked event
Is confusing with *discovering* a revocation through OCSP.

No demand for this event yet AFAIK.
2022-08-26 12:31:21 -06:00
Matthew Holt
bb468ce4b4
Change OnEvent function; emit more events
OnEvent can now control basic program flow for certain events.
For example, it can cancel cert_obtaining or cert_renewing from happening.

Slight API change adds context and changes to map[string]any for data.
This is easier to work with in practice and conforms more with Caddy's
new event system.
2022-08-26 12:17:10 -06:00
Matthew Holt
76f61c2947
Use different context for DNS challenge cleanup
Fix #200, probably
2022-08-18 10:50:50 -06:00
Matthew Holt
7f2d93f42a
Add remote to handshake logs
Can be useful for tracking D(D)oS attacks
2022-08-18 09:18:06 -06:00
Ben Burkert
871b774821
Add one second (at most) to account for NotAfter imprecision (#199)
Fix #197
2022-08-16 18:08:34 -06:00
Matthew Holt
9e63f36fa3
Revert "Prepend _acme-challenge label to OverrideDomain"
This reverts commit e0227517e0.

According to discussion in #160, there was a misunderstanding and the previous implementation seems more correct:
https://github.com/caddyserver/certmagic/pull/160#issuecomment-1213138105
2022-08-12 14:29:05 -06:00
Matthew Holt
93d9113bce
go.mod: Upgrade dependencies 2022-08-08 12:55:39 -06:00
Matthew Holt
56c70f3808
Update to Go 1.18; use any 2022-08-08 10:45:24 -06:00
Matthew Holt
46a4436693
Clarify storage documentation (close #196) 2022-08-08 10:44:46 -06:00
Matthew Holt
e0227517e0
Prepend _acme-challenge label to OverrideDomain
This way the user does not need to explicitly configure that
(which is not intuitive).
2022-08-08 10:19:38 -06:00
Matthew Holt
8531018bf2
go.mod: Upgrade acmez to v1.0.4 2022-08-02 14:52:26 -06:00
Matthew Holt
dce2de273d
Improve DNS solver efficiency and resolve deadlock
Previously, simultaneously solving for example.com and *.example.com
using the DNS challenge (i.e. both SANs on the same cert, which CertMagic
doesn't do; but this is a general-purpose library) would cause a deadlock
because both those names use the same-name TXT record. This caused
problems with previous dependencies like lego and legacy DNS solvers,
but the new acmez library and libdns packages support this.

I've removed the locking around same-name records, which resolves
the deadlock, and improves efficiency as well, since we can now solve
challenges for example.com and *.example.com at the same time.
2022-08-02 14:07:34 -06:00
Matthew Holt
5981e55018
Fix race conditions (close #195)
Also update setting acmez.Client.Logger in accordance
with latest acmez commit, which removes redundant
logger.
2022-08-01 23:04:11 -06:00
gjung56
23ca487b74
Use OverrideDomain when cleaning up DNS solver (#193) 2022-07-27 16:14:57 -06:00
Matthew Holt
9b9f842b03
Rename getEmail -> setEmail
It doesn't really return the email address; it mutates the ACMEIssuer.
2022-07-05 16:56:22 -06:00
Mohammed Al Sahaf
d08f6e10d8
Set EDNS0 to 1232 bytes per recommendation (#188) 2022-05-29 14:58:11 -06:00
Mohammed Al Sahaf
18af76fbd2
Improve Windows CI cache (#189) 2022-05-29 14:31:33 -06:00
Matthew Holt
a48e34ff31
docs: Clarify readme
DefaultStorage -> Default.Storage
2022-04-25 15:04:47 -06:00
Matthew Holt
049e60556b
Remove comment 2022-04-22 14:54:57 -06:00
Matthew Holt
8d92ff95bf
Configurable propagation checks in DNS solver
Lots of users over the years have reported that the propagation checks
time out, yet the challenges would/did still succeed. Example:
https://caddy.community/t/hard-time-getting-a-response-on-a-dns-01-challenge/15721?u=matt

We are not sure why this happens, but it seems prudent to be able to
disable or delay the propagation checks.
2022-04-22 14:49:34 -06:00
Matthew Holt
03cffeb193
Update a couple comments 2022-03-25 10:55:29 -06:00
Francis Lavoie
2f6011a04f
Provide more detailed information in certificate events (#150)
* Provide more detailed information in certificate events

The `cert_*` events were only providing the domain. This was pretty limited, because not much can be done with it without also knowing the issuer, since that affects where the cert is stored.

Providing both the `issuerKey` and `certKey` makes it possible for the event listener to call `StorageKeys.SiteCert(issuerKey, certKey)` to get the actual location of the cert (and similarly the private key). Particularly useful in situations where the user wants to copy the cert/key to some location for another app to use the cert that is being managed.

A similar change could probably also be done for `cached_managed_cert` and `cached_unmanaged_cert` events to provide more detail, because `cert.Names` string slice doesn't seem that useful, can't do much with that alone. But I'm not sure I understand the usefulness of those events, so meh. Caching seems like pretty much an internal implementation detail of certmagic.

* Adjust struct and field naming

* Mark CertificateEventData as experimental
2022-03-24 12:14:30 -06:00
Matthew Holt
55be6d8695
Rename ACMEManager -> ACMEIssuer, CertificateManager -> Manager
This is necessary to eliminate confusing naming conventions, since now
we have Manager types, having an issuer called ACMEManager was
confusing.

CertificateManager is a redundant name as this package is called
CertMagic, so that a Manager manages certificates should be obvious.
It's also more succinct. Plus, it's consistent with Issuer which is not
named CertificateIssuer.
2022-03-24 11:34:31 -06:00
Ran Chen
ae2a5ddada
solvers: Always call checkDNSPropagation in DNS01Solver (#179)
Calling checkAuthoritativeNss is wrong as it's not inter-changeable with
checkDNSPropagation.

Though IIUC it's not necessary to follow CNAME when in Wait(), with or
without OverrideDomain, let's wait until the override domain gets some
usage to change this. The reason that following CNAME is not necessary
is that CNAME cannot co-exist with other DNS records, if we succeed in
setting a TXT record on that domain, it cannot have a CNAME record.

@IndeedNotJames
2022-03-24 11:21:26 -06:00
Alban Lecocq
915efd8fdb
Fix crash because of a zero value cert in cache (#177)
* Fix crash because of a zero value cert in cache

Check a cert is still in cache when trying to update its
ocsp & OCSPStaple fields

Why: Bc in parallel of updateOCSPStaples() loops,
any cert can be removed from a full cache to make some room.

* Update maintain.go

Co-authored-by: Matt Holt <mholt@users.noreply.github.com>

Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
2022-03-22 15:54:52 -06:00
Dave Henderson
9a56fcd4f9
Propagate context in the Storage interface methods (#155)
* Add context propagation to the Storage interface

Signed-off-by: Dave Henderson <dhenderson@gmail.com>

* Bump to Go 1.17

* Minor cleanup

* filestorage: Honor context cancellation in List()

Co-authored-by: Matthew Holt <mholt@users.noreply.github.com>
2022-03-07 12:26:52 -07:00
Matt Holt
2d114193c3
storage: Require fs.ErrNotExist (fix #168) (#170)
Also stop using the deprecated io/ioutil package.
Update dependencies.
Update Go version in go.mod.
2022-03-07 11:11:20 -07:00
Ran Chen
f60ce01d6d
Implement OverrideDomain is DNS01Solver (#160)
* Add OverrideDomain option to DNS01Solver

This is to delegate the challenge to a different domain. With this
change, the solver no longer follows CNAME chain when checking for
propagation as well.

* Update solvers.go

* Only check the authoritative NS when OverrideDomain is set

and keep the old code path otherwise.

Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
2022-03-07 10:34:57 -07:00
Matt Holt
797d29bcf3
GetCertificate from external certificate sources (Managers) (#163)
This work made possible by Tailscale: https://tailscale.com - thank you to the Tailscale team!

* Implement custom GetCertificate callback

Useful if another entity is managing certificates and can
provide its own dynamically during handshakes.

* Refactor CustomGetCertificate into OnDemandConfig

* Set certs to managed=true

This is only sorta true, but it allows handshake-time maintenance of the
certificates that are cached from CustomGetCertificate.

Our background maintenance routine skips certs that are OnDemand so it
should be fine.

* Change CustomGetCertificate into interface value

Instead of a function

* Case-insensitive subject name comparison

Hostnames are case-insensitive

Also add context to GetCertificate

* Export a couple of outrageously useful functions

* Allow multiple custom certificate getters

Also minor refactoring and enhancements

* Fix tests

* Rename Getter -> Manager; refactor

And don't cache externally managed certs

* Minor updates to comments
2022-02-17 14:37:50 -07:00
Sam Lord
134f03986c
Load private keys first (#171)
The order of storing the certificates was previously changed so that the
private key would be stored first. For anyone who is creating storage
hooks which push the certificate & key to a 3rd party service (like a
CDN), the certificates are generally refused if uploaded before the
private key.

Loading can trigger the same issue if (for any reason), the certificate
& key have been deleted on the 3rd party service.

I'll admit that this stretches what the storage system should be doing,
but with this trivial change it is really easy to create a reliable
link to a CDN.
2022-02-15 12:23:49 -07:00
Matthew Holt
2f78e52756
Merge branch 'ondemanddebug' 2022-02-01 13:31:13 -07:00
Matthew Holt
bdc84f966f
Clean up logs 2022-02-01 13:30:52 -07:00