Skip to content

Commit

Permalink
Fix chip-tool to never use the stored node id when doing a new pairin…
Browse files Browse the repository at this point in the history
…g. (#8714)

We should use the default test id if we are not told to generate a
random one.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Aug 27, 2021
1 parent cdeb6d0 commit 1160824
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions examples/chip-tool/commands/pairing/PairingCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <controller/ExampleOperationalCredentialsIssuer.h>
#include <crypto/CHIPCryptoPAL.h>
#include <lib/core/CHIPSafeCasts.h>
#include <protocols/secure_channel/PASESession.h>
#include <support/logging/CHIPLogging.h>

#include <setup_payload/ManualSetupPayloadParser.h>
Expand All @@ -45,14 +46,16 @@ CHIP_ERROR PairingCommand::Run()
// TODO: Ideally we'd just ask for an operational cert for the commissionnee
// and get the node from that, but the APIs are not set up that way yet.
NodeId randomId;
if (Controller::ExampleOperationalCredentialsIssuer::GetRandomOperationalNodeId(&randomId) == CHIP_NO_ERROR)
{
ChipLogProgress(Controller, "Generated random node id: 0x" ChipLogFormatX64, ChipLogValueX64(randomId));
if (GetExecContext()->storage->SetRemoteNodeId(randomId) == CHIP_NO_ERROR)
{
GetExecContext()->remoteId = randomId;
}
}
ReturnErrorOnFailure(Controller::ExampleOperationalCredentialsIssuer::GetRandomOperationalNodeId(&randomId));

ChipLogProgress(Controller, "Generated random node id: 0x" ChipLogFormatX64, ChipLogValueX64(randomId));

ReturnErrorOnFailure(GetExecContext()->storage->SetRemoteNodeId(randomId));
GetExecContext()->remoteId = randomId;
#else // CONFIG_PAIR_WITH_RANDOM_ID
// Use the default id, not whatever happens to be in our storage, since this
// is a new pairing.
GetExecContext()->remoteId = kTestDeviceNodeId;
#endif // CONFIG_PAIR_WITH_RANDOM_ID

err = RunInternal(GetExecContext()->remoteId);
Expand Down

0 comments on commit 1160824

Please sign in to comment.