SSL_CTX_SET_TLSEXT_STATUS_CB(3ossl)
π SSL_CTX_SET_TLSEXT_STATUS_CB(3ossl) β the OCSP stapling glow-up
okay so this is an OpenSSL manual page, bestie, and it's all about OCSP Certificate Status Request functions. Yes, that's a mouthful. It's giving "I have ten functions and one very specific job" and honestly? Iconic.
The whole squad is: 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. That's ten. Ten besties. We love a full roster. π«Ά
β¨ 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);
πΈ DESCRIPTION πΈ
sooo, picture this: a client application wants the server to send back an OCSP status response β you may know it by its stage name, OCSP stapling π
β and to make that happen, the client should call SSL_CTX_set_tlsext_status_type() before any SSL objects get created. Timing matters, bestie. Alternatively, an application can call SSL_set_tlsext_status_type() on one individual SSL object, as long as it's prior to the start of the handshake.
Currently the only supported type is TLSEXT_STATUSTYPE_ocsp, and that's the value you pass in the type argument. No other options, no secret menu. π
Calling SSL_CTX_get_tlsext_status_type() will return the type TLSEXT_STATUSTYPE_ocsp that was previously set via SSL_CTX_set_tlsext_status_type(), or -1 if not set. That's it, that's the vibe.
π the callback situation
The client should additionally provide a callback function to decide what to do with the returned OCSP response, by calling SSL_CTX_set_tlsext_status_cb(). That callback's whole main character job is to determine whether the returned OCSP response is acceptable or not.
The callback will be passed, as an argument, the value previously set via a call to SSL_CTX_set_tlsext_status_arg().
β οΈ heads up: the callback will not be called in the event of a handshake where session resumption occurs β because there are no Certificates exchanged in such a handshake. That's literally the reason. π
The callback previously set via SSL_CTX_set_tlsext_status_cb() can be retrieved by calling SSL_CTX_get_tlsext_status_cb(), and the argument comes back via SSL_CTX_get_tlsext_status_arg(). Get into it. β¨
π¦ client side vs server side (the crossover episode)
On the client side, SSL_get_tlsext_status_type() can be used to determine whether the client has previously called SSL_set_tlsext_status_type(). It will return TLSEXT_STATUSTYPE_ocsp if it has been 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, different lore. π
π getting the response back
The response returned by the server can be obtained via a call to SSL_get_tlsext_status_ocsp_resp(). The value *resp will be updated to point to the OCSP response data, and the return value will be the length of that data.
Typically a callback would obtain an OCSP_RESPONSE object from this data via a call to the d2i_OCSP_RESPONSE() function.
If the server has not provided any response data, then *resp will be NULL and the return value from SSL_get_tlsext_status_ocsp_resp() will be -1. Sad but true.
π server girlies, this part's for you
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. Non-negotiable, fr fr.
Typically the server callback would:
- obtain the server certificate that is being sent back to the client via a call to
SSL_get_certificate(); - obtain the 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 be provided in the resp argument, and the length of that data should be in the len argument. Don't mix 'em up. π
β RETURN VALUES β
The callback, when used on the client side, should return:
- a negative value on error;
0if the response is not acceptable (in which case the handshake will fail β yes, actually fail, no cap);- 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 that the OCSP response that has been set should be returned;SSL_TLSEXT_ERR_NOACKβ meaning that an OCSP response should not be returned;- or
SSL_TLSEXT_ERR_ALERT_FATALβ meaning that a fatal error has occurred. π
π the setters and getters
SSL_CTX_set_tlsext_status_cb(), SSL_CTX_set_tlsext_status_arg(), SSL_CTX_set_tlsext_status_type(), SSL_set_tlsext_status_type() and SSL_set_tlsext_status_ocsp_resp() return 0 on error or 1 on success. Classic.
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_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. Periodt. π
π§ 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. They're not new new, but they're still serving.
π COPYRIGHT π
Copyright 2015-2016 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>.
π that's the whole page, bestie π β this masterpiece is from OpenSSL 3.5.6, dated 2026-04-0, and it's the SSL_CTX_SET_TLSEXT_STATUS_CB(3ossl) manual page. go forth and staple your OCSP. π¦β¨
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms