Update SSL_CTX_sess_set_new_cb(3) docs for refcounts
[openssl.git] / doc / man3 / SSL_CTX_sess_set_get_cb.pod
1 =pod
2
3 =head1 NAME
4
5 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
6
7 =head1 SYNOPSIS
8
9  #include <openssl/ssl.h>
10
11  void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx,
12                               int (*new_session_cb)(SSL *, SSL_SESSION *));
13  void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx,
14                                  void (*remove_session_cb)(SSL_CTX *ctx,
15                                                            SSL_SESSION *));
16  void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx,
17                               SSL_SESSION (*get_session_cb)(SSL *,
18                                                             const unsigned char *,
19                                                             int, int *));
20
21  int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx))(struct ssl_st *ssl,
22                                               SSL_SESSION *sess);
23  void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx))(struct ssl_ctx_st *ctx,
24                                                   SSL_SESSION *sess);
25  SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx))(struct ssl_st *ssl,
26                                                        const unsigned char *data,
27                                                        int len, int *copy);
28
29 =head1 DESCRIPTION
30
31 SSL_CTX_sess_set_new_cb() sets the callback function, which is automatically
32 called whenever a new session was negotiated.
33
34 SSL_CTX_sess_set_remove_cb() sets the callback function, which is
35 automatically called whenever a session is removed by the SSL engine,
36 because it is considered faulty or the session has become obsolete because
37 of exceeding the timeout value.
38
39 SSL_CTX_sess_set_get_cb() sets the callback function which is called,
40 whenever a SSL/TLS client proposed to resume a session but the session
41 could not be found in the internal session cache (see
42 L<SSL_CTX_set_session_cache_mode(3)>).
43 (SSL/TLS server only.)
44
45 SSL_CTX_sess_get_new_cb(), SSL_CTX_sess_get_remove_cb(), and
46 SSL_CTX_sess_get_get_cb() retrieve the function pointers set by the
47 corresponding set callback functions. If a callback function has not been
48 set, the NULL pointer is returned.
49
50 =head1 NOTES
51
52 In order to allow external session caching, synchronization with the internal
53 session cache is realized via callback functions. Inside these callback
54 functions, session can be saved to disk or put into a database using the
55 L<d2i_SSL_SESSION(3)> interface.
56
57 The new_session_cb() is called whenever a new session has been negotiated and
58 session caching is enabled (see L<SSL_CTX_set_session_cache_mode(3)>).  The
59 new_session_cb() is passed the B<ssl> connection and the ssl session B<sess>.
60 Since sessions are reference-counted objects, the reference count on the
61 session is incremented before the callback, on behalf of the application.  If
62 the callback returns B<0>, the session will be immediately removed from the
63 internal cache and the reference count released. If the callback returns B<1>,
64 the application retains the reference (for an entry in the
65 application-maintained "external session cache"), and is responsible for
66 calling SSL_SESSION_free() when the session reference is no longer in use.
67
68 Note that in TLSv1.3, sessions are established after the main
69 handshake has completed. The server decides when to send the client the session
70 information and this may occur some time after the end of the handshake (or not
71 at all). This means that applications should expect the new_session_cb()
72 function to be invoked during the handshake (for <= TLSv1.2) or after the
73 handshake (for TLSv1.3). It is also possible in TLSv1.3 for multiple sessions to
74 be established with a single connection. In these case the new_session_cb()
75 function will be invoked multiple times.
76
77 In TLSv1.3 it is recommended that each SSL_SESSION object is only used for
78 resumption once. One way of enforcing that is for applications to call
79 L<SSL_CTX_remove_session(3)> after a session has been used.
80
81 The remove_session_cb() is called, whenever the SSL engine removes a session
82 from the internal cache. This happens when the session is removed because
83 it is expired or when a connection was not shutdown cleanly. It also happens
84 for all sessions in the internal session cache when
85 L<SSL_CTX_free(3)> is called. The remove_session_cb() is passed
86 the B<ctx> and the ssl session B<sess>. It does not provide any feedback.
87
88 The get_session_cb() is only called on SSL/TLS servers with the session id
89 proposed by the client. The get_session_cb() is always called, also when
90 session caching was disabled. The get_session_cb() is passed the
91 B<ssl> connection, the session id of length B<length> at the memory location
92 B<data>. With the parameter B<copy> the callback can require the
93 SSL engine to increment the reference count of the SSL_SESSION object,
94 Normally the reference count is not incremented and therefore the
95 session must not be explicitly freed with
96 L<SSL_SESSION_free(3)>.
97
98 =head1 RETURN VALUES
99
100 SSL_CTX_sess_get_new_cb(), SSL_CTX_sess_get_remove_cb() and SSL_CTX_sess_get_get_cb()
101 return different callback function pointers respectively.
102
103 =head1 SEE ALSO
104
105 L<ssl(7)>, L<d2i_SSL_SESSION(3)>,
106 L<SSL_CTX_set_session_cache_mode(3)>,
107 L<SSL_CTX_flush_sessions(3)>,
108 L<SSL_SESSION_free(3)>,
109 L<SSL_CTX_free(3)>
110
111 =head1 COPYRIGHT
112
113 Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
114
115 Licensed under the Apache License 2.0 (the "License").  You may not use
116 this file except in compliance with the License.  You can obtain a copy
117 in the file LICENSE in the source distribution or at
118 L<https://www.openssl.org/source/license.html>.
119
120 =cut