Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returns nil when just appeared from background #20

Open
k06a opened this issue Oct 16, 2014 · 35 comments
Open

Returns nil when just appeared from background #20

k06a opened this issue Oct 16, 2014 · 35 comments

Comments

@k06a
Copy link

k06a commented Oct 16, 2014

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.

@ChristopherCarranza
Copy link

I'm getting this same behavior.

@k06a
Copy link
Author

k06a commented Oct 30, 2014

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.

@ChristopherCarranza
Copy link

Could be, looks like its hitting line 153 and returning nil there. SecItemCopyMatching is not returning a success.

@elado
Copy link

elado commented Dec 27, 2014

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.)"

@rajohns08
Copy link

I'm also having an issue with returning nil when coming back to app

@k06a
Copy link
Author

k06a commented Jan 17, 2015

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;
}

@rajohns08
Copy link

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.

@briankracoff
Copy link

Getting the same bug here. Here's how I consistently reproduce it:

  1. Hit home button to put app into background
  2. Open up 6-10 other apps to make sure iOS puts it fully in the background
  3. Open app and quickly call stringForKey:error:. Receives error "Error getting keychain value: Security error has occurred."

@pandaxbacon
Copy link

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 👯

@aryaxt
Copy link

aryaxt commented Mar 12, 2015

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

@jayztemplier
Copy link

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.

@jayztemplier
Copy link

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.

@theprojectabot
Copy link

@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?

@jondal
Copy link

jondal commented Apr 10, 2015

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.

@ilya-ramanenia
Copy link

@jayztemplier same thing

@dannyjiajia
Copy link

anyone fix it?

@theprojectabot
Copy link

@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?

@dannyjiajia
Copy link

@theprojectabot Your solution unfortunately did not work for me.I cached the value as @k06a

@Mortenest
Copy link

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"?

@cristiankocza-sv
Copy link

@MortenFalcon happens to me too only while debugging, and not always.

@allenhsu
Copy link

+1 while debugging only

@jakedunc
Copy link

Why is this happening? Is there any fix?

@gconno
Copy link

gconno commented Jul 22, 2015

Same issue here, only occurs sometimes, but its annoying because I use it to manage the state of the app.

@gconno
Copy link

gconno commented Jul 24, 2015

+1 while debugging it appears. Doesnt affect the app on the store at the moment.

@zhouzhuhao
Copy link

Is anybody solve this problem ?

@zhouzhuhao
Copy link

OSStatus error: [-34018] Security error has occurred. this problem occurs sometimes,can anybody help me?

@k06a
Copy link
Author

k06a commented Aug 26, 2015

Just cache this value in property.

@shekbagg
Copy link

Any solution?

@Blahartinger
Copy link

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

@dinhnhat0401
Copy link

@Blahartinger thanks for your helpful links.

@luowenxing
Copy link

I came across the same issue too.

@RamblinWreck77
Copy link

4 years later and this issue is still occurring for me, exclusively when the app is woken up in the background due to a significant location change.

@greenzeal
Copy link

Still there :)

1 similar comment
@zhao0
Copy link

zhao0 commented May 5, 2019

Still there :)

@MaxHasADHD
Copy link

Seeing this as well. Anyone have a fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests