← Back to section · Tutorials & Labs

Building a Local Test CA with openssl ca

Stand up a local test certificate authority from scratch with OpenSSL's built-in ca command: the directory skeleton and configuration file, root CA generation, server certificate issuance and verification, plus the classic failures — serial conflicts and database corruption.

Published 22 November 2026 · 6 min read · PQ Frontier

Building a Local Test CA with openssl ca
AI-generated site artwork
Video explainer · Lab setup: build and troubleshoot

TLS and PQC certificate experiments constantly need a certificate authority you control: issue certificates to local servers, test chain validation, try different extension combinations. A public CA is out of the question, and self-signing every certificate one by one cannot simulate chained trust. OpenSSL’s built-in ca command is the lightweight tool made for exactly this: it is deliberately plain, but it puts the core elements of a CA — the registration database, serial management, policy and extensions — right on the surface, which makes it an ideal lab bench. This tutorial builds a local test CA from zero and closes the loop: root certificate generation, server certificate issuance, and verification.

The Skeleton: Directory and Configuration File

Start with the directory skeleton. openssl ca expects a workspace layout:

mkdir -p ~/lab-ca/{certs,newcerts,private}
cd ~/lab-ca
touch index.txt
echo 1000 > serial
chmod 700 private

Three things must be understood properly. index.txt is the issuance database: every issued certificate appends one record, revocation status lives there too, and if it is corrupted or lost, the CA’s history is gone. The serial file holds the next certificate’s serial number (in hexadecimal), incremented automatically after each issuance; edit it carelessly and serials collide. The newcerts directory stores a copy of every issued certificate, named by its serial. Next, write a minimal configuration file ca.cnf: the [ ca ] section names the default CA, the [ CA_default ] section gives the paths of the directory, private key, certificate, database and serial file, and you prepare a [ policy_loose ] policy section (loose policy for a lab, so DN fields stay flexible) and a [ v3_server ] extension section stating subjectAltName, basicConstraints=CA:FALSE, keyUsage and extendedKeyUsage=serverAuth. Write all paths as fixed paths under your own CA directory, so running the command from a different working directory cannot write to the wrong place.

Generating the Root CA

openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -out private/ca.key
chmod 400 private/ca.key
openssl req -new -x509 -key private/ca.key -out certs/ca.crt -days 3650 \
  -subj "/CN=PQC Lab Root CA" -addext "basicConstraints=critical,CA:TRUE" \
  -config ca.cnf

The root certificate is self-signed in one step with req -x509; give it a generous 3650-day validity so the root does not expire in the middle of an experiment series. The -addext flag writes the CA:TRUE basic constraint directly into the certificate — that is its credential for issuing subordinate certificates. Newer OpenSSL versions support -addext; older ones need the extension via a configuration section instead, so when in doubt check openssl req -help for your local version. Tighten the private key to mode 400 and keep it inside private: this is a floor even for a test CA, because a leaked key lets anyone impersonate your entire lab trust root. Afterwards, read the certificate through with openssl x509 -in certs/ca.crt -text -noout and confirm issuer, validity window and extensions are as intended.

Issuing a Server Certificate

For a certificate for a local test server, the standard two steps apply: generate the key and a certificate signing request (CSR), then have the CA issue it.

openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out server.key
openssl req -new -key server.key -out server.csr -subj "/CN=localhost"
openssl ca -config ca.cnf -in server.csr -out server.crt \
  -extensions v3_server -extfile ca.cnf -batch -notext

Issuance is where extensions trip people up: modern browsers and TLS libraries accept only subjectAltName and no longer honor a bare CN, so the [ v3_server ] section must contain subjectAltName=DNS:localhost,IP:127.0.0.1 (adjust names and addresses to the experiment). -batch makes the command non-interactive, which suits scripts. Two signals confirm success: the output contains Data Base Updated, and index.txt gains a record starting with V while the serial value increments by one. If serial or database errors appear, stop and back up the entire CA directory before touching anything — do not edit index.txt by hand and hope; a database that disagrees with the actual certificates leaves the CA half-ruined. Finally, import the root certificate into the test client’s trust store (for curl, --cacert certs/ca.crt; for a local test browser, import the root), because only then will certificates issued by this CA be accepted.

Verification and Common Failures

Verification has two layers. Chain verification uses OpenSSL itself: openssl verify -CAfile certs/ca.crt server.crt must print OK. Functional verification installs the certificate on a local server — for example a temporary one via openssl s_server -accept 8443 -cert server.crt -key server.key — and then visits it with curl and --cacert; a clean handshake with no certificate error completes the loop. The failure catalogue: a “serial number already issued” style error at issuance time means the serial file was rolled back or edited by hand; a policy mismatch means the CSR fields conflict with the policy section — loosen the policy for lab use or complete the CSR fields; a certificate that issues fine but is still rejected by clients is almost always a missing SAN or a root that was never actually imported into the trust store — check those two first. One expectation to set for the PQC direction: stock openssl ca issues classical-algorithm certificates. Issuing post-quantum certificates such as ML-DSA requires OpenSSL to gain the algorithms through oqs-provider first; the workflow skeleton stays the same as in this tutorial, and the differences — algorithm choice and provider loading — are covered in a companion article on this site.

Practice Round: Revocation and CRLs

A CA’s full lifecycle is not just issuance but also revocation. Experiments regularly need an “issued but revoked” certificate to test client validation behavior, and the flow lives in openssl ca as well: revoke with openssl ca -config ca.cnf -revoke server.crt and the database record flips from V to R; then generate the certificate revocation list with openssl ca -config ca.cnf -gencrl -out crl.pem, and once clients or servers are configured to consult that CRL, the revoked certificate must be rejected. Work through this round and the test CA covers the full loop of issuance, verification and revocation, giving later OCSP or certificate-transparency experiments a reference point. Revocation is irreversible, so practice on a dedicated throwaway certificate, not on one that other experiments depend on; if you want to practice repeatedly, archive the whole CA directory first and restore from the archive when a round goes wrong — which is exactly what the “disposable as a whole” discipline is for.

Wrapping Up

The value of a local test CA is not raw power but structural transparency: database, serials, policy and extensions are all visible and controllable, and every step of the issuance chain can serve as an experimental variable. Keep two disciplines and it will serve you for a long time: the private key stays isolated, and the CA directory as a whole is disposable and rebuildable. The next time you need a foundation for hybrid certificates, dual certificates or chain experiments, this skeleton can be reused as-is.

Tags: OpenSSLCACertificatesPKI Lab