Let's Encrypt: Difference between revisions

From Leo's Notes
This page was last edited on 23 February 2016, at 22:27.
apache
cleaned up content
Line 2: Line 2:


== Getting Certificates ==
== Getting Certificates ==
Use the {{code|letsencrypt-auto}} script to interface with Let's Encrypt.
To get signed certificates from Let's Encrypt, you will need to use either:
# Let's Encrypt's supported auto client (requires sudo)
# letsencrypt-nosudo (no sudo, works for shared hosting)


To generate a certificate, turn off any servers on port 80 and then run:
The steps for each of the packages above will be described below.
{{highlight|lang=bash|code=
 
./letsencrypt-auto certonly
=== 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:
 
{{highlight|lang=terminal|code=
$ 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.
 
{{highlight|lang=terminal|code=
$ git clone https://github.com/diafygi/letsencrypt-nosudo
$ cd letsencrypt-nosudo
}}
}}


Once generated, you may use the new certificates.
I will do all the work inside a {{code|keys}} directory.
 
If this is the first time you are using Let's Encrypt, generate your user keys.
 
{{highlight|lang=terminal|code=
$ mkdir keys
$ cd keys
$ openssl genrsa 4096 > user.key
$ openssl rsa -in user.key -pubout > user.pub
}}


=== Apache ===
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.
To manually configure apache for a virtual host, set:
 
{{highlight|lang=terminal|code=
$ 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 {{code|sign_csr.py}} script. Since we do not want to run anything as root, we will have to use the file based challenge (option {{code|-f}}) instead as the other (default) option requires running a server on port 80.


{{highlight|lang=text|code=
{{highlight|lang=terminal|code=
SSLCertificateFile /etc/letsencrypt/live/domain/cert.pem
$ python ../sign_csr.py -f --public-key user.pub leo.leung.xyz.csr > signed.crt
  SSLCertificateKeyFile /etc/letsencrypt/live/domain/privkey.pem
SSLCACertificateFile /etc/letsencrypt/live/domain/chain.pem
}}
}}


== Running Without Root ==
Follow the instructions that the script provides you with in order to satisfy Let's Encrypt's challenges.
You may try to use the letsencrypt-nosudo project at https://github.com/diafygi/letsencrypt-nosudo.  


I was '''not able to get it working''' since the API kept on returning a 400 error:
{{highlight|lang=terminal|code=
## 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
}}


{{highlight|lang=text|code=
Once all that is done, you should now have the following files:
{"type":"urn:acme:error:malformed","detail":"Unable to read/verify body :: JWS verification error","status":400}
# {{code|domain.key}} - your domain's private key
# {{code|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:
{{highlight|lang=terminal|code=
$ wget https://letsencrypt.org/certs/lets-encrypt-x1-cross-signed.pem
$ cat signed.crt lets-encrypt-x1-cross-signed.pem > chained.pem
}}
}}


This lead me to cheat. (see below)
== Installing the Certificates ==


== Getting Certificates for cPanel ==
=== Apache ===
Because I do not want to run the {{code|letsencrypt-auto}} script as root on my cPanel account (and this applies to all shared hosting accounts too), I decided to run it inside a VM at home instead and then copy the certificate to the cPanel account. For this to work, I temporarily updated my DNS record to point to my home IP address before running {{code|letsencrypt-auto}}. Once the challenges passes and the certificate is signed, I reverted my DNS to point back to my cPanel server.
To manually configure apache for a virtual host, set:


While this still exposes the private keys to their script, I was able to get around needing root access on the cPanel server.
{{highlight|lang=text|code=
SSLCertificateFile /etc/letsencrypt/live/domain/signed.crt
SSLCertificateKeyFile /etc/letsencrypt/live/domain/domain.key
SSLCACertificateFile /etc/letsencrypt/live/domain/chain.pem
}}


Let's encrypt will then place the certificates at {{code|/etc/letsencrypt/archive/$DOMAIN$/}}, but should be referenced from the 'live' directory at {{code|/etc/letsencrypt/live/$DOMAIN$/}}. 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:
=== 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:


# Certificate: (CRT) -> {{code|privkey.pem}}
# Certificate: (CRT) -> {{code|privkey.pem}}
Line 45: Line 101:


== Renewing ==
== Renewing ==
Let's Encrypt's certificates are only valid for 90 days and requires constant renewal. Possible solutions to automate this are:
Let's Encrypt's certificates are only valid for 90 days and requires constant renewal.
# Custom DNS zone for let's encrypt so they always see my domains from my home.
# ???
 


[[Category:Linux]]
[[Category:Linux]]

Revision as of 22:27, 23 February 2016

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.