blob: 21e38cd86a3a29c7aecc60f3a95a756a955f84c0 [file] [log] [blame]
Paul Bakker0a597072012-09-25 21:55:46 +00001/*
2 * SSL session cache implementation
3 *
Bence Szépkúti1e148272020-08-07 13:07:28 +02004 * Copyright The Mbed TLS Contributors
Dave Rodgman7ff79652023-11-03 12:04:52 +00005 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Paul Bakker0a597072012-09-25 21:55:46 +00006 */
7/*
8 * These session callbacks use a simple chained list
9 * to store and retrieve the session information.
10 */
11
Gilles Peskinedb09ef62020-06-03 01:43:33 +020012#include "common.h"
Paul Bakker0a597072012-09-25 21:55:46 +000013
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020014#if defined(MBEDTLS_SSL_CACHE_C)
Paul Bakker0a597072012-09-25 21:55:46 +000015
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000016#include "mbedtls/platform.h"
Gilles Peskinefe4d93a2023-09-29 13:40:33 +020017#include "mbedtls/error.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020018
SimonBd5800b72016-04-26 07:43:27 +010019#include "mbedtls/ssl_cache.h"
Hanno Beckeraee87172019-02-06 14:53:19 +000020#include "mbedtls/ssl_internal.h"
SimonBd5800b72016-04-26 07:43:27 +010021
22#include <string.h>
23
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010024void mbedtls_ssl_cache_init(mbedtls_ssl_cache_context *cache)
Paul Bakker0a597072012-09-25 21:55:46 +000025{
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010026 memset(cache, 0, sizeof(mbedtls_ssl_cache_context));
Paul Bakker0a597072012-09-25 21:55:46 +000027
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028 cache->timeout = MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT;
29 cache->max_entries = MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES;
Paul Bakkerc5598842013-09-28 15:01:27 +020030
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020031#if defined(MBEDTLS_THREADING_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010032 mbedtls_mutex_init(&cache->mutex);
Paul Bakkerc5598842013-09-28 15:01:27 +020033#endif
Paul Bakker0a597072012-09-25 21:55:46 +000034}
35
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010036int mbedtls_ssl_cache_get(void *data, mbedtls_ssl_session *session)
Paul Bakker0a597072012-09-25 21:55:46 +000037{
Gilles Peskinefe4d93a2023-09-29 13:40:33 +020038 int ret = MBEDTLS_ERR_SSL_CACHE_ENTRY_NOT_FOUND;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020039#if defined(MBEDTLS_HAVE_TIME)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010040 mbedtls_time_t t = mbedtls_time(NULL);
Paul Bakkerfa9b1002013-07-03 15:31:03 +020041#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020042 mbedtls_ssl_cache_context *cache = (mbedtls_ssl_cache_context *) data;
43 mbedtls_ssl_cache_entry *cur, *entry;
Paul Bakker0a597072012-09-25 21:55:46 +000044
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020045#if defined(MBEDTLS_THREADING_C)
Gilles Peskinefe4d93a2023-09-29 13:40:33 +020046 if ((ret = mbedtls_mutex_lock(&cache->mutex)) != 0) {
47 return ret;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010048 }
Paul Bakkerc5598842013-09-28 15:01:27 +020049#endif
50
Paul Bakker0a597072012-09-25 21:55:46 +000051 cur = cache->chain;
52 entry = NULL;
53
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010054 while (cur != NULL) {
Paul Bakker0a597072012-09-25 21:55:46 +000055 entry = cur;
56 cur = cur->next;
57
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020058#if defined(MBEDTLS_HAVE_TIME)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010059 if (cache->timeout != 0 &&
60 (int) (t - entry->timestamp) > cache->timeout) {
Paul Bakker0a597072012-09-25 21:55:46 +000061 continue;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010062 }
Paul Bakkerfa9b1002013-07-03 15:31:03 +020063#endif
Paul Bakker0a597072012-09-25 21:55:46 +000064
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010065 if (session->id_len != entry->session.id_len ||
66 memcmp(session->id, entry->session.id,
67 entry->session.id_len) != 0) {
Paul Bakker0a597072012-09-25 21:55:46 +000068 continue;
Hanno Becker83e36712021-04-15 08:19:40 +010069 }
Paul Bakker0a597072012-09-25 21:55:46 +000070
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010071 ret = mbedtls_ssl_session_copy(session, &entry->session);
72 if (ret != 0) {
Hanno Beckeraee87172019-02-06 14:53:19 +000073 goto exit;
74 }
Manuel Pégourié-Gonnard38d1eba2013-08-23 10:44:29 +020075
Hanno Beckera887d1a2019-02-06 15:57:49 +000076#if defined(MBEDTLS_X509_CRT_PARSE_C) && \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010077 defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
Paul Bakkere81beda2013-03-06 17:40:46 +010078 /*
79 * Restore peer certificate (without rest of the original chain)
80 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010081 if (entry->peer_cert.p != NULL) {
Hanno Beckeraee87172019-02-06 14:53:19 +000082 /* `session->peer_cert` is NULL after the call to
83 * mbedtls_ssl_session_copy(), because cache entries
84 * have the `peer_cert` field set to NULL. */
85
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010086 if ((session->peer_cert = mbedtls_calloc(1,
87 sizeof(mbedtls_x509_crt))) == NULL) {
Gilles Peskinefe4d93a2023-09-29 13:40:33 +020088 ret = MBEDTLS_ERR_SSL_ALLOC_FAILED;
Paul Bakkerc5598842013-09-28 15:01:27 +020089 goto exit;
90 }
Paul Bakkere81beda2013-03-06 17:40:46 +010091
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010092 mbedtls_x509_crt_init(session->peer_cert);
Gilles Peskinefe4d93a2023-09-29 13:40:33 +020093 if ((ret = mbedtls_x509_crt_parse(session->peer_cert, entry->peer_cert.p,
94 entry->peer_cert.len)) != 0) {
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010095 mbedtls_free(session->peer_cert);
Paul Bakkere81beda2013-03-06 17:40:46 +010096 session->peer_cert = NULL;
Paul Bakkerc5598842013-09-28 15:01:27 +020097 goto exit;
Paul Bakkere81beda2013-03-06 17:40:46 +010098 }
99 }
Hanno Beckera887d1a2019-02-06 15:57:49 +0000100#endif /* MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
Paul Bakkere81beda2013-03-06 17:40:46 +0100101
Paul Bakkerc5598842013-09-28 15:01:27 +0200102 ret = 0;
103 goto exit;
Paul Bakker0a597072012-09-25 21:55:46 +0000104 }
105
Paul Bakkerc5598842013-09-28 15:01:27 +0200106exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200107#if defined(MBEDTLS_THREADING_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100108 if (mbedtls_mutex_unlock(&cache->mutex) != 0) {
Gilles Peskinefe4d93a2023-09-29 13:40:33 +0200109 ret = MBEDTLS_ERR_THREADING_MUTEX_ERROR;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100110 }
Paul Bakkerc5598842013-09-28 15:01:27 +0200111#endif
112
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100113 return ret;
Paul Bakker0a597072012-09-25 21:55:46 +0000114}
115
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100116int mbedtls_ssl_cache_set(void *data, const mbedtls_ssl_session *session)
Paul Bakker0a597072012-09-25 21:55:46 +0000117{
Gilles Peskinefe4d93a2023-09-29 13:40:33 +0200118 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200119#if defined(MBEDTLS_HAVE_TIME)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100120 mbedtls_time_t t = mbedtls_time(NULL), oldest = 0;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200121 mbedtls_ssl_cache_entry *old = NULL;
Paul Bakkerfa9b1002013-07-03 15:31:03 +0200122#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200123 mbedtls_ssl_cache_context *cache = (mbedtls_ssl_cache_context *) data;
124 mbedtls_ssl_cache_entry *cur, *prv;
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000125 int count = 0;
Paul Bakker0a597072012-09-25 21:55:46 +0000126
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127#if defined(MBEDTLS_THREADING_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100128 if ((ret = mbedtls_mutex_lock(&cache->mutex)) != 0) {
129 return ret;
130 }
Paul Bakkerc5598842013-09-28 15:01:27 +0200131#endif
132
Paul Bakker0a597072012-09-25 21:55:46 +0000133 cur = cache->chain;
134 prv = NULL;
135
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100136 while (cur != NULL) {
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000137 count++;
138
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200139#if defined(MBEDTLS_HAVE_TIME)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100140 if (cache->timeout != 0 &&
141 (int) (t - cur->timestamp) > cache->timeout) {
Paul Bakker0a597072012-09-25 21:55:46 +0000142 cur->timestamp = t;
143 break; /* expired, reuse this slot, update timestamp */
144 }
Paul Bakkerfa9b1002013-07-03 15:31:03 +0200145#endif
Paul Bakker0a597072012-09-25 21:55:46 +0000146
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100147 if (memcmp(session->id, cur->session.id, cur->session.id_len) == 0) {
Paul Bakker0a597072012-09-25 21:55:46 +0000148 break; /* client reconnected, keep timestamp for session id */
149
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100150 }
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200151#if defined(MBEDTLS_HAVE_TIME)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100152 if (oldest == 0 || cur->timestamp < oldest) {
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000153 oldest = cur->timestamp;
154 old = cur;
155 }
Paul Bakkerfa9b1002013-07-03 15:31:03 +0200156#endif
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000157
Paul Bakker0a597072012-09-25 21:55:46 +0000158 prv = cur;
159 cur = cur->next;
160 }
161
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100162 if (cur == NULL) {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200163#if defined(MBEDTLS_HAVE_TIME)
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000164 /*
165 * Reuse oldest entry if max_entries reached
166 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100167 if (count >= cache->max_entries) {
168 if (old == NULL) {
Gilles Peskinefe4d93a2023-09-29 13:40:33 +0200169 /* This should only happen on an ill-configured cache
170 * with max_entries == 0. */
171 ret = MBEDTLS_ERR_SSL_INTERNAL_ERROR;
Manuel Pégourié-Gonnard274a12e2014-02-20 21:32:08 +0100172 goto exit;
173 }
174
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000175 cur = old;
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000176 }
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200177#else /* MBEDTLS_HAVE_TIME */
Paul Bakkerfa9b1002013-07-03 15:31:03 +0200178 /*
179 * Reuse first entry in chain if max_entries reached,
180 * but move to last place
181 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100182 if (count >= cache->max_entries) {
183 if (cache->chain == NULL) {
Gilles Peskinefe4d93a2023-09-29 13:40:33 +0200184 ret = MBEDTLS_ERR_SSL_INTERNAL_ERROR;
Paul Bakkerc5598842013-09-28 15:01:27 +0200185 goto exit;
186 }
Paul Bakkerfa9b1002013-07-03 15:31:03 +0200187
188 cur = cache->chain;
189 cache->chain = cur->next;
Manuel Pégourié-Gonnard84c30c72014-02-26 17:38:55 +0100190 cur->next = NULL;
Paul Bakkerfa9b1002013-07-03 15:31:03 +0200191 prv->next = cur;
192 }
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200193#endif /* MBEDTLS_HAVE_TIME */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100194 else {
Manuel Pégourié-Gonnard274a12e2014-02-20 21:32:08 +0100195 /*
196 * max_entries not reached, create new entry
197 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100198 cur = mbedtls_calloc(1, sizeof(mbedtls_ssl_cache_entry));
199 if (cur == NULL) {
Gilles Peskinefe4d93a2023-09-29 13:40:33 +0200200 ret = MBEDTLS_ERR_SSL_ALLOC_FAILED;
Paul Bakkerc5598842013-09-28 15:01:27 +0200201 goto exit;
202 }
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000203
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100204 if (prv == NULL) {
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000205 cache->chain = cur;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100206 } else {
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000207 prv->next = cur;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100208 }
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000209 }
Paul Bakker0a597072012-09-25 21:55:46 +0000210
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200211#if defined(MBEDTLS_HAVE_TIME)
Paul Bakker0a597072012-09-25 21:55:46 +0000212 cur->timestamp = t;
Paul Bakkerfa9b1002013-07-03 15:31:03 +0200213#endif
Paul Bakker0a597072012-09-25 21:55:46 +0000214 }
215
Hanno Beckera887d1a2019-02-06 15:57:49 +0000216#if defined(MBEDTLS_X509_CRT_PARSE_C) && \
217 defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
Paul Bakkere81beda2013-03-06 17:40:46 +0100218 /*
Manuel Pégourié-Gonnard84c30c72014-02-26 17:38:55 +0100219 * If we're reusing an entry, free its certificate first
220 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100221 if (cur->peer_cert.p != NULL) {
222 mbedtls_free(cur->peer_cert.p);
223 memset(&cur->peer_cert, 0, sizeof(mbedtls_x509_buf));
Manuel Pégourié-Gonnard84c30c72014-02-26 17:38:55 +0100224 }
Hanno Beckera887d1a2019-02-06 15:57:49 +0000225#endif /* MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
Manuel Pégourié-Gonnard84c30c72014-02-26 17:38:55 +0100226
Hanno Beckeraee87172019-02-06 14:53:19 +0000227 /* Copy the entire session; this temporarily makes a copy of the
228 * X.509 CRT structure even though we only want to store the raw CRT.
229 * This inefficiency will go away as soon as we implement on-demand
230 * parsing of CRTs, in which case there's no need for the `peer_cert`
231 * field anymore in the first place, and we're done after this call. */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100232 ret = mbedtls_ssl_session_copy(&cur->session, session);
233 if (ret != 0) {
Hanno Beckeraee87172019-02-06 14:53:19 +0000234 goto exit;
235 }
236
Hanno Beckera887d1a2019-02-06 15:57:49 +0000237#if defined(MBEDTLS_X509_CRT_PARSE_C) && \
238 defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
Hanno Beckeraee87172019-02-06 14:53:19 +0000239 /* If present, free the X.509 structure and only store the raw CRT data. */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100240 if (cur->session.peer_cert != NULL) {
Hanno Beckeraee87172019-02-06 14:53:19 +0000241 cur->peer_cert.p =
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100242 mbedtls_calloc(1, cur->session.peer_cert->raw.len);
243 if (cur->peer_cert.p == NULL) {
Gilles Peskinefe4d93a2023-09-29 13:40:33 +0200244 ret = MBEDTLS_ERR_SSL_ALLOC_FAILED;
Paul Bakkerc5598842013-09-28 15:01:27 +0200245 goto exit;
246 }
Paul Bakkere81beda2013-03-06 17:40:46 +0100247
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100248 memcpy(cur->peer_cert.p,
249 cur->session.peer_cert->raw.p,
250 cur->session.peer_cert->raw.len);
Paul Bakkere81beda2013-03-06 17:40:46 +0100251 cur->peer_cert.len = session->peer_cert->raw.len;
252
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100253 mbedtls_x509_crt_free(cur->session.peer_cert);
254 mbedtls_free(cur->session.peer_cert);
Paul Bakkere81beda2013-03-06 17:40:46 +0100255 cur->session.peer_cert = NULL;
256 }
Hanno Beckera887d1a2019-02-06 15:57:49 +0000257#endif /* MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
Paul Bakker0a597072012-09-25 21:55:46 +0000258
Paul Bakkerc5598842013-09-28 15:01:27 +0200259 ret = 0;
260
261exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200262#if defined(MBEDTLS_THREADING_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100263 if (mbedtls_mutex_unlock(&cache->mutex) != 0) {
Gilles Peskinefe4d93a2023-09-29 13:40:33 +0200264 ret = MBEDTLS_ERR_THREADING_MUTEX_ERROR;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100265 }
Paul Bakkerc5598842013-09-28 15:01:27 +0200266#endif
267
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100268 return ret;
Paul Bakker0a597072012-09-25 21:55:46 +0000269}
270
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200271#if defined(MBEDTLS_HAVE_TIME)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100272void mbedtls_ssl_cache_set_timeout(mbedtls_ssl_cache_context *cache, int timeout)
Paul Bakker0a597072012-09-25 21:55:46 +0000273{
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100274 if (timeout < 0) {
275 timeout = 0;
276 }
Paul Bakker0a597072012-09-25 21:55:46 +0000277
278 cache->timeout = timeout;
279}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200280#endif /* MBEDTLS_HAVE_TIME */
Paul Bakker0a597072012-09-25 21:55:46 +0000281
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100282void mbedtls_ssl_cache_set_max_entries(mbedtls_ssl_cache_context *cache, int max)
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000283{
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100284 if (max < 0) {
285 max = 0;
286 }
Paul Bakkerba26e9e2012-10-23 22:18:28 +0000287
288 cache->max_entries = max;
289}
290
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100291void mbedtls_ssl_cache_free(mbedtls_ssl_cache_context *cache)
Paul Bakker0a597072012-09-25 21:55:46 +0000292{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200293 mbedtls_ssl_cache_entry *cur, *prv;
Paul Bakker0a597072012-09-25 21:55:46 +0000294
295 cur = cache->chain;
296
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100297 while (cur != NULL) {
Paul Bakker0a597072012-09-25 21:55:46 +0000298 prv = cur;
299 cur = cur->next;
300
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100301 mbedtls_ssl_session_free(&prv->session);
Paul Bakkere81beda2013-03-06 17:40:46 +0100302
Hanno Beckera887d1a2019-02-06 15:57:49 +0000303#if defined(MBEDTLS_X509_CRT_PARSE_C) && \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100304 defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
305 mbedtls_free(prv->peer_cert.p);
Hanno Beckera887d1a2019-02-06 15:57:49 +0000306#endif /* MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
Paul Bakkere81beda2013-03-06 17:40:46 +0100307
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100308 mbedtls_free(prv);
Paul Bakker0a597072012-09-25 21:55:46 +0000309 }
Paul Bakkerc5598842013-09-28 15:01:27 +0200310
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200311#if defined(MBEDTLS_THREADING_C)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100312 mbedtls_mutex_free(&cache->mutex);
Paul Bakkerc5598842013-09-28 15:01:27 +0200313#endif
Ron Eldor22360822017-10-29 17:53:52 +0200314 cache->chain = NULL;
Paul Bakker0a597072012-09-25 21:55:46 +0000315}
316
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200317#endif /* MBEDTLS_SSL_CACHE_C */