]> git.saurik.com Git - apple/security.git/blob - OSX/sec/securityd/Regressions/secd-82-persistent-ref.c
Security-57740.1.18.tar.gz
[apple/security.git] / OSX / sec / securityd / Regressions / secd-82-persistent-ref.c
1 //
2 // secd-82-persistent-ref.c
3 // sec
4 //
5 // Copyright (c) 2013-2014 Apple Inc. All Rights Reserved.
6 //
7 //
8
9 #include <Security/Security.h>
10 #include <Security/SecItemPriv.h>
11
12 #include "secd_regressions.h"
13 #include "SecdTestKeychainUtilities.h"
14
15 int secd_82_persistent_ref(int argc, char *const *argv)
16 {
17 plan_tests(5);
18
19 /* custom keychain dir */
20 secd_test_setup_temp_keychain("secd_82_persistent_ref", NULL);
21
22 CFMutableDictionaryRef attrs;
23 CFMutableDictionaryRef query;
24 CFDataRef data;
25 CFTypeRef result;
26 CFArrayRef array;
27 CFIndex i, n;
28 CFDictionaryRef item;
29
30 attrs = CFDictionaryCreateMutable( NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks );
31 CFDictionarySetValue( attrs, kSecClass, kSecClassGenericPassword );
32 CFDictionarySetValue( attrs, kSecAttrAccessible, kSecAttrAccessibleAlwaysPrivate );
33 CFDictionarySetValue( attrs, kSecAttrLabel, CFSTR( "TestLabel" ) );
34 CFDictionarySetValue( attrs, kSecAttrDescription, CFSTR( "TestDescription" ) );
35 CFDictionarySetValue( attrs, kSecAttrAccount, CFSTR( "TestAccount" ) );
36 CFDictionarySetValue( attrs, kSecAttrService, CFSTR( "TestService" ) );
37 data = CFDataCreate( NULL, (const uint8_t *) "\x00\x01\x02", 3 );
38 CFDictionarySetValue( attrs, kSecValueData, data );
39 CFRelease( data );
40
41 is(SecItemAdd(attrs, NULL), errSecSuccess);
42 CFRelease( attrs );
43
44 query = CFDictionaryCreateMutable( NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks );
45 CFDictionarySetValue( query, kSecClass, kSecClassGenericPassword );
46 CFDictionarySetValue( query, kSecAttrSynchronizable, kSecAttrSynchronizableAny );;
47 CFDictionarySetValue( query, kSecAttrAccount, CFSTR( "TestAccount" ) );
48 CFDictionarySetValue( query, kSecReturnAttributes, kCFBooleanTrue );
49 CFDictionarySetValue( query, kSecReturnPersistentRef, kCFBooleanTrue );
50 CFDictionarySetValue( query, kSecMatchLimit, kSecMatchLimitAll );
51
52 is(SecItemCopyMatching(query, &result), errSecSuccess);
53 CFRelease( query );
54 array = (CFArrayRef) result;
55
56 n = CFArrayGetCount( array );
57 is(n, 1);
58 for( i = 0; i < n; ++i )
59 {
60 item = (CFDictionaryRef) CFArrayGetValueAtIndex(array, i);
61
62 ok((CFDataRef) CFDictionaryGetValue(item, kSecValuePersistentRef));
63 }
64 CFRelease( result );
65
66
67 return 0;
68 }