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