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