1 #include <Security/SecKeychain.h>
2 #include <Security/SecKeychainItem.h>
6 #include "keychain_regressions.h"
7 #include "kc-helpers.h"
11 SecKeychainRef keychain
= createNewKeychain("test", "test");
12 SecKeychainItemRef item
= NULL
;
13 ok_status(SecKeychainAddInternetPassword(keychain
,
14 19, "members.spamcop.net",
18 80, kSecProtocolTypeHTTP
,
19 kSecAuthenticationTypeDefault
,
20 4, "test", &item
), "add internet password");
21 ok(item
, "is item non NULL");
22 SecKeychainItemRef oldItem
= item
;
23 is_status(SecKeychainAddInternetPassword(keychain
,
24 19, "members.spamcop.net",
28 80, kSecProtocolTypeHTTP
,
29 kSecAuthenticationTypeDefault
,
30 4, "test", &item
), errSecDuplicateItem
, "add internet password again");
31 is((intptr_t)item
, (intptr_t)oldItem
, "item is unchanged");
35 ok_status(SecKeychainFindInternetPassword(keychain
,
36 19, "members.spamcop.net",
42 kSecAuthenticationTypeDefault
,
44 &item
), "find internet password");
46 SecItemClass itemClass
= 0;
47 SecKeychainAttribute attrs
[] =
49 { kSecAccountItemAttr
},
50 { kSecSecurityDomainItemAttr
},
51 { kSecServerItemAttr
}
53 SecKeychainAttributeList attrList
=
55 sizeof(attrs
) / sizeof(*attrs
),
58 ok_status(SecKeychainItemCopyContent(item
, &itemClass
, &attrList
,
59 NULL
, NULL
), "SecKeychainItemCopyContent");
60 is(itemClass
, kSecInternetPasswordItemClass
, "is internet password?");
61 is(attrs
[0].length
, 5, "account len");
62 ok(!strncmp(attrs
[0].data
, "smith", 5), "account eq smith");
63 is(attrs
[1].length
, 0, "security domain len");
64 is(attrs
[2].length
, 19, "server len");
65 ok(!strncmp(attrs
[2].data
, "members.spamcop.net", 19),
66 "servername eq members.spamcop.net");
67 ok_status(SecKeychainItemFreeContent(&attrList
, NULL
),
68 "SecKeychainItemCopyContent");
70 SecKeychainAttribute attrs2
[] =
72 { kSecAccountItemAttr
},
73 { kSecServiceItemAttr
},
74 { kSecSecurityDomainItemAttr
},
75 { kSecServerItemAttr
}
77 SecKeychainAttributeList attrList2
=
79 (sizeof(attrs2
) / sizeof(*attrs2
)),
83 skip("<rdar://problem/3298182> 6L60 Malloc/free misuse in "
84 "SecKeychainItemCopyContent()", 1, 1);
85 is_status(SecKeychainItemCopyContent(item
, &itemClass
, &attrList2
,
86 NULL
, NULL
), errSecNoSuchAttr
, "SecKeychainItemCopyContent fails");
89 is(CFGetRetainCount(item
), 1, "item retaincount is 1");
90 cmp_ok(CFGetRetainCount(keychain
), >=, 2, "keychain retaincount is at least 2");
92 cmp_ok(CFGetRetainCount(keychain
), >=, 1, "keychain retaincount is at least 1");
93 ok_status(SecKeychainDelete(keychain
), "delete keychain");
97 int kc_10_item_add_internet(int argc
, char *const *argv
)