Skip to content

Commit da537c7

Browse files
committed
Merge branch 'feat_tofu' of github.com:dirkx/arduino-esp31 into feat_tofu
2 parents fd2d0f4 + e529fa9 commit da537c7

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

libraries/WiFiClientSecure/examples/WiFiClientInsecure/WiFiClientInsecure.ino

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#include <WiFiClientSecure.h>
22

33
/* This is a very INSECURE approach.
4-
*
54
* If for some reason the secure, proper example WiFiClientSecure
6-
* does not work for you; then you may want to * check the
7-
* WiFiClientTrustOnFirstUse first. It * is less secure than WiFiClientSecure,
8-
* but a lot better than this totally insecure approach shown below.
9-
*
5+
* does not work for you; then you may want to check the
6+
* WiFiClientTrustOnFirstUse example first. It is less secure than
7+
* WiFiClientSecure, but a lot better than this totally insecure
8+
* approach shown below.
109
*/
1110

1211
const char* ssid = "your-ssid"; // your network SSID (name of wifi network)

libraries/WiFiClientSecure/examples/WiFiClientTrustOnFirstUse/WiFiClientTrustOnFirstUse.ino

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* For any secure connection - it is (at least) essential for the
22
the client to verify that it is talking with the server it
3-
things it is talking to. And not some (invisible) man in the middle.
3+
thinks it is talking to. And not some (invisible) man in the middle.
44
55
See https://en.wikipedia.org/wiki/Man-in-the-middle_attack,
66
https://www.ai.rug.nl/mas/finishedprojects/2011/TLS/hermsencomputerservices.nl/mas/mitm.html or
@@ -50,7 +50,7 @@
5050

5151
const char* ssid = WIFI_NETWORK; // your network SSID (name of wifi network)
5252
const char* password = WIFI_PASSWD; // your network password
53-
const char* server = "www.howsmyssl.com"; // Server to test with.
53+
const char* server = "www.howsmyssl.com"; // Server to test with.
5454

5555
const int TOFU_RESET_BUTTON = 35; /* Trust reset button wired between GPIO 35 and GND (pulldown) */
5656

@@ -60,8 +60,7 @@ const int TOFU_RESET_BUTTON = 35; /* Trust reset button wired between GPIO 35 an
6060
/* Set aside some persistant memory (i.e. memory that is preserved on reboots and
6161
power cycling; and will generally survive software updates as well.
6262
*/
63-
EEPROMClass TOFU("tofu0");
64-
63+
EEPROMClass TOFU("tofu0");
6564

6665
// Utility function; checks if a given buffer is entirly
6766
// with with 0 bytes over its full length. Returns 0 on
@@ -71,6 +70,7 @@ static int memcmpzero(unsigned char * ptr, size_t len) {
7170
while (len--) if (0xff != *ptr++) return -1;
7271
return 0;
7372
};
73+
7474
static void printSHA256(unsigned char * ptr) {
7575
for (int i = 0; i < 32; i++) Serial.printf("%s%02x", i ? ":" : "", ptr[i]);
7676
Serial.println("");
@@ -170,7 +170,7 @@ bool get_tofu() {
170170
// verification.
171171
const mbedtls_x509_crt* peer = client.getPeerCertificate();
172172
char buf[1024];
173-
int l = mbedtls_x509_crt_info (buf, sizeof(buf), "", peer);
173+
int l = mbedtls_x509_crt_info(buf, sizeof(buf), "", peer);
174174
if (l <= 0) {
175175
Serial.println("Peer conversion to printable buffer failed");
176176
client.stop();
@@ -210,7 +210,6 @@ bool doTOFU_Protected_Connection(uint8_t * fingerprint_tofu) {
210210
// As we're not using a (CA) certificate to check the
211211
// connection; but the hash of the peer - we need to initially
212212
// allow the connection to be set up without the CA check.
213-
//
214213
client.setInsecure();//skip verification
215214

216215
if (!client.connect(server, 443)) {
@@ -223,7 +222,6 @@ bool doTOFU_Protected_Connection(uint8_t * fingerprint_tofu) {
223222
// end to end trust - by comparing the fingerprint we (now)
224223
// see (of the server certificate) to the one we have stored
225224
// in our EEPROM as part of an earlier trust-on-first use.
226-
//
227225
uint8_t fingerprint_remote[32];
228226
if (!client.getFingerprintSHA256(fingerprint_remote)) {
229227
Serial.println("Failed to get the fingerprint of the server");

0 commit comments

Comments
 (0)