Skip to content

Commit 2ae0c29

Browse files
Add WiFiServerSecure, a HTTPS enabled web server
Using the standard framework, patch in support for the server mode of axtls. User-supplied X509 certificates and RSA key are used for encryption. Users can generate self-signed certificates or use ones with a real CA. To generate a certificate and key usable under Linux or Windows with OpenSSL tools the following sequence of operations are needed: ...snip... BITS=512 pushd /tmp openssl genrsa -out tls.ca_key.pem $BITS openssl genrsa -out tls.key_$BITS.pem $BITS openssl rsa -in tls.key_$BITS.pem -out tls.key_$BITS -outform DER cat > certs.conf <<EOF [ req ] distinguished_name = req_distinguished_name prompt = no [ req_distinguished_name ] O = your-name-here CN = 127.0.0.1 EOF openssl req -out tls.ca_x509.req -key tls.ca_key.pem -new -config certs.conf openssl req -out tls.x509_$BITS.req -key tls.key_$BITS.pem -new -config certs.conf openssl x509 -req -in tls.ca_x509.req -out tls.ca_x509.pem -sha1 -days 5000 -signkey tls.ca_key.pem openssl x509 -req -in tls.x509_$BITS.req -out tls.x509_$BITS.pem -sha1 -CAcreateserial -days 5000 -CA tls.ca_x509.pem -CAkey tls.ca_key.pem openssl x509 -in tls.ca_x509.pem -outform DER -out tls.ca_x509.cer openssl x509 -in tls.x509_$BITS.pem -outform DER -out tls.x509_$BITS.cer xxd -i tls.key_$BITS xxd -i tls.x509_$BITS.cer popd ...snip...
1 parent 04df3ad commit 2ae0c29

File tree

8 files changed

+402
-1
lines changed

8 files changed

+402
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
/*
2+
* This sketch demonstrates how to set up a simple HTTP-like server using HTTPS encryption.
3+
* A sample self-signed certificate is included. For your own application, please be sure
4+
* to GENERATE YOUR OWN AND REPLACE.
5+
* The server will set a GPIO pin depending on the request
6+
* http://server_ip/gpio/0 will set the GPIO2 low,
7+
* http://server_ip/gpio/1 will set the GPIO2 high
8+
* server_ip is the IP address of the ESP8266 module, will be
9+
* printed to Serial when the module is connected.
10+
*/
11+
12+
#include <ESP8266WiFi.h>
13+
14+
const char* ssid = "your-ssid";
15+
const char* password = "your-password";
16+
17+
// The certificate is stored in PMEM
18+
static const uint8_t x509[] ICACHE_RODATA_ATTR = {
19+
0x30, 0x82, 0x01, 0xc9, 0x30, 0x82, 0x01, 0x32, 0x02, 0x09, 0x00, 0xe6,
20+
0x60, 0x8d, 0xa3, 0x47, 0x8f, 0x57, 0x7a, 0x30, 0x0d, 0x06, 0x09, 0x2a,
21+
0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x29,
22+
0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x0a, 0x70,
23+
0x73, 0x79, 0x63, 0x68, 0x6f, 0x70, 0x6c, 0x75, 0x67, 0x31, 0x12, 0x30,
24+
0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x09, 0x31, 0x32, 0x37, 0x2e,
25+
0x30, 0x2e, 0x30, 0x2e, 0x31, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x37, 0x30,
26+
0x32, 0x32, 0x34, 0x30, 0x38, 0x30, 0x35, 0x33, 0x36, 0x5a, 0x17, 0x0d,
27+
0x33, 0x30, 0x31, 0x31, 0x30, 0x33, 0x30, 0x38, 0x30, 0x35, 0x33, 0x36,
28+
0x5a, 0x30, 0x29, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0a,
29+
0x0c, 0x0a, 0x70, 0x73, 0x79, 0x63, 0x68, 0x6f, 0x70, 0x6c, 0x75, 0x67,
30+
0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x09, 0x31,
31+
0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x30, 0x81, 0x9f, 0x30,
32+
0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
33+
0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81,
34+
0x00, 0xb6, 0x59, 0xd0, 0x57, 0xbc, 0x3e, 0xb9, 0xa0, 0x6c, 0xf5, 0xd5,
35+
0x46, 0x49, 0xaa, 0x9a, 0xb3, 0xbf, 0x09, 0xa9, 0xbb, 0x82, 0x3b, 0xdf,
36+
0xb7, 0xe3, 0x5a, 0x8e, 0x31, 0xf7, 0x27, 0xdf, 0xaa, 0xed, 0xa3, 0xd6,
37+
0xf6, 0x74, 0x35, 0xfc, 0x8d, 0x0b, 0xbc, 0xa2, 0x96, 0x10, 0x57, 0xe8,
38+
0xb2, 0xaa, 0x94, 0xf2, 0x47, 0x12, 0x4e, 0x3f, 0x7c, 0x5e, 0x90, 0xfe,
39+
0xad, 0x75, 0x88, 0xca, 0x7b, 0x9a, 0x18, 0x15, 0xbe, 0x3d, 0xe0, 0x31,
40+
0xb5, 0x45, 0x7f, 0xe7, 0x9d, 0x22, 0x99, 0x65, 0xba, 0x63, 0x70, 0x81,
41+
0x3b, 0x37, 0x22, 0x97, 0x64, 0xc5, 0x57, 0x8c, 0x98, 0x9c, 0x10, 0x36,
42+
0x98, 0xf0, 0x0b, 0x19, 0x28, 0x16, 0x9a, 0x40, 0x31, 0x5f, 0xbc, 0xd9,
43+
0x8e, 0x73, 0x68, 0xe1, 0x6a, 0x5d, 0x91, 0x0b, 0x4f, 0x73, 0xa4, 0x6b,
44+
0x8f, 0xa5, 0xad, 0x12, 0x09, 0x32, 0xa7, 0x66, 0x3b, 0x02, 0x03, 0x01,
45+
0x00, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
46+
0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x81, 0x81, 0x00, 0x1b, 0x46, 0x78,
47+
0xd1, 0xfa, 0x21, 0xc1, 0xd6, 0x75, 0xc0, 0x83, 0x59, 0x57, 0x05, 0xd5,
48+
0xae, 0xf8, 0x8c, 0x78, 0x03, 0x65, 0x3b, 0xbf, 0xef, 0x70, 0x3f, 0x78,
49+
0xc6, 0xe1, 0x5a, 0xac, 0xb1, 0x93, 0x5b, 0x41, 0x35, 0x45, 0x47, 0xf8,
50+
0x07, 0x86, 0x40, 0x34, 0xa2, 0x9e, 0x2a, 0x16, 0x8d, 0xea, 0xf9, 0x1e,
51+
0x1f, 0xd7, 0x70, 0xb4, 0x28, 0x6b, 0xd8, 0xf5, 0x3f, 0x33, 0x3f, 0xc2,
52+
0x2c, 0x69, 0xf2, 0xa3, 0x54, 0x4d, 0xbf, 0x7d, 0xf9, 0xde, 0x05, 0x0c,
53+
0x9c, 0xe3, 0x1b, 0x72, 0x07, 0x7b, 0x41, 0x76, 0x1a, 0x57, 0x03, 0x5d,
54+
0xb2, 0xff, 0x4c, 0x17, 0xbd, 0xd7, 0x73, 0x32, 0x98, 0x26, 0x6b, 0x2c,
55+
0xc4, 0xbf, 0x6e, 0x01, 0x36, 0x8b, 0xbf, 0x00, 0x48, 0x9c, 0xfb, 0x3d,
56+
0x7d, 0x76, 0x1f, 0x55, 0x96, 0x43, 0xc5, 0x4e, 0xc1, 0xa3, 0xa1, 0x6a,
57+
0x94, 0x5f, 0x84, 0x3a, 0xdd
58+
};
59+
60+
// And so is the key. These could also be in DRAM
61+
static const uint8_t rsakey[] ICACHE_RODATA_ATTR = {
62+
0x30, 0x82, 0x02, 0x5c, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xb6,
63+
0x59, 0xd0, 0x57, 0xbc, 0x3e, 0xb9, 0xa0, 0x6c, 0xf5, 0xd5, 0x46, 0x49,
64+
0xaa, 0x9a, 0xb3, 0xbf, 0x09, 0xa9, 0xbb, 0x82, 0x3b, 0xdf, 0xb7, 0xe3,
65+
0x5a, 0x8e, 0x31, 0xf7, 0x27, 0xdf, 0xaa, 0xed, 0xa3, 0xd6, 0xf6, 0x74,
66+
0x35, 0xfc, 0x8d, 0x0b, 0xbc, 0xa2, 0x96, 0x10, 0x57, 0xe8, 0xb2, 0xaa,
67+
0x94, 0xf2, 0x47, 0x12, 0x4e, 0x3f, 0x7c, 0x5e, 0x90, 0xfe, 0xad, 0x75,
68+
0x88, 0xca, 0x7b, 0x9a, 0x18, 0x15, 0xbe, 0x3d, 0xe0, 0x31, 0xb5, 0x45,
69+
0x7f, 0xe7, 0x9d, 0x22, 0x99, 0x65, 0xba, 0x63, 0x70, 0x81, 0x3b, 0x37,
70+
0x22, 0x97, 0x64, 0xc5, 0x57, 0x8c, 0x98, 0x9c, 0x10, 0x36, 0x98, 0xf0,
71+
0x0b, 0x19, 0x28, 0x16, 0x9a, 0x40, 0x31, 0x5f, 0xbc, 0xd9, 0x8e, 0x73,
72+
0x68, 0xe1, 0x6a, 0x5d, 0x91, 0x0b, 0x4f, 0x73, 0xa4, 0x6b, 0x8f, 0xa5,
73+
0xad, 0x12, 0x09, 0x32, 0xa7, 0x66, 0x3b, 0x02, 0x03, 0x01, 0x00, 0x01,
74+
0x02, 0x81, 0x81, 0x00, 0xa8, 0x55, 0xf9, 0x33, 0x45, 0x20, 0x52, 0x94,
75+
0x7a, 0x81, 0xe6, 0xc4, 0xe0, 0x34, 0x92, 0x63, 0xe4, 0xb3, 0xb2, 0xf0,
76+
0xda, 0xa5, 0x13, 0x3d, 0xda, 0xb0, 0x3a, 0x1c, 0x7e, 0x21, 0x5d, 0x25,
77+
0x9a, 0x03, 0x69, 0xea, 0x52, 0x15, 0x94, 0x73, 0x50, 0xa6, 0x6f, 0x21,
78+
0x41, 0x2d, 0x26, 0x2f, 0xe9, 0xb1, 0x5e, 0x87, 0xa5, 0xaa, 0x7e, 0x88,
79+
0xfd, 0x73, 0xb4, 0xe7, 0xc4, 0x5c, 0xe7, 0x2d, 0xeb, 0x9e, 0x6b, 0xe1,
80+
0xf1, 0x38, 0x45, 0xf4, 0x10, 0x12, 0xac, 0x79, 0x40, 0x72, 0xf0, 0x45,
81+
0x89, 0x5c, 0x9d, 0x8b, 0x7b, 0x5d, 0x69, 0xd9, 0x11, 0xf9, 0x25, 0xff,
82+
0xe1, 0x2a, 0xb3, 0x6d, 0x49, 0x18, 0x8d, 0x38, 0x0a, 0x6f, 0x0f, 0xbd,
83+
0x48, 0xd0, 0xdd, 0xcb, 0x41, 0x5c, 0x2a, 0x75, 0xa0, 0x51, 0x43, 0x4a,
84+
0x0b, 0xf6, 0xa2, 0xd2, 0xe9, 0xda, 0x37, 0xca, 0x2d, 0xd7, 0x22, 0x01,
85+
0x02, 0x41, 0x00, 0xe7, 0x11, 0xea, 0x93, 0xf4, 0x0b, 0xe6, 0xa0, 0x1a,
86+
0x57, 0x2d, 0xee, 0x96, 0x05, 0x5c, 0xa1, 0x08, 0x8f, 0x9c, 0xac, 0x9a,
87+
0x72, 0x60, 0x5a, 0x41, 0x2a, 0x92, 0x38, 0x36, 0xa5, 0xfe, 0xb9, 0x35,
88+
0xb2, 0x06, 0xbb, 0x02, 0x58, 0xc8, 0x93, 0xd6, 0x09, 0x6f, 0x57, 0xd7,
89+
0xc1, 0x2e, 0x90, 0xb3, 0x09, 0xdd, 0x0c, 0x63, 0x99, 0x91, 0xb7, 0xe4,
90+
0xcc, 0x6f, 0x78, 0x24, 0xbc, 0x3b, 0x7b, 0x02, 0x41, 0x00, 0xca, 0x06,
91+
0x4a, 0x09, 0x36, 0x08, 0xaa, 0x27, 0x08, 0x91, 0x86, 0xc5, 0x17, 0x14,
92+
0x6e, 0x24, 0x9a, 0x86, 0xd1, 0xbc, 0x41, 0xb1, 0x42, 0x5e, 0xe8, 0x80,
93+
0x5a, 0x8f, 0x7c, 0x9b, 0xe8, 0xcc, 0x28, 0xe1, 0xa2, 0x8f, 0xe9, 0xdc,
94+
0x60, 0xd5, 0x00, 0x34, 0x76, 0x32, 0x36, 0x00, 0x93, 0x69, 0x6b, 0xab,
95+
0xc6, 0x8b, 0x70, 0x95, 0x4e, 0xc2, 0x27, 0x4a, 0x24, 0x73, 0xbf, 0xcd,
96+
0x24, 0x41, 0x02, 0x40, 0x40, 0x46, 0x75, 0x90, 0x0e, 0x54, 0xb9, 0x24,
97+
0x53, 0xef, 0x68, 0x31, 0x73, 0xbd, 0xae, 0x14, 0x85, 0x43, 0x1d, 0x7b,
98+
0xcd, 0xc2, 0x7f, 0x16, 0xdc, 0x05, 0xb1, 0x82, 0xbd, 0x80, 0xd3, 0x28,
99+
0x45, 0xcd, 0x6d, 0x9d, 0xdb, 0x7b, 0x42, 0xe0, 0x0c, 0xab, 0xb7, 0x33,
100+
0x22, 0x2a, 0xf4, 0x7e, 0xff, 0xae, 0x80, 0xb4, 0x8f, 0x88, 0x0a, 0x46,
101+
0xb2, 0xf8, 0x43, 0x11, 0x92, 0x76, 0x61, 0xbd, 0x02, 0x40, 0x5c, 0x86,
102+
0x3a, 0xdc, 0x33, 0x1a, 0x0e, 0xcb, 0xa7, 0xb9, 0xf6, 0xae, 0x47, 0x5e,
103+
0xbc, 0xff, 0x18, 0xa2, 0x8c, 0x66, 0x1a, 0xf4, 0x13, 0x00, 0xa2, 0x9d,
104+
0x3e, 0x5c, 0x9e, 0xe6, 0x4c, 0xdd, 0x4c, 0x0f, 0xe2, 0xc2, 0xe4, 0x89,
105+
0x60, 0xf3, 0xcc, 0x8f, 0x3a, 0x5e, 0xce, 0xaa, 0xbe, 0xd8, 0xb6, 0x4e,
106+
0x4a, 0xb5, 0x4c, 0x0f, 0xa5, 0xad, 0x78, 0x0f, 0x15, 0xd8, 0xc9, 0x4c,
107+
0x2b, 0xc1, 0x02, 0x40, 0x4e, 0xe9, 0x78, 0x48, 0x94, 0x11, 0x75, 0xc1,
108+
0xa2, 0xc7, 0xff, 0xf0, 0x73, 0xa2, 0x93, 0xd7, 0x67, 0xc7, 0xf8, 0x96,
109+
0xac, 0x15, 0xaa, 0xe5, 0x5d, 0x18, 0x18, 0x29, 0xa9, 0x9a, 0xfc, 0xac,
110+
0x48, 0x4d, 0xa0, 0xca, 0xa2, 0x34, 0x09, 0x7c, 0x13, 0x22, 0x4c, 0xfc,
111+
0x31, 0x75, 0xa0, 0x21, 0x1e, 0x7a, 0x91, 0xbc, 0xb1, 0x97, 0xde, 0x43,
112+
0xe1, 0x40, 0x2b, 0xe3, 0xbd, 0x98, 0x44, 0xad
113+
};
114+
115+
116+
117+
// Create an instance of the server
118+
// specify the port to listen on as an argument
119+
WiFiServerSecure server(443);
120+
121+
void setup() {
122+
Serial.begin(115200);
123+
delay(10);
124+
125+
// prepare GPIO2
126+
pinMode(2, OUTPUT);
127+
digitalWrite(2, 0);
128+
129+
// Connect to WiFi network
130+
Serial.println();
131+
Serial.println();
132+
Serial.print("Connecting to ");
133+
Serial.println(ssid);
134+
135+
WiFi.begin(ssid, password);
136+
137+
while (WiFi.status() != WL_CONNECTED) {
138+
delay(500);
139+
Serial.print(".");
140+
}
141+
Serial.println("");
142+
Serial.println("WiFi connected");
143+
144+
// Set the certificates from PMEM (if using DRAM remove the _P from the call)
145+
server.setServerKeyAndCert_P(rsakey, sizeof(rsakey), x509, sizeof(x509));
146+
147+
// Start the server
148+
server.begin();
149+
Serial.println("Server started");
150+
151+
// Print the IP address
152+
Serial.println(WiFi.localIP());
153+
}
154+
155+
void loop() {
156+
// Check if a client has connected
157+
WiFiClientSecure client = server.available();
158+
if (!client) {
159+
return;
160+
}
161+
162+
// Wait until the client sends some data
163+
Serial.println("new client");
164+
unsigned long timeout = millis() + 3000;
165+
while(!client.available() && millis() < timeout){
166+
delay(1);
167+
}
168+
if (millis() > timeout) {
169+
Serial.println("timeout");
170+
client.flush();
171+
client.stop();
172+
return;
173+
}
174+
175+
// Read the first line of the request
176+
String req = client.readStringUntil('\r');
177+
Serial.println(req);
178+
client.flush();
179+
180+
// Match the request
181+
int val;
182+
if (req.indexOf("/gpio/0") != -1)
183+
val = 0;
184+
else if (req.indexOf("/gpio/1") != -1)
185+
val = 1;
186+
else {
187+
Serial.println("invalid request");
188+
client.stop();
189+
return;
190+
}
191+
192+
// Set GPIO2 according to the request
193+
digitalWrite(2, val);
194+
195+
client.flush();
196+
197+
// Prepare the response
198+
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
199+
s += (val)?"high":"low";
200+
s += "</html>\n";
201+
202+
// Send the response to the client
203+
client.print(s);
204+
delay(1);
205+
Serial.println("Client disonnected");
206+
207+
// The client will actually be disconnected
208+
// when the function returns and 'client' object is detroyed
209+
}
210+

