Xamarin-macios: Similar to the work on `SecKey.GenerateKeyPair` we need to add a strong dictionary to `SecKey.CreateRandomKey`

Created on 14 Feb 2018  路  1Comment  路  Source: xamarin/xamarin-macios

Steps to Reproduce

Here's the Swift code, here's the doc https://developer.apple.com/documentation/security/1823694-seckeycreaterandomkey.

guard
let aclObject = SecAccessControlCreateWithFlags(
    kCFAllocatorDefault,
    kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly,
    [.privateKeyUsage,.touchIDAny],
    nil
    ) else {
    print("could not create ACL error")
    return""
}


// private key parameters
let privateKeyParams: [String: AnyObject] = [
    kSecAttrAccessControl asString:    aclObject asAnyObject, //protect with touch id
    kSecAttrIsPermanent asString:      trueas AnyObject,
]


// global parameters for our key generation
let parameters: [String: AnyObject] = [
    kSecAttrTokenID asString:          kSecAttrTokenIDSecureEnclave,
    kSecAttrKeyType asString:          kSecMessECCKeyType,
    kSecAttrKeySizeInBits asString:    kSecMessECCKeySize asAnyObject,
    kSecAttrLabel asString:            kSecMessECCSignLabel asAnyObject,
    kSecPrivateKeyAttrs asString:      privateKeyParams asAnyObject
]


guard
let eCCPrivKey = SecKeyCreateRandomKey(parameters asCFDictionary, nil) else {
    print("ECC KeyGen Error!")
    return""
}

guard
let eCCPubKey = SecKeyCopyPublicKey(eCCPrivKey) else {
    print("ECC Pub KeyGen Error")
    return""
}

We currently don't have a way to do that because we didn't open the keys (they are [Internal]).

Expected Behavior

Similar to https://github.com/xamarin/xamarin-macios/pull/3438 we should have a strong dictionary based on the Apple documentation linked above to set those keys (with strong types).

Actual Behavior

We can't set the keys.

enhancement good first issue help wanted iOS

Most helpful comment

As I have a stake in the matter I would like to do it.

>All comments

As I have a stake in the matter I would like to do it.

Was this page helpful?
0 / 5 - 0 ratings