ssl_cookie.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * \file ssl_cookie.h
  3. *
  4. * \brief DTLS cookie 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_COOKIE_H
  26. #define MBEDTLS_SSL_COOKIE_H
  27. #include "ssl.h"
  28. #if defined(MBEDTLS_THREADING_C)
  29. #include "threading.h"
  30. #endif
  31. /**
  32. * \name SECTION: Module settings
  33. *
  34. * The configuration options you can set for this module are in this section.
  35. * Either change them in config.h or define them on the compiler command line.
  36. * \{
  37. */
  38. #ifndef MBEDTLS_SSL_COOKIE_TIMEOUT
  39. #define MBEDTLS_SSL_COOKIE_TIMEOUT 60 /**< Default expiration delay of DTLS cookies, in seconds if HAVE_TIME, or in number of cookies issued */
  40. #endif
  41. /* \} name SECTION: Module settings */
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. /**
  46. * \brief Context for the default cookie functions.
  47. */
  48. typedef struct
  49. {
  50. mbedtls_md_context_t hmac_ctx; /*!< context for the HMAC portion */
  51. #if !defined(MBEDTLS_HAVE_TIME)
  52. unsigned long serial; /*!< serial number for expiration */
  53. #endif
  54. unsigned long timeout; /*!< timeout delay, in seconds if HAVE_TIME,
  55. or in number of tickets issued */
  56. #if defined(MBEDTLS_THREADING_C)
  57. mbedtls_threading_mutex_t mutex;
  58. #endif
  59. } mbedtls_ssl_cookie_ctx;
  60. /**
  61. * \brief Initialize cookie context
  62. */
  63. void mbedtls_ssl_cookie_init( mbedtls_ssl_cookie_ctx *ctx );
  64. /**
  65. * \brief Setup cookie context (generate keys)
  66. */
  67. int mbedtls_ssl_cookie_setup( mbedtls_ssl_cookie_ctx *ctx,
  68. int (*f_rng)(void *, unsigned char *, size_t),
  69. void *p_rng );
  70. /**
  71. * \brief Set expiration delay for cookies
  72. * (Default MBEDTLS_SSL_COOKIE_TIMEOUT)
  73. *
  74. * \param ctx Cookie contex
  75. * \param delay Delay, in seconds if HAVE_TIME, or in number of cookies
  76. * issued in the meantime.
  77. * 0 to disable expiration (NOT recommended)
  78. */
  79. void mbedtls_ssl_cookie_set_timeout( mbedtls_ssl_cookie_ctx *ctx, unsigned long delay );
  80. /**
  81. * \brief Free cookie context
  82. */
  83. void mbedtls_ssl_cookie_free( mbedtls_ssl_cookie_ctx *ctx );
  84. /**
  85. * \brief Generate cookie, see \c mbedtls_ssl_cookie_write_t
  86. */
  87. mbedtls_ssl_cookie_write_t mbedtls_ssl_cookie_write;
  88. /**
  89. * \brief Verify cookie, see \c mbedtls_ssl_cookie_write_t
  90. */
  91. mbedtls_ssl_cookie_check_t mbedtls_ssl_cookie_check;
  92. #ifdef __cplusplus
  93. }
  94. #endif
  95. #endif /* ssl_cookie.h */