-
Notifications
You must be signed in to change notification settings - Fork 25
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
[BITAU-191] Handle KeychainServiceError When Sync Has Been Turned Off on All Accounts #1094
[BITAU-191] Handle KeychainServiceError When Sync Has Been Turned Off on All Accounts #1094
Conversation
05b561d
to
8e2dd98
Compare
dataItems.compactMap(\.model) | ||
} | ||
.asyncTryMap { itemModel in | ||
try await self.cryptoService.decryptAuthenticatorItems(itemModel) | ||
guard let items = try? await self.cryptoService.decryptAuthenticatorItems(itemModel) else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, thinking about this some more. Will this trap other exceptions that the Authenticator app expects to catch and display an error? Should you only catch the keychain error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we keep going with this approach, then I agree with Victor that this should only catch KeychainServiceError
and, if possible, the specific error for this situation so it doesn't hide any other potential bugs; which in this case I imagine is KeychainServiceError.keyNotFound
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just ran into this bug while working on an Authenticator PR that clarified the reason we're still seeing this when turning off sync:
- The publisher is asking for the list to be decrypted even when there are no items - i.e. it sends
[]
to be decrypted. - The crypto service is looking for the key first thing, which throws the error. But in the case of an empty list, it never needed the key to decrypt.
So when a user turns off sync (or launches the first time with the feature flag enabled) we should not have any items to be decrypted. But because it's looking for the key, it will still fail here.
I'm going to re-work this PR to address the issue in the cypto service, and leave this error handling in place. 👍
🤔 @brant-livefront If I'm understanding correctly by doing this: turning off Sync in the PM app will "hide" all shared items from the Authenticator app, right? |
Yes, this is the intended behavior. In fact, we not only hide but delete all the items from the shared store. Toggling sync to off means saying "Don't allow syncing" - i.e. get rid of synced items. If we left the Authenticator items in place, there'd be no way for a user to change their mind and remove the items from sync. |
… should fix the main error while leaving all other error handling intact
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
…when-sync-has-been-turned-off-on-all-accounts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 Although if we find a KeychainServiceError
again in Crashlytics, will it be easy to spot this is the place it was originated from?
I'm approving and I'll leave it up to you to whether a more particular error should be thrown here in case the authenticator key is nil
or that's highly unlikely to happen thus it can stay as is 😄
I think it's highly unlikely because we delete the key when we delete all the shared items. So either you have the key because you have items, or you don't have the key and this fix will return immediately without throwing. However, I did think about actually removing the |
IMO we either bubble up the error or log the error there and return |
…when-sync-has-been-turned-off-on-all-accounts
@fedemkr I agree with that. Now that we've dealt with the likely problem, the other cases are truly exceptional. So it makes sense to bubble them up. 👍 |
🎟️ Tracking
BITAU-191
📔 Objective
Luke found an issue in testing that was causing the Authenticator app to fail:
The issue is that when the Authenticator app refreshes the data, the decryption key has been deleted. This causes the keychain to throw
KeychainServiceError
because the key doesn't exist. However, this is an expected condition because we delete the keys when turning off syncing.The fix in this PR is to catch any error occurring in the decryption process and simply return
[]
. This allows the Authenticator app to continue without any synced values, rather than falling into an error state.⏰ Reminders before review
🦮 Reviewer guidelines
:+1:
) or similar for great changes:memo:
) or ℹ️ (:information_source:
) for notes or general info:question:
) for questions:thinking:
) or 💭 (:thought_balloon:
) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion:art:
) for suggestions / improvements:x:
) or:warning:
) for more significant problems or concerns needing attention:seedling:
) or ♻️ (:recycle:
) for future improvements or indications of technical debt:pick:
) for minor or nitpick changes