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