SSL_CTX_SET_TLSEXT_STATUS_CB(3SSL)

πŸ“¦
version 4.0.3 Β· 3 versions
, in ubuntu stonking

πŸ’– SSL_CTX_SET_TLSEXT_STATUS_CB πŸ’–

okay bestie, gather round, because this is the OpenSSL 3SSL manual page for all the tlsext_status OCSP Certificate Status Request functions and it is lowkey the whole OCSP-stapling situation. no cap. πŸ¦‹

✨ NAME ✨

SSL_CTX_set_tlsext_status_cb, SSL_CTX_get_tlsext_status_cb, SSL_CTX_set_tlsext_status_arg, SSL_CTX_get_tlsext_status_arg, SSL_CTX_set_tlsext_status_type, SSL_CTX_get_tlsext_status_type, SSL_set_tlsext_status_type, SSL_get_tlsext_status_type, SSL_get_tlsext_status_ocsp_resp, SSL_set_tlsext_status_ocsp_resp, SSL_get0_tlsext_status_ocsp_resp_ex, SSL_set0_tlsext_status_ocsp_resp_ex β€” OCSP Certificate Status Request functions</p> πŸ’…

🌸 SYNOPSIS 🌸

#include <openssl/tls1.h>

long SSL_CTX_set_tlsext_status_cb(SSL_CTX *ctx, int (*callback)(SSL *, void *));
long SSL_CTX_get_tlsext_status_cb(SSL_CTX *ctx, int (**callback)(SSL *, void *));

long SSL_CTX_set_tlsext_status_arg(SSL_CTX *ctx, void *arg);
long SSL_CTX_get_tlsext_status_arg(SSL_CTX *ctx, void **arg);

long SSL_CTX_set_tlsext_status_type(SSL_CTX *ctx, int type);
long SSL_CTX_get_tlsext_status_type(SSL_CTX *ctx);

long SSL_set_tlsext_status_type(SSL *s, int type);
long SSL_get_tlsext_status_type(SSL *s);

long SSL_get_tlsext_status_ocsp_resp(ssl, unsigned char **resp);
long SSL_set_tlsext_status_ocsp_resp(ssl, unsigned char *resp, int len);

long SSL_get0_tlsext_status_ocsp_resp_ex(ssl, STACK_OF(OCSP_RESPONSE) **resp);
long SSL_set0_tlsext_status_ocsp_resp_ex(ssl, STACK_OF(OCSP_RESPONSE) *resp);

πŸŽ€ DESCRIPTION πŸŽ€

so basically. a client application can be like "hey server, pls send back some OCSP status response(s)" β€” that's the thing we call OCSP stapling, and it is iconic. to do the thing, the client should call SSL_CTX_set_tlsext_status_type() before creating any SSL objects. alternatively an application can call SSL_set_tlsext_status_type() on one individual SSL object before the handshake starts. rn the only supported type is TLSEXT_STATUSTYPE_ocsp, and that's the value you pass in the type argument, periodt. calling SSL_CTX_get_tlsext_status_type() hands you back the type TLSEXT_STATUSTYPE_ocsp that was previously set via SSL_CTX_set_tlsext_status_type(), or -1 if it was never set. πŸ™ˆ

for TLS versions before 1.3, the server only sends back a single OCSP status response. TLS 1.3 said "no ❀️, we can do better" and specifies that the server can send OCSP status responses for the whole chain β€” that's OCSP multi-stapling bestie, we love growth. ✨

the client should additionally provide a callback function that decides what to do with the returned OCSP response, by calling SSL_CTX_set_tlsext_status_cb(). that callback's whole job is to figure out whether the returned OCSP response(s) are acceptable or not. the callback gets passed, as its argument, the value previously set via a call to SSL_CTX_set_tlsext_status_arg(). ⚠️ heads up though: the callback will not be called in the event of a handshake where session resumption occurs β€” because there are literally no Certificates exchanged in such a handshake. the callback you previously set via SSL_CTX_set_tlsext_status_cb() can be retrieved by calling SSL_CTX_get_tlsext_status_cb(), and the argument by calling SSL_CTX_get_tlsext_status_arg(). cute, symmetric, obsessed.

on the client side, SSL_get_tlsext_status_type() can be used to figure out whether the client previously called SSL_set_tlsext_status_type(). it returns TLSEXT_STATUSTYPE_ocsp if it was called, or -1 otherwise. on the server side, SSL_get_tlsext_status_type() tells you whether the client requested OCSP stapling. if the client requested it, this function returns TLSEXT_STATUSTYPE_ocsp, or -1 otherwise. same function, two vibes, iykyk. πŸ’…

