kc-20-identity-key-attributes.c [plain text]
#import <Security/Security.h>
#import <Security/SecCertificatePriv.h>
#include "keychain_regressions.h"
#include "kc-helpers.h"
#include "kc-identity-helpers.h"
#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
#include <Security/Security.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include <time.h>
#include <sys/param.h>
static void PrintPrivateKeyAttributes(SecKeyRef keyRef)
{
CFMutableDictionaryRef query = CFDictionaryCreateMutable(NULL, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionaryAddValue( query, kSecValueRef, keyRef );
CFDictionaryAddValue( query, kSecReturnAttributes, kCFBooleanTrue );
CFTypeRef result = NULL;
OSStatus status = SecItemCopyMatching(query, &result);
ok_status(status, "%s: SecItemCopyMatching", testName);
if (query)
CFRelease(query);
if(result) {
CFShow(result);
}
}
static void tests(SecKeychainRef kc)
{
SecIdentityRef identity=NULL;
SecKeyRef privateKeyRef=NULL;
OSStatus status;
identity = copyFirstIdentity(kc);
status = SecIdentityCopyPrivateKey(identity, &privateKeyRef);
ok_status(status, "%s: SecIdentityCopyPrivateKey", testName);
if (privateKeyRef) {
PrintPrivateKeyAttributes(privateKeyRef);
CFRelease(privateKeyRef);
}
CFReleaseNull(identity);
}
int kc_20_identity_key_attributes(int argc, char *const *argv)
{
plan_tests(6);
initializeKeychainTests(__FUNCTION__);
SecKeychainRef kc = getPopulatedTestKeychain();
tests(kc);
ok_status(SecKeychainDelete(kc), "%s: SecKeychainDelete", testName);
CFReleaseNull(kc);
deleteTestFiles();
return 0;
}