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 |
| 5 | * |
| 6 | * Copyright (C) 2014, Brainspark B.V. |
| 7 | * |
Manuel Pégourié-Gonnard | e4d4890 | 2015-03-06 13:40:52 +0000 | [diff] [blame] | 8 | * This file is part of mbed TLS (https://tls.mbed.org) |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License along |
| 21 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 23 | */ |
| 24 | #ifndef POLARSSL_SSL_COOKIE_H |
| 25 | #define POLARSSL_SSL_COOKIE_H |
| 26 | |
| 27 | #include "ssl.h" |
| 28 | |
| 29 | /** |
| 30 | * \name SECTION: Module settings |
| 31 | * |
| 32 | * The configuration options you can set for this module are in this section. |
| 33 | * Either change them in config.h or define them on the compiler command line. |
| 34 | * \{ |
| 35 | */ |
Manuel Pégourié-Gonnard | bef8f09 | 2014-07-23 23:40:29 +0200 | [diff] [blame] | 36 | #ifndef POLARSSL_SSL_COOKIE_TIMEOUT |
| 37 | #define POLARSSL_SSL_COOKIE_TIMEOUT 60 /**< Default expiration delay of DTLS cookies, in seconds if HAVE_TIME, or in number of cookies issued */ |
| 38 | #endif |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 39 | |
| 40 | /* \} name SECTION: Module settings */ |
| 41 | |
| 42 | #ifdef __cplusplus |
| 43 | extern "C" { |
| 44 | #endif |
| 45 | |
| 46 | /** |
| 47 | * \brief Context for the default cookie functions. |
| 48 | */ |
| 49 | typedef struct |
| 50 | { |
Manuel Pégourié-Gonnard | bef8f09 | 2014-07-23 23:40:29 +0200 | [diff] [blame] | 51 | md_context_t hmac_ctx; /*!< context for the HMAC portion */ |
Manuel Pégourié-Gonnard | e903081 | 2014-07-23 21:29:11 +0200 | [diff] [blame] | 52 | #if !defined(POLARSSL_HAVE_TIME) |
Manuel Pégourié-Gonnard | bef8f09 | 2014-07-23 23:40:29 +0200 | [diff] [blame] | 53 | unsigned long serial; /*!< serial number for expiration */ |
Manuel Pégourié-Gonnard | e903081 | 2014-07-23 21:29:11 +0200 | [diff] [blame] | 54 | #endif |
Manuel Pégourié-Gonnard | bef8f09 | 2014-07-23 23:40:29 +0200 | [diff] [blame] | 55 | unsigned long timeout; /*!< timeout delay, in seconds if HAVE_TIME, |
| 56 | or in number of tickets issued */ |
| 57 | |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 58 | } ssl_cookie_ctx; |
| 59 | |
| 60 | /** |
| 61 | * \brief Initialize cookie context |
| 62 | */ |
| 63 | void ssl_cookie_init( ssl_cookie_ctx *ctx ); |
| 64 | |
| 65 | /** |
| 66 | * \brief Setup cookie context (generate keys) |
| 67 | */ |
| 68 | int ssl_cookie_setup( ssl_cookie_ctx *ctx, |
| 69 | int (*f_rng)(void *, unsigned char *, size_t), |
| 70 | void *p_rng ); |
| 71 | |
| 72 | /** |
Manuel Pégourié-Gonnard | bef8f09 | 2014-07-23 23:40:29 +0200 | [diff] [blame] | 73 | * \brief Set expiration delay for cookies |
| 74 | * (Default POLARSSL_SSL_COOKIE_TIMEOUT) |
| 75 | * |
| 76 | * \param ctx Cookie contex |
| 77 | * \param delay Delay, in seconds if HAVE_TIME, or in number of cookies |
| 78 | * issued in the meantime. |
| 79 | * 0 to disable expiration (NOT recommended) |
| 80 | */ |
| 81 | void ssl_cookie_set_timeout( ssl_cookie_ctx *ctx, unsigned long delay ); |
| 82 | |
| 83 | /** |
Manuel Pégourié-Gonnard | 232edd4 | 2014-07-23 16:56:27 +0200 | [diff] [blame] | 84 | * \brief Free cookie context |
| 85 | */ |
| 86 | void ssl_cookie_free( ssl_cookie_ctx *ctx ); |
| 87 | |
| 88 | /** |
| 89 | * \brief Generate cookie, see \c ssl_cookie_write_t |
| 90 | */ |
| 91 | ssl_cookie_write_t ssl_cookie_write; |
| 92 | |
| 93 | /** |
| 94 | * \brief Verify cookie, see \c ssl_cookie_write_t |
| 95 | */ |
| 96 | ssl_cookie_check_t ssl_cookie_check; |
| 97 | |
| 98 | #ifdef __cplusplus |
| 99 | } |
| 100 | #endif |
| 101 | |
| 102 | #endif /* ssl_cookie.h */ |