libraries/ESP8266WiFi/keywords.txt

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ESP8266WiFi KEYWORD3
1515
WiFi KEYWORD1
1616
WiFiClient KEYWORD1
1717
WiFiServer KEYWORD1
18+
WiFiServerSecure KEYWORD1
1819
WiFiUDP KEYWORD1
1920
WiFiClientSecure KEYWORD1
2021

libraries/ESP8266WiFi/src/ESP8266WiFi.h

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ extern "C" {
3838

3939
#include "WiFiClient.h"
4040
#include "WiFiServer.h"
41+
#include "WiFiServerSecure.h"
4142
#include "WiFiClientSecure.h"
4243

4344
#ifdef DEBUG_ESP_WIFI

libraries/ESP8266WiFi/src/WiFiClientSecure.cpp

+64-1
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,32 @@ class SSLContext
103103
}
104104
}
105105

106+
void connectServer(ClientContext *ctx) {
107+
s_io_ctx = ctx;
108+
_ssl = ssl_server_new(_ssl_ctx, 0);
109+
_isServer = true;
110+
111+
int timeout_ms = 5000;
112+
uint32_t t = millis();
113+
114+
while (millis() - t < timeout_ms && ssl_handshake_status(_ssl) != SSL_OK) {
115+
uint8_t* data;
116+
int rc = ssl_read(_ssl, &data);
117+
if (rc < SSL_OK) {
118+
break;
119+
}
120+
}
121+
}
122+
106123
void stop()
107124
{
108125
s_io_ctx = nullptr;
109126
}
110127

