26.4. Operating a Private Certificate Authority

A certificate authority is a small amount of cryptography wrapped in a large amount of procedure. The OpenSSL tooling on one Debian host can produce every certificate this chapter uses; what separates a toy from a CA is the hierarchy that limits damage, the database that records what was issued, and the revocation path that can take a certificate back. This section builds all of it, then hands every produced certificate to an independent client and makes the client prove that the right ones validate and the wrong ones fail.

26.4.1. Public ACME versus Private PKI and a Root, Issuer, Server, and Client Topology

The first decision is whether to run a CA at all:

Criterion Public ACME (as in Section 23.4.2) Private PKI (this chapter)
Names it can issue Publicly resolvable DNS names only Any name or IP you control, including internal ones
Cost per certificate Free to cheap per name, per issuer's policy Your operational time; no per-certificate cost
Validation of identity Automated challenges prove domain control Your issuance procedure, enforced by you
Renewal Automated by certbot timers Your own renewal inventory and procedure (Section 26.5.1)
Revocation Rarely relied on; short lifetimes instead CRL publication you control and clients you can test (Section 26.5.3)
Client configuration Zero - public roots ship in the system store Every client needs your root distributed (Section 26.4.6)
Failure mode An issuer outage or rate limit A compromised CA key forges anything you trusted it for

Choose ACME whenever the name is public; a public name with a public certificate is strictly less work for everyone. A private CA earns its keep for internal names, IP-address services, mutual-TLS client populations, and labs - anywhere the trust decision should follow your procedures rather than a public issuer's. The failure-mode row is the one to take seriously: the more clients trust a root, the more carefully its key must live, which is why the topology below keeps the root offline and lets the online component issue only leaves.

The hierarchy this chapter operates:

Private CA hierarchy and the paths trust travels

Figure 26.2. An offline root signs a single issuing intermediate constrained to leaf certificates (pathlen:0); the intermediate signs the server and client leaves. Clients store only the root - through the system store, an explicit CA file, nginx's client gate, or a container runtime's certs.d - and each connection delivers its own leaf and intermediate. CRLs from both issuer levels publish over plain HTTP.

Four roles, three of them on separate trust boundaries:

Role Where it lives Key properties
Root CA Handbook Root CA /root/ca/root on sec1, mode 700 RSA 4096, passphrase-encrypted key, 7300 days, pathlen:1 - signs the intermediate and nothing else
Issuing intermediate Handbook Issuing CA /srv/ca/intermediate on sec1, mode 700 RSA 3072, passphrase-encrypted key, 3650 days, pathlen:0 - signs all leaves
Server leaf CN=web.sec1.lab generated by john, signed by the intermediate DNS + DNS + IP subject alternative names, serverAuth only, 397 days
Client leaf CN=john generated by john, signed by the intermediate clientAuth only, 397 days

A production root belongs on removable media in a separate machine or location, brought online only to sign a new intermediate; this chapter keeps root and intermediate on sec1 so the procedure can be exercised, protecting them with directory permissions and encrypted keys instead. The pathlen constraints encode the compensation: even if the intermediate's key is stolen, the thief can mint leaf certificates but not another CA, and Section 26.5.5 rehearses exactly that containment. On the practice network the same host serves the TLS site whose certificates the CA issues - sec1 plays issuer and server, secclient plays every client.

26.4.2. Creating an Offline Root and Restricted Issuing Intermediate with OpenSSL

The root CA's configuration lives in /root/ca/root/root.cnf. Save this as root.cnf in the workspace on sec1; the installation below copies it to the root-owned directory:

# Offline root CA configuration.
[ ca ]
default_ca = CA_root

[ CA_root ]
dir               = /root/ca/root
database          = $dir/index.txt
new_certs_dir     = $dir/newcerts
certificate       = $dir/certs/root.crt
serial            = $dir/serial
crlnumber         = $dir/crlnumber
private_key       = $dir/private/root.key
default_md        = sha256
policy            = policy_strict
default_days      = 7300
default_crl_days  = 3650
unique_subject    = no

[ policy_strict ]
countryName             = optional
stateOrProvinceName     = optional
organizationName        = optional
organizationalUnitName  = optional
commonName              = supplied
emailAddress            = optional

[ req ]
default_bits       = 4096
prompt             = no
distinguished_name = root_dn
x509_extensions    = v3_root

[ root_dn ]
CN = Handbook Root CA
O  = Handbook Lab

[ v3_root ]
basicConstraints       = critical, CA:TRUE, pathlen:1
keyUsage               = critical, keyCertSign, cRLSign
subjectKeyIdentifier   = hash
authorityKeyIdentifier = keyid:always

[ v3_intermediate_ca ]
basicConstraints       = critical, CA:TRUE, pathlen:0
keyUsage               = critical, keyCertSign, cRLSign
subjectKeyIdentifier   = hash
authorityKeyIdentifier = keyid:always

The [CA_root] section is the issuing machinery: the database file that records every certificate the root signs, the serial file that increments per issuance, the CRL counter, and the private key. The v3_root extension block is the root's own identity - a CA allowed one level of subordinate (pathlen:1) whose key may sign certificates and CRLs, both flagged critical so no client can ignore them. The v3_intermediate_ca block, used when the root signs the intermediate, is deliberately narrower: pathlen:0 means the intermediate can sign leaves but never another CA.

Create the directory tree and install the configuration. On sec1, as john:

