SkillPilotAI

openssl (s_client, s_server, x509, req, verify, ciphers, ocsp, s_time, genpkey, pkcs12) (5/5)

The last openssl part: DH/DHX parameters with genpkey, the OCSP client (build, send and verify a revocation-status request), running your own OCSP responder, and pkcs12 to pack a certificate, key and chain into one password-protected file that Windows and Java import directly.

174.1 Where it runs and today's lab

  • Linux: apt/dnf openssl (usually preinstalled); macOS: brew install openssl@3 (built-in is LibreSSL); Windows: Git for Windows or winget ShiningLight.OpenSSL.Light.
  • Lab: 2x Alpine 3.20 + OpenSSL 3.3.7 on 192.168.194.0/24: lab-ocsp 192.168.194.10 (responder) and n174-client 192.168.194.20.

174.2 genpkey: DH and DHX parameters

Terminal
timeout 60 openssl genpkey -genparam \  -algorithm DH \  -pkeyopt dh_paramgen_prime_len:1024 \  -out dh1024.pemopenssl pkeyparam -in dh1024.pem -noout -textopenssl genpkey -genparam -algorithm DH \  -pkeyopt group:ffdhe2048 -out ffdhe.pemopenssl pkeyparam -in ffdhe.pem -noout -textopenssl genpkey -genparam -algorithm DHX \  -pkeyopt dh_rfc5114:2 -out x942.pemopenssl pkeyparam -in x942.pem -noout -text
Output
........................................+.......took 19sDH Parameters: (1024 bit)P:    00:95:33:5d:ec:bf:03:ff:0b:8d:d7:15:94:4a:9d:    ...G:    2 (0x2)recommended-private-length: 175 bitsDH Parameters: (2048 bit)GROUP: ffdhe2048DH Parameters: (2048 bit)GROUP: dh_2048_224
  • Generating your own safe prime is slow (19 s for only 1024 bits); a named group like ffdhe2048 is instant because the prime is fixed.
  • DHX (X9.42) uses the RFC 5114 groups: dh_rfc5114:2 = dh_2048_224, group:dh_2048_256.
  • Other options: group:ffdhe3072..8192, modp_1536..8192, pbits/qbits, type (generator, fips186_4...), safeprime-generator, hexseed (testing only).

174.3 How OCSP works

OCSP: client asks, responder gives a signed answer
  1. 1.n174-client wants to know if shop.lab's cert is revoked

  2. 2.POST / HTTP/1.0 to lab-ocsp:8888: issuer hash + serial 1000 + nonce

  3. 3.Responder looks up the serial in the CA index file

  4. 4.Returns a signed response: good / revoked / unknown, Next Update +1 min

  5. 5.Client verifies the signature first: Response verify OK, then trusts the status

174.4 ocsp client: building the request

Terminal
openssl ocsp -issuer inter.crt \  -cert good.crt -reqout req.deropenssl ocsp -reqin req.der -req_textopenssl ocsp -issuer inter.crt \  -cert good.crt -no_nonce -reqout req2.derls -l req.der req2.der
Output
OCSP Request Data:    Version: 1 (0x0)    Requestor List:        Certificate ID:          Hash Algorithm: sha1          Serial Number: 1000    Request Extensions:        OCSP Nonce:            0410E8979D5C33E50DC134E9946B6709EC6A-rw-r--r-- 1 root root 106 Nov  9 09:33 req.der-rw-r--r-- 1 root root  69 Nov  9 09:33 req2.der
  • The request holds the issuer hashes, the serial and a random nonce (stops replay); -no_nonce drops it (106 to 69 bytes).
  • -serial N builds a request from just a serial; -signer/-signkey sign the request; -sha256 changes the cert-ID digest (default SHA-1).

174.5 ocsp client: sending and output

Terminal
U=http://lab-ocsp:8888V="-CAfile root.crt -verify_other signer.pem"openssl ocsp -issuer inter.crt \  -cert good.crt -url $U $V \  -resp_text -respout good.deropenssl ocsp -issuer inter.crt \  -cert revoked.crt -url $U $Vopenssl ocsp -issuer inter.crt \  -serial 0x9999 -url $U $V
Output
Response verify OK    OCSP Response Status: successful (0x0)    Responder Id: CN = lab-ocsp signer    Cert Status: good    This Update: Nov  9 09:33:32 2026 GMT    Next Update: Nov  9 09:34:32 2026 GMTgood.crt: goodResponse verify OKrevoked.crt: revoked    Reason: keyCompromise    Revocation Time: Nov  9 09:32:28 2026 GMTResponse verify OK0x9999: unknown
StatusMeaning
goodSerial is in the index as valid (V)
revokedSerial is marked R, with reason and time
unknownResponder does not know this serial
  • -respout saves the response; -respin re-checks it later without the network.
  • -host/-path instead of -url, -header adds an HTTP header, -timeout for slow responders, -proxy/-no_proxy for corporate proxies.

174.6 ocsp client: verifying the response

