1 #include <Security/SecKeychain.h>
2 #include <Security/SecKeychainItem.h>
6 #include "keychain_regressions.h"
7 #include "kc-helpers.h"
11 SecKeychainRef source
, dest
;
12 source
= createNewKeychain("source", "test");
13 dest
= createNewKeychain("dest", "test");
14 SecKeychainItemRef original
= NULL
;
15 ok_status(SecKeychainAddInternetPassword(source
,
16 19, "members.spamcop.net",
20 80, kSecProtocolTypeHTTP
,
21 kSecAuthenticationTypeDefault
,
22 4, "test", &original
), "add internet password");
23 SecKeychainAttribute origAttrs
[] =
25 { kSecCreationDateItemAttr
},
26 { kSecModDateItemAttr
}
28 SecKeychainAttributeList origAttrList
=
30 sizeof(origAttrs
) / sizeof(*origAttrs
),
33 ok_status(SecKeychainItemCopyContent(original
, NULL
, &origAttrList
,
34 NULL
, NULL
), "SecKeychainItemCopyContent");
36 /* Must sleep 1 second to trigger mod date bug. */
38 SecKeychainItemRef copy
;
39 ok_status(SecKeychainItemCreateCopy(original
, dest
, NULL
, ©
),
42 SecKeychainAttribute copyAttrs
[] =
44 { kSecCreationDateItemAttr
},
45 { kSecModDateItemAttr
}
47 SecKeychainAttributeList copyAttrList
=
49 sizeof(copyAttrs
) / sizeof(*copyAttrs
),
52 ok_status(SecKeychainItemCopyContent(copy
, NULL
, ©AttrList
,
53 NULL
, NULL
), "SecKeychainItemCopyContent");
55 is(origAttrs
[0].length
, 16, "creation date length 16");
56 is(origAttrs
[1].length
, 16, "mod date length 16");
57 is(origAttrs
[0].length
, copyAttrs
[0].length
, "creation date length same");
58 is(origAttrs
[1].length
, copyAttrs
[1].length
, "mod date length same");
60 diag("original creation: %.*s copy creation: %.*s",
61 (int)origAttrs
[0].length
, (const char *)origAttrs
[0].data
,
62 (int)copyAttrs
[0].length
, (const char *)copyAttrs
[0].data
);
63 ok(!memcmp(origAttrs
[0].data
, copyAttrs
[0].data
, origAttrs
[0].length
),
64 "creation date same");
66 diag("original mod: %.*s copy mod: %.*s",
67 (int)origAttrs
[1].length
, (const char *)origAttrs
[1].data
,
68 (int)copyAttrs
[1].length
, (const char *)copyAttrs
[1].data
);
69 ok(!memcmp(origAttrs
[1].data
, copyAttrs
[1].data
, origAttrs
[1].length
),
72 ok_status(SecKeychainItemFreeContent(&origAttrList
, NULL
),
73 "SecKeychainItemCopyContent");
74 ok_status(SecKeychainItemFreeContent(©AttrList
, NULL
),
75 "SecKeychainItemCopyContent");
77 is(CFGetRetainCount(original
), 1, "original retaincount is 1");
79 is(CFGetRetainCount(copy
), 1, "copy retaincount is 1");
81 is(CFGetRetainCount(source
), 1, "source retaincount is 1");
82 ok_status(SecKeychainDelete(source
), "delete keychain source");
84 ok_status(SecKeychainDelete(dest
), "delete keychain dest");
85 is(CFGetRetainCount(dest
), 1, "dest retaincount is 1");
89 int kc_19_item_copy_internet(int argc
, char *const *argv
)