Skip to content

Commit f54f539

Browse files
[nrf fromlist][nrfconnect] Refactor of the factory data support
Refactored Factory Data Support: - Added some useful tips to the Factory Data Guide. - The SPAKE2+ verifier is now generated by default with each build. - The Test Certification Declaration can now be generated separately and no longer requires the generation of the DAC and PAI certificates. - The Rotating Device ID Unique ID can be used and generated only if the CONFIG_CHIP_ROTATING_DEVICE_ID is set to 'y'.
1 parent 623ef0a commit f54f539

File tree

4 files changed

+174
-99
lines changed

4 files changed

+174
-99
lines changed

config/nrfconnect/chip-module/Kconfig

+6
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ choice CHIP_FACTORY_DATA_CERT_SOURCE
206206

207207
endchoice
208208

209+
config CHIP_FACTORY_DATA_GENERATE_CD
210+
bool "Generates Certification Declaration to the output build directory"
211+
help
212+
Generates the new Certification Declaration and stores it to the output build directory.
213+
209214
if CHIP_FACTORY_DATA_CERT_SOURCE_USER
210215

211216
config CHIP_FACTORY_DATA_USER_CERTS_DAC_CERT
@@ -230,6 +235,7 @@ endif # CHIP_FACTORY_DATA_CERT_SOURCE_USER
230235
# Configs for SPAKE2+ generation
231236
config CHIP_FACTORY_DATA_GENERATE_SPAKE2_VERIFIER
232237
bool "Generate SPAKE2+ verifier"
238+
default y
233239
help
234240
Enables the generation of the SPAKE2+ verifier for the configured SPAKE2+
235241
passcode, iteration count and salt.

config/nrfconnect/chip-module/generate_factory_data.cmake

+26-17
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,25 @@ string(APPEND script_args "--hw_ver ${CONFIG_CHIP_DEVICE_HARDWARE_VERSION}\n")
4848
string(APPEND script_args "--hw_ver_str \"${CONFIG_CHIP_DEVICE_HARDWARE_VERSION_STRING}\"\n")
4949

5050
# check if Rotating Device Id Unique Id should be generated
51-
if(NOT CONFIG_CHIP_DEVICE_GENERATE_ROTATING_DEVICE_UID)
52-
if(NOT DEFINED CONFIG_CHIP_DEVICE_ROTATING_DEVICE_UID)
53-
message(FATAL_ERROR "CHIP_DEVICE_ROTATING_DEVICE_UID was not provided. To generate it use CONFIG_CHIP_DEVICE_GENERATE_ROTATING_DEVICE_UID=y")
51+
if(CONFIG_CHIP_ROTATING_DEVICE_ID)
52+
if(NOT CONFIG_CHIP_DEVICE_GENERATE_ROTATING_DEVICE_UID)
53+
if(NOT DEFINED CONFIG_CHIP_DEVICE_ROTATING_DEVICE_UID)
54+
message(FATAL_ERROR "CHIP_DEVICE_ROTATING_DEVICE_UID was not provided. To generate it use CONFIG_CHIP_DEVICE_GENERATE_ROTATING_DEVICE_UID=y")
55+
else()
56+
string(APPEND script_args "--rd_uid \"${CONFIG_CHIP_DEVICE_ROTATING_DEVICE_UID}\"\n")
57+
endif()
5458
else()
55-
string(APPEND script_args "--rd_uid \"${CONFIG_CHIP_DEVICE_ROTATING_DEVICE_UID}\"\n")
59+
string(APPEND script_args "--generate_rd_uid\n")
5660
endif()
57-
else()
58-
string(APPEND script_args "--generate_rd_uid\n")
61+
endif()
62+
63+
if(CONFIG_CHIP_FACTORY_DATA_CERT_SOURCE_GENERATED OR CONFIG_CHIP_FACTORY_DATA_GENERATE_CD)
64+
find_program(chip_cert_exe NAMES chip-cert REQUIRED)
65+
string(APPEND script_args "--chip_cert_path ${chip_cert_exe}\n")
66+
endif()
67+
68+
if(CONFIG_CHIP_FACTORY_DATA_GENERATE_CD)
69+
string(APPEND script_args "--gen_cd\n")
5970
endif()
6071

6172
# for development purpose user can use default certs instead of generating or providing them
@@ -77,10 +88,8 @@ elseif(CONFIG_CHIP_FACTORY_DATA_CERT_SOURCE_USER)
7788
string(APPEND script_args "--dac_cert \"${CONFIG_CHIP_FACTORY_DATA_USER_CERTS_DAC_CERT}\"\n")
7889
string(APPEND script_args "--dac_key \"${CONFIG_CHIP_FACTORY_DATA_USER_CERTS_DAC_KEY}\"\n")
7990
string(APPEND script_args "--pai_cert \"${CONFIG_CHIP_FACTORY_DATA_USER_CERTS_PAI_CERT}\"\n")
80-
else()
81-
find_program(chip_cert_exe NAMES chip-cert REQUIRED)
82-
string(APPEND script_args "--gen_cd\n")
83-
string(APPEND script_args "--chip_cert_path ${chip_cert_exe}\n")
91+
elseif(CONFIG_CHIP_FACTORY_DATA_CERT_SOURCE_GENERATED)
92+
string(APPEND script_args "--gen_certs\n")
8493
endif()
8594

8695
# add Password-Authenticated Key Exchange parameters
@@ -90,8 +99,14 @@ string(APPEND script_args "--discriminator ${CONFIG_CHIP_DEVICE_DISCRIMINATOR}\n
9099
string(APPEND script_args "--passcode ${CONFIG_CHIP_DEVICE_SPAKE2_PASSCODE}\n")
91100
string(APPEND script_args "--include_passcode\n")
92101
string(APPEND script_args "--overwrite\n")
93-
string(APPEND script_args "--product_finish ${CONFIG_CHIP_DEVICE_PRODUCT_FINISH}\n")
102+
# check if spake2 verifier should be generated using script
103+
if(NOT CONFIG_CHIP_FACTORY_DATA_GENERATE_SPAKE2_VERIFIER)
104+
# Spake2 verifier should be provided using kConfig
105+
string(APPEND script_args "--spake2_verifier \"${CONFIG_CHIP_DEVICE_SPAKE2_TEST_VERIFIER}\"\n")
106+
endif()
94107

108+
# Product appearance
109+
string(APPEND script_args "--product_finish ${CONFIG_CHIP_DEVICE_PRODUCT_FINISH}\n")
95110
if(CONFIG_CHIP_DEVICE_PRODUCT_COLOR)
96111
string(APPEND script_args "--product_color ${CONFIG_CHIP_DEVICE_PRODUCT_COLOR}\n")
97112
endif()
@@ -100,12 +115,6 @@ if(CONFIG_CHIP_FACTORY_DATA_GENERATE_ONBOARDING_CODES)
100115
string(APPEND script_args "--generate_onboarding\n")
101116
endif()
102117

103-
# check if spake2 verifier should be generated using script
104-
if(NOT CONFIG_CHIP_FACTORY_DATA_GENERATE_SPAKE2_VERIFIER)
105-
# Spake2 verifier should be provided using kConfig
106-
string(APPEND script_args "--spake2_verifier \"${CONFIG_CHIP_DEVICE_SPAKE2_TEST_VERIFIER}\"\n")
107-
endif()
108-
109118
if(CONFIG_CHIP_DEVICE_ENABLE_KEY)
110119
# Add optional EnableKey that triggers user-specific action.
111120
string(APPEND script_args "--enable_key \"${CONFIG_CHIP_DEVICE_ENABLE_KEY}\"\n")

docs/guides/nrfconnect_factory_data_configuration.md

+69-24
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,30 @@ data secure by applying hardware write protection.
3030
3131
<hr>
3232

33-
- [Configuring factory data for the nRF Connect examples](#configuring-factory-data-for-the-nrf-connect-examples)
34-
- [Overview](#overview)
35-
- [Factory data component table](#factory-data-component-table)
36-
- [Factory data format](#factory-data-format)
37-
- [Appearance field description](#appearance-field-description)
38-
- [Enabling factory data support](#enabling-factory-data-support)
39-
- [Generating factory data](#generating-factory-data)
40-
- [Creating the factory data JSON file with the first script](#creating-the-factory-data-json-file-with-the-first-script)
41-
- [How to set user data](#how-to-set-user-data)
42-
- [How to handle user data](#how-to-handle-user-data)
43-
- [Verifying using the JSON Schema tool](#verifying-using-the-json-schema-tool)
44-
- [Option 1: Using the php-json-schema tool](#option-1-using-the-php-json-schema-tool)
45-
- [Option 2: Using a website validator](#option-2-using-a-website-validator)
46-
- [Option 3: Using the nRF Connect Python script](#option-3-using-the-nrf-connect-python-script)
47-
- [Generating onboarding codes](#generating-onboarding-codes)
48-
- [Enabling onboarding codes generation within the build system](#enabling-onboarding-codes-generation-within-the-build-system)
49-
- [Preparing factory data partition on a device](#preparing-factory-data-partition-on-a-device)
50-
- [Creating a factory data partition with the second script](#creating-a-factory-data-partition-with-the-second-script)
51-
- [Building an example with factory data](#building-an-example-with-factory-data)
52-
- [Providing factory data parameters as a build argument list](#providing-factory-data-parameters-as-a-build-argument-list)
53-
- [Setting factory data parameters using interactive Kconfig interfaces](#setting-factory-data-parameters-using-interactive-kconfig-interfaces)
54-
- [Programming factory data](#programming-factory-data)
55-
- [Using own factory data implementation](#using-own-factory-data-implementation)
33+
- [Configuring factory data for the nRF Connect examples](#configuring-factory-data-for-the-nrf-connect-examples)
34+
- [Overview](#overview)
35+
- [Factory data component table](#factory-data-component-table)
36+
- [Factory data format](#factory-data-format)
37+
- [Appearance field description](#appearance-field-description)
38+
- [Enabling factory data support](#enabling-factory-data-support)
39+
- [Generating factory data](#generating-factory-data)
40+
- [Creating the factory data JSON file with the first script](#creating-the-factory-data-json-file-with-the-first-script)
41+
- [How to set user data](#how-to-set-user-data)
42+
- [How to handle user data](#how-to-handle-user-data)
43+
- [Verifying using the JSON Schema tool](#verifying-using-the-json-schema-tool)
44+
- [Option 1: Using the php-json-schema tool](#option-1-using-the-php-json-schema-tool)
45+
- [Option 2: Using a website validator](#option-2-using-a-website-validator)
46+
- [Option 3: Using the nRF Connect Python script](#option-3-using-the-nrf-connect-python-script)
47+
- [Generating onboarding codes](#generating-onboarding-codes)
48+
- [Enabling onboarding codes generation within the build system](#enabling-onboarding-codes-generation-within-the-build-system)
49+
- [Preparing factory data partition on a device](#preparing-factory-data-partition-on-a-device)
50+
- [Creating a factory data partition with the second script](#creating-a-factory-data-partition-with-the-second-script)
51+
- [Building an example with factory data](#building-an-example-with-factory-data)
52+
- [Providing factory data parameters as a build argument list](#providing-factory-data-parameters-as-a-build-argument-list)
53+
- [Setting factory data parameters using interactive Kconfig interfaces](#setting-factory-data-parameters-using-interactive-kconfig-interfaces)
54+
- [Default Kconfig values and developing aspects](#default-kconfig-values-and-developing-aspects)
55+
- [Programming factory data](#programming-factory-data)
56+
- [Using own factory data implementation](#using-own-factory-data-implementation)
5657

5758
<hr>
5859

@@ -272,6 +273,7 @@ To use this script, complete the following steps:
272273
273274
```
274275
--chip_cert_path <path to chip-cert executable>
276+
--gen_certs
275277
```
276278
277279
> **Note:** To generate new certificates, you need the `chip-cert`
@@ -293,7 +295,7 @@ To use this script, complete the following steps:
293295
--rd_uid <rotating device ID unique ID>
294296
```
295297
296-
- Generate a new ID and provide it ():
298+
- (optional) Generate a new ID and provide it:
297299
298300
```
299301
--generate_rd_uid
@@ -328,6 +330,17 @@ To use this script, complete the following steps:
328330
--product_color <color>
329331
```
330332
333+
j. (optional) Generate Certification Declaration for testing purposes
334+
335+
```
336+
--chip_cert_path <path to chip-cert executable>
337+
--gen_cd
338+
```
339+
340+
> **Note:** To generate new Certification Declaration, you need the `chip-cert`
341+
> executable. See the note at the end of this section to learn how to get
342+
> it.
343+
331344
4. Run the script using the prepared list of arguments:
332345
333346
```
@@ -794,6 +807,38 @@ snippet:
794807
> interfaces, read the
795808
> [Kconfig documentation](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/build/kconfig/menuconfig.html).
796809
810+
### Default Kconfig values and developing aspects
811+
812+
Each factory data parameter has its default value reflected in the Kconfig.
813+
The list below shows some Kconfig settings that are configured in the nRF Connect build system and have an impact on the application.
814+
You can modify them to achieve the desired behavior of your application.
815+
816+
* The device uses the test certificates located in the `credentials/development/attestation/` directory, which are generated using all default values.
817+
If you want to change the default `vendor_id`, `product_id`, `vendor_name`, or `device_name` and generate new test certificates, add the `CONFIG_CHIP_FACTORY_DATA_CERT_SOURCE_GENERATED=y` Kconfig option.
818+
Remember to build the `chip-cert` application and add it to the system PATH.
819+
820+
For developing a production-ready product, you need to write the certificates obtained during the certification process.
821+
To do this, add the `CONFIG_CHIP_FACTORY_DATA_CERT_SOURCE_USER=y` Kconfig option and set the appropriate paths for the following Kconfig options:
822+
823+
* `CONFIG_CHIP_FACTORY_DATA_USER_CERTS_DAC_CERT`
824+
* `CONFIG_CHIP_FACTORY_DATA_USER_CERTS_DAC_KEY`
825+
* `CONFIG_CHIP_FACTORY_DATA_USER_CERTS_PAI_CERT`
826+
827+
* By default, the SPAKE2+ verifier is generated during each example's build. This means that this value will change automatically if you change any of the following parameters:
828+
829+
* `CONFIG_CHIP_DEVICE_SPAKE2_PASSCODE`
830+
* `CONFIG_CHIP_DEVICE_SPAKE2_SALT`
831+
* `CONFIG_CHIP_DEVICE_SPAKE2_IT`
832+
833+
You can disable the generation of the SPAKE2+ verifier by setting the `CONFIG_CHIP_FACTORY_DATA_GENERATE_SPAKE2_VERIFIER=n` Kconfig option.
834+
Then, you will need to provide the externally-generated SPAKE2+ verifier using the `CONFIG_CHIP_DEVICE_SPAKE2_TEST_VERIFIER` Kconfig value.
835+
836+
* Generating the rotating device ID unique ID is disabled by default, but you can enable it by setting the `CONFIG_CHIP_ROTATING_DEVICE_ID=y` and `CONFIG_CHIP_DEVICE_GENERATE_ROTATING_DEVICE_UID=y` Kconfig values.
837+
Moreover, if you set the `CONFIG_CHIP_ROTATING_DEVICE_ID` Kconfig option to `y` and disable the `CONFIG_CHIP_DEVICE_GENERATE_ROTATING_DEVICE_UID` Kconfig option, you will need to provide it manually using the `CONFIG_CHIP_DEVICE_ROTATING_DEVICE_UID` Kconfig value.
838+
839+
* You can generate the test Certification Declaration by using the `CONFIG_CHIP_FACTORY_DATA_GENERATE_CD=y` Kconfig option.
840+
Remember to build the `chip-cert` application and add it to the system PATH.
841+
797842
<hr>
798843
799844
## Programming factory data

0 commit comments

Comments
 (0)