From 5ccbffd637a6f5045a97eaae27b743bb1f91984b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Wed, 25 Mar 2020 12:03:31 +0100 Subject: [PATCH] SEBWIN-351: Implemented utter hack in attempt to make legacy configuration tool calculate the same configuration key in versions 2.x and 3.x. --- .../SEBConfigFileManager.cs | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/SebWindowsClient/SebWindowsClient/ConfigurationUtils/SEBConfigFileManager.cs b/SebWindowsClient/SebWindowsClient/ConfigurationUtils/SEBConfigFileManager.cs index 9e1eaf7..43d5323 100644 --- a/SebWindowsClient/SebWindowsClient/ConfigurationUtils/SEBConfigFileManager.cs +++ b/SebWindowsClient/SebWindowsClient/ConfigurationUtils/SEBConfigFileManager.cs @@ -413,14 +413,18 @@ public static DictObj DecryptSEBSettings(byte[] sebData, bool forEditing, ref st // Get preferences dictionary from decrypted data DictObj sebPreferencesDict = GetPreferencesDictFromConfigData(sebData, forEditing); - // If we didn't get a preferences dict back, we abort reading settings - if (sebPreferencesDict == null) return null; + DictObj sebPreferencesDictOriginal = GetPreferencesDictFromConfigData(sebData, false); + // If we didn't get a preferences dict back, we abort reading settings + if (sebPreferencesDict == null) return null; // We need to set the right value for the key sebConfigPurpose to know later where to store the new settings sebPreferencesDict[SEBSettings.KeySebConfigPurpose] = (int)SEBSettings.sebConfigPurposes.sebConfigPurposeStartingExam; + sebPreferencesDictOriginal[SEBSettings.KeySebConfigPurpose] = (int)SEBSettings.sebConfigPurposes.sebConfigPurposeStartingExam; - // Reading preferences was successful! - return sebPreferencesDict; + SEBSettings.settingsCurrentOriginal = sebPreferencesDictOriginal; + + // Reading preferences was successful! + return sebPreferencesDict; } /// ---------------------------------------------------------------------------------------- @@ -445,7 +449,8 @@ private static DictObj DecryptDataWithPasswordForConfiguringClient(byte[] sebDat // We use always uppercase letters in the base16 hashed admin password used for encrypting hashedAdminPassword = hashedAdminPassword.ToUpper(); DictObj sebPreferencesDict = null; - byte[] decryptedSebData = SEBProtectionController.DecryptDataWithPassword(sebData, hashedAdminPassword); + DictObj sebPreferencesDictOriginal = null; + byte[] decryptedSebData = SEBProtectionController.DecryptDataWithPassword(sebData, hashedAdminPassword); if (decryptedSebData == null) { // If decryption with admin password didn't work, try it with an empty password @@ -500,7 +505,8 @@ private static DictObj DecryptDataWithPasswordForConfiguringClient(byte[] sebDat try { sebPreferencesDict = (DictObj)Plist.readPlist(decryptedSebData); - } + sebPreferencesDictOriginal = (DictObj)Plist.readPlist(decryptedSebData); + } catch (Exception readPlistException) { // Error when deserializing the decrypted configuration data @@ -575,9 +581,12 @@ private static DictObj DecryptDataWithPasswordForConfiguringClient(byte[] sebDat // We need to set the right value for the key sebConfigPurpose to know later where to store the new settings sebPreferencesDict[SEBSettings.KeySebConfigPurpose] = (int)SEBSettings.sebConfigPurposes.sebConfigPurposeConfiguringClient; + sebPreferencesDictOriginal[SEBSettings.KeySebConfigPurpose] = (int)SEBSettings.sebConfigPurposes.sebConfigPurposeConfiguringClient; - // Reading preferences was successful! - return sebPreferencesDict; + SEBSettings.settingsCurrentOriginal = sebPreferencesDictOriginal; + + // Reading preferences was successful! + return sebPreferencesDict; } @@ -806,8 +815,10 @@ public static byte[] GetPrefixDataFromData(ref byte[] data, int prefixLength) public static byte[] EncryptSEBSettingsWithCredentials(string settingsPassword, bool passwordIsHash, X509Certificate2 certificateRef, bool useAsymmetricOnlyEncryption, SEBSettings.sebConfigPurposes configPurpose, bool forEditing) { - // Get current settings dictionary and clean it from empty arrays and dictionaries - //DictObj cleanedCurrentSettings = SEBSettings.CleanSettingsDictionary(); + // Get current settings dictionary and clean it from empty arrays and dictionaries + //DictObj cleanedCurrentSettings = SEBSettings.CleanSettingsDictionary(); + + SEBSettings.settingsCurrentOriginal = SEBSettings.settingsCurrent; // Serialize preferences dictionary to an XML string string sebXML = Plist.writeXml(SEBSettings.settingsCurrent);