X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/5c19dc3ae3bd8e40a9c028b0deddd50ff337692c..90dc47c27df1983f6ebc252b0c4b94c8718fe52d:/OSX/libsecurity_keychain/lib/SecImportExportCrypto.cpp diff --git a/OSX/libsecurity_keychain/lib/SecImportExportCrypto.cpp b/OSX/libsecurity_keychain/lib/SecImportExportCrypto.cpp index 71a4b315..f3cf841e 100644 --- a/OSX/libsecurity_keychain/lib/SecImportExportCrypto.cpp +++ b/OSX/libsecurity_keychain/lib/SecImportExportCrypto.cpp @@ -25,7 +25,7 @@ * keys. */ -#include "SecImportExport.h" +#include #include "SecImportExportCrypto.h" #include "SecImportExportUtils.h" #include "Keychains.h" @@ -41,6 +41,7 @@ #include #include #include +#include /* * Key attrribute names and values. @@ -562,8 +563,14 @@ OSStatus impExpImportKeyCommon( KeychainCore::Access::required(accessRef) : new KeychainCore::Access("Imported Private Key")); try { - CssmClient::KeyAclBearer bearer(cspHand, unwrappedKey, Allocator::standard()); - theAccess->setAccess(bearer, maker); + if(secKeyRef != NULL) { + // setAccess using the new secKeyRef, not the old unwrappedKey. + // At this point, we might have duplicate keys registered with securityd. Use the newest one. + theAccess->setAccess(*KeyItem::required(secKeyRef)->key(), maker); + } else { + CssmClient::KeyAclBearer bearer(cspHand, unwrappedKey, Allocator::standard()); + theAccess->setAccess(bearer, maker); + } } catch (const CssmError &e) { /* not implemented means we're talking to the raw CSP which does