Skip to content

Commit b1395dd

Browse files
Merge branch 'master' into new_timer1_irq
2 parents dfc7a72 + e3c9702 commit b1395dd

File tree

84 files changed

+18595
-400
lines changed

Some content is hidden

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

84 files changed

+18595
-400
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ tools/sdk/lib/liblwip_src.a
99
tools/sdk/lwip/src/build
1010
tools/sdk/lwip/src/liblwip_src.a
1111
tools/sdk/ld/backup
12+
tools/sdk/ld/eagle.app.v6.common.ld
1213

1314
*.pyc
1415
*.gch

cores/esp8266/WString.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,7 @@ String::String(double value, unsigned char decimalPlaces) {
113113
}
114114

115115
String::~String() {
116-
if(buffer) {
117-
free(buffer);
118-
}
119-
init();
116+
invalidate();
120117
}
121118

122119
// /*********************************************/

doc/esp8266wifi/station-class.rst

+7-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,13 @@ Return the status of Wi-Fi connection.
427427
428428
WiFi.status()
429429
430-
Function returns one of the following connection statuses: \* ``WL_CONNECTED`` after successful connection is established \* ``WL_NO_SSID_AVAIL``\ in case configured SSID cannot be reached \* ``WL_CONNECT_FAILED`` if password is incorrect \* ``WL_IDLE_STATUS`` when Wi-Fi is in process of changing between statuses \* ``WL_DISCONNECTED`` if module is not configured in station mode
430+
Function returns one of the following connection statuses:
431+
432+
- ``WL_CONNECTED`` after successful connection is established
433+
- ``WL_NO_SSID_AVAIL`` in case configured SSID cannot be reached
434+
- ``WL_CONNECT_FAILED`` if password is incorrect
435+
- ``WL_IDLE_STATUS`` when Wi-Fi is in process of changing between statuses
436+
- ``WL_DISCONNECTED`` if module is not configured in station mode
431437

432438
Returned value is type of ``wl_status_t`` defined in `wl\_definitions.h <https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/include/wl_definitions.h>`__
433439

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

+65-2
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,47 @@ class TLSTraits : public TransportTraits
6060

6161
std::unique_ptr<WiFiClient> create() override
6262
{
63-
return std::unique_ptr<WiFiClient>(new WiFiClientSecure());
63+
return std::unique_ptr<WiFiClient>(new axTLS::WiFiClientSecure());
6464
}
6565

6666
bool verify(WiFiClient& client, const char* host) override
6767
{
68-
auto wcs = static_cast<WiFiClientSecure&>(client);
68+
auto wcs = static_cast<axTLS::WiFiClientSecure&>(client);
6969
return wcs.verify(_fingerprint.c_str(), host);
7070
}
7171

7272
protected:
7373
String _fingerprint;
7474
};
7575

76+
class BearSSLTraits : public TransportTraits
77+
{
78+
public:
79+
BearSSLTraits(const uint8_t fingerprint[20])
80+
{
81+
memcpy(_fingerprint, fingerprint, sizeof(_fingerprint));
82+
}
83+
84+
std::unique_ptr<WiFiClient> create() override
85+
{
86+
BearSSL::WiFiClientSecure *client = new BearSSL::WiFiClientSecure();
87+
client->setFingerprint(_fingerprint);
88+
return std::unique_ptr<WiFiClient>(client);
89+
}
90+
91+
bool verify(WiFiClient& client, const char* host) override
92+
{
93+
// No-op. BearSSL will not connect if the fingerprint doesn't match.
94+
// So if you get to here you've already connected and it matched
95+
(void) client;
96+
(void) host;
97+
return true;
98+
}
99+
100+
protected:
101+
uint8_t _fingerprint[20];
102+
};
103+
76104
/**
77105
* constructor
78106
*/
@@ -116,6 +144,24 @@ bool HTTPClient::begin(String url, String httpsFingerprint)
116144
return true;
117145
}
118146

147+
148+
bool HTTPClient::begin(String url, const uint8_t httpsFingerprint[20])
149+
{
150+
_transportTraits.reset(nullptr);
151+
_port = 443;
152+
if (!beginInternal(url, "https")) {
153+
return false;
154+
}
155+
_transportTraits = TransportTraitsPtr(new BearSSLTraits(httpsFingerprint));
156+
DEBUG_HTTPCLIENT("[HTTP-Client][begin] BearSSL-httpsFingerprint:");
157+
for (size_t i=0; i < 20; i++) {
158+
DEBUG_HTTPCLIENT(" %02x", httpsFingerprint[i]);
159+
}
160+
DEBUG_HTTPCLIENT("\n");
161+
return true;
162+
}
163+
164+
119165
/**
120166
* parsing the url for all needed parameters
121167
* @param url String
@@ -213,6 +259,23 @@ bool HTTPClient::begin(String host, uint16_t port, String uri, String httpsFinge
213259
return true;
214260
}
215261

262+
bool HTTPClient::begin(String host, uint16_t port, String uri, const uint8_t httpsFingerprint[20])
263+
{
264+
clear();
265+
_host = host;
266+
_port = port;
267+
_uri = uri;
268+
269+
_transportTraits = TransportTraitsPtr(new BearSSLTraits(httpsFingerprint));
270+
DEBUG_HTTPCLIENT("[HTTP-Client][begin] host: %s port: %d url: %s BearSSL-httpsFingerprint:", host.c_str(), port, uri.c_str());
271+
for (size_t i=0; i < 20; i++) {
272+
DEBUG_HTTPCLIENT(" %02x", httpsFingerprint[i]);
273+
}
274+
DEBUG_HTTPCLIENT("\n");
275+
return true;
276+
}
277+
278+
216279
/**
217280
* end
218281
* called after the payload is handled

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,15 @@ class HTTPClient
133133
HTTPClient();
134134
~HTTPClient();
135135

136+
// Plain HTTP connection, unencrypted
136137
bool begin(String url);
137-
bool begin(String url, String httpsFingerprint);
138138
bool begin(String host, uint16_t port, String uri = "/");
139+
// Use axTLS for secure HTTPS connection
140+
bool begin(String url, String httpsFingerprint);
139141
bool begin(String host, uint16_t port, String uri, String httpsFingerprint);
142+
// Use BearSSL for secure HTTPS connection
143+
bool begin(String url, const uint8_t httpsFingerprint[20]);
144+
bool begin(String host, uint16_t port, String uri, const uint8_t httpsFingerprint[20]);
140145
// deprecated, use the overload above instead
141146
bool begin(String host, uint16_t port, String uri, bool https, String httpsFingerprint) __attribute__ ((deprecated));
142147

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
SecureBearSSLUpdater - SSL encrypted, password-protected firmware update
3+
4+
This example starts a HTTPS server on the ESP8266 to allow firmware updates
5+
to be performed. All communication, including the username and password,
6+
is encrypted via SSL. Be sure to update the SSID and PASSWORD before running
7+
to allow connection to your WiFi network.
8+
9+
To upload through terminal you can use:
10+
curl -u admin:admin -F "[email protected]" esp8266-webupdate.local/firmware
11+
12+
Adapted by Earle F. Philhower, III, from the SecureWebUpdater.ino example.
13+
This example is released into the public domain.
14+
*/
15+
16+
#include <ESP8266WiFi.h>
17+
#include <WiFiClient.h>
18+
#include <ESP8266WebServerSecure.h>
19+
#include <ESP8266mDNS.h>
20+
#include <ESP8266HTTPUpdateServer.h>
21+
22+
const char* host = "esp8266-webupdate";
23+
const char* update_path = "/firmware";
24+
const char* update_username = "admin";
25+
const char* update_password = "admin";
26+
const char* ssid = "........";
27+
const char* password = "........";
28+
29+
BearSSL::ESP8266WebServerSecure httpServer(443);
30+
ESP8266HTTPUpdateServer httpUpdater;
31+
32+
static const char serverCert[] PROGMEM = R"EOF(
33+
-----BEGIN CERTIFICATE-----
34+
MIIDSzCCAjMCCQD2ahcfZAwXxDANBgkqhkiG9w0BAQsFADCBiTELMAkGA1UEBhMC
35+
VVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDU9yYW5nZSBDb3VudHkx
36+
EDAOBgNVBAoMB1ByaXZhZG8xGjAYBgNVBAMMEXNlcnZlci56bGFiZWwuY29tMR8w
37+
HQYJKoZIhvcNAQkBFhBlYXJsZUB6bGFiZWwuY29tMB4XDTE4MDMwNjA1NDg0NFoX
38+
DTE5MDMwNjA1NDg0NFowRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3Rh
39+
dGUxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDCCASIwDQYJKoZI
40+
hvcNAQEBBQADggEPADCCAQoCggEBAPVKBwbZ+KDSl40YCDkP6y8Sv4iNGvEOZg8Y
41+
X7sGvf/xZH7UiCBWPFIRpNmDSaZ3yjsmFqm6sLiYSGSdrBCFqdt9NTp2r7hga6Sj
42+
oASSZY4B9pf+GblDy5m10KDx90BFKXdPMCLT+o76Nx9PpCvw13A848wHNG3bpBgI
43+
t+w/vJCX3bkRn8yEYAU6GdMbYe7v446hX3kY5UmgeJFr9xz1kq6AzYrMt/UHhNzO
44+
S+QckJaY0OGWvmTNspY3xCbbFtIDkCdBS8CZAw+itnofvnWWKQEXlt6otPh5njwy
45+
+O1t/Q+Z7OMDYQaH02IQx3188/kW3FzOY32knER1uzjmRO+jhA8CAwEAATANBgkq
46+
hkiG9w0BAQsFAAOCAQEAnDrROGRETB0woIcI1+acY1yRq4yAcH2/hdq2MoM+DCyM
47+
E8CJaOznGR9ND0ImWpTZqomHOUkOBpvu7u315blQZcLbL1LfHJGRTCHVhvVrcyEb
48+
fWTnRtAQdlirUm/obwXIitoz64VSbIVzcqqfg9C6ZREB9JbEX98/9Wp2gVY+31oC
49+
JfUvYadSYxh3nblvA4OL+iEZiW8NE3hbW6WPXxvS7Euge0uWMPc4uEcnsE0ZVG3m
50+
+TGimzSdeWDvGBRWZHXczC2zD4aoE5vrl+GD2i++c6yjL/otHfYyUpzUfbI2hMAA
51+
5tAF1D5vAAwA8nfPysumlLsIjohJZo4lgnhB++AlOg==
52+
-----END CERTIFICATE-----
53+
)EOF";
54+
55+
static const char serverKey[] PROGMEM = R"EOF(
56+
-----BEGIN RSA PRIVATE KEY-----
57+
MIIEpQIBAAKCAQEA9UoHBtn4oNKXjRgIOQ/rLxK/iI0a8Q5mDxhfuwa9//FkftSI
58+
IFY8UhGk2YNJpnfKOyYWqbqwuJhIZJ2sEIWp2301OnavuGBrpKOgBJJljgH2l/4Z
59+
uUPLmbXQoPH3QEUpd08wItP6jvo3H0+kK/DXcDzjzAc0bdukGAi37D+8kJfduRGf
60+
zIRgBToZ0xth7u/jjqFfeRjlSaB4kWv3HPWSroDNisy39QeE3M5L5ByQlpjQ4Za+
61+
ZM2yljfEJtsW0gOQJ0FLwJkDD6K2eh++dZYpAReW3qi0+HmePDL47W39D5ns4wNh
62+
BofTYh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YaMV
78+
kCPgaj1BjHw4AmB0+EcajfKilcqtSroJ6MfMJ6IclVOizkjbByeTsE4lxDmPCDSt
79+
/9MKanBxAoGAY9xo741Pn9WUxDyRplww606ccdNf/ksHWNc/Y2B5SPwxxSnIq8nO
80+
j01SmsCUYVFAgZVOTiiycakjYLzxlc6p8BxSVqy6LlJqn95N8OXoQ+bkwUux/ekg
81+
gz5JWYhbD6c38khSzJb0pNXCo3EuYAVa36kDM96k1BtWuhRS10Q1VXk=
82+
-----END RSA PRIVATE KEY-----
83+
)EOF";
84+
85+
86+
void setup()
87+
{
88+
89+
Serial.begin(115200);
90+
Serial.println();
91+
Serial.println("Booting Sketch...");
92+
WiFi.mode(WIFI_AP_STA);
93+
WiFi.begin(ssid, password);
94+
95+
while(WiFi.waitForConnectResult() != WL_CONNECTED){
96+
WiFi.begin(ssid, password);
97+
Serial.println("WiFi failed, retrying.");
98+
}
99+
100+
configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");
101+
102+
MDNS.begin(host);
103+
104+
httpServer.setRSACert(new BearSSLX509List(serverCert), new BearSSLPrivateKey(serverKey));
105+
httpUpdater.setup(&httpServer, update_path, update_username, update_password);
106+
httpServer.begin();
107+
108+
MDNS.addService("https", "tcp", 443);
109+
Serial.printf("BearSSLUpdateServer ready!\nOpen https://%s.local%s in "\
110+
"your browser and login with username '%s' and password "\
111+
"'%s'\n", host, update_path, update_username, update_password);
112+
}
113+
114+
void loop()
115+
{
116+
httpServer.handleClient();
117+
}

0 commit comments

Comments
 (0)