blob: b00266c1a3bb87b1f85d3b9a90d7bbcee354ad92 [file] [log] [blame]
Manuel Pégourié-Gonnard232edd42014-07-23 16:56:27 +02001/**
2 * \file ssl_cookie.h
3 *
4 * \brief DTLS cookie callbacks implementation
5 *
6 * Copyright (C) 2014, Brainspark B.V.
7 *
Manuel Pégourié-Gonnarde4d48902015-03-06 13:40:52 +00008 * This file is part of mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnard232edd42014-07-23 16:56:27 +02009 *
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é-Gonnardbef8f092014-07-23 23:40:29 +020036#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é-Gonnard232edd42014-07-23 16:56:27 +020039
40/* \} name SECTION: Module settings */
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46/**
47 * \brief Context for the default cookie functions.
48 */
49typedef struct
50{
Manuel Pégourié-Gonnardbef8f092014-07-23 23:40:29 +020051 md_context_t hmac_ctx; /*!< context for the HMAC portion */
Manuel Pégourié-Gonnarde9030812014-07-23 21:29:11 +020052#if !defined(POLARSSL_HAVE_TIME)
Manuel Pégourié-Gonnardbef8f092014-07-23 23:40:29 +020053 unsigned long serial; /*!< serial number for expiration */
Manuel Pégourié-Gonnarde9030812014-07-23 21:29:11 +020054#endif
Manuel Pégourié-Gonnardbef8f092014-07-23 23:40:29 +020055 unsigned long timeout; /*!< timeout delay, in seconds if HAVE_TIME,
56 or in number of tickets issued */
57
Manuel Pégourié-Gonnard232edd42014-07-23 16:56:27 +020058} ssl_cookie_ctx;
59
60/**
61 * \brief Initialize cookie context
62 */
63void ssl_cookie_init( ssl_cookie_ctx *ctx );
64
65/**
66 * \brief Setup cookie context (generate keys)
67 */
68int 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é-Gonnardbef8f092014-07-23 23:40:29 +020073 * \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 */
81void ssl_cookie_set_timeout( ssl_cookie_ctx *ctx, unsigned long delay );
82
83/**
Manuel Pégourié-Gonnard232edd42014-07-23 16:56:27 +020084 * \brief Free cookie context
85 */
86void ssl_cookie_free( ssl_cookie_ctx *ctx );
87
88/**
89 * \brief Generate cookie, see \c ssl_cookie_write_t
90 */
91ssl_cookie_write_t ssl_cookie_write;
92
93/**
94 * \brief Verify cookie, see \c ssl_cookie_write_t
95 */
96ssl_cookie_check_t ssl_cookie_check;
97
98#ifdef __cplusplus
99}
100#endif
101
102#endif /* ssl_cookie.h */