111128
bool connected()
112129
{
113-
return _ssl != nullptr && ssl_handshake_status(_ssl) == SSL_OK;
130+
if (_isServer) return _ssl != nullptr;
131+
else return _ssl != nullptr && ssl_handshake_status(_ssl) == SSL_OK;
114132
}
115133

116134
int read(uint8_t* dst, size_t size)
@@ -218,6 +236,14 @@ class SSLContext
218236
return s_io_ctx;
219237
}
220238

239+
int loadServerX509Cert(const uint8_t *cert, int len) {
240+
return ssl_obj_memory_load(SSLContext::_ssl_ctx, SSL_OBJ_X509_CERT, cert, len, NULL);
241+
}
242+
243+
int loadServerRSAKey(const uint8_t *rsakey, int len) {
244+
return ssl_obj_memory_load(SSLContext::_ssl_ctx, SSL_OBJ_RSA_KEY, rsakey, len, NULL);
245+
}
246+
221247
protected:
222248
int _readAll()
223249
{
@@ -242,6 +268,7 @@ class SSLContext
242268
return _available;
243269
}
244270

271+
bool _isServer = false;
245272
static SSL_CTX* _ssl_ctx;
246273
static int _ssl_ctx_refcnt;
247274
SSL* _ssl = nullptr;
@@ -285,6 +312,42 @@ WiFiClientSecure& WiFiClientSecure::operator=(const WiFiClientSecure& rhs)
285312
return *this;
286313
}
287314

