I have a certificate that was generated with the x509 package, a CA certificate that was signed by another CA certificate that was also generated with the x509 package.
All in 1 go.
open out file
create der with x509.CreateCertificate()
marshall pem with pem.Encode()
the CA certs are valid, also imported in various browsers without complaint
openssl -text also reports parsable
I tried tls.LoadX509KeyPair()
and
func LoadX509KeyPair(certFile, keyFile string) (*x509.Certificate, *rsa.PrivateKey) {
cf, e := ioutil.ReadFile(certFile)
if e != nil {
fmt.Println("cfload:", e.Error())
os.Exit(1)
}
kf, e := ioutil.ReadFile(keyFile)
if e != nil {
fmt.Println("kfload:", e.Error())
os.Exit(1)
}
cpb, cr := pem.Decode(cf)
fmt.Println(string(cr))
kpb, kr := pem.Decode(kf)
fmt.Println(string(kr))
crt, e := x509.ParseCertificate(cpb.Bytes)
if e != nil {
fmt.Println("parsex509:", e.Error())
os.Exit(1)
}
key, e := x509.ParsePKCS1PrivateKey(kpb.Bytes)
if e != nil {
fmt.Println("parsekey:", e.Error())
os.Exit(1)
}
return crt, key
}
however,
parsex509: asn1: syntax error: data truncated
exit status 1
same with this or tls.LoadX509KeyPair()