panda's tech note

Let's Encrypt

Let's Encrypt provides free SSL/TLS certificates for your Web services. The valid period of certificates signed by them is shorter than others; 3 months. However, they provide a bot, called certbot for automation.

On Ubuntu 16.04

In the following note, mydomain.example.com is used to denote the domain name (Common Name field in the certificate) to be signed.

Install certbot

Please refer to the official instructions. It will be more helpful.

We first need to install the following required software package.

$ sudo apt install software-properties-common

Then, we add a repository of the certbot Personal Package Archive (PPA) provided by Let's Encrypt. PGP keys will be installed.

$ sudo add-apt-repository ppa:certbot/certbot
This is the PPA for packages prepared by Debian Let's Encrypt Team and backported for Ubuntu(s).
More info: https://launchpad.net/~certbot/+archive/ubuntu/certbot
Press [ENTER] to continue or ctrl-c to cancel adding it

gpg: keyring `/tmp/tmpfetyghdm/secring.gpg' created
gpg: keyring `/tmp/tmpfetyghdm/pubring.gpg' created
gpg: requesting key 75BCA694 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpfetyghdm/trustdb.gpg: trustdb created
gpg: key 75BCA694: public key "Launchpad PPA for certbot" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK

We finally install the certbot by the following commands.

$ sudo apt update
$ sudo apt install python-certbot-apache

Generate a certificate and request for signing for Apache

To generate a certificate and to request for signing it by Let's Encrypt, the following command can be used for Apache. It also automatically configures Apache's configuration files.

$ sudo certbot --apache
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache

Then, we will be asked your email address;

Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): myemail@example.com

and need to agree the terms of service of Let's Encrypt.

Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org

-------------------------------------------------------------------------------
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v01.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: A

We are asked if we share our email address specified above with Electronic Frontier Foundation. Either of Yes or No should be chosen.

-------------------------------------------------------------------------------
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: N

If you have not configure any virtual hosts in your apache configuration, you will be asked to input your domain name. Immediately after inputting your domain, a new certificate is generated and the bot will request to sign it. Apache's configuration files are also changed.

No names were found in your configuration files. Please enter in your domain
name(s) (comma and/or space separated)  (Enter 'c' to cancel): mydomain.example.com
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for mydomain.example.com
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/000-default-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate for mydomain.example.com to VirtualHost /etc/apache2/sites-available/000-default-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/000-default-le-ssl.conf

Then, we will choose if redirecting HTTP access to HTTPS or not.

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/000-default.conf to ssl vhost in /etc/apache2/sites-available/000-default-le-ssf

-------------------------------------------------------------------------------
Congratulations! You have successfully enabled https://mydomain.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=mydomain.example.com
-------------------------------------------------------------------------------

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/mydomain.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/mydomain.example.com/privkey.pem
   Your cert will expire on 2018-05-27. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

The procedure to use the Let's Encrypt certificate with Apache on Ubuntu 16.04 is almost completed. However, you may find the following error in the /var/log/syslog file. This happens when you don't complete the HTTP (not HTTPS) configuration of Apache.

Feb 26 19:23:20 mydomain apache2[1323]:  * Starting Apache httpd web server apache2
Feb 26 19:23:20 mydomain apache2[1323]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message

In such a case, you need to specify ServerName mydomain.example.com in the <VirtualHost *:80> block (e.g., second line) of /etc/apache2/sites-enabled/000-default.conf.

Renew the certificate

$ sudo certbot renew --dry-run