From dde4a8f721c4899672f359d3167bbc88b711e38e Mon Sep 17 00:00:00 2001 From: "Josh V [Apple]" Date: Mon, 7 Mar 2022 09:20:29 -0800 Subject: [PATCH] Resolve issue when attemping to send command after pair. (#15896) --- .../commands/common/CHIPToolKeypair.mm | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/chip-tool-darwin/commands/common/CHIPToolKeypair.mm b/examples/chip-tool-darwin/commands/common/CHIPToolKeypair.mm index 198f054f2f7d56..220bcd16d4dda6 100644 --- a/examples/chip-tool-darwin/commands/common/CHIPToolKeypair.mm +++ b/examples/chip-tool-darwin/commands/common/CHIPToolKeypair.mm @@ -8,7 +8,11 @@ #include #include -NSString * const kOperationalCredentialsIssuerKeypairStorage = @"ChipToolOpCredsCAKey"; +#define CHIPPlugin_CAKeyTag "com.apple.matter.commissioner.ca.issuer.id" +#define Public_KeySize "256" + +static NSString * const kCHIPToolKeychainLabel = @"Chip Tool Keypair"; +static NSString * const kOperationalCredentialsIssuerKeypairStorage = @"ChipToolOpCredsCAKey"; std::string StringToBase64(const std::string & value) { @@ -62,7 +66,7 @@ - (NSData *)ECDSA_sign_hash:(NSData *)hash CHIP_ERROR signing_error = _mKeyPair.ECDSA_sign_hash((const uint8_t *) [hash bytes], (const size_t)[hash length], signature); if (signing_error != CHIP_NO_ERROR) return nil; - out_signature = [NSData dataWithBytes:signature length:sizeof(signature)]; + out_signature = [NSData dataWithBytes:signature.Bytes() length:signature.Length()]; return out_signature; } @@ -71,8 +75,11 @@ - (SecKeyRef)pubkey chip::Crypto::P256PublicKey publicKey = _mKeyPair.Pubkey(); NSData * publicKeyNSData = [NSData dataWithBytes:publicKey.Bytes() length:publicKey.Length()]; NSDictionary * attributes = @{ - (__bridge NSString *) kSecAttrKeyType : (__bridge NSString *) kSecAttrKeyTypeECDSA, - (__bridge NSString *) kSecAttrKeyClass : (__bridge NSString *) kSecAttrKeyClassPublic + (__bridge NSString *) kSecAttrKeyClass : (__bridge NSString *) kSecAttrKeyClassPublic, + (NSString *) kSecAttrKeyType : (NSString *) kSecAttrKeyTypeECSECPrimeRandom, + (NSString *) kSecAttrKeySizeInBits : @Public_KeySize, + (NSString *) kSecAttrLabel : kCHIPToolKeychainLabel, + (NSString *) kSecAttrApplicationTag : @CHIPPlugin_CAKeyTag, }; return SecKeyCreateWithData((__bridge CFDataRef) publicKeyNSData, (__bridge CFDictionaryRef) attributes, NULL); }