PKI for FortiGate, Part 1: How a Certificate Authority Actually Works
This is the first of seven posts on running a small certificate authority for FortiGate IPsec, and on what actually happens when you test it. Everything in the series was run on a lab hub and spoke on FortiOS 7.6.8, with a CA built on step-ca. Where I did not test something, I say so.
This first post has no FortiGate in it. Certificate authentication goes wrong in confusing ways when the basic model is fuzzy, so I want the model on the table before the debug output starts. If you already know what a CSR is and why the root key stays offline, skip to Part 2.
Two earlier posts cover ground this series builds on rather than repeats. Beyond PSK, Part 1 is the design argument for a dedicated CA instead of FortiManager as the CA. The step-ca post is the build of the CA used here. This series is about the behaviour: what the pieces do, and what the test results mean.
Two keys, one rule
Everything in PKI rests on a key pair. One key is private and one is public. They are mathematically linked, and they do opposite jobs:
- The private key signs. Only the holder of the private key can produce a valid signature.
- The public key verifies. Anyone can check a signature against the public key, and nobody can forge one from the public key alone.
A signature is not encryption of the data. It is a small value computed from the data and the private key. Change one bit of the data and the signature no longer verifies. So a valid signature tells you two things: the data has not been altered, and whoever signed it held the private key.
The rule that follows is simple: the private key never leaves the place it was created. You can hand the public key to anyone. If the private key is copied, the signature stops meaning “this specific device signed this”, because now the key has two holders.
Every design choice in the next six posts comes back to protecting private keys, and to what you can still do when one is lost.
What a certificate is
A public key on its own says nothing about who owns it. A certificate fixes that. It is a short document that says “this public key belongs to this name”, signed by someone you have already decided to trust.
The fields that matter for this series:
| Field | What it says |
|---|---|
| Subject | Who the certificate is for. For a FortiGate this is the common name (CN), such as spoke1.lab |
| Issuer | Who signed it. This is the name of the CA |
| Public key | The key being vouched for |
| Serial number | A number unique among everything that issuer has signed. Revocation works on serials |
| Validity | A start and an end date. Outside that window the certificate is not valid |
| Basic constraints | Whether this certificate is itself allowed to be a CA (CA:TRUE) or only an end entity (CA:FALSE) |
| Key usage | What the key may be used for: signing certificates, signing data, and so on |
| Signature | The issuer’s signature over all of the above |
The signature is what makes the rest trustworthy. If anyone edits the subject or the dates, the issuer’s signature stops verifying.
A certificate is public. You can paste one into a post, as I do later, and nothing is lost. Only the private key behind it is secret.
The certificate authority
A certificate authority is an entity with a private key that it uses to sign certificates, and a process for deciding whose certificates it will sign. The cryptography is the easy half. The hard half is the process: who is allowed to ask, how you know the request is genuine, and what happens when something goes wrong.
When a CA signs a certificate it is saying “I checked, and this public key belongs to this name.” Everything built on that depends on the CA being careful, and on its private key staying private. If someone steals a CA’s private key, they can issue certificates that every device trusting that CA will accept.
The chain of trust
A single CA signing everything puts its key at risk every time it is used. So CAs are arranged in tiers. In this lab there are three:
Root CA self-signed, key kept offline
|
| signs
v
Intermediate CA online, does the day-to-day signing
|
| signs
v
Leaf certificates hub1.lab, spoke1.lab, ... (one per device)
Each certificate is signed by the one above it. The root is the exception: it signs itself, because nobody sits above it.
When a FortiGate is shown a leaf certificate, it walks that chain upward:
- Check that the leaf’s signature verifies against the intermediate’s public key.
- Check that the intermediate’s signature verifies against the root’s public key.
- Check that the root is one it has been told to trust.
- Check the dates on every certificate in the chain.
- Check that nothing in the chain has been revoked.
- Check that the subject matches what the configuration says to expect.
If any step fails, the certificate is rejected. Steps 1 to 4 are mathematics and dates. Step 5 needs outside information, which is what most of this series is about. Step 6 is configuration.
Why the root is different
Step 3 is where the whole structure is anchored. There is no signature to check above the root. A FortiGate trusts the root because someone installed it as a trusted CA, not because anything proves it.
That is why the root matters more than any other key in the system. If the root key is compromised, every certificate chaining to it is suspect, and the fix is to replace the root on every device. So the root key is used rarely and kept away from anything network-reachable. It signs the intermediate, and later in this series it signs a revocation list. That is all.
The intermediate is online because it has to be. It signs every device certificate, so it has to be reachable by whatever process requests them. If it is compromised, the damage is real but recoverable: you revoke the intermediate from the root, issue a new one, and re-issue the leaves. Part 5 tests exactly that.
Getting a certificate: the CSR
A device needs a certificate without anyone ever handling its private key. The mechanism is the certificate signing request, or CSR.
- The device generates its own key pair. The private key stays in the device.
- The device builds a CSR: its public key and the subject it wants, signed with its own private key. That self-signature proves the requester holds the private key matching the public key in the request.
- The CSR goes to the CA. The CA checks the request, then signs a certificate for that public key and subject.
- The signed certificate goes back to the device, which pairs it with the private key it already has.
At no point did a private key travel. The certificate and the CSR are both public. This is the model Part 3 follows on a FortiGate, where the device generates the key and I copy only the CSR out.
Lifetimes and revocation
Every certificate has an end date, and the length of that window is a design decision. A short lifetime limits how long a stolen certificate can be misused. A long lifetime means fewer renewals to forget. In this lab the root runs ten years, the intermediate five, and each leaf one year.
An end date does not help when a certificate has to be withdrawn today. For that, the CA publishes a certificate revocation list (CRL): a signed list of serial numbers it no longer vouches for. The device fetches the list and checks each certificate’s serial against it. The alternative is OCSP, where the device asks a responder about one certificate at the moment it needs to know. This lab uses CRLs.
A CRL has its own issue date and its own “next update” date, and it is itself signed. So a CRL can be fetched, can be missing, and can go out of date. What a FortiGate does in each of those cases is the subject of Parts 5 and 6, and the answers are not obvious.
What a CA cannot do
A few limits worth knowing before you build one:
- It cannot recover a private key. It never had it. If a device is lost, you issue a new certificate for a new key.
- It cannot make a certificate stop working by itself. Revocation only has an effect where a device checks the list. A revoked certificate keeps working anywhere that does not check, or has not yet fetched the latest list.
- It cannot tell you its own key is safe. If the CA key leaks, the CA still signs normally. The first sign is usually somebody else’s certificate that you did not issue.
The next post turns this model into a design: which keys exist in the lab, where each one lives, and what each loss would cost.