SSL and Certificate Authorities

Written by dkg and jrollins.

Creating a certificate authority

Create a new root certificate authority (CA). You do this by generating a private key for the CA, and creating a self-signed certificate from that key. We'll call these two pieces the 'CA-key' and the 'CA-cert'. They are generated on a machine we'll call the CA-host. If you can have a dedicated machine as CA-host, that would be great.

ca-host$ mkdir -p /path/to/your.domain.org-CA/{private,certs}
ca-host$ cd /path/to/your.domain.org-CA
ca-host$ openssl req -new -x509 -keyout private/cakey.pem -out cacert.pem -days 3652
ca-host$ openssl x509 -in cacert.pem -out cacert.crt

The CA-key never leaves CA-host. CA-key should be chmod 0400. it's best if CA-host is off-net itself, so data can only be transferred via physical media.

Distribute the CA-cert freely, and make sure that all your client machines know about it and trust it to identify hosts and users.

Setting up new SSL services

Say you want to set up a new service using SSL on some host we'll call 'service-host'. On service-host, generate a new key and a certificate request (this is *not* a certificate). When you generate the key and the cert-req, make sure that you use the fully-qualified domain name (FQDN) for the Common Name field. The FQDN is the hostname that other machines will use to access this host for the given service. We'll call these two pieces 'service-key' and 'service-req'.

service-host$ openssl req -nodes -days 365 -new -keyout service-host_service_key.pem -out service-host_service_req.pem

The service-key never leaves service-host. It should be readable only as root, or if the service runs as a separate user without starting as root and then dropping privileges, service-key should be readable only as that user.

The service-req can be distributed freely. It isn't useful, however, until it's signed by some CA which your clients trust. So hand it off to CA-host.

On CA-host, sign service-req with CA-key. This generates a certificate which we'll call 'service-cert'.

ca-host$ openssl ca -in service-host_service_req.pem -out service-host_service_cert.pem

Service-cert can be distributed freely. It's not useful for initiating SSL connections, however, unless you also control service-key. So put a copy of it back on service-host, and point your software to it.

Clients who trust your CA (because they have a copy of CA-cert which they trust) can now securely connect to service-host smoothly, without any SSL errors.

The process outlined in this section can be repeated for each new service-host.

Observations

Other useful commands

ca-host$ openssl x509 -noout -fingerprint 

External Links

openssl certificate doc


Last modified: Mon Feb 19 18:02:27 EST 2007