Skip to content

Commit 6b86f97

Browse files
authored
Merge pull request #23 from espressif/master
25102021
2 parents f0db73b + 15bbd0a commit 6b86f97

34 files changed

+104
-77
lines changed

boards.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9687,10 +9687,10 @@ deneyapmini.build.boot=qio
96879687
deneyapmini.build.partitions=default
96889688
deneyapmini.build.defines=
96899689

9690-
deneyapmini.menu.SerialMode.default=USB_CDC
9691-
deneyapmini.menu.SerialMode.default.build.serial=1
9692-
deneyapmini.menu.SerialMode.uart=UART0
9693-
deneyapmini.menu.SerialMode.uart.build.serial=0
9690+
deneyapmini.menu.CDCOnBoot.default=Disabled
9691+
deneyapmini.menu.CDCOnBoot.default.build.cdc_on_boot=0
9692+
deneyapmini.menu.CDCOnBoot.cdc=Enabled
9693+
deneyapmini.menu.CDCOnBoot.cdc.build.cdc_on_boot=1
96949694

96959695
deneyapmini.menu.PSRAM.disabled=Disabled
96969696
deneyapmini.menu.PSRAM.disabled.build.defines=

libraries/EEPROM/examples/eeprom_class/eeprom_class.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@
1111
#include "EEPROM.h"
1212

1313
// Instantiate eeprom objects with parameter/argument names and sizes
14-
EEPROMClass NAMES("eeprom0", 0x500);
15-
EEPROMClass HEIGHT("eeprom1", 0x200);
16-
EEPROMClass AGE("eeprom2", 0x100);
14+
EEPROMClass NAMES("eeprom0");
15+
EEPROMClass HEIGHT("eeprom1");
16+
EEPROMClass AGE("eeprom2");
1717

1818
void setup() {
1919
Serial.begin(115200);
2020
delay(1000);
2121
Serial.println("Testing EEPROMClass\n");
22-
if (!NAMES.begin(NAMES.length())) {
22+
if (!NAMES.begin(0x500)) {
2323
Serial.println("Failed to initialise NAMES");
2424
Serial.println("Restarting...");
2525
delay(1000);
2626
ESP.restart();
2727
}
28-
if (!HEIGHT.begin(HEIGHT.length())) {
28+
if (!HEIGHT.begin(0x200)) {
2929
Serial.println("Failed to initialise HEIGHT");
3030
Serial.println("Restarting...");
3131
delay(1000);
3232
ESP.restart();
3333
}
34-
if (!AGE.begin(AGE.length())) {
34+
if (!AGE.begin(0x100)) {
3535
Serial.println("Failed to initialise AGE");
3636
Serial.println("Restarting...");
3737
delay(1000);

libraries/EEPROM/src/EEPROM.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ EEPROMClass::EEPROMClass(void)
3434
, _size(0)
3535
, _dirty(false)
3636
, _name("eeprom")
37-
, _user_defined_size(0)
3837
{
3938
}
4039

@@ -45,17 +44,15 @@ EEPROMClass::EEPROMClass(uint32_t sector)
4544
, _size(0)
4645
, _dirty(false)
4746
, _name("eeprom")
48-
, _user_defined_size(0)
4947
{
5048
}
5149

52-
EEPROMClass::EEPROMClass(const char* name, uint32_t user_defined_size)
50+
EEPROMClass::EEPROMClass(const char* name)
5351
: _handle(0)
5452
, _data(0)
5553
, _size(0)
5654
, _dirty(false)
5755
, _name(name)
58-
, _user_defined_size(user_defined_size)
5956
{
6057
}
6158

@@ -215,7 +212,7 @@ uint8_t * EEPROMClass::getDataPtr() {
215212
*/
216213
uint16_t EEPROMClass::length ()
217214
{
218-
return _user_defined_size;
215+
return _size;
219216
}
220217

221218
/*

libraries/EEPROM/src/EEPROM.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ typedef uint32_t nvs_handle;
3535
class EEPROMClass {
3636
public:
3737
EEPROMClass(uint32_t sector);
38-
EEPROMClass(const char* name, uint32_t user_defined_size);
38+
EEPROMClass(const char* name);
3939
EEPROMClass(void);
4040
~EEPROMClass(void);
4141

@@ -112,7 +112,6 @@ class EEPROMClass {
112112
size_t _size;
113113
bool _dirty;
114114
const char* _name;
115-
uint32_t _user_defined_size;
116115
};
117116

118117
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_EEPROM)

libraries/WiFiClientSecure/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,18 @@ To use PSK:
6666
encryption for the connection
6767

6868
Please see the WiFiClientPSK example.
69+
70+
Specifying the ALPN Protocol
71+
----------------------------
72+
73+
Application-Layer Protocol Negotiation (ALPN) is a Transport Layer Security (TLS) extension that allows
74+
the application layer to negotiate which protocol should be performed over a secure connection in a manner
75+
that avoids additional round trips and which is independent of the application-layer protocols.
76+
77+
For example, this is used with AWS IoT Custom Authorizers where an MQTT client must set the ALPN protocol to ```mqtt```:
78+
79+
```
80+
const char *aws_protos[] = {"mqtt", NULL};
81+
...
82+
wiFiClient.setAlpnProtocols(aws_protos);
83+
```

libraries/WiFiClientSecure/keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ connected KEYWORD2
2929
setCACert KEYWORD2
3030
setCertificate KEYWORD2
3131
setPrivateKey KEYWORD2
32+
setAlpnProtocols KEYWORD2
3233

3334
#######################################
3435
# Constants (LITERAL1)

libraries/WiFiClientSecure/src/WiFiClientSecure.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ WiFiClientSecure::WiFiClientSecure()
4343
_pskIdent = NULL;
4444
_psKey = NULL;
4545
next = NULL;
46+
_alpn_protos = NULL;
4647
}
4748

4849

@@ -66,6 +67,7 @@ WiFiClientSecure::WiFiClientSecure(int sock)
6667
_pskIdent = NULL;
6768
_psKey = NULL;
6869
next = NULL;
70+
_alpn_protos = NULL;
6971
}
7072

7173
WiFiClientSecure::~WiFiClientSecure()
@@ -127,7 +129,7 @@ int WiFiClientSecure::connect(const char *host, uint16_t port, const char *CA_ce
127129
if(_timeout > 0){
128130
sslclient->handshake_timeout = _timeout;
129131
}
130-
int ret = start_ssl_client(sslclient, host, port, _timeout, CA_cert, cert, private_key, NULL, NULL, _use_insecure);
132+
int ret = start_ssl_client(sslclient, host, port, _timeout, CA_cert, cert, private_key, NULL, NULL, _use_insecure, _alpn_protos);
131133
_lastError = ret;
132134
if (ret < 0) {
133135
log_e("start_ssl_client: %d", ret);
@@ -147,7 +149,7 @@ int WiFiClientSecure::connect(const char *host, uint16_t port, const char *pskId
147149
if(_timeout > 0){
148150
sslclient->handshake_timeout = _timeout;
149151
}
150-
int ret = start_ssl_client(sslclient, host, port, _timeout, NULL, NULL, NULL, pskIdent, psKey, _use_insecure);
152+
int ret = start_ssl_client(sslclient, host, port, _timeout, NULL, NULL, NULL, pskIdent, psKey, _use_insecure, _alpn_protos);
151153
_lastError = ret;
152154
if (ret < 0) {
153155
log_e("start_ssl_client: %d", ret);
@@ -341,3 +343,8 @@ void WiFiClientSecure::setHandshakeTimeout(unsigned long handshake_timeout)
341343
{
342344
sslclient->handshake_timeout = handshake_timeout * 1000;
343345
}
346+
347+
void WiFiClientSecure::setAlpnProtocols(const char **alpn_protos)
348+
{
349+
_alpn_protos = alpn_protos;
350+
}

libraries/WiFiClientSecure/src/WiFiClientSecure.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class WiFiClientSecure : public WiFiClient
3939
const char *_private_key;
4040
const char *_pskIdent; // identity for PSK cipher suites
4141
const char *_psKey; // key in hex for PSK cipher suites
42+
const char **_alpn_protos;
4243

4344
public:
4445
WiFiClientSecure *next;
@@ -73,6 +74,7 @@ class WiFiClientSecure : public WiFiClient
7374
bool loadPrivateKey(Stream& stream, size_t size);
7475
bool verify(const char* fingerprint, const char* domain_name);
7576
void setHandshakeTimeout(unsigned long handshake_timeout);
77+
void setAlpnProtocols(const char **alpn_protos);
7678
const mbedtls_x509_crt* getPeerCertificate() { return mbedtls_ssl_get_peer_cert(&sslclient->ssl_ctx); };
7779
bool getFingerprintSHA256(uint8_t sha256_result[32]) { return get_peer_fingerprint(sslclient, sha256_result); };
7880
int setTimeout(uint32_t seconds){ return 0; }

libraries/WiFiClientSecure/src/ssl_client.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void ssl_init(sslclient_context *ssl_client)
5151
}
5252

5353

54-
int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t port, int timeout, const char *rootCABuff, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey, bool insecure)
54+
int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t port, int timeout, const char *rootCABuff, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey, bool insecure, const char **alpn_protos)
5555
{
5656
char buf[512];
5757
int ret, flags;
@@ -156,6 +156,13 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p
156156
return handle_error(ret);
157157
}
158158

159+
if (alpn_protos != NULL) {
160+
log_v("Setting ALPN protocols");
161+
if ((ret = mbedtls_ssl_conf_alpn_protocols(&ssl_client->ssl_conf, alpn_protos) ) != 0) {
162+
return handle_error(ret);
163+
}
164+
}
165+
159166
// MBEDTLS_SSL_VERIFY_REQUIRED if a CA certificate is defined on Arduino IDE and
160167
// MBEDTLS_SSL_VERIFY_NONE if not.
161168

libraries/WiFiClientSecure/src/ssl_client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ typedef struct sslclient_context {
2929

3030

3131
void ssl_init(sslclient_context *ssl_client);
32-
int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t port, int timeout, const char *rootCABuff, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey, bool insecure);
32+
int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t port, int timeout, const char *rootCABuff, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey, bool insecure, const char **alpn_protos);
3333
void stop_ssl_socket(sslclient_context *ssl_client, const char *rootCABuff, const char *cli_cert, const char *cli_key);
3434
int data_to_read(sslclient_context *ssl_client);
3535
int send_ssl_data(sslclient_context *ssl_client, const uint8_t *data, size_t len);

0 commit comments

Comments
 (0)