Read certificate and key for domain correctly

This commit is contained in:
Melon 2023-07-11 15:12:59 +01:00
parent 755e597a11
commit c930ddff28
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
2 changed files with 7 additions and 5 deletions

View File

@ -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)

View File

@ -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(),
},
}