From 3062fd0c5ea2e219adc7ec91462f032f11763c19 Mon Sep 17 00:00:00 2001 From: WendelHime <6754291+WendelHime@users.noreply.github.com> Date: Wed, 17 Jul 2024 15:39:37 -0300 Subject: [PATCH] feat: adding SNIConfig to provider and load it --- context.go | 2 +- masquerade.go | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/context.go b/context.go index 6e3df2a..0b08eae 100644 --- a/context.go +++ b/context.go @@ -97,7 +97,7 @@ func (fctx *FrontingContext) ConfigureWithHello(pool *x509.CertPool, providers m // copy providers for k, p := range providers { - d.providers[k] = NewProvider(p.HostAliases, p.TestURL, p.Masquerades, p.Validator, p.PassthroughPatterns) + d.providers[k] = NewProvider(p.HostAliases, p.TestURL, p.Masquerades, p.Validator, p.PassthroughPatterns, p.SNIConfig) } d.loadCandidates(d.providers) diff --git a/masquerade.go b/masquerade.go index 041b370..8231571 100644 --- a/masquerade.go +++ b/masquerade.go @@ -79,6 +79,12 @@ type Provider struct { // Url used to vet masquerades for this provider TestURL string Masquerades []*Masquerade + + // SNIConfig is a map of SNIs with configurations per region. + // The key can be a region initial or the default value, used when + // the region wants to use arbitrary SNIs but doesn't provide the SNI list. + SNIConfig *SNIConfig + // Optional response validator used to determine whether // fronting succeeded for this provider. If the validator // detects a failure for a given masquerade, it is discarded. @@ -86,14 +92,20 @@ type Provider struct { Validator ResponseValidator } +type SNIConfig struct { + UseArbitrarySNIs bool + ArbitrarySNIs []string +} + // Create a Provider with the given details -func NewProvider(hosts map[string]string, testURL string, masquerades []*Masquerade, validator ResponseValidator, passthrough []string) *Provider { +func NewProvider(hosts map[string]string, testURL string, masquerades []*Masquerade, validator ResponseValidator, passthrough []string, sniConfig *SNIConfig) *Provider { d := &Provider{ HostAliases: make(map[string]string), TestURL: testURL, Masquerades: make([]*Masquerade, 0, len(masquerades)), Validator: validator, PassthroughPatterns: make([]string, 0, len(passthrough)), + SNIConfig: sniConfig, } for k, v := range hosts { d.HostAliases[strings.ToLower(k)] = v