mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-21 05:50:46 +08:00
Disable TLS completely if there is no listener with tls enabled (#1456)
* Disable TLS completely if there is no listener with tls enabled * Format code
This commit is contained in:
parent
6083871088
commit
1262ae92e9
|
@ -93,9 +93,11 @@ func NewServer(addr string, group []*SiteConfig) (*Server, error) {
|
|||
|
||||
s.tlsConfig = tlsConfigs
|
||||
|
||||
s.Server.TLSConfig = &tls.Config{
|
||||
GetConfigForClient: s.tlsConfig.GetConfigForClient,
|
||||
GetCertificate: s.tlsConfig.GetCertificate,
|
||||
if caddytls.HasTLSEnabled(allConfigs) {
|
||||
s.Server.TLSConfig = &tls.Config{
|
||||
GetConfigForClient: s.tlsConfig.GetConfigForClient,
|
||||
GetCertificate: s.tlsConfig.GetCertificate,
|
||||
}
|
||||
}
|
||||
|
||||
// As of Go 1.7, HTTP/2 is enabled only if NextProtos includes the string "h2"
|
||||
|
|
|
@ -230,14 +230,22 @@ func (cfg *Config) Build(group ConfigGroup) error {
|
|||
return err
|
||||
}
|
||||
|
||||
cfg.tlsConfig = config
|
||||
cfg.tlsConfig.GetCertificate = group.GetCertificate
|
||||
if config != nil {
|
||||
cfg.tlsConfig = config
|
||||
cfg.tlsConfig.GetCertificate = group.GetCertificate
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (cfg *Config) build() (*tls.Config, error) {
|
||||
config := new(tls.Config)
|
||||
|
||||
if !cfg.Enabled {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
ciphersAdded := make(map[uint16]struct{})
|
||||
curvesAdded := make(map[tls.CurveID]struct{})
|
||||
|
||||
|
@ -337,6 +345,16 @@ func CheckConfigs(configs []*Config) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func HasTLSEnabled(configs []*Config) bool {
|
||||
for _, config := range configs {
|
||||
if config.Enabled {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// ConfigGetter gets a Config keyed by key.
|
||||
type ConfigGetter func(c *caddy.Controller) *Config
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user