Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address feedback from https://github.com/project-chip/connectedhomeip/issues/22197 #22175

Merged
merged 8 commits into from
Sep 1, 2022
14 changes: 14 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
static NSString * const kErrorOperationalCredentialsInit = @"Init failure while creating operational credentials delegate";
static NSString * const kErrorOperationalKeypairInit = @"Init failure while creating operational keypair bridge";
static NSString * const kErrorPairingInit = @"Init failure while creating a pairing delegate";
static NSString * const kErrorPartialDacVerifierInit = @"Init failure while creating a partial DAC verifier";
static NSString * const kErrorPairDevice = @"Failure while pairing the device";
static NSString * const kErrorUnpairDevice = @"Failure while unpairing the device";
static NSString * const kErrorStopPairing = @"Failure while trying to stop the pairing process";
Expand Down Expand Up @@ -104,6 +105,11 @@ - (instancetype)initWithFactory:(MTRControllerFactory *)factory queue:(dispatch_
return nil;
}

_partialDACVerifier = new chip::Credentials::PartialDACVerifier();
if ([self checkForInitError:(_partialDACVerifier != nullptr) logMsg:kErrorPartialDacVerifierInit]) {
return nil;
}

_operationalCredentialsDelegate = new MTROperationalCredentialsDelegate();
if ([self checkForInitError:(_operationalCredentialsDelegate != nullptr) logMsg:kErrorOperationalCredentialsInit]) {
return nil;
Expand Down Expand Up @@ -143,6 +149,9 @@ - (void)shutDownCppController
_cppCommissioner->Shutdown();
delete _cppCommissioner;
_cppCommissioner = nullptr;
if (_operationalCredentialsDelegate != nil) {
_operationalCredentialsDelegate->SetDeviceCommissioner(nullptr);
}
}
}

Expand All @@ -158,6 +167,11 @@ - (void)cleanup
_operationalCredentialsDelegate = nullptr;
}

if (_partialDACVerifier) {
sharadb-amazon marked this conversation as resolved.
Show resolved Hide resolved
sharadb-amazon marked this conversation as resolved.
Show resolved Hide resolved
delete _partialDACVerifier;
_partialDACVerifier = nullptr;
}

if (_pairingDelegateBridge) {
delete _pairingDelegateBridge;
_pairingDelegateBridge = nullptr;
Expand Down
7 changes: 4 additions & 3 deletions src/darwin/Framework/CHIP/MTRNOCChainIssuer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

NS_ASSUME_NONNULL_BEGIN

typedef void (^MTRNOCChainGenerationCompleteHandler)(NSData * operationalCertificate, NSData * intermediateCertificate,
NSData * rootCertificate, NSData * _Nullable ipk, NSNumber * _Nullable adminSubject, NSError * __autoreleasing * error);

@protocol MTRNOCChainIssuer <NSObject>
@required

Expand All @@ -43,9 +46,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)onNOCChainGenerationNeeded:(CSRInfo *)csrInfo
attestationInfo:(AttestationInfo *)attestationInfo
onNOCChainGenerationComplete:(void (^)(NSData * operationalCertificate, NSData * intermediateCertificate,
NSData * rootCertificate, NSData * ipk, NSNumber * adminSubject,
NSError * __autoreleasing * error))onNOCChainGenerationComplete;
onNOCChainGenerationComplete:(MTRNOCChainGenerationCompleteHandler)onNOCChainGenerationComplete;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ class MTROperationalCredentialsDelegate : public chip::Controller::OperationalCr
void SetDeviceID(chip::NodeId deviceId) { mDeviceBeingPaired = deviceId; }
void ResetDeviceID() { mDeviceBeingPaired = chip::kUndefinedNodeId; }

void SetDeviceCommissioner(chip::Controller::DeviceCommissioner * cppCommissioner) { mCppCommissioner = cppCommissioner; }
void SetDeviceCommissioner(chip::Controller::DeviceCommissioner * _Nullable cppCommissioner)
{
mCppCommissioner = cppCommissioner;
}

chip::Optional<chip::Controller::CommissioningParameters> GetCommissioningParameters()
{
Expand Down
17 changes: 8 additions & 9 deletions src/darwin/Framework/CHIP/MTROperationalCredentialsDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
const chip::ByteSpan & DAC, const chip::ByteSpan & PAI,
chip::Callback::Callback<chip::Controller::OnNOCChainGeneration> * onCompletion)
{
VerifyOrReturnError(mCppCommissioner != nullptr, CHIP_ERROR_INCORRECT_STATE);
mOnNOCCompletionCallback = onCompletion;

TLVReader reader;
Expand Down Expand Up @@ -178,12 +179,8 @@
chip::ByteSpan firmwareInfoSpan;
chip::Credentials::DeviceAttestationVendorReservedDeconstructor vendorReserved;

__block chip::Optional<chip::Controller::CommissioningParameters> commissioningParameters;
// Dereferencing mCppCommissioner as it would be set to point to a valid Cpp commissioner by now, as we are in the middle of
// commissioning
dispatch_sync(mChipWorkQueue, ^{
commissioningParameters = mCppCommissioner->GetCommissioningParameters();
});
chip::Optional<chip::Controller::CommissioningParameters> commissioningParameters
= mCppCommissioner->GetCommissioningParameters();
sharadb-amazon marked this conversation as resolved.
Show resolved Hide resolved
VerifyOrReturnError(commissioningParameters.HasValue(), CHIP_ERROR_INCORRECT_STATE);

// Attestation Elements, nonce and signature will have a value in Commissioning Params as the CSR needs a signature or else we
Expand Down Expand Up @@ -231,9 +228,11 @@
return;
sharadb-amazon marked this conversation as resolved.
Show resolved Hide resolved
}

// use ipk and adminSubject from CommissioningParameters if not passed in.
// Dereferencing mCppCommissioner as it would be set to point to a valid Cpp commissioner by now, as we are in the middle of
// commissioning
if (mCppCommissioner == nullptr) {
setNSError(CHIP_ERROR_INCORRECT_STATE, error);
return;
}
sharadb-amazon marked this conversation as resolved.
Show resolved Hide resolved

__block chip::Optional<chip::Controller::CommissioningParameters> commissioningParameters;
dispatch_sync(mChipWorkQueue, ^{
commissioningParameters = mCppCommissioner->GetCommissioningParameters();
Expand Down