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