static public void StartAllThreads() { FoxEventLog.VerboseWriteEventLog("StartAllThreads()", System.Diagnostics.EventLogEntryType.Information); ReportingThreadHandle1 = new Thread(new ThreadStart(ReportingThread1)); ReportingThreadHandle2 = new Thread(new ThreadStart(ReportingThread2)); PolicyThreadHandle = new Thread(new ThreadStart(PolicyThread)); DownloadThreadHandle = new Thread(new ThreadStart(DownloadThread)); ReportingThreadHandle1.Start(); ReportingThreadHandle2.Start(); PolicyThreadHandle.Start(); DownloadThreadHandle.Start(); PushMain0.StartPushThread(); PushMain1.StartPushThread(); PushMain2.StartPushThread(); #if ENABLECHAT PushMain10.StartPushThread(); #endif UpdateCheck.RunUpdateCheckAndHouseKeepingThread(); DownloadSystemFSData.StartThread(); if (SystemInfos.SysInfo.RunningInWindowsPE == false || SystemInfos.SysInfo.RunningInWindowsPE == null) { LocalPackagesHandle = new Thread(new ThreadStart(LocalPackagesThread)); LocalPackagesHandle.Start(); } FoxEventLog.VerboseWriteEventLog("StartAllThreads() - DONE", System.Diagnostics.EventLogEntryType.Information); }
public static Network NoConnectNetwork() { if (SystemInfos.ServerURL == ProgramAgent.VulpesURL) { if (SystemInfos.ContractID == "" || SystemInfos.ContractPassword == "") { FoxEventLog.VerboseWriteEventLog("Missing contract data for Vulpes Server (" + ProgramAgent.VulpesURL + ")", System.Diagnostics.EventLogEntryType.Error); return(null); } } Network net = new Network(); try { ServerInfo = null; URL = SystemInfos.ServerURL; if (net.Connect(SystemInfos.ServerURL) == false) { return(null); } } catch { } return(net); }
public static bool LoadDLL() { try { string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string filename = ""; switch (SystemInfos.GetCPU()) { case SystemInfos.CPUType.Intel32: filename = Path.Combine(dir, "FoxSDC_AgentDLL32.dll"); break; case SystemInfos.CPUType.EM64T: filename = Path.Combine(dir, "FoxSDC_AgentDLL64.dll"); break; case SystemInfos.CPUType.ARM64: filename = Path.Combine(dir, "FoxSDC_AgentDLLARM64.dll"); break; } FoxEventLog.VerboseWriteEventLog("DLL: " + filename, System.Diagnostics.EventLogEntryType.Information); Debug.WriteLine(">>> LOADING: " + filename); if (filename == "") { FoxEventLog.WriteEventLog("Cannot load FoxSDC_AgentDLL<xx>.DLL - Unknown architecture", System.Diagnostics.EventLogEntryType.Error); #if !DEBUG || DEBUGSERVICE service.Stop(); #endif return(false); } Assembly asm = Assembly.LoadFile(filename); Type t = asm.GetType("Fox.FoxCWrapper"); CPP = (CPPInterface)Activator.CreateInstance(t); DLLFile = filename; } catch (Exception ee) { Debug.WriteLine(ee.ToString()); #if DEBUG FoxEventLog.WriteEventLog("Cannot load FoxSDC_AgentDLL<xx>.DLL\n" + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); #else FoxEventLog.WriteEventLog("Cannot load FoxSDC_AgentDLL<xx>.DLL", System.Diagnostics.EventLogEntryType.Error); #endif #if !DEBUG || DEBUGSERVICE service.Stop(); #endif return(false); } return(true); }
static public void StopAllThreads() { FoxEventLog.VerboseWriteEventLog("StopAllThreads()", System.Diagnostics.EventLogEntryType.Information); StopThreads = true; Redirs.PortMappings_Kernel.StopAllConnections(); if (PolicyThreadHandle != null) { PolicyThreadHandle.Join(); } if (ReportingThreadHandle1 != null) { ReportingThreadHandle1.Join(); } if (ReportingThreadHandle2 != null) { ReportingThreadHandle2.Join(); } if (DownloadThreadHandle != null) { DownloadThreadHandle.Join(); } if (LocalPackagesHandle != null) { LocalPackagesHandle.Join(); } StopDownloads(); PushMain0.StopPushThread(); PushMain1.StopPushThread(); PushMain2.StopPushThread(); #if ENABLECHAT PushMain10.StopPushThread(); #endif UpdateCheck.StopUpdateThread(); DownloadSystemFSData.StopThread(); FoxEventLog.VerboseWriteEventLog("StopAllThreads() - Done", System.Diagnostics.EventLogEntryType.Information); }
static void DownloadThreadRunner() { try { int Direction = -1; lock (FileLock) { if (FilesystemData.FileTransferStatus.ServerID == null) { return; } Direction = FilesystemData.FileTransferStatus.Direction; } #region Client to Server if (Direction == 1) { string LocalFilename = ""; string MD5; Int64 ServerID = 0; Int64 CurrentSZ; Int64 TotalSZ; bool OverrideMetered; bool ReqOnly; DateTime LastModified; try { lock (FileLock) { LocalFilename = FilesystemData.FileTransferStatus.RemoteFileLocation; ServerID = FilesystemData.FileTransferStatus.ServerID.Value; CurrentSZ = FilesystemData.FileTransferStatus.ProgressSize; TotalSZ = FilesystemData.FileTransferStatus.Size; MD5 = FilesystemData.FileTransferStatus.MD5CheckSum; OverrideMetered = FilesystemData.FileTransferStatus.OverrideMeteredConnection; ReqOnly = FilesystemData.FileTransferStatus.RequestOnly; LastModified = FilesystemData.FileTransferStatus.LastModfied; } //won't start when in metered connection! if (OverrideMetered == false) { try { if (MeteredConnection.IsMeteredConnection() == true) { FoxEventLog.VerboseWriteEventLog("Upload paused = metered connection detected", System.Diagnostics.EventLogEntryType.Information); return; } } catch { } } Int64 ReallyCurrentSZ = 0; try { if (File.Exists(LocalFilename) == true) { FileInfo fi = new FileInfo(LocalFilename); ReallyCurrentSZ = fi.Length; } else { FoxEventLog.WriteEventLog("File " + LocalFilename + " does not exist for upload.", System.Diagnostics.EventLogEntryType.Error); return; } } catch (Exception ee) { FoxEventLog.WriteEventLog("Checking upload file " + LocalFilename + " ID: " + ServerID.ToString() + " failed:\n" + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); return; } downloadnet = Utilities.ConnectNetwork(7); if (downloadnet == null) { return; } if (ReqOnly == true) { Status.UpdateMessage(7, "Checking " + LocalFilename); MD5 = MD5Utilities.CalcMD5File(LocalFilename); FileInfo fi = new FileInfo(LocalFilename); lock (FileLock) { FilesystemData.FileTransferStatus.MD5CheckSum = MD5; FilesystemData.FileTransferStatus.LastModfied = fi.LastWriteTimeUtc; FilesystemData.WriteFileTransferStatus(); } Int64?NewID = downloadnet.File_Agent_NewUploadReq(LocalFilename, OverrideMetered, MD5); if (NewID == null) { FoxEventLog.VerboseWriteEventLog("Cannot create a new upload req for " + LocalFilename, System.Diagnostics.EventLogEntryType.Warning); return; } if (downloadnet.File_Agent_CancelUpload(ServerID) == false) { FoxEventLog.VerboseWriteEventLog("Cannot delete temp upload req for " + LocalFilename + " ID: " + ServerID.ToString(), System.Diagnostics.EventLogEntryType.Warning); return; } lock (FileLock) { //wait for the new upload req ClearDataFSD(); FilesystemData.WriteFileTransferStatus(); UnlockTimer = true; return; } } else { FileStream fs = null; do { try { if (CancelAndDeleteDL == true) { return; } FileInfo fi = new FileInfo(LocalFilename); if (roughDT(fi.LastWriteTimeUtc, LastModified) == false || fi.Length != TotalSZ) { if (downloadnet.File_Agent_CancelUpload(ServerID) == false) { FoxEventLog.VerboseWriteEventLog("Cannot cancel upload req for " + LocalFilename + " ID: " + ServerID.ToString() + ", due file changes", System.Diagnostics.EventLogEntryType.Warning); lock (FileLock) { ClearDataFSD(); FilesystemData.WriteFileTransferStatus(); } return; } else { FoxEventLog.VerboseWriteEventLog("Cannot upload req for " + LocalFilename + " ID: " + ServerID.ToString() + ": File has been changed!", System.Diagnostics.EventLogEntryType.Warning); } return; } try { if (fs == null) { fs = File.Open(LocalFilename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); } } catch (Exception ee) { FoxEventLog.WriteEventLog("Cannot upload file " + LocalFilename + " ID: " + ServerID.ToString() + " failed:\n" + ee.ToString(), System.Diagnostics.EventLogEntryType.Warning); return; } try { fs.Seek(CurrentSZ, SeekOrigin.Begin); } catch { FoxEventLog.WriteEventLog("Cannot properly seek in file " + LocalFilename + " ID: " + ServerID.ToString() + " Pos: 0x" + CurrentSZ.ToString("X"), System.Diagnostics.EventLogEntryType.Warning); return; } byte[] data = null; try { int read = 1024 * 1024; data = new byte[read]; read = fs.Read(data, 0, read); if (data.Length != read) { byte[] ddd = new byte[read]; Array.Copy(data, ddd, read); data = ddd; } } catch { FoxEventLog.WriteEventLog("Cannot read file " + LocalFilename + " ID: " + ServerID.ToString() + " Pos: 0x" + CurrentSZ.ToString("X"), System.Diagnostics.EventLogEntryType.Warning); return; } Status.UpdateMessage(7, "Uploading " + LocalFilename + "\r\n" + CommonUtilities.NiceSize(CurrentSZ) + " of " + CommonUtilities.NiceSize(TotalSZ)); bool res = downloadnet.File_Agent_AppendUpload(ServerID, data); if (res == false) { FoxEventLog.VerboseWriteEventLog("Cannot upload append req for " + LocalFilename + " ID: " + ServerID.ToString(), System.Diagnostics.EventLogEntryType.Warning); return; } CurrentSZ += data.Length; lock (FileLock) { FilesystemData.FileTransferStatus.ProgressSize = CurrentSZ; FilesystemData.WriteFileTransferStatus(); } if (CurrentSZ == TotalSZ) { FoxEventLog.WriteEventLog("Upload file success " + LocalFilename + " ID: " + ServerID.ToString(), System.Diagnostics.EventLogEntryType.Information); lock (FileLock) { ClearDataFSD(); FilesystemData.WriteFileTransferStatus(); } UnlockTimer = true; return; } } finally { if (fs != null) { fs.Close(); fs = null; } } } while (true); } } catch (Exception ee) { FoxEventLog.WriteEventLog("Downloading file " + LocalFilename + " ID: " + ServerID.ToString() + " crashed:\n" + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); } finally { Status.UpdateMessage(7); } } #endregion #region Server to Client if (Direction == 0) { string LocalFilename; string MD5; Int64 ServerID; Int64 CurrentSZ; Int64 TotalSZ; bool OverrideMetered; lock (FileLock) { LocalFilename = FilesystemData.FileTransferStatus.RemoteFileLocation; ServerID = FilesystemData.FileTransferStatus.ServerID.Value; CurrentSZ = FilesystemData.FileTransferStatus.ProgressSize; TotalSZ = FilesystemData.FileTransferStatus.Size; MD5 = FilesystemData.FileTransferStatus.MD5CheckSum; OverrideMetered = FilesystemData.FileTransferStatus.OverrideMeteredConnection; } //won't start when in metered connection! if (OverrideMetered == false) { try { if (MeteredConnection.IsMeteredConnection() == true) { FoxEventLog.VerboseWriteEventLog("Download paused = metered connection detected", System.Diagnostics.EventLogEntryType.Information); return; } } catch { } } Int64 ReallyCurrentSZ = 0; try { string Dir = Path.GetDirectoryName(LocalFilename); if (Directory.Exists(Dir) == false) { Directory.CreateDirectory(Dir); } if (File.Exists(LocalFilename) == true) { FileInfo fi = new FileInfo(LocalFilename); ReallyCurrentSZ = fi.Length; } else { ReallyCurrentSZ = 0; } } catch (Exception ee) { FoxEventLog.WriteEventLog("Checking download file " + LocalFilename + " ID: " + ServerID.ToString() + " failed:\n" + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); } if (ReallyCurrentSZ != CurrentSZ) { FoxEventLog.WriteEventLog("File Size does not match: deleting the file " + LocalFilename, System.Diagnostics.EventLogEntryType.Warning); try { File.Delete(LocalFilename); } catch (Exception ee) { FoxEventLog.WriteEventLog("Cannot delete " + LocalFilename + "\n" + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); } lock (FileLock) { ClearDataFSD(); FilesystemData.WriteFileTransferStatus(); return; } } downloadnet = Utilities.ConnectNetwork(7); if (downloadnet == null) { return; } try { downloadnet.DownloadNotify += Downloadnet_DownloadNotify; if (downloadnet.DownloadFile("api/agent/filefiledownload/" + ServerID.ToString(), LocalFilename, TotalSZ) == false) { FileInfo fi = new FileInfo(LocalFilename); lock (FileLock) { FilesystemData.FileTransferStatus.ProgressSize = fi.Length; FilesystemData.WriteFileTransferStatus(); } } else { if (downloadnet.StopDownload == false) { Status.UpdateMessage(7, "Checking " + FilesystemData.FileTransferStatus.RemoteFileLocation + "..."); string CalcMD5 = MD5Utilities.CalcMD5File(LocalFilename); if (MD5.ToLower() != CalcMD5.ToLower()) { FoxEventLog.WriteEventLog("File MD5 does not match: deleting the file " + LocalFilename, System.Diagnostics.EventLogEntryType.Warning); try { File.Delete(LocalFilename); } catch (Exception ee) { FoxEventLog.WriteEventLog("Cannot delete " + LocalFilename + "\n" + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); } lock (FileLock) { ClearDataFSD(); FilesystemData.WriteFileTransferStatus(); return; } } else { //success! FoxEventLog.WriteEventLog("File download success: " + LocalFilename, System.Diagnostics.EventLogEntryType.Information); downloadnet.File_Agent_CancelUpload(ServerID); lock (FileLock) { ClearDataFSD(); FilesystemData.WriteFileTransferStatus(); } UnlockTimer = true; return; } } else { if (CancelAndDeleteDL == true) { FoxEventLog.VerboseWriteEventLog("File " + LocalFilename + " canceled by server req.", System.Diagnostics.EventLogEntryType.Information); try { File.Delete(LocalFilename); } catch (Exception ee) { FoxEventLog.WriteEventLog("Cannot delete " + LocalFilename + "\n" + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); } lock (FileLock) { ClearDataFSD(); FilesystemData.WriteFileTransferStatus(); return; } } } } } catch (Exception ee) { FoxEventLog.WriteEventLog("Downloading file " + LocalFilename + " ID: " + ServerID.ToString() + " crashed:\n" + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); } finally { downloadnet.DownloadNotify -= Downloadnet_DownloadNotify; Status.UpdateMessage(7); } } #endregion } finally { try { if (downloadnet != null) { downloadnet.CloseConnection(); } } catch { } downloadnet = null; } }
public static Network ConnectNetwork(int MessageChannel) { if (SystemInfos.ServerURL == ProgramAgent.VulpesURL) { if (SystemInfos.ContractID == "" || SystemInfos.ContractPassword == "") { FoxEventLog.VerboseWriteEventLog("Missing contract data for Vulpes Server (" + ProgramAgent.VulpesURL + ")", System.Diagnostics.EventLogEntryType.Error); return(null); } } Network net = new Network(); if (MessageChannel > -1) { Status.UpdateMessage(MessageChannel, "Connecting to server " + SystemInfos.ServerURL); } FoxEventLog.VerboseWriteEventLog("Connecting to server " + SystemInfos.ServerURL, System.Diagnostics.EventLogEntryType.Information); try { ServerInfo = null; URL = SystemInfos.ServerURL; if (net.Connect(SystemInfos.ServerURL) == false) { if (MessageChannel > -1) { Status.UpdateMessage(MessageChannel, "Connecting to server " + SystemInfos.ServerURL + " failed"); } FoxEventLog.VerboseWriteEventLog("Connecting to server " + SystemInfos.ServerURL + " failed", System.Diagnostics.EventLogEntryType.Information); return(null); } try { SystemInfos.SysInfo.IsMeteredConnection = MeteredConnection.IsMeteredConnection(); //always update this } catch (Exception ee) { Debug.WriteLine(ee.ToString()); SystemInfos.SysInfo.IsMeteredConnection = null; } if (net.ComputerLogin(SystemInfos.SysInfo.MachineID, SystemInfos.PasswordID, SystemInfos.ContractID, SystemInfos.ContractPassword, SystemInfos.SysInfo) == false) { if (net.LoginError == null) { if (MessageChannel > -1) { Status.UpdateMessage(MessageChannel, "Login failed: <no data> ( on server " + SystemInfos.ServerURL + ")"); } FoxEventLog.VerboseWriteEventLog("Login failed: <no data> ( on server " + SystemInfos.ServerURL + ")", System.Diagnostics.EventLogEntryType.Information); } else { if (MessageChannel > -1) { Status.UpdateMessage(MessageChannel, "Login failed: " + net.LoginError.Error + " - " + net.LoginError.ErrorID.ToString() + " ( on server " + SystemInfos.ServerURL + ")"); } FoxEventLog.VerboseWriteEventLog("Login failed: " + net.LoginError.Error + " - " + net.LoginError.ErrorID.ToString() + " ( on server " + SystemInfos.ServerURL + ")", System.Diagnostics.EventLogEntryType.Information); } net.CloseConnection(); return(null); } if (net.GetInfo() == true) { ServerInfo = net.serverinfo; URL = SystemInfos.ServerURL; } if (MessageChannel > -1) { Status.UpdateMessage(MessageChannel); } } catch { FoxEventLog.VerboseWriteEventLog("Login failed - something really has gone wrong: (" + SystemInfos.ServerURL + ")", System.Diagnostics.EventLogEntryType.Information); if (MessageChannel > -1) { Status.UpdateMessage(MessageChannel); } return(null); } return(net); }
public static void RunPipeClient() { Process2ProcessComm p2p = new Process2ProcessComm(); if (p2p.ConnectPipe(ProgramAgent.PipeGUID) == false) { FoxEventLog.VerboseWriteEventLog("Cannot connect to pipe " + ProgramAgent.PipeGUID, EventLogEntryType.Error); return; } string Action = p2p.GetAction(); if (Action == null) { FoxEventLog.VerboseWriteEventLog("Got no action data from pipe " + ProgramAgent.PipeGUID, EventLogEntryType.Error); return; } switch (Action.ToLower()) { case "install": { PackageInstaller inst = new PackageInstaller(); DataHInstallPackageTODO todo = p2p.GetTODO <DataHInstallPackageTODO>(); if (todo == null) { FoxEventLog.VerboseWriteEventLog("Got no todo data from pipe " + ProgramAgent.PipeGUID, EventLogEntryType.Error); return; } DataHInstallPackageResult result = new DataHInstallPackageResult(); result.Return = inst.InstallPackage(todo.Filename, todo.CerCertificates, todo.Mode, todo.ZipIsMetaOnly, out result.ErrorText, out result.res, out result.Reciept, todo.OtherDLL); if (inst.ScriptTempDLLFilename != null) { FoxEventLog.VerboseWriteEventLog("Script DLL file = " + inst.ScriptTempDLLFilename, EventLogEntryType.Information); } result.TempDLLFilename = inst.ScriptTempDLLFilename; p2p.SetResult(result); break; } case "runuser": { DataHRunasUserTODO todo = p2p.GetTODO <DataHRunasUserTODO>(); DataHRunasUserResult res = new DataHRunasUserResult(); try { Process p = new Process(); p.StartInfo.FileName = todo.Filename; p.StartInfo.Arguments = todo.Args; p.StartInfo.UserName = todo.Username; p.StartInfo.Password = Utilities.MakeSecString(todo.Password); p.StartInfo.UseShellExecute = false; p.Start(); } catch (Win32Exception ee) { FoxEventLog.VerboseWriteEventLog("RUNUSER: Cannot run " + todo.Filename + " as user " + todo.Username + ": " + ee.ToString(), EventLogEntryType.Warning); res.Result = 0x00000000FFFFFFFF & ee.NativeErrorCode; Debug.WriteLine(ee.ToString()); } catch (Exception ee) { FoxEventLog.VerboseWriteEventLog("RUNUSER: Cannot run " + todo.Filename + " as user " + todo.Username + ": " + ee.ToString(), EventLogEntryType.Warning); res.Result = 0x8000ffff; Debug.WriteLine(ee.ToString()); } p2p.SetResult(res); break; } case "conredir": { DataHRunConredir R = p2p.GetTODO <DataHRunConredir>(); MainSTDIORedir.RunPipeConsoleEnd(p2p, R); break; } default: FoxEventLog.VerboseWriteEventLog("Action " + Action + " from pipe " + ProgramAgent.PipeGUID + "?? häh???", EventLogEntryType.Warning); return; } }
public static bool DoSyncPolicy() { RequestCertPolicyID = 0; RequestCertPolicyMessageID = 0; RequestCertPolicyCERData = null; List <Int64> ProcessedPolicies = new List <long>(); Network net; net = Utilities.ConnectNetwork(9); if (net == null) { return(false); } Status.UpdateMessage(9, "Downloading client settings"); FoxEventLog.VerboseWriteEventLog("Downloading client settings", System.Diagnostics.EventLogEntryType.Information); ClientSettings settings = net.GetClientSettings(); if (settings != null) { RegistryData.AdministratorName = settings.AdministratorName; RegistryData.MessageDisclaimer = settings.MessageDisclaimer; } Status.UpdateMessage(9, "Downloading policies"); FoxEventLog.VerboseWriteEventLog("Downloading policies", System.Diagnostics.EventLogEntryType.Information); PolicyObjectListSigned policieslistsigned = net.GetPoliciesForComputer(); List <PolicyObjectSigned> policies = policieslistsigned == null ? null : policieslistsigned.Items; if (policies == null) { FoxEventLog.VerboseWriteEventLog("Downloading policies - nix", System.Diagnostics.EventLogEntryType.Information); Status.UpdateMessage(9); net.CloseConnection(); return(true); } if (FilesystemData.LoadedCertificates.Count > 0) { bool SignatureOK = false; foreach (FilesystemCertificateData cer in FilesystemData.LoadedCertificates) { if (Certificates.Verify(policieslistsigned, cer.Certificate) == true) { SignatureOK = true; break; } } if (SignatureOK == false) { FoxEventLog.WriteEventLog("Invalid signature for PolicyList - no policies will be processed.", System.Diagnostics.EventLogEntryType.Error); net.CloseConnection(); return(true); } } if (RegistryData.Verbose == 1) { string data = "Got policy:\r\n"; foreach (PolicyObjectSigned obj in policies) { data += obj.Policy.Name + " [ID: " + obj.Policy.ID + " VER: " + obj.Policy.Version + "]\r\n"; } FoxEventLog.VerboseWriteEventLog("Downloading policies " + data, System.Diagnostics.EventLogEntryType.Information); } if (FilesystemData.LoadedCertificates.Count > 0) { foreach (PolicyObjectSigned obj in policies) { if (ApplicationCertificate.Verify(obj) == false) { FoxEventLog.WriteEventLog("One or more policies were tampered - no policies will be processed.", System.Diagnostics.EventLogEntryType.Error); net.CloseConnection(); return(true); } } } #region Certificate Checks foreach (PolicyObjectSigned obj in policies) { if (obj.Policy.Type == PolicyIDs.SignCertificate) { if (FilesystemData.ContainsPolicy(obj.Policy, false, false) == true) { continue; } PolicyObjectSigned objj = net.GetPolicyObjectSigned(obj.Policy.ID); //do not verify signing here - that won't work! - Fox PolicySigningCertificates Cert = JsonConvert.DeserializeObject <PolicySigningCertificates>(objj.Policy.Data); if (FilesystemData.ContainsLoadedCert(Convert.FromBase64String(Cert.UUCerFile)) == true) { continue; } bool sig = Certificates.Verify(Convert.FromBase64String(Cert.UUCerFile), Convert.FromBase64String(Cert.UUSignFile), InternalCertificate.Main); if (sig == false) { RequestCertPolicyID = objj.Policy.ID; RequestCertPolicyCERData = Convert.FromBase64String(Cert.UUCerFile); string CN = Certificates.GetCN(Convert.FromBase64String(Cert.UUCerFile)); if (CN == null) { FoxEventLog.WriteEventLog("Invalid certificate from server (Policy ID=" + objj.Policy.ID.ToString() + " Name=" + objj.Policy.Name + ")", System.Diagnostics.EventLogEntryType.Error); continue; } Status.RequestCertificateConfirm("The certificate with " + CN + " is not signed by Vulpes. This may that someone tampered the connection, or a false certificate is installed on the server.\nDo you want to continue, and trust this certificate?", RequestCertPolicyID); RequestCertPolicyMessageID = Status.MessageID; FoxEventLog.WriteEventLog("Got unsinged certificate (Policy ID=" + objj.Policy.ID.ToString() + " Name=" + objj.Policy.Name + " " + CN + ")", System.Diagnostics.EventLogEntryType.Warning); } else { string CN = Certificates.GetCN(Convert.FromBase64String(Cert.UUCerFile)); if (CN == null) { FoxEventLog.WriteEventLog("Invalid (Vulpes signed) certificate from server (Policy ID=" + objj.Policy.ID.ToString() + " Name=" + objj.Policy.Name + ")", System.Diagnostics.EventLogEntryType.Error); continue; } FilesystemData.InstallCertificate(Convert.FromBase64String(Cert.UUCerFile)); } } } #endregion if (FilesystemData.LoadedCertificates.Count > 0) { foreach (PolicyObjectSigned obj in policies) { if (FilesystemData.ContainsPolicy(obj.Policy, false, false) == true) { if (ProcessedPolicies.Contains(obj.Policy.ID) == false) { ProcessedPolicies.Add(obj.Policy.ID); } FilesystemData.UpdatePolicyOrder(obj.Policy, obj.Policy.Order); continue; } PolicyObjectSigned objj = net.GetPolicyObjectSigned(obj.Policy.ID); if (objj == null) { FoxEventLog.WriteEventLog("No data for policy - not applying (Policy ID=" + obj.Policy.ID.ToString() + " Name=" + obj.Policy.Name + ")", System.Diagnostics.EventLogEntryType.Error); continue; } if (ApplicationCertificate.Verify(objj) == false) { FoxEventLog.WriteEventLog("Policy was tampered - not applying (Policy ID=" + objj.Policy.ID.ToString() + " Name=" + objj.Policy.Name + ")", System.Diagnostics.EventLogEntryType.Error); continue; } if (FilesystemData.InstallPolicy(objj.Policy, obj.Policy.Order) == false) { continue; } if (ProcessedPolicies.Contains(obj.Policy.ID) == false) { ProcessedPolicies.Add(obj.Policy.ID); } } List <LoadedPolicyObject> RemovePol = new List <LoadedPolicyObject>(); foreach (LoadedPolicyObject lobj in FilesystemData.LoadedPolicyObjects) { if (ProcessedPolicies.Contains(lobj.PolicyObject.ID) == false) { RemovePol.Add(lobj); } } foreach (LoadedPolicyObject lobj in RemovePol) { FilesystemData.DeletePolicy(lobj); } } net.CloseConnection(); if (RequestCertPolicyID == 0) { Status.UpdateMessage(9); } FoxEventLog.VerboseWriteEventLog("Downloading policies - DONE", System.Diagnostics.EventLogEntryType.Information); return(true); }
static public void RemovePackage(PackagesToInstall Package, bool ForceRemove = false) { if (LocalPackages == null) { return; } string PackagesFolder = SystemInfos.ProgramData + "Packages\\"; if (Directory.Exists(PackagesFolder) == false) { Directory.CreateDirectory(PackagesFolder); } PackagesToInstall pkg = null; foreach (PackagesToInstall pp in LocalPackages) { if (Package == pp) { pkg = pp; break; } } if (pkg == null) { return; } LocalPackageData rmlpkg = null; foreach (LocalPackageData lpkg in LocalPackageDataList) { if (lpkg.PackageID == pkg.PackageID && lpkg.Version == pkg.Version) { rmlpkg = lpkg; break; } } if (ForceRemove == false) { if (rmlpkg != null) { if (rmlpkg.PKGRecieptFilename != null) { FoxEventLog.VerboseWriteEventLog("Not removing Package: " + pkg.PackageID + " V" + pkg.Version.ToString() + ". Reciept file is registred.", EventLogEntryType.Warning); if (pkg.Filename != null) { if (File.Exists(PackagesFolder + pkg.Filename) == true) { CommonUtilities.SpecialDeleteFile(PackagesFolder + pkg.Filename); } pkg.Filename = null; } rmlpkg.ServerHasPackage = false; return; } } } if (pkg.MetaFilename != null) { if (File.Exists(PackagesFolder + pkg.MetaFilename) == true) { CommonUtilities.SpecialDeleteFile(PackagesFolder + pkg.MetaFilename); } } if (pkg.Filename != null) { if (File.Exists(PackagesFolder + pkg.Filename) == true) { CommonUtilities.SpecialDeleteFile(PackagesFolder + pkg.Filename); } } LocalPackages.Remove(pkg); WritePackageList(); if (rmlpkg != null) { if (rmlpkg.PKGRecieptFilename != null) { CommonUtilities.SpecialDeleteFile(PackagesFolder + rmlpkg.PKGRecieptFilename); CommonUtilities.SpecialDeleteFile(PackagesFolder + rmlpkg.PKGRecieptFilename + ".sign"); } LocalPackageDataList.Remove(rmlpkg); WritePackageDataList(); } }