26.5. Renewing, Revoking, and Recovering Certificates

Issuance is the easy half of a CA's job. The operational half is knowing what is deployed and when it expires, replacing certificates without dropping connections, taking them back when their keys leak, moving clients between issuer generations without a maintenance window, and recovering the CA itself from its own backups. Every step in this section is verified from secclient, because a lifecycle operation that only the issuing host confirms is unverified.

26.5.1. Inventorying Certificates, Ownership, Expiry, and Renewal Dependencies

An inventory answers, for every deployed certificate: where does it live, who owns it, when does it expire, and what depends on it. On sec1, as john, find the deployed material:

$ sudo find /srv/ca/intermediate/issued /etc/nginx/ssl -maxdepth 1 -type f \( -name '*.crt' -o -name '*.pem' \) | sort
/etc/nginx/ssl/client-ca-chain.pem
/etc/nginx/ssl/intermediate.crt
/etc/nginx/ssl/root.crt
/etc/nginx/ssl/web-fullchain.pem
/srv/ca/intermediate/issued/john-client.crt
/srv/ca/intermediate/issued/web-fullchain.pem
/srv/ca/intermediate/issued/web.sec1.lab.crt

Two homes, as the deployment built them: the CA's issued/ archive and nginx's live directory. The inventory extends naturally with find /etc/docker/registry/tls -maxdepth 1 -type f for the registry and with the same command on every client holding credential copies. Read the live certificate's identity and lifetime - the flags print subject, issuer, serial, and expiry, then a renewal-window check:

$ sudo openssl x509 -in /etc/nginx/ssl/web-fullchain.pem -noout -subject -issuer -serial -enddate
subject=O=Handbook Web, CN=web.sec1.lab
issuer=O=Handbook Lab, CN=Handbook Issuing CA
serial=1000
notAfter=Dec 25 16:37:53 2027 GMT

openssl x509 reads the first certificate in a fullchain file, which is the leaf - the one whose expiry matters. The renewal check:

$ sudo openssl x509 -in /etc/nginx/ssl/web-fullchain.pem -noout -checkend 2592000
Certificate will not expire

-checkend 2592000 asks whether the certificate expires within the next 2 592 000 seconds - 30 days - and the answer Certificate will not expire means there is no forced renewal this month. Run the same command from a monthly timer and its exit status becomes the renewal signal: exit 0 means safe, exit 1 means the window has opened. The -enddate line gives the absolute date a calendar needs. The dependency half of the inventory is a table you write once and keep with the CA: the web certificate is consumed by nginx (reload to activate) and by the registry (restart to activate); the client certificate is consumed by whichever accounts hold ca/client.key copies; the root is consumed by every trust placement Section 26.4.6 made. Renewal that misses a consumer deploys a certificate that validates nowhere - the served-serial check below is how you notice in time.

A live check that the served certificate is the one you think it is - the serial clients are actually receiving, read straight from the running server:

$ sudo openssl s_client -connect 127.0.0.1:443 -servername web.sec1.lab </dev/null 2>/dev/null | openssl x509 -noout -serial
serial=1000

The pipeline connects locally, extracts the served certificate, and prints its serial - 1000, matching the inventory. After every renewal, this is the command that proves the new certificate is live, on the server itself before any client is asked.

26.5.2. Renewing Certificates and Rotating Keys with Atomic Deployment and Service Reloads

Renewal here means a fresh key as well as a fresh certificate: the old key has been on disk for the certificate's whole lifetime, and a routine renewal is the cheapest moment to replace it. Generate the new key and request on sec1, as john, in ca/server:

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

The subject is unchanged - the CA's policy and SANs come from its own configuration, so the request only needs to carry the identity. Sign it with the intermediate, 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-renew.csr -out /srv/ca/intermediate/issued/web-renew.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:39:08 2027 GMT (397 days)

Write out database with 1 new entries
Database updated

The database now records serial 1002 for the same subject - a second, overlapping validity period, which unique_subject no permits. Build the new fullchain:

$ sudo cat /srv/ca/intermediate/issued/web-renew.crt /srv/ca/intermediate/certs/intermediate.crt > /srv/ca/intermediate/issued/web-renew-fullchain.pem

Silent. The deployment is atomic in the way that matters: the new material is staged beside the old, validated, and swapped into place with two renames, and the service re-reads the files once, at a reload - there is no interval in which nginx holds a certificate it cannot load. Stage and validate first, on sec1, as john:

$ sudo install -m 600 ca/server/web-renew.key /etc/nginx/ssl/web.key.new
$ sudo install -m 644 /srv/ca/intermediate/issued/web-renew-fullchain.pem /etc/nginx/ssl/web-fullchain.pem.new
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

The two install steps are silent. The sequence's guarantee comes from its ordering: the new files are staged beside the old under the exact modes they will keep, nginx -t confirms the configuration and the files it currently names are loadable before anything changes, and the two renames then replace the live pair in single operations. The reload makes nginx's workers re-read certificate files without dropping a single connection, and the served-serial check below confirms the new pair is what clients now see. The swap:

