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

fix: BAD_DECRYPT Exception on invalid cipher #1730

Merged
merged 7 commits into from
May 4, 2022
Merged

Conversation

@M123-dev M123-dev requested a review from monsieurtanuki May 2, 2022 10:20
@M123-dev M123-dev requested a review from a team as a code owner May 2, 2022 10:20
@codecov-commenter
Copy link

codecov-commenter commented May 2, 2022

Codecov Report

Merging #1730 (1a27153) into develop (2ea0da3) will decrease coverage by 0.59%.
The diff coverage is 0.64%.

@@            Coverage Diff             @@
##           develop   #1730      +/-   ##
==========================================
- Coverage     8.86%   8.26%   -0.60%     
==========================================
  Files          161     165       +4     
  Lines         6623    7148     +525     
==========================================
+ Hits           587     591       +4     
- Misses        6036    6557     +521     
Impacted Files Coverage Δ
...h_app/lib/cards/category_cards/abstract_cache.dart 0.00% <0.00%> (ø)
...p/lib/cards/category_cards/asset_cache_helper.dart 0.00% <0.00%> (ø)
...p/lib/cards/category_cards/raster_async_asset.dart 0.00% <0.00%> (ø)
...oth_app/lib/cards/category_cards/raster_cache.dart 0.00% <0.00%> (ø)
..._app/lib/cards/category_cards/svg_async_asset.dart 0.00% <0.00%> (ø)
...smooth_app/lib/cards/category_cards/svg_cache.dart 0.00% <0.00%> (ø)
...t_cards/knowledge_panels/knowledge_panel_card.dart 0.00% <0.00%> (ø)
...t_cards/knowledge_panels/knowledge_panel_page.dart 0.00% <0.00%> (ø)
...knowledge_panels/knowledge_panel_summary_card.dart 0.00% <ø> (ø)
...s/knowledge_panels/knowledge_panel_table_card.dart 0.00% <0.00%> (ø)
... and 54 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 19e3560...1a27153. Read the comment docs.

try {
userId = await DaoSecuredString.get(_USER_ID);
password = await DaoSecuredString.get(_PASSWORD);
} on PlatformException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment here on the kind of exception it was (SSL related, possibly on old devices ?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment

Copy link
Contributor

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @M123-dev!
I think it's not fair to just bypass the exception. What are we supposed to do with "less fortunate" users? Shouldn't we store the user/password in DaoString instead, as a fallback? Shouldn't we have detected that issue previously when the user stored the user/password: it probably didn't work either at that moment.
Any idea of the root cause of this crash? (there's no "issue" by the way).

@M123-dev
Copy link
Member Author

M123-dev commented May 3, 2022

Heyyy @monsieurtanuki, the API used in the secure storage package was introduced in android 4.3 (Now around 10 years old), I think we have a lot more other problems on these version. The error occured to me when I had the app installed via the PlayStore and then installed it via USB Debugging from my PC (for running in debug mode). After that it fails what's good in terms of security. But if we know that such a case meight happen we don't need to throw a exeption but just handle it. But because it's a security and not feature related bug there is no way of knowing it in advance.

#1121 #1311

Copy link
Contributor

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @M123-dev!

I didn't know what you mentioned was possible; when I develop in Android/java the app refuses to install a debug apk on a release apk and so on. That doesn't work that way with flutter, fair enough.

The general idea is good: in those strange cases just display "you have been logged out", remove the credentials and that's it.

The timing is not good though: adding a Scaffold (for the Snackbar) is not a good solution, as we've already experienced bugs because of embedded Scaffolds. Please call the Snackbar somewhere else.

packages/smooth_app/lib/main.dart Outdated Show resolved Hide resolved
Copy link
Contributor

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@M123-dev Not convinced either by your latest change. That's tricky...
Let's say that only naughty boys like you may experience that "logged out" exception: what about just printing a log? And moving the code back to main.dart?

@github-actions github-actions bot removed the 🌐 l10n label May 3, 2022
@M123-dev
Copy link
Member Author

M123-dev commented May 3, 2022

Sure @monsieurtanuki

@@ -227,6 +227,8 @@ class SmoothAppGetLanguage extends StatelessWidget {
final LocalDatabase _localDatabase = context.read<LocalDatabase>();
AnalyticsHelper.trackStart(_localDatabase, context);

context.read<UserManagementProvider>().mountCredentials();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not await? Btw as it's in the init part and we do that only once, do we have to notify the listeners in mountCredentials? I don't think so, as it's dangerous to notify while building a Widget.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no await intended, since the credentials are not needed directly after start, this can run when there is time for that. Because of that that little more efford with the provider

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not convinced. All we do in mountCredentials is get the credentials from the dao and put them in static. Quick and easy.
OK, technically you are allowed not to wait until it finishes and use the provider for the refresh, but:

  • hey, it's init time, let's init once and for all
  • the notifylistener will trigger a display refresh just because you didn't want to spend 20 milliseconds awaiting
  • not everything we do is strictly needed at init time - we also set the query country, which is useless as we haven't queried anything yet
  • btw mountCredentials could be called much earlier, in _init1 or _init2

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just applied your suggestions, my first approach was to completely remove the provider, but looking into it again we should keep it to properly reflect logins from for example the login card.

@teolemon teolemon added this to the V1 milestone May 4, 2022
@github-actions github-actions bot added the 👥 User management Account login, signup, signout label May 4, 2022
Co-authored-by: monsieurtanuki <fabrice_fontaine@hotmail.com>
@M123-dev M123-dev merged commit 955895d into develop May 4, 2022
@M123-dev M123-dev deleted the fix-BAD_DECRYPT-error branch May 4, 2022 13:38
@M123-dev
Copy link
Member Author

M123-dev commented May 5, 2022

@monsieurtanuki just saw the stats on Sentry, looks like I'm really the only one with the problem 😆

grafik

@teolemon teolemon added the SSL label Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
security SSL 👥 User management Account login, signup, signout
4 participants