PKI for FortiGate, Part 3: Issuing and Renewing FortiGate Certificates

Part 2 set out which keys exist and where they live. This post follows one FortiGate through getting a certificate and then replacing it. The CA build and the full signing commands are in the step-ca post, so I show the FortiGate side in full and the CA side only where it matters to the sequence.

The sequence

The model from Part 1 applies without change: the device makes the key, the CA never sees it.

  1. Generate a key pair and a CSR on the FortiGate.
  2. Copy the CSR to the CA and sign it.
  3. Import the signed certificate onto the same FortiGate object.
  4. Point the IPsec phase 1 at the new certificate.

Steps 1 and 3 happen on the device. Step 2 happens on themis. Step 4 is configuration.

1. Generate the key and the CSR

On the spoke, with the subject set to the name the hub will look for:

execute vpn certificate local generate ec SPOKE1-IPSEC-3 secp256r1 spoke1.lab

That creates a local certificate object called SPOKE1-IPSEC-3, holding a new EC P-256 key and a pending CSR. The private key stays inside the object. You can read the CSR out of the configuration:

show full-configuration vpn certificate local SPOKE1-IPSEC-3

The PEM block under set csr is the request. Copy that block, and only that block, to the CA server. Nothing else in the output is needed.

2. Sign it

On themis, a token is requested from the provisioner and used to sign the CSR. The commands, including the flag ordering that catches people out, are in the step-ca post. The result is a certificate for spoke1.lab issued by the intermediate. step ca sign writes the leaf followed by the intermediate. The FortiGate wants only the leaf, because the CA certificates are imported separately.

The certificate in use at the end of my testing was valid for exactly one year:

ObjectSerialValid
SPOKE1-IPSEC-30f0dbe9b41ff0cb8ed95dde21c26af3f2026-10-29 to 2027-10-29

3. Import the leaf

Paste the leaf into the existing object, between the quotes:

config vpn certificate local
    edit "SPOKE1-IPSEC-3"
        set certificate "-----BEGIN CERTIFICATE-----
        ...
        -----END CERTIFICATE-----"
    next
end

You do not need the GUI import dialog, and you do not need to create a new object. Pasting the leaf into the object that holds the CSR is enough, because FortiOS matches the certificate to the key it already has.

Two checks tell you it worked:

get vpn certificate local details SPOKE1-IPSEC-3
show full-configuration vpn certificate local SPOKE1-IPSEC-3

The first shows the subject, issuer and dates. In the second, the set csr line has disappeared. FortiOS removes the CSR when a matching certificate arrives, so its absence is a quick sign that the import took.

4. Switch the tunnel to it

The IPsec phase 1 refers to the certificate by object name:

config vpn ipsec phase1-interface
    edit "S1-H1-ISP1"
        set certificate "SPOKE1-IPSEC-3"
    next
end

In my lab, the phase 1 is pushed from FortiManager, and the object name is a template variable. Changing which certificate the spoke uses is a one-variable change, and the install preview shows a single changed line:

set certificate "SPOKE1-IPSEC-3"

After the install, the tunnel renegotiated and the hub logged the peer identity from the new certificate, CN = spoke1.lab.

A renewal is a new key, under a new name

I did not renew by re-signing the old key. Each time, I generated a fresh key under a new object name (SPOKE1-IPSEC, then -2, then -3) and switched the phase 1 over when the new certificate was ready. Two things follow from that.

First, the old and the new certificate coexist on the device. You can import the new one, test it, and switch the tunnel to it without a window where the device has no valid identity. If it does not work, switching back is a one-line change.

Second, a new key is a stronger renewal than re-signing an old one. A private key that has been in service for a year has had a year to leak. A renewal with a fresh key resets that.

The old certificate stays valid

Here is the consequence people overlook. The hub’s peer rule accepts a certificate from the intermediate whose common name is spoke1.lab. The old certificate and the new certificate both match that rule. Switching the spoke to a new certificate does not make the hub reject the old one.

So the old certificate remains acceptable until it expires or is revoked. If the old key could be in anyone else’s hands, which is the whole reason for many renewals, you revoke the old serial after the cutover. In the revocation tests, a revoked SPOKE1-IPSEC-2 kept authenticating until the hub next fetched the CRL. Part 5 has the timeline.

For a routine, uneventful renewal, the old certificate simply runs out. For anything involving suspicion, revoke it.

Details that cost time

  • The CSR lives in the object. If you delete the object before importing the certificate, the key is gone with it.
  • Name the object for the generation. SPOKE1-IPSEC-3 tells you at a glance which one a phase 1 uses. Reusing a name makes switching and rolling back harder.
  • Keep the subject constant. Every generation here has CN = spoke1.lab, because the hub pins that name. A new subject means a change on the hub as well.

What I have not tested

I have done this renewal by hand, twice, with the CA and FortiGates reachable. I have not tested what happens when a leaf expires on a running tunnel, or what an automated renewal would look like. Part 7 lists those with the other gaps.