Mbed OS Reference
Loading...
Searching...
No Matches
ssl_ticket.h
Go to the documentation of this file.
1/**
2 * \file ssl_ticket.h
3 *
4 * \brief TLS server ticket callbacks implementation
5 */
6/*
7 * Copyright The Mbed TLS Contributors
8 * 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.
21 */
22#ifndef MBEDTLS_SSL_TICKET_H
23#define MBEDTLS_SSL_TICKET_H
24
25#if !defined(MBEDTLS_CONFIG_FILE)
26#include "mbedtls/config.h"
27#else
28#include MBEDTLS_CONFIG_FILE
29#endif
30
31/*
32 * This implementation of the session ticket callbacks includes key
33 * management, rotating the keys periodically in order to preserve forward
34 * secrecy, when MBEDTLS_HAVE_TIME is defined.
35 */
36
37#include "mbedtls/ssl.h"
38#include "mbedtls/cipher.h"
39
40#if defined(MBEDTLS_THREADING_C)
41#include "mbedtls/threading.h"
42#endif
43
44/**
45 * \ingroup mbedtls_ssl_module
46 * \{
47 */
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53/**
54 * \brief Information for session ticket protection
55 */
57{
58 unsigned char name[4]; /*!< random key identifier */
59 uint32_t generation_time; /*!< key generation timestamp (seconds) */
60 mbedtls_cipher_context_t ctx; /*!< context for auth enc/decryption */
61}
63
64/**
65 * \brief Context for session ticket handling functions
66 */
68{
69 mbedtls_ssl_ticket_key keys[2]; /*!< ticket protection keys */
70 unsigned char active; /*!< index of the currently active key */
71
72 uint32_t ticket_lifetime; /*!< lifetime of tickets in seconds */
73
74 /** Callback for getting (pseudo-)random numbers */
75 int (*f_rng)(void *, unsigned char *, size_t);
76 void *p_rng; /*!< context for the RNG function */
77
78#if defined(MBEDTLS_THREADING_C)
79 mbedtls_threading_mutex_t mutex;
80#endif
81}
83
84/**
85 * \brief Initialize a ticket context.
86 * (Just make it ready for mbedtls_ssl_ticket_setup()
87 * or mbedtls_ssl_ticket_free().)
88 *
89 * \param ctx Context to be initialized
90 */
92
93/**
94 * \brief Prepare context to be actually used
95 *
96 * \param ctx Context to be set up
97 * \param f_rng RNG callback function
98 * \param p_rng RNG callback context
99 * \param cipher AEAD cipher to use for ticket protection.
100 * Recommended value: MBEDTLS_CIPHER_AES_256_GCM.
101 * \param lifetime Tickets lifetime in seconds
102 * Recommended value: 86400 (one day).
103 *
104 * \note It is highly recommended to select a cipher that is at
105 * least as strong as the the strongest ciphersuite
106 * supported. Usually that means a 256-bit key.
107 *
108 * \note The lifetime of the keys is twice the lifetime of tickets.
109 * It is recommended to pick a reasonnable lifetime so as not
110 * to negate the benefits of forward secrecy.
111 *
112 * \return 0 if successful,
113 * or a specific MBEDTLS_ERR_XXX error code
114 */
116 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
118 uint32_t lifetime );
119
120/**
121 * \brief Implementation of the ticket write callback
122 *
123 * \note See \c mbedtls_ssl_ticket_write_t for description
124 */
126
127/**
128 * \brief Implementation of the ticket parse callback
129 *
130 * \note See \c mbedtls_ssl_ticket_parse_t for description
131 */
133
134/**
135 * \brief Free a context's content and zeroize it.
136 *
137 * \param ctx Context to be cleaned up
138 */
140
141#ifdef __cplusplus
142}
143#endif
144
145/// \}
146
147#endif /* ssl_ticket.h */
This file contains an abstraction interface for use with the cipher primitives provided by the librar...
Configuration options (set of defines)
mbedtls_cipher_type_t
Supported {cipher type, cipher mode} pairs.
Definition: cipher.h:109
void mbedtls_ssl_ticket_init(mbedtls_ssl_ticket_context *ctx)
Initialize a ticket context.
int mbedtls_ssl_ticket_write_t(void *p_ticket, const mbedtls_ssl_session *session, unsigned char *start, const unsigned char *end, size_t *tlen, uint32_t *lifetime)
Callback type: generate and write session ticket.
Definition: ssl.h:1965
void mbedtls_ssl_ticket_free(mbedtls_ssl_ticket_context *ctx)
Free a context's content and zeroize it.
int mbedtls_ssl_ticket_setup(mbedtls_ssl_ticket_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, mbedtls_cipher_type_t cipher, uint32_t lifetime)
Prepare context to be actually used.
int mbedtls_ssl_ticket_parse_t(void *p_ticket, mbedtls_ssl_session *session, unsigned char *buf, size_t len)
Callback type: parse and load session ticket.
Definition: ssl.h:2059
mbedtls_ssl_ticket_write_t mbedtls_ssl_ticket_write
Implementation of the ticket write callback.
Definition: ssl_ticket.h:125
mbedtls_ssl_ticket_parse_t mbedtls_ssl_ticket_parse
Implementation of the ticket parse callback.
Definition: ssl_ticket.h:132
SSL/TLS functions.
Generic cipher context.
Definition: cipher.h:318
Context for session ticket handling functions.
Definition: ssl_ticket.h:68
int(* f_rng)(void *, unsigned char *, size_t)
Callback for getting (pseudo-)random numbers
Definition: ssl_ticket.h:75
mbedtls_ssl_ticket_key keys[2]
Definition: ssl_ticket.h:69
Information for session ticket protection.
Definition: ssl_ticket.h:57
unsigned char name[4]
Definition: ssl_ticket.h:58
mbedtls_cipher_context_t ctx
Definition: ssl_ticket.h:60
uint32_t generation_time
Definition: ssl_ticket.h:59
Threading abstraction layer.