- Set a specific partition to store certificate files
- Multiple certificate file management
- Certificate format conversion
- Download the certificate to Flash
- Use the corresponding certificate file
1. Set a specific partition to store certificate files
Define the certificate file partition in the project partition table file, as follows:
- As above, the converted
certificate.bin
download address is0x41000
- The size of the certificate firmware is
300 KB
, it is necessary to ensure that the partitions do not overlap, and the size of the bin file meets the Flash Size setting
2. Multi-certificate file management
- Create a customized folder under the customer project
- Create a certificate folder and certificate.csv file in the customized folder directory
- Various certificate files are stored under
certificate
the folder, for exampleserver_ca.crt
,server_cert.crt
,server.key
certificate.csv
Under File , specify the file paths for various certificates in the following format:
key,type,encoding,value
server_cert,namespace,,
server_cert,file,binary,E:\esp\test\customized\server_cert\server_cert.crt
server_key,namespace,,
server_key,file,binary,E:\esp\test\customized\server_key\server.key
server_ca,namespace,,
server_ca,file,binary,E:\esp\test\customized\server_ca\server_ca.crt
For supported file types to be managed, see: CSV file format description.
- Different storage types need to set different
Encoding
3. Certificate format conversion
- Use the script tool under the esp-idf/components/nvs_flash/nvs_partition_generator file
nvs_partition_gen.py
E:\esp\test\customized\certificate.csv
Convert the file to certificate.bin
the format
For instructions on using the NVS script tool, see "NVS Partition Generator"
The command is:
python nvs_partition_gen.py generate E:\esp\test\customized\certificate.csv certificate.bin 0x4B000
0x4B000
is the converted bin file size
4. Download the certificate to Flash
As the partition table is set above, the converted certificate.bin
download address is 0x41000
, and you can directly use the Flash download tool to download certificate.bin
the file
- If you need to replace a new certificate file, you only need to replace the certificate file under the corresponding
E:\esp\test\customized\certificate
folder , and then usenvs_partition_gen.py
the script tool to convert the certificate file format into bin firmware - There is no need to put the new certificate under the project and recompile the project to obtain the certificate firmware (bin file)
5. Use the corresponding certificate file
When the certificate file needs to be used in the application, use the nvs_open_from_partition API to obtain the certificate file, and the corresponding parameters are set as follows: