diff --git a/gui/Process/SlunkCryptRunner.cs b/gui/Process/SlunkCryptRunner.cs index 6992cfa..fe4ddc5 100644 --- a/gui/Process/SlunkCryptRunner.cs +++ b/gui/Process/SlunkCryptRunner.cs @@ -21,18 +21,25 @@ namespace com.muldersoft.slunkcrypt.gui.process public struct SlunkOptions { - public SlunkOptions(bool keepIncompleteFiles, int threadCount) + public SlunkOptions(bool keepIncompleteFiles, int threadCount, bool enableLegacyCompat) { this.keepIncompleteFiles = keepIncompleteFiles; this.threadCount = threadCount; + this.enableLegacyCompat = enableLegacyCompat; } - public readonly bool keepIncompleteFiles; + public readonly bool keepIncompleteFiles, enableLegacyCompat; public readonly int threadCount; } private const string COMMAND_ENCRYPT = "-e"; 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 readonly FileStream m_executableFile; @@ -60,6 +67,8 @@ namespace com.muldersoft.slunkcrypt.gui.process environmentVariables.Add("SLUNK_PASSPHRASE", password); 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_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); } diff --git a/gui/Properties/_Version.cs b/gui/Properties/_Version.cs index 6d4c521..e406c65 100644 --- a/gui/Properties/_Version.cs +++ b/gui/Properties/_Version.cs @@ -8,7 +8,7 @@ namespace com.muldersoft.slunkcrypt.gui.Properties internal static class _Version { public const string VERS_MAJOR = "1"; - public const string VERS_MINOR = "2"; - public const string VERS_PATCH = "1"; + public const string VERS_MINOR = "3"; + public const string VERS_PATCH = "0"; } } diff --git a/gui/SlunkCryptGUI.xaml b/gui/SlunkCryptGUI.xaml index 9e9db71..206ff1d 100644 --- a/gui/SlunkCryptGUI.xaml +++ b/gui/SlunkCryptGUI.xaml @@ -97,6 +97,7 @@ + @@ -132,6 +133,7 @@ + diff --git a/gui/SlunkCryptGUI.xaml.cs b/gui/SlunkCryptGUI.xaml.cs index 4db8af5..fb9f1fb 100644 --- a/gui/SlunkCryptGUI.xaml.cs +++ b/gui/SlunkCryptGUI.xaml.cs @@ -32,7 +32,7 @@ namespace com.muldersoft.slunkcrypt.gui public partial class SlunkCryptGUI : Window, INotifyBusyChanged { private enum Status { Default, Success, Failure } - private delegate Task SlunkProcessor(string inputFile, string outputFile, string password); + private delegate Task SlunkProcessor(string inputFile, string outputFile, string password, bool enableLegacyCompat); 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; @@ -177,11 +177,11 @@ namespace com.muldersoft.slunkcrypt.gui { case 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; case 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; default: TabControl.SelectedIndex = GetTabIndexOf(m_modeOfOperation); @@ -423,7 +423,7 @@ namespace com.muldersoft.slunkcrypt.gui // 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; if (string.IsNullOrEmpty(inputFileEdit.Text = inputFilePath = PathUtils.CleanUpFilePathString(inputFileEdit.Text))) @@ -450,10 +450,10 @@ namespace com.muldersoft.slunkcrypt.gui SetFocusAndSelectAll(inputFileEdit); 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; if (string.IsNullOrEmpty(outputFileEdit.Text = outputFilePath = PathUtils.CleanUpFilePathString(outputFileEdit.Text))) @@ -488,11 +488,11 @@ namespace com.muldersoft.slunkcrypt.gui 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; if (string.IsNullOrEmpty(outputDirectory = PathUtils.TryGetDirectoryName(outputFilePath))) @@ -512,15 +512,16 @@ namespace com.muldersoft.slunkcrypt.gui 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; 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); return; } @@ -528,7 +529,7 @@ namespace com.muldersoft.slunkcrypt.gui { 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); return; @@ -542,11 +543,19 @@ namespace com.muldersoft.slunkcrypt.gui 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)) { @@ -554,7 +563,7 @@ namespace com.muldersoft.slunkcrypt.gui SetProgress(double.PositiveInfinity); ClearLogFile(); 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) { @@ -566,10 +575,10 @@ namespace com.muldersoft.slunkcrypt.gui } } - private async Task Encrypt(string inputFile, string outputFile, string password) + private async Task Encrypt(string inputFile, string outputFile, string password, bool enableLegacyCompat) { 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.Value == 0) @@ -589,10 +598,10 @@ namespace com.muldersoft.slunkcrypt.gui return false; } - private async Task Decrypt(string inputFile, string outputFile, string password) + private async Task Decrypt(string inputFile, string outputFile, string password, bool enableLegacyCompat) { 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.Value == 0) @@ -619,7 +628,7 @@ namespace com.muldersoft.slunkcrypt.gui return false; } - private async Task RunProcess(SlunkCryptRunner.Mode mode, string inputFile, string outputFile, string password) + private async Task RunProcess(SlunkCryptRunner.Mode mode, string inputFile, string outputFile, string password, bool enableLegacyCompat) { if (!ReferenceEquals(m_processRunner, null)) { @@ -627,7 +636,7 @@ namespace com.muldersoft.slunkcrypt.gui } 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)) { m_processRunner.OutputAvailable += Process_OutputAvailable;