mbed TLS Build
include/mbedtls/ssl_cache.h@0:cdf462088d13, 2017-01-05 (annotated)
- Committer:
- markrad
- Date:
- Thu Jan 05 00:18:44 2017 +0000
- Revision:
- 0:cdf462088d13
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
markrad | 0:cdf462088d13 | 1 | /** |
markrad | 0:cdf462088d13 | 2 | * \file ssl_cache.h |
markrad | 0:cdf462088d13 | 3 | * |
markrad | 0:cdf462088d13 | 4 | * \brief SSL session cache implementation |
markrad | 0:cdf462088d13 | 5 | * |
markrad | 0:cdf462088d13 | 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
markrad | 0:cdf462088d13 | 7 | * SPDX-License-Identifier: Apache-2.0 |
markrad | 0:cdf462088d13 | 8 | * |
markrad | 0:cdf462088d13 | 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
markrad | 0:cdf462088d13 | 10 | * not use this file except in compliance with the License. |
markrad | 0:cdf462088d13 | 11 | * You may obtain a copy of the License at |
markrad | 0:cdf462088d13 | 12 | * |
markrad | 0:cdf462088d13 | 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
markrad | 0:cdf462088d13 | 14 | * |
markrad | 0:cdf462088d13 | 15 | * Unless required by applicable law or agreed to in writing, software |
markrad | 0:cdf462088d13 | 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
markrad | 0:cdf462088d13 | 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
markrad | 0:cdf462088d13 | 18 | * See the License for the specific language governing permissions and |
markrad | 0:cdf462088d13 | 19 | * limitations under the License. |
markrad | 0:cdf462088d13 | 20 | * |
markrad | 0:cdf462088d13 | 21 | * This file is part of mbed TLS (https://tls.mbed.org) |
markrad | 0:cdf462088d13 | 22 | */ |
markrad | 0:cdf462088d13 | 23 | #ifndef MBEDTLS_SSL_CACHE_H |
markrad | 0:cdf462088d13 | 24 | #define MBEDTLS_SSL_CACHE_H |
markrad | 0:cdf462088d13 | 25 | |
markrad | 0:cdf462088d13 | 26 | #include "ssl.h" |
markrad | 0:cdf462088d13 | 27 | |
markrad | 0:cdf462088d13 | 28 | #if defined(MBEDTLS_THREADING_C) |
markrad | 0:cdf462088d13 | 29 | #include "threading.h" |
markrad | 0:cdf462088d13 | 30 | #endif |
markrad | 0:cdf462088d13 | 31 | |
markrad | 0:cdf462088d13 | 32 | /** |
markrad | 0:cdf462088d13 | 33 | * \name SECTION: Module settings |
markrad | 0:cdf462088d13 | 34 | * |
markrad | 0:cdf462088d13 | 35 | * The configuration options you can set for this module are in this section. |
markrad | 0:cdf462088d13 | 36 | * Either change them in config.h or define them on the compiler command line. |
markrad | 0:cdf462088d13 | 37 | * \{ |
markrad | 0:cdf462088d13 | 38 | */ |
markrad | 0:cdf462088d13 | 39 | |
markrad | 0:cdf462088d13 | 40 | #if !defined(MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT) |
markrad | 0:cdf462088d13 | 41 | #define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT 86400 /*!< 1 day */ |
markrad | 0:cdf462088d13 | 42 | #endif |
markrad | 0:cdf462088d13 | 43 | |
markrad | 0:cdf462088d13 | 44 | #if !defined(MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES) |
markrad | 0:cdf462088d13 | 45 | #define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /*!< Maximum entries in cache */ |
markrad | 0:cdf462088d13 | 46 | #endif |
markrad | 0:cdf462088d13 | 47 | |
markrad | 0:cdf462088d13 | 48 | /* \} name SECTION: Module settings */ |
markrad | 0:cdf462088d13 | 49 | |
markrad | 0:cdf462088d13 | 50 | #ifdef __cplusplus |
markrad | 0:cdf462088d13 | 51 | extern "C" { |
markrad | 0:cdf462088d13 | 52 | #endif |
markrad | 0:cdf462088d13 | 53 | |
markrad | 0:cdf462088d13 | 54 | typedef struct mbedtls_ssl_cache_context mbedtls_ssl_cache_context; |
markrad | 0:cdf462088d13 | 55 | typedef struct mbedtls_ssl_cache_entry mbedtls_ssl_cache_entry; |
markrad | 0:cdf462088d13 | 56 | |
markrad | 0:cdf462088d13 | 57 | /** |
markrad | 0:cdf462088d13 | 58 | * \brief This structure is used for storing cache entries |
markrad | 0:cdf462088d13 | 59 | */ |
markrad | 0:cdf462088d13 | 60 | struct mbedtls_ssl_cache_entry |
markrad | 0:cdf462088d13 | 61 | { |
markrad | 0:cdf462088d13 | 62 | #if defined(MBEDTLS_HAVE_TIME) |
markrad | 0:cdf462088d13 | 63 | mbedtls_time_t timestamp; /*!< entry timestamp */ |
markrad | 0:cdf462088d13 | 64 | #endif |
markrad | 0:cdf462088d13 | 65 | mbedtls_ssl_session session; /*!< entry session */ |
markrad | 0:cdf462088d13 | 66 | #if defined(MBEDTLS_X509_CRT_PARSE_C) |
markrad | 0:cdf462088d13 | 67 | mbedtls_x509_buf peer_cert; /*!< entry peer_cert */ |
markrad | 0:cdf462088d13 | 68 | #endif |
markrad | 0:cdf462088d13 | 69 | mbedtls_ssl_cache_entry *next; /*!< chain pointer */ |
markrad | 0:cdf462088d13 | 70 | }; |
markrad | 0:cdf462088d13 | 71 | |
markrad | 0:cdf462088d13 | 72 | /** |
markrad | 0:cdf462088d13 | 73 | * \brief Cache context |
markrad | 0:cdf462088d13 | 74 | */ |
markrad | 0:cdf462088d13 | 75 | struct mbedtls_ssl_cache_context |
markrad | 0:cdf462088d13 | 76 | { |
markrad | 0:cdf462088d13 | 77 | mbedtls_ssl_cache_entry *chain; /*!< start of the chain */ |
markrad | 0:cdf462088d13 | 78 | int timeout; /*!< cache entry timeout */ |
markrad | 0:cdf462088d13 | 79 | int max_entries; /*!< maximum entries */ |
markrad | 0:cdf462088d13 | 80 | #if defined(MBEDTLS_THREADING_C) |
markrad | 0:cdf462088d13 | 81 | mbedtls_threading_mutex_t mutex; /*!< mutex */ |
markrad | 0:cdf462088d13 | 82 | #endif |
markrad | 0:cdf462088d13 | 83 | }; |
markrad | 0:cdf462088d13 | 84 | |
markrad | 0:cdf462088d13 | 85 | /** |
markrad | 0:cdf462088d13 | 86 | * \brief Initialize an SSL cache context |
markrad | 0:cdf462088d13 | 87 | * |
markrad | 0:cdf462088d13 | 88 | * \param cache SSL cache context |
markrad | 0:cdf462088d13 | 89 | */ |
markrad | 0:cdf462088d13 | 90 | void mbedtls_ssl_cache_init( mbedtls_ssl_cache_context *cache ); |
markrad | 0:cdf462088d13 | 91 | |
markrad | 0:cdf462088d13 | 92 | /** |
markrad | 0:cdf462088d13 | 93 | * \brief Cache get callback implementation |
markrad | 0:cdf462088d13 | 94 | * (Thread-safe if MBEDTLS_THREADING_C is enabled) |
markrad | 0:cdf462088d13 | 95 | * |
markrad | 0:cdf462088d13 | 96 | * \param data SSL cache context |
markrad | 0:cdf462088d13 | 97 | * \param session session to retrieve entry for |
markrad | 0:cdf462088d13 | 98 | */ |
markrad | 0:cdf462088d13 | 99 | int mbedtls_ssl_cache_get( void *data, mbedtls_ssl_session *session ); |
markrad | 0:cdf462088d13 | 100 | |
markrad | 0:cdf462088d13 | 101 | /** |
markrad | 0:cdf462088d13 | 102 | * \brief Cache set callback implementation |
markrad | 0:cdf462088d13 | 103 | * (Thread-safe if MBEDTLS_THREADING_C is enabled) |
markrad | 0:cdf462088d13 | 104 | * |
markrad | 0:cdf462088d13 | 105 | * \param data SSL cache context |
markrad | 0:cdf462088d13 | 106 | * \param session session to store entry for |
markrad | 0:cdf462088d13 | 107 | */ |
markrad | 0:cdf462088d13 | 108 | int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session ); |
markrad | 0:cdf462088d13 | 109 | |
markrad | 0:cdf462088d13 | 110 | #if defined(MBEDTLS_HAVE_TIME) |
markrad | 0:cdf462088d13 | 111 | /** |
markrad | 0:cdf462088d13 | 112 | * \brief Set the cache timeout |
markrad | 0:cdf462088d13 | 113 | * (Default: MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT (1 day)) |
markrad | 0:cdf462088d13 | 114 | * |
markrad | 0:cdf462088d13 | 115 | * A timeout of 0 indicates no timeout. |
markrad | 0:cdf462088d13 | 116 | * |
markrad | 0:cdf462088d13 | 117 | * \param cache SSL cache context |
markrad | 0:cdf462088d13 | 118 | * \param timeout cache entry timeout in seconds |
markrad | 0:cdf462088d13 | 119 | */ |
markrad | 0:cdf462088d13 | 120 | void mbedtls_ssl_cache_set_timeout( mbedtls_ssl_cache_context *cache, int timeout ); |
markrad | 0:cdf462088d13 | 121 | #endif /* MBEDTLS_HAVE_TIME */ |
markrad | 0:cdf462088d13 | 122 | |
markrad | 0:cdf462088d13 | 123 | /** |
markrad | 0:cdf462088d13 | 124 | * \brief Set the maximum number of cache entries |
markrad | 0:cdf462088d13 | 125 | * (Default: MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES (50)) |
markrad | 0:cdf462088d13 | 126 | * |
markrad | 0:cdf462088d13 | 127 | * \param cache SSL cache context |
markrad | 0:cdf462088d13 | 128 | * \param max cache entry maximum |
markrad | 0:cdf462088d13 | 129 | */ |
markrad | 0:cdf462088d13 | 130 | void mbedtls_ssl_cache_set_max_entries( mbedtls_ssl_cache_context *cache, int max ); |
markrad | 0:cdf462088d13 | 131 | |
markrad | 0:cdf462088d13 | 132 | /** |
markrad | 0:cdf462088d13 | 133 | * \brief Free referenced items in a cache context and clear memory |
markrad | 0:cdf462088d13 | 134 | * |
markrad | 0:cdf462088d13 | 135 | * \param cache SSL cache context |
markrad | 0:cdf462088d13 | 136 | */ |
markrad | 0:cdf462088d13 | 137 | void mbedtls_ssl_cache_free( mbedtls_ssl_cache_context *cache ); |
markrad | 0:cdf462088d13 | 138 | |
markrad | 0:cdf462088d13 | 139 | #ifdef __cplusplus |
markrad | 0:cdf462088d13 | 140 | } |
markrad | 0:cdf462088d13 | 141 | #endif |
markrad | 0:cdf462088d13 | 142 | |
markrad | 0:cdf462088d13 | 143 | #endif /* ssl_cache.h */ |