2
0

ssl_ticket.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /**
  2. * \file ssl_ticket.h
  3. *
  4. * \brief TLS server ticket callbacks implementation
  5. */
  6. /*
  7. * Copyright The Mbed TLS Contributors
  8. * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  9. *
  10. * This file is provided under the Apache License 2.0, or the
  11. * GNU General Public License v2.0 or later.
  12. *
  13. * **********
  14. * Apache License 2.0:
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  17. * not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * http://www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  24. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. *
  28. * **********
  29. *
  30. * **********
  31. * GNU General Public License v2.0 or later:
  32. *
  33. * This program is free software; you can redistribute it and/or modify
  34. * it under the terms of the GNU General Public License as published by
  35. * the Free Software Foundation; either version 2 of the License, or
  36. * (at your option) any later version.
  37. *
  38. * This program is distributed in the hope that it will be useful,
  39. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  40. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  41. * GNU General Public License for more details.
  42. *
  43. * You should have received a copy of the GNU General Public License along
  44. * with this program; if not, write to the Free Software Foundation, Inc.,
  45. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  46. *
  47. * **********
  48. */
  49. #ifndef MBEDTLS_SSL_TICKET_H
  50. #define MBEDTLS_SSL_TICKET_H
  51. #if !defined(MBEDTLS_CONFIG_FILE)
  52. #include "config.h"
  53. #else
  54. #include MBEDTLS_CONFIG_FILE
  55. #endif
  56. /*
  57. * This implementation of the session ticket callbacks includes key
  58. * management, rotating the keys periodically in order to preserve forward
  59. * secrecy, when MBEDTLS_HAVE_TIME is defined.
  60. */
  61. #include "ssl.h"
  62. #include "cipher.h"
  63. #if defined(MBEDTLS_THREADING_C)
  64. #include "threading.h"
  65. #endif
  66. #ifdef __cplusplus
  67. extern "C" {
  68. #endif
  69. /**
  70. * \brief Information for session ticket protection
  71. */
  72. typedef struct mbedtls_ssl_ticket_key
  73. {
  74. unsigned char name[4]; /*!< random key identifier */
  75. uint32_t generation_time; /*!< key generation timestamp (seconds) */
  76. mbedtls_cipher_context_t ctx; /*!< context for auth enc/decryption */
  77. }
  78. mbedtls_ssl_ticket_key;
  79. /**
  80. * \brief Context for session ticket handling functions
  81. */
  82. typedef struct mbedtls_ssl_ticket_context
  83. {
  84. mbedtls_ssl_ticket_key keys[2]; /*!< ticket protection keys */
  85. unsigned char active; /*!< index of the currently active key */
  86. uint32_t ticket_lifetime; /*!< lifetime of tickets in seconds */
  87. /** Callback for getting (pseudo-)random numbers */
  88. int (*f_rng)(void *, unsigned char *, size_t);
  89. void *p_rng; /*!< context for the RNG function */
  90. #if defined(MBEDTLS_THREADING_C)
  91. mbedtls_threading_mutex_t mutex;
  92. #endif
  93. }
  94. mbedtls_ssl_ticket_context;
  95. /**
  96. * \brief Initialize a ticket context.
  97. * (Just make it ready for mbedtls_ssl_ticket_setup()
  98. * or mbedtls_ssl_ticket_free().)
  99. *
  100. * \param ctx Context to be initialized
  101. */
  102. void mbedtls_ssl_ticket_init( mbedtls_ssl_ticket_context *ctx );
  103. /**
  104. * \brief Prepare context to be actually used
  105. *
  106. * \param ctx Context to be set up
  107. * \param f_rng RNG callback function
  108. * \param p_rng RNG callback context
  109. * \param cipher AEAD cipher to use for ticket protection.
  110. * Recommended value: MBEDTLS_CIPHER_AES_256_GCM.
  111. * \param lifetime Tickets lifetime in seconds
  112. * Recommended value: 86400 (one day).
  113. *
  114. * \note It is highly recommended to select a cipher that is at
  115. * least as strong as the the strongest ciphersuite
  116. * supported. Usually that means a 256-bit key.
  117. *
  118. * \note The lifetime of the keys is twice the lifetime of tickets.
  119. * It is recommended to pick a reasonnable lifetime so as not
  120. * to negate the benefits of forward secrecy.
  121. *
  122. * \return 0 if successful,
  123. * or a specific MBEDTLS_ERR_XXX error code
  124. */
  125. int mbedtls_ssl_ticket_setup( mbedtls_ssl_ticket_context *ctx,
  126. int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
  127. mbedtls_cipher_type_t cipher,
  128. uint32_t lifetime );
  129. /**
  130. * \brief Implementation of the ticket write callback
  131. *
  132. * \note See \c mbedtls_ssl_ticket_write_t for description
  133. */
  134. mbedtls_ssl_ticket_write_t mbedtls_ssl_ticket_write;
  135. /**
  136. * \brief Implementation of the ticket parse callback
  137. *
  138. * \note See \c mbedtls_ssl_ticket_parse_t for description
  139. */
  140. mbedtls_ssl_ticket_parse_t mbedtls_ssl_ticket_parse;
  141. /**
  142. * \brief Free a context's content and zeroize it.
  143. *
  144. * \param ctx Context to be cleaned up
  145. */
  146. void mbedtls_ssl_ticket_free( mbedtls_ssl_ticket_context *ctx );
  147. #ifdef __cplusplus
  148. }
  149. #endif
  150. #endif /* ssl_ticket.h */