Commit Graph

20 Commits

Author SHA1 Message Date
Nick Ubels
3bad5b6bb5
Check for .internal with SubjectIsInternal (#305) 2024-08-09 18:24:33 -06:00
Matthew Holt
f7ea6fb698
Enhancements to make ZeroSSL issuer more usable in Caddy 2024-04-11 12:23:53 -06:00
Matthew Holt
66685874a8
Add .home.arpa to internal-only hostnames 2023-09-05 09:38:56 -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
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
066b08905b
More debug logging (cert selection, handshakes) 2021-08-30 12:54:05 -06:00
Matthew Holt
df1d58e0e1
Improve wildcard matching tests
Honoring RFC 2818
2021-02-10 14:36:08 -07:00
Matthew Holt
5a926ec14f
Update subject certificate qualifications
I suppose * is a valid subject -- technically -- but it probably won't
be accepted by browsers. They usually only accept wildcards
for subdomains.

Related, but only tangentially:
https://github.com/caddyserver/caddy/issues/3977
2021-01-19 14:53:32 -07:00
Matthew Holt
90d1550af4
Refactor subject qualification logic
This is necessary to support a nuance in Caddy where we have to see if a
subject qualifies for a public certificate but with custom wildcard
checking. So we separate the wildcard check from other checks.
2020-10-21 09:08:19 -06:00
Matthew Holt
6c5ba250d1
Add MatchWildcard() method for comparing names with wildcards
CertMagic currently does wildcard matching in two places:
- Cache.AllMatchingCertificates() for finding all certs in cache
- Config.getCertificate() for finding one cert in cache at handshake

But those implementations will not use MatchWildcard() because their
looping logic is slightly customized.

Caddy, however, has need to compare DNS names with wildcards in at
least two places:
- Matching TLS connection policies by ServerName (SNI)
- Matching TLS automation policies by subject names

So this function is a good implementation for that.
2020-03-26 13:58:05 -06:00
Matthew Holt
6000a83cf1
Add .local TLD to list of internal-only names
Also improve comment on Storage interface's Delete method.
2020-03-23 13:34:23 -06:00
Matthew Holt
e9f9f60183
Separate logic for qualifying names for any cert vs. public certs 2020-03-13 19:09:36 -06:00
Matthew Holt
5265f2bcb1
Rename function 2020-03-12 16:02:48 -06:00
Matthew Holt
11467829d4
Update HostQualifies logic to be specific for public certs
Because CertMagic can now be used for more than just publicly-trusted
certificates.
2020-03-07 18:56:16 -07:00
Matthew Holt
96223721b8
Reject common special characters in HostQualifies 2019-10-14 13:58:44 -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
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
Joël Gähwiler
c777edeef8 Use DefaultServerName when SNI missing (#23)
* properly test non sni connections by passing in a fake connection

* added default server name

* Refactor default server name (SNI) implementation
2019-02-02 11:10:17 -07:00
Matthew Holt
c1d472b460 handshake: Use local listener IP to find cert if no SNI provided
See mholt/caddy#2356
2019-01-21 18:48:09 -07:00
Matthew Holt
f4d0f78032
Move some tests over
Tests originally from Caddy's caddytls package

Also fix a few bugs: sorting most recent emails, and nil Config in
HTTP challenge handler
2018-12-10 09:59:03 -07:00