Paul Bakker | 0a59707 | 2012-09-25 21:55:46 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file ssl_cache.h |
| 3 | * |
| 4 | * \brief SSL session cache implementation |
| 5 | * |
Paul Bakker | 9bcf16c | 2013-06-24 19:31:17 +0200 | [diff] [blame] | 6 | * Copyright (C) 2006-2013, Brainspark B.V. |
Paul Bakker | 0a59707 | 2012-09-25 21:55:46 +0000 | [diff] [blame] | 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_CACHE_H |
| 28 | #define POLARSSL_SSL_CACHE_H |
| 29 | |
| 30 | #include "ssl.h" |
| 31 | |
Paul Bakker | 9bcf16c | 2013-06-24 19:31:17 +0200 | [diff] [blame] | 32 | #if !defined(POLARSSL_CONFIG_OPTIONS) |
Paul Bakker | ba26e9e | 2012-10-23 22:18:28 +0000 | [diff] [blame] | 33 | #define SSL_CACHE_DEFAULT_TIMEOUT 86400 /*!< 1 day */ |
| 34 | #define SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /*!< Maximum entries in cache */ |
Paul Bakker | 9bcf16c | 2013-06-24 19:31:17 +0200 | [diff] [blame] | 35 | #endif /* !POLARSSL_CONFIG_OPTIONS */ |
Paul Bakker | 0a59707 | 2012-09-25 21:55:46 +0000 | [diff] [blame] | 36 | |
| 37 | #ifdef __cplusplus |
| 38 | extern "C" { |
| 39 | #endif |
| 40 | |
| 41 | typedef struct _ssl_cache_context ssl_cache_context; |
| 42 | typedef struct _ssl_cache_entry ssl_cache_entry; |
| 43 | |
| 44 | /** |
| 45 | * \brief This structure is used for storing cache entries |
| 46 | */ |
| 47 | struct _ssl_cache_entry |
| 48 | { |
Paul Bakker | fa9b100 | 2013-07-03 15:31:03 +0200 | [diff] [blame] | 49 | #if defined(POLARSSL_HAVE_TIME) |
Paul Bakker | 0a59707 | 2012-09-25 21:55:46 +0000 | [diff] [blame] | 50 | time_t timestamp; /*!< entry timestamp */ |
Paul Bakker | fa9b100 | 2013-07-03 15:31:03 +0200 | [diff] [blame] | 51 | #endif |
Paul Bakker | 0a59707 | 2012-09-25 21:55:46 +0000 | [diff] [blame] | 52 | ssl_session session; /*!< entry session */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame^] | 53 | #if defined(POLARSSL_X509_CRT_PARSE_C) |
Paul Bakker | e81beda | 2013-03-06 17:40:46 +0100 | [diff] [blame] | 54 | x509_buf peer_cert; /*!< entry peer_cert */ |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 55 | #endif |
Paul Bakker | 0a59707 | 2012-09-25 21:55:46 +0000 | [diff] [blame] | 56 | ssl_cache_entry *next; /*!< chain pointer */ |
| 57 | }; |
| 58 | |
| 59 | /** |
| 60 | * \brief Cache context |
| 61 | */ |
| 62 | struct _ssl_cache_context |
| 63 | { |
Paul Bakker | ba26e9e | 2012-10-23 22:18:28 +0000 | [diff] [blame] | 64 | ssl_cache_entry *chain; /*!< start of the chain */ |
| 65 | int timeout; /*!< cache entry timeout */ |
| 66 | int max_entries; /*!< maximum entries */ |
Paul Bakker | 0a59707 | 2012-09-25 21:55:46 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | /** |
| 70 | * \brief Initialize an SSL cache context |
| 71 | * |
| 72 | * \param cache SSL cache context |
| 73 | */ |
| 74 | void ssl_cache_init( ssl_cache_context *cache ); |
| 75 | |
| 76 | /** |
| 77 | * \brief Cache get callback implementation |
| 78 | * |
| 79 | * \param data SSL cache context |
| 80 | * \param session session to retrieve entry for |
| 81 | */ |
| 82 | int ssl_cache_get( void *data, ssl_session *session ); |
| 83 | |
| 84 | /** |
| 85 | * \brief Cache set callback implementation |
| 86 | * |
| 87 | * \param data SSL cache context |
| 88 | * \param session session to store entry for |
| 89 | */ |
| 90 | int ssl_cache_set( void *data, const ssl_session *session ); |
| 91 | |
Paul Bakker | fa9b100 | 2013-07-03 15:31:03 +0200 | [diff] [blame] | 92 | #if defined(POLARSSL_HAVE_TIME) |
Paul Bakker | 0a59707 | 2012-09-25 21:55:46 +0000 | [diff] [blame] | 93 | /** |
| 94 | * \brief Set the cache timeout |
| 95 | * (Default: SSL_CACHE_DEFAULT_TIMEOUT (1 day)) |
| 96 | * |
| 97 | * A timeout of 0 indicates no timeout. |
| 98 | * |
| 99 | * \param cache SSL cache context |
| 100 | * \param timeout cache entry timeout |
| 101 | */ |
| 102 | void ssl_cache_set_timeout( ssl_cache_context *cache, int timeout ); |
Paul Bakker | fa9b100 | 2013-07-03 15:31:03 +0200 | [diff] [blame] | 103 | #endif /* POLARSSL_HAVE_TIME */ |
Paul Bakker | 0a59707 | 2012-09-25 21:55:46 +0000 | [diff] [blame] | 104 | |
| 105 | /** |
Paul Bakker | ba26e9e | 2012-10-23 22:18:28 +0000 | [diff] [blame] | 106 | * \brief Set the cache timeout |
| 107 | * (Default: SSL_CACHE_DEFAULT_MAX_ENTRIES (50)) |
| 108 | * |
| 109 | * \param cache SSL cache context |
| 110 | * \param max cache entry maximum |
| 111 | */ |
| 112 | void ssl_cache_set_max_entries( ssl_cache_context *cache, int max ); |
| 113 | |
| 114 | /** |
Paul Bakker | 0a59707 | 2012-09-25 21:55:46 +0000 | [diff] [blame] | 115 | * \brief Free referenced items in a cache context and clear memory |
| 116 | * |
| 117 | * \param cache SSL cache context |
| 118 | */ |
| 119 | void ssl_cache_free( ssl_cache_context *cache ); |
| 120 | |
| 121 | #ifdef __cplusplus |
| 122 | } |
| 123 | #endif |
| 124 | |
| 125 | #endif /* ssl_cache.h */ |