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
Application has issues with line 537 let status = SecItemCopyMatching(query as CFDictionary, &result) #373
Comments
@dkalinai I cannot understand what you mean and what problem occurs. Can you explain more for me? |
I have a breakpoint on all exceptions and my app doesnt have any, but seems like when the app is initialized or started the KeychainAccess encounters a problem. Image attached. I dont quite know how to get you more details on this. I can explain only that i am trying to get two keys from keychain when app starts. |
@dkalinai Can you share a reproducible sample project? |
Sorry for the big delay. https://www.dropbox.com/s/spr7i5zrp2glufg/KeychainBug.zip?dl=0 I believe the issue is that i need to save multiple items at once or fetch multiple items at once and it just doesnt like that. |
@dkalinai Thank you for the sample project. You are misunderstanding how to set a value to the keychain. do {
try AuthService.shared.keychain.set(AuthService.shared.kWoocommerceConsumerSecret,
key: "cs_stufff078340t74589769")
sleep(2)
try AuthService.shared.keychain.set(AuthService.shared.kWoocommerceConsumerKey, key: "ck_consumerKey134353453") ^ You attempt to set the value As result, That's why you cannot retrieve the value with |
Sorry, this was a typo on my behalf, since i was typing this code by hand in reality in my app it looks like this for saving: do { |
So coude for sample project should be: do {
but even that doesnt save normally. IS there a way to pass array as value and key and save that in bulk? Maybe i am doign it wrong for several items at once? |
@dkalinai OK, I swap the key and the value, then both values are saved correctly. Can you make sure again following steps?
You probably can see the saved values like the following, |
THe values will be saved, there is no issues with that. The issue i am having is that if i set a breakpoint for all exceptions it hits saving, or in my case on launch of the app loading keychain data. So thats what i need to understand, why does an exception break point hit the code. I keep exception breakpoints usually on, to debug issues right away. Can you see any eay i can keep them on and not hit the keychainaccess code please? |
That is an expected behavior. The exception thrown The SecItemAdd function seems to use exceptions to control the logic (of course it is a bad practice though). You can see a same behavior more simple case without my library, like the following (from Apple's documents https://developer.apple.com/documentation/security/keychain_services/keychain_items/adding_a_password_to_the_keychain) let account = "username"
let password = "password".data(using: .utf8)!
let query: [String: Any] = [kSecClass as String: kSecClassInternetPassword,
kSecAttrAccount as String: account,
kSecAttrService as String: "com.kishikawakatsumi.KeychainTest",
kSecValueData as String: password]
let status = SecItemAdd(query as CFDictionary, nil)
print(status) |
Hi again, I see what you mean. Well that's quite annoying that Apple let this thing through then :S So sorry that I originally thought it was your framework, I did actually try another one yesterday and it had the same problem supporting your idea. I am just wondering if maybe there is a workaround like make the calls not one after another when fetching or saving items via some function that takes a dictionary as parameter? Anyways thank you for taking the time to look into this, seems like nothing can be done here... just tad annoying that when you want to debug something on startup you have to go over the Keychain 6-7 breakpoints for 2 fetches... Thanks again for the info. |
Good, thank you for reporting! |
Each time my application opens which has a breakpoint for any errors this line stops execution for some reason:
Any ideas what may be going wrong?
The text was updated successfully, but these errors were encountered: