Blame doc/man3/SSL_get_session.pod

Packit c4476c
=pod
Packit c4476c
Packit c4476c
=head1 NAME
Packit c4476c
Packit c4476c
SSL_get_session, SSL_get0_session, SSL_get1_session - retrieve TLS/SSL session data
Packit c4476c
Packit c4476c
=head1 SYNOPSIS
Packit c4476c
Packit c4476c
 #include <openssl/ssl.h>
Packit c4476c
Packit c4476c
 SSL_SESSION *SSL_get_session(const SSL *ssl);
Packit c4476c
 SSL_SESSION *SSL_get0_session(const SSL *ssl);
Packit c4476c
 SSL_SESSION *SSL_get1_session(SSL *ssl);
Packit c4476c
Packit c4476c
=head1 DESCRIPTION
Packit c4476c
Packit c4476c
SSL_get_session() returns a pointer to the B<SSL_SESSION> actually used in
Packit c4476c
B<ssl>. The reference count of the B<SSL_SESSION> is not incremented, so
Packit c4476c
that the pointer can become invalid by other operations.
Packit c4476c
Packit c4476c
SSL_get0_session() is the same as SSL_get_session().
Packit c4476c
Packit c4476c
SSL_get1_session() is the same as SSL_get_session(), but the reference
Packit c4476c
count of the B<SSL_SESSION> is incremented by one.
Packit c4476c
Packit c4476c
=head1 NOTES
Packit c4476c
Packit c4476c
The ssl session contains all information required to re-establish the
Packit c4476c
connection without a full handshake for SSL versions up to and including
Packit c4476c
TLSv1.2. In TLSv1.3 the same is true, but sessions are established after the
Packit c4476c
main handshake has occurred. The server will send the session information to the
Packit c4476c
client at a time of its choosing, which may be some while after the initial
Packit c4476c
connection is established (or never). Calling these functions on the client side
Packit c4476c
in TLSv1.3 before the session has been established will still return an
Packit c4476c
SSL_SESSION object but that object cannot be used for resuming the session. See
Packit c4476c
L<SSL_SESSION_is_resumable(3)> for information on how to determine whether an
Packit c4476c
SSL_SESSION object can be used for resumption or not.
Packit c4476c
Packit c4476c
Additionally, in TLSv1.3, a server can send multiple messages that establish a
Packit c4476c
session for a single connection. In that case the above functions will only
Packit c4476c
return information on the last session that was received.
Packit c4476c
Packit c4476c
The preferred way for applications to obtain a resumable SSL_SESSION object is
Packit c4476c
to use a new session callback as described in L<SSL_CTX_sess_set_new_cb(3)>.
Packit c4476c
The new session callback is only invoked when a session is actually established,
Packit c4476c
so this avoids the problem described above where an application obtains an
Packit c4476c
SSL_SESSION object that cannot be used for resumption in TLSv1.3. It also
Packit c4476c
enables applications to obtain information about all sessions sent by the
Packit c4476c
server.
Packit c4476c
Packit c4476c
A session will be automatically removed from the session cache and marked as
Packit c4476c
non-resumable if the connection is not closed down cleanly, e.g. if a fatal
Packit c4476c
error occurs on the connection or L<SSL_shutdown(3)> is not called prior to
Packit c4476c
L<SSL_free(3)>.
Packit c4476c
Packit c4476c
In TLSv1.3 it is recommended that each SSL_SESSION object is only used for
Packit c4476c
resumption once.
Packit c4476c
Packit c4476c
SSL_get0_session() returns a pointer to the actual session. As the
Packit c4476c
reference counter is not incremented, the pointer is only valid while
Packit c4476c
the connection is in use. If L<SSL_clear(3)> or
Packit c4476c
L<SSL_free(3)> is called, the session may be removed completely
Packit c4476c
(if considered bad), and the pointer obtained will become invalid. Even
Packit c4476c
if the session is valid, it can be removed at any time due to timeout
Packit c4476c
during L<SSL_CTX_flush_sessions(3)>.
Packit c4476c
Packit c4476c
If the data is to be kept, SSL_get1_session() will increment the reference
Packit c4476c
count, so that the session will not be implicitly removed by other operations
Packit c4476c
but stays in memory. In order to remove the session
Packit c4476c
L<SSL_SESSION_free(3)> must be explicitly called once
Packit c4476c
to decrement the reference count again.
Packit c4476c
Packit c4476c
SSL_SESSION objects keep internal link information about the session cache
Packit c4476c
list, when being inserted into one SSL_CTX object's session cache.
Packit c4476c
One SSL_SESSION object, regardless of its reference count, must therefore
Packit c4476c
only be used with one SSL_CTX object (and the SSL objects created
Packit c4476c
from this SSL_CTX object).
Packit c4476c
Packit c4476c
=head1 RETURN VALUES
Packit c4476c
Packit c4476c
The following return values can occur:
Packit c4476c
Packit c4476c
=over 4
Packit c4476c
Packit c4476c
=item NULL
Packit c4476c
Packit c4476c
There is no session available in B<ssl>.
Packit c4476c
Packit c4476c
=item Pointer to an SSL_SESSION
Packit c4476c
Packit c4476c
The return value points to the data of an SSL session.
Packit c4476c
Packit c4476c
=back
Packit c4476c
Packit c4476c
=head1 SEE ALSO
Packit c4476c
Packit c4476c
L<ssl(7)>, L<SSL_free(3)>,
Packit c4476c
L<SSL_clear(3)>,
Packit c4476c
L<SSL_SESSION_free(3)>
Packit c4476c
Packit c4476c
=head1 COPYRIGHT
Packit c4476c
Packit c4476c
Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
Packit c4476c
Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
this file except in compliance with the License.  You can obtain a copy
Packit c4476c
in the file LICENSE in the source distribution or at
Packit c4476c
L<https://www.openssl.org/source/license.html>.
Packit c4476c
Packit c4476c
=cut