Skip to content
Snippets Groups Projects
Commit 19a53000 authored by ale's avatar ale
Browse files

Extract names from the certificate instead of storing them along it

There is no need for the extra Names field when we can get it from the
certificate itself.
parent b3ea502d
Branches
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@ import (
"log"
"math/big"
mrand "math/rand"
"strings"
"sync"
"time"
......@@ -31,9 +32,17 @@ var (
)
type Cert struct {
Names []string
Priv []byte
Pub [][]byte
Priv []byte
Pub [][]byte
}
func (c *Cert) Names() (names []string) {
if cert, err := x509.ParseCertificate(c.Pub[0]); err == nil {
for _, dn := range cert.DNSNames {
names = append(names, strings.TrimPrefix(dn, "DNS:"))
}
}
return
}
func (c *Cert) TLSCertificate() (*tls.Certificate, error) {
......@@ -140,8 +149,8 @@ func (m *Manager) shouldRenew() (bool, string) {
defer m.mx.RUnlock()
if time.Now().After(m.renewalDeadline) {
return true, fmt.Sprintf("met renewal deadline %s", m.renewalDeadline.Format(time.Stamp))
} else if !listsEqual(m.cert.Names, m.names) {
return true, fmt.Sprintf("name list changed (actual: %v, desired: %v)", m.cert.Names, m.names)
} else if names := m.cert.Names(); !listsEqual(names, m.names) {
return true, fmt.Sprintf("name list changed (actual: %v, desired: %v)", names, m.names)
}
return false, ""
}
......@@ -287,9 +296,8 @@ func makeSelfSignedCert(names []string) (*Cert, error) {
}
return &Cert{
Names: names,
Pub: [][]byte{derBytes},
Priv: keyBytes,
Pub: [][]byte{derBytes},
Priv: keyBytes,
}, nil
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment