BIO_F_SSL(3)
β¨ BIO_F_SSL(3) β SSL BIO β¨
okay bestie, you're reading the BIO_F_SSL(3) page from libssl/libcrypto, and it's giving βSSL but make it BIO.β We got a whole squad of functions here, so let's get into it π
πΈ NAME πΈ
The whole squad is: BIO_f_ssl, BIO_set_ssl, BIO_get_ssl, BIO_set_ssl_mode, BIO_set_ssl_renegotiate_bytes, BIO_get_num_renegotiates, BIO_set_ssl_renegotiate_timeout, BIO_new_ssl, BIO_new_ssl_connect, BIO_new_buffer_ssl_connect, BIO_ssl_copy_session_id, BIO_ssl_shutdown, and BIO_do_handshake β all here for the SSL BIO. Periodt.
π¦ SYNOPSIS π¦
library βlibsslβ libcrypto
#include <openssl/bio.h>
#include <openssl/ssl.h>
const BIO_METHOD *
BIO_f_ssl(void);
long
BIO_set_ssl(BIO *b, SSL *ssl, long c);
long
BIO_get_ssl(BIO *b, SSL *sslp);
long
BIO_set_ssl_mode(BIO *b, long client);
long
BIO_set_ssl_renegotiate_bytes(BIO *b, long num);
long
BIO_set_ssl_renegotiate_timeout(BIO *b, long seconds);
long
BIO_get_num_renegotiates(BIO *b);
BIO *
BIO_new_ssl(SSL_CTX *ctx, int client);
BIO *
BIO_new_ssl_connect(SSL_CTX *ctx);
BIO *
BIO_new_buffer_ssl_connect(SSL_CTX *ctx);
int
BIO_ssl_copy_session_id(BIO *to, BIO *from);
void
BIO_ssl_shutdown(BIO *bio);
long
BIO_do_handshake(BIO *b);
π DESCRIPTION π
BIO_f_ssl() hands you the SSL BIO method. Itβs a filter BIO β think of it as a little wrapper around the OpenSSL SSL routines that adds a BIO βflavorβ to SSL I/O. Cute, right? π
When you do I/O on an SSL BIO, it communicates using the SSL protocol with the SSLβs read and write BIOs. If the SSL connection is not established yet, it tries to establish one on the first I/O call. No cap.
If you append a BIO to an SSL BIO using BIO_push(3), that BIO is automatically used as the SSL BIOβs read and write BIOs.
Calling BIO_reset(3) on an SSL BIO closes down any current SSL connection by calling SSL_shutdown(3). Then BIO_reset(3) is sent to the next BIO in the chain; this will typically disconnect the underlying transport. After that, the SSL BIO is reset to the initial accept or connect state.
If the close flag is set when an SSL BIO is freed, then the internal SSL structure is also freed using SSL_free(3).
Hereβs the function-by-function tea β:
BIO_set_ssl()β sets the internal SSL pointer of BIObtossl, using the close flagc.BIO_get_ssl()β retrieves the SSL pointer of BIOb; after that you can manipulate it using the standard SSL library functions.BIO_set_ssl_mode()β sets the SSL BIO mode to client. Ifclientis1, client mode is set. Ifclientis0, server mode is set.BIO_set_ssl_renegotiate_bytes()β sets the renegotiate byte count tonum. When set, after everynumbytes of I/O (read and write) the SSL session is automatically renegotiated.nummust be at least512bytes.
π¨ bestie, yes,nummust be at least512bytes. That part is fr fr important.
BIO_set_ssl_renegotiate_timeout()β sets the renegotiate timeout toseconds. When the renegotiate timeout elapses, the session is automatically renegotiated.BIO_get_num_renegotiates()β returns the total number of session renegotiations due to I/O or timeout.BIO_new_ssl()β allocates an SSL BIO usingSSL_CTX ctxand using client mode ifclientis nonzero.BIO_new_ssl_connect()β creates a new BIO chain consisting of an SSL BIO (usingctx) followed by a connect BIO.BIO_new_buffer_ssl_connect()β creates a new BIO chain consisting of a buffering BIO, an SSL BIO (usingctx) and a connect BIO.BIO_ssl_copy_session_id()β copies an SSL session id between BIO chainsfromandto. It does this by locating the SSL BIOs in each chain and callingSSL_copy_session_id(3)on the internal SSL pointer.BIO_ssl_shutdown()β closes down an SSL connection on BIO chainbio. It does this by locating the SSL BIO in the chain and callingSSL_shutdown(3)on its internal SSL pointer.BIO_do_handshake()β attempts to complete an SSL handshake on the supplied BIO and establish the SSL connection. It returns1if the connection was established successfully. A zero or negative value is returned if the connection could not be established; the callBIO_should_retry(3)should be used for non blocking connect BIOs to determine if the call should be retried. If an SSL connection has already been established, this call has no effect.
When a chain containing an SSL BIO is copied with BIO_dup_chain(3), SSL_dup(3) is called internally to copy the SSL object from the existing BIO object to the new BIO object, and the internal data related to BIO_set_ssl_renegotiate_bytes() and BIO_set_ssl_renegotiate_timeout() is also copied.
SSL BIOs are exceptional in that if the underlying transport is non-blocking they can still request a retry in exceptional circumstances. Specifically this will happen if a session renegotiation takes place during a BIO_read(3) operation. One case where this happens is when step up occurs.
In OpenSSL 0.9.6 and later the SSL flag SSL_AUTO_RETRY can be set to disable this behaviour. In other words, when this flag is set an SSL BIO using a blocking transport will never request a retry.
Since unknown BIO_ctrl(3) operations are sent through filter BIOs, the server name and port can be set using BIO_set_conn_hostname(3) and BIO_set_conn_port(3) on the BIO returned by BIO_new_ssl_connect() without having to locate the connect BIO first. Lowkey convenient.
Applications do not have to call BIO_do_handshake() but may wish to do so to separate the handshake process from other I/O processing.
And just so you know: BIO_set_ssl(), BIO_get_ssl(), BIO_set_ssl_mode(), BIO_set_ssl_renegotiate_bytes(), BIO_set_ssl_renegotiate_timeout(), BIO_get_num_renegotiates(), and BIO_do_handshake() are implemented as macros. π
π SEE ALSO π
okay bestie, if you wanna go deeper (and you know you do π), go check these out:
BIO_new(3)β the whole how-to-make-a-BIO situation β¨ssl(3)β the SSL of it all, obvs π
π HISTORY π
ngl, this is the part where we stan the elders π«Ά β here's the whole timeline, and yes, every single version number matters, so don't skip:
BIO_f_ssl(),BIO_set_ssl(), andBIO_get_ssl()β first showed up in SSLeay 0.6.0. OG behaviour πBIO_set_ssl_mode(),BIO_new_ssl(), andBIO_ssl_copy_session_id()β first appeared in SSLeay 0.8.0. glow-up era β¨BIO_ssl_shutdown()andBIO_do_handshake()β first appeared in SSLeay 0.8.1. iconic arrivals π¦BIO_set_ssl_renegotiate_bytes(),BIO_get_num_renegotiates(),BIO_set_ssl_renegotiate_timeout(),BIO_new_ssl_connect(), andBIO_new_buffer_ssl_connect()β first appeared in SSLeay 0.9.0. the sequel that ate π₯
and then, the moment you've been waiting for: all these functions have been available since OpenBSD 2.4. literally vintage, main character energy, no cap π
so yeah, bestie β that's the whole page in one vibe check. every flag, every function, every version, every era. you're basically a BIO_f_ssl expert now ππ
πΈ mwah π β this one shipped from Debian, dated June 8, 2025, and it's the BIO_F_SSL(3) page. go forth and slay your TLS, queen π«Άπ
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2000, 2003, 2009, 2014-2016 The OpenSSL Project
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms