Skip to content

Commit 615f0f5

Browse files
Pull request project-chip#1797: Bugfix: Provision: CSR mode fixed.
Merge in WMN_TOOLS/matter from bugfix/provision_csr_mode to RC_2.3.0-1.3 Squashed commit of the following: commit 5627ee1 Author: Ricardo Casallas <77841255+rcasallas-silabs@users.noreply.github.com> Date: Mon Apr 29 11:59:47 2024 -0400 Bugfix: Provision: CSR mode fixed.
1 parent 0199eb1 commit 615f0f5

17 files changed

+42767
-42818
lines changed

examples/platform/silabs/provision/ProvisionProtocolV2.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,6 @@ struct CsrCommand: public Command
299299
{
300300
CsrCommand(Storage & store): Command(kCommand_Init, store)
301301
{
302-
// Always return CSR file
303-
_feedback_list.Add(Parameters::kCsrFile, Type_Binary);
304302
}
305303

306304
CHIP_ERROR ProcessIncoming(Argument &arg) override
@@ -314,6 +312,10 @@ struct CsrCommand: public Command
314312
case Parameters::kCommonName:
315313
return mStore.Set(arg.id, arg.value.b, arg.size);
316314

315+
case Parameters::kCsrFile:
316+
ReturnErrorOnFailure(_feedback_list.Add(arg.id, arg.type));
317+
return CHIP_NO_ERROR;
318+
317319
default:
318320
return CHIP_ERROR_UNKNOWN_RESOURCE_ID;
319321
}

provision/images/efr32mg12_psa123_nvm3k2.s37

+5,224-5,224
Large diffs are not rendered by default.

provision/images/efr32mg12_psa12_nvm3k1.s37

+5,153-5,153
Large diffs are not rendered by default.

provision/images/efr32mg12_psa12_nvm3k2.s37

+5,153-5,153
Large diffs are not rendered by default.

provision/images/efr32mg12_psa3_nvm3k2.s37

+5,500-5,502
Large diffs are not rendered by default.

provision/images/efr32mg24_psa123_nvm3k2.s37

+5,759-5,761
Large diffs are not rendered by default.

provision/images/efr32mg24_psa12_nvm3k1.s37

+5,313-5,313
Large diffs are not rendered by default.

provision/images/efr32mg24_psa12_nvm3k2.s37

+5,313-5,313
Large diffs are not rendered by default.

provision/images/efr32mg24_psa3_nvm3k2.s37

+5,315-5,315
Large diffs are not rendered by default.

provision/modules/arguments.py

+1-59
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def compileCommandInputs(self, versions, file_ver, params_path):
178178
# Load parsed values into existing arguments
179179
for k, v in inputs.items():
180180
if v is not None:
181-
arg = self.find(k)
181+
arg = self.find(k, True)
182182
arg.set(v, arg.default)
183183
arg.is_user_input = True
184184
# Create export formatter
@@ -189,7 +189,6 @@ def parseCommandLine(self, params):
189189
# Configure parser
190190
parser = argparse.ArgumentParser(add_help=False, conflict_handler='resolve')
191191
for k, p in params.ids.items():
192-
# print("{}~ {}".format(_util.MARGIN, p))
193192
# Fixed arguments
194193
if p.fixed:
195194
parser.add_argument(p.name, nargs='?', default=p.default)
@@ -217,60 +216,3 @@ def print(self):
217216
content += "\n{}+ {}".format(_util.MARGIN, a)
218217
if len(content) > 0:
219218
print("* {}({}/{}):{}\n".format(n, count, len(g), content))
220-
221-
222-
class CommonArguments:
223-
PARAMS_PATH = 'modules/parameters.yaml'
224-
225-
def __init__(self, paths) -> None:
226-
super().__init__(paths)
227-
self.configure(paths.base(CommonArguments.PARAMS_PATH))
228-
self.channel = None
229-
230-
def formatOutput(self, main = {}):
231-
# Version
232-
self.insert(main, 'version')
233-
# Options
234-
main['options'] = options = {}
235-
self.insert(options, 'stop')
236-
self.insert(options, 'params', 'parameters')
237-
self.insert(options, 'inputs')
238-
self.insert(options, 'output')
239-
self.insert(options, 'temp')
240-
self.insert(options, 'device')
241-
self.insert(options, 'channel')
242-
self.insert(options, 'generate')
243-
self.insert(options, 'csr')
244-
self.insert(options, 'gen_fw')
245-
self.insert(options, 'prod_fw')
246-
self.insert(options, 'cert_tool')
247-
self.insert(options, 'pylink_lib')
248-
if len(options) > 0: main['options'] = options
249-
# Matter
250-
main['matter'] = matter = {}
251-
# Custom
252-
self.insertCustom(main)
253-
return main
254-
255-
256-
def collectInputs(self, cin, fin = {}):
257-
# Version
258-
self.collect(fin, cin, 'version')
259-
self.collect(fin, cin, 'action')
260-
self.collect(fin, cin, 'extra')
261-
# Options
262-
options = ('options' in fin) and fin['options'] or None
263-
self.collect(options, cin, 'stop')
264-
self.collect(options, cin, 'parameters', 'params')
265-
self.collect(options, cin, 'output')
266-
self.collect(options, cin, 'temp')
267-
self.collect(options, cin, 'device')
268-
self.collect(options, cin, 'channel')
269-
self.collect(options, cin, 'generate')
270-
self.collect(options, cin, 'csr')
271-
self.collect(options, cin, 'gen_fw')
272-
self.collect(options, cin, 'prod_fw')
273-
self.collect(options, cin, 'cert_tool')
274-
self.collect(options, cin, 'pylink_lib')
275-
# Custom
276-
self.collectCustom(cin, fin)

