|
| 1 | +# Introduction to Matter factory data |
| 2 | + |
| 3 | +Each Matter device should have it own unique factory data manufactured. |
| 4 | + |
| 5 | +This guide demonstrates what `Bouffalo Lab` provides to support factory data: |
| 6 | + |
| 7 | +- credential factory data protected by hardware security engine |
| 8 | +- reference tool to generate factory data |
| 9 | +- tool/method to program factory data |
| 10 | + |
| 11 | +# Matter factory data |
| 12 | + |
| 13 | +## How to enable |
| 14 | + |
| 15 | +One dedicate flash region allocates for factory data as below which is read-only |
| 16 | +for firmware. |
| 17 | + |
| 18 | +```toml |
| 19 | +name = "MFD" |
| 20 | +address0 = 0x3FE000 |
| 21 | +size0 = 0x1000 |
| 22 | +``` |
| 23 | + |
| 24 | +To enable matter factory data feature, please append `-mfd` option at end of |
| 25 | +target name. Take BL602 Wi-Fi Matter Light as example. |
| 26 | + |
| 27 | +``` |
| 28 | +./scripts/build/build_examples.py --target bouffalolab-bl602dk-light-littlefs-mfd build |
| 29 | +``` |
| 30 | + |
| 31 | +## Factory data |
| 32 | + |
| 33 | +This flash region is divided to two parts: |
| 34 | + |
| 35 | +- One is plain text data, such as Vendor ID, Product ID, Serial number and so |
| 36 | + on. |
| 37 | + |
| 38 | + > For development/test purpose, all data can put in plain text data. |
| 39 | +
|
| 40 | +- Other is cipher text data, such as private key for device attestation data. |
| 41 | + |
| 42 | + `Bouffalo Lab` provides hardware security engine to decrypt this part data |
| 43 | + with **only hardware access** efuse key. |
| 44 | + |
| 45 | +Current supported data |
| 46 | + |
| 47 | +- DAC certificate and private key |
| 48 | +- PAI certificate |
| 49 | +- Certificate declaration |
| 50 | + |
| 51 | +- Discriminator ID |
| 52 | +- Pass Code |
| 53 | +- Spake2p iteration count, salt and verifier |
| 54 | +- Vendor ID and name |
| 55 | +- Product ID and name |
| 56 | +- Product part number and product label |
| 57 | +- Manufacturing date |
| 58 | +- Hardware version and version string |
| 59 | +- Serial Number |
| 60 | +- Unique identifier |
| 61 | + |
| 62 | +> Note, it is available to add customer/product own information in factory data, |
| 63 | +> please reference to `bl_mfd.h`/`bl_mfd.c` in SDK and reference generation |
| 64 | +> script |
| 65 | +> [generate_factory_data.py](../../../scripts/tools/bouffalolab/generate_factory_data.py) |
| 66 | +
|
| 67 | +# Generate Matter factory data |
| 68 | + |
| 69 | +Script tool |
| 70 | +[generate_factory_data.py](../../../scripts/tools/bouffalolab/generate_factory_data.py) |
| 71 | +call `chip-cert` to generate test certificates and verify certificates. |
| 72 | + |
| 73 | +Please run below command to compile `chip-cert` tool under `connnectedhomeip` |
| 74 | +repo. |
| 75 | + |
| 76 | +```shell |
| 77 | +./scripts/build/build_examples.py --target linux-x64-chip-cert build |
| 78 | +``` |
| 79 | + |
| 80 | +## Command options |
| 81 | + |
| 82 | +- `--cd`, certificate declare |
| 83 | + |
| 84 | + If not specified, `Chip-Test-CD-Signing-Cert.pem` and |
| 85 | + `Chip-Test-CD-Signing-Key.pem` will sign a test certificate declare for |
| 86 | + development and test purpose |
| 87 | + |
| 88 | +- `--pai_cert` and `--pai-key`, PAI certificate and PAI private key |
| 89 | + |
| 90 | + If not specified, `Chip-Test-PAI-FFF1-8000-Cert.pem` and |
| 91 | + `Chip-Test-PAI-FFF1-8000-Key.pem` will be used for development and test |
| 92 | + purpose. |
| 93 | + |
| 94 | +- `--dac_cert` and `--dac_key`, DAC certificate and DAC private key. |
| 95 | + |
| 96 | + If not specified, script will use PAI certificate and key specified |
| 97 | + by`--pai_cert` and `--pai-key` to generate DAC certificate and private key |
| 98 | + for development and test purpose. |
| 99 | + |
| 100 | +- `--discriminator`, discriminator ID |
| 101 | + |
| 102 | + If not specified, script will generate for user. |
| 103 | + |
| 104 | +- `--passcode`, passcode |
| 105 | + |
| 106 | + If not specified, script will generate for user. |
| 107 | + |
| 108 | +- `--spake2p_it` and `--spake2p_salt` |
| 109 | + |
| 110 | + If not specified, script will generate and calculate verifier for user. |
| 111 | + |
| 112 | +Please reference to `--help` for more detail. |
| 113 | + |
| 114 | +## Generate with default test certificates |
| 115 | + |
| 116 | +- Run following command to generate all plain text factory data |
| 117 | + |
| 118 | + Please create output folder first. Here takes `out/test-cert` as example. |
| 119 | + |
| 120 | + ```shell |
| 121 | + ./scripts/tools/bouffalolab/generate_factory_data.py --output out/test-cert |
| 122 | + ``` |
| 123 | + |
| 124 | +- Run following command to generate factory data which encrypt private of |
| 125 | + device attestation data |
| 126 | + |
| 127 | + ```shell |
| 128 | + ./scripts/tools/bouffalolab/generate_factory_data.py --output out/test-cert --key <hex string of 16 bytes> |
| 129 | + ``` |
| 130 | + |
| 131 | + > An example of hex string of 16 bytes: 12345678123456781234567812345678 |
| 132 | + |
| 133 | +After command executes successfully, the output folder will has files as below: |
| 134 | + |
| 135 | +- Test certificate declare file which file name ends with `cd.der` |
| 136 | + |
| 137 | + If user wants to reuse CD generated before, please specify CD with option |
| 138 | + `--cd` as below. |
| 139 | + |
| 140 | + ```shell |
| 141 | + ./scripts/tools/bouffalolab/generate_factory_data.py --output out/test-cert --cd <cd file> |
| 142 | + ``` |
| 143 | + |
| 144 | +- Test DAC certificate and DAC certificate key which file names ends with |
| 145 | + `dac_cert.pem` and `dac_key.pem` separately. |
| 146 | + |
| 147 | +- QR code picture which file name ends with `onboard.png` |
| 148 | +- On board information which file name ends with `onboard.txt` |
| 149 | +- Matter factory data which file name ends with `mfd.bin`. |
| 150 | + |
| 151 | +## Generate with self-defined PAA/PAI certificates |
| 152 | + |
| 153 | +Self-defined PAA/PAI certificates may use in development and test scenario. But, |
| 154 | +user should know it has limit to work with real ecosystem. |
| 155 | + |
| 156 | +- Export environment variables in terminal for easy operations |
| 157 | + |
| 158 | + ``` |
| 159 | + export TEST_CERT_VENDOR_ID=130D # Vendor ID hex string |
| 160 | + export TEST_CERT_CN=BFLB # Common Name |
| 161 | + ``` |
| 162 | + |
| 163 | +- Generate PAA certificate and key to `out/cert` folder. |
| 164 | + |
| 165 | + ```shell |
| 166 | + mkdir out/test-cert |
| 167 | + ./out/linux-x64-chip-cert/chip-cert gen-att-cert --type a --subject-cn "${TEST_CERT_CN} PAA 01" --valid-from "2020-10-15 14:23:43" --lifetime 7305 --out-key out/test-cert/Chip-PAA-Key-${TEST_CERT_VENDOR_ID}.pem --out out/test-cert/Chip-PAA-Cert-${TEST_CERT_VENDOR_ID}.pem --subject-vid ${TEST_CERT_VENDOR_ID} |
| 168 | + ``` |
| 169 | + |
| 170 | +- Convert PAA PEM format file to PAA DER format file |
| 171 | + |
| 172 | + ```shell |
| 173 | + ./out/linux-x64-chip-cert/chip-cert convert-cert -d out/test-cert/Chip-PAA-Cert-${TEST_CERT_VENDOR_ID}.pem out/test-cert/Chip-PAA-Cert-${TEST_CERT_VENDOR_ID}.der |
| 174 | + ``` |
| 175 | + |
| 176 | + > Please save this PAA DER format file which will be used by `chip-tool` |
| 177 | + > during commissioning. |
| 178 | + |
| 179 | +- Generate PAI certificate and key: |
| 180 | + |
| 181 | + ```shell |
| 182 | + ./out/linux-x64-chip-cert/chip-cert gen-att-cert --type i --subject-cn "${TEST_CERT_CN} PAI 01" --subject-vid ${TEST_CERT_VENDOR_ID} --valid-from "2020-10-15 14:23:43" --lifetime 7305 --ca-key out/test-cert/Chip-PAA-Key-${TEST_CERT_VENDOR_ID}.pem --ca-cert out/test-cert/Chip-PAA-Cert-${TEST_CERT_VENDOR_ID}.pem --out-key out/test-cert/Chip-PAI-Key-${TEST_CERT_VENDOR_ID}.pem --out out/test-cert/Chip-PAI-Cert-${TEST_CERT_VENDOR_ID}.pem |
| 183 | + ``` |
| 184 | + |
| 185 | +- Generate `MFD` in plain text data |
| 186 | + |
| 187 | + ```shell |
| 188 | + ./scripts/tools/bouffalolab/generate_factory_data.py --output out/test-cert --paa_cert out/test-cert/Chip-PAA-Cert-${TEST_CERT_VENDOR_ID}.pem --paa_key out/test-cert/Chip-PAA-Key-${TEST_CERT_VENDOR_ID}.pem --pai_cert out/test-cert/Chip-PAI-Cert-${TEST_CERT_VENDOR_ID}.pem --pai_key out/test-cert/Chip-PAI-Key-${TEST_CERT_VENDOR_ID}.pem |
| 189 | + ``` |
| 190 | + |
| 191 | + > Appending `--key <hex string of 16 bytes>` option to enable encrypt |
| 192 | + > private key of attestation device data. |
| 193 | + |
| 194 | +## Generate with self-defined DAC certificate and key |
| 195 | + |
| 196 | +Self-defined DAC certificates may use in development and test scenario. But, |
| 197 | +user should know it has limit to work with real ecosystem. |
| 198 | + |
| 199 | +- Export environment variables in terminal for easy operations |
| 200 | + |
| 201 | + ``` |
| 202 | + export TEST_CERT_VENDOR_ID=130D # Vendor ID hex string |
| 203 | + export TEST_CERT_PRODUCT_ID=1001 # Vendor ID hex string |
| 204 | + export TEST_CERT_CN=BFLB # Common Name |
| 205 | + ``` |
| 206 | + |
| 207 | +- Generate DAC certificate and key |
| 208 | + |
| 209 | + ```shell |
| 210 | + out/linux-x64-chip-cert/chip-cert gen-att-cert --type d --subject-cn "${TEST_CERT_CN} PAI 01" --subject-vid ${TEST_CERT_VENDOR_ID} --subject-pid ${TEST_CERT_VENDOR_ID} --valid-from "2020-10-16 14:23:43" --lifetime 5946 --ca-key out/test-cert/Chip-PAI-Key-${TEST_CERT_VENDOR_ID}.pem --ca-cert out/test-cert/Chip-PAI-Cert-${TEST_CERT_VENDOR_ID}.pem --out-key out/test-cert/Chip-DAC-Key-${TEST_CERT_VENDOR_ID}-${TEST_CERT_PRODUCT_ID}.pem --out out/test-cert/Chip-DAC-Cert-${TEST_CERT_VENDOR_ID}-${TEST_CERT_PRODUCT_ID}.pem |
| 211 | + ``` |
| 212 | + |
| 213 | + > **Note**, `--valid-from` and `--lifetime` should be in `--valid-from` and |
| 214 | + > `--lifetime` of PAI certificate. |
| 215 | + |
| 216 | +- Generate `MFD` in plain text data |
| 217 | + |
| 218 | + ```shell |
| 219 | + ./scripts/tools/bouffalolab/generate_factory_data.py --output out/test-cert --pai_cert out/test-cert/Chip-PAI-Cert-${TEST_CERT_VENDOR_ID}.pem --dac_cert out/test-cert/Chip-DAC-Cert-${TEST_CERT_VENDOR_ID}-${TEST_CERT_PRODUCT_ID}.pem --dac_key out/test-cert/Chip-DAC-Key-${TEST_CERT_VENDOR_ID}-${TEST_CERT_PRODUCT_ID}.pem |
| 220 | + ``` |
| 221 | + |
| 222 | + > Appending `--key <hex string of 16 bytes>` option to enable encrypt |
| 223 | + > private key of attestation device data. |
| 224 | + |
| 225 | +# Program factory data |
| 226 | + |
| 227 | +After each target built successfully, a flash programming python script will be |
| 228 | +generated under out folder. |
| 229 | + |
| 230 | +Take BL616 Wi-Fi Matter Light as example, `chip-bl616-lighting-example.flash.py` |
| 231 | +is using to program firmware, and also for factory data and factory decryption |
| 232 | +key. |
| 233 | + |
| 234 | +```shell |
| 235 | +/out/bouffalolab-bl616dk-light-wifi-mfd/chip-bl616-lighting-example.flash.py --port <serial port> --mfd out/test-cert/<mfd bin file> |
| 236 | +``` |
| 237 | + |
| 238 | +> If `MFD` file has cipher text data, please append |
| 239 | +> `--key <hex string of 16 bytes>` option to program to this key to efuse. |
| 240 | + |
| 241 | +- Limits on BL IOT SDK |
| 242 | + |
| 243 | + If developer would like to program `MFD` with all plain text data, option |
| 244 | + `--key <hex string of 16 bytes>` needs pass to script, otherwise, flash tool |
| 245 | + will raise an error. And SoC BL602, BL702 and BL702L use BL IOT SDK for |
| 246 | + Matter Application. |
| 247 | + |
| 248 | +Please free contact to `Bouffalo Lab` for DAC provider service and higher |
| 249 | +security solution, such as SoC inside certificate requesting. |
0 commit comments