コード例 #1
0
        private void PinCerts(HttpWebRequest client)
        {
            LogHelper.Log("CORE: Pinning certs...");

            client.ClientCertificates.Clear();

            foreach (var values in CertManager.GetCerts())
            {
                X509Certificate cert = new X509Certificate(values.Value);

                client.ClientCertificates.Add(cert);
            }
        }
コード例 #2
0
        /// <summary>
        /// Validates the server certificate.
        /// </summary>
        /// <returns><c>true</c>, if server certificate was validated, <c>false</c> otherwise.</returns>
        /// <param name="sender">Sender.</param>
        /// <param name="certificate">Certificate.</param>
        /// <param name="chain">Chain.</param>
        /// <param name="policyErrors">Policy errors.</param>
        public static bool ValidateServerCertificate(
            object sender,
            X509Certificate certificate,
            X509Chain chain,
            SslPolicyErrors policyErrors)
        {
            // Logic to determine the validity of the certificate
            if (policyErrors == SslPolicyErrors.None)
            {
                return(true);
            }

            if (policyErrors == SslPolicyErrors.RemoteCertificateChainErrors)
            {
                Console.WriteLine("Certificate chain error: {0}", policyErrors);
                foreach (var chainstat in chain.ChainStatus)
                {
                    Console.WriteLine("{0}", chainstat.Status);
                    Console.WriteLine("{0}", chainstat.StatusInformation);
                }

                foreach (var cert in CertManager.GetCerts())
                {
                    X509Certificate c = new X509Certificate(cert.Value);

                    if (c.GetCertHashString().Equals(certificate.GetCertHashString()))
                    {
                        return(true);
                    }
                }
                return(false);
            }

            Console.WriteLine("Certificate error: {0}", policyErrors);

            return(false);
        }