Exemplo n.º 1
0
 private void ReloadTrustListButton_Click(object sender, EventArgs e)
 {
     try
     {
         if (m_application != null)
         {
             if (m_application.RegistrationType == RegistrationType.ServerPush)
             {
                 var trustList    = m_server.ReadTrustList();
                 var rejectedList = m_server.GetRejectedList();
                 CertificateStoreControl.Initialize(trustList, rejectedList, true);
             }
             else
             {
                 CertificateStoreControl.Initialize(m_trustListStorePath, m_issuerListStorePath, null);
             }
         }
         else
         {
             CertificateStoreControl.Initialize(null, null, null);
         }
     }
     catch (Exception ex)
     {
         Opc.Ua.Client.Controls.ExceptionDlg.Show(Text, ex);
     }
 }
Exemplo n.º 2
0
        private void PushToServerButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (m_application != null)
                {
                    if (m_application.RegistrationType == RegistrationType.ServerPush)
                    {
                        var trustList = CertificateStoreControl.GetTrustLists();

                        bool applyChanges = m_server.UpdateTrustList(trustList);

                        if (applyChanges)
                        {
                            MessageBox.Show(
                                Parent,
                                "The trust list was updated, however, the apply changes command must be sent before the server will use the new trust list.",
                                Parent.Text,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);

                            ApplyChangesButton.Enabled = true;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Opc.Ua.Client.Controls.ExceptionDlg.Show(Parent.Text, exception);
            }
        }
Exemplo n.º 3
0
 private void ReloadTrustListButton_Click(object sender, EventArgs e)
 {
     try
     {
         if (m_application != null)
         {
             if (m_application.RegistrationType == RegistrationType.ServerPush)
             {
                 var trustList = m_server.ReadTrustList();
                 CertificateStoreControl.Initialize(trustList);
             }
             else
             {
                 CertificateStoreControl.Initialize(m_trustListStorePath, m_issuerListStorePath, null);
             }
         }
         else
         {
             CertificateStoreControl.Initialize(null, null, null);
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show(Parent.Text + ": " + exception.Message);
     }
 }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
0
        private void PullFromGds(bool deleteBeforeAdd)
        {
            try
            {
                NodeId trustListId = m_gds.GetTrustList(m_application.ApplicationId, null);

                if (trustListId == null)
                {
                    CertificateStoreControl.Initialize(null, null, null);
                    return;
                }

                var trustList = m_gds.ReadTrustList(trustListId);

                if (m_application.RegistrationType == RegistrationType.ServerPush)
                {
                    CertificateStoreControl.Initialize(trustList, null, deleteBeforeAdd);

                    MessageBox.Show(
                        Parent,
                        "The trust list (include CRLs) was downloaded from the GDS. It now has to be pushed to the Server.",
                        Parent.Text,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information);

                    return;
                }

                if (!String.IsNullOrEmpty(m_trustListStorePath))
                {
                    if (deleteBeforeAdd)
                    {
                        DeleteExistingFromStore(m_trustListStorePath).Wait();
                        DeleteExistingFromStore(m_issuerListStorePath).Wait();;
                    }
                }

                if (!String.IsNullOrEmpty(m_trustListStorePath))
                {
                    using (ICertificateStore store = CertificateStoreIdentifier.OpenStore(m_trustListStorePath))
                    {
                        if ((trustList.SpecifiedLists & (uint)Opc.Ua.TrustListMasks.TrustedCertificates) != 0)
                        {
                            foreach (var certificate in trustList.TrustedCertificates)
                            {
                                var x509 = new X509Certificate2(certificate);

                                X509Certificate2Collection certs = store.FindByThumbprint(x509.Thumbprint).Result;
                                if (certs.Count == 0)
                                {
                                    store.Add(x509).Wait();
                                }
                            }
                        }

                        if ((trustList.SpecifiedLists & (uint)Opc.Ua.TrustListMasks.TrustedCrls) != 0)
                        {
                            foreach (var crl in trustList.TrustedCrls)
                            {
                                store.AddCRL(new X509CRL(crl));
                            }
                        }
                    }
                }

                if (!String.IsNullOrEmpty(m_application.IssuerListStorePath))
                {
                    using (ICertificateStore store = CertificateStoreIdentifier.OpenStore(m_application.IssuerListStorePath))
                    {
                        if ((trustList.SpecifiedLists & (uint)Opc.Ua.TrustListMasks.IssuerCertificates) != 0)
                        {
                            foreach (var certificate in trustList.IssuerCertificates)
                            {
                                var x509 = new X509Certificate2(certificate);

                                X509Certificate2Collection certs = store.FindByThumbprint(x509.Thumbprint).Result;
                                if (certs.Count == 0)
                                {
                                    store.Add(x509).Wait();
                                }
                            }
                        }

                        if ((trustList.SpecifiedLists & (uint)Opc.Ua.TrustListMasks.IssuerCrls) != 0)
                        {
                            foreach (var crl in trustList.IssuerCrls)
                            {
                                store.AddCRL(new X509CRL(crl));
                            }
                        }
                    }
                }

                CertificateStoreControl.Initialize(m_trustListStorePath, m_issuerListStorePath, null);

                MessageBox.Show(
                    Parent,
                    "The trust list (include CRLs) was downloaded from the GDS and saved locally.",
                    Parent.Text,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
            }
            catch (Exception exception)
            {
                MessageBox.Show(Parent.Text + ": " + exception.Message);
            }
        }