mbed TLS library
Dependents: HTTPClient-SSL WS_SERVER
include/polarssl/ssl_cache.h@0:137634ff4186, 2015-06-11 (annotated)
- Committer:
- ansond
- Date:
- Thu Jun 11 03:27:03 2015 +0000
- Revision:
- 0:137634ff4186
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 0:137634ff4186 | 1 | /** |
ansond | 0:137634ff4186 | 2 | * \file ssl_cache.h |
ansond | 0:137634ff4186 | 3 | * |
ansond | 0:137634ff4186 | 4 | * \brief SSL session cache implementation |
ansond | 0:137634ff4186 | 5 | * |
ansond | 0:137634ff4186 | 6 | * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved |
ansond | 0:137634ff4186 | 7 | * |
ansond | 0:137634ff4186 | 8 | * This file is part of mbed TLS (https://tls.mbed.org) |
ansond | 0:137634ff4186 | 9 | * |
ansond | 0:137634ff4186 | 10 | * This program is free software; you can redistribute it and/or modify |
ansond | 0:137634ff4186 | 11 | * it under the terms of the GNU General Public License as published by |
ansond | 0:137634ff4186 | 12 | * the Free Software Foundation; either version 2 of the License, or |
ansond | 0:137634ff4186 | 13 | * (at your option) any later version. |
ansond | 0:137634ff4186 | 14 | * |
ansond | 0:137634ff4186 | 15 | * This program is distributed in the hope that it will be useful, |
ansond | 0:137634ff4186 | 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ansond | 0:137634ff4186 | 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ansond | 0:137634ff4186 | 18 | * GNU General Public License for more details. |
ansond | 0:137634ff4186 | 19 | * |
ansond | 0:137634ff4186 | 20 | * You should have received a copy of the GNU General Public License along |
ansond | 0:137634ff4186 | 21 | * with this program; if not, write to the Free Software Foundation, Inc., |
ansond | 0:137634ff4186 | 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
ansond | 0:137634ff4186 | 23 | */ |
ansond | 0:137634ff4186 | 24 | #ifndef POLARSSL_SSL_CACHE_H |
ansond | 0:137634ff4186 | 25 | #define POLARSSL_SSL_CACHE_H |
ansond | 0:137634ff4186 | 26 | |
ansond | 0:137634ff4186 | 27 | #include "ssl.h" |
ansond | 0:137634ff4186 | 28 | |
ansond | 0:137634ff4186 | 29 | #if defined(POLARSSL_THREADING_C) |
ansond | 0:137634ff4186 | 30 | #include "threading.h" |
ansond | 0:137634ff4186 | 31 | #endif |
ansond | 0:137634ff4186 | 32 | |
ansond | 0:137634ff4186 | 33 | /** |
ansond | 0:137634ff4186 | 34 | * \name SECTION: Module settings |
ansond | 0:137634ff4186 | 35 | * |
ansond | 0:137634ff4186 | 36 | * The configuration options you can set for this module are in this section. |
ansond | 0:137634ff4186 | 37 | * Either change them in config.h or define them on the compiler command line. |
ansond | 0:137634ff4186 | 38 | * \{ |
ansond | 0:137634ff4186 | 39 | */ |
ansond | 0:137634ff4186 | 40 | |
ansond | 0:137634ff4186 | 41 | #if !defined(SSL_CACHE_DEFAULT_TIMEOUT) |
ansond | 0:137634ff4186 | 42 | #define SSL_CACHE_DEFAULT_TIMEOUT 86400 /*!< 1 day */ |
ansond | 0:137634ff4186 | 43 | #endif |
ansond | 0:137634ff4186 | 44 | |
ansond | 0:137634ff4186 | 45 | #if !defined(SSL_CACHE_DEFAULT_MAX_ENTRIES) |
ansond | 0:137634ff4186 | 46 | #define SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /*!< Maximum entries in cache */ |
ansond | 0:137634ff4186 | 47 | #endif |
ansond | 0:137634ff4186 | 48 | |
ansond | 0:137634ff4186 | 49 | /* \} name SECTION: Module settings */ |
ansond | 0:137634ff4186 | 50 | |
ansond | 0:137634ff4186 | 51 | #ifdef __cplusplus |
ansond | 0:137634ff4186 | 52 | extern "C" { |
ansond | 0:137634ff4186 | 53 | #endif |
ansond | 0:137634ff4186 | 54 | |
ansond | 0:137634ff4186 | 55 | typedef struct _ssl_cache_context ssl_cache_context; |
ansond | 0:137634ff4186 | 56 | typedef struct _ssl_cache_entry ssl_cache_entry; |
ansond | 0:137634ff4186 | 57 | |
ansond | 0:137634ff4186 | 58 | /** |
ansond | 0:137634ff4186 | 59 | * \brief This structure is used for storing cache entries |
ansond | 0:137634ff4186 | 60 | */ |
ansond | 0:137634ff4186 | 61 | struct _ssl_cache_entry |
ansond | 0:137634ff4186 | 62 | { |
ansond | 0:137634ff4186 | 63 | #if defined(POLARSSL_HAVE_TIME) |
ansond | 0:137634ff4186 | 64 | time_t timestamp; /*!< entry timestamp */ |
ansond | 0:137634ff4186 | 65 | #endif |
ansond | 0:137634ff4186 | 66 | ssl_session session; /*!< entry session */ |
ansond | 0:137634ff4186 | 67 | #if defined(POLARSSL_X509_CRT_PARSE_C) |
ansond | 0:137634ff4186 | 68 | x509_buf peer_cert; /*!< entry peer_cert */ |
ansond | 0:137634ff4186 | 69 | #endif |
ansond | 0:137634ff4186 | 70 | ssl_cache_entry *next; /*!< chain pointer */ |
ansond | 0:137634ff4186 | 71 | }; |
ansond | 0:137634ff4186 | 72 | |
ansond | 0:137634ff4186 | 73 | /** |
ansond | 0:137634ff4186 | 74 | * \brief Cache context |
ansond | 0:137634ff4186 | 75 | */ |
ansond | 0:137634ff4186 | 76 | struct _ssl_cache_context |
ansond | 0:137634ff4186 | 77 | { |
ansond | 0:137634ff4186 | 78 | ssl_cache_entry *chain; /*!< start of the chain */ |
ansond | 0:137634ff4186 | 79 | int timeout; /*!< cache entry timeout */ |
ansond | 0:137634ff4186 | 80 | int max_entries; /*!< maximum entries */ |
ansond | 0:137634ff4186 | 81 | #if defined(POLARSSL_THREADING_C) |
ansond | 0:137634ff4186 | 82 | threading_mutex_t mutex; /*!< mutex */ |
ansond | 0:137634ff4186 | 83 | #endif |
ansond | 0:137634ff4186 | 84 | }; |
ansond | 0:137634ff4186 | 85 | |
ansond | 0:137634ff4186 | 86 | /** |
ansond | 0:137634ff4186 | 87 | * \brief Initialize an SSL cache context |
ansond | 0:137634ff4186 | 88 | * |
ansond | 0:137634ff4186 | 89 | * \param cache SSL cache context |
ansond | 0:137634ff4186 | 90 | */ |
ansond | 0:137634ff4186 | 91 | void ssl_cache_init( ssl_cache_context *cache ); |
ansond | 0:137634ff4186 | 92 | |
ansond | 0:137634ff4186 | 93 | /** |
ansond | 0:137634ff4186 | 94 | * \brief Cache get callback implementation |
ansond | 0:137634ff4186 | 95 | * (Thread-safe if POLARSSL_THREADING_C is enabled) |
ansond | 0:137634ff4186 | 96 | * |
ansond | 0:137634ff4186 | 97 | * \param data SSL cache context |
ansond | 0:137634ff4186 | 98 | * \param session session to retrieve entry for |
ansond | 0:137634ff4186 | 99 | */ |
ansond | 0:137634ff4186 | 100 | int ssl_cache_get( void *data, ssl_session *session ); |
ansond | 0:137634ff4186 | 101 | |
ansond | 0:137634ff4186 | 102 | /** |
ansond | 0:137634ff4186 | 103 | * \brief Cache set callback implementation |
ansond | 0:137634ff4186 | 104 | * (Thread-safe if POLARSSL_THREADING_C is enabled) |
ansond | 0:137634ff4186 | 105 | * |
ansond | 0:137634ff4186 | 106 | * \param data SSL cache context |
ansond | 0:137634ff4186 | 107 | * \param session session to store entry for |
ansond | 0:137634ff4186 | 108 | */ |
ansond | 0:137634ff4186 | 109 | int ssl_cache_set( void *data, const ssl_session *session ); |
ansond | 0:137634ff4186 | 110 | |
ansond | 0:137634ff4186 | 111 | #if defined(POLARSSL_HAVE_TIME) |
ansond | 0:137634ff4186 | 112 | /** |
ansond | 0:137634ff4186 | 113 | * \brief Set the cache timeout |
ansond | 0:137634ff4186 | 114 | * (Default: SSL_CACHE_DEFAULT_TIMEOUT (1 day)) |
ansond | 0:137634ff4186 | 115 | * |
ansond | 0:137634ff4186 | 116 | * A timeout of 0 indicates no timeout. |
ansond | 0:137634ff4186 | 117 | * |
ansond | 0:137634ff4186 | 118 | * \param cache SSL cache context |
ansond | 0:137634ff4186 | 119 | * \param timeout cache entry timeout in seconds |
ansond | 0:137634ff4186 | 120 | */ |
ansond | 0:137634ff4186 | 121 | void ssl_cache_set_timeout( ssl_cache_context *cache, int timeout ); |
ansond | 0:137634ff4186 | 122 | #endif /* POLARSSL_HAVE_TIME */ |
ansond | 0:137634ff4186 | 123 | |
ansond | 0:137634ff4186 | 124 | /** |
ansond | 0:137634ff4186 | 125 | * \brief Set the cache timeout |
ansond | 0:137634ff4186 | 126 | * (Default: SSL_CACHE_DEFAULT_MAX_ENTRIES (50)) |
ansond | 0:137634ff4186 | 127 | * |
ansond | 0:137634ff4186 | 128 | * \param cache SSL cache context |
ansond | 0:137634ff4186 | 129 | * \param max cache entry maximum |
ansond | 0:137634ff4186 | 130 | */ |
ansond | 0:137634ff4186 | 131 | void ssl_cache_set_max_entries( ssl_cache_context *cache, int max ); |
ansond | 0:137634ff4186 | 132 | |
ansond | 0:137634ff4186 | 133 | /** |
ansond | 0:137634ff4186 | 134 | * \brief Free referenced items in a cache context and clear memory |
ansond | 0:137634ff4186 | 135 | * |
ansond | 0:137634ff4186 | 136 | * \param cache SSL cache context |
ansond | 0:137634ff4186 | 137 | */ |
ansond | 0:137634ff4186 | 138 | void ssl_cache_free( ssl_cache_context *cache ); |
ansond | 0:137634ff4186 | 139 | |
ansond | 0:137634ff4186 | 140 | #ifdef __cplusplus |
ansond | 0:137634ff4186 | 141 | } |
ansond | 0:137634ff4186 | 142 | #endif |
ansond | 0:137634ff4186 | 143 | |
ansond | 0:137634ff4186 | 144 | #endif /* ssl_cache.h */ |
ansond | 0:137634ff4186 | 145 |