Skip to content

Commit bdfe352

Browse files
authored
Matter CASE Sigma1 resumption mode for faster reconnection (#21644)
1 parent d3f8afe commit bdfe352

File tree

3 files changed

+541
-514
lines changed

3 files changed

+541
-514
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file.
2121

2222
### Fixed
2323
- Matter interverted attributes 0xFFF9 and 0xFFFB (#21636)
24+
- Matter CASE Sigma1 resumption mode for faster reconnection
2425

2526
### Removed
2627

lib/libesp32/berry_matter/src/embedded/Matter_Commissioning.be

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,16 +334,14 @@ class Matter_Commisioning_Context
334334

335335
# find session
336336
var is_resumption = (sigma1.resumptionID != nil && sigma1.initiatorResumeMIC != nil)
337-
# log(format("MTR: is_resumption=%i", is_resumption ? 1 : 0), 4)
338-
# TODO disable resumption until fixed
339-
is_resumption = false
340337

341338
# Check that it's a resumption
342339
var session_resumption
343340
if is_resumption
344341
session_resumption = self.device.sessions.find_session_by_resumption_id(sigma1.resumptionID)
345342
# log(format("MTR: session_resumption found session=%s session_resumption=%s", matter.inspect(session), matter.inspect(session_resumption)), 4)
346343
if session_resumption == nil || session_resumption._fabric == nil
344+
log(f"MTR: Sigma1 Resumption FAILED, session not found resumption_id={sigma1.resumptionID}", 3)
347345
is_resumption = false
348346
end
349347
end
@@ -363,6 +361,8 @@ class Matter_Commisioning_Context
363361
var decrypted_tag = ec.tag()
364362

365363
# log("****************************************", 4)
364+
# log("MTR: * initiatorRandom = " + sigma1.initiatorRandom.tohex(), 4)
365+
# log("MTR: * ResumptionID = " + session_resumption.resumption_id.tohex(), 4)
366366
# log("MTR: * s1rk = " + s1rk.tohex(), 4)
367367
# log("MTR: * tag = " + tag.tohex(), 4)
368368
# log("MTR: * Resume1MICPayload = " + Resume1MICPayload.tohex(), 4)
@@ -392,8 +392,8 @@ class Matter_Commisioning_Context
392392

393393
var sigma2resume = matter.Sigma2Resume()
394394
sigma2resume.resumptionID = session.resumption_id
395-
sigma2resume.responderSessionID = session.__future_local_session_id
396395
sigma2resume.sigma2ResumeMIC = Resume2MIC
396+
sigma2resume.responderSessionID = session.__future_local_session_id
397397

398398
# log("****************************************", 4)
399399
# log("MTR: * s2rk = " + s2rk.tohex(), 4)
@@ -403,8 +403,10 @@ class Matter_Commisioning_Context
403403
# log("MTR: * sigma2ResumeMIC = " + Resume2MIC.tohex(), 4)
404404
# log("****************************************", 4)
405405
# # compute session key, p.178
406+
var salt_sessions = sigma1.initiatorRandom + session_resumption.resumption_id
407+
# log("MTR: * salt_session = " + salt_sessions.tohex(), 4)
406408
var session_keys = crypto.HKDF_SHA256().derive(session.shared_secret #- input key -#,
407-
sigma1.initiatorRandom + session.resumption_id #- salt -#,
409+
salt_sessions #- salt -#,
408410
bytes().fromstring("SessionResumptionKeys") #- info -#,
409411
48)
410412
var i2r = session_keys[0..15]
@@ -431,6 +433,7 @@ class Matter_Commisioning_Context
431433

432434
session.close()
433435
session.set_keys(i2r, r2i, ac, created)
436+
session.peer_node_id = session_resumption.peer_node_id # copy peer_node_id from session
434437

435438
# CASE Session completed, persist it
436439
session._breadcrumb = 0 # clear breadcrumb
@@ -440,8 +443,10 @@ class Matter_Commisioning_Context
440443
session.persist_to_fabric()
441444
session.save()
442445

446+
log("MTR: Sigma1 Resumption SUCCEEDED", 3)
443447
return true
444448
else
449+
log("MTR: Sigma1 Resumption FAILED, switching to CASE", 3)
445450
is_resumption = false
446451
# fall through normal sigma1 (non-resumption)
447452
end

0 commit comments

Comments
 (0)