Beispiel #1
0
        public void Initialize(GlobalDiscoveryServerClient gds, ServerPushConfigurationClient 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) || m_application.RegistrationType == RegistrationType.ServerPush;
            }

            ApplyChangesButton.Enabled = false;
        }
Beispiel #2
0
        private async void RegistrationPanel_RegisteredApplicationChangedAsync(object sender, RegisteredApplicationChangedEventArgs e)
        {
            try
            {
                var app = m_registeredApplication = e.Application;

                if (app == null || app.RegistrationType == RegistrationType.ClientPull)
                {
                    SetServer(null);
                }
                else if (app.RegistrationType == RegistrationType.ServerPush)
                {
                    if (!String.IsNullOrEmpty(app.ServerUrl))
                    {
                        var endpoint = new EndpointDescription(app.ServerUrl);

                        endpoint.Server.ApplicationType = ApplicationType.Server;
                        endpoint.Server.ApplicationUri  = app.ApplicationUri;
                        endpoint.Server.ProductUri      = app.ProductUri;
                        endpoint.Server.ApplicationName = app.ApplicationName;
                        endpoint.Server.DiscoveryUrls   = (app.DiscoveryUrl != null) ? new StringCollection(app.DiscoveryUrl) : null;

                        SetServer(endpoint);
                    }
                }

                CertificateButton.Enabled = (e.Application != null);
                TrustListButton.Enabled   = (e.Application != null);
#if !NO_HTTPS
                HttpsCertificateButton.Visible = (e.Application != null && !String.IsNullOrEmpty(e.Application.GetHttpsDomainName()));
                HttpsTrustListButton.Visible   = (e.Application != null && !String.IsNullOrEmpty(e.Application.HttpsTrustListStorePath));
#endif
                await CertificatePanel.Initialize(m_configuration, m_gds, m_server, e.Application, false);

                TrustListPanel.Initialize(m_gds, m_server, e.Application, false);
                UpdateMainFormHeader();
            }
            catch (Exception ex)
            {
                Opc.Ua.Client.Controls.ExceptionDlg.Show(Text, ex);
            }
        }
        public async Task Initialize(
            GlobalDiscoveryClientConfiguration configuration,
            GlobalDiscoveryServerClient gds,
            ServerPushConfigurationClient 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);
            }
        }