-
Notifications
You must be signed in to change notification settings - Fork 70
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
kotlin.IllegalStateException: Keychain error -25308: User interaction is not allowed. #171
Comments
Can you show how you're initializing The error suggests that you're trying to access a key that requires some form of interaction, which I think means it's something that requires a password input or face/fingerprint auth or the like. |
We are seeing similar issue occasionally, we don't do anything too special, just reading/writing a value into settings. Settings are initialized like so: |
This thread looks relevant, though not seeing any obvious explanation nor solution for this error: https://developer.apple.com/forums/thread/97091. |
Also looks similar to #144 (comment)? |
Interesting. Good to have confirmation you can get this error even with the default kSec args. To be clear, you're seeing the same 25308 error code? I suspect the similarity to #144 is a red herring. My sense of that issue is that there are cases when you pass certain access control flags that break the assumptions that KeychainSettings makes about status codes. If you're seeing that error without passing any non-default flags I think it's coming from a different cause. But I haven't dug deep enough into #144 to be certain, so maybe they are related. |
That's right, we are seeing the exact same error code |
I'm seeing this error in my app as well Other than this... the library is awesome! Thanks @russhwolf for the work you put into this. I suspect it happens when a user uninstalls the app then installs the app and that key may still be in keychain, but is maybe not accessible to this new app instance so it throws that exception. Just a hunch. Here's a stack trace from my app: |
This Apple Dev Forums thread was helpful for us: https://forums.developer.apple.com/forums/thread/114159. For our app, these errors seem to coincide with the user locking their device shortly before we attempt to fetch a Keychain item for which we specified |
Has anyone with these errors ever seen them in a dev build, or does it only for apps released through the store? I've done some testing but haven't been able to reproduce it when uninstalling/reinstalling through XCode. |
I have only been able to reproduce his when reading a Keychain item from an iOS widget that is on the active Home Screen page. An item written with |
I finally found the issue talking for my case. There was a kotlin flow still active with screen locked that try to read from KeyChain something. This caused the error described so making sure to not trying access keychain from lock screen, the issue seems to be not present anymore. Following @plindberg it could be potentially fixed adding the key (verify it)
|
I'm be able to reproduce it in the test application you provide, setting a value in KeyChain and then adding a delay of 30 seconds (10 or 20 isn't enough) before reading this. Meanwhile of this delay i lock the screen. Keychain access on lockI try to set the Block Keychain access on lockAnother solution is to put an observer on It would bee nice that those behaviours Is implemented in lib and customizable on the implementation Useful links: |
Hi @alessiotoma8
|
This is the code i try to add in my copy paste implementation of KeychainSettings
Please note that the previous value saved without this key is still not accessible with locked screen Alternately the second approach i mention
|
@russhwolf I have integrated this library into my app, and it’s functioning smoothly. However, there are numerous crashes occurring on iOS. Is there a reliable solution to address this issue? |
@alessiotoma8 I’m initializing KeychainSettings(service = "someString"). Is there a way to set kSecAttrAccessibleAfterFirstUnlock during initialization? |
I didn't find a way to do it, the only one think to do is to set kSecAttrAccessibleAfterFirstUnlock into the addKeychainItem as i shown and this have a limitation: that the previous value saved without this key is still not accessible with locked screen I hope to a new integrated solution to manage the customization of the 2 ways to access protected data. So who implement can decide if keychain should be available or not with locked screen and the libs manage the decision without throwing errors. PS: |
Thanks for valuable insights @alessiotoma8 👍 |
@alessiotoma8 Does it work for you if you initialize your settings as |
I try to do this and this seems to resolve the issue.
The first local test I do seems to work into the "multiplatform settings sample app". |
@alessiotoma8 @russhwolf Is this what you were referring to? Could you please confirm? |
Yes it's depends on your implementation That how @russhwolf say it can be If you are using the Settings Factory to create an instance instead, you need to do it as you shown, but it's more correct to specify the If you are copy pasting the implementation of KeychainSettings into yout projject you can directly do:
So you don't need to specify it also into Factory create function As i said before, I'm note sure that's working on 100%, I'll do some test and release an application version, checking to firebase if the crash is less or is disappeard. And i let known the result of this Please upvote |
@alessiotoma8 As you say, a solution here is to default to passing |
I tried to insert this thing in the real application and I got an unwanted behavior. The value that was previously saved without I tried everything again in the test application and it actually doesn't seem to work as I expect. Probably I didn't test thoroughly before and when I changed the initialization I didn't reset the values correctly. The most correct solution also from what I think I've read around would be to force the user to specify this key and insert it only in the Here's code snippest to test:
|
Alright, I'm clear at this point that there's some changes to make to An ideal API would set an explicit default for I'll likely come back to this ticket looking for people to help test once I have a prototype ready. |
We had the same problem in our project. We ended up passing |
@rs-georg This approach appears straightforward, but could you elaborate on how we can transition to a new instance at the implementation level? |
Hi @vinodiOS fun migrate() {
val oldStore = KeychainSettings(service = "myStore")
val newStore = KeychainSettings(
kSecAttrService to CFBridgingRetain("myStore"),
kSecAttrAccessible to kSecAttrAccessibleAfterFirstUnlock,
)
if (newStore.hasKey("_version")) return
val oldValue = oldStore.getStringOrNull("myKey")
oldStore.clear()
oldValue?.let { newStore.putString("myKey", it) }
newStore.putString("_version", "1")
} |
@rs-georg That’s helpful 😊 |
Just to inform and keep my promise about my future updates: |
We are seeing random users crashing with this error on app launch. Is there any additional info that I can provide that will help this thread to evolve and resolve the issue?
The text was updated successfully, but these errors were encountered: