--- a/Frameworks/AIUtilities Framework/Source/AIKeychain.m Mon Apr 30 19:34:32 2012 -0400
+++ b/Frameworks/AIUtilities Framework/Source/AIKeychain.m Mon Apr 30 23:02:50 2012 -0400
@@ -838,79 +838,63 @@
NSDictionary *result = nil;
// Search for keychain items whose server is our key
- SecKeychainSearchRef search = NULL;
- struct SecKeychainAttribute searchAttrs[] = {
- .tag = kSecServerItemAttr,
- .length = (UInt32)[server length],
- .data = (void *)[server UTF8String],
- .tag = kSecProtocolItemAttr,
- .length = sizeof(SecProtocolType),
- struct SecKeychainAttributeList searchAttrList = {
- // If keychainRef is NULL, the users's default keychain search list will be used
- OSStatus err = SecKeychainSearchCreateFromAttributes(keychainRef, kSecInternetPasswordItemClass, &searchAttrList, &search);
+ SecKeychainItemRef item = NULL; + UInt32 passwordLength = 0U; + void *passwordBytes = NULL;
- SecKeychainItemRef item = NULL;
- err = SecKeychainSearchCopyNext(search, &item);
+ // If keychainRef is NULL, the user's default keychain search list will be used + OSStatus err = SecKeychainFindInternetPassword(keychainRef, + (unsigned int)[server length], + kSecAuthenticationTypeAny, + if (err == errSecItemNotFound) { + // No matching server found + } else if (err == noErr) { + struct SecKeychainAttributeList *attrList = NULL; - if (err == errSecItemNotFound) {
- // No matching server found
- } else if (err == noErr) {
- struct SecKeychainAttributeList *attrList = NULL;
- UInt32 passwordLength = 0U;
- void *passwordBytes = NULL;
- // First, grab the username.
- UInt32 tags[] = { kSecAccountItemAttr };
- UInt32 formats[] = { CSSM_DB_ATTRIBUTE_FORMAT_STRING };
- struct SecKeychainAttributeInfo info = {
+ // First, grab the username. + UInt32 tags[] = { kSecAccountItemAttr }; + UInt32 formats[] = { CSSM_DB_ATTRIBUTE_FORMAT_STRING }; + struct SecKeychainAttributeInfo info = { + err = SecKeychainItemCopyAttributesAndData(item, + NSString *username = [NSString stringWithBytes:attrList->attr[0].data length:attrList->attr[0].length encoding:NSUTF8StringEncoding]; + NSString *password = [NSString stringWithBytes:passwordBytes length:passwordLength encoding:NSUTF8StringEncoding]; + result = [NSDictionary dictionaryWithObjectsAndKeys: - err = SecKeychainItemCopyAttributesAndData(item,
- NSString *username = [NSString stringWithBytes:attrList->attr[0].data length:attrList->attr[0].length encoding:NSUTF8StringEncoding];
- NSString *password = [NSString stringWithBytes:passwordBytes length:passwordLength encoding:NSUTF8StringEncoding];
- result = [NSDictionary dictionaryWithObjectsAndKeys:
- SecKeychainItemFreeAttributesAndData(attrList, passwordBytes);
- NSLog(@"Error extracting infomation from keychain item");
+ SecKeychainItemFreeAttributesAndData(attrList, passwordBytes); - NSLog(@"%@: Error in SecKeychainSearchCopyNext(); err is %ld", self, (long)err);
+ NSLog(@"Error extracting infomation from keychain item");
NSLog(@"%@: Could not create search; err is %ld", self, (long)err);