Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
562784d
experimental support of HTTPUpdate
mcspr Jun 2, 2019
4af49b8
fix async ssl build
mcspr Jun 2, 2019
cd90b4f
really fix async ssl build
mcspr Jun 5, 2019
e1d2cd7
hide ota progress in debug log when using webui
mcspr Jun 5, 2019
d1d1f29
update gh fingerprint
mcspr Jun 5, 2019
4bef90d
use github ca as default
mcspr Jun 5, 2019
ccf633a
allow to override otafp default
mcspr Jun 7, 2019
d3cae74
update comments, no need to check ssl_client_bearssl for cert root
mcspr Jun 7, 2019
e747e48
mqtt_ota support with httpupdate
mcspr Jun 7, 2019
27bc003
prefix ssl client settings with ota
mcspr Jun 20, 2019
4f64b40
strings
mcspr Jun 20, 2019
ce1eec8
use make_unique
mcspr Jun 20, 2019
dc27119
bail if mfln setting is not working
mcspr Jun 20, 2019
c8d81f6
update comments
mcspr Jun 20, 2019
d10bdba
always include arduinoota headers (fix enum arg type)
mcspr Jun 20, 2019
f7e2b9f
Merge remote-tracking branch 'origin/dev' into ota/wificlient
mcspr Jun 20, 2019
5806152
free() does nothing here
mcspr Jun 20, 2019
e6036d4
empty path placeholder
mcspr Jun 20, 2019
d8aeb5a
display supported OTA modules
mcspr Jun 20, 2019
00436b9
separate setting for mfln
mcspr Jun 20, 2019
8608449
experimental
mcspr Jun 20, 2019
2506e95
reorder definitions
mcspr Jun 20, 2019
bdc1f5d
fix basic http updater unintentionally including axtls
mcspr Jun 21, 2019
0c13f51
SSL_CLIENT -> SECURE_CLIENT
mcspr Jun 22, 2019
6f21b97
Avoid 2.4.2 for bearssl
mcspr Jun 22, 2019
f3ffa4d
formatting
mcspr Jun 22, 2019
763b66a
Merge remote-tracking branch 'origin/dev' into ota/wificlient
mcspr Aug 8, 2019
39a02d0
asyncota: close the connection on error
mcspr Aug 8, 2019
1342a80
Check otaScCheck, close when check fails
mcspr Aug 8, 2019
3128dba
httpupdate: limit valid mfln sizes, no probing
mcspr Aug 8, 2019
3889381
mfln.probe for given url
mcspr Aug 8, 2019
0537b5b
break
mcspr Aug 8, 2019
83063bf
allow schemaless url
mcspr Aug 8, 2019
d4b59c1
SECURE_CLIENT_CHECK
mcspr Aug 8, 2019
94b2a33
fixup! SECURE_CLIENT_CHECK
mcspr Aug 12, 2019
d9a3d71
Merge branch 'dev' into ota/wificlient
mcspr Aug 12, 2019
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
5 changes: 5 additions & 0 deletions code/espurna/config/dependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,8 @@
#undef NTP_SUPPORT
#define NTP_SUPPORT 1 // Scheduler needs NTP
#endif

#if (SECURE_CLIENT == SECURE_CLIENT_BEARSSL)
#undef OTA_CLIENT_HTTPUPDATE_2_3_0_COMPATIBLE
#define OTA_CLIENT_HTTPUPDATE_2_3_0_COMPATIBLE 0 // Use new HTTPUpdate API with BearSSL
#endif
88 changes: 85 additions & 3 deletions code/espurna/config/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -682,19 +682,99 @@
#define SPIFFS_SUPPORT 0 // Do not add support for SPIFFS by default
#endif

// -----------------------------------------------------------------------------
// SSL Client ** EXPERIMENTAL **
// -----------------------------------------------------------------------------

#ifndef SECURE_CLIENT
#define SECURE_CLIENT SECURE_CLIENT_NONE // What variant of WiFiClient to use
// SECURE_CLIENT_NONE - No secure client support (default)
// SECURE_CLIENT_AXTLS - axTLS client secure support (All Core versions, ONLY TLS 1.1)
// SECURE_CLIENT_BEARSSL - BearSSL client secure support (starting with 2.5.0, TLS 1.2)
//
// axTLS marked for derecation since Arduino Core 2.4.2 and **will** be removed in the future
#endif

// Security check that is performed when the connection is established:
// SECURE_CLIENT_CHECK_CA - Use Trust Anchor / Root Certificate
// Supported only by the SECURE_CLIENT_BEARSSL
// (See respective ..._SECURE_CLIENT_INCLUDE_CA options per-module)
// SECURE_CLIENT_CHECK_FINGERPRINT - Check certificate fingerprint
// SECURE_CLIENT_CHECK_NONE - Allow insecure connections

#ifndef SECURE_CLIENT_CHECK

#if SECURE_CLIENT == SECURE_CLIENT_BEARSSL
#define SECURE_CLIENT_CHECK SECURE_CLIENT_CHECK_CA

#else
#define SECURE_CLIENT_CHECK SECURE_CLIENT_CHECK_FINGERPRINT

#endif


#endif // SECURE_CLIENT_CHECK

// Support Maximum Fragment Length Negotiation TLS extension
// "...negotiate a smaller maximum fragment length due to memory limitations or bandwidth limitations."
// - https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/bearssl-client-secure-class.html#mfln-or-maximum-fragment-length-negotiation-saving-ram
// - https://tools.ietf.org/html/rfc6066#section-4
#ifndef SECURE_CLIENT_MFLN
Comment thread
mcspr marked this conversation as resolved.
#define SECURE_CLIENT_MFLN 0 // The only possible values are: 512, 1024, 2048 and 4096
// Set to 0 to disable (default)
#endif

// -----------------------------------------------------------------------------
// OTA
// -----------------------------------------------------------------------------

#ifndef OTA_PORT
#define OTA_PORT 8266 // OTA port
#define OTA_PORT 8266 // Port for ArduinoOTA
#endif

#ifndef OTA_MQTT_SUPPORT
#define OTA_MQTT_SUPPORT 0 // No support by default
#define OTA_MQTT_SUPPORT 0 // Listen for HTTP(s) URLs at '<root topic>/ota'. Depends on OTA_CLIENT
#endif

#ifndef OTA_ARDUINOOTA_SUPPORT
#define OTA_ARDUINOOTA_SUPPORT 1 // Support ArduinoOTA by default (4.2Kb)
// Implicitly depends on ESP8266mDNS library, thus increasing firmware size
#endif

#ifndef OTA_CLIENT
#define OTA_CLIENT OTA_CLIENT_ASYNCTCP // Terminal / MQTT OTA support
// OTA_CLIENT_ASYNCTCP (ESPAsyncTCP library)
// OTA_CLIENT_HTTPUPDATE (Arduino Core library)
#endif

#ifndef OTA_CLIENT_HTTPUPDATE_2_3_0_COMPATIBLE
#define OTA_CLIENT_HTTPUPDATE_2_3_0_COMPATIBLE 1 // Use old HTTPUpdate API by default
#endif

#define OTA_GITHUB_FP "CA:06:F5:6B:25:8B:7A:0D:4F:2B:05:47:09:39:47:86:51:15:19:84"

#ifndef OTA_FINGERPRINT
#define OTA_FINGERPRINT OTA_GITHUB_FP
#endif

#ifndef OTA_SECURE_CLIENT_CHECK
#define OTA_SECURE_CLIENT_CHECK SECURE_CLIENT_CHECK
#endif

#ifndef OTA_SECURE_CLIENT_MFLN
#define OTA_SECURE_CLIENT_MFLN SECURE_CLIENT_MFLN
#endif

#ifndef OTA_SECURE_CLIENT_INCLUDE_CA
#define OTA_SECURE_CLIENT_INCLUDE_CA 0 // Use user-provided CA. Only PROGMEM PEM option is supported.
// TODO: eventually should be replaced with pre-parsed structs, read directly from flash
// (ref: https://github.com/earlephilhower/bearssl-esp8266/pull/14)
//
// When enabled, current implementation includes "static/ota_secure_client_ca.h" with
// const char _ota_client_http_update_ca[] PROGMEM = "...PEM data...";
// By default, using DigiCert root in "static/digicert_evroot_pem.h" (for https://github.com)
#endif

#define OTA_GITHUB_FP "D7:9F:07:61:10:B3:92:93:E3:49:AC:89:84:5B:03:80:C1:9E:2F:8B"

// -----------------------------------------------------------------------------
// NOFUSS
Expand Down Expand Up @@ -1330,6 +1410,8 @@
#endif

// Enable RCSwitch support
// Originally implemented for SONOFF BASIC
// https://tinkerman.cat/adding-rf-to-a-non-rf-itead-sonoff/
// Also possible to use with SONOFF RF BRIDGE, thanks to @wildwiz
// https://github.com/xoseperez/espurna/wiki/Hardware-Itead-Sonoff-RF-Bridge---Direct-Hack
#ifndef RFB_DIRECT
Expand Down
1 change: 1 addition & 0 deletions code/espurna/config/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -3975,6 +3975,7 @@
#define INFLUXDB_SUPPORT 1
#define IR_SUPPORT 1
#define RF_SUPPORT 1
#define OTA_MQTT_SUPPORT 1

#define RFB_DIRECT 1
#define RFB_RX_PIN 4
Expand Down
26 changes: 26 additions & 0 deletions code/espurna/config/progmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,32 @@ PROGMEM const char espurna_modules[] =
#endif
"";

PROGMEM const char espurna_ota_modules[] =
#if OTA_ARDUINOOTA_SUPPORT
"ARDUINO "
#endif
#if (OTA_CLIENT == OTA_CLIENT_ASYNCTCP)
"ASYNCTCP "
#endif
#if (OTA_CLIENT == OTA_CLIENT_HTTPUPDATE)
#if (SECURE_CLIENT == SECURE_CLIENT_NONE)
"*HTTPUPDATE "
#endif
#if (SECURE_CLIENT == SECURE_CLIENT_AXTLS)
"*HTTPUPDATE_AXTLS "
#endif
#if (SECURE_CLIENT == SECURE_CLIENT_BEARSSL)
"*HTTPUPDATE_BEARSSL "
#endif
#endif // OTA_CLIENT_HTTPUPDATE
#if OTA_MQTT_SUPPORT
"MQTT "
#endif
#if WEB_SUPPORT
"WEB "
#endif
"";

//--------------------------------------------------------------------------------
// Sensors
//--------------------------------------------------------------------------------
Expand Down
37 changes: 36 additions & 1 deletion code/espurna/config/prototypes.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <Arduino.h>
#include <ArduinoJson.h>
#include <functional>
#include <memory>
#include <core_version.h>

