执行:加载证书,使其成为* x509.Certificate(可以对其他证书进行签名)

I've asked in golang-nuts but no response

https://groups.google.com/forum/#!topic/golang-nuts/EhlpMiMAPSM

I don't think duplicating the mail bodies would make much sense, since I don't believe Google groups or the link will change, the first email's body should suffice.

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

How do I load a certificate so I can use it to sign other certificates as a *x509.Certificate type?

There's probably something obvious I'm missing, but what is it?

The answer is: The way it's done in the question is the correct way.

The problem or bug remains in the certificate creation, so in the scope of the question "how to load a certificate" the question is answered.