Esempio n. 1
0
 internal static void ErrorLogging_Level()
 {
     try
     {
         if (Reg_Operation.CHECK_SWELF_Reg_Key_Exists(Reg_Operation.REG_KEY.logging_level) == false)
         {
             Reg_Operation.ADD_or_CHANGE_SWELF_Reg_Key(Reg_Operation.REG_KEY.logging_level, Settings.AppConfig_File_Args[Settings.SWELF_AppConfig_Args[17]]);
         }
         else if (string.IsNullOrEmpty(Reg_Operation.READ_SWELF_Reg_Key(Reg_Operation.REG_KEY.logging_level)))
         {
             if (File_Operation.CHECK_File_Encrypted(Settings.GET_AppConfigFile_Path) && File_Operation.GET_CreationTime(Settings.GET_AppConfigFile_Path) == Reg_Operation.READ_SWELF_Reg_Key(Reg_Operation.REG_KEY.ConsoleAppConfig_CreationDate))
             {
                 Reg_Operation.ADD_or_CHANGE_SWELF_Reg_Key(Reg_Operation.REG_KEY.logging_level, Settings.AppConfig_File_Args[Settings.SWELF_AppConfig_Args[17]]);
             }
             else
             {
                 //error in logic here
             }
         }
         else if (Reg_Operation.READ_SWELF_Reg_Key(Reg_Operation.REG_KEY.logging_level) != Settings.AppConfig_File_Args[Settings.SWELF_AppConfig_Args[17]])
         {
             if (File_Operation.CHECK_File_Encrypted(Settings.GET_AppConfigFile_Path) && File_Operation.GET_CreationTime(Settings.GET_AppConfigFile_Path) == Reg_Operation.READ_SWELF_Reg_Key(Reg_Operation.REG_KEY.ConsoleAppConfig_CreationDate))
             {
                 Reg_Operation.ADD_or_CHANGE_SWELF_Reg_Key(Reg_Operation.REG_KEY.logging_level, Settings.AppConfig_File_Args[Settings.SWELF_AppConfig_Args[17]]);
             }
             else
             {
                 ErrorsLog.Add("ErrorLogging_Level()" + "Possible Tampering (Reg.Reg_Keys_and_Values[\"logging_level\"] != Settings.AppConfig_File_Args[\"logging_level\"] settings changed to match.");
                 Reg_Operation.ADD_or_CHANGE_SWELF_Reg_Key(Reg_Operation.REG_KEY.logging_level, Settings.AppConfig_File_Args[Settings.SWELF_AppConfig_Args[17]]);
             }
         }
         else
         {
             Settings.Logging_Level_To_Report = Reg_Operation.READ_SWELF_Reg_Key(Reg_Operation.REG_KEY.logging_level);
         }
         int index = Array.FindIndex(Severity_Levels, row => row == Settings.Logging_Level_To_Report);
         Logging_Level_To_Report = Convert.ToInt32(index);
     }
     catch (Exception e)
     {
         if (Reg_Operation.CHECK_SWELF_Reg_Key_Exists(Reg_Operation.REG_KEY.logging_level))
         {
             Settings.Logging_Level_To_Report = Reg_Operation.READ_SWELF_Reg_Key(Reg_Operation.REG_KEY.logging_level);
         }
         else
         {
             Settings.Logging_Level_To_Report = Reg_Operation.READ_SWELF_Reg_Key(Reg_Operation.REG_KEY.logging_level);
             Logging_Level_To_Report          = 1;
         }
     }
 }
Esempio n. 2
0
 internal static void UnSecure_File(string FilePath, int RetryNumber = 0)
 {
     try
     {
         if (File_Operation.CHECK_File_Encrypted(FilePath) == true)
         {
             File.AppendAllText(FilePath, Decrypt_File_Contents(FilePath));
         }
         File.Decrypt(FilePath);
     }
     catch (Exception e)
     {
         if (RetryNumber == 0)
         {
             if (e.Message.ToString().Contains("The input data is not a complete block.") && File_Operation.CHECK_File_Encrypted(FilePath) == false)
             {
                 Encrypt_File_Contents(FilePath);
                 File.Encrypt(FilePath);
                 UnSecure_File(FilePath, 1);
             }
             else
             {
                 File.Decrypt(FilePath);
             }
         }
         if (e.Message.Contains("Padding"))
         {
             Sec_Checks.CHECK_Reg_vs_File_Config(FilePath);
         }
         else if (e.Message.Contains("The input data is not a complete block."))
         {
             if (FilePath.Contains(Settings.AppConfigFile_FileName) && Reg_Operation.CHECK_SWELF_Reg_Key_Exists(Reg_Operation.REG_KEY.ConsoleAppConfig_Contents))
             {
                 File.WriteAllText(Settings.GET_AppConfigFile_Path, Reg_Operation.READ_SWELF_Reg_Key(Reg_Operation.REG_KEY.ConsoleAppConfig_Contents));
             }
             else if (FilePath.Contains(Settings.SearchTermsFileName_FileName) && Reg_Operation.CHECK_SWELF_Reg_Key_Exists(Reg_Operation.REG_KEY.SearchTerms_File_Contents))
             {
                 File.WriteAllText(Settings.GET_AppConfigFile_Path, Reg_Operation.READ_SWELF_Reg_Key(Reg_Operation.REG_KEY.SearchTerms_File_Contents));
             }
             else
             {
                 //error is logic
             }
         }
         else
         {
             Error_Operation.Log_Error("UnLock_File()", e.Message.ToString() + " " + FilePath + "  retry=" + RetryNumber, "", Error_Operation.LogSeverity.FailureAudit);
         }
     }
 }
Esempio n. 3
0
 internal static void Secure_File(string FilePath)
 {
     try
     {
         File.Encrypt(FilePath);
         if (File_Operation.CHECK_File_Encrypted(FilePath) == false)
         {
             Encrypt_File_Contents(FilePath);
         }
     }
     catch (Exception e)
     {
         File.Decrypt(FilePath);
     }
 }
Esempio n. 4
0
 internal static void UPDATE_Local_Config_With_Central_Config(string WebPath, string LocalPath, string FileName)
 {
     if (string.IsNullOrEmpty(Central_Config_File_Web_Cache))
     {
         File_Operation.DELETE_File(LocalPath);    //remove old config file
         Wclient.DownloadFile(WebPath, LocalPath); //if match read local files
     }
     else
     {
         File_Operation.DELETE_File(LocalPath);//remove old config file
         File_Operation.APPEND_AllTXT(LocalPath, Central_Config_File_Web_Cache);
     }
     Error_Operation.Log_Error("GET_Central_Config_File()", "Updated " + FileName + " from " + WebPath + ". It was downloaded to " + LocalPath, "", Error_Operation.LogSeverity.Verbose, Error_Operation.EventID.SWELF_Central_Config_Changed);//log change
     if (File_Operation.CHECK_File_Encrypted(LocalPath) == false)
     {
         Crypto_Operation.Secure_File(LocalPath);
     }
 }
Esempio n. 5
0
        internal static string Hash(string Value)
        {
            var sha256 = SHA256.Create();

            try
            {
                if (File_Operation.CHECK_if_File_Exists(Value) && (File_Operation.CHECK_File_Encrypted(Value)))
                {
                    return(BitConverter.ToString(sha256.ComputeHash(CONVERT_To_ASCII_Bytes(Decrypt_File_Contents(Value, false)))));
                }
                else
                {
                    return(BitConverter.ToString(sha256.ComputeHash(CONVERT_To_ASCII_Bytes(Value))));
                }
            }
            catch (Exception e)
            {
                return(BitConverter.ToString(sha256.ComputeHash(CONVERT_To_ASCII_Bytes(Value))));
            }
        }