Skip to content

Commit

Permalink
Add vendorID and productID properties to MTRDeviceAttestationDeviceInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
ksperling-apple committed Jan 10, 2023
1 parent a574756 commit 6e19b0a
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 11 deletions.
35 changes: 35 additions & 0 deletions src/darwin/Framework/CHIP/MTRConversion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright (c) 2023 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import "NSDataSpanConversion.h"
#import "NSStringSpanConversion.h"

#import <Foundation/Foundation.h>

#include <lib/core/Optional.h>
#include <type_traits>

NS_ASSUME_NONNULL_BEGIN

template <typename T>
inline std::enable_if_t<std::is_integral<T>::value || std::is_floating_point<T>::value || std::is_enum<T>::value,
NSNumber * _Nullable>
AsNumber(chip::Optional<T> optional)
{
return (optional.HasValue()) ? @(optional.Value()) : nil;
}

NS_ASSUME_NONNULL_END
18 changes: 16 additions & 2 deletions src/darwin/Framework/CHIP/MTRDeviceAttestationDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,31 @@
*/

#import <Foundation/Foundation.h>
#import <Matter/MTRCertificates.h>

NS_ASSUME_NONNULL_BEGIN

@class MTRDeviceController;

@interface MTRDeviceAttestationDeviceInfo : NSObject

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
@property (nonatomic, readonly) NSData * dacCertificate;
@property (nonatomic, readonly) NSData * dacPAICertificate;

/**
* The vendor ID for the device from the Device Attestation Certificate. May be nil only if attestation was unsucessful.
*/
@property (nonatomic, readonly, nullable) NSNumber * vendorID;

/**
* The product ID for the device from the Device Attestation Certificate. May be nil only if attestation was unsucessful.
*/
@property (nonatomic, readonly, nullable) NSNumber * productID;

@property (nonatomic, readonly) MTRCertificateDERBytes dacCertificate;
@property (nonatomic, readonly) MTRCertificateDERBytes dacPAICertificate;
@property (nonatomic, readonly, nullable) NSData * certificateDeclaration;

@end

/**
Expand Down
21 changes: 17 additions & 4 deletions src/darwin/Framework/CHIP/MTRDeviceAttestationDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,32 @@
* limitations under the License.
*/

#import <Foundation/Foundation.h>
#import <MTRDeviceAttestationDelegate_Internal.h>
#import "MTRDeviceAttestationDelegate_Internal.h"

#import "MTRConversion.h"

#include <crypto/CHIPCryptoPAL.h>

using namespace chip::Crypto;

@implementation MTRDeviceAttestationDeviceInfo
- (instancetype)initWithDACCertificate:(NSData *)dacCertificate
dacPAICertificate:(NSData *)dacPAICertificate

- (instancetype)initWithDACCertificate:(MTRCertificateDERBytes)dacCertificate
dacPAICertificate:(MTRCertificateDERBytes)dacPAICertificate
certificateDeclaration:(NSData *)certificateDeclaration
{
if (self = [super init]) {
_dacCertificate = [dacCertificate copy];
_dacPAICertificate = [dacPAICertificate copy];
_certificateDeclaration = [certificateDeclaration copy];

struct AttestationCertVidPid dacVidPid;
if (ExtractVIDPIDFromX509Cert(AsByteSpan(_dacCertificate), dacVidPid) == CHIP_NO_ERROR) {
_vendorID = AsNumber(dacVidPid.mVendorId);
_productID = AsNumber(dacVidPid.mProductId);
}
}
return self;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
* limitations under the License.
*/

#import <MTRDeviceAttestationDelegate.h>
#import "MTRDeviceAttestationDelegate.h"

NS_ASSUME_NONNULL_BEGIN

@interface MTRDeviceAttestationDeviceInfo ()
- (instancetype)initWithDACCertificate:(NSData *)dacCertificate
dacPAICertificate:(NSData *)dacPAICertificate

- (instancetype)initWithDACCertificate:(MTRCertificateDERBytes)dacCertificate
dacPAICertificate:(MTRCertificateDERBytes)dacPAICertificate
certificateDeclaration:(NSData *)certificateDeclaration;

@end

NS_ASSUME_NONNULL_END
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/NSDataSpanConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#pragma once

#import "Foundation/Foundation.h"
#import <Foundation/Foundation.h>

#include <lib/support/Span.h>

Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/NSStringSpanConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#pragma once

#import "Foundation/Foundation.h"
#import <Foundation/Foundation.h>

#include <lib/support/Span.h>

Expand Down

0 comments on commit 6e19b0a

Please sign in to comment.