$ sudo install -d -m 700 /root/ca/root/{certs,private,newcerts,crl}
$ sudo install -m 600 root.cnf /root/ca/root/root.cnf

Both silent. The issuing CA gets a parallel tree under /srv/ca - /srv rather than /root because the issuing CA is the online operational component:

$ sudo install -d -m 700 /srv/ca/intermediate/{certs,private,newcerts,crl,csr,issued}

Silent. Its configuration, saved as intermediate.cnf in the workspace, differs from the root's file in the shorter default lifetime (397 days for leaves), the looser policy_loose accepting the subjects the operators bring, and the leaf extension sections that later subsections invoke:

# Issuing intermediate CA configuration.
[ ca ]
default_ca = CA_default

[ CA_default ]
dir               = /srv/ca/intermediate
database          = $dir/index.txt
new_certs_dir     = $dir/newcerts
certificate       = $dir/certs/intermediate.crt
serial            = $dir/serial
crlnumber         = $dir/crlnumber
private_key       = $dir/private/intermediate.key
default_md        = sha256
policy            = policy_loose
default_days      = 397
default_crl_days  = 30
unique_subject    = no
copy_extensions   = none

[ policy_loose ]
countryName             = optional
stateOrProvinceName     = optional
localityName            = optional
organizationName        = optional
organizationalUnitName  = optional
commonName              = supplied
emailAddress            = optional

[ req ]
default_bits       = 3072
prompt             = no
distinguished_name = intermediate_dn

[ intermediate_dn ]
CN = Handbook Issuing CA
O  = Handbook Lab

[ server_ext ]
basicConstraints       = critical, CA:FALSE
keyUsage               = critical, digitalSignature, keyEncipherment
extendedKeyUsage       = serverAuth
subjectKeyIdentifier   = hash
authorityKeyIdentifier = keyid,issuer
subjectAltName         = @server_alt_names

[ client_ext ]
basicConstraints       = critical, CA:FALSE
keyUsage               = critical, digitalSignature
extendedKeyUsage       = clientAuth
subjectKeyIdentifier   = hash
authorityKeyIdentifier = keyid,issuer

[ server_alt_names ]
DNS.1 = web.sec1.lab
DNS.2 = sec1.lab
IP.1  = 192.168.246.10

Install it beside the issuing CA's directory:

$ sudo install -m 600 intermediate.cnf /srv/ca/intermediate/intermediate.cnf

Silent. The one line that is a policy decision rather than plumbing is copy_extensions = none: a certificate request's extensions are ignored at signing, and the SANs a server certificate carries come from this file's server_alt_names section instead. A requester cannot smuggle an extra name into a certificate, because the CA's own configuration is the only source of names. The server_ext and client_ext blocks differ in exactly the ways RFC 5280 wants leaves to differ: CA:FALSE, no signing usage, and an extended key usage pinned to one purpose each.

The CA keys are passphrase-protected, and the passphrases live in files the configuration later references with -passin file:. Storing a passphrase beside its key is a rehearsal convenience - it keeps this chapter's commands reproducible; a production CA unlocks its key by typing the passphrase at an interactive prompt or by a procedure you control, because a passphrase file on the same disk as the key protects the key only from processes running as another user, not from root. On sec1, as john:

$ sudo sh -c "printf 'Handbook-Root-CA-Passphrase-2026\n' > /root/ca/root/private/passphrase"
$ sudo chmod 400 /root/ca/root/private/passphrase
$ sudo sh -c "printf 'Handbook-Issuing-CA-Passphrase-2026\n' > /srv/ca/intermediate/private/passphrase"
$ sudo chmod 400 /srv/ca/intermediate/private/passphrase

All four silent; the sh -c wrapper again exists so the redirection runs as root. Initialize the issuance databases - empty certificate index, serial and CRL counters starting at 1000 for both CAs:

$ sudo sh -c ': > /root/ca/root/index.txt && printf "1000\n" > /root/ca/root/serial && printf "1000\n" > /root/ca/root/crlnumber && chmod 600 /root/ca/root/index.txt /root/ca/root/serial /root/ca/root/crlnumber'
$ sudo sh -c ': > /srv/ca/intermediate/index.txt && printf "1000\n" > /srv/ca/intermediate/serial && printf "1000\n" > /srv/ca/intermediate/crlnumber && chmod 600 /srv/ca/intermediate/index.txt /srv/ca/intermediate/serial /srv/ca/intermediate/crlnumber'

Both commands print nothing. OpenSSL's req subcommand, used next to create both CA keys and the root's self-signed certificate:

Option Description
req -x509 Produce a self-signed certificate instead of a request
req -new Produce a certificate signing request from a new or existing key
-newkey rsa:BITS Generate a new RSA key of the given size
-keyout FILE / -out FILE Where to write the private key / the certificate or request
-config FILE Read extensions, distinguished name, and defaults from FILE
-days N Certificate lifetime in days
-sha256 Sign with SHA-256
-passout file:FILE Encrypt the output key with the passphrase in FILE
-passin file:FILE / -passin pass:WORD Unlock an input key from a file / a literal word
-nodes Write the key unencrypted (used for leaf keys)

Create the root key and self-signed certificate. On sec1, as john:

$ sudo openssl req -x509 -new -config /root/ca/root/root.cnf -keyout /root/ca/root/private/root.key -out /root/ca/root/certs/root.crt -days 7300 -sha256 -passout file:/root/ca/root/private/passphrase
..+..+...+......+. (progress dots omitted)

