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

Keychain retain a nil after long time in background #15

Open
GuyKahlon opened this issue Jan 10, 2016 · 14 comments
Open

Keychain retain a nil after long time in background #15

GuyKahlon opened this issue Jan 10, 2016 · 14 comments

Comments

@GuyKahlon
Copy link

Hi,

I have a serious inconsistent problem when the app long time in the background.

In my app I save the user finger print in the keychain, when the app launch (at didFinishLaunchingWithOptions funk) I check if the is a finger print saved in the keychain, if there isn't finger print saved in the keychain I replace my Main story board with the Register storyboard.

Note: I also save a flag in the NSUserDefault to check if this is a first launch in order to reset (clear all the data) the keychain if it's a first launch.

The problem is, after a long time in the background (sometimes not all the time) when I open the app the Register Storyboard appear. Means the app terminates by the OS in the background and there isn't finger print in the keychain.
In the beginning I thought the finger print was removed from the keychain, but, if I terminate mentally the app and open it again, everything is good and the main story board appears as expected.

Note:
The fingerprint is a String and I saved it in the keychain without any Access key.

Any idea?

Thanks

@evgenyneu
Copy link
Owner

evgenyneu commented Jan 10, 2016 via email

@GuyKahlon
Copy link
Author

Thanks :)

@rashidasgari
Copy link

@GuyKahlon I am facing the exactly same thing with UICKeyChainStore library.

@jlgaustin
Copy link

Anybody find a fix for this? I am having identical issue.

@mzaks
Copy link

mzaks commented May 30, 2017

Hi there,

AFAIK the problem is it takes time to decrypt the key chain. If you have your AccessOption set to accessibleWhenUnlocked and try to read in app delegate didFinishLaunchingWithOptions than it could happen that you get nil as the data is not decrypted.
Solution would be to either switch to less restrictive AccessOption, or to access the values in the keychain a bit later. Giving the key chain time to decrypt.
This is what helped me at least.

@RamblinWreck77
Copy link

I can confirm this occurs no matter what the access level is. We have 1.5-2mil background wakeup events a day. Of those, ~5% of users who do have a user fingerprint stored in their keychain will get a nil value.

@evgenyneu
Copy link
Owner

@RamblinWreck77, that's good to know. We can discuss your background access problems in #78.

@AndreaMiotto
Copy link

Hi, I'm facing this problem, after many hours of inactivity, when I open the application, my manager fails to retrieve the refreshToekn from the keychain and the user is redirected at the login page.

Any tip?

@mzaks
Copy link

mzaks commented Nov 21, 2018

Hi, I'm facing this problem, after many hours of inactivity, when I open the application, my manager fails to retrieve the refreshToekn from the keychain and the user is redirected at the login page.

Any tip?

Is your manager called from AppDelegate?
You need to delay the call some how, AFAIK it's all about timing, the keychain needs time to be decrypted, if it is not yet decrypted it will return nil. So my tip is: either delay the whole thing, or implement a retry, if values are nil for a couple of times.

@AndreaMiotto
Copy link

Nop, not always is called from the appDelegate. And this is very hard to debug so I think I will move to realm encrypted

@evgenyneu
Copy link
Owner

Possible unconfirmed workaround is here.

@app4g
Copy link

app4g commented Dec 9, 2023

I am also having issues now. It's really intermittent and I can't reproduce it. Some users have the issues, some don't.
What I see is that somehow I think it's related to the app being in the background and then an update (to keychain) occurs.

I am gonna add extra logging to see if I can manage to capture where it's happening. I've also streamlined the saving of the keychain so that I don't have multiple calls to it in succession.

with regard to the possible solution - #78 (comment)

This seems to only to do when a notification is received right? My App is basically updating some in-game-currency to the keychain every 60s and doesn't receive any notifications

@sincychacko-frollo
Copy link

@app4g Facing the same issue. Do you have any findings to share from the additional logging?

@app4g
Copy link

app4g commented Mar 26, 2024

@sincychacko-frollo What I essentially did was to make sure only 1 instance of command to update the keychain is done at any one time and some caching of the data into memory.

After multiple iterations, I think It's resolved.

sorry.I can't offer any help beyond that.

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

9 participants