$ sudo mv /etc/nginx/ssl/web.key.new /etc/nginx/ssl/web.key
$ sudo mv /etc/nginx/ssl/web-fullchain.pem.new /etc/nginx/ssl/web-fullchain.pem
$ sudo systemctl reload nginx

All three silent. mv within one filesystem is a rename - the file's content is replaced in a single operation, and the mode set by install travels with it. The reload makes nginx's workers re-read certificate files without dropping a single connection, which is the property that makes this a zero-downtime procedure. Now the two verifications. On sec1, as john - the served serial has moved:

$ sudo openssl s_client -connect 127.0.0.1:443 -servername web.sec1.lab </dev/null 2>/dev/null | openssl x509 -noout -serial
serial=1002

And from secclient, as john, the independent client confirms the service still validates end to end:

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

The old key file is gone (replaced by the rename), the old certificate remains in the CA's archive under its serial, and the rolled-back path - rename the previous fullchain back and reload - is the one-line recovery if the new certificate misbehaves.

26.5.3. Publishing Revocation Information and Testing Actual Client Enforcement and Limits

Revocation is a two-step claim: the CA records that a certificate is dead, and clients refuse it. Only the second step is security, and it depends on the first being published somewhere clients look. The two publication mechanisms differ in shape:

Mechanism How it works Freshness Client support and limits
CRL (this chapter) The issuer signs a list of revoked serials, published at a URL nextUpdate bounds it; a stale CRL is a policy question Broad in server software; browsers increasingly ignore CRLs for performance
OCSP / OCSP stapling The issuer answers per-certificate status queries; the server staples a signed answer to its handshake Minutes to days Widely supported by browsers; requires a responsive OCSP service

This chapter publishes CRLs because they need no running responder and because their enforcement can be tested offline - the property that made them the right rehearsal. The limitation row is real: browsers lean on short certificate lifetimes instead, and a private CA whose clients are servers and CLIs can simply require CRL checking, which is what nginx and OpenSSL do below.

The exercise: john's client credential is replaced by a new one, and the old certificate is revoked as part of the rotation - the same authorize-verify-withdraw pattern as Section 26.3.2, applied to a certificate. Generate the replacement on sec1, as john, in ca/client:

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

Sign it, as john with sudo:

$ 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-client2.csr -out /srv/ca/intermediate/issued/john-client2.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:'john2'
organizationName      :ASN.1 12:'Handbook Lab'
Certificate is to be certified until Dec 25 16:39:19 2027 GMT (397 days)

Write out database with 1 new entries
Database updated

Deliver the replacement exactly as Section 26.4.6 delivered the original: on sec1, as john, publish the new certificate into john's reach with sudo install -o john -g john -m 644 /srv/ca/intermediate/issued/john-client2.crt ca/client2-publish.crt; on secclient, as john, fetch the published certificate to ca/client2.crt and the key directly from debian-handbook/security/ca/client/john-client2.key to ca/client2.key, and chmod 600 ca/client2.key after. All of those steps are silent. Build the new fullchain on secclient, as john:

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

Now revoke the old certificate, on sec1, as john:

$ sudo openssl ca -config /srv/ca/intermediate/intermediate.cnf -revoke /srv/ca/intermediate/issued/john-client.crt -batch -passin file:/srv/ca/intermediate/private/passphrase
Using configuration from /srv/ca/intermediate/intermediate.cnf
Revoking Certificate 1001.
Database updated

Serial 1001 - the original client certificate - is marked R in the issuing database. Revocation is only a database fact until it is published, so regenerate the CRL and deploy it everywhere it is served:

$ 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 sh -c 'cat /srv/ca/intermediate/crl/intermediate.crl /root/ca/root/crl/root.crl > /etc/nginx/ssl/client-ca.crl'
$ sudo install -m 644 /srv/ca/intermediate/crl/intermediate.crl /srv/www/handbook/crl/intermediate.crl

All three steps print only the configuration notice; the CRL file is rewritten with the new revocation, the concatenated copy for nginx's future ssl_crl is refreshed, and the published copy on the port-80 site is updated. Inspect the list the CA just signed:

$ sudo openssl crl -in /srv/ca/intermediate/crl/intermediate.crl -noout -text | grep -A2 'Revoked Certificates'
Revoked Certificates:
    Serial Number: 1001
        Revocation Date: Nov 23 16:39:29 2026 GMT

Serial 1001, revoked as of the timestamp - one entry, correctly formed. Now the enforcement tests. The replacement client works through the mTLS site, from secclient, as john:

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

And the revoked certificate fails an offline verification. Fetch the published CRL to the client first - it is the same file the port-80 site serves:

$ curl -sS -o ca/trust/intermediate.crl http://web.sec1.lab/crl/intermediate.crl

Silent; the output file is the argument of -o. The check, with OpenSSL's CRL validation enabled:

