mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-19 23:11:25 +02:00
Multi-certificate, SNI matching with exact map and suffix tree Add support for multiple TLS certificates with SNI-based selection. The root provider maintains a single centralized SNI matcher that uses an exact match map for O(1) lookups, falling back to a suffix tree for wildcard matching. Key features: - Add `Extra []Config` field to autocert.Config for additional certificates - Each extra entry must specify unique `cert_path` and `key_path` - Extra certs inherit main config (except `email` and `extra` fields) - Extra certs participate in ACME obtain/renew cycles independently - SNI selection precedence: exact match > wildcard match, main > extra - Single centralized SNI matcher on root provider rebuilt after cert changes The SNI matcher structure: - Exact match map: O(1) lookup for exact domain matches - Suffix tree: Efficient wildcard matching (e.g., *.example.com) Implementation details: - Provider.GetCert() now uses SNI from ClientHelloInfo for selection - Main cert is returned as fallback when no SNI match is found - Extra providers are created as child providers with merged configs - SNI matcher is rebuilt after Setup() and after ObtainCert() completes
33 lines
759 B
Go
33 lines
759 B
Go
package provider_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/yusing/godoxy/internal/autocert"
|
|
)
|
|
|
|
func TestExtraCertKeyPathsUnique(t *testing.T) {
|
|
t.Run("duplicate cert_path rejected", func(t *testing.T) {
|
|
cfg := &autocert.Config{
|
|
Provider: autocert.ProviderLocal,
|
|
Extra: []autocert.Config{
|
|
{CertPath: "a.crt", KeyPath: "a.key"},
|
|
{CertPath: "a.crt", KeyPath: "b.key"},
|
|
},
|
|
}
|
|
require.Error(t, cfg.Validate())
|
|
})
|
|
|
|
t.Run("duplicate key_path rejected", func(t *testing.T) {
|
|
cfg := &autocert.Config{
|
|
Provider: autocert.ProviderLocal,
|
|
Extra: []autocert.Config{
|
|
{CertPath: "a.crt", KeyPath: "a.key"},
|
|
{CertPath: "b.crt", KeyPath: "a.key"},
|
|
},
|
|
}
|
|
require.Error(t, cfg.Validate())
|
|
})
|
|
}
|