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


C# X509Certificates.X509Chain类代码示例

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


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


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