Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Add sample of backup rools, and handl AEADBadTagException #540

Merged
merged 3 commits into from
Oct 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Samples/Samples.Android/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@
<uses-feature android:name="android.hardware.location" android:required="false" />
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
<uses-feature android:name="android.hardware.location.network" android:required="false" />
<application android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:theme="@style/MainTheme"></application>
<application android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/MainTheme"
android:fullBackupContent="@xml/my_backup_rules">
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have our rules and the user rules together? This appears to be an exclusive resource, so we may have to just let the user know - see my other comment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think so, it is a single xml file. This is just in the sample code though.


</application>
</manifest>
5 changes: 5 additions & 0 deletions Samples/Samples.Android/Resources/xml/my_backup_rules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
<include domain="sharedpref" path="."/>
<exclude domain="sharedpref" path="${applicationId}.xamarinessentials.xml"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

If we merge this into the actual library, my concern is that we may conflict with another resource - especially since we have to specify this on the <application> element in the manifest. But... we can add this to the library and then let the user know that for better things they should use our resource - if they have their own, then they should add the line to theirs for better security.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is just for the sample app so I can test it. We wouldn't put it into the actual app as I don't think that is a good idea.

We would just document it.

</full-backup-content>
5 changes: 5 additions & 0 deletions Samples/Samples.Android/Samples.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@
<ItemGroup>
<AndroidAsset Include="Assets\FileSystemTemplate.txt" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\xml\my_backup_rules.xml">
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<Import Project="$(MSBuildThisFileDirectory)..\..\CodeStyles.targets" />
</Project>
10 changes: 9 additions & 1 deletion Xamarin.Essentials/SecureStorage/SecureStorage.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ static Task<string> PlatformGetAsync(string key)
{
var encData = Convert.FromBase64String(encStr);
var ks = new AndroidKeyStore(context, Alias, AlwaysUseAsymmetricKeyStorage);
decryptedData = ks.Decrypt(encData);
try
{
decryptedData = ks.Decrypt(encData);
}
catch (AEADBadTagException)
{
System.Diagnostics.Debug.WriteLine($"Unable to decrypt key, {key}, which is likely due to an app uninstall. Removing old key and returning null.");
PlatformRemove(key);
}
}

return Task.FromResult(decryptedData);
Expand Down