本文整理匯總了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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例9: RemoteCertificateValidationFailedEventArgs
internal RemoteCertificateValidationFailedEventArgs(X509Certificate certificate, X509Chain chain, SslPolicyErrors error)
{
Chain = chain;
Certificate = certificate;
PolicyError = error;
IsCancelled = true;
}
示例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;
}
示例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;
}
示例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;
}
示例14: RemoteCertificateValidationCallback
public static bool RemoteCertificateValidationCallback(object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
return true;
}
示例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);
}
}