load root CA from SPIFFS and pass to WiFiClientSecure

KevinHunter
Posts: 1
Joined: Mon Oct 01, 2018 8:02 am

load root CA from SPIFFS and pass to WiFiClientSecure

Postby KevinHunter » Mon Oct 01, 2018 8:20 am

Hi all,
Im still a newbie and Im trying no move working code I wrote for the ESP8266 to the ESP32 but its not working.

I have a root certificate that I have stored in SPIFFS and I want to pass it to WifiClientSecure. On the ESP8266 I do it this way (which works):

Code: Select all

  // Load CA file from SPIFFS
  File ca = SPIFFS.open("/site.cer", "r"); 
  if (!ca) {
    Serial.println("Failed to open ca ");
  }
  else
    Serial.println("Success to open ca");
  delay(1000);

  // Set server CA file
  if (wifiClient.loadCACert(ca))
    Serial.println("ca loaded");
  else
    Serial.println("ca failed");

}
My first problem was that loadCACert() isnt supported by WiFiClientSecure on the ESP32 so I changed it to setCACert(). The problem I have now is that when I pass the file into this method ( wifiClient.setCACert(ca);) i get the following error:

no suitable conversion function from "fs::File" to "const char *" exists

So my question is , how do I convert a File to a const char ??

Thanks
Kev

spestano
Posts: 1
Joined: Tue Oct 09, 2018 12:31 am

Re: load root CA from SPIFFS and pass to WiFiClientSecure

Postby spestano » Tue Oct 09, 2018 12:35 am

Try, reading your "ca" and store it in a buffer of type char then pass that buffer in your function.

Who is online

Users browsing this forum: No registered users and 9 guests