BIO_F_SSL(3ossl)
π NAME π
Okay bestie, so this is the BIO_F_SSL(3ossl) manual page, and it's literally the whole SSL BIO saga, no cap. Buckle up π
Here's the full cast of characters (and yes, they all live on this one page, iykyk):
BIO_do_handshakeBIO_f_sslBIO_set_sslBIO_get_sslBIO_set_ssl_modeBIO_set_ssl_renegotiate_bytesBIO_get_num_renegotiatesBIO_set_ssl_renegotiate_timeoutBIO_new_sslBIO_new_ssl_connectBIO_new_buffer_ssl_connectBIO_ssl_copy_session_idBIO_ssl_shutdown
And the collective vibe? SSL BIO. That's it, that's the description. π
β¨ SYNOPSIS β¨
Like, here's what you actually type:
#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);
Every single one of those, exactly as written. Copy-paste is self care π«Ά
πΈ DESCRIPTION πΈ
The main character: BIO_f_ssl()
So BIO_f_ssl() hands you back the SSL BIO method. What even is that? It's a filter BIO β think of it as a cute little wrapper round the OpenSSL SSL routines that slaps an extra BIO "flavour" onto SSL I/O. It's giving β¨decorator patternβ¨ but make it TLS.
When you do I/O on an SSL BIO, it talks using the SSL protocol with the SSL's read and write BIOs. And here's the tea: if an SSL connection isn't established yet, it just attempts to establish one on the first I/O call. No setup era required, it just goes π
If you append a BIO to an SSL BIO using BIO_push(), it's automatically used as the SSL BIO's read and write BIOs. Automatic. Iconic. No notes.
Resetting + freeing (the cleanup era π§Ή)
Calling BIO_reset() on an SSL BIO closes down any current SSL connection by calling SSL_shutdown(). Then BIO_reset() gets sent to the next BIO in the chain β which will typically disconnect the underlying transport. After that, the SSL BIO is reset to the initial accept or connect state. So it's a full glow-up back to factory settings, basically.
And if the close flag is set when an SSL BIO is freed, then the internal SSL structure is also freed using SSL_free(). Important detail, don't sleep on it π₯
All the setters and getters, one by one
BIO_set_ssl()β sets the internal SSL pointer of SSL BIObtossl, using the close flagc.BIO_get_ssl()β retrieves the SSL pointer of SSL BIOb. Once you've got it, you can manipulate it with all the standard SSL library functions. Main character access unlocked πBIO_set_ssl_mode()β sets the SSL BIO mode toclient. Ifclientis1, client mode is set. Ifclientis0, server mode is set. Binary. Simple. We love a flag with commitment.BIO_set_ssl_renegotiate_bytes()β sets the renegotiate byte count of SSL BIObtonum. Once set, after everynumbytes of I/O (read and write), the SSL session is automatically renegotiated. Also:nummust be at least512bytes. Not a suggestion, an actual requirement, fr fr.BIO_set_ssl_renegotiate_timeout()β sets the renegotiate timeout of SSL BIObtoseconds. When the renegotiate timeout elapses, the session is automatically renegotiated. Clock's ticking bestie β°BIO_get_num_renegotiates()β returns the total number of session renegotiations due to I/O or timeout of SSL BIOb. Your receipts, quantified π§Ύ
The constructor girlies π
BIO_new_ssl()β allocates an SSL BIO using SSL_CTXctx, and uses client mode ifclientis non zero.BIO_new_ssl_connect()β creates a new BIO chain consisting of an SSL BIO (usingctx) followed by a connect BIO. Chain gang πBIO_new_buffer_ssl_connect()β creates a new BIO chain consisting of a buffering BIO, an SSL BIO (usingctx), and a connect BIO. Yes, three whole BIOs, she's stacked.
Chain surgery π§
BIO_ssl_copy_session_id()β copies an SSL session id between BIO chainsfromandto. How? By locating the SSL BIOs in each chain and callingSSL_copy_session_id()on the internal SSL pointer. Detective work, honestly.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()on its internal SSL pointer. Goodbye era π
BIO_do_handshake() β the moment of truth
BIO_do_handshake() attempts to complete an SSL handshake on the supplied BIO and establish the SSL connection. For non-SSL BIOs the connection is done typically at TCP level. And if domain name resolution yields multiple IP addresses, all of them are tried after connect() failures. She's persistent πͺ
- Returns
1if the connection was established successfully. - Returns a zero or negative value if the connection could not be established.
- For nonblocking connect BIOs, use
BIO_should_retry()to figure out whether the call should be retried. - If a connection has already been established, this call has no effect. Nothing to see here, move along π¦
π¦ NOTES π¦
SSL BIOs are exceptional β and not just in the "she's so brave" way. If the underlying transport is non blocking, they can still request a retry in exceptional circumstances. Specifically, this happens if a session renegotiation takes place during a BIO_read_ex() operation β and one case where that happens is when step up occurs.
You can set the SSL flag SSL_AUTO_RETRY to disable this behaviour. Meaning: when this flag is set, an SSL BIO using a blocking transport will never request a retry. Boundaries! We love to see them π
Now, since unknown BIO_ctrl() operations are sent through filter BIOs, you can set the server's name and port using BIO_set_host() on the BIO returned by BIO_new_ssl_connect() without having to locate the connect BIO first. Convenience queen π
Applications do not have to call BIO_do_handshake() β but they may wish to do so, to separate the handshake process from other I/O processing. Optional, but sometimes you want the handshake to have its own solo moment β¨
Heads up:BIO_set_ssl(),BIO_get_ssl(),BIO_set_ssl_mode(),BIO_set_ssl_renegotiate_bytes(),BIO_set_ssl_renegotiate_timeout(),BIO_get_num_renegotiates(), andBIO_do_handshake()are all implemented as macros. Surprise! They're not real functions, they're macros. Plot twist.
Also important, no cap: BIO_ssl_copy_session_id() is not currently supported on QUIC SSL objects and fails if called on such an object. So don't try it, bestie, she will not slay there π
β RETURN VALUES β
Here's the vibe check on what everything gives back:
BIO_f_ssl()returns the SSLBIO_METHODstructure. Simple, iconic, one job.BIO_set_ssl(),BIO_get_ssl(),BIO_set_ssl_mode(),BIO_set_ssl_renegotiate_bytes(),BIO_set_ssl_renegotiate_timeout()andBIO_get_num_renegotiates()return1on success, or a value which is less than or equal to0if an error occurred. (Yes, less than or equal to zero. Read it again, it's not just negative π)BIO_new_ssl(),BIO_new_ssl_connect()andBIO_new_buffer_ssl_connect()return a validBIOstructure on success, orNULLif an error occurred. Null check your constructors, besties, always.BIO_ssl_copy_session_id()returns1on success, or0on error β or if called on a QUIC SSL object. (Remember the QUIC thing? Yeah.0. That's the answer π₯)BIO_do_handshake()returns1if the connection was established successfully. A zero or negative value is returned if the connection could not be established.
okay so that's the whole setup β the functions, the flags, the return values, the warnings, all of it β but we are literally not even done yet, the examples are coming and they are LONG and they are GORGEOUS and you're gonna want to stick around for them π
π COPYRIGHT π
okay so the legal bit, and honestly bestie it's short and slays:
Copyright 2000-2023 The OpenSSL Project Authors. All Rights Reserved.
That's the whole copyright line, fr β 2000-2023, The OpenSSL Project Authors, all rights reserved, no notes. π
Now the license tea: this file is licensed under the Apache License 2.0 (yep, that's the "License" with a capital L β capitalisation matters, iykyk). And this part is a real one, not a vibe suggestion: you may not use this file except in compliance with the License. Like, that's the actual condition of using it. π
Want the full text? You can grab a copy in the file LICENSE in the source distribution, or online at:
https://www.openssl.org/source/license.html
That's it, that's the section β short, sweet, legally binding. π
β¨ and that's a wrap on BIO_F_SSL(3ossl), bestie β¨ this page is from OpenSSL 3.5.0, dated 2026-09-25 β go forth and filter your SSL BIOs responsibly, mwah π«Άπ
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms