First of all, .c_str() method returns temporary object. Change it with .data() method.
In your code:
mqttConfig.cert_pem = certificate.data();