I have a pkcs7 file that contains a concatenation of 3 certificates in this order: Leaf certificate -> Intermediate CA -> Root CA.
I am trying to write a go program that loads the certificate from the leaf certificate and takes the public key and the signature and my method does not work. Do you have any other suggestions of how i could do this? Am I doing something wrong?
Here is what I am trying to do:
b, err := ioutil.ReadFile(certificate_path)
block, _ := pem.Decode(b)
if block == nil {
panic("failed to parse certificate")
}
// get pkcs7 certificate
_, err = pkcs7.Parse(b)
if err != nil {
panic("failed to parse certificate in pkcs7 format: " + err.Error())
}
This fails with the following error:
panic: failed to parse certificate in pkcs7 format: ber2der: BER tag length is more than available data
Does anyone have any idea how cand i parse certificate from a pkcs7 file in go? And then how take the key and the signature?