private bool ValidateServerCertificate( X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { // TODO: this callback would be better suited as in the MainForm GUI code. It's popping a dialog box and accessing the registry key to look at a global list // of accepted certificates that is managed by the MainForm anyway. Can then get rid of the reference to the global list in the constructor. if (sslPolicyErrors == SslPolicyErrors.None) { return(true); } //Console.WriteLine("Certificate error: {0}", sslPolicyErrors); bool PreviouslyAccepted = AcceptedCertificates.IsStored(GetFQDN(HostName), new X509Certificate2(certificate)); if (PreviouslyAccepted) { return(true); } lock (ExceptionLock) { // Do not allow this client to communicate with unauthenticated servers without asking user. if (this.SilentFail) { return(false); } } ValidateCertificateForm vcf = new ValidateCertificateForm(certificate); if (vcf.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return(false); } // User has given us permission to proceed regardless. We should save the certificate for next time. AcceptedCertificates.Store(GetFQDN(HostName), new X509Certificate2(certificate)); return(true); }