From 1699db059e5bc9369725df5961468551a9ae40e1 Mon Sep 17 00:00:00 2001 From: Abdul Samad Date: Thu, 4 Jul 2024 17:56:54 -0500 Subject: [PATCH] Add verifier arg to `CommissioningWindowOpener` --- .../OpenCommissioningWindowCommand.cpp | 2 +- .../OpenCommissioningWindowCommand.cpp | 2 +- src/controller/CommissioningWindowOpener.cpp | 19 +++++++++++++------ src/controller/CommissioningWindowOpener.h | 6 ++++-- .../ChipDeviceController-ScriptBinding.cpp | 2 +- src/darwin/Framework/CHIP/MTRBaseDevice.mm | 2 +- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/examples/chip-tool/commands/pairing/OpenCommissioningWindowCommand.cpp b/examples/chip-tool/commands/pairing/OpenCommissioningWindowCommand.cpp index 3d4c296e7864fb..8e25193d4a13f7 100644 --- a/examples/chip-tool/commands/pairing/OpenCommissioningWindowCommand.cpp +++ b/examples/chip-tool/commands/pairing/OpenCommissioningWindowCommand.cpp @@ -35,7 +35,7 @@ CHIP_ERROR OpenCommissioningWindowCommand::RunCommand() { SetupPayload ignored; return mWindowOpener->OpenCommissioningWindow(mNodeId, System::Clock::Seconds16(mCommissioningWindowTimeout), mIteration, - mDiscriminator, NullOptional, NullOptional, + mDiscriminator, NullOptional, NullOptional, NullOptional, &mOnOpenCommissioningWindowCallback, ignored, /* readVIDPIDAttributes */ true); } diff --git a/examples/fabric-admin/commands/pairing/OpenCommissioningWindowCommand.cpp b/examples/fabric-admin/commands/pairing/OpenCommissioningWindowCommand.cpp index 93d1f6f51002f8..ee1c49076bb055 100644 --- a/examples/fabric-admin/commands/pairing/OpenCommissioningWindowCommand.cpp +++ b/examples/fabric-admin/commands/pairing/OpenCommissioningWindowCommand.cpp @@ -35,7 +35,7 @@ CHIP_ERROR OpenCommissioningWindowCommand::RunCommand() { SetupPayload ignored; return mWindowOpener->OpenCommissioningWindow(mNodeId, System::Clock::Seconds16(mCommissioningWindowTimeout), mIteration, - mDiscriminator, NullOptional, NullOptional, + mDiscriminator, NullOptional, NullOptional, NullOptional, &mOnOpenCommissioningWindowCallback, ignored, /* readVIDPIDAttributes */ true); } diff --git a/src/controller/CommissioningWindowOpener.cpp b/src/controller/CommissioningWindowOpener.cpp index 47666972137bcc..7fee1ba1a07434 100644 --- a/src/controller/CommissioningWindowOpener.cpp +++ b/src/controller/CommissioningWindowOpener.cpp @@ -55,7 +55,7 @@ CHIP_ERROR CommissioningWindowOpener::OpenBasicCommissioningWindow(NodeId device CHIP_ERROR CommissioningWindowOpener::OpenCommissioningWindow(NodeId deviceId, Seconds16 timeout, uint32_t iteration, uint16_t discriminator, Optional setupPIN, - Optional salt, + Optional salt, Optional verifier, Callback::Callback * callback, SetupPayload & payload, bool readVIDPIDAttributes) { @@ -106,9 +106,16 @@ CHIP_ERROR CommissioningWindowOpener::OpenCommissioningWindow(NodeId deviceId, S mCommissioningWindowTimeout = timeout; mPBKDFIterations = iteration; - bool randomSetupPIN = !setupPIN.HasValue(); - ReturnErrorOnFailure( - PASESession::GeneratePASEVerifier(mVerifier, mPBKDFIterations, mPBKDFSalt, randomSetupPIN, mSetupPayload.setUpPINCode)); + if (verifier.HasValue()) + { + ReturnErrorOnFailure(mVerifier.Deserialize(verifier.Value())); + } + else + { + bool randomSetupPIN = !setupPIN.HasValue(); + ReturnErrorOnFailure( + PASESession::GeneratePASEVerifier(mVerifier, mPBKDFIterations, mPBKDFSalt, randomSetupPIN, mSetupPayload.setUpPINCode)); + } payload = mSetupPayload; @@ -354,8 +361,8 @@ CHIP_ERROR AutoCommissioningWindowOpener::OpenCommissioningWindow(DeviceControll } CHIP_ERROR err = opener->CommissioningWindowOpener::OpenCommissioningWindow( - deviceId, timeout, iteration, discriminator, setupPIN, salt, &opener->mOnOpenCommissioningWindowCallback, payload, - readVIDPIDAttributes); + deviceId, timeout, iteration, discriminator, setupPIN, salt, NullOptional, &opener->mOnOpenCommissioningWindowCallback, + payload, readVIDPIDAttributes); if (err != CHIP_NO_ERROR) { delete opener; diff --git a/src/controller/CommissioningWindowOpener.h b/src/controller/CommissioningWindowOpener.h index 10547dce3a662d..a380d80d1f936c 100644 --- a/src/controller/CommissioningWindowOpener.h +++ b/src/controller/CommissioningWindowOpener.h @@ -89,6 +89,8 @@ class CommissioningWindowOpener * least kSpake2p_Min_PBKDF_Salt_Length bytes and * at most kSpake2p_Max_PBKDF_Salt_Length bytes in * length. + * @param[in] verifier The PAKE passcode verifier to use, or NullOptional to + * generate verifier based on PIN and other parameters. * @param[in] callback The function to be called on success or failure of opening of commissioning window. * @param[out] payload The setup payload, not including the VID/PID bits, * even if those were asked for, that is generated @@ -104,8 +106,8 @@ class CommissioningWindowOpener */ CHIP_ERROR OpenCommissioningWindow(NodeId deviceId, System::Clock::Seconds16 timeout, uint32_t iteration, uint16_t discriminator, Optional setupPIN, Optional salt, - Callback::Callback * callback, SetupPayload & payload, - bool readVIDPIDAttributes = false); + Optional verifier, Callback::Callback * callback, + SetupPayload & payload, bool readVIDPIDAttributes = false); private: enum class Step : uint8_t diff --git a/src/controller/python/ChipDeviceController-ScriptBinding.cpp b/src/controller/python/ChipDeviceController-ScriptBinding.cpp index a98c8082d45380..ae2669ccca10c4 100644 --- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp +++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp @@ -715,7 +715,7 @@ PyChipError pychip_DeviceController_OpenCommissioningWindow(chip::Controller::De auto opener = Platform::New(static_cast(devCtrl)); PyChipError err = ToPyChipError(opener->OpenCommissioningWindow(nodeid, System::Clock::Seconds16(timeout), iteration, - discriminator, NullOptional, NullOptional, + discriminator, NullOptional, NullOptional, NullOptional, pairingDelegate->GetOpenWindowCallback(opener), payload)); return err; } diff --git a/src/darwin/Framework/CHIP/MTRBaseDevice.mm b/src/darwin/Framework/CHIP/MTRBaseDevice.mm index 331d61129b9daf..bbc9cea65722af 100644 --- a/src/darwin/Framework/CHIP/MTRBaseDevice.mm +++ b/src/darwin/Framework/CHIP/MTRBaseDevice.mm @@ -1784,7 +1784,7 @@ static CHIP_ERROR OpenCommissioningWindow(Controller::DeviceController * control auto * self = new OpenCommissioningWindowHelper(controller, callback); SetupPayload unused; CHIP_ERROR err = self->mOpener.OpenCommissioningWindow(nodeID, timeout, Crypto::kSpake2p_Min_PBKDF_Iterations, discriminator, - setupPIN, NullOptional, &self->mOnOpenCommissioningWindowCallback, unused); + setupPIN, NullOptional, NullOptional, &self->mOnOpenCommissioningWindowCallback, unused); if (err != CHIP_NO_ERROR) { delete self; }