Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions boards.txt

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions doc/esp8266wifi/bearssl-client-secure-class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,14 @@ setSSLVersion(uint32_t min, uint32_t max)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Valid values for min and max are `BR_TLS10`, `BR_TLS11`, `BR_TLS12`. Min and max may be set to the same value if only a single TLS version is desired.

Build-time Cipher Profiles
~~~~~~~~~~~~~~~~~~~~~~~~~~

`setCiphers()` and `setSSLVersion()` change what is offered on the wire, but every algorithm BearSSL supports is still linked in. The "SSL Support" menu of the IDE (or a build flag elsewhere) selects which ones are built at all:

* All SSL ciphers (default): every suite BearSSL implements, TLS 1.0 to 1.2.
* Basic SSL ciphers (`-DBEARSSL_SSL_BASIC`): RSA key exchange with AES-CBC only, no elliptic curves.
* TLS 1.2 ECDHE+AEAD ciphers only (`-DBEARSSL_SSL_AEAD_ONLY`): TLS 1.2 with ECDHE key exchange and ChaCha20-Poly1305 or AES-GCM only. CBC, CCM, 3DES, static ECDH and RSA key exchange are left out, as are the TLS 1.0/1.1 PRF and the MD5, SHA-1 and SHA-224 hashes, so these are neither offered nor accepted in signatures or certificates. `setSSLVersion()` refuses a minimum below `BR_TLS12` and `setCiphersLessSecure()` returns `false`. Servers that only support older suites or SHA-1 signed certificates cannot be reached with this profile.

The two flags are mutually exclusive.
56 changes: 52 additions & 4 deletions libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void WiFiClientSecureCtx::_clear() {
_session = nullptr;
_cipher_list = nullptr;
_cipher_cnt = 0;
_tls_min = BR_TLS10;
_tls_min = BEARSSL_TLS_MIN_DEFAULT;
_tls_max = BR_TLS12;
}

Expand Down Expand Up @@ -825,6 +825,14 @@ extern "C" {
* strong enough, and AES-256 is 40% more expensive).
*/
static const uint16_t suites_P[] PROGMEM = {
#ifdef BEARSSL_SSL_AEAD_ONLY
BR_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
BR_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
BR_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
BR_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
BR_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
BR_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
#else
#ifndef BEARSSL_SSL_BASIC
BR_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
BR_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
Expand Down Expand Up @@ -873,11 +881,17 @@ extern "C" {
BR_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA,
BR_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA,
BR_TLS_RSA_WITH_3DES_EDE_CBC_SHA
#endif
#endif
};
#ifndef BEARSSL_SSL_BASIC
// Server w/EC has one set, not possible with basic SSL config
static const uint16_t suites_server_ec_P [] PROGMEM = {
#ifdef BEARSSL_SSL_AEAD_ONLY
BR_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
BR_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
BR_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
#else
BR_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
BR_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
BR_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
Expand All @@ -904,10 +918,16 @@ extern "C" {
BR_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA,
BR_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA,
BR_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
#endif
};
#endif

static const uint16_t suites_server_rsa_P[] PROGMEM = {
#ifdef BEARSSL_SSL_AEAD_ONLY
BR_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
BR_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
BR_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
#else
#ifndef BEARSSL_SSL_BASIC
BR_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
BR_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Expand All @@ -930,31 +950,38 @@ extern "C" {
#ifndef BEARSSL_SSL_BASIC
BR_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,
BR_TLS_RSA_WITH_3DES_EDE_CBC_SHA
#endif
#endif
};


#ifndef BEARSSL_SSL_AEAD_ONLY
// For apps which want to use less secure but faster ciphers, only
static const uint16_t faster_suites_P[] PROGMEM = {
BR_TLS_RSA_WITH_AES_256_CBC_SHA256,
BR_TLS_RSA_WITH_AES_128_CBC_SHA256,
BR_TLS_RSA_WITH_AES_256_CBC_SHA,
BR_TLS_RSA_WITH_AES_128_CBC_SHA };
#endif

// Install hashes into the SSL engine
static void br_ssl_client_install_hashes(br_ssl_engine_context *eng) {
#ifndef BEARSSL_SSL_AEAD_ONLY
br_ssl_engine_set_hash(eng, br_md5_ID, &br_md5_vtable);
br_ssl_engine_set_hash(eng, br_sha1_ID, &br_sha1_vtable);
br_ssl_engine_set_hash(eng, br_sha224_ID, &br_sha224_vtable);
#endif
br_ssl_engine_set_hash(eng, br_sha256_ID, &br_sha256_vtable);
br_ssl_engine_set_hash(eng, br_sha384_ID, &br_sha384_vtable);
br_ssl_engine_set_hash(eng, br_sha512_ID, &br_sha512_vtable);
}

static void br_x509_minimal_install_hashes(br_x509_minimal_context *x509) {
#ifndef BEARSSL_SSL_AEAD_ONLY
br_x509_minimal_set_hash(x509, br_md5_ID, &br_md5_vtable);
br_x509_minimal_set_hash(x509, br_sha1_ID, &br_sha1_vtable);
br_x509_minimal_set_hash(x509, br_sha224_ID, &br_sha224_vtable);
#endif
br_x509_minimal_set_hash(x509, br_sha256_ID, &br_sha256_vtable);
br_x509_minimal_set_hash(x509, br_sha384_ID, &br_sha384_vtable);
br_x509_minimal_set_hash(x509, br_sha512_ID, &br_sha512_vtable);
Expand All @@ -966,22 +993,30 @@ extern "C" {
memcpy_P(suites, cipher_list, cipher_cnt * sizeof(cipher_list[0]));
br_ssl_client_zero(cc);
br_ssl_engine_add_flags(&cc->eng, BR_OPT_NO_RENEGOTIATION); // forbid SSL renegotiation, as we free the Private Key after handshake
br_ssl_engine_set_versions(&cc->eng, BR_TLS10, BR_TLS12);
br_ssl_engine_set_versions(&cc->eng, BEARSSL_TLS_MIN_DEFAULT, BR_TLS12);
br_ssl_engine_set_suites(&cc->eng, suites, (sizeof suites) / (sizeof suites[0]));
#ifndef BEARSSL_SSL_AEAD_ONLY
br_ssl_client_set_default_rsapub(cc);
#endif
br_ssl_engine_set_default_rsavrfy(&cc->eng);
#ifndef BEARSSL_SSL_BASIC
br_ssl_engine_set_default_ecdsa(&cc->eng);
#endif
br_ssl_client_install_hashes(&cc->eng);
#ifndef BEARSSL_SSL_AEAD_ONLY
br_ssl_engine_set_prf10(&cc->eng, &br_tls10_prf);
#endif
br_ssl_engine_set_prf_sha256(&cc->eng, &br_tls12_sha256_prf);
br_ssl_engine_set_prf_sha384(&cc->eng, &br_tls12_sha384_prf);
#ifndef BEARSSL_SSL_AEAD_ONLY
br_ssl_engine_set_default_aes_cbc(&cc->eng);
#endif
#ifndef BEARSSL_SSL_BASIC
br_ssl_engine_set_default_aes_gcm(&cc->eng);
#ifndef BEARSSL_SSL_AEAD_ONLY
br_ssl_engine_set_default_aes_ccm(&cc->eng);
br_ssl_engine_set_default_des_cbc(&cc->eng);
#endif
br_ssl_engine_set_default_chapol(&cc->eng);
#endif
}
Expand All @@ -992,21 +1027,29 @@ extern "C" {
memcpy_P(suites, cipher_list, cipher_cnt * sizeof(cipher_list[0]));
br_ssl_server_zero(cc);
br_ssl_engine_add_flags(&cc->eng, BR_OPT_NO_RENEGOTIATION); // forbid SSL renegotiation, as we free the Private Key after handshake
br_ssl_engine_set_versions(&cc->eng, BR_TLS10, BR_TLS12);
br_ssl_engine_set_versions(&cc->eng, BEARSSL_TLS_MIN_DEFAULT, BR_TLS12);
br_ssl_engine_set_suites(&cc->eng, suites, (sizeof suites) / (sizeof suites[0]));
#ifndef BEARSSL_SSL_BASIC
br_ssl_engine_set_default_ec(&cc->eng);
#endif

br_ssl_client_install_hashes(&cc->eng);
#ifndef BEARSSL_SSL_AEAD_ONLY
br_ssl_engine_set_prf10(&cc->eng, &br_tls10_prf);
#endif
br_ssl_engine_set_prf_sha256(&cc->eng, &br_tls12_sha256_prf);
br_ssl_engine_set_prf_sha384(&cc->eng, &br_tls12_sha384_prf);
#ifndef BEARSSL_SSL_AEAD_ONLY
br_ssl_engine_set_default_aes_cbc(&cc->eng);
#endif
#ifndef BEARSSL_SSL_BASIC
#ifndef BEARSSL_SSL_AEAD_ONLY
br_ssl_engine_set_default_aes_ccm(&cc->eng);
#endif
br_ssl_engine_set_default_aes_gcm(&cc->eng);
#ifndef BEARSSL_SSL_AEAD_ONLY
br_ssl_engine_set_default_des_cbc(&cc->eng);
#endif
br_ssl_engine_set_default_chapol(&cc->eng);
#endif
}
Expand All @@ -1027,7 +1070,12 @@ bool WiFiClientSecureCtx::setCiphers(const uint16_t *cipherAry, int cipherCount)
}

bool WiFiClientSecureCtx::setCiphersLessSecure() {
#ifdef BEARSSL_SSL_AEAD_ONLY
DEBUG_BSSL("setCiphersLessSecure: the RSA/CBC suites are not built in with BEARSSL_SSL_AEAD_ONLY\n");
return false;
#else
return setCiphers(faster_suites_P, sizeof(faster_suites_P)/sizeof(faster_suites_P[0]));
#endif
}

bool WiFiClientSecureCtx::setCiphers(const std::vector<uint16_t>& list) {
Expand All @@ -1037,7 +1085,7 @@ bool WiFiClientSecureCtx::setCiphers(const std::vector<uint16_t>& list) {
bool WiFiClientSecureCtx::setSSLVersion(uint32_t min, uint32_t max) {
if ( ((min != BR_TLS10) && (min != BR_TLS11) && (min != BR_TLS12)) ||
((max != BR_TLS10) && (max != BR_TLS11) && (max != BR_TLS12)) ||
(max < min) ) {
(min < BEARSSL_TLS_MIN_DEFAULT) || (max < min) ) {
return false; // Invalid options
}
_tls_min = min;
Expand Down
16 changes: 14 additions & 2 deletions libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
#include "BearSSLHelpers.h"
#include "CertStoreBearSSL.h"

#if defined(BEARSSL_SSL_BASIC) && defined(BEARSSL_SSL_AEAD_ONLY)
#error "BEARSSL_SSL_BASIC and BEARSSL_SSL_AEAD_ONLY select different cipher profiles, define at most one"
#endif

// Lowest TLS version the cipher profile supports. The AEAD-only profile has no
// TLS 1.0/1.1 PRF, so it is TLS 1.2 only.
#ifdef BEARSSL_SSL_AEAD_ONLY
#define BEARSSL_TLS_MIN_DEFAULT BR_TLS12
#else
#define BEARSSL_TLS_MIN_DEFAULT BR_TLS10
#endif

namespace BearSSL {

class WiFiClientSecureCtx : public WiFiClient {
Expand Down Expand Up @@ -136,7 +148,7 @@ class WiFiClientSecureCtx : public WiFiClient {

// Limit the TLS versions BearSSL will connect with. Default is
// BR_TLS10...BR_TLS12
bool setSSLVersion(uint32_t min = BR_TLS10, uint32_t max = BR_TLS12);
bool setSSLVersion(uint32_t min = BEARSSL_TLS_MIN_DEFAULT, uint32_t max = BR_TLS12);

// peek buffer API is present
virtual bool hasPeekBufferAPI () const override { return true; }
Expand Down Expand Up @@ -354,7 +366,7 @@ class WiFiClientSecure : public WiFiClient {

// Limit the TLS versions BearSSL will connect with. Default is
// BR_TLS10...BR_TLS12. Allowed values are: BR_TLS10, BR_TLS11, BR_TLS12
bool setSSLVersion(uint32_t min = BR_TLS10, uint32_t max = BR_TLS12) { return _ctx->setSSLVersion(min, max); };
bool setSSLVersion(uint32_t min = BEARSSL_TLS_MIN_DEFAULT, uint32_t max = BR_TLS12) { return _ctx->setSSLVersion(min, max); };

// Check for Maximum Fragment Length support for given len before connection (possibly insecure)
static bool probeMaxFragmentLength(IPAddress ip, uint16_t port, uint16_t len);
Expand Down
2 changes: 1 addition & 1 deletion libraries/ESP8266WiFi/src/WiFiServerSecureBearSSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ WiFiClientSecure WiFiServerSecure::accept() {
bool WiFiServerSecure::setSSLVersion(uint32_t min, uint32_t max) {
if ( ((min != BR_TLS10) && (min != BR_TLS11) && (min != BR_TLS12)) ||
((max != BR_TLS10) && (max != BR_TLS11) && (max != BR_TLS12)) ||
(max < min) ) {
(min < BEARSSL_TLS_MIN_DEFAULT) || (max < min) ) {
return false; // Invalid options
}
_tls_min = min;
Expand Down
4 changes: 2 additions & 2 deletions libraries/ESP8266WiFi/src/WiFiServerSecureBearSSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class WiFiServerSecure : public WiFiServer {

// Limit the TLS versions BearSSL will connect with. Default is
// BR_TLS10...BR_TLS12
bool setSSLVersion(uint32_t min = BR_TLS10, uint32_t max = BR_TLS12);
bool setSSLVersion(uint32_t min = BEARSSL_TLS_MIN_DEFAULT, uint32_t max = BR_TLS12);

// If awaiting connection available and authenticated (i.e. client cert), return it.
WiFiClientSecure accept(); // https://www.arduino.cc/en/Reference/EthernetServerAccept
Expand All @@ -82,7 +82,7 @@ class WiFiServerSecure : public WiFiServer {
ServerSessions *_cache = nullptr;

// TLS ciphers allowed
uint32_t _tls_min = BR_TLS10;
uint32_t _tls_min = BEARSSL_TLS_MIN_DEFAULT;
uint32_t _tls_max = BR_TLS12;
};

Expand Down
2 changes: 2 additions & 0 deletions tools/boards.txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,8 @@
( '.menu.ssl.all.build.sslflags', ''),
( '.menu.ssl.basic', 'Basic SSL ciphers (lower ROM use)' ),
( '.menu.ssl.basic.build.sslflags', '-DBEARSSL_SSL_BASIC'),
( '.menu.ssl.aead', 'TLS 1.2 ECDHE+AEAD ciphers only (lower ROM use)' ),
( '.menu.ssl.aead.build.sslflags', '-DBEARSSL_SSL_AEAD_ONLY'),
]),

####################### mmu
Expand Down