Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 1 | /** |
| 2 | * \file ssl_cookie.h |
| 3 | * |
| 4 | * \brief DTLS cookie callbacks implementation |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 5 | */ |
| 6 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 7 | * Copyright The Mbed TLS Contributors |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: Apache-2.0 |
| 9 | * |
| 10 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 11 | * not use this file except in compliance with the License. |
| 12 | * You may obtain a copy of the License at |
| 13 | * |
| 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | * |
| 16 | * Unless required by applicable law or agreed to in writing, software |
| 17 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 18 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | * See the License for the specific language governing permissions and |
| 20 | * limitations under the License. |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 21 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 22 | #ifndef MBEDTLS_SSL_COOKIE_H |
| 23 | #define MBEDTLS_SSL_COOKIE_H |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 24 | #include "mbedtls/private_access.h" |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 25 | |
Bence Szépkúti | c662b36 | 2021-05-27 11:25:03 +0200 | [diff] [blame] | 26 | #include "mbedtls/build_info.h" |
Ron Eldor | 8b0cf2e | 2018-02-14 16:02:41 +0200 | [diff] [blame] | 27 | |
Jaeden Amero | 6609aef | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 28 | #include "mbedtls/ssl.h" |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 29 | |
Neil Armstrong | c0db762 | 2022-03-22 10:38:58 +0100 | [diff] [blame] | 30 | #if !defined(MBEDTLS_USE_PSA_CRYPTO) |
Manuel Pégourié-Gonnard | 2a84dfd | 2015-05-28 15:48:09 +0200 | [diff] [blame] | 31 | #if defined(MBEDTLS_THREADING_C) |
Jaeden Amero | 6609aef | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 32 | #include "mbedtls/threading.h" |
Manuel Pégourié-Gonnard | 2a84dfd | 2015-05-28 15:48:09 +0200 | [diff] [blame] | 33 | #endif |
Neil Armstrong | c0db762 | 2022-03-22 10:38:58 +0100 | [diff] [blame] | 34 | #endif /* !MBEDTLS_USE_PSA_CRYPTO */ |
Manuel Pégourié-Gonnard | 2a84dfd | 2015-05-28 15:48:09 +0200 | [diff] [blame] | 35 | |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 36 | /** |
| 37 | * \name SECTION: Module settings |
| 38 | * |
| 39 | * The configuration options you can set for this module are in this section. |
Bence Szépkúti | bb0cfeb | 2021-05-28 09:42:25 +0200 | [diff] [blame] | 40 | * Either change them in mbedtls_config.h or define them on the compiler command line. |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 41 | * \{ |
| 42 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 43 | #ifndef MBEDTLS_SSL_COOKIE_TIMEOUT |
| 44 | #define MBEDTLS_SSL_COOKIE_TIMEOUT 60 /**< Default expiration delay of DTLS cookies, in seconds if HAVE_TIME, or in number of cookies issued */ |
Manuel Pégourié-Gonnard | bef8f09 | 2014-07-23 23:40:29 +0200 | [diff] [blame] | 45 | #endif |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 46 | |
Andrzej Kurek | 38d4fdd | 2021-12-28 16:22:52 +0100 | [diff] [blame] | 47 | /** \} name SECTION: Module settings */ |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 48 | |
| 49 | #ifdef __cplusplus |
| 50 | extern "C" { |
| 51 | #endif |
| 52 | |
| 53 | /** |
| 54 | * \brief Context for the default cookie functions. |
| 55 | */ |
Dawid Drozd | 428cc52 | 2018-07-24 10:02:47 +0200 | [diff] [blame] | 56 | typedef struct mbedtls_ssl_cookie_ctx |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 57 | { |
Neil Armstrong | bca99ee | 2022-03-04 10:20:20 +0100 | [diff] [blame] | 58 | #if defined(MBEDTLS_USE_PSA_CRYPTO) |
Neil Armstrong | 488a40e | 2022-03-22 10:41:38 +0100 | [diff] [blame] | 59 | mbedtls_svc_key_id_t MBEDTLS_PRIVATE(psa_hmac_key); /*!< key id for the HMAC portion */ |
Neil Armstrong | bca99ee | 2022-03-04 10:20:20 +0100 | [diff] [blame] | 60 | psa_algorithm_t MBEDTLS_PRIVATE(psa_hmac_alg); /*!< key algorithm for the HMAC portion */ |
Neil Armstrong | 77b69ab | 2022-03-04 14:35:13 +0100 | [diff] [blame] | 61 | #else |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 62 | mbedtls_md_context_t MBEDTLS_PRIVATE(hmac_ctx); /*!< context for the HMAC portion */ |
Neil Armstrong | 77b69ab | 2022-03-04 14:35:13 +0100 | [diff] [blame] | 63 | #endif /* MBEDTLS_USE_PSA_CRYPTO */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 64 | #if !defined(MBEDTLS_HAVE_TIME) |
Mateusz Starzyk | 2abe51c | 2021-06-07 11:08:01 +0200 | [diff] [blame] | 65 | unsigned long MBEDTLS_PRIVATE(serial); /*!< serial number for expiration */ |
Manuel Pégourié-Gonnard | e903081 | 2014-07-23 21:29:11 +0200 | [diff] [blame] | 66 | #endif |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 67 | unsigned long MBEDTLS_PRIVATE(timeout); /*!< timeout delay, in seconds if HAVE_TIME, |
Manuel Pégourié-Gonnard | bef8f09 | 2014-07-23 23:40:29 +0200 | [diff] [blame] | 68 | or in number of tickets issued */ |
| 69 | |
Neil Armstrong | 7cd0270 | 2022-03-04 15:08:43 +0100 | [diff] [blame] | 70 | #if !defined(MBEDTLS_USE_PSA_CRYPTO) |
Manuel Pégourié-Gonnard | 2a84dfd | 2015-05-28 15:48:09 +0200 | [diff] [blame] | 71 | #if defined(MBEDTLS_THREADING_C) |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 72 | mbedtls_threading_mutex_t MBEDTLS_PRIVATE(mutex); |
Manuel Pégourié-Gonnard | 2a84dfd | 2015-05-28 15:48:09 +0200 | [diff] [blame] | 73 | #endif |
Neil Armstrong | 7cd0270 | 2022-03-04 15:08:43 +0100 | [diff] [blame] | 74 | #endif /* !MBEDTLS_USE_PSA_CRYPTO */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 75 | } mbedtls_ssl_cookie_ctx; |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * \brief Initialize cookie context |
| 79 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 80 | void mbedtls_ssl_cookie_init( mbedtls_ssl_cookie_ctx *ctx ); |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * \brief Setup cookie context (generate keys) |
| 84 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 85 | int mbedtls_ssl_cookie_setup( mbedtls_ssl_cookie_ctx *ctx, |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 86 | int (*f_rng)(void *, unsigned char *, size_t), |
| 87 | void *p_rng ); |
| 88 | |
| 89 | /** |
Manuel Pégourié-Gonnard | bef8f09 | 2014-07-23 23:40:29 +0200 | [diff] [blame] | 90 | * \brief Set expiration delay for cookies |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 91 | * (Default MBEDTLS_SSL_COOKIE_TIMEOUT) |
Manuel Pégourié-Gonnard | bef8f09 | 2014-07-23 23:40:29 +0200 | [diff] [blame] | 92 | * |
| 93 | * \param ctx Cookie contex |
| 94 | * \param delay Delay, in seconds if HAVE_TIME, or in number of cookies |
| 95 | * issued in the meantime. |
| 96 | * 0 to disable expiration (NOT recommended) |
| 97 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 98 | void mbedtls_ssl_cookie_set_timeout( mbedtls_ssl_cookie_ctx *ctx, unsigned long delay ); |
Manuel Pégourié-Gonnard | bef8f09 | 2014-07-23 23:40:29 +0200 | [diff] [blame] | 99 | |
| 100 | /** |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 101 | * \brief Free cookie context |
| 102 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 103 | void mbedtls_ssl_cookie_free( mbedtls_ssl_cookie_ctx *ctx ); |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 104 | |
| 105 | /** |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 106 | * \brief Generate cookie, see \c mbedtls_ssl_cookie_write_t |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 107 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 108 | mbedtls_ssl_cookie_write_t mbedtls_ssl_cookie_write; |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 109 | |
| 110 | /** |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 111 | * \brief Verify cookie, see \c mbedtls_ssl_cookie_write_t |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 112 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 113 | mbedtls_ssl_cookie_check_t mbedtls_ssl_cookie_check; |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 114 | |
| 115 | #ifdef __cplusplus |
| 116 | } |
| 117 | #endif |
| 118 | |
| 119 | #endif /* ssl_cookie.h */ |