Skip to content

Commit

Permalink
Fix ACME ALPN conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Dec 26, 2023
1 parent 76a295a commit 3eed614
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
13 changes: 12 additions & 1 deletion common/tls/acme.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions common/tls/acme_contstant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package tls

const ACMETLS1Protocol = "acme-tls/1"
12 changes: 10 additions & 2 deletions common/tls/std_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3eed614

Please sign in to comment.