Skip to content

Instantly share code, notes, and snippets.

@tmthrgd
Created May 27, 2016 12:03
Show Gist options
  • Save tmthrgd/3a30779756011f57b5931788a84d591a to your computer and use it in GitHub Desktop.
Save tmthrgd/3a30779756011f57b5931788a84d591a to your computer and use it in GitHub Desktop.
Create an X509 certificate with local IP addresses in Golang.
/*
template := x509.Certificate{
...
}
*/
addrs, err := net.InterfaceAddrs()
if err != nil {
panic(err)
}
for _, addr := range addrs {
var ip net.IP
switch v := addr.(type) {
case *net.IPNet:
ip = v.IP
case *net.IPAddr:
ip = v.IP
default:
continue
}
template.IPAddresses = append(template.IPAddresses, ip)
template.DNSNames = append(template.DNSNames, ip.String())
}
/*
der, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment