Skip to content

Commit b3577be

Browse files
Add HTTPUpdateServer(Secure)
1 parent ae9fa9f commit b3577be

File tree

8 files changed

+458
-1
lines changed

8 files changed

+458
-1
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
SecureBearSSLUpdater - SSL encrypted, password-protected firmware update
3+
4+
This example starts a HTTPS server on the Pico 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 "image=@firmware.bin" picow-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 <WiFi.h>
17+
#include <WiFiClient.h>
18+
#include <WebServerSecure.h>
19+
#include <LEAmDNS.h>
20+
#include <HTTPUpdateServer.h>
21+
22+
#ifndef STASSID
23+
#define STASSID "your-ssid"
24+
#define STAPSK "your-password"
25+
#endif
26+
27+
const char* host = "picow-webupdate";
28+
const char* update_path = "/firmware";
29+
const char* update_username = "admin";
30+
const char* update_password = "admin";
31+
const char* ssid = STASSID;
32+
const char* password = STAPSK;
33+
34+
WebServerSecure httpServer(443);
35+
HTTPUpdateServerSecure httpUpdater;
36+
37+
static const char serverCert[] PROGMEM = R"EOF(
38+
-----BEGIN CERTIFICATE-----
39+
MIIDSzCCAjMCCQD2ahcfZAwXxDANBgkqhkiG9w0BAQsFADCBiTELMAkGA1UEBhMC
40+
VVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDU9yYW5nZSBDb3VudHkx
41+
EDAOBgNVBAoMB1ByaXZhZG8xGjAYBgNVBAMMEXNlcnZlci56bGFiZWwuY29tMR8w
42+
HQYJKoZIhvcNAQkBFhBlYXJsZUB6bGFiZWwuY29tMB4XDTE4MDMwNjA1NDg0NFoX
43+
DTE5MDMwNjA1NDg0NFowRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3Rh
44+
dGUxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDCCASIwDQYJKoZI
45+
hvcNAQEBBQADggEPADCCAQoCggEBAPVKBwbZ+KDSl40YCDkP6y8Sv4iNGvEOZg8Y
46+
X7sGvf/xZH7UiCBWPFIRpNmDSaZ3yjsmFqm6sLiYSGSdrBCFqdt9NTp2r7hga6Sj
47+
oASSZY4B9pf+GblDy5m10KDx90BFKXdPMCLT+o76Nx9PpCvw13A848wHNG3bpBgI
48+
t+w/vJCX3bkRn8yEYAU6GdMbYe7v446hX3kY5UmgeJFr9xz1kq6AzYrMt/UHhNzO
49+
S+QckJaY0OGWvmTNspY3xCbbFtIDkCdBS8CZAw+itnofvnWWKQEXlt6otPh5njwy
50+
+O1t/Q+Z7OMDYQaH02IQx3188/kW3FzOY32knER1uzjmRO+jhA8CAwEAATANBgkq
51+
hkiG9w0BAQsFAAOCAQEAnDrROGRETB0woIcI1+acY1yRq4yAcH2/hdq2MoM+DCyM
52+
E8CJaOznGR9ND0ImWpTZqomHOUkOBpvu7u315blQZcLbL1LfHJGRTCHVhvVrcyEb
53+
fWTnRtAQdlirUm/obwXIitoz64VSbIVzcqqfg9C6ZREB9JbEX98/9Wp2gVY+31oC
54+
JfUvYadSYxh3nblvA4OL+iEZiW8NE3hbW6WPXxvS7Euge0uWMPc4uEcnsE0ZVG3m
55+
+TGimzSdeWDvGBRWZHXczC2zD4aoE5vrl+GD2i++c6yjL/otHfYyUpzUfbI2hMAA
56+
5tAF1D5vAAwA8nfPysumlLsIjohJZo4lgnhB++AlOg==
57+
-----END CERTIFICATE-----
58+
)EOF";
59+
60+
static const char serverKey[] PROGMEM = R"EOF(
61+
-----BEGIN RSA PRIVATE KEY-----
62+
MIIEpQIBAAKCAQEA9UoHBtn4oNKXjRgIOQ/rLxK/iI0a8Q5mDxhfuwa9//FkftSI
63+
IFY8UhGk2YNJpnfKOy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8Il12q57mqgsq7ag7NPwWOymHesxHV5mMh/Dw+NyBi4xAGWRh9mtrUmeqK
80+
iyICik773Gxo0RIqnPgd4jJWN3N3YWeynzulOIkJnSNx5BforOCTc3uCD2s2YB5X
81+
jx1LKoNQxLeLRN8cmpIWicf/AoGBANjRSsZTKwV9WWIDJoHyxav/vPb+8WYFp8lZ
82+
zaRxQbGM6nn4NiZI7OF62N3uhWB/1c7IqTK/bVHqFTuJCrCNcsgld3gLZ2QWYaMV
83+
kCPgaj1BjHw4AmB0+EcajfKilcqtSroJ6MfMJ6IclVOizkjbByeTsE4lxDmPCDSt
84+
/9MKanBxAoGAY9xo741Pn9WUxDyRplww606ccdNf/ksHWNc/Y2B5SPwxxSnIq8nO
85+
j01SmsCUYVFAgZVOTiiycakjYLzxlc6p8BxSVqy6LlJqn95N8OXoQ+bkwUux/ekg
86+
gz5JWYhbD6c38khSzJb0pNXCo3EuYAVa36kDM96k1BtWuhRS10Q1VXk=
87+
-----END RSA PRIVATE KEY-----
88+
)EOF";
89+
90+
91+
void setup() {
92+
93+
Serial.begin(115200);
94+
Serial.println();
95+
Serial.println("Booting Sketch...");
96+
WiFi.mode(WIFI_STA);
97+
WiFi.begin(ssid, password);
98+
99+
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
100+
WiFi.begin(ssid, password);
101+
Serial.println("WiFi failed, retrying.");
102+
}
103+
104+
configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");
105+
106+
MDNS.begin(host);
107+
108+
httpServer.getServer().setRSACert(new BearSSL::X509List(serverCert), new BearSSL::PrivateKey(serverKey));
109+
httpUpdater.setup(&httpServer, update_path, update_username, update_password);
110+
httpServer.begin();
111+
112+
MDNS.addService("https", "tcp", 443);
113+
Serial.printf("BearSSLUpdateServer ready!\nOpen https://%s.local%s in "
114+
"your browser and login with username '%s' and password "
115+
"'%s'\n",
116+
host, update_path, update_username, update_password);
117+
}
118+
119+
void loop() {
120+
httpServer.handleClient();
121+
MDNS.update();
122+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
To upload through terminal you can use: curl -F "image=@firmware.bin" picow-webupdate.local/update
3+
*/
4+
5+
#include <WiFi.h>
6+
#include <WiFiClient.h>
7+
#include <WebServer.h>
8+
#include <LEAmDNS.h>
9+
#include <HTTPUpdateServer.h>
10+
11+
#ifndef STASSID
12+
#define STASSID "your-ssid"
13+
#define STAPSK "your-password"
14+
#endif
15+
16+
const char* host = "picow-webupdate";
17+
const char* ssid = STASSID;
18+
const char* password = STAPSK;
19+
20+
WebServer httpServer(80);
21+
HTTPUpdateServer httpUpdater;
22+
23+
void setup(void) {
24+
25+
Serial.begin(115200);
26+
Serial.println();
27+
Serial.println("Booting Sketch...");
28+
WiFi.mode(WIFI_STA);
29+
WiFi.begin(ssid, password);
30+
31+
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
32+
WiFi.begin(ssid, password);
33+
Serial.println("WiFi failed, retrying.");
34+
}
35+
36+
MDNS.begin(host);
37+
38+
httpUpdater.setup(&httpServer);
39+
httpServer.begin();
40+
41+
MDNS.addService("http", "tcp", 80);
42+
Serial.printf("HTTPUpdateServer ready! Open http://%s.local/update in your browser\n", host);
43+
}
44+
45+
void loop(void) {
46+
httpServer.handleClient();
47+
MDNS.update();
48+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
To upload through terminal you can use: curl -u admin:admin -F "image=@firmware.bin" picow-webupdate.local/firmware
3+
*/
4+
5+
#include <WiFi.h>
6+
#include <WiFiClient.h>
7+
#include <WebServer.h>
8+
#include <LEAmDNS.h>
9+
#include <HTTPUpdateServer.h>
10+
11+
#ifndef STASSID
12+
#define STASSID "your-ssid"
13+
#define STAPSK "your-password"
14+
#endif
15+
16+
const char* host = "picow-webupdate";
17+
const char* update_path = "/firmware";
18+
const char* update_username = "admin";
19+
const char* update_password = "admin";
20+
const char* ssid = STASSID;
21+
const char* password = STAPSK;
22+
23+
WebServer httpServer(80);
24+
HTTPUpdateServer httpUpdater;
25+
26+
void setup(void) {
27+
28+
Serial.begin(115200);
29+
Serial.println();
30+
Serial.println("Booting Sketch...");
31+
WiFi.mode(WIFI_STA);
32+
WiFi.begin(ssid, password);
33+
34+
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
35+
WiFi.begin(ssid, password);
36+
Serial.println("WiFi failed, retrying.");
37+
}
38+
39+
MDNS.begin(host);
40+
41+
httpUpdater.setup(&httpServer, update_path, update_username, update_password);
42+
httpServer.begin();
43+
44+
MDNS.addService("http", "tcp", 80);
45+
Serial.printf("HTTPUpdateServer ready! Open http://%s.local%s in your browser and login with username '%s' and password '%s'\n", host, update_path, update_username, update_password);
46+
}
47+
48+
void loop(void) {
49+
httpServer.handleClient();
50+
MDNS.update();
51+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#######################################
2+
# Syntax Coloring Map For HTTPUpdateServer
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
HTTPUpdateServer KEYWORD1
10+
HTTPUpdateServerSecure KEYWORD1
11+
12+
#######################################
13+
# Methods and Functions (KEYWORD2)
14+
#######################################
15+
16+
begin KEYWORD2
17+
setup KEYWORD2
18+
19+
#######################################
20+
# Constants (LITERAL1)
21+
#######################################
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=HTTPUpdateServer
2+
version=1.0
3+
author=Ivan Grokhotkov, Miguel Angel Ajo
4+
maintainer=Earle F. Philhower, III <earlephilhower@yahoo.com>
5+
sentence=Simple HTTP Update server based on the Pico WebServer
6+
paragraph=The library accepts HTTP post requests to the /update url, and updates the ESP8266 firmware.
7+
category=Communication
8+
url=https://github.com/earlephilhower/arduino-pico
9+
architectures=rp2040
10+
dot_a_linkage=false

0 commit comments

Comments
 (0)