Hi there, I'm continuing to build up the API on keychain, I'm trying to implement the ability to create an own certificate chain for validation purposes, similar to ssl. To this extent I need to retrieve the certificates from the System's stores but I can't seem to find a way to do this in code?
Creating a query with kSecMatchTrustedOnly only returns certificates which are seemingly manually marked as trusted or otherwise just skips over the System roots keychain.
As far as I understand using kSecUseKeychain doesn't work either, since (besides SecKeychain being deprecated) it only works with SecItemAdd.
Post
Replies
Boosts
Views
Activity
I'm extending a C++ library to gather some data from the keychain, I have a prototype code written in Swift that works just fine:
import Security;
import Foundation;
let query: [String: Any] = [
kSecClass as String: kSecClassCertificate,
kSecReturnData as String: true,
kSecMatchLimit as String: kSecMatchLimitAll
]
var items: CFTypeRef?;
let status = SecItemCopyMatching(query as CFDictionary, &items);
However trying to do the same in C++ crashes:
#include <security/SecItem.h>
int main() {
static const void* keys[] = {
kSecClass,
kSecMatchLimit,
kSecReturnData,
};
static const void* values[] = {
kSecClassCertificate,
kSecMatchLimitOne,
kCFBooleanTrue,
};
static_assert(sizeof(keys) == sizeof(values), "Key-value lengths mismatch for query dictionary constructor!");
CFDictionaryRef query = CFDictionaryCreate(kCFAllocatorDefault, keys, values, sizeof(keys), nullptr, nullptr);
SecItemCopyMatching(query, nullptr);
return 0;
}
With the backtrace of:
Thread 1 Queue : com.apple.main-thread (serial)
#0 0x0000000191a7f1b8 in objc_retain ()
#1 0x0000000191ed9e0c in -[__NSDictionaryM __setObject:forKey:] ()
#2 0x0000000191f3ae28 in __CFDictionaryApplyFunction_block_invoke ()
#3 0x0000000191effbb0 in CFBasicHashApply ()
#4 0x0000000191ef2ccc in CFDictionaryApplyFunction ()
#5 0x0000000194cdafc4 in SecCFDictionaryCOWGetMutable ()
#6 0x0000000194cdf3e8 in SecItemCopyMatching_ios ()
#7 0x0000000194e79754 in SecItemCopyMatching ()
#8 0x0000000100003f68 in main at /Users/kkurek/whatever/whatever/main.cpp:15
#9 0x0000000191acf154 in start ()
I don't have much experience with MacOS so I'm not sure how to analyze this situation. I have tried running with sanitizers enabled but somehow the crash doesn't occur at all when running with them.
Hi there, I'm currently working on a compatibility feature for Apple that allows the user to manage their keys and certificates from within our internal API. For this I need to retrieve all the items contained within keychains.
I am looking at the documentation for SecItem API but so far I have not really found an obvious way to link these items together. My best guess so far is to perform two queries, grabbing all SecKeys from the keychains, pairing them up with public keys through SecKeyCopyPublicKey, then downloading all CertItems and pairing them with public keys with SecCertificateCopyKey, and then join the two using public keys.
This sounds however somewhat involved and I was wondering if there was a better way of going about the process?