Skip to content

Add unsecure exchange initiation#385

Merged
ivmarkov merged 9 commits intoproject-chip:mainfrom
estincelle:marko/unsecure-exchange-initiation
Mar 11, 2026
Merged

Add unsecure exchange initiation#385
ivmarkov merged 9 commits intoproject-chip:mainfrom
estincelle:marko/unsecure-exchange-initiation

Conversation

@marko655
Copy link
Copy Markdown
Contributor

@marko655 marko655 commented Mar 3, 2026

This PR adds the building blocks to initiate an unsecured exchange, a prerequisite for PASE and CASE initiator flows (a part of #368).

  • Exchange::initiate_unsecured() is the public entry point for opening a new unsecured exchange.
  • An xtask integration test (cargo xtask exchangetest) is added to verify the exchange, it: starts a Matter example device, opens an unsecured exchange, sends a PASE PBKDFParamRequest to the device, and asserts that the device responds.
  • A CI workflow (exchange-tests.yml) is added to run the integration test.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request provides the foundational components for initiating unsecured communication exchanges within the Matter protocol. It enables controllers to establish plain-text sessions with devices, which is a prerequisite for secure pairing mechanisms like PASE and CASE. The changes include new API methods for session and exchange creation, along with comprehensive testing to validate the functionality and ensure its reliability in various scenarios.

Highlights

  • Unsecured Exchange Initiation API: Introduced Exchange::initiate_unsecured(), a new public entry point for establishing unsecured (plain-text) exchanges, crucial for PASE and CASE initiator flows. This includes lower-level create_unsecured_session() and initiate_unsecured_now() methods within TransportMgr.
  • Integration Test for Unsecured Exchanges: Added a new cargo xtask exchangetest integration test. This test starts a Matter example device, initiates an unsecured exchange, sends a PASE PBKDFParamRequest, and verifies the device's response, ensuring the new API functions correctly.
  • CI Workflow for Exchange Tests: A new CI workflow (exchange-tests.yml) has been implemented to automatically run the integration test, ensuring continuous validation of the unsecured exchange functionality.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • rs-matter/src/transport.rs
    • Added create_unsecured_session function to create new plain-text sessions.
    • Added initiate_unsecured_now function to combine session creation and exchange initiation.
    • Included unit tests for the new unsecured session and exchange initiation functionalities.
  • rs-matter/src/transport/exchange.rs
    • Imported the Crypto trait.
    • Implemented initiate_unsecured as a public asynchronous function for creating initiator exchanges, incorporating session eviction logic.
    • Added unit tests for initiate_unsecured, covering successful initiation, retry mechanisms, and failure conditions.
  • xtask/Cargo.toml
    • Added new dependencies: embassy-sync, embassy-futures, rand, and static_cell.
  • xtask/src/exchangetest.rs
    • Added a new module containing the ExchangeTests utility and the core logic for the exchange initiation integration test.
  • xtask/src/main.rs
    • Imported the new exchangetest module.
    • Added a new Exchangetest subcommand to the CLI, allowing configuration of device IP, port, binary, features, profile, and wait time.
    • Integrated the Exchangetest command handler to execute the exchange initiation test.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/exchange-tests.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 3, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the necessary components for initiating unsecured exchanges, a crucial step for PASE and CASE initiator flows, including Exchange::initiate_unsecured() and its supporting functions in TransportMgr, along with a new integration test, exchangetest. A critical security concern has been identified regarding the use of non-cryptographically secure randomness for initializing message counters in new unsecured sessions, which violates the Matter specification's requirement for unpredictable message counters. Furthermore, opportunities for improvement exist concerning error handling robustness and code clarity.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 3, 2026

PR #385: Size comparison from 96b3d51 to 7395920

Full report (8 builds for (core), dimmable-light, onoff-light, onoff-light-bt, speaker)
platform target config section 96b3d51 7395920 change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 383376 383350 -26 -0.0
RAM 65880 65880 0 0.0
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 322588 322620 32 0.0
RAM 62208 62208 0 0.0
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 295964 295956 -8 -0.0
RAM 61696 61700 4 0.0
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 820391 820391 0 0.0
RAM 65544 65544 0 0.0
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1885456 1885568 112 0.0
RAM 46904 46904 0 0.0
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1813448 1813528 80 0.0
RAM 46576 46576 0 0.0
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3131736 3130936 -800 -0.0
RAM 9304 9304 0 0.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 801120 801104 -16 -0.0
RAM 2832 2832 0 0.0

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 3, 2026

PR #385: Size comparison from 96b3d51 to de999cd

Full report (8 builds for (core), dimmable-light, onoff-light, onoff-light-bt, speaker)
platform target config section 96b3d51 de999cd change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 383376 383350 -26 -0.0
RAM 65880 65880 0 0.0
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 322588 322620 32 0.0
RAM 62208 62208 0 0.0
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 295964 295956 -8 -0.0
RAM 61696 61700 4 0.0
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 820391 820375 -16 -0.0
RAM 65544 65544 0 0.0
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1885456 1885568 112 0.0
RAM 46904 46904 0 0.0
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1813448 1813528 80 0.0
RAM 46576 46576 0 0.0
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3131736 3130936 -800 -0.0
RAM 9304 9304 0 0.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 801120 801104 -16 -0.0
RAM 2832 2832 0 0.0

@marko655 marko655 force-pushed the marko/unsecure-exchange-initiation branch from de999cd to a040c0c Compare March 3, 2026 14:53
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 3, 2026

PR #385: Size comparison from 96b3d51 to a040c0c

Full report (8 builds for (core), dimmable-light, onoff-light, onoff-light-bt, speaker)
platform target config section 96b3d51 a040c0c change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 383376 383350 -26 -0.0
RAM 65880 65880 0 0.0
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 322588 322620 32 0.0
RAM 62208 62208 0 0.0
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 295964 295956 -8 -0.0
RAM 61696 61700 4 0.0
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 820391 820375 -16 -0.0
RAM 65544 65544 0 0.0
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1885456 1885568 112 0.0
RAM 46904 46904 0 0.0
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1813448 1813528 80 0.0
RAM 46576 46576 0 0.0
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3131736 3130936 -800 -0.0
RAM 9304 9304 0 0.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 801120 801104 -16 -0.0
RAM 2832 2832 0 0.0

Copy link
Copy Markdown
Contributor

@ivmarkov ivmarkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do have some smaller nits, like e.g. the names of the newly introduced methods in TransportMgr and Exchange, but these are not so important so I have not even noted them.

Most important is to clarify why we need exchangetest to be part of the xtask test suite in the first place.

marko655 added 9 commits March 6, 2026 08:53
    Checking rs-matter v0.1.1
(/home/runner/work/rs-matter/rs-matter/rs-matter)
error: this `if` has identical blocks
   --> rs-matter/src/dm/types/cluster.rs:466:26
    |
466 |               if index > 0 {
    |  __________________________^
467 | |                 defmt::write!(f, ", {}", attr);
468 | |             } else {
    | |_____________^
    |
note: same as this
   --> rs-matter/src/dm/types/cluster.rs:468:20
    |
468 |               } else {
    |  ____________________^
469 | |                 defmt::write!(f, "{}", attr);
470 | |             }
    | |_____________^
    = help: for further information visit
https://rust-lang.github.io/rust-clippy/rust-1.94.0/index.html#if_same_then_else
    = note: `-D clippy::if-same-then-else` implied by `-D warnings`
    = help: to override `-D warnings` add
`#[allow(clippy::if_same_then_else)]`

error: this `if` has identical blocks
   --> rs-matter/src/dm/types/cluster.rs:475:26
    |
475 |               if index > 0 {
    |  __________________________^
476 | |                 defmt::write!(f, ", {}", cmd);
477 | |             } else {
    | |_____________^
    |
note: same as this
   --> rs-matter/src/dm/types/cluster.rs:477:20
    |
477 |               } else {
    |  ____________________^
478 | |                 defmt::write!(f, "{}", cmd);
479 | |             }
    | |_____________^
    = help: for further information visit
https://rust-lang.github.io/rust-clippy/rust-1.94.0/index.html#if_same_then_else
@marko655 marko655 force-pushed the marko/unsecure-exchange-initiation branch from a040c0c to b9b4d31 Compare March 6, 2026 11:00
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 6, 2026

PR #385: Size comparison from e9314f9 to b9b4d31

Full report (8 builds for (core), dimmable-light, onoff-light, onoff-light-bt, speaker)
platform target config section e9314f9 b9b4d31 change % change
(core) riscv32imac-unknown-none-elf infodefmt-optz-ltofat FLASH 383352 383516 164 0.0
RAM 65880 65880 0 0.0
thumbv6m-none-eabi infodefmt-optz-ltofat FLASH 322612 322764 152 0.0
RAM 62216 62208 -8 -0.0
thumbv7em-none-eabi infodefmt-optz-ltofat FLASH 295964 296184 220 0.1
RAM 61708 61704 -4 -0.0
x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 820391 821847 1456 0.2
RAM 65544 65544 0 0.0
dimmable-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1885664 1884488 -1176 -0.1
RAM 46904 46904 0 0.0
onoff-light x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 1813608 1812376 -1232 -0.1
RAM 46576 46576 0 0.0
onoff-light-bt x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 3130952 3130264 -688 -0.0
RAM 9304 9304 0 0.0
speaker x86_64-unknown-linux-gnu infologs-optz-ltofat FLASH 801120 801920 800 0.1
RAM 2832 2832 0 0.0

@marko655
Copy link
Copy Markdown
Contributor Author

marko655 commented Mar 6, 2026

I do have some smaller nits, like e.g. the names of the newly introduced methods in TransportMgr and Exchange, but these are not so important so I have not even noted them.

Most important is to clarify why we need exchangetest to be part of the xtask test suite in the first place.

Thanks for the feedback!
Tried to handle it with the latest update. Let me know if it looks better now

Additionally, I've pushed a lint fix in b9b4d31 (seems toolchain update made it visible now) this was done to unblock CI for this PR, if you prefer it fixed differently / outside this PR (since it is technically unrelated to the PR content) let me know so I can drop it.

Thanks!

@ivmarkov ivmarkov merged commit b040a28 into project-chip:main Mar 11, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants