Skip to content

Commit 7e40b18

Browse files
committed
update AxTLS HTTPS examples, update AxTLS API to deprecated
1 parent be3c5cf commit 7e40b18

File tree

8 files changed

+136
-19
lines changed

8 files changed

+136
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
HTTP over TLS (HTTPS) example sketch
3+
4+
This example demonstrates how to use
5+
WiFiClientSecure class to access HTTPS API.
6+
We fetch and display the status of
7+
esp8266/Arduino project continuous integration
8+
build.
9+
10+
Limitations:
11+
only RSA certificates
12+
no support of Perfect Forward Secrecy (PFS)
13+
TLSv1.2 is supported since version 2.4.0-rc1
14+
15+
Created by Ivan Grokhotkov, 2015.
16+
This example is in public domain.
17+
*/
18+
19+
#include <ESP8266WiFi.h>
20+
21+
// force use of AxTLS (BearSSL is now default)
22+
#include <WiFiClientSecureAxTLS.h>
23+
using namespace axTLS;
24+
25+
#ifndef STASSID
26+
#define STASSID "your-ssid"
27+
#define PSK "your-password"
28+
#endif
29+
30+
const char* ssid = STASSID;
31+
const char* password = PSK;
32+
33+
const char* host = "api.github.com";
34+
const int httpsPort = 443;
35+
36+
// Use web browser to view and copy
37+
// SHA1 fingerprint of the certificate
38+
const char* fingerprint = "5F F1 60 31 09 04 3E F2 90 D2 B0 8A 50 38 04 E8 37 9F BC 76";
39+
40+
void setup() {
41+
Serial.begin(115200);
42+
Serial.println();
43+
Serial.print("connecting to ");
44+
Serial.println(ssid);
45+
WiFi.mode(WIFI_STA);
46+
WiFi.begin(ssid, password);
47+
while (WiFi.status() != WL_CONNECTED) {
48+
delay(500);
49+
Serial.print(".");
50+
}
51+
Serial.println("");
52+
Serial.println("WiFi connected");
53+
Serial.println("IP address: ");
54+
Serial.println(WiFi.localIP());
55+
56+
// Use WiFiClientSecure class to create TLS connection
57+
WiFiClientSecure client;
58+
Serial.print("connecting to ");
59+
Serial.println(host);
60+
if (!client.connect(host, httpsPort)) {
61+
Serial.println("connection failed");
62+
return;
63+
}
64+
65+
if (client.verify(fingerprint, host)) {
66+
Serial.println("certificate matches");
67+
} else {
68+
Serial.println("certificate doesn't match");
69+
}
70+
71+
String url = "/repos/esp8266/Arduino/commits/master/status";
72+
Serial.print("requesting URL: ");
73+
Serial.println(url);
74+
75+
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
76+
"Host: " + host + "\r\n" +
77+
"User-Agent: BuildFailureDetectorESP8266\r\n" +
78+
"Connection: close\r\n\r\n");
79+
80+
Serial.println("request sent");
81+
while (client.connected()) {
82+
String line = client.readStringUntil('\n');
83+
if (line == "\r") {
84+
Serial.println("headers received");
85+
break;
86+
}
87+
}
88+
String line = client.readStringUntil('\n');
89+
if (line.startsWith("{\"state\":\"success\"")) {
90+
Serial.println("esp8266/Arduino CI successfull!");
91+
} else {
92+
Serial.println("esp8266/Arduino CI has failed");
93+
}
94+
Serial.println("reply was:");
95+
Serial.println("==========");
96+
Serial.println(line);
97+
Serial.println("==========");
98+
Serial.println("closing connection");
99+
}
100+
101+
void loop() {
102+
}

libraries/ESP8266WiFi/examples/HTTPSRequestCACert/HTTPSRequestCACert.ino renamed to libraries/ESP8266WiFi/examples/HTTPSRequestCACertAxTLS/HTTPSRequestCACertAxTLS.ino

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020

2121
// force use of AxTLS (BearSSL is now default)
2222
#include <WiFiClientSecureAxTLS.h>
23-
using namespace AxTLS;
24-
25-
// uncomment the line below to run the sketch
26-
#error Keeping this example for history, watch BearSSL_Validation example instead
23+
using namespace axTLS;
2724

2825
#ifndef STASSID
2926
#define STASSID "your-ssid"

