From d5aa959525813f9defe3348361cd7d97f2b394c3 Mon Sep 17 00:00:00 2001 From: brentru Date: Mon, 20 May 2019 11:20:45 -0400 Subject: [PATCH] adding ssl fingerprint verification to comply with bearssl in esp8266 bsp 2.5.1 --- .../adafruitio_secure_esp8266.ino | 32 ++----------------- library.properties | 2 +- 2 files changed, 3 insertions(+), 31 deletions(-) diff --git a/examples/adafruitio_secure_esp8266/adafruitio_secure_esp8266.ino b/examples/adafruitio_secure_esp8266/adafruitio_secure_esp8266.ino index 3d0c159..323d772 100644 --- a/examples/adafruitio_secure_esp8266/adafruitio_secure_esp8266.ino +++ b/examples/adafruitio_secure_esp8266/adafruitio_secure_esp8266.ino @@ -44,7 +44,7 @@ WiFiClientSecure client; Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY); // io.adafruit.com SHA1 fingerprint -const char *fingerprint = "77 00 54 2D DA E7 D8 03 27 31 23 99 EB 27 DB CB A5 4C 57 18"; +static const char *fingerprint PROGMEM = "77 00 54 2D DA E7 D8 03 27 31 23 99 EB 27 DB CB A5 4C 57 18"; /****************************** Feeds ***************************************/ @@ -54,11 +54,6 @@ Adafruit_MQTT_Publish test = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/t /*************************** Sketch Code ************************************/ -// Bug workaround for Arduino 1.6.6, it seems to need a function declaration -// for some reason (only affects ESP8266, likely an arduino-builder bug). -void MQTT_connect(); -void verifyFingerprint(); - void setup() { Serial.begin(115200); delay(10); @@ -85,8 +80,7 @@ void setup() { Serial.println("IP address: "); Serial.println(WiFi.localIP()); // check the fingerprint of io.adafruit.com's SSL cert - verifyFingerprint(); - + client.setFingerprint(fingerprint); } uint32_t x=0; @@ -112,28 +106,6 @@ void loop() { } - -void verifyFingerprint() { - - const char* host = AIO_SERVER; - - Serial.print("Connecting to "); - Serial.println(host); - - if (! client.connect(host, AIO_SERVERPORT)) { - Serial.println("Connection failed. Halting execution."); - while(1); - } - - if (client.verify(fingerprint, host)) { - Serial.println("Connection secure."); - } else { - Serial.println("Connection insecure! Halting execution."); - while(1); - } - -} - // Function to connect and reconnect as necessary to the MQTT server. // Should be called in the loop function and it will take care if connecting. void MQTT_connect() { diff --git a/library.properties b/library.properties index 8cd00b7..81f1d21 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Adafruit MQTT Library -version=1.0.1 +version=1.0.2 author=Adafruit maintainer=Adafruit sentence=MQTT library that supports the FONA, ESP8266, Yun, and generic Arduino Client hardware.