Skip to content
Hogin Hogin
Go back

SSL Certificates Made Simple

Updated:
3 мин чтения

SSL certificates play a key role in keeping websites secure. X.509 is an ITU standard that defines the format of public-key certificates, which are used in TLS/SSL and form the foundation of HTTPS. An X.509 certificate binds an identity to a public key by means of a digital signature. Such a certificate contains identity information (hostname, organization, etc.) and a public key (RSA, DSA, ECDSA, ed25519, and others). A certificate can be signed by a Certificate Authority or be self-signed.

Self-Signed Certificates

Creating a CA

  1. Generate an RSA key:
openssl genrsa -aes256 -out ca-key.pem 4096
  1. Generate the CA’s public certificate:
openssl req -new -x509 -sha256 -days 365 -key ca-key.pem -out ca.pem

Optional Step: Inspecting the Certificate’s Contents

To check the information contained in the certificate, you can use the following commands:

openssl x509 -in ca.pem -text
openssl x509 -in ca.pem -purpose -noout -text

Generating a Certificate

  1. Create an RSA key:
openssl genrsa -out cert-key.pem 4096
  1. Create a Certificate Signing Request (CSR):
openssl req -new -sha256 -subj "/CN=yourcn" -key cert-key.pem -out cert.csr
  1. Create an extfile with all the subject alternative names:
echo "subjectAltName=DNS:your-dns.record,IP:257.10.10.1" >> extfile.cnf
# optional
echo extendedKeyUsage = serverAuth >> extfile.cnf
  1. Create the certificate:
openssl x509 -req -sha256 -days 365 -in cert.csr -CA ca.pem -CAkey ca-key.pem -out cert.pem -extfile extfile.cnf -CAcreateserial

Certificate Formats

X.509 certificates exist in the Base64 formats PEM (.pem, .crt, .ca-bundle), PKCS#7 (.p7b, .p7s), and the binary formats DER (.der, .cer), PKCS#12 (.pfx, .p12).

Converting Certificates

COMMANDCONVERSION
openssl x509 -outform der -in cert.pem -out cert.derPEM to DER
openssl x509 -inform der -in cert.der -out cert.pemDER to PEM
openssl pkcs12 -in cert.pfx -out cert.pem -nodesPFX to PEM

Verifying Certificates

You can verify a certificate’s validity with the following command:

openssl verify -CAfile ca.pem -verbose cert.pem

Installing the CA Certificate as a Trusted Root CA

On Debian and Its Derivatives

sudo update-ca-certificates

See the documentation here and here.

On Fedora

update-ca-trust

See the documentation here.

On Arch

System level – Arch (p11-kit)

  1. Run (as root):
trust anchor --store myCA.crt
  1. The certificate will be written to /etc/ca-certificates/trust-source/myCA.p11-kit, and the “legacy” directories will be updated automatically.
  2. If you get a “no configured writable location” error or similar, import the certificate manually:
    • Copy the certificate into the /etc/ca-certificates/trust-source/anchors directory.
  3. Then run:
update-ca-trust

The wiki page is here.

On Windows

Assume the path to your generated CA certificate is C:\ca.pem. Run:

Import-Certificate -FilePath "C:\ca.pem" -CertStoreLocation Cert:\LocalMachine\Root

OR

At the command line, run:

certutil.exe -addstore root C:\ca.pem
openssl pkcs12 -export -out rds_cert.pfx -inkey ca.key -in ca.pem

This process converts your certificate to the PKCS#12 (PFX) format, which can be used for various purposes.

On Android

The exact steps may vary depending on the device, but here is a generalized guide:

  1. Open your phone’s settings.
  2. Find the Encryption & credentials section. It’s usually located under Settings > Security > Encryption & credentials.
  3. Select Install a certificate.
  4. Select CA certificate.
  5. Find the ca.pem certificate file on your SD card / internal storage using a file manager.
  6. Select it to load.
  7. Done!

Share this post:

Previous Post
Proper, Secure SSH Configuration