Using and changing Certificates with arduinoJSON

Hi everyone, I am trying to onboard a device on AWS IOT. The process is that you start with default certificates, you onboard and receive now ones, then you can use them. This is arduino on ESP32, but I struggle with the char arrays and copies...

So I need to:

  • store a string in a JSON document (a default certificate)
  • Save that JSON to file
    then later:
  • Load the string, and onboard my device which will then receive its final certificate
  • change the certificate string with that new value
  • Save to file again to keep the new certi hardcoded.

My first issue: saving the default certificate. In the code below I have tried different formats

char* AWS_CERT_CA = \                              
"-----BEGIN CERTIFICATE-----\n" \
"5MsI+yMRQ+h.....................K642M4UwtBV8ob2xJNDd2ZhwLnoQdeXeGADbkpy\n" \
"rqXRfboQnoZsG4q5WTP468SQvvG5\n" \
"-----END CERTIFICATE-----\n"; 

(and same for AWS_CERT_CRT and AWS_CERT_PRIVATE)

const int capacity = 100 + JSON_OBJECT_SIZE(3);
  StaticJsonDocument<capacity> doc;
  File file;
  //Save to file
  file = SPIFFS.open(certs, "w+");  //Create file
 doc["AWS_CERT_CA"] = *AWS_CERT_CA;
 doc["AWS_CERT_CRT"] = (char*)AWS_CERT_CRT;
 doc["AWS_CERT_PRIVATE"] = "*AWS_CERT_PRIVATE";
 if (serializeJson(doc, file) == 0) {
   Serial.println(F("Failed to write to file"));
 } else Serial.println("file written");
 file.close();

When I print the resulting file, it gives that result:

10:06:18.031 -> Load certificates from file
10:06:18.031 -> {"AWS_CERT_CA":45,"AWS_CERT_CRT":null,"AWS_CERT_PRIVATE":"*AWS_CERT_PRIVATE"}

How can I write the certificate correctly?