Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (
"net"
"runtime"
"sort"
"time"
"strings"
"sync"
"time"
)

func hashSorted(lst []string) []byte {
Expand All @@ -41,12 +42,8 @@ var hostMap sync.Map //map[string]*tls.Certificate
func signHost(ca tls.Certificate, hosts []string) (cert *tls.Certificate, err error) {
var x509ca *x509.Certificate

// FIXME: There is a bug here. If hosts[] is ever more than one element long, there will be potential for host mismatches.
if len(hosts) == 0 {
return
}

cachedCert, ok := hostMap.Load(hosts[0])
cacheKey := strings.Join(hosts, ":")
cachedCert, ok := hostMap.Load(cacheKey)

if ok {
cert = cachedCert.(*tls.Certificate)
Expand Down Expand Up @@ -117,9 +114,7 @@ func signHost(ca tls.Certificate, hosts []string) (cert *tls.Certificate, err er
}

// Cache the certificate for later.
for _, h := range hosts {
hostMap.Store(h, tlsCert)
}
hostMap.Store(cacheKey, tlsCert)

return tlsCert, nil
}