I create a asymmetric signing key on macOS using this code:
const NSData* SignKeyTag = [@"ca.website.signRSA2048" dataUsingEncoding:NSUTF8StringEncoding];
const NSNumber* SignKeySize = @2048;
const SecKeyAlgorithm SigningAlg = kSecKeyAlgorithmRSASignatureDigestPKCS1v15SHA384;
const NSString* SignKeyType = (id)kSecAttrKeyTypeRSA;
const NSString* SignKeyLabel = @"Signing Key";
NSDictionary* attributes =
@{
(id)kSecAttrKeyType: SignKeyType,
(id)kSecAttrKeySizeInBits: SignKeySize,
(id)kSecAttrLabel: SignKeyLabel,
(id)kSecAttrDescription: SignKeyLabel,
(id)kSecPrivateKeyAttrs:
@{
(id)kSecAttrIsPermanent: @YES,
(id)kSecAttrApplicationTag: SignKeyTag,
},
};
CFErrorRef error = NULL;
myPrivKeyRef = SecKeyCreateRandomKey((__bridge CFDictionaryRef)attributes, &error);
This works fine, and I'm able to sign and verify without issue. The problem I'm facing is that if permission needs to be given to access the key, the dialog asking the user to Allow/Deny/Always Allow access to the key shows the name <key> instead of any of the labels/tag/descriptions I give it. Also if I edit the key in Keychain Access.app, it also asks me for permission to change <key>.
Keychain Access shows the label correctly in the list, I don't see <key> anywhere in the key info. Also if I enumerate the attributes for the key in code I don't see <key>.
Now, I'm assuming that label I'm seeing may be from the public key. However the documentation says I shouldn't store the public key separately, and just get it from the private key when required using SecKeyCopyPublicKey().
Any ideas? Thanks!