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