예제 #1
0
 public void CheckApplicationInstanceCertificateNoGeneratorTestMethod1()
 {
     using (Main _main = new Main())
     {
         _main.CreateDefaultConfiguration();
         CASConfiguration _default = _main.Configuration;
         Assert.IsNotNull(_default);
         X509Certificate2 _certificate = ApplicationCertificate.CheckApplicationInstanceCertificate(_default, 1028, (x, y) => true, false);
     }
 }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServerForm"/> class.
 /// </summary>
 /// <param name="server">The server.</param>
 /// <param name="configuration">The configuration.</param>
 /// <param name="application">The application.</param>
 public ServerForm(StandardServer server, ApplicationConfiguration configuration, CASApplicationInstance application)
 {
     InitializeComponent();
     m_application = application;
     m_server      = server;
     this.ServerDiagnosticsCTRL.Initialize(m_server, configuration);
     ApplicationCertificate.DisplayUaTcpImplementation(x => this.Text = x, this.Text, configuration);
     m_server.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);
     TrayIcon.Text = this.Text;
 }
예제 #3
0
파일: Program.cs 프로젝트: sparkeh9/LibUA
            public override IList <EndpointDescription> GetEndpointDescriptions(string endpointUrlHint)
            {
                var certStr = ApplicationCertificate.Export(X509ContentType.Cert);

                var epNoSecurity = new EndpointDescription(
                    endpointUrlHint, uaAppDesc, null,
                    MessageSecurityMode.None, Types.SLSecurityPolicyUris[(int)SecurityPolicy.None],
                    new UserTokenPolicy[]
                {
                    new UserTokenPolicy("0", UserTokenType.Anonymous, null, null, Types.SLSecurityPolicyUris[(int)SecurityPolicy.None]),
                }, Types.TransportProfileBinary, 0);

                var epSignBasic128Rsa15 = new EndpointDescription(
                    endpointUrlHint, uaAppDesc, certStr,
                    MessageSecurityMode.Sign, Types.SLSecurityPolicyUris[(int)SecurityPolicy.Basic128Rsa15],
                    new UserTokenPolicy[]
                {
                    new UserTokenPolicy("0", UserTokenType.Anonymous, null, null, Types.SLSecurityPolicyUris[(int)SecurityPolicy.Basic128Rsa15]),
                    new UserTokenPolicy("1", UserTokenType.UserName, null, null, Types.SLSecurityPolicyUris[(int)SecurityPolicy.Basic128Rsa15]),
                }, Types.TransportProfileBinary, 0);

                var epSignBasic256 = new EndpointDescription(
                    endpointUrlHint, uaAppDesc, certStr,
                    MessageSecurityMode.Sign, Types.SLSecurityPolicyUris[(int)SecurityPolicy.Basic256],
                    new UserTokenPolicy[]
                {
                    new UserTokenPolicy("0", UserTokenType.Anonymous, null, null, Types.SLSecurityPolicyUris[(int)SecurityPolicy.Basic256]),
                    new UserTokenPolicy("1", UserTokenType.UserName, null, null, Types.SLSecurityPolicyUris[(int)SecurityPolicy.Basic256]),
                }, Types.TransportProfileBinary, 0);

                var epSignEncryptBasic128Rsa15 = new EndpointDescription(
                    endpointUrlHint, uaAppDesc, certStr,
                    MessageSecurityMode.SignAndEncrypt, Types.SLSecurityPolicyUris[(int)SecurityPolicy.Basic128Rsa15],
                    new UserTokenPolicy[]
                {
                    new UserTokenPolicy("0", UserTokenType.Anonymous, null, null, Types.SLSecurityPolicyUris[(int)SecurityPolicy.Basic128Rsa15]),
                    new UserTokenPolicy("1", UserTokenType.UserName, null, null, Types.SLSecurityPolicyUris[(int)SecurityPolicy.Basic128Rsa15]),
                }, Types.TransportProfileBinary, 0);

                var epSignEncryptBasic256 = new EndpointDescription(
                    endpointUrlHint, uaAppDesc, certStr,
                    MessageSecurityMode.SignAndEncrypt, Types.SLSecurityPolicyUris[(int)SecurityPolicy.Basic256],
                    new UserTokenPolicy[]
                {
                    new UserTokenPolicy("0", UserTokenType.Anonymous, null, null, Types.SLSecurityPolicyUris[(int)SecurityPolicy.Basic256]),
                    new UserTokenPolicy("1", UserTokenType.UserName, null, null, Types.SLSecurityPolicyUris[(int)SecurityPolicy.Basic256]),
                }, Types.TransportProfileBinary, 0);

                return(new EndpointDescription[]
                {
                    epNoSecurity,
                    epSignBasic128Rsa15, epSignBasic256,
                    epSignEncryptBasic128Rsa15, epSignEncryptBasic256
                });
            }
