Ejemplo n.º 1
0
        /// <summary>
        ///     Call back to override server certificate validation
        /// </summary>
        /// <param name="sender">The sender object.</param>
        /// <param name="certificate">The remote certificate.</param>
        /// <param name="chain">The certificate chain.</param>
        /// <param name="sslPolicyErrors">Ssl policy errors</param>
        /// <returns>Return true if valid certificate.</returns>
        internal bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain,
                                                SslPolicyErrors sslPolicyErrors)
        {
            // if user callback is registered then do it
            if (ServerCertificateValidationCallback != null)
            {
                var args = new CertificateValidationEventArgs
                {
                    Certificate     = certificate,
                    Chain           = chain,
                    SslPolicyErrors = sslPolicyErrors
                };

                // why is the sender null?
                ServerCertificateValidationCallback.InvokeAsync(this, args, exceptionFunc).Wait();
                return(args.IsValid);
            }

            if (sslPolicyErrors == SslPolicyErrors.None)
            {
                return(true);
            }

            // By default
            // do not allow this client to communicate with unauthenticated servers.
            return(false);
        }