void client_CertificateReceived(object sender, ComponentPro.Security.CertificateReceivedEventArgs e) { CertValidator dlg = new CertValidator(); CertificateVerificationStatus status = e.Status; CertificateVerificationStatus[] values = (CertificateVerificationStatus[])Enum.GetValues(typeof(CertificateVerificationStatus)); StringBuilder sbIssues = new StringBuilder(); bool showAddTrusted = false; for (int i = 0; i < values.Length; i++) { // Matches the validation status? if ((status & values[i]) == 0) { continue; } // The issue is processed. status ^= values[i]; sbIssues.AppendFormat("{0}\r\n", GetCertProblem(values[i], e.ErrorCode, ref showAddTrusted)); } dlg.Certificate = e.ServerCertificates[0]; dlg.Issues = sbIssues.ToString(); dlg.ShowAddToTrustedList = showAddTrusted; dlg.ShowDialog(); e.AddToTrustedRoot = dlg.AddToTrustedList; e.Accept = dlg.Accepted; }
/// <summary> /// Returns all issues of the given certificate. /// </summary> private static string GetCertProblem(CertificateVerificationStatus status, int code, ref bool showAddTrusted) { switch (status) { case CertificateVerificationStatus.TimeNotValid: return("Server's certificate has expired or is not valid yet."); case CertificateVerificationStatus.Revoked: return("Server's certificate has been revoked."); case CertificateVerificationStatus.UnknownCA: return("Server's certificate was issued by an unknown authority."); case CertificateVerificationStatus.RootNotTrusted: showAddTrusted = true; return("Server's certificate was issued by an untrusted authority."); case CertificateVerificationStatus.IncompleteChain: return("Server's certificate does not chain up to a trusted root authority."); case CertificateVerificationStatus.Malformed: return("Server's certificate is malformed."); case CertificateVerificationStatus.CNNotMatch: return("Server hostname does not match the certificate."); case CertificateVerificationStatus.UnknownError: return(string.Format("Error {0:x} encountered while validating server's certificate.", code)); default: return(status.ToString()); } }