|
| 1 | +# Using esp_secure_cert partition |
| 2 | + |
| 3 | +## 1.1 ESP Secure Cert Partition |
| 4 | + |
| 5 | +- When a device is pre-provisioned, the PKI credentials are generated for the |
| 6 | + device and stored in a partition named esp_secure_cert. |
| 7 | +- In the Matter Pre-Provisioning service, the Matter DAC certificate is |
| 8 | + pre-flashed in esp_secure_cert partition. |
| 9 | +- The ESP32SecureCertDACProvider reads the PKI credentials from |
| 10 | + esp_secure_cert_partition. |
| 11 | +- The DAC,PAI and private key are read from the esp_secure_cert_partition, but |
| 12 | + the certificate declaration is read from the factory data partition. |
| 13 | + Therefore, we need to also generate a factory partition besides |
| 14 | + esp_secure_cert_partition. |
| 15 | +- The esp_secure_cert partition can be generated on host with help of |
| 16 | + configure_esp_secure_cert.py utility. |
| 17 | +- The use of esp_secure_cert_partition is demonstrated in lighting-app. |
| 18 | + |
| 19 | +## 1.2 Prerequisites: |
| 20 | + |
| 21 | +To generate the esp_secure_cert_partition and the factory_data_partition, we |
| 22 | +need the DAC and PAI certificate as well as the private key(DAC key) in .der |
| 23 | +format. The factory_data_provider in addition requires the certificate |
| 24 | +declaration in .der format. The generation of the required certificates and keys |
| 25 | +is mentioned in the steps given below. |
| 26 | + |
| 27 | +### 1.2.1 Build certification generation tool: |
| 28 | + |
| 29 | +Run the commands below: |
| 30 | + |
| 31 | +``` |
| 32 | +cd path/to/connectedhomeip |
| 33 | +source scripts/activate.sh |
| 34 | +gn gen out/host |
| 35 | +ninja -C out/host chip-cert |
| 36 | +cd out/host |
| 37 | +``` |
| 38 | + |
| 39 | +At /path/to/connectedhomeip/out/host run the below commands. |
| 40 | + |
| 41 | +### 1.2.2 Generating Certification Declaration |
| 42 | + |
| 43 | +``` |
| 44 | +./chip-cert gen-cd -K ../../credentials/test/certification-declaration/Chip-Test-CD-Signing-Key.pem -C ../../credentials/test/certification-declaration/Chip-Test-CD-Signing-Cert.pem -O esp_dac_fff1_8000.der -f 1 -V 0xfff1 -p 0x8000 -d 0x0016 -c "CSA00000SWC00000-01" -l 0 -i 0 -n 1 -t 0 |
| 45 | +``` |
| 46 | + |
| 47 | +### 1.2.3 Generating PAI |
| 48 | + |
| 49 | +``` |
| 50 | +./chip-cert gen-att-cert -t i -c "ESP TEST PAI" -V 0xfff1 -P 0x8000 -C ../../credentials/development/attestation/Chip-Development-PAA-Cert.pem -K ../../credentials/development/attestation/Chip-Development-PAA-Key.pem -o Esp-Development-PAI-Cert.pem -O Esp-Development-PAI-Key.pem -l 4294967295 |
| 51 | +``` |
| 52 | + |
| 53 | +### 1.2.4 Generating DAC |
| 54 | + |
| 55 | +``` |
| 56 | +./chip-cert gen-att-cert -t d -c "ESP TEST DAC 01" -V 0xfff1 -P 0x8000 -C Esp-Development-PAI-Cert.pem -K Esp-Development-PAI-Key.pem -o Esp-Development-DAC-01.pem -O Esp-Development-DAC-Key-01.pem -l 4294967295 |
| 57 | +``` |
| 58 | + |
| 59 | +### 1.2.5 Change format for the certificates and key (.pem to .der format) |
| 60 | + |
| 61 | +- Convert DAC key from .pem to .der format. |
| 62 | + |
| 63 | +``` |
| 64 | +openssl ec -in Esp-Development-DAC-Key-01.pem -out Esp-Development-DAC-Key-01.der -inform pem -outform der |
| 65 | +``` |
| 66 | + |
| 67 | +- Convert DAC and PAI cert from .pem to .der format |
| 68 | + |
| 69 | +``` |
| 70 | +openssl x509 -in Esp-Development-DAC-01.pem -out Esp-Development-DAC-01.der-inform pem -outform der |
| 71 | +openssl x509 -in Esp-Development-PAI-Cert.pem -out Esp-Development-PAI-Cert.der -inform pem -outform der |
| 72 | +``` |
| 73 | + |
| 74 | +The certificates in the steps 1.2 will be generated at |
| 75 | +/path/to/connectedhomeip/out/host.For steps 1.3 and 1.4 go to |
| 76 | +connectedhomeip/scripts/tools , set IDF_PATH. |
| 77 | + |
| 78 | +## 1.3 Generating esp_secure_cert_partition |
| 79 | + |
| 80 | +To generate the esp_secure_cert_partition install esp-secure-cert-tool using |
| 81 | + |
| 82 | +``` |
| 83 | +pip install esp-secure-cert-tool |
| 84 | +``` |
| 85 | + |
| 86 | +Example command to generate a esp_secure_cert_partition |
| 87 | + |
| 88 | +``` |
| 89 | +configure_esp_secure_cert.py --private-key path/to/dac-key \ |
| 90 | +--device-cert path/to/dac-cert \ |
| 91 | +--ca-cert path/to/pai-cert \ |
| 92 | +--target_chip esp32c3 \ |
| 93 | +--port /dev/ttyUSB0 -- skip_flash |
| 94 | +``` |
| 95 | + |
| 96 | +Refer |
| 97 | +https://github.com/espressif/esp_secure_cert_mgr/tree/main/tools#generate-esp_secure_cert-partition |
| 98 | +for more help. |
| 99 | + |
| 100 | +## 1.4 Generating the factory_data_partition |
| 101 | + |
| 102 | +Example command to generate a factory_data_partition |
| 103 | + |
| 104 | +``` |
| 105 | +./generate_esp32_chip_factory_bin.py -d 3434 -p 99663300 \ |
| 106 | + --product-name ESP-lighting-app --product-id 0x8000 \ |
| 107 | + --vendor-name Test-vendor --vendor-id 0xFFF1 \ |
| 108 | + --hw-ver 1 --hw-ver-str DevKit \ |
| 109 | + --dac-cert path/to/dac-cert \ |
| 110 | + --dac-key path/to/dac-key \ |
| 111 | + --pai-cert path/to/pai-cert \ |
| 112 | + --cd path/to/certificate-declaration |
| 113 | +``` |
| 114 | + |
| 115 | +Refer |
| 116 | +https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/esp32/factory_data.md#generate-nvs-binary-image |
| 117 | +to generate a factory_data_partition. |
| 118 | + |
| 119 | +## 1.5 Build the firmware with below configuration options |
| 120 | + |
| 121 | +``` |
| 122 | +# Disable the DS Peripheral support |
| 123 | +CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n |
| 124 | +# Use DAC Provider implementation which reads attestation data from secure cert partition |
| 125 | +CONFIG_SEC_CERT_DAC_PROVIDER=y |
| 126 | +# Enable some options which reads CD and other basic info from the factory partition |
| 127 | +CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER=y |
| 128 | +CONFIG_ENABLE_ESP32_DEVICE_INSTANCE_INFO_PROVIDER=y |
| 129 | +CONFIG_CHIP_FACTORY_NAMESPACE_PARTITION_LABEL="fctry" |
| 130 | +``` |
| 131 | + |
| 132 | +In order to use the esp_secure_cert_partition, in addition to enabling the above |
| 133 | +config options, you should also have the esp_secure_cert_partition and factory |
| 134 | +partition in your app. For reference, refer to partitions.csv file of |
| 135 | +lighting-app. |
| 136 | + |
| 137 | +## 1.6 Flashing firmware, secure cert and factory partition |
| 138 | + |
| 139 | +### Build and flash |
| 140 | + |
| 141 | +``` |
| 142 | +idf.py -p (PORT) build flash |
| 143 | +``` |
| 144 | + |
| 145 | +### Flash `esp_secure_cert` and factory partition binaries |
| 146 | + |
| 147 | +The `esp_secure_cert` partition binary contains device attestation information |
| 148 | +and the factory partition binary contains Matter manufacturing specific data. |
| 149 | + |
| 150 | +- Flash `esp_secure_cert` partition binary |
| 151 | + |
| 152 | +``` |
| 153 | +esptool.py -p (PORT) write_flash 0xd000 path/to/secure_cert_partition.bin |
| 154 | +``` |
| 155 | + |
| 156 | +- Flash factory partition binary |
| 157 | + |
| 158 | +``` |
| 159 | +esptool.py -p (PORT) write_flash 0x3E0000 path/to/factory_partition.bin |
| 160 | +``` |
| 161 | + |
| 162 | +### Monitor |
| 163 | + |
| 164 | +``` |
| 165 | +idf.py monitor |
| 166 | +``` |
| 167 | + |
| 168 | +Please flash the above mentioned partitions by looking into the addresses in |
| 169 | +partitions.csv.The above commands are for example purpose. |
| 170 | + |
| 171 | +## 1.6 Test commissioning using chip-tool |
| 172 | + |
| 173 | +Run the following command from host to commission the device. |
| 174 | + |
| 175 | +``` |
| 176 | +./chip-tool pairing ble-wifi 1234 my_SSID my_PASSPHRASE my_PASSCODE my_DISCRIMINATOR --paa-trust-store-path /path/to/PAA-Certificates/ |
| 177 | +``` |
| 178 | + |
| 179 | +For example: |
| 180 | + |
| 181 | +``` |
| 182 | +./chip-tool pairing ble-wifi 0x7283 my_SSID my_PASSPHRASE 99663300 3434 --paa-trust-store-path /path/to/connectedhomeip/credentials/development/attestation/ |
| 183 | +``` |
0 commit comments