From c930ddff287a9119fb7c08f26e47f84bb3a89f2d Mon Sep 17 00:00:00 2001 From: MrMelon54 Date: Tue, 11 Jul 2023 15:12:59 +0100 Subject: [PATCH] Read certificate and key for domain correctly --- certs/certs.go | 8 +++++--- certs/certs_test.go | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/certs/certs.go b/certs/certs.go index 78d5be6..56921b0 100644 --- a/certs/certs.go +++ b/certs/certs.go @@ -10,7 +10,7 @@ import ( "io/fs" "log" "math/big" - "path/filepath" + "strings" "sync" "sync/atomic" "time" @@ -158,8 +158,10 @@ func (c *Certs) internalCompile(m map[string]*tls.Certificate) error { // get file name and extension name := i.Name() - ext := filepath.Ext(name) - keyName := name[:len(name)-len(ext)] + ".key" + if !strings.HasSuffix(name, ".cert.pem") { + continue + } + keyName := name[:len(name)-len("cert.pem")] + "key.pem" // try to read cert file certData, err := fs.ReadFile(c.cDir, name) diff --git a/certs/certs_test.go b/certs/certs_test.go index 42b9c58..f0549d9 100644 --- a/certs/certs_test.go +++ b/certs/certs_test.go @@ -41,13 +41,13 @@ func TestCertsNew_Lookup(t *testing.T) { assert.NoError(t, err) certDir := fstest.MapFS{ - "example.com.pem": { + "example.com.cert.pem": { Data: serverTls.GetCertPem(), }, } keyDir := fstest.MapFS{ - "example.com.key": { + "example.com.key.pem": { Data: serverTls.GetKeyPem(), }, }