blob: a4d8cd30c0f1589e76343a50e379f4e2dd5a3f45 [file] [log] [blame]
Paul Bakker0a597072012-09-25 21:55:46 +00001/*
2 * SSL session cache implementation
3 *
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02004 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02005 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
Paul Bakker0a597072012-09-25 21:55:46 +000018 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000019 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker0a597072012-09-25 21:55:46 +000020 */
21/*
22 * These session callbacks use a simple chained list
23 * to store and retrieve the session information.
24 */
25
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000027#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020028#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020029#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#endif
Paul Bakker0a597072012-09-25 21:55:46 +000031
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020032#if defined(MBEDTLS_SSL_CACHE_C)
Paul Bakker0a597072012-09-25 21:55:46 +000033
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020034#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000035#include "mbedtls/platform.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020036#else
Rich Evans00ab4702015-02-06 13:43:58 +000037#include <stdlib.h>
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +020038#define mbedtls_calloc calloc
SimonBd5800b72016-04-26 07:43:27 +010039#define mbedtls_free free
Paul Bakker6e339b52013-07-03 13:37:05 +020040#endif
41
SimonBd5800b72016-04-26 07:43:27 +010042#include "mbedtls/ssl_cache.h"
Hanno Beckera177b382019-02-06 14:53:19 +000043#include "mbedtls/ssl_internal.h"
SimonBd5800b72016-04-26 07:43:27 +010044
45#include <string.h>
Manuel Pégourié-Gonnard52207812019-10-02 15:55:23 +020046#include "mbedtls/platform_util.h"
SimonBd5800b72016-04-26 07:43:27 +010047
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020048void mbedtls_ssl_cache_init( mbedtls_ssl_cache_context *cache )
Paul Bakker0a597072012-09-25 21:55:46 +000049{
Manuel Pégourié-Gonnard7a346b82019-10-02 14:47:01 +020050 mbedtls_platform_memset( cache, 0, sizeof( mbedtls_ssl_cache_context ) );
Paul Bakker0a597072012-09-25 21:55:46 +000051
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052 cache->timeout = MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT;
53 cache->max_entries = MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES;
Paul Bakkerc5598842013-09-28 15:01:27 +020054
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055#if defined(MBEDTLS_THREADING_C)
56 mbedtls_mutex_init( &cache->mutex );
Paul Bakkerc5598842013-09-28 15:01:27 +020057#endif
Paul Bakker0a597072012-09-25 21:55:46 +000058}
59
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060int mbedtls_ssl_cache_get( void *data, mbedtls_ssl_session *session )
Paul Bakker0a597072012-09-25 21:55:46 +000061{
Paul Bakkerc5598842013-09-28 15:01:27 +020062 int ret = 1;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063#if defined(MBEDTLS_HAVE_TIME)
SimonBd5800b72016-04-26 07:43:27 +010064 mbedtls_time_t t = mbedtls_time( NULL );
Paul Bakkerfa9b1002013-07-03 15:31:03 +020065#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020066 mbedtls_ssl_cache_context *cache = (mbedtls_ssl_cache_context *) data;
67 mbedtls_ssl_cache_entry *cur, *entry;
Paul Bakker0a597072012-09-25 21:55:46 +000068
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020069#if defined(MBEDTLS_THREADING_C)
70 if( mbedtls_mutex_lock( &cache->mutex ) != 0 )
Paul Bakkerc5598842013-09-28 15:01:27 +020071 return( 1 );
72#endif
73
Paul Bakker0a597072012-09-25 21:55:46 +000074 cur = cache->chain;
75 entry = NULL;
76
77 while( cur != NULL )
78 {
79 entry = cur;
80 cur = cur->next;
81
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020082#if defined(MBEDTLS_HAVE_TIME)
Paul Bakker0a597072012-09-25 21:55:46 +000083 if( cache->timeout != 0 &&
84 (int) ( t - entry->timestamp ) > cache->timeout )
85 continue;
Paul Bakkerfa9b1002013-07-03 15:31:03 +020086#endif
Paul Bakker0a597072012-09-25 21:55:46 +000087
Hanno Beckere02758c2019-06-26 15:31:31 +010088 if( mbedtls_ssl_session_get_ciphersuite( session ) !=
89 mbedtls_ssl_session_get_ciphersuite( &entry->session ) ||
Hanno Becker88440552019-07-03 14:16:13 +010090 mbedtls_ssl_session_get_compression( session ) !=
91 mbedtls_ssl_session_get_compression( &entry->session ) ||
Manuel Pégourié-Gonnard12ad7982015-06-18 15:50:37 +020092 session->id_len != entry->session.id_len )
Hanno Beckere02758c2019-06-26 15:31:31 +010093 {
Paul Bakker0a597072012-09-25 21:55:46 +000094 continue;
Hanno Beckere02758c2019-06-26 15:31:31 +010095 }
Paul Bakker0a597072012-09-25 21:55:46 +000096
Teppo Järvelin61f412e2019-10-03 12:25:22 +030097 if( mbedtls_platform_memcmp( session->id, entry->session.id,
Manuel Pégourié-Gonnard12ad7982015-06-18 15:50:37 +020098 entry->session.id_len ) != 0 )
Paul Bakker0a597072012-09-25 21:55:46 +000099 continue;
100
Hanno Beckera177b382019-02-06 14:53:19 +0000101 ret = mbedtls_ssl_session_copy( session, &entry->session );
102 if( ret != 0 )
103 {
104 ret = 1;
105 goto exit;
106 }
Manuel Pégourié-Gonnard38d1eba2013-08-23 10:44:29 +0200107
Hanno Becker2e6d3472019-02-06 15:40:27 +0000108#if defined(MBEDTLS_X509_CRT_PARSE_C) && \
109 defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
Paul Bakkere81beda2013-03-06 17:40:46 +0100110 /*
111 * Restore peer certificate (without rest of the original chain)
112 */
113 if( entry->peer_cert.p != NULL )
114 {
Hanno Beckera177b382019-02-06 14:53:19 +0000115 /* `session->peer_cert` is NULL after the call to
116 * mbedtls_ssl_session_copy(), because cache entries
117 * have the `peer_cert` field set to NULL. */
118
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200119 if( ( session->peer_cert = mbedtls_calloc( 1,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200120 sizeof(mbedtls_x509_crt) ) ) == NULL )
Paul Bakkerc5598842013-09-28 15:01:27 +0200121 {
122 ret = 1;
123 goto exit;
124 }
Paul Bakkere81beda2013-03-06 17:40:46 +0100125
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200126 mbedtls_x509_crt_init( session->peer_cert );
127 if( mbedtls_x509_crt_parse( session->peer_cert, entry->peer_cert.p,
Paul Bakkerddf26b42013-09-18 13:46:23 +0200128 entry->peer_cert.len ) != 0 )
Paul Bakkere81beda2013-03-06 17:40:46 +0100129 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200130 mbedtls_free( session->peer_cert );
Paul Bakkere81beda2013-03-06 17:40:46 +0100131 session->peer_cert = NULL;
Paul Bakkerc5598842013-09-28 15:01:27 +0200132 ret = 1;
133 goto exit;
Paul Bakkere81beda2013-03-06 17:40:46 +0100134 }
135 }
Hanno Becker2e6d3472019-02-06 15:40:27 +0000136#endif /* MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
Paul Bakkere81beda2013-03-06 17:40:46 +0100137
Paul Bakkerc5598842013-09-28 15:01:27 +0200138 ret = 0;
139 goto exit;
Paul Bakker0a597072012-09-25 21:55:46 +0000140 }
141
Paul Bakkerc5598842013-09-28 15:01:27 +0200142exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200143#if defined(MBEDTLS_THREADING_C)
144 if( mbedtls_mutex_unlock( &cache->mutex ) != 0 )
Paul Bakkerc5598842013-09-28 15:01:27 +0200145 ret = 1;
146#endif
147
148 return( ret );
Paul Bakker0a597072012-09-25 21:55:46 +0000149}
150
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200151int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session )
Paul Bakker0a597072012-09-25 21:55:46 +0000152{
Paul Bakkerc5598842013-09-28 15:01:27 +0200153 int ret = 1;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200154#if defined(MBEDTLS_HAVE_TIME)
Simon Butchera55e0842017-07-28 23:46:43 +0100155 mbedtls_time_t t = mbedtls_time( NULL ), oldest = 0;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200156 mbedtls_ssl_cache_entry *old = NULL;
Paul Bakkerfa9b1002013-07-03 15:31:03 +0200157#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200158 mbedtls_ssl_cache_context *cache = (mbedtls_ssl_cache_context *) data;
159 mbedtls_ssl_cache_entry *cur, *prv;
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000160 int count = 0;
Paul Bakker0a597072012-09-25 21:55:46 +0000161
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200162#if defined(MBEDTLS_THREADING_C)
163 if( ( ret = mbedtls_mutex_lock( &cache->mutex ) ) != 0 )
Paul Bakkerc5598842013-09-28 15:01:27 +0200164 return( ret );
165#endif
166
Paul Bakker0a597072012-09-25 21:55:46 +0000167 cur = cache->chain;
168 prv = NULL;
169
170 while( cur != NULL )
171 {
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000172 count++;
173
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200174#if defined(MBEDTLS_HAVE_TIME)
Paul Bakker0a597072012-09-25 21:55:46 +0000175 if( cache->timeout != 0 &&
176 (int) ( t - cur->timestamp ) > cache->timeout )
177 {
178 cur->timestamp = t;
179 break; /* expired, reuse this slot, update timestamp */
180 }
Paul Bakkerfa9b1002013-07-03 15:31:03 +0200181#endif
Paul Bakker0a597072012-09-25 21:55:46 +0000182
Teppo Järvelin61f412e2019-10-03 12:25:22 +0300183 if( mbedtls_platform_memcmp( session->id, cur->session.id, cur->session.id_len ) == 0 )
Paul Bakker0a597072012-09-25 21:55:46 +0000184 break; /* client reconnected, keep timestamp for session id */
185
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200186#if defined(MBEDTLS_HAVE_TIME)
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000187 if( oldest == 0 || cur->timestamp < oldest )
188 {
189 oldest = cur->timestamp;
190 old = cur;
191 }
Paul Bakkerfa9b1002013-07-03 15:31:03 +0200192#endif
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000193
Paul Bakker0a597072012-09-25 21:55:46 +0000194 prv = cur;
195 cur = cur->next;
196 }
197
198 if( cur == NULL )
199 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200200#if defined(MBEDTLS_HAVE_TIME)
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000201 /*
202 * Reuse oldest entry if max_entries reached
203 */
Manuel Pégourié-Gonnard274a12e2014-02-20 21:32:08 +0100204 if( count >= cache->max_entries )
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000205 {
Manuel Pégourié-Gonnard274a12e2014-02-20 21:32:08 +0100206 if( old == NULL )
207 {
208 ret = 1;
209 goto exit;
210 }
211
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000212 cur = old;
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000213 }
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200214#else /* MBEDTLS_HAVE_TIME */
Paul Bakkerfa9b1002013-07-03 15:31:03 +0200215 /*
216 * Reuse first entry in chain if max_entries reached,
217 * but move to last place
218 */
219 if( count >= cache->max_entries )
220 {
221 if( cache->chain == NULL )
Paul Bakkerc5598842013-09-28 15:01:27 +0200222 {
223 ret = 1;
224 goto exit;
225 }
Paul Bakkerfa9b1002013-07-03 15:31:03 +0200226
227 cur = cache->chain;
228 cache->chain = cur->next;
Manuel Pégourié-Gonnard84c30c72014-02-26 17:38:55 +0100229 cur->next = NULL;
Paul Bakkerfa9b1002013-07-03 15:31:03 +0200230 prv->next = cur;
231 }
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200232#endif /* MBEDTLS_HAVE_TIME */
Paul Bakker0a597072012-09-25 21:55:46 +0000233 else
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000234 {
Manuel Pégourié-Gonnard274a12e2014-02-20 21:32:08 +0100235 /*
236 * max_entries not reached, create new entry
237 */
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200238 cur = mbedtls_calloc( 1, sizeof(mbedtls_ssl_cache_entry) );
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000239 if( cur == NULL )
Paul Bakkerc5598842013-09-28 15:01:27 +0200240 {
241 ret = 1;
242 goto exit;
243 }
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000244
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000245 if( prv == NULL )
246 cache->chain = cur;
247 else
248 prv->next = cur;
249 }
Paul Bakker0a597072012-09-25 21:55:46 +0000250
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200251#if defined(MBEDTLS_HAVE_TIME)
Paul Bakker0a597072012-09-25 21:55:46 +0000252 cur->timestamp = t;
Paul Bakkerfa9b1002013-07-03 15:31:03 +0200253#endif
Paul Bakker0a597072012-09-25 21:55:46 +0000254 }
255
Hanno Becker2e6d3472019-02-06 15:40:27 +0000256#if defined(MBEDTLS_X509_CRT_PARSE_C) && \
257 defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
Paul Bakkere81beda2013-03-06 17:40:46 +0100258 /*
Manuel Pégourié-Gonnard84c30c72014-02-26 17:38:55 +0100259 * If we're reusing an entry, free its certificate first
260 */
261 if( cur->peer_cert.p != NULL )
262 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200263 mbedtls_free( cur->peer_cert.p );
Manuel Pégourié-Gonnard7a346b82019-10-02 14:47:01 +0200264 mbedtls_platform_memset( &cur->peer_cert, 0, sizeof(mbedtls_x509_buf) );
Manuel Pégourié-Gonnard84c30c72014-02-26 17:38:55 +0100265 }
Hanno Becker2e6d3472019-02-06 15:40:27 +0000266#endif /* MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
Manuel Pégourié-Gonnard84c30c72014-02-26 17:38:55 +0100267
Hanno Beckera177b382019-02-06 14:53:19 +0000268 /* Copy the entire session; this temporarily makes a copy of the
269 * X.509 CRT structure even though we only want to store the raw CRT.
270 * This inefficiency will go away as soon as we implement on-demand
271 * parsing of CRTs, in which case there's no need for the `peer_cert`
272 * field anymore in the first place, and we're done after this call. */
273 ret = mbedtls_ssl_session_copy( &cur->session, session );
274 if( ret != 0 )
Paul Bakkere81beda2013-03-06 17:40:46 +0100275 {
Hanno Beckera177b382019-02-06 14:53:19 +0000276 ret = 1;
277 goto exit;
278 }
279
Hanno Becker2e6d3472019-02-06 15:40:27 +0000280#if defined(MBEDTLS_X509_CRT_PARSE_C) && \
281 defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
Hanno Beckera177b382019-02-06 14:53:19 +0000282 /* If present, free the X.509 structure and only store the raw CRT data. */
283 if( cur->session.peer_cert != NULL )
284 {
285 cur->peer_cert.p =
286 mbedtls_calloc( 1, cur->session.peer_cert->raw.len );
Paul Bakkere81beda2013-03-06 17:40:46 +0100287 if( cur->peer_cert.p == NULL )
Paul Bakkerc5598842013-09-28 15:01:27 +0200288 {
289 ret = 1;
290 goto exit;
291 }
Paul Bakkere81beda2013-03-06 17:40:46 +0100292
Teppo Järvelin91d79382019-10-02 09:09:31 +0300293 mbedtls_platform_memcpy( cur->peer_cert.p,
Hanno Beckera177b382019-02-06 14:53:19 +0000294 cur->session.peer_cert->raw.p,
295 cur->session.peer_cert->raw.len );
Paul Bakkere81beda2013-03-06 17:40:46 +0100296 cur->peer_cert.len = session->peer_cert->raw.len;
297
Hanno Beckera177b382019-02-06 14:53:19 +0000298 mbedtls_x509_crt_free( cur->session.peer_cert );
299 mbedtls_free( cur->session.peer_cert );
Paul Bakkere81beda2013-03-06 17:40:46 +0100300 cur->session.peer_cert = NULL;
301 }
Hanno Becker2e6d3472019-02-06 15:40:27 +0000302#endif /* MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
Paul Bakker0a597072012-09-25 21:55:46 +0000303
Paul Bakkerc5598842013-09-28 15:01:27 +0200304 ret = 0;
305
306exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200307#if defined(MBEDTLS_THREADING_C)
308 if( mbedtls_mutex_unlock( &cache->mutex ) != 0 )
Paul Bakkerc5598842013-09-28 15:01:27 +0200309 ret = 1;
310#endif
311
312 return( ret );
Paul Bakker0a597072012-09-25 21:55:46 +0000313}
314
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200315#if defined(MBEDTLS_HAVE_TIME)
316void mbedtls_ssl_cache_set_timeout( mbedtls_ssl_cache_context *cache, int timeout )
Paul Bakker0a597072012-09-25 21:55:46 +0000317{
318 if( timeout < 0 ) timeout = 0;
319
320 cache->timeout = timeout;
321}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200322#endif /* MBEDTLS_HAVE_TIME */
Paul Bakker0a597072012-09-25 21:55:46 +0000323
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200324void mbedtls_ssl_cache_set_max_entries( mbedtls_ssl_cache_context *cache, int max )
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000325{
326 if( max < 0 ) max = 0;
327
328 cache->max_entries = max;
329}
330
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200331void mbedtls_ssl_cache_free( mbedtls_ssl_cache_context *cache )
Paul Bakker0a597072012-09-25 21:55:46 +0000332{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200333 mbedtls_ssl_cache_entry *cur, *prv;
Paul Bakker0a597072012-09-25 21:55:46 +0000334
335 cur = cache->chain;
336
337 while( cur != NULL )
338 {
339 prv = cur;
340 cur = cur->next;
341
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200342 mbedtls_ssl_session_free( &prv->session );
Paul Bakkere81beda2013-03-06 17:40:46 +0100343
Hanno Becker2e6d3472019-02-06 15:40:27 +0000344#if defined(MBEDTLS_X509_CRT_PARSE_C) && \
345 defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200346 mbedtls_free( prv->peer_cert.p );
Hanno Becker2e6d3472019-02-06 15:40:27 +0000347#endif /* MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
Paul Bakkere81beda2013-03-06 17:40:46 +0100348
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200349 mbedtls_free( prv );
Paul Bakker0a597072012-09-25 21:55:46 +0000350 }
Paul Bakkerc5598842013-09-28 15:01:27 +0200351
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200352#if defined(MBEDTLS_THREADING_C)
353 mbedtls_mutex_free( &cache->mutex );
Paul Bakkerc5598842013-09-28 15:01:27 +0200354#endif
Ron Eldor22360822017-10-29 17:53:52 +0200355 cache->chain = NULL;
Paul Bakker0a597072012-09-25 21:55:46 +0000356}
357
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200358#endif /* MBEDTLS_SSL_CACHE_C */