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

Expose DeviceProxy::GetAttestationChallenge to Obj-C. #22111

Merged
8 changes: 8 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ typedef void (^MTRDeviceConnectionCallback)(MTRBaseDevice * _Nullable device, NS
*/
- (void)setNocChainIssuer:(id<MTRNOCChainIssuer>)nocChainIssuer queue:(dispatch_queue_t)queue;

/**
* Return the attestation challenge for the secure session of the device being commissioned.
*
* Attempts to retreive the generated attestation challenge from a commissionee with the given Device ID.
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
* Returns nil if given Device ID does not match an active commissionee, or if a Secure Session is not availale.
*/
- (nullable NSData *)generateAttestationChallengeForDeviceId:(uint64_t)deviceId;

/**
* Compute a PASE verifier and passcode ID for the desired setup pincode.
*
Expand Down
28 changes: 28 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
static NSString * const kErrorGenerateNOC = @"Generating operational certificate failed";
static NSString * const kErrorKeyAllocation = @"Generating new operational key failed";
static NSString * const kErrorCSRValidation = @"Extracting public key from CSR failed";
static NSString * const kErrorGetCommissionee = @"Failure obtaining device being commissioned";
static NSString * const kErrorGetAttestationChallenge = @"Failure getting attestation challenge";

@interface MTRDeviceController ()

Expand Down Expand Up @@ -703,6 +705,32 @@ - (nullable NSData *)computePaseVerifier:(uint32_t)setupPincode iterations:(uint
return result;
}

- (nullable NSData *)generateAttestationChallengeForDeviceId:(uint64_t)deviceId
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
{
VerifyOrReturnValue([self checkIsRunning], nil);

__block NSData * attestationChallenge;
dispatch_sync(_chipWorkQueue, ^{
VerifyOrReturn([self checkIsRunning]);

chip::CommissioneeDeviceProxy * deviceProxy;
auto errorCode = self.cppCommissioner->GetDeviceBeingCommissioned(deviceId, &deviceProxy);
auto success = ![self checkForError:errorCode logMsg:kErrorGetCommissionee error:nil];
VerifyOrReturn(success);

uint8_t challengeBuffer[chip::Crypto::kAES_CCM128_Key_Length];
chip::ByteSpan challenge(challengeBuffer);

errorCode = deviceProxy->GetAttestationChallenge(challenge);
success = ![self checkForError:errorCode logMsg:kErrorGetAttestationChallenge error:nil];
VerifyOrReturn(success);

attestationChallenge = AsData(challenge);
});

return attestationChallenge;
}

- (BOOL)checkForInitError:(BOOL)condition logMsg:(NSString *)logMsg
{
if (condition) {
Expand Down