I'm working with OpenSSL and need a sane default list of CAs. I'm using Mozilla's list of trusted CAs, as bundled by cURL. However, I need to split this bundle of CA certs, because the OpenSSL documentation says:
If CApath is not NULL, it points to a directory containing CA certificates in PEM format. The files each contain one CA certificate. The files are looked up by the CA subject name hash value, which must hence be available.
For example, using the ca-bundle.crt
file directly works fine:
openssl-1.0.1g> ./apps/openssl s_client -connect www.google.com:443 -CAfile /home/user/certs/ca-bundle.crt
...
Verify return code: 0 (ok)
---
DONE
But specifying the directory containing the ca-bundle.crt
file does not work:
openssl-1.0.1g> ./apps/openssl s_client -connect www.google.com:443 -CApath /opt/aspera/certs
Verify return code: 20 (unable to get local issuer certificate)
---
DONE
I presume this is because my folder doesn't adhere to what the documentation asks for (namely, a directory containing CA certs in PEM format, with each file containing one cert, named by hash value). My directory just has the single bundle of certs.
How can I split my bundle of certs to adhere to OpenSSL's request that each cert be in an individual file? Bonus points if the hashing can be done too (though if needed I could write a script to do that myself if all the certs are in individual files).
Just to give an alternative; facing the same issue I ended up with csplit:
If you want to get a single certificate out of a multi-certificate PEM, try:
source
Here is mine in Perl (so much code, but I like gonzo programming):
You can split the bundle with
awk
, like this, in an appropriate directory:Then, create the links OpenSSL wants by running the
c_rehash
utility that comes with OpenSSL:Note: use 'gawk' on non linux-platforms - as above relies on a GNU specific feature.
The following Ruby-script will split the bundle (with one or more certificates in it) into files named after the hashes -- side-stepping the
c_rehash
step in most cases.To use,
cd
into the right directory (such as/etc/ssl/certs/
) and run the script with the path to your certificate bundle as the sole argument. For example:ruby /tmp/split-certificates.rb ca-root-nss.crt
.