Skip to content

Commit 08830a5

Browse files
mburshteyn1restyled-commitsbzbarsky-apple
authored
Expose DeviceProxy::GetAttestationChallenge to Obj-C. (#22111)
* Expose `DeviceCommissioner::GetAttestationChallenge` to Obj-C. * Update PR based on comments from bzbarsky. * Restyled by whitespace * Restyled by clang-format * Fix typo in comment. Co-authored-by: Restyled.io <[email protected]> Co-authored-by: Boris Zbarsky <[email protected]>
1 parent a2d3f39 commit 08830a5

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/darwin/Framework/CHIP/MTRDeviceController.h

+8
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ typedef void (^MTRDeviceConnectionCallback)(MTRBaseDevice * _Nullable device, NS
134134
*/
135135
- (void)setNocChainIssuer:(id<MTRNOCChainIssuer>)nocChainIssuer queue:(dispatch_queue_t)queue;
136136

137+
/**
138+
* Return the attestation challenge for the secure session of the device being commissioned.
139+
*
140+
* Attempts to retrieve the generated attestation challenge from a commissionee with the given Device ID.
141+
* Returns nil if given Device ID does not match an active commissionee, or if a Secure Session is not availale.
142+
*/
143+
- (nullable NSData *)generateAttestationChallengeForDeviceId:(uint64_t)deviceId;
144+
137145
/**
138146
* Compute a PASE verifier and passcode ID for the desired setup pincode.
139147
*

src/darwin/Framework/CHIP/MTRDeviceController.mm

+28
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
static NSString * const kErrorGenerateNOC = @"Generating operational certificate failed";
7272
static NSString * const kErrorKeyAllocation = @"Generating new operational key failed";
7373
static NSString * const kErrorCSRValidation = @"Extracting public key from CSR failed";
74+
static NSString * const kErrorGetCommissionee = @"Failure obtaining device being commissioned";
75+
static NSString * const kErrorGetAttestationChallenge = @"Failure getting attestation challenge";
7476

7577
@interface MTRDeviceController ()
7678

@@ -703,6 +705,32 @@ - (nullable NSData *)computePaseVerifier:(uint32_t)setupPincode iterations:(uint
703705
return result;
704706
}
705707

708+
- (nullable NSData *)generateAttestationChallengeForDeviceId:(uint64_t)deviceId
709+
{
710+
VerifyOrReturnValue([self checkIsRunning], nil);
711+
712+
__block NSData * attestationChallenge;
713+
dispatch_sync(_chipWorkQueue, ^{
714+
VerifyOrReturn([self checkIsRunning]);
715+
716+
chip::CommissioneeDeviceProxy * deviceProxy;
717+
auto errorCode = self.cppCommissioner->GetDeviceBeingCommissioned(deviceId, &deviceProxy);
718+
auto success = ![self checkForError:errorCode logMsg:kErrorGetCommissionee error:nil];
719+
VerifyOrReturn(success);
720+
721+
uint8_t challengeBuffer[chip::Crypto::kAES_CCM128_Key_Length];
722+
chip::ByteSpan challenge(challengeBuffer);
723+
724+
errorCode = deviceProxy->GetAttestationChallenge(challenge);
725+
success = ![self checkForError:errorCode logMsg:kErrorGetAttestationChallenge error:nil];
726+
VerifyOrReturn(success);
727+
728+
attestationChallenge = AsData(challenge);
729+
});
730+
731+
return attestationChallenge;
732+
}
733+
706734
- (BOOL)checkForInitError:(BOOL)condition logMsg:(NSString *)logMsg
707735
{
708736
if (condition) {

0 commit comments

Comments
 (0)