shurillu / CTBot

A simple (and easy to use) Arduino Telegram BOT Library for ESP8266/ESP32
MIT License
147 stars 34 forks source link

Long term support #56

Closed AndiP1234 closed 4 years ago

AndiP1234 commented 4 years ago

Hi,

is there a solution for long term support? With the last IP and fingerprint change it was necessary to download the sketch to my ESP again.

For the future I changed my code, it´s working but not secure:

  1. m_useDNS = true;
  2. use telegramServer.setInsecure(); instead of telegramServer.setFingerprint(m_fingerprint);
CTBot::CTBot() {
    m_wifiConnectionTries = 0;  // wait until connection to the AP is established (locking!)
    m_statusPin = CTBOT_DISABLE_STATUS_PIN; // status pin disabled
    m_token = ""; // no token
    m_lastUpdate = 0;  // not updated yet
    m_useDNS = true; // use static IP for Telegram Server
    m_UTF8Encoding = false; // no UTF8 encoded string conversion
    setFingerprint(fingerprint);   // set the default fingerprint
}

CTBot::~CTBot() {
}

String CTBot::sendCommand(String command, String parameters)
{
#if CTBOT_USE_FINGERPRINT == 0
    WiFiClientSecure telegramServer;
#else
    BearSSL::WiFiClientSecure telegramServer;
    //telegramServer.setFingerprint(m_fingerprint);
    telegramServer.setInsecure();
#endif
shurillu commented 4 years ago

Hello AndiP1234, changing the source code of the library is not recommanded because upgrading the library to a new version will overwrite your changes. There is a member function called useDNS(bool value): calling it with value=true will use the URL instead of using the fixed IP. Take in mind that if the DNS fail, it will try with the fixed IP. Regarding the use of the fingerprint, I read that from the 2.5.0 version and above of the Library Core of the ESP8266, all HTTPS connection must provide the fingerprint as verification. Maybe some things has been changed, I'll check it and if it work, I'll put inside the CTBOT_USE_FINGERPRINT = 0 define.

Another option is to use libraries like WiFiManager (https://github.com/tzapu/WiFiManager). This library provide a captive portal where you can change wifi network properties (SSID and password) but you can add more custom parameters. So you can add a way to update the Telegram IP / fingerprint with your PC/mobile in a easy way. There are lots of examples. Cheers

Stefano

shurillu commented 4 years ago

Ok AndiP124: with the setInsecure() method all works without fingerprint. Soon I'll upload the new version, changing the CTBOT_USE_FINGERPRINT define to 0 will not use the fingerprint.

In the new version (2.0.0), the defines are located in the CTBotDefines.h file.

Stefano