2 * Copyright (c) 2006-2010,2012-2013 Apple Inc. All Rights Reserved.
5 #include <CoreFoundation/CoreFoundation.h>
6 #include <Security/SecItem.h>
7 #include <Security/SecItemPriv.h>
8 #include <Security/SecBase.h>
9 #include <utilities/array_size.h>
13 #include "Security_regressions.h"
15 /* Test basic add delete update copy matching stuff. */
16 static void tests(void)
18 const char *v_data
= "test";
19 CFDataRef pwdata
= CFDataCreate(NULL
, (UInt8
*)v_data
, strlen(v_data
));
20 const void *keys
[] = {
26 const void *values
[] = {
27 kSecClassGenericPassword
,
32 CFDictionaryRef item
= CFDictionaryCreate(NULL
, keys
, values
,
33 array_size(keys
), NULL
, NULL
);
34 ok_status(SecItemAdd(item
, NULL
), "add generic password");
36 CFTypeRef results
= NULL
;
37 /* Create a dict with all attrs except the data. */
38 CFDictionaryRef query
= CFDictionaryCreate(NULL
, keys
, values
,
39 (array_size(keys
)) - 1, NULL
, NULL
);
40 ok_status(SecItemCopyMatching(query
, &results
), "find generic password");
46 /* Modify the data of the item. */
47 const char *v_data2
= "different password data this time";
48 CFDataRef pwdata2
= CFDataCreate(NULL
, (UInt8
*)v_data2
, strlen(v_data2
));
49 CFMutableDictionaryRef changes
= CFDictionaryCreateMutable(NULL
, 0, NULL
, NULL
);
50 CFDictionarySetValue(changes
, kSecValueData
, pwdata2
);
51 ok_status(SecItemUpdate(query
, changes
), "update generic password");
53 CFDictionarySetValue(changes
, kSecValueData
, NULL
);
54 is_status(SecItemUpdate(query
, changes
), errSecParam
, "update NULL data");
56 /* This seems to be what we were seeing in
57 <rdar://problem/6940041> 466 Crashes in securityd: kc_encrypt_data (SecItemServer.c:971).
58 which is now fixed. */
59 CFDictionarySetValue(changes
, kSecValueData
, CFSTR("bogus"));
60 is_status(SecItemUpdate(query
, changes
), errSecParam
, "update string data");
62 ok_status(SecItemDelete(query
), "delete generic password");
90 int si_11_update_data(int argc
, char *const *argv
)