SSL_CTX_sess_set_get_cb.pod 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. =pod
  2. =head1 NAME
  3. SSL_CTX_sess_set_new_cb, SSL_CTX_sess_set_remove_cb, SSL_CTX_sess_set_get_cb, SSL_CTX_sess_get_new_cb, SSL_CTX_sess_get_remove_cb, SSL_CTX_sess_get_get_cb - provide callback functions for server side external session caching
  4. =head1 SYNOPSIS
  5. #include <openssl/ssl.h>
  6. void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx,
  7. int (*new_session_cb)(SSL *, SSL_SESSION *));
  8. void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx,
  9. void (*remove_session_cb)(SSL_CTX *ctx,
  10. SSL_SESSION *));
  11. void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx,
  12. SSL_SESSION (*get_session_cb)(SSL *,
  13. const unsigned char *,
  14. int, int *));
  15. int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx))(struct ssl_st *ssl,
  16. SSL_SESSION *sess);
  17. void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx))(struct ssl_ctx_st *ctx,
  18. SSL_SESSION *sess);
  19. SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx))(struct ssl_st *ssl,
  20. const unsigned char *data,
  21. int len, int *copy);
  22. =head1 DESCRIPTION
  23. SSL_CTX_sess_set_new_cb() sets the callback function that is
  24. called whenever a new session was negotiated.
  25. SSL_CTX_sess_set_remove_cb() sets the callback function that is
  26. called whenever a session is removed by the SSL engine. For example,
  27. this can occur because a session is considered faulty or has become obsolete
  28. because of exceeding the timeout value.
  29. SSL_CTX_sess_set_get_cb() sets the callback function that is called
  30. whenever a TLS client proposed to resume a session but the session
  31. could not be found in the internal session cache (see
  32. L<SSL_CTX_set_session_cache_mode(3)>).
  33. (TLS server only.)
  34. SSL_CTX_sess_get_new_cb(), SSL_CTX_sess_get_remove_cb(), and
  35. SSL_CTX_sess_get_get_cb() retrieve the function pointers set by the
  36. corresponding set callback functions. If a callback function has not been
  37. set, the NULL pointer is returned.
  38. =head1 NOTES
  39. In order to allow external session caching, synchronization with the internal
  40. session cache is realized via callback functions. Inside these callback
  41. functions, session can be saved to disk or put into a database using the
  42. L<d2i_SSL_SESSION(3)> interface.
  43. The new_session_cb() is called whenever a new session has been negotiated and
  44. session caching is enabled (see L<SSL_CTX_set_session_cache_mode(3)>). The
  45. new_session_cb() is passed the B<ssl> connection and the nascent
  46. ssl session B<sess>.
  47. Since sessions are reference-counted objects, the reference count on the
  48. session is incremented before the callback, on behalf of the application. If
  49. the callback returns B<0>, the session will be immediately removed from the
  50. internal cache and the reference count released. If the callback returns B<1>,
  51. the application retains the reference (for an entry in the
  52. application-maintained "external session cache"), and is responsible for
  53. calling SSL_SESSION_free() when the session reference is no longer in use.
  54. Note that in TLSv1.3, sessions are established after the main
  55. handshake has completed. The server decides when to send the client the session
  56. information and this may occur some time after the end of the handshake (or not
  57. at all). This means that applications should expect the new_session_cb()
  58. function to be invoked during the handshake (for <= TLSv1.2) or after the
  59. handshake (for TLSv1.3). It is also possible in TLSv1.3 for multiple sessions to
  60. be established with a single connection. In these case the new_session_cb()
  61. function will be invoked multiple times.
  62. In TLSv1.3 it is recommended that each SSL_SESSION object is only used for
  63. resumption once. One way of enforcing that is for applications to call
  64. L<SSL_CTX_remove_session(3)> after a session has been used.
  65. The remove_session_cb() is called whenever the SSL engine removes a session
  66. from the internal cache. This can happen when the session is removed because
  67. it is expired or when a connection was not shutdown cleanly. It also happens
  68. for all sessions in the internal session cache when
  69. L<SSL_CTX_free(3)> is called. The remove_session_cb() is passed
  70. the B<ctx> and the ssl session B<sess>. It does not provide any feedback.
  71. The get_session_cb() is only called on SSL/TLS servers, and is given
  72. the session id
  73. proposed by the client. The get_session_cb() is always called, even when
  74. session caching was disabled. The get_session_cb() is passed the
  75. B<ssl> connection and the session id of length B<length> at the memory location
  76. B<data>. By setting the parameter B<copy> to B<1>, the callback can require the
  77. SSL engine to increment the reference count of the SSL_SESSION object;
  78. setting B<copy> to B<0> causes the reference count to remain unchanged.
  79. If the get_session_cb() does not write to B<copy>, the reference count
  80. is incremented and the session must be explicitly freed with
  81. L<SSL_SESSION_free(3)>.
  82. =head1 RETURN VALUES
  83. SSL_CTX_sess_get_new_cb(), SSL_CTX_sess_get_remove_cb() and SSL_CTX_sess_get_get_cb()
  84. return different callback function pointers respectively.
  85. =head1 SEE ALSO
  86. L<ssl(7)>, L<d2i_SSL_SESSION(3)>,
  87. L<SSL_CTX_set_session_cache_mode(3)>,
  88. L<SSL_CTX_flush_sessions(3)>,
  89. L<SSL_SESSION_free(3)>,
  90. L<SSL_CTX_free(3)>
  91. =head1 COPYRIGHT
  92. Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
  93. Licensed under the Apache License 2.0 (the "License"). You may not use
  94. this file except in compliance with the License. You can obtain a copy
  95. in the file LICENSE in the source distribution or at
  96. L<https://www.openssl.org/source/license.html>.
  97. =cut