diff --git a/common/tls/acme.go b/common/tls/acme.go index d311c279..08b24ed2 100644 --- a/common/tls/acme.go +++ b/common/tls/acme.go @@ -105,5 +105,16 @@ func startACME(ctx context.Context, options option.InboundACMEOptions) (*tls.Con }, }) config = certmagic.New(cache, *config) - return config.TLSConfig(), &acmeWrapper{ctx: ctx, cfg: config, cache: cache, domain: options.Domain}, nil + var tlsConfig *tls.Config + if acmeConfig.DisableTLSALPNChallenge || acmeConfig.DNS01Solver != nil { + tlsConfig = &tls.Config{ + GetCertificate: config.GetCertificate, + } + } else { + tlsConfig = &tls.Config{ + GetCertificate: config.GetCertificate, + NextProtos: []string{ACMETLS1Protocol}, + } + } + return tlsConfig, &acmeWrapper{ctx: ctx, cfg: config, cache: cache, domain: options.Domain}, nil } diff --git a/common/tls/acme_contstant.go b/common/tls/acme_contstant.go new file mode 100644 index 00000000..c5cd2ff1 --- /dev/null +++ b/common/tls/acme_contstant.go @@ -0,0 +1,3 @@ +package tls + +const ACMETLS1Protocol = "acme-tls/1" diff --git a/common/tls/std_server.go b/common/tls/std_server.go index 28a94cf1..7184bdb3 100644 --- a/common/tls/std_server.go +++ b/common/tls/std_server.go @@ -39,11 +39,19 @@ func (c *STDServerConfig) SetServerName(serverName string) { } func (c *STDServerConfig) NextProtos() []string { - return c.config.NextProtos + if c.acmeService != nil && len(c.config.NextProtos) > 1 && c.config.NextProtos[0] == ACMETLS1Protocol { + return c.config.NextProtos[1:] + } else { + return c.config.NextProtos + } } func (c *STDServerConfig) SetNextProtos(nextProto []string) { - c.config.NextProtos = nextProto + if c.acmeService != nil && len(c.config.NextProtos) > 1 && c.config.NextProtos[0] == ACMETLS1Protocol { + c.config.NextProtos = append(c.config.NextProtos[:1], nextProto...) + } else { + c.config.NextProtos = nextProto + } } func (c *STDServerConfig) Config() (*STDConfig, error) {