|
|
@@ -209,10 +209,10 @@ static NSString *SFHFKeychainUtilsErrorDomain = @"SFHFKeychainUtilsErrorDomain";
|
|
|
|
|
|
// Set up a query dictionary with the base query attributes: item type (generic), username, and service
|
|
|
|
|
|
- NSArray *keys = [[[NSArray alloc] initWithObjects: (NSString *) kSecClass, kSecAttrAccount, kSecAttrService, nil] autorelease];
|
|
|
- NSArray *objects = [[[NSArray alloc] initWithObjects: (NSString *) kSecClassGenericPassword, username, serviceName, nil] autorelease];
|
|
|
+ NSArray *keys = [[NSArray alloc] initWithObjects: (__bridge NSString *) kSecClass, kSecAttrAccount, kSecAttrService, nil];
|
|
|
+ NSArray *objects = [[NSArray alloc] initWithObjects: (__bridge NSString *) kSecClassGenericPassword, username, serviceName, nil];
|
|
|
|
|
|
- NSMutableDictionary *query = [[[NSMutableDictionary alloc] initWithObjects: objects forKeys: keys] autorelease];
|
|
|
+ NSMutableDictionary *query = [[NSMutableDictionary alloc] initWithObjects: objects forKeys: keys];
|
|
|
|
|
|
// First do a query for attributes, in case we already have a Keychain item with no password data set.
|
|
|
// One likely way such an incorrect item could have come about is due to the previous (incorrect)
|
|
|
@@ -220,11 +220,9 @@ static NSString *SFHFKeychainUtilsErrorDomain = @"SFHFKeychainUtilsErrorDomain";
|
|
|
|
|
|
NSDictionary *attributeResult = NULL;
|
|
|
NSMutableDictionary *attributeQuery = [query mutableCopy];
|
|
|
- [attributeQuery setObject: (id) kCFBooleanTrue forKey:(id) kSecReturnAttributes];
|
|
|
- OSStatus status = SecItemCopyMatching((CFDictionaryRef) attributeQuery, (CFTypeRef *) &attributeResult);
|
|
|
+ [attributeQuery setObject: (id) kCFBooleanTrue forKey:(__bridge id) kSecReturnAttributes];
|
|
|
+ OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef) attributeQuery, (void*) &attributeResult);
|
|
|
|
|
|
- [attributeResult release];
|
|
|
- [attributeQuery release];
|
|
|
|
|
|
if (status != noErr) {
|
|
|
// No existing item found--simply return nil for the password
|
|
|
@@ -240,12 +238,10 @@ static NSString *SFHFKeychainUtilsErrorDomain = @"SFHFKeychainUtilsErrorDomain";
|
|
|
|
|
|
NSData *resultData = nil;
|
|
|
NSMutableDictionary *passwordQuery = [query mutableCopy];
|
|
|
- [passwordQuery setObject: (id) kCFBooleanTrue forKey: (id) kSecReturnData];
|
|
|
+ [passwordQuery setObject: (id) kCFBooleanTrue forKey: (__bridge id) kSecReturnData];
|
|
|
|
|
|
- status = SecItemCopyMatching((CFDictionaryRef) passwordQuery, (CFTypeRef *) &resultData);
|
|
|
+ status = SecItemCopyMatching((__bridge CFDictionaryRef) passwordQuery, (void*) &resultData);
|
|
|
|
|
|
- [resultData autorelease];
|
|
|
- [passwordQuery release];
|
|
|
|
|
|
if (status != noErr) {
|
|
|
if (status == errSecItemNotFound) {
|
|
|
@@ -283,7 +279,7 @@ static NSString *SFHFKeychainUtilsErrorDomain = @"SFHFKeychainUtilsErrorDomain";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return [password autorelease];
|
|
|
+ return password;
|
|
|
}
|
|
|
|
|
|
+ (BOOL) storeUsername: (NSString *) username andPassword: (NSString *) password forServiceName: (NSString *) serviceName updateExisting: (BOOL) updateExisting error: (NSError **) error
|
|
|
@@ -344,21 +340,21 @@ static NSString *SFHFKeychainUtilsErrorDomain = @"SFHFKeychainUtilsErrorDomain";
|
|
|
{
|
|
|
//Only update if we're allowed to update existing. If not, simply do nothing.
|
|
|
|
|
|
- NSArray *keys = [[[NSArray alloc] initWithObjects: (NSString *) kSecClass,
|
|
|
+ NSArray *keys = [[NSArray alloc] initWithObjects: (__bridge NSString *) kSecClass,
|
|
|
kSecAttrService,
|
|
|
kSecAttrLabel,
|
|
|
kSecAttrAccount,
|
|
|
- nil] autorelease];
|
|
|
+ nil];
|
|
|
|
|
|
- NSArray *objects = [[[NSArray alloc] initWithObjects: (NSString *) kSecClassGenericPassword,
|
|
|
+ NSArray *objects = [[NSArray alloc] initWithObjects: (__bridge NSString *) kSecClassGenericPassword,
|
|
|
serviceName,
|
|
|
serviceName,
|
|
|
username,
|
|
|
- nil] autorelease];
|
|
|
+ nil];
|
|
|
|
|
|
- NSDictionary *query = [[[NSDictionary alloc] initWithObjects: objects forKeys: keys] autorelease];
|
|
|
+ NSDictionary *query = [[NSDictionary alloc] initWithObjects: objects forKeys: keys];
|
|
|
|
|
|
- status = SecItemUpdate((CFDictionaryRef) query, (CFDictionaryRef) [NSDictionary dictionaryWithObject: [password dataUsingEncoding: NSUTF8StringEncoding] forKey: (NSString *) kSecValueData]);
|
|
|
+ status = SecItemUpdate((__bridge CFDictionaryRef) query, (__bridge CFDictionaryRef) [NSDictionary dictionaryWithObject: [password dataUsingEncoding: NSUTF8StringEncoding] forKey: (__bridge NSString *) kSecValueData]);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
@@ -366,23 +362,23 @@ static NSString *SFHFKeychainUtilsErrorDomain = @"SFHFKeychainUtilsErrorDomain";
|
|
|
// No existing entry (or an existing, improperly entered, and therefore now
|
|
|
// deleted, entry). Create a new entry.
|
|
|
|
|
|
- NSArray *keys = [[[NSArray alloc] initWithObjects: (NSString *) kSecClass,
|
|
|
+ NSArray *keys = [[NSArray alloc] initWithObjects: (__bridge NSString *) kSecClass,
|
|
|
kSecAttrService,
|
|
|
kSecAttrLabel,
|
|
|
kSecAttrAccount,
|
|
|
kSecValueData,
|
|
|
- nil] autorelease];
|
|
|
+ nil];
|
|
|
|
|
|
- NSArray *objects = [[[NSArray alloc] initWithObjects: (NSString *) kSecClassGenericPassword,
|
|
|
+ NSArray *objects = [[NSArray alloc] initWithObjects: (__bridge NSString *) kSecClassGenericPassword,
|
|
|
serviceName,
|
|
|
serviceName,
|
|
|
username,
|
|
|
[password dataUsingEncoding: NSUTF8StringEncoding],
|
|
|
- nil] autorelease];
|
|
|
+ nil];
|
|
|
|
|
|
- NSDictionary *query = [[[NSDictionary alloc] initWithObjects: objects forKeys: keys] autorelease];
|
|
|
+ NSDictionary *query = [[NSDictionary alloc] initWithObjects: objects forKeys: keys];
|
|
|
|
|
|
- status = SecItemAdd((CFDictionaryRef) query, NULL);
|
|
|
+ status = SecItemAdd((__bridge CFDictionaryRef) query, NULL);
|
|
|
}
|
|
|
|
|
|
if (status != noErr)
|
|
|
@@ -414,12 +410,12 @@ static NSString *SFHFKeychainUtilsErrorDomain = @"SFHFKeychainUtilsErrorDomain";
|
|
|
*error = nil;
|
|
|
}
|
|
|
|
|
|
- NSArray *keys = [[[NSArray alloc] initWithObjects: (NSString *) kSecClass, kSecAttrAccount, kSecAttrService, kSecReturnAttributes, nil] autorelease];
|
|
|
- NSArray *objects = [[[NSArray alloc] initWithObjects: (NSString *) kSecClassGenericPassword, username, serviceName, kCFBooleanTrue, nil] autorelease];
|
|
|
+ NSArray *keys = [[NSArray alloc] initWithObjects: (__bridge NSString *) kSecClass, kSecAttrAccount, kSecAttrService, kSecReturnAttributes, nil];
|
|
|
+ NSArray *objects = [[NSArray alloc] initWithObjects: (__bridge NSString *) kSecClassGenericPassword, username, serviceName, kCFBooleanTrue, nil];
|
|
|
|
|
|
- NSDictionary *query = [[[NSDictionary alloc] initWithObjects: objects forKeys: keys] autorelease];
|
|
|
+ NSDictionary *query = [[NSDictionary alloc] initWithObjects: objects forKeys: keys];
|
|
|
|
|
|
- OSStatus status = SecItemDelete((CFDictionaryRef) query);
|
|
|
+ OSStatus status = SecItemDelete((__bridge CFDictionaryRef) query);
|
|
|
|
|
|
if (status != noErr)
|
|
|
{
|