Skip to content

Commit b13148a

Browse files
Damian-Nordicadbridge
authored andcommitted
[nrfconnect] Correct factory data JSON schema (project-chip#23386)
Fix typos and regular expressions do better catch format errors. Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no> Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
1 parent 13ebefd commit b13148a

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

scripts/tools/nrfconnect/nrfconnect_factory_data.schema

+14-12
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@
6868
"date": {
6969
"description": "Manufacturing date according to ISO 8601 in notation YYYY-MM-DD",
7070
"type": "string",
71-
"format": "date"
71+
"format": "date",
72+
"minLength": 10,
73+
"maxLength": 10,
74+
"pattern": "^\\d{4}-\\d{2}-\\d{2}$"
7275
},
7376
"hw_ver": {
7477
"description": "Hardware version - integer",
@@ -85,30 +88,29 @@
8588
"rd_uid": {
8689
"description": "A randomly-generated 128-bit or longer octet string. Length has been expanded with 'hex:' prefix",
8790
"type": "string",
88-
"pattern:": "^hex:{1}",
91+
"pattern": "^hex:([0-9A-Fa-f]{2}){16,}$",
8992
"minLength": 20,
90-
"minLength": 5,
91-
"maxLength": 36
93+
"minLength": 36
9294
},
9395
"dac_cert": {
9496
"description": "DAC certificate in hex-string format",
9597
"type": "string",
96-
"pattern:": "^hex:{1}([0-9A-Fa-f]){2,}",
97-
"minLength": 5,
98+
"pattern": "^hex:([0-9A-Fa-f]{2})+$",
99+
"minLength": 6,
98100
"maxLength": 1204
99101
},
100102
"dac_key": {
101103
"description": "DAC Private Key in hex-string format",
102104
"type": "string",
103-
"pattern:": "^hex:{1}([0-9A-Fa-f]){2,}",
105+
"pattern": "^hex:([0-9A-Fa-f]{2}){32}$",
104106
"minLength": 68,
105107
"maxLength": 68
106108
},
107109
"pai_cert": {
108110
"description": "PAI certificate in hex-string format",
109111
"type": "string",
110-
"pattern:": "^hex:{1}([0-9A-Fa-f]){2,}",
111-
"minLength": 5,
112+
"pattern": "^hex:([0-9A-Fa-f]{2})+$",
113+
"minLength": 6,
112114
"maxLength": 1204
113115
},
114116
"passcode": {
@@ -126,14 +128,14 @@
126128
"spake2_salt": {
127129
"description": "A key-derivation function for the Symmetric Password-Authenticated Key Exchange.",
128130
"type": "string",
129-
"pattern:": "^hex:{1}([0-9A-Fa-f]){2,}",
131+
"pattern": "^hex:([0-9A-Fa-f]{2})+$",
130132
"minLength": 36,
131133
"maxLength": 68
132134
},
133135
"spake2_verifier": {
134136
"description": "A verifier for the Symmetric Password-Authenticated Key Exchange",
135137
"type": "string",
136-
"pattern:": "^hex:{1}([0-9A-Fa-f]){2,}",
138+
"pattern": "^hex:([0-9A-Fa-f]{2})+$",
137139
"minLength": 97
138140
},
139141
"discriminator": {
@@ -145,7 +147,7 @@
145147
"enable_key": {
146148
"description": "The Enable Key is a 128-bit value that triggers manufacturer-specific action while invoking the TestEventTrigger Command",
147149
"type": "string",
148-
"pattern": "^hex:{1}([0-9A-Fa-f]){32}",
150+
"pattern": "^hex:([0-9A-Fa-f]{2}){16}$",
149151
"minLength": 36,
150152
"maxLength": 36
151153
},

scripts/tools/nrfconnect/tests/test_generate_factory_data.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def test_generate_factory_data_all_specified(self):
148148
write_file(os.path.join(outdir, 'PAI_cert.der'), PAI_DER_CERT)
149149

150150
subprocess.check_call(['python3', os.path.join(TOOLS_DIR, 'generate_nrfconnect_chip_factory_data.py'),
151+
'-s', os.path.join(TOOLS_DIR, 'nrfconnect_factory_data.schema'),
151152
'--include_passcode',
152153
'--sn', 'SN:12345678',
153154
'--vendor_id', '0x127F',
@@ -167,7 +168,7 @@ def test_generate_factory_data_all_specified(self):
167168
'--passcode', '13243546',
168169
'--spake2_verifier', 'WN0SgEXLfUN19BbJqp6qn4pS69EtdNLReIMZwv/CIM0ECMP7ytiAJ7txIYJ0Ovlha/rQ3E+88mj3qaqqnviMaZzG+OyXEdSocDIT9ZhmkTCgWwERaHz4Vdh3G37RT6kqbw==',
169170
'--discriminator', '0xFED',
170-
'--rd_uid', '0123456789ABCDEF',
171+
'--rd_uid', '91a9c12a7c80700a31ddcfa7fce63e44',
171172
'--enable_key', '00112233445566778899aabbccddeeff',
172173
'-o', os.path.join(outdir, 'fd.json')
173174
])
@@ -194,7 +195,7 @@ def test_generate_factory_data_all_specified(self):
194195
'WN0SgEXLfUN19BbJqp6qn4pS69EtdNLReIMZwv/CIM0ECMP7ytiAJ7txIYJ0Ovlha/rQ3E+88mj3qaqqnviMaZzG+OyXEdSocDIT9ZhmkTCgWwERaHz4Vdh3G37RT6kqbw=='))
195196
self.assertEqual(factory_data.get('discriminator'), 0xFED)
196197
self.assertEqual(factory_data.get('passcode'), 13243546)
197-
self.assertEqual(factory_data.get('rd_uid'), 'hex:0123456789ABCDEF')
198+
self.assertEqual(factory_data.get('rd_uid'), 'hex:91a9c12a7c80700a31ddcfa7fce63e44')
198199
self.assertEqual(factory_data.get('enable_key'), 'hex:00112233445566778899aabbccddeeff')
199200

200201

0 commit comments

Comments
 (0)