How to create Your Own Self-Signed Certificates
You know how there are services like Let's Encrypt offering SSL Certificates Cheat-Sheetthat
X.509work on the WAN and the World Wide Web? Well we are going become our own Certificate Authority like let's encrypt, and we will sign our own ssl certificates with our custom CA (Certificate Authority) certificate.
This is an ITU standard defininghow the formatsystem works:
On almost every device, certificates of public"trusted keyRoot certificates.Certificate X.509Authorities" are usedstored, inso TLS/SSL,that whichwhen isyou visit a HTTPS website, and the basisSSL forit HTTPS. An X.509 certificate binds an identity to a public key using a digital signature. A certificate contains an identity (hostname, organization, etc.) and a public key (RSA, DSA, ECDSA, ed25519, etc.), andpresents is either signed by aone of these "Trusted Root Certificate Authority or is Self-Signed.
---
Self-Signed Certificates
Generate CA
Generate RSA
openssl genrsa -aes256 -out ca-key.pem 4096
Generate a public CA Cert
openssl req -new -x509 -sha256 -days 365 -key ca-key.pem -out ca.pem
Generate Certificate
Create a RSA key
openssl genrsa -out cert-key.pem 4096
Create a Certificate Signing Request (CSR)
openssl req -new -sha256 -subj "/CN=yourcn" -key cert-key.pem -out cert.csr
Create aextfilewith allAuthorities", thealternativedevice/namesbrowser
andechoautomatically"subjectAltName=DNS:your-dns.record,IP:257.10.10.1"trust>>itextfile.cnf
# optional echo extendedKeyUsage = serverAuth >> extfile.cnf
Createdisplay thecertificatelock
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 Base64 Formats PEM (.pem, .crt, .ca-bundle), PKCS#7 (.p7b, p7s) and Binary Formats DER (.der, .cer), PKCS#12 (.pfx, p12).symbol.
Convert Certs
| |
| |
|
Verify Certificates
openssl verify -CAfile ca.pem -verbose cert.pem
Install the CA Cert as a trusted root CA
On Debian & Derivatives
Move the CA certificate (ca.pem) into/usr/local/share/ca-certificates/ca.crt.Update the Cert Store with:
sudo update-ca-certificates
Refer the documentation here and here.
On Fedora
Move the CA certificate (ca.pem) to/etc/pki/ca-trust/source/anchors/ca.pemor/usr/share/pki/ca-trust-source/anchors/ca.pemNow run (with sudo if necessary):
update-ca-trust
Refer the documentation here.
On Arch
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
wiki page here
On Windows
Assuming the path to your generated CA certificate as C:\ca.pem, run:
Import-Certificate -FilePath "C:\ca.pem" -CertStoreLocation Cert:\LocalMachine\Root
Set-CertStoreLocationtoCert:\CurrentUser\Rootin caseyou want totrustsee these "Trusted Root Certificate Authorities" for yourself, follow the steps below:On windows:
Press on the start button, and search
certificates
onlyand you should see an app called "Manage Computer Certificates"Click on that, and on the left menu, you should see "Trusted Root Certificate Authorities".
Click on that and you should see a massive dropdown with names of many different companies and familiar ones such as Microsoft, Amazon, Google etc., This means that any website that presents SSLs, signed by any of these Root CAs, will be instantly trusted.
To create our own SSL certs for local domains, we need to first create a Certificate Authority file, which will then sign our generated SSLs, I will explain the process as we go ahead.
Prerequisites:
- You need to know how to setup your own local, recursive DNS server and create local DNS records that point to certain IP addresses (Something like Pi-hole is perfect for this)
- You need to have a linux machine
How we will implement this on our local LAN:
- Using our local DNS resolver like Pi-Hole, we will create custom domains (something like
kvis.network
) to point to an IP address running a particular services - We will create a Certificate Authority File and add it to the "Trusted Root Certificate Authority" store of the devices you will be using to visit these custom domains**
- We will generate SSL certs that are signed by our CA file
- You can either upload this SSL directly into service like Proxmox's Web UI, or you can use a reverse proxy like NGINX Proxy Manager to configure SSLs, just like you would for the
logged in user.WAN.
ORProceed to next step, to see steps on how to create SSLsInCommand Prompt, run:certutil.exe -addstore root C:\ca.pemcertutil.exeis a built-in tool (classicSystem32one) and adds a system-wide trust anchor.
On AndroidThe exact steps vary device-to-device, but here is a generalised guide:Open Phone SettingsLocateEncryption and Credentialssection. It is generally found underSettings > Security > Encryption and CredentialsChooseInstall a certificateChooseCA CertificateLocate the certificate fileca.pemon your SD Card/Internal Storage using the file manager.Select to load it.Done!
Links:- You need to know how to setup your own local, recursive DNS server and create local DNS records that point to certain IP addresses (Something like Pi-hole is perfect for this)