Commit Graph

33 Commits

Author SHA1 Message Date
Matthew Holt
16c9db1449
zerossl: Make CNAME target absolute (fix #304) 2024-08-02 17:26:49 -06:00
Matthew Holt
16e2e0b344
Synchronize ARI fetching (fix #297) 2024-06-28 10:33:21 -06:00
Matt Holt
193db7523a
Sync ACME account registration (#293)
https://caddy.community/t/lets-encrypt-hits-rate-limit-too-many-registrations-for-this-ip/24343
2024-06-06 05:17:18 -06:00
Matthew Holt
a1e1bd6ab5
More logging about account loading/creation 2024-06-03 19:47:29 -06:00
Matthew Holt
ed73243f8b
Export interface for GetRenewalInfo
We can't assume the ARI-supporting issuer types are exactly *ACMEIssuer; they may be implemented by third party packages (such as caddytls.ACMEIssuer).
2024-06-01 17:59:39 -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
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
28e3a67376
Remove deprecated call to rand.Seed 2024-04-08 12:41:42 -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
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
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
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
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
Matthew Holt
047b545304
Adjust ACME client throttle to 10/10s (close #143) 2021-09-16 12:21:57 -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
14b314f4d6
Increase internal ACME transaction rate limit
From 1 every 6 seconds to 1 every 3 seconds. If this becomes a problem we'll reduce them again.
2021-04-01 12:30:23 -06:00
Matthew Holt
ebb8d8b435
Return Account from NewAccountFunc
This allows the callback to change the Account.

This useful if, for example, using the callback to set missing contact info on the Account.
2021-02-10 19:00:17 -07:00
Matthew Holt
2a9ad38637
Refactor challenge info / solving
This allows any challenges initiated within the process to be solved by whatever HTTP or TLS server is running, even if they do not know about the challenges themselves.

This is useful when a process has multiple servers running, but only one can solve the challenges (which is often the case, since a socket belongs to one listener at a time) and they do not know about each other or share configs. The trick is to wrap the solvers with a thin wrapper that stores all the challenge info in memory while the challenge is active.

A nice side-effect is I've simplified/unified the code that gets the challenge info when actually solving the challenges.
2021-01-22 17:43:33 -07:00
Matthew Holt
892ccc9af1
Ability to specify ACME account by private key
This makes it possible to use existing ACME account when you have the private key but not the contact information. Often the case when the ACME account is created out-of-band of the ACME client.
2021-01-22 17:26:47 -07:00
Matthew Holt
5259faf208
Support account lookup by private key
This enables adding existing accounts to storage so they
can be used in future ACME transactions, as long as the
private key is possessed.
2021-01-20 14:52:08 -07:00
Matt Holt
0f8a9f6887
Implement multiple issuer support (#109)
* Implement multiple issuer support

This change refactors Config.Issuer to be Config.Issuers, an array of
issuers. Each Issuer will be tried in turn until one succeeds. During
retries, each attempt will try each configured Issuer. When loading
certs from storage, CertMagic will look in each Issuer's storage
location for a qualifying asset. If multiple Issuers have one in storage
then the most-recently-issued cert will be selected.

This is a breaking change in that Config now accepts a slice of Issuers
rather than a single Issuer. The Revoker field is removed, as supporting
it is optional anyway. If the Issuer is also a Revoker, it can be used
implicitly to revoke certificates.

Also added a const for ZeroSSL's ACME endpoint.

* Load matching wildcard on-demand from storage

With this change, a config using on-demand TLS can load a certificate
for "sub.example.com" from storage using a matching  wildcard cert
(i.e. "*.example.com") if no better matching certificate is available.

* Fix distributed solving with tls-alpn challenges

The type assertion in handshake.go was problematic since there's no
guarantee that an ACME issuer would be a concrete ACMEManager type.

Refactored the code to accept IssuerKey values generally, rather than
specific ACMEManager values only.

This fixes solving tls-alpn challenges in distributed settings.

More cleanup can be done, another time.
2020-11-16 10:53:41 -07:00
Matthew Holt
5fd26543e0
Add NewAccountFunc callback
This is necessary for a downstream requirement where the ACME CA offers
an API key to generate EAB credentials, but each time their API call is
used, new credentials are generated, so we need to be sure to use it
only once (when an account is actually being created). Thus, CertMagic
needs a way to tell the application when the account is actually being
created versus being reused. This allows the application to make an API
call just before account registration and fill the EAB credentials into
the ACMEManager struct.
2020-08-04 14:21:47 -06:00
Matthew Holt
7d9dfc3fe6
Add DNS-01 solver implementation that uses acmez and libdns APIs
Before when we used lego as our ACME library, DNS solvers abounded in
the lego repository and they could be used directly. Our new acmez lib
is very lightweight, and "bring-your-own-solvers", let alone your own
DNS provider implementations.

DNS providers are implemented in libdns: https://github.com/libdns

This commit adds an implementation of acmez.Solver that solves the DNS
challenge using libdns providers.

Unlike the other solvers, this one is exported because it is not a
challenge type that is enabled by default, and there is more config
surface.

We borrowed some DNS utility functions and tests from the lego repo.

But this is a very lightweight implementation that has a much, much
simpler API and smaller footprint.
2020-07-30 14:07:04 -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
Matt Holt
b76b76abfc
Replace lego with ACMEz (close #71) (#78) 2020-07-27 16:50:41 -06:00
Matthew Holt
77f91b9bbe
Don't encode EAB HMAC
Most providers already encode it
2020-06-11 15:30:56 -06:00
Matthew Holt
5b5ac32a85
Only use default test CA if primary CA is also default
Fixes https://github.com/caddyserver/caddy/issues/3466
2020-06-02 11:11:01 -06:00
Matthew Holt
663df05914
Allow duplicate 'obtain' jobs
See https://github.com/caddyserver/caddy/issues/3202
2020-04-14 11:26:24 -06:00
Matthew Holt
079e973f5b
Add support for the externalAccountBinding ACME extension 2020-03-31 21:05:39 -06:00
Matthew Holt
e02edabc36 Ask before renewing and uncache rejected certs; fix certs path 2020-03-06 17:55:13 -07:00
Matthew Holt
37e754b40c
Major refactor to improve performance, correctness, and extensibility
Breaking changes; thank goodness we're not 1.0 yet 😅 - read on!

This change completely separates ACME-specific code from the rest of the
certificate management process, allowing pluggable sources for certs
that aren't ACME.

Notably, most of Config was spliced into ACMEManager. Similarly, there's
now Default and DefaultACME.

Storage structure had to be reconfigured. Certificates are no longer in
the acme/ subfolder since they can be obtained by ways other than ACME!
Certificates moved to a new certificates/ subfolder. The subfolders in
that folder use the path of the ACME endpoint instead of just the host,
so that also changed. Be aware that unless you move your certs over,
CertMagic will not find them and will attempt to get new ones. That is
usually fine for most users, but for extremely large deployments, you
will want to move them over first.

Old certs path:
  acme/acme-staging-v02.api.letsencrypt.org/...

New certs path:
  certificates/acme-staging-v02.api.letsencrypt.org-directory/...

That's all for significant storage changes!

But this refactor also vastly improves performance, especially at scale,
and makes CertMagic way more resilient to errors. Retries are done on
the staging endpoint by default, so they won't count against your rate
limit. If your hardware can handle it, I'm now pretty confident that you
can give CertMagic a million domain names and it will gracefully manage
them, as fast as it can within internal and external rate limits, even
in the presence of errors. Errors will of course slow some things down,
but you should be good to go if you're monitoring logs and can fix any
misconfigurations or other external errors!

Several other mostly-minor enhancements fix bugs, especially at scale.
For example, duplicated renewal tasks (that continuously fail) will not
pile up on each other: only one will operate, under exponential backoff.

Closes #50 and fixes #55
2020-02-21 14:32:57 -07:00