(sorry for resurrecting a zombie post...)
I'm in the same boat as mcel - what I'd like to do add a new root CA inside of a single Golang process - *not* install it on the OS. Then I'd like to have a connection work with either my new, internal-to-the-process CA, or some other well known system CA. I can get halfway there with
const specialRoot = `
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----`
roots := x509.NewCertPool()
ok := roots.AppendCertsFromPEM([]byte(specialRoot))
if !ok {
panic("failed to parse root certificate")
}
// Here example.com *must* use my special root cert, or the connection fails. RootCAs: roots,
})
However, I don't know if
example.com above will use the specialRoot cert or some other system root. What I'd really like to do is
roots := x509.NewCertPool()
roots.AppendAllFromPool(systemRootsPool) // <<-- NOT REAL GO
ok := roots.AppendCertsFromPEM([]byte(specialRoot))
// Now example.com can either use a cert from the OS, *or* my special cert RootCAs: roots,
})
Is there more correct way of doing that? Or is there something particularly wrongheaded about wanting to do it in the first place?