Post not yet marked as solved
Post marked as unsolved with 12 replies, 2,661 views
I'm trying to interact with a remote server that requires a client certificate. I have obtained the required info from a separate login tool from the same vendor. However, I am having no end of trouble connecting the dots.
Specifically I can't manage to get the needed SecIdentity from the raw PEM data.
Here is the code (with actual data copy/pasted from vendor, but truncated here):
let pemString =
"""----BEGIN PRIVATE KEY
MIGHAg(key contents truncated)QS1osPzBH8----END PRIVATE KEY
----BEGIN CERTIFICATE
MIIDkT(cert contents trucated)1yIMCYx2E=----END CERTIFICATE
----BEGIN CERTIFICATE
MIIDWD(cert contents trucated)e19Jv799c=----END CERTIFICATE
"""
let pemData = pemString.data(using: .utf8)!
var inputFormat :SecExternalFormat = .formatUnknown
var itemType :SecExternalItemType = .itemTypeUnknown
var itemsCFArray :CFArray? = nil
let error = SecItemImport(pemData as CFData, nil, &inputFormat, &itemType, [], nil, nil, &itemsCFArray)
let errorString = SecCopyErrorMessageString(error, nil)
The error is always "Unknown format in import."
Any ideas why this is returning "Unknown format"?