Пример #1
0
        public MainForm(ApplicationInstance application)
        {
            InitializeComponent();
            Icon = ClientUtils.GetAppIcon();

            m_application = application;

            // get the configuration.
            m_configuration = m_application.ApplicationConfiguration.ParseExtension <GlobalDiscoveryClientConfiguration>();

            // use suitable defaults if no configuration exists.
            if (m_configuration == null)
            {
                m_configuration = new GlobalDiscoveryClientConfiguration()
                {
                    GlobalDiscoveryServerUrl = "opc.tcp://localhost:58810/GlobalDiscoveryServer",
                    ExternalEditor           = "notepad.exe"
                };
            }

            m_filters                         = new QueryServersFilter();
            m_identity                        = new UserIdentity();
            m_gds                             = new GlobalDiscoveryServerMethods(m_application, m_configuration);
            m_gds.KeepAlive                  += GdsServer_KeepAlive;
            m_gds.ServerStatusChanged        += GdsServer_StatusNotification;
            m_lds                             = new LocalDiscoveryServerMethods(m_application.ApplicationConfiguration);
            m_server                          = new ServerPushConfigurationMethods(m_application);
            m_server.KeepAlive               += Server_KeepAlive;
            m_server.ServerStatusChanged     += Server_StatusNotification;
            m_server.ConnectionStatusChanged += Server_ConnectionStatusChanged;

            RegistrationPanel.Initialize(m_gds, null, m_configuration);

            m_application.ApplicationConfiguration.CertificateValidator.CertificateValidation += CertificateValidator_CertificateValidation;
            UpdateStatus(true, DateTime.MinValue, "---");
            UpdateGdsStatus(true, DateTime.MinValue, "---");

            ShowPanel(Panel.None);

            SelectServerButton.Enabled     = false;
            ServerStatusButton.Enabled     = false;
            CertificateButton.Enabled      = false;
            HttpsCertificateButton.Visible = false;
            TrustListButton.Enabled        = false;
            HttpsTrustListButton.Visible   = false;
        }
Пример #2
0
        public void Initialize(GlobalDiscoveryServerMethods gds, ServerPushConfigurationMethods server, RegisteredApplication application, bool isHttps)
        {
            m_gds         = gds;
            m_server      = server;
            m_application = application;

            // display local trust list.
            if (application != null)
            {
                m_trustListStorePath  = (isHttps) ? m_application.HttpsTrustListStorePath : m_application.TrustListStorePath;
                m_issuerListStorePath = (isHttps) ? m_application.HttpsIssuerListStorePath : m_application.IssuerListStorePath;
                CertificateStoreControl.Initialize(m_trustListStorePath, m_issuerListStorePath, null);
                MergeWithGdsButton.Enabled = !String.IsNullOrEmpty(m_trustListStorePath);
            }

            ApplyChangesButton.Enabled = false;
        }
Пример #3
0
        public async Task Initialize(
            GlobalDiscoveryClientConfiguration configuration,
            GlobalDiscoveryServerMethods gds,
            ServerPushConfigurationMethods server,
            RegisteredApplication application,
            bool isHttps)
        {
            m_configuration       = configuration;
            m_gds                 = gds;
            m_server              = server;
            m_application         = application;
            m_certificate         = null;
            m_certificatePassword = null;

            CertificateRequestTimer.Enabled = false;
            RequestProgressLabel.Visible    = false;
            ApplyChangesButton.Enabled      = false;

            CertificateControl.ShowNothing();

            X509Certificate2 certificate = null;

            if (!isHttps)
            {
                if (server.Endpoint != null && server.Endpoint.Description.ServerCertificate != null)
                {
                    certificate = new X509Certificate2(server.Endpoint.Description.ServerCertificate);
                }
                else if (application != null)
                {
                    if (!String.IsNullOrEmpty(application.CertificatePublicKeyPath))
                    {
                        string file = Utils.GetAbsoluteFilePath(application.CertificatePublicKeyPath, true, false, false);

                        if (file != null)
                        {
                            certificate = new X509Certificate2(file);
                        }
                    }
                    else if (!String.IsNullOrEmpty(application.CertificateStorePath))
                    {
                        CertificateIdentifier id = new CertificateIdentifier
                        {
                            StorePath = application.CertificateStorePath
                        };
                        id.StoreType   = CertificateStoreIdentifier.DetermineStoreType(id.StorePath);
                        id.SubjectName = application.CertificateSubjectName.Replace("localhost", Utils.GetHostName());

                        certificate = await id.Find(true);
                    }
                }
            }
            else
            {
                if (application != null)
                {
                    if (!String.IsNullOrEmpty(application.HttpsCertificatePublicKeyPath))
                    {
                        string file = Utils.GetAbsoluteFilePath(application.HttpsCertificatePublicKeyPath, true, false, false);

                        if (file != null)
                        {
                            certificate = new X509Certificate2(file);
                        }
                    }
                    else
                    {
                        foreach (string disoveryUrl in application.DiscoveryUrl)
                        {
                            if (Uri.IsWellFormedUriString(disoveryUrl, UriKind.Absolute))
                            {
                                Uri url = new Uri(disoveryUrl);

                                CertificateIdentifier id = new CertificateIdentifier()
                                {
                                    StoreType   = CertificateStoreType.X509Store,
                                    StorePath   = "CurrentUser\\UA_MachineDefault",
                                    SubjectName = "CN=" + url.DnsSafeHost
                                };

                                certificate = await id.Find();
                            }
                        }
                    }
                }
            }

            if (certificate != null)
            {
                try
                {
                    CertificateControl.Tag = certificate.Thumbprint;
                }
                catch (Exception)
                {
                    MessageBox.Show(
                        Parent,
                        "The certificate does not appear to be valid. Please check configuration settings.",
                        Parent.Text,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);

                    certificate = null;
                }
            }

            WarningLabel.Visible = certificate == null;

            if (certificate != null)
            {
                m_certificate = certificate;
                CertificateControl.ShowValue(null, "Application Certificate", new CertificateWrapper()
                {
                    Certificate = certificate
                }, true);
            }
        }
 public void Initialize(ServerPushConfigurationMethods server)
 {
     m_server = server;
     ServerBrowseControl.Initialize((server != null) ? server.Session : null, Opc.Ua.ObjectIds.ObjectsFolder, ReferenceTypeIds.HierarchicalReferences);
 }