SkillPilotAI

Certificates and PKI

A certificate is a server's digital ID card: it binds a public key to a domain name and is signed by a trusted Certificate Authority. PKI (Public Key Infrastructure) is the whole system of Root CAs, Intermediates, leaf certificates, revocation and trust stores that lets a browser know it is talking to the real shop.lab.

133.1 Why is it used?

  • Encryption alone is not enough: an attacker on the same cafe Wi-Fi can claim to be shop.lab and encrypt with their own key, so your password goes to them.
  • The certificate proves the server's identity: it was issued by a CA the browser already trusts.
  • A certificate carries only the public key, never the private key.
  • mTLS extends this so the server can also verify the client (service mesh, zero trust).

133.2 How it works: the CA chain

  • Root CA: self-signed, private key kept offline, signs only Intermediate CAs; it lives in the browser/OS trust store.
  • Intermediate (Issuing) CA: signs server (leaf) certificates like shop.lab.
  • In the handshake the server sends its leaf + the Intermediate; the Root is already on the client.
  • The browser checks each signature with the issuer's public key until it reaches a trusted Root, then checks dates, hostname and revocation.
How the browser verifies the chain
  1. 1.Server sends Certificate (CN=shop.lab) + Intermediate (Issuing CA 1)

  2. 2.shop.lab <- Issuing CA 1: signature OK

  3. 3.Issuing CA 1 <- Root CA: signature OK

  4. 4.Root CA found in the trust store: chain complete

  5. 5.Check Not Before/Not After, hostname in SAN, revoked? (CRL/OCSP)

  6. 6.All pass -> lock icon; any fail -> red warning page

133.3 Important certificate fields

FieldMeaningshop.lab example
SubjectWhose certificate it isCN=shop.lab
IssuerWho signed itShop Lab Issuing CA 1
ValidityNot Before / Not AfterNov 9 2026 - Feb 7 2027 (90 days)
SANAll valid names; browsers check SAN, not CNDNS:shop.lab, DNS:www.shop.lab
Key Usage / EKUWhat the key is forDigital Signature, TLS Web Server Authentication
Basic ConstraintsIs it a CA?CA:FALSE
Authority Information AccessWhere to ask OCSPOCSP - URI:http://192.168.153.20:8888

133.4 Building a lab PKI with openssl

Terminal
# 1. Root CA: self-signed, 10 yearsopenssl req -x509 $EC -days 3650 \  -keyout root.key -out root.crt \  -subj "/C=IN/O=Shop Lab/CN=Shop Lab Root CA"# 2. Intermediate CA, signed by root, 5 yearsopenssl x509 -req -in inter.csr \  -CA root.crt -CAkey root.key -CAcreateserial \  -days 1825 -extfile inter.ext \  -out inter.crt 2>/dev/null# 3. shop.lab server cert (openssl ca), 90 daysopenssl ca -batch -config ca.cnf \  -extensions server_ext $D -notext \  -in $1.csr -out $1.crt 2>/dev/null# verifyopenssl verify -show_chain -CAfile root.crt \  -untrusted inter.crt shop.crt
Output
shop.crt: OKChain:depth=0: CN=shop.lab (untrusted)depth=1: C=IN, O=Shop Lab, CN=Shop Lab Issuing CA 1 (untrusted)depth=2: C=IN, O=Shop Lab, CN=Shop Lab Root CA
Terminal
openssl x509 -in shop.crt -noout -text \  -certopt no_pubkey,no_sigdump
Output
Serial Number: 4096 (0x1000)Issuer: C=IN, O=Shop Lab, CN=Shop Lab Issuing CA 1Validity  Not Before: Nov  9 03:48:54 2026 GMT  Not After : Feb  7 03:48:54 2027 GMTSubject: CN=shop.labX509v3 extensions:  X509v3 Basic Constraints: critical    CA:FALSE  X509v3 Key Usage: critical    Digital Signature  X509v3 Extended Key Usage:    TLS Web Server Authentication  X509v3 Subject Alternative Name:    DNS:shop.lab, DNS:www.shop.lab  Authority Information Access:    OCSP - URI:http://192.168.153.20:8888

133.5 Seeing the chain with openssl s_client

Terminal
openssl s_client -connect shop.lab:443 \  -servername shop.lab -CAfile root.crt \  -showcerts
Output
CONNECTED(00000003)depth=2 C=IN, O=Shop Lab, CN=Shop Lab Root CAverify return:1depth=1 C=IN, O=Shop Lab, CN=Shop Lab Issuing CA 1verify return:1depth=0 CN=shop.labverify return:1Certificate chain 0 s:CN=shop.lab   i:C=IN, O=Shop Lab, CN=Shop Lab Issuing CA 1 1 s:C=IN, O=Shop Lab, CN=Shop Lab Issuing CA 1   i:C=IN, O=Shop Lab, CN=Shop Lab Root CANew, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384Verify return code: 0 (ok)
  • -servername sets SNI; -CAfile root.crt trusts only the lab Root.
  • s: = subject, i: = issuer; each cert's issuer should be the next cert's subject.

133.6 When verification fails

ErrorCauseLab port
18 self-signed certificateSubject = issuer = shop.lab, no trusted CA signed it8441
20 unable to get local issuer certificateClient does not have the lab Root: chain reaches no trusted Root443 without -CAfile
21 unable to verify the first certificateServer sends only the leaf, not the Intermediate8442
10 certificate has expirednotAfter=Jan 1 00:00:00 2025 GMT has passed8443
62 hostname mismatchConnecting to wrong.lab; SAN has only shop.lab, www.shop.lab443 as wrong.lab
23 certificate revokedSerial 1001 is in the CRL (Key Compromise)8444
Terminal
openssl s_client -connect shop.lab:8441 \  -servername shop.lab -CAfile root.crtopenssl s_client -connect shop.lab:8443 \  -servername shop.lab -CAfile root.crtopenssl s_client -connect wrong.lab:443 \  -servername wrong.lab -CAfile root.crt \  -verify_hostname wrong.lab
Output
depth=0 CN=shop.labverify error:num=18:self-signed certificate 0 s:CN=shop.lab   i:CN=shop.labVerify return code: 18 (self-signed certificate) depth=0 CN=shop.labverify error:num=10:certificate has expirednotAfter=Jan  1 00:00:00 2025 GMTVerify return code: 10 (certificate has expired) depth=0 CN=shop.labverify error:num=62:hostname mismatchVerify return code: 62 (hostname mismatch)

133.7 Revocation: CRL vs OCSP

Revoking a leaked certificate
  1. 1.shop.lab private key leaks while the cert (serial 1001) is still valid

  2. 2.Issuing CA 1 revokes it and publishes it in the CRL

  3. 3.CRL way: client downloads the whole list and finds 1001 revoked

  4. 4.OCSP way: client asks the responder 192.168.153.20:8888 about serial 1001 only

  5. 5.Answer: good / revoked / unknown -> revoked: keyCompromise

PointCRLOCSP
What the client getsWhole list of revoked serialsStatus of one serial
FreshnessUntil Next Update (7 days in lab)Live answer from the responder
AnswerListed or notgood, revoked or unknown
openssl-crl_check -CRL issuing.crlopenssl ocsp -issuer -cert -url
Terminal
openssl crl -in issuing.crl -noout -textopenssl s_client -connect shop.lab:8444 \  -servername shop.lab -CAfile root.crt \  -crl_check -CRL issuing.crlopenssl x509 -in shop.crt -noout -ocsp_uriopenssl ocsp -issuer inter.crt -cert old.crt \  -url http://192.168.153.20:8888 -CAfile root.crt
Output
Revoked Certificates:    Serial Number: 1001        Revocation Date: Nov  9 03:48:55 2026 GMT            X509v3 CRL Reason Code:                Key Compromiseverify error:num=23:certificate revokedVerify return code: 23 (certificate revoked) http://192.168.153.20:8888Response verify OKshop.crt: goodResponse verify OKold.crt: revoked  Reason: keyCompromise  Revocation Time: Nov  9 03:48:55 2026 GMT

133.8 mTLS: certificates on both sides

mTLS between billing-service and the shop.lab API
  1. 1.billing-service 192.168.153.10 connects to shop.lab API 192.168.153.20:8445

  2. 2.Server sends its cert (shop.lab) and a CertificateRequest

  3. 3.Client sends its cert CN=billing-service, signed by the lab CA

  4. 4.Both verify the other's chain against the same Root

  5. 5.No client cert -> alert certificate required, connection refused

Terminal
openssl s_client -connect shop.lab:8445 \  -servername shop.lab -CAfile root.crt \  -cert client.crt -key client.key \  -cert_chain inter.crt
Output
# without a client cert:ssl3_read_bytes:tlsv13 alert certificate required# server log: peer did not return a certificate # with the cert (server log):depth=0 CN=billing-serviceverify return:1Client certificatesubject=CN=billing-serviceissuer=C=IN, O=Shop Lab, CN=Shop Lab Issuing CA 1CIPHER is TLS_AES_256_GCM_SHA384

133.9 Common mistakes

  • Server not sending the Intermediate: browsers cache/download it so the site looks fine, but openssl, curl and apps fail with error 21.
  • Lock icon = honest site: it only proves encryption and domain control; phishing sites get valid certs for free.
  • Thinking self-signed is always wrong: every Root CA is self-signed; the issue is only whether it is trusted.
  • Putting names only in CN: browsers check the SAN.
  • Forgetting to renew: 90-day certs expire fast (error 10).

133.10 Interview tips

  • Chain verification: verify each signature with the issuer's public key up to a Root in the trust store; check dates and Basic Constraints; hostname must match SAN; check revocation via CRL/OCSP.
  • Root keys stay offline; Intermediates do the daily signing, so a compromised Intermediate can be revoked without replacing the Root.
  • Know the openssl error numbers: 18 self-signed, 20 unknown issuer, 21 missing Intermediate, 10 expired, 62 hostname, 23 revoked.
  • mTLS = server also sends CertificateRequest and verifies the client cert: used in service meshes and zero trust.