The command prints OpenSSL's key-generation progress on standard error and nothing else; the capture is abbreviated. The key arrives encrypted with the passphrase file. Tighten its permissions:

$ sudo chmod 400 /root/ca/root/private/root.key

Silent. Inspect the certificate the root just issued to itself, with a filter that keeps the identity and constraint lines:

$ sudo openssl x509 -in /root/ca/root/certs/root.crt -noout -text | grep -E 'Subject:|Issuer:|Serial Number|Not Before|Not After|CA:TRUE|pathlen'
        Serial Number:
        Issuer: CN=Handbook Root CA, O=Handbook Lab
            Not Before: Nov 23 16:37:30 2026 GMT
            Not After : Nov 18 16:37:30 2046 GMT
        Subject: CN=Handbook Root CA, O=Handbook Lab
                CA:TRUE, pathlen:1

The pipeline is one logical operation: openssl x509 -noout -text prints the full decoded certificate and grep keeps the lines named in its pattern. The serial number's hexadecimal value itself sits on the line after Serial Number: and did not match the filter; openssl req -x509 chooses that serial at random, which is why it is not the 1000 from the serial file. Issuer and subject are identical, as a self-signed certificate requires; the twenty-year lifetime is a root convention, acceptable because root keys are rotated by procedure (Section 26.5.4), not by expiry pressure; and CA:TRUE, pathlen:1 is the v3_root extension doing its job.

The intermediate now asks the root for a signature. Create its key and request, on sec1, as john:

$ sudo openssl req -new -newkey rsa:3072 -config /srv/ca/intermediate/intermediate.cnf -keyout /srv/ca/intermediate/private/intermediate.key -out /srv/ca/intermediate/csr/intermediate.csr -sha256 -passout file:/srv/ca/intermediate/private/passphrase
.......+. (progress dots omitted)

Progress dots on standard error again, nothing else. Protect the key:

$ sudo chmod 400 /srv/ca/intermediate/private/intermediate.key

Silent. Signing with the root key is the first operation this chapter performs in a root shell on sec1, because /root/ca/root is mode 700 and its key should stay unreachable from john's session: open the shell from john's account with $ sudo -i, and leave it with exit when the block is done. The openssl ca subcommand performs the signing with the database machinery:

Option Description
-config FILE Read the CA section (database, key, policy) from FILE
-extensions SECTION Apply the named extension section from the configuration
-days N / -notext Certificate lifetime; omit the human-readable preamble
-batch Sign without the interactive confirmation prompt
-passin file:FILE Unlock the CA key with the passphrase in FILE
-in FILE / -out FILE The signing request / the issued certificate

In the root shell on sec1:

# openssl ca -config /root/ca/root/root.cnf -extensions v3_intermediate_ca -days 3650 -notext -batch -passin file:/root/ca/root/private/passphrase -in /srv/ca/intermediate/csr/intermediate.csr -out /srv/ca/intermediate/certs/intermediate.crt
Using configuration from /root/ca/root/root.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName            :ASN.1 12:'Handbook Issuing CA'
organizationName      :ASN.1 12:'Handbook Lab'
Certificate is to be certified until Nov 20 16:37:36 2036 GMT (3650 days)

Write out database with 1 new entries
Database updated

Every element of the transcript is the procedure working: the request's signature was checked against its key, the subject was echoed back for inspection, the ten-year lifetime was applied, and - the part that makes this a CA rather than a one-off signature - the root's database recorded the issuance. Without -batch, openssl ca asks Sign the certificate? [y/n] before writing, which is the right behavior for a rarely-used offline root; the flag exists so signing can be scripted when the procedure is already governed elsewhere. Leave the root shell with exit. Verify the intermediate against the root, as john:

$ sudo openssl verify -CAfile /root/ca/root/certs/root.crt /srv/ca/intermediate/certs/intermediate.crt
/srv/ca/intermediate/certs/intermediate.crt: OK

The chain of exactly one link validates. Inspect the intermediate's identity and lifetime:

$ sudo openssl x509 -in /srv/ca/intermediate/certs/intermediate.crt -noout -subject -issuer -serial -dates
subject=O=Handbook Lab, CN=Handbook Issuing CA
issuer=CN=Handbook Root CA, O=Handbook Lab
serial=1000
notBefore=Nov 23 16:37:36 2026 GMT
notAfter=Nov 20 16:37:36 2036 GMT

Serial 1000 was the root's first issuance, drawn from the serial file initialized earlier. And the constraint that defines the intermediate:

$ sudo openssl x509 -in /srv/ca/intermediate/certs/intermediate.crt -noout -text | grep -A2 'Basic Constraints'
            X509v3 Basic Constraints: critical
                CA:TRUE, pathlen:0
            X509v3 Key Usage: critical

pathlen:0: a valid chain through this intermediate contains no CA below it. Finally, generate the root's own CRL - the list of subordinate CAs the root has revoked, empty for now, but produced and published from the first day so that clients that check it have something to check:

$ sudo openssl ca -config /root/ca/root/root.cnf -gencrl -batch -passin file:/root/ca/root/private/passphrase -out /root/ca/root/crl/root.crl
Using configuration from /root/ca/root/root.cnf

-gencrl writes the CRL file and prints only the configuration notice on standard error. Inspect the result:

