GUI: Added checkbox to enable/disable "legacy" compatibility mode.

This commit is contained in:
LoRd_MuldeR 2022-10-15 18:32:54 +02:00
parent b654c89dbf
commit b5b6e3eaf0
Signed by: mulder
GPG Key ID: 2B5913365F57E03F
4 changed files with 45 additions and 25 deletions

View File

@ -21,18 +21,25 @@ namespace com.muldersoft.slunkcrypt.gui.process
public struct SlunkOptions public struct SlunkOptions
{ {
public SlunkOptions(bool keepIncompleteFiles, int threadCount) public SlunkOptions(bool keepIncompleteFiles, int threadCount, bool enableLegacyCompat)
{ {
this.keepIncompleteFiles = keepIncompleteFiles; this.keepIncompleteFiles = keepIncompleteFiles;
this.threadCount = threadCount; this.threadCount = threadCount;
this.enableLegacyCompat = enableLegacyCompat;
} }
public readonly bool keepIncompleteFiles; public readonly bool keepIncompleteFiles, enableLegacyCompat;
public readonly int threadCount; public readonly int threadCount;
} }
private const string COMMAND_ENCRYPT = "-e"; private const string COMMAND_ENCRYPT = "-e";
private const string COMMAND_DECRYPT = "-d"; private const string COMMAND_DECRYPT = "-d";
#if DEBUG
private const bool ENABLE_DEBUG_LOGGING = true;
#else
private const bool ENABLE_DEBUG_LOGGING = false;
#endif
private static readonly Regex RX_PROGRESS = new Regex(@"(\d+)\.(\d)%", RegexOptions.Compiled); private static readonly Regex RX_PROGRESS = new Regex(@"(\d+)\.(\d)%", RegexOptions.Compiled);
private readonly FileStream m_executableFile; private readonly FileStream m_executableFile;
@ -60,6 +67,8 @@ namespace com.muldersoft.slunkcrypt.gui.process
environmentVariables.Add("SLUNK_PASSPHRASE", password); environmentVariables.Add("SLUNK_PASSPHRASE", password);
environmentVariables.Add("SLUNK_KEEP_INCOMPLETE", Convert.ToString(Convert.ToInt32(options.HasValue ? options.Value.keepIncompleteFiles : false))); environmentVariables.Add("SLUNK_KEEP_INCOMPLETE", Convert.ToString(Convert.ToInt32(options.HasValue ? options.Value.keepIncompleteFiles : false)));
environmentVariables.Add("SLUNK_THREADS", Convert.ToString(Math.Max(0, Math.Min(32, options.HasValue ? options.Value.threadCount : 0)))); environmentVariables.Add("SLUNK_THREADS", Convert.ToString(Math.Max(0, Math.Min(32, options.HasValue ? options.Value.threadCount : 0))));
environmentVariables.Add("SLUNK_LEGACY_COMPAT", Convert.ToString(Convert.ToInt32(options.HasValue ? options.Value.enableLegacyCompat : false)));
environmentVariables.Add("SLUNK_DEBUG_LOGGING", Convert.ToString(Convert.ToInt32(ENABLE_DEBUG_LOGGING)));
return await ExecAsnyc(m_executableFile.Name, new string[] { GetCommandString(mode), inputFile, outputFile }, Path.GetDirectoryName(outputFile), environmentVariables); return await ExecAsnyc(m_executableFile.Name, new string[] { GetCommandString(mode), inputFile, outputFile }, Path.GetDirectoryName(outputFile), environmentVariables);
} }

View File

@ -8,7 +8,7 @@ namespace com.muldersoft.slunkcrypt.gui.Properties
internal static class _Version internal static class _Version
{ {
public const string VERS_MAJOR = "1"; public const string VERS_MAJOR = "1";
public const string VERS_MINOR = "2"; public const string VERS_MINOR = "3";
public const string VERS_PATCH = "1"; public const string VERS_PATCH = "0";
} }
} }

View File

@ -97,6 +97,7 @@
<ctrls:ImageButton DockPanel.Dock="Right" Margin="3,0,0,0" Clicked="Button_GeneratePasswd_Click" ImageSource="{StaticResource ImageSource_Die}" ButtonToolTip="Generate random password"/> <ctrls:ImageButton DockPanel.Dock="Right" Margin="3,0,0,0" Clicked="Button_GeneratePasswd_Click" ImageSource="{StaticResource ImageSource_Die}" ButtonToolTip="Generate random password"/>
<ctrls:PasswordToggleBox DockPanel.Dock="Left" EditPadding="3,5,3,5" x:Name="Edit_Encrypt_Password" EditFontFamily="{StaticResource Monospace}" IsRevealed="{Binding IsChecked, ElementName=Button_Encrypt_Toggle}" PasswordChar="*" MaxLength="{x:Static local:SlunkCryptGUI.MAX_PASSWD_LENGTH}" Entered="Edit_Password_Entered"/> <ctrls:PasswordToggleBox DockPanel.Dock="Left" EditPadding="3,5,3,5" x:Name="Edit_Encrypt_Password" EditFontFamily="{StaticResource Monospace}" IsRevealed="{Binding IsChecked, ElementName=Button_Encrypt_Toggle}" PasswordChar="*" MaxLength="{x:Static local:SlunkCryptGUI.MAX_PASSWD_LENGTH}" Entered="Edit_Password_Entered"/>
</DockPanel> </DockPanel>
<CheckBox x:Name="Checkbox_Encrypt_LegacyCompat" Content="Enable &quot;legacy&quot; compatibility-mode (version 1.2.x)" ToolTip="This option should *not* be used when encrypting new files!" Margin="0,14,0,0"/>
</StackPanel> </StackPanel>
</TabItem> </TabItem>
<TabItem Name="TabItem_Decrypt" Tag="{x:Static local:ModeOfOperation.Decrypt}"> <TabItem Name="TabItem_Decrypt" Tag="{x:Static local:ModeOfOperation.Decrypt}">
@ -132,6 +133,7 @@
<ctrls:ImageToggleButton DockPanel.Dock="Right" Margin="3,0,0,0" x:Name="Button_Decrypt_Toggle" ImageSourceDefault="{StaticResource ImageSource_Eye1}" ImageSourceChecked="{StaticResource ImageSource_Eye2}" ToolTipDefault="Show password" ToolTipChecked="Hide password"/> <ctrls:ImageToggleButton DockPanel.Dock="Right" Margin="3,0,0,0" x:Name="Button_Decrypt_Toggle" ImageSourceDefault="{StaticResource ImageSource_Eye1}" ImageSourceChecked="{StaticResource ImageSource_Eye2}" ToolTipDefault="Show password" ToolTipChecked="Hide password"/>
<ctrls:PasswordToggleBox DockPanel.Dock="Left" EditPadding="3,5,3,5" x:Name="Edit_Decrypt_Password" EditFontFamily="{StaticResource Monospace}" IsRevealed="{Binding IsChecked, ElementName=Button_Decrypt_Toggle}" PasswordChar="*" MaxLength="{x:Static local:SlunkCryptGUI.MAX_PASSWD_LENGTH}" Entered="Edit_Password_Entered"/> <ctrls:PasswordToggleBox DockPanel.Dock="Left" EditPadding="3,5,3,5" x:Name="Edit_Decrypt_Password" EditFontFamily="{StaticResource Monospace}" IsRevealed="{Binding IsChecked, ElementName=Button_Decrypt_Toggle}" PasswordChar="*" MaxLength="{x:Static local:SlunkCryptGUI.MAX_PASSWD_LENGTH}" Entered="Edit_Password_Entered"/>
</DockPanel> </DockPanel>
<CheckBox x:Name="Checkbox_Decrypt_LegacyCompat" Content="Enable &quot;legacy&quot; compatibility-mode (version 1.2.x)" ToolTip="This option *must* be enabled to decrypt files that were in encrypted with version 1.2.x or older!" Margin="0,14,0,0"/>
</StackPanel> </StackPanel>
</TabItem> </TabItem>
<TabItem Name="TabItem_LogFile"> <TabItem Name="TabItem_LogFile">

View File

@ -32,7 +32,7 @@ namespace com.muldersoft.slunkcrypt.gui
public partial class SlunkCryptGUI : Window, INotifyBusyChanged public partial class SlunkCryptGUI : Window, INotifyBusyChanged
{ {
private enum Status { Default, Success, Failure } private enum Status { Default, Success, Failure }
private delegate Task<bool> SlunkProcessor(string inputFile, string outputFile, string password); private delegate Task<bool> SlunkProcessor(string inputFile, string outputFile, string password, bool enableLegacyCompat);
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
public const int MIN_PASSWD_LENGTH = 8, REC_PASSWD_LENGTH = 12, GEN_PASSWD_LENGTH = 24, MAX_PASSWD_LENGTH = 256, MAX_PATH = 259; public const int MIN_PASSWD_LENGTH = 8, REC_PASSWD_LENGTH = 12, GEN_PASSWD_LENGTH = 24, MAX_PASSWD_LENGTH = 256, MAX_PATH = 259;
@ -177,11 +177,11 @@ namespace com.muldersoft.slunkcrypt.gui
{ {
case ModeOfOperation.Encrypt: case ModeOfOperation.Encrypt:
Debug.Assert(m_modeOfOperation == ModeOfOperation.Encrypt); Debug.Assert(m_modeOfOperation == ModeOfOperation.Encrypt);
await ValidateInputFile(Edit_Encrypt_InputFile, Edit_Encrypt_OutputFile, Edit_Encrypt_Password, Encrypt, true); await ValidateInputFile(Edit_Encrypt_InputFile, Edit_Encrypt_OutputFile, Edit_Encrypt_Password, Checkbox_Encrypt_LegacyCompat, Encrypt, true);
break; break;
case ModeOfOperation.Decrypt: case ModeOfOperation.Decrypt:
Debug.Assert(m_modeOfOperation == ModeOfOperation.Decrypt); Debug.Assert(m_modeOfOperation == ModeOfOperation.Decrypt);
await ValidateInputFile(Edit_Decrypt_InputFile, Edit_Decrypt_OutputFile, Edit_Decrypt_Password, Decrypt, false); await ValidateInputFile(Edit_Decrypt_InputFile, Edit_Decrypt_OutputFile, Edit_Decrypt_Password, Checkbox_Decrypt_LegacyCompat, Decrypt, false);
break; break;
default: default:
TabControl.SelectedIndex = GetTabIndexOf(m_modeOfOperation); TabControl.SelectedIndex = GetTabIndexOf(m_modeOfOperation);
@ -423,7 +423,7 @@ namespace com.muldersoft.slunkcrypt.gui
// Internal methods // Internal methods
// ============================================================================= // =============================================================================
private async Task ValidateInputFile(TextBox inputFileEdit, TextBox outputFileEdit, PasswordToggleBox passwordEdit, SlunkProcessor processor, bool checkStrongPasswd) private async Task ValidateInputFile(TextBox inputFileEdit, TextBox outputFileEdit, PasswordToggleBox passwordEdit, CheckBox legacyCheckBox, SlunkProcessor processor, bool checkStrongPasswd)
{ {
string inputFilePath; string inputFilePath;
if (string.IsNullOrEmpty(inputFileEdit.Text = inputFilePath = PathUtils.CleanUpFilePathString(inputFileEdit.Text))) if (string.IsNullOrEmpty(inputFileEdit.Text = inputFilePath = PathUtils.CleanUpFilePathString(inputFileEdit.Text)))
@ -450,10 +450,10 @@ namespace com.muldersoft.slunkcrypt.gui
SetFocusAndSelectAll(inputFileEdit); SetFocusAndSelectAll(inputFileEdit);
return; return;
} }
await ValidateOutputFile(inputFilePath, outputFileEdit, passwordEdit, processor, checkStrongPasswd); await ValidateOutputFile(inputFilePath, outputFileEdit, passwordEdit, legacyCheckBox, processor, checkStrongPasswd);
} }
private async Task ValidateOutputFile(string inputFilePath, TextBox outputFileEdit, PasswordToggleBox passwordEdit, SlunkProcessor processor, bool checkStrongPasswd) private async Task ValidateOutputFile(string inputFilePath, TextBox outputFileEdit, PasswordToggleBox passwordEdit, CheckBox legacyCheckBox, SlunkProcessor processor, bool checkStrongPasswd)
{ {
string outputFilePath; string outputFilePath;
if (string.IsNullOrEmpty(outputFileEdit.Text = outputFilePath = PathUtils.CleanUpFilePathString(outputFileEdit.Text))) if (string.IsNullOrEmpty(outputFileEdit.Text = outputFilePath = PathUtils.CleanUpFilePathString(outputFileEdit.Text)))
@ -488,11 +488,11 @@ namespace com.muldersoft.slunkcrypt.gui
return; return;
} }
} }
await ValidateOutputDirectory(inputFilePath, outputFilePath, passwordEdit, processor, checkStrongPasswd); await ValidateOutputDirectory(inputFilePath, outputFilePath, passwordEdit, legacyCheckBox, processor, checkStrongPasswd);
} }
private async Task ValidateOutputDirectory(string inputFilePath, string outputFilePath, PasswordToggleBox passwordEdit, SlunkProcessor processor, bool checkStrongPasswd) private async Task ValidateOutputDirectory(string inputFilePath, string outputFilePath, PasswordToggleBox passwordEdit, CheckBox legacyCheckBox, SlunkProcessor processor, bool checkStrongPasswd)
{ {
string outputDirectory; string outputDirectory;
if (string.IsNullOrEmpty(outputDirectory = PathUtils.TryGetDirectoryName(outputFilePath))) if (string.IsNullOrEmpty(outputDirectory = PathUtils.TryGetDirectoryName(outputFilePath)))
@ -512,15 +512,16 @@ namespace com.muldersoft.slunkcrypt.gui
return; return;
} }
} }
await ValidatePassword(inputFilePath, outputFilePath, passwordEdit, processor, checkStrongPasswd); await ValidatePassword(inputFilePath, outputFilePath, passwordEdit, legacyCheckBox, processor, checkStrongPasswd);
} }
private async Task ValidatePassword(string inputFilePath, string outputFilePath, PasswordToggleBox passwordEdit, SlunkProcessor processor, bool checkStrongPasswd) private async Task ValidatePassword(string inputFilePath, string outputFilePath, PasswordToggleBox passwordEdit, CheckBox legacyCheckBox, SlunkProcessor processor, bool checkStrongPasswd)
{ {
bool enableLegacyCompat = legacyCheckBox.IsChecked.GetValueOrDefault();
string passwordStr; string passwordStr;
if (string.IsNullOrEmpty(passwordStr = passwordEdit.Password) || (passwordStr.Length < MIN_PASSWD_LENGTH)) if (string.IsNullOrEmpty(passwordStr = passwordEdit.Password) || (passwordStr.Length < MIN_PASSWD_LENGTH))
{ {
MessageBox.Show(this, String.Format("Passphrase must be at least {0:D} characters in length!", MIN_PASSWD_LENGTH), "Passphrase Missing", MessageBoxButton.OK, MessageBoxImage.Warning); MessageBox.Show(this, string.Format("Passphrase must be at least {0:D} characters in length!", MIN_PASSWD_LENGTH), "Passphrase Missing", MessageBoxButton.OK, MessageBoxImage.Warning);
SetFocusAndSelectAll(passwordEdit); SetFocusAndSelectAll(passwordEdit);
return; return;
} }
@ -528,7 +529,7 @@ namespace com.muldersoft.slunkcrypt.gui
{ {
if (passwordStr.Length < REC_PASSWD_LENGTH) if (passwordStr.Length < REC_PASSWD_LENGTH)
{ {
if (MessageBox.Show(this, String.Format("Recommended passphrase length is at least {0:D} characters!", REC_PASSWD_LENGTH), "Short Passphrase", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel) != MessageBoxResult.OK) if (MessageBox.Show(this, string.Format("Recommended passphrase length is at least {0:D} characters!", REC_PASSWD_LENGTH), "Short Passphrase", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel) != MessageBoxResult.OK)
{ {
SetFocusAndSelectAll(passwordEdit); SetFocusAndSelectAll(passwordEdit);
return; return;
@ -542,11 +543,19 @@ namespace com.muldersoft.slunkcrypt.gui
return; return;
} }
} }
if (enableLegacyCompat)
{
if (MessageBox.Show(this, "Legacy compat-mode should not be used to encrypt new files!", "Legacy Compatibility", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel) != MessageBoxResult.OK)
{
legacyCheckBox.Focus();
return;
}
}
} }
await InvokeProcessor(inputFilePath, outputFilePath, passwordStr, processor); await InvokeProcessor(inputFilePath, outputFilePath, passwordStr, processor, enableLegacyCompat);
} }
private async Task InvokeProcessor(string inputFile, string outputFile, string password, SlunkProcessor processor) private async Task InvokeProcessor(string inputFile, string outputFile, string password, SlunkProcessor processor, bool enableLegacyCompat)
{ {
using (BusyManager busyManager = new BusyManager(this)) using (BusyManager busyManager = new BusyManager(this))
{ {
@ -554,7 +563,7 @@ namespace com.muldersoft.slunkcrypt.gui
SetProgress(double.PositiveInfinity); SetProgress(double.PositiveInfinity);
ClearLogFile(); ClearLogFile();
Button_Decrypt_Toggle.IsChecked = Button_Encrypt_Toggle.IsChecked = m_checksumError = m_processReceived = false; Button_Decrypt_Toggle.IsChecked = Button_Encrypt_Toggle.IsChecked = m_checksumError = m_processReceived = false;
if (!await processor(inputFile, outputFile, password)) if (!await processor(inputFile, outputFile, password, enableLegacyCompat))
{ {
if (!m_config.KeepIncompleteFiles) if (!m_config.KeepIncompleteFiles)
{ {
@ -566,10 +575,10 @@ namespace com.muldersoft.slunkcrypt.gui
} }
} }
private async Task<bool> Encrypt(string inputFile, string outputFile, string password) private async Task<bool> Encrypt(string inputFile, string outputFile, string password, bool enableLegacyCompat)
{ {
SetStatus("Please wait while the encryption process is initializing..."); SetStatus("Please wait while the encryption process is initializing...");
int? exitCode = await RunProcess(SlunkCryptRunner.Mode.Encrypt, inputFile, outputFile, password); int? exitCode = await RunProcess(SlunkCryptRunner.Mode.Encrypt, inputFile, outputFile, password, enableLegacyCompat);
if (exitCode.HasValue) if (exitCode.HasValue)
{ {
if (exitCode.Value == 0) if (exitCode.Value == 0)
@ -589,10 +598,10 @@ namespace com.muldersoft.slunkcrypt.gui
return false; return false;
} }
private async Task<bool> Decrypt(string inputFile, string outputFile, string password) private async Task<bool> Decrypt(string inputFile, string outputFile, string password, bool enableLegacyCompat)
{ {
SetStatus("Please wait while the decryption process is initializing..."); SetStatus("Please wait while the decryption process is initializing...");
int? exitCode = await RunProcess(SlunkCryptRunner.Mode.Decrypt, inputFile, outputFile, password); int? exitCode = await RunProcess(SlunkCryptRunner.Mode.Decrypt, inputFile, outputFile, password, enableLegacyCompat);
if (exitCode.HasValue) if (exitCode.HasValue)
{ {
if (exitCode.Value == 0) if (exitCode.Value == 0)
@ -619,7 +628,7 @@ namespace com.muldersoft.slunkcrypt.gui
return false; return false;
} }
private async Task<int?> RunProcess(SlunkCryptRunner.Mode mode, string inputFile, string outputFile, string password) private async Task<int?> RunProcess(SlunkCryptRunner.Mode mode, string inputFile, string outputFile, string password, bool enableLegacyCompat)
{ {
if (!ReferenceEquals(m_processRunner, null)) if (!ReferenceEquals(m_processRunner, null))
{ {
@ -627,7 +636,7 @@ namespace com.muldersoft.slunkcrypt.gui
} }
try try
{ {
SlunkCryptRunner.SlunkOptions options = new SlunkCryptRunner.SlunkOptions(m_config.KeepIncompleteFiles, m_config.ThreadCount); SlunkCryptRunner.SlunkOptions options = new SlunkCryptRunner.SlunkOptions(m_config.KeepIncompleteFiles, m_config.ThreadCount, enableLegacyCompat);
using (m_processRunner = new SlunkCryptRunner(Dispatcher)) using (m_processRunner = new SlunkCryptRunner(Dispatcher))
{ {
m_processRunner.OutputAvailable += Process_OutputAvailable; m_processRunner.OutputAvailable += Process_OutputAvailable;