8
8
#include < WiFiClientSecure.h>
9
9
#include < StackThunk.h>
10
10
#include < time.h>
11
+ #include " certs.h"
11
12
12
13
#ifndef STASSID
13
14
#define STASSID " your-ssid"
17
18
const char *ssid = STASSID;
18
19
const char *pass = STAPSK;
19
20
20
- const char * host = " api.github.com" ;
21
- const uint16_t port = 443 ;
22
21
const char * path = " /" ;
23
22
24
23
// 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.
92
91
Expect the following call to fail as none have been configured.
93
92
)EOF" );
94
93
BearSSL::WiFiClientSecure client;
95
- fetchURL (&client, host, port , path);
94
+ fetchURL (&client, gitlab_host, gitlab_port , path);
96
95
}
97
96
98
97
void fetchInsecure () {
@@ -103,7 +102,7 @@ which is subject to man-in-the-middle (MITM) attacks.
103
102
)EOF" );
104
103
BearSSL::WiFiClientSecure client;
105
104
client.setInsecure ();
106
- fetchURL (&client, host, port , path);
105
+ fetchURL (&client, gitlab_host, gitlab_port , path);
107
106
}
108
107
109
108
void fetchFingerprint () {
@@ -116,9 +115,8 @@ fingerprints will change if anything changes in the certificate chain
116
115
the root authorities, etc.).
117
116
)EOF" );
118
117
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);
122
120
}
123
121
124
122
void fetchSelfSigned () {
@@ -142,51 +140,13 @@ needs to be paired with the private key of the site, which is obviously
142
140
private and not shared. A MITM without the private key would not be
143
141
able to establish communications.
144
142
)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" ;
157
143
BearSSL::WiFiClientSecure client;
158
- BearSSL::PublicKey key (pubkey );
144
+ BearSSL::PublicKey key (pubkey_gitlab_com );
159
145
client.setKnownKey (&key);
160
- fetchURL (&client, host, port , path);
146
+ fetchURL (&client, gitlab_host, gitlab_port , path);
161
147
}
162
148
163
149
void 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
-
190
150
Serial.printf (R"EOF(
191
151
A specific certification authority can be passed in and used to validate
192
152
a chain of certificates from a given server. These will be validated
@@ -197,14 +157,14 @@ BearSSL does verify the notValidBefore/After fields.
197
157
)EOF" );
198
158
199
159
BearSSL::WiFiClientSecure client;
200
- BearSSL::X509List cert (digicert );
160
+ BearSSL::X509List cert (cert_USERTrust_RSA_Certification_Authority );
201
161
client.setTrustAnchors (&cert);
202
162
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);
204
164
205
165
Serial.printf (" Try again after setting NTP time (should pass)\n " );
206
166
setClock ();
207
- fetchURL (&client, host, port , path);
167
+ fetchURL (&client, gitlab_host, gitlab_port , path);
208
168
}
209
169
210
170
void fetchFaster () {
@@ -217,18 +177,18 @@ may make sense
217
177
BearSSL::WiFiClientSecure client;
218
178
client.setInsecure ();
219
179
uint32_t now = millis ();
220
- fetchURL (&client, host, port , path);
180
+ fetchURL (&client, gitlab_host, gitlab_port , path);
221
181
uint32_t delta = millis () - now;
222
182
client.setInsecure ();
223
183
client.setCiphersLessSecure ();
224
184
now = millis ();
225
- fetchURL (&client, host, port , path);
185
+ fetchURL (&client, gitlab_host, gitlab_port , path);
226
186
uint32_t delta2 = millis () - now;
227
187
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 };
228
188
client.setInsecure ();
229
189
client.setCiphers (myCustomList);
230
190
now = millis ();
231
- fetchURL (&client, host, port , path);
191
+ fetchURL (&client, gitlab_host, gitlab_port , path);
232
192
uint32_t delta3 = millis () - now;
233
193
Serial.printf (" Using more secure: %dms\n Using less secure ciphers: %dms\n Using custom cipher list: %dms\n " , delta, delta2, delta3);
234
194
}
0 commit comments