Skip to content

Commit 5415256

Browse files
Josh V [Apple]pull[bot]
Josh V [Apple]
authored andcommitted
Resolve issue when attemping to send command after pair. (#15896)
1 parent 64e803f commit 5415256

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

+11-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
#include <stddef.h>
99
#include <string>
1010

11-
NSString * const kOperationalCredentialsIssuerKeypairStorage = @"ChipToolOpCredsCAKey";
11+
#define CHIPPlugin_CAKeyTag "com.apple.matter.commissioner.ca.issuer.id"
12+
#define Public_KeySize "256"
13+
14+
static NSString * const kCHIPToolKeychainLabel = @"Chip Tool Keypair";
15+
static NSString * const kOperationalCredentialsIssuerKeypairStorage = @"ChipToolOpCredsCAKey";
1216

1317
std::string StringToBase64(const std::string & value)
1418
{
@@ -62,7 +66,7 @@ - (NSData *)ECDSA_sign_hash:(NSData *)hash
6266
CHIP_ERROR signing_error = _mKeyPair.ECDSA_sign_hash((const uint8_t *) [hash bytes], (const size_t)[hash length], signature);
6367
if (signing_error != CHIP_NO_ERROR)
6468
return nil;
65-
out_signature = [NSData dataWithBytes:signature length:sizeof(signature)];
69+
out_signature = [NSData dataWithBytes:signature.Bytes() length:signature.Length()];
6670
return out_signature;
6771
}
6872

@@ -71,8 +75,11 @@ - (SecKeyRef)pubkey
7175
chip::Crypto::P256PublicKey publicKey = _mKeyPair.Pubkey();
7276
NSData * publicKeyNSData = [NSData dataWithBytes:publicKey.Bytes() length:publicKey.Length()];
7377
NSDictionary * attributes = @{
74-
(__bridge NSString *) kSecAttrKeyType : (__bridge NSString *) kSecAttrKeyTypeECDSA,
75-
(__bridge NSString *) kSecAttrKeyClass : (__bridge NSString *) kSecAttrKeyClassPublic
78+
(__bridge NSString *) kSecAttrKeyClass : (__bridge NSString *) kSecAttrKeyClassPublic,
79+
(NSString *) kSecAttrKeyType : (NSString *) kSecAttrKeyTypeECSECPrimeRandom,
80+
(NSString *) kSecAttrKeySizeInBits : @Public_KeySize,
81+
(NSString *) kSecAttrLabel : kCHIPToolKeychainLabel,
82+
(NSString *) kSecAttrApplicationTag : @CHIPPlugin_CAKeyTag,
7683
};
7784
return SecKeyCreateWithData((__bridge CFDataRef) publicKeyNSData, (__bridge CFDictionaryRef) attributes, NULL);
7885
}

0 commit comments

Comments
 (0)