1c2c66affSColin Finck /** 2c2c66affSColin Finck * \file ssl.h 3c2c66affSColin Finck * 4c2c66affSColin Finck * \brief SSL/TLS functions. 5d9e6c9b5SThomas Faber */ 6d9e6c9b5SThomas Faber /* 7218e2596SThomas Faber * Copyright The Mbed TLS Contributors 8e57126f5SThomas Faber * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 9e57126f5SThomas Faber * 10e57126f5SThomas Faber * This file is provided under the Apache License 2.0, or the 11e57126f5SThomas Faber * GNU General Public License v2.0 or later. 12e57126f5SThomas Faber * 13e57126f5SThomas Faber * ********** 14e57126f5SThomas Faber * Apache License 2.0: 15e57126f5SThomas Faber * 16e57126f5SThomas Faber * Licensed under the Apache License, Version 2.0 (the "License"); you may 17e57126f5SThomas Faber * not use this file except in compliance with the License. 18e57126f5SThomas Faber * You may obtain a copy of the License at 19e57126f5SThomas Faber * 20e57126f5SThomas Faber * http://www.apache.org/licenses/LICENSE-2.0 21e57126f5SThomas Faber * 22e57126f5SThomas Faber * Unless required by applicable law or agreed to in writing, software 23e57126f5SThomas Faber * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 24e57126f5SThomas Faber * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25e57126f5SThomas Faber * See the License for the specific language governing permissions and 26e57126f5SThomas Faber * limitations under the License. 27e57126f5SThomas Faber * 28e57126f5SThomas Faber * ********** 29e57126f5SThomas Faber * 30e57126f5SThomas Faber * ********** 31e57126f5SThomas Faber * GNU General Public License v2.0 or later: 32c2c66affSColin Finck * 33c2c66affSColin Finck * This program is free software; you can redistribute it and/or modify 34c2c66affSColin Finck * it under the terms of the GNU General Public License as published by 35c2c66affSColin Finck * the Free Software Foundation; either version 2 of the License, or 36c2c66affSColin Finck * (at your option) any later version. 37c2c66affSColin Finck * 38c2c66affSColin Finck * This program is distributed in the hope that it will be useful, 39c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of 40c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 41c2c66affSColin Finck * GNU General Public License for more details. 42c2c66affSColin Finck * 43c2c66affSColin Finck * You should have received a copy of the GNU General Public License along 44c2c66affSColin Finck * with this program; if not, write to the Free Software Foundation, Inc., 45c2c66affSColin Finck * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 46c2c66affSColin Finck * 47e57126f5SThomas Faber * ********** 48c2c66affSColin Finck */ 49c2c66affSColin Finck #ifndef MBEDTLS_SSL_H 50c2c66affSColin Finck #define MBEDTLS_SSL_H 51c2c66affSColin Finck 52c2c66affSColin Finck #if !defined(MBEDTLS_CONFIG_FILE) 53c2c66affSColin Finck #include "config.h" 54c2c66affSColin Finck #else 55c2c66affSColin Finck #include MBEDTLS_CONFIG_FILE 56c2c66affSColin Finck #endif 57c2c66affSColin Finck 58c2c66affSColin Finck #include "bignum.h" 59c2c66affSColin Finck #include "ecp.h" 60c2c66affSColin Finck 61c2c66affSColin Finck #include "ssl_ciphersuites.h" 62c2c66affSColin Finck 63c2c66affSColin Finck #if defined(MBEDTLS_X509_CRT_PARSE_C) 64c2c66affSColin Finck #include "x509_crt.h" 65c2c66affSColin Finck #include "x509_crl.h" 66c2c66affSColin Finck #endif 67c2c66affSColin Finck 68c2c66affSColin Finck #if defined(MBEDTLS_DHM_C) 69c2c66affSColin Finck #include "dhm.h" 70c2c66affSColin Finck #endif 71c2c66affSColin Finck 72c2c66affSColin Finck #if defined(MBEDTLS_ECDH_C) 73c2c66affSColin Finck #include "ecdh.h" 74c2c66affSColin Finck #endif 75c2c66affSColin Finck 76c2c66affSColin Finck #if defined(MBEDTLS_ZLIB_SUPPORT) 77cbda039fSThomas Faber 78cbda039fSThomas Faber #if defined(MBEDTLS_DEPRECATED_WARNING) 79cbda039fSThomas Faber #warning "Record compression support via MBEDTLS_ZLIB_SUPPORT is deprecated and will be removed in the next major revision of the library" 80cbda039fSThomas Faber #endif 81cbda039fSThomas Faber 82cbda039fSThomas Faber #if defined(MBEDTLS_DEPRECATED_REMOVED) 83cbda039fSThomas Faber #error "Record compression support via MBEDTLS_ZLIB_SUPPORT is deprecated and cannot be used if MBEDTLS_DEPRECATED_REMOVED is set" 84cbda039fSThomas Faber #endif 85cbda039fSThomas Faber 86c2c66affSColin Finck #include "zlib.h" 87c2c66affSColin Finck #endif 88c2c66affSColin Finck 89c2c66affSColin Finck #if defined(MBEDTLS_HAVE_TIME) 90d9e6c9b5SThomas Faber #include "platform_time.h" 91c2c66affSColin Finck #endif 92c2c66affSColin Finck 93c2c66affSColin Finck /* 94c2c66affSColin Finck * SSL Error codes 95c2c66affSColin Finck */ 96c2c66affSColin Finck #define MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE -0x7080 /**< The requested feature is not available. */ 97c2c66affSColin Finck #define MBEDTLS_ERR_SSL_BAD_INPUT_DATA -0x7100 /**< Bad input parameters to function. */ 98c2c66affSColin Finck #define MBEDTLS_ERR_SSL_INVALID_MAC -0x7180 /**< Verification of the message MAC failed. */ 99c2c66affSColin Finck #define MBEDTLS_ERR_SSL_INVALID_RECORD -0x7200 /**< An invalid SSL record was received. */ 100c2c66affSColin Finck #define MBEDTLS_ERR_SSL_CONN_EOF -0x7280 /**< The connection indicated an EOF. */ 101c2c66affSColin Finck #define MBEDTLS_ERR_SSL_UNKNOWN_CIPHER -0x7300 /**< An unknown cipher was received. */ 102c2c66affSColin Finck #define MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN -0x7380 /**< The server has no ciphersuites in common with the client. */ 103c2c66affSColin Finck #define MBEDTLS_ERR_SSL_NO_RNG -0x7400 /**< No RNG was provided to the SSL module. */ 104c2c66affSColin Finck #define MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480 /**< No client certification received from the client, but required by the authentication mode. */ 105c2c66affSColin Finck #define MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500 /**< Our own certificate(s) is/are too large to send in an SSL message. */ 106c2c66affSColin Finck #define MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED -0x7580 /**< The own certificate is not set, but needed by the server. */ 107c2c66affSColin Finck #define MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600 /**< The own private key or pre-shared key is not set, but needed. */ 108c2c66affSColin Finck #define MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED -0x7680 /**< No CA Chain is set, but required to operate. */ 109c2c66affSColin Finck #define MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE -0x7700 /**< An unexpected message was received from our peer. */ 110c2c66affSColin Finck #define MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780 /**< A fatal alert message was received from our peer. */ 111c2c66affSColin Finck #define MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED -0x7800 /**< Verification of our peer failed. */ 112c2c66affSColin Finck #define MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880 /**< The peer notified us that the connection is going to be closed. */ 113c2c66affSColin Finck #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO -0x7900 /**< Processing of the ClientHello handshake message failed. */ 114c2c66affSColin Finck #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO -0x7980 /**< Processing of the ServerHello handshake message failed. */ 115c2c66affSColin Finck #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE -0x7A00 /**< Processing of the Certificate handshake message failed. */ 116c2c66affSColin Finck #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST -0x7A80 /**< Processing of the CertificateRequest handshake message failed. */ 117c2c66affSColin Finck #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE -0x7B00 /**< Processing of the ServerKeyExchange handshake message failed. */ 118c2c66affSColin Finck #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE -0x7B80 /**< Processing of the ServerHelloDone handshake message failed. */ 119c2c66affSColin Finck #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE -0x7C00 /**< Processing of the ClientKeyExchange handshake message failed. */ 120c2c66affSColin Finck #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP -0x7C80 /**< Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public. */ 121c2c66affSColin Finck #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS -0x7D00 /**< Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret. */ 122c2c66affSColin Finck #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY -0x7D80 /**< Processing of the CertificateVerify handshake message failed. */ 123c2c66affSColin Finck #define MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC -0x7E00 /**< Processing of the ChangeCipherSpec handshake message failed. */ 124c2c66affSColin Finck #define MBEDTLS_ERR_SSL_BAD_HS_FINISHED -0x7E80 /**< Processing of the Finished handshake message failed. */ 125c2c66affSColin Finck #define MBEDTLS_ERR_SSL_ALLOC_FAILED -0x7F00 /**< Memory allocation failed */ 126c2c66affSColin Finck #define MBEDTLS_ERR_SSL_HW_ACCEL_FAILED -0x7F80 /**< Hardware acceleration function returned with error */ 127c2c66affSColin Finck #define MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80 /**< Hardware acceleration function skipped / left alone data */ 128c2c66affSColin Finck #define MBEDTLS_ERR_SSL_COMPRESSION_FAILED -0x6F00 /**< Processing of the compression / decompression failed */ 129c2c66affSColin Finck #define MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION -0x6E80 /**< Handshake protocol not within min/max boundaries */ 130c2c66affSColin Finck #define MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET -0x6E00 /**< Processing of the NewSessionTicket handshake message failed. */ 131c2c66affSColin Finck #define MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED -0x6D80 /**< Session ticket has expired. */ 132c2c66affSColin Finck #define MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH -0x6D00 /**< Public key type mismatch (eg, asked for RSA key exchange and presented EC key) */ 133c2c66affSColin Finck #define MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY -0x6C80 /**< Unknown identity received (eg, PSK identity) */ 134c2c66affSColin Finck #define MBEDTLS_ERR_SSL_INTERNAL_ERROR -0x6C00 /**< Internal error (eg, unexpected failure in lower-level module) */ 135c2c66affSColin Finck #define MBEDTLS_ERR_SSL_COUNTER_WRAPPING -0x6B80 /**< A counter would wrap (eg, too many messages exchanged). */ 136c2c66affSColin Finck #define MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO -0x6B00 /**< Unexpected message at ServerHello in renegotiation. */ 137c2c66affSColin Finck #define MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED -0x6A80 /**< DTLS client must retry for hello verification */ 138c2c66affSColin Finck #define MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL -0x6A00 /**< A buffer is too small to receive or write a message */ 139c2c66affSColin Finck #define MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE -0x6980 /**< None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages). */ 140cbda039fSThomas Faber #define MBEDTLS_ERR_SSL_WANT_READ -0x6900 /**< No data of requested type currently available on underlying transport. */ 141c2c66affSColin Finck #define MBEDTLS_ERR_SSL_WANT_WRITE -0x6880 /**< Connection requires a write call. */ 142c2c66affSColin Finck #define MBEDTLS_ERR_SSL_TIMEOUT -0x6800 /**< The operation timed out. */ 143c2c66affSColin Finck #define MBEDTLS_ERR_SSL_CLIENT_RECONNECT -0x6780 /**< The client initiated a reconnect from the same port. */ 144c2c66affSColin Finck #define MBEDTLS_ERR_SSL_UNEXPECTED_RECORD -0x6700 /**< Record header looks valid but is not expected. */ 145c2c66affSColin Finck #define MBEDTLS_ERR_SSL_NON_FATAL -0x6680 /**< The alert message received indicates a non-fatal error. */ 146c2c66affSColin Finck #define MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH -0x6600 /**< Couldn't set the hash for verifying CertificateVerify */ 147cbda039fSThomas Faber #define MBEDTLS_ERR_SSL_CONTINUE_PROCESSING -0x6580 /**< Internal-only message signaling that further message-processing should be done */ 148cbda039fSThomas Faber #define MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS -0x6500 /**< The asynchronous operation is not completed yet. */ 149cbda039fSThomas Faber #define MBEDTLS_ERR_SSL_EARLY_MESSAGE -0x6480 /**< Internal-only message signaling that a message arrived early. */ 150cbda039fSThomas Faber #define MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS -0x7000 /**< A cryptographic operation is in progress. Try again later. */ 151292f67afSThomas Faber #define MBEDTLS_ERR_SSL_BAD_CONFIG -0x5E80 /**< Invalid value in SSL config */ 152c2c66affSColin Finck 153c2c66affSColin Finck /* 154c2c66affSColin Finck * Various constants 155c2c66affSColin Finck */ 156c2c66affSColin Finck #define MBEDTLS_SSL_MAJOR_VERSION_3 3 157c2c66affSColin Finck #define MBEDTLS_SSL_MINOR_VERSION_0 0 /*!< SSL v3.0 */ 158c2c66affSColin Finck #define MBEDTLS_SSL_MINOR_VERSION_1 1 /*!< TLS v1.0 */ 159c2c66affSColin Finck #define MBEDTLS_SSL_MINOR_VERSION_2 2 /*!< TLS v1.1 */ 160c2c66affSColin Finck #define MBEDTLS_SSL_MINOR_VERSION_3 3 /*!< TLS v1.2 */ 161c2c66affSColin Finck 162c2c66affSColin Finck #define MBEDTLS_SSL_TRANSPORT_STREAM 0 /*!< TLS */ 163c2c66affSColin Finck #define MBEDTLS_SSL_TRANSPORT_DATAGRAM 1 /*!< DTLS */ 164c2c66affSColin Finck 165c2c66affSColin Finck #define MBEDTLS_SSL_MAX_HOST_NAME_LEN 255 /*!< Maximum host name defined in RFC 1035 */ 166292f67afSThomas Faber #define MBEDTLS_SSL_MAX_ALPN_NAME_LEN 255 /*!< Maximum size in bytes of a protocol name in alpn ext., RFC 7301 */ 167292f67afSThomas Faber 168292f67afSThomas Faber #define MBEDTLS_SSL_MAX_ALPN_LIST_LEN 65535 /*!< Maximum size in bytes of list in alpn ext., RFC 7301 */ 169c2c66affSColin Finck 170c2c66affSColin Finck /* RFC 6066 section 4, see also mfl_code_to_length in ssl_tls.c 171c2c66affSColin Finck * NONE must be zero so that memset()ing structure to zero works */ 172c2c66affSColin Finck #define MBEDTLS_SSL_MAX_FRAG_LEN_NONE 0 /*!< don't use this extension */ 173c2c66affSColin Finck #define MBEDTLS_SSL_MAX_FRAG_LEN_512 1 /*!< MaxFragmentLength 2^9 */ 174c2c66affSColin Finck #define MBEDTLS_SSL_MAX_FRAG_LEN_1024 2 /*!< MaxFragmentLength 2^10 */ 175c2c66affSColin Finck #define MBEDTLS_SSL_MAX_FRAG_LEN_2048 3 /*!< MaxFragmentLength 2^11 */ 176c2c66affSColin Finck #define MBEDTLS_SSL_MAX_FRAG_LEN_4096 4 /*!< MaxFragmentLength 2^12 */ 177c2c66affSColin Finck #define MBEDTLS_SSL_MAX_FRAG_LEN_INVALID 5 /*!< first invalid value */ 178c2c66affSColin Finck 179c2c66affSColin Finck #define MBEDTLS_SSL_IS_CLIENT 0 180c2c66affSColin Finck #define MBEDTLS_SSL_IS_SERVER 1 181c2c66affSColin Finck 182c2c66affSColin Finck #define MBEDTLS_SSL_IS_NOT_FALLBACK 0 183c2c66affSColin Finck #define MBEDTLS_SSL_IS_FALLBACK 1 184c2c66affSColin Finck 185c2c66affSColin Finck #define MBEDTLS_SSL_EXTENDED_MS_DISABLED 0 186c2c66affSColin Finck #define MBEDTLS_SSL_EXTENDED_MS_ENABLED 1 187c2c66affSColin Finck 188c2c66affSColin Finck #define MBEDTLS_SSL_ETM_DISABLED 0 189c2c66affSColin Finck #define MBEDTLS_SSL_ETM_ENABLED 1 190c2c66affSColin Finck 191c2c66affSColin Finck #define MBEDTLS_SSL_COMPRESS_NULL 0 192c2c66affSColin Finck #define MBEDTLS_SSL_COMPRESS_DEFLATE 1 193c2c66affSColin Finck 194c2c66affSColin Finck #define MBEDTLS_SSL_VERIFY_NONE 0 195c2c66affSColin Finck #define MBEDTLS_SSL_VERIFY_OPTIONAL 1 196c2c66affSColin Finck #define MBEDTLS_SSL_VERIFY_REQUIRED 2 197c2c66affSColin Finck #define MBEDTLS_SSL_VERIFY_UNSET 3 /* Used only for sni_authmode */ 198c2c66affSColin Finck 199c2c66affSColin Finck #define MBEDTLS_SSL_LEGACY_RENEGOTIATION 0 200c2c66affSColin Finck #define MBEDTLS_SSL_SECURE_RENEGOTIATION 1 201c2c66affSColin Finck 202c2c66affSColin Finck #define MBEDTLS_SSL_RENEGOTIATION_DISABLED 0 203c2c66affSColin Finck #define MBEDTLS_SSL_RENEGOTIATION_ENABLED 1 204c2c66affSColin Finck 205c2c66affSColin Finck #define MBEDTLS_SSL_ANTI_REPLAY_DISABLED 0 206c2c66affSColin Finck #define MBEDTLS_SSL_ANTI_REPLAY_ENABLED 1 207c2c66affSColin Finck 208c2c66affSColin Finck #define MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED -1 209c2c66affSColin Finck #define MBEDTLS_SSL_RENEGO_MAX_RECORDS_DEFAULT 16 210c2c66affSColin Finck 211c2c66affSColin Finck #define MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION 0 212c2c66affSColin Finck #define MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION 1 213c2c66affSColin Finck #define MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE 2 214c2c66affSColin Finck 215c2c66affSColin Finck #define MBEDTLS_SSL_TRUNC_HMAC_DISABLED 0 216c2c66affSColin Finck #define MBEDTLS_SSL_TRUNC_HMAC_ENABLED 1 217c2c66affSColin Finck #define MBEDTLS_SSL_TRUNCATED_HMAC_LEN 10 /* 80 bits, rfc 6066 section 7 */ 218c2c66affSColin Finck 219c2c66affSColin Finck #define MBEDTLS_SSL_SESSION_TICKETS_DISABLED 0 220c2c66affSColin Finck #define MBEDTLS_SSL_SESSION_TICKETS_ENABLED 1 221c2c66affSColin Finck 222c2c66affSColin Finck #define MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED 0 223c2c66affSColin Finck #define MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED 1 224c2c66affSColin Finck 225c2c66affSColin Finck #define MBEDTLS_SSL_ARC4_ENABLED 0 226c2c66affSColin Finck #define MBEDTLS_SSL_ARC4_DISABLED 1 227c2c66affSColin Finck 228c2c66affSColin Finck #define MBEDTLS_SSL_PRESET_DEFAULT 0 229c2c66affSColin Finck #define MBEDTLS_SSL_PRESET_SUITEB 2 230c2c66affSColin Finck 231c2c66affSColin Finck #define MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED 1 232c2c66affSColin Finck #define MBEDTLS_SSL_CERT_REQ_CA_LIST_DISABLED 0 233c2c66affSColin Finck 234c2c66affSColin Finck /* 235c2c66affSColin Finck * Default range for DTLS retransmission timer value, in milliseconds. 236c2c66affSColin Finck * RFC 6347 4.2.4.1 says from 1 second to 60 seconds. 237c2c66affSColin Finck */ 238c2c66affSColin Finck #define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MIN 1000 239c2c66affSColin Finck #define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MAX 60000 240c2c66affSColin Finck 241c2c66affSColin Finck /** 242c2c66affSColin Finck * \name SECTION: Module settings 243c2c66affSColin Finck * 244c2c66affSColin Finck * The configuration options you can set for this module are in this section. 245c2c66affSColin Finck * Either change them in config.h or define them on the compiler command line. 246c2c66affSColin Finck * \{ 247c2c66affSColin Finck */ 248c2c66affSColin Finck 249c2c66affSColin Finck #if !defined(MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME) 250c2c66affSColin Finck #define MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME 86400 /**< Lifetime of session tickets (if enabled) */ 251c2c66affSColin Finck #endif 252c2c66affSColin Finck 253c2c66affSColin Finck /* 254cbda039fSThomas Faber * Maximum fragment length in bytes, 255c2c66affSColin Finck * determines the size of each of the two internal I/O buffers. 256c2c66affSColin Finck * 257c2c66affSColin Finck * Note: the RFC defines the default size of SSL / TLS messages. If you 258c2c66affSColin Finck * change the value here, other clients / servers may not be able to 259c2c66affSColin Finck * communicate with you anymore. Only change this value if you control 260c2c66affSColin Finck * both sides of the connection and have it reduced at both sides, or 261c2c66affSColin Finck * if you're using the Max Fragment Length extension and you know all your 262c2c66affSColin Finck * peers are using it too! 263c2c66affSColin Finck */ 264c2c66affSColin Finck #if !defined(MBEDTLS_SSL_MAX_CONTENT_LEN) 265c2c66affSColin Finck #define MBEDTLS_SSL_MAX_CONTENT_LEN 16384 /**< Size of the input / output buffer */ 266c2c66affSColin Finck #endif 267c2c66affSColin Finck 268cbda039fSThomas Faber #if !defined(MBEDTLS_SSL_IN_CONTENT_LEN) 269cbda039fSThomas Faber #define MBEDTLS_SSL_IN_CONTENT_LEN MBEDTLS_SSL_MAX_CONTENT_LEN 270cbda039fSThomas Faber #endif 271cbda039fSThomas Faber 272cbda039fSThomas Faber #if !defined(MBEDTLS_SSL_OUT_CONTENT_LEN) 273cbda039fSThomas Faber #define MBEDTLS_SSL_OUT_CONTENT_LEN MBEDTLS_SSL_MAX_CONTENT_LEN 274cbda039fSThomas Faber #endif 275cbda039fSThomas Faber 276cbda039fSThomas Faber /* 277cbda039fSThomas Faber * Maximum number of heap-allocated bytes for the purpose of 278cbda039fSThomas Faber * DTLS handshake message reassembly and future message buffering. 279cbda039fSThomas Faber */ 280cbda039fSThomas Faber #if !defined(MBEDTLS_SSL_DTLS_MAX_BUFFERING) 281cbda039fSThomas Faber #define MBEDTLS_SSL_DTLS_MAX_BUFFERING 32768 282cbda039fSThomas Faber #endif 283cbda039fSThomas Faber 284c2c66affSColin Finck /* \} name SECTION: Module settings */ 285c2c66affSColin Finck 286c2c66affSColin Finck /* 287c2c66affSColin Finck * Length of the verify data for secure renegotiation 288c2c66affSColin Finck */ 289c2c66affSColin Finck #if defined(MBEDTLS_SSL_PROTO_SSL3) 290c2c66affSColin Finck #define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 36 291c2c66affSColin Finck #else 292c2c66affSColin Finck #define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 12 293c2c66affSColin Finck #endif 294c2c66affSColin Finck 295c2c66affSColin Finck /* 296c2c66affSColin Finck * Signaling ciphersuite values (SCSV) 297c2c66affSColin Finck */ 298c2c66affSColin Finck #define MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO 0xFF /**< renegotiation info ext */ 299c2c66affSColin Finck #define MBEDTLS_SSL_FALLBACK_SCSV_VALUE 0x5600 /**< RFC 7507 section 2 */ 300c2c66affSColin Finck 301c2c66affSColin Finck /* 302c2c66affSColin Finck * Supported Signature and Hash algorithms (For TLS 1.2) 303c2c66affSColin Finck * RFC 5246 section 7.4.1.4.1 304c2c66affSColin Finck */ 305c2c66affSColin Finck #define MBEDTLS_SSL_HASH_NONE 0 306c2c66affSColin Finck #define MBEDTLS_SSL_HASH_MD5 1 307c2c66affSColin Finck #define MBEDTLS_SSL_HASH_SHA1 2 308c2c66affSColin Finck #define MBEDTLS_SSL_HASH_SHA224 3 309c2c66affSColin Finck #define MBEDTLS_SSL_HASH_SHA256 4 310c2c66affSColin Finck #define MBEDTLS_SSL_HASH_SHA384 5 311c2c66affSColin Finck #define MBEDTLS_SSL_HASH_SHA512 6 312c2c66affSColin Finck 313c2c66affSColin Finck #define MBEDTLS_SSL_SIG_ANON 0 314c2c66affSColin Finck #define MBEDTLS_SSL_SIG_RSA 1 315c2c66affSColin Finck #define MBEDTLS_SSL_SIG_ECDSA 3 316c2c66affSColin Finck 317c2c66affSColin Finck /* 318c2c66affSColin Finck * Client Certificate Types 319c2c66affSColin Finck * RFC 5246 section 7.4.4 plus RFC 4492 section 5.5 320c2c66affSColin Finck */ 321c2c66affSColin Finck #define MBEDTLS_SSL_CERT_TYPE_RSA_SIGN 1 322c2c66affSColin Finck #define MBEDTLS_SSL_CERT_TYPE_ECDSA_SIGN 64 323c2c66affSColin Finck 324c2c66affSColin Finck /* 325c2c66affSColin Finck * Message, alert and handshake types 326c2c66affSColin Finck */ 327c2c66affSColin Finck #define MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC 20 328c2c66affSColin Finck #define MBEDTLS_SSL_MSG_ALERT 21 329c2c66affSColin Finck #define MBEDTLS_SSL_MSG_HANDSHAKE 22 330c2c66affSColin Finck #define MBEDTLS_SSL_MSG_APPLICATION_DATA 23 331c2c66affSColin Finck 332c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_LEVEL_WARNING 1 333c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_LEVEL_FATAL 2 334c2c66affSColin Finck 335c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY 0 /* 0x00 */ 336c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE 10 /* 0x0A */ 337c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC 20 /* 0x14 */ 338c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_DECRYPTION_FAILED 21 /* 0x15 */ 339c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_RECORD_OVERFLOW 22 /* 0x16 */ 340c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_DECOMPRESSION_FAILURE 30 /* 0x1E */ 341c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE 40 /* 0x28 */ 342c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_NO_CERT 41 /* 0x29 */ 343c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_BAD_CERT 42 /* 0x2A */ 344c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT 43 /* 0x2B */ 345c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_CERT_REVOKED 44 /* 0x2C */ 346c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_CERT_EXPIRED 45 /* 0x2D */ 347c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_CERT_UNKNOWN 46 /* 0x2E */ 348c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER 47 /* 0x2F */ 349c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_CA 48 /* 0x30 */ 350c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_ACCESS_DENIED 49 /* 0x31 */ 351c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR 50 /* 0x32 */ 352c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_DECRYPT_ERROR 51 /* 0x33 */ 353c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_EXPORT_RESTRICTION 60 /* 0x3C */ 354c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION 70 /* 0x46 */ 355c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_INSUFFICIENT_SECURITY 71 /* 0x47 */ 356c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR 80 /* 0x50 */ 357c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK 86 /* 0x56 */ 358c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_USER_CANCELED 90 /* 0x5A */ 359c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION 100 /* 0x64 */ 360c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT 110 /* 0x6E */ 361c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_UNRECOGNIZED_NAME 112 /* 0x70 */ 362c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY 115 /* 0x73 */ 363c2c66affSColin Finck #define MBEDTLS_SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL 120 /* 0x78 */ 364c2c66affSColin Finck 365c2c66affSColin Finck #define MBEDTLS_SSL_HS_HELLO_REQUEST 0 366c2c66affSColin Finck #define MBEDTLS_SSL_HS_CLIENT_HELLO 1 367c2c66affSColin Finck #define MBEDTLS_SSL_HS_SERVER_HELLO 2 368c2c66affSColin Finck #define MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST 3 369c2c66affSColin Finck #define MBEDTLS_SSL_HS_NEW_SESSION_TICKET 4 370c2c66affSColin Finck #define MBEDTLS_SSL_HS_CERTIFICATE 11 371c2c66affSColin Finck #define MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE 12 372c2c66affSColin Finck #define MBEDTLS_SSL_HS_CERTIFICATE_REQUEST 13 373c2c66affSColin Finck #define MBEDTLS_SSL_HS_SERVER_HELLO_DONE 14 374c2c66affSColin Finck #define MBEDTLS_SSL_HS_CERTIFICATE_VERIFY 15 375c2c66affSColin Finck #define MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE 16 376c2c66affSColin Finck #define MBEDTLS_SSL_HS_FINISHED 20 377c2c66affSColin Finck 378c2c66affSColin Finck /* 379c2c66affSColin Finck * TLS extensions 380c2c66affSColin Finck */ 381c2c66affSColin Finck #define MBEDTLS_TLS_EXT_SERVERNAME 0 382c2c66affSColin Finck #define MBEDTLS_TLS_EXT_SERVERNAME_HOSTNAME 0 383c2c66affSColin Finck 384c2c66affSColin Finck #define MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH 1 385c2c66affSColin Finck 386c2c66affSColin Finck #define MBEDTLS_TLS_EXT_TRUNCATED_HMAC 4 387c2c66affSColin Finck 388c2c66affSColin Finck #define MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES 10 389c2c66affSColin Finck #define MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS 11 390c2c66affSColin Finck 391c2c66affSColin Finck #define MBEDTLS_TLS_EXT_SIG_ALG 13 392c2c66affSColin Finck 393c2c66affSColin Finck #define MBEDTLS_TLS_EXT_ALPN 16 394c2c66affSColin Finck 395c2c66affSColin Finck #define MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC 22 /* 0x16 */ 396c2c66affSColin Finck #define MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET 0x0017 /* 23 */ 397c2c66affSColin Finck 398c2c66affSColin Finck #define MBEDTLS_TLS_EXT_SESSION_TICKET 35 399c2c66affSColin Finck 400c2c66affSColin Finck #define MBEDTLS_TLS_EXT_ECJPAKE_KKPP 256 /* experimental */ 401c2c66affSColin Finck 402c2c66affSColin Finck #define MBEDTLS_TLS_EXT_RENEGOTIATION_INFO 0xFF01 403c2c66affSColin Finck 404c2c66affSColin Finck /* 405c2c66affSColin Finck * Size defines 406c2c66affSColin Finck */ 407c2c66affSColin Finck #if !defined(MBEDTLS_PSK_MAX_LEN) 408c2c66affSColin Finck #define MBEDTLS_PSK_MAX_LEN 32 /* 256 bits */ 409c2c66affSColin Finck #endif 410c2c66affSColin Finck 411c2c66affSColin Finck /* Dummy type used only for its size */ 412c2c66affSColin Finck union mbedtls_ssl_premaster_secret 413c2c66affSColin Finck { 414c2c66affSColin Finck #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) 415c2c66affSColin Finck unsigned char _pms_rsa[48]; /* RFC 5246 8.1.1 */ 416c2c66affSColin Finck #endif 417c2c66affSColin Finck #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) 418c2c66affSColin Finck unsigned char _pms_dhm[MBEDTLS_MPI_MAX_SIZE]; /* RFC 5246 8.1.2 */ 419c2c66affSColin Finck #endif 420c2c66affSColin Finck #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \ 421c2c66affSColin Finck defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \ 422c2c66affSColin Finck defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \ 423c2c66affSColin Finck defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) 424c2c66affSColin Finck unsigned char _pms_ecdh[MBEDTLS_ECP_MAX_BYTES]; /* RFC 4492 5.10 */ 425c2c66affSColin Finck #endif 426c2c66affSColin Finck #if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) 427c2c66affSColin Finck unsigned char _pms_psk[4 + 2 * MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 2 */ 428c2c66affSColin Finck #endif 429c2c66affSColin Finck #if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) 430c2c66affSColin Finck unsigned char _pms_dhe_psk[4 + MBEDTLS_MPI_MAX_SIZE 431c2c66affSColin Finck + MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 3 */ 432c2c66affSColin Finck #endif 433c2c66affSColin Finck #if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) 434c2c66affSColin Finck unsigned char _pms_rsa_psk[52 + MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 4 */ 435c2c66affSColin Finck #endif 436c2c66affSColin Finck #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) 437c2c66affSColin Finck unsigned char _pms_ecdhe_psk[4 + MBEDTLS_ECP_MAX_BYTES 438c2c66affSColin Finck + MBEDTLS_PSK_MAX_LEN]; /* RFC 5489 2 */ 439c2c66affSColin Finck #endif 440c2c66affSColin Finck #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) 441c2c66affSColin Finck unsigned char _pms_ecjpake[32]; /* Thread spec: SHA-256 output */ 442c2c66affSColin Finck #endif 443c2c66affSColin Finck }; 444c2c66affSColin Finck 445c2c66affSColin Finck #define MBEDTLS_PREMASTER_SIZE sizeof( union mbedtls_ssl_premaster_secret ) 446c2c66affSColin Finck 447c2c66affSColin Finck #ifdef __cplusplus 448c2c66affSColin Finck extern "C" { 449c2c66affSColin Finck #endif 450c2c66affSColin Finck 451c2c66affSColin Finck /* 452c2c66affSColin Finck * SSL state machine 453c2c66affSColin Finck */ 454c2c66affSColin Finck typedef enum 455c2c66affSColin Finck { 456c2c66affSColin Finck MBEDTLS_SSL_HELLO_REQUEST, 457c2c66affSColin Finck MBEDTLS_SSL_CLIENT_HELLO, 458c2c66affSColin Finck MBEDTLS_SSL_SERVER_HELLO, 459c2c66affSColin Finck MBEDTLS_SSL_SERVER_CERTIFICATE, 460c2c66affSColin Finck MBEDTLS_SSL_SERVER_KEY_EXCHANGE, 461c2c66affSColin Finck MBEDTLS_SSL_CERTIFICATE_REQUEST, 462c2c66affSColin Finck MBEDTLS_SSL_SERVER_HELLO_DONE, 463c2c66affSColin Finck MBEDTLS_SSL_CLIENT_CERTIFICATE, 464c2c66affSColin Finck MBEDTLS_SSL_CLIENT_KEY_EXCHANGE, 465c2c66affSColin Finck MBEDTLS_SSL_CERTIFICATE_VERIFY, 466c2c66affSColin Finck MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC, 467c2c66affSColin Finck MBEDTLS_SSL_CLIENT_FINISHED, 468c2c66affSColin Finck MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC, 469c2c66affSColin Finck MBEDTLS_SSL_SERVER_FINISHED, 470c2c66affSColin Finck MBEDTLS_SSL_FLUSH_BUFFERS, 471c2c66affSColin Finck MBEDTLS_SSL_HANDSHAKE_WRAPUP, 472c2c66affSColin Finck MBEDTLS_SSL_HANDSHAKE_OVER, 473c2c66affSColin Finck MBEDTLS_SSL_SERVER_NEW_SESSION_TICKET, 474c2c66affSColin Finck MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT, 475c2c66affSColin Finck } 476c2c66affSColin Finck mbedtls_ssl_states; 477c2c66affSColin Finck 478c2c66affSColin Finck /** 479c2c66affSColin Finck * \brief Callback type: send data on the network. 480c2c66affSColin Finck * 481c2c66affSColin Finck * \note That callback may be either blocking or non-blocking. 482c2c66affSColin Finck * 483c2c66affSColin Finck * \param ctx Context for the send callback (typically a file descriptor) 484c2c66affSColin Finck * \param buf Buffer holding the data to send 485c2c66affSColin Finck * \param len Length of the data to send 486c2c66affSColin Finck * 487c2c66affSColin Finck * \return The callback must return the number of bytes sent if any, 488c2c66affSColin Finck * or a non-zero error code. 489c2c66affSColin Finck * If performing non-blocking I/O, \c MBEDTLS_ERR_SSL_WANT_WRITE 490c2c66affSColin Finck * must be returned when the operation would block. 491c2c66affSColin Finck * 492c2c66affSColin Finck * \note The callback is allowed to send fewer bytes than requested. 493c2c66affSColin Finck * It must always return the number of bytes actually sent. 494c2c66affSColin Finck */ 495c2c66affSColin Finck typedef int mbedtls_ssl_send_t( void *ctx, 496c2c66affSColin Finck const unsigned char *buf, 497c2c66affSColin Finck size_t len ); 498c2c66affSColin Finck 499c2c66affSColin Finck /** 500c2c66affSColin Finck * \brief Callback type: receive data from the network. 501c2c66affSColin Finck * 502c2c66affSColin Finck * \note That callback may be either blocking or non-blocking. 503c2c66affSColin Finck * 504c2c66affSColin Finck * \param ctx Context for the receive callback (typically a file 505c2c66affSColin Finck * descriptor) 506c2c66affSColin Finck * \param buf Buffer to write the received data to 507c2c66affSColin Finck * \param len Length of the receive buffer 508c2c66affSColin Finck * 509c2c66affSColin Finck * \return The callback must return the number of bytes received, 510c2c66affSColin Finck * or a non-zero error code. 511c2c66affSColin Finck * If performing non-blocking I/O, \c MBEDTLS_ERR_SSL_WANT_READ 512c2c66affSColin Finck * must be returned when the operation would block. 513c2c66affSColin Finck * 514c2c66affSColin Finck * \note The callback may receive fewer bytes than the length of the 515c2c66affSColin Finck * buffer. It must always return the number of bytes actually 516c2c66affSColin Finck * received and written to the buffer. 517c2c66affSColin Finck */ 518c2c66affSColin Finck typedef int mbedtls_ssl_recv_t( void *ctx, 519c2c66affSColin Finck unsigned char *buf, 520c2c66affSColin Finck size_t len ); 521c2c66affSColin Finck 522c2c66affSColin Finck /** 523c2c66affSColin Finck * \brief Callback type: receive data from the network, with timeout 524c2c66affSColin Finck * 525c2c66affSColin Finck * \note That callback must block until data is received, or the 526c2c66affSColin Finck * timeout delay expires, or the operation is interrupted by a 527c2c66affSColin Finck * signal. 528c2c66affSColin Finck * 529c2c66affSColin Finck * \param ctx Context for the receive callback (typically a file descriptor) 530c2c66affSColin Finck * \param buf Buffer to write the received data to 531c2c66affSColin Finck * \param len Length of the receive buffer 532c2c66affSColin Finck * \param timeout Maximum nomber of millisecondes to wait for data 533c2c66affSColin Finck * 0 means no timeout (potentially waiting forever) 534c2c66affSColin Finck * 535c2c66affSColin Finck * \return The callback must return the number of bytes received, 536c2c66affSColin Finck * or a non-zero error code: 537c2c66affSColin Finck * \c MBEDTLS_ERR_SSL_TIMEOUT if the operation timed out, 538c2c66affSColin Finck * \c MBEDTLS_ERR_SSL_WANT_READ if interrupted by a signal. 539c2c66affSColin Finck * 540c2c66affSColin Finck * \note The callback may receive fewer bytes than the length of the 541c2c66affSColin Finck * buffer. It must always return the number of bytes actually 542c2c66affSColin Finck * received and written to the buffer. 543c2c66affSColin Finck */ 544c2c66affSColin Finck typedef int mbedtls_ssl_recv_timeout_t( void *ctx, 545c2c66affSColin Finck unsigned char *buf, 546c2c66affSColin Finck size_t len, 547c2c66affSColin Finck uint32_t timeout ); 548c2c66affSColin Finck /** 549c2c66affSColin Finck * \brief Callback type: set a pair of timers/delays to watch 550c2c66affSColin Finck * 551c2c66affSColin Finck * \param ctx Context pointer 552c2c66affSColin Finck * \param int_ms Intermediate delay in milliseconds 553c2c66affSColin Finck * \param fin_ms Final delay in milliseconds 554c2c66affSColin Finck * 0 cancels the current timer. 555c2c66affSColin Finck * 556c2c66affSColin Finck * \note This callback must at least store the necessary information 557c2c66affSColin Finck * for the associated \c mbedtls_ssl_get_timer_t callback to 558c2c66affSColin Finck * return correct information. 559c2c66affSColin Finck * 560c2c66affSColin Finck * \note If using a event-driven style of programming, an event must 561c2c66affSColin Finck * be generated when the final delay is passed. The event must 562c2c66affSColin Finck * cause a call to \c mbedtls_ssl_handshake() with the proper 563c2c66affSColin Finck * SSL context to be scheduled. Care must be taken to ensure 564c2c66affSColin Finck * that at most one such call happens at a time. 565c2c66affSColin Finck * 566c2c66affSColin Finck * \note Only one timer at a time must be running. Calling this 567c2c66affSColin Finck * function while a timer is running must cancel it. Cancelled 568c2c66affSColin Finck * timers must not generate any event. 569c2c66affSColin Finck */ 570c2c66affSColin Finck typedef void mbedtls_ssl_set_timer_t( void * ctx, 571c2c66affSColin Finck uint32_t int_ms, 572c2c66affSColin Finck uint32_t fin_ms ); 573c2c66affSColin Finck 574c2c66affSColin Finck /** 575c2c66affSColin Finck * \brief Callback type: get status of timers/delays 576c2c66affSColin Finck * 577c2c66affSColin Finck * \param ctx Context pointer 578c2c66affSColin Finck * 579c2c66affSColin Finck * \return This callback must return: 580c2c66affSColin Finck * -1 if cancelled (fin_ms == 0), 581c2c66affSColin Finck * 0 if none of the delays have passed, 582c2c66affSColin Finck * 1 if only the intermediate delay has passed, 583c2c66affSColin Finck * 2 if the final delay has passed. 584c2c66affSColin Finck */ 585c2c66affSColin Finck typedef int mbedtls_ssl_get_timer_t( void * ctx ); 586c2c66affSColin Finck 587c2c66affSColin Finck /* Defined below */ 588c2c66affSColin Finck typedef struct mbedtls_ssl_session mbedtls_ssl_session; 589c2c66affSColin Finck typedef struct mbedtls_ssl_context mbedtls_ssl_context; 590c2c66affSColin Finck typedef struct mbedtls_ssl_config mbedtls_ssl_config; 591c2c66affSColin Finck 592c2c66affSColin Finck /* Defined in ssl_internal.h */ 593c2c66affSColin Finck typedef struct mbedtls_ssl_transform mbedtls_ssl_transform; 594c2c66affSColin Finck typedef struct mbedtls_ssl_handshake_params mbedtls_ssl_handshake_params; 595c2c66affSColin Finck typedef struct mbedtls_ssl_sig_hash_set_t mbedtls_ssl_sig_hash_set_t; 596c2c66affSColin Finck #if defined(MBEDTLS_X509_CRT_PARSE_C) 597c2c66affSColin Finck typedef struct mbedtls_ssl_key_cert mbedtls_ssl_key_cert; 598c2c66affSColin Finck #endif 599c2c66affSColin Finck #if defined(MBEDTLS_SSL_PROTO_DTLS) 600c2c66affSColin Finck typedef struct mbedtls_ssl_flight_item mbedtls_ssl_flight_item; 601c2c66affSColin Finck #endif 602c2c66affSColin Finck 603cbda039fSThomas Faber #if defined(MBEDTLS_SSL_ASYNC_PRIVATE) 604cbda039fSThomas Faber #if defined(MBEDTLS_X509_CRT_PARSE_C) 605cbda039fSThomas Faber /** 606cbda039fSThomas Faber * \brief Callback type: start external signature operation. 607cbda039fSThomas Faber * 608cbda039fSThomas Faber * This callback is called during an SSL handshake to start 609cbda039fSThomas Faber * a signature decryption operation using an 610cbda039fSThomas Faber * external processor. The parameter \p cert contains 611cbda039fSThomas Faber * the public key; it is up to the callback function to 612cbda039fSThomas Faber * determine how to access the associated private key. 613cbda039fSThomas Faber * 614cbda039fSThomas Faber * This function typically sends or enqueues a request, and 615cbda039fSThomas Faber * does not wait for the operation to complete. This allows 616cbda039fSThomas Faber * the handshake step to be non-blocking. 617cbda039fSThomas Faber * 618cbda039fSThomas Faber * The parameters \p ssl and \p cert are guaranteed to remain 619cbda039fSThomas Faber * valid throughout the handshake. On the other hand, this 620cbda039fSThomas Faber * function must save the contents of \p hash if the value 621cbda039fSThomas Faber * is needed for later processing, because the \p hash buffer 622cbda039fSThomas Faber * is no longer valid after this function returns. 623cbda039fSThomas Faber * 624cbda039fSThomas Faber * This function may call mbedtls_ssl_set_async_operation_data() 625cbda039fSThomas Faber * to store an operation context for later retrieval 626cbda039fSThomas Faber * by the resume or cancel callback. 627cbda039fSThomas Faber * 628cbda039fSThomas Faber * \note For RSA signatures, this function must produce output 629cbda039fSThomas Faber * that is consistent with PKCS#1 v1.5 in the same way as 630cbda039fSThomas Faber * mbedtls_rsa_pkcs1_sign(). Before the private key operation, 631cbda039fSThomas Faber * apply the padding steps described in RFC 8017, section 9.2 632cbda039fSThomas Faber * "EMSA-PKCS1-v1_5" as follows. 633cbda039fSThomas Faber * - If \p md_alg is #MBEDTLS_MD_NONE, apply the PKCS#1 v1.5 634cbda039fSThomas Faber * encoding, treating \p hash as the DigestInfo to be 635cbda039fSThomas Faber * padded. In other words, apply EMSA-PKCS1-v1_5 starting 636cbda039fSThomas Faber * from step 3, with `T = hash` and `tLen = hash_len`. 637cbda039fSThomas Faber * - If `md_alg != MBEDTLS_MD_NONE`, apply the PKCS#1 v1.5 638cbda039fSThomas Faber * encoding, treating \p hash as the hash to be encoded and 639cbda039fSThomas Faber * padded. In other words, apply EMSA-PKCS1-v1_5 starting 640cbda039fSThomas Faber * from step 2, with `digestAlgorithm` obtained by calling 641cbda039fSThomas Faber * mbedtls_oid_get_oid_by_md() on \p md_alg. 642cbda039fSThomas Faber * 643cbda039fSThomas Faber * \note For ECDSA signatures, the output format is the DER encoding 644cbda039fSThomas Faber * `Ecdsa-Sig-Value` defined in 645cbda039fSThomas Faber * [RFC 4492 section 5.4](https://tools.ietf.org/html/rfc4492#section-5.4). 646cbda039fSThomas Faber * 647cbda039fSThomas Faber * \param ssl The SSL connection instance. It should not be 648cbda039fSThomas Faber * modified other than via 649cbda039fSThomas Faber * mbedtls_ssl_set_async_operation_data(). 650cbda039fSThomas Faber * \param cert Certificate containing the public key. 651cbda039fSThomas Faber * In simple cases, this is one of the pointers passed to 652cbda039fSThomas Faber * mbedtls_ssl_conf_own_cert() when configuring the SSL 653cbda039fSThomas Faber * connection. However, if other callbacks are used, this 654cbda039fSThomas Faber * property may not hold. For example, if an SNI callback 655cbda039fSThomas Faber * is registered with mbedtls_ssl_conf_sni(), then 656cbda039fSThomas Faber * this callback determines what certificate is used. 657cbda039fSThomas Faber * \param md_alg Hash algorithm. 658cbda039fSThomas Faber * \param hash Buffer containing the hash. This buffer is 659cbda039fSThomas Faber * no longer valid when the function returns. 660cbda039fSThomas Faber * \param hash_len Size of the \c hash buffer in bytes. 661cbda039fSThomas Faber * 662cbda039fSThomas Faber * \return 0 if the operation was started successfully and the SSL 663cbda039fSThomas Faber * stack should call the resume callback immediately. 664cbda039fSThomas Faber * \return #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS if the operation 665cbda039fSThomas Faber * was started successfully and the SSL stack should return 666cbda039fSThomas Faber * immediately without calling the resume callback yet. 667cbda039fSThomas Faber * \return #MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH if the external 668cbda039fSThomas Faber * processor does not support this key. The SSL stack will 669cbda039fSThomas Faber * use the private key object instead. 670cbda039fSThomas Faber * \return Any other error indicates a fatal failure and is 671cbda039fSThomas Faber * propagated up the call chain. The callback should 672cbda039fSThomas Faber * use \c MBEDTLS_ERR_PK_xxx error codes, and <b>must not</b> 673cbda039fSThomas Faber * use \c MBEDTLS_ERR_SSL_xxx error codes except as 674cbda039fSThomas Faber * directed in the documentation of this callback. 675cbda039fSThomas Faber */ 676cbda039fSThomas Faber typedef int mbedtls_ssl_async_sign_t( mbedtls_ssl_context *ssl, 677cbda039fSThomas Faber mbedtls_x509_crt *cert, 678cbda039fSThomas Faber mbedtls_md_type_t md_alg, 679cbda039fSThomas Faber const unsigned char *hash, 680cbda039fSThomas Faber size_t hash_len ); 681cbda039fSThomas Faber 682cbda039fSThomas Faber /** 683cbda039fSThomas Faber * \brief Callback type: start external decryption operation. 684cbda039fSThomas Faber * 685cbda039fSThomas Faber * This callback is called during an SSL handshake to start 686cbda039fSThomas Faber * an RSA decryption operation using an 687cbda039fSThomas Faber * external processor. The parameter \p cert contains 688cbda039fSThomas Faber * the public key; it is up to the callback function to 689cbda039fSThomas Faber * determine how to access the associated private key. 690cbda039fSThomas Faber * 691cbda039fSThomas Faber * This function typically sends or enqueues a request, and 692cbda039fSThomas Faber * does not wait for the operation to complete. This allows 693cbda039fSThomas Faber * the handshake step to be non-blocking. 694cbda039fSThomas Faber * 695cbda039fSThomas Faber * The parameters \p ssl and \p cert are guaranteed to remain 696cbda039fSThomas Faber * valid throughout the handshake. On the other hand, this 697cbda039fSThomas Faber * function must save the contents of \p input if the value 698cbda039fSThomas Faber * is needed for later processing, because the \p input buffer 699cbda039fSThomas Faber * is no longer valid after this function returns. 700cbda039fSThomas Faber * 701cbda039fSThomas Faber * This function may call mbedtls_ssl_set_async_operation_data() 702cbda039fSThomas Faber * to store an operation context for later retrieval 703cbda039fSThomas Faber * by the resume or cancel callback. 704cbda039fSThomas Faber * 705cbda039fSThomas Faber * \warning RSA decryption as used in TLS is subject to a potential 706cbda039fSThomas Faber * timing side channel attack first discovered by Bleichenbacher 707cbda039fSThomas Faber * in 1998. This attack can be remotely exploitable 708cbda039fSThomas Faber * in practice. To avoid this attack, you must ensure that 709cbda039fSThomas Faber * if the callback performs an RSA decryption, the time it 710cbda039fSThomas Faber * takes to execute and return the result does not depend 711cbda039fSThomas Faber * on whether the RSA decryption succeeded or reported 712cbda039fSThomas Faber * invalid padding. 713cbda039fSThomas Faber * 714cbda039fSThomas Faber * \param ssl The SSL connection instance. It should not be 715cbda039fSThomas Faber * modified other than via 716cbda039fSThomas Faber * mbedtls_ssl_set_async_operation_data(). 717cbda039fSThomas Faber * \param cert Certificate containing the public key. 718cbda039fSThomas Faber * In simple cases, this is one of the pointers passed to 719cbda039fSThomas Faber * mbedtls_ssl_conf_own_cert() when configuring the SSL 720cbda039fSThomas Faber * connection. However, if other callbacks are used, this 721cbda039fSThomas Faber * property may not hold. For example, if an SNI callback 722cbda039fSThomas Faber * is registered with mbedtls_ssl_conf_sni(), then 723cbda039fSThomas Faber * this callback determines what certificate is used. 724cbda039fSThomas Faber * \param input Buffer containing the input ciphertext. This buffer 725cbda039fSThomas Faber * is no longer valid when the function returns. 726cbda039fSThomas Faber * \param input_len Size of the \p input buffer in bytes. 727cbda039fSThomas Faber * 728cbda039fSThomas Faber * \return 0 if the operation was started successfully and the SSL 729cbda039fSThomas Faber * stack should call the resume callback immediately. 730cbda039fSThomas Faber * \return #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS if the operation 731cbda039fSThomas Faber * was started successfully and the SSL stack should return 732cbda039fSThomas Faber * immediately without calling the resume callback yet. 733cbda039fSThomas Faber * \return #MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH if the external 734cbda039fSThomas Faber * processor does not support this key. The SSL stack will 735cbda039fSThomas Faber * use the private key object instead. 736cbda039fSThomas Faber * \return Any other error indicates a fatal failure and is 737cbda039fSThomas Faber * propagated up the call chain. The callback should 738cbda039fSThomas Faber * use \c MBEDTLS_ERR_PK_xxx error codes, and <b>must not</b> 739cbda039fSThomas Faber * use \c MBEDTLS_ERR_SSL_xxx error codes except as 740cbda039fSThomas Faber * directed in the documentation of this callback. 741cbda039fSThomas Faber */ 742cbda039fSThomas Faber typedef int mbedtls_ssl_async_decrypt_t( mbedtls_ssl_context *ssl, 743cbda039fSThomas Faber mbedtls_x509_crt *cert, 744cbda039fSThomas Faber const unsigned char *input, 745cbda039fSThomas Faber size_t input_len ); 746cbda039fSThomas Faber #endif /* MBEDTLS_X509_CRT_PARSE_C */ 747cbda039fSThomas Faber 748cbda039fSThomas Faber /** 749cbda039fSThomas Faber * \brief Callback type: resume external operation. 750cbda039fSThomas Faber * 751cbda039fSThomas Faber * This callback is called during an SSL handshake to resume 752cbda039fSThomas Faber * an external operation started by the 753cbda039fSThomas Faber * ::mbedtls_ssl_async_sign_t or 754cbda039fSThomas Faber * ::mbedtls_ssl_async_decrypt_t callback. 755cbda039fSThomas Faber * 756cbda039fSThomas Faber * This function typically checks the status of a pending 757cbda039fSThomas Faber * request or causes the request queue to make progress, and 758cbda039fSThomas Faber * does not wait for the operation to complete. This allows 759cbda039fSThomas Faber * the handshake step to be non-blocking. 760cbda039fSThomas Faber * 761cbda039fSThomas Faber * This function may call mbedtls_ssl_get_async_operation_data() 762cbda039fSThomas Faber * to retrieve an operation context set by the start callback. 763cbda039fSThomas Faber * It may call mbedtls_ssl_set_async_operation_data() to modify 764cbda039fSThomas Faber * this context. 765cbda039fSThomas Faber * 766cbda039fSThomas Faber * Note that when this function returns a status other than 767cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS, it must free any 768cbda039fSThomas Faber * resources associated with the operation. 769cbda039fSThomas Faber * 770cbda039fSThomas Faber * \param ssl The SSL connection instance. It should not be 771cbda039fSThomas Faber * modified other than via 772cbda039fSThomas Faber * mbedtls_ssl_set_async_operation_data(). 773cbda039fSThomas Faber * \param output Buffer containing the output (signature or decrypted 774cbda039fSThomas Faber * data) on success. 775cbda039fSThomas Faber * \param output_len On success, number of bytes written to \p output. 776cbda039fSThomas Faber * \param output_size Size of the \p output buffer in bytes. 777cbda039fSThomas Faber * 778cbda039fSThomas Faber * \return 0 if output of the operation is available in the 779cbda039fSThomas Faber * \p output buffer. 780cbda039fSThomas Faber * \return #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS if the operation 781cbda039fSThomas Faber * is still in progress. Subsequent requests for progress 782cbda039fSThomas Faber * on the SSL connection will call the resume callback 783cbda039fSThomas Faber * again. 784cbda039fSThomas Faber * \return Any other error means that the operation is aborted. 785cbda039fSThomas Faber * The SSL handshake is aborted. The callback should 786cbda039fSThomas Faber * use \c MBEDTLS_ERR_PK_xxx error codes, and <b>must not</b> 787cbda039fSThomas Faber * use \c MBEDTLS_ERR_SSL_xxx error codes except as 788cbda039fSThomas Faber * directed in the documentation of this callback. 789cbda039fSThomas Faber */ 790cbda039fSThomas Faber typedef int mbedtls_ssl_async_resume_t( mbedtls_ssl_context *ssl, 791cbda039fSThomas Faber unsigned char *output, 792cbda039fSThomas Faber size_t *output_len, 793cbda039fSThomas Faber size_t output_size ); 794cbda039fSThomas Faber 795cbda039fSThomas Faber /** 796cbda039fSThomas Faber * \brief Callback type: cancel external operation. 797cbda039fSThomas Faber * 798cbda039fSThomas Faber * This callback is called if an SSL connection is closed 799cbda039fSThomas Faber * while an asynchronous operation is in progress. Note that 800cbda039fSThomas Faber * this callback is not called if the 801cbda039fSThomas Faber * ::mbedtls_ssl_async_resume_t callback has run and has 802cbda039fSThomas Faber * returned a value other than 803cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS, since in that case 804cbda039fSThomas Faber * the asynchronous operation has already completed. 805cbda039fSThomas Faber * 806cbda039fSThomas Faber * This function may call mbedtls_ssl_get_async_operation_data() 807cbda039fSThomas Faber * to retrieve an operation context set by the start callback. 808cbda039fSThomas Faber * 809cbda039fSThomas Faber * \param ssl The SSL connection instance. It should not be 810cbda039fSThomas Faber * modified. 811cbda039fSThomas Faber */ 812cbda039fSThomas Faber typedef void mbedtls_ssl_async_cancel_t( mbedtls_ssl_context *ssl ); 813cbda039fSThomas Faber #endif /* MBEDTLS_SSL_ASYNC_PRIVATE */ 814cbda039fSThomas Faber 815c2c66affSColin Finck /* 816c2c66affSColin Finck * This structure is used for storing current session data. 817c2c66affSColin Finck */ 818c2c66affSColin Finck struct mbedtls_ssl_session 819c2c66affSColin Finck { 820c2c66affSColin Finck #if defined(MBEDTLS_HAVE_TIME) 821c2c66affSColin Finck mbedtls_time_t start; /*!< starting time */ 822c2c66affSColin Finck #endif 823c2c66affSColin Finck int ciphersuite; /*!< chosen ciphersuite */ 824c2c66affSColin Finck int compression; /*!< chosen compression */ 825c2c66affSColin Finck size_t id_len; /*!< session id length */ 826c2c66affSColin Finck unsigned char id[32]; /*!< session identifier */ 827c2c66affSColin Finck unsigned char master[48]; /*!< the master secret */ 828c2c66affSColin Finck 829c2c66affSColin Finck #if defined(MBEDTLS_X509_CRT_PARSE_C) 830c2c66affSColin Finck mbedtls_x509_crt *peer_cert; /*!< peer X.509 cert chain */ 831c2c66affSColin Finck #endif /* MBEDTLS_X509_CRT_PARSE_C */ 832c2c66affSColin Finck uint32_t verify_result; /*!< verification result */ 833c2c66affSColin Finck 834c2c66affSColin Finck #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C) 835c2c66affSColin Finck unsigned char *ticket; /*!< RFC 5077 session ticket */ 836c2c66affSColin Finck size_t ticket_len; /*!< session ticket length */ 837c2c66affSColin Finck uint32_t ticket_lifetime; /*!< ticket lifetime hint */ 838c2c66affSColin Finck #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */ 839c2c66affSColin Finck 840c2c66affSColin Finck #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) 841c2c66affSColin Finck unsigned char mfl_code; /*!< MaxFragmentLength negotiated by peer */ 842c2c66affSColin Finck #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */ 843c2c66affSColin Finck 844c2c66affSColin Finck #if defined(MBEDTLS_SSL_TRUNCATED_HMAC) 845c2c66affSColin Finck int trunc_hmac; /*!< flag for truncated hmac activation */ 846c2c66affSColin Finck #endif /* MBEDTLS_SSL_TRUNCATED_HMAC */ 847c2c66affSColin Finck 848c2c66affSColin Finck #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) 849c2c66affSColin Finck int encrypt_then_mac; /*!< flag for EtM activation */ 850c2c66affSColin Finck #endif 851c2c66affSColin Finck }; 852c2c66affSColin Finck 853c2c66affSColin Finck /** 854c2c66affSColin Finck * SSL/TLS configuration to be shared between mbedtls_ssl_context structures. 855c2c66affSColin Finck */ 856c2c66affSColin Finck struct mbedtls_ssl_config 857c2c66affSColin Finck { 858c2c66affSColin Finck /* Group items by size (largest first) to minimize padding overhead */ 859c2c66affSColin Finck 860c2c66affSColin Finck /* 861c2c66affSColin Finck * Pointers 862c2c66affSColin Finck */ 863c2c66affSColin Finck 864c2c66affSColin Finck const int *ciphersuite_list[4]; /*!< allowed ciphersuites per version */ 865c2c66affSColin Finck 866c2c66affSColin Finck /** Callback for printing debug output */ 867c2c66affSColin Finck void (*f_dbg)(void *, int, const char *, int, const char *); 868c2c66affSColin Finck void *p_dbg; /*!< context for the debug function */ 869c2c66affSColin Finck 870c2c66affSColin Finck /** Callback for getting (pseudo-)random numbers */ 871c2c66affSColin Finck int (*f_rng)(void *, unsigned char *, size_t); 872c2c66affSColin Finck void *p_rng; /*!< context for the RNG function */ 873c2c66affSColin Finck 874c2c66affSColin Finck /** Callback to retrieve a session from the cache */ 875c2c66affSColin Finck int (*f_get_cache)(void *, mbedtls_ssl_session *); 876c2c66affSColin Finck /** Callback to store a session into the cache */ 877c2c66affSColin Finck int (*f_set_cache)(void *, const mbedtls_ssl_session *); 878c2c66affSColin Finck void *p_cache; /*!< context for cache callbacks */ 879c2c66affSColin Finck 880c2c66affSColin Finck #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) 881c2c66affSColin Finck /** Callback for setting cert according to SNI extension */ 882c2c66affSColin Finck int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *, size_t); 883c2c66affSColin Finck void *p_sni; /*!< context for SNI callback */ 884c2c66affSColin Finck #endif 885c2c66affSColin Finck 886c2c66affSColin Finck #if defined(MBEDTLS_X509_CRT_PARSE_C) 887c2c66affSColin Finck /** Callback to customize X.509 certificate chain verification */ 888c2c66affSColin Finck int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *); 889c2c66affSColin Finck void *p_vrfy; /*!< context for X.509 verify calllback */ 890c2c66affSColin Finck #endif 891c2c66affSColin Finck 892c2c66affSColin Finck #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) 893c2c66affSColin Finck /** Callback to retrieve PSK key from identity */ 894c2c66affSColin Finck int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *, size_t); 895c2c66affSColin Finck void *p_psk; /*!< context for PSK callback */ 896c2c66affSColin Finck #endif 897c2c66affSColin Finck 898c2c66affSColin Finck #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C) 899c2c66affSColin Finck /** Callback to create & write a cookie for ClientHello veirifcation */ 900c2c66affSColin Finck int (*f_cookie_write)( void *, unsigned char **, unsigned char *, 901c2c66affSColin Finck const unsigned char *, size_t ); 902c2c66affSColin Finck /** Callback to verify validity of a ClientHello cookie */ 903c2c66affSColin Finck int (*f_cookie_check)( void *, const unsigned char *, size_t, 904c2c66affSColin Finck const unsigned char *, size_t ); 905c2c66affSColin Finck void *p_cookie; /*!< context for the cookie callbacks */ 906c2c66affSColin Finck #endif 907c2c66affSColin Finck 908c2c66affSColin Finck #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C) 909c2c66affSColin Finck /** Callback to create & write a session ticket */ 910c2c66affSColin Finck int (*f_ticket_write)( void *, const mbedtls_ssl_session *, 911c2c66affSColin Finck unsigned char *, const unsigned char *, size_t *, uint32_t * ); 912c2c66affSColin Finck /** Callback to parse a session ticket into a session structure */ 913c2c66affSColin Finck int (*f_ticket_parse)( void *, mbedtls_ssl_session *, unsigned char *, size_t); 914c2c66affSColin Finck void *p_ticket; /*!< context for the ticket callbacks */ 915c2c66affSColin Finck #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */ 916c2c66affSColin Finck 917c2c66affSColin Finck #if defined(MBEDTLS_SSL_EXPORT_KEYS) 918c2c66affSColin Finck /** Callback to export key block and master secret */ 919c2c66affSColin Finck int (*f_export_keys)( void *, const unsigned char *, 920c2c66affSColin Finck const unsigned char *, size_t, size_t, size_t ); 921c2c66affSColin Finck void *p_export_keys; /*!< context for key export callback */ 922c2c66affSColin Finck #endif 923c2c66affSColin Finck 924c2c66affSColin Finck #if defined(MBEDTLS_X509_CRT_PARSE_C) 925c2c66affSColin Finck const mbedtls_x509_crt_profile *cert_profile; /*!< verification profile */ 926c2c66affSColin Finck mbedtls_ssl_key_cert *key_cert; /*!< own certificate/key pair(s) */ 927c2c66affSColin Finck mbedtls_x509_crt *ca_chain; /*!< trusted CAs */ 928c2c66affSColin Finck mbedtls_x509_crl *ca_crl; /*!< trusted CAs CRLs */ 929c2c66affSColin Finck #endif /* MBEDTLS_X509_CRT_PARSE_C */ 930c2c66affSColin Finck 931cbda039fSThomas Faber #if defined(MBEDTLS_SSL_ASYNC_PRIVATE) 932cbda039fSThomas Faber #if defined(MBEDTLS_X509_CRT_PARSE_C) 933cbda039fSThomas Faber mbedtls_ssl_async_sign_t *f_async_sign_start; /*!< start asynchronous signature operation */ 934cbda039fSThomas Faber mbedtls_ssl_async_decrypt_t *f_async_decrypt_start; /*!< start asynchronous decryption operation */ 935cbda039fSThomas Faber #endif /* MBEDTLS_X509_CRT_PARSE_C */ 936cbda039fSThomas Faber mbedtls_ssl_async_resume_t *f_async_resume; /*!< resume asynchronous operation */ 937cbda039fSThomas Faber mbedtls_ssl_async_cancel_t *f_async_cancel; /*!< cancel asynchronous operation */ 938cbda039fSThomas Faber void *p_async_config_data; /*!< Configuration data set by mbedtls_ssl_conf_async_private_cb(). */ 939cbda039fSThomas Faber #endif /* MBEDTLS_SSL_ASYNC_PRIVATE */ 940cbda039fSThomas Faber 941c2c66affSColin Finck #if defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED) 942c2c66affSColin Finck const int *sig_hashes; /*!< allowed signature hashes */ 943c2c66affSColin Finck #endif 944c2c66affSColin Finck 945c2c66affSColin Finck #if defined(MBEDTLS_ECP_C) 946c2c66affSColin Finck const mbedtls_ecp_group_id *curve_list; /*!< allowed curves */ 947c2c66affSColin Finck #endif 948c2c66affSColin Finck 949c2c66affSColin Finck #if defined(MBEDTLS_DHM_C) 950c2c66affSColin Finck mbedtls_mpi dhm_P; /*!< prime modulus for DHM */ 951c2c66affSColin Finck mbedtls_mpi dhm_G; /*!< generator for DHM */ 952c2c66affSColin Finck #endif 953c2c66affSColin Finck 954c2c66affSColin Finck #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) 955cbda039fSThomas Faber unsigned char *psk; /*!< pre-shared key. This field should 956cbda039fSThomas Faber only be set via 957cbda039fSThomas Faber mbedtls_ssl_conf_psk() */ 958cbda039fSThomas Faber size_t psk_len; /*!< length of the pre-shared key. This 959cbda039fSThomas Faber field should only be set via 960cbda039fSThomas Faber mbedtls_ssl_conf_psk() */ 961cbda039fSThomas Faber unsigned char *psk_identity; /*!< identity for PSK negotiation. This 962cbda039fSThomas Faber field should only be set via 963cbda039fSThomas Faber mbedtls_ssl_conf_psk() */ 964cbda039fSThomas Faber size_t psk_identity_len;/*!< length of identity. This field should 965cbda039fSThomas Faber only be set via 966cbda039fSThomas Faber mbedtls_ssl_conf_psk() */ 967c2c66affSColin Finck #endif 968c2c66affSColin Finck 969c2c66affSColin Finck #if defined(MBEDTLS_SSL_ALPN) 970c2c66affSColin Finck const char **alpn_list; /*!< ordered list of protocols */ 971c2c66affSColin Finck #endif 972c2c66affSColin Finck 973c2c66affSColin Finck /* 974c2c66affSColin Finck * Numerical settings (int then char) 975c2c66affSColin Finck */ 976c2c66affSColin Finck 977c2c66affSColin Finck uint32_t read_timeout; /*!< timeout for mbedtls_ssl_read (ms) */ 978c2c66affSColin Finck 979c2c66affSColin Finck #if defined(MBEDTLS_SSL_PROTO_DTLS) 980c2c66affSColin Finck uint32_t hs_timeout_min; /*!< initial value of the handshake 981c2c66affSColin Finck retransmission timeout (ms) */ 982c2c66affSColin Finck uint32_t hs_timeout_max; /*!< maximum value of the handshake 983c2c66affSColin Finck retransmission timeout (ms) */ 984c2c66affSColin Finck #endif 985c2c66affSColin Finck 986c2c66affSColin Finck #if defined(MBEDTLS_SSL_RENEGOTIATION) 987c2c66affSColin Finck int renego_max_records; /*!< grace period for renegotiation */ 988c2c66affSColin Finck unsigned char renego_period[8]; /*!< value of the record counters 989c2c66affSColin Finck that triggers renegotiation */ 990c2c66affSColin Finck #endif 991c2c66affSColin Finck 992c2c66affSColin Finck #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT) 993c2c66affSColin Finck unsigned int badmac_limit; /*!< limit of records with a bad MAC */ 994c2c66affSColin Finck #endif 995c2c66affSColin Finck 996c2c66affSColin Finck #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C) 997c2c66affSColin Finck unsigned int dhm_min_bitlen; /*!< min. bit length of the DHM prime */ 998c2c66affSColin Finck #endif 999c2c66affSColin Finck 1000c2c66affSColin Finck unsigned char max_major_ver; /*!< max. major version used */ 1001c2c66affSColin Finck unsigned char max_minor_ver; /*!< max. minor version used */ 1002c2c66affSColin Finck unsigned char min_major_ver; /*!< min. major version used */ 1003c2c66affSColin Finck unsigned char min_minor_ver; /*!< min. minor version used */ 1004c2c66affSColin Finck 1005c2c66affSColin Finck /* 1006c2c66affSColin Finck * Flags (bitfields) 1007c2c66affSColin Finck */ 1008c2c66affSColin Finck 1009c2c66affSColin Finck unsigned int endpoint : 1; /*!< 0: client, 1: server */ 1010c2c66affSColin Finck unsigned int transport : 1; /*!< stream (TLS) or datagram (DTLS) */ 1011c2c66affSColin Finck unsigned int authmode : 2; /*!< MBEDTLS_SSL_VERIFY_XXX */ 1012c2c66affSColin Finck /* needed even with renego disabled for LEGACY_BREAK_HANDSHAKE */ 1013c2c66affSColin Finck unsigned int allow_legacy_renegotiation : 2 ; /*!< MBEDTLS_LEGACY_XXX */ 1014c2c66affSColin Finck #if defined(MBEDTLS_ARC4_C) 1015c2c66affSColin Finck unsigned int arc4_disabled : 1; /*!< blacklist RC4 ciphersuites? */ 1016c2c66affSColin Finck #endif 1017c2c66affSColin Finck #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) 1018c2c66affSColin Finck unsigned int mfl_code : 3; /*!< desired fragment length */ 1019c2c66affSColin Finck #endif 1020c2c66affSColin Finck #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) 1021c2c66affSColin Finck unsigned int encrypt_then_mac : 1 ; /*!< negotiate encrypt-then-mac? */ 1022c2c66affSColin Finck #endif 1023c2c66affSColin Finck #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET) 1024c2c66affSColin Finck unsigned int extended_ms : 1; /*!< negotiate extended master secret? */ 1025c2c66affSColin Finck #endif 1026c2c66affSColin Finck #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY) 1027c2c66affSColin Finck unsigned int anti_replay : 1; /*!< detect and prevent replay? */ 1028c2c66affSColin Finck #endif 1029c2c66affSColin Finck #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING) 1030c2c66affSColin Finck unsigned int cbc_record_splitting : 1; /*!< do cbc record splitting */ 1031c2c66affSColin Finck #endif 1032c2c66affSColin Finck #if defined(MBEDTLS_SSL_RENEGOTIATION) 1033c2c66affSColin Finck unsigned int disable_renegotiation : 1; /*!< disable renegotiation? */ 1034c2c66affSColin Finck #endif 1035c2c66affSColin Finck #if defined(MBEDTLS_SSL_TRUNCATED_HMAC) 1036c2c66affSColin Finck unsigned int trunc_hmac : 1; /*!< negotiate truncated hmac? */ 1037c2c66affSColin Finck #endif 1038c2c66affSColin Finck #if defined(MBEDTLS_SSL_SESSION_TICKETS) 1039c2c66affSColin Finck unsigned int session_tickets : 1; /*!< use session tickets? */ 1040c2c66affSColin Finck #endif 1041c2c66affSColin Finck #if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C) 1042c2c66affSColin Finck unsigned int fallback : 1; /*!< is this a fallback? */ 1043c2c66affSColin Finck #endif 1044c2c66affSColin Finck #if defined(MBEDTLS_SSL_SRV_C) 1045c2c66affSColin Finck unsigned int cert_req_ca_list : 1; /*!< enable sending CA list in 1046c2c66affSColin Finck Certificate Request messages? */ 1047c2c66affSColin Finck #endif 1048c2c66affSColin Finck }; 1049c2c66affSColin Finck 1050c2c66affSColin Finck 1051c2c66affSColin Finck struct mbedtls_ssl_context 1052c2c66affSColin Finck { 1053c2c66affSColin Finck const mbedtls_ssl_config *conf; /*!< configuration information */ 1054c2c66affSColin Finck 1055c2c66affSColin Finck /* 1056c2c66affSColin Finck * Miscellaneous 1057c2c66affSColin Finck */ 1058c2c66affSColin Finck int state; /*!< SSL handshake: current state */ 1059c2c66affSColin Finck #if defined(MBEDTLS_SSL_RENEGOTIATION) 1060c2c66affSColin Finck int renego_status; /*!< Initial, in progress, pending? */ 1061c2c66affSColin Finck int renego_records_seen; /*!< Records since renego request, or with DTLS, 1062c2c66affSColin Finck number of retransmissions of request if 1063c2c66affSColin Finck renego_max_records is < 0 */ 1064cbda039fSThomas Faber #endif /* MBEDTLS_SSL_RENEGOTIATION */ 1065c2c66affSColin Finck 1066c2c66affSColin Finck int major_ver; /*!< equal to MBEDTLS_SSL_MAJOR_VERSION_3 */ 1067c2c66affSColin Finck int minor_ver; /*!< either 0 (SSL3) or 1 (TLS1.0) */ 1068c2c66affSColin Finck 1069c2c66affSColin Finck #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT) 1070c2c66affSColin Finck unsigned badmac_seen; /*!< records with a bad MAC received */ 1071cbda039fSThomas Faber #endif /* MBEDTLS_SSL_DTLS_BADMAC_LIMIT */ 1072c2c66affSColin Finck 1073c2c66affSColin Finck mbedtls_ssl_send_t *f_send; /*!< Callback for network send */ 1074c2c66affSColin Finck mbedtls_ssl_recv_t *f_recv; /*!< Callback for network receive */ 1075c2c66affSColin Finck mbedtls_ssl_recv_timeout_t *f_recv_timeout; 1076c2c66affSColin Finck /*!< Callback for network receive with timeout */ 1077c2c66affSColin Finck 1078c2c66affSColin Finck void *p_bio; /*!< context for I/O operations */ 1079c2c66affSColin Finck 1080c2c66affSColin Finck /* 1081c2c66affSColin Finck * Session layer 1082c2c66affSColin Finck */ 1083c2c66affSColin Finck mbedtls_ssl_session *session_in; /*!< current session data (in) */ 1084c2c66affSColin Finck mbedtls_ssl_session *session_out; /*!< current session data (out) */ 1085c2c66affSColin Finck mbedtls_ssl_session *session; /*!< negotiated session data */ 1086c2c66affSColin Finck mbedtls_ssl_session *session_negotiate; /*!< session data in negotiation */ 1087c2c66affSColin Finck 1088c2c66affSColin Finck mbedtls_ssl_handshake_params *handshake; /*!< params required only during 1089c2c66affSColin Finck the handshake process */ 1090c2c66affSColin Finck 1091c2c66affSColin Finck /* 1092c2c66affSColin Finck * Record layer transformations 1093c2c66affSColin Finck */ 1094c2c66affSColin Finck mbedtls_ssl_transform *transform_in; /*!< current transform params (in) */ 1095c2c66affSColin Finck mbedtls_ssl_transform *transform_out; /*!< current transform params (in) */ 1096c2c66affSColin Finck mbedtls_ssl_transform *transform; /*!< negotiated transform params */ 1097c2c66affSColin Finck mbedtls_ssl_transform *transform_negotiate; /*!< transform params in negotiation */ 1098c2c66affSColin Finck 1099c2c66affSColin Finck /* 1100c2c66affSColin Finck * Timers 1101c2c66affSColin Finck */ 1102c2c66affSColin Finck void *p_timer; /*!< context for the timer callbacks */ 1103c2c66affSColin Finck 1104c2c66affSColin Finck mbedtls_ssl_set_timer_t *f_set_timer; /*!< set timer callback */ 1105c2c66affSColin Finck mbedtls_ssl_get_timer_t *f_get_timer; /*!< get timer callback */ 1106c2c66affSColin Finck 1107c2c66affSColin Finck /* 1108c2c66affSColin Finck * Record layer (incoming data) 1109c2c66affSColin Finck */ 1110c2c66affSColin Finck unsigned char *in_buf; /*!< input buffer */ 1111c2c66affSColin Finck unsigned char *in_ctr; /*!< 64-bit incoming message counter 1112c2c66affSColin Finck TLS: maintained by us 1113c2c66affSColin Finck DTLS: read from peer */ 1114c2c66affSColin Finck unsigned char *in_hdr; /*!< start of record header */ 1115c2c66affSColin Finck unsigned char *in_len; /*!< two-bytes message length field */ 1116c2c66affSColin Finck unsigned char *in_iv; /*!< ivlen-byte IV */ 1117c2c66affSColin Finck unsigned char *in_msg; /*!< message contents (in_iv+ivlen) */ 1118c2c66affSColin Finck unsigned char *in_offt; /*!< read offset in application data */ 1119c2c66affSColin Finck 1120c2c66affSColin Finck int in_msgtype; /*!< record header: message type */ 1121c2c66affSColin Finck size_t in_msglen; /*!< record header: message length */ 1122c2c66affSColin Finck size_t in_left; /*!< amount of data read so far */ 1123c2c66affSColin Finck #if defined(MBEDTLS_SSL_PROTO_DTLS) 1124c2c66affSColin Finck uint16_t in_epoch; /*!< DTLS epoch for incoming records */ 1125c2c66affSColin Finck size_t next_record_offset; /*!< offset of the next record in datagram 1126c2c66affSColin Finck (equal to in_left if none) */ 1127cbda039fSThomas Faber #endif /* MBEDTLS_SSL_PROTO_DTLS */ 1128c2c66affSColin Finck #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY) 1129c2c66affSColin Finck uint64_t in_window_top; /*!< last validated record seq_num */ 1130c2c66affSColin Finck uint64_t in_window; /*!< bitmask for replay detection */ 1131cbda039fSThomas Faber #endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */ 1132c2c66affSColin Finck 1133c2c66affSColin Finck size_t in_hslen; /*!< current handshake message length, 1134c2c66affSColin Finck including the handshake header */ 1135c2c66affSColin Finck int nb_zero; /*!< # of 0-length encrypted messages */ 1136c2c66affSColin Finck 1137c2c66affSColin Finck int keep_current_message; /*!< drop or reuse current message 1138c2c66affSColin Finck on next call to record layer? */ 1139c2c66affSColin Finck 1140cbda039fSThomas Faber #if defined(MBEDTLS_SSL_PROTO_DTLS) 1141cbda039fSThomas Faber uint8_t disable_datagram_packing; /*!< Disable packing multiple records 1142cbda039fSThomas Faber * within a single datagram. */ 1143cbda039fSThomas Faber #endif /* MBEDTLS_SSL_PROTO_DTLS */ 1144cbda039fSThomas Faber 1145c2c66affSColin Finck /* 1146c2c66affSColin Finck * Record layer (outgoing data) 1147c2c66affSColin Finck */ 1148c2c66affSColin Finck unsigned char *out_buf; /*!< output buffer */ 1149c2c66affSColin Finck unsigned char *out_ctr; /*!< 64-bit outgoing message counter */ 1150c2c66affSColin Finck unsigned char *out_hdr; /*!< start of record header */ 1151c2c66affSColin Finck unsigned char *out_len; /*!< two-bytes message length field */ 1152c2c66affSColin Finck unsigned char *out_iv; /*!< ivlen-byte IV */ 1153c2c66affSColin Finck unsigned char *out_msg; /*!< message contents (out_iv+ivlen) */ 1154c2c66affSColin Finck 1155c2c66affSColin Finck int out_msgtype; /*!< record header: message type */ 1156c2c66affSColin Finck size_t out_msglen; /*!< record header: message length */ 1157c2c66affSColin Finck size_t out_left; /*!< amount of data not yet written */ 1158c2c66affSColin Finck 1159cbda039fSThomas Faber unsigned char cur_out_ctr[8]; /*!< Outgoing record sequence number. */ 1160cbda039fSThomas Faber 1161cbda039fSThomas Faber #if defined(MBEDTLS_SSL_PROTO_DTLS) 1162cbda039fSThomas Faber uint16_t mtu; /*!< path mtu, used to fragment outgoing messages */ 1163cbda039fSThomas Faber #endif /* MBEDTLS_SSL_PROTO_DTLS */ 1164cbda039fSThomas Faber 1165c2c66affSColin Finck #if defined(MBEDTLS_ZLIB_SUPPORT) 1166c2c66affSColin Finck unsigned char *compress_buf; /*!< zlib data buffer */ 1167cbda039fSThomas Faber #endif /* MBEDTLS_ZLIB_SUPPORT */ 1168c2c66affSColin Finck #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING) 1169c2c66affSColin Finck signed char split_done; /*!< current record already splitted? */ 1170cbda039fSThomas Faber #endif /* MBEDTLS_SSL_CBC_RECORD_SPLITTING */ 1171c2c66affSColin Finck 1172c2c66affSColin Finck /* 1173c2c66affSColin Finck * PKI layer 1174c2c66affSColin Finck */ 1175c2c66affSColin Finck int client_auth; /*!< flag for client auth. */ 1176c2c66affSColin Finck 1177c2c66affSColin Finck /* 1178c2c66affSColin Finck * User settings 1179c2c66affSColin Finck */ 1180c2c66affSColin Finck #if defined(MBEDTLS_X509_CRT_PARSE_C) 1181c2c66affSColin Finck char *hostname; /*!< expected peer CN for verification 1182c2c66affSColin Finck (and SNI if available) */ 1183cbda039fSThomas Faber #endif /* MBEDTLS_X509_CRT_PARSE_C */ 1184c2c66affSColin Finck 1185c2c66affSColin Finck #if defined(MBEDTLS_SSL_ALPN) 1186c2c66affSColin Finck const char *alpn_chosen; /*!< negotiated protocol */ 1187cbda039fSThomas Faber #endif /* MBEDTLS_SSL_ALPN */ 1188c2c66affSColin Finck 1189c2c66affSColin Finck /* 1190c2c66affSColin Finck * Information for DTLS hello verify 1191c2c66affSColin Finck */ 1192c2c66affSColin Finck #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C) 1193c2c66affSColin Finck unsigned char *cli_id; /*!< transport-level ID of the client */ 1194c2c66affSColin Finck size_t cli_id_len; /*!< length of cli_id */ 1195cbda039fSThomas Faber #endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY && MBEDTLS_SSL_SRV_C */ 1196c2c66affSColin Finck 1197c2c66affSColin Finck /* 1198c2c66affSColin Finck * Secure renegotiation 1199c2c66affSColin Finck */ 1200c2c66affSColin Finck /* needed to know when to send extension on server */ 1201c2c66affSColin Finck int secure_renegotiation; /*!< does peer support legacy or 1202c2c66affSColin Finck secure renegotiation */ 1203c2c66affSColin Finck #if defined(MBEDTLS_SSL_RENEGOTIATION) 1204c2c66affSColin Finck size_t verify_data_len; /*!< length of verify data stored */ 1205c2c66affSColin Finck char own_verify_data[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN]; /*!< previous handshake verify data */ 1206c2c66affSColin Finck char peer_verify_data[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN]; /*!< previous handshake verify data */ 1207cbda039fSThomas Faber #endif /* MBEDTLS_SSL_RENEGOTIATION */ 1208c2c66affSColin Finck }; 1209c2c66affSColin Finck 1210c2c66affSColin Finck #if defined(MBEDTLS_SSL_HW_RECORD_ACCEL) 1211c2c66affSColin Finck 1212c2c66affSColin Finck #define MBEDTLS_SSL_CHANNEL_OUTBOUND 0 1213c2c66affSColin Finck #define MBEDTLS_SSL_CHANNEL_INBOUND 1 1214c2c66affSColin Finck 1215c2c66affSColin Finck extern int (*mbedtls_ssl_hw_record_init)(mbedtls_ssl_context *ssl, 1216c2c66affSColin Finck const unsigned char *key_enc, const unsigned char *key_dec, 1217c2c66affSColin Finck size_t keylen, 1218c2c66affSColin Finck const unsigned char *iv_enc, const unsigned char *iv_dec, 1219c2c66affSColin Finck size_t ivlen, 1220c2c66affSColin Finck const unsigned char *mac_enc, const unsigned char *mac_dec, 1221c2c66affSColin Finck size_t maclen); 1222c2c66affSColin Finck extern int (*mbedtls_ssl_hw_record_activate)(mbedtls_ssl_context *ssl, int direction); 1223c2c66affSColin Finck extern int (*mbedtls_ssl_hw_record_reset)(mbedtls_ssl_context *ssl); 1224c2c66affSColin Finck extern int (*mbedtls_ssl_hw_record_write)(mbedtls_ssl_context *ssl); 1225c2c66affSColin Finck extern int (*mbedtls_ssl_hw_record_read)(mbedtls_ssl_context *ssl); 1226c2c66affSColin Finck extern int (*mbedtls_ssl_hw_record_finish)(mbedtls_ssl_context *ssl); 1227c2c66affSColin Finck #endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */ 1228c2c66affSColin Finck 1229c2c66affSColin Finck /** 1230c2c66affSColin Finck * \brief Return the name of the ciphersuite associated with the 1231c2c66affSColin Finck * given ID 1232c2c66affSColin Finck * 1233c2c66affSColin Finck * \param ciphersuite_id SSL ciphersuite ID 1234c2c66affSColin Finck * 1235c2c66affSColin Finck * \return a string containing the ciphersuite name 1236c2c66affSColin Finck */ 1237c2c66affSColin Finck const char *mbedtls_ssl_get_ciphersuite_name( const int ciphersuite_id ); 1238c2c66affSColin Finck 1239c2c66affSColin Finck /** 1240c2c66affSColin Finck * \brief Return the ID of the ciphersuite associated with the 1241c2c66affSColin Finck * given name 1242c2c66affSColin Finck * 1243c2c66affSColin Finck * \param ciphersuite_name SSL ciphersuite name 1244c2c66affSColin Finck * 1245c2c66affSColin Finck * \return the ID with the ciphersuite or 0 if not found 1246c2c66affSColin Finck */ 1247c2c66affSColin Finck int mbedtls_ssl_get_ciphersuite_id( const char *ciphersuite_name ); 1248c2c66affSColin Finck 1249c2c66affSColin Finck /** 1250c2c66affSColin Finck * \brief Initialize an SSL context 1251c2c66affSColin Finck * Just makes the context ready for mbedtls_ssl_setup() or 1252c2c66affSColin Finck * mbedtls_ssl_free() 1253c2c66affSColin Finck * 1254c2c66affSColin Finck * \param ssl SSL context 1255c2c66affSColin Finck */ 1256c2c66affSColin Finck void mbedtls_ssl_init( mbedtls_ssl_context *ssl ); 1257c2c66affSColin Finck 1258c2c66affSColin Finck /** 1259c2c66affSColin Finck * \brief Set up an SSL context for use 1260c2c66affSColin Finck * 1261c2c66affSColin Finck * \note No copy of the configuration context is made, it can be 1262c2c66affSColin Finck * shared by many mbedtls_ssl_context structures. 1263c2c66affSColin Finck * 1264d9e6c9b5SThomas Faber * \warning The conf structure will be accessed during the session. 1265d9e6c9b5SThomas Faber * It must not be modified or freed as long as the session 1266d9e6c9b5SThomas Faber * is active. 1267d9e6c9b5SThomas Faber * 1268d9e6c9b5SThomas Faber * \warning This function must be called exactly once per context. 1269d9e6c9b5SThomas Faber * Calling mbedtls_ssl_setup again is not supported, even 1270d9e6c9b5SThomas Faber * if no session is active. 1271c2c66affSColin Finck * 1272c2c66affSColin Finck * \param ssl SSL context 1273c2c66affSColin Finck * \param conf SSL configuration to use 1274c2c66affSColin Finck * 1275c2c66affSColin Finck * \return 0 if successful, or MBEDTLS_ERR_SSL_ALLOC_FAILED if 1276c2c66affSColin Finck * memory allocation failed 1277c2c66affSColin Finck */ 1278c2c66affSColin Finck int mbedtls_ssl_setup( mbedtls_ssl_context *ssl, 1279c2c66affSColin Finck const mbedtls_ssl_config *conf ); 1280c2c66affSColin Finck 1281c2c66affSColin Finck /** 1282c2c66affSColin Finck * \brief Reset an already initialized SSL context for re-use 1283c2c66affSColin Finck * while retaining application-set variables, function 1284c2c66affSColin Finck * pointers and data. 1285c2c66affSColin Finck * 1286c2c66affSColin Finck * \param ssl SSL context 1287c2c66affSColin Finck * \return 0 if successful, or MBEDTLS_ERR_SSL_ALLOC_FAILED, 1288c2c66affSColin Finck MBEDTLS_ERR_SSL_HW_ACCEL_FAILED or 1289c2c66affSColin Finck * MBEDTLS_ERR_SSL_COMPRESSION_FAILED 1290c2c66affSColin Finck */ 1291c2c66affSColin Finck int mbedtls_ssl_session_reset( mbedtls_ssl_context *ssl ); 1292c2c66affSColin Finck 1293c2c66affSColin Finck /** 1294c2c66affSColin Finck * \brief Set the current endpoint type 1295c2c66affSColin Finck * 1296c2c66affSColin Finck * \param conf SSL configuration 1297c2c66affSColin Finck * \param endpoint must be MBEDTLS_SSL_IS_CLIENT or MBEDTLS_SSL_IS_SERVER 1298c2c66affSColin Finck */ 1299c2c66affSColin Finck void mbedtls_ssl_conf_endpoint( mbedtls_ssl_config *conf, int endpoint ); 1300c2c66affSColin Finck 1301c2c66affSColin Finck /** 1302c2c66affSColin Finck * \brief Set the transport type (TLS or DTLS). 1303c2c66affSColin Finck * Default: TLS 1304c2c66affSColin Finck * 1305c2c66affSColin Finck * \note For DTLS, you must either provide a recv callback that 1306c2c66affSColin Finck * doesn't block, or one that handles timeouts, see 1307c2c66affSColin Finck * \c mbedtls_ssl_set_bio(). You also need to provide timer 1308c2c66affSColin Finck * callbacks with \c mbedtls_ssl_set_timer_cb(). 1309c2c66affSColin Finck * 1310c2c66affSColin Finck * \param conf SSL configuration 1311c2c66affSColin Finck * \param transport transport type: 1312c2c66affSColin Finck * MBEDTLS_SSL_TRANSPORT_STREAM for TLS, 1313c2c66affSColin Finck * MBEDTLS_SSL_TRANSPORT_DATAGRAM for DTLS. 1314c2c66affSColin Finck */ 1315c2c66affSColin Finck void mbedtls_ssl_conf_transport( mbedtls_ssl_config *conf, int transport ); 1316c2c66affSColin Finck 1317c2c66affSColin Finck /** 1318c2c66affSColin Finck * \brief Set the certificate verification mode 1319c2c66affSColin Finck * Default: NONE on server, REQUIRED on client 1320c2c66affSColin Finck * 1321c2c66affSColin Finck * \param conf SSL configuration 1322c2c66affSColin Finck * \param authmode can be: 1323c2c66affSColin Finck * 1324c2c66affSColin Finck * MBEDTLS_SSL_VERIFY_NONE: peer certificate is not checked 1325c2c66affSColin Finck * (default on server) 1326c2c66affSColin Finck * (insecure on client) 1327c2c66affSColin Finck * 1328c2c66affSColin Finck * MBEDTLS_SSL_VERIFY_OPTIONAL: peer certificate is checked, however the 1329c2c66affSColin Finck * handshake continues even if verification failed; 1330c2c66affSColin Finck * mbedtls_ssl_get_verify_result() can be called after the 1331c2c66affSColin Finck * handshake is complete. 1332c2c66affSColin Finck * 1333c2c66affSColin Finck * MBEDTLS_SSL_VERIFY_REQUIRED: peer *must* present a valid certificate, 1334c2c66affSColin Finck * handshake is aborted if verification failed. 1335c2c66affSColin Finck * (default on client) 1336c2c66affSColin Finck * 1337c2c66affSColin Finck * \note On client, MBEDTLS_SSL_VERIFY_REQUIRED is the recommended mode. 1338c2c66affSColin Finck * With MBEDTLS_SSL_VERIFY_OPTIONAL, the user needs to call mbedtls_ssl_get_verify_result() at 1339c2c66affSColin Finck * the right time(s), which may not be obvious, while REQUIRED always perform 1340c2c66affSColin Finck * the verification as soon as possible. For example, REQUIRED was protecting 1341c2c66affSColin Finck * against the "triple handshake" attack even before it was found. 1342c2c66affSColin Finck */ 1343c2c66affSColin Finck void mbedtls_ssl_conf_authmode( mbedtls_ssl_config *conf, int authmode ); 1344c2c66affSColin Finck 1345c2c66affSColin Finck #if defined(MBEDTLS_X509_CRT_PARSE_C) 1346c2c66affSColin Finck /** 1347c2c66affSColin Finck * \brief Set the verification callback (Optional). 1348c2c66affSColin Finck * 1349c2c66affSColin Finck * If set, the verify callback is called for each 1350c2c66affSColin Finck * certificate in the chain. For implementation 1351c2c66affSColin Finck * information, please see \c mbedtls_x509_crt_verify() 1352c2c66affSColin Finck * 1353c2c66affSColin Finck * \param conf SSL configuration 1354c2c66affSColin Finck * \param f_vrfy verification function 1355c2c66affSColin Finck * \param p_vrfy verification parameter 1356c2c66affSColin Finck */ 1357c2c66affSColin Finck void mbedtls_ssl_conf_verify( mbedtls_ssl_config *conf, 1358c2c66affSColin Finck int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *), 1359c2c66affSColin Finck void *p_vrfy ); 1360c2c66affSColin Finck #endif /* MBEDTLS_X509_CRT_PARSE_C */ 1361c2c66affSColin Finck 1362c2c66affSColin Finck /** 1363c2c66affSColin Finck * \brief Set the random number generator callback 1364c2c66affSColin Finck * 1365c2c66affSColin Finck * \param conf SSL configuration 1366c2c66affSColin Finck * \param f_rng RNG function 1367c2c66affSColin Finck * \param p_rng RNG parameter 1368c2c66affSColin Finck */ 1369c2c66affSColin Finck void mbedtls_ssl_conf_rng( mbedtls_ssl_config *conf, 1370c2c66affSColin Finck int (*f_rng)(void *, unsigned char *, size_t), 1371c2c66affSColin Finck void *p_rng ); 1372c2c66affSColin Finck 1373c2c66affSColin Finck /** 1374c2c66affSColin Finck * \brief Set the debug callback 1375c2c66affSColin Finck * 1376c2c66affSColin Finck * The callback has the following argument: 1377c2c66affSColin Finck * void * opaque context for the callback 1378c2c66affSColin Finck * int debug level 1379c2c66affSColin Finck * const char * file name 1380c2c66affSColin Finck * int line number 1381c2c66affSColin Finck * const char * message 1382c2c66affSColin Finck * 1383c2c66affSColin Finck * \param conf SSL configuration 1384c2c66affSColin Finck * \param f_dbg debug function 1385c2c66affSColin Finck * \param p_dbg debug parameter 1386c2c66affSColin Finck */ 1387c2c66affSColin Finck void mbedtls_ssl_conf_dbg( mbedtls_ssl_config *conf, 1388c2c66affSColin Finck void (*f_dbg)(void *, int, const char *, int, const char *), 1389c2c66affSColin Finck void *p_dbg ); 1390c2c66affSColin Finck 1391c2c66affSColin Finck /** 1392c2c66affSColin Finck * \brief Set the underlying BIO callbacks for write, read and 1393c2c66affSColin Finck * read-with-timeout. 1394c2c66affSColin Finck * 1395c2c66affSColin Finck * \param ssl SSL context 1396c2c66affSColin Finck * \param p_bio parameter (context) shared by BIO callbacks 1397c2c66affSColin Finck * \param f_send write callback 1398c2c66affSColin Finck * \param f_recv read callback 1399c2c66affSColin Finck * \param f_recv_timeout blocking read callback with timeout. 1400c2c66affSColin Finck * 1401c2c66affSColin Finck * \note One of f_recv or f_recv_timeout can be NULL, in which case 1402c2c66affSColin Finck * the other is used. If both are non-NULL, f_recv_timeout is 1403c2c66affSColin Finck * used and f_recv is ignored (as if it were NULL). 1404c2c66affSColin Finck * 1405c2c66affSColin Finck * \note The two most common use cases are: 1406c2c66affSColin Finck * - non-blocking I/O, f_recv != NULL, f_recv_timeout == NULL 1407c2c66affSColin Finck * - blocking I/O, f_recv == NULL, f_recv_timout != NULL 1408c2c66affSColin Finck * 1409c2c66affSColin Finck * \note For DTLS, you need to provide either a non-NULL 1410c2c66affSColin Finck * f_recv_timeout callback, or a f_recv that doesn't block. 1411c2c66affSColin Finck * 14122e53fc8eSThomas Faber * \note See the documentations of \c mbedtls_ssl_send_t, 1413c2c66affSColin Finck * \c mbedtls_ssl_recv_t and \c mbedtls_ssl_recv_timeout_t for 1414c2c66affSColin Finck * the conventions those callbacks must follow. 1415c2c66affSColin Finck * 1416c2c66affSColin Finck * \note On some platforms, net_sockets.c provides 1417c2c66affSColin Finck * \c mbedtls_net_send(), \c mbedtls_net_recv() and 1418c2c66affSColin Finck * \c mbedtls_net_recv_timeout() that are suitable to be used 1419c2c66affSColin Finck * here. 1420c2c66affSColin Finck */ 1421c2c66affSColin Finck void mbedtls_ssl_set_bio( mbedtls_ssl_context *ssl, 1422c2c66affSColin Finck void *p_bio, 1423c2c66affSColin Finck mbedtls_ssl_send_t *f_send, 1424c2c66affSColin Finck mbedtls_ssl_recv_t *f_recv, 1425c2c66affSColin Finck mbedtls_ssl_recv_timeout_t *f_recv_timeout ); 1426c2c66affSColin Finck 1427cbda039fSThomas Faber #if defined(MBEDTLS_SSL_PROTO_DTLS) 1428cbda039fSThomas Faber /** 1429cbda039fSThomas Faber * \brief Set the Maximum Tranport Unit (MTU). 1430cbda039fSThomas Faber * Special value: 0 means unset (no limit). 1431cbda039fSThomas Faber * This represents the maximum size of a datagram payload 1432cbda039fSThomas Faber * handled by the transport layer (usually UDP) as determined 1433cbda039fSThomas Faber * by the network link and stack. In practice, this controls 1434cbda039fSThomas Faber * the maximum size datagram the DTLS layer will pass to the 1435cbda039fSThomas Faber * \c f_send() callback set using \c mbedtls_ssl_set_bio(). 1436cbda039fSThomas Faber * 1437cbda039fSThomas Faber * \note The limit on datagram size is converted to a limit on 1438cbda039fSThomas Faber * record payload by subtracting the current overhead of 1439cbda039fSThomas Faber * encapsulation and encryption/authentication if any. 1440cbda039fSThomas Faber * 1441cbda039fSThomas Faber * \note This can be called at any point during the connection, for 1442cbda039fSThomas Faber * example when a Path Maximum Transfer Unit (PMTU) 1443cbda039fSThomas Faber * estimate becomes available from other sources, 1444cbda039fSThomas Faber * such as lower (or higher) protocol layers. 1445cbda039fSThomas Faber * 1446cbda039fSThomas Faber * \note This setting only controls the size of the packets we send, 1447cbda039fSThomas Faber * and does not restrict the size of the datagrams we're 1448cbda039fSThomas Faber * willing to receive. Client-side, you can request the 1449cbda039fSThomas Faber * server to use smaller records with \c 1450cbda039fSThomas Faber * mbedtls_ssl_conf_max_frag_len(). 1451cbda039fSThomas Faber * 1452cbda039fSThomas Faber * \note If both a MTU and a maximum fragment length have been 1453cbda039fSThomas Faber * configured (or negotiated with the peer), the resulting 1454cbda039fSThomas Faber * lower limit on record payload (see first note) is used. 1455cbda039fSThomas Faber * 1456cbda039fSThomas Faber * \note This can only be used to decrease the maximum size 1457cbda039fSThomas Faber * of datagrams (hence records, see first note) sent. It 1458cbda039fSThomas Faber * cannot be used to increase the maximum size of records over 1459cbda039fSThomas Faber * the limit set by #MBEDTLS_SSL_OUT_CONTENT_LEN. 1460cbda039fSThomas Faber * 1461cbda039fSThomas Faber * \note Values lower than the current record layer expansion will 1462cbda039fSThomas Faber * result in an error when trying to send data. 1463cbda039fSThomas Faber * 1464cbda039fSThomas Faber * \note Using record compression together with a non-zero MTU value 1465cbda039fSThomas Faber * will result in an error when trying to send data. 1466cbda039fSThomas Faber * 1467cbda039fSThomas Faber * \param ssl SSL context 1468cbda039fSThomas Faber * \param mtu Value of the path MTU in bytes 1469cbda039fSThomas Faber */ 1470cbda039fSThomas Faber void mbedtls_ssl_set_mtu( mbedtls_ssl_context *ssl, uint16_t mtu ); 1471cbda039fSThomas Faber #endif /* MBEDTLS_SSL_PROTO_DTLS */ 1472cbda039fSThomas Faber 1473c2c66affSColin Finck /** 1474c2c66affSColin Finck * \brief Set the timeout period for mbedtls_ssl_read() 1475c2c66affSColin Finck * (Default: no timeout.) 1476c2c66affSColin Finck * 1477c2c66affSColin Finck * \param conf SSL configuration context 1478c2c66affSColin Finck * \param timeout Timeout value in milliseconds. 1479c2c66affSColin Finck * Use 0 for no timeout (default). 1480c2c66affSColin Finck * 1481c2c66affSColin Finck * \note With blocking I/O, this will only work if a non-NULL 1482c2c66affSColin Finck * \c f_recv_timeout was set with \c mbedtls_ssl_set_bio(). 1483c2c66affSColin Finck * With non-blocking I/O, this will only work if timer 1484c2c66affSColin Finck * callbacks were set with \c mbedtls_ssl_set_timer_cb(). 1485c2c66affSColin Finck * 1486c2c66affSColin Finck * \note With non-blocking I/O, you may also skip this function 1487c2c66affSColin Finck * altogether and handle timeouts at the application layer. 1488c2c66affSColin Finck */ 1489c2c66affSColin Finck void mbedtls_ssl_conf_read_timeout( mbedtls_ssl_config *conf, uint32_t timeout ); 1490c2c66affSColin Finck 1491c2c66affSColin Finck /** 1492c2c66affSColin Finck * \brief Set the timer callbacks (Mandatory for DTLS.) 1493c2c66affSColin Finck * 1494c2c66affSColin Finck * \param ssl SSL context 1495c2c66affSColin Finck * \param p_timer parameter (context) shared by timer callbacks 1496c2c66affSColin Finck * \param f_set_timer set timer callback 1497c2c66affSColin Finck * \param f_get_timer get timer callback. Must return: 1498c2c66affSColin Finck * 1499c2c66affSColin Finck * \note See the documentation of \c mbedtls_ssl_set_timer_t and 1500c2c66affSColin Finck * \c mbedtls_ssl_get_timer_t for the conventions this pair of 1501c2c66affSColin Finck * callbacks must follow. 1502c2c66affSColin Finck * 1503c2c66affSColin Finck * \note On some platforms, timing.c provides 1504c2c66affSColin Finck * \c mbedtls_timing_set_delay() and 1505c2c66affSColin Finck * \c mbedtls_timing_get_delay() that are suitable for using 1506c2c66affSColin Finck * here, except if using an event-driven style. 1507c2c66affSColin Finck * 1508c2c66affSColin Finck * \note See also the "DTLS tutorial" article in our knowledge base. 1509c2c66affSColin Finck * https://tls.mbed.org/kb/how-to/dtls-tutorial 1510c2c66affSColin Finck */ 1511c2c66affSColin Finck void mbedtls_ssl_set_timer_cb( mbedtls_ssl_context *ssl, 1512c2c66affSColin Finck void *p_timer, 1513c2c66affSColin Finck mbedtls_ssl_set_timer_t *f_set_timer, 1514c2c66affSColin Finck mbedtls_ssl_get_timer_t *f_get_timer ); 1515c2c66affSColin Finck 1516c2c66affSColin Finck /** 1517c2c66affSColin Finck * \brief Callback type: generate and write session ticket 1518c2c66affSColin Finck * 1519c2c66affSColin Finck * \note This describes what a callback implementation should do. 1520c2c66affSColin Finck * This callback should generate an encrypted and 1521c2c66affSColin Finck * authenticated ticket for the session and write it to the 1522c2c66affSColin Finck * output buffer. Here, ticket means the opaque ticket part 1523c2c66affSColin Finck * of the NewSessionTicket structure of RFC 5077. 1524c2c66affSColin Finck * 1525c2c66affSColin Finck * \param p_ticket Context for the callback 1526c2c66affSColin Finck * \param session SSL session to be written in the ticket 1527c2c66affSColin Finck * \param start Start of the output buffer 1528c2c66affSColin Finck * \param end End of the output buffer 1529c2c66affSColin Finck * \param tlen On exit, holds the length written 1530c2c66affSColin Finck * \param lifetime On exit, holds the lifetime of the ticket in seconds 1531c2c66affSColin Finck * 1532c2c66affSColin Finck * \return 0 if successful, or 1533c2c66affSColin Finck * a specific MBEDTLS_ERR_XXX code. 1534c2c66affSColin Finck */ 1535c2c66affSColin Finck typedef int mbedtls_ssl_ticket_write_t( void *p_ticket, 1536c2c66affSColin Finck const mbedtls_ssl_session *session, 1537c2c66affSColin Finck unsigned char *start, 1538c2c66affSColin Finck const unsigned char *end, 1539c2c66affSColin Finck size_t *tlen, 1540c2c66affSColin Finck uint32_t *lifetime ); 1541c2c66affSColin Finck 1542c2c66affSColin Finck #if defined(MBEDTLS_SSL_EXPORT_KEYS) 1543c2c66affSColin Finck /** 1544c2c66affSColin Finck * \brief Callback type: Export key block and master secret 1545c2c66affSColin Finck * 1546c2c66affSColin Finck * \note This is required for certain uses of TLS, e.g. EAP-TLS 1547c2c66affSColin Finck * (RFC 5216) and Thread. The key pointers are ephemeral and 1548c2c66affSColin Finck * therefore must not be stored. The master secret and keys 1549c2c66affSColin Finck * should not be used directly except as an input to a key 1550c2c66affSColin Finck * derivation function. 1551c2c66affSColin Finck * 1552c2c66affSColin Finck * \param p_expkey Context for the callback 1553c2c66affSColin Finck * \param ms Pointer to master secret (fixed length: 48 bytes) 1554c2c66affSColin Finck * \param kb Pointer to key block, see RFC 5246 section 6.3 1555c2c66affSColin Finck * (variable length: 2 * maclen + 2 * keylen + 2 * ivlen). 1556c2c66affSColin Finck * \param maclen MAC length 1557c2c66affSColin Finck * \param keylen Key length 1558c2c66affSColin Finck * \param ivlen IV length 1559c2c66affSColin Finck * 1560c2c66affSColin Finck * \return 0 if successful, or 1561c2c66affSColin Finck * a specific MBEDTLS_ERR_XXX code. 1562c2c66affSColin Finck */ 1563c2c66affSColin Finck typedef int mbedtls_ssl_export_keys_t( void *p_expkey, 1564c2c66affSColin Finck const unsigned char *ms, 1565c2c66affSColin Finck const unsigned char *kb, 1566c2c66affSColin Finck size_t maclen, 1567c2c66affSColin Finck size_t keylen, 1568c2c66affSColin Finck size_t ivlen ); 1569c2c66affSColin Finck #endif /* MBEDTLS_SSL_EXPORT_KEYS */ 1570c2c66affSColin Finck 1571c2c66affSColin Finck /** 1572c2c66affSColin Finck * \brief Callback type: parse and load session ticket 1573c2c66affSColin Finck * 1574c2c66affSColin Finck * \note This describes what a callback implementation should do. 1575c2c66affSColin Finck * This callback should parse a session ticket as generated 1576c2c66affSColin Finck * by the corresponding mbedtls_ssl_ticket_write_t function, 1577c2c66affSColin Finck * and, if the ticket is authentic and valid, load the 1578c2c66affSColin Finck * session. 1579c2c66affSColin Finck * 1580c2c66affSColin Finck * \note The implementation is allowed to modify the first len 1581c2c66affSColin Finck * bytes of the input buffer, eg to use it as a temporary 1582c2c66affSColin Finck * area for the decrypted ticket contents. 1583c2c66affSColin Finck * 1584c2c66affSColin Finck * \param p_ticket Context for the callback 1585c2c66affSColin Finck * \param session SSL session to be loaded 1586c2c66affSColin Finck * \param buf Start of the buffer containing the ticket 1587c2c66affSColin Finck * \param len Length of the ticket. 1588c2c66affSColin Finck * 1589c2c66affSColin Finck * \return 0 if successful, or 1590c2c66affSColin Finck * MBEDTLS_ERR_SSL_INVALID_MAC if not authentic, or 1591c2c66affSColin Finck * MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED if expired, or 1592c2c66affSColin Finck * any other non-zero code for other failures. 1593c2c66affSColin Finck */ 1594c2c66affSColin Finck typedef int mbedtls_ssl_ticket_parse_t( void *p_ticket, 1595c2c66affSColin Finck mbedtls_ssl_session *session, 1596c2c66affSColin Finck unsigned char *buf, 1597c2c66affSColin Finck size_t len ); 1598c2c66affSColin Finck 1599c2c66affSColin Finck #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C) 1600c2c66affSColin Finck /** 1601c2c66affSColin Finck * \brief Configure SSL session ticket callbacks (server only). 1602c2c66affSColin Finck * (Default: none.) 1603c2c66affSColin Finck * 1604c2c66affSColin Finck * \note On server, session tickets are enabled by providing 1605c2c66affSColin Finck * non-NULL callbacks. 1606c2c66affSColin Finck * 1607c2c66affSColin Finck * \note On client, use \c mbedtls_ssl_conf_session_tickets(). 1608c2c66affSColin Finck * 1609c2c66affSColin Finck * \param conf SSL configuration context 1610c2c66affSColin Finck * \param f_ticket_write Callback for writing a ticket 1611c2c66affSColin Finck * \param f_ticket_parse Callback for parsing a ticket 1612c2c66affSColin Finck * \param p_ticket Context shared by the two callbacks 1613c2c66affSColin Finck */ 1614c2c66affSColin Finck void mbedtls_ssl_conf_session_tickets_cb( mbedtls_ssl_config *conf, 1615c2c66affSColin Finck mbedtls_ssl_ticket_write_t *f_ticket_write, 1616c2c66affSColin Finck mbedtls_ssl_ticket_parse_t *f_ticket_parse, 1617c2c66affSColin Finck void *p_ticket ); 1618c2c66affSColin Finck #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */ 1619c2c66affSColin Finck 1620c2c66affSColin Finck #if defined(MBEDTLS_SSL_EXPORT_KEYS) 1621c2c66affSColin Finck /** 1622c2c66affSColin Finck * \brief Configure key export callback. 1623c2c66affSColin Finck * (Default: none.) 1624c2c66affSColin Finck * 1625c2c66affSColin Finck * \note See \c mbedtls_ssl_export_keys_t. 1626c2c66affSColin Finck * 1627c2c66affSColin Finck * \param conf SSL configuration context 1628c2c66affSColin Finck * \param f_export_keys Callback for exporting keys 1629c2c66affSColin Finck * \param p_export_keys Context for the callback 1630c2c66affSColin Finck */ 1631c2c66affSColin Finck void mbedtls_ssl_conf_export_keys_cb( mbedtls_ssl_config *conf, 1632c2c66affSColin Finck mbedtls_ssl_export_keys_t *f_export_keys, 1633c2c66affSColin Finck void *p_export_keys ); 1634c2c66affSColin Finck #endif /* MBEDTLS_SSL_EXPORT_KEYS */ 1635c2c66affSColin Finck 1636cbda039fSThomas Faber #if defined(MBEDTLS_SSL_ASYNC_PRIVATE) 1637cbda039fSThomas Faber /** 1638cbda039fSThomas Faber * \brief Configure asynchronous private key operation callbacks. 1639cbda039fSThomas Faber * 1640cbda039fSThomas Faber * \param conf SSL configuration context 1641cbda039fSThomas Faber * \param f_async_sign Callback to start a signature operation. See 1642cbda039fSThomas Faber * the description of ::mbedtls_ssl_async_sign_t 1643cbda039fSThomas Faber * for more information. This may be \c NULL if the 1644cbda039fSThomas Faber * external processor does not support any signature 1645cbda039fSThomas Faber * operation; in this case the private key object 1646cbda039fSThomas Faber * associated with the certificate will be used. 1647cbda039fSThomas Faber * \param f_async_decrypt Callback to start a decryption operation. See 1648cbda039fSThomas Faber * the description of ::mbedtls_ssl_async_decrypt_t 1649cbda039fSThomas Faber * for more information. This may be \c NULL if the 1650cbda039fSThomas Faber * external processor does not support any decryption 1651cbda039fSThomas Faber * operation; in this case the private key object 1652cbda039fSThomas Faber * associated with the certificate will be used. 1653cbda039fSThomas Faber * \param f_async_resume Callback to resume an asynchronous operation. See 1654cbda039fSThomas Faber * the description of ::mbedtls_ssl_async_resume_t 1655cbda039fSThomas Faber * for more information. This may not be \c NULL unless 1656cbda039fSThomas Faber * \p f_async_sign and \p f_async_decrypt are both 1657cbda039fSThomas Faber * \c NULL. 1658cbda039fSThomas Faber * \param f_async_cancel Callback to cancel an asynchronous operation. See 1659cbda039fSThomas Faber * the description of ::mbedtls_ssl_async_cancel_t 1660cbda039fSThomas Faber * for more information. This may be \c NULL if 1661cbda039fSThomas Faber * no cleanup is needed. 1662cbda039fSThomas Faber * \param config_data A pointer to configuration data which can be 1663cbda039fSThomas Faber * retrieved with 1664cbda039fSThomas Faber * mbedtls_ssl_conf_get_async_config_data(). The 1665cbda039fSThomas Faber * library stores this value without dereferencing it. 1666cbda039fSThomas Faber */ 1667cbda039fSThomas Faber void mbedtls_ssl_conf_async_private_cb( mbedtls_ssl_config *conf, 1668cbda039fSThomas Faber mbedtls_ssl_async_sign_t *f_async_sign, 1669cbda039fSThomas Faber mbedtls_ssl_async_decrypt_t *f_async_decrypt, 1670cbda039fSThomas Faber mbedtls_ssl_async_resume_t *f_async_resume, 1671cbda039fSThomas Faber mbedtls_ssl_async_cancel_t *f_async_cancel, 1672cbda039fSThomas Faber void *config_data ); 1673cbda039fSThomas Faber 1674cbda039fSThomas Faber /** 1675cbda039fSThomas Faber * \brief Retrieve the configuration data set by 1676cbda039fSThomas Faber * mbedtls_ssl_conf_async_private_cb(). 1677cbda039fSThomas Faber * 1678cbda039fSThomas Faber * \param conf SSL configuration context 1679cbda039fSThomas Faber * \return The configuration data set by 1680cbda039fSThomas Faber * mbedtls_ssl_conf_async_private_cb(). 1681cbda039fSThomas Faber */ 1682cbda039fSThomas Faber void *mbedtls_ssl_conf_get_async_config_data( const mbedtls_ssl_config *conf ); 1683cbda039fSThomas Faber 1684cbda039fSThomas Faber /** 1685cbda039fSThomas Faber * \brief Retrieve the asynchronous operation user context. 1686cbda039fSThomas Faber * 1687cbda039fSThomas Faber * \note This function may only be called while a handshake 1688cbda039fSThomas Faber * is in progress. 1689cbda039fSThomas Faber * 1690cbda039fSThomas Faber * \param ssl The SSL context to access. 1691cbda039fSThomas Faber * 1692cbda039fSThomas Faber * \return The asynchronous operation user context that was last 1693cbda039fSThomas Faber * set during the current handshake. If 1694cbda039fSThomas Faber * mbedtls_ssl_set_async_operation_data() has not yet been 1695cbda039fSThomas Faber * called during the current handshake, this function returns 1696cbda039fSThomas Faber * \c NULL. 1697cbda039fSThomas Faber */ 1698cbda039fSThomas Faber void *mbedtls_ssl_get_async_operation_data( const mbedtls_ssl_context *ssl ); 1699cbda039fSThomas Faber 1700cbda039fSThomas Faber /** 1701cbda039fSThomas Faber * \brief Retrieve the asynchronous operation user context. 1702cbda039fSThomas Faber * 1703cbda039fSThomas Faber * \note This function may only be called while a handshake 1704cbda039fSThomas Faber * is in progress. 1705cbda039fSThomas Faber * 1706cbda039fSThomas Faber * \param ssl The SSL context to access. 1707cbda039fSThomas Faber * \param ctx The new value of the asynchronous operation user context. 1708cbda039fSThomas Faber * Call mbedtls_ssl_get_async_operation_data() later during the 1709cbda039fSThomas Faber * same handshake to retrieve this value. 1710cbda039fSThomas Faber */ 1711cbda039fSThomas Faber void mbedtls_ssl_set_async_operation_data( mbedtls_ssl_context *ssl, 1712cbda039fSThomas Faber void *ctx ); 1713cbda039fSThomas Faber #endif /* MBEDTLS_SSL_ASYNC_PRIVATE */ 1714cbda039fSThomas Faber 1715c2c66affSColin Finck /** 1716c2c66affSColin Finck * \brief Callback type: generate a cookie 1717c2c66affSColin Finck * 1718c2c66affSColin Finck * \param ctx Context for the callback 1719c2c66affSColin Finck * \param p Buffer to write to, 1720c2c66affSColin Finck * must be updated to point right after the cookie 1721c2c66affSColin Finck * \param end Pointer to one past the end of the output buffer 1722c2c66affSColin Finck * \param info Client ID info that was passed to 1723c2c66affSColin Finck * \c mbedtls_ssl_set_client_transport_id() 1724c2c66affSColin Finck * \param ilen Length of info in bytes 1725c2c66affSColin Finck * 1726c2c66affSColin Finck * \return The callback must return 0 on success, 1727c2c66affSColin Finck * or a negative error code. 1728c2c66affSColin Finck */ 1729c2c66affSColin Finck typedef int mbedtls_ssl_cookie_write_t( void *ctx, 1730c2c66affSColin Finck unsigned char **p, unsigned char *end, 1731c2c66affSColin Finck const unsigned char *info, size_t ilen ); 1732c2c66affSColin Finck 1733c2c66affSColin Finck /** 1734c2c66affSColin Finck * \brief Callback type: verify a cookie 1735c2c66affSColin Finck * 1736c2c66affSColin Finck * \param ctx Context for the callback 1737c2c66affSColin Finck * \param cookie Cookie to verify 1738c2c66affSColin Finck * \param clen Length of cookie 1739c2c66affSColin Finck * \param info Client ID info that was passed to 1740c2c66affSColin Finck * \c mbedtls_ssl_set_client_transport_id() 1741c2c66affSColin Finck * \param ilen Length of info in bytes 1742c2c66affSColin Finck * 1743c2c66affSColin Finck * \return The callback must return 0 if cookie is valid, 1744c2c66affSColin Finck * or a negative error code. 1745c2c66affSColin Finck */ 1746c2c66affSColin Finck typedef int mbedtls_ssl_cookie_check_t( void *ctx, 1747c2c66affSColin Finck const unsigned char *cookie, size_t clen, 1748c2c66affSColin Finck const unsigned char *info, size_t ilen ); 1749c2c66affSColin Finck 1750c2c66affSColin Finck #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C) 1751c2c66affSColin Finck /** 1752c2c66affSColin Finck * \brief Register callbacks for DTLS cookies 1753c2c66affSColin Finck * (Server only. DTLS only.) 1754c2c66affSColin Finck * 1755c2c66affSColin Finck * Default: dummy callbacks that fail, in order to force you to 1756c2c66affSColin Finck * register working callbacks (and initialize their context). 1757c2c66affSColin Finck * 1758c2c66affSColin Finck * To disable HelloVerifyRequest, register NULL callbacks. 1759c2c66affSColin Finck * 1760c2c66affSColin Finck * \warning Disabling hello verification allows your server to be used 1761c2c66affSColin Finck * for amplification in DoS attacks against other hosts. 1762c2c66affSColin Finck * Only disable if you known this can't happen in your 1763c2c66affSColin Finck * particular environment. 1764c2c66affSColin Finck * 1765c2c66affSColin Finck * \note See comments on \c mbedtls_ssl_handshake() about handling 1766c2c66affSColin Finck * the MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED that is expected 1767c2c66affSColin Finck * on the first handshake attempt when this is enabled. 1768c2c66affSColin Finck * 1769c2c66affSColin Finck * \note This is also necessary to handle client reconnection from 1770c2c66affSColin Finck * the same port as described in RFC 6347 section 4.2.8 (only 1771c2c66affSColin Finck * the variant with cookies is supported currently). See 1772c2c66affSColin Finck * comments on \c mbedtls_ssl_read() for details. 1773c2c66affSColin Finck * 1774c2c66affSColin Finck * \param conf SSL configuration 1775c2c66affSColin Finck * \param f_cookie_write Cookie write callback 1776c2c66affSColin Finck * \param f_cookie_check Cookie check callback 1777c2c66affSColin Finck * \param p_cookie Context for both callbacks 1778c2c66affSColin Finck */ 1779c2c66affSColin Finck void mbedtls_ssl_conf_dtls_cookies( mbedtls_ssl_config *conf, 1780c2c66affSColin Finck mbedtls_ssl_cookie_write_t *f_cookie_write, 1781c2c66affSColin Finck mbedtls_ssl_cookie_check_t *f_cookie_check, 1782c2c66affSColin Finck void *p_cookie ); 1783c2c66affSColin Finck 1784c2c66affSColin Finck /** 1785c2c66affSColin Finck * \brief Set client's transport-level identification info. 1786c2c66affSColin Finck * (Server only. DTLS only.) 1787c2c66affSColin Finck * 1788c2c66affSColin Finck * This is usually the IP address (and port), but could be 1789c2c66affSColin Finck * anything identify the client depending on the underlying 1790c2c66affSColin Finck * network stack. Used for HelloVerifyRequest with DTLS. 1791c2c66affSColin Finck * This is *not* used to route the actual packets. 1792c2c66affSColin Finck * 1793c2c66affSColin Finck * \param ssl SSL context 1794c2c66affSColin Finck * \param info Transport-level info identifying the client (eg IP + port) 1795c2c66affSColin Finck * \param ilen Length of info in bytes 1796c2c66affSColin Finck * 1797c2c66affSColin Finck * \note An internal copy is made, so the info buffer can be reused. 1798c2c66affSColin Finck * 1799c2c66affSColin Finck * \return 0 on success, 1800c2c66affSColin Finck * MBEDTLS_ERR_SSL_BAD_INPUT_DATA if used on client, 1801c2c66affSColin Finck * MBEDTLS_ERR_SSL_ALLOC_FAILED if out of memory. 1802c2c66affSColin Finck */ 1803c2c66affSColin Finck int mbedtls_ssl_set_client_transport_id( mbedtls_ssl_context *ssl, 1804c2c66affSColin Finck const unsigned char *info, 1805c2c66affSColin Finck size_t ilen ); 1806c2c66affSColin Finck 1807c2c66affSColin Finck #endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY && MBEDTLS_SSL_SRV_C */ 1808c2c66affSColin Finck 1809c2c66affSColin Finck #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY) 1810c2c66affSColin Finck /** 1811c2c66affSColin Finck * \brief Enable or disable anti-replay protection for DTLS. 1812c2c66affSColin Finck * (DTLS only, no effect on TLS.) 1813c2c66affSColin Finck * Default: enabled. 1814c2c66affSColin Finck * 1815c2c66affSColin Finck * \param conf SSL configuration 1816c2c66affSColin Finck * \param mode MBEDTLS_SSL_ANTI_REPLAY_ENABLED or MBEDTLS_SSL_ANTI_REPLAY_DISABLED. 1817c2c66affSColin Finck * 1818c2c66affSColin Finck * \warning Disabling this is a security risk unless the application 1819c2c66affSColin Finck * protocol handles duplicated packets in a safe way. You 1820c2c66affSColin Finck * should not disable this without careful consideration. 1821c2c66affSColin Finck * However, if your application already detects duplicated 1822c2c66affSColin Finck * packets and needs information about them to adjust its 1823c2c66affSColin Finck * transmission strategy, then you'll want to disable this. 1824c2c66affSColin Finck */ 1825c2c66affSColin Finck void mbedtls_ssl_conf_dtls_anti_replay( mbedtls_ssl_config *conf, char mode ); 1826c2c66affSColin Finck #endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */ 1827c2c66affSColin Finck 1828c2c66affSColin Finck #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT) 1829c2c66affSColin Finck /** 1830c2c66affSColin Finck * \brief Set a limit on the number of records with a bad MAC 1831c2c66affSColin Finck * before terminating the connection. 1832c2c66affSColin Finck * (DTLS only, no effect on TLS.) 1833c2c66affSColin Finck * Default: 0 (disabled). 1834c2c66affSColin Finck * 1835c2c66affSColin Finck * \param conf SSL configuration 1836c2c66affSColin Finck * \param limit Limit, or 0 to disable. 1837c2c66affSColin Finck * 1838c2c66affSColin Finck * \note If the limit is N, then the connection is terminated when 1839c2c66affSColin Finck * the Nth non-authentic record is seen. 1840c2c66affSColin Finck * 1841c2c66affSColin Finck * \note Records with an invalid header are not counted, only the 1842c2c66affSColin Finck * ones going through the authentication-decryption phase. 1843c2c66affSColin Finck * 1844c2c66affSColin Finck * \note This is a security trade-off related to the fact that it's 1845c2c66affSColin Finck * often relatively easy for an active attacker ot inject UDP 1846c2c66affSColin Finck * datagrams. On one hand, setting a low limit here makes it 1847c2c66affSColin Finck * easier for such an attacker to forcibly terminated a 1848c2c66affSColin Finck * connection. On the other hand, a high limit or no limit 1849c2c66affSColin Finck * might make us waste resources checking authentication on 1850c2c66affSColin Finck * many bogus packets. 1851c2c66affSColin Finck */ 1852c2c66affSColin Finck void mbedtls_ssl_conf_dtls_badmac_limit( mbedtls_ssl_config *conf, unsigned limit ); 1853c2c66affSColin Finck #endif /* MBEDTLS_SSL_DTLS_BADMAC_LIMIT */ 1854c2c66affSColin Finck 1855c2c66affSColin Finck #if defined(MBEDTLS_SSL_PROTO_DTLS) 1856cbda039fSThomas Faber 1857cbda039fSThomas Faber /** 1858cbda039fSThomas Faber * \brief Allow or disallow packing of multiple handshake records 1859cbda039fSThomas Faber * within a single datagram. 1860cbda039fSThomas Faber * 1861cbda039fSThomas Faber * \param ssl The SSL context to configure. 1862cbda039fSThomas Faber * \param allow_packing This determines whether datagram packing may 1863cbda039fSThomas Faber * be used or not. A value of \c 0 means that every 1864cbda039fSThomas Faber * record will be sent in a separate datagram; a 1865cbda039fSThomas Faber * value of \c 1 means that, if space permits, 1866cbda039fSThomas Faber * multiple handshake messages (including CCS) belonging to 1867cbda039fSThomas Faber * a single flight may be packed within a single datagram. 1868cbda039fSThomas Faber * 1869cbda039fSThomas Faber * \note This is enabled by default and should only be disabled 1870cbda039fSThomas Faber * for test purposes, or if datagram packing causes 1871cbda039fSThomas Faber * interoperability issues with peers that don't support it. 1872cbda039fSThomas Faber * 1873cbda039fSThomas Faber * \note Allowing datagram packing reduces the network load since 1874cbda039fSThomas Faber * there's less overhead if multiple messages share the same 1875cbda039fSThomas Faber * datagram. Also, it increases the handshake efficiency 1876cbda039fSThomas Faber * since messages belonging to a single datagram will not 1877cbda039fSThomas Faber * be reordered in transit, and so future message buffering 1878cbda039fSThomas Faber * or flight retransmission (if no buffering is used) as 1879cbda039fSThomas Faber * means to deal with reordering are needed less frequently. 1880cbda039fSThomas Faber * 1881cbda039fSThomas Faber * \note Application records are not affected by this option and 1882cbda039fSThomas Faber * are currently always sent in separate datagrams. 1883cbda039fSThomas Faber * 1884cbda039fSThomas Faber */ 1885cbda039fSThomas Faber void mbedtls_ssl_set_datagram_packing( mbedtls_ssl_context *ssl, 1886cbda039fSThomas Faber unsigned allow_packing ); 1887cbda039fSThomas Faber 1888c2c66affSColin Finck /** 1889c2c66affSColin Finck * \brief Set retransmit timeout values for the DTLS handshake. 1890c2c66affSColin Finck * (DTLS only, no effect on TLS.) 1891c2c66affSColin Finck * 1892c2c66affSColin Finck * \param conf SSL configuration 1893c2c66affSColin Finck * \param min Initial timeout value in milliseconds. 1894c2c66affSColin Finck * Default: 1000 (1 second). 1895c2c66affSColin Finck * \param max Maximum timeout value in milliseconds. 1896c2c66affSColin Finck * Default: 60000 (60 seconds). 1897c2c66affSColin Finck * 1898c2c66affSColin Finck * \note Default values are from RFC 6347 section 4.2.4.1. 1899c2c66affSColin Finck * 1900c2c66affSColin Finck * \note The 'min' value should typically be slightly above the 1901c2c66affSColin Finck * expected round-trip time to your peer, plus whatever time 1902c2c66affSColin Finck * it takes for the peer to process the message. For example, 1903c2c66affSColin Finck * if your RTT is about 600ms and you peer needs up to 1s to 1904c2c66affSColin Finck * do the cryptographic operations in the handshake, then you 1905c2c66affSColin Finck * should set 'min' slightly above 1600. Lower values of 'min' 1906c2c66affSColin Finck * might cause spurious resends which waste network resources, 1907c2c66affSColin Finck * while larger value of 'min' will increase overall latency 1908c2c66affSColin Finck * on unreliable network links. 1909c2c66affSColin Finck * 1910c2c66affSColin Finck * \note The more unreliable your network connection is, the larger 1911c2c66affSColin Finck * your max / min ratio needs to be in order to achieve 1912c2c66affSColin Finck * reliable handshakes. 1913c2c66affSColin Finck * 1914c2c66affSColin Finck * \note Messages are retransmitted up to log2(ceil(max/min)) times. 1915c2c66affSColin Finck * For example, if min = 1s and max = 5s, the retransmit plan 1916c2c66affSColin Finck * goes: send ... 1s -> resend ... 2s -> resend ... 4s -> 1917c2c66affSColin Finck * resend ... 5s -> give up and return a timeout error. 1918c2c66affSColin Finck */ 1919c2c66affSColin Finck void mbedtls_ssl_conf_handshake_timeout( mbedtls_ssl_config *conf, uint32_t min, uint32_t max ); 1920c2c66affSColin Finck #endif /* MBEDTLS_SSL_PROTO_DTLS */ 1921c2c66affSColin Finck 1922c2c66affSColin Finck #if defined(MBEDTLS_SSL_SRV_C) 1923c2c66affSColin Finck /** 1924c2c66affSColin Finck * \brief Set the session cache callbacks (server-side only) 1925c2c66affSColin Finck * If not set, no session resuming is done (except if session 1926c2c66affSColin Finck * tickets are enabled too). 1927c2c66affSColin Finck * 1928c2c66affSColin Finck * The session cache has the responsibility to check for stale 1929c2c66affSColin Finck * entries based on timeout. See RFC 5246 for recommendations. 1930c2c66affSColin Finck * 1931c2c66affSColin Finck * Warning: session.peer_cert is cleared by the SSL/TLS layer on 1932c2c66affSColin Finck * connection shutdown, so do not cache the pointer! Either set 1933c2c66affSColin Finck * it to NULL or make a full copy of the certificate. 1934c2c66affSColin Finck * 1935c2c66affSColin Finck * The get callback is called once during the initial handshake 1936c2c66affSColin Finck * to enable session resuming. The get function has the 1937c2c66affSColin Finck * following parameters: (void *parameter, mbedtls_ssl_session *session) 1938c2c66affSColin Finck * If a valid entry is found, it should fill the master of 1939c2c66affSColin Finck * the session object with the cached values and return 0, 1940c2c66affSColin Finck * return 1 otherwise. Optionally peer_cert can be set as well 1941c2c66affSColin Finck * if it is properly present in cache entry. 1942c2c66affSColin Finck * 1943c2c66affSColin Finck * The set callback is called once during the initial handshake 1944c2c66affSColin Finck * to enable session resuming after the entire handshake has 1945c2c66affSColin Finck * been finished. The set function has the following parameters: 1946c2c66affSColin Finck * (void *parameter, const mbedtls_ssl_session *session). The function 1947c2c66affSColin Finck * should create a cache entry for future retrieval based on 1948c2c66affSColin Finck * the data in the session structure and should keep in mind 1949c2c66affSColin Finck * that the mbedtls_ssl_session object presented (and all its referenced 1950c2c66affSColin Finck * data) is cleared by the SSL/TLS layer when the connection is 1951c2c66affSColin Finck * terminated. It is recommended to add metadata to determine if 1952c2c66affSColin Finck * an entry is still valid in the future. Return 0 if 1953c2c66affSColin Finck * successfully cached, return 1 otherwise. 1954c2c66affSColin Finck * 1955c2c66affSColin Finck * \param conf SSL configuration 1956c2c66affSColin Finck * \param p_cache parmater (context) for both callbacks 1957c2c66affSColin Finck * \param f_get_cache session get callback 1958c2c66affSColin Finck * \param f_set_cache session set callback 1959c2c66affSColin Finck */ 1960c2c66affSColin Finck void mbedtls_ssl_conf_session_cache( mbedtls_ssl_config *conf, 1961c2c66affSColin Finck void *p_cache, 1962c2c66affSColin Finck int (*f_get_cache)(void *, mbedtls_ssl_session *), 1963c2c66affSColin Finck int (*f_set_cache)(void *, const mbedtls_ssl_session *) ); 1964c2c66affSColin Finck #endif /* MBEDTLS_SSL_SRV_C */ 1965c2c66affSColin Finck 1966c2c66affSColin Finck #if defined(MBEDTLS_SSL_CLI_C) 1967c2c66affSColin Finck /** 1968c2c66affSColin Finck * \brief Request resumption of session (client-side only) 1969c2c66affSColin Finck * Session data is copied from presented session structure. 1970c2c66affSColin Finck * 1971c2c66affSColin Finck * \param ssl SSL context 1972c2c66affSColin Finck * \param session session context 1973c2c66affSColin Finck * 1974c2c66affSColin Finck * \return 0 if successful, 1975c2c66affSColin Finck * MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed, 1976c2c66affSColin Finck * MBEDTLS_ERR_SSL_BAD_INPUT_DATA if used server-side or 1977c2c66affSColin Finck * arguments are otherwise invalid 1978c2c66affSColin Finck * 1979c2c66affSColin Finck * \sa mbedtls_ssl_get_session() 1980c2c66affSColin Finck */ 1981c2c66affSColin Finck int mbedtls_ssl_set_session( mbedtls_ssl_context *ssl, const mbedtls_ssl_session *session ); 1982c2c66affSColin Finck #endif /* MBEDTLS_SSL_CLI_C */ 1983c2c66affSColin Finck 1984c2c66affSColin Finck /** 1985c2c66affSColin Finck * \brief Set the list of allowed ciphersuites and the preference 1986c2c66affSColin Finck * order. First in the list has the highest preference. 1987c2c66affSColin Finck * (Overrides all version-specific lists) 1988c2c66affSColin Finck * 1989c2c66affSColin Finck * The ciphersuites array is not copied, and must remain 1990c2c66affSColin Finck * valid for the lifetime of the ssl_config. 1991c2c66affSColin Finck * 1992c2c66affSColin Finck * Note: The server uses its own preferences 1993c2c66affSColin Finck * over the preference of the client unless 1994c2c66affSColin Finck * MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE is defined! 1995c2c66affSColin Finck * 1996c2c66affSColin Finck * \param conf SSL configuration 1997c2c66affSColin Finck * \param ciphersuites 0-terminated list of allowed ciphersuites 1998c2c66affSColin Finck */ 1999c2c66affSColin Finck void mbedtls_ssl_conf_ciphersuites( mbedtls_ssl_config *conf, 2000c2c66affSColin Finck const int *ciphersuites ); 2001c2c66affSColin Finck 2002c2c66affSColin Finck /** 2003c2c66affSColin Finck * \brief Set the list of allowed ciphersuites and the 2004c2c66affSColin Finck * preference order for a specific version of the protocol. 2005c2c66affSColin Finck * (Only useful on the server side) 2006c2c66affSColin Finck * 2007c2c66affSColin Finck * The ciphersuites array is not copied, and must remain 2008c2c66affSColin Finck * valid for the lifetime of the ssl_config. 2009c2c66affSColin Finck * 2010c2c66affSColin Finck * \param conf SSL configuration 2011c2c66affSColin Finck * \param ciphersuites 0-terminated list of allowed ciphersuites 2012c2c66affSColin Finck * \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3 2013c2c66affSColin Finck * supported) 2014c2c66affSColin Finck * \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0, 2015c2c66affSColin Finck * MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2, 2016c2c66affSColin Finck * MBEDTLS_SSL_MINOR_VERSION_3 supported) 2017c2c66affSColin Finck * 2018c2c66affSColin Finck * \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_2 for DTLS 1.0 2019c2c66affSColin Finck * and MBEDTLS_SSL_MINOR_VERSION_3 for DTLS 1.2 2020c2c66affSColin Finck */ 2021c2c66affSColin Finck void mbedtls_ssl_conf_ciphersuites_for_version( mbedtls_ssl_config *conf, 2022c2c66affSColin Finck const int *ciphersuites, 2023c2c66affSColin Finck int major, int minor ); 2024c2c66affSColin Finck 2025c2c66affSColin Finck #if defined(MBEDTLS_X509_CRT_PARSE_C) 2026c2c66affSColin Finck /** 2027c2c66affSColin Finck * \brief Set the X.509 security profile used for verification 2028c2c66affSColin Finck * 2029c2c66affSColin Finck * \note The restrictions are enforced for all certificates in the 2030c2c66affSColin Finck * chain. However, signatures in the handshake are not covered 2031c2c66affSColin Finck * by this setting but by \b mbedtls_ssl_conf_sig_hashes(). 2032c2c66affSColin Finck * 2033c2c66affSColin Finck * \param conf SSL configuration 2034c2c66affSColin Finck * \param profile Profile to use 2035c2c66affSColin Finck */ 2036c2c66affSColin Finck void mbedtls_ssl_conf_cert_profile( mbedtls_ssl_config *conf, 2037c2c66affSColin Finck const mbedtls_x509_crt_profile *profile ); 2038c2c66affSColin Finck 2039c2c66affSColin Finck /** 2040c2c66affSColin Finck * \brief Set the data required to verify peer certificate 2041c2c66affSColin Finck * 2042d9e6c9b5SThomas Faber * \note See \c mbedtls_x509_crt_verify() for notes regarding the 2043d9e6c9b5SThomas Faber * parameters ca_chain (maps to trust_ca for that function) 2044d9e6c9b5SThomas Faber * and ca_crl. 2045d9e6c9b5SThomas Faber * 2046c2c66affSColin Finck * \param conf SSL configuration 2047c2c66affSColin Finck * \param ca_chain trusted CA chain (meaning all fully trusted top-level CAs) 2048c2c66affSColin Finck * \param ca_crl trusted CA CRLs 2049c2c66affSColin Finck */ 2050c2c66affSColin Finck void mbedtls_ssl_conf_ca_chain( mbedtls_ssl_config *conf, 2051c2c66affSColin Finck mbedtls_x509_crt *ca_chain, 2052c2c66affSColin Finck mbedtls_x509_crl *ca_crl ); 2053c2c66affSColin Finck 2054c2c66affSColin Finck /** 2055c2c66affSColin Finck * \brief Set own certificate chain and private key 2056c2c66affSColin Finck * 2057c2c66affSColin Finck * \note own_cert should contain in order from the bottom up your 2058c2c66affSColin Finck * certificate chain. The top certificate (self-signed) 2059c2c66affSColin Finck * can be omitted. 2060c2c66affSColin Finck * 2061c2c66affSColin Finck * \note On server, this function can be called multiple times to 2062c2c66affSColin Finck * provision more than one cert/key pair (eg one ECDSA, one 2063c2c66affSColin Finck * RSA with SHA-256, one RSA with SHA-1). An adequate 2064c2c66affSColin Finck * certificate will be selected according to the client's 2065c1eccaffSThomas Faber * advertised capabilities. In case multiple certificates are 2066c2c66affSColin Finck * adequate, preference is given to the one set by the first 2067c2c66affSColin Finck * call to this function, then second, etc. 2068c2c66affSColin Finck * 2069c2c66affSColin Finck * \note On client, only the first call has any effect. That is, 2070c2c66affSColin Finck * only one client certificate can be provisioned. The 2071c2c66affSColin Finck * server's preferences in its CertficateRequest message will 2072c2c66affSColin Finck * be ignored and our only cert will be sent regardless of 2073c2c66affSColin Finck * whether it matches those preferences - the server can then 2074c2c66affSColin Finck * decide what it wants to do with it. 2075c2c66affSColin Finck * 20760ba5bc40SThomas Faber * \note The provided \p pk_key needs to match the public key in the 20770ba5bc40SThomas Faber * first certificate in \p own_cert, or all handshakes using 20780ba5bc40SThomas Faber * that certificate will fail. It is your responsibility 20790ba5bc40SThomas Faber * to ensure that; this function will not perform any check. 20800ba5bc40SThomas Faber * You may use mbedtls_pk_check_pair() in order to perform 20810ba5bc40SThomas Faber * this check yourself, but be aware that this function can 20820ba5bc40SThomas Faber * be computationally expensive on some key types. 20830ba5bc40SThomas Faber * 2084c2c66affSColin Finck * \param conf SSL configuration 2085c2c66affSColin Finck * \param own_cert own public certificate chain 2086c2c66affSColin Finck * \param pk_key own private key 2087c2c66affSColin Finck * 2088c2c66affSColin Finck * \return 0 on success or MBEDTLS_ERR_SSL_ALLOC_FAILED 2089c2c66affSColin Finck */ 2090c2c66affSColin Finck int mbedtls_ssl_conf_own_cert( mbedtls_ssl_config *conf, 2091c2c66affSColin Finck mbedtls_x509_crt *own_cert, 2092c2c66affSColin Finck mbedtls_pk_context *pk_key ); 2093c2c66affSColin Finck #endif /* MBEDTLS_X509_CRT_PARSE_C */ 2094c2c66affSColin Finck 2095c2c66affSColin Finck #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) 2096c2c66affSColin Finck /** 2097c2c66affSColin Finck * \brief Set the Pre Shared Key (PSK) and the expected identity name 2098c2c66affSColin Finck * 2099c2c66affSColin Finck * \note This is mainly useful for clients. Servers will usually 2100c2c66affSColin Finck * want to use \c mbedtls_ssl_conf_psk_cb() instead. 2101c2c66affSColin Finck * 2102c2c66affSColin Finck * \note Currently clients can only register one pre-shared key. 2103c2c66affSColin Finck * In other words, the servers' identity hint is ignored. 2104c2c66affSColin Finck * Support for setting multiple PSKs on clients and selecting 2105c2c66affSColin Finck * one based on the identity hint is not a planned feature but 2106c2c66affSColin Finck * feedback is welcomed. 2107c2c66affSColin Finck * 2108c2c66affSColin Finck * \param conf SSL configuration 2109c2c66affSColin Finck * \param psk pointer to the pre-shared key 2110c2c66affSColin Finck * \param psk_len pre-shared key length 2111c2c66affSColin Finck * \param psk_identity pointer to the pre-shared key identity 2112c2c66affSColin Finck * \param psk_identity_len identity key length 2113c2c66affSColin Finck * 2114c2c66affSColin Finck * \return 0 if successful or MBEDTLS_ERR_SSL_ALLOC_FAILED 2115c2c66affSColin Finck */ 2116c2c66affSColin Finck int mbedtls_ssl_conf_psk( mbedtls_ssl_config *conf, 2117c2c66affSColin Finck const unsigned char *psk, size_t psk_len, 2118c2c66affSColin Finck const unsigned char *psk_identity, size_t psk_identity_len ); 2119c2c66affSColin Finck 2120c2c66affSColin Finck 2121c2c66affSColin Finck /** 2122c2c66affSColin Finck * \brief Set the Pre Shared Key (PSK) for the current handshake 2123c2c66affSColin Finck * 2124c2c66affSColin Finck * \note This should only be called inside the PSK callback, 2125c2c66affSColin Finck * ie the function passed to \c mbedtls_ssl_conf_psk_cb(). 2126c2c66affSColin Finck * 2127c2c66affSColin Finck * \param ssl SSL context 2128c2c66affSColin Finck * \param psk pointer to the pre-shared key 2129c2c66affSColin Finck * \param psk_len pre-shared key length 2130c2c66affSColin Finck * 2131c2c66affSColin Finck * \return 0 if successful or MBEDTLS_ERR_SSL_ALLOC_FAILED 2132c2c66affSColin Finck */ 2133c2c66affSColin Finck int mbedtls_ssl_set_hs_psk( mbedtls_ssl_context *ssl, 2134c2c66affSColin Finck const unsigned char *psk, size_t psk_len ); 2135c2c66affSColin Finck 2136c2c66affSColin Finck /** 2137c2c66affSColin Finck * \brief Set the PSK callback (server-side only). 2138c2c66affSColin Finck * 2139c2c66affSColin Finck * If set, the PSK callback is called for each 2140c2c66affSColin Finck * handshake where a PSK ciphersuite was negotiated. 2141c2c66affSColin Finck * The caller provides the identity received and wants to 2142c2c66affSColin Finck * receive the actual PSK data and length. 2143c2c66affSColin Finck * 2144c2c66affSColin Finck * The callback has the following parameters: (void *parameter, 2145c2c66affSColin Finck * mbedtls_ssl_context *ssl, const unsigned char *psk_identity, 2146c2c66affSColin Finck * size_t identity_len) 2147c2c66affSColin Finck * If a valid PSK identity is found, the callback should use 2148c2c66affSColin Finck * \c mbedtls_ssl_set_hs_psk() on the ssl context to set the 2149c2c66affSColin Finck * correct PSK and return 0. 2150c2c66affSColin Finck * Any other return value will result in a denied PSK identity. 2151c2c66affSColin Finck * 2152c2c66affSColin Finck * \note If you set a PSK callback using this function, then you 2153c2c66affSColin Finck * don't need to set a PSK key and identity using 2154c2c66affSColin Finck * \c mbedtls_ssl_conf_psk(). 2155c2c66affSColin Finck * 2156c2c66affSColin Finck * \param conf SSL configuration 2157c2c66affSColin Finck * \param f_psk PSK identity function 2158c2c66affSColin Finck * \param p_psk PSK identity parameter 2159c2c66affSColin Finck */ 2160c2c66affSColin Finck void mbedtls_ssl_conf_psk_cb( mbedtls_ssl_config *conf, 2161c2c66affSColin Finck int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *, 2162c2c66affSColin Finck size_t), 2163c2c66affSColin Finck void *p_psk ); 2164c2c66affSColin Finck #endif /* MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED */ 2165c2c66affSColin Finck 2166c2c66affSColin Finck #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_SRV_C) 2167d9e6c9b5SThomas Faber 2168d9e6c9b5SThomas Faber #if !defined(MBEDTLS_DEPRECATED_REMOVED) 2169d9e6c9b5SThomas Faber 2170d9e6c9b5SThomas Faber #if defined(MBEDTLS_DEPRECATED_WARNING) 2171d9e6c9b5SThomas Faber #define MBEDTLS_DEPRECATED __attribute__((deprecated)) 2172d9e6c9b5SThomas Faber #else 2173d9e6c9b5SThomas Faber #define MBEDTLS_DEPRECATED 2174d9e6c9b5SThomas Faber #endif 2175d9e6c9b5SThomas Faber 2176c2c66affSColin Finck /** 2177c2c66affSColin Finck * \brief Set the Diffie-Hellman public P and G values, 2178c2c66affSColin Finck * read as hexadecimal strings (server-side only) 2179d9e6c9b5SThomas Faber * (Default values: MBEDTLS_DHM_RFC3526_MODP_2048_[PG]) 2180c2c66affSColin Finck * 2181c2c66affSColin Finck * \param conf SSL configuration 2182c2c66affSColin Finck * \param dhm_P Diffie-Hellman-Merkle modulus 2183c2c66affSColin Finck * \param dhm_G Diffie-Hellman-Merkle generator 2184c2c66affSColin Finck * 2185d9e6c9b5SThomas Faber * \deprecated Superseded by \c mbedtls_ssl_conf_dh_param_bin. 2186d9e6c9b5SThomas Faber * 2187c2c66affSColin Finck * \return 0 if successful 2188c2c66affSColin Finck */ 2189d9e6c9b5SThomas Faber MBEDTLS_DEPRECATED int mbedtls_ssl_conf_dh_param( mbedtls_ssl_config *conf, 2190d9e6c9b5SThomas Faber const char *dhm_P, 2191d9e6c9b5SThomas Faber const char *dhm_G ); 2192d9e6c9b5SThomas Faber 2193d9e6c9b5SThomas Faber #endif /* MBEDTLS_DEPRECATED_REMOVED */ 2194d9e6c9b5SThomas Faber 2195d9e6c9b5SThomas Faber /** 2196d9e6c9b5SThomas Faber * \brief Set the Diffie-Hellman public P and G values 2197d9e6c9b5SThomas Faber * from big-endian binary presentations. 2198d9e6c9b5SThomas Faber * (Default values: MBEDTLS_DHM_RFC3526_MODP_2048_[PG]_BIN) 2199d9e6c9b5SThomas Faber * 2200d9e6c9b5SThomas Faber * \param conf SSL configuration 2201d9e6c9b5SThomas Faber * \param dhm_P Diffie-Hellman-Merkle modulus in big-endian binary form 2202d9e6c9b5SThomas Faber * \param P_len Length of DHM modulus 2203d9e6c9b5SThomas Faber * \param dhm_G Diffie-Hellman-Merkle generator in big-endian binary form 2204d9e6c9b5SThomas Faber * \param G_len Length of DHM generator 2205d9e6c9b5SThomas Faber * 2206d9e6c9b5SThomas Faber * \return 0 if successful 2207d9e6c9b5SThomas Faber */ 2208d9e6c9b5SThomas Faber int mbedtls_ssl_conf_dh_param_bin( mbedtls_ssl_config *conf, 2209d9e6c9b5SThomas Faber const unsigned char *dhm_P, size_t P_len, 2210d9e6c9b5SThomas Faber const unsigned char *dhm_G, size_t G_len ); 2211c2c66affSColin Finck 2212c2c66affSColin Finck /** 2213c2c66affSColin Finck * \brief Set the Diffie-Hellman public P and G values, 2214c2c66affSColin Finck * read from existing context (server-side only) 2215c2c66affSColin Finck * 2216c2c66affSColin Finck * \param conf SSL configuration 2217c2c66affSColin Finck * \param dhm_ctx Diffie-Hellman-Merkle context 2218c2c66affSColin Finck * 2219c2c66affSColin Finck * \return 0 if successful 2220c2c66affSColin Finck */ 2221c2c66affSColin Finck int mbedtls_ssl_conf_dh_param_ctx( mbedtls_ssl_config *conf, mbedtls_dhm_context *dhm_ctx ); 2222c2c66affSColin Finck #endif /* MBEDTLS_DHM_C && defined(MBEDTLS_SSL_SRV_C) */ 2223c2c66affSColin Finck 2224c2c66affSColin Finck #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C) 2225c2c66affSColin Finck /** 2226c2c66affSColin Finck * \brief Set the minimum length for Diffie-Hellman parameters. 2227c2c66affSColin Finck * (Client-side only.) 2228c2c66affSColin Finck * (Default: 1024 bits.) 2229c2c66affSColin Finck * 2230c2c66affSColin Finck * \param conf SSL configuration 2231c2c66affSColin Finck * \param bitlen Minimum bit length of the DHM prime 2232c2c66affSColin Finck */ 2233c2c66affSColin Finck void mbedtls_ssl_conf_dhm_min_bitlen( mbedtls_ssl_config *conf, 2234c2c66affSColin Finck unsigned int bitlen ); 2235c2c66affSColin Finck #endif /* MBEDTLS_DHM_C && MBEDTLS_SSL_CLI_C */ 2236c2c66affSColin Finck 2237c2c66affSColin Finck #if defined(MBEDTLS_ECP_C) 2238c2c66affSColin Finck /** 2239c2c66affSColin Finck * \brief Set the allowed curves in order of preference. 2240*103a79ceSThomas Faber * (Default: all defined curves in order of decreasing size.) 2241c2c66affSColin Finck * 2242c2c66affSColin Finck * On server: this only affects selection of the ECDHE curve; 2243c2c66affSColin Finck * the curves used for ECDH and ECDSA are determined by the 2244c2c66affSColin Finck * list of available certificates instead. 2245c2c66affSColin Finck * 2246c2c66affSColin Finck * On client: this affects the list of curves offered for any 2247c2c66affSColin Finck * use. The server can override our preference order. 2248c2c66affSColin Finck * 2249c2c66affSColin Finck * Both sides: limits the set of curves accepted for use in 2250c2c66affSColin Finck * ECDHE and in the peer's end-entity certificate. 2251c2c66affSColin Finck * 2252c2c66affSColin Finck * \note This has no influence on which curves are allowed inside the 2253c2c66affSColin Finck * certificate chains, see \c mbedtls_ssl_conf_cert_profile() 2254c2c66affSColin Finck * for that. For the end-entity certificate however, the key 2255c2c66affSColin Finck * will be accepted only if it is allowed both by this list 2256c2c66affSColin Finck * and by the cert profile. 2257c2c66affSColin Finck * 2258c2c66affSColin Finck * \note This list should be ordered by decreasing preference 2259c2c66affSColin Finck * (preferred curve first). 2260c2c66affSColin Finck * 2261c2c66affSColin Finck * \param conf SSL configuration 2262c2c66affSColin Finck * \param curves Ordered list of allowed curves, 2263c2c66affSColin Finck * terminated by MBEDTLS_ECP_DP_NONE. 2264c2c66affSColin Finck */ 2265c2c66affSColin Finck void mbedtls_ssl_conf_curves( mbedtls_ssl_config *conf, 2266c2c66affSColin Finck const mbedtls_ecp_group_id *curves ); 2267c2c66affSColin Finck #endif /* MBEDTLS_ECP_C */ 2268c2c66affSColin Finck 2269c2c66affSColin Finck #if defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED) 2270c2c66affSColin Finck /** 2271c2c66affSColin Finck * \brief Set the allowed hashes for signatures during the handshake. 2272*103a79ceSThomas Faber * (Default: all SHA-2 hashes, largest first. Also SHA-1 if 2273*103a79ceSThomas Faber * the compile-time option 2274*103a79ceSThomas Faber * `MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE` is enabled.) 2275c2c66affSColin Finck * 2276c2c66affSColin Finck * \note This only affects which hashes are offered and can be used 2277c2c66affSColin Finck * for signatures during the handshake. Hashes for message 2278c2c66affSColin Finck * authentication and the TLS PRF are controlled by the 2279c2c66affSColin Finck * ciphersuite, see \c mbedtls_ssl_conf_ciphersuites(). Hashes 2280c2c66affSColin Finck * used for certificate signature are controlled by the 2281c2c66affSColin Finck * verification profile, see \c mbedtls_ssl_conf_cert_profile(). 2282c2c66affSColin Finck * 2283c2c66affSColin Finck * \note This list should be ordered by decreasing preference 2284c2c66affSColin Finck * (preferred hash first). 2285c2c66affSColin Finck * 2286c2c66affSColin Finck * \param conf SSL configuration 2287c2c66affSColin Finck * \param hashes Ordered list of allowed signature hashes, 2288c2c66affSColin Finck * terminated by \c MBEDTLS_MD_NONE. 2289c2c66affSColin Finck */ 2290c2c66affSColin Finck void mbedtls_ssl_conf_sig_hashes( mbedtls_ssl_config *conf, 2291c2c66affSColin Finck const int *hashes ); 2292c2c66affSColin Finck #endif /* MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED */ 2293c2c66affSColin Finck 2294c2c66affSColin Finck #if defined(MBEDTLS_X509_CRT_PARSE_C) 2295c2c66affSColin Finck /** 2296d9e6c9b5SThomas Faber * \brief Set or reset the hostname to check against the received 2297d9e6c9b5SThomas Faber * server certificate. It sets the ServerName TLS extension, 2298d9e6c9b5SThomas Faber * too, if that extension is enabled. (client-side only) 2299c2c66affSColin Finck * 2300c2c66affSColin Finck * \param ssl SSL context 2301d9e6c9b5SThomas Faber * \param hostname the server hostname, may be NULL to clear hostname 2302cbda039fSThomas Faber 2303d9e6c9b5SThomas Faber * \note Maximum hostname length MBEDTLS_SSL_MAX_HOST_NAME_LEN. 2304d9e6c9b5SThomas Faber * 2305d9e6c9b5SThomas Faber * \return 0 if successful, MBEDTLS_ERR_SSL_ALLOC_FAILED on 2306d9e6c9b5SThomas Faber * allocation failure, MBEDTLS_ERR_SSL_BAD_INPUT_DATA on 2307d9e6c9b5SThomas Faber * too long input hostname. 2308d9e6c9b5SThomas Faber * 2309d9e6c9b5SThomas Faber * Hostname set to the one provided on success (cleared 2310d9e6c9b5SThomas Faber * when NULL). On allocation failure hostname is cleared. 2311d9e6c9b5SThomas Faber * On too long input failure, old hostname is unchanged. 2312c2c66affSColin Finck */ 2313c2c66affSColin Finck int mbedtls_ssl_set_hostname( mbedtls_ssl_context *ssl, const char *hostname ); 2314c2c66affSColin Finck #endif /* MBEDTLS_X509_CRT_PARSE_C */ 2315c2c66affSColin Finck 2316c2c66affSColin Finck #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) 2317c2c66affSColin Finck /** 2318c2c66affSColin Finck * \brief Set own certificate and key for the current handshake 2319c2c66affSColin Finck * 2320c2c66affSColin Finck * \note Same as \c mbedtls_ssl_conf_own_cert() but for use within 2321c2c66affSColin Finck * the SNI callback. 2322c2c66affSColin Finck * 2323c2c66affSColin Finck * \param ssl SSL context 2324c2c66affSColin Finck * \param own_cert own public certificate chain 2325c2c66affSColin Finck * \param pk_key own private key 2326c2c66affSColin Finck * 2327c2c66affSColin Finck * \return 0 on success or MBEDTLS_ERR_SSL_ALLOC_FAILED 2328c2c66affSColin Finck */ 2329c2c66affSColin Finck int mbedtls_ssl_set_hs_own_cert( mbedtls_ssl_context *ssl, 2330c2c66affSColin Finck mbedtls_x509_crt *own_cert, 2331c2c66affSColin Finck mbedtls_pk_context *pk_key ); 2332c2c66affSColin Finck 2333c2c66affSColin Finck /** 2334c2c66affSColin Finck * \brief Set the data required to verify peer certificate for the 2335c2c66affSColin Finck * current handshake 2336c2c66affSColin Finck * 2337c2c66affSColin Finck * \note Same as \c mbedtls_ssl_conf_ca_chain() but for use within 2338c2c66affSColin Finck * the SNI callback. 2339c2c66affSColin Finck * 2340c2c66affSColin Finck * \param ssl SSL context 2341c2c66affSColin Finck * \param ca_chain trusted CA chain (meaning all fully trusted top-level CAs) 2342c2c66affSColin Finck * \param ca_crl trusted CA CRLs 2343c2c66affSColin Finck */ 2344c2c66affSColin Finck void mbedtls_ssl_set_hs_ca_chain( mbedtls_ssl_context *ssl, 2345c2c66affSColin Finck mbedtls_x509_crt *ca_chain, 2346c2c66affSColin Finck mbedtls_x509_crl *ca_crl ); 2347c2c66affSColin Finck 2348c2c66affSColin Finck /** 2349c2c66affSColin Finck * \brief Set authmode for the current handshake. 2350c2c66affSColin Finck * 2351c2c66affSColin Finck * \note Same as \c mbedtls_ssl_conf_authmode() but for use within 2352c2c66affSColin Finck * the SNI callback. 2353c2c66affSColin Finck * 2354c2c66affSColin Finck * \param ssl SSL context 2355c2c66affSColin Finck * \param authmode MBEDTLS_SSL_VERIFY_NONE, MBEDTLS_SSL_VERIFY_OPTIONAL or 2356c2c66affSColin Finck * MBEDTLS_SSL_VERIFY_REQUIRED 2357c2c66affSColin Finck */ 2358c2c66affSColin Finck void mbedtls_ssl_set_hs_authmode( mbedtls_ssl_context *ssl, 2359c2c66affSColin Finck int authmode ); 2360c2c66affSColin Finck 2361c2c66affSColin Finck /** 2362c2c66affSColin Finck * \brief Set server side ServerName TLS extension callback 2363c2c66affSColin Finck * (optional, server-side only). 2364c2c66affSColin Finck * 2365c2c66affSColin Finck * If set, the ServerName callback is called whenever the 2366c2c66affSColin Finck * server receives a ServerName TLS extension from the client 2367c2c66affSColin Finck * during a handshake. The ServerName callback has the 2368c2c66affSColin Finck * following parameters: (void *parameter, mbedtls_ssl_context *ssl, 2369c2c66affSColin Finck * const unsigned char *hostname, size_t len). If a suitable 2370c2c66affSColin Finck * certificate is found, the callback must set the 2371c2c66affSColin Finck * certificate(s) and key(s) to use with \c 2372c2c66affSColin Finck * mbedtls_ssl_set_hs_own_cert() (can be called repeatedly), 2373c2c66affSColin Finck * and may optionally adjust the CA and associated CRL with \c 2374c2c66affSColin Finck * mbedtls_ssl_set_hs_ca_chain() as well as the client 2375c2c66affSColin Finck * authentication mode with \c mbedtls_ssl_set_hs_authmode(), 2376c2c66affSColin Finck * then must return 0. If no matching name is found, the 2377c2c66affSColin Finck * callback must either set a default cert, or 2378c2c66affSColin Finck * return non-zero to abort the handshake at this point. 2379c2c66affSColin Finck * 2380c2c66affSColin Finck * \param conf SSL configuration 2381c2c66affSColin Finck * \param f_sni verification function 2382c2c66affSColin Finck * \param p_sni verification parameter 2383c2c66affSColin Finck */ 2384c2c66affSColin Finck void mbedtls_ssl_conf_sni( mbedtls_ssl_config *conf, 2385c2c66affSColin Finck int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *, 2386c2c66affSColin Finck size_t), 2387c2c66affSColin Finck void *p_sni ); 2388c2c66affSColin Finck #endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */ 2389c2c66affSColin Finck 2390c2c66affSColin Finck #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) 2391c2c66affSColin Finck /** 2392c2c66affSColin Finck * \brief Set the EC J-PAKE password for current handshake. 2393c2c66affSColin Finck * 2394c2c66affSColin Finck * \note An internal copy is made, and destroyed as soon as the 2395c2c66affSColin Finck * handshake is completed, or when the SSL context is reset or 2396c2c66affSColin Finck * freed. 2397c2c66affSColin Finck * 2398c2c66affSColin Finck * \note The SSL context needs to be already set up. The right place 2399c2c66affSColin Finck * to call this function is between \c mbedtls_ssl_setup() or 2400c2c66affSColin Finck * \c mbedtls_ssl_reset() and \c mbedtls_ssl_handshake(). 2401c2c66affSColin Finck * 2402c2c66affSColin Finck * \param ssl SSL context 2403c2c66affSColin Finck * \param pw EC J-PAKE password (pre-shared secret) 2404c2c66affSColin Finck * \param pw_len length of pw in bytes 2405c2c66affSColin Finck * 2406c2c66affSColin Finck * \return 0 on success, or a negative error code. 2407c2c66affSColin Finck */ 2408c2c66affSColin Finck int mbedtls_ssl_set_hs_ecjpake_password( mbedtls_ssl_context *ssl, 2409c2c66affSColin Finck const unsigned char *pw, 2410c2c66affSColin Finck size_t pw_len ); 2411c2c66affSColin Finck #endif /*MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */ 2412c2c66affSColin Finck 2413c2c66affSColin Finck #if defined(MBEDTLS_SSL_ALPN) 2414c2c66affSColin Finck /** 2415c2c66affSColin Finck * \brief Set the supported Application Layer Protocols. 2416c2c66affSColin Finck * 2417c2c66affSColin Finck * \param conf SSL configuration 2418c2c66affSColin Finck * \param protos Pointer to a NULL-terminated list of supported protocols, 2419c2c66affSColin Finck * in decreasing preference order. The pointer to the list is 2420c2c66affSColin Finck * recorded by the library for later reference as required, so 2421c2c66affSColin Finck * the lifetime of the table must be atleast as long as the 2422c2c66affSColin Finck * lifetime of the SSL configuration structure. 2423c2c66affSColin Finck * 2424c2c66affSColin Finck * \return 0 on success, or MBEDTLS_ERR_SSL_BAD_INPUT_DATA. 2425c2c66affSColin Finck */ 2426c2c66affSColin Finck int mbedtls_ssl_conf_alpn_protocols( mbedtls_ssl_config *conf, const char **protos ); 2427c2c66affSColin Finck 2428c2c66affSColin Finck /** 2429c2c66affSColin Finck * \brief Get the name of the negotiated Application Layer Protocol. 2430c2c66affSColin Finck * This function should be called after the handshake is 2431c2c66affSColin Finck * completed. 2432c2c66affSColin Finck * 2433c2c66affSColin Finck * \param ssl SSL context 2434c2c66affSColin Finck * 2435c2c66affSColin Finck * \return Protcol name, or NULL if no protocol was negotiated. 2436c2c66affSColin Finck */ 2437c2c66affSColin Finck const char *mbedtls_ssl_get_alpn_protocol( const mbedtls_ssl_context *ssl ); 2438c2c66affSColin Finck #endif /* MBEDTLS_SSL_ALPN */ 2439c2c66affSColin Finck 2440c2c66affSColin Finck /** 2441c2c66affSColin Finck * \brief Set the maximum supported version sent from the client side 2442c2c66affSColin Finck * and/or accepted at the server side 2443c2c66affSColin Finck * (Default: MBEDTLS_SSL_MAX_MAJOR_VERSION, MBEDTLS_SSL_MAX_MINOR_VERSION) 2444c2c66affSColin Finck * 2445c2c66affSColin Finck * \note This ignores ciphersuites from higher versions. 2446c2c66affSColin Finck * 2447c2c66affSColin Finck * \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_2 for DTLS 1.0 and 2448c2c66affSColin Finck * MBEDTLS_SSL_MINOR_VERSION_3 for DTLS 1.2 2449c2c66affSColin Finck * 2450c2c66affSColin Finck * \param conf SSL configuration 2451c2c66affSColin Finck * \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3 supported) 2452c2c66affSColin Finck * \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0, 2453c2c66affSColin Finck * MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2, 2454c2c66affSColin Finck * MBEDTLS_SSL_MINOR_VERSION_3 supported) 2455c2c66affSColin Finck */ 2456c2c66affSColin Finck void mbedtls_ssl_conf_max_version( mbedtls_ssl_config *conf, int major, int minor ); 2457c2c66affSColin Finck 2458c2c66affSColin Finck /** 2459c2c66affSColin Finck * \brief Set the minimum accepted SSL/TLS protocol version 2460c2c66affSColin Finck * (Default: TLS 1.0) 2461c2c66affSColin Finck * 2462c2c66affSColin Finck * \note Input outside of the SSL_MAX_XXXXX_VERSION and 2463c2c66affSColin Finck * SSL_MIN_XXXXX_VERSION range is ignored. 2464c2c66affSColin Finck * 2465c2c66affSColin Finck * \note MBEDTLS_SSL_MINOR_VERSION_0 (SSL v3) should be avoided. 2466c2c66affSColin Finck * 2467c2c66affSColin Finck * \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_2 for DTLS 1.0 and 2468c2c66affSColin Finck * MBEDTLS_SSL_MINOR_VERSION_3 for DTLS 1.2 2469c2c66affSColin Finck * 2470c2c66affSColin Finck * \param conf SSL configuration 2471c2c66affSColin Finck * \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3 supported) 2472c2c66affSColin Finck * \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0, 2473c2c66affSColin Finck * MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2, 2474c2c66affSColin Finck * MBEDTLS_SSL_MINOR_VERSION_3 supported) 2475c2c66affSColin Finck */ 2476c2c66affSColin Finck void mbedtls_ssl_conf_min_version( mbedtls_ssl_config *conf, int major, int minor ); 2477c2c66affSColin Finck 2478c2c66affSColin Finck #if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C) 2479c2c66affSColin Finck /** 2480c2c66affSColin Finck * \brief Set the fallback flag (client-side only). 2481c2c66affSColin Finck * (Default: MBEDTLS_SSL_IS_NOT_FALLBACK). 2482c2c66affSColin Finck * 2483c2c66affSColin Finck * \note Set to MBEDTLS_SSL_IS_FALLBACK when preparing a fallback 2484c2c66affSColin Finck * connection, that is a connection with max_version set to a 2485c2c66affSColin Finck * lower value than the value you're willing to use. Such 2486c2c66affSColin Finck * fallback connections are not recommended but are sometimes 2487c2c66affSColin Finck * necessary to interoperate with buggy (version-intolerant) 2488c2c66affSColin Finck * servers. 2489c2c66affSColin Finck * 2490c2c66affSColin Finck * \warning You should NOT set this to MBEDTLS_SSL_IS_FALLBACK for 2491c2c66affSColin Finck * non-fallback connections! This would appear to work for a 2492c2c66affSColin Finck * while, then cause failures when the server is upgraded to 2493c2c66affSColin Finck * support a newer TLS version. 2494c2c66affSColin Finck * 2495c2c66affSColin Finck * \param conf SSL configuration 2496c2c66affSColin Finck * \param fallback MBEDTLS_SSL_IS_NOT_FALLBACK or MBEDTLS_SSL_IS_FALLBACK 2497c2c66affSColin Finck */ 2498c2c66affSColin Finck void mbedtls_ssl_conf_fallback( mbedtls_ssl_config *conf, char fallback ); 2499c2c66affSColin Finck #endif /* MBEDTLS_SSL_FALLBACK_SCSV && MBEDTLS_SSL_CLI_C */ 2500c2c66affSColin Finck 2501c2c66affSColin Finck #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) 2502c2c66affSColin Finck /** 2503c2c66affSColin Finck * \brief Enable or disable Encrypt-then-MAC 2504c2c66affSColin Finck * (Default: MBEDTLS_SSL_ETM_ENABLED) 2505c2c66affSColin Finck * 2506c2c66affSColin Finck * \note This should always be enabled, it is a security 2507c2c66affSColin Finck * improvement, and should not cause any interoperability 2508c2c66affSColin Finck * issue (used only if the peer supports it too). 2509c2c66affSColin Finck * 2510c2c66affSColin Finck * \param conf SSL configuration 2511c2c66affSColin Finck * \param etm MBEDTLS_SSL_ETM_ENABLED or MBEDTLS_SSL_ETM_DISABLED 2512c2c66affSColin Finck */ 2513c2c66affSColin Finck void mbedtls_ssl_conf_encrypt_then_mac( mbedtls_ssl_config *conf, char etm ); 2514c2c66affSColin Finck #endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */ 2515c2c66affSColin Finck 2516c2c66affSColin Finck #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET) 2517c2c66affSColin Finck /** 2518c2c66affSColin Finck * \brief Enable or disable Extended Master Secret negotiation. 2519c2c66affSColin Finck * (Default: MBEDTLS_SSL_EXTENDED_MS_ENABLED) 2520c2c66affSColin Finck * 2521c2c66affSColin Finck * \note This should always be enabled, it is a security fix to the 2522c2c66affSColin Finck * protocol, and should not cause any interoperability issue 2523c2c66affSColin Finck * (used only if the peer supports it too). 2524c2c66affSColin Finck * 2525c2c66affSColin Finck * \param conf SSL configuration 2526c2c66affSColin Finck * \param ems MBEDTLS_SSL_EXTENDED_MS_ENABLED or MBEDTLS_SSL_EXTENDED_MS_DISABLED 2527c2c66affSColin Finck */ 2528c2c66affSColin Finck void mbedtls_ssl_conf_extended_master_secret( mbedtls_ssl_config *conf, char ems ); 2529c2c66affSColin Finck #endif /* MBEDTLS_SSL_EXTENDED_MASTER_SECRET */ 2530c2c66affSColin Finck 2531c2c66affSColin Finck #if defined(MBEDTLS_ARC4_C) 2532c2c66affSColin Finck /** 2533c2c66affSColin Finck * \brief Disable or enable support for RC4 2534c2c66affSColin Finck * (Default: MBEDTLS_SSL_ARC4_DISABLED) 2535c2c66affSColin Finck * 2536c2c66affSColin Finck * \warning Use of RC4 in DTLS/TLS has been prohibited by RFC 7465 2537c2c66affSColin Finck * for security reasons. Use at your own risk. 2538c2c66affSColin Finck * 2539c2c66affSColin Finck * \note This function is deprecated and will likely be removed in 2540c2c66affSColin Finck * a future version of the library. 2541c2c66affSColin Finck * RC4 is disabled by default at compile time and needs to be 2542c2c66affSColin Finck * actively enabled for use with legacy systems. 2543c2c66affSColin Finck * 2544c2c66affSColin Finck * \param conf SSL configuration 2545c2c66affSColin Finck * \param arc4 MBEDTLS_SSL_ARC4_ENABLED or MBEDTLS_SSL_ARC4_DISABLED 2546c2c66affSColin Finck */ 2547c2c66affSColin Finck void mbedtls_ssl_conf_arc4_support( mbedtls_ssl_config *conf, char arc4 ); 2548c2c66affSColin Finck #endif /* MBEDTLS_ARC4_C */ 2549c2c66affSColin Finck 2550c2c66affSColin Finck #if defined(MBEDTLS_SSL_SRV_C) 2551c2c66affSColin Finck /** 2552c2c66affSColin Finck * \brief Whether to send a list of acceptable CAs in 2553c2c66affSColin Finck * CertificateRequest messages. 2554c2c66affSColin Finck * (Default: do send) 2555c2c66affSColin Finck * 2556c2c66affSColin Finck * \param conf SSL configuration 2557c2c66affSColin Finck * \param cert_req_ca_list MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED or 2558c2c66affSColin Finck * MBEDTLS_SSL_CERT_REQ_CA_LIST_DISABLED 2559c2c66affSColin Finck */ 2560c2c66affSColin Finck void mbedtls_ssl_conf_cert_req_ca_list( mbedtls_ssl_config *conf, 2561c2c66affSColin Finck char cert_req_ca_list ); 2562c2c66affSColin Finck #endif /* MBEDTLS_SSL_SRV_C */ 2563c2c66affSColin Finck 2564c2c66affSColin Finck #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) 2565c2c66affSColin Finck /** 2566430656f0SThomas Faber * \brief Set the maximum fragment length to emit and/or negotiate. 2567cbda039fSThomas Faber * (Typical: the smaller of #MBEDTLS_SSL_IN_CONTENT_LEN and 2568cbda039fSThomas Faber * #MBEDTLS_SSL_OUT_CONTENT_LEN, usually `2^14` bytes) 2569c2c66affSColin Finck * (Server: set maximum fragment length to emit, 2570430656f0SThomas Faber * usually negotiated by the client during handshake) 2571c2c66affSColin Finck * (Client: set maximum fragment length to emit *and* 2572c2c66affSColin Finck * negotiate with the server during handshake) 2573430656f0SThomas Faber * (Default: #MBEDTLS_SSL_MAX_FRAG_LEN_NONE) 2574430656f0SThomas Faber * 2575430656f0SThomas Faber * \note On the client side, the maximum fragment length extension 2576430656f0SThomas Faber * *will not* be used, unless the maximum fragment length has 2577430656f0SThomas Faber * been set via this function to a value different than 2578430656f0SThomas Faber * #MBEDTLS_SSL_MAX_FRAG_LEN_NONE. 2579430656f0SThomas Faber * 2580430656f0SThomas Faber * \note This sets the maximum length for a record's payload, 2581430656f0SThomas Faber * excluding record overhead that will be added to it, see 2582430656f0SThomas Faber * \c mbedtls_ssl_get_record_expansion(). 2583c2c66affSColin Finck * 2584cbda039fSThomas Faber * \note With TLS, this currently only affects ApplicationData (sent 2585cbda039fSThomas Faber * with \c mbedtls_ssl_read()), not handshake messages. 2586cbda039fSThomas Faber * With DTLS, this affects both ApplicationData and handshake. 2587cbda039fSThomas Faber * 2588cbda039fSThomas Faber * \note For DTLS, it is also possible to set a limit for the total 2589cbda039fSThomas Faber * size of daragrams passed to the transport layer, including 2590cbda039fSThomas Faber * record overhead, see \c mbedtls_ssl_set_mtu(). 2591cbda039fSThomas Faber * 2592c2c66affSColin Finck * \param conf SSL configuration 2593c2c66affSColin Finck * \param mfl_code Code for maximum fragment length (allowed values: 2594c2c66affSColin Finck * MBEDTLS_SSL_MAX_FRAG_LEN_512, MBEDTLS_SSL_MAX_FRAG_LEN_1024, 2595c2c66affSColin Finck * MBEDTLS_SSL_MAX_FRAG_LEN_2048, MBEDTLS_SSL_MAX_FRAG_LEN_4096) 2596c2c66affSColin Finck * 2597c2c66affSColin Finck * \return 0 if successful or MBEDTLS_ERR_SSL_BAD_INPUT_DATA 2598c2c66affSColin Finck */ 2599c2c66affSColin Finck int mbedtls_ssl_conf_max_frag_len( mbedtls_ssl_config *conf, unsigned char mfl_code ); 2600c2c66affSColin Finck #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */ 2601c2c66affSColin Finck 2602c2c66affSColin Finck #if defined(MBEDTLS_SSL_TRUNCATED_HMAC) 2603c2c66affSColin Finck /** 2604c2c66affSColin Finck * \brief Activate negotiation of truncated HMAC 2605c2c66affSColin Finck * (Default: MBEDTLS_SSL_TRUNC_HMAC_DISABLED) 2606c2c66affSColin Finck * 2607c2c66affSColin Finck * \param conf SSL configuration 2608c2c66affSColin Finck * \param truncate Enable or disable (MBEDTLS_SSL_TRUNC_HMAC_ENABLED or 2609c2c66affSColin Finck * MBEDTLS_SSL_TRUNC_HMAC_DISABLED) 2610c2c66affSColin Finck */ 2611c2c66affSColin Finck void mbedtls_ssl_conf_truncated_hmac( mbedtls_ssl_config *conf, int truncate ); 2612c2c66affSColin Finck #endif /* MBEDTLS_SSL_TRUNCATED_HMAC */ 2613c2c66affSColin Finck 2614c2c66affSColin Finck #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING) 2615c2c66affSColin Finck /** 2616c2c66affSColin Finck * \brief Enable / Disable 1/n-1 record splitting 2617c2c66affSColin Finck * (Default: MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED) 2618c2c66affSColin Finck * 2619c2c66affSColin Finck * \note Only affects SSLv3 and TLS 1.0, not higher versions. 2620c2c66affSColin Finck * Does not affect non-CBC ciphersuites in any version. 2621c2c66affSColin Finck * 2622c2c66affSColin Finck * \param conf SSL configuration 2623c2c66affSColin Finck * \param split MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED or 2624c2c66affSColin Finck * MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED 2625c2c66affSColin Finck */ 2626c2c66affSColin Finck void mbedtls_ssl_conf_cbc_record_splitting( mbedtls_ssl_config *conf, char split ); 2627c2c66affSColin Finck #endif /* MBEDTLS_SSL_CBC_RECORD_SPLITTING */ 2628c2c66affSColin Finck 2629c2c66affSColin Finck #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C) 2630c2c66affSColin Finck /** 2631c2c66affSColin Finck * \brief Enable / Disable session tickets (client only). 2632c2c66affSColin Finck * (Default: MBEDTLS_SSL_SESSION_TICKETS_ENABLED.) 2633c2c66affSColin Finck * 2634c2c66affSColin Finck * \note On server, use \c mbedtls_ssl_conf_session_tickets_cb(). 2635c2c66affSColin Finck * 2636c2c66affSColin Finck * \param conf SSL configuration 2637c2c66affSColin Finck * \param use_tickets Enable or disable (MBEDTLS_SSL_SESSION_TICKETS_ENABLED or 2638c2c66affSColin Finck * MBEDTLS_SSL_SESSION_TICKETS_DISABLED) 2639c2c66affSColin Finck */ 2640c2c66affSColin Finck void mbedtls_ssl_conf_session_tickets( mbedtls_ssl_config *conf, int use_tickets ); 2641c2c66affSColin Finck #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */ 2642c2c66affSColin Finck 2643c2c66affSColin Finck #if defined(MBEDTLS_SSL_RENEGOTIATION) 2644c2c66affSColin Finck /** 2645c2c66affSColin Finck * \brief Enable / Disable renegotiation support for connection when 2646c2c66affSColin Finck * initiated by peer 2647c2c66affSColin Finck * (Default: MBEDTLS_SSL_RENEGOTIATION_DISABLED) 2648c2c66affSColin Finck * 2649c2c66affSColin Finck * \warning It is recommended to always disable renegotation unless you 2650c2c66affSColin Finck * know you need it and you know what you're doing. In the 2651c2c66affSColin Finck * past, there have been several issues associated with 2652c2c66affSColin Finck * renegotiation or a poor understanding of its properties. 2653c2c66affSColin Finck * 2654c2c66affSColin Finck * \note Server-side, enabling renegotiation also makes the server 2655c2c66affSColin Finck * susceptible to a resource DoS by a malicious client. 2656c2c66affSColin Finck * 2657c2c66affSColin Finck * \param conf SSL configuration 2658c2c66affSColin Finck * \param renegotiation Enable or disable (MBEDTLS_SSL_RENEGOTIATION_ENABLED or 2659c2c66affSColin Finck * MBEDTLS_SSL_RENEGOTIATION_DISABLED) 2660c2c66affSColin Finck */ 2661c2c66affSColin Finck void mbedtls_ssl_conf_renegotiation( mbedtls_ssl_config *conf, int renegotiation ); 2662c2c66affSColin Finck #endif /* MBEDTLS_SSL_RENEGOTIATION */ 2663c2c66affSColin Finck 2664c2c66affSColin Finck /** 2665c2c66affSColin Finck * \brief Prevent or allow legacy renegotiation. 2666c2c66affSColin Finck * (Default: MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION) 2667c2c66affSColin Finck * 2668c2c66affSColin Finck * MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION allows connections to 2669c2c66affSColin Finck * be established even if the peer does not support 2670c2c66affSColin Finck * secure renegotiation, but does not allow renegotiation 2671c2c66affSColin Finck * to take place if not secure. 2672c2c66affSColin Finck * (Interoperable and secure option) 2673c2c66affSColin Finck * 2674c2c66affSColin Finck * MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION allows renegotiations 2675c2c66affSColin Finck * with non-upgraded peers. Allowing legacy renegotiation 2676c2c66affSColin Finck * makes the connection vulnerable to specific man in the 2677c2c66affSColin Finck * middle attacks. (See RFC 5746) 2678c2c66affSColin Finck * (Most interoperable and least secure option) 2679c2c66affSColin Finck * 2680c2c66affSColin Finck * MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE breaks off connections 2681c2c66affSColin Finck * if peer does not support secure renegotiation. Results 2682c2c66affSColin Finck * in interoperability issues with non-upgraded peers 2683c2c66affSColin Finck * that do not support renegotiation altogether. 2684c2c66affSColin Finck * (Most secure option, interoperability issues) 2685c2c66affSColin Finck * 2686c2c66affSColin Finck * \param conf SSL configuration 2687c2c66affSColin Finck * \param allow_legacy Prevent or allow (SSL_NO_LEGACY_RENEGOTIATION, 2688c2c66affSColin Finck * SSL_ALLOW_LEGACY_RENEGOTIATION or 2689c2c66affSColin Finck * MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE) 2690c2c66affSColin Finck */ 2691c2c66affSColin Finck void mbedtls_ssl_conf_legacy_renegotiation( mbedtls_ssl_config *conf, int allow_legacy ); 2692c2c66affSColin Finck 2693c2c66affSColin Finck #if defined(MBEDTLS_SSL_RENEGOTIATION) 2694c2c66affSColin Finck /** 2695c2c66affSColin Finck * \brief Enforce renegotiation requests. 2696c2c66affSColin Finck * (Default: enforced, max_records = 16) 2697c2c66affSColin Finck * 2698c2c66affSColin Finck * When we request a renegotiation, the peer can comply or 2699c2c66affSColin Finck * ignore the request. This function allows us to decide 2700c2c66affSColin Finck * whether to enforce our renegotiation requests by closing 2701c2c66affSColin Finck * the connection if the peer doesn't comply. 2702c2c66affSColin Finck * 2703c2c66affSColin Finck * However, records could already be in transit from the peer 2704c2c66affSColin Finck * when the request is emitted. In order to increase 2705c2c66affSColin Finck * reliability, we can accept a number of records before the 2706c2c66affSColin Finck * expected handshake records. 2707c2c66affSColin Finck * 2708c2c66affSColin Finck * The optimal value is highly dependent on the specific usage 2709c2c66affSColin Finck * scenario. 2710c2c66affSColin Finck * 2711c2c66affSColin Finck * \note With DTLS and server-initiated renegotiation, the 2712c2c66affSColin Finck * HelloRequest is retransmited every time mbedtls_ssl_read() times 2713c2c66affSColin Finck * out or receives Application Data, until: 2714c2c66affSColin Finck * - max_records records have beens seen, if it is >= 0, or 2715c2c66affSColin Finck * - the number of retransmits that would happen during an 2716c2c66affSColin Finck * actual handshake has been reached. 2717c2c66affSColin Finck * Please remember the request might be lost a few times 2718c2c66affSColin Finck * if you consider setting max_records to a really low value. 2719c2c66affSColin Finck * 2720c2c66affSColin Finck * \warning On client, the grace period can only happen during 2721c2c66affSColin Finck * mbedtls_ssl_read(), as opposed to mbedtls_ssl_write() and mbedtls_ssl_renegotiate() 2722c2c66affSColin Finck * which always behave as if max_record was 0. The reason is, 2723c2c66affSColin Finck * if we receive application data from the server, we need a 2724c2c66affSColin Finck * place to write it, which only happens during mbedtls_ssl_read(). 2725c2c66affSColin Finck * 2726c2c66affSColin Finck * \param conf SSL configuration 2727c2c66affSColin Finck * \param max_records Use MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED if you don't want to 2728c2c66affSColin Finck * enforce renegotiation, or a non-negative value to enforce 2729c2c66affSColin Finck * it but allow for a grace period of max_records records. 2730c2c66affSColin Finck */ 2731c2c66affSColin Finck void mbedtls_ssl_conf_renegotiation_enforced( mbedtls_ssl_config *conf, int max_records ); 2732c2c66affSColin Finck 2733c2c66affSColin Finck /** 2734c2c66affSColin Finck * \brief Set record counter threshold for periodic renegotiation. 2735c2c66affSColin Finck * (Default: 2^48 - 1) 2736c2c66affSColin Finck * 2737c2c66affSColin Finck * Renegotiation is automatically triggered when a record 2738c2c66affSColin Finck * counter (outgoing or ingoing) crosses the defined 2739c2c66affSColin Finck * threshold. The default value is meant to prevent the 2740c2c66affSColin Finck * connection from being closed when the counter is about to 2741c2c66affSColin Finck * reached its maximal value (it is not allowed to wrap). 2742c2c66affSColin Finck * 2743c2c66affSColin Finck * Lower values can be used to enforce policies such as "keys 2744c2c66affSColin Finck * must be refreshed every N packets with cipher X". 2745c2c66affSColin Finck * 2746c2c66affSColin Finck * The renegotiation period can be disabled by setting 2747c2c66affSColin Finck * conf->disable_renegotiation to 2748c2c66affSColin Finck * MBEDTLS_SSL_RENEGOTIATION_DISABLED. 2749c2c66affSColin Finck * 2750c2c66affSColin Finck * \note When the configured transport is 2751c2c66affSColin Finck * MBEDTLS_SSL_TRANSPORT_DATAGRAM the maximum renegotiation 2752c2c66affSColin Finck * period is 2^48 - 1, and for MBEDTLS_SSL_TRANSPORT_STREAM, 2753c2c66affSColin Finck * the maximum renegotiation period is 2^64 - 1. 2754c2c66affSColin Finck * 2755c2c66affSColin Finck * \param conf SSL configuration 2756c2c66affSColin Finck * \param period The threshold value: a big-endian 64-bit number. 2757c2c66affSColin Finck */ 2758c2c66affSColin Finck void mbedtls_ssl_conf_renegotiation_period( mbedtls_ssl_config *conf, 2759c2c66affSColin Finck const unsigned char period[8] ); 2760c2c66affSColin Finck #endif /* MBEDTLS_SSL_RENEGOTIATION */ 2761c2c66affSColin Finck 2762c2c66affSColin Finck /** 2763cbda039fSThomas Faber * \brief Check if there is data already read from the 2764cbda039fSThomas Faber * underlying transport but not yet processed. 2765c2c66affSColin Finck * 2766c2c66affSColin Finck * \param ssl SSL context 2767c2c66affSColin Finck * 2768cbda039fSThomas Faber * \return 0 if nothing's pending, 1 otherwise. 2769cbda039fSThomas Faber * 2770cbda039fSThomas Faber * \note This is different in purpose and behaviour from 2771cbda039fSThomas Faber * \c mbedtls_ssl_get_bytes_avail in that it considers 2772cbda039fSThomas Faber * any kind of unprocessed data, not only unread 2773cbda039fSThomas Faber * application data. If \c mbedtls_ssl_get_bytes 2774cbda039fSThomas Faber * returns a non-zero value, this function will 2775cbda039fSThomas Faber * also signal pending data, but the converse does 2776cbda039fSThomas Faber * not hold. For example, in DTLS there might be 2777cbda039fSThomas Faber * further records waiting to be processed from 2778cbda039fSThomas Faber * the current underlying transport's datagram. 2779cbda039fSThomas Faber * 2780cbda039fSThomas Faber * \note If this function returns 1 (data pending), this 2781cbda039fSThomas Faber * does not imply that a subsequent call to 2782cbda039fSThomas Faber * \c mbedtls_ssl_read will provide any data; 2783cbda039fSThomas Faber * e.g., the unprocessed data might turn out 2784cbda039fSThomas Faber * to be an alert or a handshake message. 2785cbda039fSThomas Faber * 2786cbda039fSThomas Faber * \note This function is useful in the following situation: 2787cbda039fSThomas Faber * If the SSL/TLS module successfully returns from an 2788cbda039fSThomas Faber * operation - e.g. a handshake or an application record 2789cbda039fSThomas Faber * read - and you're awaiting incoming data next, you 2790cbda039fSThomas Faber * must not immediately idle on the underlying transport 2791cbda039fSThomas Faber * to have data ready, but you need to check the value 2792cbda039fSThomas Faber * of this function first. The reason is that the desired 2793cbda039fSThomas Faber * data might already be read but not yet processed. 2794cbda039fSThomas Faber * If, in contrast, a previous call to the SSL/TLS module 2795cbda039fSThomas Faber * returned MBEDTLS_ERR_SSL_WANT_READ, it is not necessary 2796cbda039fSThomas Faber * to call this function, as the latter error code entails 2797cbda039fSThomas Faber * that all internal data has been processed. 2798cbda039fSThomas Faber * 2799cbda039fSThomas Faber */ 2800cbda039fSThomas Faber int mbedtls_ssl_check_pending( const mbedtls_ssl_context *ssl ); 2801cbda039fSThomas Faber 2802cbda039fSThomas Faber /** 2803cbda039fSThomas Faber * \brief Return the number of application data bytes 2804cbda039fSThomas Faber * remaining to be read from the current record. 2805cbda039fSThomas Faber * 2806cbda039fSThomas Faber * \param ssl SSL context 2807cbda039fSThomas Faber * 2808cbda039fSThomas Faber * \return How many bytes are available in the application 2809cbda039fSThomas Faber * data record read buffer. 2810cbda039fSThomas Faber * 2811cbda039fSThomas Faber * \note When working over a datagram transport, this is 2812cbda039fSThomas Faber * useful to detect the current datagram's boundary 2813cbda039fSThomas Faber * in case \c mbedtls_ssl_read has written the maximal 2814cbda039fSThomas Faber * amount of data fitting into the input buffer. 2815cbda039fSThomas Faber * 2816c2c66affSColin Finck */ 2817c2c66affSColin Finck size_t mbedtls_ssl_get_bytes_avail( const mbedtls_ssl_context *ssl ); 2818c2c66affSColin Finck 2819c2c66affSColin Finck /** 2820c2c66affSColin Finck * \brief Return the result of the certificate verification 2821c2c66affSColin Finck * 28220ba5bc40SThomas Faber * \param ssl The SSL context to use. 2823c2c66affSColin Finck * 28240ba5bc40SThomas Faber * \return \c 0 if the certificate verification was successful. 28250ba5bc40SThomas Faber * \return \c -1u if the result is not available. This may happen 28260ba5bc40SThomas Faber * e.g. if the handshake aborts early, or a verification 28270ba5bc40SThomas Faber * callback returned a fatal error. 28280ba5bc40SThomas Faber * \return A bitwise combination of \c MBEDTLS_X509_BADCERT_XXX 28290ba5bc40SThomas Faber * and \c MBEDTLS_X509_BADCRL_XXX failure flags; see x509.h. 2830c2c66affSColin Finck */ 2831c2c66affSColin Finck uint32_t mbedtls_ssl_get_verify_result( const mbedtls_ssl_context *ssl ); 2832c2c66affSColin Finck 2833c2c66affSColin Finck /** 2834c2c66affSColin Finck * \brief Return the name of the current ciphersuite 2835c2c66affSColin Finck * 2836c2c66affSColin Finck * \param ssl SSL context 2837c2c66affSColin Finck * 2838c2c66affSColin Finck * \return a string containing the ciphersuite name 2839c2c66affSColin Finck */ 2840c2c66affSColin Finck const char *mbedtls_ssl_get_ciphersuite( const mbedtls_ssl_context *ssl ); 2841c2c66affSColin Finck 2842c2c66affSColin Finck /** 2843c2c66affSColin Finck * \brief Return the current SSL version (SSLv3/TLSv1/etc) 2844c2c66affSColin Finck * 2845c2c66affSColin Finck * \param ssl SSL context 2846c2c66affSColin Finck * 2847c2c66affSColin Finck * \return a string containing the SSL version 2848c2c66affSColin Finck */ 2849c2c66affSColin Finck const char *mbedtls_ssl_get_version( const mbedtls_ssl_context *ssl ); 2850c2c66affSColin Finck 2851c2c66affSColin Finck /** 2852c2c66affSColin Finck * \brief Return the (maximum) number of bytes added by the record 2853c2c66affSColin Finck * layer: header + encryption/MAC overhead (inc. padding) 2854c2c66affSColin Finck * 2855cbda039fSThomas Faber * \note This function is not available (always returns an error) 2856cbda039fSThomas Faber * when record compression is enabled. 2857cbda039fSThomas Faber * 2858c2c66affSColin Finck * \param ssl SSL context 2859c2c66affSColin Finck * 2860c2c66affSColin Finck * \return Current maximum record expansion in bytes, or 2861c2c66affSColin Finck * MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE if compression is 2862c2c66affSColin Finck * enabled, which makes expansion much less predictable 2863c2c66affSColin Finck */ 2864c2c66affSColin Finck int mbedtls_ssl_get_record_expansion( const mbedtls_ssl_context *ssl ); 2865c2c66affSColin Finck 2866c2c66affSColin Finck #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) 2867c2c66affSColin Finck /** 2868c2c66affSColin Finck * \brief Return the maximum fragment length (payload, in bytes). 2869c2c66affSColin Finck * This is the value negotiated with peer if any, 2870c2c66affSColin Finck * or the locally configured value. 2871c2c66affSColin Finck * 2872cbda039fSThomas Faber * \sa mbedtls_ssl_conf_max_frag_len() 2873cbda039fSThomas Faber * \sa mbedtls_ssl_get_max_record_payload() 2874c2c66affSColin Finck * 2875c2c66affSColin Finck * \param ssl SSL context 2876c2c66affSColin Finck * 2877c2c66affSColin Finck * \return Current maximum fragment length. 2878c2c66affSColin Finck */ 2879c2c66affSColin Finck size_t mbedtls_ssl_get_max_frag_len( const mbedtls_ssl_context *ssl ); 2880c2c66affSColin Finck #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */ 2881c2c66affSColin Finck 2882cbda039fSThomas Faber /** 2883cbda039fSThomas Faber * \brief Return the current maximum outgoing record payload in bytes. 2884cbda039fSThomas Faber * This takes into account the config.h setting \c 2885cbda039fSThomas Faber * MBEDTLS_SSL_OUT_CONTENT_LEN, the configured and negotiated 2886cbda039fSThomas Faber * max fragment length extension if used, and for DTLS the 2887cbda039fSThomas Faber * path MTU as configured and current record expansion. 2888cbda039fSThomas Faber * 2889cbda039fSThomas Faber * \note With DTLS, \c mbedtls_ssl_write() will return an error if 2890cbda039fSThomas Faber * called with a larger length value. 2891cbda039fSThomas Faber * With TLS, \c mbedtls_ssl_write() will fragment the input if 2892cbda039fSThomas Faber * necessary and return the number of bytes written; it is up 2893cbda039fSThomas Faber * to the caller to call \c mbedtls_ssl_write() again in 2894cbda039fSThomas Faber * order to send the remaining bytes if any. 2895cbda039fSThomas Faber * 2896cbda039fSThomas Faber * \note This function is not available (always returns an error) 2897cbda039fSThomas Faber * when record compression is enabled. 2898cbda039fSThomas Faber * 2899cbda039fSThomas Faber * \sa mbedtls_ssl_set_mtu() 2900cbda039fSThomas Faber * \sa mbedtls_ssl_get_max_frag_len() 2901cbda039fSThomas Faber * \sa mbedtls_ssl_get_record_expansion() 2902cbda039fSThomas Faber * 2903cbda039fSThomas Faber * \param ssl SSL context 2904cbda039fSThomas Faber * 2905cbda039fSThomas Faber * \return Current maximum payload for an outgoing record, 2906cbda039fSThomas Faber * or a negative error code. 2907cbda039fSThomas Faber */ 2908cbda039fSThomas Faber int mbedtls_ssl_get_max_out_record_payload( const mbedtls_ssl_context *ssl ); 2909cbda039fSThomas Faber 2910c2c66affSColin Finck #if defined(MBEDTLS_X509_CRT_PARSE_C) 2911c2c66affSColin Finck /** 2912c2c66affSColin Finck * \brief Return the peer certificate from the current connection 2913c2c66affSColin Finck * 2914c2c66affSColin Finck * Note: Can be NULL in case no certificate was sent during 2915c2c66affSColin Finck * the handshake. Different calls for the same connection can 2916c2c66affSColin Finck * return the same or different pointers for the same 2917c2c66affSColin Finck * certificate and even a different certificate altogether. 2918c2c66affSColin Finck * The peer cert CAN change in a single connection if 2919c2c66affSColin Finck * renegotiation is performed. 2920c2c66affSColin Finck * 2921c2c66affSColin Finck * \param ssl SSL context 2922c2c66affSColin Finck * 2923c2c66affSColin Finck * \return the current peer certificate 2924c2c66affSColin Finck */ 2925c2c66affSColin Finck const mbedtls_x509_crt *mbedtls_ssl_get_peer_cert( const mbedtls_ssl_context *ssl ); 2926c2c66affSColin Finck #endif /* MBEDTLS_X509_CRT_PARSE_C */ 2927c2c66affSColin Finck 2928c2c66affSColin Finck #if defined(MBEDTLS_SSL_CLI_C) 2929c2c66affSColin Finck /** 2930c2c66affSColin Finck * \brief Save session in order to resume it later (client-side only) 2931c2c66affSColin Finck * Session data is copied to presented session structure. 2932c2c66affSColin Finck * 2933c2c66affSColin Finck * 2934c2c66affSColin Finck * \param ssl SSL context 2935c2c66affSColin Finck * \param session session context 2936c2c66affSColin Finck * 2937c2c66affSColin Finck * \return 0 if successful, 2938c2c66affSColin Finck * MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed, 2939c2c66affSColin Finck * MBEDTLS_ERR_SSL_BAD_INPUT_DATA if used server-side or 2940d9e6c9b5SThomas Faber * arguments are otherwise invalid. 2941d9e6c9b5SThomas Faber * 2942d9e6c9b5SThomas Faber * \note Only the server certificate is copied, and not the full chain, 2943d9e6c9b5SThomas Faber * so you should not attempt to validate the certificate again 2944d9e6c9b5SThomas Faber * by calling \c mbedtls_x509_crt_verify() on it. 2945d9e6c9b5SThomas Faber * Instead, you should use the results from the verification 2946d9e6c9b5SThomas Faber * in the original handshake by calling \c mbedtls_ssl_get_verify_result() 2947d9e6c9b5SThomas Faber * after loading the session again into a new SSL context 2948d9e6c9b5SThomas Faber * using \c mbedtls_ssl_set_session(). 2949d9e6c9b5SThomas Faber * 2950d9e6c9b5SThomas Faber * \note Once the session object is not needed anymore, you should 2951d9e6c9b5SThomas Faber * free it by calling \c mbedtls_ssl_session_free(). 2952c2c66affSColin Finck * 2953c2c66affSColin Finck * \sa mbedtls_ssl_set_session() 2954c2c66affSColin Finck */ 2955c2c66affSColin Finck int mbedtls_ssl_get_session( const mbedtls_ssl_context *ssl, mbedtls_ssl_session *session ); 2956c2c66affSColin Finck #endif /* MBEDTLS_SSL_CLI_C */ 2957c2c66affSColin Finck 2958c2c66affSColin Finck /** 2959c2c66affSColin Finck * \brief Perform the SSL handshake 2960c2c66affSColin Finck * 2961c2c66affSColin Finck * \param ssl SSL context 2962c2c66affSColin Finck * 2963cbda039fSThomas Faber * \return \c 0 if successful. 2964cbda039fSThomas Faber * \return #MBEDTLS_ERR_SSL_WANT_READ or #MBEDTLS_ERR_SSL_WANT_WRITE 2965cbda039fSThomas Faber * if the handshake is incomplete and waiting for data to 2966cbda039fSThomas Faber * be available for reading from or writing to the underlying 2967cbda039fSThomas Faber * transport - in this case you must call this function again 2968cbda039fSThomas Faber * when the underlying transport is ready for the operation. 2969cbda039fSThomas Faber * \return #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS if an asynchronous 2970cbda039fSThomas Faber * operation is in progress (see 2971cbda039fSThomas Faber * mbedtls_ssl_conf_async_private_cb()) - in this case you 2972cbda039fSThomas Faber * must call this function again when the operation is ready. 2973cbda039fSThomas Faber * \return #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS if a cryptographic 2974cbda039fSThomas Faber * operation is in progress (see mbedtls_ecp_set_max_ops()) - 2975cbda039fSThomas Faber * in this case you must call this function again to complete 2976cbda039fSThomas Faber * the handshake when you're done attending other tasks. 2977cbda039fSThomas Faber * \return #MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED if DTLS is in use 2978cbda039fSThomas Faber * and the client did not demonstrate reachability yet - in 2979cbda039fSThomas Faber * this case you must stop using the context (see below). 2980cbda039fSThomas Faber * \return Another SSL error code - in this case you must stop using 2981cbda039fSThomas Faber * the context (see below). 2982c2c66affSColin Finck * 2983cbda039fSThomas Faber * \warning If this function returns something other than 2984cbda039fSThomas Faber * \c 0, 2985cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_WANT_READ, 2986cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_WANT_WRITE, 2987cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS or 2988cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS, 2989cbda039fSThomas Faber * you must stop using the SSL context for reading or writing, 2990cbda039fSThomas Faber * and either free it or call \c mbedtls_ssl_session_reset() 2991cbda039fSThomas Faber * on it before re-using it for a new connection; the current 2992cbda039fSThomas Faber * connection must be closed. 2993c2c66affSColin Finck * 2994c2c66affSColin Finck * \note If DTLS is in use, then you may choose to handle 2995cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED specially for logging 2996c2c66affSColin Finck * purposes, as it is an expected return value rather than an 2997c2c66affSColin Finck * actual error, but you still need to reset/free the context. 2998cbda039fSThomas Faber * 2999cbda039fSThomas Faber * \note Remarks regarding event-driven DTLS: 3000cbda039fSThomas Faber * If the function returns #MBEDTLS_ERR_SSL_WANT_READ, no datagram 3001cbda039fSThomas Faber * from the underlying transport layer is currently being processed, 3002cbda039fSThomas Faber * and it is safe to idle until the timer or the underlying transport 3003cbda039fSThomas Faber * signal a new event. This is not true for a successful handshake, 3004cbda039fSThomas Faber * in which case the datagram of the underlying transport that is 3005cbda039fSThomas Faber * currently being processed might or might not contain further 3006cbda039fSThomas Faber * DTLS records. 3007c2c66affSColin Finck */ 3008c2c66affSColin Finck int mbedtls_ssl_handshake( mbedtls_ssl_context *ssl ); 3009c2c66affSColin Finck 3010c2c66affSColin Finck /** 3011c2c66affSColin Finck * \brief Perform a single step of the SSL handshake 3012c2c66affSColin Finck * 3013c2c66affSColin Finck * \note The state of the context (ssl->state) will be at 3014cbda039fSThomas Faber * the next state after this function returns \c 0. Do not 3015c2c66affSColin Finck * call this function if state is MBEDTLS_SSL_HANDSHAKE_OVER. 3016c2c66affSColin Finck * 3017c2c66affSColin Finck * \param ssl SSL context 3018c2c66affSColin Finck * 3019cbda039fSThomas Faber * \return See mbedtls_ssl_handshake(). 3020cbda039fSThomas Faber * 3021cbda039fSThomas Faber * \warning If this function returns something other than \c 0, 3022cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_WANT_READ, #MBEDTLS_ERR_SSL_WANT_WRITE, 3023cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS or 3024cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS, you must stop using 3025cbda039fSThomas Faber * the SSL context for reading or writing, and either free it 3026cbda039fSThomas Faber * or call \c mbedtls_ssl_session_reset() on it before 3027cbda039fSThomas Faber * re-using it for a new connection; the current connection 3028cbda039fSThomas Faber * must be closed. 3029c2c66affSColin Finck */ 3030c2c66affSColin Finck int mbedtls_ssl_handshake_step( mbedtls_ssl_context *ssl ); 3031c2c66affSColin Finck 3032c2c66affSColin Finck #if defined(MBEDTLS_SSL_RENEGOTIATION) 3033c2c66affSColin Finck /** 3034c2c66affSColin Finck * \brief Initiate an SSL renegotiation on the running connection. 3035c2c66affSColin Finck * Client: perform the renegotiation right now. 3036c2c66affSColin Finck * Server: request renegotiation, which will be performed 3037c2c66affSColin Finck * during the next call to mbedtls_ssl_read() if honored by 3038c2c66affSColin Finck * client. 3039c2c66affSColin Finck * 3040c2c66affSColin Finck * \param ssl SSL context 3041c2c66affSColin Finck * 3042c2c66affSColin Finck * \return 0 if successful, or any mbedtls_ssl_handshake() return 3043cbda039fSThomas Faber * value except #MBEDTLS_ERR_SSL_CLIENT_RECONNECT that can't 3044cbda039fSThomas Faber * happen during a renegotiation. 3045c2c66affSColin Finck * 3046cbda039fSThomas Faber * \warning If this function returns something other than \c 0, 3047cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_WANT_READ, #MBEDTLS_ERR_SSL_WANT_WRITE, 3048cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS or 3049cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS, you must stop using 3050cbda039fSThomas Faber * the SSL context for reading or writing, and either free it 3051cbda039fSThomas Faber * or call \c mbedtls_ssl_session_reset() on it before 3052cbda039fSThomas Faber * re-using it for a new connection; the current connection 3053cbda039fSThomas Faber * must be closed. 3054cbda039fSThomas Faber * 3055c2c66affSColin Finck */ 3056c2c66affSColin Finck int mbedtls_ssl_renegotiate( mbedtls_ssl_context *ssl ); 3057c2c66affSColin Finck #endif /* MBEDTLS_SSL_RENEGOTIATION */ 3058c2c66affSColin Finck 3059c2c66affSColin Finck /** 3060c2c66affSColin Finck * \brief Read at most 'len' application data bytes 3061c2c66affSColin Finck * 3062c2c66affSColin Finck * \param ssl SSL context 3063c2c66affSColin Finck * \param buf buffer that will hold the data 3064c2c66affSColin Finck * \param len maximum number of bytes to read 3065c2c66affSColin Finck * 3066cbda039fSThomas Faber * \return The (positive) number of bytes read if successful. 3067cbda039fSThomas Faber * \return \c 0 if the read end of the underlying transport was closed 3068cbda039fSThomas Faber * - in this case you must stop using the context (see below). 3069cbda039fSThomas Faber * \return #MBEDTLS_ERR_SSL_WANT_READ or #MBEDTLS_ERR_SSL_WANT_WRITE 3070cbda039fSThomas Faber * if the handshake is incomplete and waiting for data to 3071cbda039fSThomas Faber * be available for reading from or writing to the underlying 3072cbda039fSThomas Faber * transport - in this case you must call this function again 3073cbda039fSThomas Faber * when the underlying transport is ready for the operation. 3074cbda039fSThomas Faber * \return #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS if an asynchronous 3075cbda039fSThomas Faber * operation is in progress (see 3076cbda039fSThomas Faber * mbedtls_ssl_conf_async_private_cb()) - in this case you 3077cbda039fSThomas Faber * must call this function again when the operation is ready. 3078cbda039fSThomas Faber * \return #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS if a cryptographic 3079cbda039fSThomas Faber * operation is in progress (see mbedtls_ecp_set_max_ops()) - 3080cbda039fSThomas Faber * in this case you must call this function again to complete 3081cbda039fSThomas Faber * the handshake when you're done attending other tasks. 3082cbda039fSThomas Faber * \return #MBEDTLS_ERR_SSL_CLIENT_RECONNECT if we're at the server 3083cbda039fSThomas Faber * side of a DTLS connection and the client is initiating a 3084cbda039fSThomas Faber * new connection using the same source port. See below. 3085cbda039fSThomas Faber * \return Another SSL error code - in this case you must stop using 3086cbda039fSThomas Faber * the context (see below). 3087c2c66affSColin Finck * 3088cbda039fSThomas Faber * \warning If this function returns something other than 3089cbda039fSThomas Faber * a positive value, 3090cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_WANT_READ, 3091cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_WANT_WRITE, 3092cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS, 3093cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS or 3094cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_CLIENT_RECONNECT, 3095cbda039fSThomas Faber * you must stop using the SSL context for reading or writing, 3096cbda039fSThomas Faber * and either free it or call \c mbedtls_ssl_session_reset() 3097cbda039fSThomas Faber * on it before re-using it for a new connection; the current 3098cbda039fSThomas Faber * connection must be closed. 3099c2c66affSColin Finck * 3100cbda039fSThomas Faber * \note When this function returns #MBEDTLS_ERR_SSL_CLIENT_RECONNECT 3101c2c66affSColin Finck * (which can only happen server-side), it means that a client 3102c2c66affSColin Finck * is initiating a new connection using the same source port. 3103c2c66affSColin Finck * You can either treat that as a connection close and wait 3104c2c66affSColin Finck * for the client to resend a ClientHello, or directly 3105c2c66affSColin Finck * continue with \c mbedtls_ssl_handshake() with the same 3106cbda039fSThomas Faber * context (as it has been reset internally). Either way, you 3107cbda039fSThomas Faber * must make sure this is seen by the application as a new 3108c2c66affSColin Finck * connection: application state, if any, should be reset, and 3109c2c66affSColin Finck * most importantly the identity of the client must be checked 3110c2c66affSColin Finck * again. WARNING: not validating the identity of the client 3111c2c66affSColin Finck * again, or not transmitting the new identity to the 3112c2c66affSColin Finck * application layer, would allow authentication bypass! 3113cbda039fSThomas Faber * 3114cbda039fSThomas Faber * \note Remarks regarding event-driven DTLS: 3115cbda039fSThomas Faber * - If the function returns #MBEDTLS_ERR_SSL_WANT_READ, no datagram 3116cbda039fSThomas Faber * from the underlying transport layer is currently being processed, 3117cbda039fSThomas Faber * and it is safe to idle until the timer or the underlying transport 3118cbda039fSThomas Faber * signal a new event. 3119cbda039fSThomas Faber * - This function may return MBEDTLS_ERR_SSL_WANT_READ even if data was 3120cbda039fSThomas Faber * initially available on the underlying transport, as this data may have 3121cbda039fSThomas Faber * been only e.g. duplicated messages or a renegotiation request. 3122cbda039fSThomas Faber * Therefore, you must be prepared to receive MBEDTLS_ERR_SSL_WANT_READ even 3123cbda039fSThomas Faber * when reacting to an incoming-data event from the underlying transport. 3124cbda039fSThomas Faber * - On success, the datagram of the underlying transport that is currently 3125cbda039fSThomas Faber * being processed may contain further DTLS records. You should call 3126cbda039fSThomas Faber * \c mbedtls_ssl_check_pending to check for remaining records. 3127cbda039fSThomas Faber * 3128c2c66affSColin Finck */ 3129c2c66affSColin Finck int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len ); 3130c2c66affSColin Finck 3131c2c66affSColin Finck /** 3132c2c66affSColin Finck * \brief Try to write exactly 'len' application data bytes 3133c2c66affSColin Finck * 3134c2c66affSColin Finck * \warning This function will do partial writes in some cases. If the 3135c2c66affSColin Finck * return value is non-negative but less than length, the 3136c2c66affSColin Finck * function must be called again with updated arguments: 3137c2c66affSColin Finck * buf + ret, len - ret (if ret is the return value) until 3138c2c66affSColin Finck * it returns a value equal to the last 'len' argument. 3139c2c66affSColin Finck * 3140c2c66affSColin Finck * \param ssl SSL context 3141c2c66affSColin Finck * \param buf buffer holding the data 3142c2c66affSColin Finck * \param len how many bytes must be written 3143c2c66affSColin Finck * 3144cbda039fSThomas Faber * \return The (non-negative) number of bytes actually written if 3145cbda039fSThomas Faber * successful (may be less than \p len). 3146cbda039fSThomas Faber * \return #MBEDTLS_ERR_SSL_WANT_READ or #MBEDTLS_ERR_SSL_WANT_WRITE 3147cbda039fSThomas Faber * if the handshake is incomplete and waiting for data to 3148cbda039fSThomas Faber * be available for reading from or writing to the underlying 3149cbda039fSThomas Faber * transport - in this case you must call this function again 3150cbda039fSThomas Faber * when the underlying transport is ready for the operation. 3151cbda039fSThomas Faber * \return #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS if an asynchronous 3152cbda039fSThomas Faber * operation is in progress (see 3153cbda039fSThomas Faber * mbedtls_ssl_conf_async_private_cb()) - in this case you 3154cbda039fSThomas Faber * must call this function again when the operation is ready. 3155cbda039fSThomas Faber * \return #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS if a cryptographic 3156cbda039fSThomas Faber * operation is in progress (see mbedtls_ecp_set_max_ops()) - 3157cbda039fSThomas Faber * in this case you must call this function again to complete 3158cbda039fSThomas Faber * the handshake when you're done attending other tasks. 3159cbda039fSThomas Faber * \return Another SSL error code - in this case you must stop using 3160cbda039fSThomas Faber * the context (see below). 3161c2c66affSColin Finck * 3162cbda039fSThomas Faber * \warning If this function returns something other than 3163cbda039fSThomas Faber * a non-negative value, 3164cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_WANT_READ, 3165cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_WANT_WRITE, 3166cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS or 3167cbda039fSThomas Faber * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS, 3168cbda039fSThomas Faber * you must stop using the SSL context for reading or writing, 3169cbda039fSThomas Faber * and either free it or call \c mbedtls_ssl_session_reset() 3170cbda039fSThomas Faber * on it before re-using it for a new connection; the current 3171cbda039fSThomas Faber * connection must be closed. 3172c2c66affSColin Finck * 3173cbda039fSThomas Faber * \note When this function returns #MBEDTLS_ERR_SSL_WANT_WRITE/READ, 3174c2c66affSColin Finck * it must be called later with the *same* arguments, 3175d9e6c9b5SThomas Faber * until it returns a value greater that or equal to 0. When 3176cbda039fSThomas Faber * the function returns #MBEDTLS_ERR_SSL_WANT_WRITE there may be 3177d9e6c9b5SThomas Faber * some partial data in the output buffer, however this is not 3178d9e6c9b5SThomas Faber * yet sent. 3179c2c66affSColin Finck * 3180c2c66affSColin Finck * \note If the requested length is greater than the maximum 3181c2c66affSColin Finck * fragment length (either the built-in limit or the one set 3182c2c66affSColin Finck * or negotiated with the peer), then: 3183c2c66affSColin Finck * - with TLS, less bytes than requested are written. 3184c2c66affSColin Finck * - with DTLS, MBEDTLS_ERR_SSL_BAD_INPUT_DATA is returned. 3185c2c66affSColin Finck * \c mbedtls_ssl_get_max_frag_len() may be used to query the 3186c2c66affSColin Finck * active maximum fragment length. 3187d9e6c9b5SThomas Faber * 3188d9e6c9b5SThomas Faber * \note Attempting to write 0 bytes will result in an empty TLS 3189d9e6c9b5SThomas Faber * application record being sent. 3190c2c66affSColin Finck */ 3191c2c66affSColin Finck int mbedtls_ssl_write( mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len ); 3192c2c66affSColin Finck 3193c2c66affSColin Finck /** 3194c2c66affSColin Finck * \brief Send an alert message 3195c2c66affSColin Finck * 3196c2c66affSColin Finck * \param ssl SSL context 3197c2c66affSColin Finck * \param level The alert level of the message 3198c2c66affSColin Finck * (MBEDTLS_SSL_ALERT_LEVEL_WARNING or MBEDTLS_SSL_ALERT_LEVEL_FATAL) 3199c2c66affSColin Finck * \param message The alert message (SSL_ALERT_MSG_*) 3200c2c66affSColin Finck * 3201c2c66affSColin Finck * \return 0 if successful, or a specific SSL error code. 3202c2c66affSColin Finck * 3203c2c66affSColin Finck * \note If this function returns something other than 0 or 3204cbda039fSThomas Faber * MBEDTLS_ERR_SSL_WANT_READ/WRITE, you must stop using 3205cbda039fSThomas Faber * the SSL context for reading or writing, and either free it or 3206cbda039fSThomas Faber * call \c mbedtls_ssl_session_reset() on it before re-using it 3207cbda039fSThomas Faber * for a new connection; the current connection must be closed. 3208c2c66affSColin Finck */ 3209c2c66affSColin Finck int mbedtls_ssl_send_alert_message( mbedtls_ssl_context *ssl, 3210c2c66affSColin Finck unsigned char level, 3211c2c66affSColin Finck unsigned char message ); 3212c2c66affSColin Finck /** 3213c2c66affSColin Finck * \brief Notify the peer that the connection is being closed 3214c2c66affSColin Finck * 3215c2c66affSColin Finck * \param ssl SSL context 3216c2c66affSColin Finck * 3217c2c66affSColin Finck * \return 0 if successful, or a specific SSL error code. 3218c2c66affSColin Finck * 3219c2c66affSColin Finck * \note If this function returns something other than 0 or 3220cbda039fSThomas Faber * MBEDTLS_ERR_SSL_WANT_READ/WRITE, you must stop using 3221cbda039fSThomas Faber * the SSL context for reading or writing, and either free it or 3222cbda039fSThomas Faber * call \c mbedtls_ssl_session_reset() on it before re-using it 3223cbda039fSThomas Faber * for a new connection; the current connection must be closed. 3224c2c66affSColin Finck */ 3225c2c66affSColin Finck int mbedtls_ssl_close_notify( mbedtls_ssl_context *ssl ); 3226c2c66affSColin Finck 3227c2c66affSColin Finck /** 3228c2c66affSColin Finck * \brief Free referenced items in an SSL context and clear memory 3229c2c66affSColin Finck * 3230c2c66affSColin Finck * \param ssl SSL context 3231c2c66affSColin Finck */ 3232c2c66affSColin Finck void mbedtls_ssl_free( mbedtls_ssl_context *ssl ); 3233c2c66affSColin Finck 3234c2c66affSColin Finck /** 3235c2c66affSColin Finck * \brief Initialize an SSL configuration context 3236c2c66affSColin Finck * Just makes the context ready for 3237c2c66affSColin Finck * mbedtls_ssl_config_defaults() or mbedtls_ssl_config_free(). 3238c2c66affSColin Finck * 3239c2c66affSColin Finck * \note You need to call mbedtls_ssl_config_defaults() unless you 3240c1eccaffSThomas Faber * manually set all of the relevant fields yourself. 3241c2c66affSColin Finck * 3242c2c66affSColin Finck * \param conf SSL configuration context 3243c2c66affSColin Finck */ 3244c2c66affSColin Finck void mbedtls_ssl_config_init( mbedtls_ssl_config *conf ); 3245c2c66affSColin Finck 3246c2c66affSColin Finck /** 3247c2c66affSColin Finck * \brief Load reasonnable default SSL configuration values. 3248c2c66affSColin Finck * (You need to call mbedtls_ssl_config_init() first.) 3249c2c66affSColin Finck * 3250c2c66affSColin Finck * \param conf SSL configuration context 3251c2c66affSColin Finck * \param endpoint MBEDTLS_SSL_IS_CLIENT or MBEDTLS_SSL_IS_SERVER 3252c2c66affSColin Finck * \param transport MBEDTLS_SSL_TRANSPORT_STREAM for TLS, or 3253c2c66affSColin Finck * MBEDTLS_SSL_TRANSPORT_DATAGRAM for DTLS 3254c2c66affSColin Finck * \param preset a MBEDTLS_SSL_PRESET_XXX value 3255c2c66affSColin Finck * 3256c2c66affSColin Finck * \note See \c mbedtls_ssl_conf_transport() for notes on DTLS. 3257c2c66affSColin Finck * 3258c2c66affSColin Finck * \return 0 if successful, or 3259c2c66affSColin Finck * MBEDTLS_ERR_XXX_ALLOC_FAILED on memory allocation error. 3260c2c66affSColin Finck */ 3261c2c66affSColin Finck int mbedtls_ssl_config_defaults( mbedtls_ssl_config *conf, 3262c2c66affSColin Finck int endpoint, int transport, int preset ); 3263c2c66affSColin Finck 3264c2c66affSColin Finck /** 3265c2c66affSColin Finck * \brief Free an SSL configuration context 3266c2c66affSColin Finck * 3267c2c66affSColin Finck * \param conf SSL configuration context 3268c2c66affSColin Finck */ 3269c2c66affSColin Finck void mbedtls_ssl_config_free( mbedtls_ssl_config *conf ); 3270c2c66affSColin Finck 3271c2c66affSColin Finck /** 3272c2c66affSColin Finck * \brief Initialize SSL session structure 3273c2c66affSColin Finck * 3274c2c66affSColin Finck * \param session SSL session 3275c2c66affSColin Finck */ 3276c2c66affSColin Finck void mbedtls_ssl_session_init( mbedtls_ssl_session *session ); 3277c2c66affSColin Finck 3278c2c66affSColin Finck /** 3279c2c66affSColin Finck * \brief Free referenced items in an SSL session including the 3280c2c66affSColin Finck * peer certificate and clear memory 3281c2c66affSColin Finck * 3282d9e6c9b5SThomas Faber * \note A session object can be freed even if the SSL context 3283d9e6c9b5SThomas Faber * that was used to retrieve the session is still in use. 3284d9e6c9b5SThomas Faber * 3285c2c66affSColin Finck * \param session SSL session 3286c2c66affSColin Finck */ 3287c2c66affSColin Finck void mbedtls_ssl_session_free( mbedtls_ssl_session *session ); 3288c2c66affSColin Finck 3289c2c66affSColin Finck #ifdef __cplusplus 3290c2c66affSColin Finck } 3291c2c66affSColin Finck #endif 3292c2c66affSColin Finck 3293c2c66affSColin Finck #endif /* ssl.h */ 3294