To copy data and / or attributes stored in a given keychain element, the 3rd parameter of the SecKeychainItemCopyContent() function is SecKeychainAttributeList *attrList with type type
struct SecKeychainAttributeList { UInt32 count; SecKeychainAttribute *attr; };
For this parameter, IN / OUT attrList : The input is a list of attributes that you request to retrieve. At the output, the attributes are populated. Pass NULL if there is no need to retrieve any attributes or pass the list of attributes that you need to get. It must be one of the two passages mentioned in the arguments. Leaving it uninitialized can cause problems like segfault.
So, please try this way, this should work well.
SecKeychainAttributeList attrs = {0, NULL};
or
//SecKeychainAttributeList attrs ; //... check(SecKeychainItemCopyContent(item, &cls, NULL, &dataLen, &data)); printf("Key: %d\n", (int)dataLen); check(SecKeychainItemFreeContent(NULL, data));
If you need to get a list of attributes, the code example may be as follows:
SecKeychainAttributeList xlist; SecKeychainAttribute outList[] = { {kSecAddressItemAttr,}, {kSecAccountItemAttr,}, {kSecVolumeItemAttr,}, {kSecProtocolItemAttr} }; xlist.count = sizeof(outList)/sizeof(outList[0]); xlist.attr = outList;
source share