]>
git.saurik.com Git - apple/security.git/blob - OSX/sec/Security/Regressions/secitem/si-78-query-attrs.c
2 * Copyright (c) 2006-2010,2014 Apple Inc. All Rights Reserved.
5 #include <CoreFoundation/CoreFoundation.h>
6 #include <Security/SecItem.h>
7 #include <Security/SecBase.h>
8 #include <utilities/array_size.h>
9 #include <utilities/SecCFWrappers.h>
13 #include "Security_regressions.h"
15 /* Test regression from <rdar://problem/16461008> REGRESSION (Security-1601?): Preferences crashes when trying to view Safari > Saved Credit Cards (SecItemCopyMatching returns empty dictionaries when kSecReturnAttributes is not true) */
17 static void tests ( void )
20 security item -g class=genp agrp=com.apple.safari.credit-cards sync=1
21 acct : 3B1ED3EC-A558-43F0-B337-6E891000466B
22 agrp : com.apple.safari.credit-cards
23 cdat : 2014-01-24 22:58:17 +0000
24 icmt : This keychain item is used by Safari to automatically fill credit card information in web forms.
25 labl : Safari Credit Card Entry:
26 mdat : 2014-03-31 05:22:53 +0000
28 svce : SafariCreditCardEntries
31 v_Data : 62706C6973743030D30102030405065E43617264686F6C6465724E616D655F1010436172644E616D655549537472696E675A436172644E756D6265725B4D69747A2050657474656C505F101031323334353637383938373636353535080F1E313C4849000000000000010100000000000000070000000000000000000000000000005C
33 We actually use altered data and attributes to not mess up with real CreditCard data when running tests on system
36 static const uint8_t vdata
[] = {
37 0x62 , 0x70 , 0x6c , 0x69 , 0x73 , 0x74 , 0x30 , 0x30 , 0xd3 , 0x01 , 0x02 , 0x03 ,
38 0x04 , 0x05 , 0x06 , 0x5e , 0x43 , 0x61 , 0x72 , 0x64 , 0x68 , 0x6f , 0x6c , 0x64 ,
39 0x65 , 0x72 , 0x4e , 0x61 , 0x6d , 0x65 , 0x5f , 0x10 , 0x10 , 0x43 , 0x61 , 0x72 ,
40 0x64 , 0x4e , 0x61 , 0x6d , 0x65 , 0x55 , 0x49 , 0x53 , 0x74 , 0x72 , 0x69 , 0x6e ,
41 0x67 , 0x5a , 0x43 , 0x61 , 0x72 , 0x64 , 0x4e , 0x75 , 0x6d , 0x62 , 0x65 , 0x72 ,
42 0x5b , 0x4d , 0x69 , 0x74 , 0x7a , 0x20 , 0x50 , 0x65 , 0x74 , 0x74 , 0x65 , 0x6c ,
43 0x50 , 0x5f , 0x10 , 0x10 , 0x31 , 0x32 , 0x33 , 0x34 , 0x35 , 0x36 , 0x37 , 0x38 ,
44 0x39 , 0x38 , 0x37 , 0x36 , 0x36 , 0x35 , 0x35 , 0x35 , 0x08 , 0x0f , 0x1e , 0x31 ,
45 0x3c , 0x48 , 0x49 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x01 , 0x00 ,
46 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x07 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
47 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x5c
49 CFDataRef data
= CFDataCreate ( NULL
, vdata
, sizeof ( vdata
));
50 CFDictionaryRef item
= CFDictionaryCreateForCFTypes ( NULL
,
51 kSecClass
, kSecClassGenericPassword
,
52 kSecAttrAccount
, CFSTR ( "3B1ED3EC-A558-43F0-B337-6E891000466B-test" ),
53 kSecAttrService
, CFSTR ( "SafariCreditCardEntries-test" ),
56 ok_status ( SecItemAdd ( item
, NULL
), "add generic password" );
59 agrp = "com.apple.safari.credit-cards";
61 "m_Limit" = "m_LimitAll";
63 "r_PersistentRef" = 1;
64 svce = SafariCreditCardEntries;
66 CFDictionaryRef query
= CFDictionaryCreateForCFTypes ( NULL
,
67 kSecClass
, kSecClassGenericPassword
,
68 kSecAttrService
, CFSTR ( "SafariCreditCardEntries-test" ),
69 kSecMatchLimit
, kSecMatchLimitAll
,
70 kSecReturnData
, kCFBooleanTrue
,
71 kSecReturnPersistentRef
, kCFBooleanTrue
,
74 ok_status ( SecItemCopyMatching ( query
, & result
), "query generic password" );
75 ok ( isArray ( result
) && CFArrayGetCount ( result
) == 1 , "return 1-sized array of results" );
76 CFDictionaryRef row
= CFArrayGetValueAtIndex ( result
, 0 );
77 ok ( isDictionary ( row
), "array row is dictionary" );
78 ok ( isData ( CFDictionaryGetValue ( row
, kSecValuePersistentRef
)), "result contains valid persistentref" );
79 ok ( isData ( CFDictionaryGetValue ( row
, kSecValueData
)), "result contains data" );
80 ok ( CFEqual ( CFDictionaryGetValue ( row
, kSecValueData
), data
), "returned data are correct" );
84 query
= CFDictionaryCreateForCFTypes ( NULL
,
85 kSecClass
, kSecClassGenericPassword
,
86 kSecAttrService
, CFSTR ( "SafariCreditCardEntries-test" ),
87 kSecMatchLimit
, kSecMatchLimitAll
,
88 kSecReturnData
, kCFBooleanTrue
,
90 ok_status ( SecItemCopyMatching ( query
, & result
), "query generic password" );
91 ok ( isArray ( result
) && CFArrayGetCount ( result
) == 1 , "return 1-sized array of results" );
92 row
= CFArrayGetValueAtIndex ( result
, 0 );
93 ok ( isData ( row
), "result contains data" );
94 ok ( CFEqual ( row
, data
), "returned data are correct" );
98 query
= CFDictionaryCreateForCFTypes ( NULL
,
99 kSecClass
, kSecClassGenericPassword
,
100 kSecAttrService
, CFSTR ( "SafariCreditCardEntries-test" ),
101 kSecMatchLimit
, kSecMatchLimitAll
,
102 kSecReturnPersistentRef
, kCFBooleanTrue
,
104 ok_status ( SecItemCopyMatching ( query
, & result
), "query generic password" );
105 ok ( isArray ( result
) && CFArrayGetCount ( result
) == 1 , "return 1-sized array of results" );
106 row
= CFArrayGetValueAtIndex ( result
, 0 );
107 ok ( isData ( row
), "result contains data" );
110 query
= CFDictionaryCreateForCFTypes ( NULL
,
111 kSecClass
, kSecClassGenericPassword
,
112 kSecAttrService
, CFSTR ( "SafariCreditCardEntries-test" ),
114 ok_status ( SecItemDelete ( query
), "delete testing item" );
121 int si_78_query_attrs ( int argc
, char * const * argv
)