当前位置: 首页>>代码示例>>C#>>正文


C# SslPolicyErrors.Equals方法代码示例

本文整理汇总了C#中SslPolicyErrors.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# SslPolicyErrors.Equals方法的具体用法?C# SslPolicyErrors.Equals怎么用?C# SslPolicyErrors.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SslPolicyErrors的用法示例。


在下文中一共展示了SslPolicyErrors.Equals方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MyServerCertificateValidationCallback

        static bool MyServerCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
        {
            // Check if there are any errors.
            bool ok = errors.Equals(SslPolicyErrors.None);

            //this.AddLogEntry(string.Format("SSL Authentication was {0} successful", (ok ? "" : "NOT ")));

            // We decide to allow communication with the server even if it isn't authenticated (not recommended).
            return true;
        }
开发者ID:haoasqui,项目名称:MailSystem.NET,代码行数:10,代码来源:SendingWithSecureConnection.cs

示例2: ValidateWebCertificates

        /// <summary>
        /// Validates the web certificates.
        /// </summary>
        /// <returns>
        /// <c>true</c>, if web certificates was validated, <c>false</c> otherwise.
        /// </returns>
        /// <param name='sender'>
        /// <c>Object</c> usually parsed as WebRequest or HttpWebRequest.
        /// </param>
        /// <param name='endCert'>
        /// Certificate consumed in the request.
        /// </param>
        /// <param name='chain'>
        /// Certificate chain total or partial.
        /// </param>
        /// <param name='Errors'>
        /// Policy errors found during the chain build process.
        /// </param>
        public static bool ValidateWebCertificates(Object sender, System.Security.Cryptography.X509Certificates.X509Certificate endCert, System.Security.Cryptography.X509Certificates.X509Chain chain, SslPolicyErrors Errors)
        {
            var request = sender as WebRequest;
            string requestUri = request.RequestUri.ToString();

            SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation");
            bool bErrorsFound = false;
            try {
                X509Certificate BCCert = Org.BouncyCastle.Security.DotNetUtilities.FromX509Certificate (endCert);
                if (!CertificateIsTheSame (BCCert)) {
                    chain.Build (new System.Security.Cryptography.X509Certificates.X509Certificate2 (endCert.GetRawCertData ()));
                    if(Errors.Equals(SslPolicyErrors.None))
                    {
                        if(chain== null || chain.ChainElements== null || chain.ChainElements.Count == 0){
                            SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation. Chain is empty");
                            bErrorsFound = true;
                        }else
                            SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation. Chain Element count: " + chain.ChainElements.Count);

                        if(CertIsSelfSigned(BCCert)){
                            SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation. End Certificate is Self Signed");
                            bErrorsFound = true;
                        }else
                            SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation. End Certificate NOT Self Signed");

                        if(ValidateFingerprints){
                            SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation. VALIDATING Fingerprint");
                            if(!VerifyFingerprint(endCert, requestUri)){
                                SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation. Invalid Fingerprint");
                                bErrorsFound = true;
                            }else
                                SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation. Valid Fingerprint");
                        }else{
                            SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation. DO NOT validate Fingerprint");
                        }

                        if(ValidatePublicKey){
                            SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation. VALIDATING Public Key");
                            if(!VerifyPublicKey(endCert, requestUri)){
                                SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation. Invalid Public Key");
                                bErrorsFound = true;
                            }else
                                SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation. Valid Public Key");
                        }else{
                            SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation. DO NOT validate Public Key");
                        }

                        /*foreach (System.Security.Cryptography.X509Certificates.X509ChainElement cert in chain.ChainElements) {
                            X509Certificate BCCerto = Org.BouncyCastle.Security.DotNetUtilities.FromX509Certificate (cert.Certificate);
                            if(CertIsSelfSigned(BCCerto)){
                                SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** SELF SIGNED Certificate: CERT NAME " + BCCerto.SubjectDN.ToString() + " ;ID = " + BCCerto.SerialNumber);
                                if(cert.Certificate.SerialNumber.Equals(chain.ChainElements[chain.ChainElements.Count-1].Certificate.SerialNumber)){
                                    string[] stringSeparators = new string[] {";"};
                                    string[] valids = _VALIDROOTAUTHORITIES.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries);
                                    foreach(String validRoot in valids){
                                        SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** SELF SIGNED Certificate check ["+validRoot+"]: "+cert.Certificate.SerialNumber+":"+chain.ChainElements[chain.ChainElements.Count-1].Certificate.SerialNumber);
                                        if(BCCerto.SubjectDN.ToString().Contains(validRoot)){
                                            bErrorsFound = false;
                                        } else {
                                            bErrorsFound = true;
                                        }
                                    }
                                }else {
                                    bErrorsFound = true;
                                }

                            }else{
                                SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** CERT NAME " + BCCerto.SubjectDN.ToString() + " ;ID = " + BCCerto.SerialNumber);
                            }

                            if(!CertIsValidNow(BCCerto)) bErrorsFound = true;
                        }*/

                            //if (chain.ChainElements.Count > 1 && !VerifyCertificateOCSP(chain)) bCertIsOk = true;

                            //if (chain.ChainElements.Count > 1) bCertIsOk = true;
                            // DO NOT check OCSP revocation URLs. The time consuming this is expensive.
                            // TODO make this configurable and asynchronously in the case of enabled
                            // !VerifyCertificateOCSP(chain)  ---> ASYNC
                            SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** OCSP Verification (certificate revocation check) is DISABLED for this build");

                        if (!bErrorsFound) {
//.........这里部分代码省略.........
开发者ID:ik3210,项目名称:appverse-mobile,代码行数:101,代码来源:SecurityUtils.cs

示例3: ValidateWebCertificates

        /// <summary>
        /// Validates the web certificates.
        /// </summary>
        /// <returns>
        /// <c>true</c>, if web certificates was validated, <c>false</c> otherwise.
        /// </returns>
        /// <param name='sender'>
        /// <c>Object</c> usually parsed as WebRequest or HttpWebRequest.
        /// </param>
        /// <param name='endCert'>
        /// Certificate consumed in the request.
        /// </param>
        /// <param name='chain'>
        /// Certificate chain total or partial.
        /// </param>
        /// <param name='Errors'>
        /// Policy errors found during the chain build process.
        /// </param>
        public static bool ValidateWebCertificates(Object sender, System.Security.Cryptography.X509Certificates.X509Certificate endCert, System.Security.Cryptography.X509Certificates.X509Chain chain, SslPolicyErrors Errors)
        {
            SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation");
            try {
                X509Certificate BCCert = Org.BouncyCastle.Security.DotNetUtilities.FromX509Certificate (endCert);
                if (!CertificateIsTheSame (BCCert)) {
                    chain.Build (new System.Security.Cryptography.X509Certificates.X509Certificate2 (endCert.GetRawCertData ()));
                    if(Errors.Equals(SslPolicyErrors.None))
                    {
                        if(chain== null || chain.ChainElements== null || chain.ChainElements.Count==0)
                            SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation. Chain is empty");
                        bool bCertIsOk = false;
                        if (CertIsValidNow (BCCert))
                            if (chain.ChainElements.Count > 1 && !VerifyCertificateOCSP(chain)) bCertIsOk = true;
                        if (bCertIsOk) {
                            myCertificateList.Add (BCCert.GetHashCode(), DateTime.Now);
                            SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation. Valid Certificate");
                            return true;
                        } else{
                            SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation. Invalid Certificate");
                            return false;
                        }

                    }else if(Errors.Equals(SslPolicyErrors.RemoteCertificateChainErrors)){
                        SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation: Errors found in the certificate chain.");
                    }
                    else if(Errors.Equals(SslPolicyErrors.RemoteCertificateNameMismatch)){
                        SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation: The certificate contains errors.");
                    }
                    else if(Errors.Equals(SslPolicyErrors.RemoteCertificateNotAvailable)){
                        SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation: The certificate is not available");
                    }

                    SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation. Policy Errors: " + Errors);
                    return false;
                } else{ //Trusted certificate
                    SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation. Trusted Certificate");
                    return true;
                }
            } catch (Exception e) {
                SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation: Unhandled exception: " + e.Message);
                return false;
            }
        }
开发者ID:jioe,项目名称:appverse-mobile,代码行数:62,代码来源:SecurityUtils.cs


注:本文中的SslPolicyErrors.Equals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。