Skip to content

Commit 1a9ef6b

Browse files
committed
Add option to prevent unencrypted exports
+ Update icon pack
1 parent 2530fc2 commit 1a9ef6b

File tree

8 files changed

+45
-11
lines changed

8 files changed

+45
-11
lines changed

Guard.Core/RegistrySettings.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,14 @@ int minLength
128128
);
129129
return (requireLowerAndUpperCase, requireDigits, requireSpecialChars, minLength);
130130
}
131+
132+
public static bool PreventUnencryptedExports()
133+
{
134+
return GetValue(
135+
@"HKEY_CURRENT_USER\Software\Policies\2FAGuard",
136+
"PreventUnencryptedExports",
137+
false
138+
);
139+
}
131140
}
132141
}

Guard.WPF/Assets/Icons/si.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

Guard.WPF/Core/Export/Exporter/AuthenticatorProExporter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ public async Task Export(string? path, byte[]? password)
4040
var tokenHelpers =
4141
await TokenManager.GetAllTokens()
4242
?? throw new Exception(I18n.GetString("export.notokens"));
43+
44+
if (tokenHelpers.Count == 0)
45+
{
46+
throw new Exception(I18n.GetString("export.notokens"));
47+
}
48+
4349
List<AuthenticatorProBackup.Authenticator> authenticators = [];
4450

4551
foreach (var tokenHelper in tokenHelpers)

Guard.WPF/Core/Export/Exporter/BackupExporter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ public async Task Export(string? path, byte[]? password)
3333
var tokenHelpers =
3434
await TokenManager.GetAllTokens()
3535
?? throw new Exception(I18n.GetString("export.notokens"));
36+
37+
if (tokenHelpers.Count == 0)
38+
{
39+
throw new Exception(I18n.GetString("export.notokens"));
40+
}
41+
3642
List<Backup.Token> tokens = [];
3743

3844
foreach (var tokenHelper in tokenHelpers)

Guard.WPF/Resources/Strings.en.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@
194194
<system:String x:Key="i.page.exportpage">Export tokens</system:String>
195195
<system:String x:Key="i.export.failed.title">Export failed</system:String>
196196
<system:String x:Key="i.export.failed.content">An error occurred while exporting:</system:String>
197+
<system:String x:Key="i.export.failed.unencrypted">Unencrypted backups are blocked by your administrator</system:String>
197198
<system:String x:Key="i.export.password">Please enter a password for the backup file</system:String>
198199
<system:String x:Key="i.export.password.invalid">Please enter a valid password</system:String>
199200
<system:String x:Key="i.export.backup">Backup</system:String>

Guard.WPF/Views/Dialogs/PasswordDialog.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
1414
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
1515
CloseButtonText="{DynamicResource i.dialog.close}"
16-
DialogMaxHeight="250"
16+
DialogMaxHeight="275"
1717
IsPrimaryButtonEnabled="True"
1818
PrimaryButtonIcon="{ui:SymbolIcon ArrowCircleRight24,
1919
Filled=True}"

Guard.WPF/Views/Pages/ExportPage.xaml.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ private async void Export(IExporter exporter)
2727
{
2828
try
2929
{
30+
if (!exporter.RequiresPassword() && RegistrySettings.PreventUnencryptedExports())
31+
{
32+
throw new Exception(I18n.GetString("i.export.failed.unencrypted"));
33+
}
34+
3035
if (exporter.Type == IExporter.ExportType.File)
3136
{
3237
Microsoft.Win32.SaveFileDialog saveFileDialog =
@@ -60,6 +65,7 @@ private async void Export(IExporter exporter)
6065
throw new Exception(I18n.GetString("export.password.invalid"));
6166
}
6267
}
68+
6369
await exporter.Export(saveFileDialog.FileName, password);
6470

6571
Wpf.Ui.Controls.MessageBoxResult sucessDialogResult =

docs/advanced.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ The default data paths are:
2323
- Installer version: `%LOCALAPPDATA%\2FAGuard`
2424
- Portable version: `.\2FAGuard-Data`
2525

26+
### Prevent unencrypted exports
27+
28+
Create a value named `PreventUnencryptedExports` in the path above. The value should be of type `DWORD`. If set to `1`, the application will not allow unencrypted exports of the secrets. The default is `0`.
29+
30+
### Password requirements
31+
32+
Create a subkey named `Password` in the path specified above. The following values can be set:
33+
34+
- `RequireLowerAndUpperCase` (DWORD): Requires at least one lowercase and one uppercase letter in the password. The default is `0`.
35+
- `RequireDigits` (DWORD): Requires at least one digit in the password. The default is `0`.
36+
- `RequireSpecialChars` (DWORD): Requires at least one special character in the password. The default is `0`.
37+
- `MinLength` (DWORD): The minimum length of the password. The default is `8`. Tip: Select decimal as the base for the value in the registry editor when entering the value.
38+
39+
Please note that the password requirements are only enforced when creating a new password. If you change the requirements after a password has been set, the new requirements will not be enforced for the existing password.
40+
2641
### Modify setup
2742

2843
Create a subkey named `Setup` in the path specified above. The following values can be set:
@@ -40,12 +55,3 @@ Create a subkey named `Settings` in the path specified above. These keys can be
4055
- `HideWinHello` (DWORD): If set to `1`, the settings page will not show the Windows Hello settings. The default is `0`.
4156
- `HidePreventRecording` (DWORD): The settings page will not show the option to prevent screen recording if set to `1`. The default is `0`.
4257
- `HideSecurityKey` (DWORD): If set to `1`, the settings page will not show the security key (WebAuthn / FIDO2) settings. The default is `0`.
43-
44-
### Password requirements
45-
46-
Create a subkey named `Password` in the path specified above. The following values can be set:
47-
48-
- `RequireLowerAndUpperCase` (DWORD): Requires at least one lowercase and one uppercase letter in the password. The default is `0`.
49-
- `RequireDigits` (DWORD): Requires at least one digit in the password. The default is `0`.
50-
- `RequireSpecialChars` (DWORD): Requires at least one special character in the password. The default is `0`.
51-
- `MinLength` (DWORD): The minimum length of the password. The default is `8`. Tip: Select decimal as the base for the value in the registry editor when entering the value.

0 commit comments

Comments
 (0)