fix application bug
This commit is contained in:
32
vendor/github.com/mholt/caddy/caddytls/setup.go
generated
vendored
32
vendor/github.com/mholt/caddy/caddytls/setup.go
generated
vendored
@@ -36,7 +36,9 @@ import (
|
||||
func init() {
|
||||
// opt-in TLS 1.3 for Go1.12
|
||||
// TODO: remove this line when Go1.13 is released.
|
||||
os.Setenv("GODEBUG", os.Getenv("GODEBUG")+",tls13=1")
|
||||
if err := os.Setenv("GODEBUG", os.Getenv("GODEBUG")+",tls13=1"); err != nil {
|
||||
log.Println("[ERROR] failed to set environment variable: ", err)
|
||||
}
|
||||
|
||||
caddy.RegisterPlugin("tls", caddy.Plugin{Action: setupTLS})
|
||||
|
||||
@@ -63,7 +65,7 @@ func setupTLS(c *caddy.Controller) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("constructing cluster plugin %s: %v", clusterPluginName, err)
|
||||
}
|
||||
certmagic.DefaultStorage = storage
|
||||
certmagic.Default.Storage = storage
|
||||
} else {
|
||||
return fmt.Errorf("unrecognized cluster plugin (was it included in the Caddy build?): %s", clusterPluginName)
|
||||
}
|
||||
@@ -363,6 +365,14 @@ func setupTLS(c *caddy.Controller) error {
|
||||
telemetry.Increment("tls_self_signed_count")
|
||||
}
|
||||
|
||||
// store this as a custom config
|
||||
cfgMap, ok := c.Get(configMapKey).(map[string]*Config)
|
||||
if !ok || cfgMap == nil {
|
||||
cfgMap = make(map[string]*Config)
|
||||
}
|
||||
cfgMap[config.Hostname] = config
|
||||
c.Set(configMapKey, cfgMap)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -401,26 +411,34 @@ func loadCertsInDir(cfg *Config, c *caddy.Controller, dir string) error {
|
||||
|
||||
if derBlock.Type == "CERTIFICATE" {
|
||||
// Re-encode certificate as PEM, appending to certificate chain
|
||||
pem.Encode(certBuilder, derBlock)
|
||||
if err := pem.Encode(certBuilder, derBlock); err != nil {
|
||||
log.Println("[ERROR] failed to write PEM encoding: ", err)
|
||||
}
|
||||
} else if derBlock.Type == "EC PARAMETERS" {
|
||||
// EC keys generated from openssl can be composed of two blocks:
|
||||
// parameters and key (parameter block should come first)
|
||||
if !foundKey {
|
||||
// Encode parameters
|
||||
pem.Encode(keyBuilder, derBlock)
|
||||
if err := pem.Encode(keyBuilder, derBlock); err != nil {
|
||||
log.Println("[ERROR] failed to write PEM encoding: ", err)
|
||||
}
|
||||
|
||||
// Key must immediately follow
|
||||
derBlock, bundle = pem.Decode(bundle)
|
||||
if derBlock == nil || derBlock.Type != "EC PRIVATE KEY" {
|
||||
return c.Errf("%s: expected elliptic private key to immediately follow EC parameters", path)
|
||||
}
|
||||
pem.Encode(keyBuilder, derBlock)
|
||||
if err := pem.Encode(keyBuilder, derBlock); err != nil {
|
||||
log.Println("[ERROR] failed to write PEM encoding: ", err)
|
||||
}
|
||||
foundKey = true
|
||||
}
|
||||
} else if derBlock.Type == "PRIVATE KEY" || strings.HasSuffix(derBlock.Type, " PRIVATE KEY") {
|
||||
// RSA key
|
||||
if !foundKey {
|
||||
pem.Encode(keyBuilder, derBlock)
|
||||
if err := pem.Encode(keyBuilder, derBlock); err != nil {
|
||||
log.Println("[ERROR] failed to write PEM encoding: ", err)
|
||||
}
|
||||
foundKey = true
|
||||
}
|
||||
} else {
|
||||
@@ -449,3 +467,5 @@ func loadCertsInDir(cfg *Config, c *caddy.Controller, dir string) error {
|
||||
func constructDefaultClusterPlugin() (certmagic.Storage, error) {
|
||||
return &certmagic.FileStorage{Path: caddy.AssetsPath()}, nil
|
||||
}
|
||||
|
||||
const configMapKey = "tls_custom_configs"
|
||||
|
||||
Reference in New Issue
Block a user