mbed client lightswitch demo

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by Austin Blackstone

Committer:
mbedAustin
Date:
Thu Jun 09 17:08:36 2016 +0000
Revision:
11:cada08fc8a70
Commit for public Consumption

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 11:cada08fc8a70 1 /**
mbedAustin 11:cada08fc8a70 2 * \file ssl.h
mbedAustin 11:cada08fc8a70 3 *
mbedAustin 11:cada08fc8a70 4 * \brief SSL/TLS functions.
mbedAustin 11:cada08fc8a70 5 *
mbedAustin 11:cada08fc8a70 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
mbedAustin 11:cada08fc8a70 7 * SPDX-License-Identifier: Apache-2.0
mbedAustin 11:cada08fc8a70 8 *
mbedAustin 11:cada08fc8a70 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
mbedAustin 11:cada08fc8a70 10 * not use this file except in compliance with the License.
mbedAustin 11:cada08fc8a70 11 * You may obtain a copy of the License at
mbedAustin 11:cada08fc8a70 12 *
mbedAustin 11:cada08fc8a70 13 * http://www.apache.org/licenses/LICENSE-2.0
mbedAustin 11:cada08fc8a70 14 *
mbedAustin 11:cada08fc8a70 15 * Unless required by applicable law or agreed to in writing, software
mbedAustin 11:cada08fc8a70 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
mbedAustin 11:cada08fc8a70 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbedAustin 11:cada08fc8a70 18 * See the License for the specific language governing permissions and
mbedAustin 11:cada08fc8a70 19 * limitations under the License.
mbedAustin 11:cada08fc8a70 20 *
mbedAustin 11:cada08fc8a70 21 * This file is part of mbed TLS (https://tls.mbed.org)
mbedAustin 11:cada08fc8a70 22 */
mbedAustin 11:cada08fc8a70 23 #ifndef MBEDTLS_SSL_H
mbedAustin 11:cada08fc8a70 24 #define MBEDTLS_SSL_H
mbedAustin 11:cada08fc8a70 25
mbedAustin 11:cada08fc8a70 26 #if !defined(MBEDTLS_CONFIG_FILE)
mbedAustin 11:cada08fc8a70 27 #include "config.h"
mbedAustin 11:cada08fc8a70 28 #else
mbedAustin 11:cada08fc8a70 29 #include MBEDTLS_CONFIG_FILE
mbedAustin 11:cada08fc8a70 30 #endif
mbedAustin 11:cada08fc8a70 31
mbedAustin 11:cada08fc8a70 32 #include "bignum.h"
mbedAustin 11:cada08fc8a70 33 #include "ecp.h"
mbedAustin 11:cada08fc8a70 34
mbedAustin 11:cada08fc8a70 35 #include "ssl_ciphersuites.h"
mbedAustin 11:cada08fc8a70 36
mbedAustin 11:cada08fc8a70 37 #if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedAustin 11:cada08fc8a70 38 #include "x509_crt.h"
mbedAustin 11:cada08fc8a70 39 #include "x509_crl.h"
mbedAustin 11:cada08fc8a70 40 #endif
mbedAustin 11:cada08fc8a70 41
mbedAustin 11:cada08fc8a70 42 #if defined(MBEDTLS_DHM_C)
mbedAustin 11:cada08fc8a70 43 #include "dhm.h"
mbedAustin 11:cada08fc8a70 44 #endif
mbedAustin 11:cada08fc8a70 45
mbedAustin 11:cada08fc8a70 46 #if defined(MBEDTLS_ECDH_C)
mbedAustin 11:cada08fc8a70 47 #include "ecdh.h"
mbedAustin 11:cada08fc8a70 48 #endif
mbedAustin 11:cada08fc8a70 49
mbedAustin 11:cada08fc8a70 50 #if defined(MBEDTLS_ZLIB_SUPPORT)
mbedAustin 11:cada08fc8a70 51 #include "zlib.h"
mbedAustin 11:cada08fc8a70 52 #endif
mbedAustin 11:cada08fc8a70 53
mbedAustin 11:cada08fc8a70 54 #if defined(MBEDTLS_HAVE_TIME)
mbedAustin 11:cada08fc8a70 55 #include <time.h>
mbedAustin 11:cada08fc8a70 56 #endif
mbedAustin 11:cada08fc8a70 57
mbedAustin 11:cada08fc8a70 58 /*
mbedAustin 11:cada08fc8a70 59 * SSL Error codes
mbedAustin 11:cada08fc8a70 60 */
mbedAustin 11:cada08fc8a70 61 #define MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE -0x7080 /**< The requested feature is not available. */
mbedAustin 11:cada08fc8a70 62 #define MBEDTLS_ERR_SSL_BAD_INPUT_DATA -0x7100 /**< Bad input parameters to function. */
mbedAustin 11:cada08fc8a70 63 #define MBEDTLS_ERR_SSL_INVALID_MAC -0x7180 /**< Verification of the message MAC failed. */
mbedAustin 11:cada08fc8a70 64 #define MBEDTLS_ERR_SSL_INVALID_RECORD -0x7200 /**< An invalid SSL record was received. */
mbedAustin 11:cada08fc8a70 65 #define MBEDTLS_ERR_SSL_CONN_EOF -0x7280 /**< The connection indicated an EOF. */
mbedAustin 11:cada08fc8a70 66 #define MBEDTLS_ERR_SSL_UNKNOWN_CIPHER -0x7300 /**< An unknown cipher was received. */
mbedAustin 11:cada08fc8a70 67 #define MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN -0x7380 /**< The server has no ciphersuites in common with the client. */
mbedAustin 11:cada08fc8a70 68 #define MBEDTLS_ERR_SSL_NO_RNG -0x7400 /**< No RNG was provided to the SSL module. */
mbedAustin 11:cada08fc8a70 69 #define MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480 /**< No client certification received from the client, but required by the authentication mode. */
mbedAustin 11:cada08fc8a70 70 #define MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500 /**< Our own certificate(s) is/are too large to send in an SSL message. */
mbedAustin 11:cada08fc8a70 71 #define MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED -0x7580 /**< The own certificate is not set, but needed by the server. */
mbedAustin 11:cada08fc8a70 72 #define MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600 /**< The own private key or pre-shared key is not set, but needed. */
mbedAustin 11:cada08fc8a70 73 #define MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED -0x7680 /**< No CA Chain is set, but required to operate. */
mbedAustin 11:cada08fc8a70 74 #define MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE -0x7700 /**< An unexpected message was received from our peer. */
mbedAustin 11:cada08fc8a70 75 #define MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780 /**< A fatal alert message was received from our peer. */
mbedAustin 11:cada08fc8a70 76 #define MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED -0x7800 /**< Verification of our peer failed. */
mbedAustin 11:cada08fc8a70 77 #define MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880 /**< The peer notified us that the connection is going to be closed. */
mbedAustin 11:cada08fc8a70 78 #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO -0x7900 /**< Processing of the ClientHello handshake message failed. */
mbedAustin 11:cada08fc8a70 79 #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO -0x7980 /**< Processing of the ServerHello handshake message failed. */
mbedAustin 11:cada08fc8a70 80 #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE -0x7A00 /**< Processing of the Certificate handshake message failed. */
mbedAustin 11:cada08fc8a70 81 #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST -0x7A80 /**< Processing of the CertificateRequest handshake message failed. */
mbedAustin 11:cada08fc8a70 82 #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE -0x7B00 /**< Processing of the ServerKeyExchange handshake message failed. */
mbedAustin 11:cada08fc8a70 83 #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE -0x7B80 /**< Processing of the ServerHelloDone handshake message failed. */
mbedAustin 11:cada08fc8a70 84 #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE -0x7C00 /**< Processing of the ClientKeyExchange handshake message failed. */
mbedAustin 11:cada08fc8a70 85 #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP -0x7C80 /**< Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public. */
mbedAustin 11:cada08fc8a70 86 #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS -0x7D00 /**< Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret. */
mbedAustin 11:cada08fc8a70 87 #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY -0x7D80 /**< Processing of the CertificateVerify handshake message failed. */
mbedAustin 11:cada08fc8a70 88 #define MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC -0x7E00 /**< Processing of the ChangeCipherSpec handshake message failed. */
mbedAustin 11:cada08fc8a70 89 #define MBEDTLS_ERR_SSL_BAD_HS_FINISHED -0x7E80 /**< Processing of the Finished handshake message failed. */
mbedAustin 11:cada08fc8a70 90 #define MBEDTLS_ERR_SSL_ALLOC_FAILED -0x7F00 /**< Memory allocation failed */
mbedAustin 11:cada08fc8a70 91 #define MBEDTLS_ERR_SSL_HW_ACCEL_FAILED -0x7F80 /**< Hardware acceleration function returned with error */
mbedAustin 11:cada08fc8a70 92 #define MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80 /**< Hardware acceleration function skipped / left alone data */
mbedAustin 11:cada08fc8a70 93 #define MBEDTLS_ERR_SSL_COMPRESSION_FAILED -0x6F00 /**< Processing of the compression / decompression failed */
mbedAustin 11:cada08fc8a70 94 #define MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION -0x6E80 /**< Handshake protocol not within min/max boundaries */
mbedAustin 11:cada08fc8a70 95 #define MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET -0x6E00 /**< Processing of the NewSessionTicket handshake message failed. */
mbedAustin 11:cada08fc8a70 96 #define MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED -0x6D80 /**< Session ticket has expired. */
mbedAustin 11:cada08fc8a70 97 #define MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH -0x6D00 /**< Public key type mismatch (eg, asked for RSA key exchange and presented EC key) */
mbedAustin 11:cada08fc8a70 98 #define MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY -0x6C80 /**< Unknown identity received (eg, PSK identity) */
mbedAustin 11:cada08fc8a70 99 #define MBEDTLS_ERR_SSL_INTERNAL_ERROR -0x6C00 /**< Internal error (eg, unexpected failure in lower-level module) */
mbedAustin 11:cada08fc8a70 100 #define MBEDTLS_ERR_SSL_COUNTER_WRAPPING -0x6B80 /**< A counter would wrap (eg, too many messages exchanged). */
mbedAustin 11:cada08fc8a70 101 #define MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO -0x6B00 /**< Unexpected message at ServerHello in renegotiation. */
mbedAustin 11:cada08fc8a70 102 #define MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED -0x6A80 /**< DTLS client must retry for hello verification */
mbedAustin 11:cada08fc8a70 103 #define MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL -0x6A00 /**< A buffer is too small to receive or write a message */
mbedAustin 11:cada08fc8a70 104 #define MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE -0x6980 /**< None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages). */
mbedAustin 11:cada08fc8a70 105 #define MBEDTLS_ERR_SSL_WANT_READ -0x6900 /**< Connection requires a read call. */
mbedAustin 11:cada08fc8a70 106 #define MBEDTLS_ERR_SSL_WANT_WRITE -0x6880 /**< Connection requires a write call. */
mbedAustin 11:cada08fc8a70 107 #define MBEDTLS_ERR_SSL_TIMEOUT -0x6800 /**< The operation timed out. */
mbedAustin 11:cada08fc8a70 108 #define MBEDTLS_ERR_SSL_CLIENT_RECONNECT -0x6780 /**< The client initiated a reconnect from the same port. */
mbedAustin 11:cada08fc8a70 109
mbedAustin 11:cada08fc8a70 110 /*
mbedAustin 11:cada08fc8a70 111 * Various constants
mbedAustin 11:cada08fc8a70 112 */
mbedAustin 11:cada08fc8a70 113 #define MBEDTLS_SSL_MAJOR_VERSION_3 3
mbedAustin 11:cada08fc8a70 114 #define MBEDTLS_SSL_MINOR_VERSION_0 0 /*!< SSL v3.0 */
mbedAustin 11:cada08fc8a70 115 #define MBEDTLS_SSL_MINOR_VERSION_1 1 /*!< TLS v1.0 */
mbedAustin 11:cada08fc8a70 116 #define MBEDTLS_SSL_MINOR_VERSION_2 2 /*!< TLS v1.1 */
mbedAustin 11:cada08fc8a70 117 #define MBEDTLS_SSL_MINOR_VERSION_3 3 /*!< TLS v1.2 */
mbedAustin 11:cada08fc8a70 118
mbedAustin 11:cada08fc8a70 119 #define MBEDTLS_SSL_TRANSPORT_STREAM 0 /*!< TLS */
mbedAustin 11:cada08fc8a70 120 #define MBEDTLS_SSL_TRANSPORT_DATAGRAM 1 /*!< DTLS */
mbedAustin 11:cada08fc8a70 121
mbedAustin 11:cada08fc8a70 122 #define MBEDTLS_SSL_MAX_HOST_NAME_LEN 255 /*!< Maximum host name defined in RFC 1035 */
mbedAustin 11:cada08fc8a70 123
mbedAustin 11:cada08fc8a70 124 /* RFC 6066 section 4, see also mfl_code_to_length in ssl_tls.c
mbedAustin 11:cada08fc8a70 125 * NONE must be zero so that memset()ing structure to zero works */
mbedAustin 11:cada08fc8a70 126 #define MBEDTLS_SSL_MAX_FRAG_LEN_NONE 0 /*!< don't use this extension */
mbedAustin 11:cada08fc8a70 127 #define MBEDTLS_SSL_MAX_FRAG_LEN_512 1 /*!< MaxFragmentLength 2^9 */
mbedAustin 11:cada08fc8a70 128 #define MBEDTLS_SSL_MAX_FRAG_LEN_1024 2 /*!< MaxFragmentLength 2^10 */
mbedAustin 11:cada08fc8a70 129 #define MBEDTLS_SSL_MAX_FRAG_LEN_2048 3 /*!< MaxFragmentLength 2^11 */
mbedAustin 11:cada08fc8a70 130 #define MBEDTLS_SSL_MAX_FRAG_LEN_4096 4 /*!< MaxFragmentLength 2^12 */
mbedAustin 11:cada08fc8a70 131 #define MBEDTLS_SSL_MAX_FRAG_LEN_INVALID 5 /*!< first invalid value */
mbedAustin 11:cada08fc8a70 132
mbedAustin 11:cada08fc8a70 133 #define MBEDTLS_SSL_IS_CLIENT 0
mbedAustin 11:cada08fc8a70 134 #define MBEDTLS_SSL_IS_SERVER 1
mbedAustin 11:cada08fc8a70 135
mbedAustin 11:cada08fc8a70 136 #define MBEDTLS_SSL_IS_NOT_FALLBACK 0
mbedAustin 11:cada08fc8a70 137 #define MBEDTLS_SSL_IS_FALLBACK 1
mbedAustin 11:cada08fc8a70 138
mbedAustin 11:cada08fc8a70 139 #define MBEDTLS_SSL_EXTENDED_MS_DISABLED 0
mbedAustin 11:cada08fc8a70 140 #define MBEDTLS_SSL_EXTENDED_MS_ENABLED 1
mbedAustin 11:cada08fc8a70 141
mbedAustin 11:cada08fc8a70 142 #define MBEDTLS_SSL_ETM_DISABLED 0
mbedAustin 11:cada08fc8a70 143 #define MBEDTLS_SSL_ETM_ENABLED 1
mbedAustin 11:cada08fc8a70 144
mbedAustin 11:cada08fc8a70 145 #define MBEDTLS_SSL_COMPRESS_NULL 0
mbedAustin 11:cada08fc8a70 146 #define MBEDTLS_SSL_COMPRESS_DEFLATE 1
mbedAustin 11:cada08fc8a70 147
mbedAustin 11:cada08fc8a70 148 #define MBEDTLS_SSL_VERIFY_NONE 0
mbedAustin 11:cada08fc8a70 149 #define MBEDTLS_SSL_VERIFY_OPTIONAL 1
mbedAustin 11:cada08fc8a70 150 #define MBEDTLS_SSL_VERIFY_REQUIRED 2
mbedAustin 11:cada08fc8a70 151 #define MBEDTLS_SSL_VERIFY_UNSET 3 /* Used only for sni_authmode */
mbedAustin 11:cada08fc8a70 152
mbedAustin 11:cada08fc8a70 153 #define MBEDTLS_SSL_LEGACY_RENEGOTIATION 0
mbedAustin 11:cada08fc8a70 154 #define MBEDTLS_SSL_SECURE_RENEGOTIATION 1
mbedAustin 11:cada08fc8a70 155
mbedAustin 11:cada08fc8a70 156 #define MBEDTLS_SSL_RENEGOTIATION_DISABLED 0
mbedAustin 11:cada08fc8a70 157 #define MBEDTLS_SSL_RENEGOTIATION_ENABLED 1
mbedAustin 11:cada08fc8a70 158
mbedAustin 11:cada08fc8a70 159 #define MBEDTLS_SSL_ANTI_REPLAY_DISABLED 0
mbedAustin 11:cada08fc8a70 160 #define MBEDTLS_SSL_ANTI_REPLAY_ENABLED 1
mbedAustin 11:cada08fc8a70 161
mbedAustin 11:cada08fc8a70 162 #define MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED -1
mbedAustin 11:cada08fc8a70 163 #define MBEDTLS_SSL_RENEGO_MAX_RECORDS_DEFAULT 16
mbedAustin 11:cada08fc8a70 164
mbedAustin 11:cada08fc8a70 165 #define MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION 0
mbedAustin 11:cada08fc8a70 166 #define MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION 1
mbedAustin 11:cada08fc8a70 167 #define MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE 2
mbedAustin 11:cada08fc8a70 168
mbedAustin 11:cada08fc8a70 169 #define MBEDTLS_SSL_TRUNC_HMAC_DISABLED 0
mbedAustin 11:cada08fc8a70 170 #define MBEDTLS_SSL_TRUNC_HMAC_ENABLED 1
mbedAustin 11:cada08fc8a70 171 #define MBEDTLS_SSL_TRUNCATED_HMAC_LEN 10 /* 80 bits, rfc 6066 section 7 */
mbedAustin 11:cada08fc8a70 172
mbedAustin 11:cada08fc8a70 173 #define MBEDTLS_SSL_SESSION_TICKETS_DISABLED 0
mbedAustin 11:cada08fc8a70 174 #define MBEDTLS_SSL_SESSION_TICKETS_ENABLED 1
mbedAustin 11:cada08fc8a70 175
mbedAustin 11:cada08fc8a70 176 #define MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED 0
mbedAustin 11:cada08fc8a70 177 #define MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED 1
mbedAustin 11:cada08fc8a70 178
mbedAustin 11:cada08fc8a70 179 #define MBEDTLS_SSL_ARC4_ENABLED 0
mbedAustin 11:cada08fc8a70 180 #define MBEDTLS_SSL_ARC4_DISABLED 1
mbedAustin 11:cada08fc8a70 181
mbedAustin 11:cada08fc8a70 182 #define MBEDTLS_SSL_PRESET_DEFAULT 0
mbedAustin 11:cada08fc8a70 183 #define MBEDTLS_SSL_PRESET_SUITEB 2
mbedAustin 11:cada08fc8a70 184
mbedAustin 11:cada08fc8a70 185 /*
mbedAustin 11:cada08fc8a70 186 * Default range for DTLS retransmission timer value, in milliseconds.
mbedAustin 11:cada08fc8a70 187 * RFC 6347 4.2.4.1 says from 1 second to 60 seconds.
mbedAustin 11:cada08fc8a70 188 */
mbedAustin 11:cada08fc8a70 189 #define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MIN 1000
mbedAustin 11:cada08fc8a70 190 #define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MAX 60000
mbedAustin 11:cada08fc8a70 191
mbedAustin 11:cada08fc8a70 192 /**
mbedAustin 11:cada08fc8a70 193 * \name SECTION: Module settings
mbedAustin 11:cada08fc8a70 194 *
mbedAustin 11:cada08fc8a70 195 * The configuration options you can set for this module are in this section.
mbedAustin 11:cada08fc8a70 196 * Either change them in config.h or define them on the compiler command line.
mbedAustin 11:cada08fc8a70 197 * \{
mbedAustin 11:cada08fc8a70 198 */
mbedAustin 11:cada08fc8a70 199
mbedAustin 11:cada08fc8a70 200 #if !defined(MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME)
mbedAustin 11:cada08fc8a70 201 #define MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME 86400 /**< Lifetime of session tickets (if enabled) */
mbedAustin 11:cada08fc8a70 202 #endif
mbedAustin 11:cada08fc8a70 203
mbedAustin 11:cada08fc8a70 204 /*
mbedAustin 11:cada08fc8a70 205 * Maxium fragment length in bytes,
mbedAustin 11:cada08fc8a70 206 * determines the size of each of the two internal I/O buffers.
mbedAustin 11:cada08fc8a70 207 *
mbedAustin 11:cada08fc8a70 208 * Note: the RFC defines the default size of SSL / TLS messages. If you
mbedAustin 11:cada08fc8a70 209 * change the value here, other clients / servers may not be able to
mbedAustin 11:cada08fc8a70 210 * communicate with you anymore. Only change this value if you control
mbedAustin 11:cada08fc8a70 211 * both sides of the connection and have it reduced at both sides, or
mbedAustin 11:cada08fc8a70 212 * if you're using the Max Fragment Length extension and you know all your
mbedAustin 11:cada08fc8a70 213 * peers are using it too!
mbedAustin 11:cada08fc8a70 214 */
mbedAustin 11:cada08fc8a70 215 #if !defined(MBEDTLS_SSL_MAX_CONTENT_LEN)
mbedAustin 11:cada08fc8a70 216 #define MBEDTLS_SSL_MAX_CONTENT_LEN 16384 /**< Size of the input / output buffer */
mbedAustin 11:cada08fc8a70 217 #endif
mbedAustin 11:cada08fc8a70 218
mbedAustin 11:cada08fc8a70 219 /* \} name SECTION: Module settings */
mbedAustin 11:cada08fc8a70 220
mbedAustin 11:cada08fc8a70 221 /*
mbedAustin 11:cada08fc8a70 222 * Length of the verify data for secure renegotiation
mbedAustin 11:cada08fc8a70 223 */
mbedAustin 11:cada08fc8a70 224 #if defined(MBEDTLS_SSL_PROTO_SSL3)
mbedAustin 11:cada08fc8a70 225 #define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 36
mbedAustin 11:cada08fc8a70 226 #else
mbedAustin 11:cada08fc8a70 227 #define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 12
mbedAustin 11:cada08fc8a70 228 #endif
mbedAustin 11:cada08fc8a70 229
mbedAustin 11:cada08fc8a70 230 /*
mbedAustin 11:cada08fc8a70 231 * Signaling ciphersuite values (SCSV)
mbedAustin 11:cada08fc8a70 232 */
mbedAustin 11:cada08fc8a70 233 #define MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO 0xFF /**< renegotiation info ext */
mbedAustin 11:cada08fc8a70 234 #define MBEDTLS_SSL_FALLBACK_SCSV_VALUE 0x5600 /**< draft-ietf-tls-downgrade-scsv-00 */
mbedAustin 11:cada08fc8a70 235
mbedAustin 11:cada08fc8a70 236 /*
mbedAustin 11:cada08fc8a70 237 * Supported Signature and Hash algorithms (For TLS 1.2)
mbedAustin 11:cada08fc8a70 238 * RFC 5246 section 7.4.1.4.1
mbedAustin 11:cada08fc8a70 239 */
mbedAustin 11:cada08fc8a70 240 #define MBEDTLS_SSL_HASH_NONE 0
mbedAustin 11:cada08fc8a70 241 #define MBEDTLS_SSL_HASH_MD5 1
mbedAustin 11:cada08fc8a70 242 #define MBEDTLS_SSL_HASH_SHA1 2
mbedAustin 11:cada08fc8a70 243 #define MBEDTLS_SSL_HASH_SHA224 3
mbedAustin 11:cada08fc8a70 244 #define MBEDTLS_SSL_HASH_SHA256 4
mbedAustin 11:cada08fc8a70 245 #define MBEDTLS_SSL_HASH_SHA384 5
mbedAustin 11:cada08fc8a70 246 #define MBEDTLS_SSL_HASH_SHA512 6
mbedAustin 11:cada08fc8a70 247
mbedAustin 11:cada08fc8a70 248 #define MBEDTLS_SSL_SIG_ANON 0
mbedAustin 11:cada08fc8a70 249 #define MBEDTLS_SSL_SIG_RSA 1
mbedAustin 11:cada08fc8a70 250 #define MBEDTLS_SSL_SIG_ECDSA 3
mbedAustin 11:cada08fc8a70 251
mbedAustin 11:cada08fc8a70 252 /*
mbedAustin 11:cada08fc8a70 253 * Client Certificate Types
mbedAustin 11:cada08fc8a70 254 * RFC 5246 section 7.4.4 plus RFC 4492 section 5.5
mbedAustin 11:cada08fc8a70 255 */
mbedAustin 11:cada08fc8a70 256 #define MBEDTLS_SSL_CERT_TYPE_RSA_SIGN 1
mbedAustin 11:cada08fc8a70 257 #define MBEDTLS_SSL_CERT_TYPE_ECDSA_SIGN 64
mbedAustin 11:cada08fc8a70 258
mbedAustin 11:cada08fc8a70 259 /*
mbedAustin 11:cada08fc8a70 260 * Message, alert and handshake types
mbedAustin 11:cada08fc8a70 261 */
mbedAustin 11:cada08fc8a70 262 #define MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC 20
mbedAustin 11:cada08fc8a70 263 #define MBEDTLS_SSL_MSG_ALERT 21
mbedAustin 11:cada08fc8a70 264 #define MBEDTLS_SSL_MSG_HANDSHAKE 22
mbedAustin 11:cada08fc8a70 265 #define MBEDTLS_SSL_MSG_APPLICATION_DATA 23
mbedAustin 11:cada08fc8a70 266
mbedAustin 11:cada08fc8a70 267 #define MBEDTLS_SSL_ALERT_LEVEL_WARNING 1
mbedAustin 11:cada08fc8a70 268 #define MBEDTLS_SSL_ALERT_LEVEL_FATAL 2
mbedAustin 11:cada08fc8a70 269
mbedAustin 11:cada08fc8a70 270 #define MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY 0 /* 0x00 */
mbedAustin 11:cada08fc8a70 271 #define MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE 10 /* 0x0A */
mbedAustin 11:cada08fc8a70 272 #define MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC 20 /* 0x14 */
mbedAustin 11:cada08fc8a70 273 #define MBEDTLS_SSL_ALERT_MSG_DECRYPTION_FAILED 21 /* 0x15 */
mbedAustin 11:cada08fc8a70 274 #define MBEDTLS_SSL_ALERT_MSG_RECORD_OVERFLOW 22 /* 0x16 */
mbedAustin 11:cada08fc8a70 275 #define MBEDTLS_SSL_ALERT_MSG_DECOMPRESSION_FAILURE 30 /* 0x1E */
mbedAustin 11:cada08fc8a70 276 #define MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE 40 /* 0x28 */
mbedAustin 11:cada08fc8a70 277 #define MBEDTLS_SSL_ALERT_MSG_NO_CERT 41 /* 0x29 */
mbedAustin 11:cada08fc8a70 278 #define MBEDTLS_SSL_ALERT_MSG_BAD_CERT 42 /* 0x2A */
mbedAustin 11:cada08fc8a70 279 #define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT 43 /* 0x2B */
mbedAustin 11:cada08fc8a70 280 #define MBEDTLS_SSL_ALERT_MSG_CERT_REVOKED 44 /* 0x2C */
mbedAustin 11:cada08fc8a70 281 #define MBEDTLS_SSL_ALERT_MSG_CERT_EXPIRED 45 /* 0x2D */
mbedAustin 11:cada08fc8a70 282 #define MBEDTLS_SSL_ALERT_MSG_CERT_UNKNOWN 46 /* 0x2E */
mbedAustin 11:cada08fc8a70 283 #define MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER 47 /* 0x2F */
mbedAustin 11:cada08fc8a70 284 #define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_CA 48 /* 0x30 */
mbedAustin 11:cada08fc8a70 285 #define MBEDTLS_SSL_ALERT_MSG_ACCESS_DENIED 49 /* 0x31 */
mbedAustin 11:cada08fc8a70 286 #define MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR 50 /* 0x32 */
mbedAustin 11:cada08fc8a70 287 #define MBEDTLS_SSL_ALERT_MSG_DECRYPT_ERROR 51 /* 0x33 */
mbedAustin 11:cada08fc8a70 288 #define MBEDTLS_SSL_ALERT_MSG_EXPORT_RESTRICTION 60 /* 0x3C */
mbedAustin 11:cada08fc8a70 289 #define MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION 70 /* 0x46 */
mbedAustin 11:cada08fc8a70 290 #define MBEDTLS_SSL_ALERT_MSG_INSUFFICIENT_SECURITY 71 /* 0x47 */
mbedAustin 11:cada08fc8a70 291 #define MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR 80 /* 0x50 */
mbedAustin 11:cada08fc8a70 292 #define MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK 86 /* 0x56 */
mbedAustin 11:cada08fc8a70 293 #define MBEDTLS_SSL_ALERT_MSG_USER_CANCELED 90 /* 0x5A */
mbedAustin 11:cada08fc8a70 294 #define MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION 100 /* 0x64 */
mbedAustin 11:cada08fc8a70 295 #define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT 110 /* 0x6E */
mbedAustin 11:cada08fc8a70 296 #define MBEDTLS_SSL_ALERT_MSG_UNRECOGNIZED_NAME 112 /* 0x70 */
mbedAustin 11:cada08fc8a70 297 #define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY 115 /* 0x73 */
mbedAustin 11:cada08fc8a70 298 #define MBEDTLS_SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL 120 /* 0x78 */
mbedAustin 11:cada08fc8a70 299
mbedAustin 11:cada08fc8a70 300 #define MBEDTLS_SSL_HS_HELLO_REQUEST 0
mbedAustin 11:cada08fc8a70 301 #define MBEDTLS_SSL_HS_CLIENT_HELLO 1
mbedAustin 11:cada08fc8a70 302 #define MBEDTLS_SSL_HS_SERVER_HELLO 2
mbedAustin 11:cada08fc8a70 303 #define MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST 3
mbedAustin 11:cada08fc8a70 304 #define MBEDTLS_SSL_HS_NEW_SESSION_TICKET 4
mbedAustin 11:cada08fc8a70 305 #define MBEDTLS_SSL_HS_CERTIFICATE 11
mbedAustin 11:cada08fc8a70 306 #define MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE 12
mbedAustin 11:cada08fc8a70 307 #define MBEDTLS_SSL_HS_CERTIFICATE_REQUEST 13
mbedAustin 11:cada08fc8a70 308 #define MBEDTLS_SSL_HS_SERVER_HELLO_DONE 14
mbedAustin 11:cada08fc8a70 309 #define MBEDTLS_SSL_HS_CERTIFICATE_VERIFY 15
mbedAustin 11:cada08fc8a70 310 #define MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE 16
mbedAustin 11:cada08fc8a70 311 #define MBEDTLS_SSL_HS_FINISHED 20
mbedAustin 11:cada08fc8a70 312
mbedAustin 11:cada08fc8a70 313 /*
mbedAustin 11:cada08fc8a70 314 * TLS extensions
mbedAustin 11:cada08fc8a70 315 */
mbedAustin 11:cada08fc8a70 316 #define MBEDTLS_TLS_EXT_SERVERNAME 0
mbedAustin 11:cada08fc8a70 317 #define MBEDTLS_TLS_EXT_SERVERNAME_HOSTNAME 0
mbedAustin 11:cada08fc8a70 318
mbedAustin 11:cada08fc8a70 319 #define MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH 1
mbedAustin 11:cada08fc8a70 320
mbedAustin 11:cada08fc8a70 321 #define MBEDTLS_TLS_EXT_TRUNCATED_HMAC 4
mbedAustin 11:cada08fc8a70 322
mbedAustin 11:cada08fc8a70 323 #define MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES 10
mbedAustin 11:cada08fc8a70 324 #define MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS 11
mbedAustin 11:cada08fc8a70 325
mbedAustin 11:cada08fc8a70 326 #define MBEDTLS_TLS_EXT_SIG_ALG 13
mbedAustin 11:cada08fc8a70 327
mbedAustin 11:cada08fc8a70 328 #define MBEDTLS_TLS_EXT_ALPN 16
mbedAustin 11:cada08fc8a70 329
mbedAustin 11:cada08fc8a70 330 #define MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC 22 /* 0x16 */
mbedAustin 11:cada08fc8a70 331 #define MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET 0x0017 /* 23 */
mbedAustin 11:cada08fc8a70 332
mbedAustin 11:cada08fc8a70 333 #define MBEDTLS_TLS_EXT_SESSION_TICKET 35
mbedAustin 11:cada08fc8a70 334
mbedAustin 11:cada08fc8a70 335 #define MBEDTLS_TLS_EXT_ECJPAKE_KKPP 256 /* experimental */
mbedAustin 11:cada08fc8a70 336
mbedAustin 11:cada08fc8a70 337 #define MBEDTLS_TLS_EXT_RENEGOTIATION_INFO 0xFF01
mbedAustin 11:cada08fc8a70 338
mbedAustin 11:cada08fc8a70 339 /*
mbedAustin 11:cada08fc8a70 340 * Size defines
mbedAustin 11:cada08fc8a70 341 */
mbedAustin 11:cada08fc8a70 342 #if !defined(MBEDTLS_PSK_MAX_LEN)
mbedAustin 11:cada08fc8a70 343 #define MBEDTLS_PSK_MAX_LEN 32 /* 256 bits */
mbedAustin 11:cada08fc8a70 344 #endif
mbedAustin 11:cada08fc8a70 345
mbedAustin 11:cada08fc8a70 346 /* Dummy type used only for its size */
mbedAustin 11:cada08fc8a70 347 union mbedtls_ssl_premaster_secret
mbedAustin 11:cada08fc8a70 348 {
mbedAustin 11:cada08fc8a70 349 #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED)
mbedAustin 11:cada08fc8a70 350 unsigned char _pms_rsa[48]; /* RFC 5246 8.1.1 */
mbedAustin 11:cada08fc8a70 351 #endif
mbedAustin 11:cada08fc8a70 352 #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED)
mbedAustin 11:cada08fc8a70 353 unsigned char _pms_dhm[MBEDTLS_MPI_MAX_SIZE]; /* RFC 5246 8.1.2 */
mbedAustin 11:cada08fc8a70 354 #endif
mbedAustin 11:cada08fc8a70 355 #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
mbedAustin 11:cada08fc8a70 356 defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
mbedAustin 11:cada08fc8a70 357 defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
mbedAustin 11:cada08fc8a70 358 defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
mbedAustin 11:cada08fc8a70 359 unsigned char _pms_ecdh[MBEDTLS_ECP_MAX_BYTES]; /* RFC 4492 5.10 */
mbedAustin 11:cada08fc8a70 360 #endif
mbedAustin 11:cada08fc8a70 361 #if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
mbedAustin 11:cada08fc8a70 362 unsigned char _pms_psk[4 + 2 * MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 2 */
mbedAustin 11:cada08fc8a70 363 #endif
mbedAustin 11:cada08fc8a70 364 #if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED)
mbedAustin 11:cada08fc8a70 365 unsigned char _pms_dhe_psk[4 + MBEDTLS_MPI_MAX_SIZE
mbedAustin 11:cada08fc8a70 366 + MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 3 */
mbedAustin 11:cada08fc8a70 367 #endif
mbedAustin 11:cada08fc8a70 368 #if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED)
mbedAustin 11:cada08fc8a70 369 unsigned char _pms_rsa_psk[52 + MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 4 */
mbedAustin 11:cada08fc8a70 370 #endif
mbedAustin 11:cada08fc8a70 371 #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
mbedAustin 11:cada08fc8a70 372 unsigned char _pms_ecdhe_psk[4 + MBEDTLS_ECP_MAX_BYTES
mbedAustin 11:cada08fc8a70 373 + MBEDTLS_PSK_MAX_LEN]; /* RFC 5489 2 */
mbedAustin 11:cada08fc8a70 374 #endif
mbedAustin 11:cada08fc8a70 375 #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
mbedAustin 11:cada08fc8a70 376 unsigned char _pms_ecjpake[32]; /* Thread spec: SHA-256 output */
mbedAustin 11:cada08fc8a70 377 #endif
mbedAustin 11:cada08fc8a70 378 };
mbedAustin 11:cada08fc8a70 379
mbedAustin 11:cada08fc8a70 380 #define MBEDTLS_PREMASTER_SIZE sizeof( union mbedtls_ssl_premaster_secret )
mbedAustin 11:cada08fc8a70 381
mbedAustin 11:cada08fc8a70 382 #ifdef __cplusplus
mbedAustin 11:cada08fc8a70 383 extern "C" {
mbedAustin 11:cada08fc8a70 384 #endif
mbedAustin 11:cada08fc8a70 385
mbedAustin 11:cada08fc8a70 386 /*
mbedAustin 11:cada08fc8a70 387 * SSL state machine
mbedAustin 11:cada08fc8a70 388 */
mbedAustin 11:cada08fc8a70 389 typedef enum
mbedAustin 11:cada08fc8a70 390 {
mbedAustin 11:cada08fc8a70 391 MBEDTLS_SSL_HELLO_REQUEST,
mbedAustin 11:cada08fc8a70 392 MBEDTLS_SSL_CLIENT_HELLO,
mbedAustin 11:cada08fc8a70 393 MBEDTLS_SSL_SERVER_HELLO,
mbedAustin 11:cada08fc8a70 394 MBEDTLS_SSL_SERVER_CERTIFICATE,
mbedAustin 11:cada08fc8a70 395 MBEDTLS_SSL_SERVER_KEY_EXCHANGE,
mbedAustin 11:cada08fc8a70 396 MBEDTLS_SSL_CERTIFICATE_REQUEST,
mbedAustin 11:cada08fc8a70 397 MBEDTLS_SSL_SERVER_HELLO_DONE,
mbedAustin 11:cada08fc8a70 398 MBEDTLS_SSL_CLIENT_CERTIFICATE,
mbedAustin 11:cada08fc8a70 399 MBEDTLS_SSL_CLIENT_KEY_EXCHANGE,
mbedAustin 11:cada08fc8a70 400 MBEDTLS_SSL_CERTIFICATE_VERIFY,
mbedAustin 11:cada08fc8a70 401 MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC,
mbedAustin 11:cada08fc8a70 402 MBEDTLS_SSL_CLIENT_FINISHED,
mbedAustin 11:cada08fc8a70 403 MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC,
mbedAustin 11:cada08fc8a70 404 MBEDTLS_SSL_SERVER_FINISHED,
mbedAustin 11:cada08fc8a70 405 MBEDTLS_SSL_FLUSH_BUFFERS,
mbedAustin 11:cada08fc8a70 406 MBEDTLS_SSL_HANDSHAKE_WRAPUP,
mbedAustin 11:cada08fc8a70 407 MBEDTLS_SSL_HANDSHAKE_OVER,
mbedAustin 11:cada08fc8a70 408 MBEDTLS_SSL_SERVER_NEW_SESSION_TICKET,
mbedAustin 11:cada08fc8a70 409 MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT,
mbedAustin 11:cada08fc8a70 410 }
mbedAustin 11:cada08fc8a70 411 mbedtls_ssl_states;
mbedAustin 11:cada08fc8a70 412
mbedAustin 11:cada08fc8a70 413 /* Defined below */
mbedAustin 11:cada08fc8a70 414 typedef struct mbedtls_ssl_session mbedtls_ssl_session;
mbedAustin 11:cada08fc8a70 415 typedef struct mbedtls_ssl_context mbedtls_ssl_context;
mbedAustin 11:cada08fc8a70 416 typedef struct mbedtls_ssl_config mbedtls_ssl_config;
mbedAustin 11:cada08fc8a70 417
mbedAustin 11:cada08fc8a70 418 /* Defined in ssl_internal.h */
mbedAustin 11:cada08fc8a70 419 typedef struct mbedtls_ssl_transform mbedtls_ssl_transform;
mbedAustin 11:cada08fc8a70 420 typedef struct mbedtls_ssl_handshake_params mbedtls_ssl_handshake_params;
mbedAustin 11:cada08fc8a70 421 #if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedAustin 11:cada08fc8a70 422 typedef struct mbedtls_ssl_key_cert mbedtls_ssl_key_cert;
mbedAustin 11:cada08fc8a70 423 #endif
mbedAustin 11:cada08fc8a70 424 #if defined(MBEDTLS_SSL_PROTO_DTLS)
mbedAustin 11:cada08fc8a70 425 typedef struct mbedtls_ssl_flight_item mbedtls_ssl_flight_item;
mbedAustin 11:cada08fc8a70 426 #endif
mbedAustin 11:cada08fc8a70 427
mbedAustin 11:cada08fc8a70 428 /*
mbedAustin 11:cada08fc8a70 429 * This structure is used for storing current session data.
mbedAustin 11:cada08fc8a70 430 */
mbedAustin 11:cada08fc8a70 431 struct mbedtls_ssl_session
mbedAustin 11:cada08fc8a70 432 {
mbedAustin 11:cada08fc8a70 433 #if defined(MBEDTLS_HAVE_TIME)
mbedAustin 11:cada08fc8a70 434 time_t start; /*!< starting time */
mbedAustin 11:cada08fc8a70 435 #endif
mbedAustin 11:cada08fc8a70 436 int ciphersuite; /*!< chosen ciphersuite */
mbedAustin 11:cada08fc8a70 437 int compression; /*!< chosen compression */
mbedAustin 11:cada08fc8a70 438 size_t id_len; /*!< session id length */
mbedAustin 11:cada08fc8a70 439 unsigned char id[32]; /*!< session identifier */
mbedAustin 11:cada08fc8a70 440 unsigned char master[48]; /*!< the master secret */
mbedAustin 11:cada08fc8a70 441
mbedAustin 11:cada08fc8a70 442 #if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedAustin 11:cada08fc8a70 443 mbedtls_x509_crt *peer_cert; /*!< peer X.509 cert chain */
mbedAustin 11:cada08fc8a70 444 #endif /* MBEDTLS_X509_CRT_PARSE_C */
mbedAustin 11:cada08fc8a70 445 uint32_t verify_result; /*!< verification result */
mbedAustin 11:cada08fc8a70 446
mbedAustin 11:cada08fc8a70 447 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
mbedAustin 11:cada08fc8a70 448 unsigned char *ticket; /*!< RFC 5077 session ticket */
mbedAustin 11:cada08fc8a70 449 size_t ticket_len; /*!< session ticket length */
mbedAustin 11:cada08fc8a70 450 uint32_t ticket_lifetime; /*!< ticket lifetime hint */
mbedAustin 11:cada08fc8a70 451 #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
mbedAustin 11:cada08fc8a70 452
mbedAustin 11:cada08fc8a70 453 #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
mbedAustin 11:cada08fc8a70 454 unsigned char mfl_code; /*!< MaxFragmentLength negotiated by peer */
mbedAustin 11:cada08fc8a70 455 #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
mbedAustin 11:cada08fc8a70 456
mbedAustin 11:cada08fc8a70 457 #if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
mbedAustin 11:cada08fc8a70 458 int trunc_hmac; /*!< flag for truncated hmac activation */
mbedAustin 11:cada08fc8a70 459 #endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
mbedAustin 11:cada08fc8a70 460
mbedAustin 11:cada08fc8a70 461 #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
mbedAustin 11:cada08fc8a70 462 int encrypt_then_mac; /*!< flag for EtM activation */
mbedAustin 11:cada08fc8a70 463 #endif
mbedAustin 11:cada08fc8a70 464 };
mbedAustin 11:cada08fc8a70 465
mbedAustin 11:cada08fc8a70 466 /**
mbedAustin 11:cada08fc8a70 467 * SSL/TLS configuration to be shared between mbedtls_ssl_context structures.
mbedAustin 11:cada08fc8a70 468 */
mbedAustin 11:cada08fc8a70 469 struct mbedtls_ssl_config
mbedAustin 11:cada08fc8a70 470 {
mbedAustin 11:cada08fc8a70 471 /* Group items by size (largest first) to minimize padding overhead */
mbedAustin 11:cada08fc8a70 472
mbedAustin 11:cada08fc8a70 473 /*
mbedAustin 11:cada08fc8a70 474 * Pointers
mbedAustin 11:cada08fc8a70 475 */
mbedAustin 11:cada08fc8a70 476
mbedAustin 11:cada08fc8a70 477 const int *ciphersuite_list[4]; /*!< allowed ciphersuites per version */
mbedAustin 11:cada08fc8a70 478
mbedAustin 11:cada08fc8a70 479 /** Callback for printing debug output */
mbedAustin 11:cada08fc8a70 480 void (*f_dbg)(void *, int, const char *, int, const char *);
mbedAustin 11:cada08fc8a70 481 void *p_dbg; /*!< context for the debug function */
mbedAustin 11:cada08fc8a70 482
mbedAustin 11:cada08fc8a70 483 /** Callback for getting (pseudo-)random numbers */
mbedAustin 11:cada08fc8a70 484 int (*f_rng)(void *, unsigned char *, size_t);
mbedAustin 11:cada08fc8a70 485 void *p_rng; /*!< context for the RNG function */
mbedAustin 11:cada08fc8a70 486
mbedAustin 11:cada08fc8a70 487 /** Callback to retrieve a session from the cache */
mbedAustin 11:cada08fc8a70 488 int (*f_get_cache)(void *, mbedtls_ssl_session *);
mbedAustin 11:cada08fc8a70 489 /** Callback to store a session into the cache */
mbedAustin 11:cada08fc8a70 490 int (*f_set_cache)(void *, const mbedtls_ssl_session *);
mbedAustin 11:cada08fc8a70 491 void *p_cache; /*!< context for cache callbacks */
mbedAustin 11:cada08fc8a70 492
mbedAustin 11:cada08fc8a70 493 #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
mbedAustin 11:cada08fc8a70 494 /** Callback for setting cert according to SNI extension */
mbedAustin 11:cada08fc8a70 495 int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
mbedAustin 11:cada08fc8a70 496 void *p_sni; /*!< context for SNI callback */
mbedAustin 11:cada08fc8a70 497 #endif
mbedAustin 11:cada08fc8a70 498
mbedAustin 11:cada08fc8a70 499 #if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedAustin 11:cada08fc8a70 500 /** Callback to customize X.509 certificate chain verification */
mbedAustin 11:cada08fc8a70 501 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *);
mbedAustin 11:cada08fc8a70 502 void *p_vrfy; /*!< context for X.509 verify calllback */
mbedAustin 11:cada08fc8a70 503 #endif
mbedAustin 11:cada08fc8a70 504
mbedAustin 11:cada08fc8a70 505 #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
mbedAustin 11:cada08fc8a70 506 /** Callback to retrieve PSK key from identity */
mbedAustin 11:cada08fc8a70 507 int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
mbedAustin 11:cada08fc8a70 508 void *p_psk; /*!< context for PSK callback */
mbedAustin 11:cada08fc8a70 509 #endif
mbedAustin 11:cada08fc8a70 510
mbedAustin 11:cada08fc8a70 511 #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
mbedAustin 11:cada08fc8a70 512 /** Callback to create & write a cookie for ClientHello veirifcation */
mbedAustin 11:cada08fc8a70 513 int (*f_cookie_write)( void *, unsigned char **, unsigned char *,
mbedAustin 11:cada08fc8a70 514 const unsigned char *, size_t );
mbedAustin 11:cada08fc8a70 515 /** Callback to verify validity of a ClientHello cookie */
mbedAustin 11:cada08fc8a70 516 int (*f_cookie_check)( void *, const unsigned char *, size_t,
mbedAustin 11:cada08fc8a70 517 const unsigned char *, size_t );
mbedAustin 11:cada08fc8a70 518 void *p_cookie; /*!< context for the cookie callbacks */
mbedAustin 11:cada08fc8a70 519 #endif
mbedAustin 11:cada08fc8a70 520
mbedAustin 11:cada08fc8a70 521 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
mbedAustin 11:cada08fc8a70 522 /** Callback to create & write a session ticket */
mbedAustin 11:cada08fc8a70 523 int (*f_ticket_write)( void *, const mbedtls_ssl_session *,
mbedAustin 11:cada08fc8a70 524 unsigned char *, const unsigned char *, size_t *, uint32_t * );
mbedAustin 11:cada08fc8a70 525 /** Callback to parse a session ticket into a session structure */
mbedAustin 11:cada08fc8a70 526 int (*f_ticket_parse)( void *, mbedtls_ssl_session *, unsigned char *, size_t);
mbedAustin 11:cada08fc8a70 527 void *p_ticket; /*!< context for the ticket callbacks */
mbedAustin 11:cada08fc8a70 528 #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
mbedAustin 11:cada08fc8a70 529
mbedAustin 11:cada08fc8a70 530 #if defined(MBEDTLS_SSL_EXPORT_KEYS)
mbedAustin 11:cada08fc8a70 531 /** Callback to export key block and master secret */
mbedAustin 11:cada08fc8a70 532 int (*f_export_keys)( void *, const unsigned char *,
mbedAustin 11:cada08fc8a70 533 const unsigned char *, size_t, size_t, size_t );
mbedAustin 11:cada08fc8a70 534 void *p_export_keys; /*!< context for key export callback */
mbedAustin 11:cada08fc8a70 535 #endif
mbedAustin 11:cada08fc8a70 536
mbedAustin 11:cada08fc8a70 537 #if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedAustin 11:cada08fc8a70 538 const mbedtls_x509_crt_profile *cert_profile; /*!< verification profile */
mbedAustin 11:cada08fc8a70 539 mbedtls_ssl_key_cert *key_cert; /*!< own certificate/key pair(s) */
mbedAustin 11:cada08fc8a70 540 mbedtls_x509_crt *ca_chain; /*!< trusted CAs */
mbedAustin 11:cada08fc8a70 541 mbedtls_x509_crl *ca_crl; /*!< trusted CAs CRLs */
mbedAustin 11:cada08fc8a70 542 #endif /* MBEDTLS_X509_CRT_PARSE_C */
mbedAustin 11:cada08fc8a70 543
mbedAustin 11:cada08fc8a70 544 #if defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED)
mbedAustin 11:cada08fc8a70 545 const int *sig_hashes; /*!< allowed signature hashes */
mbedAustin 11:cada08fc8a70 546 #endif
mbedAustin 11:cada08fc8a70 547
mbedAustin 11:cada08fc8a70 548 #if defined(MBEDTLS_ECP_C)
mbedAustin 11:cada08fc8a70 549 const mbedtls_ecp_group_id *curve_list; /*!< allowed curves */
mbedAustin 11:cada08fc8a70 550 #endif
mbedAustin 11:cada08fc8a70 551
mbedAustin 11:cada08fc8a70 552 #if defined(MBEDTLS_DHM_C)
mbedAustin 11:cada08fc8a70 553 mbedtls_mpi dhm_P; /*!< prime modulus for DHM */
mbedAustin 11:cada08fc8a70 554 mbedtls_mpi dhm_G; /*!< generator for DHM */
mbedAustin 11:cada08fc8a70 555 #endif
mbedAustin 11:cada08fc8a70 556
mbedAustin 11:cada08fc8a70 557 #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
mbedAustin 11:cada08fc8a70 558 unsigned char *psk; /*!< pre-shared key */
mbedAustin 11:cada08fc8a70 559 size_t psk_len; /*!< length of the pre-shared key */
mbedAustin 11:cada08fc8a70 560 unsigned char *psk_identity; /*!< identity for PSK negotiation */
mbedAustin 11:cada08fc8a70 561 size_t psk_identity_len;/*!< length of identity */
mbedAustin 11:cada08fc8a70 562 #endif
mbedAustin 11:cada08fc8a70 563
mbedAustin 11:cada08fc8a70 564 #if defined(MBEDTLS_SSL_ALPN)
mbedAustin 11:cada08fc8a70 565 const char **alpn_list; /*!< ordered list of protocols */
mbedAustin 11:cada08fc8a70 566 #endif
mbedAustin 11:cada08fc8a70 567
mbedAustin 11:cada08fc8a70 568 /*
mbedAustin 11:cada08fc8a70 569 * Numerical settings (int then char)
mbedAustin 11:cada08fc8a70 570 */
mbedAustin 11:cada08fc8a70 571
mbedAustin 11:cada08fc8a70 572 uint32_t read_timeout; /*!< timeout for mbedtls_ssl_read (ms) */
mbedAustin 11:cada08fc8a70 573
mbedAustin 11:cada08fc8a70 574 #if defined(MBEDTLS_SSL_PROTO_DTLS)
mbedAustin 11:cada08fc8a70 575 uint32_t hs_timeout_min; /*!< initial value of the handshake
mbedAustin 11:cada08fc8a70 576 retransmission timeout (ms) */
mbedAustin 11:cada08fc8a70 577 uint32_t hs_timeout_max; /*!< maximum value of the handshake
mbedAustin 11:cada08fc8a70 578 retransmission timeout (ms) */
mbedAustin 11:cada08fc8a70 579 #endif
mbedAustin 11:cada08fc8a70 580
mbedAustin 11:cada08fc8a70 581 #if defined(MBEDTLS_SSL_RENEGOTIATION)
mbedAustin 11:cada08fc8a70 582 int renego_max_records; /*!< grace period for renegotiation */
mbedAustin 11:cada08fc8a70 583 unsigned char renego_period[8]; /*!< value of the record counters
mbedAustin 11:cada08fc8a70 584 that triggers renegotiation */
mbedAustin 11:cada08fc8a70 585 #endif
mbedAustin 11:cada08fc8a70 586
mbedAustin 11:cada08fc8a70 587 #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
mbedAustin 11:cada08fc8a70 588 unsigned int badmac_limit; /*!< limit of records with a bad MAC */
mbedAustin 11:cada08fc8a70 589 #endif
mbedAustin 11:cada08fc8a70 590
mbedAustin 11:cada08fc8a70 591 #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
mbedAustin 11:cada08fc8a70 592 unsigned int dhm_min_bitlen; /*!< min. bit length of the DHM prime */
mbedAustin 11:cada08fc8a70 593 #endif
mbedAustin 11:cada08fc8a70 594
mbedAustin 11:cada08fc8a70 595 unsigned char max_major_ver; /*!< max. major version used */
mbedAustin 11:cada08fc8a70 596 unsigned char max_minor_ver; /*!< max. minor version used */
mbedAustin 11:cada08fc8a70 597 unsigned char min_major_ver; /*!< min. major version used */
mbedAustin 11:cada08fc8a70 598 unsigned char min_minor_ver; /*!< min. minor version used */
mbedAustin 11:cada08fc8a70 599
mbedAustin 11:cada08fc8a70 600 /*
mbedAustin 11:cada08fc8a70 601 * Flags (bitfields)
mbedAustin 11:cada08fc8a70 602 */
mbedAustin 11:cada08fc8a70 603
mbedAustin 11:cada08fc8a70 604 unsigned int endpoint : 1; /*!< 0: client, 1: server */
mbedAustin 11:cada08fc8a70 605 unsigned int transport : 1; /*!< stream (TLS) or datagram (DTLS) */
mbedAustin 11:cada08fc8a70 606 unsigned int authmode : 2; /*!< MBEDTLS_SSL_VERIFY_XXX */
mbedAustin 11:cada08fc8a70 607 /* needed even with renego disabled for LEGACY_BREAK_HANDSHAKE */
mbedAustin 11:cada08fc8a70 608 unsigned int allow_legacy_renegotiation : 2 ; /*!< MBEDTLS_LEGACY_XXX */
mbedAustin 11:cada08fc8a70 609 #if defined(MBEDTLS_ARC4_C)
mbedAustin 11:cada08fc8a70 610 unsigned int arc4_disabled : 1; /*!< blacklist RC4 ciphersuites? */
mbedAustin 11:cada08fc8a70 611 #endif
mbedAustin 11:cada08fc8a70 612 #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
mbedAustin 11:cada08fc8a70 613 unsigned int mfl_code : 3; /*!< desired fragment length */
mbedAustin 11:cada08fc8a70 614 #endif
mbedAustin 11:cada08fc8a70 615 #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
mbedAustin 11:cada08fc8a70 616 unsigned int encrypt_then_mac : 1 ; /*!< negotiate encrypt-then-mac? */
mbedAustin 11:cada08fc8a70 617 #endif
mbedAustin 11:cada08fc8a70 618 #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
mbedAustin 11:cada08fc8a70 619 unsigned int extended_ms : 1; /*!< negotiate extended master secret? */
mbedAustin 11:cada08fc8a70 620 #endif
mbedAustin 11:cada08fc8a70 621 #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
mbedAustin 11:cada08fc8a70 622 unsigned int anti_replay : 1; /*!< detect and prevent replay? */
mbedAustin 11:cada08fc8a70 623 #endif
mbedAustin 11:cada08fc8a70 624 #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
mbedAustin 11:cada08fc8a70 625 unsigned int cbc_record_splitting : 1; /*!< do cbc record splitting */
mbedAustin 11:cada08fc8a70 626 #endif
mbedAustin 11:cada08fc8a70 627 #if defined(MBEDTLS_SSL_RENEGOTIATION)
mbedAustin 11:cada08fc8a70 628 unsigned int disable_renegotiation : 1; /*!< disable renegotiation? */
mbedAustin 11:cada08fc8a70 629 #endif
mbedAustin 11:cada08fc8a70 630 #if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
mbedAustin 11:cada08fc8a70 631 unsigned int trunc_hmac : 1; /*!< negotiate truncated hmac? */
mbedAustin 11:cada08fc8a70 632 #endif
mbedAustin 11:cada08fc8a70 633 #if defined(MBEDTLS_SSL_SESSION_TICKETS)
mbedAustin 11:cada08fc8a70 634 unsigned int session_tickets : 1; /*!< use session tickets? */
mbedAustin 11:cada08fc8a70 635 #endif
mbedAustin 11:cada08fc8a70 636 #if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C)
mbedAustin 11:cada08fc8a70 637 unsigned int fallback : 1; /*!< is this a fallback? */
mbedAustin 11:cada08fc8a70 638 #endif
mbedAustin 11:cada08fc8a70 639 };
mbedAustin 11:cada08fc8a70 640
mbedAustin 11:cada08fc8a70 641
mbedAustin 11:cada08fc8a70 642 struct mbedtls_ssl_context
mbedAustin 11:cada08fc8a70 643 {
mbedAustin 11:cada08fc8a70 644 const mbedtls_ssl_config *conf; /*!< configuration information */
mbedAustin 11:cada08fc8a70 645
mbedAustin 11:cada08fc8a70 646 /*
mbedAustin 11:cada08fc8a70 647 * Miscellaneous
mbedAustin 11:cada08fc8a70 648 */
mbedAustin 11:cada08fc8a70 649 int state; /*!< SSL handshake: current state */
mbedAustin 11:cada08fc8a70 650 #if defined(MBEDTLS_SSL_RENEGOTIATION)
mbedAustin 11:cada08fc8a70 651 int renego_status; /*!< Initial, in progress, pending? */
mbedAustin 11:cada08fc8a70 652 int renego_records_seen; /*!< Records since renego request, or with DTLS,
mbedAustin 11:cada08fc8a70 653 number of retransmissions of request if
mbedAustin 11:cada08fc8a70 654 renego_max_records is < 0 */
mbedAustin 11:cada08fc8a70 655 #endif
mbedAustin 11:cada08fc8a70 656
mbedAustin 11:cada08fc8a70 657 int major_ver; /*!< equal to MBEDTLS_SSL_MAJOR_VERSION_3 */
mbedAustin 11:cada08fc8a70 658 int minor_ver; /*!< either 0 (SSL3) or 1 (TLS1.0) */
mbedAustin 11:cada08fc8a70 659
mbedAustin 11:cada08fc8a70 660 #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
mbedAustin 11:cada08fc8a70 661 unsigned badmac_seen; /*!< records with a bad MAC received */
mbedAustin 11:cada08fc8a70 662 #endif
mbedAustin 11:cada08fc8a70 663
mbedAustin 11:cada08fc8a70 664 /*
mbedAustin 11:cada08fc8a70 665 * Callbacks
mbedAustin 11:cada08fc8a70 666 */
mbedAustin 11:cada08fc8a70 667 int (*f_send)(void *, const unsigned char *, size_t);
mbedAustin 11:cada08fc8a70 668 int (*f_recv)(void *, unsigned char *, size_t);
mbedAustin 11:cada08fc8a70 669 int (*f_recv_timeout)(void *, unsigned char *, size_t, uint32_t);
mbedAustin 11:cada08fc8a70 670 void *p_bio; /*!< context for I/O operations */
mbedAustin 11:cada08fc8a70 671
mbedAustin 11:cada08fc8a70 672 /*
mbedAustin 11:cada08fc8a70 673 * Session layer
mbedAustin 11:cada08fc8a70 674 */
mbedAustin 11:cada08fc8a70 675 mbedtls_ssl_session *session_in; /*!< current session data (in) */
mbedAustin 11:cada08fc8a70 676 mbedtls_ssl_session *session_out; /*!< current session data (out) */
mbedAustin 11:cada08fc8a70 677 mbedtls_ssl_session *session; /*!< negotiated session data */
mbedAustin 11:cada08fc8a70 678 mbedtls_ssl_session *session_negotiate; /*!< session data in negotiation */
mbedAustin 11:cada08fc8a70 679
mbedAustin 11:cada08fc8a70 680 mbedtls_ssl_handshake_params *handshake; /*!< params required only during
mbedAustin 11:cada08fc8a70 681 the handshake process */
mbedAustin 11:cada08fc8a70 682
mbedAustin 11:cada08fc8a70 683 /*
mbedAustin 11:cada08fc8a70 684 * Record layer transformations
mbedAustin 11:cada08fc8a70 685 */
mbedAustin 11:cada08fc8a70 686 mbedtls_ssl_transform *transform_in; /*!< current transform params (in) */
mbedAustin 11:cada08fc8a70 687 mbedtls_ssl_transform *transform_out; /*!< current transform params (in) */
mbedAustin 11:cada08fc8a70 688 mbedtls_ssl_transform *transform; /*!< negotiated transform params */
mbedAustin 11:cada08fc8a70 689 mbedtls_ssl_transform *transform_negotiate; /*!< transform params in negotiation */
mbedAustin 11:cada08fc8a70 690
mbedAustin 11:cada08fc8a70 691 /*
mbedAustin 11:cada08fc8a70 692 * Timers
mbedAustin 11:cada08fc8a70 693 */
mbedAustin 11:cada08fc8a70 694 void *p_timer; /*!< context for the timer callbacks */
mbedAustin 11:cada08fc8a70 695 void (*f_set_timer)(void *, uint32_t, uint32_t); /*!< set timer callback */
mbedAustin 11:cada08fc8a70 696 int (*f_get_timer)(void *); /*!< get timer callback */
mbedAustin 11:cada08fc8a70 697
mbedAustin 11:cada08fc8a70 698 /*
mbedAustin 11:cada08fc8a70 699 * Record layer (incoming data)
mbedAustin 11:cada08fc8a70 700 */
mbedAustin 11:cada08fc8a70 701 unsigned char *in_buf; /*!< input buffer */
mbedAustin 11:cada08fc8a70 702 unsigned char *in_ctr; /*!< 64-bit incoming message counter
mbedAustin 11:cada08fc8a70 703 TLS: maintained by us
mbedAustin 11:cada08fc8a70 704 DTLS: read from peer */
mbedAustin 11:cada08fc8a70 705 unsigned char *in_hdr; /*!< start of record header */
mbedAustin 11:cada08fc8a70 706 unsigned char *in_len; /*!< two-bytes message length field */
mbedAustin 11:cada08fc8a70 707 unsigned char *in_iv; /*!< ivlen-byte IV */
mbedAustin 11:cada08fc8a70 708 unsigned char *in_msg; /*!< message contents (in_iv+ivlen) */
mbedAustin 11:cada08fc8a70 709 unsigned char *in_offt; /*!< read offset in application data */
mbedAustin 11:cada08fc8a70 710
mbedAustin 11:cada08fc8a70 711 int in_msgtype; /*!< record header: message type */
mbedAustin 11:cada08fc8a70 712 size_t in_msglen; /*!< record header: message length */
mbedAustin 11:cada08fc8a70 713 size_t in_left; /*!< amount of data read so far */
mbedAustin 11:cada08fc8a70 714 #if defined(MBEDTLS_SSL_PROTO_DTLS)
mbedAustin 11:cada08fc8a70 715 uint16_t in_epoch; /*!< DTLS epoch for incoming records */
mbedAustin 11:cada08fc8a70 716 size_t next_record_offset; /*!< offset of the next record in datagram
mbedAustin 11:cada08fc8a70 717 (equal to in_left if none) */
mbedAustin 11:cada08fc8a70 718 #endif
mbedAustin 11:cada08fc8a70 719 #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
mbedAustin 11:cada08fc8a70 720 uint64_t in_window_top; /*!< last validated record seq_num */
mbedAustin 11:cada08fc8a70 721 uint64_t in_window; /*!< bitmask for replay detection */
mbedAustin 11:cada08fc8a70 722 #endif
mbedAustin 11:cada08fc8a70 723
mbedAustin 11:cada08fc8a70 724 size_t in_hslen; /*!< current handshake message length,
mbedAustin 11:cada08fc8a70 725 including the handshake header */
mbedAustin 11:cada08fc8a70 726 int nb_zero; /*!< # of 0-length encrypted messages */
mbedAustin 11:cada08fc8a70 727 int record_read; /*!< record is already present */
mbedAustin 11:cada08fc8a70 728
mbedAustin 11:cada08fc8a70 729 /*
mbedAustin 11:cada08fc8a70 730 * Record layer (outgoing data)
mbedAustin 11:cada08fc8a70 731 */
mbedAustin 11:cada08fc8a70 732 unsigned char *out_buf; /*!< output buffer */
mbedAustin 11:cada08fc8a70 733 unsigned char *out_ctr; /*!< 64-bit outgoing message counter */
mbedAustin 11:cada08fc8a70 734 unsigned char *out_hdr; /*!< start of record header */
mbedAustin 11:cada08fc8a70 735 unsigned char *out_len; /*!< two-bytes message length field */
mbedAustin 11:cada08fc8a70 736 unsigned char *out_iv; /*!< ivlen-byte IV */
mbedAustin 11:cada08fc8a70 737 unsigned char *out_msg; /*!< message contents (out_iv+ivlen) */
mbedAustin 11:cada08fc8a70 738
mbedAustin 11:cada08fc8a70 739 int out_msgtype; /*!< record header: message type */
mbedAustin 11:cada08fc8a70 740 size_t out_msglen; /*!< record header: message length */
mbedAustin 11:cada08fc8a70 741 size_t out_left; /*!< amount of data not yet written */
mbedAustin 11:cada08fc8a70 742
mbedAustin 11:cada08fc8a70 743 #if defined(MBEDTLS_ZLIB_SUPPORT)
mbedAustin 11:cada08fc8a70 744 unsigned char *compress_buf; /*!< zlib data buffer */
mbedAustin 11:cada08fc8a70 745 #endif
mbedAustin 11:cada08fc8a70 746 #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
mbedAustin 11:cada08fc8a70 747 signed char split_done; /*!< current record already splitted? */
mbedAustin 11:cada08fc8a70 748 #endif
mbedAustin 11:cada08fc8a70 749
mbedAustin 11:cada08fc8a70 750 /*
mbedAustin 11:cada08fc8a70 751 * PKI layer
mbedAustin 11:cada08fc8a70 752 */
mbedAustin 11:cada08fc8a70 753 int client_auth; /*!< flag for client auth. */
mbedAustin 11:cada08fc8a70 754
mbedAustin 11:cada08fc8a70 755 /*
mbedAustin 11:cada08fc8a70 756 * User settings
mbedAustin 11:cada08fc8a70 757 */
mbedAustin 11:cada08fc8a70 758 #if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedAustin 11:cada08fc8a70 759 char *hostname; /*!< expected peer CN for verification
mbedAustin 11:cada08fc8a70 760 (and SNI if available) */
mbedAustin 11:cada08fc8a70 761 #endif
mbedAustin 11:cada08fc8a70 762
mbedAustin 11:cada08fc8a70 763 #if defined(MBEDTLS_SSL_ALPN)
mbedAustin 11:cada08fc8a70 764 const char *alpn_chosen; /*!< negotiated protocol */
mbedAustin 11:cada08fc8a70 765 #endif
mbedAustin 11:cada08fc8a70 766
mbedAustin 11:cada08fc8a70 767 /*
mbedAustin 11:cada08fc8a70 768 * Information for DTLS hello verify
mbedAustin 11:cada08fc8a70 769 */
mbedAustin 11:cada08fc8a70 770 #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
mbedAustin 11:cada08fc8a70 771 unsigned char *cli_id; /*!< transport-level ID of the client */
mbedAustin 11:cada08fc8a70 772 size_t cli_id_len; /*!< length of cli_id */
mbedAustin 11:cada08fc8a70 773 #endif
mbedAustin 11:cada08fc8a70 774
mbedAustin 11:cada08fc8a70 775 /*
mbedAustin 11:cada08fc8a70 776 * Secure renegotiation
mbedAustin 11:cada08fc8a70 777 */
mbedAustin 11:cada08fc8a70 778 /* needed to know when to send extension on server */
mbedAustin 11:cada08fc8a70 779 int secure_renegotiation; /*!< does peer support legacy or
mbedAustin 11:cada08fc8a70 780 secure renegotiation */
mbedAustin 11:cada08fc8a70 781 #if defined(MBEDTLS_SSL_RENEGOTIATION)
mbedAustin 11:cada08fc8a70 782 size_t verify_data_len; /*!< length of verify data stored */
mbedAustin 11:cada08fc8a70 783 char own_verify_data[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN]; /*!< previous handshake verify data */
mbedAustin 11:cada08fc8a70 784 char peer_verify_data[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN]; /*!< previous handshake verify data */
mbedAustin 11:cada08fc8a70 785 #endif
mbedAustin 11:cada08fc8a70 786 };
mbedAustin 11:cada08fc8a70 787
mbedAustin 11:cada08fc8a70 788 #if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
mbedAustin 11:cada08fc8a70 789
mbedAustin 11:cada08fc8a70 790 #define MBEDTLS_SSL_CHANNEL_OUTBOUND 0
mbedAustin 11:cada08fc8a70 791 #define MBEDTLS_SSL_CHANNEL_INBOUND 1
mbedAustin 11:cada08fc8a70 792
mbedAustin 11:cada08fc8a70 793 extern int (*mbedtls_ssl_hw_record_init)(mbedtls_ssl_context *ssl,
mbedAustin 11:cada08fc8a70 794 const unsigned char *key_enc, const unsigned char *key_dec,
mbedAustin 11:cada08fc8a70 795 size_t keylen,
mbedAustin 11:cada08fc8a70 796 const unsigned char *iv_enc, const unsigned char *iv_dec,
mbedAustin 11:cada08fc8a70 797 size_t ivlen,
mbedAustin 11:cada08fc8a70 798 const unsigned char *mac_enc, const unsigned char *mac_dec,
mbedAustin 11:cada08fc8a70 799 size_t maclen);
mbedAustin 11:cada08fc8a70 800 extern int (*mbedtls_ssl_hw_record_activate)(mbedtls_ssl_context *ssl, int direction);
mbedAustin 11:cada08fc8a70 801 extern int (*mbedtls_ssl_hw_record_reset)(mbedtls_ssl_context *ssl);
mbedAustin 11:cada08fc8a70 802 extern int (*mbedtls_ssl_hw_record_write)(mbedtls_ssl_context *ssl);
mbedAustin 11:cada08fc8a70 803 extern int (*mbedtls_ssl_hw_record_read)(mbedtls_ssl_context *ssl);
mbedAustin 11:cada08fc8a70 804 extern int (*mbedtls_ssl_hw_record_finish)(mbedtls_ssl_context *ssl);
mbedAustin 11:cada08fc8a70 805 #endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */
mbedAustin 11:cada08fc8a70 806
mbedAustin 11:cada08fc8a70 807 /**
mbedAustin 11:cada08fc8a70 808 * \brief Returns the list of ciphersuites supported by the SSL/TLS module.
mbedAustin 11:cada08fc8a70 809 *
mbedAustin 11:cada08fc8a70 810 * \return a statically allocated array of ciphersuites, the last
mbedAustin 11:cada08fc8a70 811 * entry is 0.
mbedAustin 11:cada08fc8a70 812 */
mbedAustin 11:cada08fc8a70 813 const int *mbedtls_ssl_list_ciphersuites( void );
mbedAustin 11:cada08fc8a70 814
mbedAustin 11:cada08fc8a70 815 /**
mbedAustin 11:cada08fc8a70 816 * \brief Return the name of the ciphersuite associated with the
mbedAustin 11:cada08fc8a70 817 * given ID
mbedAustin 11:cada08fc8a70 818 *
mbedAustin 11:cada08fc8a70 819 * \param ciphersuite_id SSL ciphersuite ID
mbedAustin 11:cada08fc8a70 820 *
mbedAustin 11:cada08fc8a70 821 * \return a string containing the ciphersuite name
mbedAustin 11:cada08fc8a70 822 */
mbedAustin 11:cada08fc8a70 823 const char *mbedtls_ssl_get_ciphersuite_name( const int ciphersuite_id );
mbedAustin 11:cada08fc8a70 824
mbedAustin 11:cada08fc8a70 825 /**
mbedAustin 11:cada08fc8a70 826 * \brief Return the ID of the ciphersuite associated with the
mbedAustin 11:cada08fc8a70 827 * given name
mbedAustin 11:cada08fc8a70 828 *
mbedAustin 11:cada08fc8a70 829 * \param ciphersuite_name SSL ciphersuite name
mbedAustin 11:cada08fc8a70 830 *
mbedAustin 11:cada08fc8a70 831 * \return the ID with the ciphersuite or 0 if not found
mbedAustin 11:cada08fc8a70 832 */
mbedAustin 11:cada08fc8a70 833 int mbedtls_ssl_get_ciphersuite_id( const char *ciphersuite_name );
mbedAustin 11:cada08fc8a70 834
mbedAustin 11:cada08fc8a70 835 /**
mbedAustin 11:cada08fc8a70 836 * \brief Initialize an SSL context
mbedAustin 11:cada08fc8a70 837 * Just makes the context ready for mbedtls_ssl_setup() or
mbedAustin 11:cada08fc8a70 838 * mbedtls_ssl_free()
mbedAustin 11:cada08fc8a70 839 *
mbedAustin 11:cada08fc8a70 840 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 841 */
mbedAustin 11:cada08fc8a70 842 void mbedtls_ssl_init( mbedtls_ssl_context *ssl );
mbedAustin 11:cada08fc8a70 843
mbedAustin 11:cada08fc8a70 844 /**
mbedAustin 11:cada08fc8a70 845 * \brief Set up an SSL context for use
mbedAustin 11:cada08fc8a70 846 *
mbedAustin 11:cada08fc8a70 847 * \note No copy of the configuration context is made, it can be
mbedAustin 11:cada08fc8a70 848 * shared by many mbedtls_ssl_context structures.
mbedAustin 11:cada08fc8a70 849 *
mbedAustin 11:cada08fc8a70 850 * \warning Modifying the conf structure after is has been used in this
mbedAustin 11:cada08fc8a70 851 * function is unsupported!
mbedAustin 11:cada08fc8a70 852 *
mbedAustin 11:cada08fc8a70 853 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 854 * \param conf SSL configuration to use
mbedAustin 11:cada08fc8a70 855 *
mbedAustin 11:cada08fc8a70 856 * \return 0 if successful, or MBEDTLS_ERR_SSL_ALLOC_FAILED if
mbedAustin 11:cada08fc8a70 857 * memory allocation failed
mbedAustin 11:cada08fc8a70 858 */
mbedAustin 11:cada08fc8a70 859 int mbedtls_ssl_setup( mbedtls_ssl_context *ssl,
mbedAustin 11:cada08fc8a70 860 const mbedtls_ssl_config *conf );
mbedAustin 11:cada08fc8a70 861
mbedAustin 11:cada08fc8a70 862 /**
mbedAustin 11:cada08fc8a70 863 * \brief Reset an already initialized SSL context for re-use
mbedAustin 11:cada08fc8a70 864 * while retaining application-set variables, function
mbedAustin 11:cada08fc8a70 865 * pointers and data.
mbedAustin 11:cada08fc8a70 866 *
mbedAustin 11:cada08fc8a70 867 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 868 * \return 0 if successful, or POLASSL_ERR_SSL_MALLOC_FAILED,
mbedAustin 11:cada08fc8a70 869 MBEDTLS_ERR_SSL_HW_ACCEL_FAILED or
mbedAustin 11:cada08fc8a70 870 * MBEDTLS_ERR_SSL_COMPRESSION_FAILED
mbedAustin 11:cada08fc8a70 871 */
mbedAustin 11:cada08fc8a70 872 int mbedtls_ssl_session_reset( mbedtls_ssl_context *ssl );
mbedAustin 11:cada08fc8a70 873
mbedAustin 11:cada08fc8a70 874 /**
mbedAustin 11:cada08fc8a70 875 * \brief Set the current endpoint type
mbedAustin 11:cada08fc8a70 876 *
mbedAustin 11:cada08fc8a70 877 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 878 * \param endpoint must be MBEDTLS_SSL_IS_CLIENT or MBEDTLS_SSL_IS_SERVER
mbedAustin 11:cada08fc8a70 879 */
mbedAustin 11:cada08fc8a70 880 void mbedtls_ssl_conf_endpoint( mbedtls_ssl_config *conf, int endpoint );
mbedAustin 11:cada08fc8a70 881
mbedAustin 11:cada08fc8a70 882 /**
mbedAustin 11:cada08fc8a70 883 * \brief Set the transport type (TLS or DTLS).
mbedAustin 11:cada08fc8a70 884 * Default: TLS
mbedAustin 11:cada08fc8a70 885 *
mbedAustin 11:cada08fc8a70 886 * \note For DTLS, you must either provide a recv callback that
mbedAustin 11:cada08fc8a70 887 * doesn't block, or one that handles timeouts, see
mbedAustin 11:cada08fc8a70 888 * \c mbedtls_ssl_set_bio(). You also need to provide timer
mbedAustin 11:cada08fc8a70 889 * callbacks with \c mbedtls_ssl_set_timer_cb().
mbedAustin 11:cada08fc8a70 890 *
mbedAustin 11:cada08fc8a70 891 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 892 * \param transport transport type:
mbedAustin 11:cada08fc8a70 893 * MBEDTLS_SSL_TRANSPORT_STREAM for TLS,
mbedAustin 11:cada08fc8a70 894 * MBEDTLS_SSL_TRANSPORT_DATAGRAM for DTLS.
mbedAustin 11:cada08fc8a70 895 */
mbedAustin 11:cada08fc8a70 896 void mbedtls_ssl_conf_transport( mbedtls_ssl_config *conf, int transport );
mbedAustin 11:cada08fc8a70 897
mbedAustin 11:cada08fc8a70 898 /**
mbedAustin 11:cada08fc8a70 899 * \brief Set the certificate verification mode
mbedAustin 11:cada08fc8a70 900 * Default: NONE on server, REQUIRED on client
mbedAustin 11:cada08fc8a70 901 *
mbedAustin 11:cada08fc8a70 902 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 903 * \param authmode can be:
mbedAustin 11:cada08fc8a70 904 *
mbedAustin 11:cada08fc8a70 905 * MBEDTLS_SSL_VERIFY_NONE: peer certificate is not checked
mbedAustin 11:cada08fc8a70 906 * (default on server)
mbedAustin 11:cada08fc8a70 907 * (insecure on client)
mbedAustin 11:cada08fc8a70 908 *
mbedAustin 11:cada08fc8a70 909 * MBEDTLS_SSL_VERIFY_OPTIONAL: peer certificate is checked, however the
mbedAustin 11:cada08fc8a70 910 * handshake continues even if verification failed;
mbedAustin 11:cada08fc8a70 911 * mbedtls_ssl_get_verify_result() can be called after the
mbedAustin 11:cada08fc8a70 912 * handshake is complete.
mbedAustin 11:cada08fc8a70 913 *
mbedAustin 11:cada08fc8a70 914 * MBEDTLS_SSL_VERIFY_REQUIRED: peer *must* present a valid certificate,
mbedAustin 11:cada08fc8a70 915 * handshake is aborted if verification failed.
mbedAustin 11:cada08fc8a70 916 *
mbedAustin 11:cada08fc8a70 917 * \note On client, MBEDTLS_SSL_VERIFY_REQUIRED is the recommended mode.
mbedAustin 11:cada08fc8a70 918 * With MBEDTLS_SSL_VERIFY_OPTIONAL, the user needs to call mbedtls_ssl_get_verify_result() at
mbedAustin 11:cada08fc8a70 919 * the right time(s), which may not be obvious, while REQUIRED always perform
mbedAustin 11:cada08fc8a70 920 * the verification as soon as possible. For example, REQUIRED was protecting
mbedAustin 11:cada08fc8a70 921 * against the "triple handshake" attack even before it was found.
mbedAustin 11:cada08fc8a70 922 */
mbedAustin 11:cada08fc8a70 923 void mbedtls_ssl_conf_authmode( mbedtls_ssl_config *conf, int authmode );
mbedAustin 11:cada08fc8a70 924
mbedAustin 11:cada08fc8a70 925 #if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedAustin 11:cada08fc8a70 926 /**
mbedAustin 11:cada08fc8a70 927 * \brief Set the verification callback (Optional).
mbedAustin 11:cada08fc8a70 928 *
mbedAustin 11:cada08fc8a70 929 * If set, the verify callback is called for each
mbedAustin 11:cada08fc8a70 930 * certificate in the chain. For implementation
mbedAustin 11:cada08fc8a70 931 * information, please see \c x509parse_verify()
mbedAustin 11:cada08fc8a70 932 *
mbedAustin 11:cada08fc8a70 933 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 934 * \param f_vrfy verification function
mbedAustin 11:cada08fc8a70 935 * \param p_vrfy verification parameter
mbedAustin 11:cada08fc8a70 936 */
mbedAustin 11:cada08fc8a70 937 void mbedtls_ssl_conf_verify( mbedtls_ssl_config *conf,
mbedAustin 11:cada08fc8a70 938 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
mbedAustin 11:cada08fc8a70 939 void *p_vrfy );
mbedAustin 11:cada08fc8a70 940 #endif /* MBEDTLS_X509_CRT_PARSE_C */
mbedAustin 11:cada08fc8a70 941
mbedAustin 11:cada08fc8a70 942 /**
mbedAustin 11:cada08fc8a70 943 * \brief Set the random number generator callback
mbedAustin 11:cada08fc8a70 944 *
mbedAustin 11:cada08fc8a70 945 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 946 * \param f_rng RNG function
mbedAustin 11:cada08fc8a70 947 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 948 */
mbedAustin 11:cada08fc8a70 949 void mbedtls_ssl_conf_rng( mbedtls_ssl_config *conf,
mbedAustin 11:cada08fc8a70 950 int (*f_rng)(void *, unsigned char *, size_t),
mbedAustin 11:cada08fc8a70 951 void *p_rng );
mbedAustin 11:cada08fc8a70 952
mbedAustin 11:cada08fc8a70 953 /**
mbedAustin 11:cada08fc8a70 954 * \brief Set the debug callback
mbedAustin 11:cada08fc8a70 955 *
mbedAustin 11:cada08fc8a70 956 * The callback has the following argument:
mbedAustin 11:cada08fc8a70 957 * void * opaque context for the callback
mbedAustin 11:cada08fc8a70 958 * int debug level
mbedAustin 11:cada08fc8a70 959 * const char * file name
mbedAustin 11:cada08fc8a70 960 * int line number
mbedAustin 11:cada08fc8a70 961 * const char * message
mbedAustin 11:cada08fc8a70 962 *
mbedAustin 11:cada08fc8a70 963 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 964 * \param f_dbg debug function
mbedAustin 11:cada08fc8a70 965 * \param p_dbg debug parameter
mbedAustin 11:cada08fc8a70 966 */
mbedAustin 11:cada08fc8a70 967 void mbedtls_ssl_conf_dbg( mbedtls_ssl_config *conf,
mbedAustin 11:cada08fc8a70 968 void (*f_dbg)(void *, int, const char *, int, const char *),
mbedAustin 11:cada08fc8a70 969 void *p_dbg );
mbedAustin 11:cada08fc8a70 970
mbedAustin 11:cada08fc8a70 971 /**
mbedAustin 11:cada08fc8a70 972 * \brief Set the underlying BIO callbacks for write, read and
mbedAustin 11:cada08fc8a70 973 * read-with-timeout.
mbedAustin 11:cada08fc8a70 974 *
mbedAustin 11:cada08fc8a70 975 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 976 * \param p_bio parameter (context) shared by BIO callbacks
mbedAustin 11:cada08fc8a70 977 * \param f_send write callback
mbedAustin 11:cada08fc8a70 978 * \param f_recv read callback
mbedAustin 11:cada08fc8a70 979 * \param f_recv_timeout blocking read callback with timeout.
mbedAustin 11:cada08fc8a70 980 * The last argument is the timeout in milliseconds,
mbedAustin 11:cada08fc8a70 981 * 0 means no timeout (block forever until a message comes)
mbedAustin 11:cada08fc8a70 982 *
mbedAustin 11:cada08fc8a70 983 * \note One of f_recv or f_recv_timeout can be NULL, in which case
mbedAustin 11:cada08fc8a70 984 * the other is used. If both are non-NULL, f_recv_timeout is
mbedAustin 11:cada08fc8a70 985 * used and f_recv is ignored (as if it were NULL).
mbedAustin 11:cada08fc8a70 986 *
mbedAustin 11:cada08fc8a70 987 * \note The two most common use cases are:
mbedAustin 11:cada08fc8a70 988 * - non-blocking I/O, f_recv != NULL, f_recv_timeout == NULL
mbedAustin 11:cada08fc8a70 989 * - blocking I/O, f_recv == NULL, f_recv_timout != NULL
mbedAustin 11:cada08fc8a70 990 *
mbedAustin 11:cada08fc8a70 991 * \note For DTLS, you need to provide either a non-NULL
mbedAustin 11:cada08fc8a70 992 * f_recv_timeout callback, or a f_recv that doesn't block.
mbedAustin 11:cada08fc8a70 993 */
mbedAustin 11:cada08fc8a70 994 void mbedtls_ssl_set_bio( mbedtls_ssl_context *ssl,
mbedAustin 11:cada08fc8a70 995 void *p_bio,
mbedAustin 11:cada08fc8a70 996 int (*f_send)(void *, const unsigned char *, size_t),
mbedAustin 11:cada08fc8a70 997 int (*f_recv)(void *, unsigned char *, size_t),
mbedAustin 11:cada08fc8a70 998 int (*f_recv_timeout)(void *, unsigned char *, size_t, uint32_t) );
mbedAustin 11:cada08fc8a70 999
mbedAustin 11:cada08fc8a70 1000 /**
mbedAustin 11:cada08fc8a70 1001 * \brief Set the timeout period for mbedtls_ssl_read()
mbedAustin 11:cada08fc8a70 1002 * (Default: no timeout.)
mbedAustin 11:cada08fc8a70 1003 *
mbedAustin 11:cada08fc8a70 1004 * \param conf SSL configuration context
mbedAustin 11:cada08fc8a70 1005 * \param timeout Timeout value in milliseconds.
mbedAustin 11:cada08fc8a70 1006 * Use 0 for no timeout (default).
mbedAustin 11:cada08fc8a70 1007 *
mbedAustin 11:cada08fc8a70 1008 * \note With blocking I/O, this will only work if a non-NULL
mbedAustin 11:cada08fc8a70 1009 * \c f_recv_timeout was set with \c mbedtls_ssl_set_bio().
mbedAustin 11:cada08fc8a70 1010 * With non-blocking I/O, this will only work if timer
mbedAustin 11:cada08fc8a70 1011 * callbacks were set with \c mbedtls_ssl_set_timer_cb().
mbedAustin 11:cada08fc8a70 1012 *
mbedAustin 11:cada08fc8a70 1013 * \note With non-blocking I/O, you may also skip this function
mbedAustin 11:cada08fc8a70 1014 * altogether and handle timeouts at the application layer.
mbedAustin 11:cada08fc8a70 1015 */
mbedAustin 11:cada08fc8a70 1016 void mbedtls_ssl_conf_read_timeout( mbedtls_ssl_config *conf, uint32_t timeout );
mbedAustin 11:cada08fc8a70 1017
mbedAustin 11:cada08fc8a70 1018 /**
mbedAustin 11:cada08fc8a70 1019 * \brief Set the timer callbacks
mbedAustin 11:cada08fc8a70 1020 * (Mandatory for DTLS.)
mbedAustin 11:cada08fc8a70 1021 *
mbedAustin 11:cada08fc8a70 1022 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 1023 * \param p_timer parameter (context) shared by timer callback
mbedAustin 11:cada08fc8a70 1024 * \param f_set_timer set timer callback
mbedAustin 11:cada08fc8a70 1025 * Accepts an intermediate and a final delay in milliseconcs
mbedAustin 11:cada08fc8a70 1026 * If the final delay is 0, cancels the running timer.
mbedAustin 11:cada08fc8a70 1027 * \param f_get_timer get timer callback. Must return:
mbedAustin 11:cada08fc8a70 1028 * -1 if cancelled
mbedAustin 11:cada08fc8a70 1029 * 0 if none of the delays is expired
mbedAustin 11:cada08fc8a70 1030 * 1 if the intermediate delay only is expired
mbedAustin 11:cada08fc8a70 1031 * 2 if the final delay is expired
mbedAustin 11:cada08fc8a70 1032 */
mbedAustin 11:cada08fc8a70 1033 void mbedtls_ssl_set_timer_cb( mbedtls_ssl_context *ssl,
mbedAustin 11:cada08fc8a70 1034 void *p_timer,
mbedAustin 11:cada08fc8a70 1035 void (*f_set_timer)(void *, uint32_t int_ms, uint32_t fin_ms),
mbedAustin 11:cada08fc8a70 1036 int (*f_get_timer)(void *) );
mbedAustin 11:cada08fc8a70 1037
mbedAustin 11:cada08fc8a70 1038 /**
mbedAustin 11:cada08fc8a70 1039 * \brief Callback type: generate and write session ticket
mbedAustin 11:cada08fc8a70 1040 *
mbedAustin 11:cada08fc8a70 1041 * \note This describes what a callback implementation should do.
mbedAustin 11:cada08fc8a70 1042 * This callback should generate and encrypted and
mbedAustin 11:cada08fc8a70 1043 * authenticated ticket for the session and write it to the
mbedAustin 11:cada08fc8a70 1044 * output buffer. Here, ticket means the opaque ticket part
mbedAustin 11:cada08fc8a70 1045 * of the NewSessionTicket structure of RFC 5077.
mbedAustin 11:cada08fc8a70 1046 *
mbedAustin 11:cada08fc8a70 1047 * \param p_ticket Context for the callback
mbedAustin 11:cada08fc8a70 1048 * \param session SSL session to bo written in the ticket
mbedAustin 11:cada08fc8a70 1049 * \param start Start of the outpur buffer
mbedAustin 11:cada08fc8a70 1050 * \param end End of the output buffer
mbedAustin 11:cada08fc8a70 1051 * \param tlen On exit, holds the length written
mbedAustin 11:cada08fc8a70 1052 * \param lifetime On exit, holds the lifetime of the ticket in seconds
mbedAustin 11:cada08fc8a70 1053 *
mbedAustin 11:cada08fc8a70 1054 * \return 0 if successful, or
mbedAustin 11:cada08fc8a70 1055 * a specific MBEDTLS_ERR_XXX code.
mbedAustin 11:cada08fc8a70 1056 */
mbedAustin 11:cada08fc8a70 1057 typedef int mbedtls_ssl_ticket_write_t( void *p_ticket,
mbedAustin 11:cada08fc8a70 1058 const mbedtls_ssl_session *session,
mbedAustin 11:cada08fc8a70 1059 unsigned char *start,
mbedAustin 11:cada08fc8a70 1060 const unsigned char *end,
mbedAustin 11:cada08fc8a70 1061 size_t *tlen,
mbedAustin 11:cada08fc8a70 1062 uint32_t *lifetime );
mbedAustin 11:cada08fc8a70 1063
mbedAustin 11:cada08fc8a70 1064 #if defined(MBEDTLS_SSL_EXPORT_KEYS)
mbedAustin 11:cada08fc8a70 1065 /**
mbedAustin 11:cada08fc8a70 1066 * \brief Callback type: Export key block and master secret
mbedAustin 11:cada08fc8a70 1067 *
mbedAustin 11:cada08fc8a70 1068 * \note This is required for certain uses of TLS, e.g. EAP-TLS
mbedAustin 11:cada08fc8a70 1069 * (RFC 5216) and Thread. The key pointers are ephemeral and
mbedAustin 11:cada08fc8a70 1070 * therefore must not be stored. The master secret and keys
mbedAustin 11:cada08fc8a70 1071 * should not be used directly except as an input to a key
mbedAustin 11:cada08fc8a70 1072 * derivation function.
mbedAustin 11:cada08fc8a70 1073 *
mbedAustin 11:cada08fc8a70 1074 * \param p_expkey Context for the callback
mbedAustin 11:cada08fc8a70 1075 * \param ms Pointer to master secret (fixed length: 48 bytes)
mbedAustin 11:cada08fc8a70 1076 * \param kb Pointer to key block, see RFC 5246 section 6.3
mbedAustin 11:cada08fc8a70 1077 * (variable length: 2 * maclen + 2 * keylen + 2 * ivlen).
mbedAustin 11:cada08fc8a70 1078 * \param maclen MAC length
mbedAustin 11:cada08fc8a70 1079 * \param keylen Key length
mbedAustin 11:cada08fc8a70 1080 * \param ivlen IV length
mbedAustin 11:cada08fc8a70 1081 *
mbedAustin 11:cada08fc8a70 1082 * \return 0 if successful, or
mbedAustin 11:cada08fc8a70 1083 * a specific MBEDTLS_ERR_XXX code.
mbedAustin 11:cada08fc8a70 1084 */
mbedAustin 11:cada08fc8a70 1085 typedef int mbedtls_ssl_export_keys_t( void *p_expkey,
mbedAustin 11:cada08fc8a70 1086 const unsigned char *ms,
mbedAustin 11:cada08fc8a70 1087 const unsigned char *kb,
mbedAustin 11:cada08fc8a70 1088 size_t maclen,
mbedAustin 11:cada08fc8a70 1089 size_t keylen,
mbedAustin 11:cada08fc8a70 1090 size_t ivlen );
mbedAustin 11:cada08fc8a70 1091 #endif /* MBEDTLS_SSL_EXPORT_KEYS */
mbedAustin 11:cada08fc8a70 1092
mbedAustin 11:cada08fc8a70 1093 /**
mbedAustin 11:cada08fc8a70 1094 * \brief Callback type: parse and load session ticket
mbedAustin 11:cada08fc8a70 1095 *
mbedAustin 11:cada08fc8a70 1096 * \note This describes what a callback implementation should do.
mbedAustin 11:cada08fc8a70 1097 * This callback should parse a session ticket as generated
mbedAustin 11:cada08fc8a70 1098 * by the corresponding mbedtls_ssl_ticket_write_t function,
mbedAustin 11:cada08fc8a70 1099 * and, if the ticket is authentic and valid, load the
mbedAustin 11:cada08fc8a70 1100 * session.
mbedAustin 11:cada08fc8a70 1101 *
mbedAustin 11:cada08fc8a70 1102 * \note The implementation is allowed to modify the first len
mbedAustin 11:cada08fc8a70 1103 * bytes of the input buffer, eg to use it as a temporary
mbedAustin 11:cada08fc8a70 1104 * area for the decrypted ticket contents.
mbedAustin 11:cada08fc8a70 1105 *
mbedAustin 11:cada08fc8a70 1106 * \param p_ticket Context for the callback
mbedAustin 11:cada08fc8a70 1107 * \param session SSL session to be loaded
mbedAustin 11:cada08fc8a70 1108 * \param buf Start of the buffer containing the ticket
mbedAustin 11:cada08fc8a70 1109 * \param len Length of the ticket.
mbedAustin 11:cada08fc8a70 1110 *
mbedAustin 11:cada08fc8a70 1111 * \return 0 if successful, or
mbedAustin 11:cada08fc8a70 1112 * MBEDTLS_ERR_SSL_INVALID_MAC if not authentic, or
mbedAustin 11:cada08fc8a70 1113 * MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED if expired, or
mbedAustin 11:cada08fc8a70 1114 * any other non-zero code for other failures.
mbedAustin 11:cada08fc8a70 1115 */
mbedAustin 11:cada08fc8a70 1116 typedef int mbedtls_ssl_ticket_parse_t( void *p_ticket,
mbedAustin 11:cada08fc8a70 1117 mbedtls_ssl_session *session,
mbedAustin 11:cada08fc8a70 1118 unsigned char *buf,
mbedAustin 11:cada08fc8a70 1119 size_t len );
mbedAustin 11:cada08fc8a70 1120
mbedAustin 11:cada08fc8a70 1121 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
mbedAustin 11:cada08fc8a70 1122 /**
mbedAustin 11:cada08fc8a70 1123 * \brief Configure SSL session ticket callbacks (server only).
mbedAustin 11:cada08fc8a70 1124 * (Default: none.)
mbedAustin 11:cada08fc8a70 1125 *
mbedAustin 11:cada08fc8a70 1126 * \note On server, session tickets are enabled by providing
mbedAustin 11:cada08fc8a70 1127 * non-NULL callbacks.
mbedAustin 11:cada08fc8a70 1128 *
mbedAustin 11:cada08fc8a70 1129 * \note On client, use \c mbedtls_ssl_conf_session_tickets().
mbedAustin 11:cada08fc8a70 1130 *
mbedAustin 11:cada08fc8a70 1131 * \param conf SSL configuration context
mbedAustin 11:cada08fc8a70 1132 * \param f_ticket_write Callback for writing a ticket
mbedAustin 11:cada08fc8a70 1133 * \param f_ticket_parse Callback for parsing a ticket
mbedAustin 11:cada08fc8a70 1134 * \param p_ticket Context shared by the two callbacks
mbedAustin 11:cada08fc8a70 1135 */
mbedAustin 11:cada08fc8a70 1136 void mbedtls_ssl_conf_session_tickets_cb( mbedtls_ssl_config *conf,
mbedAustin 11:cada08fc8a70 1137 mbedtls_ssl_ticket_write_t *f_ticket_write,
mbedAustin 11:cada08fc8a70 1138 mbedtls_ssl_ticket_parse_t *f_ticket_parse,
mbedAustin 11:cada08fc8a70 1139 void *p_ticket );
mbedAustin 11:cada08fc8a70 1140 #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
mbedAustin 11:cada08fc8a70 1141
mbedAustin 11:cada08fc8a70 1142 #if defined(MBEDTLS_SSL_EXPORT_KEYS)
mbedAustin 11:cada08fc8a70 1143 /**
mbedAustin 11:cada08fc8a70 1144 * \brief Configure key export callback.
mbedAustin 11:cada08fc8a70 1145 * (Default: none.)
mbedAustin 11:cada08fc8a70 1146 *
mbedAustin 11:cada08fc8a70 1147 * \note See \c mbedtls_ssl_export_keys_t.
mbedAustin 11:cada08fc8a70 1148 *
mbedAustin 11:cada08fc8a70 1149 * \param conf SSL configuration context
mbedAustin 11:cada08fc8a70 1150 * \param f_export_keys Callback for exporting keys
mbedAustin 11:cada08fc8a70 1151 * \param p_export_keys Context for the callback
mbedAustin 11:cada08fc8a70 1152 */
mbedAustin 11:cada08fc8a70 1153 void mbedtls_ssl_conf_export_keys_cb( mbedtls_ssl_config *conf,
mbedAustin 11:cada08fc8a70 1154 mbedtls_ssl_export_keys_t *f_export_keys,
mbedAustin 11:cada08fc8a70 1155 void *p_export_keys );
mbedAustin 11:cada08fc8a70 1156 #endif /* MBEDTLS_SSL_EXPORT_KEYS */
mbedAustin 11:cada08fc8a70 1157
mbedAustin 11:cada08fc8a70 1158 /**
mbedAustin 11:cada08fc8a70 1159 * \brief Callback type: generate a cookie
mbedAustin 11:cada08fc8a70 1160 *
mbedAustin 11:cada08fc8a70 1161 * \param ctx Context for the callback
mbedAustin 11:cada08fc8a70 1162 * \param p Buffer to write to,
mbedAustin 11:cada08fc8a70 1163 * must be updated to point right after the cookie
mbedAustin 11:cada08fc8a70 1164 * \param end Pointer to one past the end of the output buffer
mbedAustin 11:cada08fc8a70 1165 * \param info Client ID info that was passed to
mbedAustin 11:cada08fc8a70 1166 * \c mbedtls_ssl_set_client_transport_id()
mbedAustin 11:cada08fc8a70 1167 * \param ilen Length of info in bytes
mbedAustin 11:cada08fc8a70 1168 *
mbedAustin 11:cada08fc8a70 1169 * \return The callback must return 0 on success,
mbedAustin 11:cada08fc8a70 1170 * or a negative error code.
mbedAustin 11:cada08fc8a70 1171 */
mbedAustin 11:cada08fc8a70 1172 typedef int mbedtls_ssl_cookie_write_t( void *ctx,
mbedAustin 11:cada08fc8a70 1173 unsigned char **p, unsigned char *end,
mbedAustin 11:cada08fc8a70 1174 const unsigned char *info, size_t ilen );
mbedAustin 11:cada08fc8a70 1175
mbedAustin 11:cada08fc8a70 1176 /**
mbedAustin 11:cada08fc8a70 1177 * \brief Callback type: verify a cookie
mbedAustin 11:cada08fc8a70 1178 *
mbedAustin 11:cada08fc8a70 1179 * \param ctx Context for the callback
mbedAustin 11:cada08fc8a70 1180 * \param cookie Cookie to verify
mbedAustin 11:cada08fc8a70 1181 * \param clen Length of cookie
mbedAustin 11:cada08fc8a70 1182 * \param info Client ID info that was passed to
mbedAustin 11:cada08fc8a70 1183 * \c mbedtls_ssl_set_client_transport_id()
mbedAustin 11:cada08fc8a70 1184 * \param ilen Length of info in bytes
mbedAustin 11:cada08fc8a70 1185 *
mbedAustin 11:cada08fc8a70 1186 * \return The callback must return 0 if cookie is valid,
mbedAustin 11:cada08fc8a70 1187 * or a negative error code.
mbedAustin 11:cada08fc8a70 1188 */
mbedAustin 11:cada08fc8a70 1189 typedef int mbedtls_ssl_cookie_check_t( void *ctx,
mbedAustin 11:cada08fc8a70 1190 const unsigned char *cookie, size_t clen,
mbedAustin 11:cada08fc8a70 1191 const unsigned char *info, size_t ilen );
mbedAustin 11:cada08fc8a70 1192
mbedAustin 11:cada08fc8a70 1193 #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
mbedAustin 11:cada08fc8a70 1194 /**
mbedAustin 11:cada08fc8a70 1195 * \brief Register callbacks for DTLS cookies
mbedAustin 11:cada08fc8a70 1196 * (Server only. DTLS only.)
mbedAustin 11:cada08fc8a70 1197 *
mbedAustin 11:cada08fc8a70 1198 * Default: dummy callbacks that fail, in order to force you to
mbedAustin 11:cada08fc8a70 1199 * register working callbacks (and initialize their context).
mbedAustin 11:cada08fc8a70 1200 *
mbedAustin 11:cada08fc8a70 1201 * To disable HelloVerifyRequest, register NULL callbacks.
mbedAustin 11:cada08fc8a70 1202 *
mbedAustin 11:cada08fc8a70 1203 * \warning Disabling hello verification allows your server to be used
mbedAustin 11:cada08fc8a70 1204 * for amplification in DoS attacks against other hosts.
mbedAustin 11:cada08fc8a70 1205 * Only disable if you known this can't happen in your
mbedAustin 11:cada08fc8a70 1206 * particular environment.
mbedAustin 11:cada08fc8a70 1207 *
mbedAustin 11:cada08fc8a70 1208 * \note See comments on \c mbedtls_ssl_handshake() about handling
mbedAustin 11:cada08fc8a70 1209 * the MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED that is expected
mbedAustin 11:cada08fc8a70 1210 * on the first handshake attempt when this is enabled.
mbedAustin 11:cada08fc8a70 1211 *
mbedAustin 11:cada08fc8a70 1212 * \note This is also necessary to handle client reconnection from
mbedAustin 11:cada08fc8a70 1213 * the same port as described in RFC 6347 section 4.2.8 (only
mbedAustin 11:cada08fc8a70 1214 * the variant with cookies is supported currently). See
mbedAustin 11:cada08fc8a70 1215 * comments on \c mbedtls_ssl_read() for details.
mbedAustin 11:cada08fc8a70 1216 *
mbedAustin 11:cada08fc8a70 1217 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1218 * \param f_cookie_write Cookie write callback
mbedAustin 11:cada08fc8a70 1219 * \param f_cookie_check Cookie check callback
mbedAustin 11:cada08fc8a70 1220 * \param p_cookie Context for both callbacks
mbedAustin 11:cada08fc8a70 1221 */
mbedAustin 11:cada08fc8a70 1222 void mbedtls_ssl_conf_dtls_cookies( mbedtls_ssl_config *conf,
mbedAustin 11:cada08fc8a70 1223 mbedtls_ssl_cookie_write_t *f_cookie_write,
mbedAustin 11:cada08fc8a70 1224 mbedtls_ssl_cookie_check_t *f_cookie_check,
mbedAustin 11:cada08fc8a70 1225 void *p_cookie );
mbedAustin 11:cada08fc8a70 1226
mbedAustin 11:cada08fc8a70 1227 /**
mbedAustin 11:cada08fc8a70 1228 * \brief Set client's transport-level identification info.
mbedAustin 11:cada08fc8a70 1229 * (Server only. DTLS only.)
mbedAustin 11:cada08fc8a70 1230 *
mbedAustin 11:cada08fc8a70 1231 * This is usually the IP address (and port), but could be
mbedAustin 11:cada08fc8a70 1232 * anything identify the client depending on the underlying
mbedAustin 11:cada08fc8a70 1233 * network stack. Used for HelloVerifyRequest with DTLS.
mbedAustin 11:cada08fc8a70 1234 * This is *not* used to route the actual packets.
mbedAustin 11:cada08fc8a70 1235 *
mbedAustin 11:cada08fc8a70 1236 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 1237 * \param info Transport-level info identifying the client (eg IP + port)
mbedAustin 11:cada08fc8a70 1238 * \param ilen Length of info in bytes
mbedAustin 11:cada08fc8a70 1239 *
mbedAustin 11:cada08fc8a70 1240 * \note An internal copy is made, so the info buffer can be reused.
mbedAustin 11:cada08fc8a70 1241 *
mbedAustin 11:cada08fc8a70 1242 * \return 0 on success,
mbedAustin 11:cada08fc8a70 1243 * MBEDTLS_ERR_SSL_BAD_INPUT_DATA if used on client,
mbedAustin 11:cada08fc8a70 1244 * MBEDTLS_ERR_SSL_ALLOC_FAILED if out of memory.
mbedAustin 11:cada08fc8a70 1245 */
mbedAustin 11:cada08fc8a70 1246 int mbedtls_ssl_set_client_transport_id( mbedtls_ssl_context *ssl,
mbedAustin 11:cada08fc8a70 1247 const unsigned char *info,
mbedAustin 11:cada08fc8a70 1248 size_t ilen );
mbedAustin 11:cada08fc8a70 1249
mbedAustin 11:cada08fc8a70 1250 #endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY && MBEDTLS_SSL_SRV_C */
mbedAustin 11:cada08fc8a70 1251
mbedAustin 11:cada08fc8a70 1252 #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
mbedAustin 11:cada08fc8a70 1253 /**
mbedAustin 11:cada08fc8a70 1254 * \brief Enable or disable anti-replay protection for DTLS.
mbedAustin 11:cada08fc8a70 1255 * (DTLS only, no effect on TLS.)
mbedAustin 11:cada08fc8a70 1256 * Default: enabled.
mbedAustin 11:cada08fc8a70 1257 *
mbedAustin 11:cada08fc8a70 1258 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1259 * \param mode MBEDTLS_SSL_ANTI_REPLAY_ENABLED or MBEDTLS_SSL_ANTI_REPLAY_DISABLED.
mbedAustin 11:cada08fc8a70 1260 *
mbedAustin 11:cada08fc8a70 1261 * \warning Disabling this is a security risk unless the application
mbedAustin 11:cada08fc8a70 1262 * protocol handles duplicated packets in a safe way. You
mbedAustin 11:cada08fc8a70 1263 * should not disable this without careful consideration.
mbedAustin 11:cada08fc8a70 1264 * However, if your application already detects duplicated
mbedAustin 11:cada08fc8a70 1265 * packets and needs information about them to adjust its
mbedAustin 11:cada08fc8a70 1266 * transmission strategy, then you'll want to disable this.
mbedAustin 11:cada08fc8a70 1267 */
mbedAustin 11:cada08fc8a70 1268 void mbedtls_ssl_conf_dtls_anti_replay( mbedtls_ssl_config *conf, char mode );
mbedAustin 11:cada08fc8a70 1269 #endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */
mbedAustin 11:cada08fc8a70 1270
mbedAustin 11:cada08fc8a70 1271 #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
mbedAustin 11:cada08fc8a70 1272 /**
mbedAustin 11:cada08fc8a70 1273 * \brief Set a limit on the number of records with a bad MAC
mbedAustin 11:cada08fc8a70 1274 * before terminating the connection.
mbedAustin 11:cada08fc8a70 1275 * (DTLS only, no effect on TLS.)
mbedAustin 11:cada08fc8a70 1276 * Default: 0 (disabled).
mbedAustin 11:cada08fc8a70 1277 *
mbedAustin 11:cada08fc8a70 1278 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1279 * \param limit Limit, or 0 to disable.
mbedAustin 11:cada08fc8a70 1280 *
mbedAustin 11:cada08fc8a70 1281 * \note If the limit is N, then the connection is terminated when
mbedAustin 11:cada08fc8a70 1282 * the Nth non-authentic record is seen.
mbedAustin 11:cada08fc8a70 1283 *
mbedAustin 11:cada08fc8a70 1284 * \note Records with an invalid header are not counted, only the
mbedAustin 11:cada08fc8a70 1285 * ones going through the authentication-decryption phase.
mbedAustin 11:cada08fc8a70 1286 *
mbedAustin 11:cada08fc8a70 1287 * \note This is a security trade-off related to the fact that it's
mbedAustin 11:cada08fc8a70 1288 * often relatively easy for an active attacker ot inject UDP
mbedAustin 11:cada08fc8a70 1289 * datagrams. On one hand, setting a low limit here makes it
mbedAustin 11:cada08fc8a70 1290 * easier for such an attacker to forcibly terminated a
mbedAustin 11:cada08fc8a70 1291 * connection. On the other hand, a high limit or no limit
mbedAustin 11:cada08fc8a70 1292 * might make us waste resources checking authentication on
mbedAustin 11:cada08fc8a70 1293 * many bogus packets.
mbedAustin 11:cada08fc8a70 1294 */
mbedAustin 11:cada08fc8a70 1295 void mbedtls_ssl_conf_dtls_badmac_limit( mbedtls_ssl_config *conf, unsigned limit );
mbedAustin 11:cada08fc8a70 1296 #endif /* MBEDTLS_SSL_DTLS_BADMAC_LIMIT */
mbedAustin 11:cada08fc8a70 1297
mbedAustin 11:cada08fc8a70 1298 #if defined(MBEDTLS_SSL_PROTO_DTLS)
mbedAustin 11:cada08fc8a70 1299 /**
mbedAustin 11:cada08fc8a70 1300 * \brief Set retransmit timeout values for the DTLS handshale.
mbedAustin 11:cada08fc8a70 1301 * (DTLS only, no effect on TLS.)
mbedAustin 11:cada08fc8a70 1302 *
mbedAustin 11:cada08fc8a70 1303 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1304 * \param min Initial timeout value in milliseconds.
mbedAustin 11:cada08fc8a70 1305 * Default: 1000 (1 second).
mbedAustin 11:cada08fc8a70 1306 * \param max Maximum timeout value in milliseconds.
mbedAustin 11:cada08fc8a70 1307 * Default: 60000 (60 seconds).
mbedAustin 11:cada08fc8a70 1308 *
mbedAustin 11:cada08fc8a70 1309 * \note Default values are from RFC 6347 section 4.2.4.1.
mbedAustin 11:cada08fc8a70 1310 *
mbedAustin 11:cada08fc8a70 1311 * \note Higher values for initial timeout may increase average
mbedAustin 11:cada08fc8a70 1312 * handshake latency. Lower values may increase the risk of
mbedAustin 11:cada08fc8a70 1313 * network congestion by causing more retransmissions.
mbedAustin 11:cada08fc8a70 1314 */
mbedAustin 11:cada08fc8a70 1315 void mbedtls_ssl_conf_handshake_timeout( mbedtls_ssl_config *conf, uint32_t min, uint32_t max );
mbedAustin 11:cada08fc8a70 1316 #endif /* MBEDTLS_SSL_PROTO_DTLS */
mbedAustin 11:cada08fc8a70 1317
mbedAustin 11:cada08fc8a70 1318 #if defined(MBEDTLS_SSL_SRV_C)
mbedAustin 11:cada08fc8a70 1319 /**
mbedAustin 11:cada08fc8a70 1320 * \brief Set the session cache callbacks (server-side only)
mbedAustin 11:cada08fc8a70 1321 * If not set, no session resuming is done (except if session
mbedAustin 11:cada08fc8a70 1322 * tickets are enabled too).
mbedAustin 11:cada08fc8a70 1323 *
mbedAustin 11:cada08fc8a70 1324 * The session cache has the responsibility to check for stale
mbedAustin 11:cada08fc8a70 1325 * entries based on timeout. See RFC 5246 for recommendations.
mbedAustin 11:cada08fc8a70 1326 *
mbedAustin 11:cada08fc8a70 1327 * Warning: session.peer_cert is cleared by the SSL/TLS layer on
mbedAustin 11:cada08fc8a70 1328 * connection shutdown, so do not cache the pointer! Either set
mbedAustin 11:cada08fc8a70 1329 * it to NULL or make a full copy of the certificate.
mbedAustin 11:cada08fc8a70 1330 *
mbedAustin 11:cada08fc8a70 1331 * The get callback is called once during the initial handshake
mbedAustin 11:cada08fc8a70 1332 * to enable session resuming. The get function has the
mbedAustin 11:cada08fc8a70 1333 * following parameters: (void *parameter, mbedtls_ssl_session *session)
mbedAustin 11:cada08fc8a70 1334 * If a valid entry is found, it should fill the master of
mbedAustin 11:cada08fc8a70 1335 * the session object with the cached values and return 0,
mbedAustin 11:cada08fc8a70 1336 * return 1 otherwise. Optionally peer_cert can be set as well
mbedAustin 11:cada08fc8a70 1337 * if it is properly present in cache entry.
mbedAustin 11:cada08fc8a70 1338 *
mbedAustin 11:cada08fc8a70 1339 * The set callback is called once during the initial handshake
mbedAustin 11:cada08fc8a70 1340 * to enable session resuming after the entire handshake has
mbedAustin 11:cada08fc8a70 1341 * been finished. The set function has the following parameters:
mbedAustin 11:cada08fc8a70 1342 * (void *parameter, const mbedtls_ssl_session *session). The function
mbedAustin 11:cada08fc8a70 1343 * should create a cache entry for future retrieval based on
mbedAustin 11:cada08fc8a70 1344 * the data in the session structure and should keep in mind
mbedAustin 11:cada08fc8a70 1345 * that the mbedtls_ssl_session object presented (and all its referenced
mbedAustin 11:cada08fc8a70 1346 * data) is cleared by the SSL/TLS layer when the connection is
mbedAustin 11:cada08fc8a70 1347 * terminated. It is recommended to add metadata to determine if
mbedAustin 11:cada08fc8a70 1348 * an entry is still valid in the future. Return 0 if
mbedAustin 11:cada08fc8a70 1349 * successfully cached, return 1 otherwise.
mbedAustin 11:cada08fc8a70 1350 *
mbedAustin 11:cada08fc8a70 1351 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1352 * \param p_cache parmater (context) for both callbacks
mbedAustin 11:cada08fc8a70 1353 * \param f_get_cache session get callback
mbedAustin 11:cada08fc8a70 1354 * \param f_set_cache session set callback
mbedAustin 11:cada08fc8a70 1355 */
mbedAustin 11:cada08fc8a70 1356 void mbedtls_ssl_conf_session_cache( mbedtls_ssl_config *conf,
mbedAustin 11:cada08fc8a70 1357 void *p_cache,
mbedAustin 11:cada08fc8a70 1358 int (*f_get_cache)(void *, mbedtls_ssl_session *),
mbedAustin 11:cada08fc8a70 1359 int (*f_set_cache)(void *, const mbedtls_ssl_session *) );
mbedAustin 11:cada08fc8a70 1360 #endif /* MBEDTLS_SSL_SRV_C */
mbedAustin 11:cada08fc8a70 1361
mbedAustin 11:cada08fc8a70 1362 #if defined(MBEDTLS_SSL_CLI_C)
mbedAustin 11:cada08fc8a70 1363 /**
mbedAustin 11:cada08fc8a70 1364 * \brief Request resumption of session (client-side only)
mbedAustin 11:cada08fc8a70 1365 * Session data is copied from presented session structure.
mbedAustin 11:cada08fc8a70 1366 *
mbedAustin 11:cada08fc8a70 1367 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 1368 * \param session session context
mbedAustin 11:cada08fc8a70 1369 *
mbedAustin 11:cada08fc8a70 1370 * \return 0 if successful,
mbedAustin 11:cada08fc8a70 1371 * MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed,
mbedAustin 11:cada08fc8a70 1372 * MBEDTLS_ERR_SSL_BAD_INPUT_DATA if used server-side or
mbedAustin 11:cada08fc8a70 1373 * arguments are otherwise invalid
mbedAustin 11:cada08fc8a70 1374 *
mbedAustin 11:cada08fc8a70 1375 * \sa mbedtls_ssl_get_session()
mbedAustin 11:cada08fc8a70 1376 */
mbedAustin 11:cada08fc8a70 1377 int mbedtls_ssl_set_session( mbedtls_ssl_context *ssl, const mbedtls_ssl_session *session );
mbedAustin 11:cada08fc8a70 1378 #endif /* MBEDTLS_SSL_CLI_C */
mbedAustin 11:cada08fc8a70 1379
mbedAustin 11:cada08fc8a70 1380 /**
mbedAustin 11:cada08fc8a70 1381 * \brief Set the list of allowed ciphersuites and the preference
mbedAustin 11:cada08fc8a70 1382 * order. First in the list has the highest preference.
mbedAustin 11:cada08fc8a70 1383 * (Overrides all version specific lists)
mbedAustin 11:cada08fc8a70 1384 *
mbedAustin 11:cada08fc8a70 1385 * The ciphersuites array is not copied, and must remain
mbedAustin 11:cada08fc8a70 1386 * valid for the lifetime of the ssl_config.
mbedAustin 11:cada08fc8a70 1387 *
mbedAustin 11:cada08fc8a70 1388 * Note: The server uses its own preferences
mbedAustin 11:cada08fc8a70 1389 * over the preference of the client unless
mbedAustin 11:cada08fc8a70 1390 * MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE is defined!
mbedAustin 11:cada08fc8a70 1391 *
mbedAustin 11:cada08fc8a70 1392 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1393 * \param ciphersuites 0-terminated list of allowed ciphersuites
mbedAustin 11:cada08fc8a70 1394 */
mbedAustin 11:cada08fc8a70 1395 void mbedtls_ssl_conf_ciphersuites( mbedtls_ssl_config *conf,
mbedAustin 11:cada08fc8a70 1396 const int *ciphersuites );
mbedAustin 11:cada08fc8a70 1397
mbedAustin 11:cada08fc8a70 1398 /**
mbedAustin 11:cada08fc8a70 1399 * \brief Set the list of allowed ciphersuites and the
mbedAustin 11:cada08fc8a70 1400 * preference order for a specific version of the protocol.
mbedAustin 11:cada08fc8a70 1401 * (Only useful on the server side)
mbedAustin 11:cada08fc8a70 1402 *
mbedAustin 11:cada08fc8a70 1403 * The ciphersuites array is not copied, and must remain
mbedAustin 11:cada08fc8a70 1404 * valid for the lifetime of the ssl_config.
mbedAustin 11:cada08fc8a70 1405 *
mbedAustin 11:cada08fc8a70 1406 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1407 * \param ciphersuites 0-terminated list of allowed ciphersuites
mbedAustin 11:cada08fc8a70 1408 * \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3
mbedAustin 11:cada08fc8a70 1409 * supported)
mbedAustin 11:cada08fc8a70 1410 * \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0,
mbedAustin 11:cada08fc8a70 1411 * MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2,
mbedAustin 11:cada08fc8a70 1412 * MBEDTLS_SSL_MINOR_VERSION_3 supported)
mbedAustin 11:cada08fc8a70 1413 *
mbedAustin 11:cada08fc8a70 1414 * \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_2 for DTLS 1.0
mbedAustin 11:cada08fc8a70 1415 * and MBEDTLS_SSL_MINOR_VERSION_3 for DTLS 1.2
mbedAustin 11:cada08fc8a70 1416 */
mbedAustin 11:cada08fc8a70 1417 void mbedtls_ssl_conf_ciphersuites_for_version( mbedtls_ssl_config *conf,
mbedAustin 11:cada08fc8a70 1418 const int *ciphersuites,
mbedAustin 11:cada08fc8a70 1419 int major, int minor );
mbedAustin 11:cada08fc8a70 1420
mbedAustin 11:cada08fc8a70 1421 #if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedAustin 11:cada08fc8a70 1422 /**
mbedAustin 11:cada08fc8a70 1423 * \brief Set the X.509 security profile used for verification
mbedAustin 11:cada08fc8a70 1424 *
mbedAustin 11:cada08fc8a70 1425 * \note The restrictions are enforced for all certificates in the
mbedAustin 11:cada08fc8a70 1426 * chain. However, signatures in the handshake are not covered
mbedAustin 11:cada08fc8a70 1427 * by this setting but by \b mbedtls_ssl_conf_sig_hashes().
mbedAustin 11:cada08fc8a70 1428 *
mbedAustin 11:cada08fc8a70 1429 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1430 * \param profile Profile to use
mbedAustin 11:cada08fc8a70 1431 */
mbedAustin 11:cada08fc8a70 1432 void mbedtls_ssl_conf_cert_profile( mbedtls_ssl_config *conf,
mbedAustin 11:cada08fc8a70 1433 const mbedtls_x509_crt_profile *profile );
mbedAustin 11:cada08fc8a70 1434
mbedAustin 11:cada08fc8a70 1435 /**
mbedAustin 11:cada08fc8a70 1436 * \brief Set the data required to verify peer certificate
mbedAustin 11:cada08fc8a70 1437 *
mbedAustin 11:cada08fc8a70 1438 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1439 * \param ca_chain trusted CA chain (meaning all fully trusted top-level CAs)
mbedAustin 11:cada08fc8a70 1440 * \param ca_crl trusted CA CRLs
mbedAustin 11:cada08fc8a70 1441 */
mbedAustin 11:cada08fc8a70 1442 void mbedtls_ssl_conf_ca_chain( mbedtls_ssl_config *conf,
mbedAustin 11:cada08fc8a70 1443 mbedtls_x509_crt *ca_chain,
mbedAustin 11:cada08fc8a70 1444 mbedtls_x509_crl *ca_crl );
mbedAustin 11:cada08fc8a70 1445
mbedAustin 11:cada08fc8a70 1446 /**
mbedAustin 11:cada08fc8a70 1447 * \brief Set own certificate chain and private key
mbedAustin 11:cada08fc8a70 1448 *
mbedAustin 11:cada08fc8a70 1449 * \note own_cert should contain in order from the bottom up your
mbedAustin 11:cada08fc8a70 1450 * certificate chain. The top certificate (self-signed)
mbedAustin 11:cada08fc8a70 1451 * can be omitted.
mbedAustin 11:cada08fc8a70 1452 *
mbedAustin 11:cada08fc8a70 1453 * \note On server, this function can be called multiple times to
mbedAustin 11:cada08fc8a70 1454 * provision more than one cert/key pair (eg one ECDSA, one
mbedAustin 11:cada08fc8a70 1455 * RSA with SHA-256, one RSA with SHA-1). An adequate
mbedAustin 11:cada08fc8a70 1456 * certificate will be selected according to the client's
mbedAustin 11:cada08fc8a70 1457 * advertised capabilities. In case mutliple certificates are
mbedAustin 11:cada08fc8a70 1458 * adequate, preference is given to the one set by the first
mbedAustin 11:cada08fc8a70 1459 * call to this function, then second, etc.
mbedAustin 11:cada08fc8a70 1460 *
mbedAustin 11:cada08fc8a70 1461 * \note On client, only the first call has any effect.
mbedAustin 11:cada08fc8a70 1462 *
mbedAustin 11:cada08fc8a70 1463 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1464 * \param own_cert own public certificate chain
mbedAustin 11:cada08fc8a70 1465 * \param pk_key own private key
mbedAustin 11:cada08fc8a70 1466 *
mbedAustin 11:cada08fc8a70 1467 * \return 0 on success or MBEDTLS_ERR_SSL_ALLOC_FAILED
mbedAustin 11:cada08fc8a70 1468 */
mbedAustin 11:cada08fc8a70 1469 int mbedtls_ssl_conf_own_cert( mbedtls_ssl_config *conf,
mbedAustin 11:cada08fc8a70 1470 mbedtls_x509_crt *own_cert,
mbedAustin 11:cada08fc8a70 1471 mbedtls_pk_context *pk_key );
mbedAustin 11:cada08fc8a70 1472 #endif /* MBEDTLS_X509_CRT_PARSE_C */
mbedAustin 11:cada08fc8a70 1473
mbedAustin 11:cada08fc8a70 1474 #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
mbedAustin 11:cada08fc8a70 1475 /**
mbedAustin 11:cada08fc8a70 1476 * \brief Set the Pre Shared Key (PSK) and the expected identity name
mbedAustin 11:cada08fc8a70 1477 *
mbedAustin 11:cada08fc8a70 1478 * \note This is mainly useful for clients. Servers will usually
mbedAustin 11:cada08fc8a70 1479 * want to use \c mbedtls_ssl_conf_psk_cb() instead.
mbedAustin 11:cada08fc8a70 1480 *
mbedAustin 11:cada08fc8a70 1481 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1482 * \param psk pointer to the pre-shared key
mbedAustin 11:cada08fc8a70 1483 * \param psk_len pre-shared key length
mbedAustin 11:cada08fc8a70 1484 * \param psk_identity pointer to the pre-shared key identity
mbedAustin 11:cada08fc8a70 1485 * \param psk_identity_len identity key length
mbedAustin 11:cada08fc8a70 1486 *
mbedAustin 11:cada08fc8a70 1487 * \return 0 if successful or MBEDTLS_ERR_SSL_ALLOC_FAILED
mbedAustin 11:cada08fc8a70 1488 */
mbedAustin 11:cada08fc8a70 1489 int mbedtls_ssl_conf_psk( mbedtls_ssl_config *conf,
mbedAustin 11:cada08fc8a70 1490 const unsigned char *psk, size_t psk_len,
mbedAustin 11:cada08fc8a70 1491 const unsigned char *psk_identity, size_t psk_identity_len );
mbedAustin 11:cada08fc8a70 1492
mbedAustin 11:cada08fc8a70 1493
mbedAustin 11:cada08fc8a70 1494 /**
mbedAustin 11:cada08fc8a70 1495 * \brief Set the Pre Shared Key (PSK) for the current handshake
mbedAustin 11:cada08fc8a70 1496 *
mbedAustin 11:cada08fc8a70 1497 * \note This should only be called inside the PSK callback,
mbedAustin 11:cada08fc8a70 1498 * ie the function passed to \c mbedtls_ssl_conf_psk_cb().
mbedAustin 11:cada08fc8a70 1499 *
mbedAustin 11:cada08fc8a70 1500 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 1501 * \param psk pointer to the pre-shared key
mbedAustin 11:cada08fc8a70 1502 * \param psk_len pre-shared key length
mbedAustin 11:cada08fc8a70 1503 *
mbedAustin 11:cada08fc8a70 1504 * \return 0 if successful or MBEDTLS_ERR_SSL_ALLOC_FAILED
mbedAustin 11:cada08fc8a70 1505 */
mbedAustin 11:cada08fc8a70 1506 int mbedtls_ssl_set_hs_psk( mbedtls_ssl_context *ssl,
mbedAustin 11:cada08fc8a70 1507 const unsigned char *psk, size_t psk_len );
mbedAustin 11:cada08fc8a70 1508
mbedAustin 11:cada08fc8a70 1509 /**
mbedAustin 11:cada08fc8a70 1510 * \brief Set the PSK callback (server-side only).
mbedAustin 11:cada08fc8a70 1511 *
mbedAustin 11:cada08fc8a70 1512 * If set, the PSK callback is called for each
mbedAustin 11:cada08fc8a70 1513 * handshake where a PSK ciphersuite was negotiated.
mbedAustin 11:cada08fc8a70 1514 * The caller provides the identity received and wants to
mbedAustin 11:cada08fc8a70 1515 * receive the actual PSK data and length.
mbedAustin 11:cada08fc8a70 1516 *
mbedAustin 11:cada08fc8a70 1517 * The callback has the following parameters: (void *parameter,
mbedAustin 11:cada08fc8a70 1518 * mbedtls_ssl_context *ssl, const unsigned char *psk_identity,
mbedAustin 11:cada08fc8a70 1519 * size_t identity_len)
mbedAustin 11:cada08fc8a70 1520 * If a valid PSK identity is found, the callback should use
mbedAustin 11:cada08fc8a70 1521 * \c mbedtls_ssl_set_hs_psk() on the ssl context to set the
mbedAustin 11:cada08fc8a70 1522 * correct PSK and return 0.
mbedAustin 11:cada08fc8a70 1523 * Any other return value will result in a denied PSK identity.
mbedAustin 11:cada08fc8a70 1524 *
mbedAustin 11:cada08fc8a70 1525 * \note If you set a PSK callback using this function, then you
mbedAustin 11:cada08fc8a70 1526 * don't need to set a PSK key and identity using
mbedAustin 11:cada08fc8a70 1527 * \c mbedtls_ssl_conf_psk().
mbedAustin 11:cada08fc8a70 1528 *
mbedAustin 11:cada08fc8a70 1529 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1530 * \param f_psk PSK identity function
mbedAustin 11:cada08fc8a70 1531 * \param p_psk PSK identity parameter
mbedAustin 11:cada08fc8a70 1532 */
mbedAustin 11:cada08fc8a70 1533 void mbedtls_ssl_conf_psk_cb( mbedtls_ssl_config *conf,
mbedAustin 11:cada08fc8a70 1534 int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *,
mbedAustin 11:cada08fc8a70 1535 size_t),
mbedAustin 11:cada08fc8a70 1536 void *p_psk );
mbedAustin 11:cada08fc8a70 1537 #endif /* MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED */
mbedAustin 11:cada08fc8a70 1538
mbedAustin 11:cada08fc8a70 1539 #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_SRV_C)
mbedAustin 11:cada08fc8a70 1540 /**
mbedAustin 11:cada08fc8a70 1541 * \brief Set the Diffie-Hellman public P and G values,
mbedAustin 11:cada08fc8a70 1542 * read as hexadecimal strings (server-side only)
mbedAustin 11:cada08fc8a70 1543 * (Default: MBEDTLS_DHM_RFC5114_MODP_2048_[PG])
mbedAustin 11:cada08fc8a70 1544 *
mbedAustin 11:cada08fc8a70 1545 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1546 * \param dhm_P Diffie-Hellman-Merkle modulus
mbedAustin 11:cada08fc8a70 1547 * \param dhm_G Diffie-Hellman-Merkle generator
mbedAustin 11:cada08fc8a70 1548 *
mbedAustin 11:cada08fc8a70 1549 * \return 0 if successful
mbedAustin 11:cada08fc8a70 1550 */
mbedAustin 11:cada08fc8a70 1551 int mbedtls_ssl_conf_dh_param( mbedtls_ssl_config *conf, const char *dhm_P, const char *dhm_G );
mbedAustin 11:cada08fc8a70 1552
mbedAustin 11:cada08fc8a70 1553 /**
mbedAustin 11:cada08fc8a70 1554 * \brief Set the Diffie-Hellman public P and G values,
mbedAustin 11:cada08fc8a70 1555 * read from existing context (server-side only)
mbedAustin 11:cada08fc8a70 1556 *
mbedAustin 11:cada08fc8a70 1557 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1558 * \param dhm_ctx Diffie-Hellman-Merkle context
mbedAustin 11:cada08fc8a70 1559 *
mbedAustin 11:cada08fc8a70 1560 * \return 0 if successful
mbedAustin 11:cada08fc8a70 1561 */
mbedAustin 11:cada08fc8a70 1562 int mbedtls_ssl_conf_dh_param_ctx( mbedtls_ssl_config *conf, mbedtls_dhm_context *dhm_ctx );
mbedAustin 11:cada08fc8a70 1563 #endif /* MBEDTLS_DHM_C && defined(MBEDTLS_SSL_SRV_C) */
mbedAustin 11:cada08fc8a70 1564
mbedAustin 11:cada08fc8a70 1565 #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
mbedAustin 11:cada08fc8a70 1566 /**
mbedAustin 11:cada08fc8a70 1567 * \brief Set the minimum length for Diffie-Hellman parameters.
mbedAustin 11:cada08fc8a70 1568 * (Client-side only.)
mbedAustin 11:cada08fc8a70 1569 * (Default: 1024 bits.)
mbedAustin 11:cada08fc8a70 1570 *
mbedAustin 11:cada08fc8a70 1571 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1572 * \param bitlen Minimum bit length of the DHM prime
mbedAustin 11:cada08fc8a70 1573 */
mbedAustin 11:cada08fc8a70 1574 void mbedtls_ssl_conf_dhm_min_bitlen( mbedtls_ssl_config *conf,
mbedAustin 11:cada08fc8a70 1575 unsigned int bitlen );
mbedAustin 11:cada08fc8a70 1576 #endif /* MBEDTLS_DHM_C && MBEDTLS_SSL_CLI_C */
mbedAustin 11:cada08fc8a70 1577
mbedAustin 11:cada08fc8a70 1578 #if defined(MBEDTLS_ECP_C)
mbedAustin 11:cada08fc8a70 1579 /**
mbedAustin 11:cada08fc8a70 1580 * \brief Set the allowed curves in order of preference.
mbedAustin 11:cada08fc8a70 1581 * (Default: all defined curves.)
mbedAustin 11:cada08fc8a70 1582 *
mbedAustin 11:cada08fc8a70 1583 * On server: this only affects selection of the ECDHE curve;
mbedAustin 11:cada08fc8a70 1584 * the curves used for ECDH and ECDSA are determined by the
mbedAustin 11:cada08fc8a70 1585 * list of available certificates instead.
mbedAustin 11:cada08fc8a70 1586 *
mbedAustin 11:cada08fc8a70 1587 * On client: this affects the list of curves offered for any
mbedAustin 11:cada08fc8a70 1588 * use. The server can override our preference order.
mbedAustin 11:cada08fc8a70 1589 *
mbedAustin 11:cada08fc8a70 1590 * Both sides: limits the set of curves accepted for use in
mbedAustin 11:cada08fc8a70 1591 * ECDHE and in the peer's end-entity certificate.
mbedAustin 11:cada08fc8a70 1592 *
mbedAustin 11:cada08fc8a70 1593 * \note This has no influence on which curves are allowed inside the
mbedAustin 11:cada08fc8a70 1594 * certificate chains, see \c mbedtls_ssl_conf_cert_profile()
mbedAustin 11:cada08fc8a70 1595 * for that. For the end-entity certificate however, the key
mbedAustin 11:cada08fc8a70 1596 * will be accepted only if it is allowed both by this list
mbedAustin 11:cada08fc8a70 1597 * and by the cert profile.
mbedAustin 11:cada08fc8a70 1598 *
mbedAustin 11:cada08fc8a70 1599 * \note This list should be ordered by decreasing preference
mbedAustin 11:cada08fc8a70 1600 * (preferred curve first).
mbedAustin 11:cada08fc8a70 1601 *
mbedAustin 11:cada08fc8a70 1602 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1603 * \param curves Ordered list of allowed curves,
mbedAustin 11:cada08fc8a70 1604 * terminated by MBEDTLS_ECP_DP_NONE.
mbedAustin 11:cada08fc8a70 1605 */
mbedAustin 11:cada08fc8a70 1606 void mbedtls_ssl_conf_curves( mbedtls_ssl_config *conf,
mbedAustin 11:cada08fc8a70 1607 const mbedtls_ecp_group_id *curves );
mbedAustin 11:cada08fc8a70 1608 #endif /* MBEDTLS_ECP_C */
mbedAustin 11:cada08fc8a70 1609
mbedAustin 11:cada08fc8a70 1610 #if defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED)
mbedAustin 11:cada08fc8a70 1611 /**
mbedAustin 11:cada08fc8a70 1612 * \brief Set the allowed hashes for signatures during the handshake.
mbedAustin 11:cada08fc8a70 1613 * (Default: all available hashes.)
mbedAustin 11:cada08fc8a70 1614 *
mbedAustin 11:cada08fc8a70 1615 * \note This only affects which hashes are offered and can be used
mbedAustin 11:cada08fc8a70 1616 * for signatures during the handshake. Hashes for message
mbedAustin 11:cada08fc8a70 1617 * authentication and the TLS PRF are controlled by the
mbedAustin 11:cada08fc8a70 1618 * ciphersuite, see \c mbedtls_ssl_conf_ciphersuites(). Hashes
mbedAustin 11:cada08fc8a70 1619 * used for certificate signature are controlled by the
mbedAustin 11:cada08fc8a70 1620 * verification profile, see \c mbedtls_ssl_conf_cert_profile().
mbedAustin 11:cada08fc8a70 1621 *
mbedAustin 11:cada08fc8a70 1622 * \note This list should be ordered by decreasing preference
mbedAustin 11:cada08fc8a70 1623 * (preferred hash first).
mbedAustin 11:cada08fc8a70 1624 *
mbedAustin 11:cada08fc8a70 1625 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1626 * \param hashes Ordered list of allowed signature hashes,
mbedAustin 11:cada08fc8a70 1627 * terminated by \c MBEDTLS_MD_NONE.
mbedAustin 11:cada08fc8a70 1628 */
mbedAustin 11:cada08fc8a70 1629 void mbedtls_ssl_conf_sig_hashes( mbedtls_ssl_config *conf,
mbedAustin 11:cada08fc8a70 1630 const int *hashes );
mbedAustin 11:cada08fc8a70 1631 #endif /* MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED */
mbedAustin 11:cada08fc8a70 1632
mbedAustin 11:cada08fc8a70 1633 #if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedAustin 11:cada08fc8a70 1634 /**
mbedAustin 11:cada08fc8a70 1635 * \brief Set hostname for ServerName TLS extension
mbedAustin 11:cada08fc8a70 1636 * (client-side only)
mbedAustin 11:cada08fc8a70 1637 *
mbedAustin 11:cada08fc8a70 1638 *
mbedAustin 11:cada08fc8a70 1639 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 1640 * \param hostname the server hostname
mbedAustin 11:cada08fc8a70 1641 *
mbedAustin 11:cada08fc8a70 1642 * \return 0 if successful or MBEDTLS_ERR_SSL_ALLOC_FAILED
mbedAustin 11:cada08fc8a70 1643 */
mbedAustin 11:cada08fc8a70 1644 int mbedtls_ssl_set_hostname( mbedtls_ssl_context *ssl, const char *hostname );
mbedAustin 11:cada08fc8a70 1645 #endif /* MBEDTLS_X509_CRT_PARSE_C */
mbedAustin 11:cada08fc8a70 1646
mbedAustin 11:cada08fc8a70 1647 #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
mbedAustin 11:cada08fc8a70 1648 /**
mbedAustin 11:cada08fc8a70 1649 * \brief Set own certificate and key for the current handshake
mbedAustin 11:cada08fc8a70 1650 *
mbedAustin 11:cada08fc8a70 1651 * \note Same as \c mbedtls_ssl_conf_own_cert() but for use within
mbedAustin 11:cada08fc8a70 1652 * the SNI callback.
mbedAustin 11:cada08fc8a70 1653 *
mbedAustin 11:cada08fc8a70 1654 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 1655 * \param own_cert own public certificate chain
mbedAustin 11:cada08fc8a70 1656 * \param pk_key own private key
mbedAustin 11:cada08fc8a70 1657 *
mbedAustin 11:cada08fc8a70 1658 * \return 0 on success or MBEDTLS_ERR_SSL_ALLOC_FAILED
mbedAustin 11:cada08fc8a70 1659 */
mbedAustin 11:cada08fc8a70 1660 int mbedtls_ssl_set_hs_own_cert( mbedtls_ssl_context *ssl,
mbedAustin 11:cada08fc8a70 1661 mbedtls_x509_crt *own_cert,
mbedAustin 11:cada08fc8a70 1662 mbedtls_pk_context *pk_key );
mbedAustin 11:cada08fc8a70 1663
mbedAustin 11:cada08fc8a70 1664 /**
mbedAustin 11:cada08fc8a70 1665 * \brief Set the data required to verify peer certificate for the
mbedAustin 11:cada08fc8a70 1666 * current handshake
mbedAustin 11:cada08fc8a70 1667 *
mbedAustin 11:cada08fc8a70 1668 * \note Same as \c mbedtls_ssl_conf_ca_chain() but for use within
mbedAustin 11:cada08fc8a70 1669 * the SNI callback.
mbedAustin 11:cada08fc8a70 1670 *
mbedAustin 11:cada08fc8a70 1671 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 1672 * \param ca_chain trusted CA chain (meaning all fully trusted top-level CAs)
mbedAustin 11:cada08fc8a70 1673 * \param ca_crl trusted CA CRLs
mbedAustin 11:cada08fc8a70 1674 */
mbedAustin 11:cada08fc8a70 1675 void mbedtls_ssl_set_hs_ca_chain( mbedtls_ssl_context *ssl,
mbedAustin 11:cada08fc8a70 1676 mbedtls_x509_crt *ca_chain,
mbedAustin 11:cada08fc8a70 1677 mbedtls_x509_crl *ca_crl );
mbedAustin 11:cada08fc8a70 1678
mbedAustin 11:cada08fc8a70 1679 /**
mbedAustin 11:cada08fc8a70 1680 * \brief Set authmode for the current handshake.
mbedAustin 11:cada08fc8a70 1681 *
mbedAustin 11:cada08fc8a70 1682 * \note Same as \c mbedtls_ssl_conf_authmode() but for use within
mbedAustin 11:cada08fc8a70 1683 * the SNI callback.
mbedAustin 11:cada08fc8a70 1684 *
mbedAustin 11:cada08fc8a70 1685 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 1686 * \param authmode MBEDTLS_SSL_VERIFY_NONE, MBEDTLS_SSL_VERIFY_OPTIONAL or
mbedAustin 11:cada08fc8a70 1687 * MBEDTLS_SSL_VERIFY_REQUIRED
mbedAustin 11:cada08fc8a70 1688 */
mbedAustin 11:cada08fc8a70 1689 void mbedtls_ssl_set_hs_authmode( mbedtls_ssl_context *ssl,
mbedAustin 11:cada08fc8a70 1690 int authmode );
mbedAustin 11:cada08fc8a70 1691
mbedAustin 11:cada08fc8a70 1692 /**
mbedAustin 11:cada08fc8a70 1693 * \brief Set server side ServerName TLS extension callback
mbedAustin 11:cada08fc8a70 1694 * (optional, server-side only).
mbedAustin 11:cada08fc8a70 1695 *
mbedAustin 11:cada08fc8a70 1696 * If set, the ServerName callback is called whenever the
mbedAustin 11:cada08fc8a70 1697 * server receives a ServerName TLS extension from the client
mbedAustin 11:cada08fc8a70 1698 * during a handshake. The ServerName callback has the
mbedAustin 11:cada08fc8a70 1699 * following parameters: (void *parameter, mbedtls_ssl_context *ssl,
mbedAustin 11:cada08fc8a70 1700 * const unsigned char *hostname, size_t len). If a suitable
mbedAustin 11:cada08fc8a70 1701 * certificate is found, the callback must set the
mbedAustin 11:cada08fc8a70 1702 * certificate(s) and key(s) to use with \c
mbedAustin 11:cada08fc8a70 1703 * mbedtls_ssl_set_hs_own_cert() (can be called repeatedly),
mbedAustin 11:cada08fc8a70 1704 * and may optionally adjust the CA and associated CRL with \c
mbedAustin 11:cada08fc8a70 1705 * mbedtls_ssl_set_hs_ca_chain() as well as the client
mbedAustin 11:cada08fc8a70 1706 * authentication mode with \c mbedtls_ssl_set_hs_authmode(),
mbedAustin 11:cada08fc8a70 1707 * then must return 0. If no matching name is found, the
mbedAustin 11:cada08fc8a70 1708 * callback must either set a default cert, or
mbedAustin 11:cada08fc8a70 1709 * return non-zero to abort the handshake at this point.
mbedAustin 11:cada08fc8a70 1710 *
mbedAustin 11:cada08fc8a70 1711 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1712 * \param f_sni verification function
mbedAustin 11:cada08fc8a70 1713 * \param p_sni verification parameter
mbedAustin 11:cada08fc8a70 1714 */
mbedAustin 11:cada08fc8a70 1715 void mbedtls_ssl_conf_sni( mbedtls_ssl_config *conf,
mbedAustin 11:cada08fc8a70 1716 int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *,
mbedAustin 11:cada08fc8a70 1717 size_t),
mbedAustin 11:cada08fc8a70 1718 void *p_sni );
mbedAustin 11:cada08fc8a70 1719 #endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
mbedAustin 11:cada08fc8a70 1720
mbedAustin 11:cada08fc8a70 1721 #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
mbedAustin 11:cada08fc8a70 1722 /**
mbedAustin 11:cada08fc8a70 1723 * \brief Set the EC J-PAKE password for current handshake.
mbedAustin 11:cada08fc8a70 1724 *
mbedAustin 11:cada08fc8a70 1725 * \note An internal copy is made, and destroyed as soon as the
mbedAustin 11:cada08fc8a70 1726 * handshake is completed, or when the SSL context is reset or
mbedAustin 11:cada08fc8a70 1727 * freed.
mbedAustin 11:cada08fc8a70 1728 *
mbedAustin 11:cada08fc8a70 1729 * \note The SSL context needs to be already set up. The right place
mbedAustin 11:cada08fc8a70 1730 * to call this function is between \c mbedtls_ssl_setup() or
mbedAustin 11:cada08fc8a70 1731 * \c mbedtls_ssl_reset() and \c mbedtls_ssl_handshake().
mbedAustin 11:cada08fc8a70 1732 *
mbedAustin 11:cada08fc8a70 1733 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 1734 * \param pw EC J-PAKE password (pre-shared secret)
mbedAustin 11:cada08fc8a70 1735 * \param pw_len length of pw in bytes
mbedAustin 11:cada08fc8a70 1736 *
mbedAustin 11:cada08fc8a70 1737 * \return 0 on success, or a negative error code.
mbedAustin 11:cada08fc8a70 1738 */
mbedAustin 11:cada08fc8a70 1739 int mbedtls_ssl_set_hs_ecjpake_password( mbedtls_ssl_context *ssl,
mbedAustin 11:cada08fc8a70 1740 const unsigned char *pw,
mbedAustin 11:cada08fc8a70 1741 size_t pw_len );
mbedAustin 11:cada08fc8a70 1742 #endif /*MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
mbedAustin 11:cada08fc8a70 1743
mbedAustin 11:cada08fc8a70 1744 #if defined(MBEDTLS_SSL_ALPN)
mbedAustin 11:cada08fc8a70 1745 /**
mbedAustin 11:cada08fc8a70 1746 * \brief Set the supported Application Layer Protocols.
mbedAustin 11:cada08fc8a70 1747 *
mbedAustin 11:cada08fc8a70 1748 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1749 * \param protos NULL-terminated list of supported protocols,
mbedAustin 11:cada08fc8a70 1750 * in decreasing preference order.
mbedAustin 11:cada08fc8a70 1751 *
mbedAustin 11:cada08fc8a70 1752 * \return 0 on success, or MBEDTLS_ERR_SSL_BAD_INPUT_DATA.
mbedAustin 11:cada08fc8a70 1753 */
mbedAustin 11:cada08fc8a70 1754 int mbedtls_ssl_conf_alpn_protocols( mbedtls_ssl_config *conf, const char **protos );
mbedAustin 11:cada08fc8a70 1755
mbedAustin 11:cada08fc8a70 1756 /**
mbedAustin 11:cada08fc8a70 1757 * \brief Get the name of the negotiated Application Layer Protocol.
mbedAustin 11:cada08fc8a70 1758 * This function should be called after the handshake is
mbedAustin 11:cada08fc8a70 1759 * completed.
mbedAustin 11:cada08fc8a70 1760 *
mbedAustin 11:cada08fc8a70 1761 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 1762 *
mbedAustin 11:cada08fc8a70 1763 * \return Protcol name, or NULL if no protocol was negotiated.
mbedAustin 11:cada08fc8a70 1764 */
mbedAustin 11:cada08fc8a70 1765 const char *mbedtls_ssl_get_alpn_protocol( const mbedtls_ssl_context *ssl );
mbedAustin 11:cada08fc8a70 1766 #endif /* MBEDTLS_SSL_ALPN */
mbedAustin 11:cada08fc8a70 1767
mbedAustin 11:cada08fc8a70 1768 /**
mbedAustin 11:cada08fc8a70 1769 * \brief Set the maximum supported version sent from the client side
mbedAustin 11:cada08fc8a70 1770 * and/or accepted at the server side
mbedAustin 11:cada08fc8a70 1771 * (Default: MBEDTLS_SSL_MAX_MAJOR_VERSION, MBEDTLS_SSL_MAX_MINOR_VERSION)
mbedAustin 11:cada08fc8a70 1772 *
mbedAustin 11:cada08fc8a70 1773 * \note This ignores ciphersuites from higher versions.
mbedAustin 11:cada08fc8a70 1774 *
mbedAustin 11:cada08fc8a70 1775 * \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_2 for DTLS 1.0 and
mbedAustin 11:cada08fc8a70 1776 * MBEDTLS_SSL_MINOR_VERSION_3 for DTLS 1.2
mbedAustin 11:cada08fc8a70 1777 *
mbedAustin 11:cada08fc8a70 1778 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1779 * \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3 supported)
mbedAustin 11:cada08fc8a70 1780 * \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0,
mbedAustin 11:cada08fc8a70 1781 * MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2,
mbedAustin 11:cada08fc8a70 1782 * MBEDTLS_SSL_MINOR_VERSION_3 supported)
mbedAustin 11:cada08fc8a70 1783 */
mbedAustin 11:cada08fc8a70 1784 void mbedtls_ssl_conf_max_version( mbedtls_ssl_config *conf, int major, int minor );
mbedAustin 11:cada08fc8a70 1785
mbedAustin 11:cada08fc8a70 1786 /**
mbedAustin 11:cada08fc8a70 1787 * \brief Set the minimum accepted SSL/TLS protocol version
mbedAustin 11:cada08fc8a70 1788 * (Default: TLS 1.0)
mbedAustin 11:cada08fc8a70 1789 *
mbedAustin 11:cada08fc8a70 1790 * \note Input outside of the SSL_MAX_XXXXX_VERSION and
mbedAustin 11:cada08fc8a70 1791 * SSL_MIN_XXXXX_VERSION range is ignored.
mbedAustin 11:cada08fc8a70 1792 *
mbedAustin 11:cada08fc8a70 1793 * \note MBEDTLS_SSL_MINOR_VERSION_0 (SSL v3) should be avoided.
mbedAustin 11:cada08fc8a70 1794 *
mbedAustin 11:cada08fc8a70 1795 * \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_2 for DTLS 1.0 and
mbedAustin 11:cada08fc8a70 1796 * MBEDTLS_SSL_MINOR_VERSION_3 for DTLS 1.2
mbedAustin 11:cada08fc8a70 1797 *
mbedAustin 11:cada08fc8a70 1798 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1799 * \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3 supported)
mbedAustin 11:cada08fc8a70 1800 * \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0,
mbedAustin 11:cada08fc8a70 1801 * MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2,
mbedAustin 11:cada08fc8a70 1802 * MBEDTLS_SSL_MINOR_VERSION_3 supported)
mbedAustin 11:cada08fc8a70 1803 */
mbedAustin 11:cada08fc8a70 1804 void mbedtls_ssl_conf_min_version( mbedtls_ssl_config *conf, int major, int minor );
mbedAustin 11:cada08fc8a70 1805
mbedAustin 11:cada08fc8a70 1806 #if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C)
mbedAustin 11:cada08fc8a70 1807 /**
mbedAustin 11:cada08fc8a70 1808 * \brief Set the fallback flag (client-side only).
mbedAustin 11:cada08fc8a70 1809 * (Default: MBEDTLS_SSL_IS_NOT_FALLBACK).
mbedAustin 11:cada08fc8a70 1810 *
mbedAustin 11:cada08fc8a70 1811 * \note Set to MBEDTLS_SSL_IS_FALLBACK when preparing a fallback
mbedAustin 11:cada08fc8a70 1812 * connection, that is a connection with max_version set to a
mbedAustin 11:cada08fc8a70 1813 * lower value than the value you're willing to use. Such
mbedAustin 11:cada08fc8a70 1814 * fallback connections are not recommended but are sometimes
mbedAustin 11:cada08fc8a70 1815 * necessary to interoperate with buggy (version-intolerant)
mbedAustin 11:cada08fc8a70 1816 * servers.
mbedAustin 11:cada08fc8a70 1817 *
mbedAustin 11:cada08fc8a70 1818 * \warning You should NOT set this to MBEDTLS_SSL_IS_FALLBACK for
mbedAustin 11:cada08fc8a70 1819 * non-fallback connections! This would appear to work for a
mbedAustin 11:cada08fc8a70 1820 * while, then cause failures when the server is upgraded to
mbedAustin 11:cada08fc8a70 1821 * support a newer TLS version.
mbedAustin 11:cada08fc8a70 1822 *
mbedAustin 11:cada08fc8a70 1823 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1824 * \param fallback MBEDTLS_SSL_IS_NOT_FALLBACK or MBEDTLS_SSL_IS_FALLBACK
mbedAustin 11:cada08fc8a70 1825 */
mbedAustin 11:cada08fc8a70 1826 void mbedtls_ssl_conf_fallback( mbedtls_ssl_config *conf, char fallback );
mbedAustin 11:cada08fc8a70 1827 #endif /* MBEDTLS_SSL_FALLBACK_SCSV && MBEDTLS_SSL_CLI_C */
mbedAustin 11:cada08fc8a70 1828
mbedAustin 11:cada08fc8a70 1829 #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
mbedAustin 11:cada08fc8a70 1830 /**
mbedAustin 11:cada08fc8a70 1831 * \brief Enable or disable Encrypt-then-MAC
mbedAustin 11:cada08fc8a70 1832 * (Default: MBEDTLS_SSL_ETM_ENABLED)
mbedAustin 11:cada08fc8a70 1833 *
mbedAustin 11:cada08fc8a70 1834 * \note This should always be enabled, it is a security
mbedAustin 11:cada08fc8a70 1835 * improvement, and should not cause any interoperability
mbedAustin 11:cada08fc8a70 1836 * issue (used only if the peer supports it too).
mbedAustin 11:cada08fc8a70 1837 *
mbedAustin 11:cada08fc8a70 1838 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1839 * \param etm MBEDTLS_SSL_ETM_ENABLED or MBEDTLS_SSL_ETM_DISABLED
mbedAustin 11:cada08fc8a70 1840 */
mbedAustin 11:cada08fc8a70 1841 void mbedtls_ssl_conf_encrypt_then_mac( mbedtls_ssl_config *conf, char etm );
mbedAustin 11:cada08fc8a70 1842 #endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */
mbedAustin 11:cada08fc8a70 1843
mbedAustin 11:cada08fc8a70 1844 #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
mbedAustin 11:cada08fc8a70 1845 /**
mbedAustin 11:cada08fc8a70 1846 * \brief Enable or disable Extended Master Secret negotiation.
mbedAustin 11:cada08fc8a70 1847 * (Default: MBEDTLS_SSL_EXTENDED_MS_ENABLED)
mbedAustin 11:cada08fc8a70 1848 *
mbedAustin 11:cada08fc8a70 1849 * \note This should always be enabled, it is a security fix to the
mbedAustin 11:cada08fc8a70 1850 * protocol, and should not cause any interoperability issue
mbedAustin 11:cada08fc8a70 1851 * (used only if the peer supports it too).
mbedAustin 11:cada08fc8a70 1852 *
mbedAustin 11:cada08fc8a70 1853 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1854 * \param ems MBEDTLS_SSL_EXTENDED_MS_ENABLED or MBEDTLS_SSL_EXTENDED_MS_DISABLED
mbedAustin 11:cada08fc8a70 1855 */
mbedAustin 11:cada08fc8a70 1856 void mbedtls_ssl_conf_extended_master_secret( mbedtls_ssl_config *conf, char ems );
mbedAustin 11:cada08fc8a70 1857 #endif /* MBEDTLS_SSL_EXTENDED_MASTER_SECRET */
mbedAustin 11:cada08fc8a70 1858
mbedAustin 11:cada08fc8a70 1859 #if defined(MBEDTLS_ARC4_C)
mbedAustin 11:cada08fc8a70 1860 /**
mbedAustin 11:cada08fc8a70 1861 * \brief Disable or enable support for RC4
mbedAustin 11:cada08fc8a70 1862 * (Default: MBEDTLS_SSL_ARC4_DISABLED)
mbedAustin 11:cada08fc8a70 1863 *
mbedAustin 11:cada08fc8a70 1864 * \warning Use of RC4 in (D)TLS has been prohibited by RFC ????
mbedAustin 11:cada08fc8a70 1865 * for security reasons. Use at your own risks.
mbedAustin 11:cada08fc8a70 1866 *
mbedAustin 11:cada08fc8a70 1867 * \note This function will likely be removed in future versions as
mbedAustin 11:cada08fc8a70 1868 * RC4 will then be disabled by default at compile time.
mbedAustin 11:cada08fc8a70 1869 *
mbedAustin 11:cada08fc8a70 1870 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1871 * \param arc4 MBEDTLS_SSL_ARC4_ENABLED or MBEDTLS_SSL_ARC4_DISABLED
mbedAustin 11:cada08fc8a70 1872 */
mbedAustin 11:cada08fc8a70 1873 void mbedtls_ssl_conf_arc4_support( mbedtls_ssl_config *conf, char arc4 );
mbedAustin 11:cada08fc8a70 1874 #endif /* MBEDTLS_ARC4_C */
mbedAustin 11:cada08fc8a70 1875
mbedAustin 11:cada08fc8a70 1876 #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
mbedAustin 11:cada08fc8a70 1877 /**
mbedAustin 11:cada08fc8a70 1878 * \brief Set the maximum fragment length to emit and/or negotiate
mbedAustin 11:cada08fc8a70 1879 * (Default: MBEDTLS_SSL_MAX_CONTENT_LEN, usually 2^14 bytes)
mbedAustin 11:cada08fc8a70 1880 * (Server: set maximum fragment length to emit,
mbedAustin 11:cada08fc8a70 1881 * usually negotiated by the client during handshake
mbedAustin 11:cada08fc8a70 1882 * (Client: set maximum fragment length to emit *and*
mbedAustin 11:cada08fc8a70 1883 * negotiate with the server during handshake)
mbedAustin 11:cada08fc8a70 1884 *
mbedAustin 11:cada08fc8a70 1885 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1886 * \param mfl_code Code for maximum fragment length (allowed values:
mbedAustin 11:cada08fc8a70 1887 * MBEDTLS_SSL_MAX_FRAG_LEN_512, MBEDTLS_SSL_MAX_FRAG_LEN_1024,
mbedAustin 11:cada08fc8a70 1888 * MBEDTLS_SSL_MAX_FRAG_LEN_2048, MBEDTLS_SSL_MAX_FRAG_LEN_4096)
mbedAustin 11:cada08fc8a70 1889 *
mbedAustin 11:cada08fc8a70 1890 * \return 0 if successful or MBEDTLS_ERR_SSL_BAD_INPUT_DATA
mbedAustin 11:cada08fc8a70 1891 */
mbedAustin 11:cada08fc8a70 1892 int mbedtls_ssl_conf_max_frag_len( mbedtls_ssl_config *conf, unsigned char mfl_code );
mbedAustin 11:cada08fc8a70 1893 #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
mbedAustin 11:cada08fc8a70 1894
mbedAustin 11:cada08fc8a70 1895 #if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
mbedAustin 11:cada08fc8a70 1896 /**
mbedAustin 11:cada08fc8a70 1897 * \brief Activate negotiation of truncated HMAC
mbedAustin 11:cada08fc8a70 1898 * (Default: MBEDTLS_SSL_TRUNC_HMAC_DISABLED)
mbedAustin 11:cada08fc8a70 1899 *
mbedAustin 11:cada08fc8a70 1900 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1901 * \param truncate Enable or disable (MBEDTLS_SSL_TRUNC_HMAC_ENABLED or
mbedAustin 11:cada08fc8a70 1902 * MBEDTLS_SSL_TRUNC_HMAC_DISABLED)
mbedAustin 11:cada08fc8a70 1903 */
mbedAustin 11:cada08fc8a70 1904 void mbedtls_ssl_conf_truncated_hmac( mbedtls_ssl_config *conf, int truncate );
mbedAustin 11:cada08fc8a70 1905 #endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
mbedAustin 11:cada08fc8a70 1906
mbedAustin 11:cada08fc8a70 1907 #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
mbedAustin 11:cada08fc8a70 1908 /**
mbedAustin 11:cada08fc8a70 1909 * \brief Enable / Disable 1/n-1 record splitting
mbedAustin 11:cada08fc8a70 1910 * (Default: MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED)
mbedAustin 11:cada08fc8a70 1911 *
mbedAustin 11:cada08fc8a70 1912 * \note Only affects SSLv3 and TLS 1.0, not higher versions.
mbedAustin 11:cada08fc8a70 1913 * Does not affect non-CBC ciphersuites in any version.
mbedAustin 11:cada08fc8a70 1914 *
mbedAustin 11:cada08fc8a70 1915 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1916 * \param split MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED or
mbedAustin 11:cada08fc8a70 1917 * MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED
mbedAustin 11:cada08fc8a70 1918 */
mbedAustin 11:cada08fc8a70 1919 void mbedtls_ssl_conf_cbc_record_splitting( mbedtls_ssl_config *conf, char split );
mbedAustin 11:cada08fc8a70 1920 #endif /* MBEDTLS_SSL_CBC_RECORD_SPLITTING */
mbedAustin 11:cada08fc8a70 1921
mbedAustin 11:cada08fc8a70 1922 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
mbedAustin 11:cada08fc8a70 1923 /**
mbedAustin 11:cada08fc8a70 1924 * \brief Enable / Disable session tickets (client only).
mbedAustin 11:cada08fc8a70 1925 * (Default: MBEDTLS_SSL_SESSION_TICKETS_ENABLED.)
mbedAustin 11:cada08fc8a70 1926 *
mbedAustin 11:cada08fc8a70 1927 * \note On server, use \c mbedtls_ssl_conf_session_tickets_cb().
mbedAustin 11:cada08fc8a70 1928 *
mbedAustin 11:cada08fc8a70 1929 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1930 * \param use_tickets Enable or disable (MBEDTLS_SSL_SESSION_TICKETS_ENABLED or
mbedAustin 11:cada08fc8a70 1931 * MBEDTLS_SSL_SESSION_TICKETS_DISABLED)
mbedAustin 11:cada08fc8a70 1932 */
mbedAustin 11:cada08fc8a70 1933 void mbedtls_ssl_conf_session_tickets( mbedtls_ssl_config *conf, int use_tickets );
mbedAustin 11:cada08fc8a70 1934 #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
mbedAustin 11:cada08fc8a70 1935
mbedAustin 11:cada08fc8a70 1936 #if defined(MBEDTLS_SSL_RENEGOTIATION)
mbedAustin 11:cada08fc8a70 1937 /**
mbedAustin 11:cada08fc8a70 1938 * \brief Enable / Disable renegotiation support for connection when
mbedAustin 11:cada08fc8a70 1939 * initiated by peer
mbedAustin 11:cada08fc8a70 1940 * (Default: MBEDTLS_SSL_RENEGOTIATION_DISABLED)
mbedAustin 11:cada08fc8a70 1941 *
mbedAustin 11:cada08fc8a70 1942 * \warning It is recommended to always disable renegotation unless you
mbedAustin 11:cada08fc8a70 1943 * know you need it and you know what you're doing. In the
mbedAustin 11:cada08fc8a70 1944 * past, there has been several issues associated with
mbedAustin 11:cada08fc8a70 1945 * renegotiation or a poor understanding of its properties.
mbedAustin 11:cada08fc8a70 1946 *
mbedAustin 11:cada08fc8a70 1947 * \note Server-side, enabling renegotiation also makes the server
mbedAustin 11:cada08fc8a70 1948 * susceptible to a resource DoS by a malicious client.
mbedAustin 11:cada08fc8a70 1949 *
mbedAustin 11:cada08fc8a70 1950 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1951 * \param renegotiation Enable or disable (MBEDTLS_SSL_RENEGOTIATION_ENABLED or
mbedAustin 11:cada08fc8a70 1952 * MBEDTLS_SSL_RENEGOTIATION_DISABLED)
mbedAustin 11:cada08fc8a70 1953 */
mbedAustin 11:cada08fc8a70 1954 void mbedtls_ssl_conf_renegotiation( mbedtls_ssl_config *conf, int renegotiation );
mbedAustin 11:cada08fc8a70 1955 #endif /* MBEDTLS_SSL_RENEGOTIATION */
mbedAustin 11:cada08fc8a70 1956
mbedAustin 11:cada08fc8a70 1957 /**
mbedAustin 11:cada08fc8a70 1958 * \brief Prevent or allow legacy renegotiation.
mbedAustin 11:cada08fc8a70 1959 * (Default: MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION)
mbedAustin 11:cada08fc8a70 1960 *
mbedAustin 11:cada08fc8a70 1961 * MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION allows connections to
mbedAustin 11:cada08fc8a70 1962 * be established even if the peer does not support
mbedAustin 11:cada08fc8a70 1963 * secure renegotiation, but does not allow renegotiation
mbedAustin 11:cada08fc8a70 1964 * to take place if not secure.
mbedAustin 11:cada08fc8a70 1965 * (Interoperable and secure option)
mbedAustin 11:cada08fc8a70 1966 *
mbedAustin 11:cada08fc8a70 1967 * MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION allows renegotiations
mbedAustin 11:cada08fc8a70 1968 * with non-upgraded peers. Allowing legacy renegotiation
mbedAustin 11:cada08fc8a70 1969 * makes the connection vulnerable to specific man in the
mbedAustin 11:cada08fc8a70 1970 * middle attacks. (See RFC 5746)
mbedAustin 11:cada08fc8a70 1971 * (Most interoperable and least secure option)
mbedAustin 11:cada08fc8a70 1972 *
mbedAustin 11:cada08fc8a70 1973 * MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE breaks off connections
mbedAustin 11:cada08fc8a70 1974 * if peer does not support secure renegotiation. Results
mbedAustin 11:cada08fc8a70 1975 * in interoperability issues with non-upgraded peers
mbedAustin 11:cada08fc8a70 1976 * that do not support renegotiation altogether.
mbedAustin 11:cada08fc8a70 1977 * (Most secure option, interoperability issues)
mbedAustin 11:cada08fc8a70 1978 *
mbedAustin 11:cada08fc8a70 1979 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 1980 * \param allow_legacy Prevent or allow (SSL_NO_LEGACY_RENEGOTIATION,
mbedAustin 11:cada08fc8a70 1981 * SSL_ALLOW_LEGACY_RENEGOTIATION or
mbedAustin 11:cada08fc8a70 1982 * MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE)
mbedAustin 11:cada08fc8a70 1983 */
mbedAustin 11:cada08fc8a70 1984 void mbedtls_ssl_conf_legacy_renegotiation( mbedtls_ssl_config *conf, int allow_legacy );
mbedAustin 11:cada08fc8a70 1985
mbedAustin 11:cada08fc8a70 1986 #if defined(MBEDTLS_SSL_RENEGOTIATION)
mbedAustin 11:cada08fc8a70 1987 /**
mbedAustin 11:cada08fc8a70 1988 * \brief Enforce renegotiation requests.
mbedAustin 11:cada08fc8a70 1989 * (Default: enforced, max_records = 16)
mbedAustin 11:cada08fc8a70 1990 *
mbedAustin 11:cada08fc8a70 1991 * When we request a renegotiation, the peer can comply or
mbedAustin 11:cada08fc8a70 1992 * ignore the request. This function allows us to decide
mbedAustin 11:cada08fc8a70 1993 * whether to enforce our renegotiation requests by closing
mbedAustin 11:cada08fc8a70 1994 * the connection if the peer doesn't comply.
mbedAustin 11:cada08fc8a70 1995 *
mbedAustin 11:cada08fc8a70 1996 * However, records could already be in transit from the peer
mbedAustin 11:cada08fc8a70 1997 * when the request is emitted. In order to increase
mbedAustin 11:cada08fc8a70 1998 * reliability, we can accept a number of records before the
mbedAustin 11:cada08fc8a70 1999 * expected handshake records.
mbedAustin 11:cada08fc8a70 2000 *
mbedAustin 11:cada08fc8a70 2001 * The optimal value is highly dependent on the specific usage
mbedAustin 11:cada08fc8a70 2002 * scenario.
mbedAustin 11:cada08fc8a70 2003 *
mbedAustin 11:cada08fc8a70 2004 * \note With DTLS and server-initiated renegotiation, the
mbedAustin 11:cada08fc8a70 2005 * HelloRequest is retransmited every time mbedtls_ssl_read() times
mbedAustin 11:cada08fc8a70 2006 * out or receives Application Data, until:
mbedAustin 11:cada08fc8a70 2007 * - max_records records have beens seen, if it is >= 0, or
mbedAustin 11:cada08fc8a70 2008 * - the number of retransmits that would happen during an
mbedAustin 11:cada08fc8a70 2009 * actual handshake has been reached.
mbedAustin 11:cada08fc8a70 2010 * Please remember the request might be lost a few times
mbedAustin 11:cada08fc8a70 2011 * if you consider setting max_records to a really low value.
mbedAustin 11:cada08fc8a70 2012 *
mbedAustin 11:cada08fc8a70 2013 * \warning On client, the grace period can only happen during
mbedAustin 11:cada08fc8a70 2014 * mbedtls_ssl_read(), as opposed to mbedtls_ssl_write() and mbedtls_ssl_renegotiate()
mbedAustin 11:cada08fc8a70 2015 * which always behave as if max_record was 0. The reason is,
mbedAustin 11:cada08fc8a70 2016 * if we receive application data from the server, we need a
mbedAustin 11:cada08fc8a70 2017 * place to write it, which only happens during mbedtls_ssl_read().
mbedAustin 11:cada08fc8a70 2018 *
mbedAustin 11:cada08fc8a70 2019 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 2020 * \param max_records Use MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED if you don't want to
mbedAustin 11:cada08fc8a70 2021 * enforce renegotiation, or a non-negative value to enforce
mbedAustin 11:cada08fc8a70 2022 * it but allow for a grace period of max_records records.
mbedAustin 11:cada08fc8a70 2023 */
mbedAustin 11:cada08fc8a70 2024 void mbedtls_ssl_conf_renegotiation_enforced( mbedtls_ssl_config *conf, int max_records );
mbedAustin 11:cada08fc8a70 2025
mbedAustin 11:cada08fc8a70 2026 /**
mbedAustin 11:cada08fc8a70 2027 * \brief Set record counter threshold for periodic renegotiation.
mbedAustin 11:cada08fc8a70 2028 * (Default: 2^64 - 256.)
mbedAustin 11:cada08fc8a70 2029 *
mbedAustin 11:cada08fc8a70 2030 * Renegotiation is automatically triggered when a record
mbedAustin 11:cada08fc8a70 2031 * counter (outgoing or ingoing) crosses the defined
mbedAustin 11:cada08fc8a70 2032 * threshold. The default value is meant to prevent the
mbedAustin 11:cada08fc8a70 2033 * connection from being closed when the counter is about to
mbedAustin 11:cada08fc8a70 2034 * reached its maximal value (it is not allowed to wrap).
mbedAustin 11:cada08fc8a70 2035 *
mbedAustin 11:cada08fc8a70 2036 * Lower values can be used to enforce policies such as "keys
mbedAustin 11:cada08fc8a70 2037 * must be refreshed every N packets with cipher X".
mbedAustin 11:cada08fc8a70 2038 *
mbedAustin 11:cada08fc8a70 2039 * \param conf SSL configuration
mbedAustin 11:cada08fc8a70 2040 * \param period The threshold value: a big-endian 64-bit number.
mbedAustin 11:cada08fc8a70 2041 * Set to 2^64 - 1 to disable periodic renegotiation
mbedAustin 11:cada08fc8a70 2042 */
mbedAustin 11:cada08fc8a70 2043 void mbedtls_ssl_conf_renegotiation_period( mbedtls_ssl_config *conf,
mbedAustin 11:cada08fc8a70 2044 const unsigned char period[8] );
mbedAustin 11:cada08fc8a70 2045 #endif /* MBEDTLS_SSL_RENEGOTIATION */
mbedAustin 11:cada08fc8a70 2046
mbedAustin 11:cada08fc8a70 2047 /**
mbedAustin 11:cada08fc8a70 2048 * \brief Return the number of data bytes available to read
mbedAustin 11:cada08fc8a70 2049 *
mbedAustin 11:cada08fc8a70 2050 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 2051 *
mbedAustin 11:cada08fc8a70 2052 * \return how many bytes are available in the read buffer
mbedAustin 11:cada08fc8a70 2053 */
mbedAustin 11:cada08fc8a70 2054 size_t mbedtls_ssl_get_bytes_avail( const mbedtls_ssl_context *ssl );
mbedAustin 11:cada08fc8a70 2055
mbedAustin 11:cada08fc8a70 2056 /**
mbedAustin 11:cada08fc8a70 2057 * \brief Return the result of the certificate verification
mbedAustin 11:cada08fc8a70 2058 *
mbedAustin 11:cada08fc8a70 2059 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 2060 *
mbedAustin 11:cada08fc8a70 2061 * \return 0 if successful,
mbedAustin 11:cada08fc8a70 2062 * -1 if result is not available (eg because the handshake was
mbedAustin 11:cada08fc8a70 2063 * aborted too early), or
mbedAustin 11:cada08fc8a70 2064 * a combination of BADCERT_xxx and BADCRL_xxx flags, see
mbedAustin 11:cada08fc8a70 2065 * x509.h
mbedAustin 11:cada08fc8a70 2066 */
mbedAustin 11:cada08fc8a70 2067 uint32_t mbedtls_ssl_get_verify_result( const mbedtls_ssl_context *ssl );
mbedAustin 11:cada08fc8a70 2068
mbedAustin 11:cada08fc8a70 2069 /**
mbedAustin 11:cada08fc8a70 2070 * \brief Return the name of the current ciphersuite
mbedAustin 11:cada08fc8a70 2071 *
mbedAustin 11:cada08fc8a70 2072 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 2073 *
mbedAustin 11:cada08fc8a70 2074 * \return a string containing the ciphersuite name
mbedAustin 11:cada08fc8a70 2075 */
mbedAustin 11:cada08fc8a70 2076 const char *mbedtls_ssl_get_ciphersuite( const mbedtls_ssl_context *ssl );
mbedAustin 11:cada08fc8a70 2077
mbedAustin 11:cada08fc8a70 2078 /**
mbedAustin 11:cada08fc8a70 2079 * \brief Return the current SSL version (SSLv3/TLSv1/etc)
mbedAustin 11:cada08fc8a70 2080 *
mbedAustin 11:cada08fc8a70 2081 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 2082 *
mbedAustin 11:cada08fc8a70 2083 * \return a string containing the SSL version
mbedAustin 11:cada08fc8a70 2084 */
mbedAustin 11:cada08fc8a70 2085 const char *mbedtls_ssl_get_version( const mbedtls_ssl_context *ssl );
mbedAustin 11:cada08fc8a70 2086
mbedAustin 11:cada08fc8a70 2087 /**
mbedAustin 11:cada08fc8a70 2088 * \brief Return the (maximum) number of bytes added by the record
mbedAustin 11:cada08fc8a70 2089 * layer: header + encryption/MAC overhead (inc. padding)
mbedAustin 11:cada08fc8a70 2090 *
mbedAustin 11:cada08fc8a70 2091 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 2092 *
mbedAustin 11:cada08fc8a70 2093 * \return Current maximum record expansion in bytes, or
mbedAustin 11:cada08fc8a70 2094 * MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE if compression is
mbedAustin 11:cada08fc8a70 2095 * enabled, which makes expansion much less predictable
mbedAustin 11:cada08fc8a70 2096 */
mbedAustin 11:cada08fc8a70 2097 int mbedtls_ssl_get_record_expansion( const mbedtls_ssl_context *ssl );
mbedAustin 11:cada08fc8a70 2098
mbedAustin 11:cada08fc8a70 2099 #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
mbedAustin 11:cada08fc8a70 2100 /**
mbedAustin 11:cada08fc8a70 2101 * \brief Return the maximum fragment length (payload, in bytes).
mbedAustin 11:cada08fc8a70 2102 * This is the value negotiated with peer if any,
mbedAustin 11:cada08fc8a70 2103 * or the locally configured value.
mbedAustin 11:cada08fc8a70 2104 *
mbedAustin 11:cada08fc8a70 2105 * \note With DTLS, \c mbedtls_ssl_write() will return an error if
mbedAustin 11:cada08fc8a70 2106 * called with a larger length value.
mbedAustin 11:cada08fc8a70 2107 * With TLS, \c mbedtls_ssl_write() will fragment the input if
mbedAustin 11:cada08fc8a70 2108 * necessary and return the number of bytes written; it is up
mbedAustin 11:cada08fc8a70 2109 * to the caller to call \c mbedtls_ssl_write() again in
mbedAustin 11:cada08fc8a70 2110 * order to send the remaining bytes if any.
mbedAustin 11:cada08fc8a70 2111 *
mbedAustin 11:cada08fc8a70 2112 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 2113 *
mbedAustin 11:cada08fc8a70 2114 * \return Current maximum fragment length.
mbedAustin 11:cada08fc8a70 2115 */
mbedAustin 11:cada08fc8a70 2116 size_t mbedtls_ssl_get_max_frag_len( const mbedtls_ssl_context *ssl );
mbedAustin 11:cada08fc8a70 2117 #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
mbedAustin 11:cada08fc8a70 2118
mbedAustin 11:cada08fc8a70 2119 #if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedAustin 11:cada08fc8a70 2120 /**
mbedAustin 11:cada08fc8a70 2121 * \brief Return the peer certificate from the current connection
mbedAustin 11:cada08fc8a70 2122 *
mbedAustin 11:cada08fc8a70 2123 * Note: Can be NULL in case no certificate was sent during
mbedAustin 11:cada08fc8a70 2124 * the handshake. Different calls for the same connection can
mbedAustin 11:cada08fc8a70 2125 * return the same or different pointers for the same
mbedAustin 11:cada08fc8a70 2126 * certificate and even a different certificate altogether.
mbedAustin 11:cada08fc8a70 2127 * The peer cert CAN change in a single connection if
mbedAustin 11:cada08fc8a70 2128 * renegotiation is performed.
mbedAustin 11:cada08fc8a70 2129 *
mbedAustin 11:cada08fc8a70 2130 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 2131 *
mbedAustin 11:cada08fc8a70 2132 * \return the current peer certificate
mbedAustin 11:cada08fc8a70 2133 */
mbedAustin 11:cada08fc8a70 2134 const mbedtls_x509_crt *mbedtls_ssl_get_peer_cert( const mbedtls_ssl_context *ssl );
mbedAustin 11:cada08fc8a70 2135 #endif /* MBEDTLS_X509_CRT_PARSE_C */
mbedAustin 11:cada08fc8a70 2136
mbedAustin 11:cada08fc8a70 2137 #if defined(MBEDTLS_SSL_CLI_C)
mbedAustin 11:cada08fc8a70 2138 /**
mbedAustin 11:cada08fc8a70 2139 * \brief Save session in order to resume it later (client-side only)
mbedAustin 11:cada08fc8a70 2140 * Session data is copied to presented session structure.
mbedAustin 11:cada08fc8a70 2141 *
mbedAustin 11:cada08fc8a70 2142 * \warning Currently, peer certificate is lost in the operation.
mbedAustin 11:cada08fc8a70 2143 *
mbedAustin 11:cada08fc8a70 2144 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 2145 * \param session session context
mbedAustin 11:cada08fc8a70 2146 *
mbedAustin 11:cada08fc8a70 2147 * \return 0 if successful,
mbedAustin 11:cada08fc8a70 2148 * MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed,
mbedAustin 11:cada08fc8a70 2149 * MBEDTLS_ERR_SSL_BAD_INPUT_DATA if used server-side or
mbedAustin 11:cada08fc8a70 2150 * arguments are otherwise invalid
mbedAustin 11:cada08fc8a70 2151 *
mbedAustin 11:cada08fc8a70 2152 * \sa mbedtls_ssl_set_session()
mbedAustin 11:cada08fc8a70 2153 */
mbedAustin 11:cada08fc8a70 2154 int mbedtls_ssl_get_session( const mbedtls_ssl_context *ssl, mbedtls_ssl_session *session );
mbedAustin 11:cada08fc8a70 2155 #endif /* MBEDTLS_SSL_CLI_C */
mbedAustin 11:cada08fc8a70 2156
mbedAustin 11:cada08fc8a70 2157 /**
mbedAustin 11:cada08fc8a70 2158 * \brief Perform the SSL handshake
mbedAustin 11:cada08fc8a70 2159 *
mbedAustin 11:cada08fc8a70 2160 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 2161 *
mbedAustin 11:cada08fc8a70 2162 * \return 0 if successful, or
mbedAustin 11:cada08fc8a70 2163 * MBEDTLS_ERR_SSL_WANT_READ or MBEDTLS_ERR_SSL_WANT_WRITE, or
mbedAustin 11:cada08fc8a70 2164 * MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED (see below), or
mbedAustin 11:cada08fc8a70 2165 * a specific SSL error code.
mbedAustin 11:cada08fc8a70 2166 *
mbedAustin 11:cada08fc8a70 2167 * \note If this function returns something other than 0 or
mbedAustin 11:cada08fc8a70 2168 * MBEDTLS_ERR_SSL_WANT_READ/WRITE, then the ssl context
mbedAustin 11:cada08fc8a70 2169 * becomes unusable, and you should either free it or call
mbedAustin 11:cada08fc8a70 2170 * \c mbedtls_ssl_session_reset() on it before re-using it.
mbedAustin 11:cada08fc8a70 2171 *
mbedAustin 11:cada08fc8a70 2172 * \note If DTLS is in use, then you may choose to handle
mbedAustin 11:cada08fc8a70 2173 * MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED specially for logging
mbedAustin 11:cada08fc8a70 2174 * purposes, as it is an expected return value rather than an
mbedAustin 11:cada08fc8a70 2175 * actual error, but you still need to reset/free the context.
mbedAustin 11:cada08fc8a70 2176 */
mbedAustin 11:cada08fc8a70 2177 int mbedtls_ssl_handshake( mbedtls_ssl_context *ssl );
mbedAustin 11:cada08fc8a70 2178
mbedAustin 11:cada08fc8a70 2179 /**
mbedAustin 11:cada08fc8a70 2180 * \brief Perform a single step of the SSL handshake
mbedAustin 11:cada08fc8a70 2181 *
mbedAustin 11:cada08fc8a70 2182 * \note The state of the context (ssl->state) will be at
mbedAustin 11:cada08fc8a70 2183 * the following state after execution of this function.
mbedAustin 11:cada08fc8a70 2184 * Do not call this function if state is MBEDTLS_SSL_HANDSHAKE_OVER.
mbedAustin 11:cada08fc8a70 2185 *
mbedAustin 11:cada08fc8a70 2186 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 2187 *
mbedAustin 11:cada08fc8a70 2188 * \return 0 if successful, or
mbedAustin 11:cada08fc8a70 2189 * MBEDTLS_ERR_SSL_WANT_READ or MBEDTLS_ERR_SSL_WANT_WRITE, or
mbedAustin 11:cada08fc8a70 2190 * a specific SSL error code.
mbedAustin 11:cada08fc8a70 2191 */
mbedAustin 11:cada08fc8a70 2192 int mbedtls_ssl_handshake_step( mbedtls_ssl_context *ssl );
mbedAustin 11:cada08fc8a70 2193
mbedAustin 11:cada08fc8a70 2194 #if defined(MBEDTLS_SSL_RENEGOTIATION)
mbedAustin 11:cada08fc8a70 2195 /**
mbedAustin 11:cada08fc8a70 2196 * \brief Initiate an SSL renegotiation on the running connection.
mbedAustin 11:cada08fc8a70 2197 * Client: perform the renegotiation right now.
mbedAustin 11:cada08fc8a70 2198 * Server: request renegotiation, which will be performed
mbedAustin 11:cada08fc8a70 2199 * during the next call to mbedtls_ssl_read() if honored by client.
mbedAustin 11:cada08fc8a70 2200 *
mbedAustin 11:cada08fc8a70 2201 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 2202 *
mbedAustin 11:cada08fc8a70 2203 * \return 0 if successful, or any mbedtls_ssl_handshake() return value.
mbedAustin 11:cada08fc8a70 2204 */
mbedAustin 11:cada08fc8a70 2205 int mbedtls_ssl_renegotiate( mbedtls_ssl_context *ssl );
mbedAustin 11:cada08fc8a70 2206 #endif /* MBEDTLS_SSL_RENEGOTIATION */
mbedAustin 11:cada08fc8a70 2207
mbedAustin 11:cada08fc8a70 2208 /**
mbedAustin 11:cada08fc8a70 2209 * \brief Read at most 'len' application data bytes
mbedAustin 11:cada08fc8a70 2210 *
mbedAustin 11:cada08fc8a70 2211 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 2212 * \param buf buffer that will hold the data
mbedAustin 11:cada08fc8a70 2213 * \param len maximum number of bytes to read
mbedAustin 11:cada08fc8a70 2214 *
mbedAustin 11:cada08fc8a70 2215 * \return the number of bytes read, or
mbedAustin 11:cada08fc8a70 2216 * 0 for EOF, or
mbedAustin 11:cada08fc8a70 2217 * MBEDTLS_ERR_SSL_WANT_READ or MBEDTLS_ERR_SSL_WANT_WRITE, or
mbedAustin 11:cada08fc8a70 2218 * MBEDTLS_ERR_SSL_CLIENT_RECONNECT (see below), or
mbedAustin 11:cada08fc8a70 2219 * another negative error code.
mbedAustin 11:cada08fc8a70 2220 *
mbedAustin 11:cada08fc8a70 2221 * \note When this function return MBEDTLS_ERR_SSL_CLIENT_RECONNECT
mbedAustin 11:cada08fc8a70 2222 * (which can only happen server-side), it means that a client
mbedAustin 11:cada08fc8a70 2223 * is initiating a new connection using the same source port.
mbedAustin 11:cada08fc8a70 2224 * You can either treat that as a connection close and wait
mbedAustin 11:cada08fc8a70 2225 * for the client to resend a ClientHello, or directly
mbedAustin 11:cada08fc8a70 2226 * continue with \c mbedtls_ssl_handshake() with the same
mbedAustin 11:cada08fc8a70 2227 * context (as it has beeen reset internally). Either way, you
mbedAustin 11:cada08fc8a70 2228 * should make sure this is seen by the application as a new
mbedAustin 11:cada08fc8a70 2229 * connection: application state, if any, should be reset, and
mbedAustin 11:cada08fc8a70 2230 * most importantly the identity of the client must be checked
mbedAustin 11:cada08fc8a70 2231 * again. WARNING: not validating the identity of the client
mbedAustin 11:cada08fc8a70 2232 * again, or not transmitting the new identity to the
mbedAustin 11:cada08fc8a70 2233 * application layer, would allow authentication bypass!
mbedAustin 11:cada08fc8a70 2234 */
mbedAustin 11:cada08fc8a70 2235 int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len );
mbedAustin 11:cada08fc8a70 2236
mbedAustin 11:cada08fc8a70 2237 /**
mbedAustin 11:cada08fc8a70 2238 * \brief Try to write exactly 'len' application data bytes
mbedAustin 11:cada08fc8a70 2239 *
mbedAustin 11:cada08fc8a70 2240 * \warning This function will do partial writes in some cases. If the
mbedAustin 11:cada08fc8a70 2241 * return value is non-negative but less than length, the
mbedAustin 11:cada08fc8a70 2242 * function must be called again with updated arguments:
mbedAustin 11:cada08fc8a70 2243 * buf + ret, len - ret (if ret is the return value) until
mbedAustin 11:cada08fc8a70 2244 * it returns a value equal to the last 'len' argument.
mbedAustin 11:cada08fc8a70 2245 *
mbedAustin 11:cada08fc8a70 2246 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 2247 * \param buf buffer holding the data
mbedAustin 11:cada08fc8a70 2248 * \param len how many bytes must be written
mbedAustin 11:cada08fc8a70 2249 *
mbedAustin 11:cada08fc8a70 2250 * \return the number of bytes actually written (may be less than len),
mbedAustin 11:cada08fc8a70 2251 * or MBEDTLS_ERR_SSL_WANT_WRITE of MBEDTLS_ERR_SSL_WANT_READ,
mbedAustin 11:cada08fc8a70 2252 * or another negative error code.
mbedAustin 11:cada08fc8a70 2253 *
mbedAustin 11:cada08fc8a70 2254 * \note When this function returns MBEDTLS_ERR_SSL_WANT_WRITE/READ,
mbedAustin 11:cada08fc8a70 2255 * it must be called later with the *same* arguments,
mbedAustin 11:cada08fc8a70 2256 * until it returns a positive value.
mbedAustin 11:cada08fc8a70 2257 *
mbedAustin 11:cada08fc8a70 2258 * \note If the requested length is greater than the maximum
mbedAustin 11:cada08fc8a70 2259 * fragment length (either the built-in limit or the one set
mbedAustin 11:cada08fc8a70 2260 * or negotiated with the peer), then:
mbedAustin 11:cada08fc8a70 2261 * - with TLS, less bytes than requested are written.
mbedAustin 11:cada08fc8a70 2262 * - with DTLS, MBEDTLS_ERR_SSL_BAD_INPUT_DATA is returned.
mbedAustin 11:cada08fc8a70 2263 * \c mbedtls_ssl_get_max_frag_len() may be used to query the
mbedAustin 11:cada08fc8a70 2264 * active maximum fragment length.
mbedAustin 11:cada08fc8a70 2265 */
mbedAustin 11:cada08fc8a70 2266 int mbedtls_ssl_write( mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len );
mbedAustin 11:cada08fc8a70 2267
mbedAustin 11:cada08fc8a70 2268 /**
mbedAustin 11:cada08fc8a70 2269 * \brief Send an alert message
mbedAustin 11:cada08fc8a70 2270 *
mbedAustin 11:cada08fc8a70 2271 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 2272 * \param level The alert level of the message
mbedAustin 11:cada08fc8a70 2273 * (MBEDTLS_SSL_ALERT_LEVEL_WARNING or MBEDTLS_SSL_ALERT_LEVEL_FATAL)
mbedAustin 11:cada08fc8a70 2274 * \param message The alert message (SSL_ALERT_MSG_*)
mbedAustin 11:cada08fc8a70 2275 *
mbedAustin 11:cada08fc8a70 2276 * \return 0 if successful, or a specific SSL error code.
mbedAustin 11:cada08fc8a70 2277 */
mbedAustin 11:cada08fc8a70 2278 int mbedtls_ssl_send_alert_message( mbedtls_ssl_context *ssl,
mbedAustin 11:cada08fc8a70 2279 unsigned char level,
mbedAustin 11:cada08fc8a70 2280 unsigned char message );
mbedAustin 11:cada08fc8a70 2281 /**
mbedAustin 11:cada08fc8a70 2282 * \brief Notify the peer that the connection is being closed
mbedAustin 11:cada08fc8a70 2283 *
mbedAustin 11:cada08fc8a70 2284 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 2285 */
mbedAustin 11:cada08fc8a70 2286 int mbedtls_ssl_close_notify( mbedtls_ssl_context *ssl );
mbedAustin 11:cada08fc8a70 2287
mbedAustin 11:cada08fc8a70 2288 /**
mbedAustin 11:cada08fc8a70 2289 * \brief Free referenced items in an SSL context and clear memory
mbedAustin 11:cada08fc8a70 2290 *
mbedAustin 11:cada08fc8a70 2291 * \param ssl SSL context
mbedAustin 11:cada08fc8a70 2292 */
mbedAustin 11:cada08fc8a70 2293 void mbedtls_ssl_free( mbedtls_ssl_context *ssl );
mbedAustin 11:cada08fc8a70 2294
mbedAustin 11:cada08fc8a70 2295 /**
mbedAustin 11:cada08fc8a70 2296 * \brief Initialize an SSL configuration context
mbedAustin 11:cada08fc8a70 2297 * Just makes the context ready for
mbedAustin 11:cada08fc8a70 2298 * mbedtls_ssl_config_defaults() or mbedtls_ssl_config_free().
mbedAustin 11:cada08fc8a70 2299 *
mbedAustin 11:cada08fc8a70 2300 * \note You need to call mbedtls_ssl_config_defaults() unless you
mbedAustin 11:cada08fc8a70 2301 * manually set all of the relevent fields yourself.
mbedAustin 11:cada08fc8a70 2302 *
mbedAustin 11:cada08fc8a70 2303 * \param conf SSL configuration context
mbedAustin 11:cada08fc8a70 2304 */
mbedAustin 11:cada08fc8a70 2305 void mbedtls_ssl_config_init( mbedtls_ssl_config *conf );
mbedAustin 11:cada08fc8a70 2306
mbedAustin 11:cada08fc8a70 2307 /**
mbedAustin 11:cada08fc8a70 2308 * \brief Load reasonnable default SSL configuration values.
mbedAustin 11:cada08fc8a70 2309 * (You need to call mbedtls_ssl_config_init() first.)
mbedAustin 11:cada08fc8a70 2310 *
mbedAustin 11:cada08fc8a70 2311 * \param conf SSL configuration context
mbedAustin 11:cada08fc8a70 2312 * \param endpoint MBEDTLS_SSL_IS_CLIENT or MBEDTLS_SSL_IS_SERVER
mbedAustin 11:cada08fc8a70 2313 * \param transport MBEDTLS_SSL_TRANSPORT_STREAM for TLS, or
mbedAustin 11:cada08fc8a70 2314 * MBEDTLS_SSL_TRANSPORT_DATAGRAM for DTLS
mbedAustin 11:cada08fc8a70 2315 * \param preset a MBEDTLS_SSL_PRESET_XXX value
mbedAustin 11:cada08fc8a70 2316 * (currently unused).
mbedAustin 11:cada08fc8a70 2317 *
mbedAustin 11:cada08fc8a70 2318 * \note See \c mbedtls_ssl_conf_transport() for notes on DTLS.
mbedAustin 11:cada08fc8a70 2319 *
mbedAustin 11:cada08fc8a70 2320 * \return 0 if successful, or
mbedAustin 11:cada08fc8a70 2321 * MBEDTLS_ERR_XXX_ALLOC_FAILED on memory allocation error.
mbedAustin 11:cada08fc8a70 2322 */
mbedAustin 11:cada08fc8a70 2323 int mbedtls_ssl_config_defaults( mbedtls_ssl_config *conf,
mbedAustin 11:cada08fc8a70 2324 int endpoint, int transport, int preset );
mbedAustin 11:cada08fc8a70 2325
mbedAustin 11:cada08fc8a70 2326 /**
mbedAustin 11:cada08fc8a70 2327 * \brief Free an SSL configuration context
mbedAustin 11:cada08fc8a70 2328 *
mbedAustin 11:cada08fc8a70 2329 * \param conf SSL configuration context
mbedAustin 11:cada08fc8a70 2330 */
mbedAustin 11:cada08fc8a70 2331 void mbedtls_ssl_config_free( mbedtls_ssl_config *conf );
mbedAustin 11:cada08fc8a70 2332
mbedAustin 11:cada08fc8a70 2333 /**
mbedAustin 11:cada08fc8a70 2334 * \brief Initialize SSL session structure
mbedAustin 11:cada08fc8a70 2335 *
mbedAustin 11:cada08fc8a70 2336 * \param session SSL session
mbedAustin 11:cada08fc8a70 2337 */
mbedAustin 11:cada08fc8a70 2338 void mbedtls_ssl_session_init( mbedtls_ssl_session *session );
mbedAustin 11:cada08fc8a70 2339
mbedAustin 11:cada08fc8a70 2340 /**
mbedAustin 11:cada08fc8a70 2341 * \brief Free referenced items in an SSL session including the
mbedAustin 11:cada08fc8a70 2342 * peer certificate and clear memory
mbedAustin 11:cada08fc8a70 2343 *
mbedAustin 11:cada08fc8a70 2344 * \param session SSL session
mbedAustin 11:cada08fc8a70 2345 */
mbedAustin 11:cada08fc8a70 2346 void mbedtls_ssl_session_free( mbedtls_ssl_session *session );
mbedAustin 11:cada08fc8a70 2347
mbedAustin 11:cada08fc8a70 2348 #ifdef __cplusplus
mbedAustin 11:cada08fc8a70 2349 }
mbedAustin 11:cada08fc8a70 2350 #endif
mbedAustin 11:cada08fc8a70 2351
mbedAustin 11:cada08fc8a70 2352 #endif /* ssl.h */