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