Skip to content

Commit 63b41bc

Browse files
Use root cert, not fingerprint for api.github.com (#7490)
In the HTTPS example we were using a fingerprint which changes almost daily as the github.com certificates are regenerated. Replace this with a trust anchor based on the ultimate root CA that github.com uses to sign their certificates. Assuming they don't change CAs, this certificate should be good until 2030+ Fixes #7489
1 parent 355b291 commit 63b41bc

File tree

1 file changed

+53
-18
lines changed

1 file changed

+53
-18
lines changed

libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino

+53-18
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77
esp8266/Arduino project continuous integration
88
build.
99
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-
1510
Created by Ivan Grokhotkov, 2015.
1611
This example is in public domain.
1712
*/
@@ -30,14 +25,38 @@ const char* password = STAPSK;
3025
const char* host = "api.github.com";
3126
const int httpsPort = 443;
3227

33-
// Use web browser to view and copy
34-
// SHA1 fingerprint of the certificate
35-
const char fingerprint[] PROGMEM = "5F F1 60 31 09 04 3E F2 90 D2 B0 8A 50 38 04 E8 37 9F BC 76";
28+
// DigiCert High Assurance EV Root CA
29+
const char trustRoot[] PROGMEM = R"EOF(
30+
-----BEGIN CERTIFICATE-----
31+
MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBs
32+
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
33+
d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5j
34+
ZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAwMFoXDTMxMTExMDAwMDAwMFowbDEL
35+
MAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3
36+
LmRpZ2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509List cert(trustRoot);
3655

3756
void setup() {
3857
Serial.begin(115200);
3958
Serial.println();
40-
Serial.print("connecting to ");
59+
Serial.print("Connecting to ");
4160
Serial.println(ssid);
4261
WiFi.mode(WIFI_STA);
4362
WiFi.begin(ssid, password);
@@ -50,33 +69,49 @@ void setup() {
5069
Serial.println("IP address: ");
5170
Serial.println(WiFi.localIP());
5271

72+
// Set time via NTP, as required for x.509 validation
73+
configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");
74+
75+
Serial.print("Waiting for NTP time sync: ");
76+
time_t now = time(nullptr);
77+
while (now < 8 * 3600 * 2) {
78+
delay(500);
79+
Serial.print(".");
80+
now = time(nullptr);
81+
}
82+
Serial.println("");
83+
struct tm timeinfo;
84+
gmtime_r(&now, &timeinfo);
85+
Serial.print("Current time: ");
86+
Serial.print(asctime(&timeinfo));
87+
5388
// Use WiFiClientSecure class to create TLS connection
5489
WiFiClientSecure client;
55-
Serial.print("connecting to ");
90+
Serial.print("Connecting to ");
5691
Serial.println(host);
5792

58-
Serial.printf("Using fingerprint '%s'\n", fingerprint);
59-
client.setFingerprint(fingerprint);
93+
Serial.printf("Using certificate: %s\n", trustRoot);
94+
client.setTrustAnchors(&cert);
6095

6196
if (!client.connect(host, httpsPort)) {
62-
Serial.println("connection failed");
97+
Serial.println("Connection failed");
6398
return;
6499
}
65100

66101
String url = "/repos/esp8266/Arduino/commits/master/status";
67-
Serial.print("requesting URL: ");
102+
Serial.print("Requesting URL: ");
68103
Serial.println(url);
69104

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

75-
Serial.println("request sent");
110+
Serial.println("Request sent");
76111
while (client.connected()) {
77112
String line = client.readStringUntil('\n');
78113
if (line == "\r") {
79-
Serial.println("headers received");
114+
Serial.println("Headers received");
80115
break;
81116
}
82117
}
@@ -86,11 +121,11 @@ void setup() {
86121
} else {
87122
Serial.println("esp8266/Arduino CI has failed");
88123
}
89-
Serial.println("reply was:");
124+
Serial.println("Reply was:");
90125
Serial.println("==========");
91126
Serial.println(line);
92127
Serial.println("==========");
93-
Serial.println("closing connection");
128+
Serial.println("Closing connection");
94129
}
95130

96131
void loop() {

0 commit comments

Comments
 (0)