Trusting a self-signed certificate
12 Oct 2018When working in development and sandboxes, it can make sense to trust the self-signed certificates that you might be using. This can lower the amount of workflow noise that you might endure.
In today’s article, I’ll take you through generating a certificate; using the certificate (its use-case is terribly simple), and finally trusting the certificate.
Generation
In a previous post titled “Working with OpenSSL”, I took you through a few different utilities available to you within the OpenSSL suite. One of the sections was on generating your own self-signed certificate.
You should receive output which looks like the following:
On the filesystem now you should have a server.key
and server.cer
files waiting for you.
Using the certificate
Now we’re going to stand up a web server that uses this key/certificate pair. Using the nginx docker image, we can quickly get this moving with the following nginx.conf
.
Starting the server requires the cerificate, key and configuration file to be mounted in. I’ve also exposed 443 here.
Right now, when we use the curl
command without the --insecure
switch, we receive the following:
Trusting the certificate
We can now use cerutil to work with the NSS database to add this certificate.
If you’re on a brand new system, you may need to create your NSS database. This can be done with the following instructions. Please note, that I’m not using a password to secure the database here.
With a database created, you can now add the actual certificate itself. You can acquire the certificate with the following script (that uses OpenSSL):
This script is doing a little bit; but most important to see that openssl
acquires the certificate for us; then we issue a call to certutil
to add the certificate into our store.
Chrome will look for the nss database in $HOME/.pki/nssdb
. This is why this folder has been chosen. The -t
switch allows you to specify trustargs
. Lifted from the manpage:
The trust settings are applied as a combination of these characters, in a series of three.
There are three available trust categories for each certificate, expressed in the order SSL, email, object signing for each trust setting.
With the certificate added into the store, we can re-start chrome and hit our website. Chrome no longer complains about the certificate not being trusted.