Skip to content

Commit 521dbc6

Browse files
committed
Merge remote-tracking branch 'tls/development' into development
Merge Mbed TLS at f790a6c into Mbed Crypto. Resolve conflicts by performing the following: - Reject changes to README.md - Don't add crypto as a submodule - Remove test/ssl_cert_test from programs/Makefile - Add cipher.nist_kw test to tests/CMakeLists.txt - Reject removal of crypto-specific all.sh tests - Reject update to SSL-specific portion of component_test_valgrind in all.sh - Reject addition of ssl-opt.sh testing to component_test_m32_o1 in all.sh * tls/development: (87 commits) Call mbedtls_cipher_free() to reset a cipher context Don't call mbedtls_cipher_setkey twice Update crypto submodule Minor fixes in get certificate policies oid test Add certificate policy oid x509 extension cpp_dummy_build: Add missing header psa_util.h Clarify comment mangled by an earlier refactoring Add an "out-of-box" component Run ssl-opt.sh on 32-bit runtime Don't use debug level 1 for informational messages Skip uncritical unsupported extensions Give credit to OSS-Fuzz for #2404 all.sh: remove component_test_new_ecdh_context Remove crypto-only related components from all.sh Remove ssl_cert_test sample app Make CRT callback tests more robust Rename constant in client2.c Document and test flags in x509_verify Fix style issues and a typo Fix a rebase error ...
2 parents 125a1e9 + f790a6c commit 521dbc6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1560
-1191
lines changed

.pylint

Lines changed: 0 additions & 425 deletions
This file was deleted.

.pylintrc

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[BASIC]
2+
# We're ok with short funtion argument names.
3+
# [invalid-name]
4+
argument-rgx=[a-z_][a-z0-9_]*$
5+
6+
# Allow filter and map.
7+
# [bad-builtin]
8+
bad-functions=input
9+
10+
# We prefer docstrings, but we don't require them on all functions.
11+
# Require them only on long functions (for some value of long).
12+
# [missing-docstring]
13+
docstring-min-length=10
14+
15+
# Allow longer methods than the default.
16+
# [invalid-name]
17+
method-rgx=[a-z_][a-z0-9_]{2,35}$
18+
19+
# Allow module names containing a dash (but no underscore or uppercase letter).
20+
# They are whole programs, not meant to be included by another module.
21+
# [invalid-name]
22+
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+)|[a-z][-0-9a-z]+)$
23+
24+
# Some functions don't need docstrings.
25+
# [missing-docstring]
26+
no-docstring-rgx=(run_)?main$
27+
28+
# We're ok with short local or global variable names.
29+
# [invalid-name]
30+
variable-rgx=[a-z_][a-z0-9_]*$
31+
32+
[DESIGN]
33+
# Allow more than the default 7 attributes.
34+
# [too-many-instance-attributes]
35+
max-attributes=15
36+
37+
[FORMAT]
38+
# Allow longer modules than the default recommended maximum.
39+
# [too-many-lines]
40+
max-module-lines=2000
41+
42+
[MESSAGES CONTROL]
43+
disable=
44+
45+
[REPORTS]
46+
# Don't diplay statistics. Just the facts.
47+
reports=no
48+
49+
[VARIABLES]
50+
# Allow unused variables if their name starts with an underscore.
51+
# [unused-argument]
52+
dummy-variables-rgx=_.*

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ script:
2626
- tests/scripts/curves.pl
2727
env:
2828
global:
29-
secure: "barHldniAfXyoWOD/vcO+E6/Xm4fmcaUoC9BeKW+LwsHqlDMLvugaJnmLXkSpkbYhVL61Hzf3bo0KPJn88AFc5Rkf8oYHPjH4adMnVXkf3B9ghHCgznqHsAH3choo6tnPxaFgOwOYmLGb382nQxfE5lUdvnM/W/psQjWt66A1+k="
29+
- SEED=1
30+
- secure: "barHldniAfXyoWOD/vcO+E6/Xm4fmcaUoC9BeKW+LwsHqlDMLvugaJnmLXkSpkbYhVL61Hzf3bo0KPJn88AFc5Rkf8oYHPjH4adMnVXkf3B9ghHCgznqHsAH3choo6tnPxaFgOwOYmLGb382nQxfE5lUdvnM/W/psQjWt66A1+k="
3031

3132
addons:
3233
apt:

ChangeLog

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,28 @@ mbed TLS ChangeLog (Sorted per branch, date)
55
Features
66
* Add the Any Policy certificate policy oid, as defined in
77
rfc 5280 section 4.2.1.4.
8+
* It is now possible to use NIST key wrap mode via the mbedtls_cipher API.
9+
Contributed by Jack Lloyd and Fortanix Inc.
10+
* Add the Wi-SUN Field Area Network (FAN) device extended key usage.
11+
* Add the oid certificate policy x509 extension.
812

913
Bugfix
1014
* Fix private key DER output in the key_app_writer example. File contents
1115
were shifted by one byte, creating an invalid ASN.1 tag. Fixed by
1216
Christian Walther in #2239.
17+
* Fix potential memory leak in X.509 self test. Found and fixed by
18+
Junhwan Park, #2106.
19+
* Reduce stack usage of hkdf tests. Fixes #2195.
20+
* Fix 1-byte buffer overflow in mbedtls_mpi_write_string() when
21+
used with negative inputs. Found by Guido Vranken in #2404. Credit to
22+
OSS-Fuzz.
23+
* Fix bugs in the AEAD test suite which would be exposed by ciphers which
24+
either used both encrypt and decrypt key schedules, or which perform padding.
25+
GCM and CCM were not affected. Fixed by Jack Lloyd.
26+
* Fix incorrect default port number in ssl_mail_client example's usage.
27+
Found and fixed by irwir. #2337
28+
* Add psa_util.h to test/cpp_dummy_build to fix build_default_make_gcc_and_cxx.
29+
Fixed by Peter Kolbus (Garmin). #2579
1330

1431
Changes
1532
* Server's RSA certificate in certs.c was SHA-1 signed. In the default

circle.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

include/mbedtls/cipher.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ typedef enum {
176176
MBEDTLS_CIPHER_AES_256_XTS, /**< AES 256-bit cipher in XTS block mode. */
177177
MBEDTLS_CIPHER_CHACHA20, /**< ChaCha20 stream cipher. */
178178
MBEDTLS_CIPHER_CHACHA20_POLY1305, /**< ChaCha20-Poly1305 AEAD cipher. */
179+
MBEDTLS_CIPHER_AES_128_KW, /**< AES cipher with 128-bit NIST KW mode. */
180+
MBEDTLS_CIPHER_AES_192_KW, /**< AES cipher with 192-bit NIST KW mode. */
181+
MBEDTLS_CIPHER_AES_256_KW, /**< AES cipher with 256-bit NIST KW mode. */
182+
MBEDTLS_CIPHER_AES_128_KWP, /**< AES cipher with 128-bit NIST KWP mode. */
183+
MBEDTLS_CIPHER_AES_192_KWP, /**< AES cipher with 192-bit NIST KWP mode. */
184+
MBEDTLS_CIPHER_AES_256_KWP, /**< AES cipher with 256-bit NIST KWP mode. */
179185
} mbedtls_cipher_type_t;
180186

181187
/** Supported cipher modes. */
@@ -191,6 +197,8 @@ typedef enum {
191197
MBEDTLS_MODE_CCM, /**< The CCM cipher mode. */
192198
MBEDTLS_MODE_XTS, /**< The XTS cipher mode. */
193199
MBEDTLS_MODE_CHACHAPOLY, /**< The ChaCha-Poly cipher mode. */
200+
MBEDTLS_MODE_KW, /**< The SP800-38F KW mode */
201+
MBEDTLS_MODE_KWP, /**< The SP800-38F KWP mode */
194202
} mbedtls_cipher_mode_t;
195203

196204
/** Supported cipher padding types. */

include/mbedtls/config.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,25 @@
17911791
*/
17921792
//#define MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
17931793

1794+
/**
1795+
* \def MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
1796+
*
1797+
* If set, this enables the X.509 API `mbedtls_x509_crt_verify_with_ca_cb()`
1798+
* and the SSL API `mbedtls_ssl_conf_ca_cb()` which allow users to configure
1799+
* the set of trusted certificates through a callback instead of a linked
1800+
* list.
1801+
*
1802+
* This is useful for example in environments where a large number of trusted
1803+
* certificates is present and storing them in a linked list isn't efficient
1804+
* enough, or when the set of trusted certificates changes frequently.
1805+
*
1806+
* See the documentation of `mbedtls_x509_crt_verify_with_ca_cb()` and
1807+
* `mbedtls_ssl_conf_ca_cb()` for more information.
1808+
*
1809+
* Uncomment to enable trusted certificate callbacks.
1810+
*/
1811+
//#define MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
1812+
17941813
/**
17951814
* \def MBEDTLS_X509_CHECK_KEY_USAGE
17961815
*

include/mbedtls/oid.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@
122122
* { iso(1) identified-organization(3) dod(6) internet(1)
123123
* security(5) mechanisms(5) pkix(7) }
124124
*/
125-
#define MBEDTLS_OID_PKIX MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_DOD "\x01\x05\x05\x07"
125+
#define MBEDTLS_OID_INTERNET MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_DOD "\x01"
126+
#define MBEDTLS_OID_PKIX MBEDTLS_OID_INTERNET "\x05\x05\x07"
126127

127128
/*
128129
* Arc for standard naming attributes
@@ -206,6 +207,13 @@
206207
#define MBEDTLS_OID_TIME_STAMPING MBEDTLS_OID_KP "\x08" /**< id-kp-timeStamping OBJECT IDENTIFIER ::= { id-kp 8 } */
207208
#define MBEDTLS_OID_OCSP_SIGNING MBEDTLS_OID_KP "\x09" /**< id-kp-OCSPSigning OBJECT IDENTIFIER ::= { id-kp 9 } */
208209

210+
/**
211+
* Wi-SUN Alliance Field Area Network
212+
* { iso(1) identified-organization(3) dod(6) internet(1)
213+
* private(4) enterprise(1) WiSUN(45605) FieldAreaNetwork(1) }
214+
*/
215+
#define MBEDTLS_OID_WISUN_FAN MBEDTLS_OID_INTERNET "\x04\x01\x82\xe4\x25\x01"
216+
209217
/*
210218
* PKCS definition OIDs
211219
*/

include/mbedtls/ssl.h

Lines changed: 101 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,10 @@ struct mbedtls_ssl_config
928928
mbedtls_ssl_key_cert *key_cert; /*!< own certificate/key pair(s) */
929929
mbedtls_x509_crt *ca_chain; /*!< trusted CAs */
930930
mbedtls_x509_crl *ca_crl; /*!< trusted CAs CRLs */
931+
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
932+
mbedtls_x509_crt_ca_cb_t f_ca_cb;
933+
void *p_ca_cb;
934+
#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
931935
#endif /* MBEDTLS_X509_CRT_PARSE_C */
932936

933937
#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
@@ -1090,6 +1094,12 @@ struct mbedtls_ssl_context
10901094
unsigned badmac_seen; /*!< records with a bad MAC received */
10911095
#endif /* MBEDTLS_SSL_DTLS_BADMAC_LIMIT */
10921096

1097+
#if defined(MBEDTLS_X509_CRT_PARSE_C)
1098+
/** Callback to customize X.509 certificate chain verification */
1099+
int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *);
1100+
void *p_vrfy; /*!< context for X.509 verify callback */
1101+
#endif
1102+
10931103
mbedtls_ssl_send_t *f_send; /*!< Callback for network send */
10941104
mbedtls_ssl_recv_t *f_recv; /*!< Callback for network receive */
10951105
mbedtls_ssl_recv_timeout_t *f_recv_timeout;
@@ -1366,13 +1376,17 @@ void mbedtls_ssl_conf_authmode( mbedtls_ssl_config *conf, int authmode );
13661376
/**
13671377
* \brief Set the verification callback (Optional).
13681378
*
1369-
* If set, the verify callback is called for each
1370-
* certificate in the chain. For implementation
1371-
* information, please see \c mbedtls_x509_crt_verify()
1379+
* If set, the provided verify callback is called for each
1380+
* certificate in the peer's CRT chain, including the trusted
1381+
* root. For more information, please see the documentation of
1382+
* \c mbedtls_x509_crt_verify().
13721383
*
1373-
* \param conf SSL configuration
1374-
* \param f_vrfy verification function
1375-
* \param p_vrfy verification parameter
1384+
* \note For per context callbacks and contexts, please use
1385+
* mbedtls_ssl_set_verify() instead.
1386+
*
1387+
* \param conf The SSL configuration to use.
1388+
* \param f_vrfy The verification callback to use during CRT verification.
1389+
* \param p_vrfy The opaque context to be passed to the callback.
13761390
*/
13771391
void mbedtls_ssl_conf_verify( mbedtls_ssl_config *conf,
13781392
int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
@@ -1490,6 +1504,30 @@ void mbedtls_ssl_set_bio( mbedtls_ssl_context *ssl,
14901504
void mbedtls_ssl_set_mtu( mbedtls_ssl_context *ssl, uint16_t mtu );
14911505
#endif /* MBEDTLS_SSL_PROTO_DTLS */
14921506

1507+
#if defined(MBEDTLS_X509_CRT_PARSE_C)
1508+
/**
1509+
* \brief Set a connection-specific verification callback (optional).
1510+
*
1511+
* If set, the provided verify callback is called for each
1512+
* certificate in the peer's CRT chain, including the trusted
1513+
* root. For more information, please see the documentation of
1514+
* \c mbedtls_x509_crt_verify().
1515+
*
1516+
* \note This call is analogous to mbedtls_ssl_conf_verify() but
1517+
* binds the verification callback and context to an SSL context
1518+
* as opposed to an SSL configuration.
1519+
* If mbedtls_ssl_conf_verify() and mbedtls_ssl_set_verify()
1520+
* are both used, mbedtls_ssl_set_verify() takes precedence.
1521+
*
1522+
* \param ssl The SSL context to use.
1523+
* \param f_vrfy The verification callback to use during CRT verification.
1524+
* \param p_vrfy The opaque context to be passed to the callback.
1525+
*/
1526+
void mbedtls_ssl_set_verify( mbedtls_ssl_context *ssl,
1527+
int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
1528+
void *p_vrfy );
1529+
#endif /* MBEDTLS_X509_CRT_PARSE_C */
1530+
14931531
/**
14941532
* \brief Set the timeout period for mbedtls_ssl_read()
14951533
* (Default: no timeout.)
@@ -2071,6 +2109,63 @@ void mbedtls_ssl_conf_ca_chain( mbedtls_ssl_config *conf,
20712109
mbedtls_x509_crt *ca_chain,
20722110
mbedtls_x509_crl *ca_crl );
20732111

2112+
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
2113+
/**
2114+
* \brief Set the trusted certificate callback.
2115+
*
2116+
* This API allows to register the set of trusted certificates
2117+
* through a callback, instead of a linked list as configured
2118+
* by mbedtls_ssl_conf_ca_chain().
2119+
*
2120+
* This is useful for example in contexts where a large number
2121+
* of CAs are used, and the inefficiency of maintaining them
2122+
* in a linked list cannot be tolerated. It is also useful when
2123+
* the set of trusted CAs needs to be modified frequently.
2124+
*
2125+
* See the documentation of `mbedtls_x509_crt_ca_cb_t` for
2126+
* more information.
2127+
*
2128+
* \param conf The SSL configuration to register the callback with.
2129+
* \param f_ca_cb The trusted certificate callback to use when verifying
2130+
* certificate chains.
2131+
* \param p_ca_cb The context to be passed to \p f_ca_cb (for example,
2132+
* a reference to a trusted CA database).
2133+
*
2134+
* \note This API is incompatible with mbedtls_ssl_conf_ca_chain():
2135+
* Any call to this function overwrites the values set through
2136+
* earlier calls to mbedtls_ssl_conf_ca_chain() or
2137+
* mbedtls_ssl_conf_ca_cb().
2138+
*
2139+
* \note This API is incompatible with CA indication in
2140+
* CertificateRequest messages: A server-side SSL context which
2141+
* is bound to an SSL configuration that uses a CA callback
2142+
* configured via mbedtls_ssl_conf_ca_cb(), and which requires
2143+
* client authentication, will send an empty CA list in the
2144+
* corresponding CertificateRequest message.
2145+
*
2146+
* \note This API is incompatible with mbedtls_ssl_set_hs_ca_chain():
2147+
* If an SSL context is bound to an SSL configuration which uses
2148+
* CA callbacks configured via mbedtls_ssl_conf_ca_cb(), then
2149+
* calls to mbedtls_ssl_set_hs_ca_chain() have no effect.
2150+
*
2151+
* \note The use of this API disables the use of restartable ECC
2152+
* during X.509 CRT signature verification (but doesn't affect
2153+
* other uses).
2154+
*
2155+
* \warning This API is incompatible with the use of CRLs. Any call to
2156+
* mbedtls_ssl_conf_ca_cb() unsets CRLs configured through
2157+
* earlier calls to mbedtls_ssl_conf_ca_chain().
2158+
*
2159+
* \warning In multi-threaded environments, the callback \p f_ca_cb
2160+
* must be thread-safe, and it is the user's responsibility
2161+
* to guarantee this (for example through a mutex
2162+
* contained in the callback context pointed to by \p p_ca_cb).
2163+
*/
2164+
void mbedtls_ssl_conf_ca_cb( mbedtls_ssl_config *conf,
2165+
mbedtls_x509_crt_ca_cb_t f_ca_cb,
2166+
void *p_ca_cb );
2167+
#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
2168+
20742169
/**
20752170
* \brief Set own certificate chain and private key
20762171
*

0 commit comments

Comments
 (0)