315+
// Only called by the WifiServerSecure, need to get the keys/certs loaded before beginning
316+
WiFiClientSecure::WiFiClientSecure(ClientContext* client, bool usePMEM, const uint8_t *rsakey, int rsakeyLen, const uint8_t *cert, int certLen)
317+
{
318+
_client = client;
319+
if (_ssl) {
320+
_ssl->unref();
321+
_ssl = nullptr;
322+
}
323+
324+
_ssl = new SSLContext;
325+
_ssl->ref();
326+
327+
if (usePMEM) {
328+
// When using PMEM based certs, allocate stack and copy from flash to DRAM, call SSL functions to avoid
329+
// heap fragmentation that would happen w/malloc()
330+
uint8_t *stackData = (uint8_t*)alloca(max(certLen, rsakeyLen));
331+
if (rsakey && rsakeyLen) {
332+
memcpy_P(stackData, rsakey, rsakeyLen);
333+
_ssl->loadServerRSAKey(stackData, rsakeyLen);
334+
}
335+
if (cert && certLen) {
336+
memcpy_P(stackData, cert, certLen);
337+
_ssl->loadServerX509Cert(stackData, certLen);
338+
}
339+
} else {
340+
if (rsakey && rsakeyLen) {
341+
_ssl->loadServerRSAKey(rsakey, rsakeyLen);
342+
}
343+
if (cert && certLen) {
344+
_ssl->loadServerX509Cert(cert, certLen);
345+
}
346+
}
347+
_client->ref();
348+
_ssl->connectServer(client);
349+
}
350+
288351
int WiFiClientSecure::connect(IPAddress ip, uint16_t port)
289352
{
290353
if (!WiFiClient::connect(ip, port)) {

libraries/ESP8266WiFi/src/WiFiClientSecure.h

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class WiFiClientSecure : public WiFiClient {
3434
~WiFiClientSecure() override;
3535
WiFiClientSecure(const WiFiClientSecure&);
3636
WiFiClientSecure& operator=(const WiFiClientSecure&);
37+
// Only called by WiFiServerSecure
38+
WiFiClientSecure(ClientContext* client, bool usePMEM, const uint8_t *rsakey, int rsakeyLen, const uint8_t *cert, int certLen);
3739

3840
int connect(IPAddress ip, uint16_t port) override;
3941
int connect(const char* name, uint16_t port) override;

libraries/ESP8266WiFi/src/WiFiServer.h

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class ClientContext;
3535
class WiFiClient;
3636

3737
class WiFiServer : public Server {
38+
// Secure server needs access to all the private entries here
39+
friend class WiFiServerSecure;
40+
3841
private:
3942
uint16_t _port;
4043
IPAddress _addr;

0 commit comments

Comments
 (0)