extern "C" {
Expand Down Expand Up @@ -168,7 +169,30 @@ void i2c_read_buffer(uint8_t address, uint8_t * buffer, size_t len);
// -----------------------------------------------------------------------------
// OTA
// -----------------------------------------------------------------------------
#include "ESPAsyncTCP.h"

#include <ArduinoOTA.h>

#if OTA_CLIENT == OTA_CLIENT_ASYNCTCP
#include <ESPAsyncTCP.h>
#endif

#if OTA_CLIENT == OTA_CLIENT_HTTPUPDATE
#include <ESP8266HTTPClient.h>
#include <ESP8266httpUpdate.h>
#endif

#if SECURE_CLIENT != SECURE_CLIENT_NONE

#include <WiFiClientSecure.h>

#if OTA_SECURE_CLIENT_INCLUDE_CA
#include "static/ota_secure_client_ca.h"
#else

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#else if SSL_CLIENT_BEARSSL?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I wanted to add something here using .cpp files and weaken the progmem char symbol, but that did not quite work. This probably can even be just a check for include_ca flag, progmem'ed array will be discarded anyways as unused variable.

#include "static/digicert_evroot_pem.h"
#define _ota_client_http_update_ca _ssl_digicert_ev_root_ca
#endif

#endif // SECURE_CLIENT_SUPPORT

// -----------------------------------------------------------------------------
// RFM69
Expand Down Expand Up @@ -285,3 +309,14 @@ bool wifiConnected();
// -----------------------------------------------------------------------------
#include "rtcmem.h"

// -----------------------------------------------------------------------------
// std::make_unique backport for C++11
// -----------------------------------------------------------------------------
#if 201103L >= __cplusplus
namespace std {
template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
}
#endif
23 changes: 22 additions & 1 deletion code/espurna/config/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,25 @@
// Telnet server
//------------------------------------------------------------------------------
#define TELNET_SERVER_ASYNC 0
#define TELNET_SERVER_WIFISERVER 1
#define TELNET_SERVER_WIFISERVER 1

//------------------------------------------------------------------------------
// OTA Client (not related to the Web OTA support)
//------------------------------------------------------------------------------

#define OTA_CLIENT_NONE 0
#define OTA_CLIENT_ASYNCTCP 1
#define OTA_CLIENT_HTTPUPDATE 2

//------------------------------------------------------------------------------
// Secure Client
//------------------------------------------------------------------------------

#define SECURE_CLIENT_NONE 0
#define SECURE_CLIENT_AXTLS 1
#define SECURE_CLIENT_BEARSSL 2

#define SECURE_CLIENT_CHECK_NONE 0 // !!! INSECURE CONNECTION !!!
#define SECURE_CLIENT_CHECK_FINGERPRINT 1 // legacy fingerprint validation
#define SECURE_CLIENT_CHECK_CA 2 // set trust anchor from PROGMEM CA certificate

7 changes: 6 additions & 1 deletion code/espurna/espurna.ino
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,15 @@ void setup() {
info();

wifiSetup();
otaSetup();
#if OTA_ARDUINOOTA_SUPPORT
arduinoOtaSetup();
#endif
#if TELNET_SUPPORT
telnetSetup();
#endif
#if OTA_CLIENT != OTA_CLIENT_NONE
otaClientSetup();
#endif

// -------------------------------------------------------------------------
// Check if system is stable
Expand Down
68 changes: 68 additions & 0 deletions code/espurna/libs/URL.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// -----------------------------------------------------------------------------
// Parse char string as URL
//
// Adapted from HTTPClient::beginInternal()
// https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
//
// -----------------------------------------------------------------------------

#pragma once

struct URL {
String value;
String protocol;
String host;
String path;
uint16_t port;

URL(const char* url) { init(url); }
URL(const String& url) { init(url); }

void init(String url);
};

void URL::init(String url) {

this->value = url;

// cut the protocol part
int index = url.indexOf("://");
if (index > 0) {
this->protocol = url.substring(0, index);
url.remove(0, (index + 3));
}

if (this->protocol == "http") {
this->port = 80;
} else if (this->protocol == "https") {
this->port = 443;
}

// cut the host part
String _host;

index = url.indexOf('/');
if (index >= 0) {
_host = url.substring(0, index);
} else {
_host = url;
}

// store the remaining part as path
if (index >= 0) {
url.remove(0, index);
this->path = url;
} else {
this->path = "/";
}

// separate host from port, when present
index = _host.indexOf(':');
if (index >= 0) {
this->port = _host.substring(index + 1).toInt();
this->host = _host.substring(0, index);
} else {
this->host = _host;
}

}
Loading