-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[regression/8.0.0] [Maui][Android] Signature/MAC verification failed #18230
Comments
Can I see your if you have
try setting it to
There are also other workarounds, but I'll need to dive in deeper. And please report whether that worked. |
Hi @devWR. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
Strange case. I just tested it on Samsung A51 with Android 12 and issue doesn't happen. android:fullBackupContent="@xml/auto_backup_rules" where auto_backup_rules is as following: <?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
<include domain="sharedpref" path="."/>
<exclude domain="sharedpref" path="${applicationId}.mauiessentials.xml"/>
</full-backup-content> |
Not completely. I checked native Android issues on SO and github and saw that as quick-n-dirty workaround. There are some other workarounds, but thosw will need deeper dives and curently I am not sure if I will have time for that. |
Thank you for the workaround then. I believe that some solution shall be found as soon as possible because there is a number of applicaitons that need to store data securely - tokens, etc. |
I can confirm the issue happening in my case. The other workaround is to clear the storage and cache of the app from app settings. |
Same issue here but the workaround isn't working for me at all. |
I had the same issue. setting allowBackup to false fixed it for me. |
I'm having the same issue, (on an actual samsung device - Release APK installation only). I'll try this workaround... not sure if it'll help.... it worked so far, but this issue needs to resolved @maui team ** UPDATE this work around worked for me so far, but I'll have to retest this again later. |
@devWR what backup rules did you end up using that fixed the issue? Or did you not get it resolved and needed to fully disable backup? |
Leonluc already submitted a GitHub issue for the docs :) dotnet/docs-maui#2167 (comment) |
Issue was raised. |
Hello just found this, i think i am also getting hit by this. i have a new app that when i run it for debug builds on my device i do not see a problem. from my sentry logs i get messages like this: android.security.keystore2.AndroidKeyStoreCipherSpiBase in engineDoFinal at line 632 and then KeyStoreException Caused by: android v14 also i see this: JniObjectReference StaticMethods.CallStaticObjectMethod(JniObjectReference, JniMethodInfo, JniArgumentValue*) Assembly: Called from: ISharedPreferences EncryptedSharedPreferences.Create(Context, string, MasterKey, PrefKeyEncryptionScheme, PrefValueEncryptionScheme) Show 2 more frames the app wants to use secure storage for user tokens. try to login or resume from recent session and BOOM! i will see if the info here lets me work past this..... |
first test setting allow backup to false seems to stop the crash! |
@figuerres I have the error on both debug and release using MAUI 8.0.20 Also Allow Backup none doesn´t seem to be a workaround since all saved data get´s deleted after a restart of the app. I´m having the same error when using any SecureStorage command:
|
To add another wrinkle to this, the documentation says:
First, it doesn't handle the case because it still fails. Second, and more importantly, removing the key myself doesn't work either. It seems that calling SetValue must be attempting to read the value before setting it because the call still fails with the same exception. @leonluc-dev Thank you for putting the complete workaround. Unfortunately for me, I still can't set secure storage values. I'm getting |
Same problem as @mmiller-d8, I have done the work around @leonluc-dev posted but its crashing on |
Same issue as @mmiller-d8. Seeing this exception on my Android 14 / Pixel 6a device. Building with Maui 8.0.21, NET SDK 8.0.300, Xcode 15.4 I was struggling to consistently reproduce the issue but figured out a process:
Clearing the app storage avoids the problem (not suggesting that as a solution). But for anyone else that feels the issue is happening randomly for them I realized that my phone does auto-backup after 2hrs of inactivity which made the problem pop up again the next time I rebuilt after clearing app storage. |
A workaround I've found is to clear the shared preferences with Android code. It feels brittle and not quite a polished solution but it does enable you to get past the error and back to saving/loading data
At this point I'm not sure whether the flag |
It appears that reusing the shared preferences instance sometimes causes changes to not be properly committed to disk as the instance is not disposed in some cases before the app is torn down (eg: force close). Caching isn't really necessary here anyways as the underlying android preference manager does its own layer of caching (so we are just paying the interop tax to get a 'new' instance here). The simplest fix is to stop caching which is the real content of this change. We don't cache in the regular preferences API where we use shared preferences and the issue does not seem to exist there.
The reason for this is that the SecureStorage GeneralSecurityException handling is broken: maui/src/Essentials/src/SecureStorage/SecureStorage.android.cs Lines 30 to 37 in 5bb5ed2
The idea is good but calling Why For regular developers consuming SecureStorage it's best to either disable auto-backup all together or selectively as @leonluc-dev described here #18230 (comment) For microsoft developers maintaining this part of code:
This should resolve it properly for all developers. @Redth @moljac Could you have a look and resolve it? So to summarize I think the right solution would be to change the SecureStorage.android.cs code like below:
|
Thank you for that @kmiterror I tried selectively removing the backup as in the comment you mentioned, but I'm still getting crashes when I update the app on a device. I haven't turned off all backups yet because I'm hoping they fix it. I'm not yet live, so I just delete the application data when I update it with a release build. |
I think that the thing that you specify in AndroidManifest.xml just excludes the files from the backup. Since the file has already been restored on your device and you don't have keys to decrypt it So it seems that at this point you have to catch the
So the solution is two-fold, |
@kmiterror I did do the selective backup. Here's what I have.
I also have a legacy set for older devices. I'll try out the error handling. Thanks! |
There's some great recommendations for working around the issues in this issue. Thanks to everyone who took the time to provide them, including @kmiterror who had a long write up on their findings, and @gerhartz who found a way to reliably reproduce the issue. One more thing to note is that if you're using the approach to try/catch and delete the shared preferences outlined in this thread, you may want to consider the difference between If you're attempting to delete the shared preferences and then immediately try creating them again, you should be using So, the code I would suggest using for now while waiting for the fix to merge and be released in MAUI itself would be: string someValue;
try
{
someValue = await SecureStorage.GetAsync(key);
}
catch (Exception ex)
{
var packageName = AppInfo.Current.PackageName;
var alias = $"{packageName}.microsoft.maui.essentials.preferences";
var preferences = AndroidApp.Context.GetSharedPreferences(alias, FileCreationMode.Private);
preferences?.Edit()?.Clear()?.Commit();
someValue = await SecureStorage.GetAsync(key);
} |
Description
Since I updated to .NET8 RC2 SecureStorage.SetAsync does not work. It throws Javax.Crypto.AEADBadTagException with the following message: "Signature/MAC verification failed".
Issue reproduced using Samsung A40 with Android 11. Case happens when backup rules exclude mauiessentials.xml file.
Below you can find stacktrace:
Steps to Reproduce
Invoke Microsoft.Maui.Storage.SecureStorage.SetAsync
Link to public reproduction project repository
No response
Version with bug
8.0.0-rc.2.9373
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
8.0.0-rc.1.9171
Affected platforms
Android
Affected platform versions
No response
Did you find any workaround?
Yes
Issue doesn't happen when, in manifest, android:allowBackup is set to false as following:
<application android:allowBackup="false" ... >
Relevant log output
No response
The text was updated successfully, but these errors were encountered: