Skip to content

Commit 1431582

Browse files
shripad621gitpull[bot]
authored andcommitted
Secure Cert DAC Provider impl to read attestation info from esp_secure_cert partition. (#25802)
Refactored some code related to setting the attestation info provider. Added the configuration of SEC_CERT_DAC_PROVIDER and code which lets user decide which implementation of DAC Provider to use. Added esp_secure_cert_mgr component.
1 parent 8b703af commit 1431582

File tree

12 files changed

+436
-12
lines changed

12 files changed

+436
-12
lines changed

.github/.wordlist.txt

+3
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,7 @@ otatesting
985985
otaURL
986986
OTBR
987987
otcli
988+
outform
988989
outgoingCommands
989990
OxygenConcentrationMeasurement
990991
OzoneConcentrationMeasurement
@@ -1024,6 +1025,7 @@ Pigweed
10241025
PinCode
10251026
pinrequest
10261027
pkgconfig
1028+
PKI
10271029
plaintext
10281030
PlatformManager
10291031
PlatformManagerImpl
@@ -1180,6 +1182,7 @@ sdkconfig
11801182
SDKs
11811183
SDKTARGETSYSROOT
11821184
sdl
1185+
SecureCertDACProvider
11831186
SED
11841187
SEGGER
11851188
semver

config/esp32/components/chip/CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ if (CONFIG_ENABLE_ESP32_DEVICE_INFO_PROVIDER)
207207
chip_gn_arg_append("chip_use_device_info_provider" "true")
208208
endif()
209209

210+
if (CONFIG_SEC_CERT_DAC_PROVIDER)
211+
chip_gn_arg_append("chip_use_secure_cert_dac_provider" "true")
212+
endif()
213+
214+
210215
set(args_gn_input "${CMAKE_CURRENT_BINARY_DIR}/args.gn.in")
211216
file(GENERATE OUTPUT "${args_gn_input}" CONTENT "${chip_gn_args}")
212217

@@ -346,6 +351,11 @@ endif()
346351
idf_component_get_property(main_lib main COMPONENT_LIB)
347352
list(APPEND chip_libraries $<TARGET_FILE:${main_lib}>)
348353

354+
if (CONFIG_SEC_CERT_DAC_PROVIDER)
355+
idf_component_get_property(esp32_secure_cert_mgr_lib espressif__esp_secure_cert_mgr COMPONENT_LIB)
356+
list(APPEND chip_libraries $<TARGET_FILE:${esp32_secure_cert_mgr_lib}>)
357+
endif()
358+
349359
target_link_libraries(${COMPONENT_LIB} INTERFACE -Wl,--start-group
350360
${chip_libraries}
351361
$<TARGET_FILE:mbedcrypto> $<TARGET_FILE:${esp32_mbedtls_lib}>

config/esp32/components/chip/Kconfig

+7
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,13 @@ menu "CHIP Device Layer"
678678
help
679679
Enable ESP32 Device LocationCapability
680680

681+
config SEC_CERT_DAC_PROVIDER
682+
bool "Use Secure Cert DAC Provider"
683+
default n
684+
help
685+
Use ESP32 Secure Cert DAC Provider which is ESP32 DeviceAttestationCredentialsProvider implementation which reads attestation
686+
information from the esp_secure_cert partition
687+
681688
endmenu
682689

683690

config/esp32/components/chip/idf_component.yml

+5
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ dependencies:
55
rules:
66
- if: "idf_version >=5.0"
77
- if: "target != esp32h2"
8+
9+
espressif/esp_secure_cert_mgr:
10+
version: "^2.2.1"
11+
rules:
12+
- if: "idf_version >=4.3"

docs/guides/esp32/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ example on ESP32 series of SoCs
1616
- [Flash and NVS encryption for securing factory data](flash_nvs_encryption.md)
1717
- [RPC Console and Device Tracing](rpc_console.md)
1818
- [Matter OTA](ota.md)
19+
- [Generating and Using ESP Secure Cert Parttiton](secure_cert_partition.md)
+183
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
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+
```

examples/lighting-app/esp32/main/main.cpp

+22-4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
#include <DeviceInfoProviderImpl.h>
5555
#endif // CONFIG_ENABLE_ESP32_DEVICE_INFO_PROVIDER
5656

57+
#if CONFIG_SEC_CERT_DAC_PROVIDER
58+
#include <platform/ESP32/ESP32SecureCertDACProvider.h>
59+
#endif
60+
5761
using namespace ::chip;
5862
using namespace ::chip::Credentials;
5963
using namespace ::chip::DeviceManager;
@@ -74,6 +78,22 @@ DeviceLayer::ESP32DeviceInfoProvider gExampleDeviceInfoProvider;
7478
#else
7579
DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;
7680
#endif // CONFIG_ENABLE_ESP32_DEVICE_INFO_PROVIDER
81+
82+
#if CONFIG_SEC_CERT_DAC_PROVIDER
83+
DeviceLayer::ESP32SecureCertDACProvider gSecureCertDACProvider;
84+
#endif // CONFIG_SEC_CERT_DAC_PROVIDER
85+
86+
chip::Credentials::DeviceAttestationCredentialsProvider * get_dac_provider(void)
87+
{
88+
#if CONFIG_SEC_CERT_DAC_PROVIDER
89+
return &gSecureCertDACProvider;
90+
#elif CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
91+
return &sFactoryDataProvider;
92+
#else // EXAMPLE_DAC_PROVIDER
93+
return chip::Credentials::Examples::GetExampleDACProvider();
94+
#endif
95+
}
96+
7797
} // namespace
7898

7999
static void InitServer(intptr_t context)
@@ -131,14 +151,12 @@ extern "C" void app_main()
131151

132152
#if CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
133153
SetCommissionableDataProvider(&sFactoryDataProvider);
134-
SetDeviceAttestationCredentialsProvider(&sFactoryDataProvider);
135154
#if CONFIG_ENABLE_ESP32_DEVICE_INSTANCE_INFO_PROVIDER
136155
SetDeviceInstanceInfoProvider(&sFactoryDataProvider);
137156
#endif
138-
#else
139-
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
140-
#endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER
157+
#endif
141158

159+
SetDeviceAttestationCredentialsProvider(get_dac_provider());
142160
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
143161
if (ThreadStackMgr().InitThreadStack() != CHIP_NO_ERROR)
144162
{
+9-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Name, Type, SubType, Offset, Size, Flags
2-
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
3-
nvs, data, nvs, , 0x6000,
4-
otadata, data, ota, , 0x2000,
5-
phy_init, data, phy, , 0x1000,
6-
ota_0, app, ota_0, , 1500K,
7-
ota_1, app, ota_1, , 1500K,
2+
# Note: Firmware partition offset needs to be 64K aligned, initial 36K (9 sectors) are reserved for bootloader and partition table
3+
esp_secure_cert, 0x3F, , 0xD000, 0x2000, encrypted
4+
nvs, data, nvs, 0x10000, 0x6000,
5+
nvs_keys, data, nvs_keys,, 0x1000,
6+
otadata, data, ota, , 0x2000
7+
phy_init, data, phy, , 0x1000,
8+
ota_0, app, ota_0, 0x20000, 0x1E0000,
9+
ota_1, app, ota_1, 0x200000, 0x1E0000,
10+
fctry, data, nvs, 0x3E0000, 0x6000

examples/lighting-app/esp32/sdkconfig.defaults

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@ CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
5353
# Disable softap support by default
5454
CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n
5555
# This example uses the older version of RMT driver to work with both
56-
# idf-v4.4.3 and idf-v5.0, so supressing the warnings by setting below option
56+
# idf-v4.4.3 and idf-v5.0, so suppressing the warnings by setting below option
5757
CONFIG_RMT_SUPPRESS_DEPRECATE_WARN=y

src/platform/ESP32/BUILD.gn

+12-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ declare_args() {
2727
chip_enable_chipoble = true
2828
chip_bt_nimble_enabled = false
2929
chip_bt_bluedroid_enabled = false
30+
chip_use_secure_cert_dac_provider = false
3031
}
3132

3233
defines = [
@@ -64,7 +65,10 @@ static_library("ESP32") {
6465
"${chip_root}/src/setup_payload",
6566
]
6667

67-
public = [ "${chip_root}/src/credentials/DeviceAttestationCredsProvider.h" ]
68+
public = [
69+
"${chip_root}/src/credentials/CHIPCert.h",
70+
"${chip_root}/src/credentials/DeviceAttestationCredsProvider.h",
71+
]
6872

6973
public_deps = [
7074
"${chip_root}/src/crypto",
@@ -149,5 +153,12 @@ static_library("ESP32") {
149153
]
150154
}
151155

156+
if (chip_use_secure_cert_dac_provider) {
157+
sources += [
158+
"ESP32SecureCertDACProvider.cpp",
159+
"ESP32SecureCertDACProvider.h",
160+
]
161+
}
162+
152163
cflags = [ "-Wconversion" ]
153164
}

0 commit comments

Comments
 (0)