Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
ssl_cache.h
00001 /** 00002 * \file ssl_cache.h 00003 * 00004 * \brief SSL session cache implementation 00005 */ 00006 /* 00007 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 00008 * SPDX-License-Identifier: Apache-2.0 00009 * 00010 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00011 * not use this file except in compliance with the License. 00012 * You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, software 00017 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00018 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 * See the License for the specific language governing permissions and 00020 * limitations under the License. 00021 * 00022 * This file is part of mbed TLS (https://tls.mbed.org) 00023 */ 00024 #ifndef MBEDTLS_SSL_CACHE_H 00025 #define MBEDTLS_SSL_CACHE_H 00026 00027 #if !defined(MBEDTLS_CONFIG_FILE) 00028 #include "mbedtls/config.h" 00029 #else 00030 #include MBEDTLS_CONFIG_FILE 00031 #endif 00032 00033 #include "mbedtls/ssl.h" 00034 00035 #if defined(MBEDTLS_THREADING_C) 00036 #include "mbedtls/threading.h" 00037 #endif 00038 00039 /** 00040 * \name SECTION: Module settings 00041 * 00042 * The configuration options you can set for this module are in this section. 00043 * Either change them in config.h or define them on the compiler command line. 00044 * \{ 00045 */ 00046 00047 #if !defined(MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT) 00048 #define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT 86400 /*!< 1 day */ 00049 #endif 00050 00051 #if !defined(MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES) 00052 #define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /*!< Maximum entries in cache */ 00053 #endif 00054 00055 /* \} name SECTION: Module settings */ 00056 00057 #ifdef __cplusplus 00058 extern "C" { 00059 #endif 00060 00061 typedef struct mbedtls_ssl_cache_context mbedtls_ssl_cache_context; 00062 typedef struct mbedtls_ssl_cache_entry mbedtls_ssl_cache_entry; 00063 00064 /** 00065 * \brief This structure is used for storing cache entries 00066 */ 00067 struct mbedtls_ssl_cache_entry 00068 { 00069 #if defined(MBEDTLS_HAVE_TIME) 00070 mbedtls_time_t timestamp ; /*!< entry timestamp */ 00071 #endif 00072 mbedtls_ssl_session session ; /*!< entry session */ 00073 #if defined(MBEDTLS_X509_CRT_PARSE_C) && \ 00074 defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) 00075 mbedtls_x509_buf peer_cert ; /*!< entry peer_cert */ 00076 #endif 00077 mbedtls_ssl_cache_entry *next ; /*!< chain pointer */ 00078 }; 00079 00080 /** 00081 * \brief Cache context 00082 */ 00083 struct mbedtls_ssl_cache_context 00084 { 00085 mbedtls_ssl_cache_entry *chain ; /*!< start of the chain */ 00086 int timeout ; /*!< cache entry timeout */ 00087 int max_entries ; /*!< maximum entries */ 00088 #if defined(MBEDTLS_THREADING_C) 00089 mbedtls_threading_mutex_t mutex ; /*!< mutex */ 00090 #endif 00091 }; 00092 00093 /** 00094 * \brief Initialize an SSL cache context 00095 * 00096 * \param cache SSL cache context 00097 */ 00098 void mbedtls_ssl_cache_init( mbedtls_ssl_cache_context *cache ); 00099 00100 /** 00101 * \brief Cache get callback implementation 00102 * (Thread-safe if MBEDTLS_THREADING_C is enabled) 00103 * 00104 * \param data SSL cache context 00105 * \param session session to retrieve entry for 00106 */ 00107 int mbedtls_ssl_cache_get( void *data, mbedtls_ssl_session *session ); 00108 00109 /** 00110 * \brief Cache set callback implementation 00111 * (Thread-safe if MBEDTLS_THREADING_C is enabled) 00112 * 00113 * \param data SSL cache context 00114 * \param session session to store entry for 00115 */ 00116 int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session ); 00117 00118 #if defined(MBEDTLS_HAVE_TIME) 00119 /** 00120 * \brief Set the cache timeout 00121 * (Default: MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT (1 day)) 00122 * 00123 * A timeout of 0 indicates no timeout. 00124 * 00125 * \param cache SSL cache context 00126 * \param timeout cache entry timeout in seconds 00127 */ 00128 void mbedtls_ssl_cache_set_timeout( mbedtls_ssl_cache_context *cache, int timeout ); 00129 #endif /* MBEDTLS_HAVE_TIME */ 00130 00131 /** 00132 * \brief Set the maximum number of cache entries 00133 * (Default: MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES (50)) 00134 * 00135 * \param cache SSL cache context 00136 * \param max cache entry maximum 00137 */ 00138 void mbedtls_ssl_cache_set_max_entries( mbedtls_ssl_cache_context *cache, int max ); 00139 00140 /** 00141 * \brief Free referenced items in a cache context and clear memory 00142 * 00143 * \param cache SSL cache context 00144 */ 00145 void mbedtls_ssl_cache_free( mbedtls_ssl_cache_context *cache ); 00146 00147 #ifdef __cplusplus 00148 } 00149 #endif 00150 00151 #endif /* ssl_cache.h */
Generated on Tue Jul 12 2022 13:54:52 by
