Commit Graph

28 Commits

Author SHA1 Message Date
Matthew Holt
140a6fa920
Improve API from previous commit to pair Subject with Issuer 2024-04-23 11:25:19 -06:00
Matthew Holt
81683c8d20
Add optional issuerKey to Cache.RemoveManaged 2024-04-23 10:47:06 -06:00
Matthew Holt
f7ea6fb698
Enhancements to make ZeroSSL issuer more usable in Caddy 2024-04-11 12:23:53 -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
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
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
a46420babd
Merge tags when reusing cert (fix #211) 2022-12-05 12:34:37 -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
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
88b8609b4d
Better fix for #142; patches 335551df 2021-09-22 14:28:00 -06:00
Matthew Holt
066b08905b
More debug logging (cert selection, handshakes) 2021-08-30 12:54:05 -06:00
Matthew Holt
93c97f917b
Debug logs on cert cache add/remove; fix loop
Remove loop had some fishy behavior in some contrived test cases.
2021-08-30 11:52:13 -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
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
Matthew Holt
7249bad811
Configurable cache capacity 2020-06-01 15:03:14 -06:00
Matthew Holt
fff412bb74
Restart maintenance routine if it panics 2020-05-13 11:11:27 -06:00
Matthew Holt
0a90841d31
Consider client's signature support when choosing certificates
This allows two certs (say, RSA and ECDSA) for the same names to be
loaded, and CertMagic will consider which one the client supports and
use that.

We used to extract just select fields from the leaf certificate so that
we didn't need to fill memory with more data than necessary, but in
order to use the stdlib's SupportsCertificate() method, we have to keep
the full tls.Certificate.Leaf field set for speed during handshakes.
2020-04-01 18:25:02 -06:00
Matthew Holt
10654c88f5
Let custom CertSelection choose from certs that don't match name 2020-03-17 16:00:18 -06:00
Matthew Holt
cbeee6e6b2
A few tweaks and fixes 2020-02-24 12:23:54 -07:00
Matthew Holt
7311b4680c
Perform OCSP staple updates outside of lock on certCache
Also add some log entries when certs are replaced in cache
2020-01-10 11:18:37 -07:00
Matthew Holt
ec140bfc93
Replace CertificatesWithSAN with AllMatchingCertificates
Does the same thing but includes wildcard certificates for matching
2019-09-13 11:43:02 -06:00
Matthew Holt
7b64d461c0
Add method to cache for getting certificates matching SAN 2019-08-09 12:12:46 -06:00
Matthew Holt
6a42ef9fe8
Optional tags for unmanaged certificates
This allows for user-loaded certificates to be associated with arbitrary
values such as user-provided IDs or categories. This can be useful if
multiple certificates satisfy a ClientHello but if a specific one still
needs to be chosen. See for example:
https://github.com/mholt/caddy/issues/2588

This is a breaking API change since we need to expose a tags parameter
to the caching functions, but we're not 1.0 yet so we will try this
API change and see how it goes.
2019-06-24 11:51:58 -06:00
Matthew Holt
c0671874d2
Retry if creating manager (ACME client) fails 2019-06-19 16:49:54 -06:00
Matthew Holt
9f9dd53d26
Add hook for custom certificate selection logic (mholt/caddy#2588) 2019-05-23 16:11:32 -06:00
Matt Holt
8f7a1caa59
Significant refactoring to improve correctness and flexibility (#39)
* Significant refactor

This refactoring expands the capabilities of the library for advanced
use cases, as well as improving the overall architecture, including
possible memory leak fixes if used over a long period with many certs
loaded into memory. This refactor enables using different configs
depending on the certificate.

The public API has changed slightly, however, and arguably it is
slightly less convenient/elegant. I have never quite found the perfect
design for this package, and this certainly isn't it, but I think it's
better than what we had before.

There is still work to be done, but this is a good step forward. I've
decoupled Storage from Cache, and made it easier and more correct for
Configs (and Storage values) to be short-lived. Cache is the only value
that should be long-lived.

Note that CertMagic no longer automatically takes care of storage (i.e.
it used to delete old OCSP staples, but now it doesn't). The functions
to do this are still there and even exported, and now we expect the
application to call the cleanup functions when it wants to.

* Fix little oopsies

* Create Manager abstraction so obtain/renew isn't limited to ACME
2019-04-20 10:44:55 -06:00
Matthew Holt
b4085847b5
Don't initialize a default cache until one is needed
This gives importers the opportunity to set DefaultStorage first, then
the it will be used thereafter with the default cache, which is only
initialized once.

Also it should prevent confusing or unnecessary log messages like
reported at the end of issue #4.
2018-12-12 16:40:19 -07:00
Matthew Holt
bea13a36c8
Initial commit 2018-12-09 20:15:26 -07:00