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>
12 #include "secd_regressions.h"
13 #include "SecdTestKeychainUtilities.h"
15 int secd_82_persistent_ref(int argc
, char *const *argv
)
19 /* custom keychain dir */
20 secd_test_setup_temp_keychain("secd_82_persistent_ref", NULL
);
22 CFMutableDictionaryRef attrs
;
23 CFMutableDictionaryRef query
;
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
);
41 is(SecItemAdd(attrs
, NULL
), errSecSuccess
);
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
);
52 is(SecItemCopyMatching(query
, &result
), errSecSuccess
);
54 array
= (CFArrayRef
) result
;
56 n
= CFArrayGetCount( array
);
58 for( i
= 0; i
< n
; ++i
)
60 item
= (CFDictionaryRef
) CFArrayGetValueAtIndex(array
, i
);
62 ok((CFDataRef
) CFDictionaryGetValue(item
, kSecValuePersistentRef
));