Manuel Pégourié-Gonnard | fd6d897 | 2015-05-15 12:09:00 +0200 | [diff] [blame] | 1 | /* |
| 2 | * TLS server tickets callbacks implementation |
| 3 | * |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 4 | * Copyright The Mbed TLS Contributors |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 5 | * 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. |
Manuel Pégourié-Gonnard | fd6d897 | 2015-05-15 12:09:00 +0200 | [diff] [blame] | 18 | */ |
| 19 | |
Gilles Peskine | db09ef6 | 2020-06-03 01:43:33 +0200 | [diff] [blame] | 20 | #include "common.h" |
Manuel Pégourié-Gonnard | fd6d897 | 2015-05-15 12:09:00 +0200 | [diff] [blame] | 21 | |
| 22 | #if defined(MBEDTLS_SSL_TICKET_C) |
| 23 | |
Manuel Pégourié-Gonnard | fd6d897 | 2015-05-15 12:09:00 +0200 | [diff] [blame] | 24 | #if defined(MBEDTLS_PLATFORM_C) |
| 25 | #include "mbedtls/platform.h" |
| 26 | #else |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 27 | #include <stdlib.h> |
| 28 | #define mbedtls_calloc calloc |
SimonB | d5800b7 | 2016-04-26 07:43:27 +0100 | [diff] [blame] | 29 | #define mbedtls_free free |
Manuel Pégourié-Gonnard | fd6d897 | 2015-05-15 12:09:00 +0200 | [diff] [blame] | 30 | #endif |
| 31 | |
Chris Jones | 84a773f | 2021-03-05 18:38:47 +0000 | [diff] [blame] | 32 | #include "ssl_misc.h" |
SimonB | d5800b7 | 2016-04-26 07:43:27 +0100 | [diff] [blame] | 33 | #include "mbedtls/ssl_ticket.h" |
Janos Follath | 865b3eb | 2019-12-16 11:46:15 +0000 | [diff] [blame] | 34 | #include "mbedtls/error.h" |
Janos Follath | 73c616b | 2019-12-18 15:07:04 +0000 | [diff] [blame] | 35 | #include "mbedtls/platform_util.h" |
SimonB | d5800b7 | 2016-04-26 07:43:27 +0100 | [diff] [blame] | 36 | |
Manuel Pégourié-Gonnard | fd6d897 | 2015-05-15 12:09:00 +0200 | [diff] [blame] | 37 | #include <string.h> |
| 38 | |
Manuel Pégourié-Gonnard | d59675d | 2015-05-19 15:28:00 +0200 | [diff] [blame] | 39 | /* |
| 40 | * Initialze context |
| 41 | */ |
| 42 | void mbedtls_ssl_ticket_init( mbedtls_ssl_ticket_context *ctx ) |
| 43 | { |
| 44 | memset( ctx, 0, sizeof( mbedtls_ssl_ticket_context ) ); |
Manuel Pégourié-Gonnard | 0849a0a | 2015-05-20 11:34:54 +0200 | [diff] [blame] | 45 | |
| 46 | #if defined(MBEDTLS_THREADING_C) |
| 47 | mbedtls_mutex_init( &ctx->mutex ); |
| 48 | #endif |
Manuel Pégourié-Gonnard | d59675d | 2015-05-19 15:28:00 +0200 | [diff] [blame] | 49 | } |
| 50 | |
Glenn Strauss | a941b62 | 2022-02-09 15:24:56 -0500 | [diff] [blame] | 51 | #define MAX_KEY_BYTES MBEDTLS_SSL_TICKET_MAX_KEY_BYTES |
Manuel Pégourié-Gonnard | 887674a | 2015-05-25 11:00:19 +0200 | [diff] [blame] | 52 | |
Glenn Strauss | a941b62 | 2022-02-09 15:24:56 -0500 | [diff] [blame] | 53 | #define TICKET_KEY_NAME_BYTES MBEDTLS_SSL_TICKET_KEY_NAME_BYTES |
Hanno Becker | d140d08 | 2018-11-17 21:18:01 +0000 | [diff] [blame] | 54 | #define TICKET_IV_BYTES 12 |
| 55 | #define TICKET_CRYPT_LEN_BYTES 2 |
| 56 | #define TICKET_AUTH_TAG_BYTES 16 |
| 57 | |
| 58 | #define TICKET_MIN_LEN ( TICKET_KEY_NAME_BYTES + \ |
| 59 | TICKET_IV_BYTES + \ |
| 60 | TICKET_CRYPT_LEN_BYTES + \ |
| 61 | TICKET_AUTH_TAG_BYTES ) |
| 62 | #define TICKET_ADD_DATA_LEN ( TICKET_KEY_NAME_BYTES + \ |
| 63 | TICKET_IV_BYTES + \ |
| 64 | TICKET_CRYPT_LEN_BYTES ) |
| 65 | |
Manuel Pégourié-Gonnard | 887674a | 2015-05-25 11:00:19 +0200 | [diff] [blame] | 66 | /* |
| 67 | * Generate/update a key |
| 68 | */ |
| 69 | static int ssl_ticket_gen_key( mbedtls_ssl_ticket_context *ctx, |
| 70 | unsigned char index ) |
| 71 | { |
Janos Follath | 865b3eb | 2019-12-16 11:46:15 +0000 | [diff] [blame] | 72 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Manuel Pégourié-Gonnard | 887674a | 2015-05-25 11:00:19 +0200 | [diff] [blame] | 73 | unsigned char buf[MAX_KEY_BYTES]; |
| 74 | mbedtls_ssl_ticket_key *key = ctx->keys + index; |
| 75 | |
Gabor Mezei | 2a02051 | 2022-03-10 15:15:46 +0100 | [diff] [blame] | 76 | #if defined(MBEDTLS_USE_PSA_CRYPTO) |
| 77 | psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; |
| 78 | #endif |
| 79 | |
Manuel Pégourié-Gonnard | 887674a | 2015-05-25 11:00:19 +0200 | [diff] [blame] | 80 | #if defined(MBEDTLS_HAVE_TIME) |
SimonB | d5800b7 | 2016-04-26 07:43:27 +0100 | [diff] [blame] | 81 | key->generation_time = (uint32_t) mbedtls_time( NULL ); |
Manuel Pégourié-Gonnard | 887674a | 2015-05-25 11:00:19 +0200 | [diff] [blame] | 82 | #endif |
| 83 | |
| 84 | if( ( ret = ctx->f_rng( ctx->p_rng, key->name, sizeof( key->name ) ) ) != 0 ) |
| 85 | return( ret ); |
| 86 | |
| 87 | if( ( ret = ctx->f_rng( ctx->p_rng, buf, sizeof( buf ) ) ) != 0 ) |
| 88 | return( ret ); |
| 89 | |
Gabor Mezei | 2a02051 | 2022-03-10 15:15:46 +0100 | [diff] [blame] | 90 | #if defined(MBEDTLS_USE_PSA_CRYPTO) |
| 91 | |
| 92 | psa_set_key_usage_flags( &attributes, |
| 93 | PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT ); |
| 94 | psa_set_key_algorithm( &attributes, key->alg ); |
| 95 | psa_set_key_type( &attributes, key->key_type ); |
| 96 | psa_set_key_bits( &attributes, key->key_bits ); |
| 97 | |
| 98 | ret = psa_ssl_status_to_mbedtls( |
| 99 | psa_import_key( &attributes, buf, |
| 100 | PSA_BITS_TO_BYTES( key->key_bits ), |
| 101 | &key->key ) ); |
| 102 | |
| 103 | #else |
| 104 | |
Manuel Pégourié-Gonnard | 887674a | 2015-05-25 11:00:19 +0200 | [diff] [blame] | 105 | /* With GCM and CCM, same context can encrypt & decrypt */ |
| 106 | ret = mbedtls_cipher_setkey( &key->ctx, buf, |
Manuel Pégourié-Gonnard | 097c7bb | 2015-06-18 16:43:38 +0200 | [diff] [blame] | 107 | mbedtls_cipher_get_key_bitlen( &key->ctx ), |
Manuel Pégourié-Gonnard | 887674a | 2015-05-25 11:00:19 +0200 | [diff] [blame] | 108 | MBEDTLS_ENCRYPT ); |
| 109 | |
Gabor Mezei | 2a02051 | 2022-03-10 15:15:46 +0100 | [diff] [blame] | 110 | #endif /* MBEDTLS_USE_PSA_CRYPTO */ |
| 111 | |
Andres Amaya Garcia | 1f6301b | 2018-04-17 09:51:09 -0500 | [diff] [blame] | 112 | mbedtls_platform_zeroize( buf, sizeof( buf ) ); |
Manuel Pégourié-Gonnard | 887674a | 2015-05-25 11:00:19 +0200 | [diff] [blame] | 113 | |
| 114 | return( ret ); |
| 115 | } |
| 116 | |
Manuel Pégourié-Gonnard | d59675d | 2015-05-19 15:28:00 +0200 | [diff] [blame] | 117 | /* |
Manuel Pégourié-Gonnard | 1e9c4db | 2015-05-25 14:07:08 +0200 | [diff] [blame] | 118 | * Rotate/generate keys if necessary |
| 119 | */ |
| 120 | static int ssl_ticket_update_keys( mbedtls_ssl_ticket_context *ctx ) |
| 121 | { |
| 122 | #if !defined(MBEDTLS_HAVE_TIME) |
| 123 | ((void) ctx); |
| 124 | #else |
| 125 | if( ctx->ticket_lifetime != 0 ) |
| 126 | { |
SimonB | d5800b7 | 2016-04-26 07:43:27 +0100 | [diff] [blame] | 127 | uint32_t current_time = (uint32_t) mbedtls_time( NULL ); |
Manuel Pégourié-Gonnard | 1e9c4db | 2015-05-25 14:07:08 +0200 | [diff] [blame] | 128 | uint32_t key_time = ctx->keys[ctx->active].generation_time; |
| 129 | |
Gabor Mezei | 2a02051 | 2022-03-10 15:15:46 +0100 | [diff] [blame] | 130 | #if defined(MBEDTLS_USE_PSA_CRYPTO) |
| 131 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
| 132 | #endif |
| 133 | |
Hanno Becker | aa71500 | 2018-08-21 13:55:31 +0100 | [diff] [blame] | 134 | if( current_time >= key_time && |
Manuel Pégourié-Gonnard | 1e9c4db | 2015-05-25 14:07:08 +0200 | [diff] [blame] | 135 | current_time - key_time < ctx->ticket_lifetime ) |
| 136 | { |
| 137 | return( 0 ); |
| 138 | } |
| 139 | |
| 140 | ctx->active = 1 - ctx->active; |
| 141 | |
Gabor Mezei | 2a02051 | 2022-03-10 15:15:46 +0100 | [diff] [blame] | 142 | #if defined(MBEDTLS_USE_PSA_CRYPTO) |
| 143 | |
| 144 | if( ( ret = psa_ssl_status_to_mbedtls( |
| 145 | psa_destroy_key( ctx->keys[ctx->active].key ) ) ) != 0 ) |
| 146 | return( ret ); |
| 147 | |
| 148 | #endif /* MBEDTLS_USE_PSA_CRYPTO */ |
| 149 | |
Manuel Pégourié-Gonnard | 1e9c4db | 2015-05-25 14:07:08 +0200 | [diff] [blame] | 150 | return( ssl_ticket_gen_key( ctx, ctx->active ) ); |
| 151 | } |
| 152 | else |
| 153 | #endif /* MBEDTLS_HAVE_TIME */ |
| 154 | return( 0 ); |
| 155 | } |
| 156 | |
| 157 | /* |
Glenn Strauss | a950938 | 2022-02-02 23:32:18 -0500 | [diff] [blame] | 158 | * Rotate active session ticket encryption key |
| 159 | */ |
| 160 | int mbedtls_ssl_ticket_rotate( mbedtls_ssl_ticket_context *ctx, |
| 161 | const unsigned char *name, size_t nlength, |
| 162 | const unsigned char *k, size_t klength, |
| 163 | uint32_t lifetime ) |
| 164 | { |
| 165 | const unsigned char idx = 1 - ctx->active; |
| 166 | mbedtls_ssl_ticket_key * const key = ctx->keys + idx; |
Gabor Mezei | 2a02051 | 2022-03-10 15:15:46 +0100 | [diff] [blame] | 167 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
| 168 | |
| 169 | #if defined(MBEDTLS_USE_PSA_CRYPTO) |
| 170 | psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; |
| 171 | const int bitlen = key->key_bits; |
| 172 | #else |
Glenn Strauss | a950938 | 2022-02-02 23:32:18 -0500 | [diff] [blame] | 173 | const int bitlen = mbedtls_cipher_get_key_bitlen( &key->ctx ); |
Gabor Mezei | 2a02051 | 2022-03-10 15:15:46 +0100 | [diff] [blame] | 174 | #endif |
| 175 | |
Glenn Strauss | a950938 | 2022-02-02 23:32:18 -0500 | [diff] [blame] | 176 | if( nlength < TICKET_KEY_NAME_BYTES || klength * 8 < (size_t)bitlen ) |
| 177 | return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); |
| 178 | |
Gabor Mezei | 2a02051 | 2022-03-10 15:15:46 +0100 | [diff] [blame] | 179 | #if defined(MBEDTLS_USE_PSA_CRYPTO) |
| 180 | |
| 181 | if( ( ret = psa_ssl_status_to_mbedtls( |
| 182 | psa_destroy_key( key->key ) ) ) != 0 ) |
| 183 | return( ret ); |
| 184 | |
| 185 | psa_set_key_usage_flags( &attributes, |
| 186 | PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT ); |
| 187 | psa_set_key_algorithm( &attributes, key->alg ); |
| 188 | psa_set_key_type( &attributes, key->key_type ); |
| 189 | psa_set_key_bits( &attributes, key->key_bits ); |
| 190 | |
| 191 | if( ( ret = psa_ssl_status_to_mbedtls( |
| 192 | psa_import_key( &attributes, k, |
| 193 | PSA_BITS_TO_BYTES( key->key_bits ), |
| 194 | &key->key ) ) ) != 0 ) |
| 195 | return( ret ); |
| 196 | |
| 197 | #else |
| 198 | |
Glenn Strauss | a950938 | 2022-02-02 23:32:18 -0500 | [diff] [blame] | 199 | ret = mbedtls_cipher_setkey( &key->ctx, k, bitlen, MBEDTLS_ENCRYPT ); |
| 200 | if( ret != 0 ) |
| 201 | return( ret ); |
| 202 | |
Gabor Mezei | 2a02051 | 2022-03-10 15:15:46 +0100 | [diff] [blame] | 203 | #endif /* MBEDTLS_USE_PSA_CRYPTO */ |
| 204 | |
Glenn Strauss | a950938 | 2022-02-02 23:32:18 -0500 | [diff] [blame] | 205 | ctx->active = idx; |
| 206 | ctx->ticket_lifetime = lifetime; |
| 207 | memcpy( key->name, name, TICKET_KEY_NAME_BYTES ); |
| 208 | #if defined(MBEDTLS_HAVE_TIME) |
| 209 | key->generation_time = (uint32_t) mbedtls_time( NULL ); |
| 210 | #endif |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | /* |
Manuel Pégourié-Gonnard | d59675d | 2015-05-19 15:28:00 +0200 | [diff] [blame] | 215 | * Setup context for actual use |
| 216 | */ |
| 217 | int mbedtls_ssl_ticket_setup( mbedtls_ssl_ticket_context *ctx, |
| 218 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, |
Manuel Pégourié-Gonnard | a0adc1b | 2015-05-25 10:35:16 +0200 | [diff] [blame] | 219 | mbedtls_cipher_type_t cipher, |
Manuel Pégourié-Gonnard | d59675d | 2015-05-19 15:28:00 +0200 | [diff] [blame] | 220 | uint32_t lifetime ) |
| 221 | { |
Janos Follath | 865b3eb | 2019-12-16 11:46:15 +0000 | [diff] [blame] | 222 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Manuel Pégourié-Gonnard | 887674a | 2015-05-25 11:00:19 +0200 | [diff] [blame] | 223 | const mbedtls_cipher_info_t *cipher_info; |
Manuel Pégourié-Gonnard | d59675d | 2015-05-19 15:28:00 +0200 | [diff] [blame] | 224 | |
Gabor Mezei | 2a02051 | 2022-03-10 15:15:46 +0100 | [diff] [blame] | 225 | #if defined(MBEDTLS_USE_PSA_CRYPTO) |
| 226 | psa_algorithm_t alg; |
| 227 | psa_key_type_t key_type; |
| 228 | size_t key_bits; |
| 229 | #endif |
| 230 | |
Manuel Pégourié-Gonnard | d59675d | 2015-05-19 15:28:00 +0200 | [diff] [blame] | 231 | ctx->f_rng = f_rng; |
| 232 | ctx->p_rng = p_rng; |
| 233 | |
| 234 | ctx->ticket_lifetime = lifetime; |
| 235 | |
Gabor Mezei | e6d867f | 2022-03-10 15:04:58 +0100 | [diff] [blame] | 236 | cipher_info = mbedtls_cipher_info_from_type( cipher ); |
Manuel Pégourié-Gonnard | 887674a | 2015-05-25 11:00:19 +0200 | [diff] [blame] | 237 | |
Gilles Peskine | e720dbe | 2021-07-19 17:37:46 +0200 | [diff] [blame] | 238 | if( mbedtls_cipher_info_get_mode( cipher_info ) != MBEDTLS_MODE_GCM && |
| 239 | mbedtls_cipher_info_get_mode( cipher_info ) != MBEDTLS_MODE_CCM ) |
Manuel Pégourié-Gonnard | d59675d | 2015-05-19 15:28:00 +0200 | [diff] [blame] | 240 | { |
Manuel Pégourié-Gonnard | 887674a | 2015-05-25 11:00:19 +0200 | [diff] [blame] | 241 | return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); |
Manuel Pégourié-Gonnard | d59675d | 2015-05-19 15:28:00 +0200 | [diff] [blame] | 242 | } |
| 243 | |
Gilles Peskine | e720dbe | 2021-07-19 17:37:46 +0200 | [diff] [blame] | 244 | if( mbedtls_cipher_info_get_key_bitlen( cipher_info ) > 8 * MAX_KEY_BYTES ) |
Manuel Pégourié-Gonnard | 887674a | 2015-05-25 11:00:19 +0200 | [diff] [blame] | 245 | return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); |
| 246 | |
Hanno Becker | 679d8ce | 2018-11-17 21:25:59 +0000 | [diff] [blame] | 247 | #if defined(MBEDTLS_USE_PSA_CRYPTO) |
Gabor Mezei | 2a02051 | 2022-03-10 15:15:46 +0100 | [diff] [blame] | 248 | |
| 249 | if( mbedtls_ssl_cipher_to_psa( cipher_info->type, TICKET_AUTH_TAG_BYTES, |
| 250 | &alg, &key_type, &key_bits ) != PSA_SUCCESS ) |
| 251 | return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); |
| 252 | |
| 253 | ctx->keys[0].alg = alg; |
| 254 | ctx->keys[0].key_type = key_type; |
| 255 | ctx->keys[0].key_bits = key_bits; |
| 256 | |
| 257 | ctx->keys[1].alg = alg; |
| 258 | ctx->keys[1].key_type = key_type; |
| 259 | ctx->keys[1].key_bits = key_bits; |
| 260 | |
| 261 | #else |
| 262 | |
Hanno Becker | 679d8ce | 2018-11-17 21:25:59 +0000 | [diff] [blame] | 263 | if( ( ret = mbedtls_cipher_setup( &ctx->keys[0].ctx, cipher_info ) ) != 0 ) |
| 264 | return( ret ); |
| 265 | |
Hanno Becker | 679d8ce | 2018-11-17 21:25:59 +0000 | [diff] [blame] | 266 | if( ( ret = mbedtls_cipher_setup( &ctx->keys[1].ctx, cipher_info ) ) != 0 ) |
| 267 | return( ret ); |
Manuel Pégourié-Gonnard | a0adc1b | 2015-05-25 10:35:16 +0200 | [diff] [blame] | 268 | |
Gabor Mezei | 2a02051 | 2022-03-10 15:15:46 +0100 | [diff] [blame] | 269 | #endif /* MBEDTLS_USE_PSA_CRYPTO */ |
| 270 | |
Manuel Pégourié-Gonnard | 887674a | 2015-05-25 11:00:19 +0200 | [diff] [blame] | 271 | if( ( ret = ssl_ticket_gen_key( ctx, 0 ) ) != 0 || |
| 272 | ( ret = ssl_ticket_gen_key( ctx, 1 ) ) != 0 ) |
Manuel Pégourié-Gonnard | a0adc1b | 2015-05-25 10:35:16 +0200 | [diff] [blame] | 273 | { |
Manuel Pégourié-Gonnard | 887674a | 2015-05-25 11:00:19 +0200 | [diff] [blame] | 274 | return( ret ); |
Manuel Pégourié-Gonnard | a0adc1b | 2015-05-25 10:35:16 +0200 | [diff] [blame] | 275 | } |
| 276 | |
Manuel Pégourié-Gonnard | 887674a | 2015-05-25 11:00:19 +0200 | [diff] [blame] | 277 | return( 0 ); |
Manuel Pégourié-Gonnard | d59675d | 2015-05-19 15:28:00 +0200 | [diff] [blame] | 278 | } |
| 279 | |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 280 | /* |
Manuel Pégourié-Gonnard | 1041a39 | 2015-05-20 19:59:39 +0200 | [diff] [blame] | 281 | * Create session ticket, with the following structure: |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 282 | * |
| 283 | * struct { |
Manuel Pégourié-Gonnard | 1041a39 | 2015-05-20 19:59:39 +0200 | [diff] [blame] | 284 | * opaque key_name[4]; |
| 285 | * opaque iv[12]; |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 286 | * opaque encrypted_state<0..2^16-1>; |
Manuel Pégourié-Gonnard | 1041a39 | 2015-05-20 19:59:39 +0200 | [diff] [blame] | 287 | * opaque tag[16]; |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 288 | * } ticket; |
| 289 | * |
Manuel Pégourié-Gonnard | 1041a39 | 2015-05-20 19:59:39 +0200 | [diff] [blame] | 290 | * The key_name, iv, and length of encrypted_state are the additional |
| 291 | * authenticated data. |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 292 | */ |
Hanno Becker | d140d08 | 2018-11-17 21:18:01 +0000 | [diff] [blame] | 293 | |
Manuel Pégourié-Gonnard | b0394be | 2015-05-19 11:40:30 +0200 | [diff] [blame] | 294 | int mbedtls_ssl_ticket_write( void *p_ticket, |
Manuel Pégourié-Gonnard | 69f1728 | 2015-05-18 14:35:08 +0200 | [diff] [blame] | 295 | const mbedtls_ssl_session *session, |
| 296 | unsigned char *start, |
| 297 | const unsigned char *end, |
Manuel Pégourié-Gonnard | b0394be | 2015-05-19 11:40:30 +0200 | [diff] [blame] | 298 | size_t *tlen, |
| 299 | uint32_t *ticket_lifetime ) |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 300 | { |
Janos Follath | 865b3eb | 2019-12-16 11:46:15 +0000 | [diff] [blame] | 301 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Manuel Pégourié-Gonnard | d59675d | 2015-05-19 15:28:00 +0200 | [diff] [blame] | 302 | mbedtls_ssl_ticket_context *ctx = p_ticket; |
Manuel Pégourié-Gonnard | 1e9c4db | 2015-05-25 14:07:08 +0200 | [diff] [blame] | 303 | mbedtls_ssl_ticket_key *key; |
Manuel Pégourié-Gonnard | 1041a39 | 2015-05-20 19:59:39 +0200 | [diff] [blame] | 304 | unsigned char *key_name = start; |
Hanno Becker | d140d08 | 2018-11-17 21:18:01 +0000 | [diff] [blame] | 305 | unsigned char *iv = start + TICKET_KEY_NAME_BYTES; |
| 306 | unsigned char *state_len_bytes = iv + TICKET_IV_BYTES; |
| 307 | unsigned char *state = state_len_bytes + TICKET_CRYPT_LEN_BYTES; |
Manuel Pégourié-Gonnard | 1041a39 | 2015-05-20 19:59:39 +0200 | [diff] [blame] | 308 | size_t clear_len, ciph_len; |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 309 | |
| 310 | *tlen = 0; |
| 311 | |
Manuel Pégourié-Gonnard | 1041a39 | 2015-05-20 19:59:39 +0200 | [diff] [blame] | 312 | if( ctx == NULL || ctx->f_rng == NULL ) |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 313 | return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); |
| 314 | |
Manuel Pégourié-Gonnard | 1041a39 | 2015-05-20 19:59:39 +0200 | [diff] [blame] | 315 | /* We need at least 4 bytes for key_name, 12 for IV, 2 for len 16 for tag, |
| 316 | * in addition to session itself, that will be checked when writing it. */ |
Hanno Becker | 261602c | 2017-04-12 14:54:42 +0100 | [diff] [blame] | 317 | MBEDTLS_SSL_CHK_BUF_PTR( start, end, TICKET_MIN_LEN ); |
Manuel Pégourié-Gonnard | 69f1728 | 2015-05-18 14:35:08 +0200 | [diff] [blame] | 318 | |
Manuel Pégourié-Gonnard | 0849a0a | 2015-05-20 11:34:54 +0200 | [diff] [blame] | 319 | #if defined(MBEDTLS_THREADING_C) |
| 320 | if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) |
| 321 | return( ret ); |
| 322 | #endif |
| 323 | |
Manuel Pégourié-Gonnard | 1e9c4db | 2015-05-25 14:07:08 +0200 | [diff] [blame] | 324 | if( ( ret = ssl_ticket_update_keys( ctx ) ) != 0 ) |
| 325 | goto cleanup; |
| 326 | |
| 327 | key = &ctx->keys[ctx->active]; |
| 328 | |
Manuel Pégourié-Gonnard | 0849a0a | 2015-05-20 11:34:54 +0200 | [diff] [blame] | 329 | *ticket_lifetime = ctx->ticket_lifetime; |
| 330 | |
Hanno Becker | d140d08 | 2018-11-17 21:18:01 +0000 | [diff] [blame] | 331 | memcpy( key_name, key->name, TICKET_KEY_NAME_BYTES ); |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 332 | |
Hanno Becker | d140d08 | 2018-11-17 21:18:01 +0000 | [diff] [blame] | 333 | if( ( ret = ctx->f_rng( ctx->p_rng, iv, TICKET_IV_BYTES ) ) != 0 ) |
Manuel Pégourié-Gonnard | 0849a0a | 2015-05-20 11:34:54 +0200 | [diff] [blame] | 334 | goto cleanup; |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 335 | |
Manuel Pégourié-Gonnard | 69f1728 | 2015-05-18 14:35:08 +0200 | [diff] [blame] | 336 | /* Dump session state */ |
Manuel Pégourié-Gonnard | a3e7c65 | 2019-05-16 10:08:35 +0200 | [diff] [blame] | 337 | if( ( ret = mbedtls_ssl_session_save( session, |
| 338 | state, end - state, |
| 339 | &clear_len ) ) != 0 || |
Manuel Pégourié-Gonnard | 1041a39 | 2015-05-20 19:59:39 +0200 | [diff] [blame] | 340 | (unsigned long) clear_len > 65535 ) |
Manuel Pégourié-Gonnard | 0849a0a | 2015-05-20 11:34:54 +0200 | [diff] [blame] | 341 | { |
| 342 | goto cleanup; |
| 343 | } |
Joe Subbiani | 6dd7364 | 2021-07-19 11:56:54 +0100 | [diff] [blame] | 344 | MBEDTLS_PUT_UINT16_BE( clear_len, state_len_bytes, 0 ); |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 345 | |
Manuel Pégourié-Gonnard | 1041a39 | 2015-05-20 19:59:39 +0200 | [diff] [blame] | 346 | /* Encrypt and authenticate */ |
Gabor Mezei | 2a02051 | 2022-03-10 15:15:46 +0100 | [diff] [blame] | 347 | #if defined(MBEDTLS_USE_PSA_CRYPTO) |
| 348 | if( ( ret = psa_ssl_status_to_mbedtls( |
| 349 | psa_aead_encrypt( key->key, key->alg, iv, TICKET_IV_BYTES, |
| 350 | key_name, TICKET_ADD_DATA_LEN, |
| 351 | state, clear_len, |
| 352 | state, end - state, &ciph_len ) ) ) != 0 ) |
| 353 | #else |
Manuel Pégourié-Gonnard | f5cf71e | 2020-12-01 11:43:40 +0100 | [diff] [blame] | 354 | if( ( ret = mbedtls_cipher_auth_encrypt_ext( &key->ctx, |
Hanno Becker | d140d08 | 2018-11-17 21:18:01 +0000 | [diff] [blame] | 355 | iv, TICKET_IV_BYTES, |
| 356 | /* Additional data: key name, IV and length */ |
| 357 | key_name, TICKET_ADD_DATA_LEN, |
Manuel Pégourié-Gonnard | f5cf71e | 2020-12-01 11:43:40 +0100 | [diff] [blame] | 358 | state, clear_len, |
| 359 | state, end - state, &ciph_len, |
| 360 | TICKET_AUTH_TAG_BYTES ) ) != 0 ) |
Gabor Mezei | 2a02051 | 2022-03-10 15:15:46 +0100 | [diff] [blame] | 361 | #endif /* MBEDTLS_USE_PSA_CRYPTO */ |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 362 | { |
Manuel Pégourié-Gonnard | 0849a0a | 2015-05-20 11:34:54 +0200 | [diff] [blame] | 363 | goto cleanup; |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 364 | } |
Gabor Mezei | 2a02051 | 2022-03-10 15:15:46 +0100 | [diff] [blame] | 365 | |
Manuel Pégourié-Gonnard | f5cf71e | 2020-12-01 11:43:40 +0100 | [diff] [blame] | 366 | if( ciph_len != clear_len + TICKET_AUTH_TAG_BYTES ) |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 367 | { |
Manuel Pégourié-Gonnard | 1041a39 | 2015-05-20 19:59:39 +0200 | [diff] [blame] | 368 | ret = MBEDTLS_ERR_SSL_INTERNAL_ERROR; |
Manuel Pégourié-Gonnard | 0849a0a | 2015-05-20 11:34:54 +0200 | [diff] [blame] | 369 | goto cleanup; |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 370 | } |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 371 | |
Manuel Pégourié-Gonnard | f5cf71e | 2020-12-01 11:43:40 +0100 | [diff] [blame] | 372 | *tlen = TICKET_MIN_LEN + ciph_len - TICKET_AUTH_TAG_BYTES; |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 373 | |
Manuel Pégourié-Gonnard | 0849a0a | 2015-05-20 11:34:54 +0200 | [diff] [blame] | 374 | cleanup: |
| 375 | #if defined(MBEDTLS_THREADING_C) |
| 376 | if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) |
| 377 | return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); |
| 378 | #endif |
| 379 | |
| 380 | return( ret ); |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | /* |
Manuel Pégourié-Gonnard | 1e9c4db | 2015-05-25 14:07:08 +0200 | [diff] [blame] | 384 | * Select key based on name |
| 385 | */ |
| 386 | static mbedtls_ssl_ticket_key *ssl_ticket_select_key( |
| 387 | mbedtls_ssl_ticket_context *ctx, |
| 388 | const unsigned char name[4] ) |
| 389 | { |
| 390 | unsigned char i; |
| 391 | |
| 392 | for( i = 0; i < sizeof( ctx->keys ) / sizeof( *ctx->keys ); i++ ) |
| 393 | if( memcmp( name, ctx->keys[i].name, 4 ) == 0 ) |
| 394 | return( &ctx->keys[i] ); |
| 395 | |
| 396 | return( NULL ); |
| 397 | } |
| 398 | |
| 399 | /* |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 400 | * Load session ticket (see mbedtls_ssl_ticket_write for structure) |
| 401 | */ |
Manuel Pégourié-Gonnard | b0394be | 2015-05-19 11:40:30 +0200 | [diff] [blame] | 402 | int mbedtls_ssl_ticket_parse( void *p_ticket, |
Manuel Pégourié-Gonnard | 69f1728 | 2015-05-18 14:35:08 +0200 | [diff] [blame] | 403 | mbedtls_ssl_session *session, |
| 404 | unsigned char *buf, |
| 405 | size_t len ) |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 406 | { |
Janos Follath | 865b3eb | 2019-12-16 11:46:15 +0000 | [diff] [blame] | 407 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Manuel Pégourié-Gonnard | d59675d | 2015-05-19 15:28:00 +0200 | [diff] [blame] | 408 | mbedtls_ssl_ticket_context *ctx = p_ticket; |
Manuel Pégourié-Gonnard | 1e9c4db | 2015-05-25 14:07:08 +0200 | [diff] [blame] | 409 | mbedtls_ssl_ticket_key *key; |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 410 | unsigned char *key_name = buf; |
Hanno Becker | d140d08 | 2018-11-17 21:18:01 +0000 | [diff] [blame] | 411 | unsigned char *iv = buf + TICKET_KEY_NAME_BYTES; |
| 412 | unsigned char *enc_len_p = iv + TICKET_IV_BYTES; |
| 413 | unsigned char *ticket = enc_len_p + TICKET_CRYPT_LEN_BYTES; |
Manuel Pégourié-Gonnard | 1041a39 | 2015-05-20 19:59:39 +0200 | [diff] [blame] | 414 | size_t enc_len, clear_len; |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 415 | |
Manuel Pégourié-Gonnard | 1e9c4db | 2015-05-25 14:07:08 +0200 | [diff] [blame] | 416 | if( ctx == NULL || ctx->f_rng == NULL ) |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 417 | return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); |
Manuel Pégourié-Gonnard | 1e9c4db | 2015-05-25 14:07:08 +0200 | [diff] [blame] | 418 | |
Hanno Becker | d140d08 | 2018-11-17 21:18:01 +0000 | [diff] [blame] | 419 | if( len < TICKET_MIN_LEN ) |
Manuel Pégourié-Gonnard | 1e9c4db | 2015-05-25 14:07:08 +0200 | [diff] [blame] | 420 | return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 421 | |
Manuel Pégourié-Gonnard | 0849a0a | 2015-05-20 11:34:54 +0200 | [diff] [blame] | 422 | #if defined(MBEDTLS_THREADING_C) |
| 423 | if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) |
| 424 | return( ret ); |
| 425 | #endif |
| 426 | |
Manuel Pégourié-Gonnard | 1e9c4db | 2015-05-25 14:07:08 +0200 | [diff] [blame] | 427 | if( ( ret = ssl_ticket_update_keys( ctx ) ) != 0 ) |
| 428 | goto cleanup; |
| 429 | |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 430 | enc_len = ( enc_len_p[0] << 8 ) | enc_len_p[1]; |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 431 | |
Hanno Becker | d140d08 | 2018-11-17 21:18:01 +0000 | [diff] [blame] | 432 | if( len != TICKET_MIN_LEN + enc_len ) |
Manuel Pégourié-Gonnard | 0849a0a | 2015-05-20 11:34:54 +0200 | [diff] [blame] | 433 | { |
| 434 | ret = MBEDTLS_ERR_SSL_BAD_INPUT_DATA; |
| 435 | goto cleanup; |
| 436 | } |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 437 | |
Manuel Pégourié-Gonnard | 1e9c4db | 2015-05-25 14:07:08 +0200 | [diff] [blame] | 438 | /* Select key */ |
| 439 | if( ( key = ssl_ticket_select_key( ctx, key_name ) ) == NULL ) |
Manuel Pégourié-Gonnard | 0849a0a | 2015-05-20 11:34:54 +0200 | [diff] [blame] | 440 | { |
Manuel Pégourié-Gonnard | 1e9c4db | 2015-05-25 14:07:08 +0200 | [diff] [blame] | 441 | /* We can't know for sure but this is a likely option unless we're |
| 442 | * under attack - this is only informative anyway */ |
| 443 | ret = MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED; |
Manuel Pégourié-Gonnard | 0849a0a | 2015-05-20 11:34:54 +0200 | [diff] [blame] | 444 | goto cleanup; |
| 445 | } |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 446 | |
Manuel Pégourié-Gonnard | 1041a39 | 2015-05-20 19:59:39 +0200 | [diff] [blame] | 447 | /* Decrypt and authenticate */ |
Gabor Mezei | 2a02051 | 2022-03-10 15:15:46 +0100 | [diff] [blame] | 448 | #if defined(MBEDTLS_USE_PSA_CRYPTO) |
| 449 | if( ( ret = psa_ssl_status_to_mbedtls( |
| 450 | psa_aead_decrypt( key->key, key->alg, iv, TICKET_IV_BYTES, |
| 451 | key_name, TICKET_ADD_DATA_LEN, |
| 452 | ticket, enc_len + TICKET_AUTH_TAG_BYTES, |
| 453 | ticket, enc_len, &clear_len ) ) ) != 0 ) |
| 454 | #else |
Manuel Pégourié-Gonnard | f5cf71e | 2020-12-01 11:43:40 +0100 | [diff] [blame] | 455 | if( ( ret = mbedtls_cipher_auth_decrypt_ext( &key->ctx, |
Hanno Becker | d140d08 | 2018-11-17 21:18:01 +0000 | [diff] [blame] | 456 | iv, TICKET_IV_BYTES, |
| 457 | /* Additional data: key name, IV and length */ |
| 458 | key_name, TICKET_ADD_DATA_LEN, |
Manuel Pégourié-Gonnard | f5cf71e | 2020-12-01 11:43:40 +0100 | [diff] [blame] | 459 | ticket, enc_len + TICKET_AUTH_TAG_BYTES, |
| 460 | ticket, enc_len, &clear_len, |
| 461 | TICKET_AUTH_TAG_BYTES ) ) != 0 ) |
Gabor Mezei | 2a02051 | 2022-03-10 15:15:46 +0100 | [diff] [blame] | 462 | #endif /* MBEDTLS_USE_PSA_CRYPTO */ |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 463 | { |
Manuel Pégourié-Gonnard | 1e9c4db | 2015-05-25 14:07:08 +0200 | [diff] [blame] | 464 | if( ret == MBEDTLS_ERR_CIPHER_AUTH_FAILED ) |
| 465 | ret = MBEDTLS_ERR_SSL_INVALID_MAC; |
| 466 | |
Manuel Pégourié-Gonnard | 0849a0a | 2015-05-20 11:34:54 +0200 | [diff] [blame] | 467 | goto cleanup; |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 468 | } |
Manuel Pégourié-Gonnard | 1041a39 | 2015-05-20 19:59:39 +0200 | [diff] [blame] | 469 | if( clear_len != enc_len ) |
| 470 | { |
| 471 | ret = MBEDTLS_ERR_SSL_INTERNAL_ERROR; |
Manuel Pégourié-Gonnard | 0849a0a | 2015-05-20 11:34:54 +0200 | [diff] [blame] | 472 | goto cleanup; |
Manuel Pégourié-Gonnard | 1041a39 | 2015-05-20 19:59:39 +0200 | [diff] [blame] | 473 | } |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 474 | |
| 475 | /* Actually load session */ |
Manuel Pégourié-Gonnard | a3e7c65 | 2019-05-16 10:08:35 +0200 | [diff] [blame] | 476 | if( ( ret = mbedtls_ssl_session_load( session, ticket, clear_len ) ) != 0 ) |
Manuel Pégourié-Gonnard | 0849a0a | 2015-05-20 11:34:54 +0200 | [diff] [blame] | 477 | goto cleanup; |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 478 | |
| 479 | #if defined(MBEDTLS_HAVE_TIME) |
Manuel Pégourié-Gonnard | 0849a0a | 2015-05-20 11:34:54 +0200 | [diff] [blame] | 480 | { |
Manuel Pégourié-Gonnard | 8eff512 | 2015-05-20 11:41:36 +0200 | [diff] [blame] | 481 | /* Check for expiration */ |
SimonB | d5800b7 | 2016-04-26 07:43:27 +0100 | [diff] [blame] | 482 | mbedtls_time_t current_time = mbedtls_time( NULL ); |
Manuel Pégourié-Gonnard | 8eff512 | 2015-05-20 11:41:36 +0200 | [diff] [blame] | 483 | |
| 484 | if( current_time < session->start || |
| 485 | (uint32_t)( current_time - session->start ) > ctx->ticket_lifetime ) |
| 486 | { |
| 487 | ret = MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED; |
| 488 | goto cleanup; |
| 489 | } |
Manuel Pégourié-Gonnard | 0849a0a | 2015-05-20 11:34:54 +0200 | [diff] [blame] | 490 | } |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 491 | #endif |
| 492 | |
Manuel Pégourié-Gonnard | 0849a0a | 2015-05-20 11:34:54 +0200 | [diff] [blame] | 493 | cleanup: |
| 494 | #if defined(MBEDTLS_THREADING_C) |
| 495 | if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) |
| 496 | return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); |
| 497 | #endif |
| 498 | |
| 499 | return( ret ); |
Manuel Pégourié-Gonnard | a4a4735 | 2015-05-15 15:14:54 +0200 | [diff] [blame] | 500 | } |
| 501 | |
Manuel Pégourié-Gonnard | d59675d | 2015-05-19 15:28:00 +0200 | [diff] [blame] | 502 | /* |
| 503 | * Free context |
| 504 | */ |
| 505 | void mbedtls_ssl_ticket_free( mbedtls_ssl_ticket_context *ctx ) |
| 506 | { |
Gabor Mezei | 2a02051 | 2022-03-10 15:15:46 +0100 | [diff] [blame] | 507 | #if defined(MBEDTLS_USE_PSA_CRYPTO) |
| 508 | |
| 509 | psa_destroy_key( ctx->keys[0].key ); |
| 510 | psa_destroy_key( ctx->keys[1].key ); |
| 511 | |
| 512 | #else |
| 513 | |
Manuel Pégourié-Gonnard | 887674a | 2015-05-25 11:00:19 +0200 | [diff] [blame] | 514 | mbedtls_cipher_free( &ctx->keys[0].ctx ); |
| 515 | mbedtls_cipher_free( &ctx->keys[1].ctx ); |
Manuel Pégourié-Gonnard | d59675d | 2015-05-19 15:28:00 +0200 | [diff] [blame] | 516 | |
Gabor Mezei | 2a02051 | 2022-03-10 15:15:46 +0100 | [diff] [blame] | 517 | #endif /* MBEDTLS_USE_PSA_CRYPTO */ |
| 518 | |
Manuel Pégourié-Gonnard | 0849a0a | 2015-05-20 11:34:54 +0200 | [diff] [blame] | 519 | #if defined(MBEDTLS_THREADING_C) |
| 520 | mbedtls_mutex_free( &ctx->mutex ); |
| 521 | #endif |
| 522 | |
Andres Amaya Garcia | 1f6301b | 2018-04-17 09:51:09 -0500 | [diff] [blame] | 523 | mbedtls_platform_zeroize( ctx, sizeof( mbedtls_ssl_ticket_context ) ); |
Manuel Pégourié-Gonnard | d59675d | 2015-05-19 15:28:00 +0200 | [diff] [blame] | 524 | } |
| 525 | |
Manuel Pégourié-Gonnard | fd6d897 | 2015-05-15 12:09:00 +0200 | [diff] [blame] | 526 | #endif /* MBEDTLS_SSL_TICKET_C */ |