1
1
/* For any secure connection - it is (at least) essential for the
2
2
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.
4
4
5
5
See https://en.wikipedia.org/wiki/Man-in-the-middle_attack,
6
6
https://www.ai.rug.nl/mas/finishedprojects/2011/TLS/hermsencomputerservices.nl/mas/mitm.html or
50
50
51
51
const char * ssid = WIFI_NETWORK; // your network SSID (name of wifi network)
52
52
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.
54
54
55
55
const int TOFU_RESET_BUTTON = 35 ; /* Trust reset button wired between GPIO 35 and GND (pulldown) */
56
56
@@ -60,8 +60,7 @@ const int TOFU_RESET_BUTTON = 35; /* Trust reset button wired between GPIO 35 an
60
60
/* Set aside some persistant memory (i.e. memory that is preserved on reboots and
61
61
power cycling; and will generally survive software updates as well.
62
62
*/
63
- EEPROMClass TOFU (" tofu0" );
64
-
63
+ EEPROMClass TOFU (" tofu0" );
65
64
66
65
// Utility function; checks if a given buffer is entirly
67
66
// with with 0 bytes over its full length. Returns 0 on
@@ -71,6 +70,7 @@ static int memcmpzero(unsigned char * ptr, size_t len) {
71
70
while (len--) if (0xff != *ptr++) return -1 ;
72
71
return 0 ;
73
72
};
73
+
74
74
static void printSHA256 (unsigned char * ptr) {
75
75
for (int i = 0 ; i < 32 ; i++) Serial.printf (" %s%02x" , i ? " :" : " " , ptr[i]);
76
76
Serial.println (" " );
@@ -170,7 +170,7 @@ bool get_tofu() {
170
170
// verification.
171
171
const mbedtls_x509_crt* peer = client.getPeerCertificate ();
172
172
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);
174
174
if (l <= 0 ) {
175
175
Serial.println (" Peer conversion to printable buffer failed" );
176
176
client.stop ();
@@ -210,7 +210,6 @@ bool doTOFU_Protected_Connection(uint8_t * fingerprint_tofu) {
210
210
// As we're not using a (CA) certificate to check the
211
211
// connection; but the hash of the peer - we need to initially
212
212
// allow the connection to be set up without the CA check.
213
- //
214
213
client.setInsecure ();// skip verification
215
214
216
215
if (!client.connect (server, 443 )) {
@@ -223,7 +222,6 @@ bool doTOFU_Protected_Connection(uint8_t * fingerprint_tofu) {
223
222
// end to end trust - by comparing the fingerprint we (now)
224
223
// see (of the server certificate) to the one we have stored
225
224
// in our EEPROM as part of an earlier trust-on-first use.
226
- //
227
225
uint8_t fingerprint_remote[32 ];
228
226
if (!client.getFingerprintSHA256 (fingerprint_remote)) {
229
227
Serial.println (" Failed to get the fingerprint of the server" );
0 commit comments