2012/10/25, updated 2013/08/17
If you run your own CA or need to trust certificates issued
by a third party CA whose issuing certificate(s) are not
included in the Ubuntu distribution at /etc/ssl/certs
then you may need to trust them by adding them to your system.
Briefly (more detail on each of these steps below):
Certificates are generally delivered in one of two formats:
PEM (ASCII, originally described in the Privacy
Enhanced Mail RFCs
1421,
1422,
1423,
1424) and DER
(binary, defined in the ITU's X.690
Distinguished Encoding Rules). You need PEM. Translate
binary cert.crt
→ ASCII cert.pem
as follows:
alice@ubuntu:~$ cd /tmp alice@ubuntu:/tmp$ openssl x509 -in cert.crt -inform DER \ -out cert.pem -outform PEM
Ubuntu has a directory for local trusted CA certificates:
/usr/local/share/ca-certificates
. Copy your PEM file into this directory
(any filename that you choose). The file should be owned by root:root
and with mode 644 (rw-r--r--
). Clearly you don't want this file (or
indeed directory) to be writable by anyone other than root
. Oh, and
you should be really sure that you do trust the certificate that you're
about to add.
alice@ubuntu:~$ cd /usr/local/share/ca-certificates/ alice@ubuntu:/usr/local/share/ca-certificates$ sudo cp /tmp/cert.pem . alice@ubuntu:/usr/local/share/ca-certificates$ sudo chown root:root cert.pem alice@ubuntu:/usr/local/share/ca-certificates$ sudo chmod 0644 cert.pem
(You should probably choose a better name than cert
).
For fast location of a specific certificate on the file system
a long-standing OpenSSL mechanism creates symlinks named after the
subject hash to the actual friendly-named
version. (The hash filenames are postfixed with an integer extension
in case you happen to have two certificates with the same subject hash,
for example if a certificate has been renewed). You can generate these
links using c_rehash
from OpenSSL:
alice@ubuntu:/usr/local/share/ca-certificates$ sudo c_rehash .
Some software does not know about /usr/local/share/ca-certificates
so
requires a link from the system store in /etc/ssl/certs
.
alice@ubuntu:~$ cd /etc/ssl/certs alice@ubuntu:/etc/ssl/certs$ sudo ln -s /usr/local/share/ca-certificates/cert.pem alice@ubuntu:/etc/ssl/certs$ sudo c_rehash .
The symbolic link nicely documents "this certificate is not part of the base install".
The JRE stores trusted CA certificates under lib/security/cacerts
(similarly for the JDK this is in jre/lib/security/cacerts
). You
can add certificates to the store using the keytool
utility shipped
with your JRE.
alice@ubuntu:/tmp$ sudo keytool -import -trustcacerts -file cert.pem \ -alias "New CA certificate" \ -keystore /opt/jdk1.7.0/jre/lib/security/cacerts
If you're using rvm
to manage your ruby environment along with
a rvm-local OpenSSL package then this won't pick up certificates
added to your sytem CA certificate store. The trusted certifcate
store for rvm is at $rvm_path/usr/ssl/certs
. Replace
/usr/local/share/ca-certificates
in the instructions above with
this path: install the certificate at this second location and re-run
c_rehash
.
c_rehash
recreates all fingerprint symbolic links in
the given directory (.
).unsigned long
and then converts it into a hex string. Under the covers c_rehash
calls openssl x509 -subject_hash_old
.unsigned long
and then converts it
into a hex string. Under the covers c_rehash
calls openssl x509
-subject_hash
.update-ca-certificates(8)
. This can be used to
refresh/update the CA certificates contained in /etc/ssl/certs
. I don't
like this approach since I like to separate certificates shipped with
the system (/etc/ssl/certs
) from certificates that I have subsequently
added (/usr/local/share/ca-certificates
).