
#use wml::openssl-macros area=docs page=SSL_CTX_sess_set_get_cb

<title>Documents, SSL_CTX_sess_set_get_cb(3)</title>

<h1>SSL_CTX_sess_set_get_cb(3)</h1>

#use wml::imp::generic

{:
## What's this? [[s|(<STRONG>[^<].+?)</A>(</STRONG><DD>)|$1$2|sg]]
[[s|<P>\s+<P>|<P>|sg]]
[[s|<P>\s+</|</|sg]]
[[s|<DD>\s*<DT>|<DD>&nbsp;<DT>|sg]]
[[s|<DD>\s*</DL>|<DD>&nbsp;</DL>|sg]]
[[s|\[|&#91;|sg]]
[[s|\]|&#93;|sg]]

<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#NAME">NAME</A>
	<LI><A HREF="#SYNOPSIS">SYNOPSIS</A>
	<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
	<LI><A HREF="#NOTES">NOTES</A>
	<LI><A HREF="#SEE_ALSO">SEE ALSO</A>
</UL>
<!-- INDEX END -->

<HR>
<P>
<HR>
<H1><A NAME="NAME">NAME</A></H1>
<P>
SSL_CTX_sess_set_new_cb, SSL_CTX_sess_set_remove_cb,
SSL_CTX_sess_set_get_cb, SSL_CTX_sess_get_new_cb,
SSL_CTX_sess_get_remove_cb, SSL_CTX_sess_get_get_cb - provide callback
functions for server side external session caching

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/ssl.h&gt;
</PRE>
<PRE> void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx,
                              int (*new_session_cb)(SSL *, SSL_SESSION *));
 void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx,
           void (*remove_session_cb)(SSL_CTX *ctx, SSL_SESSION *));
 void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx,
           SSL_SESSION (*get_session_cb)(SSL *, unsigned char *, int, int *));
</PRE>
<PRE> int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx))(struct ssl_st *ssl, SSL_SESSION *sess);
 void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx))(struct ssl_ctx_st *ctx, SSL_SESSION *sess);
 SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx))(struct ssl_st *ssl, unsigned char *data, int len, int *copy);
</PRE>
<PRE> int (*new_session_cb)(struct ssl_st *ssl, SSL_SESSION *sess);
 void (*remove_session_cb)(struct ssl_ctx_st *ctx, SSL_SESSION *sess);
 SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl, unsigned char *data,
               int len, int *copy);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
<CODE>SSL_CTX_sess_set_new_cb()</CODE> sets the callback function, which is
automatically called whenever a new session was negotiated.

</P>
<P>
<CODE>SSL_CTX_sess_set_remove_cb()</CODE> sets the callback function, which
is automatically called whenever a session is removed by the SSL engine,
because it is considered faulty or the session has become obsolete because
of exceeding the timeout value.

</P>
<P>
<CODE>SSL_CTX_sess_set_get_cb()</CODE> sets the callback function which is
called, whenever a SSL/TLS client proposed to resume a session but the
session could not be found in the internal session cache (see
<A HREF="../ssl/SSL_CTX_set_session_cache_mode.html#">SSL_CTX_set_session_cache_mode(3)</A>). (SSL/TLS server only.)

</P>
<P>
<CODE>SSL_CTX_sess_get_new_cb(),</CODE>
<CODE>SSL_CTX_sess_get_remove_cb(),</CODE> and
<CODE>SSL_CTX_sess_get_get_cb()</CODE> allow to retrieve the function
pointers of the provided callback functions. If a callback function has not
been set, the NULL pointer is returned.

</P>
<P>
<HR>
<H1><A NAME="NOTES">NOTES</A></H1>
<P>
In order to allow external session caching, synchronization with the
internal session cache is realized via callback functions. Inside these
callback functions, session can be saved to disk or put into a database
using the
<A HREF="../ssl/d2i_SSL_SESSION.html#">d2i_SSL_SESSION(3)</A> interface.

</P>
<P>
The <CODE>new_session_cb()</CODE> is called, whenever a new session has
been negotiated and session caching is enabled (see
<A HREF="../ssl/SSL_CTX_set_session_cache_mode.html#">SSL_CTX_set_session_cache_mode(3)</A>). The <CODE>new_session_cb()</CODE> is passed the <STRONG>ssl</STRONG> connection and the ssl session
<STRONG>sess</STRONG>. If the callback returns <STRONG>0</STRONG>, the session will be immediately removed again.

</P>
<P>
The <CODE>remove_session_cb()</CODE> is called, whenever the SSL engine
removes a session from the internal cache. This happens when the session is
removed because it is expired or when a connection was not shutdown
cleanly. It also happens for all sessions in the internal session cache
when
<A HREF="../ssl/SSL_CTX_free.html#">SSL_CTX_free(3)</A> is called. The <CODE>remove_session_cb()</CODE> is passed the <STRONG>ctx</STRONG> and the ssl session <STRONG>sess</STRONG>. It does not provide any feedback.

</P>
<P>
The <CODE>get_session_cb()</CODE> is only called on SSL/TLS servers with
the session id proposed by the client. The <CODE>get_session_cb()</CODE> is
always called, also when session caching was disabled. The
<CODE>get_session_cb()</CODE> is passed the
<STRONG>ssl</STRONG> connection, the session id of length <STRONG>length</STRONG> at the memory location
<STRONG>data</STRONG>. With the parameter <STRONG>copy</STRONG> the callback can require the SSL engine to increment the reference count of
the SSL_SESSION object, Normally the reference count is not incremented and
therefore the session must not be explicitly freed with
<A HREF="../ssl/SSL_SESSION_free.html#">SSL_SESSION_free(3)</A>.

</P>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
<A HREF="../ssl/ssl.html#">ssl(3)</A>, <A HREF="../ssl/d2i_SSL_SESSION.html#">d2i_SSL_SESSION(3)</A>,
<A HREF="../ssl/SSL_CTX_set_session_cache_mode.html#">SSL_CTX_set_session_cache_mode(3)</A>,
<A HREF="../ssl/SSL_CTX_flush_sessions.html#">SSL_CTX_flush_sessions(3)</A>,
<A HREF="../ssl/SSL_SESSION_free.html#">SSL_SESSION_free(3)</A>,
<A HREF="../ssl/SSL_CTX_free.html#">SSL_CTX_free(3)</A>



</P>
:}

