From b0b2aaa70ce6681b44fee5a90f4c18ff9d39a76f Mon Sep 17 00:00:00 2001 From: WeidiDeng Date: Sat, 18 Sep 2021 03:48:22 +0800 Subject: [PATCH] Fixed refresh error when multiple certificates exist (#663) * Fix when there are multiple certs, after refresh from file all will be the same as the last. --- transport/internet/tls/config.go | 4 ++-- transport/internet/xtls/config.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/transport/internet/tls/config.go b/transport/internet/tls/config.go index 230b670e..219fbaaf 100644 --- a/transport/internet/tls/config.go +++ b/transport/internet/tls/config.go @@ -66,7 +66,7 @@ func (c *Config) BuildCertificates() []*tls.Certificate { isOcspstapling = true } index := len(certs) - 1 - go func(cert *tls.Certificate, index int) { + go func(entry *Certificate, cert *tls.Certificate, index int) { t := time.NewTicker(time.Duration(hotReloadCertInterval) * time.Second) for { if entry.CertificatePath != "" && entry.KeyPath != "" { @@ -107,7 +107,7 @@ func (c *Config) BuildCertificates() []*tls.Certificate { certs[index] = cert <-t.C } - }(certs[len(certs)-1], index) + }(entry, certs[index], index) } } return certs diff --git a/transport/internet/xtls/config.go b/transport/internet/xtls/config.go index 071bcc8f..8a631eb8 100644 --- a/transport/internet/xtls/config.go +++ b/transport/internet/xtls/config.go @@ -67,7 +67,7 @@ func (c *Config) BuildCertificates() []*xtls.Certificate { isOcspstapling = true } index := len(certs) - 1 - go func(cert *xtls.Certificate, index int) { + go func(entry *Certificate, cert *xtls.Certificate, index int) { t := time.NewTicker(time.Duration(hotRelodaInterval) * time.Second) for { if entry.CertificatePath != "" && entry.KeyPath != "" { @@ -108,7 +108,7 @@ func (c *Config) BuildCertificates() []*xtls.Certificate { certs[index] = cert <-t.C } - }(certs[len(certs)-1], index) + }(entry, certs[index], index) } } return certs