blob: 1047dbb0d4f8cf1e9d21af850d9f3769233cb576 [file] [log] [blame]
Manuel Pégourié-Gonnardfd6d8972015-05-15 12:09:00 +02001/**
2 * \file ssl_ticket.h
3 *
4 * \brief TLS server ticket callbacks implementation
Darryl Greena40a1012018-01-05 15:33:17 +00005 */
6/*
Bence Szépkúti1e148272020-08-07 13:07:28 +02007 * Copyright The Mbed TLS Contributors
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02008 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
Manuel Pégourié-Gonnardfd6d8972015-05-15 12:09:00 +020021 */
22#ifndef MBEDTLS_SSL_TICKET_H
23#define MBEDTLS_SSL_TICKET_H
Mateusz Starzyk846f0212021-05-19 19:44:07 +020024#include "mbedtls/private_access.h"
Manuel Pégourié-Gonnardfd6d8972015-05-15 12:09:00 +020025
Ron Eldor8b0cf2e2018-02-14 16:02:41 +020026#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Amero6609aef2019-07-04 20:01:14 +010027#include "mbedtls/config.h"
Ron Eldor8b0cf2e2018-02-14 16:02:41 +020028#else
29#include MBEDTLS_CONFIG_FILE
30#endif
31
Manuel Pégourié-Gonnard4214e3a2015-05-25 19:34:49 +020032/*
33 * This implementation of the session ticket callbacks includes key
34 * management, rotating the keys periodically in order to preserve forward
35 * secrecy, when MBEDTLS_HAVE_TIME is defined.
36 */
37
Jaeden Amero6609aef2019-07-04 20:01:14 +010038#include "mbedtls/ssl.h"
39#include "mbedtls/cipher.h"
Manuel Pégourié-Gonnardfd6d8972015-05-15 12:09:00 +020040
Manuel Pégourié-Gonnard0849a0a2015-05-20 11:34:54 +020041#if defined(MBEDTLS_THREADING_C)
Jaeden Amero6609aef2019-07-04 20:01:14 +010042#include "mbedtls/threading.h"
Manuel Pégourié-Gonnard0849a0a2015-05-20 11:34:54 +020043#endif
44
Manuel Pégourié-Gonnardfd6d8972015-05-15 12:09:00 +020045#ifdef __cplusplus
46extern "C" {
47#endif
48
Manuel Pégourié-Gonnardd59675d2015-05-19 15:28:00 +020049/**
Manuel Pégourié-Gonnard887674a2015-05-25 11:00:19 +020050 * \brief Information for session ticket protection
51 */
Dawid Drozd428cc522018-07-24 10:02:47 +020052typedef struct mbedtls_ssl_ticket_key
Manuel Pégourié-Gonnard887674a2015-05-25 11:00:19 +020053{
Mateusz Starzyk846f0212021-05-19 19:44:07 +020054 unsigned char MBEDTLS_PRIVATE(name)[4]; /*!< random key identifier */
55 uint32_t MBEDTLS_PRIVATE(generation_time); /*!< key generation timestamp (seconds) */
56 mbedtls_cipher_context_t MBEDTLS_PRIVATE(ctx); /*!< context for auth enc/decryption */
Manuel Pégourié-Gonnard887674a2015-05-25 11:00:19 +020057}
58mbedtls_ssl_ticket_key;
59
60/**
Manuel Pégourié-Gonnardd59675d2015-05-19 15:28:00 +020061 * \brief Context for session ticket handling functions
62 */
Dawid Drozd428cc522018-07-24 10:02:47 +020063typedef struct mbedtls_ssl_ticket_context
Manuel Pégourié-Gonnardd59675d2015-05-19 15:28:00 +020064{
Mateusz Starzyk846f0212021-05-19 19:44:07 +020065 mbedtls_ssl_ticket_key MBEDTLS_PRIVATE(keys)[2]; /*!< ticket protection keys */
66 unsigned char MBEDTLS_PRIVATE(active); /*!< index of the currently active key */
Manuel Pégourié-Gonnardd59675d2015-05-19 15:28:00 +020067
Mateusz Starzyk846f0212021-05-19 19:44:07 +020068 uint32_t MBEDTLS_PRIVATE(ticket_lifetime); /*!< lifetime of tickets in seconds */
Manuel Pégourié-Gonnardd59675d2015-05-19 15:28:00 +020069
70 /** Callback for getting (pseudo-)random numbers */
Mateusz Starzyk846f0212021-05-19 19:44:07 +020071 int (*MBEDTLS_PRIVATE(f_rng))(void *, unsigned char *, size_t);
72 void *MBEDTLS_PRIVATE(p_rng); /*!< context for the RNG function */
Manuel Pégourié-Gonnard0849a0a2015-05-20 11:34:54 +020073
74#if defined(MBEDTLS_THREADING_C)
Mateusz Starzyk846f0212021-05-19 19:44:07 +020075 mbedtls_threading_mutex_t MBEDTLS_PRIVATE(mutex);
Manuel Pégourié-Gonnard0849a0a2015-05-20 11:34:54 +020076#endif
Manuel Pégourié-Gonnardd59675d2015-05-19 15:28:00 +020077}
78mbedtls_ssl_ticket_context;
79
80/**
81 * \brief Initialize a ticket context.
82 * (Just make it ready for mbedtls_ssl_ticket_setup()
83 * or mbedtls_ssl_ticket_free().)
84 *
85 * \param ctx Context to be initialized
86 */
87void mbedtls_ssl_ticket_init( mbedtls_ssl_ticket_context *ctx );
88
89/**
90 * \brief Prepare context to be actually used
91 *
92 * \param ctx Context to be set up
Manuel Pégourié-Gonnardad5390f2021-06-15 11:29:26 +020093 * \param f_rng RNG callback function (mandatory)
Manuel Pégourié-Gonnardd59675d2015-05-19 15:28:00 +020094 * \param p_rng RNG callback context
Manuel Pégourié-Gonnarddc54ff82015-06-25 12:44:46 +020095 * \param cipher AEAD cipher to use for ticket protection.
96 * Recommended value: MBEDTLS_CIPHER_AES_256_GCM.
Manuel Pégourié-Gonnardd59675d2015-05-19 15:28:00 +020097 * \param lifetime Tickets lifetime in seconds
Manuel Pégourié-Gonnarddc54ff82015-06-25 12:44:46 +020098 * Recommended value: 86400 (one day).
Manuel Pégourié-Gonnardd59675d2015-05-19 15:28:00 +020099 *
Manuel Pégourié-Gonnarda0adc1b2015-05-25 10:35:16 +0200100 * \note It is highly recommended to select a cipher that is at
Tobias Nießen1e8ca122021-05-10 19:53:15 +0200101 * least as strong as the strongest ciphersuite
Manuel Pégourié-Gonnarda0adc1b2015-05-25 10:35:16 +0200102 * supported. Usually that means a 256-bit key.
103 *
Manuel Pégourié-Gonnarddc54ff82015-06-25 12:44:46 +0200104 * \note The lifetime of the keys is twice the lifetime of tickets.
105 * It is recommended to pick a reasonnable lifetime so as not
106 * to negate the benefits of forward secrecy.
107 *
Manuel Pégourié-Gonnard81abefd2015-05-29 12:53:47 +0200108 * \return 0 if successful,
Manuel Pégourié-Gonnardd59675d2015-05-19 15:28:00 +0200109 * or a specific MBEDTLS_ERR_XXX error code
110 */
111int mbedtls_ssl_ticket_setup( mbedtls_ssl_ticket_context *ctx,
112 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
Manuel Pégourié-Gonnarda0adc1b2015-05-25 10:35:16 +0200113 mbedtls_cipher_type_t cipher,
Manuel Pégourié-Gonnardd59675d2015-05-19 15:28:00 +0200114 uint32_t lifetime );
115
116/**
117 * \brief Implementation of the ticket write callback
118 *
Antonin Décimo36e89b52019-01-23 15:24:37 +0100119 * \note See \c mbedtls_ssl_ticket_write_t for description
Manuel Pégourié-Gonnardd59675d2015-05-19 15:28:00 +0200120 */
121mbedtls_ssl_ticket_write_t mbedtls_ssl_ticket_write;
122
123/**
124 * \brief Implementation of the ticket parse callback
125 *
Antonin Décimo36e89b52019-01-23 15:24:37 +0100126 * \note See \c mbedtls_ssl_ticket_parse_t for description
Manuel Pégourié-Gonnardd59675d2015-05-19 15:28:00 +0200127 */
128mbedtls_ssl_ticket_parse_t mbedtls_ssl_ticket_parse;
129
130/**
131 * \brief Free a context's content and zeroize it.
132 *
133 * \param ctx Context to be cleaned up
134 */
135void mbedtls_ssl_ticket_free( mbedtls_ssl_ticket_context *ctx );
Manuel Pégourié-Gonnardfd6d8972015-05-15 12:09:00 +0200136
137#ifdef __cplusplus
138}
139#endif
140
141#endif /* ssl_ticket.h */