mirror of
https://git.sr.ht/~adnano/go-gemini
synced 2024-11-23 16:52:06 +01:00
Handle multiple DNS names
Each DNS name gets its own entry in the known hosts file
This commit is contained in:
parent
d7717577ea
commit
f38da56732
19
tofu.go
19
tofu.go
@ -61,11 +61,14 @@ func (k *KnownHosts) LoadFrom(path string) error {
|
|||||||
// Add adds a certificate to the list of known hosts.
|
// Add adds a certificate to the list of known hosts.
|
||||||
// If KnownHosts was loaded from a file, Add will append to the file.
|
// If KnownHosts was loaded from a file, Add will append to the file.
|
||||||
func (k *KnownHosts) Add(cert *x509.Certificate) {
|
func (k *KnownHosts) Add(cert *x509.Certificate) {
|
||||||
host := NewKnownHost(cert)
|
// Add an entry per hostname
|
||||||
k.hosts = append(k.hosts, host)
|
for _, name := range cert.DNSNames {
|
||||||
// Append to the file
|
host := NewKnownHost(name, cert)
|
||||||
if k.file != nil {
|
k.hosts = append(k.hosts, host)
|
||||||
host.Write(k.file)
|
// Append to the file
|
||||||
|
if k.file != nil {
|
||||||
|
host.Write(k.file)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,10 +143,10 @@ type KnownHost struct {
|
|||||||
Expires int64 // unix time of certificate notAfter date
|
Expires int64 // unix time of certificate notAfter date
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewKnownHost creates a new known host from a certificate.
|
// NewKnownHost creates a new known host from a hostname and a certificate.
|
||||||
func NewKnownHost(cert *x509.Certificate) KnownHost {
|
func NewKnownHost(hostname string, cert *x509.Certificate) KnownHost {
|
||||||
return KnownHost{
|
return KnownHost{
|
||||||
Hostname: cert.Subject.CommonName,
|
Hostname: hostname,
|
||||||
Algorithm: "SHA-512",
|
Algorithm: "SHA-512",
|
||||||
Fingerprint: Fingerprint(cert),
|
Fingerprint: Fingerprint(cert),
|
||||||
Expires: cert.NotAfter.Unix(),
|
Expires: cert.NotAfter.Unix(),
|
||||||
|
Loading…
Reference in New Issue
Block a user