Commit Graph

102 Commits

Author SHA1 Message Date
Matthew Holt
80bb9a843f Debug log when creating CSR 2024-09-04 15:23:58 -06:00
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
Matthew Holt
1ff1ad8413
Normalize domain before managing
Fix github.com/caddyserver/caddy/issues/6456
2024-07-22 08:53:24 -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
fb2d9bff95
Write CSR PEM to cert_obtained events
Close caddyserver/caddy#5999
2024-04-13 07:33:47 -06:00
Matthew Holt
f7ea6fb698
Enhancements to make ZeroSSL issuer more usable in Caddy 2024-04-11 12:23:53 -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
30e4f93722
Log issuer when cert is obtained or renwed successfully 2024-04-08 13:35:23 -06:00
Matthew Holt
b29d2a03a0
Implement SubjectTransformer
This makes it possible to replace cert subjects with wildcards, for example

Related: #280
2024-04-08 13:35:09 -06:00
Matt Holt
6095ab8069
Initial implementation of ZeroSSL API issuer (#279)
* Initial implementation of ZeroSSL API issuer

Still needs CA support for CommonName-less certs

* Accommodate ZeroSSL CSR requirements; fix DNS prop check

* Fix README example

* Fix comment
2024-04-08 10:59:55 -06:00
Matthew Holt
8613f4a444
Configurable HTTP proxy for OCSP requests (close #267) 2024-03-01 10:30:36 -07: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
7836d86c96 Change slice to map to avoid O(n^2) performance 2023-06-30 18:45:39 -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
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
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
69cca0e742
Fix decision func enforcement (d'oh) 2023-05-06 12:30:48 -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
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
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
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
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
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
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
56c70f3808
Update to Go 1.18; use any 2022-08-08 10:45:24 -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
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
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
Basit Ali
924f3153e9
Remove duplicate OnDemand assignment (#153) 2021-11-23 09:48:41 -07:00
Matthew Holt
6b2f5f9b1b
Update readme
And keep two similar methods next to each other
2021-09-30 13:20:39 -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
d9f599a2f7
Clarify NextProtos usage (#145) 2021-09-20 13:49:38 -06:00
ryankoski
647f27cf26
Add nil checks for log (#135) 2021-06-16 13:16:43 -06:00
Matt Holt
07f7d0dec1
Allow forced renewals; fix renew on OCSP revoke; change key on compromise (#134)
* Begin refactor of ObtainCert and RenewCert to allow force renews

* Don't reuse private key in case of revocation due to key compromise

* Improve logging in renew

* Run OCSP check at start of cache maintenance

Otherwise we wait until first tick (currently 1 hour) which might be too long

* Fix obtain; move some things around

Obtain now tries to reuse private key if exists, but if it doesn't exist, that shouldn't be an error (so we clear the error in that case).

Moved the removal of compromised private keys to have logging make more sense.
2021-06-12 13:47:47 -06:00
Matthew Holt
388f3ed4c5
Log errors between issuer attempts
See https://caddy.community/t/no-certificate-created-for-long-domain-name/12729/7?u=matt
2021-06-09 13:11:36 -06:00
Matthew Holt
267fdad76a
Add ClientCredentials() method
CertMagic has always been useful for TLS servers, with its Cache
type, which enables long-term automation of managed certs.
But there has never been a good way to use CertMagic with
client certificates, which can be automated the same way, but
which are used sporadically and instantaneously, rather than
during the long-running lifetime of a server.

This is a simple addition which provides a lot of value, so that
TLS clients can use CertMagic to automate their certificates.
The ClientCredentials() method returns chains of TLS certs that
are ready to be used in tls.Config structs to enable client auth.
2021-01-26 16:01:15 -07:00