Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can't retrieve kSecLabelItemAttr of KeychainItem (getting malloc errors in Apple's code)




Sorry, minor update:

The C file had some flaws, not that they really matter, but here is a corrected version:

#include <Security/Security.h>
#include <stdlib.h>
#include <stdio.h>


#define GETLABEL #define value(x) strlen(x), x

int main(int argc, char **argv) {
	OSStatus err;
	SecKeychainItemRef	item;
	SecKeychainAttribute attr[] = {
		{ kSecDescriptionItemAttr, value("theDescription") },
		{ kSecCommentItemAttr, value("theComment") },
		{ kSecLabelItemAttr, value("theLabel") },
		{ kSecAccountItemAttr, value("theAccount") },
		{ kSecServiceItemAttr, value("theService") }
	};

	SecKeychainAttributeList list;
	
	list.count = 5;
	list.attr = attr;

	err = SecKeychainItemCreateFromContent(
		kSecGenericPasswordItemClass,
		&list,
		10,
		"1234567890",
		NULL,
		NULL,
		&item
	);
	
	printf("Error %d\n", err);
	
	UInt32 tags[] = {
		kSecDescriptionItemAttr,
		kSecCommentItemAttr,

#ifdef GETLABEL	
		kSecLabelItemAttr,
#endif		
		
		kSecAccountItemAttr,
		kSecServiceItemAttr,
		kSecCreationDateItemAttr
	};
	
	SecKeychainAttributeInfo attr2 = {
#ifdef GETLABEL
		6,
#else
		5,
#endif
		tags,
		NULL
	};

	SecKeychainAttributeList *l;

	err = SecKeychainItemCopyAttributesAndData(
		item,
		&attr2,
		NULL,
		&l,
		NULL,
		NULL
	);
		
	printf("Error %d\n", err);
	
	if (err) exit(1);

	int i;
	int limit;
	
#ifdef GETLABEL
	limit = 6;
#else
	limit = 5;
#endif
	for (i = 0; i < limit; i++) {
		printf("Attribute %d of size %d: %.*s\n",
			l->attr[i].tag,
			l->attr[i].length,
			l->attr[i].length,
			l->attr[i].data);
	}

	return 0;
}


-- Best Regards, Markus Hanauska


_______________________________________________ Do not post admin requests to the list. They will be ignored. Apple-cdsa mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/apple-cdsa/email@hidden

This email sent to email@hidden
References: 
 >Can't retrieve kSecLabelItemAttr of KeychainItem (getting malloc errors in Apple's code) (From: Markus Hanauska <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.