Documentation updates for TLSv1.3 sessions
[oweals/openssl.git] / doc / man3 / SSL_get_session.pod
1 =pod
2
3 =head1 NAME
4
5 SSL_get_session, SSL_get0_session, SSL_get1_session - retrieve TLS/SSL session data
6
7 =head1 SYNOPSIS
8
9  #include <openssl/ssl.h>
10
11  SSL_SESSION *SSL_get_session(const SSL *ssl);
12  SSL_SESSION *SSL_get0_session(const SSL *ssl);
13  SSL_SESSION *SSL_get1_session(SSL *ssl);
14
15 =head1 DESCRIPTION
16
17 SSL_get_session() returns a pointer to the B<SSL_SESSION> actually used in
18 B<ssl>. The reference count of the B<SSL_SESSION> is not incremented, so
19 that the pointer can become invalid by other operations.
20
21 SSL_get0_session() is the same as SSL_get_session().
22
23 SSL_get1_session() is the same as SSL_get_session(), but the reference
24 count of the B<SSL_SESSION> is incremented by one.
25
26 =head1 NOTES
27
28 The ssl session contains all information required to re-establish the
29 connection without a full handshake for SSL versions <= TLSv1.2. In TLSv1.3 the
30 same is true, but sessions are established after the main handshake has occurred.
31 The server will send the session information to the client at a time of its
32 choosing which may be some while after the initial connection is established (or
33 not at all). Calling these functions on the client side in TLSv1.3 before the
34 session has been established will still return an SSL_SESSION object but it
35 cannot be used for resuming the session. See L<SSL_SESSION_is_resumable(3)> for
36 information on how to determine whether an SSL_SESSION object can be used for
37 resumption or not.
38
39 Additionally, in TLSv1.3, a server can send multiple session messages for a
40 single connection. In that case the above functions will only return information
41 on the last session that was received.
42
43 The preferred way for applications to obtain a resumable SSL_SESSION object is
44 to use a new session callback as described in L<SSL_CTX_sess_set_new_cb(3)>.
45 The new session callback is only invoked when a session is actually established,
46 so this avoids the problem described above where an application obtains an
47 SSL_SESSION object that cannot be used for resumption in TLSv1.3. It also
48 enables applications to obtain information about all sessions sent by the
49 server.
50
51 In TLSv1.3 it is recommended that each SSL_SESSION object is only used for
52 resumption once.
53
54 SSL_get0_session() returns a pointer to the actual session. As the
55 reference counter is not incremented, the pointer is only valid while
56 the connection is in use. If L<SSL_clear(3)> or
57 L<SSL_free(3)> is called, the session may be removed completely
58 (if considered bad), and the pointer obtained will become invalid. Even
59 if the session is valid, it can be removed at any time due to timeout
60 during L<SSL_CTX_flush_sessions(3)>.
61
62 If the data is to be kept, SSL_get1_session() will increment the reference
63 count, so that the session will not be implicitly removed by other operations
64 but stays in memory. In order to remove the session
65 L<SSL_SESSION_free(3)> must be explicitly called once
66 to decrement the reference count again.
67
68 SSL_SESSION objects keep internal link information about the session cache
69 list, when being inserted into one SSL_CTX object's session cache.
70 One SSL_SESSION object, regardless of its reference count, must therefore
71 only be used with one SSL_CTX object (and the SSL objects created
72 from this SSL_CTX object).
73
74 =head1 RETURN VALUES
75
76 The following return values can occur:
77
78 =over 4
79
80 =item NULL
81
82 There is no session available in B<ssl>.
83
84 =item Pointer to an SSL_SESSION
85
86 The return value points to the data of an SSL session.
87
88 =back
89
90 =head1 SEE ALSO
91
92 L<ssl(7)>, L<SSL_free(3)>,
93 L<SSL_clear(3)>,
94 L<SSL_SESSION_free(3)>
95
96 =head1 COPYRIGHT
97
98 Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
99
100 Licensed under the OpenSSL license (the "License").  You may not use
101 this file except in compliance with the License.  You can obtain a copy
102 in the file LICENSE in the source distribution or at
103 L<https://www.openssl.org/source/license.html>.
104
105 =cut