a single response returned by the server (TLS < 1.3) can be obtained via a call to SSL_get_tlsext_status_ocsp_resp(). the value *resp gets updated to point to the OCSP response data, and the return value is the length of that data. typically a callback would grab an OCSP_RESPONSE object from this data via a call to d2i_OCSP_RESPONSE(). if the server hasn't provided any response data then *resp will be NULL and the return value from SSL_get_tlsext_status_ocsp_resp() will be -1. 😭

a server application must also call SSL_CTX_set_tlsext_status_cb() if it wants to be able to provide clients with a (single) OCSP response for the server certificate. typically the server callback would obtain the server certificate that's being sent back to the client via a call to SSL_get_certificate(); retrieve the related OCSP response to be sent back; and then set that response data by calling SSL_set_tlsext_status_ocsp_resp(). a pointer to the response data should go in the resp argument, and the length of that data should be in the len argument. 🫢 and listen: the ownership of the data is transferred to the ssl object. it's not yours anymore bestie, it moved out.

in the case of multi-stapling, the responses the server should return can be obtained via a call to SSL_get0_tlsext_status_ocsp_resp_ex(). the value *resp gets updated to point to the OCSP response stack, and the return value is the number of responses on the stack. the OCSP responses on the stack are expected to be in the same order as the certificates in the chain. if there's no OCSP response available for a certificate in the chain, a NULL element in the stack represents that β€” representation, we love to see it. typically a callback would obtain an OCSP_RESPONSE object from the stack via a call to sk_OCSP_RESPONSE_pop. if the server hasn't provided any response data then *resp will be NULL and the return value from SSL_get0_tlsext_status_ocsp_resp_ex() will be -1. πŸ’€

a server application must also call SSL_CTX_set_tlsext_status_cb() if it wants to be able to provide clients with OCSP Certificate Status responses, where TLS 1.3 allows for multi-stapling, i.e., providing responses for all certificates in the chain of the server certificate (excluding the root CA certificate). the certificates sent back to the client, and for which OCSP response(s) should be acquired, could be obtained via a call to SSL_get_certificate() resp. SSL_get0_chain_certs(). OCSP response(s) are then set by calling SSL_set0_tlsext_status_ocsp_resp_ex(). a stack of OCSP responses should be provided in the resp argument. the OCSP responses on the stack are expected to be in the same order as the certificate in the chain. if no OCSP response is available for a certificate in the chain, a NULL element in the stack will represent this. 🌈


⭐ RETURN VALUES ⭐

the callback, when used on the client side, should return a negative value on error; 0 if the response is not acceptable (in which case the handshake will fail, noooo) or a positive value if it is acceptable. πŸ’–

the callback, when used on the server side, should return with either SSL_TLSEXT_ERR_OK (meaning the OCSP response that has been set should be returned), SSL_TLSEXT_ERR_NOACK (meaning an OCSP response should not be returned) or SSL_TLSEXT_ERR_ALERT_FATAL (meaning a fatal error has occurred). pick your fighter. πŸ‘‘

SSL_CTX_set_tlsext_status_cb(), SSL_CTX_set_tlsext_status_arg(), SSL_CTX_set_tlsext_status_type(), SSL_set_tlsext_status_type(), SSL_set_tlsext_status_ocsp_resp() return 0 on error or 1 on success. SSL_set0_tlsext_status_ocsp_resp_ex() will return always 1 β€” yes, always, it said what it said.

SSL_CTX_get_tlsext_status_type() returns the value previously set by SSL_CTX_set_tlsext_status_type(), or -1 if not set.

SSL_get_tlsext_status_ocsp_resp() returns the length of the OCSP response data or -1 if there is no OCSP response data.

SSL_get0_tlsext_status_ocsp_resp_ex() returns the number of the OCSP responses on the stack or -1 if there is no OCSP response data.

SSL_get_tlsext_status_type() returns TLSEXT_STATUSTYPE_ocsp on the client side if SSL_set_tlsext_status_type() was previously called, or on the server side if the client requested OCSP stapling. otherwise -1 is returned. ✨


πŸ¦‹ SEE ALSO πŸ¦‹


πŸ’œ HISTORY πŸ’œ

  • the SSL_get_tlsext_status_type(), SSL_CTX_get_tlsext_status_type() and SSL_CTX_set_tlsext_status_type() functions were added in OpenSSL 1.1.0. ⭐
  • the SSL_get0_tlsext_status_ocsp_resp_ex() and SSL_set0_tlsext_status_ocsp_resp_ex() macros were added in OpenSSL 3.6. πŸ”₯

Copyright 2015-2025 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


and that's the whole page bestie, you ate πŸ’… this was OpenSSL 4.0.3, dated 2026-09-29, and honestly? main character energy from start to finish. go staple some OCSP responses, you've got this πŸŽ€βœ¨

πŸ“¦ where this page comes from