Let's Encrypt

From Leo's Notes
Revision as of 22:27, 23 February 2016 by Leo (talk | contribs) (cleaned up content)
This page was last edited on 23 February 2016, at 22:27.

Let's Encrypt is a service that provides free SSL certificates. It verifies a website's server by a series of challenges before signing any certificate requests.

Getting Certificates

To get signed certificates from Let's Encrypt, you will need to use either:

  1. Let's Encrypt's supported auto client (requires sudo)
  2. letsencrypt-nosudo (no sudo, works for shared hosting)

The steps for each of the packages above will be described below.

Let's Encrypt

The supported client from Let's Encrypt requires root access. It can automatically install the certificates for you (which is a bit scary!) depending on the plugins you have enabled.

Get the client from their GitHub repository:

$ git clone https://github.com/letsencrypt/letsencrypt
$ cd letsencrypt
$ ./letsencrypt-auto --help

Read more here: http://letsencrypt.readthedocs.org/en/latest/using.html#webroot

letsencrypt-nosudo

This neat project contains only the essential pieces of code in order to obtain signed certificate. Unlike the official client, this does not require sudo which is great for shared hosting accounts of paranoid sysadmins.

Get the code from their GitHub repository at https://github.com/diafygi/letsencrypt-nosudo.

$ git clone https://github.com/diafygi/letsencrypt-nosudo
$ cd letsencrypt-nosudo

I will do all the work inside a keys directory.

If this is the first time you are using Let's Encrypt, generate your user keys.

$ mkdir keys
$ cd keys
$ openssl genrsa 4096 > user.key
$ openssl rsa -in user.key -pubout > user.pub

Create a private key for your domain if you don't have one already and then generate a certificate signing request with the subject containing the domain name to be signed.

$ openssl genrsa 4096 > domain.key
$ openssl req -new -sha256 -key domain.key -subj "/CN=leo.leung.xyz" > leo.leung.xyz.csr

In a separate window (or screen, or Ctrl+Z out), run the sign_csr.py script. Since we do not want to run anything as root, we will have to use the file based challenge (option -f) instead as the other (default) option requires running a server on port 80.

$ python ../sign_csr.py -f --public-key user.pub  leo.leung.xyz.csr > signed.crt

Follow the instructions that the script provides you with in order to satisfy Let's Encrypt's challenges.

## Step 2?
$ openssl dgst -sha256 -sign user.key -out register_kZt6ne.sig register_XHetUA.json
$ openssl dgst -sha256 -sign user.key -out domain_7w4NCI.sig domain_zrVWwn.json
$ openssl dgst -sha256 -sign user.key -out cert_LTLknJ.sig cert_cFr76L.json
## Step 3?
$ openssl dgst -sha256 -sign user.key -out challenge_2Hk1Dk.sig challenge_rVYWdK.json
## Step 4
## You will need to place the challenge file and response to a file served by your domain.
$ mkdir -p ~/public_html/.well-known/acme-challenge/
$ echo "" > ~/public_html/.well-known/acme-challenge/b9dITAlwo94hzwIiSHvR7wPclNpWHIJG5YnNHP4UvoM

Once all that is done, you should now have the following files:

  1. domain.key - your domain's private key
  2. signed.crt - your domain's signed certificate

You may want to create chained certificate in case some browsers are unable to verify the deep chain of trust like so:

$ wget https://letsencrypt.org/certs/lets-encrypt-x1-cross-signed.pem
$ cat signed.crt lets-encrypt-x1-cross-signed.pem > chained.pem

Installing the Certificates

Apache

To manually configure apache for a virtual host, set:

SSLCertificateFile /etc/letsencrypt/live/domain/signed.crt
 SSLCertificateKeyFile /etc/letsencrypt/live/domain/domain.key
 SSLCACertificateFile /etc/letsencrypt/live/domain/chain.pem

cPanel

To get your certificate working with cPanel, log in to cPanel, click on 'Install an SSL Website', then fill the following fields with their respective file contents:

  1. Certificate: (CRT) -> privkey.pem
  2. Private Key (KEY) -> cert.pem
  3. Certificate Authority Bundle: (CABUNDLE) -> chain.pem

cPanel should take care of the rest once the SSL certificates are installed.

Renewing

Let's Encrypt's certificates are only valid for 90 days and requires constant renewal.