Commit Graph

87 Commits

Author SHA1 Message Date
Matthew Holt
5ee48a3108
Add config option to disable ARI
This may be temporary until ARI is more mature
2024-08-08 08:08:29 -06:00
Matt Holt
8ac11fafd0
Apply DefaultServerName more broadly during handshake (#287) 2024-05-13 09:08:05 -06:00
Matthew Holt
2ef8fdfaaf
Stricter TLS-ALPN challenge matching
According to RFC 8737.
2024-05-08 20:10:52 -06:00
Matt Holt
0e88b3eaa1
Initial implementation of ARI (#286)
* Initial implementation of ARI

* Enhance redundancy, robustness, and logging

* Improve ARI updating; integrate on-demand TLS; detect changed window
2024-05-07 09:46:03 -06:00
Matthew Holt
aa4d957707
Return error if cert manager returns error
Don't try to issue certificate. If a cert manager returns an error, it indicates that
it was supposed to be able to get a cert for that
name but was unable to do so.
2024-04-12 10:09:24 -06:00
Matthew Holt
7681257d05
Try cert Manager before asking permission
Managers are expected to have 'asking permission' built in
2024-04-12 08:48:27 -06:00
Matthew Holt
74862ff45a
Upgrade acmez to v2 beta
Adds support for customizing NotBefore/NotAfter times of certs
2024-04-08 14:05:43 -06:00
Matthew Holt
707ebd9455
Fix typo, tune backoff more 2023-12-06 13:11:57 -07:00
Matthew Holt
4574cfafa8
Fix unserializable ClientHelloInfo 2023-11-14 13:15:20 -07:00
Matthew Holt
e017bf7f67
Fix test (context can't be set in ClientHelloInfo) 2023-11-13 23:16:37 -07:00
Matthew Holt
db6a5762cf
Add decoded ClientHello to DecisionFunc context 2023-11-13 22:25:23 -07:00
Andreas Kohn
e8e6167a2a
Wrap error returned from checkIfCertShouldBeObtained (#256)
This allows a outside caller of `GetCertificate` to use `errors.As` to check for
their own response, and react accordingly.
2023-10-30 11:54:48 -06:00
Andreas Kohn
f0038ffe14
Add context arg to DecisionFunc (#255)
* Optionally pass the context argument down to the OnDemand decision func

* Remove the "compatibility shims"

This "breaks" the API here, but the change should be trivially obvious to an implementor
and it gives a lot less headache later.
2023-10-30 07:47:31 -06:00
Matt Holt
e82245309e
Use context from ClientHello during GetCertificate (#249)
* Use context from ClientHello during GetCertificate

(see #247)

* Avoid recursive ops during on-demand issuance
2023-08-17 11:24:25 -06:00
Matthew Holt
5bca6d1898
Fix on-demand TLS when SNI is empty
A recent change passed in ClientHello into loadCertFromStorage.
Then it used hello.ServerName directly, but this is empty
if the client connects via IP address.
Previously, we passed in the name from the ClientHello
which would be the SNI if set, or the conn IP.
We now use getNameFromClientHello() as we should.

Fixes https://github.com/caddyserver/caddy/issues/5758
2023-08-17 11:12:47 -06:00
Andreas Kohn
8fac0d028d
Use background context for renewing dynamic cert in background (#248)
The context available to `renewDynamicCertificate` comes from inside the TLS handshake, and as such
may be bounded by the lifespan of the connection. Passing this into a goroutine will lead to problems
when the connection ends (and the connection context gets canceled with it) but the goroutine is going
to do more I/O on that context.
2023-08-08 12:48:39 -06:00
Matthew Holt
93a28b732a
Make cache options updateable; new remove methods
These are useful for advanced applications (like Caddy) which would
like to remove certificates from the
cache in a controlled way, and operate the
cache with new settings while running.
2023-07-08 09:56:51 -06:00
Matthew Holt
7836d86c96 Change slice to map to avoid O(n^2) performance 2023-06-30 18:45:39 -06:00
Matt Holt
8728b186fa
Refactor Managers into on-demand config (#231) 2023-05-11 12:36:44 -06:00
Matthew Holt
dec254055d
Initial implementation of FallbackServerName 2023-05-09 19:53:35 -06:00
Matthew Holt
25b55042e5
Further fix on-demand cert loading 2023-05-06 19:01:58 -06:00
Matthew Holt
69cca0e742
Fix decision func enforcement (d'oh) 2023-05-06 12:30:48 -06:00
Matthew Holt
6670b5e1cc
Improve handshake logic
- Only load cert from storage (or manager) if allowed to do so  (fix #174)
- Sync cert loading so storage isn't stampeded (fix #185)
- Update dependencies
2023-05-05 20:26:50 -06:00
Andreas Kohn
0dc2834a03
Add a GetCertificateWithContext function (#225) 2023-05-05 10:53:21 -06:00
Samuel Hitz
6b92945f9d
Obtain instead of renew cert if it does not exist in storage (#221)
* obtain instead of renew cert if it does not exist in storage

* only check storage if the cert needs is about to be renewed
2023-03-21 15:14:57 -06: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
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
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
Matthew Holt
ab3db7526d
If DecisionFunc errors, log it and return currentCert 2022-08-31 14:37:06 -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
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
03cffeb193
Update a couple comments 2022-03-25 10:55:29 -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
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
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
Matthew Holt
bdc84f966f
Clean up logs 2022-02-01 13:30:52 -07:00
Matthew Holt
f849f878ef
Move force check 2022-02-01 10:50:23 -07:00
Matthew Holt
60df7f89b9
Some debug logs 2022-02-01 10:00:49 -07:00
Matt Holt
eef59acc1d
Fix force-renewing revoked on-demand certs (#166)
* Fix force-renewing revoked on-demand certs

Follow-up to 9245be5a2f

* One more fix for on-demand logic of revoked certs

* OCSP revocation checks at startup, too

Required significant refactoring, hope it works.
Yet again way too late at night for this...
2022-02-01 09:05:24 -07:00
Matthew Holt
9245be5a2f
Automatically replace revoked certs managed on-demand
When I initially wrote the auto-replace feature, it was for the standard mode of operation,
which I presumed the vast majority of CertMagic deployments use. At the time, On-Demand
mode of operation was fairly niche. And at the time, it looked tricky to properly enable this feature for on-demand certificates, so I shelved it considering it would be low-impact anyway.
So on-demand certificates didn't benefit from auto-replace in the case of revocation (oh well,
no other servers / ACME clients do that at all anyway).

I guess since that time, the use of CertMagic's exclusive on-demand feature has risen in
popularity. But there is no way to tell, and I had no real way of knowing whether any
significant use of the feature is being had since Caddy has no telemetry. (We used to
have telemetry -- benign, anonymous technical stats to help us understand usage -- but
unfortunately public backlash forced us to end the program.) Based on public feedback
forced by external events, it seems that on-demand TLS deployments are probably rare,
but each of those few deployments actually serve thousands of sites/domains. (The
true importance of this feature would have been clear months ago if Caddy had telemetry,
as Caddy is the primary importer of CertMagic.)

This commit should enable auto-replace for on-demand certificates. It required some
refactoring and some decisions that aren't *entirely* clear are right, but that's how it
goes.

I haven't tested this. (Last time I worked on this feature it took me about 2 days to test properly.)
2022-01-30 21:58:34 -07:00
Simon Kirsten
9b2c6ac884
Fix cacheAlmostFull calculation for unbounded caches (#156) 2021-12-15 10:40:53 -07:00
Matthew Holt
c17cc71228
Extend on-demand timeout to 3 minutes
Motivated by https://caddy.community/t/zerossl-dns-challenge-failing-often-route53-plugin/13822/25?u=matt

This seems excessive but has been confirmed to fix the problem in most cases.
2021-10-06 20:57:44 -06:00
Matthew Holt
1bbe11e291
Change ManageSync() to take a context (close #146)
This brings it in line with ObtainSync and RenewSync, and makes it consistent with ManageAsync.
2021-09-23 14:35:51 -06:00
Matthew Holt
88b8609b4d
Better fix for #142; patches 335551df 2021-09-22 14:28:00 -06:00
Matthew Holt
b74a9ce808
Add one more debug log to handshake 2021-09-03 11:34:05 -06:00
Matthew Holt
066b08905b
More debug logging (cert selection, handshakes) 2021-08-30 12:54:05 -06:00
Matt Holt
335551df8f
Load certs from storage if cache is full (#142)
Should fix "no certificate available" errors.

https://caddy.community/t/error-tls-alert-internal-error-592-again/13272/9?u=matt
2021-08-26 14:54:13 -06:00