$ openssl verify -crl_check -CAfile ca/trust/root.crt -untrusted ca/trust/intermediate.crt -CRLfile ca/trust/intermediate.crl ca/client.crt
O=Handbook Lab, CN=john
error 23 at 0 depth lookup: certificate revoked
error ca/client.crt: verification failed

-crl_check turns on revocation checking for the leaf, -CRLfile supplies the list, and error 23 is the specific refusal: the chain is otherwise valid, and the certificate is rejected because it is revoked. The old key still works cryptographically - nothing about a revoked key is broken - which is the entire reason revocation must be published and checked: without this step, a stolen key remains a working credential until its expiry date.

One limit deserves its own sentence, because it is a design decision rather than a failure: as deployed so far, the mTLS site does not yet consult the CRL - nginx accepts any client certificate whose chain it trusts, including a revoked one, until Section 26.5.5 adds the ssl_crl directive that enforces the list server-side. The dependency is deliberate: CRL enforcement is switched on together with the issuing-CA migration, so the directive and the CRL it reads are deployed as one reviewed change rather than two.

26.5.4. Rolling Over Issuing and Root CAs with Overlapping Trust and Client Migration

Roots age out on procedure, not on expiry: a key should be replaced after years of exposure, and the replacement must happen without a maintenance window in which clients trust nothing. The technique is overlapping trust - both hierarchies are valid at once, every client is migrated across, and only then does the old root retire. The sequence, which this subsection performs end to end:

Rolling over the CA with overlapping trust

Figure 26.3. The old and replacement hierarchies run beside each other. During the overlap, clients hold both roots; the server deploys its new chain; then the old root is withdrawn and the old issuing CA revoked, so any certificate left over from the old hierarchy stops validating.

Build the replacement hierarchy exactly as the original was built, with fresh keys, fresh serial ranges, and a dated name. Create the directories, passphrases, and databases on sec1, as john:

$ sudo install -d -m 700 /root/ca/root-2027/{certs,private,newcerts,crl}
$ sudo sh -c "printf 'Handbook-Root-2027-Passphrase\n' > /root/ca/root-2027/private/passphrase"
$ sudo chmod 400 /root/ca/root-2027/private/passphrase
$ sudo install -d -m 700 /srv/ca/intermediate-2027/{certs,private,newcerts,crl,csr,issued}
$ sudo sh -c "printf 'Handbook-Issuing-2027-Passphrase\n' > /srv/ca/intermediate-2027/private/passphrase"
$ sudo chmod 400 /srv/ca/intermediate-2027/private/passphrase
$ sudo sh -c ': > /root/ca/root-2027/index.txt && printf "2000\n" > /root/ca/root-2027/serial && printf "2000\n" > /root/ca/root-2027/crlnumber && chmod 600 /root/ca/root-2027/index.txt /root/ca/root-2027/serial /root/ca/root-2027/crlnumber'
$ sudo sh -c ': > /srv/ca/intermediate-2027/index.txt && printf "2000\n" > /srv/ca/intermediate-2027/serial && printf "2000\n" > /srv/ca/intermediate-2027/crlnumber && chmod 600 /srv/ca/intermediate-2027/index.txt /srv/ca/intermediate-2027/serial /srv/ca/intermediate-2027/crlnumber'

All silent. The 2000-range serials guarantee a serial issued by the new CAs can never collide with one from the old. The configuration files are the originals with names and paths changed - save root-2027.cnf with the distinguished name CN = Handbook Root CA 2027 and dir = /root/ca/root-2027, and intermediate-2027.cnf with CN = Handbook Issuing CA 2027, dir = /srv/ca/intermediate-2027, and its server_ext extended by one line the original lacked:

crlDistributionPoints  = URI:http://web.sec1.lab/crl/intermediate-2027.crl

The new leaves will carry their CRL's location in the certificate itself, which the original generation omitted. Install both files and create the new root, on sec1, as john:

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

The key generation prints its progress dots; everything else is silent. The new intermediate's key and request, then the root-shell signing - the same root-shell convention as Section 26.4.2, opened with $ sudo -i and left with exit:

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

In the root shell on sec1:

# openssl ca -config /root/ca/root-2027/root.cnf -extensions v3_intermediate_ca -days 3650 -notext -batch -passin file:/root/ca/root-2027/private/passphrase -in /srv/ca/intermediate-2027/csr/intermediate.csr -out /srv/ca/intermediate-2027/certs/intermediate.crt
Using configuration from /root/ca/root-2027/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 2027'
organizationName      :ASN.1 12:'Handbook Lab'
Certificate is to be certified until Nov 20 16:39:58 2036 GMT (3650 days)

Write out database with 1 new entries
Database updated

Leave the root shell. Generate both CRLs for the new hierarchy, as john:

$ sudo openssl ca -config /srv/ca/intermediate-2027/intermediate.cnf -gencrl -batch -passin file:/srv/ca/intermediate-2027/private/passphrase -out /srv/ca/intermediate-2027/crl/intermediate.crl
$ sudo openssl ca -config /root/ca/root-2027/root.cnf -gencrl -batch -passin file:/root/ca/root-2027/private/passphrase -out /root/ca/root-2027/crl/root.crl

Both print only their Using configuration from notice on standard error. Issue the new leaves - a fresh server key and a fresh client key, generated by john exactly as in Section 26.4.4, then signed by the new intermediate. Generate on sec1, as john:

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

Sign both, and build the new server fullchain, as john with sudo:

$ sudo openssl ca -config /srv/ca/intermediate-2027/intermediate.cnf -extensions server_ext -days 397 -notext -batch -passin file:/srv/ca/intermediate-2027/private/passphrase -in /home/john/debian-handbook/security/ca/server/web-2027.csr -out /srv/ca/intermediate-2027/issued/web-2027.crt
Using configuration from /srv/ca/intermediate-2027/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:40:06 2027 GMT (397 days)

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

Write out database with 1 new entries
Database updated
$ sudo cat /srv/ca/intermediate-2027/issued/web-2027.crt /srv/ca/intermediate-2027/certs/intermediate.crt > /srv/ca/intermediate-2027/issued/web-2027-fullchain.pem

The last command is silent. The new root, intermediate, and client certificate live in root-owned directories, so the CA operator publishes copies into john's reach on sec1 exactly as in Section 26.4.6 - as john:

$ sudo install -o john -g john -m 644 /root/ca/root-2027/certs/root.crt ca/root-2027.crt
$ sudo install -o john -g john -m 644 /srv/ca/intermediate-2027/certs/intermediate.crt ca/intermediate-2027.crt
$ sudo install -o john -g john -m 644 /srv/ca/intermediate-2027/issued/john-2027.crt ca/john-2027.crt

All silent. The client key was generated by john, so it needs no publishing. On secclient, as john, fetch the four files - the root first:

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

Silent, and the same command form for ca/intermediate-2027.crt to ca/trust/intermediate-2027.crt, ca/john-2027.crt to ca/john-2027.crt, and ca/client/john-2027.key to ca/john-2027.key (chmod 600 ca/john-2027.key after). The overlap begins when the client trusts both roots at once. On secclient, as john:

$ sudo install -m 644 ca/trust/root-2027.crt /usr/local/share/ca-certificates/handbook-root-2027.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.

Both roots now sit in the system store. Before the swap, preserve the old server chain - it is the artifact the negative tests below depend on. On sec1, as john:

$ sudo install -o john -g john -m 644 /etc/nginx/ssl/web-fullchain.pem ca/web-old-fullchain.pem

Silent. Fetch it on secclient, as john:

$ scp john@web.sec1.lab:debian-handbook/security/ca/web-old-fullchain.pem ca/trust/web-old-fullchain.pem

Also silent. Deploy the new server chain on sec1 - the same atomic procedure as Section 26.5.2, against the 2027 material, as john:

$ sudo install -m 600 ca/server/web-2027.key /etc/nginx/ssl/web.key
$ sudo install -m 644 /srv/ca/intermediate-2027/issued/web-2027-fullchain.pem /etc/nginx/ssl/web-fullchain.pem
$ sudo install -m 644 /srv/ca/intermediate-2027/certs/intermediate.crt /etc/nginx/ssl/intermediate.crt
$ sudo install -m 644 /root/ca/root-2027/certs/root.crt /etc/nginx/ssl/root.crt
$ sudo nginx -t && sudo systemctl reload nginx
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

The installs are silent; the test-and-reload pair speaks only through nginx -t. The server now presents the new chain while both roots are trusted - a client holding either one succeeds, which is the overlap guaranteeing no lockout. Prove it from secclient, as john:

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

The client's store holds both roots, so this success alone does not yet prove which chain was served - the migration check does. Withdraw the old root, on secclient, as john:

$ sudo rm /usr/local/share/ca-certificates/handbook-root-ca.crt && sudo update-ca-certificates --fresh
Clearing symlinks in /etc/ssl/certs...
done.
Updating certificates in /etc/ssl/certs...
149 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.

--fresh clears and rebuilds the store from what is actually present - plain update-ca-certificates does not remove a deleted file's entry, the trap Section 23.7.1 demonstrates. The count confirms the arithmetic: 149 certificates relinked, the 148 stock roots plus the one remaining Handbook root, the 2027. The same curl, over the new chain alone:

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

Now the migration is proven: with only the 2027 root trusted, the connection validates, so the served chain is the new one. The old chain, for contrast, fails against the new trust - from secclient, as john, verifying the saved old fullchain against the new root:

$ openssl verify -CAfile ca/trust/root-2027.crt -untrusted ca/trust/intermediate-2027.crt ca/trust/web-old-fullchain.pem
O=Handbook Web, CN=web.sec1.lab
error 20 at 0 depth lookup: unable to get local issuer certificate
error ca/trust/web-old-fullchain.pem: verification failed

The old chain's intermediate is signed by the old root, which the client no longer holds, so the chain is orphaned - that is the saved copy from before the swap doing its job. The registry from Section 26.4.6 is the one client that keeps working untouched through the whole rollover: it still serves the original chain, and its certs.d trust entry still holds the original root, so per-registry trust is unaffected by the system store's migration. That same independence cuts the other way - a site that rolls its CA must remember to reissue the registry's certificate and refresh certs.d, or the registry's trust entry will outlive the CA that signed it. Complete the retirement by revoking the old issuing CA itself, on sec1, as john - the root that still exists in the CA's records must say that its old subordinate is dead:

$ sudo openssl ca -config /root/ca/root/root.cnf -revoke /srv/ca/intermediate/certs/intermediate.crt -batch -passin file:/root/ca/root/private/passphrase
Using configuration from /root/ca/root/root.cnf
Revoking Certificate 1000.
Database updated
$ 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

Serial 1000 - the old intermediate, as issued by the old root in Section 26.4.2 - is revoked, and the root's CRL now lists it. A client that checks the old root's CRL rejects every old leaf at once, one revocation covering the whole hierarchy. Verify exactly that, with the old chain checked against both CRLs, on sec1, as john:

$ sudo sh -c 'cat /root/ca/root/crl/root.crl /srv/ca/intermediate/crl/intermediate.crl > /tmp/old-combined.crl'
$ sudo openssl verify -crl_check_all -CAfile /root/ca/root/certs/root.crt -untrusted /srv/ca/intermediate/certs/intermediate.crt -CRLfile /tmp/old-combined.crl /srv/ca/intermediate/issued/web-old-fullchain.pem
O=Handbook Lab, CN=Handbook Issuing CA
error 23 at 1 depth lookup: certificate revoked
error /srv/ca/intermediate/issued/web-old-fullchain.pem: verification failed

-crl_check_all checks every chain level, and the refusal fires at depth 1 - the intermediate, revoked by the root's CRL. The old root's key is still online on sec1 in this rehearsal; a production rollover finishes by taking the old root's storage offline and treating its remaining lifetime as evidence retention, not operational material.

26.5.5. Containing an Issuer Compromise and Replacing Keys, Certificates, and Trust

The rollover above was a planned migration. A compromise is the same operations with no schedule: an issuing key must be assumed stolen the moment unauthorized access to its host is suspected, and the response is to withdraw trust from everything it signed and reissue from a different issuer. The practice hosts are now mid-exercise in exactly the right state: the old issuing CA's key still exists on sec1, and this subsection treats it as compromised.

First the server side stops trusting the old issuer entirely: the mTLS site's client gate switches to the 2027 chain, and revocation checking switches on in the same change. Build the new client-CA and CRL files and enable both in the site. On sec1, as john:

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

All silent. In /etc/nginx/sites-available/handbook.conf, in the 8443 server block, change the client gate and turn on the CRL check:

    ssl_client_certificate  /etc/nginx/ssl/client-ca-chain-2027.pem;
    ssl_verify_client       on;
    ssl_verify_depth        2;
    ssl_crl                 /etc/nginx/ssl/client-ca-2027.crl;

Two directives changed - ssl_client_certificate now names the 2027 chain, and the placeholder comment from Section 26.4.6 is replaced by ssl_crl pointing at the concatenated 2027 CRL file. Validate and activate:

$ 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

The gate now demands client certificates chaining to the new intermediate and rejects any entry in the new CRLs. The old client credential - issued by the compromised issuer - is refused, from secclient, as john:

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

The old chain no longer validates against the gate - one directive change withdrew trust from every certificate the old issuer ever signed. The new-issuer client is accepted:

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

Now the second half of a compromise: a credential issued by the new issuer must also be revocable, because reissuing everything does not fix a single leaked key. Treat john-2027's key as exposed. Revoke it and publish, on sec1, as john:

$ sudo openssl ca -config /srv/ca/intermediate-2027/intermediate.cnf -revoke /srv/ca/intermediate-2027/issued/john-2027.crt -batch -passin file:/srv/ca/intermediate-2027/private/passphrase
Using configuration from /srv/ca/intermediate-2027/intermediate.cnf
Revoking Certificate 2001.
Database updated
$ sudo openssl ca -config /srv/ca/intermediate-2027/intermediate.cnf -gencrl -batch -passin file:/srv/ca/intermediate-2027/private/passphrase -out /srv/ca/intermediate-2027/crl/intermediate.crl
Using configuration from /srv/ca/intermediate-2027/intermediate.cnf
$ sudo sh -c 'cat /srv/ca/intermediate-2027/crl/intermediate.crl /root/ca/root-2027/crl/root.crl > /etc/nginx/ssl/client-ca-2027.crl'
$ sudo install -m 644 /srv/ca/intermediate-2027/crl/intermediate.crl /srv/www/handbook/crl/intermediate-2027.crl
$ sudo systemctl restart nginx

The CRL that nginx reads is regenerated and reinstalled, and the restart reloads it - ssl_crl is read at start or reload, which is why every revocation publication includes this activation step. The same credential that worked a moment ago is now refused, from secclient, as john:

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

That 400 is the CRL doing its job server-side: the chain validates, the name is right, and the serial is on the list - refused. Issue the replacement the standard way, on sec1, as john:

$ openssl req -new -newkey rsa:2048 -nodes -keyout ca/client/john-2027b.key -out ca/client/john-2027b.csr -subj '/CN=john-2027b/O=Handbook Lab'
.+....+. (progress dots omitted)
$ chmod 600 ca/client/john-2027b.key
$ sudo openssl ca -config /srv/ca/intermediate-2027/intermediate.cnf -extensions client_ext -days 397 -notext -batch -passin file:/srv/ca/intermediate-2027/private/passphrase -in /home/john/debian-handbook/security/ca/client/john-2027b.csr -out /srv/ca/intermediate-2027/issued/john-2027b.crt
Using configuration from /srv/ca/intermediate-2027/intermediate.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName            :ASN.1 12:'john-2027b'
organizationName      :ASN.1 12:'Handbook Lab'
Certificate is to be certified until Dec 25 16:40:54 2027 GMT (397 days)

Write out database with 1 new entries
Database updated

Deliver the replacement as before - on sec1, as john, publish /srv/ca/intermediate-2027/issued/john-2027b.crt into john's reach with sudo install -o john -g john -m 644, then on secclient fetch the certificate to ca/john-2027b.crt and the key directly from debian-handbook/security/ca/client/john-2027b.key to ca/john-2027b.key, followed by chmod 600 ca/john-2027b.key; every step is silent - and confirm, from secclient, as john:

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

The compromise is contained on every axis this chapter can test: the old issuer's certificates are refused at the gate, the leaked new-issuer credential is refused through the CRL, the replacement works, and each refusal was observed from the independent client rather than assumed. What the exercise cannot demonstrate - and what a real response would still owe - is the destruction of the compromised key's copies: the old intermediate's key file should be destroyed, not merely revoked, because revocation persuades cooperating clients while a live key still signs convincing forgeries for any client that fails to check.

26.5.6. Backing Up and Restoring CA Keys, Issuance State, and Configuration in Isolation

A CA that cannot be restored after a disk failure loses its issuance history - the database that says which serials were issued and revoked - and with it the ability to answer for anything it ever signed. The backup must therefore capture keys, database, serials, and configuration together, and it must be protected as one unit, because the archive now contains every private key. The procedure here produces a single encrypted archive with its own passphrase, held apart from the machine it protects.

Set the backup passphrase apart from the CA passphrases, on sec1, as john:

$ sudo sh -c "printf 'Handbook-CA-Backup-Passphrase-2026\n' > /root/ca/backup.passphrase"
$ sudo chmod 600 /root/ca/backup.passphrase

Both silent. Build the archive - both CA trees, both issuing directories, everything:

$ sudo tar -C / -czf /root/ca-backup.tar.gz root/ca srv/ca/intermediate srv/ca/intermediate-2027
$ sudo gpg --batch --yes --symmetric --cipher-algo AES256 --passphrase-file /root/ca/backup.passphrase -o /root/ca-backup.tar.gz.gpg /root/ca-backup.tar.gz
$ sudo rm /root/ca-backup.tar.gz
$ sudo ls -l /root/ca-backup.tar.gz.gpg
-rw------- 1 root root 31294 Nov 23 16:41 /root/ca-backup.tar.gz.gpg

The tar, gpg, and rm steps are silent - the first writes the archive, the second encrypts it, the third removes the plaintext - and the listing confirms the result. The plaintext archive existed only between the two commands; the encrypted copy is mode 600, and its small size is worth noting: a complete CA is megabytes at most, so there is no capacity excuse for not having copies in two places. The wrong-passphrase behavior is the same as Section 26.3.1's:

$ sudo gpg --batch --yes --decrypt --passphrase wrong-passphrase /root/ca-backup.tar.gz.gpg > /dev/null
gpg: AES256.CFB encrypted data
gpg: encrypted with 1 passphrase
gpg: decryption failed: Bad session key

The restore rehearsal is the part most backup procedures skip and every CA procedure needs: restore to an isolated directory and use the restored CA, proving the archive is complete without touching the live one. On sec1, as john:

$ sudo install -d -m 700 /srv/ca-restore
$ sudo gpg --batch --quiet --decrypt --passphrase-file /root/ca/backup.passphrase /root/ca-backup.tar.gz.gpg | sudo tar -xz -C /srv/ca-restore

The first command is silent; the second is a two-stage pipeline - gpg writes the plaintext archive to standard output, tar reads and extracts it - and it prints nothing either. The restored tree needs one adjustment before it can sign: the configuration files record their original absolute paths, so a working restored copy needs the paths rewritten to the restore location. With the editor, or a targeted substitution:

$ sudo sh -c "sed 's|/srv/ca/intermediate|/srv/ca-restore/srv/ca/intermediate|g; s|/root/ca/root|/srv/ca-restore/root/ca/root|g' /srv/ca-restore/srv/ca/intermediate/intermediate.cnf > /srv/ca-restore/srv/ca/intermediate/intermediate-restore.cnf"

Silent. Check what the restore preserved - the key's mode came through the archive intact:

$ sudo stat -c '%a %U:%G %n' /srv/ca-restore/srv/ca/intermediate/private/intermediate.key
400 root:root /srv/ca-restore/srv/ca/intermediate/private/intermediate.key

Now make the restored CA prove itself: sign a fresh certificate from the restored state. Generate a disposable test request - its subject says what it is:

$ sudo openssl req -new -newkey rsa:2048 -nodes -keyout /srv/ca-restore/restore-test.key -out /srv/ca-restore/restore-test.csr -subj '/CN=restore-test/O=Handbook Lab'

The command prints OpenSSL's key-generation progress dots and nothing else. Sign it with the restored configuration - on sec1, as john:

$ sudo openssl ca -config /srv/ca-restore/srv/ca/intermediate/intermediate-restore.cnf -extensions server_ext -days 30 -notext -batch -passin file:/srv/ca-restore/srv/ca/intermediate/private/passphrase -in /srv/ca-restore/restore-test.csr -out /srv/ca-restore/restore-test.crt
Using configuration from /srv/ca-restore/srv/ca/intermediate/intermediate-restore.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName            :ASN.1 12:'restore-test'
organizationName      :ASN.1 12:'Handbook Lab'
Certificate is to be certified until Dec 23 16:41:09 2026 GMT (30 days)

Write out database with 1 new entries
Database updated

The restored key decrypted with its passphrase, the restored database accepted a new entry, and the serial counter continued from where the backup captured it. Verify the result against the restored chain:

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

The archive is proven complete: keys, database, serial state, and configuration all survived, and the restored CA produces certificates that validate against the original root. Clean up the rehearsal state - /srv/ca-restore has served its purpose, and the backup passphrase file belongs somewhere other than the CA host:

$ sudo rm -rf /srv/ca-restore

Silent. The isolation property worth stating: this whole restore ran without disturbing the live CA, so a restore rehearsal can be a scheduled procedure, not an act of desperation. Chapter 15 covers backup discipline generally; the CA-specific rules are the ones this section exercised - the archive is complete, encrypted, tested by use, and its passphrase is held apart from the archive itself.

26.5.7. Testing Expiry, Failed Renewal, Trust Removal, and Recovery from Independent Clients

The last lifecycle tests are the ones you want to have rehearsed before they happen for real: a certificate that expires, a renewal that fails at the CA, and trust that must be withdrawn from clients. All three are staged here deliberately, and each is observed from secclient.

One fact about the state the last two sections left deserves a sentence before the tests use it: the old issuing CA - revoked by the root in Section 26.5.4 and declared compromised in Section 26.5.5 - is still physically present on sec1, key, database, and configuration intact. Signing with it still works mechanically, because revocation is a fact that clients check, not a property the key loses. That is precisely why a compromised issuer's key must be destroyed rather than merely revoked, and it is also what makes the old CA usable here as the test subject: it can still sign a test certificate, and every client that checks anything will refuse it.

A failed renewal. The most common renewal failure is the boring one: the CA key does not unlock. Simulate it by presenting the wrong passphrase to the old issuing CA's configuration, on sec1, as john:

$ sudo openssl ca -config /srv/ca/intermediate/intermediate.cnf -extensions server_ext -days 397 -notext -batch -passin pass:wrong-passphrase -in /home/john/debian-handbook/security/ca/server/web-renew.csr -out /srv/ca/intermediate/issued/web-renew.crt
Using configuration from /srv/ca/intermediate/intermediate.cnf
Could not find CA private key from /srv/ca/intermediate/private/intermediate.key
4077131B197F0000:error:1C800064:Provider routines:ossl_cipher_unpadblock:bad decrypt:../providers/implementations/ciphers/ciphercommon_block.c:107:
4077131B197F0000:error:11800074:PKCS12 routines:PKCS12_pbe_crypt_ex:pkcs12 cipherfinal error:../crypto/pkcs12/p12_decr.c:94:maybe wrong password

Read the transcript carefully, because the first line is misleading: Could not find CA private key does not mean the file is missing - the decrypt errors below it mean the key file was found and could not be unlocked. The last line says so in OpenSSL's vocabulary: maybe wrong password. No certificate was written and the database is untouched; the failure is clean. The operational response is the check worth making whenever a scheduled renewal fails - the passphrases, then the key file's presence and mode, then the configuration's private_key path - before assuming a storage failure.

Expiry. A certificate past its notAfter is refused by every verifier with no ceremony, which is easy to state and worth watching. Issue a deliberately expired certificate with explicit validity dates, on sec1, as john - the -startdate and -enddate options override the configured lifetime:

$ sudo openssl ca -config /srv/ca/intermediate/intermediate.cnf -extensions server_ext -startdate 200101000000Z -enddate 200201000000Z -notext -batch -passin file:/srv/ca/intermediate/private/passphrase -in /home/john/debian-handbook/security/ca/server/web-renew.csr -out /srv/ca/intermediate/issued/web-expired.crt
Using configuration from /srv/ca/intermediate/intermediate.cnf
Warning: -enddate or -not_after option overriding -days option
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 Feb  1 00:00:00 2020 GMT (-2487 days)

The dates are YYMMDDHHMMSSZ: valid from 2020-01-01 to 2020-02-01, and the (-2487 days) is OpenSSL itself observing how far in the past the end lies. The warning is expected - -enddate overrides the -days value, which is exactly what makes the option useful for tests. Verification refuses it:

$ sudo openssl verify -CAfile /root/ca/root/certs/root.crt -untrusted /srv/ca/intermediate/certs/intermediate.crt /srv/ca/intermediate/issued/web-expired.crt
O=Handbook Web, CN=web.sec1.lab
error 10 at 0 depth lookup: certificate has expired
error /srv/ca/intermediate/issued/web-expired.crt: verification failed

Error 10, certificate has expired - the chain is valid and the signature is genuine, and the date alone disqualifies it. Now serve it and watch a real client refuse it. The temporary TLS listener runs in the root shell on sec1 (open with $ sudo -i from john's session if it is not already open; leave with exit afterwards):

# systemd-run --unit=expired-tls --property=WorkingDirectory=/srv/ca/intermediate/issued /usr/bin/openssl s_server -accept 9443 -cert /srv/ca/intermediate/issued/web-expired.crt -key /home/john/debian-handbook/security/ca/server/web-renew.key -cert_chain /srv/ca/intermediate/certs/intermediate.crt -www
Running as unit: expired-tls.service; invocation ID: e5c3fa6062f247edb2e96094cd5b5762

systemd-run starts openssl s_server as the transient unit expired-tls.service - a TLS listener on port 9443 presenting the expired certificate, with the intermediate supplied as its chain. The invocation ID line is the unit's startup report. From secclient, as john, the client's verdict:

$ curl -sS --cacert ca/trust/root.crt https://web.sec1.lab:9443/
curl: (60) SSL certificate problem: certificate has expired
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 same refusal a client would give the morning a renewal was forgotten - and the reason the inventory procedure of Section 26.5.1 exists. Stop the temporary listener, on sec1, as john:

$ sudo systemctl stop expired-tls.service

Silent.

Trust removal and recovery. Withdrawing a root from a client must break every certificate that depended on it, and restoring trust must restore them - both directions get tested. The secclient store currently trusts the 2027 root. Withdraw it, as john:

$ sudo rm /usr/local/share/ca-certificates/handbook-root-2027.crt && sudo update-ca-certificates --fresh
Clearing symlinks in /etc/ssl/certs...
done.
Updating certificates in /etc/ssl/certs...
148 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.

The count is the stock 148 alone - the private root is gone from the store. The connection that worked moments ago fails:

$ curl -sS 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.

One root file removed, and the entire private PKI became untrusted on this client - the blast radius of a root, made visible. The container runtime shows the same failure through its own trust path: with the certs.d entry moved aside and no root in the system store, registry operations refuse, as john on secclient:

$ mv ~/.config/containers/certs.d/web.sec1.lab:5000 ~/.config/containers/certs.d/web.sec1.lab:5000.off

Silent. Now:

$ skopeo inspect docker://web.sec1.lab:5000/alpine:3.20
time="2026-11-23T16:41:51Z" level=fatal msg="Error parsing image name \"docker://web.sec1.lab:5000/alpine:3.20\": pinging container registry web.sec1.lab:5000: Get \"https://web.sec1.lab:5000/v2/\": tls: failed to verify certificate: x509: certificate signed by unknown authority"

x509: certificate signed by unknown authority - the runtime found no CA for this registry in either trust location, and the operation dies before any image data moves. Both trust paths restored, in reverse order:

$ sudo install -m 644 ca/trust/root-2027.crt /usr/local/share/ca-certificates/handbook-root-2027.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.
$ mv ~/.config/containers/certs.d/web.sec1.lab:5000.off ~/.config/containers/certs.d/web.sec1.lab:5000

Both the store addition and the directory move are as silent as their removals were. The recovery confirmation, from secclient, as john:

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

Trust restored, service reachable, and - because the removal test touched both the system store and the runtime's per-registry entry - the recovery is known to be complete on every path that used it. A production root compromise is the same operation at scale: remove the root everywhere it was placed, reissue from the replacement hierarchy, and only declare recovery when a client that trusted only the old root validates the new chain - which is precisely the test Section 26.5.4 ended on.