예제 #4
0
 public void DisplayUaTcpImplementationForDefaultConfigurationTest()
 {
     using (Main _main = new Main())
     {
         _main.CreateDefaultConfiguration();
         CASConfiguration _default  = _main.Configuration;
         string           _result   = null;
         string           _formText = "Form text";
         ApplicationCertificate.DisplayUaTcpImplementation(x => _result = x, _formText, _default);
         Assert.IsNull(_result);
     }
 }
예제 #5
0
 public void DisplayUaTcpImplementationForDemoConfigurationTest()
 {
     using (Main _main = new Main())
     {
         _main.ReadConfiguration(AssemblyInitializeClass.CASConfigurationFileInfo);
         Assert.IsNotNull(_main.Configuration);
         Assert.AreEqual <int>(0, _main.Configuration.TransportConfigurations.Count); //TODO the configuration contains empty array ??!
         string _result   = null;
         string _formText = "Form text";
         ApplicationCertificate.DisplayUaTcpImplementation(x => _result = x, _formText, _main.Configuration);
         Assert.IsNull(_result);
     }
 }
예제 #6
0
 /// <summary>
 /// Handles a certificate validation error.
 /// </summary>
 /// <param name="validator">The validator.</param>
 /// <param name="e">The <see cref="Opc.Ua.CertificateValidationEventArgs"/> instance containing the event data.</param>
 private void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
 {
     try
     {
         string message = ApplicationCertificate.HandleCertificateValidationError(e);
         if (MessageBox.Show(message, this.Text, MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             e.Accept = true;
         }
     }
     catch (Exception exception)
     {
         HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
     }
 }
예제 #7
0
 public void OverrideUaTcpImplementationTest()
 {
     using (ShimsContext.Create())
     {
         System.Fakes.ShimEnvironment.GetCommandLineArgs = () => { return(new string[] { "Application name", "-uaTcpAnsiC" }); };
         ApplicationConfiguration _newTcpSettings = new ApplicationConfiguration()
         {
             TransportConfigurations = new TransportConfigurationCollection(new TransportConfiguration[] { new TransportConfiguration()
                                                                                                           {
                                                                                                               TypeName = "TypeName", UriScheme = Utils.UriSchemeOpcTcp
                                                                                                           } })
         };
         ApplicationCertificate.OverrideUaTcpImplementation(_newTcpSettings);
         Assert.IsNotNull(_newTcpSettings.TransportConfigurations);
         Assert.AreEqual <int>(1, _newTcpSettings.TransportConfigurations.Count);
         Assert.AreEqual <string>(Utils.UaTcpBindingNativeStack, _newTcpSettings.TransportConfigurations[0].TypeName);
     }
 }
예제 #8
0
        static void PushThread()
        {
            Network      net = null;
            PushDataRoot pd;
            int          Crashes = 0;

            do
            {
                try
                {
                    if (net == null)
                    {
                        net = Utilities.ConnectNetwork(-1);
                    }

                    if (net == null)
                    {
                        FoxEventLog.VerboseWriteEventLog("Push0: no connection", System.Diagnostics.EventLogEntryType.Information);
                        for (int i = 0; i < WaitNoConnection; i++)
                        {
                            Thread.Sleep(1000);
                            if (StopThread == true)
                            {
                                return;
                            }
                        }
                        continue;
                    }
                    pd = net.GetPushData0();
                    if (pd == null)
                    {
                        FoxEventLog.VerboseWriteEventLog("Push0: pd==null", System.Diagnostics.EventLogEntryType.Information);
                        for (int i = 0; i < WaitPDisNULL; i++)
                        {
                            Thread.Sleep(1000);
                            if (StopThread == true)
                            {
                                return;
                            }
                        }
                        pd = net.GetPushData0();
                        if (pd == null)
                        {
                            net = null;
                            FoxEventLog.VerboseWriteEventLog("Push0: pd==null - 2nd time - resetting connection", System.Diagnostics.EventLogEntryType.Information);
                            for (int i = 0; i < WaitPDisNULL2; i++)
                            {
                                Thread.Sleep(1000);
                                if (StopThread == true)
                                {
                                    return;
                                }
                            }
                            continue;
                        }
                    }
                    if (ApplicationCertificate.Verify(pd) == false)
                    {
                        FoxEventLog.WriteEventLog("Push0: One or more PushData were tampered - no PushData will be processed.", System.Diagnostics.EventLogEntryType.Error);
                        for (int i = 0; i < WaitTamperIssue; i++)
                        {
                            Thread.Sleep(1000);
                            if (StopThread == true)
                            {
                                return;
                            }
                        }
                        continue;
                    }
                    Crashes = 0;

                    if (pd.Data.Action == "repeat")
                    {
                        if (StopThread == true)
                        {
                            return;
                        }
                        FoxEventLog.VerboseWriteEventLog("Push0: repeat", System.Diagnostics.EventLogEntryType.Information);
                        continue;
                    }
                    if (pd.Data.Action == "quit")
                    {
                        FoxEventLog.VerboseWriteEventLog("Push0: quit", System.Diagnostics.EventLogEntryType.Information);
                        net = null;
                        for (int i = 0; i < WaitQuit; i++)
                        {
                            Thread.Sleep(1000);
                            if (StopThread == true)
                            {
                                return;
                            }
                        }
                        continue;
                    }
                    if (pd.Data.Action == "stdin")
                    {
                        Redirs.MainSTDIORedir.ProcessStdInAgent(pd.Data.AdditionalData1);
                        continue;
                    }

                    Thread a = new Thread(new ParameterizedThreadStart(PushThreadActionRunner));
                    PushDataForThreadRunner t = new PushDataForThreadRunner();
                    t.net = net.CloneElement();
                    t.p   = pd.Data;
                    a.Start(t);
                }
                catch (Exception ee)
                {
                    Debug.WriteLine(ee.ToString());
                    FoxEventLog.VerboseWriteEventLog("Push0: SEH internally", System.Diagnostics.EventLogEntryType.Information);
                    Crashes++;
                    if (Crashes > 3)
                    {
                        FoxEventLog.VerboseWriteEventLog("Push0: Resetting connection due too many crashes", System.Diagnostics.EventLogEntryType.Information);
                        net     = null;
                        Crashes = 0;
                    }
                    for (int i = 0; i < WaitCrash; i++)
                    {
                        Thread.Sleep(1000);
                        if (StopThread == true)
                        {
                            return;
                        }
                    }
                }
            } while (StopThread == false);
        }
예제 #9
0
        static void PushThread()
        {
            Network      net = null;
            PushDataRoot pd;
            int          Crashes    = 0;
            DateTime?    ChatPickup = null;

            do
            {
                try
                {
                    if (net == null)
                    {
                        net = Utilities.ConnectNetwork(-1);
                    }

                    if (net == null)
                    {
                        FoxEventLog.VerboseWriteEventLog("Push10: no connection", System.Diagnostics.EventLogEntryType.Information);
                        for (int i = 0; i < WaitNoConnection; i++)
                        {
                            Thread.Sleep(1000);
                            if (StopThread == true)
                            {
                                return;
                            }
                        }
                        continue;
                    }

                    ConfirmPopMessage(net);
                    if (ChatPickup == null)
                    {
                        ChatPickup = DateTime.UtcNow.AddDays(-1);
                    }
                    if ((DateTime.UtcNow - ChatPickup.Value).TotalMinutes > ChatPickupPeriodMin)
                    {
                        PickupMessages(net);
                        ChatPickup = DateTime.UtcNow;
                    }

                    pd = net.GetPushData10();
                    if (pd == null)
                    {
                        FoxEventLog.VerboseWriteEventLog("Push10: pd==null", System.Diagnostics.EventLogEntryType.Information);
                        for (int i = 0; i < WaitPDisNULL; i++)
                        {
                            Thread.Sleep(1000);
                            if (StopThread == true)
                            {
                                return;
                            }
                        }
                        pd = net.GetPushData10();
                        if (pd == null)
                        {
                            net = null;
                            FoxEventLog.VerboseWriteEventLog("Push10: pd==null - 2nd time - resetting connection", System.Diagnostics.EventLogEntryType.Information);
                            for (int i = 0; i < WaitPDisNULL2; i++)
                            {
                                Thread.Sleep(1000);
                                if (StopThread == true)
                                {
                                    return;
                                }
                            }
                            continue;
                        }
                    }
                    if (ApplicationCertificate.Verify(pd) == false)
                    {
                        FoxEventLog.WriteEventLog("Push10: One or more PushData were tampered - no PushData will be processed.", System.Diagnostics.EventLogEntryType.Error);
                        for (int i = 0; i < WaitTamperIssue; i++)
                        {
                            Thread.Sleep(1000);
                            if (StopThread == true)
                            {
                                return;
                            }
                        }
                        continue;
                    }
                    Crashes = 0;

                    if (pd.Data.Action == "repeat")
                    {
                        if (StopThread == true)
                        {
                            return;
                        }
                        FoxEventLog.VerboseWriteEventLog("Push10: repeat", System.Diagnostics.EventLogEntryType.Information);
                        continue;
                    }
                    if (pd.Data.Action == "quit")
                    {
                        FoxEventLog.VerboseWriteEventLog("Push10: quit", System.Diagnostics.EventLogEntryType.Information);
                        net = null;
                        for (int i = 0; i < WaitQuit; i++)
                        {
                            Thread.Sleep(1000);
                            if (StopThread == true)
                            {
                                return;
                            }
                        }
                        continue;
                    }

                    Thread a = new Thread(new ParameterizedThreadStart(PushThreadActionRunner));
                    PushDataForThreadRunner t = new PushDataForThreadRunner();
                    t.net = net.CloneElement2();
                    t.p   = pd.Data;
                    a.Start(t);
                }
                catch (Exception ee)
                {
                    Debug.WriteLine(ee.ToString());
                    FoxEventLog.VerboseWriteEventLog("Push10: SEH internally", System.Diagnostics.EventLogEntryType.Information);
                    Crashes++;
                    if (Crashes > 3)
                    {
                        FoxEventLog.VerboseWriteEventLog("Push10: Resetting connection due too many crashes", System.Diagnostics.EventLogEntryType.Information);
                        net     = null;
                        Crashes = 0;
                    }
                    for (int i = 0; i < WaitCrash; i++)
                    {
                        Thread.Sleep(1000);
                        if (StopThread == true)
                        {
                            return;
                        }
                    }
                }
            } while (StopThread == false);
        }
예제 #10
0
        static int Main()
        {
            FoxEventLog.Shutup = true;
            string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            if (dir.EndsWith("\\") == false)
            {
                dir += "\\";
            }

            ProgramAgent.Init();

            if (ProgramAgent.LoadDLL() == false)
            {
                return(1);
            }

            if (SystemInfos.CollectSystemInfo() != 0)
            {
                return(1);
            }

            if (ApplicationCertificate.LoadCertificate() == false)
            {
                FoxEventLog.WriteEventLog("Cannot load certificate", System.Diagnostics.EventLogEntryType.Error);
                return(1);
            }

            if (FilesystemData.LoadCertificates() == false)
            {
                return(1);
            }
            if (FilesystemData.LoadPolicies() == false)
            {
                return(1);
            }
            FilesystemData.LoadLocalPackageData();
            FilesystemData.LoadLocalPackages();
            FilesystemData.LoadUserPackageData();
            FilesystemData.LoadEventLogList();

            FoxEventLog.Shutup = false;

            if (SyncPolicy.ApplyPolicy(SyncPolicy.ApplyPolicyFunction.Uninstall) == false)
            {
                return(5);
            }

            ServiceController svc = new ServiceController("FoxSDCA");

            try
            {
                svc.Stop();
            }
            catch
            {
            }

            int i = 0;

            do
            {
                i++;
                if (i > 120 * 4)
                {
                    break;
                }
                svc.Refresh();
                Thread.Sleep(1000);
            } while (svc.Status != ServiceControllerStatus.Stopped);

            #region Kill Processes

            foreach (Process proc in Process.GetProcesses())
            {
                try
                {
                    if (proc.MainModule.FileName.ToLower() == dir.ToLower() + "foxsdc_agent_ui.exe")
                    {
                        proc.Kill();
                    }
                }
                catch
                {
                }
            }

            foreach (Process proc in Process.GetProcesses())
            {
                try
                {
                    if (proc.MainModule.FileName.ToLower() == dir.ToLower() + "foxsdc_applyusersettings.exe")
                    {
                        proc.Kill();
                    }
                }
                catch
                {
                }
            }

            foreach (Process proc in Process.GetProcesses())
            {
                try
                {
                    if (proc.MainModule.FileName.ToLower() == dir.ToLower() + "foxsdc_agent.exe")
                    {
                        proc.Kill();
                    }
                }
                catch
                {
                }
            }

            #endregion

            try
            {
                RegistryKey reg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                reg.DeleteValue("FoxSDCAgent", false);
                reg.DeleteValue("FoxSDCAgentApply", false);
                reg.Close();
            }
            catch
            {
            }

            try
            {
                Process.Start(Environment.ExpandEnvironmentVariables("%systemroot%\\system32\\msiexec.exe"), "/x {A6F066EE-E795-4C65-8FE4-2D93AB52BC36} /passive");
            }
            catch
            {
            }
            return(0);
        }
예제 #11
0
 public void HandleCertificateValidationErrorTestMethod()
 {
     ApplicationCertificate.HandleCertificateValidationError(null);
 }
예제 #12
0
        static int Main(string[] args)
        {
            foreach (string arg in args)
            {
                if (arg.ToLower() == "-nopackages")
                {
                    NoPackages = true;
                }
            }

            FoxEventLog.Shutup = true;

            ProgramAgent.Init();

            if (ProgramAgent.LoadDLL() == false)
            {
                return(1);
            }

            FoxEventLog.Shutup = false;
#if !DEBUG
            List <string> Additionals = new List <string>();
            Additionals.Add(Assembly.GetExecutingAssembly().Location);
            if (ProgramAgent.TestIntegrity(Additionals) == false)
            {
                FoxEventLog.WriteEventLog("Apply User settings: Integrity failed!", EventLogEntryType.Error, true);
                return(1);
            }
#endif

            FoxEventLog.Shutup = true;

            if (SystemInfos.CollectSystemInfo() != 0)
            {
                return(1);
            }

            if (ApplicationCertificate.LoadCertificate() == false)
            {
                FoxEventLog.Shutup = false;
                FoxEventLog.WriteEventLog("Apply User settings: Cannot load certificate", System.Diagnostics.EventLogEntryType.Error);
                return(1);
            }

            FoxEventLog.Shutup = false;

            if (FilesystemData.LoadCertificates(true) == false)
            {
                return(1);
            }
            if (FilesystemData.LoadPolicies() == false)
            {
                return(1);
            }
            FilesystemData.LoadLocalPackageData();
            FilesystemData.LoadLocalPackages();
            FilesystemData.LoadUserPackageData();
            FilesystemData.LoadEventLogList();

            SyncPolicy.ApplyPolicy(SyncPolicy.ApplyPolicyFunction.ApplyUser);

            if (NoPackages == true)
            {
                return(0);
            }

            string PackagesFolder = SystemInfos.ProgramData + "Packages\\";
            if (Directory.Exists(PackagesFolder) == false)
            {
                return(2);
            }

            foreach (PackagesToInstall pkg in FilesystemData.LocalPackages)
            {
                LocalPackageData lpkg = FilesystemData.FindLocalPackageFromListLatest(pkg.PackageID);
                if (lpkg == null)
                {
                    continue;
                }
                if (pkg.Version != lpkg.Version)
                {
                    continue;
                }

                PackageInstaller inst     = new PackageInstaller();
                string           metafile = PackagesFolder + pkg.MetaFilename;
                if (File.Exists(metafile) == false)
                {
                    continue;
                }
                string         Error;
                PKGRecieptData Reciept;
                PKGStatus      res;
                if (inst.InstallPackage(metafile, PackageCertificate.ActivePackageCerts, PackageInstaller.InstallMode.ApplyUserSettingsTest, true, out Error, out res, out Reciept) == false)
                {
                    FoxEventLog.WriteEventLog("Apply User settings: The Metapackage " + pkg.MetaFilename + " cannot be tested: " + Error, System.Diagnostics.EventLogEntryType.Error);
                    continue;
                }
                FoxEventLog.VerboseWriteEventLog("Apply User settings: Applying user settings for " + pkg.MetaFilename, EventLogEntryType.Information);
                if (inst.ApplyUserSettings(metafile, PackageCertificate.ActivePackageCerts, out Error, out res) == false)
                {
                    FoxEventLog.WriteEventLog("Apply User settings: The Metapackage " + pkg.MetaFilename + " cannot be used to apply user settings: " + Error, System.Diagnostics.EventLogEntryType.Error);
                    continue;
                }
            }

            if (RegistryData.Verbose == 1)
            {
                FoxEventLog.VerboseWriteEventLog("Apply User settings: ApplyUserSettings success for " + Environment.UserDomainName + "\\" + Environment.UserName, EventLogEntryType.Information);
            }

            return(0);
        }