Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate axTLS, update examples #5366

Merged
merged 36 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9dfdfd5
update examples
d-a-v Nov 22, 2018
a28b183
fix serial<->tcp example, use STASSID instead of SSID (name collision)
d-a-v Nov 23, 2018
be3c5cf
fix HTTPSRequest.ino
d-a-v Nov 23, 2018
7e40b18
update AxTLS HTTPS examples, update AxTLS API to deprecated
d-a-v Nov 24, 2018
3e94897
fixes
d-a-v Nov 24, 2018
c2301e2
fixes + fix astyle (no preproc directives) + restyling script
d-a-v Nov 24, 2018
0b849cf
fix HTTPClient library
d-a-v Nov 24, 2018
8ecae22
fixes
d-a-v Nov 24, 2018
68f77a5
common.sh: do not reload arduino when already present (for locally CI…
d-a-v Nov 24, 2018
f1bb21d
common.sh: do not reload ArduinoJson when already present (for locall…
d-a-v Nov 24, 2018
797bb37
fix
d-a-v Nov 24, 2018
9c2c90a
fix
d-a-v Nov 24, 2018
dd0f55f
fix deprecated example
d-a-v Nov 24, 2018
e7ec28a
fix WiFiHTTPSServer.ino
d-a-v Nov 24, 2018
70ef54b
reduce footprint
d-a-v Nov 25, 2018
003c190
wipfix
d-a-v Nov 25, 2018
49a5d9b
fix led builtin
d-a-v Nov 25, 2018
c48d5f4
fix example
d-a-v Nov 25, 2018
119e73d
finished updating APSSID on all examples
d-a-v Nov 25, 2018
8a28979
style
d-a-v Nov 25, 2018
bc945af
Merge branch 'master' into examples
d-a-v Nov 25, 2018
d742388
Merge branch 'master' into examples
earlephilhower Nov 26, 2018
ef890c9
Merge branch 'master' into examples
d-a-v Nov 27, 2018
b7c4e55
restyle examples
d-a-v Nov 27, 2018
8473361
Merge branch 'master' into examples
d-a-v Nov 28, 2018
e2ebfab
helper to run CI test locally
d-a-v Nov 28, 2018
ab0b372
local CI runner more verbose
d-a-v Nov 28, 2018
a9a7572
Merge branch 'master' into examples
d-a-v Nov 28, 2018
cbebae6
Merge branch 'master' into examples
d-a-v Nov 29, 2018
822c38c
+const
d-a-v Nov 29, 2018
42dc0b7
deprecation deprecation
d-a-v Nov 29, 2018
3c298e6
deprecation
d-a-v Nov 29, 2018
c00b975
Merge branch 'master' into examples
d-a-v Nov 29, 2018
6048663
Merge branch 'master' into examples
earlephilhower Nov 30, 2018
5385a93
Update NTPClient.ino
devyte Nov 30, 2018
cc15e6f
Update interactive.ino
devyte Nov 30, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiClientSecure.h>

#include <ESP8266HTTPClient.h>

Expand Down
9 changes: 8 additions & 1 deletion libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@

#ifdef HTTPCLIENT_1_1_COMPATIBLE
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <WiFiClientSecureAxTLS.h>
devyte marked this conversation as resolved.
Show resolved Hide resolved
earlephilhower marked this conversation as resolved.
Show resolved Hide resolved
#endif
#include <WiFiClientSecureBearSSL.h>

#include <StreamString.h>
#include <base64.h>
Expand Down Expand Up @@ -64,12 +65,18 @@ class TLSTraits : public TransportTraits

std::unique_ptr<WiFiClient> create() override
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return std::unique_ptr<WiFiClient>(new axTLS::WiFiClientSecure());
#pragma GCC diagnostic pop
}

bool verify(WiFiClient& client, const char* host) override
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
auto wcs = static_cast<axTLS::WiFiClientSecure&>(client);
#pragma GCC diagnostic pop
return wcs.verify(_fingerprint.c_str(), host);
}

Expand Down
4 changes: 3 additions & 1 deletion libraries/ESP8266WebServer/src/ESP8266WebServerSecure.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "ESP8266WebServerSecureAxTLS.h"
#include <WiFiClientSecure.h>

//#include "ESP8266WebServerSecureAxTLS.h"
#include "ESP8266WebServerSecureBearSSL.h"
10 changes: 9 additions & 1 deletion libraries/ESP8266WebServer/src/ESP8266WebServerSecureAxTLS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <libb64/cencode.h>
#include "WiFiServer.h"
#include "WiFiClient.h"
#include "ESP8266WebServerSecure.h"
#include "ESP8266WebServerSecureAxTLS.h"

//#define DEBUG_ESP_HTTP_SERVER
#ifdef DEBUG_ESP_PORT
Expand All @@ -36,6 +36,9 @@

namespace axTLS {

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

ESP8266WebServerSecure::ESP8266WebServerSecure(IPAddress addr, int port)
: _serverSecure(addr, port)
{
Expand All @@ -46,6 +49,8 @@ ESP8266WebServerSecure::ESP8266WebServerSecure(int port)
{
}

#pragma GCC diagnostic pop

void ESP8266WebServerSecure::setServerKeyAndCert_P(const uint8_t *key, int keyLen, const uint8_t *cert, int certLen)
{
_serverSecure.setServerKeyAndCert_P(key, keyLen, cert, certLen);
Expand Down Expand Up @@ -131,7 +136,10 @@ void ESP8266WebServerSecure::handleClient() {
}

if (!keepCurrentClient) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
_currentClientSecure = WiFiClientSecure();
#pragma GCC diagnostic pop
_currentStatus = HC_NONE;
_currentUpload.reset();
}
Expand Down
3 changes: 2 additions & 1 deletion libraries/ESP8266WebServer/src/ESP8266WebServerSecureAxTLS.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#define ESP8266WEBSERVERSECURE_H

#include <ESP8266WebServer.h>
#include <WiFiServerSecure.h>
#include <WiFiServerSecureAxTLS.h>
#include <WiFiClientSecureAxTLS.h>

namespace axTLS {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@
// Released to the public domain

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <CertStoreBearSSL.h>
#include <time.h>

const char *ssid = "....";
const char *pass = "....";
#ifndef STASSID
#define STASSID "your-ssid"
#define PSK "your-password"
#endif

const char *ssid = STASSID;
const char *pass = PSK;

// A single, global CertStore which can be used by all
// connections. Needs to stay live the entire time any of
Expand Down Expand Up @@ -192,11 +198,11 @@ void setup() {
Serial.println();
Serial.println();

#ifdef USE_SDCARD
#ifdef USE_SDCARD
SD.begin();
#else
#else
SPIFFS.begin();
#endif
#endif

// We start by connecting to a WiFi network
Serial.print("Connecting to ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
// Released to the public domain

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>

const char *ssid = "....";
const char *pass = "....";
#ifndef STASSID
#define STASSID "your-ssid"
#define PSK "your-password"
#endif

const char *ssid = STASSID;
const char *pass = PSK;

void fetch(BearSSL::WiFiClientSecure *client) {
client->write("GET / HTTP/1.0\r\nHost: tls.mbed.org\r\nUser-Agent: ESP8266\r\n\r\n");
Expand Down
10 changes: 8 additions & 2 deletions libraries/ESP8266WiFi/examples/BearSSL_Server/BearSSL_Server.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@
*/

#include <ESP8266WiFi.h>
#include <WiFiServerSecure.h>
#include <time.h>

const char *ssid = "....";
const char *pass = "....";
#ifndef STASSID
#define STASSID "your-ssid"
#define PSK "your-password"
#endif

const char *ssid = STASSID;
const char *pass = PSK;

// The HTTPS server
BearSSL::WiFiServerSecure server(443);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,16 @@
*/

#include <ESP8266WiFi.h>
#include <WiFiServerSecure.h>
#include <time.h>

const char *ssid = "....";
const char *pass = "....";
#ifndef STASSID
#define STASSID "your-ssid"
#define PSK "your-password"
#endif

const char *ssid = STASSID;
const char *pass = PSK;

// The server which will require a client cert signed by the trusted CA
BearSSL::WiFiServerSecure server(443);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
// Released to the public domain

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <time.h>

const char *ssid = "....";
const char *pass = "....";
#ifndef STASSID
#define STASSID "your-ssid"
#define PSK "your-password"
#endif

const char *ssid = STASSID;
const char *pass = PSK;

const char * host = "api.github.com";
const uint16_t port = 443;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
// Released to the public domain

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <time.h>

const char *ssid = "....";
const char *pass = "....";
#ifndef STASSID
#define STASSID "your-ssid"
#define PSK "your-password"
#endif

const char *ssid = STASSID;
const char *pass = PSK;

const char * host = "api.github.com";
const uint16_t port = 443;
Expand Down
21 changes: 12 additions & 9 deletions libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>

const char* ssid = "........";
const char* password = "........";
#ifndef STASSID
#define STASSID "your-ssid"
#define PSK "your-password"
#endif

const char* ssid = STASSID;
const char* password = PSK;

const char* host = "api.github.com";
const int httpsPort = 443;

// Use web browser to view and copy
// SHA1 fingerprint of the certificate
const char* fingerprint = "5F F1 60 31 09 04 3E F2 90 D2 B0 8A 50 38 04 E8 37 9F BC 76";
const char fingerprint[] PROGMEM = "5F F1 60 31 09 04 3E F2 90 D2 B0 8A 50 38 04 E8 37 9F BC 76";

void setup() {
Serial.begin(115200);
Expand All @@ -49,17 +54,15 @@ void setup() {
WiFiClientSecure client;
Serial.print("connecting to ");
Serial.println(host);

Serial.printf("Using fingerprint '%s'\n", fingerprint);
client.setFingerprint(fingerprint);

if (!client.connect(host, httpsPort)) {
Serial.println("connection failed");
return;
}

if (client.verify(fingerprint, host)) {
Serial.println("certificate matches");
} else {
Serial.println("certificate doesn't match");
}

String url = "/repos/esp8266/Arduino/commits/master/status";
Serial.print("requesting URL: ");
Serial.println(url);
Expand Down
105 changes: 105 additions & 0 deletions libraries/ESP8266WiFi/examples/HTTPSRequestAxTLS/HTTPSRequestAxTLS.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
HTTP over TLS (HTTPS) example sketch

This example demonstrates how to use
WiFiClientSecure class to access HTTPS API.
We fetch and display the status of
esp8266/Arduino project continuous integration
build.

Limitations:
only RSA certificates
no support of Perfect Forward Secrecy (PFS)
TLSv1.2 is supported since version 2.4.0-rc1

Created by Ivan Grokhotkov, 2015.
This example is in public domain.
*/

#include <ESP8266WiFi.h>

// force use of AxTLS (BearSSL is now default)
#include <WiFiClientSecureAxTLS.h>
using namespace axTLS;

#ifndef STASSID
#define STASSID "your-ssid"
#define PSK "your-password"
#endif

const char* ssid = STASSID;
const char* password = PSK;

const char* host = "api.github.com";
const int httpsPort = 443;

// Use web browser to view and copy
// SHA1 fingerprint of the certificate
const char* fingerprint = "5F F1 60 31 09 04 3E F2 90 D2 B0 8A 50 38 04 E8 37 9F BC 76";

void setup() {
Serial.begin(115200);
Serial.println();
Serial.print("connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

// Use WiFiClientSecure class to create TLS connection
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
WiFiClientSecure client;
#pragma GCC diagnostic pop
Serial.print("connecting to ");
Serial.println(host);
if (!client.connect(host, httpsPort)) {
Serial.println("connection failed");
return;
}

if (client.verify(fingerprint, host)) {
Serial.println("certificate matches");
} else {
Serial.println("certificate doesn't match");
}

String url = "/repos/esp8266/Arduino/commits/master/status";
Serial.print("requesting URL: ");
Serial.println(url);

client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: BuildFailureDetectorESP8266\r\n" +
"Connection: close\r\n\r\n");

Serial.println("request sent");
while (client.connected()) {
String line = client.readStringUntil('\n');
if (line == "\r") {
Serial.println("headers received");
break;
}
}
String line = client.readStringUntil('\n');
if (line.startsWith("{\"state\":\"success\"")) {
Serial.println("esp8266/Arduino CI successfull!");
} else {
Serial.println("esp8266/Arduino CI has failed");
}
Serial.println("reply was:");
Serial.println("==========");
Serial.println(line);
Serial.println("==========");
Serial.println("closing connection");
}

void loop() {
}
Loading