printf("heap_size%d\n”,system_get_free_heap_size());
6. When the SSL authentication function is required:
• If not using SPIFFS file system, please run python script esp_iot_sdk_freertos\tools\
make_cert.py, generate esp_ca_cert.bin, and write it into the flash.
Below is an example showing how to read information about the SSL encryption key
and certificate from the flash.
uint8flash_offset=0x78;//Example:Flashaddress0x78000
if(ssl_obj_option_load(ssl_ctx,SSL_OBJ_RSA_KEY,“XX.key”,password,flash_offset)){
printf("Error:thePrivatekeyisundefined.\n");
}
if(ssl_obj_option_load(ssl_ctx,SSL_OBJ_X509_CERT,“XX.cer”,NULL,flash_offset)){
printf("Error:theCertificateisundefined.\n");
}
• If using SPIFFS file system, please run the tool spiffy (https://github.com/xlfe/spiffy.
Please note that the spiffs_config.h of this tool has to be the same as the one in the
RTOS SDK). Then generate spiffs_rom.bin, and write it into the flash; for details on
this process please refer to the example of esp_spiffs_init.
Below is an example showing how to read information about the SSL encryption key
and certificate from the flash using SPIFFS.
if(ssl_obj_load(ssl_ctx,SSL_OBJ_RSA_KEY,“XX.key”,password)){
printf("Error:thePrivatekeyisundefined.\n");
}
if(ssl_obj_load(ssl_ctx,SSL_OBJ_X509_CERT,“XX.cer”,NULL)){
printf("Error:theCertificateisundefined.\n");
}
7. Start a handshake with the SSL client.
ssl=ssl_client_new(ssl_ctx,client_fd,NULL,0);
if(ssl!=NULL){
printf("clienthandshakestart\n");
}
8. Check the status of the SSL connection.
if((res=ssl_handshake_status(ssl))==SSL_OK){
……
}
9. If the handshake is successful, then the certificate can be released and more memory
space will be available.