maui icon indicating copy to clipboard operation
maui copied to clipboard

Catch InvalidProtocolBufferException creating EncryptedSharedPreferences

Open Cheesebaron opened this issue 1 year ago • 12 comments

Description of Change

Creating EncryptedSharedPreferences on some devices throw InvalidProtocolBufferException.

This PR catches this exception instead of throwing it to the consumer.

Issues Fixed

Fixes #13597

Cheesebaron avatar Feb 28 '23 13:02 Cheesebaron

Hey there @Cheesebaron! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

ghost avatar Feb 28 '23 13:02 ghost

/azp run

rmarinho avatar Feb 28 '23 14:02 rmarinho

Azure Pipelines successfully started running 2 pipeline(s).

azure-pipelines[bot] avatar Feb 28 '23 14:02 azure-pipelines[bot]

Not 100% sure, but perhaps we should remove all keys if this occurs.

Cheesebaron avatar Feb 28 '23 15:02 Cheesebaron

Not 100% sure, but perhaps we should remove all keys if this occurs.

What is the situation here? When does this occur? Is there any recovery scenario? If not, I'd say indeed wipe it.

jfversluis avatar Feb 28 '23 15:02 jfversluis

Not 100% sure, but perhaps we should remove all keys if this occurs.

What is the situation here? When does this occur? Is there any recovery scenario? If not, I'd say indeed wipe it.

It is a bug in AndroidX Security that Essentials is currently using, which breaks the Encrypted Shared Preferences when restored from a backup and results in a exception.

Situation should be better with a newer version according to the bug linked in the issue. However, there are no bindings for it 🥲

I asked @moljac on Discord if we could perhaps get a newer version bound, even though there is a policy on not binding pre-release stuff.

Cheesebaron avatar Mar 01 '23 20:03 Cheesebaron

Azure Pipelines successfully started running 2 pipeline(s).

azure-pipelines[bot] avatar Mar 02 '23 10:03 azure-pipelines[bot]

/azp run

mattleibow avatar Mar 07 '23 13:03 mattleibow

Azure Pipelines successfully started running 2 pipeline(s).

azure-pipelines[bot] avatar Mar 07 '23 13:03 azure-pipelines[bot]

Not 100% sure, but perhaps we should remove all keys if this occurs.

What is the situation here? When does this occur? Is there any recovery scenario? If not, I'd say indeed wipe it.

It is a bug in AndroidX Security that Essentials is currently using, which breaks the Encrypted Shared Preferences when restored from a backup and results in a exception.

Situation should be better with a newer version according to the bug linked in the issue. However, there are no bindings for it 🥲

I asked @moljac on Discord if we could perhaps get a newer version bound, even though there is a policy on not binding pre-release stuff.

... and I got green light to bind update

https://github.com/xamarin/AndroidX/pull/707

moljac avatar Mar 08 '23 21:03 moljac

Build error 🙅

D:\a_work\1\s\src\Essentials\src\SecureStorage\SecureStorage.android.cs(113,5): error CS0120: An object reference is required for the non-static field, method, or property 'SecureStorageImplementation.PlatformRemoveAll()' [D:\a_work\1\s\src\Essentials\src\Essentials.csproj::TargetFramework=net7.0-android]

Oopsie. Fixed.

Cheesebaron avatar Mar 09 '23 10:03 Cheesebaron

published new previews

https://www.nuget.org/packages/Xamarin.AndroidX.Security.SecurityCrypto/1.1.0-alpha05 https://www.nuget.org/packages/Xamarin.AndroidX.Security.SecurityCrypto.Ktx/1.1.0-alpha05

moljac avatar Mar 11 '23 17:03 moljac

/azp run

samhouts avatar Mar 16 '23 18:03 samhouts

Azure Pipelines successfully started running 2 pipeline(s).

azure-pipelines[bot] avatar Mar 16 '23 18:03 azure-pipelines[bot]

hi I still have the same issue and app is crashing

image

kirakosyan avatar Mar 28 '23 22:03 kirakosyan

See also:

  • https://learn.microsoft.com/en-us/answers/questions/1001662/suddenly-getting-securestorage-issues-in-maui

jonpryor avatar May 25 '23 18:05 jonpryor

Would strongly recommend backporting this to .net 7. There is no recovery path when it starts happening randomly, and in my experience, even catching exceptions is not sufficient - there are exceptions that bubble up the stack and cause crashes.

plequere-ms avatar May 25 '23 18:05 plequere-ms

/backport to net7.0

hartez avatar Jun 14 '23 17:06 hartez

Started backporting to net7.0: https://github.com/dotnet/maui/actions/runs/5270320306

github-actions[bot] avatar Jun 14 '23 17:06 github-actions[bot]