• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# X509Certificates.X509Chain类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Security.Cryptography.X509Certificates.X509Chain的典型用法代码示例。如果您正苦于以下问题:C# X509Chain类的具体用法?C# X509Chain怎么用?C# X509Chain使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



X509Chain类属于System.Security.Cryptography.X509Certificates命名空间,在下文中一共展示了X509Chain类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: RemoteCertificateValidate

 // 在生成的代理类中添加RemoteCertificateValidate函数
 private static bool RemoteCertificateValidate(object sender, X509Certificate cert,X509Chain chain, SslPolicyErrors error)
 {
     //System.Console.WriteLine("Warning, trust any certificate");
     //MessageBox.Show("Warning, trust any certificate");
     //为了通过证书验证,总是返回true
     return true;
 }
开发者ID:AllenSteve,项目名称:Instance,代码行数:8,代码来源:TransactionService.cs


示例2: ValidateServerCertficate

		public bool ValidateServerCertficate (object sender, X509Certificate receivedCertificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
		{
			bool validRequest = true;

//			var enumerator = chain.ChainPolicy.ExtraStore.GetEnumerator();
//
//			while (enumerator.MoveNext ()) {
//				var pem = ExportToPEM (loop.Current);
//			}
//
			if (receivedCertificate.Subject.IndexOf (".xamarin.com", 0, StringComparison.CurrentCultureIgnoreCase) == -1) { //not a request to an Xamarin server so verify certificate
				//This is not an https request for Xamarin Insights

				if (originalRootCertificate == null) {
					validRequest = false;
				} else {
					//check if certificate chain contains original root certificate
					validRequest = chain.ChainPolicy.ExtraStore.Contains (originalRootCertificate);
				}
			}

			if (!validRequest) {
				EventHandler handler = CertificateMismatchFound;
				if (handler != null) {
					handler (this, null);
				}
			}

			return validRequest;
		}
开发者ID:RoyStobbelaar,项目名称:MedewerkerTemp,代码行数:30,代码来源:SslValidator.cs


示例3: CertificateValidationCallBack

        private static bool CertificateValidationCallBack(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            if (sslPolicyErrors == SslPolicyErrors.None)
            {
                return true;
            }

            if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateChainErrors) != 0)
            {
                if (chain != null && chain.ChainStatus != null)
                {
                    foreach (var status in chain.ChainStatus)
                    {
                        if ((certificate.Subject == certificate.Issuer) &&
                           (status.Status == X509ChainStatusFlags.UntrustedRoot))
                        {
                            continue;
                        }
                        else
                        {
                            if (status.Status != X509ChainStatusFlags.NoError)
                            {
                                return false;
                            }
                        }
                    }
                }

                return true;
            }
            else
            {
                return false;
            }
        }
开发者ID:Transcanada-TRPS,项目名称:TBOT,代码行数:35,代码来源:HydroOneMeterParser.cs


示例4: CheckCertificateEventArgs

 /// <summary>
 /// Initializes a new instance of the <see cref="CheckCertificateEventArgs"/> class.
 /// </summary>
 /// <param name="certificate">The certificate.</param>
 /// <param name="chain">The chain.</param>
 /// <param name="sslpolicyerrors">The sslpolicyerrors.</param>
 public CheckCertificateEventArgs(X509Certificate certificate, X509Chain chain, SslPolicyErrors sslpolicyerrors)
 {
     Certificate = certificate;
     Chain = chain;
     Sslpolicyerrors = sslpolicyerrors;
     IsValid = true;
 }
开发者ID:modulexcite,项目名称:FTP,代码行数:13,代码来源:CheckCertificateEventArgs.cs


示例5: CertCheck

		private static bool CertCheck(object sender, 
		                              X509Certificate cert, 
		                              X509Chain chain, 
		                              SslPolicyErrors error)
		{
#if !BYPASS_SSL_CHECK
			if (cert == null)
			{
				Console.WriteLine("Warning: Certificate is null!");
				return false;
			}
			
			FileStream stream = Assembly.GetCallingAssembly().GetFile("PublicKey");
			byte[] bytes = new byte[stream.Length];
			stream.Read(bytes, 0, bytes.Length);
			
			if (bytes.Length < cert.GetPublicKey().Length)
				return false;
			
			for (int i = 0; i < bytes.Length; i++)
			{
				if (bytes[i] != cert.GetPublicKey()[i])
				{
					return false;
				}
			}
#endif
			return true;
		}
开发者ID:GUIpsp,项目名称:MultiMC,代码行数:29,代码来源:AppUtils.cs


示例6: ValidateRemoteCertificate

		private bool ValidateRemoteCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
		{
			IsAuthenticatedByDane = false;

			switch (_tlsaRecords.ValidationResult)
			{
				case DnsSecValidationResult.Signed:
					if (_tlsaRecords.Records.Count == 0)
						return !_enforceTlsaValidation && (sslPolicyErrors == SslPolicyErrors.None);

					foreach (var tlsaRecord in _tlsaRecords.Records)
					{
						if (ValidateCertificateByTlsa(tlsaRecord, certificate, chain, sslPolicyErrors))
						{
							IsAuthenticatedByDane = true;
							return true;
						}
					}

					return false;

				case DnsSecValidationResult.Bogus:
					return false;

				default:
					return !_enforceTlsaValidation && (sslPolicyErrors == SslPolicyErrors.None);
			}
		}
开发者ID:huoxudong125,项目名称:ARSoft.Tools.Net,代码行数:28,代码来源:DaneStream.cs


示例7: OnValidationCallback

        public bool OnValidationCallback(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors errors)
        {
            if (errors.ToString() != "None")
            {
                MessageBox.Show("Please click yes on the next dialog box.\nThis will allow us to install the Net7 certificate.", "Certificate Install",
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                try
                {
                    X509Store Certificate = new X509Store(StoreName.Root);

                    X509Certificate2 cert2 = new X509Certificate2(cert);

                    Certificate.Open(OpenFlags.ReadWrite);

                    // Add Certificate
                    Certificate.Add(cert2);
                    Certificate.Close();
                }
                catch (Exception e)
                {
                    MessageBox.Show("Error installing certificate: " + e.ToString());
                }
            }
            else
            {
                MessageBox.Show("Certificate is installed!");
            }

            // Remove this message
            ServicePointManager.ServerCertificateValidationCallback = null;

            return true;
        }
开发者ID:RavenB,项目名称:Earth-and-Beyond-server,代码行数:34,代码来源:FormMain.cs


示例8: CheckErrors

 internal bool CheckErrors(string hostName, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
 {
     if (sslPolicyErrors == SslPolicyErrors.None)
     {
         return this.Accept(certificate, 0);
     }
     if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateNotAvailable) != SslPolicyErrors.None)
     {
         return this.Accept(certificate, -2146762491);
     }
     if (((sslPolicyErrors & SslPolicyErrors.RemoteCertificateChainErrors) != SslPolicyErrors.None) || ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateNameMismatch) != SslPolicyErrors.None))
     {
         bool fatalError = false;
         uint[] numArray = this.GetChainErrors(hostName, chain, ref fatalError);
         if (fatalError)
         {
             this.Accept(certificate, -2146893052);
             return false;
         }
         if (numArray.Length == 0)
         {
             return this.Accept(certificate, 0);
         }
         foreach (uint num in numArray)
         {
             if (!this.Accept(certificate, (int) num))
             {
                 return false;
             }
         }
     }
     return true;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:33,代码来源:PolicyWrapper.cs


示例9: RemoteCertificateValidationFailedEventArgs

 internal RemoteCertificateValidationFailedEventArgs(X509Certificate certificate, X509Chain chain, SslPolicyErrors error)
 {
     Chain = chain;
     Certificate = certificate;
     PolicyError = error;
     IsCancelled = true;
 }
开发者ID:pravse,项目名称:CommSample,代码行数:7,代码来源:RemoteCertificateValidationFailedEventArgs.cs


示例10: Validate

        /// <summary>
        /// Validates at least one SPKI hash is known.
        /// </summary>
        /// <param name="sender">An object that contains state information for this validation.</param>
        /// <param name="certificate">The certificate used to authenticate the remote party.</param>
        /// <param name="chain">The chain of certificate authorities associated with the remote certificate.</param>
        /// <param name="sslPolicyErrors">One or more errors associated with the remote certificate.</param>
        /// <returns>A Boolean value that determines whether the specified certificate is accepted for authentication.</returns>
        public bool Validate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            if (sslPolicyErrors != SslPolicyErrors.None)
            {
                return false;
            }

            if (chain == null)
            {
                throw new ArgumentNullException("chain");
            }

            if (chain.ChainElements.Count < 2)
            {
                return false;
            }

            using (HashAlgorithm algorithm = CreateHashAlgorithm())
            {
                foreach (var chainElement in chain.ChainElements)
                {
                    X509Certificate2 chainedCertificate = chainElement.Certificate;
                    string base64Spki = Convert.ToBase64String(algorithm.ComputeHash(ExtractSpkiBlob(chainedCertificate)));
                    if (_validBase64EncodedSubjectPublicKeyInfoHashes.Contains(base64Spki))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
开发者ID:Kstal,项目名称:Microsoft.Owin,代码行数:40,代码来源:CertificateSubjectPublicKeyInfoValidator.cs


示例11: CreateBagOfCertificates

 internal static X509Certificate2Collection CreateBagOfCertificates(CmsSigner signer)
 {
     X509Certificate2Collection certificates = new X509Certificate2Collection();
     certificates.AddRange(signer.Certificates);
     if (signer.IncludeOption != X509IncludeOption.None)
     {
         if (signer.IncludeOption == X509IncludeOption.EndCertOnly)
         {
             certificates.Add(signer.Certificate);
             return certificates;
         }
         int count = 1;
         X509Chain chain = new X509Chain();
         chain.Build(signer.Certificate);
         if ((chain.ChainStatus.Length > 0) && ((chain.ChainStatus[0].Status & X509ChainStatusFlags.PartialChain) == X509ChainStatusFlags.PartialChain))
         {
             throw new CryptographicException(-2146762486);
         }
         if (signer.IncludeOption == X509IncludeOption.WholeChain)
         {
             count = chain.ChainElements.Count;
         }
         else if (chain.ChainElements.Count > 1)
         {
             count = chain.ChainElements.Count - 1;
         }
         for (int i = 0; i < count; i++)
         {
             certificates.Add(chain.ChainElements[i].Certificate);
         }
     }
     return certificates;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:33,代码来源:PkcsUtils.cs


示例12: OnValidateServerCertificate

 private static bool OnValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
 {
     HttpWebRequest key = sender as HttpWebRequest;
     if (key != null)
     {
         string str;
         lock (serverCertMap)
         {
             serverCertMap.TryGetValue(key, out str);
         }
         if (str != null)
         {
             try
             {
                 ValidateServerCertificate(certificate, str);
             }
             catch (SecurityNegotiationException exception)
             {
                 if (DiagnosticUtility.ShouldTraceInformation)
                 {
                     DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
                 }
                 return false;
             }
         }
     }
     if (chainedServerCertValidationCallback == null)
     {
         return (sslPolicyErrors == SslPolicyErrors.None);
     }
     return chainedServerCertValidationCallback(sender, certificate, chain, sslPolicyErrors);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:32,代码来源:HttpTransportSecurityHelpers.cs


示例13: ValidateServerCertificate

 bool ValidateServerCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors errors)
 {
     if (errors == 0)
         return true;
     this.OnNotify(new YMSGNotification(Resources._1002, null) { NotificationType = YMSGNotificationTypes.Information });
     return false;
 }
开发者ID:klog,项目名称:ycs,代码行数:7,代码来源:YMSGConnection.Utils.cs


示例14: RemoteCertificateValidationCallback

 public static bool RemoteCertificateValidationCallback(object sender,
                                         X509Certificate certificate,
                                         X509Chain chain,
                                         SslPolicyErrors sslPolicyErrors)
 {
     return true;
 }
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:7,代码来源:X509CertificateLoader.cs


示例15: CmiAuthenticodeSignerInfo

 internal CmiAuthenticodeSignerInfo(System.Deployment.Internal.CodeSigning.Win32.AXL_SIGNER_INFO signerInfo, System.Deployment.Internal.CodeSigning.Win32.AXL_TIMESTAMPER_INFO timestamperInfo)
 {
     this.m_error = (int) signerInfo.dwError;
     if (signerInfo.pChainContext != IntPtr.Zero)
     {
         this.m_signerChain = new X509Chain(signerInfo.pChainContext);
     }
     this.m_algHash = signerInfo.algHash;
     if (signerInfo.pwszHash != IntPtr.Zero)
     {
         this.m_hash = Marshal.PtrToStringUni(signerInfo.pwszHash);
     }
     if (signerInfo.pwszDescription != IntPtr.Zero)
     {
         this.m_description = Marshal.PtrToStringUni(signerInfo.pwszDescription);
     }
     if (signerInfo.pwszDescriptionUrl != IntPtr.Zero)
     {
         this.m_descriptionUrl = Marshal.PtrToStringUni(signerInfo.pwszDescriptionUrl);
     }
     if (timestamperInfo.dwError != 0x800b0100)
     {
         this.m_timestamperInfo = new System.Deployment.Internal.CodeSigning.CmiAuthenticodeTimestamperInfo(timestamperInfo);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:25,代码来源:CmiAuthenticodeSignerInfo.cs


示例16: ValidateCertificate

        private static bool ValidateCertificate(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            if (sslPolicyErrors != SslPolicyErrors.None)
            {
                return false;
            }

            var cert2 = new X509Certificate2(certificate);
            var time = System.DateTime.Now;

            if (time > cert2.NotAfter || time < cert2.NotBefore)
            {
                // expiry
                return false;
            }

            var der_encoded = certificate.Export(X509ContentType.Cert);
            var hash = SHA256.Create().ComputeHash(der_encoded);
            var received_fingerprint = BitConverter.ToString(hash).Replace('-', ':');

            foreach (String fingerprint in Sha256Fingerprints)
            {
                if (fingerprint == received_fingerprint) { return true; }
            }

            return false;
        }
开发者ID:cmr,项目名称:VisualRust,代码行数:27,代码来源:Downloader.cs


示例17: Invoke

        internal bool Invoke(string hostName,
                             ServicePoint servicePoint,
                             X509Certificate certificate,
                             WebRequest request,
                             X509Chain chain,
                             SslPolicyErrors sslPolicyErrors)
        {
            PolicyWrapper policyWrapper = new PolicyWrapper(m_CertificatePolicy,
                                                            servicePoint,
                                                            (WebRequest) request);

            if (m_Context == null)
            {
                return policyWrapper.CheckErrors(hostName,
                                                 certificate,
                                                 chain,
                                                 sslPolicyErrors);
            }
            else
            {
                ExecutionContext execContext = m_Context.CreateCopy();
                CallbackContext callbackContext = new CallbackContext(policyWrapper,
                                                                      hostName,
                                                                      certificate,
                                                                      chain,
                                                                      sslPolicyErrors);
                ExecutionContext.Run(execContext, Callback, callbackContext);
                return callbackContext.result;
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:30,代码来源:ServicePointManager.cs


示例18: AnyCertificateValidationCallback

		/// <summary>
		/// Certificate validation callback to accepts any SSL certificate.
		/// </summary>
		public static bool AnyCertificateValidationCallback(Object sender,
      		X509Certificate certificate,
      		X509Chain chain,
      		SslPolicyErrors sslPolicyErrors) {
			Console.WriteLine("Any Certificate Validation Callback");
        	return true;
		}
开发者ID:brunobouko,项目名称:eid-trust-service,代码行数:10,代码来源:WCFUtil.cs


示例19: ShouldByPassValidationError

        private static bool ShouldByPassValidationError(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            var request = sender as HttpWebRequest;

            if (request == null)
            {
                return true;
            }

            var req = sender as HttpWebRequest;
            var cert2 = certificate as X509Certificate2;
            if (cert2 != null && req != null && cert2.SignatureAlgorithm.FriendlyName == "md5RSA")
            {
                Logger.Error("https://{0} uses the obsolete md5 hash in it's https certificate, if that is your certificate, please (re)create certificate with better algorithm as soon as possible.", req.RequestUri.Authority);
            }

            if (sslPolicyErrors == SslPolicyErrors.None)
            {
                return true;
            }

            Logger.Debug("Certificate validation for {0} failed. {1}", request.Address, sslPolicyErrors);

            return true;
        }
开发者ID:drewfreyling,项目名称:NzbDrone,代码行数:25,代码来源:X509CertificateValidationPolicy.cs


示例20: GetCertificateChain

        public X509Certificate[] GetCertificateChain()
        {
            var list = new List<X509Certificate>();

            var chain = new SystemX509.X509Chain();

            chain.ChainPolicy.RevocationFlag = SystemX509.X509RevocationFlag.EntireChain;
            chain.ChainPolicy.RevocationMode = SystemX509.X509RevocationMode.Online;
            chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 0, 30);
            chain.ChainPolicy.VerificationFlags = SystemX509.X509VerificationFlags.NoFlag;

            if (chain.Build(this.Cert2) == true)
            {
                foreach (SystemX509.X509ChainElement element in chain.ChainElements)
                {
                    list.Add(DotNetUtilities.FromX509Certificate(element.Certificate));
                }
            }
            else
            {
                list.Add(DotNetUtilities.FromX509Certificate(this.Cert2));
            }
            
            return list.ToArray();
        }
开发者ID:Gianluigi,项目名称:dssnet,代码行数:25,代码来源:KSX509Certificate2Entry.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# X509Certificates.X509Extension类代码示例发布时间:2022-05-26
下一篇:
C# X509Certificates.X509CertificateCollection类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap