]> git.saurik.com Git - apple/security.git/blob - OSX/sec/Security/Regressions/secitem/si-78-query-attrs.c
Security-57336.10.29.tar.gz
[apple/security.git] / OSX / sec / Security / Regressions / secitem / si-78-query-attrs.c
1 /*
2 * Copyright (c) 2006-2010,2014 Apple Inc. All Rights Reserved.
3 */
4
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>
10 #include <stdlib.h>
11 #include <unistd.h>
12
13 #include "Security_regressions.h"
14
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) */
16
17 static void tests(void)
18 {
19 /*
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
27 pdmn : ak
28 svce : SafariCreditCardEntries
29 sync : 1
30 tomb : 0
31 v_Data : 62706C6973743030D30102030405065E43617264686F6C6465724E616D655F1010436172644E616D655549537472696E675A436172644E756D6265725B4D69747A2050657474656C505F101031323334353637383938373636353535080F1E313C4849000000000000010100000000000000070000000000000000000000000000005C
32
33 We actually use altered data and attributes to not mess up with real CreditCard data when running tests on system
34 where data exist.
35 */
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
48 };
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"),
54 kSecValueData, data,
55 NULL);
56 ok_status(SecItemAdd(item, NULL), "add generic password");
57
58 /*
59 agrp = "com.apple.safari.credit-cards";
60 class = genp;
61 "m_Limit" = "m_LimitAll";
62 "r_Data" = 1;
63 "r_PersistentRef" = 1;
64 svce = SafariCreditCardEntries;
65 */
66 CFDictionaryRef query = CFDictionaryCreateForCFTypes(NULL,
67 kSecClass, kSecClassGenericPassword,
68 kSecAttrService, CFSTR("SafariCreditCardEntries-test"),
69 kSecMatchLimit, kSecMatchLimitAll,
70 kSecReturnData, kCFBooleanTrue,
71 kSecReturnPersistentRef, kCFBooleanTrue,
72 NULL);
73 CFTypeRef result;
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");
81
82 CFRelease(result);
83 CFRelease(query);
84 query = CFDictionaryCreateForCFTypes(NULL,
85 kSecClass, kSecClassGenericPassword,
86 kSecAttrService, CFSTR("SafariCreditCardEntries-test"),
87 kSecMatchLimit, kSecMatchLimitAll,
88 kSecReturnData, kCFBooleanTrue,
89 NULL);
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");
95
96 CFRelease(result);
97 CFRelease(query);
98 query = CFDictionaryCreateForCFTypes(NULL,
99 kSecClass, kSecClassGenericPassword,
100 kSecAttrService, CFSTR("SafariCreditCardEntries-test"),
101 kSecMatchLimit, kSecMatchLimitAll,
102 kSecReturnPersistentRef, kCFBooleanTrue,
103 NULL);
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");
108
109 CFRelease(query);
110 query = CFDictionaryCreateForCFTypes(NULL,
111 kSecClass, kSecClassGenericPassword,
112 kSecAttrService, CFSTR("SafariCreditCardEntries-test"),
113 NULL);
114 ok_status(SecItemDelete(query), "delete testing item");
115
116 CFRelease(query);
117 CFRelease(data);
118 CFRelease(item);
119 }
120
121 int si_78_query_attrs(int argc, char *const *argv)
122 {
123 plan_tests(15);
124
125 tests();
126
127 return 0;
128 }