mavishak / cnss-embedded

1 stars 0 forks source link

SSL handshake fail with Firebase #36

Open mavishak opened 3 years ago

mavishak commented 3 years ago

06-07-2021 Up to a few days ago our ESP connection with firebase was working great. Then we didn't use the device for a few days and, out of the blue, the device is not succeeding to create an SSL connection with firebase.

Note: We had some Firebase billing issues that were taken care of right before this happened.

We are getting:

AT+CIPSSLSIZE=4096

OK AT+CIPSTART="SSL","project-host",443

ERROR CLOSED

It manages to pass by if the output is:

ALREADY CONNECTED

ERROR

or:

CONNECT

OK

This appeared once:

AT+CIPSSLSIZE=4096

must close SSL link

ERROR

Note: the handshake stopped working all together now, from all 4 ESP WiFi modules one day later

mavishak commented 3 years ago

06-07-2021 _Here is a documentation of AT+CIPSTART https://docs.espressif.com/projects/esp-at/en/latest/AT_Command_Set/TCP-IP_AT_Commands.html#cmd-start_

Try List:

mavishak commented 3 years ago

real main backup

int main(void)
{
    //set_sys_clock_to_32MHz();
    //init_MCO();

    USART1_init(); // for ESP8266
    USART2_init(); // for debugging

    TIMER2_init(); // for monitoring switch state.
    TIMER3_init(); // for sensor delay
    TIMER4_init(); // for ESP8266 timeout

    QUEUE_init();

    CONFIGURATIONS_set_device_id();

    USART2_enable_Rx(); // for ESC

    USART2_write((uint8_t*)("\033[32m\r\nPress ESC to configure\033[0m"));
    TIMER4_set_timeout(60);
    while(QUEUE_isEmpty() && !TIMER4_timeout_done());

    SENSOR_init(); // sensor interrupts are not inabled

    LED_init();

    //init_i2c1();
    USART2_write((uint8_t*)("\r\n_______________\r\n"));//For test

    while(1)
    {

        QUEUE_do_event();
        SYSTEM_CONTROL_monitor_switch_state(120); // every 2 minutes

    }
}
mavishak commented 3 years ago

Checking valid connection with wether API (TCP Connection) This worked!

Functionality in use:

int main(void){

    USART1_init(); // for ESP8266
    USART2_init(); // for debugging

    TIMER2_init(); // for monitoring switch state.
    TIMER3_init(); // for sensor delay
    TIMER4_init(); // for ESP8266 timeout

    //restore(1,60);// ESP8266 Restore factory flash setup
    localIP(2,6); // ESP8266 FOR MINITORRING PRINT LOCAL IP - DEBUGGING
    while(1){

        USART2_write((uint8_t*)("\r\n_______________\r\n"));//For test

        TestWifiConnection(); // TESTING WIFI CONNECTION

    }
}
/*this function is ment for testing WiFi conditions with TCP connection using whether API*/
BOOL TestWifiConnection(void){

    // before useing this function init_usart1(); and  init_usart2(); must be executed

    //Set client mode
    if(!setClientMode(2,6)){
        return FALSE;
    }
    USART2_write((uint8_t*)"1\r\n");

    //Join access point
    if(!joinAccessPoint_T(2,10)){
        return FALSE;
    }
    USART2_write((uint8_t*)"2\r\n");

    /*Default: AT+CIPMUX=0 (according to: AT instruction set- 5.2.15)*/

    //Connect HOST IP
    if(!connectWeatherAPI(2, 30)){
        return FALSE;
    }
    USART2_write((uint8_t*)"3\r\n");

    createTestMsg();
    USART2_write((uint8_t*)"4\r\n");

    //Send number of data bytes
    if(!sendRequest(1,1,30,40)){
        connection_closed = closeConnection(2,6);
        return FALSE;
    }
    USART2_write((uint8_t*)"5\r\n");

    USART1_write((uint8_t*)http);

    //Read response
    if(!readResponse(60)){//timeout set t0 3 minutes
        connection_closed = closeConnection(2,6);//added 30.4.21
        return FALSE;
    }

    USART2_write((uint8_t*)"6\r\n");

    //Close cunnection with firebase - this might be useless as firebase already closes connection with "CLOSED" response
    closeConnection(3,3);
    USART2_write((uint8_t*)"7\r\n");

    return TRUE;

}

Special functions:

}

- createTestMsg