$ sudo openssl crl -in /root/ca/root/crl/root.crl -noout -issuer -lastupdate -nextupdate
issuer=CN=Handbook Root CA, O=Handbook Lab
lastUpdate=Nov 23 16:37:45 2026 GMT
nextUpdate=Nov 20 16:37:45 2036 GMT

The crl subcommand with -noout prints only the metadata: the issuing root, when the list was produced, and by when clients should expect a replacement - ten years here, matching the root's stately default_crl_days 3650.

26.4.3. Maintaining CA Configuration, Issuance Records, Serial Numbers, and Protected Keys

Everything a CA knows about its own history lives in three small files per issuer. Read the root's issuance record, on sec1, as john:

$ sudo cat /root/ca/root/index.txt
V   361120163736Z       1000    unknown /O=Handbook Lab/CN=Handbook Issuing CA

One line per certificate ever signed, tab-separated: V for a valid certificate (a revoked one becomes R with the revocation time filled in), the expiry timestamp, an empty revocation field, the serial, the file the certificate copy was archived to, and the subject. The newcerts/ directory holds a copy of every issued certificate under its serial, which is what openssl ca -revoke and -status consult, and what lets a CA answer "what exactly did we issue in 2026?" years later. The serial counter is a plain file:

$ sudo cat /srv/ca/intermediate/serial
1000

The next certificate the intermediate signs will take serial 1000 - the value just shown is the next one - and openssl ca increments it atomically as part of each signing. The crlnumber file does the same for CRL versions, so every regenerated CRL is distinguishable from its predecessor. Three practices keep this machinery sound. First, the database, serial, and crlnumber files are as valuable as the key itself: a CA that loses its index cannot reliably revoke, so they are backed up with the keys in Section 26.5.6. Second, unique_subject no in this chapter's configuration permits reissuing the same subject - the normal case when renewing a certificate - but it also means the database alone is not proof of what is currently deployed; the inventory procedure in Section 26.5.1 is. Third, the private keys stay encrypted and mode 400 in their private/ directories, unlocked only per-operation through -passin; a passphrase stored beside the key is the compromise this rehearsal makes explicit, and an operational CA moves past it the way Section 26.4.2's root-shell procedure suggests - by unlocking the key at a controlled moment rather than leaving the unlocking material on the same disk.

26.4.4. Generating Service Keys and Requests with DNS and IP Subject Alternative Names

The leaf keys belong to the people who run the services, generated on the machine that will present them - the split between "who owns a key" and "who signs the certificate" is what makes the CA's operators unable to use other people's keys. Make a sub-workspace and generate the web server's key and request on sec1, as john:

$ mkdir -p ca/server ca/client ca/trust

Silent. Then the key and request:

$ openssl req -new -newkey rsa:2048 -nodes -keyout ca/server/web.sec1.lab.key -out ca/server/web.sec1.lab.csr -subj '/CN=web.sec1.lab/O=Handbook Web'
.....+. (progress dots omitted)

Progress dots on standard error; the files are written silently. The key arrives unencrypted (-nodes) because the service that loads it must start unattended; its protection is the filesystem - tighten it now, since OpenSSL writes it with the umask's default permissions:

$ chmod 600 ca/server/web.sec1.lab.key

Silent. The request carries the subject and the public key only. Check that the request is self-consistent and read the subject back:

$ openssl req -in ca/server/web.sec1.lab.csr -noout -subject -verify
Certificate request self-signature verify OK
subject=CN=web.sec1.lab, O=Handbook Web

The subject's common name is the primary name, but modern clients validate against the subjectAltName extension, which this request does not carry - deliberately. Recall copy_extensions = none in Section 26.4.2: even if a request carried SANs, the intermediate would ignore them, and the certificate will get its names from the CA's own server_alt_names section. That section lists DNS:web.sec1.lab, DNS:sec1.lab, and IP:192.168.246.10 - the FQDN clients actually type, the short name, and the address a client might hard-code. That is the correct shape for an internal service: every name a legitimate client could use, and no name the operator did not intend to grant. The CSR could also be produced on a different machine and copied here, which is the usual case - the request is public by design and carries nothing secret.

The client credential follows the same pattern. Still on sec1, as john:

$ openssl req -new -newkey rsa:2048 -nodes -keyout ca/client/john-client.key -out ca/client/john-client.csr -subj '/CN=john/O=Handbook Lab'
......+. (progress dots omitted)
$ chmod 600 ca/client/john-client.key

A client certificate needs no subjectAltName at all: mTLS servers authenticate the certificate's validity and often its subject, not a hostname the client would answer to.

26.4.5. Issuing Server and Client Certificates with Appropriate Constraints and Key Usage

The intermediate signs both requests, applying its extension sections. The server certificate first, on sec1, as john:

$ sudo openssl ca -config /srv/ca/intermediate/intermediate.cnf -extensions server_ext -days 397 -notext -batch -passin file:/srv/ca/intermediate/private/passphrase -in /home/john/debian-handbook/security/ca/server/web.sec1.lab.csr -out /srv/ca/intermediate/issued/web.sec1.lab.crt
Using configuration from /srv/ca/intermediate/intermediate.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName            :ASN.1 12:'web.sec1.lab'
organizationName      :ASN.1 12:'Handbook Web'
Certificate is to be certified until Dec 25 16:37:53 2027 GMT (397 days)

Write out database with 1 new entries
Database updated

The same machinery as the root's signing, one level down: signature checked, subject echoed, 397 days applied, database updated. The server_ext section supplied the certificate's constraints, and the next commands read them back - never trust an extension you did not inspect. The client certificate:

