@@ -43,83 +43,87 @@ CHIP_ERROR CommissioningWindowOpener::OpenBasicCommissioningWindow(NodeId device
43
43
44
44
// Basic commissioning does not use the setup payload.
45
45
46
- mCommissioningWindowOption = CommissioningWindowOption::kOriginalSetupCode ;
47
- mBasicCommissioningWindowCallback = callback;
48
- mCommissioningWindowCallback = nullptr ;
49
- mNodeId = deviceId;
50
- mCommissioningWindowTimeout = timeout;
46
+ mCommissioningWindowOption = CommissioningWindowOption::kOriginalSetupCode ;
47
+ mBasicCommissioningWindowCallback = callback;
48
+ mCommissioningWindowCallback = nullptr ;
49
+ mCommissioningWindowVerifierCallback = nullptr ;
50
+ mNodeId = deviceId;
51
+ mCommissioningWindowTimeout = timeout;
51
52
52
53
mNextStep = Step::kOpenCommissioningWindow ;
53
54
return mController ->GetConnectedDevice (mNodeId , &mDeviceConnected , &mDeviceConnectionFailure );
54
55
}
55
56
56
57
CHIP_ERROR CommissioningWindowOpener::OpenCommissioningWindow (NodeId deviceId, Seconds16 timeout, uint32_t iteration,
57
58
uint16_t discriminator, Optional<uint32_t > setupPIN,
58
- Optional<ByteSpan> salt, Optional<ByteSpan> verifier,
59
+ Optional<ByteSpan> salt,
59
60
Callback::Callback<OnOpenCommissioningWindow> * callback,
60
61
SetupPayload & payload, bool readVIDPIDAttributes)
61
62
{
62
- VerifyOrReturnError (mNextStep == Step::kAcceptCommissioningStart , CHIP_ERROR_INCORRECT_STATE);
63
+ CommissioningWindowPasscodeParams params = {
64
+ .common = { .deviceId = deviceId, .timeout = timeout, .iteration = iteration, .discriminator = discriminator },
65
+ .setupPIN = setupPIN,
66
+ .salt = salt,
67
+ .readVIDPIDAttributes = readVIDPIDAttributes,
68
+ .callback = callback,
69
+ };
70
+
71
+ return OpenCommissioningWindow (params, payload);
72
+ }
63
73
64
- VerifyOrReturnError (kSpake2p_Min_PBKDF_Iterations <= iteration && iteration <= kSpake2p_Max_PBKDF_Iterations ,
74
+ CHIP_ERROR CommissioningWindowOpener::OpenCommissioningWindow (const CommissioningWindowPasscodeParams & params,
75
+ SetupPayload & payload)
76
+ {
77
+ VerifyOrReturnError (mNextStep == Step::kAcceptCommissioningStart , CHIP_ERROR_INCORRECT_STATE);
78
+ VerifyOrReturnError (kSpake2p_Min_PBKDF_Iterations <= params.common .iteration &&
79
+ params.common .iteration <= kSpake2p_Max_PBKDF_Iterations ,
80
+ CHIP_ERROR_INVALID_ARGUMENT);
81
+ VerifyOrReturnError (!params.salt .HasValue () ||
82
+ (params.salt .Value ().size () >= kSpake2p_Min_PBKDF_Salt_Length &&
83
+ params.salt .Value ().size () <= kSpake2p_Max_PBKDF_Salt_Length ),
65
84
CHIP_ERROR_INVALID_ARGUMENT);
66
- VerifyOrReturnError (
67
- !salt.HasValue () ||
68
- (salt.Value ().size () >= kSpake2p_Min_PBKDF_Salt_Length && salt.Value ().size () <= kSpake2p_Max_PBKDF_Salt_Length ),
69
- CHIP_ERROR_INVALID_ARGUMENT);
70
85
71
86
mSetupPayload = SetupPayload ();
72
87
73
- if (setupPIN.HasValue ())
88
+ if (params. setupPIN .HasValue ())
74
89
{
75
- if (!SetupPayload::IsValidSetupPIN (setupPIN.Value ()))
76
- {
77
- return CHIP_ERROR_INVALID_ARGUMENT;
78
- }
79
-
90
+ VerifyOrReturnError (SetupPayload::IsValidSetupPIN (params.setupPIN .Value ()), CHIP_ERROR_INVALID_ARGUMENT);
80
91
mCommissioningWindowOption = CommissioningWindowOption::kTokenWithProvidedPIN ;
81
- mSetupPayload .setUpPINCode = setupPIN.Value ();
92
+ mSetupPayload .setUpPINCode = params. setupPIN .Value ();
82
93
}
83
94
else
84
95
{
85
96
mCommissioningWindowOption = CommissioningWindowOption::kTokenWithRandomPIN ;
86
97
}
87
98
88
- if (salt.HasValue ())
89
- {
90
- memcpy (mPBKDFSaltBuffer , salt.Value ().data (), salt.Value ().size ());
91
- mPBKDFSalt = ByteSpan (mPBKDFSaltBuffer , salt.Value ().size ());
92
- }
93
- else
94
- {
95
- ReturnErrorOnFailure (DRBG_get_bytes (mPBKDFSaltBuffer , sizeof (mPBKDFSaltBuffer )));
96
- mPBKDFSalt = ByteSpan (mPBKDFSaltBuffer );
97
- }
98
-
99
99
mSetupPayload .version = 0 ;
100
- mSetupPayload .discriminator .SetLongValue (discriminator);
100
+ mSetupPayload .discriminator .SetLongValue (params. common . discriminator );
101
101
mSetupPayload .rendezvousInformation .SetValue (RendezvousInformationFlag::kOnNetwork );
102
102
103
- mCommissioningWindowCallback = callback;
104
- mBasicCommissioningWindowCallback = nullptr ;
105
- mNodeId = deviceId;
106
- mCommissioningWindowTimeout = timeout;
107
- mPBKDFIterations = iteration;
108
-
109
- if (verifier.HasValue ())
103
+ if (params.salt .HasValue ())
110
104
{
111
- ReturnErrorOnFailure (mVerifier .Deserialize (verifier.Value ()));
105
+ memcpy (mPBKDFSaltBuffer , params.salt .Value ().data (), params.salt .Value ().size ());
106
+ mPBKDFSalt = ByteSpan (mPBKDFSaltBuffer , params.salt .Value ().size ());
112
107
}
113
108
else
114
109
{
115
- bool randomSetupPIN = !setupPIN.HasValue ();
116
- ReturnErrorOnFailure (
117
- PASESession::GeneratePASEVerifier (mVerifier , mPBKDFIterations , mPBKDFSalt , randomSetupPIN, mSetupPayload .setUpPINCode ));
110
+ ReturnErrorOnFailure (DRBG_get_bytes (mPBKDFSaltBuffer , sizeof (mPBKDFSaltBuffer )));
111
+ mPBKDFSalt = ByteSpan (mPBKDFSaltBuffer );
118
112
}
119
113
120
- payload = mSetupPayload ;
114
+ bool randomSetupPIN = !params.setupPIN .HasValue ();
115
+ ReturnErrorOnFailure (
116
+ PASESession::GeneratePASEVerifier (mVerifier , mPBKDFIterations , mPBKDFSalt , randomSetupPIN, mSetupPayload .setUpPINCode ));
117
+
118
+ payload = mSetupPayload ;
119
+ mCommissioningWindowCallback = params.callback ;
120
+ mBasicCommissioningWindowCallback = nullptr ;
121
+ mCommissioningWindowVerifierCallback = nullptr ;
122
+ mNodeId = params.common .deviceId ;
123
+ mCommissioningWindowTimeout = params.common .timeout ;
124
+ mPBKDFIterations = params.common .iteration ;
121
125
122
- if (readVIDPIDAttributes)
126
+ if (params. readVIDPIDAttributes )
123
127
{
124
128
mNextStep = Step::kReadVID ;
125
129
}
@@ -131,6 +135,31 @@ CHIP_ERROR CommissioningWindowOpener::OpenCommissioningWindow(NodeId deviceId, S
131
135
return mController ->GetConnectedDevice (mNodeId , &mDeviceConnected , &mDeviceConnectionFailure );
132
136
}
133
137
138
+ CHIP_ERROR CommissioningWindowOpener::OpenCommissioningWindow (const CommissioningWindowVerifierParams & params)
139
+ {
140
+ VerifyOrReturnError (mNextStep == Step::kAcceptCommissioningStart , CHIP_ERROR_INCORRECT_STATE);
141
+ VerifyOrReturnError (kSpake2p_Min_PBKDF_Iterations <= params.common .iteration &&
142
+ params.common .iteration <= kSpake2p_Max_PBKDF_Iterations ,
143
+ CHIP_ERROR_INVALID_ARGUMENT);
144
+ VerifyOrReturnError (params.salt .size () >= kSpake2p_Min_PBKDF_Salt_Length &&
145
+ params.salt .size () <= kSpake2p_Max_PBKDF_Salt_Length ,
146
+ CHIP_ERROR_INVALID_ARGUMENT);
147
+ memcpy (mPBKDFSaltBuffer , params.salt .data (), params.salt .size ());
148
+ mPBKDFSalt = ByteSpan (mPBKDFSaltBuffer , params.salt .size ());
149
+
150
+ ReturnErrorOnFailure (mVerifier .Deserialize (params.verifier ));
151
+ mCommissioningWindowVerifierCallback = params.callback ;
152
+ mBasicCommissioningWindowCallback = nullptr ;
153
+ mCommissioningWindowCallback = nullptr ;
154
+ mNodeId = params.common .deviceId ;
155
+ mCommissioningWindowTimeout = params.common .timeout ;
156
+ mPBKDFIterations = params.common .iteration ;
157
+
158
+ mNextStep = Step::kOpenCommissioningWindow ;
159
+
160
+ return mController ->GetConnectedDevice (mNodeId , &mDeviceConnected , &mDeviceConnectionFailure );
161
+ }
162
+
134
163
CHIP_ERROR CommissioningWindowOpener::OpenCommissioningWindowInternal (Messaging::ExchangeManager & exchangeMgr,
135
164
const SessionHandle & sessionHandle)
136
165
{
@@ -237,15 +266,19 @@ void CommissioningWindowOpener::OnOpenCommissioningWindowSuccess(void * context,
237
266
238
267
self->mCommissioningWindowCallback ->mCall (self->mCommissioningWindowCallback ->mContext , self->mNodeId , CHIP_NO_ERROR,
239
268
self->mSetupPayload );
240
- // Don't touch `self` anymore; it might have been destroyed by the
241
- // callee.
269
+ // Don't touch `self` anymore; it might have been destroyed by the callee.
270
+ }
271
+ else if (self->mCommissioningWindowVerifierCallback != nullptr )
272
+ {
273
+ self->mCommissioningWindowVerifierCallback ->mCall (self->mCommissioningWindowVerifierCallback ->mContext , self->mNodeId ,
274
+ CHIP_NO_ERROR);
275
+ // Don't touch `self` anymore; it might have been destroyed by the callee.
242
276
}
243
277
else if (self->mBasicCommissioningWindowCallback != nullptr )
244
278
{
245
279
self->mBasicCommissioningWindowCallback ->mCall (self->mBasicCommissioningWindowCallback ->mContext , self->mNodeId ,
246
280
CHIP_NO_ERROR);
247
- // Don't touch `self` anymore; it might have been destroyed by the
248
- // callee.
281
+ // Don't touch `self` anymore; it might have been destroyed by the callee.
249
282
}
250
283
}
251
284
@@ -259,6 +292,11 @@ void CommissioningWindowOpener::OnOpenCommissioningWindowFailure(void * context,
259
292
self->mCommissioningWindowCallback ->mCall (self->mCommissioningWindowCallback ->mContext , self->mNodeId , error,
260
293
SetupPayload ());
261
294
}
295
+ else if (self->mCommissioningWindowVerifierCallback != nullptr )
296
+ {
297
+ self->mCommissioningWindowVerifierCallback ->mCall (self->mCommissioningWindowVerifierCallback ->mContext , self->mNodeId ,
298
+ error);
299
+ }
262
300
else if (self->mBasicCommissioningWindowCallback != nullptr )
263
301
{
264
302
self->mBasicCommissioningWindowCallback ->mCall (self->mBasicCommissioningWindowCallback ->mContext , self->mNodeId , error);
@@ -361,8 +399,8 @@ CHIP_ERROR AutoCommissioningWindowOpener::OpenCommissioningWindow(DeviceControll
361
399
}
362
400
363
401
CHIP_ERROR err = opener->CommissioningWindowOpener ::OpenCommissioningWindow (
364
- deviceId, timeout, iteration, discriminator, setupPIN, salt, NullOptional, &opener->mOnOpenCommissioningWindowCallback ,
365
- payload, readVIDPIDAttributes);
402
+ deviceId, timeout, iteration, discriminator, setupPIN, salt, &opener->mOnOpenCommissioningWindowCallback , payload ,
403
+ readVIDPIDAttributes);
366
404
if (err != CHIP_NO_ERROR)
367
405
{
368
406
delete opener;
0 commit comments