This is a fork due to permission issues

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of 6_songs-from-the-cloud by MakingMusicWorkshop

Committer:
timbeight
Date:
Thu May 19 16:02:10 2016 +0000
Revision:
1:0ddbe2d3319c
Parent:
0:f7c60d3e7b8a
This is my first commit while in the class.

Who changed what in which revision?

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