SSL_CTX_SET_MODE(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸ’… SSL_CTX_SET_MODE πŸ’…

okay so this is a libssl / libcrypto page, section 3 of the manual, and bestie it's literally all about the ~mode~ flags β€” the little personality settings for your SSL engine. yes we're doing this, and yes it's gonna slay.


✨ SYNOPSIS ✨

library β€œlibssl” libcrypto #include <openssl/ssl.h>

long
SSL_CTX_set_mode(SSL_CTX *ctx, long mode);

long
SSL_set_mode(SSL *ssl, long mode);

long
SSL_CTX_clear_mode(SSL_CTX *ctx, long mode);

long
SSL_clear_mode(SSL *ssl, long mode);

long
SSL_CTX_get_mode(SSL_CTX *ctx);

long
SSL_get_mode(SSL *ssl);

🌸 DESCRIPTION 🌸

so here's the tea: SSL_CTX_set_mode() and SSL_set_mode() turn on whatever options are hiding inside the bitmask mode β€” for the ctx object or the ssl object respectively. and like, options that were already enabled before you called? they stay on. no takesies-backsies, we don't disable anything here.

SSL_CTX_clear_mode() and SSL_clear_mode() are the opposite vibe: they turn off the options contained in the bitmask mode for the ctx or ssl object.

SSL_CTX_get_mode() and SSL_get_mode() just hand you back a bitmask that represents all the options currently enabled for that ctx or ssl object. it's giving "what's your status rn" and honestly? iconic.

the following options are available, and yes we're going through every single one 🫢

  • SSL_MODE_ENABLE_PARTIAL_WRITE β€” allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success when just a single record has been written). when this is not set β€” which is the default β€” SSL_write(3) will only report success once the complete chunk was written. once SSL_write(3) returns with r, then r bytes have been successfully written and the next call to SSL_write(3) must only send the n βˆ’ r bytes left, imitating the behaviour of write(2). main character energy fr.
  • SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER β€” makes it possible to retry SSL_write(3) with a changed buffer location (the buffer contents must stay the same, no cap). this is not the default because they didn't want people out here with the misconception that non-blocking SSL_write(3) behaves like non-blocking write(2). it does not, bestie.
  • SSL_MODE_AUTO_RETRY β€” never bother the application with retries if the transport is blocking. like, ever. so if a renegotiation takes place during normal operation, a SSL_read(3) or SSL_write(3) would return with βˆ’1 and indicate the need to retry with SSL_ERROR_WANT_READ. in a non-blocking environment, applications must be prepared to handle incomplete read/write operations. in a blocking environment, applications are not always prepared to deal with read/write operations returning without success report. the flag SSL_MODE_AUTO_RETRY will cause read/write operations to only return after the handshake and successful completion. periodt.
  • SSL_MODE_RELEASE_BUFFERS β€” when we no longer need a read buffer or a write buffer for a given SSL, then release the memory we were using to hold it. using this flag can save around 34k per idle SSL connection πŸ”₯. heads up though: this flag has no effect on SSL v2 connections, or on DTLS connections. πŸ’€

πŸŽ€ RETURN VALUES πŸŽ€

SSL_CTX_set_mode(), SSL_set_mode(), SSL_CTX_clear_mode(), and SSL_clear_mode() return the new mode bitmask after adding or clearing mode.

SSL_CTX_get_mode() and SSL_get_mode() return the current bitmask. simple as that, no plot twist.


πŸ¦‹ SEE ALSO πŸ¦‹

ssl(3), SSL_CTX_ctrl(3), SSL_read(3), SSL_write(3)


πŸ‘‘ HISTORY πŸ‘‘

SSL_CTX_set_mode(), SSL_set_mode(), SSL_CTX_get_mode(), and SSL_get_mode() first appeared in OpenSSL 0.9.4 and have been available since OpenBSD 2.6. absolute veterans, we stan.

SSL_CTX_clear_mode() and SSL_clear_mode() first appeared in OpenSSL 0.9.8m and have been available since OpenBSD 4.9. late bloomers but they ate.

SSL_MODE_AUTO_RETRY was added in OpenSSL 0.9.6. ⭐


okay that's the whole page, you're officially educated πŸ’œ this cutie dropped on Debian, dated June 8, 2025 β€” go forth and set your modes, bestie 🧚✨

πŸ“¦ where this page comes from