provision/modules/credentials.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ def collect(self):
5151
# Collect PKCS#12 bundle
5252
self.collectPKCS12(pkcs12, pai_cert, dac_cert, dac_key)
5353

54-
#Calculate offsets sizes here and generate the silabs_cred.h header file
5554

56-
self.generateLegacyHeader(dac_cert, pai_cert, cd)
57-
58-
59-
def generateLegacyHeader(self, dac_cert, pai_cert, cd):
55+
def generateLegacyHeader(self):
56+
cd = self.args.get(ID.kCertification)
57+
pai_cert = self.args.get(ID.kPaiCert)
58+
dac_cert = self.args.get(ID.kDacCert)
6059
# Calculate offsets
6160
dac_stats = os.stat(dac_cert.str())
6261
pai_stats = os.stat(pai_cert.str())

provision/modules/formatter.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def parse(self, main):
5353
self.extract(options, 'device')
5454
self.extract(options, 'channel')
5555
self.extract(options, 'generate')
56-
self.extract(options, 'csr')
56+
self.extract(options, 'csr_mode')
5757
self.extract(options, 'gen_fw')
5858
self.extract(options, 'prod_fw')
5959
self.extract(options, 'cert_tool')
@@ -72,7 +72,7 @@ def format(self, main = {}):
7272
self.insert(options, 'device')
7373
self.insert(options, 'channel')
7474
self.insert(options, 'generate')
75-
self.insert(options, 'csr')
75+
self.insert(options, 'csr_mode')
7676
self.insert(options, 'gen_fw')
7777
self.insert(options, 'prod_fw')
7878
self.insert(options, 'cert_tool')

provision/modules/manager.py

+5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def execute(self, paths, args):
4242
paths.setTemp(args.str(ID.kTemporaryDir))
4343

4444
# Compute defaults
45+
creds = _creds.Credentials(paths, args)
4546
if ('auto' == action) or ('binary' == action):
47+
creds.collect()
4648
self.computeDefaults(paths, args)
4749

4850
# Stop
@@ -68,6 +70,9 @@ def execute(self, paths, args):
6870
# Export arguments (including returned values)
6971
args.export()
7072

73+
# Generate legacy header (silabs_cred.h) with credentials offsets and sizes
74+
creds.generateLegacyHeader()
75+
7176
# Production Firmware
7277
if _chan.Channel.BLE != chan.type:
7378
self.writeProductionFirmware(args, conn)

provision/modules/parameters.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ class ParameterList:
331331
def __init__(self, paths, custom_path = None) -> None:
332332
self.paths = paths
333333
self.names = {}
334+
self.longs = {}
334335
self.ids = {}
335336
self.groups = {}
336337
self.custom = {}
@@ -370,6 +371,7 @@ def add(self, id, y):
370371
self.ids[id] = p
371372
p.parse(y)
372373
self.names[p.name] = p
374+
self.longs[p.long] = p
373375
return p
374376

375377
def create(self, y):
@@ -380,9 +382,13 @@ def get(self, k):
380382
return self.ids[k]
381383
raise ValueError("Unknown parameter 0x{:02x}".format(k))
382384

