blob: cdb200c0519c24c93beab38078b7f11e9f179a32 [file] [log] [blame]
Paul Bakker0a597072012-09-25 21:55:46 +00001/**
2 * \file ssl_cache.h
3 *
4 * \brief SSL session cache implementation
5 *
Paul Bakker530927b2015-02-13 14:24:10 +01006 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Paul Bakker0a597072012-09-25 21:55:46 +00007 *
Manuel Pégourié-Gonnarde12abf92015-01-28 17:13:45 +00008 * This file is part of mbed TLS (https://polarssl.org)
Paul Bakker0a597072012-09-25 21:55:46 +00009 *
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_CACHE_H
25#define POLARSSL_SSL_CACHE_H
26
27#include "ssl.h"
28
Paul Bakker6fa54882013-06-17 15:44:03 +020029#if !defined(POLARSSL_CONFIG_OPTIONS)
Paul Bakkerba26e9e2012-10-23 22:18:28 +000030#define SSL_CACHE_DEFAULT_TIMEOUT 86400 /*!< 1 day */
31#define SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /*!< Maximum entries in cache */
Paul Bakker6fa54882013-06-17 15:44:03 +020032#endif /* !POLARSSL_CONFIG_OPTIONS */
Paul Bakker0a597072012-09-25 21:55:46 +000033
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38typedef struct _ssl_cache_context ssl_cache_context;
39typedef struct _ssl_cache_entry ssl_cache_entry;
40
41/**
42 * \brief This structure is used for storing cache entries
43 */
44struct _ssl_cache_entry
45{
46 time_t timestamp; /*!< entry timestamp */
47 ssl_session session; /*!< entry session */
Paul Bakkere81beda2013-03-06 17:40:46 +010048 x509_buf peer_cert; /*!< entry peer_cert */
Paul Bakker0a597072012-09-25 21:55:46 +000049 ssl_cache_entry *next; /*!< chain pointer */
50};
51
52/**
53 * \brief Cache context
54 */
55struct _ssl_cache_context
56{
Paul Bakkerba26e9e2012-10-23 22:18:28 +000057 ssl_cache_entry *chain; /*!< start of the chain */
58 int timeout; /*!< cache entry timeout */
59 int max_entries; /*!< maximum entries */
Paul Bakker0a597072012-09-25 21:55:46 +000060};
61
62/**
63 * \brief Initialize an SSL cache context
64 *
65 * \param cache SSL cache context
66 */
67void ssl_cache_init( ssl_cache_context *cache );
68
69/**
70 * \brief Cache get callback implementation
71 *
72 * \param data SSL cache context
73 * \param session session to retrieve entry for
74 */
75int ssl_cache_get( void *data, ssl_session *session );
76
77/**
78 * \brief Cache set callback implementation
79 *
80 * \param data SSL cache context
81 * \param session session to store entry for
82 */
83int ssl_cache_set( void *data, const ssl_session *session );
84
85/**
86 * \brief Set the cache timeout
87 * (Default: SSL_CACHE_DEFAULT_TIMEOUT (1 day))
88 *
89 * A timeout of 0 indicates no timeout.
90 *
91 * \param cache SSL cache context
92 * \param timeout cache entry timeout
93 */
94void ssl_cache_set_timeout( ssl_cache_context *cache, int timeout );
95
96/**
Paul Bakkerba26e9e2012-10-23 22:18:28 +000097 * \brief Set the cache timeout
98 * (Default: SSL_CACHE_DEFAULT_MAX_ENTRIES (50))
99 *
100 * \param cache SSL cache context
101 * \param max cache entry maximum
102 */
103void ssl_cache_set_max_entries( ssl_cache_context *cache, int max );
104
105/**
Paul Bakker0a597072012-09-25 21:55:46 +0000106 * \brief Free referenced items in a cache context and clear memory
107 *
108 * \param cache SSL cache context
109 */
110void ssl_cache_free( ssl_cache_context *cache );
111
112#ifdef __cplusplus
113}
114#endif
115
116#endif /* ssl_cache.h */