$ sudo openssl ca -config /srv/ca/intermediate/intermediate.cnf -extensions client_ext -days 397 -notext -batch -passin file:/srv/ca/intermediate/private/passphrase -in /home/john/debian-handbook/security/ca/client/john-client.csr -out /srv/ca/intermediate/issued/john-client.crt
Using configuration from /srv/ca/intermediate/intermediate.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName            :ASN.1 12:'john'
organizationName      :ASN.1 12:'Handbook Lab'
Certificate is to be certified until Dec 25 16:37:57 2027 GMT (397 days)

Write out database with 1 new entries
Database updated

Both leaves are recorded in the intermediate's database, serials 1000 and 1001. Verify both against the full chain in one command - -CAfile names the trusted root and -untrusted the intermediate the chain passes through:

$ sudo openssl verify -CAfile /root/ca/root/certs/root.crt -untrusted /srv/ca/intermediate/certs/intermediate.crt /srv/ca/intermediate/issued/web.sec1.lab.crt /srv/ca/intermediate/issued/john-client.crt
/srv/ca/intermediate/issued/web.sec1.lab.crt: OK
/srv/ca/intermediate/issued/john-client.crt: OK

Now the constraint checks. The server's names:

$ sudo openssl x509 -in /srv/ca/intermediate/issued/web.sec1.lab.crt -noout -ext subjectAltName
X509v3 Subject Alternative Name:
    DNS:web.sec1.lab, DNS:sec1.lab, IP Address:192.168.246.10

Exactly the three names from server_alt_names, and nothing the request could have contributed. The server's purpose:

$ sudo openssl x509 -in /srv/ca/intermediate/issued/web.sec1.lab.crt -noout -ext extendedKeyUsage
X509v3 Extended Key Usage:
    TLS Web Server Authentication
$ sudo openssl x509 -in /srv/ca/intermediate/issued/john-client.crt -noout -ext extendedKeyUsage
X509v3 Extended Key Usage:
    TLS Web Client Authentication

serverAuth and clientAuth, one per certificate. These extensions are what Section 26.4.7's wrong-purpose tests hinge on: a verifier that asks for a purpose the extension forbids rejects the certificate, so a stolen server key cannot be repurposed as a client identity without a CA signature. Build the chain file nginx will serve - leaf first, then the intermediate, in one PEM file:

$ sudo cat /srv/ca/intermediate/issued/web.sec1.lab.crt /srv/ca/intermediate/certs/intermediate.crt > /srv/ca/intermediate/issued/web-fullchain.pem
$ sudo wc -l < /srv/ca/intermediate/issued/web-fullchain.pem
52

The cat is silent; the redirection writes the file. wc -l confirms its size - 52 lines, two PEM blocks - and more usefully confirms the file is not empty before nginx tries to load it. The ordering is protocol-mandated: a server presents its leaf first because the client validates top-down from the leaf. Generate the intermediate's CRL now as well, so revocation has a published home before any certificate exists to revoke:

$ sudo openssl ca -config /srv/ca/intermediate/intermediate.cnf -gencrl -batch -passin file:/srv/ca/intermediate/private/passphrase -out /srv/ca/intermediate/crl/intermediate.crl
Using configuration from /srv/ca/intermediate/intermediate.cnf
$ sudo openssl crl -in /srv/ca/intermediate/crl/intermediate.crl -noout -issuer -lastupdate -nextupdate
issuer=O=Handbook Lab, CN=Handbook Issuing CA
lastUpdate=Nov 23 16:38:08 2026 GMT
nextUpdate=Dec 23 16:38:08 2026 GMT

The intermediate's CRL refreshes monthly (default_crl_days 30), matching a CA that actually revokes - a root's decade-long CRL interval is a statement that its subordinates almost never change; an issuer's 30-day interval is a statement that clients should check often.

26.4.6. Distributing Certificate Chains and Trust to Debian, Applications, and Container Runtimes

Distribution has two directions, and they are protected differently: the private key moves only to the service that needs it, by a protected channel; the public material - root, intermediate, certificates, CRLs - moves anywhere, because its integrity, not its secrecy, is what matters.

The TLS web site receives the private material first. The site configuration, saved as handbook.conf in the workspace on sec1 for installation to /etc/nginx/sites-available/handbook.conf - three server blocks: cleartext HTTP that also serves the published CRLs, the TLS site, and the mutual-TLS site:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name web.sec1.lab sec1.lab;
    root /srv/www/handbook;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    server_name web.sec1.lab sec1.lab;
    root /srv/www/handbook;
    index index.html;

    ssl_certificate     /etc/nginx/ssl/web-fullchain.pem;
    ssl_certificate_key /etc/nginx/ssl/web.key;
    ssl_protocols       TLSv1.2 TLSv1.3;
    ssl_ciphers         HIGH:!aNULL:!MD5;
    add_header Strict-Transport-Security "max-age=31536000" always;

    location / {
        try_files $uri $uri/ =404;
    }
}

server {
    listen 8443 ssl;
    server_name web.sec1.lab sec1.lab;
    root /srv/www/handbook;

    ssl_certificate         /etc/nginx/ssl/web-fullchain.pem;
    ssl_certificate_key     /etc/nginx/ssl/web.key;
    ssl_client_certificate  /etc/nginx/ssl/client-ca-chain.pem;
    ssl_verify_client       on;
    ssl_verify_depth        2;
    # ssl_crl is added when revocation checking is turned on (Section 26.5.5).
    ssl_protocols           TLSv1.2 TLSv1.3;

    location / {
        return 200 "mTLS access granted to $ssl_client_s_dn\n";
    }
}