383-
def find(self, name):
384-
if name in self.names:
385-
return self.names[name]
385+
def find(self, name, use_long = False):
386+
if use_long:
387+
if name in self.longs:
388+
return self.longs[name]
389+
else:
390+
if name in self.names:
391+
return self.names[name]
386392
raise ValueError("Unknown parameter \"{}\"".format(name))
387393

388394
def findList(self, names):

provision/modules/parameters.yaml

+5-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ internal:
3131

3232
- id: 0x0105
3333
desc: 'Certificate Signing Request'
34-
name: '_csr_'
34+
name: 'csr'
35+
long: 'csr_file'
3536
short: '_i5'
36-
type: 'string'
37+
type: 'path'
3738
hidden: true
3839

3940
options:
@@ -111,7 +112,8 @@ options:
111112

112113
- id: 0x0134
113114
desc: 'Certificate Signing Request Mode'
114-
name: 'csr'
115+
name: 'csr_mode'
116+
long: 'csr'
115117
short: 'r'
116118
type: 'flag'
117119

provision/modules/v1_0/protocol.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def decode(self):
9292
pass
9393

9494
def execute(self, chan):
95-
print("{}:".format(self.name))
95+
print("\n{}:".format(self.name))
9696
# Encode
9797
self.addInt8u(self.id)
9898
self.encode()
@@ -188,7 +188,7 @@ def encode(self):
188188
def decode(self):
189189
kid = self.getInt32u()
190190
csr = self.getString()
191-
print("{}+ vendor_id:{:04x}, product_id:{:04x}, key:{}, req({}):\n{}".format(_util.MARGIN, self.vendor_id, self.product_id, kid, len(csr), csr))
191+
print("{}+ vendor_id:{:04x}, product_id:{:04x}, key:{}, csr({})\n".format(_util.MARGIN, self.vendor_id, self.product_id, kid, len(csr)))
192192
# Write CSR to file
193193
_util.File(self.csr_path).write(csr)
194194

provision/modules/v2_0/protocol.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,23 @@ def execute(self, paths, args, chan):
3030
return e.export()
3131
# Init
3232
init = InitCommand(paths, args)
33+
init.execute(chan)
3334
if 'auto' == action:
35+
# CSR
3436
if args.bool(ID.kCsrMode):
3537
self.csr(paths, args, chan)
3638
# Write all
3739
write = AutoCommand(paths, args)
38-
init.execute(chan)
3940
write.execute(chan)
4041
write = FinishCommand(paths, args)
4142
write.execute(chan)
4243
elif 'write' == action:
4344
# Write non-nulls
4445
write = WriteCommand(paths, args)
45-
init.execute(chan)
4646
write.execute(chan)
4747
elif 'read' == action:
4848
# Read
4949
read = ReadCommand(paths, args, args.str(ID.kExtra))
50-
init.execute(chan)
5150
read.execute(chan)
5251
else:
5352
raise ValueError("Action not supported: \"{}\"".format(action))
@@ -73,10 +72,8 @@ def csr(self, paths, args, chan):
7372
# CSR
7473
cmd = CsrCommand(paths, args)
7574
cmd.execute(chan)
76-
# Write CSR to file
77-
csr_path = paths.temp('csr.pem')
78-
_util.File(csr_path).write(args.value(ID.kCsrFile))
7975
# Sign
76+
csr_path = args.value(ID.kCsrFile)
8077
signer = _pki.SigningServer(base_dir, csr_path, pai_cert_path, pai_key_path, dac_path)
8178
signer.sign()
8279

@@ -222,7 +219,7 @@ def receivePackage(self, chan, counter, req):
222219
self.fail(req, res, e)
223220

224221
def encodeValue(self, a):
225-
if not self.send_values:
222+
if (not self.send_values) or (a.value is None):
226223
return None
227224
elif (Types.BINARY == a.type) and (Formats.PATH == a.format) and os.path.isfile(a.value):
228225
return _util.BinaryFile(a.value).read()
@@ -247,7 +244,7 @@ def processIncoming(self, ctx, value):
247244
if Formats.PATH == arg.format:
248245
if arg.value is None:
249246
# Use temporary file
250-
arg.set(self.paths.temp("{}.bin".format(arg.name)))
247+
arg.set(self.paths.temp("{}.bin".format(arg.name)), None, False)
251248
_util.BinaryFile(arg.value).write(value)
252249
else:
253250
arg.set(value, None, False)

0 commit comments

Comments
 (0)