ssl_ticket.h 4.3 KB

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