Skip to content

Commit

Permalink
Merge 36b5c4c into 3be848d
Browse files Browse the repository at this point in the history
  • Loading branch information
mburshteyn1 authored Aug 30, 2022
2 parents 3be848d + 36b5c4c commit 1605442
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
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 retrieve the generated attestation challenge from a commissionee with the given Device ID.
* 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
{
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

0 comments on commit 1605442

Please sign in to comment.