Ensure generated cert contains 127.0.0.1.

This commit is contained in:
Dave Collins 2013-11-19 16:35:00 -06:00
parent d18c34a628
commit 9edf7d44fa

View file

@ -359,6 +359,7 @@ func genKey(key, cert string) error {
}
template.DNSNames = append(template.DNSNames, host, "localhost")
needLocalhost := true
addrs, err := net.InterfaceAddrs()
if err != nil {
return err
@ -366,9 +367,16 @@ func genKey(key, cert string) error {
for _, a := range addrs {
ip, _, err := net.ParseCIDR(a.String())
if err == nil {
if ip.String() == "127.0.0.1" {
needLocalhost = false
}
template.IPAddresses = append(template.IPAddresses, ip)
}
}
if needLocalhost {
localHost := net.ParseIP("127.0.0.1")
template.IPAddresses = append(template.IPAddresses, localHost)
}
derBytes, err := x509.CreateCertificate(rand.Reader, &template,
&template, &priv.PublicKey, priv)