BugzillaInterface.SecurityCertificateHandler.RemoteCertificateValidationCallback C# (CSharp) Method

RemoteCertificateValidationCallback() protected method

protected RemoteCertificateValidationCallback ( Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors ) : bool
sender Object
certificate System.Security.Cryptography.X509Certificates.X509Certificate
chain System.Security.Cryptography.X509Certificates.X509Chain
sslPolicyErrors SslPolicyErrors
return bool
        protected bool RemoteCertificateValidationCallback(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            if (AllowedThumbPrints == null)
                AllowedThumbPrints = new List<string> ();

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

            string thumbprint = certificate.GetCertHashString ();

            if (AllowedThumbPrints.Contains (thumbprint))
                return true;

            if (PromptMethod == null) {
                return false;
            }

            SecurityCertificateHandler.CertificateAllowanceState answer = PromptMethod (thumbprint);
            if (answer == SecurityCertificateHandler.CertificateAllowanceState.DontAllow) {
                return false;
            } else if (answer == SecurityCertificateHandler.CertificateAllowanceState.AllowThisTime) {
                return true;
            } else if (answer == SecurityCertificateHandler.CertificateAllowanceState.AlwaysAllow) {
                AllowedThumbPrints.Add(thumbprint);
                return true;
            } else {
                // Better to crash than connect to servers we don't trust.
                // Should not be executed if there is no disparity in the
                // code.
                throw new System.NotImplementedException ();
            }
        }