libraries/ESP8266WiFi/src/ESP8266WiFi.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ extern "C" {
3838

3939
#include "WiFiClient.h"
4040
#include "WiFiServer.h"
41-
#include "WiFiServerSecure.h"
42-
#include "WiFiClientSecure.h"
43-
#include "BearSSLHelpers.h"
44-
#include "CertStoreBearSSL.h"
41+
//#include "WiFiServerSecure.h"
42+
//#include "WiFiClientSecure.h"
43+
//#include "BearSSLHelpers.h"
44+
//#include "CertStoreBearSSL.h"
4545

4646
#ifdef DEBUG_ESP_WIFI
4747
#ifdef DEBUG_ESP_PORT

libraries/ESP8266WiFi/src/WiFiClientSecure.h

+9-6
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,21 @@
2020
2121
*/
2222

23-
#include "WiFiClientSecureAxTLS.h"
24-
#include "WiFiClientSecureBearSSL.h"
25-
23+
//#include "WiFiClientSecureAxTLS.h"
2624
//using namespace axTLS;
25+
26+
#include "WiFiClientSecureBearSSL.h"
2727
using namespace BearSSL;
2828

29-
/* !! Now BearSSL is the default !!
29+
/**********************************
30+
* !! Now BearSSL is the default !!
3031
3132
While not advised,
32-
to keep legacy code without updating, use:
33+
Use legacy API without updating with:
3334
35+
//#include <WiFiClientSecure.h>
3436
#include "WiFiClientSecureAxTLS.h"
3537
using namespace axTLS;
3638
37-
*/
39+
*
40+
**********************************/

libraries/ESP8266WiFi/src/WiFiClientSecureAxTLS.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class SSLContext;
3232

3333
class WiFiClientSecure : public WiFiClient {
3434
public:
35-
WiFiClientSecure();
35+
WiFiClientSecure() __attribute__((deprecated("Upgrade to BearSSL is advised, check https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/WiFiClientSecure.h#L25-L99")));
3636
~WiFiClientSecure() override;
3737

3838
int connect(IPAddress ip, uint16_t port) override;

libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.h

+15-4
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,6 @@ class WiFiClientSecure : public WiFiClient {
121121
static bool probeMaxFragmentLength(const char *hostname, uint16_t port, uint16_t len);
122122
static bool probeMaxFragmentLength(const String host, uint16_t port, uint16_t len);
123123

124-
// AXTLS compatible wrappers
125-
// Cannot implement this mode, we need FP before we can connect: bool verify(const char* fingerprint, const char* domain_name)
126-
bool verifyCertChain(const char* domain_name) { (void)domain_name; return connected(); } // If we're connected, the cert passed validation during handshake
127-
128124
bool setCACert(const uint8_t* pk, size_t size);
129125
bool setCertificate(const uint8_t* pk, size_t size);
130126
bool setPrivateKey(const uint8_t* pk, size_t size);
@@ -152,6 +148,21 @@ class WiFiClientSecure : public WiFiClient {
152148
return loadCACert(file, file.size());
153149
}
154150

151+
// AxTLS API deprecated warnings to help upgrading
152+
153+
bool verify(const char* fingerprint, const char* domain_name)
154+
__attribute__((deprecated("This is deprecated AxTLS API, check https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/WiFiClientSecure.h#L25-L99"))) {
155+
(void)fingerprint;
156+
(void)domain_name;
157+
return connected();
158+
}
159+
160+
bool verifyCertChain(const char* domain_name)
161+
__attribute__((deprecated("This is deprecated AxTLS API, check https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/WiFiClientSecure.h#L25-L99"))) {
162+
(void)domain_name;
163+
return connected();
164+
}
165+
155166
private:
156167
void _clear();
157168
void _clearAuthenticationSettings();

libraries/ESP8266WiFi/src/WiFiServerSecureAxTLS.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern "C" {
3030
#include "ESP8266WiFi.h"
3131
#include "WiFiClient.h"
3232
#include "WiFiServer.h"
33+
#include "WiFiClientSecureAxTLS.h"
3334
#include "lwip/opt.h"
3435
#include "lwip/tcp.h"
3536
#include "lwip/inet.h"
@@ -77,7 +78,10 @@ WiFiClientSecure WiFiServerSecure::available(uint8_t* status)
7778
}
7879

7980
optimistic_yield(1000);
81+
#pragma GCC diagnostic push
82+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
8083
return WiFiClientSecure();
84+
#pragma GCC diagnostic pop
8185
}
8286

8387
};

0 commit comments

Comments
 (0)