Skip to content

Commit

Permalink
ESP8266 authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
shurillu committed Oct 4, 2024
1 parent a0d7f5f commit 1ba574e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ A special thanks go to these people who helped me making this library
+ [x] ArduinoJSON 6 support

### Changelog
+ 2.1.14 ESP8266 authentication issue when user defined WiFi connection
+ 2.1.13 ESP32 compile error
+ 2.1.12 No more fingerprint certificate validation for ESP8266
+ 2.1.11 Fixed an issue on group/chat ID in callback queries
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "git",
"url": "https://github.com/shurillu/CTBot.git"
},
"version": "2.1.13",
"version": "2.1.14",
"authors": {
"name": "Stefano Ledda",
"email": "[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=CTBot
version=2.1.13
version=2.1.14
author=Stefano Ledda <[email protected]>
maintainer=Stefano Ledda <[email protected]>
sentence=Simple Arduino Telegram BOT library for ESP8266/ESP32
Expand Down
20 changes: 18 additions & 2 deletions src/CTBotSecureConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
CTBotSecureConnection::CTBotSecureConnection() {
m_useDNS = true;
#if defined(ARDUINO_ARCH_ESP8266)
// moved from CTBotWiFiSetup::wifiConnect() to here. Time must be synch here because wifiSetup could be not used
// (user defined wifi connection i.e. WiFiManager)
configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");
m_timeSynch = false;
m_cert.append(m_CAcert);
#endif
}
Expand Down Expand Up @@ -52,6 +56,18 @@ String CTBotSecureConnection::send(const String& message) {
#elif defined(ARDUINO_ARCH_ESP8266) && CTBOT_USE_FINGERPRINT == 1 // ESP8266 with HTTPS verification
BearSSL::WiFiClientSecure telegramServer;
// telegramServer.setFingerprint(m_fingerprint);

// moved from CTBotWiFiSetup::wifiConnect() to here. Time must be synch here because wifiSetup could be not used
// (user defined wifi connection i.e. WiFiManager)
if (!m_timeSynch) {
time_t now = time(nullptr);
if (now < 8 * 3600 * 2) {
serialLog("\n--->connect: Unable to sync time data.\n", CTBOT_DEBUG_WIFI);
}
else
m_timeSynch = true;
}

telegramServer.setTrustAnchors(&m_cert);
serialLog(FSTR("ESP8266 with https verification"), CTBOT_DEBUG_CONNECTION);
#elif defined(ARDUINO_ARCH_ESP32) // ESP32
Expand Down Expand Up @@ -79,7 +95,7 @@ String CTBotSecureConnection::send(const String& message) {
IPAddress telegramServerIP;
telegramServerIP.fromString(TELEGRAM_IP);
if (!telegramServer.connect(telegramServerIP, TELEGRAM_PORT)) {
serialLog(FSTR("\nUnable to connect to Telegram server\n"), CTBOT_DEBUG_CONNECTION);
serialLog(FSTR("\nUnable to connect to Telegram server (URL)\n"), CTBOT_DEBUG_CONNECTION);
return("");
}
else {
Expand All @@ -96,7 +112,7 @@ String CTBotSecureConnection::send(const String& message) {
IPAddress telegramServerIP; // (149, 154, 167, 220);
telegramServerIP.fromString(TELEGRAM_IP);
if (!telegramServer.connect(telegramServerIP, TELEGRAM_PORT)) {
serialLog(FSTR("\nUnable to connect to Telegram server\n"), CTBOT_DEBUG_CONNECTION);
serialLog(FSTR("\nUnable to connect to Telegram server (IP)\n"), CTBOT_DEBUG_CONNECTION);
return("");
}
else
Expand Down
1 change: 1 addition & 0 deletions src/CTBotSecureConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class CTBotSecureConnection
private:
bool m_useDNS;
CTBotStatusPin m_statusPin;
bool m_timeSynch;

#if defined(ARDUINO_ARCH_ESP8266)
X509List m_cert;
Expand Down
5 changes: 5 additions & 0 deletions src/CTBotWifiSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ bool CTBotWifiSetup::wifiConnect(const String& ssid, const String& password) {

if (WiFi.status() == WL_CONNECTED) {

// moved in CTBotSecureConnection::Send() + constructor because the user can manage by himself the wifi connection
// i.e. WifiManager
/*
#if defined(ARDUINO_ARCH_ESP8266)
// Set time via NTP, as required for x.509 validation
configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");
Expand Down Expand Up @@ -144,6 +147,8 @@ bool CTBotWifiSetup::wifiConnect(const String& ssid, const String& password) {
serialLog(asctime(&timeinfo), CTBOT_DEBUG_WIFI);
serialLog("\n", CTBOT_DEBUG_WIFI);
#endif
*/


IPAddress ip = WiFi.localIP();
message = (String)FSTR("\nWiFi connected\nIP address: ") + ip.toString() + (String)"\n";
Expand Down

0 comments on commit 1ba574e

Please sign in to comment.