SSL_NEW(3ossl)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 15.1

🌸 SSL_NEW(3ossl) β€” or: how to birth a whole TLS connection πŸ’…

okay so this is the 3ossl girlies' guide to making SSL objects. yes bestie, the manual page name is literally SSL_NEW(3ossl) and it covers SSL_dup, SSL_new, and SSL_up_ref β€” the creation trio. let's go πŸŽ€


✨ SYNOPSIS ✨

#include <openssl/ssl.h>

SSL *SSL_dup(SSL *s);
SSL *SSL_new(SSL_CTX *ctx);
int SSL_up_ref(SSL *s);

πŸ¦‹ DESCRIPTION πŸ¦‹

SSL_new() β€” the main character πŸ‘‘

SSL_new() creates a brand-new SSL structure, and like… you need this thing, it's literally what holds all the data for a TLS/SSL connection. no SSL struct, no connection, periodt.

the new structure inherits the settings of the underlying context ctx:

  • connection method
  • options
  • verification settings
  • timeout settings

an SSL structure is reference counted, iykyk. creating one for the first time bumps the reference count up by one ☝️. freeing it (with SSL_free) decrements it πŸ‘‡. and the second that reference count hits zero, any memory or resources allocated to the SSL structure get freed. bye bestie, gone, released 🫢

SSL_up_ref() β€” the hype girl πŸ“ˆ

SSL_up_ref() just increments the reference count for an existing SSL structure. that's it. that's the whole job. iconic honestly.

SSL_dup() β€” the clone saga 🧬

the function SSL_dup() creates and returns a new SSL structure from the same SSL_CTX that was used to create s. it additionally duplicates a subset of the settings in s into the new SSL object.

⚠️ for SSL_dup() to work, the connection MUST be in its initial state and MUST NOT have yet started the SSL handshake. no exceptions, no cap.

for connections that are not in their initial state, SSL_dup() just increments an internal reference count and returns the same handle. like, same object, different day πŸ’€. it may be possible to use SSL_clear(3) to recycle an SSL handle that isn't in its initial state for reuse, but fr fr this is best avoided. instead: save and restore the session if you want it, and construct a fresh handle for each connection. clean slate energy ✨

the subset of settings in s that get duplicated πŸŽ€

🚫 SSL_dup() is not supported on QUIC SSL objects and returns NULL if called on such an object. QUIC girlies, this one's not for you πŸ™ˆ

πŸ’– RETURN VALUES πŸ’–

the following return values can occur:

  • NULL β€” the creation of a new SSL structure failed 😭. check the error stack to find out the reason.
  • Pointer to an SSL structure β€” the return value points to an allocated SSL structure. slay ✨

and separately: SSL_up_ref() returns 1 for success and 0 for failure.


πŸ”₯ SEE ALSO πŸ”₯

SSL_free(3), SSL_clear(3), SSL_CTX_set_options(3), SSL_get_SSL_CTX(3), ssl(7)


Copyright 2000-2023 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>.


okay that's the whole page bestie, go forth and make your SSL objects responsibly πŸ§šπŸ’œ

~ with love, signed off from the 3ossl corner β€” OpenSSL 3.5.6, dated 2026-04-07 ~ 🌈

πŸ“¦ where this page comes from