The 443 block is the standard HTTPS pattern from Section 23.4.1; the new material is the 8443 block. ssl_client_certificate names the chain nginx will accept client certificates against - the intermediate and root, not the server's own chain - and ssl_verify_client on makes a valid client certificate mandatory rather than optional. ssl_verify_depth 2 allows the client chain to run leaf → intermediate → root. Deploy everything. On sec1, as john:

$ sudo install -d -m 755 /etc/nginx/ssl /srv/www/handbook /srv/www/handbook/crl

Silent. The private key, by the protected path - install rather than cp so the mode is set in the same operation as the copy:

$ sudo install -m 600 ca/server/web.sec1.lab.key /etc/nginx/ssl/web.key

Silent; nginx's workers, which run as the www-data user, read the key once at start or reload while root still holds it at mode 600. The public material:

$ sudo install -m 644 /srv/ca/intermediate/issued/web-fullchain.pem /etc/nginx/ssl/web-fullchain.pem
$ sudo install -m 644 /srv/ca/intermediate/certs/intermediate.crt /etc/nginx/ssl/intermediate.crt
$ sudo install -m 644 /root/ca/root/certs/root.crt /etc/nginx/ssl/root.crt
$ sudo install -m 644 /srv/ca/intermediate/crl/intermediate.crl /etc/nginx/ssl/intermediate.crl
$ sudo sh -c 'cat /etc/nginx/ssl/intermediate.crt /etc/nginx/ssl/root.crt > /etc/nginx/ssl/client-ca-chain.pem'
$ sudo sh -c 'cat /etc/nginx/ssl/intermediate.crl /root/ca/root/crl/root.crl > /etc/nginx/ssl/client-ca.crl'

All silent. The client-ca-chain.pem file is what ssl_client_certificate reads; client-ca.crl concatenates both issuers' CRLs into the file Section 26.5.5's ssl_crl will point at. Publish the CRLs over the port-80 site, add the content, and enable the site:

$ sudo install -m 644 /srv/ca/intermediate/crl/intermediate.crl /srv/www/handbook/crl/intermediate.crl
$ sudo install -m 644 /root/ca/root/crl/root.crl /srv/www/handbook/crl/root.crl
$ printf 'Handbook private PKI demonstration\n' > index.html
$ sudo install -m 644 index.html /srv/www/handbook/index.html
$ sudo install -m 644 handbook.conf /etc/nginx/sites-available/handbook.conf
$ sudo ln -sf /etc/nginx/sites-available/handbook.conf /etc/nginx/sites-enabled/handbook.conf
$ sudo rm -f /etc/nginx/sites-enabled/default

Every step in that block is silent; the printf writes through its redirection and the install lines carry their content to the site directories. Validate the whole configuration and activate it:

$ sudo nginx -t && sudo systemctl restart nginx
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

nginx -t parses and verifies every site file and both certificate pairs before anything is reloaded; only a passing test reaches the &&. The restart prints nothing itself. The site now serves three ports.

Trust distribution to the independent client comes next, and its first step belongs to the CA's public material: the root certificate, copied into john's reach on sec1 - as john is the operator running the client side - with a publish copy whose name says what it is. On sec1, as john:

$ sudo install -o john -g john -m 644 /root/ca/root/certs/root.crt ca/trust-root.crt
$ sudo install -o john -g john -m 644 /srv/ca/intermediate/certs/intermediate.crt ca/trust-intermediate.crt
$ sudo install -o john -g john -m 644 /srv/ca/intermediate/issued/web.sec1.lab.crt ca/trust-server.crt
$ sudo install -o john -g john -m 644 /srv/ca/intermediate/issued/john-client.crt ca/trust-client.crt

All silent; -o john -g john hands the copies to the account that will fetch them. On secclient, as john, from the workspace, fetch the root first:

$ scp john@web.sec1.lab:debian-handbook/security/ca/trust-root.crt ca/trust/root.crt

The transfer is silent on success and travels over john's verified SSH from Section 26.1.1. Repeat it for the three remaining files - the intermediate, the server certificate, and the client certificate - the same command with trust-intermediate.crt to ca/trust/intermediate.crt, trust-server.crt to ca/trust/server.crt, and trust-client.crt to ca/trust/client.crt. Then see what arrived:

$ ls -l ca/trust
total 16
-rw-r--r-- 1 john john 1379 Nov 23 16:38 client.crt
-rw-r--r-- 1 john john 1720 Nov 23 16:38 intermediate.crt
-rw-r--r-- 1 john john 1915 Nov 23 16:38 root.crt
-rw-r--r-- 1 john john 1448 Nov 23 16:38 server.crt

The sizes differ per file - the root (1915 bytes) and intermediate (1720) are self-contained CAs, the leaves are shorter. Now trust the root host-wide, on secclient, as john:

$ sudo install -m 644 ca/trust/root.crt /usr/local/share/ca-certificates/handbook-root-ca.crt
$ sudo update-ca-certificates
Updating certificates in /etc/ssl/certs...
1 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.

The first line of the second command's output is the one that matters: 1 added. The command also prints a rehash: warning on standard error about ca-certificates.crt being skipped - cosmetic: the combined bundle holds many certificates in one file, so the per-certificate rehash pass cannot process it, and update-ca-certificates writes the bundle itself.

From this moment, every TLS client on secclient that uses the system store trusts the Handbook root, which is the claim to test immediately:

$ curl -sS https://web.sec1.lab/
Handbook private PKI demonstration

curl verified the server's chain - leaf to intermediate to a root in the system store - and matched the requested name against the certificate's SANs before accepting a byte. If the name had failed to resolve, or the chain had broken, curl would have refused the connection. Confirm the same facts with OpenSSL's verifier, one step at a time. The chain:

$ openssl verify -CAfile ca/trust/root.crt -untrusted ca/trust/intermediate.crt ca/trust/server.crt
ca/trust/server.crt: OK

-CAfile here names an explicit root instead of the system store, which is the per-command trust placement from Section 26.3.3 - the same verdict arrived by a different channel, proving the store is not the only path that works. The hostname check, with a live connection:

$ openssl s_client -connect web.sec1.lab:443 -servername web.sec1.lab -verify_hostname web.sec1.lab -CAfile ca/trust/root.crt </dev/null 2>&1 | grep -E 'Verify return code|subject='
subject=O=Handbook Web, CN=web.sec1.lab
Verify return code: 0 (ok)

s_client opens the connection and prints the full handshake transcript; the pipeline's grep stage keeps the two lines that carry the verdict. -servername sends the SNI name, -verify_hostname asks OpenSSL to enforce the SAN match, -CAfile supplies the root, and </dev/null closes s_client's standard input so the session ends immediately instead of waiting for an interactive Q on a terminal. Verify return code: 0 is the whole chain and hostname verdict in one field. The published CRL is fetchable the same way - this pipeline fetches and decodes it in one operation:

$ curl -sS http://web.sec1.lab/crl/intermediate.crl | openssl crl -noout -issuer -lastupdate
issuer=O=Handbook Lab, CN=Handbook Issuing CA
lastUpdate=Nov 23 16:38:08 2026 GMT

CRL distribution points use plain HTTP deliberately: the CRL's authenticity comes from the issuer's signature, not the transport, so a plaintext fetch cannot weaken it.

The mTLS site on 8443 is the second distribution direction - the client's private key now moves to the client. First prove the gate is closed:

$ curl -sS -o /dev/null -w '%{http_code}\n' https://web.sec1.lab:8443/
400

HTTP 400 before any content: nginx demanded a client certificate and the connection offered none - the -w '%{http_code}' option prints just the status so the refusal is visible without a body. Fetch the client's own key and certificate from sec1 - the key is the one sensitive transfer, so it lands mode 600 and stays that way:

$ scp john@web.sec1.lab:debian-handbook/security/ca/client/john-client.key ca/client.key
$ scp john@web.sec1.lab:debian-handbook/security/ca/trust-client.crt ca/client.crt
$ chmod 600 ca/client.key
$ ls -l ca/client.crt ca/client.key
-rw-r--r-- 1 john john 1379 Nov 23 16:38 ca/client.crt
-rw------- 1 john john 1704 Nov 23 16:38 ca/client.key

The scps are silent; the listing confirms the key's mode. Build the client's own fullchain - its leaf plus the intermediate, because the mTLS server's ssl_client_certificate names intermediate and root, and the client must present the connecting link:

$ cat ca/client.crt ca/trust/intermediate.crt > ca/client-fullchain.pem
$ wc -l < ca/client-fullchain.pem
51

Silent, then the line count. Present both halves to the mTLS site:

$ curl -sS --cert ca/client-fullchain.pem --key ca/client.key https://web.sec1.lab:8443/
mTLS access granted to CN=john,O=Handbook Lab

The server validated the client chain and echoed the client subject DN - the response body is nginx's configured $ssl_client_s_dn - so mutual TLS is fully operational: each side verified the other, and the identity the server saw is the one the CA signed.

The container runtime is the last client, and it must not need host-wide trust. Deploy the private registry on sec1 with the same certificates - its configuration, saved as registry-config.yml in the workspace for installation to /etc/docker/registry/config.yml:

version: 0.1
log:
  level: info
storage:
  filesystem:
    rootdirectory: /var/lib/docker-registry
  delete:
    enabled: true
http:
  addr: 0.0.0.0:5000
  tls:
    certificate: /etc/docker/registry/tls/web-fullchain.pem
    key: /etc/docker/registry/tls/web.key

Install the TLS material and enable the registry. On sec1, as john:

$ sudo install -d -m 755 /etc/docker/registry/tls
$ sudo install -m 644 /srv/ca/intermediate/issued/web-fullchain.pem /etc/docker/registry/tls/web-fullchain.pem
$ sudo install -m 640 -g docker-registry ca/server/web.sec1.lab.key /etc/docker/registry/tls/web.key
$ sudo install -m 644 registry-config.yml /etc/docker/registry/config.yml
$ sudo systemctl daemon-reload
$ sudo systemctl enable --now docker-registry
Synchronizing state of docker-registry.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable docker-registry
Created symlink '/etc/systemd/system/multi-user.target.wants/docker-registry.service' → '/usr/lib/systemd/system/docker-registry.service'.

The install steps are silent; enable --now reports the unit's activation. The key is installed group-readable by the docker-registry service account - the same one-service pattern as nginx's. This registry has no authentication configured; a production registry adds the auth: section, which Section 25.5.1 demonstrates. On secclient, the runtime's per-registry trust entry receives the root - as john:

