Getting Attributes of Keychain Items

Posted by rgov on Stack Overflow See other posts from Stack Overflow or by rgov
Published on 2009-07-27T04:08:08Z Indexed on 2010/03/26 1:43 UTC
Read the original article Hit count: 666

Filed under:
|
|
|

I'm trying to get the attributes of a keychain item. This code should look up all the available attributes, then print off their tags and contents.

According to the docs I should be seeing tags like 'cdat', but instead they just look like an index (i.e., the first tag is 0, next is 1). This makes it pretty useless since I can't tell which attribute is the one I'm looking for.

	SecItemClass itemClass;
	SecKeychainItemCopyAttributesAndData(itemRef, NULL, &itemClass, NULL, NULL, NULL);

	SecKeychainRef keychainRef;
	SecKeychainItemCopyKeychain(itemRef, &keychainRef);

	SecKeychainAttributeInfo *attrInfo;
	SecKeychainAttributeInfoForItemID(keychainRef, itemClass, &attrInfo);

	SecKeychainAttributeList *attributes;
	SecKeychainItemCopyAttributesAndData(itemRef, attrInfo, NULL, &attributes, 0, NULL);

	for (int i = 0; i < attributes->count; i ++)
	{
		SecKeychainAttribute attr = attributes->attr[i];
		NSLog(@"%08x %@", attr.tag, [NSData dataWithBytes:attr.data length:attr.length]);
	}

	SecKeychainFreeAttributeInfo(attrInfo);
	SecKeychainItemFreeAttributesAndData(attributes, NULL);
	CFRelease(itemRef);
	CFRelease(keychainRef);

© Stack Overflow or respective owner

Related posts about keychain

Related posts about mac