Making a self-signed TLS certificate

Sending data over the internet unencrypted means anybody with the right tools can see this data. Making a certificate means that you can then encrypt the data. This means that the data is no longer readable to anybody that doesn't have your certificate. This guide will show you how to make a certificate authority, sign and make an TLS certificate ready to be used by your web server.

Due to the way the encryption landscape has changed on the internet, we will be creating a ECDSA certificate. EC stands for Elliptic Curve and uses prime number curves which allow smaller key sizes for the same amount or better protection than the larger traditional key sizes. As of TLS 1.3, ECDSA is the only supported key exchange method and is now widely supported so is highly recommended over RSA.

SSL is now deprecated and disabled on most modern browsers and servers. There are lists of vulnerability in everything but the latest TLS versions. Recommended versions are TLS v1.2 (now widely supported) and TLS v1.3 (Newer and more secure, support is gaining way. Supported on =>openSUSE Leap 15.2). We refer to SSL as TLS as this protocol replaced SSL and is supported by most browsers and is now what is used by default.

We used to use self-signed certificates on the server as it was not cost effective to buy an TLS certificate each year on the server. Let's Encrypt allow us to make fully trusted certificates for our domain using a small script program called acme.sh which we now use as it more than fulfils our needs. We use acme.sh as it allows us to create ECC certificates which Let's Encrypt certbot would not allow us to do. A limitation is that certificates only last 3 months, but this is for security.

Creating a signed certificate with Let's Encrypt and acme.sh

TBD

Creating a self-signed certificate

What you need to know

  • You will be making a self-signed certificate. All browsers through up an error. This is OK and can usually be avoided in the future by using an exception.
  • To make it easier, it is suggested to make all the certificates in a dedicated folder somewhere that you have easy access to, for example in your home folder. This will avoid permission problems.
  • If your making a certificate with a private key without a password, the resulting certificate must be kept in a safe place. If this private key is EVER disclosed, anyone can use your certificate and pose as you. The newest versions of Apache only allow www and root users to read the key folder by default. If the private key is believed to be compromised, you should immediately revoke affected certificates and generate new certificates with a new private key.
  • Many of the fields when making a certificate authority or server certificate are dated. The ones marked (OPTIONAL) don't have to be filled in.

Create an elliptic curve private key

  • Open a terminal window.
  • Type the following into the terminal:
 # openssl ecparam -genkey -name prime384v1 -out key.pem
  • NOTE: This is the private key that must be kept safe. If anyone gets hold of this, they will be able to decrypt your data.

Creating a Certificate Signing Request (CSR)

A certificate signing request combines the private key and some information to fill out the certificate with and makes a public key out of this information. Type the following into the terminal:

 openssl req -new -key key.pem -out csr.pem

You will be presented with some options to fill out:

  • Type in a Country code when asked (GB for England).
  • Type in a State or Provence (or County in England) when asked. (OPTIONAL)
  • Type in a Locality (a town or city) when asked. (OPTIONAL)
  • Type in an Organisation name (or company name) when asked. If left blank, it will be filled with 'Internet Widgets Pty.'. (OPTIONAL)
  • Type in an Organisation unit (or department within company) when asked. (OPTIONAL)
  • Type in a Common name when asked. This is is usually a FQDN, but can be what you usually how you access the page by (IP address, hostname, or FQDN).
  • Type in an e-mail address when asked. This is the e-mail address people will contact you on if there is a problem with the certificates. Make sure you type an address you would access often enough.
  • Type a challenge password (this will stop the private key being accessible, but is not required. If going for simplicity, don't type a password). (OPTIONAL)
  • Type an optional company name (this is an extra attribute and isn't required). (OPTIONAL)

As a side note, a challenge password can be used while the certificate is in storage and stripped off when used for the server for security.

Creating the certificate

With the private key and the certificate signing request we made earlier, we can now make the certificate. Type the following into the terminal:

openssl req -x509 -days 365 -rand /dev/random -key key.pem -in csr.pem -out cert.pem
  • If that command blocks and takes too long, try using urandom instead of random. It may be worth the wait as /dev/random is considered to have better random data but may take a long time to gather enough random data to be useful.
  • No more than a year (365 years) validity is recommended as browsers are starting to not accept any certificates issued recently that have more than a year validity. This does not affect older certificates already issued.

Securing Apache the with certificate created

See the following article:

HTTPS/TLS in Apache HTTP Server article

External Links

https://msol.io/blog/tech/create-a-self-signed-ecc-certificate/ - Thanks for the information, your site helped us change over to ECDSA!