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
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 BOOL (^MTRNOCChainGenerationCompleteHandler)(NSData * operationalCertificate, NSData * intermediateCertificate,
sharadb-amazon marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -127,7 +127,7 @@ class MTROperationalCredentialsDelegate : public chip::Controller::OperationalCr
* If ipk and adminSubject are non nil, then they will be used in the AddNOC command sent to the commissionee. If they are not
* populated, then the values provided in the MTRDeviceController initialization will be used.
*/
void onNOCChainGenerationComplete(NSData * operationalCertificate, NSData * intermediateCertificate, NSData * rootCertificate,
BOOL onNOCChainGenerationComplete(NSData * operationalCertificate, NSData * intermediateCertificate, NSData * rootCertificate,
sharadb-amazon marked this conversation as resolved.
Show resolved Hide resolved
NSData * _Nullable ipk, NSNumber * _Nullable adminSubject, NSError * __autoreleasing * error);

void setNSError(CHIP_ERROR err, NSError * __autoreleasing * outError);
Expand Down
26 changes: 12 additions & 14 deletions src/darwin/Framework/CHIP/MTROperationalCredentialsDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,10 @@
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 All @@ -205,9 +203,9 @@
dispatch_sync(mNocChainIssuerQueue, ^{
[mNocChainIssuer onNOCChainGenerationNeeded:csrInfo
attestationInfo:attestationInfo
onNOCChainGenerationComplete:^void(NSData * operationalCertificate, NSData * intermediateCertificate,
onNOCChainGenerationComplete:^BOOL(NSData * operationalCertificate, NSData * intermediateCertificate,
NSData * rootCertificate, NSData * ipk, NSNumber * adminSubject, NSError * __autoreleasing * error) {
onNOCChainGenerationComplete(
return onNOCChainGenerationComplete(
operationalCertificate, intermediateCertificate, rootCertificate, ipk, adminSubject, error);
}];
});
Expand All @@ -222,25 +220,23 @@
}
}

void MTROperationalCredentialsDelegate::onNOCChainGenerationComplete(NSData * operationalCertificate,
BOOL MTROperationalCredentialsDelegate::onNOCChainGenerationComplete(NSData * operationalCertificate,
NSData * intermediateCertificate, NSData * rootCertificate, NSData * _Nullable ipk, NSNumber * _Nullable adminSubject,
NSError * __autoreleasing * error)
{
if (operationalCertificate == nil || intermediateCertificate == nil || rootCertificate == nil) {
setNSError(CHIP_ERROR_INVALID_ARGUMENT, error);
return;
sharadb-amazon marked this conversation as resolved.
Show resolved Hide resolved
return NO;
}

// 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
__block chip::Optional<chip::Controller::CommissioningParameters> commissioningParameters;
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
if (!commissioningParameters.HasValue()) {
setNSError(CHIP_ERROR_INCORRECT_STATE, error);
return;
sharadb-amazon marked this conversation as resolved.
Show resolved Hide resolved
return NO;
}

chip::Optional<chip::Crypto::AesCcm128KeySpan> ipkOptional;
Expand All @@ -249,7 +245,7 @@
if (ipk != nil) {
if ([ipk length] != sizeof(ipkValue)) {
setNSError(CHIP_ERROR_INCORRECT_STATE, error);
return;
return NO;
}
memcpy(&ipkValue[0], [ipk bytes], [ipk length]);
ipkOptional.SetValue(ipkTempSpan);
Expand All @@ -273,7 +269,9 @@
if (err != CHIP_NO_ERROR) {
MTR_LOG_ERROR("Failed to SetNocChain for the device: %" CHIP_ERROR_FORMAT, err.Format());
setNSError(CHIP_ERROR_INCORRECT_STATE, error);
return NO;
}
return YES;
}

CHIP_ERROR MTROperationalCredentialsDelegate::LocalGenerateNOCChain(const chip::ByteSpan & csrElements,
Expand Down