Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-extractable private key in Keychain on OS X

The manual page for /usr/bin/security on OS X 10.9 indicates that there is a -x option for security import to specify that private keys are non-extractable after being imported.

How is this implemented? Are the private keys imported through such means really become completely non-extractable, or is there still a way to get a hold of them through some kind of memory dump? How do applications still use such keys for their crypto?

like image 658
cnst Avatar asked Oct 15 '25 09:10

cnst


1 Answers

I'm not sure how the applications still use such keys, but as per https://reverseengineering.stackexchange.com/questions/6043/extract-non-extractable-private-key-from-os-x-keychain, it appears that this is simply implemented as a bit attribute for CSSM_KEYATTR_FLAGS keyAttributes of struct SecKeyImportExportParameters named CSSM_KEYATTR_EXTRACTABLE.

  • http://opensource.apple.com/source/SecurityTool/SecurityTool-55115/keychain_import.c
  • http://opensource.apple.com/source/Security/Security-55471.14/libsecurity_keychain/lib/SecImportExport.h

As per the above, when the import is done, this attribute is specifically omitted when the -x option is specified to security import.


According to SecItem.h, this kSecAttrIsExtractable has been introduced with OS X 10.6.

  • http://opensource.apple.com/source/Security/Security-55471.14/libsecurity_keychain/lib/SecItem.h

Subsequently, when trying to do a wrapped export, several places within the Security framework appear to check to make sure that this CSSM_KEYATTR_EXTRACTABLE bit is set prior to doing any kind of export, and return an error in case the attribute is not set.

  • http://opensource.apple.com/source/Security/Security-55471.14/libsecurity_keychain/lib/SecImportExportCrypto.cpp
  • http://opensource.apple.com/source/Security/Security-55471.14/libsecurity_pkcs12/lib/pkcs12Crypto.cpp
like image 142
cnst Avatar answered Oct 17 '25 02:10

cnst