void createTestMsg(void){

//Set HTTP request
memset((char*)http, '\0', HTTP_SIZE*sizeof(uint8_t));
sprintf((char*)http,("GET /data/2.5/weather?q=London,uk&appid=%s HTTP/1.0\r\nHost: %s\r\n\r\n\r\n"),weather_api_key,weather_api); // HTTP/1.0- Allow only one request
http_len = strlen((char*)http)-strlen("\r\n"); // the last \r\n is for the AT command, and not included in the request's length

}



_**the rest is the same**_
mavishak commented 2 years ago

11-07-2021 We opened a new project and copied only the relevant code to it.

mavishak commented 2 years ago

12-07-2021 It turns out we have two types of ESP8266 boards one is ESP-01 (which we used up until now) the other is ESP-01S wich seems to work even worse :/ see: https://www.esp8266.com/viewtopic.php?t=11657

Some other things we tried:

NaomiCreate commented 2 years ago
mavishak commented 2 years ago

During the last week we have been reaching out to different sources:

Here are the questions we posted

mavishak commented 2 years ago

The official Problem

For the last 5 months, we have successfully managed to create an SSL connection to Firebase via ESP8266 (ESP-01). A week and a half ago the connection stopped working aside for a few individual times. A day after we couldn't connect at all. -> AT+CIPSTART responded ever since with

ERROR

CLOSED

We tried switching between different WiFi networks and got the same results. Moreover, we are successfully connecting to other HTTPS hosts, such as 'www.google.com'

Details:

  1. We are managing to connect to other HTTPS websites using an SSL connection, such as 'www.google.com'.
  2. The WiFi module is connected to an STM32 microcontroller, which is connected to the PC. The communication is established by using AT commands via UART (serial connection with baud rate 115200).
  3. We are connecting to our Firebase project to interact with the Realtime DB by running the AT+CIPSTART command without any certificate file.
  4. We have four ESP8266 (ESP-01) WiFi modules, and one ESP8266MOD WiFi module. They all reacted the same.
  5. We set the SSL buffer size to 4096 (the maximum size).
  6. We didn't flash firmware or AT libraries to the WiFi modules, and left them with their original state.
  7. This is the output of the command AT+GMR (version information): ESP8266 (ESP-01)

    AT+GMR AT version:1.1.0.0(May 11 2016 18:09:56) SDK version:1.5.4(baaeaebb) compile time:May 20 2016 15:08:19

ESP8266MOD

AT+GMR AT version:1.3.0.0(Jul 14 2016 18:54:01) SDK version:2.0.0(5a875ba) v1.0.0.3 Mar 13 2018 09:37:06

AT commands details

AT+RST (reset the module) AT+CWMODE=1 (set the Wi-Fi mode to station mode) AT+CWJAP="SSID","PWD" (connect to a Wi-Fi network) AT+CIFSR (get the Wi-Fi module IP) AT+CIPSSLSIZE=4096 (change the SSL buffer size) AT+CIPSTART="SSL","project-name-rtdb.firebaseio.com",443 (establish a SSL connection) AT+CIPSEND=300 (send data)

Devices Wi-Fi module: https://www.makerfocus.com/products/4pcs-esp8266-esp-01-serial-wireless-wifi-transceiver-module-compatible-with-arduino STM32 microcontroller: https://www.st.com/en/evaluation-tools/nucleo-f103rb.html

Reference https://github.com/espressif/esp-at/blob/v2.0.0.0_esp8266/docs/ESP_AT_Commands_Set.md https://www.espressif.com/sites/default/files/documentation/4a-esp8266_at_instruction_set_en.pdf

Screenshots AT commands AT command image

ESP8266 Images

ESP purchase details

If anyone can help, we would appreciate it very much.

Thank you in advance!

NaomiCreate commented 2 years ago

Documentation of successful SSL connection: 1 hour run output 29-06-2021.log

NaomiCreate commented 2 years ago

In the ESP8266 Community Forum, someone informed us that: "Firebase switched to TLS 1.2 and AT firmware doesn't support it".

We still need to confirm it with Firebase, but it sounds reasonable.

mavishak commented 2 years ago

We entered our database url in to: https://www.cdn77.com/tls-test. This is what we got image

This is what we found when we searched wether ESP supports TLS 1.2 https://forum.arduino.cc/t/can-i-do-tls-1-2-on-esp-01-with-at-commands/689671