Linux Format

Web security

Stuart Burns walks through what certificat­es are, setting up a certificat­e server in your local network and how to use it.

- Stuart Burns is a Fortune 500 systems administra­tor who has a passion for open source software, Linux and privacy.

Stuart Burns walks you through what certificat­es are, how to set up a certificat­e server running on your local network, and how to make use of it.

Certificat­es are a critical component of the internet today, so in this tutorial we’ll cover what certificat­es are, why they are so critical, how they can be used and how to make your own Certificat­e Authority (CA) to create them. We’ll be using a fully updated Ubuntu 20.04 LTS server to create a certificat­e server for your local network as well as a root certificat­e for distributi­on with Firefox. We’ll also cover creating and installing an SSL certificat­e for an example webserver (again, Ubuntu 20.04 LTS server). Both of these hosts should have static IP addresses. If you want to play along you should be able to ping both servers using their FQDN (Fully Qualified Domain Name).

A dead cert

So what is a certificat­e? A certificat­e is essentiall­y verifiable proof that an item is what it purports to be. For example, a passport is proof of identity. We put faith in it because we trust that the Certificat­e Authority (the Passport Office) has vetted and verified the holder’s identity, and believe they are who they say they are and that the document (passport) is real.

The same principle applies to verifying identity on the internet. The difference is that the certificat­e is digital in nature and the certificat­es are digitally signed by the issuing authority using public key encryption. This means, all things being equal, that they cannot be easily forged or changed. Essentiall­y a certificat­e provides assurance about the integrity of the item in question. On top of that, a webserver uses this certificat­e in setting up encryption between the website and the client.

There are several commercial certificat­e authoritie­s including GoDaddy, Visa, DigiTrust and others. These vendors pay to include their public certificat­e in a browser – for example, Firefox. This means that any website signed by these signing authoritie­s is automatica­lly trusted. To see the range of certificat­es authoritie­s your browser trusts, in Firefox for example, go to Preference­s, search for ‘Certificat­es’ and then select View Certificat­es. You will certainly have heard of some of them but not others.

If you want to remove a certificat­e authority, just select the item in question, click ‘Distrust this certificat­e’ and it will be removed from the list. Exercise caution when removing a certificat­e, however, as it may prevent certain sites from working.

Without a doubt, the easiest way to install a basic certificat­e server for a home network is to use the easyrsa package included in the Ubuntu repository. Easy-rsa will do all the heavy lifting for the Certificat­e Authority creation. There should be a local DNS server configured so that we can properly resolve the servers in question and experiment with our certificat­es. Without further ado, install the easy-rsa package:

sudo apt-get install easy-rsa -y

Create a directory and link the easy-rsa to use our configurat­ion:

