What is OCSP stapling?

4 min readUpdated

OCSP stapling is a TLS server handing the client a signed, recent answer to the question "has this certificate been revoked?" along with the certificate itself, so the client need not ask anyone else. Stapling is the status_request extension of RFC 6066 [2][4].

OCSP, the Online Certificate Status Protocol of RFC 6960, is how that question is asked: a client sends the issuing authority or a responder an identifier of the certificate and gets back a signed status [1]. Both share one entry in this SSL and TLS glossary, since stapling changes only who asks.

Status
good, revoked or unknown [1]
Signed by
the issuing authority, a responder it designated, or one the client trusts [1]
Must-staple
a certificate extension that makes a staple expected, RFC 7633 [4]

How it works

Without stapling, a client that checks status asks the responder named in the certificate and holds off accepting the certificate until the answer arrives [1][6].

With stapling, the client puts status_request in its ClientHello, and a server that agrees fetches the answer itself and sends the complete OCSP response with its certificate [2]. In TLS 1.2 and earlier it is a separate CertificateStatus message; in TLS 1.3 it sits inside the certificate entry it describes (RFC 9846 §4.5.1.1) [3]. RFC 6066 allows a single response [2]; RFC 6961 added an extension covering intermediates too [5], deprecated by RFC 9846 [3].

The server cannot write a favourable answer for itself, because the response is signed by the authority or a responder the client accepts [1]. Each response records when its status was known to be correct [1]. In a test for this page on OpenSSL 3.0.13, changing one digit of a saved response made verification fail: Response Verify Failure.

Why it matters

OCSP stapling removes a third-party connection from the TLS handshake, and RFC 7633 lists what that costs: privacy, performance and reliability [4].

  • Privacy. The request identifies the certificate [1], so an OCSP responder asked by every visitor learns which site each one is checking.

  • Performance. RFC 6066 describes the extension as saving round trips and resources [2].

  • Reliability. A client checking on its own waits for the responder [1], and RFC 7633 treats blocking the OCSP response as a denial of service against the client [4].

When the staple is missing or wrong

A connection without a staple is not insecure for that reason alone. A server may skip it even after agreeing to send one [2], and a client cannot tell a server without the feature from one knowingly withholding status on an invalid certificate [4].

Must-staple closes that gap: with the TLS Feature extension set to status_request, a client can fail at once when no staple comes [4].

A wrong staple is worse than none. A client that finds the stapled response unsatisfactory must abort the handshake with a fatal alert [2]; browser error messages are sorted in the errors section.

A staple also needs an authority that answers OCSP, which the CA/Browser Forum Baseline Requirements call an "optional OCSP capability" [6]. Let's Encrypt does not run one for its certificates: in a Let's Encrypt certificate we checked, Authority Information Access listed only the issuer certificate's address, beside a CRL distribution point [8], and the authority publishes revocation through CRLs [9]. For such a certificate a server has no OCSP answer to staple.

openssl s_client -status asks for status and prints any response [7]; on a test server for this page that staples:

$ openssl s_client -connect "$HOST" -status </dev/null | grep -E 'OCSP response:|Cert Status'
OCSP response:
    Cert Status: good

Without a staple, it prints OCSP response: no response sent.

How to turn on OCSP stapling

First check that there is something to staple. openssl x509 -in cert.pem -noout -ocsp_uri prints the responder address from Authority Information Access; in our check it printed an http:// address for a certificate from an authority that runs OCSP and nothing for the Let's Encrypt certificate [12]. With no address there is no response to fetch, whatever the server is told.

OCSP stapling in nginx

ssl_stapling on turns it on. nginx needs the certificate of the issuer, so either the ssl_certificate file includes the intermediate or the issuer goes into ssl_trusted_certificate, and a resolver to look up the responder's host name. ssl_stapling_verify on makes nginx check each response, which needs the issuer, the intermediates and the root in ssl_trusted_certificate [10].

ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/ssl/example.com/chain-with-root.pem;
resolver 192.0.2.1;

OCSP stapling in Apache

SSLUseStapling on turns it on, and a stapling cache is mandatory: SSLStaplingCache goes in the server config, outside any virtual host [11].

SSLStaplingCache shmcb:/var/run/ocsp(128000)
<VirtualHost *:443>
    SSLUseStapling on
</VirtualHost>

Reload, then run the openssl s_client -status check above from another machine: Cert Status: good means the staple arrives.

Revocation and the CRL are on the certificate revocation page, the handshake on the TLS handshake page. X.509 and certificate transparency have their own entries here.

FAQ

Does OCSP stapling work with Let's Encrypt certificates?

No. Let's Encrypt certificates name no OCSP responder, and the authority publishes revocation through CRLs, so there is no response for a server to fetch and staple.

How do I enable OCSP stapling in nginx?

Set ssl_stapling on, make the issuer certificate known through the certificate chain or ssl_trusted_certificate, and set a resolver for the responder's host name. ssl_stapling_verify on also checks each response.

How do I enable OCSP stapling in Apache?

Configure SSLStaplingCache in the server config and set SSLUseStapling on. A stapling cache is mandatory for OCSP stapling in Apache.

Sources

  1. RFC 6960, X.509 Internet Public Key Infrastructure Online Certificate Status Protocol - OCSP: §2, §2.1, §2.2, §2.4.

  2. RFC 6066, Transport Layer Security (TLS) Extensions: Extension Definitions, §8.

  3. RFC 9846, The Transport Layer Security (TLS) Protocol Version 1.3, §4.5.1.1.

  4. RFC 7633, X.509v3 Transport Layer Security (TLS) Feature Extension, §3.

  5. RFC 6961, The Transport Layer Security (TLS) Multiple Certificate Status Request Extension, Abstract.

  6. CA/Browser Forum Baseline Requirements, §4.10.2, §7.1.2.7.7.

  7. OpenSSL 3.0 manual: openssl-s_client, option -status; openssl-s_server, option -status_file.

  8. Our check: a Let's Encrypt certificate issued by the YE2 intermediate, read with OpenSSL 3.0.13 (openssl x509 -ext authorityInfoAccess,crlDistributionPoints); the OCSP host names r10.o.lencr.org, r11.o.lencr.org and e5.o.lencr.org did not resolve.

  9. Let's Encrypt, Revoking Certificates: revocation information published in Certificate Revocation Lists (CRLs).

  10. nginx documentation, Module ngx_http_ssl_module: ssl_stapling, ssl_stapling_verify, ssl_trusted_certificate.

  11. Apache HTTP Server 2.4 documentation, mod_ssl: SSLUseStapling, SSLStaplingCache.

  12. Our check: openssl x509 -noout -ocsp_uri (OpenSSL 3.0.13) on the Let's Encrypt certificate of item 8 and on a certificate from another public authority.