Objectives to the accomplished
- First I will be getting and installing a new cert for use on pad.byjuho.fi which will host an Etherpad instance to fulfill my secure textual collaboration needs safely.
- Second I will be replacing the shortly expiring commercial certificate for *.consumium.org. So far I know that I can have the old cert still in place and insert the new certs under a subjectAltName. This way the free social media that I host can continue operating normally (hopefully) without any downtime.
How I did it
The definitive instructions from readthedocs.io I found only sometime after starting this were very helpful as they almost always are.
https://letsencrypt.org/getting-started/ recommends using
CertBot from Electronic Frontier Foundation to automate the installation of LetsEncrypt certificates so I’m doing that.
CertBot takes as arguments your web server and operating system and provides instructions customized by those.
ByJuho.fi is being served by an Apache2.4 on a Debian8.5 so I chose those.
CertBot points to instructions for enabling backports on my system. Which I promptly followed successfully.
Then you naturally need to
sudo apt-get update
before the backports start to work.
sudo apt-get install python-certbot-apache -t jessie-backport
Runs fine and installs a bunch of python candy
Next I ran
sudo certbot --apache
as instructed by CertBot interactive website. That complained that it did not find any ‘ServerName’s in the configuration files which is slightly strange. When answering ‘no’ to the “Do you want to proceed?” question it exited and hinted to specify domain name with the ‘–domains’ switch
sudo certbot --apache --domains byjuho.fi
A blue screen comes up that asks for the “emergency” email address. Put one that you will never lose like an https://iki.fi address which I’ve used for over 20 yrs now and which is valid for a lifetime.
Next the blue screen asks if you want to have all traffic redirected to TLS encrypted. I chose to allow normal http too.
Program exits and gives good advice to check the installed cert with the awesome free test tool by SSLLabs so I proceeded to do so. Certbot apparently knows its stuff since the site got an ‘A’ rating for the things SSL.
Automating renewal of certificates
LetsEncrypt.org certificates are valid only for 90 days. Probably due to meticulous planning and execution to maximize security so we want to automate the renewal.
Now CertBot site instructs to test automatic renewal arrangement by issuing command
sudo certbot renew --dry-run
and it reports that everything seems to be in order to automate the renewal so I proceeded to do so with
and inserted instructions to run on quiet the renewal script twice a day 12-hours apart. The command to be run is given as
certbot renew --quiet
But that will fail unless run with sudo because it cannot access certain files so you need to set the cronjob as superuser. Type
give password and then run
(See here for practical examples of crontab entry syntax). Exit super user account with ctrl-d and you are done automating the renewal of the certs.
The encrypted URL now leads to the default Apache2 on Debian landing page “It works.. blahblahblah…” so I need to make a new VirtualHost directive for the encrypted site in /etc/apache2/sites-enabled/001-hosts which is where I keep the directives.
So I need to figure where the CertBot put the certificate and the key.
CertBot puts the very secret key and the very public certificate in
‘/etc/letsencrypt/live/domain.tld’ and the automagic from the blue screen creates a VirtualHost entry in ‘/etc/apache2/sites-enabled/000-default-le-ssl.conf’. After I made a normal VirtualHost entry in ‘/etc/apache2/sites-enabled/001-sites.conf’ and commented everything out in the 000-default-le-ssl.conf this blog is now available also in TLS protected https://ByJuho.fi.
Friendly folks at #freenode pointed out that
sudo apachectl -S
is very useful for locating problem points regarding conflicting VirtualHost directives
Next I am going to figure out if the commenting out stuff from 000-default-le-ssl.conf has any adverse effects. It seems the files with lower prefixed number takes precedence.
Next I try to replicate the necessary steps described in this blog post to actually enable https://pad.byjuho.fi
All that was needed to bring up the default Debian/Apache “it works page” over TLS encrypted https was one run of
sudo certbot --apache --domains pad.byjuho.fi
and fix the VirtualHost directive to your liking to actually serve your content.
Getting new certs with nginx.
There doesn’t seem to be quite the same level of automation with Nginx hosted sites than the Apache ones.
sudo certbot certonly --webroot -d d.consumium.org --webroot-path /var/www/diaspora
Is what I used to successfully get the new certificates in place.