Skip to content

Commit

Permalink
Expose DeviceCommissioner::GetAttestationChallenge to Obj-C.
Browse files Browse the repository at this point in the history
  • Loading branch information
mburshteyn1 committed Aug 29, 2022
1 parent 0abfab0 commit f636396
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ 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. */
- (nullable NSData *)generateAttestationChallengeForDeviceId:(uint64_t)deviceId;

/**
* Compute a PASE verifier and passcode ID for the desired setup pincode.
*
Expand Down
31 changes: 31 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,37 @@ - (nullable NSData *)computePaseVerifier:(uint32_t)setupPincode iterations:(uint
return result;
}

- (nullable NSData *)generateAttestationChallengeForDeviceId:(uint64_t)deviceId
{
__block CHIP_ERROR errorCode = CHIP_ERROR_INCORRECT_STATE;
if (![self isRunning]) {
[self checkForError:errorCode logMsg:kErrorNotRunning error:nil];
return nil;
}

__block NSData * attestationChallenge;
dispatch_sync(_chipWorkQueue, ^{
if ([self isRunning]) {
chip::CommissioneeDeviceProxy * deviceProxy;
errorCode = self.cppCommissioner->GetDeviceBeingCommissioned(deviceId, &deviceProxy);
if (errorCode != CHIP_NO_ERROR) {
[self checkForError:errorCode logMsg:@"Invalid Attestation Challenge device ID." error:nil];
return;
}

NSMutableData * challengeBuffer = [[NSMutableData alloc] initWithLength:chip::Crypto::kAES_CCM128_Key_Length];
chip::ByteSpan challenge((uint8_t *) [challengeBuffer mutableBytes], chip::Crypto::kAES_CCM128_Key_Length);

errorCode = deviceProxy->GetAttestationChallenge(challenge);
MTR_LOG_ERROR("GetAttestationChallenge: %s", chip::ErrorStr(errorCode));

attestationChallenge = [NSData dataWithBytes:challenge.data() length:challenge.size()];
}
});

return attestationChallenge;
}

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

0 comments on commit f636396

Please sign in to comment.