Created
May 27, 2016 12:03
-
-
Save tmthrgd/3a30779756011f57b5931788a84d591a to your computer and use it in GitHub Desktop.
Create an X509 certificate with local IP addresses in Golang.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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