Easy to use, this script allows you to generate self-signed certificates that can be trusted thanks to the CA. This is entirely offline, no certificate authority is required.
The script generate_certificate.sh
will generate a private key (or use an existing one) and
allows you to generate trusted self-signed certificates for your home or company network.
This script is a wrapper around the openssl
command.
It allows anyone to generate a RootCA, and issue certificates for home
servers to be trusted.
It is a very painful process to do manually, where you very often endup with a certificate which look valid but is reported invalid for some obscure reasons. This script automatize this process and provide you with valid certificates, perfect for any local server such as Home Assistant, Pi-Hole, Proxmox, Local GitLab, etc.
Warning
You will need to trust the Root CA on every client that will be connecting. This is easy to do at home or in small company network. However the certificates will not work for an online service.
Find more informations below.
USAGE: generate_certificate.sh [-h] [-f] [-C <cert>] [-K <key>]
Options:
-h Display help
-f Force overwrite certificate if it exists
-K <key> Use <key> as CA private key
-C <cert> Use <cert> as CA public certificate
-d <days> Set new certificate life duration to <days>
Note
It is better to use-C
and-K
together as a private key should always be linked with its public key.
If the public key is not mentionned it will be re-generated. If the private key is not mentionned, both keys will be regenerated.
Here is the simplest workflow you may want to follow to get started.
Note
Steps 3 and 4 are skipped if the Root CA already exists.
- Download this project locally
- Execute
bash generate_certificate.sh
(see above or-h
for more options) - [🔄3x] Enter a new password for Root CA Private Key (later referred as: 'CA Password')
- Fill in the details of the RootCA (most are optional)
- Enter new Certificate ID (recommended to use the local domain name as cert name, e.g:
mydomain.local
) - Enter Certificate life duration in days (You may skip with step with the
-d <days>
option.) - Enter alternative names one after the other (examples:
DNS:mydomain.local
,DNS:*.mydomain.local
orIP:192.168.1.1
).
When you are done, pressENTER
- Press
ENTER
to validate the displayed alternative name or edit the configuration manually if required. - Enter CA Password (from step 3)
- Press
ENTER
to start another certificate (➡ step 5) orCTRL
+C
to Stop here.
Refer to the documentation of the device or service you are setting up.
Be aware: some service will ask only for a private and public key, and some will ask for the root CA in addition.
- If you are prompted only for private and public key:
- Upload the
./<id>/<id>.priv.key
as private key - Upload the
./<id>/<id>.chain.pem
as public certificate chain
- Upload the
- If you are also prompted for the Root CA in addition to the private and public key:
- Upload the
./<id>/<id>.priv.key
as private key - Upload the
./<id>/<id>.pub.pem
as public key - Upload the
./CA/CA.pem
as Root CA
- Upload the
Those indications are general and may not be accurate to your specific need.
In order to trust the certificates you generated you will have to import the public CA directly on your devices.
The default file path for the public CA when generated is ./CA/CA.pem
Please make sure you copied the CA on the device as a first step.
Note that the extension .pem
may be replaced by .crt
without modifying the content of the file.
- Move the CA certificate (
ca.pem
) into/usr/local/share/ca-certificates/ca.crt
. - Update the Cert Store with:
sudo update-ca-certificates
See documentation here and here.
- Move the CA certificate (
ca.pem
) to/etc/pki/ca-trust/source/anchors/ca.pem
or/usr/share/pki/ca-trust-source/anchors/ca.pem
- Now run as root / with
sudo
:
update-ca-trust
See documentation here.
System-wide – Arch(p11-kit) (From arch wiki)
- Run (As root)
trust anchor --store myCA.crt
- The certificate will be written to
/etc/ca-certificates/trust-source/myCA.p11-kit
and the "legacy" directories automatically updated. - If you get "no configured writable location" or a similar error, import the CA manually:
- Copy the certificate to the /etc/ca-certificates/trust-source/anchors directory.
- and then
update-ca-trust
See documentation here
- Assuming the path to your generated CA certificate as
C:\ca.pem
, run:Import-Certificate -FilePath "C:\ca.pem" -CertStoreLocation Cert:\LocalMachine\Root
Note
Set-CertStoreLocation
toCert:\CurrentUser\Root
in case you want to trust certificates only for the logged in user.
OR
- In Command Prompt, run:
certutil.exe -addstore root C:\ca.pem
certutil.exe
is a built-in tool (classicSystem32
one) and adds a system-wide trust anchor.
The steps may vary from device / OS version but that should be looking like that:
- Open Phone Settings
- Locate
Encryption and Credentials
section. It is generally found underSettings > Security > Encryption and Credentials
- Choose
Install a certificate
- Choose
CA Certificate
- Locate the certificate file
ca.pem
on your SD Card/Internal Storage using the file manager. - Select to load it.
- Done!
- Inspired by Christian Lempa CheatSheet about SSL Certificate
openssl
is a command line tool from the OpenSSL Project