D2I_SSL_SESSION(3SSL)

πŸ’– d2i_SSL_SESSION β€” the OpenSSL manual, bestie edition πŸ’–

okay so this page lives in section 3SSL of the OpenSSL manual and it's literally all about turning SSL_SESSION objects into ASN1 bytes and back again. bestie, it's giving serialization but make it ✨TLS✨.


✨ NAME ✨

d2i_SSL_SESSION, d2i_SSL_SESSION_ex, i2d_SSL_SESSION β€” convert an SSL_SESSION object from/to ASN1 representation πŸ¦‹

no cap, that's the whole vibe. one direction encodes, the other direction decodes, and they're both obsessed with ASN1.


🌸 SYNOPSIS 🌸

like always, you gotta pull in the header first:

#include <openssl/ssl.h>

and then here are the three little icons themselves, exactly as they appear:

SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp,
                             long length);
SSL_SESSION *d2i_SSL_SESSION_ex(SSL_SESSION **a, const unsigned char **pp,
                                long length, OSSL_LIB_CTX *libctx,
                                const char *propq);
int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp);

πŸ‘‘ DESCRIPTION πŸ‘‘

these functions decode and encode an SSL_SESSION object. that's it, that's the main character energy. πŸ’…

for the deets on how the encoding actually works, go peek at d2i_X509(3) β€” it's the ASN1 lore keeper.

🚨 okay serious moment, bestie, listen up: SSL_SESSION objects keep internal link information about the session cache list, when being inserted into one SSL_CTX object's session cache. so one SSL_SESSION object, regardless of its reference count, must therefore only be used with one SSL_CTX object (and the SSL objects created from this SSL_CTX object). like, one session, one SSL_CTX, no sharing, no polyamory. that's the rule. periodt.

πŸ’€ RETURN VALUES πŸ’€

  • d2i_SSL_SESSION() and d2i_SSL_SESSION_ex() return a pointer to the newly allocated SSL_SESSION object. πŸŽ€ and if it goes wrong? in case of failure the NULL-pointer is returned and the error message can be retrieved from the error stack. so go check the stack, she's holding the receipts.
  • i2d_SSL_SESSION() returns the size of the ASN1 representation in bytes. when the session is not valid, 0 is returned and no operation is performed. zero bytes, zero drama, nothing happened. πŸ’€

🌈 SEE ALSO 🌈

go read these next, iykyk:


πŸ“œ HISTORY πŸ“œ

the function d2i_SSL_SESSION_ex() was added in OpenSSL 3.2. so she's the new girl in town, and honestly she ate. ✨


Copyright 2001-2024 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>.


and that's the whole page, bestie!! this edition came from OpenSSL 4.0.3, dated 2026-09-29, and it's filed under D2I_SSL_SESSION(3SSL) in the manual. mwah, go encode something iconic πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from