Wildcard OpenSSL Certificate Authority

[TOC]

I deploy a really simple certificate authority for all my self-hosted, LAN services, which deploys a single root authority, and a wildcard certificate.

Directory Structure

mkdir --parents ~/my/files/code/config/ark-ca/{certificates,private-keys}

The structure will end up looking like this when certificates and keys have been created.

├── certificates
│   ├── ark_lan_cert.pem
│   ├── ark_lan_csr.pem
│   ├── ark_root_ca_cert.pem
│   └── ark_root_ca_cert.srl
├── private-keys
│   ├── ark_lan_key.pem
│   └── ark_root_ca_key.pem
└── v3.ext

Root CA

Create Root Key and Certificate

openssl req \
    -x509 \
    -newkey rsa:4096 \
    -keyout ~/my/files/code/config/ark-ca/private-keys/ark_root_ca_key.pem \
    -nodes \
    -days 10950 \
    -sha256 \
    -extensions v3_ca \
    -subj "/C=GB/ST=LAN/L=LAN/O=Ark Certificate Authority/CN=Ark Root CA" \
    -out ~/my/files/code/config/ark-ca/certificates/ark_root_ca_cert.pem

Server Certificate

Create Key & Certificate Signing Request

openssl req \
    -new \
    -newkey rsa:4096 \
    -nodes \
    -keyout ~/my/files/code/config/ark-ca/private-keys/ark_lan_key.pem \
    -subj "/C=GB/ST=LAN/L=LAN/O=Ark LAN/CN=*.ark.lan" \
    -out ~/my/files/code/config/ark-ca/certificates/ark_lan_csr.pem

Check the Certificate Signing Request.

openssl req \
    -text \
    -noout \
    -verify \
    -in ~/my/files/code/config/ark-ca/certificates/ark_lan_csr.pem

Create Extensions

Create and add the below content into ~/my/files/code/config/ark-ca/v3.ext.

[req]
req_extensions = v3_req

[ v3_req ]
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names

[alt_names]
DNS.1 = *.ark.lan
DNS.2 = ark.lan

Create the Certificate

openssl x509 \
    -req \
    -in ~/my/files/code/config/ark-ca/certificates/ark_lan_csr.pem \
    -extfile ~/my/files/code/config/ark-ca/v3.ext \
    -extensions v3_req \
    -CA ~/my/files/code/config/ark-ca/certificates/ark_root_ca_cert.pem \
    -CAkey ~/my/files/code/config/ark-ca/private-keys/ark_root_ca_key.pem \
    -CAcreateserial \
    -out ~/my/files/code/config/ark-ca/certificates/ark_lan_cert.pem \
    -days 365 \
    -sha256

Check the certificate looks correct and includes everything you want it to include.

openssl x509 \
    -noout \
    -text \
    -in ~/my/files/code/config/ark-ca/certificates/ark_lan_cert.pem

About

I'm a technology professional who's been passionate about computers since my Grandad introduced me to an Intel 386 back in the 90s when I was a kid. Those moments inspired a passion within for technology, and I've been playing around with anything with a circuit board ever since. Whenever I have a moment you can probably find me working on something computer-related, and this is where I like to write about those moments.