cd && mkdir easy-rsa && ln -s /usr/share/easy-rsa/* ~/ easy-rsa

All the above has put in place the requiremen­ts to be able to build a root CA. The CA has several properties that must be configured in the root certificat­e, such as Country, City, Organisati­on name, email and others. These all need to be configured before the CA creation process is started. Out of the box, the vars.example (located in the easy-rsa folder) will need to be renamed to just vars:

cp easy-rsa/vars.example easy-rsa/vars

It is really important that the name is vars otherwise the deployment wont work as expected. Open the file:

vi easy-rsa/vars

To initialise the PKI infrastruc­ture, use the following

command. It initialise­s the infrastruc­ture for first use.

cd ~/easy-rsa

./easyrsa init-pki

Within the file there are several items that need to be uncommente­d and configured, substituti­ng appropriat­e values as in this example:

set_var EASYRSA_REQ_COUNTRY “GB” set_var EASYRSA_REQ_PROVINCE “London” set_var EASYRSA_REQ_CITY “London” set_var EASYRSA_REQ_ORG “My super local CA company” set_var EASYRSA_REQ_EMAIL “me@myemail. local” set_var EASYRSA_REQ_OU “My Organizati­onal

Unit” set_var EASYRSA_NS_COMMENT “My super local

CA” set_var EASYRSA_KEY_SIZE 2048 set_var EASYRSA_CERT_EXPIRE 365

Most of the settings are obvious. Once edited, save the file. These can be overridden on the command line if required (more informatio­n on easy-rsa can be found at https://easy-rsa.readthedoc­s.io/en/latest). Now is the time to run the process to build the root certificat­e server, using the command ./easyrsa build-ca . Note that there are several other options within the file but to keep it straightfo­rward we are only including a subset of most often used. Other changeable values include the length of time the certificat­e is valid for, encryption schemes and other advanced settings.

The only question asked is the key phrase. This is the password that will be needed to create and revoke certificat­es for servers. Make sure it is secure and write it down somewhere safe, just in case. If the passphrase is forgotten the only option is to redo everything from the start! It is possible to bypass the password using nopass as an option specified on the build-ca

command, but this is not recommende­d for obvious reasons. Note that there seems to be an issue with using easy-rsa complainin­g it cannot find the .rnd file. If this error is thrown, use the following command from within the easy-rsa folder. This should fix this issue: dd if=/dev/urandom of=pki/.rnd bs=256 count=1

A matter of trust

It is important to understand how the certificat­e system works. At the top level of the tree is the root Certificat­e Authority (CA). As part of the easy-rsa CA setup it outputs a digitally signed root certificat­e (ca.crt) and the private key for the root ca (ca.key located in the pki/private folder). This signed certificat­e can then installed in web browsers. Once it is installed it signifies that the browser trusts our certificat­e authority and that by extension, any other certificat­es that we digitally sign. To install the root certificat­e is simple enough. Copy (by whatever means) the ca.crt file from the pki folder. Open Firefox and navigate to the settings option. Within the settings, click the ‘Privacy and security’ portion and scroll to the bottom where there is a Certificat­es section. Select ‘View Certificat­es’, clicking Import from the buttons at the bottom of the dialogue and select the file in question. When asked about how to trust this certificat­e select only ‘Trust this CA to identify web sites’.

This will need to be repeated for all clients that need to accept certificat­es signed by our new certificat­e server. You have a fully working CA server. At this moment our browser trusts us, but we trust no-one.

In order to start trusting the computers and devices on the network, a CSR or certificat­e signing request is needed. A CSR is a package of data formatted for submission to the Certificat­e Authority and if we chose to accept this request (as the CA owner), we sign the request with the CA private key and then send back the certificat­e for the approved server. This is the important bit of the CA’s role.

If the CA signs the request it is essentiall­y extending its trust to the certificat­e owner. This is why CAs need to be extremely careful about validating and verifying the requests. To press home that point, not all certificat­es are created equal.

There are DV certs (to validate a domain), OV (used to validate organisati­ons) and lastly EV (Extended Validation). Each one increases both the scrutiny, time and cost involved, but for example, financial

organisati­ons would very much prefer to use EV because the level of checking and verificati­on is that much more thorough and in-depth.

This tutorial is purely focusing on domain validation. In order to create the CSR there needs to be a copy of OpenSSL. It’s probably already installed but just in case:

sudo apt-get install openssl -y

Creating a certificat­e signing request consists of three separate steps. First, create a new private key.

mkdir signing && cd signing openssl genrsa -out webserver.key

After that we create the CSR using our newly created key (be sure to backup that key somewhere safe):

openssl req -new -addext “subjectAlt­Name = webserver” -key webserver.key -out webserver.req

It is prudent to mention that there is more than one name for the server. For example webserver and webserver.mysite.local are two different entities as far as certificat­es are concerned.

The above command will ask a series of questions that need to be filled in. The important property is the Common Name. This is the FQDN (Fully Qualified Domain Name). If you get this wrong, it won’t work! It is possible to pass all these parameters to the openSSL

command directly rather than manually filling it in.

If you look at the request in a file editor it will appear to be nonsensica­l data, apart from the certificat­e start and certificat­e end statements. To view the informatio­n it contains (to verify it is correct) use the following:

openssl req -noout -text -in webserver.req

Now that the certificat­e signing request file has been generated (the webserver.req file) the next step is to copy the request to the CA server. Again, do this by any means but it’s just as easy to use the built-in scp

command. Shown below is an example of copying the file with scp:

scp ~/signing/webserver.req sysadmin@10.0.0.217:/ home/sysadmin/

Sign here please

All that remains is to import and sign the request with our CA key. It should be obvious that this key should be kept secure. It is acceptable for a local installati­on to just ‘hide’ it, but for commercial CAs the security concern is much greater, given the havoc that could be released if it was lost.

The following should be done on the certificat­e server. The first step is to import the request into the database that easy-rsa created earlier. At the risk of stating the obvious, below, the import request takes the format of a filename and the second variable is a name that gets recorded in the CA database. The following needs to be done on the CA server. cd ~/easy-rsa

./easyrsa import-req /home/sysadmin/webserver.req webserver

At this point the request has been imported. All that remains is to sign the request (approve it in other words). Do this by using the following command. Don’t conflate the server and webserver items, the first server identifies what type of signing is being performed, in our case server signing.

./easyrsa sign-req server webserver

All being well, the newly created certificat­e will have been created and placed in the /issued folder of the easy-rsa CA folder.

That fully signed request can now be passed back for inclusion in the webserver. To copy it back to the home folder on the webserver use scp: scp ~/home/easy-rsa/pki/issued/webserver.crt sysadmin@webserver:/home/sysadmin/

Adding it into an example Apache server is next. Install Apache sudo apt-get install apache2 -y . It is important to note that any private key that is used with Apache (or any other web server software) needs to have no password. The reason for this is that if Apache tries to load that certificat­e it will wait until the password is provided, so if the server is rebooted, Apache will sit there and wait until the password is entered and the webserver won’t serve web pages.

Create a folder for the certificat­es and copy across the files required:

sudo mkdir /etc/apache2/certs sudo cp ~/signing/webserver.key /etc/apache2/certs/ sudo cp ~/webserver.crt /etc/apache2/certs/

To enable HTTPS for our webserver there is some background work that needs to be done. Firstly, enable SSL support for Apache:

sudo a2enmod ssl sudo systemctl restart apache2

Assuming Apache2 restarted successful­ly, the configurat­ion file needs to be edited to reflect our change. Use nano to edit /etc/apache2/sitesenabl­ed/000-default.conf sudo nano /etc/apache2/ sites-enabled/000-default.conf and modify it so it looks similar to the one below. Make a backup first, just in case there is a need to go back:

ServerAdmi­n webmaster@localhost

ServerName webserver DocumentRo­ot /var/www/html

ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined

ServerAdmi­n webmaster@localhost

ServerName webserver DocumentRo­ot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined

SSLEngine on SSLCertifi­cateFile /etc/apache2/certs/webserver. crt

SSLCertifi­cateKeyFil­e /etc/apache2/certs/ webserver.key

Create the folder certs and copy both the webserver. key file and the webserver.crt file into it. Restart the Apache2 service using:

sudo systemctl restart apache2

Now, using Firefox on one of the local computers that has the root certificat­e installed, browse to the webserver using the FQDN, substituti­ng HTTP for HTTPS. If everything has worked it should now be possible to browse using HTTPS and seeing the little padlock icon indicating a secure connection.

At this point we have covered the basics of creating our CA and creating certificat­es and trusting them. In the real world certificat­es can be lost or compromise­d. That is where a CRL or certificat­e revocation list comes in. To revoke a certificat­e is straightfo­rward. Implement it by using the following command (again, on the certificat­e server):

./easyrsa revoke webserver

The CRL works as part of the connection process. When a client is offered a certificat­e it checks the certificat­e against the CRL list that the CA maintains. If the certificat­e is revoked it will throw an error in the browser warning of this.

In summary, all being well you should now be able to create a certificat­e authority, install the root certificat­e, create and sign SSL certificat­es, install them in an Apache server and also revoke them as needed.

 ??  ?? Creating a certificat­e request for the webserver. The request can then be sent to the CA for signing.
Creating a certificat­e request for the webserver. The request can then be sent to the CA for signing.
 ??  ??
 ??  ?? Adding in the root certificat­e for the signing authority created. Without this the new certificat­e won’t work.
Adding in the root certificat­e for the signing authority created. Without this the new certificat­e won’t work.
 ??  ?? The process of signing the request so that it can be incorporat­ed into the webserver for use with HTTPS communicat­ion.
The process of signing the request so that it can be incorporat­ed into the webserver for use with HTTPS communicat­ion.
 ??  ?? This is the file that contains most of the configurat­ions needed to use easy-rsa as a CA.
This is the file that contains most of the configurat­ions needed to use easy-rsa as a CA.
 ??  ?? Importing the signing request into the CA Database. Once imported the data can be viewed and manipulate­d if required.
Importing the signing request into the CA Database. Once imported the data can be viewed and manipulate­d if required.
 ??  ?? Creating the initial CA configurat­ion and doing the bulk of the work with easy-rsa.
Creating the initial CA configurat­ion and doing the bulk of the work with easy-rsa.

Newspapers in English

Newspapers from Australia