$ install -d -m 700 ~/.config/containers/certs.d/web.sec1.lab:5000
$ cp ca/trust/root.crt ~/.config/containers/certs.d/web.sec1.lab:5000/ca.crt

Both silent. The directory name is the registry host and port exactly as the runtime will address it, per containers-certs.d(5); the file inside is always ca.crt. Verify the registry's TLS endpoint:

$ curl -sS -o /dev/null -w '%{http_code}\n' --cacert ~/.config/containers/certs.d/web.sec1.lab:5000/ca.crt https://web.sec1.lab:5000/v2/
200

The /v2/ endpoint answers 200 - the registry is alive and its chain verifies against the explicitly named CA. Push an image through the same trust:

$ skopeo copy docker://docker.io/library/alpine:3.20 docker://web.sec1.lab:5000/alpine:3.20
Copying blob sha256:25f1d6b1951ac8eb3740558fe94cb83d377bdadf95fd9f98b50d2e1b96130471
Copying config sha256:bf8527eb54c3680e728d5b4b383a8ba730d72dae7236fbc8dff97ed6b224a731
Writing manifest to image destination

Selected output - skopeo's final progress lines as it copies the image's blob and config and writes the manifest to the private registry. The digest proves the round trip:

$ skopeo inspect --tls-verify=true docker://web.sec1.lab:5000/alpine:3.20 | jq -r .Digest
sha256:c64c687cbea9300178b30c95835354e34c4e4febc4badfe27102879de0483b5e

The pipeline extracts one field: skopeo inspect prints the image's JSON record and jq -r .Digest prints the manifest digest - the content-addressed identity of the image now stored in the private registry, verifiable byte-for-byte by any client that pulls it. Note what the runtime did not need: the root is not in the host-wide store for this exchange - certs.d scoped the trust to exactly one registry for exactly one user, the narrow placement Section 26.3.3 recommends.

26.4.7. Verifying Hostnames, Chains, Mutual TLS, and Rejected Untrusted or Wrong-Purpose Certificates

Everything so far verified the positive path. The security claim only holds if the failures fail, so this subsection breaks the chain four ways and watches each one be refused - all from secclient, the independent client, as john.

A name the certificate does not cover. wrong.sec1.lab resolves to the same address as web.sec1.lab - the /etc/hosts entry from the chapter's setup - so the connection reaches the right server with the right certificate, and only the name check can fail:

$ curl -sS https://wrong.sec1.lab/
curl: (60) SSL: no alternative certificate subject name matches target hostname 'wrong.sec1.lab'
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the webpage mentioned above.

curl error 60 is the certificate-verification failure class, and the message names the exact cause: no SAN in the certificate matches the requested hostname. A server operator's fix is a new certificate with the name in its SANs - never a client-side option to skip the check.

An issuer the client does not trust. Create an unrelated CA and point curl at it - --cacert replaces the system store for this one connection, so the Handbook root in the system store cannot rescue the attempt:

$ openssl req -x509 -newkey rsa:2048 -nodes -days 30 -keyout wrong-ca.key -out wrong-ca.crt -subj '/CN=Unrelated Test CA'
...........+ (progress dots omitted)

The unrelated CA exists (key mode 600 with chmod 600 wrong-ca.key - silent - if you keep it). Now verify against it alone:

$ curl -sS --cacert wrong-ca.crt https://web.sec1.lab/
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the webpage mentioned above.

The server's chain is intact and genuinely signed by the Handbook root - but that root is not the CA the client was told to trust for this connection, so the chain terminates nowhere and the handshake fails. A certificate proves nothing by existing; it proves something only relative to a trust anchor the client actually holds.

A certificate used for the wrong purpose. OpenSSL's verify has a -purpose flag that models what a TLS implementation checks. Ask it to accept the server certificate as a client credential:

$ openssl verify -purpose sslclient -CAfile ca/trust/root.crt -untrusted ca/trust/intermediate.crt ca/trust/server.crt
O=Handbook Web, CN=web.sec1.lab
error 26 at 0 depth lookup: unsuitable certificate purpose
error ca/trust/server.crt: verification failed

And the mirror image - the client certificate offered as a server's:

$ openssl verify -purpose sslserver -CAfile ca/trust/root.crt -untrusted ca/trust/intermediate.crt ca/trust/client.crt
O=Handbook Lab, CN=john
error 26 at 0 depth lookup: unsuitable certificate purpose
error ca/trust/client.crt: verification failed

Error 26 is the extendedKeyUsage extension refusing: the server certificate says serverAuth and the client certificate says clientAuth, and the verifier honors the constraint even though both chains are otherwise perfect. This is the payoff of the one-purpose extension sections from Section 26.4.5: a key stolen from the web server cannot be presented as a client identity to the mTLS site, and a stolen client key cannot impersonate the server.

The full rejection matrix this chapter has now exercised:

Test Result What it proves
Correct name, full chain Verify return code: 0 (ok) The positive path works end to end
No client certificate on mTLS HTTP 400 The gate is closed by default
Valid client certificate on mTLS Subject DN echoed Client identity is checked and reported
Wrong hostname curl error 60, no match in SANs Name checks cannot be bypassed by connectivity
Untrusted issuer unable to get local issuer certificate Trust must be anchored in what the client holds
Server cert as client credential unsuitable certificate purpose Key usage extensions are enforced
Client cert as server credential unsuitable certificate purpose Both directions of misuse are refused