SSL_get_session.pod 4.2 KB

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