/// <summary>
 /// Handles a certificate validation error.
 /// </summary>
 void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
 {
     ManualResetEvent ev = new ManualResetEvent(false);
     Dispatcher.RunAsync(
         CoreDispatcherPriority.Normal,
         async () =>
         {
             await GuiUtils.HandleCertificateValidationError(this, validator, e);
             ev.Set();
         }
         ).AsTask().Wait();
     ev.WaitOne();
 }
Exemplo n.º 2
0
        void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
        {
            if (InvokeRequired)
            {
                Invoke(new CertificateValidationEventHandler(CertificateValidator_CertificateValidation), validator, e);
                return;
            }

            try
            {
                GuiUtils.HandleCertificateValidationError(this, validator, e);
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
Exemplo n.º 3
0
 private void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
 {
     if (e.Error.StatusCode == StatusCodes.BadCertificateUntrusted)
     {
         e.Accept = autoAccept;
         if (autoAccept)
         {
             Log(conn_name + " - " + "Accepted Certificate: " + e.Certificate.Subject);
         }
         else
         {
             Log(conn_name + " - " + "Rejected Certificate: " + e.Certificate.Subject);
         }
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Handles a certificate validation error.
 /// </summary>
 void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
 {
     try
     {
         Opc.Ua.Client.Controls.GuiUtils.HandleCertificateValidationError(this, validator, e);
     }
     catch (Exception exception)
     {
         Opc.Ua.Client.Controls.GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
     }
 }
        /// <summary>
        /// Handles a certificate validation error.
        /// </summary>
        /// <param name="caller">The caller's text is used as the caption of the <see cref="MessageBox"/> shown to provide details about the error.</param>
        /// <param name="validator">The validator (not used).</param>
        /// <param name="e">The <see cref="Opc.Ua.CertificateValidationEventArgs"/> instance event arguments provided when a certificate validation error occurs.</param>
        public static async Task HandleCertificateValidationError(Page caller, CertificateValidator validator, CertificateValidationEventArgs e)
        {
            StringBuilder buffer = new StringBuilder();

            buffer.AppendFormat("Certificate could not be validated: {0}\r\n\r\n", e.Error.StatusCode);
            buffer.AppendFormat("Subject: {0}\r\n", e.Certificate.Subject);
            buffer.AppendFormat("Issuer: {0}\r\n", (e.Certificate.Subject == e.Certificate.Issuer) ? "Self-signed" : e.Certificate.Issuer);
            buffer.AppendFormat("Thumbprint: {0}\r\n\r\n", e.Certificate.Thumbprint);
            buffer.AppendFormat("The security certificate was not issued by a trusted certificate authority.\r\n");
            buffer.AppendFormat("Security certificate problems may indicate an attempt to intercept any data you send\r\n");
            buffer.AppendFormat("to a server or to allow an untrusted client to connect to your server.\r\n");
            buffer.AppendFormat("\r\nAccept anyway?");
            MessageDlg       dialog = new MessageDlg(buffer.ToString(), MessageDlgButton.Yes, MessageDlgButton.No);
            MessageDlgButton result = await dialog.ShowAsync();

            if (result == MessageDlgButton.Yes)
            {
                e.Accept = true;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Handles a certificate validation error.
        /// </summary>
        /// <param name="caller">The caller's text is used as the caption of the <see cref="MessageBox"/> shown to provide details about the error.</param>
        /// <param name="validator">The validator (not used).</param>
        /// <param name="e">The <see cref="Opc.Ua.CertificateValidationEventArgs"/> instance event arguments provided when a certificate validation error occurs.</param>
        public static void HandleCertificateValidationError(Form caller, CertificateValidator validator, CertificateValidationEventArgs e)
        {
            StringBuilder buffer = new StringBuilder();

            buffer.AppendFormat("Certificate could not be validated: {0}\r\n\r\n", e.Error.StatusCode);
            buffer.AppendFormat("Subject: {0}\r\n", e.Certificate.Subject);
            buffer.AppendFormat("Issuer: {0}\r\n", (e.Certificate.Subject == e.Certificate.Issuer)?"Self-signed":e.Certificate.Issuer);
            buffer.AppendFormat("Valid From: {0}\r\n", e.Certificate.NotBefore);
            buffer.AppendFormat("Valid To: {0}\r\n", e.Certificate.NotAfter);
            buffer.AppendFormat("Thumbprint: {0}\r\n\r\n", e.Certificate.Thumbprint);
            buffer.AppendFormat("The security certificate was not issued by a trusted certificate authority. ");
            buffer.AppendFormat("Security certificate problems may indicate an attempt to intercept any data you send ");
            buffer.AppendFormat("to a server or to allow an untrusted client to connect to your server.");
            buffer.AppendFormat("\r\n\r\nAccept anyway?");

            if (MessageBox.Show(buffer.ToString(), caller.Text, MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                e.Accept = true;
            }
        }
        /// <summary>
        /// Handles a certificate validation error.
        /// </summary>
        private void CertificateValidator_CertificateValidation(CertificateValidator sender, CertificateValidationEventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new CertificateValidationEventHandler(CertificateValidator_CertificateValidation), sender, e);
                return;
            }

            try
            {
                e.Accept = m_configuration.SecurityConfiguration.AutoAcceptUntrustedCertificates;

                if (!m_configuration.SecurityConfiguration.AutoAcceptUntrustedCertificates)
                {
                    DialogResult result = MessageBox.Show(
                        e.Certificate.Subject,
                        "Untrusted Certificate",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Warning);

                    e.Accept = (result == DialogResult.Yes);
                }
            }
            catch (Exception exception)
            {
                ClientUtils.HandleException(this.Text, exception);
            }
        }
Exemplo n.º 8
0
        public static Task OnCertificateValidation(object sender, CertificateValidationEventArgs e)
        {
            if (e.SslPolicyErrors == System.Net.Security.SslPolicyErrors.None)
                e.IsValid = true;

            return Task.FromResult(0);
        }
Exemplo n.º 9
0
 private void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
 {
     if (e.Error.StatusCode == StatusCodes.BadCertificateUntrusted)
     {
         e.Accept = config.SecurityConfiguration.AutoAcceptUntrustedCertificates;
         if (config.SecurityConfiguration.AutoAcceptUntrustedCertificates)
         {
             info.LabelText = "Accepted Certificate: " + e.Certificate.Subject.ToString();
         }
         else
         {
             info.LabelText = "Rejected Certificate: " + e.Certificate.Subject.ToString();
         }
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Prompts the user to accept an untrusted certificate.
        /// </summary>
        private void CertificateValidator_CertificateValidation(CertificateValidator sender, CertificateValidationEventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new CertificateValidationEventHandler(CertificateValidator_CertificateValidation), sender, e);
                return;
            }

            try
            {
                DialogResult result = MessageBox.Show(
                    e.Certificate.Subject,
                    "Untrusted Certificate",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Warning);

                e.Accept = (result == DialogResult.Yes);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 11
0
        private static void CertificateValidator_CertificateValidation(CertificateValidator sender, CertificateValidationEventArgs e)
        {
            if (e.Error.StatusCode == StatusCodes.BadCertificateTimeInvalid)
            {
                //if (isInvalidPeriodAccepted)
                {
                    e.Accept = true;
                    return;
                }
                return;
            }
            else if (e.Error.StatusCode == StatusCodes.BadCertificateHostNameInvalid)
            {
                //if (isInvalidHostNameAllowed)
                {
                    e.Accept = true;
                    return;
                }
            }
            else if (e.Error.StatusCode == StatusCodes.BadCertificateUntrusted)
            {
                if (configuredEndpoint.Description.SecurityPolicyUri == SecurityPolicies.None &&
                    configuredEndpoint.Description.SecurityMode == MessageSecurityMode.None)
                {
                    e.Accept = true;
                    return;
                }
            }

            e.Accept = false;
            return;
        }
        private static void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
        {
            string logPrefix = $"{_logClassPrefix}:CertificateValidator_CertificateValidation:";

            if (e.Error.StatusCode == StatusCodes.BadCertificateUntrusted)
            {
                e.Accept = AutoAccept;
                if (AutoAccept)
                {
                    Logger.Verbose($"{logPrefix} Accepted Certificate: {0}", e.Certificate.Subject);
                }
                else
                {
                    Logger.Warning($"{logPrefix} Rejected Certificate: {0}", e.Certificate.Subject);
                }
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Standard certificate validation callback
 /// </summary>
 private static void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
 {
     if (e.Error.StatusCode == StatusCodes.BadCertificateUntrusted)
     {
         Trace("Certificate \""
               + e.Certificate.Subject
               + "\" not trusted. If you want to trust this certificate, please copy it from the \""
               + m_configuration.SecurityConfiguration.RejectedCertificateStore.StorePath + "/certs"
               + "\" to the \""
               + m_configuration.SecurityConfiguration.TrustedPeerCertificates.StorePath + "/certs"
               + "\" folder. A restart of the gateway is NOT required.");
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// UI: handle server certificate validation
        ///     and prompt for user interaction if required.
        /// </summary>
        void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
        {
            ManualResetEvent ev = new ManualResetEvent(false);

            Dispatcher.RunAsync(
                CoreDispatcherPriority.Normal,
                async() =>
            {
                await GuiUtils.HandleCertificateValidationError(this, validator, e);
                if (e.Accept)
                {
                    MessageDialog showDialog = new MessageDialog("Would you like to save this certificate?");
                    showDialog.Commands.Add(new UICommand("Save")
                    {
                        Id = 0
                    });
                    showDialog.Commands.Add(new UICommand("Cancel")
                    {
                        Id = 1
                    });
                    showDialog.DefaultCommandIndex = 1;
                    showDialog.CancelCommandIndex  = 1;
                    var result = await showDialog.ShowAsync();

                    if ((int)result.Id == 0)
                    {
                        try
                        {
                            byte[] cert       = e.Certificate.Export(System.Security.Cryptography.X509Certificates.X509ContentType.Cert);
                            string issuerName = e.Certificate.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, true);
                            string filePath   = Path.Combine(m_cert_full_path, String.Format("{0} [{1}].der", issuerName, e.Certificate.Thumbprint));
                            File.WriteAllBytes(filePath, cert);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                progringConnection.IsActive = true;
                ev.Set();
            }
                ).AsTask().Wait();
            ev.WaitOne();
        }
Exemplo n.º 15
0
 private static void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
 {
     if (e.Error.StatusCode == StatusCodes.BadCertificateUntrusted)
     {
         e.Accept = false;
         Console.WriteLine("Rejected Certificate: {0}", e.Certificate.Subject);
     }
 }
Exemplo n.º 16
0
 /// <summary>
 /// Handles a certificate validation error.
 /// </summary>
 private void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
 {
     try
     {
         if (m_applicationConfiguration.SecurityConfiguration != null &&
             m_applicationConfiguration.SecurityConfiguration.AutoAcceptUntrustedCertificates &&
             e.Error != null && e.Error.Code == StatusCodes.BadCertificateUntrusted)
         {
             e.Accept = true;
             Utils.Trace((int)Utils.TraceMasks.Security, "Automatically accepted certificate: {0}", e.Certificate.Subject);
         }
     }
     catch (Exception exception)
     {
         Utils.Trace(exception, "Error accepting certificate.");
     }
 }
Exemplo n.º 17
0
 /// <summary>
 /// Auto accept certificates
 /// </summary>
 /// <param name="validator"></param>
 /// <param name="e"></param>
 private void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
 {
     if (e.Error.StatusCode == StatusCodes.BadCertificateUntrusted)
     {
         e.Accept = true;
         Console.WriteLine($"Opc.Ua.Client.SampleModule: WARNING: Auto-accepting certificate: {e.Certificate.Subject}");
     }
 }
Exemplo n.º 18
0
 private void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
 {
     if (e.Error.StatusCode == StatusCodes.BadCertificateUntrusted)
     {
         e.Accept = _autoAccept;
         if (_autoAccept)
         {
             Console.WriteLine("Accepted Certificate: {0}", e.Certificate.Subject);
         }
         else
         {
             Console.WriteLine("Rejected Certificate: {0}", e.Certificate.Subject);
         }
     }
 }
Exemplo n.º 19
0
		private static void Application_CertificateValidation(object sender, CertificateValidationEventArgs e)
		{
			e.ValidationOption = CertificateValidationOption.AcceptOnce;
		}
        /// <summary>
        /// Checks that the domains in the certificate match the current host.
        /// </summary>
        private void RegistrationValidator_CertificateValidation(CertificateValidator sender, CertificateValidationEventArgs e)
        {
            Task t = Task.Run(async () =>
            {
                System.Net.IPAddress[] targetAddresses = await Utils.GetHostAddresses(Utils.GetHostName());

                foreach (string domain in Utils.GetDomainsFromCertficate(e.Certificate))
                {
                    System.Net.IPAddress[] actualAddresses = await Utils.GetHostAddresses(domain);

                    foreach (System.Net.IPAddress actualAddress in actualAddresses)
                    {
                        foreach (System.Net.IPAddress targetAddress in targetAddresses)
                        {
                            if (targetAddress.Equals(actualAddress))
                            {
                                e.Accept = true;
                                return;
                            }
                        }
                    }
                }
            });
            t.Wait();
        }
Exemplo n.º 21
0
 /// <summary>
 /// The certificate validator is used
 /// if auto accept is not selected in the configuration.
 /// </summary>
 private void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
 {
     if (e.Error.StatusCode == StatusCodes.BadCertificateUntrusted)
     {
         if (AutoAccept)
         {
             m_output.WriteLine("Accepted Certificate: [{0}] [{1}]", e.Certificate.Subject, e.Certificate.Thumbprint);
             e.Accept = true;
             return;
         }
     }
     m_output.WriteLine("Rejected Certificate: {0} [{1}] [{2}]", e.Error, e.Certificate.Subject, e.Certificate.Thumbprint);
 }
Exemplo n.º 22
0
        /// <summary>
        /// Handles a certificate validation error.
        /// </summary>
        /// <param name="caller">The caller's text is used as the caption of the <see cref="MessageBox"/> shown to provide details about the error.</param>
        /// <param name="validator">The validator (not used).</param>
        /// <param name="e">The <see cref="Opc.Ua.CertificateValidationEventArgs"/> instance event arguments provided when a certificate validation error occurs.</param>
        public static void HandleCertificateValidationError(Form caller, CertificateValidator validator, CertificateValidationEventArgs e)
        {       
            StringBuilder buffer = new StringBuilder();

            buffer.AppendFormat("Certificate could not validated: {0}\r\n\r\n", e.Error.StatusCode);
            buffer.AppendFormat("Subject: {0}\r\n", e.Certificate.Subject);
            buffer.AppendFormat("Issuer: {0}\r\n", (e.Certificate.Subject == e.Certificate.Issuer)?"Self-signed":e.Certificate.Issuer);
            buffer.AppendFormat("Valid From: {0}\r\n", e.Certificate.NotBefore);
            buffer.AppendFormat("Valid To: {0}\r\n", e.Certificate.NotAfter);
            buffer.AppendFormat("Thumbprint: {0}\r\n\r\n", e.Certificate.Thumbprint);
            
            buffer.AppendFormat("Accept anyways?");

            if (MessageBox.Show(buffer.ToString(), caller.Text, MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                e.Accept = true;
            }
        }
Exemplo n.º 23
0
 /// <summary>
 /// Handles a certificate validation error.
 /// </summary>
 /// <param name="form">The caller's form is used as the caption of the <see cref="MessageBox"/> shown to provide details about the error.</param>
 /// <param name="validator">The validator (not used).</param>
 /// <param name="e">The <see cref="Opc.Ua.CertificateValidationEventArgs"/> instance event arguments provided when a certificate validation error occurs.</param>
 public static void HandleCertificateValidationError(Form form, CertificateValidator validator, CertificateValidationEventArgs e)
 {
     HandleCertificateValidationError(form.Text, validator, e);
 }
Exemplo n.º 24
0
 /// <summary>
 /// Handles an error validating the server certificate.
 /// </summary>
 /// <remarks>
 /// Applications should never accept certificates silently. Doing do will create the illusion of security
 /// that will come back to haunt the vendor in the future. Compliance tests by the OPC Foundation will
 /// fail products that silently accept untrusted certificates.
 /// </remarks>
 static void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
 {
     e.Accept = true;
     Console.WriteLine("WARNING: Accepting Untrusted Certificate: {0}", e.Certificate.Subject);
 }
Exemplo n.º 25
0
        /// <summary>
        /// Handles a certificate validation error.
        /// </summary>
        /// <param name="caption">The caller's text is used as the caption of the <see cref="MessageBox"/> shown to provide details about the error.</param>
        /// <param name="validator">The validator (not used).</param>
        /// <param name="e">The <see cref="Opc.Ua.CertificateValidationEventArgs"/> instance event arguments provided when a certificate validation error occurs.</param>
        public static void HandleCertificateValidationError(string caption, CertificateValidator validator, CertificateValidationEventArgs e)
        {
            StringBuilder buffer = new StringBuilder();

            buffer.AppendFormat("Certificate could not be validated!\r\n");
            buffer.AppendFormat("Validation error(s): \r\n");
            buffer.AppendFormat("\t{0}\r\n", e.Error.StatusCode);
            if (e.Error.InnerResult != null)
            {
                buffer.AppendFormat("\t{0}\r\n", e.Error.InnerResult.StatusCode);
            }
            buffer.AppendFormat("\r\nSubject: {0}\r\n", e.Certificate.Subject);
            buffer.AppendFormat("Issuer: {0}\r\n", (e.Certificate.Subject == e.Certificate.Issuer) ? "Self-signed" : e.Certificate.Issuer);
            buffer.AppendFormat("Valid From: {0}\r\n", e.Certificate.NotBefore);
            buffer.AppendFormat("Valid To: {0}\r\n", e.Certificate.NotAfter);
            buffer.AppendFormat("Thumbprint: {0}\r\n\r\n", e.Certificate.Thumbprint);
            buffer.AppendFormat("Certificate validation errors may indicate an attempt to intercept any data you send ");
            buffer.AppendFormat("to a server or to allow an untrusted client to connect to your server.");
            buffer.AppendFormat("\r\n\r\nAccept anyway?");

            if (MessageBox.Show(buffer.ToString(), caption, MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                e.Accept = true;
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Check for untrusted certificates and only accept them if the user has accepted them
        /// </summary>
        private void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
        {
            if (e.Error.StatusCode == StatusCodes.BadCertificateUntrusted)
            {
                // Session is not accessible from here so we need to iterate through all key-value-pairs
                foreach (KeyValuePair <string, OpcSessionCacheData> pair in OpcSessionCache.ToArray())
                {
                    // try processing each entry
                    try
                    {
                        string hostName = pair.Value.EndpointURL.Substring("opc.tcp://".Length);
                        if (hostName.Contains(":"))
                        {
                            hostName = hostName.Substring(0, hostName.IndexOf(':'));
                        }

                        // Look up by cert thumbprint
                        if (string.Equals(pair.Value.CertThumbprint, e.Certificate.Thumbprint, StringComparison.InvariantCultureIgnoreCase))
                        {
                            // check if the current session user has confirmed trust
                            if (pair.Value.Trusted)
                            {
                                // In this case, we accept the cert
                                e.Accept = true;
                                break;
                            }
                        }

                        // Update our cache data
                        if (e.Certificate.Subject.Contains(hostName))
                        {
                            OpcSessionCacheData newValue = new OpcSessionCacheData
                            {
                                OPCSession     = pair.Value.OPCSession,
                                EndpointURL    = pair.Value.EndpointURL,
                                Trusted        = pair.Value.Trusted,
                                CertThumbprint = e.Certificate.Thumbprint
                            };
                            OpcSessionCache.TryUpdate(pair.Key, newValue, pair.Value);
                            break;
                        }
                    }
                    catch (Exception)
                    {
                        // do nothing
                    }
                }
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Handles a certificate validation error.
        /// </summary>
        /// <param name="caller">The caller's text is used as the caption of the <see cref="MessageBox"/> shown to provide details about the error.</param>
        /// <param name="validator">The validator (not used).</param>
        /// <param name="e">The <see cref="Opc.Ua.CertificateValidationEventArgs"/> instance event arguments provided when a certificate validation error occurs.</param>
        public static async Task HandleCertificateValidationError(Page caller, CertificateValidator validator, CertificateValidationEventArgs e)
        {
            StringBuilder buffer = new StringBuilder();

            buffer.AppendFormat("Certificate could not validated: {0}\r\n\r\n", e.Error.StatusCode);
            buffer.AppendFormat("Subject: {0}\r\n", e.Certificate.Subject);
            buffer.AppendFormat("Issuer: {0}\r\n", (e.Certificate.Subject == e.Certificate.Issuer) ? "Self-signed" : e.Certificate.Issuer);
            buffer.AppendFormat("Thumbprint: {0}\r\n\r\n", e.Certificate.Thumbprint);

            buffer.AppendFormat("Accept anyways?");
            MessageDlg       dialog = new MessageDlg(buffer.ToString(), MessageDlgButton.Yes, MessageDlgButton.No);
            MessageDlgButton result = await dialog.ShowAsync();

            if (result == MessageDlgButton.Yes)
            {
                e.Accept = true;
            }
        }
 /// <summary>
 /// Handles a certificate validation error.
 /// </summary>
 private static void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
 {
     try
     {
         if (e.Error != null && e.Error.Code == StatusCodes.BadCertificateUntrusted)
         {
             e.Accept = true;
             Utils.Trace((int)Utils.TraceMasks.Security, "Automatically accepted certificate: {0}", e.Certificate.Subject);
         }
     }
     catch (Exception exception)
     {
         Utils.Trace(exception, "Error accepting certificate.");
     }
 }
Exemplo n.º 29
0
        /// <summary>
        /// Handles a certificate validation error.
        /// 处理证书验证失败的情况
        /// </summary>
        private void CertificateValidator_CertificateValidation(CertificateValidator sender, CertificateValidationEventArgs e)
        {
            try
            {
                e.Accept = m_configuration.SecurityConfiguration.AutoAcceptUntrustedCertificates;

                if (!m_configuration.SecurityConfiguration.AutoAcceptUntrustedCertificates)
                {
                    e.Accept = true;
                    //if (!m_configuration.SecurityConfiguration.AutoAcceptUntrustedCertificates)
                    //{
                    //    DialogResult result = MessageBox.Show(
                    //        e.Certificate.Subject,
                    //        "Untrusted Certificate",
                    //        MessageBoxButtons.YesNo,
                    //        MessageBoxIcon.Warning);

                    //    e.Accept = (result == DialogResult.Yes);
                    //}
                }
            }
            catch (Exception exception)
            {
                ClientUtils.HandleException(application.ApplicationName, exception);
            }
        }
Exemplo n.º 30
0
 private void my_Server_CertificateEvent(CertificateValidator validator, CertificateValidationEventArgs e)
 {
     // Accept all certificate -> better ask user
     e.Accept = true;
 }
Exemplo n.º 31
0
 /// <summary>
 /// Accepts server certificates.
 /// </summary>
 void CertificateValidator_CertificateValidation(CertificateValidator validator,
                                                 CertificateValidationEventArgs e)
 {
     // always safe to trust servers when connecting as a test application.
     e.Accept = true;
 }
Exemplo n.º 32
0
        private void CertificateValidator_CertificateValidation(CertificateValidator sender, CertificateValidationEventArgs e)
        {
            if (InvokeRequired)
            {
                Invoke(new CertificateValidationEventHandler(CertificateValidator_CertificateValidation), sender, e);
                return;
            }

            try
            {
                var result = new UntrustedCertificateDialog().ShowDialog(this, e.Certificate);

                if (result == DialogResult.OK)
                {
                    e.Accept = true;
                }
            }
            catch (Exception ex)
            {
                Opc.Ua.Client.Controls.ExceptionDlg.Show(Text, ex);
            }
        }
Exemplo n.º 33
0
        void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
        {
            if (InvokeRequired)
            {
                Invoke(new CertificateValidationEventHandler(CertificateValidator_CertificateValidation), validator, e);
                return;
            }

            try
            {
                GuiUtils.HandleCertificateValidationError(this, validator, e);
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
Exemplo n.º 34
0
        void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
        {
            ManualResetEvent ev = new ManualResetEvent(false);

            Dispatcher.RunAsync(
                CoreDispatcherPriority.Normal,
                async() =>
            {
                await GuiUtils.HandleCertificateValidationError(this, validator, e);
                ev.Set();
            }
                ).AsTask().Wait();
            ev.WaitOne();
        }
        /// <summary>
        /// Handles a certificate validation error.
        /// </summary>
        /// <param name="caller">The caller's text is used as the caption of the <see cref="MessageBox"/> shown to provide details about the error.</param>
        /// <param name="validator">The validator (not used).</param>
        /// <param name="e">The <see cref="Opc.Ua.CertificateValidationEventArgs"/> instance event arguments provided when a certificate validation error occurs.</param>
        public static async Task HandleCertificateValidationError(Page caller, CertificateValidator validator, CertificateValidationEventArgs e)
        {
            StringBuilder buffer = new StringBuilder();

            buffer.AppendFormat("Certificate could not validated: {0}\r\n\r\n", e.Error.StatusCode);
            buffer.AppendFormat("Subject: {0}\r\n", e.Certificate.Subject);
            buffer.AppendFormat("Issuer: {0}\r\n", (e.Certificate.Subject == e.Certificate.Issuer) ? "Self-signed" : e.Certificate.Issuer);
            buffer.AppendFormat("Thumbprint: {0}\r\n\r\n", e.Certificate.Thumbprint);

            buffer.AppendFormat("Accept anyways?");
            MessageDlg dialog = new MessageDlg(buffer.ToString(), MessageDlgButton.Yes, MessageDlgButton.No);
            MessageDlgButton result = await dialog.ShowAsync();
            if (result == MessageDlgButton.Yes)
            {
                e.Accept = true;
            }
        }
Exemplo n.º 36
0
        /// <summary>
        /// Handles a certificate validation error.
        /// </summary>
        private void CertificateValidator_CertificateValidation(CertificateValidator sender, CertificateValidationEventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new CertificateValidationEventHandler(CertificateValidator_CertificateValidation), sender, e);
                return;
            }

            try
            {
                e.Accept = m_configuration.SecurityConfiguration.AutoAcceptUntrustedCertificates;

                if (!m_configuration.SecurityConfiguration.AutoAcceptUntrustedCertificates)
                {
                    DialogResult result = MessageBox.Show(
                        e.Certificate.Subject,
                        "Untrusted Certificate",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Warning);

                    e.Accept = (result == DialogResult.Yes);
                }
            }
            catch (Exception exception)
            {
                ClientUtils.HandleException(this.Text, exception);
            }
        }
Exemplo n.º 37
0
 private Task OnCertificateValidation(object sender, CertificateValidationEventArgs e)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Handles a certificate validation error.
        /// </summary>
        /// <param name="caller">The caller's text is used as the caption of the <see cref="MessageBox"/> shown to provide details about the error.</param>
        /// <param name="validator">The validator (not used).</param>
        /// <param name="e">The <see cref="Opc.Ua.CertificateValidationEventArgs"/> instance event arguments provided when a certificate validation error occurs.</param>
        public static void HandleCertificateValidationError(Form caller, CertificateValidator validator, CertificateValidationEventArgs e)
        {       
            StringBuilder buffer = new StringBuilder();

            buffer.AppendFormat("Certificate could not be validated: {0}\r\n\r\n", e.Error.StatusCode);
            buffer.AppendFormat("Subject: {0}\r\n", e.Certificate.Subject);
            buffer.AppendFormat("Issuer: {0}\r\n", (e.Certificate.Subject == e.Certificate.Issuer)?"Self-signed":e.Certificate.Issuer);
            buffer.AppendFormat("Valid From: {0}\r\n", e.Certificate.NotBefore);
            buffer.AppendFormat("Valid To: {0}\r\n", e.Certificate.NotAfter);
            buffer.AppendFormat("Thumbprint: {0}\r\n\r\n", e.Certificate.Thumbprint);
            buffer.AppendFormat("The security certificate was not issued by a trusted certificate authority. ");
            buffer.AppendFormat("Security certificate problems may indicate an attempt to intercept any data you send ");
            buffer.AppendFormat("to a server or to allow an untrusted client to connect to your server.");
            buffer.AppendFormat("\r\n\r\nAccept anyway?");

            if (MessageBox.Show(buffer.ToString(), caller.Text, MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                e.Accept = true;
            }
        }
Exemplo n.º 39
0
        /// <summary>
        /// Handles a certificate validation error.
        /// </summary>
        /// <param name="caller">The caller's text is used as the caption of the <see cref="MessageBox"/> shown to provide details about the error.</param>
        /// <param name="validator">The validator (not used).</param>
        /// <param name="e">The <see cref="Opc.Ua.CertificateValidationEventArgs"/> instance event arguments provided when a certificate validation error occurs.</param>
        public static void HandleCertificateValidationError(Form caller, CertificateValidator validator, CertificateValidationEventArgs e)
        {
            StringBuilder buffer = new StringBuilder();

            buffer.AppendFormat("Certificate could not validated: {0}\r\n\r\n", e.Error.StatusCode);
            buffer.AppendFormat("Subject: {0}\r\n", e.Certificate.Subject);
            buffer.AppendFormat("Issuer: {0}\r\n", (e.Certificate.Subject == e.Certificate.Issuer)?"Self-signed":e.Certificate.Issuer);
            buffer.AppendFormat("Valid From: {0}\r\n", e.Certificate.NotBefore);
            buffer.AppendFormat("Valid To: {0}\r\n", e.Certificate.NotAfter);
            buffer.AppendFormat("Thumbprint: {0}\r\n\r\n", e.Certificate.Thumbprint);

            buffer.AppendFormat("Accept anyways?");

            if (MessageBox.Show(buffer.ToString(), caller.Text, MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                e.Accept = true;
            }
        }
Exemplo n.º 40
0
 /// <summary>
 /// Always accept server certificates.
 /// </summary>
 void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
 {
     e.Accept = true;
 }
Exemplo n.º 41
0
        private static Task ProxyServer_ServerCertificateValidationCallback(object arg1, CertificateValidationEventArgs e)
        {
            //set IsValid to true/false based on Certificate Errors
            if (e.SslPolicyErrors == System.Net.Security.SslPolicyErrors.None)
            {
                e.IsValid = true;
            }

            return(Task.FromResult(0));
        }
Exemplo n.º 42
0
 /// <summary>
 /// Accepts server certificates.
 /// </summary>
 void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
 {
     // always safe to trust servers when connecting as a test application.
     e.Accept = true;
 }
Exemplo n.º 43
0
        /// <summary>
        /// Handles a certificate validation error.
        /// </summary>
        void CertificateValidator_CertificateValidation(CertificateValidator validator, CertificateValidationEventArgs e)
        {
            try
            {
                Opc.Ua.Client.Controls.GuiUtils.HandleCertificateValidationError(this, validator, e);
            }
            catch (Exception exception)
            {
				Opc.Ua.Client.Controls.GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }