Show vault export warning as popup (#1185)

This commit is contained in:
Matt Gibson 2020-12-18 16:47:34 -06:00 committed by GitHub
parent e0191c573d
commit 217514af66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 37 deletions

View File

@ -76,19 +76,6 @@
<Label
Text="{u:I18n ExportVaultMasterPasswordDescription}"
StyleClass="box-footer-label, box-footer-label-switch" />
<Label
StyleClass="box-footer-label, box-footer-label-switch"
Margin="0, 20">
<Label.FormattedText>
<FormattedString>
<Span
Text="{Binding Converter={StaticResource toUpper}, ConverterParameter={u:I18n Warning}}"
FontAttributes="Bold" />
<Span Text=": " FontAttributes="Bold" />
<Span Text="{Binding ExportWarningMessage}" />
</FormattedString>
</Label.FormattedText>
</Label>
<StackLayout Spacing="20">
<Button Text="{u:I18n ExportVault}"
Clicked="ExportVault_Clicked"

View File

@ -105,36 +105,43 @@ namespace Bit.App.Pages
var keyHash = await _cryptoService.HashPasswordAsync(_masterPassword, null);
MasterPassword = string.Empty;
var storedKeyHash = await _cryptoService.GetKeyHashAsync();
if (storedKeyHash != null && keyHash != null && storedKeyHash == keyHash)
{
try
{
var data = await _exportService.GetExport(FileFormatOptions[FileFormatSelectedIndex].Key);
var fileFormat = FileFormatOptions[FileFormatSelectedIndex].Key;
_defaultFilename = _exportService.GetFileName(null, fileFormat);
_exportResult = Encoding.ASCII.GetBytes(data);
if (!_deviceActionService.SaveFile(_exportResult, null, _defaultFilename, null))
{
ClearResult();
await _platformUtilsService.ShowDialogAsync(_i18nService.T("ExportVaultFailure"));
}
}
catch (Exception ex)
var storedKeyHash = await _cryptoService.GetKeyHashAsync();
if (storedKeyHash == null || keyHash == null || storedKeyHash != keyHash)
{
await _platformUtilsService.ShowDialogAsync(_i18nService.T("InvalidMasterPassword"));
return;
}
bool userConfirmedExport = await _platformUtilsService.ShowDialogAsync(ExportWarningMessage,
_i18nService.T("ExportVaultConfirmationTitle"), _i18nService.T("ExportVault"), _i18nService.T("Cancel"));
if (!userConfirmedExport)
{
return;
}
try
{
var data = await _exportService.GetExport(FileFormatOptions[FileFormatSelectedIndex].Key);
var fileFormat = FileFormatOptions[FileFormatSelectedIndex].Key;
_defaultFilename = _exportService.GetFileName(null, fileFormat);
_exportResult = Encoding.ASCII.GetBytes(data);
if (!_deviceActionService.SaveFile(_exportResult, null, _defaultFilename, null))
{
ClearResult();
await _platformUtilsService.ShowDialogAsync(_i18nService.T("ExportVaultFailure"));
System.Diagnostics.Debug.WriteLine(">>> {0}: {1}", ex.GetType(), ex.StackTrace);
#if !FDROID
Crashes.TrackError(ex);
#endif
}
}
else
catch (Exception ex)
{
await _platformUtilsService.ShowDialogAsync(_i18nService.T("InvalidMasterPassword"));
ClearResult();
await _platformUtilsService.ShowDialogAsync(_i18nService.T("ExportVaultFailure"));
System.Diagnostics.Debug.WriteLine(">>> {0}: {1}", ex.GetType(), ex.StackTrace);
#if !FDROID
Crashes.TrackError(ex);
#endif
}
}

View File

@ -2827,6 +2827,14 @@ namespace Bit.App.Resources {
}
}
public static string ExportVaultConfirmationTitle
{
get
{
return ResourceManager.GetString("ExportVaultConfirmationTitle", resourceCulture);
}
}
public static string Warning {
get {
return ResourceManager.GetString("Warning", resourceCulture);

View File

@ -1605,6 +1605,10 @@
<data name="EncExportVaultWarning" xml:space="preserve">
<value>This export encrypts your data using your account's encryption key. If you ever rotate your account's encryption key you should export again since you will not be able to decrypt this export file.</value>
</data>
<data name="ExportVaultConfirmationTitle" xml:space="preserve">
<value>Confirm Vault Export</value>
<comment>Title for the alert to confirm vault exports.</comment>
</data>
<data name="Warning" xml:space="preserve">
<value>Warning</value>
</data>
@ -1792,4 +1796,4 @@
<data name="PersonalOwnershipSubmitError" xml:space="preserve">
<value>Due to an Enterprise Policy, you are restricted from saving items to your personal vault. Change the Ownership option to an organization and choose from available Collections.</value>
</data>
</root>
</root>