|
1 | | -/* |
2 | | - * This file is part of the MicroPython project, http://micropython.org/ |
3 | | - * |
4 | | - * The MIT License (MIT) |
5 | | - * |
6 | | - * Copyright (c) 2018-2019 Damien P. George |
7 | | - * |
8 | | - * Permission is hereby granted, free of charge, to any person obtaining a copy |
9 | | - * of this software and associated documentation files (the "Software"), to deal |
10 | | - * in the Software without restriction, including without limitation the rights |
11 | | - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
12 | | - * copies of the Software, and to permit persons to whom the Software is |
13 | | - * furnished to do so, subject to the following conditions: |
14 | | - * |
15 | | - * The above copyright notice and this permission notice shall be included in |
16 | | - * all copies or substantial portions of the Software. |
17 | | - * |
18 | | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
19 | | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
20 | | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
21 | | - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
22 | | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
23 | | - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
24 | | - * THE SOFTWARE. |
25 | | - */ |
26 | | -#ifndef MICROPY_INCLUDED_MBEDTLS_CONFIG_H |
27 | | -#define MICROPY_INCLUDED_MBEDTLS_CONFIG_H |
28 | | - |
29 | | -// If you want to debug MBEDTLS uncomment the following and |
30 | | -// Pass 3 to mbedtls_debug_set_threshold in socket_new |
| 1 | +// This file is part of the CircuitPython project: https://circuitpython.org |
| 2 | +// |
| 3 | +// SPDX-FileCopyrightText: Copyright (c) 2018-2019 Damien P. George |
| 4 | +// SPDX-FileCopyrightText: Copyright (c) 2026 Dan Halbert for Adafruit Industries |
| 5 | +// |
| 6 | +// SPDX-License-Identifier: MIT |
| 7 | + |
| 8 | +// mbedtls TLS and X.509 configuration, selected with MBEDTLS_CONFIG_FILE. |
| 9 | +// |
| 10 | +// As of mbedtls 4.0 this file covers only TLS and X.509. Everything cryptographic -- |
| 11 | +// algorithms, key types, the platform hooks and the RNG -- is configured in |
| 12 | +// tf_psa_crypto_config.h next to this file, and selected with |
| 13 | +// TF_PSA_CRYPTO_CONFIG_FILE. |
| 14 | + |
| 15 | +#pragma once |
| 16 | + |
| 17 | +// If you want to debug mbedtls, uncomment the following. SSLSocket.c raises the debug |
| 18 | +// threshold to 4 when it is set. |
31 | 19 | // #define MBEDTLS_DEBUG_C |
32 | 20 |
|
33 | | -// Set mbedtls configuration |
34 | | -#define MBEDTLS_PLATFORM_MEMORY |
35 | | -#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS |
36 | | -#define MBEDTLS_DEPRECATED_REMOVED |
37 | | -#define MBEDTLS_ENTROPY_HARDWARE_ALT |
38 | | -#define MBEDTLS_AES_ROM_TABLES |
39 | | -#define MBEDTLS_CIPHER_MODE_CBC |
40 | | -#define MBEDTLS_ECP_DP_SECP192R1_ENABLED |
41 | | -#define MBEDTLS_ECP_DP_SECP224R1_ENABLED |
42 | | -#define MBEDTLS_ECP_DP_SECP256R1_ENABLED |
43 | | -#define MBEDTLS_ECP_DP_SECP384R1_ENABLED |
44 | | -#define MBEDTLS_ECP_DP_SECP521R1_ENABLED |
45 | | -#define MBEDTLS_ECP_DP_SECP192K1_ENABLED |
46 | | -#define MBEDTLS_ECP_DP_SECP224K1_ENABLED |
47 | | -#define MBEDTLS_ECP_DP_SECP256K1_ENABLED |
48 | | -#define MBEDTLS_ECP_DP_BP256R1_ENABLED |
49 | | -#define MBEDTLS_ECP_DP_BP384R1_ENABLED |
50 | | -#define MBEDTLS_ECP_DP_BP512R1_ENABLED |
51 | | -#define MBEDTLS_ECP_DP_CURVE25519_ENABLED |
52 | | -#define MBEDTLS_ECP_NIST_OPTIM |
53 | | -#define MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED |
54 | | -#define MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED |
55 | | -#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED |
56 | | -#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED |
57 | | -#define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED |
58 | | -#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED |
59 | | -#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED |
60 | | -#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED |
61 | | -#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED |
62 | | -#define MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED |
63 | | -#define MBEDTLS_NO_PLATFORM_ENTROPY |
64 | | -#define MBEDTLS_PKCS1_V15 |
65 | | -#define MBEDTLS_SHA256_SMALLER |
66 | | -#define MBEDTLS_SSL_PROTO_TLS1 |
67 | | -#define MBEDTLS_SSL_PROTO_TLS1_1 |
| 21 | +// Protocol versions |
| 22 | + |
| 23 | +// TLS 1.0 and 1.1 were removed in mbedtls 3.0, and were obsolete long before that. |
| 24 | +// |
| 25 | +// TLS 1.3 is available in 4.x but is turned off, to match espressif |
| 26 | +// It also cost 25648 bytes on Pico W, which has only ~50 KB of firmware |
| 27 | +// space left. Enabling it here would also require enabling |
| 28 | +// MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED, and PSA_WANT_ALG_HKDF* in |
| 29 | +// tf_psa_crypto_config.h for the 1.3 key schedule. |
68 | 30 | #define MBEDTLS_SSL_PROTO_TLS1_2 |
| 31 | + |
| 32 | +// DTLS is deliberately off: common_hal_ssl_sslcontext_wrap_socket() rejects anything |
| 33 | +// that is not SOCKETPOOL_SOCK_STREAM, so it could never be reached. |
| 34 | + |
| 35 | +#define MBEDTLS_SSL_CLI_C |
| 36 | +#define MBEDTLS_SSL_SRV_C |
| 37 | +#define MBEDTLS_SSL_TLS_C |
| 38 | + |
| 39 | +// Key exchanges. Without at least one of these there are no TLS 1.2 ciphersuites at |
| 40 | +// all, the ClientHello offers nothing, and the server answers with a fatal |
| 41 | +// handshake_failure alert. These two are what espressif enables |
| 42 | +// (CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_{RSA,ECDSA}) and cover the public web. The PSK |
| 43 | +// and ECJPAKE exchanges that 4.x also still offers are not reachable from the ssl |
| 44 | +// module, and the static-RSA and DHE exchanges the mbedtls 2.28 config enabled are |
| 45 | +// gone from 4.x upstream. |
| 46 | +#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED |
| 47 | +#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED |
| 48 | + |
| 49 | +// Extensions |
| 50 | + |
69 | 51 | #define MBEDTLS_SSL_SERVER_NAME_INDICATION |
| 52 | +#define MBEDTLS_SSL_KEEP_PEER_CERTIFICATE |
| 53 | +#define MBEDTLS_SSL_ENCRYPT_THEN_MAC |
| 54 | +#define MBEDTLS_SSL_EXTENDED_MASTER_SECRET |
| 55 | + |
| 56 | +// Buffers |
70 | 57 |
|
71 | | -// Use a smaller output buffer to reduce size of SSL context |
| 58 | +// Accept a full-size record inbound, since we do not control what the peer sends, |
| 59 | +// but use a smaller outbound buffer to reduce the SSL context size. |
72 | 60 | #define MBEDTLS_SSL_MAX_CONTENT_LEN (16384) |
73 | 61 | #define MBEDTLS_SSL_IN_CONTENT_LEN (MBEDTLS_SSL_MAX_CONTENT_LEN) |
74 | 62 | #define MBEDTLS_SSL_OUT_CONTENT_LEN (4096) |
75 | 63 |
|
76 | | -// Enable mbedtls modules |
77 | | -#define MBEDTLS_AES_C |
78 | | -#define MBEDTLS_ASN1_PARSE_C |
79 | | -#define MBEDTLS_ASN1_WRITE_C |
80 | | -#define MBEDTLS_BASE64_C |
81 | | -#define MBEDTLS_BIGNUM_C |
82 | | -#define MBEDTLS_CIPHER_C |
83 | | -#define MBEDTLS_CTR_DRBG_C |
84 | | -#define MBEDTLS_ECDH_C |
85 | | -#define MBEDTLS_ECDSA_C |
86 | | -#define MBEDTLS_ECP_C |
87 | | -#define MBEDTLS_ENTROPY_C |
88 | | -#define MBEDTLS_ERROR_C |
89 | | -#define MBEDTLS_GCM_C |
90 | | -#define MBEDTLS_MD_C |
91 | | -#define MBEDTLS_MD5_C |
92 | | -#define MBEDTLS_OID_C |
93 | | -#define MBEDTLS_PKCS5_C |
94 | | -#define MBEDTLS_PEM_PARSE_C |
95 | | -#define MBEDTLS_PK_C |
96 | | -#define MBEDTLS_PK_HAVE_ECC_KEYS |
97 | | -#define MBEDTLS_PK_PARSE_C |
98 | | -#define MBEDTLS_PLATFORM_C |
99 | | -#define MBEDTLS_RSA_C |
100 | | -#define MBEDTLS_SHA1_C |
101 | | -#define MBEDTLS_SHA256_C |
102 | | -#define MBEDTLS_SHA512_C |
103 | | -#define MBEDTLS_SSL_CLI_C |
104 | | -#define MBEDTLS_SSL_PROTO_DTLS |
105 | | -#define MBEDTLS_SSL_SRV_C |
106 | | -#define MBEDTLS_SSL_TLS_C |
107 | | -#define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE |
108 | | -#define MBEDTLS_X509_CRT_PARSE_C |
| 64 | +// X.509 |
| 65 | + |
109 | 66 | #define MBEDTLS_X509_USE_C |
110 | | -#define MBEDTLS_HAVE_TIME |
111 | | -#define MBEDTLS_DHM_C // needed by DHE_PSK |
112 | | -#undef MBEDTLS_HAVE_TIME_DATE |
113 | | - |
114 | | -// Memory allocation hooks |
115 | | -#include <stdlib.h> |
116 | | -#include <stdio.h> |
117 | | -void *m_tracked_calloc(size_t nmemb, size_t size); |
118 | | -void m_tracked_free(void *ptr); |
119 | | -#define MBEDTLS_PLATFORM_STD_CALLOC m_tracked_calloc |
120 | | -#define MBEDTLS_PLATFORM_STD_FREE m_tracked_free |
121 | | -#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf |
122 | | - |
123 | | -// Time hook |
124 | | -#include <time.h> |
125 | | -time_t rp2_rtctime_seconds(time_t *timer); |
126 | | -#define MBEDTLS_PLATFORM_TIME_MACRO rp2_rtctime_seconds |
127 | | - |
128 | | -#include "mbedtls/check_config.h" |
129 | | - |
130 | | -#endif /* MICROPY_INCLUDED_MBEDTLS_CONFIG_H */ |
| 67 | +#define MBEDTLS_X509_CRT_PARSE_C |
| 68 | +#define MBEDTLS_X509_RSASSA_PSS_SUPPORT |
| 69 | + |
| 70 | +// MBEDTLS_HAVE_TIME_DATE is deliberately left off, so certificate notBefore/notAfter |
| 71 | +// are not checked (see the BADCERT_EXPIRED/BADCERT_FUTURE tests in x509_crt.c, which |
| 72 | +// are compiled out without it). CircuitPython does not know the wall clock time unless |
| 73 | +// the program sets it explicitly, which often does not happen; with an unset clock, |
| 74 | +// checking the dates would reject valid certificates rather than catch expired ones. |
| 75 | +// espressif does not set CONFIG_MBEDTLS_HAVE_TIME_DATE either. |
| 76 | +// |
| 77 | +// Nothing else we enable consumes time -- no session tickets, no context |
| 78 | +// serialization, no DTLS, no TLS 1.3 -- so MBEDTLS_HAVE_TIME is off as well, and |
| 79 | +// mbedtls_port.c needs neither a wall clock nor mbedtls_ms_time(). |
| 80 | + |
| 81 | +// Error strings |
| 82 | + |
| 83 | +// SSLSocket.c keys off MBEDTLS_ERROR_C to decide whether to put a message on the |
| 84 | +// OSError it raises. mbedtls's own error.c is not built; lib/mbedtls_errors supplies |
| 85 | +// a smaller mbedtls_strerror() instead. |
| 86 | +#define MBEDTLS_ERROR_C |
| 87 | + |
| 88 | +// Sanity checks |
| 89 | +// |
| 90 | +// mbedtls's own mbedtls_check_config.h only validates the prerequisites of options |
| 91 | +// that are enabled, so it says nothing when a whole category is missing. This is where |
| 92 | +// TF_PSA_CRYPTO_CONFIG_FILE replacing psa/crypto_config.h rather than overlaying it |
| 93 | +// bites: every default we rely on has to be restated here, and forgetting one produces |
| 94 | +// a build that compiles and links but cannot complete a handshake. |
| 95 | +#if !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) && \ |
| 96 | + !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) && \ |
| 97 | + !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) && \ |
| 98 | + !defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) && \ |
| 99 | + !defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) |
| 100 | +#error "No MBEDTLS_KEY_EXCHANGE_* enabled: ciphersuite_definitions[] would be empty, " \ |
| 101 | + "so the ClientHello would offer nothing and every TLS 1.2 handshake would fail." |
| 102 | +#endif |
0 commit comments