aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2021-03-04 19:26:13 -0500
committerAdnan Maolood <[email protected]>2021-03-04 19:26:13 -0500
commitc9e2af98f3c244604379035730a83e7361d4590b (patch)
tree584d21c6c147c098a6343def6557052d9f933075
parentcertificate.Store: Bump default duration to 250 years (diff)
downloadarchived-go-gemini-c9e2af98f3c244604379035730a83e7361d4590b.tar.xz
archived-go-gemini-c9e2af98f3c244604379035730a83e7361d4590b.zip
Revert "certificate.Store: Allow using '*' in DNSNames"
This reverts commit de0b93a4f6f5df309816a8cf718c8325a1bb619d.
-rw-r--r--certificate/store.go21
1 files changed, 11 insertions, 10 deletions
diff --git a/certificate/store.go b/certificate/store.go
index e39f52b..067dfcc 100644
--- a/certificate/store.go
+++ b/certificate/store.go
@@ -33,9 +33,10 @@ type Store struct {
// The provided scope is suitable for use in a certificate's DNSNames.
CreateCertificate func(scope string) (tls.Certificate, error)
- certs map[string]tls.Certificate
- path string
- mu sync.RWMutex
+ scopes map[string]struct{}
+ certs map[string]tls.Certificate
+ path string
+ mu sync.RWMutex
}
// Register registers the provided scope with the certificate store.
@@ -47,10 +48,10 @@ type Store struct {
func (s *Store) Register(scope string) {
s.mu.Lock()
defer s.mu.Unlock()
- if s.certs == nil {
- s.certs = make(map[string]tls.Certificate)
+ if s.scopes == nil {
+ s.scopes = make(map[string]struct{})
}
- s.certs[scope] = tls.Certificate{}
+ s.scopes[scope] = struct{}{}
}
// Add registers the certificate for the given scope.
@@ -104,24 +105,24 @@ func (s *Store) write(scope string, cert tls.Certificate) error {
// Get is suitable for use in a gemini.Server's GetCertificate field.
func (s *Store) Get(hostname string) (*tls.Certificate, error) {
s.mu.RLock()
- cert, ok := s.certs[hostname]
+ _, ok := s.scopes[hostname]
if !ok {
// Try wildcard
wildcard := strings.SplitN(hostname, ".", 2)
if len(wildcard) == 2 {
hostname = "*." + wildcard[1]
- cert, ok = s.certs[hostname]
+ _, ok = s.scopes[hostname]
}
}
if !ok {
// Try "*"
- hostname = "*"
- cert, ok = s.certs[hostname]
+ _, ok = s.scopes["*"]
}
if !ok {
s.mu.RUnlock()
return nil, errors.New("unrecognized scope")
}
+ cert := s.certs[hostname]
s.mu.RUnlock()
// If the certificate is empty or expired, generate a new one.