1 #include <Security/SecKeychain.h>
2 #include <Security/SecKeychainItem.h>
10 void tests(int dont_skip
)
12 SecKeychainRef source
, dest
;
13 ok_status(SecKeychainCreate("source", 4, "test", FALSE
, NULL
, &source
),
14 "create source keychain");
15 ok_status(SecKeychainCreate("dest", 4, "test", FALSE
, NULL
, &dest
),
16 "create dest keychain");
17 SecKeychainItemRef original
= NULL
;
18 ok_status(SecKeychainAddInternetPassword(source
,
19 19, "members.spamcop.net",
23 80, kSecProtocolTypeHTTP
,
24 kSecAuthenticationTypeDefault
,
25 4, "test", &original
), "add internet password");
26 SecKeychainAttribute origAttrs
[] =
28 { kSecCreationDateItemAttr
},
29 { kSecModDateItemAttr
}
31 SecKeychainAttributeList origAttrList
=
33 sizeof(origAttrs
) / sizeof(*origAttrs
),
36 ok_status(SecKeychainItemCopyContent(original
, NULL
, &origAttrList
,
37 NULL
, NULL
), "SecKeychainItemCopyContent");
39 /* Must sleep 1 second to trigger mod date bug. */
41 SecKeychainItemRef copy
;
42 ok_status(SecKeychainItemCreateCopy(original
, dest
, NULL
, ©
),
45 SecKeychainAttribute copyAttrs
[] =
47 { kSecCreationDateItemAttr
},
48 { kSecModDateItemAttr
}
50 SecKeychainAttributeList copyAttrList
=
52 sizeof(copyAttrs
) / sizeof(*copyAttrs
),
55 ok_status(SecKeychainItemCopyContent(copy
, NULL
, ©AttrList
,
56 NULL
, NULL
), "SecKeychainItemCopyContent");
58 is(origAttrs
[0].length
, 16, "creation date length 16");
59 is(origAttrs
[1].length
, 16, "mod date length 16");
60 is(origAttrs
[0].length
, copyAttrs
[0].length
, "creation date length same");
61 is(origAttrs
[1].length
, copyAttrs
[1].length
, "mod date length same");
64 todo("<rdar://problem/3731664> Moving/copying a keychain item "
65 "between keychains erroneously updates dates");
67 diag("original creation: %.*s copy creation: %.*s",
68 (int)origAttrs
[0].length
, (const char *)origAttrs
[0].data
,
69 (int)copyAttrs
[0].length
, (const char *)copyAttrs
[0].data
);
70 ok(!memcmp(origAttrs
[0].data
, copyAttrs
[0].data
, origAttrs
[0].length
),
71 "creation date same");
73 diag("original mod: %.*s copy mod: %.*s",
74 (int)origAttrs
[1].length
, (const char *)origAttrs
[1].data
,
75 (int)copyAttrs
[1].length
, (const char *)copyAttrs
[1].data
);
76 ok(!memcmp(origAttrs
[1].data
, copyAttrs
[1].data
, origAttrs
[1].length
),
80 ok_status(SecKeychainItemFreeContent(&origAttrList
, NULL
),
81 "SecKeychainItemCopyContent");
82 ok_status(SecKeychainItemFreeContent(©AttrList
, NULL
),
83 "SecKeychainItemCopyContent");
85 is(CFGetRetainCount(original
), 1, "original retaincount is 1");
87 is(CFGetRetainCount(copy
), 1, "copy retaincount is 1");
89 is(CFGetRetainCount(source
), 1, "source retaincount is 1");
90 ok_status(SecKeychainDelete(source
), "delete keychain source");
92 ok_status(SecKeychainDelete(dest
), "delete keychain dest");
93 is(CFGetRetainCount(dest
), 1, "dest retaincount is 1");
96 ok(tests_end(1), "cleanup");
99 int main(int argc
, char *const *argv
)
101 int dont_skip
= argc
> 1 && !strcmp(argv
[1], "-s");
105 if (!tests_begin(argc
, argv
))
106 BAIL_OUT("tests_begin failed");
109 ok_leaks("no leaks");