Skip to content

Commit 6597d72

Browse files
committed
[darwin-framework-tool] Update CHIPToolKeyPair implementation to not use matter sdk specific APIs but native APIS
1 parent e419e33 commit 6597d72

File tree

7 files changed

+268
-225
lines changed

7 files changed

+268
-225
lines changed

examples/darwin-framework-tool/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ executable("darwin-framework-tool") {
200200
"commands/clusters/WriteAttributeCommandBridge.h",
201201
"commands/common/CHIPCommandBridge.mm",
202202
"commands/common/CHIPCommandStorageDelegate.mm",
203-
"commands/common/CHIPToolKeypair.mm",
204203
"commands/common/CertificateIssuer.h",
205204
"commands/common/CertificateIssuer.mm",
206205
"commands/common/ControllerStorage.h",
207206
"commands/common/ControllerStorage.mm",
207+
"commands/common/DFTKeypair.mm",
208208
"commands/common/DeviceDelegate.h",
209209
"commands/common/DeviceDelegate.mm",
210210
"commands/common/MTRDevice_Externs.h",

examples/darwin-framework-tool/commands/common/CHIPCommandBridge.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include "CHIPCommandBridge.h"
2020

21-
#import "CHIPToolKeypair.h"
21+
#import "DFTKeypair.h"
2222
#import <Matter/Matter.h>
2323

2424
#include <lib/core/CHIPConfig.h>

examples/darwin-framework-tool/commands/common/CHIPToolKeypair.mm

-193
This file was deleted.

examples/darwin-framework-tool/commands/common/CertificateIssuer.mm

+7-14
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
#import "CertificateIssuer.h"
20-
#import "CHIPToolKeypair.h"
20+
#import "DFTKeypair.h"
2121

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

@@ -61,17 +61,13 @@ - (instancetype)init
6161
- (void)startWithStorage:(id<MTRStorage>)storage
6262
error:(NSError * _Nullable __autoreleasing * _Nonnull)error
6363
{
64-
__auto_type * signingKey = [[CHIPToolKeypair alloc] init];
65-
66-
__auto_type err = [signingKey createOrLoadKeys:storage];
67-
if (CHIP_NO_ERROR != err) {
68-
*error = [NSError errorWithDomain:@"Error" code:0 userInfo:@{ @"reason" : @"Error creating or loading keys" }];
64+
__auto_type * signingKey = [DFTKeypair createKeypairWithStorage:storage error:error];
65+
if (!signingKey) {
6966
return;
7067
}
7168

7269
__auto_type * rootCertificate = [MTRCertificates createRootCertificate:signingKey issuerID:@(kIssuerId) fabricID:nil error:error];
73-
if (nil == rootCertificate) {
74-
*error = [NSError errorWithDomain:@"Error" code:0 userInfo:@{ @"reason" : @"Error creating root certificate" }];
70+
if (!rootCertificate) {
7571
return;
7672
}
7773

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

8379
- (id<MTRKeypair>)issueOperationalKeypairWithControllerStorage:(ControllerStorage *)storage error:(NSError * _Nullable __autoreleasing * _Nonnull)error
8480
{
85-
__auto_type * keypair = [[CHIPToolKeypair alloc] init];
86-
87-
__auto_type err = [keypair createOrLoadKeys:storage];
88-
if (CHIP_NO_ERROR != err) {
89-
*error = [NSError errorWithDomain:@"Error" code:0 userInfo:@{ @"reason" : @"Error creating or loading keys" }];
81+
__auto_type * signingKey = [DFTKeypair createKeypairWithStorage:storage error:error];
82+
if (!signingKey) {
9083
return nil;
9184
}
9285

93-
return keypair;
86+
return signingKey;
9487
}
9588

9689
- (void)issueOperationalCertificateForRequest:(MTROperationalCSRInfo *)csrInfo

examples/darwin-framework-tool/commands/common/CHIPToolKeypair.h examples/darwin-framework-tool/commands/common/DFTKeypair.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
*/
1818

1919
#import <Matter/Matter.h>
20-
#include <crypto/CHIPCryptoPAL.h>
2120

22-
@interface CHIPToolKeypair : NSObject <MTRKeypair>
23-
- (BOOL)initialize;
24-
- (NSData *)signMessageECDSA_RAW:(NSData *)message;
21+
NS_ASSUME_NONNULL_BEGIN
22+
23+
@interface DFTKeypair : NSObject <MTRKeypair>
24+
- (instancetype)init NS_UNAVAILABLE;
25+
+ (instancetype)createKeypairWithStorage:(id)storage error:(NSError * _Nullable __autoreleasing *)error;
26+
- (NSData *)signMessageECDSA_DER:(NSData *)message;
2527
- (SecKeyRef)copyPublicKey;
26-
- (CHIP_ERROR)Serialize:(chip::Crypto::P256SerializedKeypair &)output;
27-
- (CHIP_ERROR)Deserialize:(chip::Crypto::P256SerializedKeypair &)input;
28-
- (CHIP_ERROR)createOrLoadKeys:(id)storage;
2928
- (NSData *)getIPK;
30-
3129
@end
30+
31+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)