mbedtls ported to mbed-classic

Fork of mbedtls by Christopher Haster

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ssl_ticket.h Source File

ssl_ticket.h

Go to the documentation of this file.
00001 /**
00002  * \file ssl_ticket.h
00003  *
00004  * \brief TLS server ticket callbacks implementation
00005  *
00006  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
00007  *  SPDX-License-Identifier: Apache-2.0
00008  *
00009  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
00010  *  not use this file except in compliance with the License.
00011  *  You may obtain a copy of the License at
00012  *
00013  *  http://www.apache.org/licenses/LICENSE-2.0
00014  *
00015  *  Unless required by applicable law or agreed to in writing, software
00016  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00017  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00018  *  See the License for the specific language governing permissions and
00019  *  limitations under the License.
00020  *
00021  *  This file is part of mbed TLS (https://tls.mbed.org)
00022  */
00023 #ifndef MBEDTLS_SSL_TICKET_H
00024 #define MBEDTLS_SSL_TICKET_H
00025 
00026 /*
00027  * This implementation of the session ticket callbacks includes key
00028  * management, rotating the keys periodically in order to preserve forward
00029  * secrecy, when MBEDTLS_HAVE_TIME is defined.
00030  */
00031 
00032 #include "ssl.h"
00033 #include "cipher.h"
00034 
00035 #if defined(MBEDTLS_THREADING_C)
00036 #include "threading.h"
00037 #endif
00038 
00039 #ifdef __cplusplus
00040 extern "C" {
00041 #endif
00042 
00043 /**
00044  * \brief   Information for session ticket protection
00045  */
00046 typedef struct
00047 {
00048     unsigned char name[4];          /*!< random key identifier              */
00049     uint32_t generation_time ;       /*!< key generation timestamp (seconds) */
00050     mbedtls_cipher_context_t ctx ;   /*!< context for auth enc/decryption    */
00051 }
00052 mbedtls_ssl_ticket_key;
00053 
00054 /**
00055  * \brief   Context for session ticket handling functions
00056  */
00057 typedef struct
00058 {
00059     mbedtls_ssl_ticket_key keys[2]; /*!< ticket protection keys             */
00060     unsigned char active ;           /*!< index of the currently active key  */
00061 
00062     uint32_t ticket_lifetime ;       /*!< lifetime of tickets in seconds     */
00063 
00064     /** Callback for getting (pseudo-)random numbers                        */
00065     int  (*f_rng)(void *, unsigned char *, size_t);
00066     void *p_rng ;                    /*!< context for the RNG function       */
00067 
00068 #if defined(MBEDTLS_THREADING_C)
00069     mbedtls_threading_mutex_t mutex;
00070 #endif
00071 }
00072 mbedtls_ssl_ticket_context;
00073 
00074 /**
00075  * \brief           Initialize a ticket context.
00076  *                  (Just make it ready for mbedtls_ssl_ticket_setup()
00077  *                  or mbedtls_ssl_ticket_free().)
00078  *
00079  * \param ctx       Context to be initialized
00080  */
00081 void mbedtls_ssl_ticket_init( mbedtls_ssl_ticket_context *ctx );
00082 
00083 /**
00084  * \brief           Prepare context to be actually used
00085  *
00086  * \param ctx       Context to be set up
00087  * \param f_rng     RNG callback function
00088  * \param p_rng     RNG callback context
00089  * \param cipher    AEAD cipher to use for ticket protection.
00090  *                  Recommended value: MBEDTLS_CIPHER_AES_256_GCM.
00091  * \param lifetime  Tickets lifetime in seconds
00092  *                  Recommended value: 86400 (one day).
00093  *
00094  * \note            It is highly recommended to select a cipher that is at
00095  *                  least as strong as the the strongest ciphersuite
00096  *                  supported. Usually that means a 256-bit key.
00097  *
00098  * \note            The lifetime of the keys is twice the lifetime of tickets.
00099  *                  It is recommended to pick a reasonnable lifetime so as not
00100  *                  to negate the benefits of forward secrecy.
00101  *
00102  * \return          0 if successful,
00103  *                  or a specific MBEDTLS_ERR_XXX error code
00104  */
00105 int mbedtls_ssl_ticket_setup( mbedtls_ssl_ticket_context *ctx,
00106     int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
00107     mbedtls_cipher_type_t cipher,
00108     uint32_t lifetime );
00109 
00110 /**
00111  * \brief           Implementation of the ticket write callback
00112  *
00113  * \note            See \c mbedlts_ssl_ticket_write_t for description
00114  */
00115 mbedtls_ssl_ticket_write_t mbedtls_ssl_ticket_write;
00116 
00117 /**
00118  * \brief           Implementation of the ticket parse callback
00119  *
00120  * \note            See \c mbedlts_ssl_ticket_parse_t for description
00121  */
00122 mbedtls_ssl_ticket_parse_t mbedtls_ssl_ticket_parse;
00123 
00124 /**
00125  * \brief           Free a context's content and zeroize it.
00126  *
00127  * \param ctx       Context to be cleaned up
00128  */
00129 void mbedtls_ssl_ticket_free( mbedtls_ssl_ticket_context *ctx );
00130 
00131 #ifdef __cplusplus
00132 }
00133 #endif
00134 
00135 #endif /* ssl_ticket.h */