Skip to content

Commit 4645aa0

Browse files
Jerry-ESPchshu
authored andcommitted
examples: add custom certification declaration example in light example
1 parent 6aa71da commit 4645aa0

File tree

6 files changed

+41
-2
lines changed

6 files changed

+41
-2
lines changed

components/esp_matter/esp_matter_providers.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void set_custom_device_info_provider(DeviceInfoProvider *provider)
7171
}
7272
#endif
7373

74-
static DeviceAttestationCredentialsProvider *get_dac_provider(void)
74+
DeviceAttestationCredentialsProvider *get_dac_provider(void)
7575
{
7676
#if CONFIG_SEC_CERT_DAC_PROVIDER
7777
static ESP32SecureCertDACProvider instance;

components/esp_matter/esp_matter_providers.h

+2
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,6 @@ void set_custom_device_info_provider(chip::DeviceLayer::DeviceInfoProvider *prov
5858
#endif
5959

6060
void setup_providers();
61+
62+
chip::Credentials::DeviceAttestationCredentialsProvider *get_dac_provider(void);
6163
} // namespace esp_matter

docs/en/developing.rst

+7-1
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,13 @@ For more info about the arguments, please check `here <https://github.com/espres
11101110
2.7.3 Factory Partition
11111111
~~~~~~~~~~~~~~~~~~~~~~~
11121112

1113-
Factory partition contains basic information like VID, PID, etc, and CD.
1113+
Factory partition contains basic information like VID, PID, etc.
1114+
1115+
By default, the CD(Certification Declaration) is stored in the factory partition and we need to add the ``-cd`` option when generating the factory partition.
1116+
1117+
Alternatively, if you’d like to embed the CD in the firmware, you can enable the
1118+
``CONFIG_ENABLE_SET_CERT_DECLARATION_API`` option and use the ``SetCertificationDeclaration()`` API to set the CD.
1119+
You can refer to the reference implementation in :project_file: `light example <https://github.com/espressif/esp-matter/tree/main/examples/light>`__.
11141120

11151121
Export the dependent tools path
11161122

examples/light/main/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
idf_component_register(SRC_DIRS "."
22
PRIV_INCLUDE_DIRS "." "${ESP_MATTER_PATH}/examples/common/utils")
33

4+
if (CONFIG_ENABLE_SET_CERT_DECLARATION_API)
5+
target_add_binary_data(${COMPONENT_TARGET} "certification_declaration/certification_declaration.der" BINARY)
6+
endif()
7+
48
set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17)
59
target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H")

examples/light/main/app_main.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@
2424
#include <app/server/CommissioningWindowManager.h>
2525
#include <app/server/Server.h>
2626

27+
#ifdef CONFIG_ENABLE_SET_CERT_DECLARATION_API
28+
#include <esp_matter_providers.h>
29+
#include <lib/support/Span.h>
30+
#ifdef CONFIG_SEC_CERT_DAC_PROVIDER
31+
#include <platform/ESP32/ESP32SecureCertDACProvider.h>
32+
#elif defined(CONFIG_FACTORY_PARTITION_DAC_PROVIDER)
33+
#include <platform/ESP32/ESP32FactoryDataProvider.h>
34+
#endif
35+
using namespace chip::DeviceLayer;
36+
#endif
37+
2738
static const char *TAG = "app_main";
2839
uint16_t light_endpoint_id = 0;
2940

@@ -34,6 +45,13 @@ using namespace chip::app::Clusters;
3445

3546
constexpr auto k_timeout_seconds = 300;
3647

48+
#ifdef CONFIG_ENABLE_SET_CERT_DECLARATION_API
49+
extern const uint8_t cd_start[] asm("_binary_certification_declaration_der_start");
50+
extern const uint8_t cd_end[] asm("_binary_certification_declaration_der_end");
51+
52+
const chip::ByteSpan cdSpan(cd_start, static_cast<size_t>(cd_end - cd_start));
53+
#endif // CONFIG_ENABLE_SET_CERT_DECLARATION_API
54+
3755
#if CONFIG_ENABLE_ENCRYPTED_OTA
3856
extern const char decryption_key_start[] asm("_binary_esp_image_encryption_key_pem_start");
3957
extern const char decryption_key_end[] asm("_binary_esp_image_encryption_key_pem_end");
@@ -208,6 +226,15 @@ extern "C" void app_main()
208226
set_openthread_platform_config(&config);
209227
#endif
210228

229+
#ifdef CONFIG_ENABLE_SET_CERT_DECLARATION_API
230+
auto * dac_provider = get_dac_provider();
231+
#ifdef CONFIG_SEC_CERT_DAC_PROVIDER
232+
static_cast<ESP32SecureCertDACProvider *>(dac_provider)->SetCertificationDeclaration(cdSpan);
233+
#elif defined(CONFIG_FACTORY_PARTITION_DAC_PROVIDER)
234+
static_cast<ESP32FactoryDataProvider *>(dac_provider)->SetCertificationDeclaration(cdSpan);
235+
#endif
236+
#endif // CONFIG_ENABLE_SET_CERT_DECLARATION_API
237+
211238
/* Matter start */
212239
err = esp_matter::start(app_event_cb);
213240
ABORT_APP_ON_FAILURE(err == ESP_OK, ESP_LOGE(TAG, "Failed to start Matter, err:%d", err));
Binary file not shown.

0 commit comments

Comments
 (0)