OptionsResult
-CAfile root.crtResponse Verify Failure: signer certificate not found (responder used -resp_no_certs)
-CAfile root.crt -verify_other signer.pemResponse verify OK
-CAfile fake-root.crt -verify_other signer.pemResponse Verify Failure (but good.crt: good still printed!)
-VAfile ocsp.crtResponse verify OK (responder cert trusted directly)
fake-root + -no_cert_verifyResponse verify OK: signer chain never checked
Terminal
V="-CAfile root.crt -no_nonce"C="-issuer inter.crt -cert good.crt"openssl ocsp -respin good.der $C $V \  -VAfile ocsp.crt -validity_period 0openssl ocsp $C -url http://lab-ocsp:8889 \  $V -respout age.dersleep 3openssl ocsp -respin age.der $C $V \  -status_age 2
Output
Response verify OKgood.crt: WARNING: Status times invalid.error:1380007D:OCSP routines:OCSP_check_validity:status expiredgood...good.crt: WARNING: Status times invalid.error:1380007F:OCSP routines:OCSP_check_validity:status too old
  • Default -validity_period gives 300 s clock tolerance, so a just-expired Next Update still passes; 0 gives status expired.
  • -status_age N checks responses without Next Update (port 8889): 3 s old with N=2 gives status too old.
  • -trust_other, -noverify, -no_signature_verify, -no_cert_checks: testing only. The 30 standard verify options (-attime, -purpose, -verify_depth...) apply to the signer's chain.

174.7 Running an OCSP responder

Terminal
cat db/index.txtopenssl ocsp -index db/index.txt \  -port 8888 -CA inter.crt \  -rsigner ocsp.crt -rkey ocsp.key \  -nmin 1 -nrequest 30 -resp_no_certs
Output
V 270207093228Z         1000 unknown /CN=shop.labR 270207093228Z 261109093228Z,keyCompromise                        1001 unknown /CN=shop.labV 270207093228Z         1002 unknown                        /CN=lab-ocsp signerACCEPT 0.0.0.0:8888 PID=152ocsp: waiting for OCSP client connections...ocsp: received request, 1st line: POST / HTTP/1.0ocsp: sending response, 1st line: HTTP/1.0 200 OK
OptionMeaning
-indexCA index file: V = valid, R = revoked
-CACertificate of the issuer of those certs
-rsigner / -rkeyOCSP signer cert and key that sign responses
-nmin / -ndaysNext Update this many minutes / days ahead
-nrequest NExit after N requests (next call: Connection refused)
-resp_no_certsDo not include the signer cert in responses
-reqin / -respoutLocal mode without a port (like a CGI script)
-rmd / -rcid / -multi / -badsigDigest, cert-ID digest, child processes, corrupt sig (test)
  • Local mode with -ndays 1 gave Next Update: Nov 10 09:33:44 2026 GMT, a full day after This Update.
  • Providers: -provider default|legacy|fips, -provider-path, -propquery.

174.8 pkcs12: export

Terminal
openssl pkcs12 -export -inkey good.key \  -in good.crt -certfile inter.crt \  -name shop.lab -passout pass:lab \  -out shop.p12openssl pkcs12 -in shop.p12 -info -nokeys \  -passin pass:lab -out certs.pemgrep -E 'friendlyName|subject' certs.pem
Output
MAC: sha256, Iteration 2048MAC length: 32, salt length: 8PKCS7 Encrypted data: PBES2, PBKDF2,  AES-256-CBC, Iteration 2048, PRF hmacWithSHA256Certificate bagCertificate bagPKCS7 DataShrouded Keybag: PBES2, PBKDF2, AES-256-CBC, ...    friendlyName: shop.labsubject=CN=shop.labsubject=O=Shop Lab, CN=Shop Lab Issuing CA 1
Export variantEncryption / MACNote
default (OpenSSL 3)AES-256-CBC, MAC sha256Modern, recommended
-legacy40-bit RC2 certs, 3DES key, MAC sha1For old software; OpenSSL 3 cannot read it without -legacy (unsupported RC2-40-CBC)
-keypbe AES-128-CBC -certpbe NONE -macalg sha512AES-128 key, plain certs, MAC sha512Custom choice
  • -chain -CAfile builds and adds the full chain; -caname names CA certs; -iter raises the iteration count; -CSP/-LMK/-keyex are Microsoft-only.

174.9 pkcs12: parsing and general options

Terminal
openssl pkcs12 -in shop.p12 -clcerts \  -nokeys -passin pass:lab \  | openssl x509 -noout -subjectopenssl pkcs12 -in shop.p12 -cacerts \  -nokeys -passin pass:lab \  | openssl x509 -noout -subjectopenssl pkcs12 -in shop.p12 -noout \  -passin pass:wrong
Output
subject=CN=shop.labsubject=O=Shop Lab, CN=Shop Lab Issuing CA 1Mac verify error: invalid password?
  • -clcerts = only the leaf, -cacerts = only CA certs, -nokeys / -nocerts leave out the key / certs.
  • A wrong password fails at the MAC integrity check first (Mac verify error); -noout just checks the file.
  • -aes256 etc. encrypt the extracted key; -noenc (old -nodes) writes it in plain text: only on a secure machine. -twopass uses separate MAC and encryption passwords.

174.10 Common mistakes

  • Trusting good when the line above says Response Verify Failure: it could be a fake responder.
  • Using -noverify / -no_cert_verify in production: any signer is accepted.
  • Generating custom DH primes when ffdhe2048 is ready and safe.
  • Exporting with -legacy for modern systems, or extracting keys with -noenc on a shared machine.

174.11 Interview tips

  • OCSP vs CRL: CRL downloads the whole revoked list; OCSP asks the live status of one cert, signed by the responder, nonce stops replay.
  • OCSP stapling: the server itself hands the signed OCSP response over in the TLS handshake.
  • Responder needs -index, -CA, -rsigner, -rkey.
  • PKCS#12 (.p12/.pfx) = cert + key + chain in one password-protected file for Windows/Java.