SecPKCS12Import() from Security.framework fails on OS X 10.6

cocoa, macos, security

Solution

Security.framework is most certainly implemented — see the Security Reference Update which documents what has changed in the framework in 10.6 and prior. Since you know the headers to use, I assume you've already consulted the Security Framework Reference.

Are you sure you're properly importing and linking against the framework? (It's in `/System/Library/Security.framework`, so you shouldn't have to specify the path.)

Does the compiler issue warnings or errors stating that the symbols in SecImportExport.h are undefined? (If not, how do you know they're "declared but undefined"?)

When you say that this fails on 10.6, have you tried it on an earlier version of the OS successfully?

EDIT: Okay, since you're using other parts of Security.framework successfully, and the APIs and constants you're trying to use are 10.6 only, it doesn't seem like a linking issue. What do your import look like? Are you sure you're importing `SecImportExport.h` properly? The constants are declared just above the `SecPKCS12Import()` function, so if you get warnings for the constants, you should get one for the function being undefined as well.

EDIT: I have confirmed with a member of the team at Apple that works on Security.framework that this functionality is not currently implemented. Please file a bug to gripe about this at http://bugreport.apple.com against component `Security (New Bugs)`, version `X`. Include the URL to this question in your report. Sorry there's not a better answer at the moment.

Problem

When I attempt to use `SecPKCS12Import()` from the Security framework as provided by Mac OS X 10.6, the result code is always `errSecUnimplemented`, regardless of the arguments provided. Furthermore, the linker is unable to find symbols for the constants relevant to this function declared in SecImportExport.h (i.e. `kSecImportExportPassphrase`, `kSecImportItemIdentity`, et al.). What on Earth is going on with this library -- is the function implemented or is it not? Why can the linker resolve all other symbols in the framework, but not these? How should I convert a PKCS12-formatted binary blob to a SecIdentityRef or SecCertificateRef and SecKeyRef pair? What am I doing wrong? I'm sure this is a PEBKAC issue. :-) EDIT: I see that I was very unclear in my question. I'm aware that Security.framework is implemented, given that I am able to use the other functionality it provides without an issue. Given this, I'm fairly certain that I'm linking against the framework correctly, since if I remove the link, none of the symbols can be found -- as expected. When I relink the framework, all the symbols are found, with the exception of the constants relevant to `SecPKCS12Import()`, e.g. `kSecImportExportPassphrase`, `kSecImportItemIdentity`, etc. Given that I cannot use these symbols, I passed in what could have been incorrect strings (`@"kSecImportItemIdentity"`, etc.), but the error code returned was `errSecUnimplemented`. This led me to believe that perhaps this specific functionality has not been implemented. I tried using the 10.5 SDK, but that didn't work, of course. :-) EDIT: My import is just a regular `#import <Security/Security.h>`. For kicks, I tried `#import <Security/SecImportExport.h>` as well, but this effected no change. That said, the error is issued by the linker, not the compiler. I ran `dyldinfo -export Security.framework/Security` to list the symbols exported by the library and found many of the new symbols, but `kSecImportExportPassphrase` and friends were conspicuously missing. This might explain why the linker cannot find the symbols. The symbol for `SecPKCS12Import` appears in the symbol table and I can call that with no issues, it's just the functionality does not seem to be there.

Original source