88#include < WiFiClientSecure.h>
99#include < StackThunk.h>
1010#include < time.h>
11+ #include " certs.h"
1112
1213#ifndef STASSID
1314#define STASSID " your-ssid"
1718const char *ssid = STASSID;
1819const char *pass = STAPSK;
1920
20- const char * host = " api.github.com" ;
21- const uint16_t port = 443 ;
2221const char * path = " /" ;
2322
2423// Set time via NTP, as required for x.509 validation
@@ -92,7 +91,7 @@ If there are no CAs or insecure options specified, BearSSL will not connect.
9291Expect the following call to fail as none have been configured.
9392)EOF" );
9493 BearSSL::WiFiClientSecure client;
95- fetchURL (&client, host, port , path);
94+ fetchURL (&client, gitlab_host, gitlab_port , path);
9695}
9796
9897void fetchInsecure () {
@@ -103,7 +102,7 @@ which is subject to man-in-the-middle (MITM) attacks.
103102)EOF" );
104103 BearSSL::WiFiClientSecure client;
105104 client.setInsecure ();
106- fetchURL (&client, host, port , path);
105+ fetchURL (&client, gitlab_host, gitlab_port , path);
107106}
108107
109108void fetchFingerprint () {
@@ -116,9 +115,8 @@ fingerprints will change if anything changes in the certificate chain
116115the root authorities, etc.).
117116)EOF" );
118117 BearSSL::WiFiClientSecure client;
119- static const char fp[] PROGMEM = " 59:74:61:88:13:CA:12:34:15:4D:11:0A:C1:7F:E6:67:07:69:42:F5" ;
120- client.setFingerprint (fp);
121- fetchURL (&client, host, port, path);
118+ client.setFingerprint (fingerprint_gitlab_com);
119+ fetchURL (&client, gitlab_host, gitlab_port, path);
122120}
123121
124122void fetchSelfSigned () {
@@ -142,51 +140,13 @@ needs to be paired with the private key of the site, which is obviously
142140private and not shared. A MITM without the private key would not be
143141able to establish communications.
144142)EOF" );
145- // Extracted by: openssl x509 -pubkey -noout -in servercert.pem
146- static const char pubkey[] PROGMEM = R"KEY(
147- -----BEGIN PUBLIC KEY-----
148- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy+3Up8qBkIn/7S9AfWlH
149- Od8SdXmnWx+JCIHvnWzjFcLeLvQb2rMqqCDL5XDlvkyC5SZ8ZyLITemej5aJYuBv
150- zcKPzyZ0QfYZiskU9nzL2qBQj8alzJJ/Cc32AWuuWrPrzVxBmOEW9gRCGFCD3m0z
151- 53y6GjcmBS2wcX7RagqbD7g2frEGko4G7kmW96H6dyh2j9Rou8TwAK6CnbiXPAM/
152- 5Q6dyfdYlHOCgP75F7hhdKB5gpprm9A/OnQsmZjUPzy4u0EKCxE8MfhBerZrZdod
153- 88ZdDG3CvTgm050bc+lGlbsT+s09lp0dgxSZIeI8+syV2Owt4YF/PdjeeymtzQdI
154- wQIDAQAB
155- -----END PUBLIC KEY-----
156- )KEY" ;
157143 BearSSL::WiFiClientSecure client;
158- BearSSL::PublicKey key (pubkey );
144+ BearSSL::PublicKey key (pubkey_gitlab_com );
159145 client.setKnownKey (&key);
160- fetchURL (&client, host, port , path);
146+ fetchURL (&client, gitlab_host, gitlab_port , path);
161147}
162148
163149void fetchCertAuthority () {
164- static const char digicert[] PROGMEM = R"EOF(
165- -----BEGIN CERTIFICATE-----
166- MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBs
167- MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
168- d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5j
169- ZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAwMFoXDTMxMTExMDAwMDAwMFowbDEL
170- MAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3
171- LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFuY2Ug
172- RVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm
173- +9S75S0tMqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTW
174- PNt0OKRKzE0lgvdKpVMSOO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEM
175- xChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFB
176- Ik5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQNAQTXKFx01p8VdteZOE3
177- hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUeh10aUAsg
178- EsxBu24LUTi4S8sCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQF
179- MAMBAf8wHQYDVR0OBBYEFLE+w2kD+L9HAdSYJhoIAu9jZCvDMB8GA1UdIwQYMBaA
180- FLE+w2kD+L9HAdSYJhoIAu9jZCvDMA0GCSqGSIb3DQEBBQUAA4IBAQAcGgaX3Nec
181- nzyIZgYIVyHbIUf4KmeqvxgydkAQV8GK83rZEWWONfqe/EW1ntlMMUu4kehDLI6z
182- eM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFpmyPInngiK3BD41VHMWEZ71jF
183- hS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkKmNEVX58Svnw2
184- Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe
185- vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep
186- +OkuE6N36B9K
187- -----END CERTIFICATE-----
188- )EOF" ;
189-
190150 Serial.printf (R"EOF(
191151A specific certification authority can be passed in and used to validate
192152a chain of certificates from a given server. These will be validated
@@ -197,14 +157,14 @@ BearSSL does verify the notValidBefore/After fields.
197157)EOF" );
198158
199159 BearSSL::WiFiClientSecure client;
200- BearSSL::X509List cert (digicert );
160+ BearSSL::X509List cert (cert_USERTrust_RSA_Certification_Authority );
201161 client.setTrustAnchors (&cert);
202162 Serial.printf (" Try validating without setting the time (should fail)\n " );
203- fetchURL (&client, host, port , path);
163+ fetchURL (&client, gitlab_host, gitlab_port , path);
204164
205165 Serial.printf (" Try again after setting NTP time (should pass)\n " );
206166 setClock ();
207- fetchURL (&client, host, port , path);
167+ fetchURL (&client, gitlab_host, gitlab_port , path);
208168}
209169
210170void fetchFaster () {
@@ -217,18 +177,18 @@ may make sense
217177 BearSSL::WiFiClientSecure client;
218178 client.setInsecure ();
219179 uint32_t now = millis ();
220- fetchURL (&client, host, port , path);
180+ fetchURL (&client, gitlab_host, gitlab_port , path);
221181 uint32_t delta = millis () - now;
222182 client.setInsecure ();
223183 client.setCiphersLessSecure ();
224184 now = millis ();
225- fetchURL (&client, host, port , path);
185+ fetchURL (&client, gitlab_host, gitlab_port , path);
226186 uint32_t delta2 = millis () - now;
227187 std::vector<uint16_t > myCustomList = { BR_TLS_RSA_WITH_AES_256_CBC_SHA256, BR_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, BR_TLS_RSA_WITH_3DES_EDE_CBC_SHA };
228188 client.setInsecure ();
229189 client.setCiphers (myCustomList);
230190 now = millis ();
231- fetchURL (&client, host, port , path);
191+ fetchURL (&client, gitlab_host, gitlab_port , path);
232192 uint32_t delta3 = millis () - now;
233193 Serial.printf (" Using more secure: %dms\n Using less secure ciphers: %dms\n Using custom cipher list: %dms\n " , delta, delta2, delta3);
234194}
0 commit comments