Pinned to some recent date

Committer:
Simon Cooksey
Date:
Thu Nov 17 16:43:53 2016 +0000
Revision:
0:fb7af294d5d9
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Simon Cooksey 0:fb7af294d5d9 1 /*
Simon Cooksey 0:fb7af294d5d9 2 * SSL session cache implementation
Simon Cooksey 0:fb7af294d5d9 3 *
Simon Cooksey 0:fb7af294d5d9 4 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Simon Cooksey 0:fb7af294d5d9 5 * SPDX-License-Identifier: Apache-2.0
Simon Cooksey 0:fb7af294d5d9 6 *
Simon Cooksey 0:fb7af294d5d9 7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
Simon Cooksey 0:fb7af294d5d9 8 * not use this file except in compliance with the License.
Simon Cooksey 0:fb7af294d5d9 9 * You may obtain a copy of the License at
Simon Cooksey 0:fb7af294d5d9 10 *
Simon Cooksey 0:fb7af294d5d9 11 * http://www.apache.org/licenses/LICENSE-2.0
Simon Cooksey 0:fb7af294d5d9 12 *
Simon Cooksey 0:fb7af294d5d9 13 * Unless required by applicable law or agreed to in writing, software
Simon Cooksey 0:fb7af294d5d9 14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
Simon Cooksey 0:fb7af294d5d9 15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Simon Cooksey 0:fb7af294d5d9 16 * See the License for the specific language governing permissions and
Simon Cooksey 0:fb7af294d5d9 17 * limitations under the License.
Simon Cooksey 0:fb7af294d5d9 18 *
Simon Cooksey 0:fb7af294d5d9 19 * This file is part of mbed TLS (https://tls.mbed.org)
Simon Cooksey 0:fb7af294d5d9 20 */
Simon Cooksey 0:fb7af294d5d9 21 /*
Simon Cooksey 0:fb7af294d5d9 22 * These session callbacks use a simple chained list
Simon Cooksey 0:fb7af294d5d9 23 * to store and retrieve the session information.
Simon Cooksey 0:fb7af294d5d9 24 */
Simon Cooksey 0:fb7af294d5d9 25
Simon Cooksey 0:fb7af294d5d9 26 #if !defined(MBEDTLS_CONFIG_FILE)
Simon Cooksey 0:fb7af294d5d9 27 #include "mbedtls/config.h"
Simon Cooksey 0:fb7af294d5d9 28 #else
Simon Cooksey 0:fb7af294d5d9 29 #include MBEDTLS_CONFIG_FILE
Simon Cooksey 0:fb7af294d5d9 30 #endif
Simon Cooksey 0:fb7af294d5d9 31
Simon Cooksey 0:fb7af294d5d9 32 #if defined(MBEDTLS_SSL_CACHE_C)
Simon Cooksey 0:fb7af294d5d9 33
Simon Cooksey 0:fb7af294d5d9 34 #if defined(MBEDTLS_PLATFORM_C)
Simon Cooksey 0:fb7af294d5d9 35 #include "mbedtls/platform.h"
Simon Cooksey 0:fb7af294d5d9 36 #else
Simon Cooksey 0:fb7af294d5d9 37 #include <stdlib.h>
Simon Cooksey 0:fb7af294d5d9 38 #define mbedtls_calloc calloc
Simon Cooksey 0:fb7af294d5d9 39 #define mbedtls_free free
Simon Cooksey 0:fb7af294d5d9 40 #endif
Simon Cooksey 0:fb7af294d5d9 41
Simon Cooksey 0:fb7af294d5d9 42 #include "mbedtls/ssl_cache.h"
Simon Cooksey 0:fb7af294d5d9 43
Simon Cooksey 0:fb7af294d5d9 44 #include <string.h>
Simon Cooksey 0:fb7af294d5d9 45
Simon Cooksey 0:fb7af294d5d9 46 void mbedtls_ssl_cache_init( mbedtls_ssl_cache_context *cache )
Simon Cooksey 0:fb7af294d5d9 47 {
Simon Cooksey 0:fb7af294d5d9 48 memset( cache, 0, sizeof( mbedtls_ssl_cache_context ) );
Simon Cooksey 0:fb7af294d5d9 49
Simon Cooksey 0:fb7af294d5d9 50 cache->timeout = MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT;
Simon Cooksey 0:fb7af294d5d9 51 cache->max_entries = MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES;
Simon Cooksey 0:fb7af294d5d9 52
Simon Cooksey 0:fb7af294d5d9 53 #if defined(MBEDTLS_THREADING_C)
Simon Cooksey 0:fb7af294d5d9 54 mbedtls_mutex_init( &cache->mutex );
Simon Cooksey 0:fb7af294d5d9 55 #endif
Simon Cooksey 0:fb7af294d5d9 56 }
Simon Cooksey 0:fb7af294d5d9 57
Simon Cooksey 0:fb7af294d5d9 58 int mbedtls_ssl_cache_get( void *data, mbedtls_ssl_session *session )
Simon Cooksey 0:fb7af294d5d9 59 {
Simon Cooksey 0:fb7af294d5d9 60 int ret = 1;
Simon Cooksey 0:fb7af294d5d9 61 #if defined(MBEDTLS_HAVE_TIME)
Simon Cooksey 0:fb7af294d5d9 62 mbedtls_time_t t = mbedtls_time( NULL );
Simon Cooksey 0:fb7af294d5d9 63 #endif
Simon Cooksey 0:fb7af294d5d9 64 mbedtls_ssl_cache_context *cache = (mbedtls_ssl_cache_context *) data;
Simon Cooksey 0:fb7af294d5d9 65 mbedtls_ssl_cache_entry *cur, *entry;
Simon Cooksey 0:fb7af294d5d9 66
Simon Cooksey 0:fb7af294d5d9 67 #if defined(MBEDTLS_THREADING_C)
Simon Cooksey 0:fb7af294d5d9 68 if( mbedtls_mutex_lock( &cache->mutex ) != 0 )
Simon Cooksey 0:fb7af294d5d9 69 return( 1 );
Simon Cooksey 0:fb7af294d5d9 70 #endif
Simon Cooksey 0:fb7af294d5d9 71
Simon Cooksey 0:fb7af294d5d9 72 cur = cache->chain;
Simon Cooksey 0:fb7af294d5d9 73 entry = NULL;
Simon Cooksey 0:fb7af294d5d9 74
Simon Cooksey 0:fb7af294d5d9 75 while( cur != NULL )
Simon Cooksey 0:fb7af294d5d9 76 {
Simon Cooksey 0:fb7af294d5d9 77 entry = cur;
Simon Cooksey 0:fb7af294d5d9 78 cur = cur->next;
Simon Cooksey 0:fb7af294d5d9 79
Simon Cooksey 0:fb7af294d5d9 80 #if defined(MBEDTLS_HAVE_TIME)
Simon Cooksey 0:fb7af294d5d9 81 if( cache->timeout != 0 &&
Simon Cooksey 0:fb7af294d5d9 82 (int) ( t - entry->timestamp ) > cache->timeout )
Simon Cooksey 0:fb7af294d5d9 83 continue;
Simon Cooksey 0:fb7af294d5d9 84 #endif
Simon Cooksey 0:fb7af294d5d9 85
Simon Cooksey 0:fb7af294d5d9 86 if( session->ciphersuite != entry->session.ciphersuite ||
Simon Cooksey 0:fb7af294d5d9 87 session->compression != entry->session.compression ||
Simon Cooksey 0:fb7af294d5d9 88 session->id_len != entry->session.id_len )
Simon Cooksey 0:fb7af294d5d9 89 continue;
Simon Cooksey 0:fb7af294d5d9 90
Simon Cooksey 0:fb7af294d5d9 91 if( memcmp( session->id, entry->session.id,
Simon Cooksey 0:fb7af294d5d9 92 entry->session.id_len ) != 0 )
Simon Cooksey 0:fb7af294d5d9 93 continue;
Simon Cooksey 0:fb7af294d5d9 94
Simon Cooksey 0:fb7af294d5d9 95 memcpy( session->master, entry->session.master, 48 );
Simon Cooksey 0:fb7af294d5d9 96
Simon Cooksey 0:fb7af294d5d9 97 session->verify_result = entry->session.verify_result;
Simon Cooksey 0:fb7af294d5d9 98
Simon Cooksey 0:fb7af294d5d9 99 #if defined(MBEDTLS_X509_CRT_PARSE_C)
Simon Cooksey 0:fb7af294d5d9 100 /*
Simon Cooksey 0:fb7af294d5d9 101 * Restore peer certificate (without rest of the original chain)
Simon Cooksey 0:fb7af294d5d9 102 */
Simon Cooksey 0:fb7af294d5d9 103 if( entry->peer_cert.p != NULL )
Simon Cooksey 0:fb7af294d5d9 104 {
Simon Cooksey 0:fb7af294d5d9 105 if( ( session->peer_cert = mbedtls_calloc( 1,
Simon Cooksey 0:fb7af294d5d9 106 sizeof(mbedtls_x509_crt) ) ) == NULL )
Simon Cooksey 0:fb7af294d5d9 107 {
Simon Cooksey 0:fb7af294d5d9 108 ret = 1;
Simon Cooksey 0:fb7af294d5d9 109 goto exit;
Simon Cooksey 0:fb7af294d5d9 110 }
Simon Cooksey 0:fb7af294d5d9 111
Simon Cooksey 0:fb7af294d5d9 112 mbedtls_x509_crt_init( session->peer_cert );
Simon Cooksey 0:fb7af294d5d9 113 if( mbedtls_x509_crt_parse( session->peer_cert, entry->peer_cert.p,
Simon Cooksey 0:fb7af294d5d9 114 entry->peer_cert.len ) != 0 )
Simon Cooksey 0:fb7af294d5d9 115 {
Simon Cooksey 0:fb7af294d5d9 116 mbedtls_free( session->peer_cert );
Simon Cooksey 0:fb7af294d5d9 117 session->peer_cert = NULL;
Simon Cooksey 0:fb7af294d5d9 118 ret = 1;
Simon Cooksey 0:fb7af294d5d9 119 goto exit;
Simon Cooksey 0:fb7af294d5d9 120 }
Simon Cooksey 0:fb7af294d5d9 121 }
Simon Cooksey 0:fb7af294d5d9 122 #endif /* MBEDTLS_X509_CRT_PARSE_C */
Simon Cooksey 0:fb7af294d5d9 123
Simon Cooksey 0:fb7af294d5d9 124 ret = 0;
Simon Cooksey 0:fb7af294d5d9 125 goto exit;
Simon Cooksey 0:fb7af294d5d9 126 }
Simon Cooksey 0:fb7af294d5d9 127
Simon Cooksey 0:fb7af294d5d9 128 exit:
Simon Cooksey 0:fb7af294d5d9 129 #if defined(MBEDTLS_THREADING_C)
Simon Cooksey 0:fb7af294d5d9 130 if( mbedtls_mutex_unlock( &cache->mutex ) != 0 )
Simon Cooksey 0:fb7af294d5d9 131 ret = 1;
Simon Cooksey 0:fb7af294d5d9 132 #endif
Simon Cooksey 0:fb7af294d5d9 133
Simon Cooksey 0:fb7af294d5d9 134 return( ret );
Simon Cooksey 0:fb7af294d5d9 135 }
Simon Cooksey 0:fb7af294d5d9 136
Simon Cooksey 0:fb7af294d5d9 137 int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session )
Simon Cooksey 0:fb7af294d5d9 138 {
Simon Cooksey 0:fb7af294d5d9 139 int ret = 1;
Simon Cooksey 0:fb7af294d5d9 140 #if defined(MBEDTLS_HAVE_TIME)
Simon Cooksey 0:fb7af294d5d9 141 mbedtls_time_t t = time( NULL ), oldest = 0;
Simon Cooksey 0:fb7af294d5d9 142 mbedtls_ssl_cache_entry *old = NULL;
Simon Cooksey 0:fb7af294d5d9 143 #endif
Simon Cooksey 0:fb7af294d5d9 144 mbedtls_ssl_cache_context *cache = (mbedtls_ssl_cache_context *) data;
Simon Cooksey 0:fb7af294d5d9 145 mbedtls_ssl_cache_entry *cur, *prv;
Simon Cooksey 0:fb7af294d5d9 146 int count = 0;
Simon Cooksey 0:fb7af294d5d9 147
Simon Cooksey 0:fb7af294d5d9 148 #if defined(MBEDTLS_THREADING_C)
Simon Cooksey 0:fb7af294d5d9 149 if( ( ret = mbedtls_mutex_lock( &cache->mutex ) ) != 0 )
Simon Cooksey 0:fb7af294d5d9 150 return( ret );
Simon Cooksey 0:fb7af294d5d9 151 #endif
Simon Cooksey 0:fb7af294d5d9 152
Simon Cooksey 0:fb7af294d5d9 153 cur = cache->chain;
Simon Cooksey 0:fb7af294d5d9 154 prv = NULL;
Simon Cooksey 0:fb7af294d5d9 155
Simon Cooksey 0:fb7af294d5d9 156 while( cur != NULL )
Simon Cooksey 0:fb7af294d5d9 157 {
Simon Cooksey 0:fb7af294d5d9 158 count++;
Simon Cooksey 0:fb7af294d5d9 159
Simon Cooksey 0:fb7af294d5d9 160 #if defined(MBEDTLS_HAVE_TIME)
Simon Cooksey 0:fb7af294d5d9 161 if( cache->timeout != 0 &&
Simon Cooksey 0:fb7af294d5d9 162 (int) ( t - cur->timestamp ) > cache->timeout )
Simon Cooksey 0:fb7af294d5d9 163 {
Simon Cooksey 0:fb7af294d5d9 164 cur->timestamp = t;
Simon Cooksey 0:fb7af294d5d9 165 break; /* expired, reuse this slot, update timestamp */
Simon Cooksey 0:fb7af294d5d9 166 }
Simon Cooksey 0:fb7af294d5d9 167 #endif
Simon Cooksey 0:fb7af294d5d9 168
Simon Cooksey 0:fb7af294d5d9 169 if( memcmp( session->id, cur->session.id, cur->session.id_len ) == 0 )
Simon Cooksey 0:fb7af294d5d9 170 break; /* client reconnected, keep timestamp for session id */
Simon Cooksey 0:fb7af294d5d9 171
Simon Cooksey 0:fb7af294d5d9 172 #if defined(MBEDTLS_HAVE_TIME)
Simon Cooksey 0:fb7af294d5d9 173 if( oldest == 0 || cur->timestamp < oldest )
Simon Cooksey 0:fb7af294d5d9 174 {
Simon Cooksey 0:fb7af294d5d9 175 oldest = cur->timestamp;
Simon Cooksey 0:fb7af294d5d9 176 old = cur;
Simon Cooksey 0:fb7af294d5d9 177 }
Simon Cooksey 0:fb7af294d5d9 178 #endif
Simon Cooksey 0:fb7af294d5d9 179
Simon Cooksey 0:fb7af294d5d9 180 prv = cur;
Simon Cooksey 0:fb7af294d5d9 181 cur = cur->next;
Simon Cooksey 0:fb7af294d5d9 182 }
Simon Cooksey 0:fb7af294d5d9 183
Simon Cooksey 0:fb7af294d5d9 184 if( cur == NULL )
Simon Cooksey 0:fb7af294d5d9 185 {
Simon Cooksey 0:fb7af294d5d9 186 #if defined(MBEDTLS_HAVE_TIME)
Simon Cooksey 0:fb7af294d5d9 187 /*
Simon Cooksey 0:fb7af294d5d9 188 * Reuse oldest entry if max_entries reached
Simon Cooksey 0:fb7af294d5d9 189 */
Simon Cooksey 0:fb7af294d5d9 190 if( count >= cache->max_entries )
Simon Cooksey 0:fb7af294d5d9 191 {
Simon Cooksey 0:fb7af294d5d9 192 if( old == NULL )
Simon Cooksey 0:fb7af294d5d9 193 {
Simon Cooksey 0:fb7af294d5d9 194 ret = 1;
Simon Cooksey 0:fb7af294d5d9 195 goto exit;
Simon Cooksey 0:fb7af294d5d9 196 }
Simon Cooksey 0:fb7af294d5d9 197
Simon Cooksey 0:fb7af294d5d9 198 cur = old;
Simon Cooksey 0:fb7af294d5d9 199 }
Simon Cooksey 0:fb7af294d5d9 200 #else /* MBEDTLS_HAVE_TIME */
Simon Cooksey 0:fb7af294d5d9 201 /*
Simon Cooksey 0:fb7af294d5d9 202 * Reuse first entry in chain if max_entries reached,
Simon Cooksey 0:fb7af294d5d9 203 * but move to last place
Simon Cooksey 0:fb7af294d5d9 204 */
Simon Cooksey 0:fb7af294d5d9 205 if( count >= cache->max_entries )
Simon Cooksey 0:fb7af294d5d9 206 {
Simon Cooksey 0:fb7af294d5d9 207 if( cache->chain == NULL )
Simon Cooksey 0:fb7af294d5d9 208 {
Simon Cooksey 0:fb7af294d5d9 209 ret = 1;
Simon Cooksey 0:fb7af294d5d9 210 goto exit;
Simon Cooksey 0:fb7af294d5d9 211 }
Simon Cooksey 0:fb7af294d5d9 212
Simon Cooksey 0:fb7af294d5d9 213 cur = cache->chain;
Simon Cooksey 0:fb7af294d5d9 214 cache->chain = cur->next;
Simon Cooksey 0:fb7af294d5d9 215 cur->next = NULL;
Simon Cooksey 0:fb7af294d5d9 216 prv->next = cur;
Simon Cooksey 0:fb7af294d5d9 217 }
Simon Cooksey 0:fb7af294d5d9 218 #endif /* MBEDTLS_HAVE_TIME */
Simon Cooksey 0:fb7af294d5d9 219 else
Simon Cooksey 0:fb7af294d5d9 220 {
Simon Cooksey 0:fb7af294d5d9 221 /*
Simon Cooksey 0:fb7af294d5d9 222 * max_entries not reached, create new entry
Simon Cooksey 0:fb7af294d5d9 223 */
Simon Cooksey 0:fb7af294d5d9 224 cur = mbedtls_calloc( 1, sizeof(mbedtls_ssl_cache_entry) );
Simon Cooksey 0:fb7af294d5d9 225 if( cur == NULL )
Simon Cooksey 0:fb7af294d5d9 226 {
Simon Cooksey 0:fb7af294d5d9 227 ret = 1;
Simon Cooksey 0:fb7af294d5d9 228 goto exit;
Simon Cooksey 0:fb7af294d5d9 229 }
Simon Cooksey 0:fb7af294d5d9 230
Simon Cooksey 0:fb7af294d5d9 231 if( prv == NULL )
Simon Cooksey 0:fb7af294d5d9 232 cache->chain = cur;
Simon Cooksey 0:fb7af294d5d9 233 else
Simon Cooksey 0:fb7af294d5d9 234 prv->next = cur;
Simon Cooksey 0:fb7af294d5d9 235 }
Simon Cooksey 0:fb7af294d5d9 236
Simon Cooksey 0:fb7af294d5d9 237 #if defined(MBEDTLS_HAVE_TIME)
Simon Cooksey 0:fb7af294d5d9 238 cur->timestamp = t;
Simon Cooksey 0:fb7af294d5d9 239 #endif
Simon Cooksey 0:fb7af294d5d9 240 }
Simon Cooksey 0:fb7af294d5d9 241
Simon Cooksey 0:fb7af294d5d9 242 memcpy( &cur->session, session, sizeof( mbedtls_ssl_session ) );
Simon Cooksey 0:fb7af294d5d9 243
Simon Cooksey 0:fb7af294d5d9 244 #if defined(MBEDTLS_X509_CRT_PARSE_C)
Simon Cooksey 0:fb7af294d5d9 245 /*
Simon Cooksey 0:fb7af294d5d9 246 * If we're reusing an entry, free its certificate first
Simon Cooksey 0:fb7af294d5d9 247 */
Simon Cooksey 0:fb7af294d5d9 248 if( cur->peer_cert.p != NULL )
Simon Cooksey 0:fb7af294d5d9 249 {
Simon Cooksey 0:fb7af294d5d9 250 mbedtls_free( cur->peer_cert.p );
Simon Cooksey 0:fb7af294d5d9 251 memset( &cur->peer_cert, 0, sizeof(mbedtls_x509_buf) );
Simon Cooksey 0:fb7af294d5d9 252 }
Simon Cooksey 0:fb7af294d5d9 253
Simon Cooksey 0:fb7af294d5d9 254 /*
Simon Cooksey 0:fb7af294d5d9 255 * Store peer certificate
Simon Cooksey 0:fb7af294d5d9 256 */
Simon Cooksey 0:fb7af294d5d9 257 if( session->peer_cert != NULL )
Simon Cooksey 0:fb7af294d5d9 258 {
Simon Cooksey 0:fb7af294d5d9 259 cur->peer_cert.p = mbedtls_calloc( 1, session->peer_cert->raw.len );
Simon Cooksey 0:fb7af294d5d9 260 if( cur->peer_cert.p == NULL )
Simon Cooksey 0:fb7af294d5d9 261 {
Simon Cooksey 0:fb7af294d5d9 262 ret = 1;
Simon Cooksey 0:fb7af294d5d9 263 goto exit;
Simon Cooksey 0:fb7af294d5d9 264 }
Simon Cooksey 0:fb7af294d5d9 265
Simon Cooksey 0:fb7af294d5d9 266 memcpy( cur->peer_cert.p, session->peer_cert->raw.p,
Simon Cooksey 0:fb7af294d5d9 267 session->peer_cert->raw.len );
Simon Cooksey 0:fb7af294d5d9 268 cur->peer_cert.len = session->peer_cert->raw.len;
Simon Cooksey 0:fb7af294d5d9 269
Simon Cooksey 0:fb7af294d5d9 270 cur->session.peer_cert = NULL;
Simon Cooksey 0:fb7af294d5d9 271 }
Simon Cooksey 0:fb7af294d5d9 272 #endif /* MBEDTLS_X509_CRT_PARSE_C */
Simon Cooksey 0:fb7af294d5d9 273
Simon Cooksey 0:fb7af294d5d9 274 ret = 0;
Simon Cooksey 0:fb7af294d5d9 275
Simon Cooksey 0:fb7af294d5d9 276 exit:
Simon Cooksey 0:fb7af294d5d9 277 #if defined(MBEDTLS_THREADING_C)
Simon Cooksey 0:fb7af294d5d9 278 if( mbedtls_mutex_unlock( &cache->mutex ) != 0 )
Simon Cooksey 0:fb7af294d5d9 279 ret = 1;
Simon Cooksey 0:fb7af294d5d9 280 #endif
Simon Cooksey 0:fb7af294d5d9 281
Simon Cooksey 0:fb7af294d5d9 282 return( ret );
Simon Cooksey 0:fb7af294d5d9 283 }
Simon Cooksey 0:fb7af294d5d9 284
Simon Cooksey 0:fb7af294d5d9 285 #if defined(MBEDTLS_HAVE_TIME)
Simon Cooksey 0:fb7af294d5d9 286 void mbedtls_ssl_cache_set_timeout( mbedtls_ssl_cache_context *cache, int timeout )
Simon Cooksey 0:fb7af294d5d9 287 {
Simon Cooksey 0:fb7af294d5d9 288 if( timeout < 0 ) timeout = 0;
Simon Cooksey 0:fb7af294d5d9 289
Simon Cooksey 0:fb7af294d5d9 290 cache->timeout = timeout;
Simon Cooksey 0:fb7af294d5d9 291 }
Simon Cooksey 0:fb7af294d5d9 292 #endif /* MBEDTLS_HAVE_TIME */
Simon Cooksey 0:fb7af294d5d9 293
Simon Cooksey 0:fb7af294d5d9 294 void mbedtls_ssl_cache_set_max_entries( mbedtls_ssl_cache_context *cache, int max )
Simon Cooksey 0:fb7af294d5d9 295 {
Simon Cooksey 0:fb7af294d5d9 296 if( max < 0 ) max = 0;
Simon Cooksey 0:fb7af294d5d9 297
Simon Cooksey 0:fb7af294d5d9 298 cache->max_entries = max;
Simon Cooksey 0:fb7af294d5d9 299 }
Simon Cooksey 0:fb7af294d5d9 300
Simon Cooksey 0:fb7af294d5d9 301 void mbedtls_ssl_cache_free( mbedtls_ssl_cache_context *cache )
Simon Cooksey 0:fb7af294d5d9 302 {
Simon Cooksey 0:fb7af294d5d9 303 mbedtls_ssl_cache_entry *cur, *prv;
Simon Cooksey 0:fb7af294d5d9 304
Simon Cooksey 0:fb7af294d5d9 305 cur = cache->chain;
Simon Cooksey 0:fb7af294d5d9 306
Simon Cooksey 0:fb7af294d5d9 307 while( cur != NULL )
Simon Cooksey 0:fb7af294d5d9 308 {
Simon Cooksey 0:fb7af294d5d9 309 prv = cur;
Simon Cooksey 0:fb7af294d5d9 310 cur = cur->next;
Simon Cooksey 0:fb7af294d5d9 311
Simon Cooksey 0:fb7af294d5d9 312 mbedtls_ssl_session_free( &prv->session );
Simon Cooksey 0:fb7af294d5d9 313
Simon Cooksey 0:fb7af294d5d9 314 #if defined(MBEDTLS_X509_CRT_PARSE_C)
Simon Cooksey 0:fb7af294d5d9 315 mbedtls_free( prv->peer_cert.p );
Simon Cooksey 0:fb7af294d5d9 316 #endif /* MBEDTLS_X509_CRT_PARSE_C */
Simon Cooksey 0:fb7af294d5d9 317
Simon Cooksey 0:fb7af294d5d9 318 mbedtls_free( prv );
Simon Cooksey 0:fb7af294d5d9 319 }
Simon Cooksey 0:fb7af294d5d9 320
Simon Cooksey 0:fb7af294d5d9 321 #if defined(MBEDTLS_THREADING_C)
Simon Cooksey 0:fb7af294d5d9 322 mbedtls_mutex_free( &cache->mutex );
Simon Cooksey 0:fb7af294d5d9 323 #endif
Simon Cooksey 0:fb7af294d5d9 324 }
Simon Cooksey 0:fb7af294d5d9 325
Simon Cooksey 0:fb7af294d5d9 326 #endif /* MBEDTLS_SSL_CACHE_C */