UICKeyChainStore
UICKeyChainStore copied to clipboard
Returns nil when just appeared from background
This code sometimes returns nil when my app is just appeared from background:
[UICKeyChainStore dataForKey:self.privateKeyTag]
When I restart app - it returns non-nil value.
I'm getting this same behavior.
I think this may happens because of iPhone locking. It always auto-locks because of touch-ID enabled. So some keychain items can be unavailable IMHO.
Could be, looks like its hitting line 153 and returning nil there. SecItemCopyMatching is not returning a success.
Same error here. Log:
Communications error: <OS_xpc_error: <error: 0x19c8a3a80> { count = 1, contents =
"XPCErrorDescription" => <string: 0x19c8a3e78> { length = 22, contents = "Connection interrupted" }
}>
Error Domain=com.kishikawakatsumi.uickeychainstore Code=-34018 "The operation couldn’t be completed. (com.kishikawakatsumi.uickeychainstore error -34018.)"
I'm also having an issue with returning nil when coming back to app
I've solved problem by caching keychain data in property.
@property (nonatomic, strong) NSData *privateKey;
...
- (NSData *)privateKey {
if (_privateKey == nil)
_privateKey = [UICKeychainStore dataForKey:@"mykeytag"];
return _privateKey;
}
What's weird is, I saw this issue twice within 30 minutes of loading an app with UICKeyChainStore for the first time. The following 24 hours I never could reproduce it a single time.
Getting the same bug here. Here's how I consistently reproduce it:
- Hit home button to put app into background
- Open up 6-10 other apps to make sure iOS puts it fully in the background
- Open app and quickly call
stringForKey:error:. Receives error "Error getting keychain value: Security error has occurred."
please take a look to the UICKeychain documentation. and search for keywords "Configuration (Accessibility, Sharing, iCould Sync)"
you need to call the [keyChain setAccessibility: ....... ] function. Cheers :dancers:
Same here randomly returning nil with warning "OSStatus error: [-34018] Security error has occurred"
For me this wasn't due to application going to background/foreground, it just happens randomly Setting accessibility to UICKeyChainStoreAccessibilityWhenUnlocked, and setting a specific service did not fix the issue either
Having the same issue here, the application goes back from background, and I have the "Security error has occurred" both when trying to set and get a value from the keychain.
Alright so I made it work on my device. All it took was to set nil to the accessGroup, and rely on the fact that it takes the first group in the entitlement as default group.
I don't know if it's a bug within iOS or a signing issue.
@jayztemplier how did you set the accessGroup to nil? I am getting the same issue and curretnly it is a read only property. Did you mod the source?
I can consistently reproduce this too, doing what @briankracoff described. @jayztemplier 's solution unfortunately did not work for me. Version 1 was working fine. Will investegate.
@jayztemplier same thing
anyone fix it?
@dannyjiajia I just tried this because I had a thought last night:
in - (void)applicationDidBecomeActive:(UIApplication *)application { [UICKeyChainStore keyChainStoreWithService:NAME_OF_YOUR_SERVICE accessGroup:nil];
}
It seemed to have worked!
Try it out?
@theprojectabot Your solution unfortunately did not work for me.I cached the value as @k06a
I am also experiencing this problem already in :
-(void)applicationWillEnterForeground:(UIApplication *)application { UICKeyChainStore *keyChainStore = [UICKeyChainStore keyChainStoreWithService:SERVICE accessGroup:nil];
}
I am also getting the error: OSStatus error: [-34018] Security error has occurred. However, it looks like it only happens when I am debugging the build. Haven't seen it else - Anyone who can "confirm"?
@MortenFalcon happens to me too only while debugging, and not always.
+1 while debugging only
Why is this happening? Is there any fix?
Same issue here, only occurs sometimes, but its annoying because I use it to manage the state of the app.
+1 while debugging it appears. Doesnt affect the app on the store at the moment.
Is anybody solve this problem ?
OSStatus error: [-34018] Security error has occurred. this problem occurs sometimes,can anybody help me?
Just cache this value in property.
Any solution?
This is a known apple bug in the keychain that has yet to be fixed https://forums.developer.apple.com/thread/4743
Facebook and others that depend on app switching for oauth are notably affected. https://m.facebook.com/login.php?next=https%3A%2F%2Fdevelopers.facebook.com%2Fbugs%2F136880803313865&refsrc=https%3A%2F%2Fwww.facebook.com%2Flogin.php&_rdr
@Blahartinger thanks for your helpful links.