/// <summary> /// Get the Certificate for the specified store. /// </summary> /// <param name="host">The host who owns the certificate.</param> /// <returns>The certificate as a byte array.</returns> public static byte[] GetCertificate(string host) { CertPolicy.CertificateState cs = CertPolicy.GetCertificate(GetHostFromUri(host)); if (cs != null) { return(cs.Certificate.GetRawCertData()); } return(null); }
/// <summary> /// Check for trust failure /// </summary> /// <param name="host">Host name</param> /// <param name="we">WebException occured</param> static void IsTrustFailure(string host, WebException we) { if (we.Status == WebExceptionStatus.TrustFailure) { throw we; } CertPolicy.CertificateState cs = CertPolicy.GetCertificate(host); if (cs != null && !cs.Accepted) { // BUGBUG this is here to work around a mono bug. throw new WebException(we.Message, we, WebExceptionStatus.TrustFailure, we.Response); } }
/// <summary> /// Get the Certificate for the specified store along with Problem. /// </summary> /// <param name="host">The host who owns the certificate.</param> /// <param name="Problem"></param> /// <returns>The certificate as a byte array.</returns> public static byte[] GetCertificate(string host, out CertPolicy.CertificateProblem Problem) { CertPolicy.CertificateState cs = CertPolicy.GetCertificate(GetHostFromUri(host)); if (cs != null) { Problem = cs.Problem; if (cs.Certificate.GetRawCertData().Length == 0) { log.Info("GetCertificate either null or empty"); } return(cs.Certificate.GetRawCertData()); } Problem = CertPolicy.CertificateProblem.CertOK; return(null); }