Skip to content

Commit

Permalink
[darwin-framework-tool] Update CHIPToolKeyPair implementation to not …
Browse files Browse the repository at this point in the history
…use matter sdk specific APIs but native APIS (project-chip#36723)
  • Loading branch information
vivien-apple authored Dec 5, 2024
1 parent 6063e23 commit 6484899
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 225 deletions.
2 changes: 1 addition & 1 deletion examples/darwin-framework-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ executable("darwin-framework-tool") {
"commands/clusters/WriteAttributeCommandBridge.h",
"commands/common/CHIPCommandBridge.mm",
"commands/common/CHIPCommandStorageDelegate.mm",
"commands/common/CHIPToolKeypair.mm",
"commands/common/CertificateIssuer.h",
"commands/common/CertificateIssuer.mm",
"commands/common/ControllerStorage.h",
"commands/common/ControllerStorage.mm",
"commands/common/DFTKeypair.mm",
"commands/common/DeviceDelegate.h",
"commands/common/DeviceDelegate.mm",
"commands/common/MTRDevice_Externs.h",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "CHIPCommandBridge.h"

#import "CHIPToolKeypair.h"
#import "DFTKeypair.h"
#import <Matter/Matter.h>

#include <lib/core/CHIPConfig.h>
Expand Down
193 changes: 0 additions & 193 deletions examples/darwin-framework-tool/commands/common/CHIPToolKeypair.mm

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

#import "CertificateIssuer.h"
#import "CHIPToolKeypair.h"
#import "DFTKeypair.h"

#include <lib/support/logging/CHIPLogging.h>

Expand Down Expand Up @@ -61,17 +61,13 @@ - (instancetype)init
- (void)startWithStorage:(id<MTRStorage>)storage
error:(NSError * _Nullable __autoreleasing * _Nonnull)error
{
__auto_type * signingKey = [[CHIPToolKeypair alloc] init];

__auto_type err = [signingKey createOrLoadKeys:storage];
if (CHIP_NO_ERROR != err) {
*error = [NSError errorWithDomain:@"Error" code:0 userInfo:@{ @"reason" : @"Error creating or loading keys" }];
__auto_type * signingKey = [DFTKeypair createKeypairWithStorage:storage error:error];
if (!signingKey) {
return;
}

__auto_type * rootCertificate = [MTRCertificates createRootCertificate:signingKey issuerID:@(kIssuerId) fabricID:nil error:error];
if (nil == rootCertificate) {
*error = [NSError errorWithDomain:@"Error" code:0 userInfo:@{ @"reason" : @"Error creating root certificate" }];
if (!rootCertificate) {
return;
}

Expand All @@ -82,15 +78,12 @@ - (void)startWithStorage:(id<MTRStorage>)storage

- (id<MTRKeypair>)issueOperationalKeypairWithControllerStorage:(ControllerStorage *)storage error:(NSError * _Nullable __autoreleasing * _Nonnull)error
{
__auto_type * keypair = [[CHIPToolKeypair alloc] init];

__auto_type err = [keypair createOrLoadKeys:storage];
if (CHIP_NO_ERROR != err) {
*error = [NSError errorWithDomain:@"Error" code:0 userInfo:@{ @"reason" : @"Error creating or loading keys" }];
__auto_type * signingKey = [DFTKeypair createKeypairWithStorage:storage error:error];
if (!signingKey) {
return nil;
}

return keypair;
return signingKey;
}

- (void)issueOperationalCertificateForRequest:(MTROperationalCSRInfo *)csrInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
*/

#import <Matter/Matter.h>
#include <crypto/CHIPCryptoPAL.h>

@interface CHIPToolKeypair : NSObject <MTRKeypair>
- (BOOL)initialize;
- (NSData *)signMessageECDSA_RAW:(NSData *)message;
NS_ASSUME_NONNULL_BEGIN

@interface DFTKeypair : NSObject <MTRKeypair>
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)createKeypairWithStorage:(id)storage error:(NSError * _Nullable __autoreleasing *)error;
- (NSData *)signMessageECDSA_DER:(NSData *)message;
- (SecKeyRef)copyPublicKey;
- (CHIP_ERROR)Serialize:(chip::Crypto::P256SerializedKeypair &)output;
- (CHIP_ERROR)Deserialize:(chip::Crypto::P256SerializedKeypair &)input;
- (CHIP_ERROR)createOrLoadKeys:(id)storage;
- (NSData *)getIPK;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 6484899

Please sign in to comment.