172613Skris=pod 272613Skris 372613Skris=head1 NAME 476866Skris 572613Skrisd2i_SSL_SESSION, i2d_SSL_SESSION - convert SSL_SESSION object from/to ASN1 representation 672613Skris 772613Skris=head1 SYNOPSIS 872613Skris 972613Skris #include <openssl/ssl.h> 1072613Skris 11160814Ssimon SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, long length); 1272613Skris int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp); 1372613Skris 1472613Skris=head1 DESCRIPTION 1572613Skris 1672613Skrisd2i_SSL_SESSION() transforms the external ASN1 representation of an SSL/TLS 1772613Skrissession, stored as binary data at location B<pp> with length B<length>, into 1872613Skrisan SSL_SESSION object. 1972613Skris 2072613Skrisi2d_SSL_SESSION() transforms the SSL_SESSION object B<in> into the ASN1 2172613Skrisrepresentation and stores it into the memory location pointed to by B<pp>. 2272613SkrisThe length of the resulting ASN1 representation is returned. If B<pp> is 2372613Skristhe NULL pointer, only the length is calculated and returned. 2472613Skris 2572613Skris=head1 NOTES 2672613Skris 2772613SkrisThe SSL_SESSION object is built from several malloc()ed parts, it can 2872613Skristherefore not be moved, copied or stored directly. In order to store 2972613Skrissession data on disk or into a database, it must be transformed into 3072613Skrisa binary ASN1 representation. 3172613Skris 3272613SkrisWhen using d2i_SSL_SESSION(), the SSL_SESSION object is automatically 3389837Skrisallocated. The reference count is 1, so that the session must be 3489837Skrisexplicitly removed using L<SSL_SESSION_free(3)|SSL_SESSION_free(3)>, 3589837Skrisunless the SSL_SESSION object is completely taken over, when being called 3689837Skrisinside the get_session_cb() (see 3789837SkrisL<SSL_CTX_sess_set_get_cb(3)|SSL_CTX_sess_set_get_cb(3)>). 3872613Skris 3989837SkrisSSL_SESSION objects keep internal link information about the session cache 4089837Skrislist, when being inserted into one SSL_CTX object's session cache. 4189837SkrisOne SSL_SESSION object, regardless of its reference count, must therefore 4289837Skrisonly be used with one SSL_CTX object (and the SSL objects created 4389837Skrisfrom this SSL_CTX object). 4489837Skris 4572613SkrisWhen using i2d_SSL_SESSION(), the memory location pointed to by B<pp> must be 4672613Skrislarge enough to hold the binary representation of the session. There is no 4772613Skrisknown limit on the size of the created ASN1 representation, so the necessary 4872613Skrisamount of space should be obtained by first calling i2d_SSL_SESSION() with 4972613SkrisB<pp=NULL>, and obtain the size needed, then allocate the memory and 5072613Skriscall i2d_SSL_SESSION() again. 51269682SjkimNote that this will advance the value contained in B<*pp> so it is necessary 52269682Sjkimto save a copy of the original allocation. 53269682SjkimFor example: 54269682Sjkim int i,j; 55269682Sjkim char *p, *temp; 56269682Sjkim i = i2d_SSL_SESSION(sess, NULL); 57269682Sjkim p = temp = malloc(i); 58269682Sjkim j = i2d_SSL_SESSION(sess, &temp); 59269682Sjkim assert(i == j); 60269682Sjkim assert(p+i == temp); 6172613Skris 6272613Skris=head1 RETURN VALUES 6372613Skris 6472613Skrisd2i_SSL_SESSION() returns a pointer to the newly allocated SSL_SESSION 6572613Skrisobject. In case of failure the NULL-pointer is returned and the error message 6672613Skriscan be retrieved from the error stack. 6772613Skris 6872613Skrisi2d_SSL_SESSION() returns the size of the ASN1 representation in bytes. 6972613SkrisWhen the session is not valid, B<0> is returned and no operation is performed. 7072613Skris 7172613Skris=head1 SEE ALSO 7272613Skris 7389837SkrisL<ssl(3)|ssl(3)>, L<SSL_SESSION_free(3)|SSL_SESSION_free(3)>, 7472613SkrisL<SSL_CTX_sess_set_get_cb(3)|SSL_CTX_sess_set_get_cb(3)> 7572613Skris 7672613Skris=cut 77