Peters School of Business · Assiniboine College · NETW-0014
2 hours · Lecture + Lab 5C · strongswan-pki, CA generation, server certificate issuance
sudo ipsec status. Ask: "Why is a PSK less secure than certificate authentication?" — the PSK is a shared secret. Both sides know it. If either is compromised, the attacker can impersonate the other endpoint. A certificate's private key stays on one machine — the CA can revoke a compromised certificate without affecting other tunnels. PKI also scales: a central CA can issue certs to hundreds of VPN endpoints; distributing hundreds of unique PSKs is an administrative nightmare.PKI trust chains, the strongswan-pki toolkit, and certificate lifecycle
Part 1 — PKI trust model (10 min)
/etc/ipsec.d/private/caKey.pem — CA's private key. Never leaves S3. chmod 600.
/etc/ipsec.d/cacerts/caCert.pem — CA's public certificate. Distributed to all clients that need to trust this CA.
/etc/ipsec.d/private/s1Key.pem — S1's private key. Never leaves the machine it was generated for.
/etc/ipsec.d/certs/s1Cert.pem — S1's certificate, signed by the CA. Shared with peers.
Part 2 — strongswan-pki command syntax (12 min)
ipsec pki command is the Swiss Army knife for certificate operations. Walk through each command used in today's lab:
ipsec pki --gen --type rsa --size 4096 --outform pem > file.pem — generate a new RSA private key, output as PEM format, write to file.
ipsec pki --self --ca --lifetime 3650 --in caKey.pem --type rsa --dn "CN=..." --outform pem > caCert.pem — create a self-signed CA certificate. --ca marks it as a CA (allowed to sign other certs). --lifetime 3650 = 10 years.
ipsec pki --print --in certfile.pem — inspect a certificate's contents: issuer, subject, validity dates, key size, flags.
ipsec pki --pub --in privateKey.pem | ipsec pki --issue --lifetime 730 --cacert caCert.pem --cakey caKey.pem --dn "..." --san hostname --flag serverAuth --flag ikeIntermediate --outform pem > cert.pem
--san s1.yourname.net — Subject Alternative Name. This is the hostname the cert is valid for — must match what the remote peer will present as its identity in ipsec.conf.
--flag serverAuth — marks the cert as valid for server authentication (TLS/IPSec).
--flag ikeIntermediate — required by some IKE implementations (including older StrongSwan) to accept the cert for IKE authentication.
--lifetime 730 — two years in days.
--cakey /etc/ipsec.d/private/caKey.pem (the CA's private key to sign the cert), not the server's own key. The notes had a transcription error using s3Key.pem as the CA key — this would fail because s3Key.pem is not the CA key. Always use caKey.pem as the --cakey argument.Part 3 — Distinguished Names (8 min)
C=CA — Country (ISO 3166-1 alpha-2 code)
O=YourName — Organisation
CN=YourName.net — Common Name (for a CA cert, this is the CA's name; for a server cert, this is the hostname)
leftid/rightid in ipsec.conf must match exactly what was embedded in the certificate during issuance. A mismatch causes authentication failure even if the certificate is technically valid.Lab 5C — Build the CA on S3, issue server certificates for S1 and S3, distribute files
Part 1 — Install strongswan-pki on S3 (5 min)
sudo apt install strongswan-pki. Verify: ipsec pki --version.Part 2 — Generate the CA private key and certificate (15 min)
ipsec pki --gen --type rsa --size 4096 --outform pem > /etc/ipsec.d/private/caKey.pem
sudo chmod 600 /etc/ipsec.d/private/caKey.pem
ipsec pki --self --ca --lifetime 3650 \
--in /etc/ipsec.d/private/caKey.pem --type rsa \
--dn "C=CA, O=YourName, CN=YourName.net" \
--outform pem > /etc/ipsec.d/cacerts/caCert.pem
ipsec pki --print --in /etc/ipsec.d/cacerts/caCert.pem. Identify: issuer (same as subject — it's self-signed), validity period (10 years), is CA: yes, key size.Part 3 — Generate S3's server certificate (15 min)
ipsec pki --gen --type rsa --size 4096 --outform pem > /etc/ipsec.d/private/s3Key.pem
sudo chmod 600 /etc/ipsec.d/private/s3Key.pem
ipsec pki --pub --in /etc/ipsec.d/private/s3Key.pem --type rsa | \
ipsec pki --issue --lifetime 730 \
--cacert /etc/ipsec.d/cacerts/caCert.pem \
--cakey /etc/ipsec.d/private/caKey.pem \
--dn "C=CA, O=YourName, CN=s3.yourname.net" \
--san s3.yourname.net \
--flag serverAuth --flag ikeIntermediate \
--outform pem > /etc/ipsec.d/certs/s3Cert.pem
--cakey must be the CA's private key (caKey.pem), not S3's key.
ipsec pki --print --in /etc/ipsec.d/certs/s3Cert.pem. Identify: issuer (the CA), subject (s3.yourname.net), SAN, flags.Part 4 — Generate S1's certificate (also on S3) (15 min)
ipsec pki --gen --type rsa --size 4096 --outform pem > /etc/ipsec.d/private/s1Key.pem
sudo chmod 600 /etc/ipsec.d/private/s1Key.pem
ipsec pki --pub --in /etc/ipsec.d/private/s1Key.pem --type rsa | \
ipsec pki --issue --lifetime 730 \
--cacert /etc/ipsec.d/cacerts/caCert.pem \
--cakey /etc/ipsec.d/private/caKey.pem \
--dn "C=CA, O=YourName, CN=s1.yourname.net" \
--san s1.yourname.net \
--flag serverAuth --flag ikeIntermediate \
--outform pem > /etc/ipsec.d/certs/s1Cert.pem
Part 5 — Copy files to S1 (10 min)
sudo scp -P [ssh-port] /etc/ipsec.d/cacerts/caCert.pem student@[S1-IP]:/home/student/
sudo scp -P [ssh-port] /etc/ipsec.d/private/s1Key.pem student@[S1-IP]:/home/student/
sudo scp -P [ssh-port] /etc/ipsec.d/certs/s1Cert.pem student@[S1-IP]:/home/student/
sudo mv ~/caCert.pem /etc/ipsec.d/cacerts/
sudo mv ~/s1Key.pem /etc/ipsec.d/private/ && sudo chmod 600 /etc/ipsec.d/private/s1Key.pem
sudo mv ~/s1Cert.pem /etc/ipsec.d/certs/
ls /etc/ipsec.d/cacerts/ /etc/ipsec.d/private/ /etc/ipsec.d/certs/Learning outcomes — by end of Day 3, students can…
Common issues and fixes
| Issue | Likely cause | Fix |
|---|---|---|
| ipsec pki --issue fails with "CA is not a CA" | --cakey is pointing to s3Key.pem (server key) instead of caKey.pem (CA key) | Always use caKey.pem for the --cakey argument. The caKey is what signs other certs — it must be the CA's private key, not the server's |
| ipsec pki --print shows wrong CN or missing SAN | Typo in --dn or --san argument during cert issuance | Regenerate the cert with the correct DN. The certificate cannot be edited after issuance — it must be re-issued |
| SCP fails — permission denied copying to /etc/ipsec.d/ | SCP lands in /home/student first, then must be moved with sudo | SCP to /home/student/ first. On S1: sudo mv ~/caCert.pem /etc/ipsec.d/cacerts/. Always chmod 600 private keys after moving |