2 // secd-82-persistent-ref.c
5 // Copyright (c) 2013-2014 Apple Inc. All Rights Reserved.
9 #include <Security/Security.h>
10 #include <Security/SecItemPriv.h>
11 #include <utilities/SecCFWrappers.h>
13 #include "secd_regressions.h"
14 #include "SecdTestKeychainUtilities.h"
16 int secd_82_persistent_ref(int argc, char *const *argv)
20 /* custom keychain dir */
21 secd_test_setup_temp_keychain("secd_82_persistent_ref", NULL);
23 CFMutableDictionaryRef attrs = NULL;
24 CFMutableDictionaryRef query = NULL;
25 CFDataRef data = NULL;
26 CFTypeRef result = NULL;
27 CFArrayRef array = NULL;
29 CFDictionaryRef item = NULL;
31 attrs = CFDictionaryCreateMutable( NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks );
32 CFDictionarySetValue( attrs, kSecClass, kSecClassGenericPassword );
33 CFDictionarySetValue( attrs, kSecAttrAccessible, kSecAttrAccessibleAlwaysPrivate );
34 CFDictionarySetValue( attrs, kSecAttrLabel, CFSTR( "TestLabel" ) );
35 CFDictionarySetValue( attrs, kSecAttrDescription, CFSTR( "TestDescription" ) );
36 CFDictionarySetValue( attrs, kSecAttrAccount, CFSTR( "TestAccount" ) );
37 CFDictionarySetValue( attrs, kSecAttrService, CFSTR( "TestService" ) );
38 data = CFDataCreate( NULL, (const uint8_t *) "\x00\x01\x02", 3 );
39 CFDictionarySetValue( attrs, kSecValueData, data );
40 CFReleaseNull( data );
42 is(SecItemAdd(attrs, NULL), errSecSuccess);
43 CFReleaseNull( attrs );
45 query = CFDictionaryCreateMutable( NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks );
46 CFDictionarySetValue( query, kSecClass, kSecClassGenericPassword );
47 CFDictionarySetValue( query, kSecAttrSynchronizable, kSecAttrSynchronizableAny );;
48 CFDictionarySetValue( query, kSecAttrAccount, CFSTR( "TestAccount" ) );
49 CFDictionarySetValue( query, kSecReturnAttributes, kCFBooleanTrue );
50 CFDictionarySetValue( query, kSecReturnPersistentRef, kCFBooleanTrue );
51 CFDictionarySetValue( query, kSecMatchLimit, kSecMatchLimitAll );
53 is(SecItemCopyMatching(query, &result), errSecSuccess);
54 CFReleaseNull( query );
55 array = (CFArrayRef) result;
58 skip("No results from SecItemCopyMatching", 2, array && (CFArrayGetTypeID() == CFGetTypeID(array)));
59 n = CFArrayGetCount( array );
61 for( i = 0; i < n; ++i )
63 item = (CFDictionaryRef) CFArrayGetValueAtIndex(array, i);
65 ok((CFDataRef) CFDictionaryGetValue(item, kSecValuePersistentRef));
68 CFReleaseNull( result );