ssl_mutual_auth not working with SPIFFS [IDFGH-4115]

MihirShah
Posts: 6
Joined: Sat Apr 18, 2020 7:00 am

ssl_mutual_auth not working with SPIFFS [IDFGH-4115]

Postby MihirShah » Thu Oct 15, 2020 11:45 am

  • Development Kit: [ESP32-DevKitC]
    Kit version (v1]
    Module or chip used: [ESP32-WROOM-32|ESP32-WROOM-32D]
    IDF version: v4.3-dev-771-gc77c4ccf6
    Build System: idf.py
    Compiler version: xtensa-esp32-elf-gcc (crosstool-NG esp-2020r2) 8.2.0
    Operating System: [Windows]
    (Windows only) environment type: [ESP Command Prompt].
    Using an IDE?: [Yes. VS Code]
    Power Supply: [USB]
Problem Description

I am using esp-idf \ examples \ protocols \ mqtt \ ssl_mutual_auth to connect to AWS-IoT-Core.
When I use EMBEDDED certificates, it works very good.
But when I use SPIFFS files for the certificates it does not work.
I tried reading the certificates into a variable & then assigning it to the configuration structure.

Actual code with configuration structure is as follows...

Code: Select all

size_t len_root_ca = 0, len_device_certificate = 0, len_device_private_key = 0;
len_root_ca = getFileSize((const char *)ROOT_CA_PATH);
len_device_certificate = getFileSize((const char *)DEVICE_CERTIFICATE_PATH);
len_device_private_key = getFileSize((const char *)DEVICE_PRIVATE_KEY_PATH);
char root_ca[len_root_ca];
char device_certificate[len_device_certificate];
char device_private_key[len_device_private_key];

if (load_file_into_buffer("storage", (const char *)ROOT_CA_PATH, (char *)root_ca, len_root_ca) != ESP_OK)
{
    TAG = (char *)oldTAG;
    return;
}

if (load_file_into_buffer("storage", (const char *)DEVICE_CERTIFICATE_PATH, (char *)device_certificate, len_device_certificate) != ESP_OK)
{
    TAG = (char *)oldTAG;
    return;
}

if (load_file_into_buffer("storage", (const char *)DEVICE_PRIVATE_KEY_PATH, (char *)device_private_key, len_device_private_key) != ESP_OK)
{
    TAG = (char *)oldTAG;
    return;
}


const esp_mqtt_client_config_t mqtt_cfg = {
    .host = HostAddress,      /*!< "a2vbvxlpw8zcql-ats.iot.us-west-2.amazonaws.com", */
    .port = AWS_MQTT_PORT,    /*!< 8883, */
    .client_id = "LNM_DSM4", 
    .disable_auto_reconnect = false,
    .keepalive = 120,
    .event_handle = mqtt_event_handler,
    .cert_pem = (const char *)root_ca,
    .cert_len = len_root_ca,
    .client_cert_pem = (const char *)device_certificate,
    .client_cert_len = len_device_certificate,
    .client_key_pem = (const char *)device_private_key,
    .client_key_len = len_device_private_key,
    .transport = MQTT_TRANSPORT_OVER_SSL,
};

I tried checking the content of variables, along with their length & it matches with EMBEDDED version. Each variable is NULL ( '\0' ) terminated.

The error is as follows...
I (34715) MQTTS: Ack Other event id:7
E (35045) esp-tls-mbedtls: mbedtls_x509_crt_parse returned -0x2180
E (35045) esp-tls-mbedtls: Failed to set client configurations
E (35045) esp-tls: create_ssl_handle failed
E (35055) esp-tls: Failed to open new connection
E (35055) TRANS_SSL: Failed to open a new connection
E (35065) MQTT_CLIENT: Error transport connect
I (35065) MQTTS: Ack MQTT_EVENT_ERROR
I (35075) MQTTS: Ack MQTT_EVENT_DISCONNECTED

Please help me resolve this.

Who is online

Users browsing this forum: Gaston1980 and 176 guests