Skip to content

Commit

Permalink
Add verifier arg to CommissioningWindowOpener
Browse files Browse the repository at this point in the history
  • Loading branch information
samadDotDev committed Jul 5, 2024
1 parent f779369 commit 1699db0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
19 changes: 13 additions & 6 deletions src/controller/CommissioningWindowOpener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t> setupPIN,
Optional<ByteSpan> salt,
Optional<ByteSpan> salt, Optional<ByteSpan> verifier,
Callback::Callback<OnOpenCommissioningWindow> * callback,
SetupPayload & payload, bool readVIDPIDAttributes)
{
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/controller/CommissioningWindowOpener.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -104,8 +106,8 @@ class CommissioningWindowOpener
*/
CHIP_ERROR OpenCommissioningWindow(NodeId deviceId, System::Clock::Seconds16 timeout, uint32_t iteration,
uint16_t discriminator, Optional<uint32_t> setupPIN, Optional<ByteSpan> salt,
Callback::Callback<OnOpenCommissioningWindow> * callback, SetupPayload & payload,
bool readVIDPIDAttributes = false);
Optional<ByteSpan> verifier, Callback::Callback<OnOpenCommissioningWindow> * callback,
SetupPayload & payload, bool readVIDPIDAttributes = false);

private:
enum class Step : uint8_t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ PyChipError pychip_DeviceController_OpenCommissioningWindow(chip::Controller::De
auto opener =
Platform::New<Controller::CommissioningWindowOpener>(static_cast<chip::Controller::DeviceController *>(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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRBaseDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 1699db0

Please sign in to comment.