Commit Graph

360 Commits

Author SHA1 Message Date
Matthew Holt
707ebd9455
Fix typo, tune backoff more 2023-12-06 13:11:57 -07:00
Kenneth Jenkins
2b4a688bf9
Add OCSP stapling unit tests (#259)
Add a few tests to exercise OCSP stapling, using an httptest.Server
acting as the OCSP responder.

These tests are very simplistic:
 - a "good" OCSP response should be stapled
 - a "revoked" OCSP response should not be stapled
 - the DisableStapling option should be honored
 - OCSP stapling requires an issuing certificate

No attempt is made to provide sensible timestamps, either in the test
certificates or in the OCSP responses.

This brings unit test coverage for ocsp.go from 21% to 70%.
2023-11-28 21:26:51 -07:00
Matthew Holt
4574cfafa8
Fix unserializable ClientHelloInfo 2023-11-14 13:15:20 -07:00
Matthew Holt
754844673f
Don't try to decode last clean data if file does not exist 2023-11-14 07:45:43 -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
Matthew Holt
ee3b26a5e1
Global exclusion lock on storage cleaning
Cleaning storage now obtains a lock, and it can optionally be configured
to only happen once per interval.

This should help lower costs for expensive storage backends
that are used by clusters of CertMagic/Caddy instances.
2023-11-13 20:59:51 -07:00
Matthew Holt
63493552e4 Tune exponential backoff
Based on recent DNS propagation experiences
2023-11-09 11:59:32 -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
dependabot[bot]
560847b904
Bump golang.org/x/net from 0.11.0 to 0.17.0 (#253)
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.11.0 to 0.17.0.
- [Commits](https://github.com/golang/net/compare/v0.11.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-11 22:07:28 -06:00
Matthew Holt
93305b0e56
Improv port in use warning message (fix #250) 2023-09-07 16:59:03 -06:00
Matthew Holt
66685874a8
Add .home.arpa to internal-only hostnames 2023-09-05 09:38:56 -06:00
oliverpool
4fbb049d3b
README: Add hint about NextProtos for certmagic.TLS (#251) 2023-08-22 11:56:44 -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
Matthew Holt
37f5766fed
Use fresh context for Unlock (fix #247) 2023-08-09 13:23:11 -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
51b31907aa Fix downstream race conditions with NewAccountFunc
These functions typically modify the ACMEIssuer.
Only one such consumer of this API is known (Caddy).
2023-07-19 16:12:43 -06:00
Kenneth Jenkins
693a79bb13
Define a NoOCSPServerSpecified error (#245)
Define an exported NoOCSPServerSpecified error, to make it easier to
distinguish the case that a certificate does not support OCSP (from
other OCSP stapling errors). Add a unit test exercising this behavior.
2023-07-17 19:42:48 -06:00
Matthew Holt
1bdc8fd841
Remove flaky tests...
We need a better way of testing DNS utils.
2023-07-09 21:53:48 -06:00
Matthew Holt
fb1700b298
Getter method for cert hash
Useful downstream where we need to see if cache has a specific cert
2023-07-09 21:47:35 -06:00
Matthew Holt
f01bd63514
Only load *uncached* managed certs from storage
If a managed certificate already exists in the cache,
don't load it from storage again.
2023-07-08 10:44:13 -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
d8b13df4d1 Add pki.goog to known public ACME CAs 2023-06-30 18:45:39 -06:00
Matthew Holt
7836d86c96 Change slice to map to avoid O(n^2) performance 2023-06-30 18:45:39 -06:00
Conrad Hoffmann
d8e706f9b5
README: fix typo in sample code and update (#243) 2023-06-28 10:59:06 -06:00
Matthew Holt
223063d7be
Enhance Storage/Locker comments (fix #242) 2023-06-28 10:39:10 -06:00
Matthew Holt
dc8e4faa1c
Update PEM of private key after regenerating
Otherwise, leads to mismatched key + cert in storage
2023-06-21 13:23:41 -06:00
Matthew Holt
dd8df32b42
go.mod: Upgrade dependencies 2023-06-20 13:33:14 -06:00
Matthew Holt
0bc747093f
Tune empty-lock retry mechanism (issue #232) 2023-06-16 10:19:46 -06:00
Matthew Holt
321ed64912
Wait and retry if lockfile is empty (fix #232) 2023-06-15 15:32:25 -06:00
Matt Holt
65d3af6938
Issuer policies that can randomize issuer used (#238) 2023-06-13 22:05:29 -06:00
Matt Holt
232fade720
Generate new private keys for new certificates (#237)
* Always generate new private keys by default

* Update readme
2023-06-13 19:01:17 -06:00
Matthew Holt
25bb2afb2c
Fix cert_obtained event info 2023-06-09 11:46:12 -06:00
Sebastian Mæland Pedersen
d37847a6d4
Fix advanced cache initialization in README (#198)
* Fix advanced cache initialization in README

As per the documentation of GetConfigForCert:
> The returned Config MUST be associated with the same Cache as the caller.
A valid Config cannot be constructed with &certmagic.Config{} as the certCache field is unexported.
The only way to construct a Config with a non-nil Cache is to use either NewDefault or New.

* Make it an error for GetConfigForCert to return Config w/ nil cache

This prevents an invalid Config from slipping through and causing a hard to
debug nil pointer dereference at some later point.
2023-06-05 16:33:38 -06:00
Matt Holt
8728b186fa
Refactor Managers into on-demand config (#231) 2023-05-11 12:36:44 -06:00
Matthew Holt
53140d5220
Remove accidental inclusion from other branch 2023-05-10 13:39:43 -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
06734ae740
Update CI to Go 1.19, 1.20 2023-05-06 09:12:59 -06:00
Matthew Holt
53575742b6
Make storage check optional (close #201)
Not a good idea most of the time though.
2023-05-05 20:36:14 -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
Francis Lavoie
15a8b4f4c5
chore: Skip slow tests on Windows (#229) 2023-04-18 10:47:55 -06:00
wusatosi
c76688207f
Update & Improve CI (#227)
* Update ci.yml

* Trigger CI

* Remove commented-out section

* Trigger CI

* Use go mod download

* Replace set-output

* Cleanup

* Archive code coverage result

* Better artifact name scheme

* Use implicit default of `cache-dependency-path`

* Update CI

* Update matrix to include 1.20
2023-04-17 19:56:36 -06:00
kizmc
462f5e2334
Use recursive query when checking for TXT records (#224) 2023-04-10 10:22:45 -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
dependabot[bot]
3514797a52
Bump golang.org/x/net from 0.0.0-20220805013720-a33c5aa5df48 to 0.7.0 (#218)
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.0.0-20220805013720-a33c5aa5df48 to 0.7.0.
- [Release notes](https://github.com/golang/net/releases)
- [Commits](https://github.com/golang/net/commits/v0.7.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-06 22:34:59 -07:00