You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Don't think this is an FXKeyChain issue but for info - updating a key fails with a -25300 error (errSecItemNotFound).
Sample code (as per radar which is a cut down version of FXKeyChain attached below)
/// ---------------------------------------------------------//// ViewController.m// KeychainBugSample//// Created by Andy Qua on 12/02/2014.// Copyright (c) 2014 Andy Qua. All rights reserved.//
#import"ViewController.h"/******* * Sample demonstrating a bug with updating a value stored in the KeyChain. * When running on Simulator this fails with a -25300 error (errSecItemNotFound) * But works fine when running on device * * Note this is simplified keychain code and assumes that you will be saving and retrieving an NSString value *******/@interfaceViewController ()
{
NSString *service;
}
@end@implementationViewController
- (void)viewDidLoad
{
[superviewDidLoad];
service = @"test";
NSString *key = @"MyKey";
NSString *text;
// Key shouldn't exist
text = [selfstringForKey:key];
NSLog( @"Before add - value stored - [%@]", text );
// Set value
[selfaddString:@"Test"forKey:key];
// Make sure that value has been set correctly
text = [selfstringForKey:key];
NSLog( @"After initial add - value stored - [%@]", text );
// Now Update the value - This will log error -25300 (keyNotFound)
[selfupdateString:@"This has changed"forKey:key];
// Make sure that value has been set correctly
text = [selfstringForKey:key];
NSLog( @"After update value - [%@]", text );
// Clear outs data from keychain for next run
[selfdeleteDataForKey:key];
text = [selfstringForKey:key];
NSLog( @"After delete value - [%@]", text );
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSString *)stringForKey:(id)key
{
//generate queryNSMutableDictionary *query = [NSMutableDictionarydictionary];
if ([service length]) query[(__bridge NSString *)kSecAttrService] = service;
query[(__bridge NSString *)kSecClass] = (__bridge id)kSecClassGenericPassword;
query[(__bridge NSString *)kSecMatchLimit] = (__bridge id)kSecMatchLimitOne;
query[(__bridge NSString *)kSecReturnData] = (__bridge id)kCFBooleanTrue;
query[(__bridge NSString *)kSecAttrAccount] = [key description];
//recover dataCFDataRef data = NULL;
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query, (CFTypeRef *)&data);
if (status != errSecSuccess && status != errSecItemNotFound)
{
NSLog(@"Failed to retrieve data for key '%@', error: %ld", key, (long)status);
}
NSData *dataObj = CFBridgingRelease(data);
NSString *text = [[NSStringalloc] initWithData:dataObj encoding:NSUTF8StringEncoding];
return text;
}
- (BOOL) addString:(NSString *)stringforKey:(NSString *)key
{
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
NSMutableDictionary *query = [NSMutableDictionarydictionary];
if ([service length]) query[(__bridge NSString *)kSecAttrService] = service;
query[(__bridge NSString *)kSecClass] = (__bridge id)kSecClassGenericPassword;
query[(__bridge NSString *)kSecAttrAccount] = [key description];
query[(__bridge NSString *)kSecValueData] = data;
OSStatus status = SecItemAdd ((__bridge CFDictionaryRef)query, NULL);
if (status != errSecSuccess)
{
NSLog(@"Failed to add data for key '%@', error: %ld", key, (long)status);
returnNO;
}
returnYES;
}
- (BOOL) updateString:(NSString *)stringforKey:(NSString *)key
{
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
NSMutableDictionary *query = [NSMutableDictionarydictionary];
if ([service length]) query[(__bridge NSString *)kSecAttrService] = service;
query[(__bridge NSString *)kSecClass] = (__bridge id)kSecClassGenericPassword;
query[(__bridge NSString *)kSecAttrAccount] = [key description];
NSMutableDictionary *update = [@{(__bridge NSString *)kSecValueData: data} mutableCopy];
OSStatus status = SecItemUpdate((__bridge CFDictionaryRef)query, (__bridge CFDictionaryRef)update);
if (status != errSecSuccess)
{
NSLog(@"Failed to update data for key '%@', error: %ld", key, (long)status);
returnNO;
}
returnYES;
}
- (BOOL)deleteDataForKey:(id)key
{
//generate queryNSMutableDictionary *query = [NSMutableDictionarydictionary];
if ([service length]) query[(__bridge NSString *)kSecAttrService] = service;
query[(__bridge NSString *)kSecClass] = (__bridge id)kSecClassGenericPassword;
query[(__bridge NSString *)kSecAttrAccount] = [key description];
//delete existing dataOSStatus status = SecItemDelete((__bridge CFDictionaryRef)query);
if (status != errSecSuccess)
{
NSLog(@"Failed to delete data for key '%@', error: %ld", key, (long)status);
returnNO;
}
returnYES;
}
@end/// ---------------------------------------------------------
The text was updated successfully, but these errors were encountered:
Bug was closed as a dupe but the issue had not been fixed in 7.1 - although haven't yet tested with latest version as worked around the issue for the moment.
Don't think this is an FXKeyChain issue but for info - updating a key fails with a -25300 error (errSecItemNotFound).
Sample code (as per radar which is a cut down version of FXKeyChain attached below)
The text was updated successfully, but these errors were encountered: