本文整理汇总了C#中SslPolicyErrors类的典型用法代码示例。如果您正苦于以下问题:C# SslPolicyErrors类的具体用法?C# SslPolicyErrors怎么用?C# SslPolicyErrors使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SslPolicyErrors类属于命名空间,在下文中一共展示了SslPolicyErrors类的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: ServerCertificateValidationCallback
public static bool ServerCertificateValidationCallback(
Object obj,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors errors)
{
bool result = false;
HttpWebRequest request = obj as HttpWebRequest;
if (request != null)
{
// Check for allowed UserAgent
lock (CertificateValidationHelper.uaLock)
{
if (CertificateValidationHelper.allowedUserAgents.Contains(request.UserAgent))
{
result = true;
}
}
// Check for allowed Url
lock (CertificateValidationHelper.urlLock)
{
if (CertificateValidationHelper.allowedUrls.Contains(request.RequestUri))
{
result = true;
}
}
}
return result;
}
示例3: Validate
/// <summary>
/// Verifies the remote Secure Sockets Layer (SSL) certificate used for authentication.
/// </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, [NotNull] X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors != SslPolicyErrors.None)
{
return false;
}
if (chain.ChainElements.Count < 2)
{
// Self signed.
return false;
}
foreach (var chainElement in chain.ChainElements)
{
string subjectKeyIdentifier = GetSubjectKeyIdentifier(chainElement.Certificate);
if (string.IsNullOrWhiteSpace(subjectKeyIdentifier))
{
continue;
}
if (_validSubjectKeyIdentifiers.Contains(subjectKeyIdentifier))
{
return true;
}
}
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: 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;
}
示例7: 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, [NotNull] X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors != SslPolicyErrors.None)
{
return false;
}
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;
}
示例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: Configure
/// <summary>
/// Configures the rabbit mq client connection for Sll properties.
/// </summary>
/// <param name="builder">Builder with appropriate properties set.</param>
/// <returns>A connection factory builder</returns>
/// <remarks>
/// SSL configuration in Rabbit MQ is a complex topic. In order to ensure that rabbit can work without client presenting a client certificate
/// and working just like an SSL enabled web-site which does not require certificate you need to have the following settings in your rabbitmq.config
/// file.
/// {ssl_options, [{cacertfile,"/path_to/cacert.pem"},
/// {certfile,"/path_to/server/cert.pem"},
/// {keyfile,"/path_to/server/key.pem"},
/// {verify,verify_none},
/// {fail_if_no_peer_cert,false}]}
/// The last 2 lines are the important ones.
/// </remarks>
public ConnectionFactoryBuilder Configure(ConnectionFactoryBuilder builder)
{
builder.Add(connectionFactory =>
{
connectionFactory.Ssl.Enabled = true;
if (!_clientCertificateRequired)
{
// These properties need to be set as empty for the Rabbit MQ client. Null's cause an exception in the client library.
connectionFactory.Ssl.CertPath = string.Empty;
connectionFactory.Ssl.CertPassphrase = string.Empty;
connectionFactory.Ssl.ServerName = string.Empty;
// Because no client certificate is present we must allow the remote certificate name mismatch for the connection to succeed.
_acceptablePolicyErrors = _acceptablePolicyErrors
| SslPolicyErrors.RemoteCertificateNameMismatch;
}
else
{
connectionFactory.Ssl.CertPath = _certificatePath;
connectionFactory.Ssl.CertPassphrase = _passphrase;
connectionFactory.Ssl.ServerName = _serverName;
}
connectionFactory.Ssl.AcceptablePolicyErrors = _acceptablePolicyErrors;
connectionFactory.Ssl.Version = SslProtocols.Tls;
return connectionFactory;
});
return builder;
}
示例11: ComputeX509Chain
public virtual X509Chain ComputeX509Chain (XX509CertificateCollection certs, ref SslPolicyErrors errors, ref int status11)
{
#if MOBILE
return null;
#else
if (is_macosx)
return null;
var chain = new X509Chain ();
chain.ChainPolicy = new X509ChainPolicy ();
chain.ChainPolicy.RevocationMode = revocation_mode;
for (int i = 1; i < certs.Count; i++) {
chain.ChainPolicy.ExtraStore.Add (certs [i]);
}
var leaf = (X509Certificate2)certs [0];
try {
if (!chain.Build (leaf))
errors |= GetErrorsFromChain (chain);
} catch (Exception e) {
Console.Error.WriteLine ("ERROR building certificate chain: {0}", e);
Console.Error.WriteLine ("Please, report this problem to the Mono team");
errors |= SslPolicyErrors.RemoteCertificateChainErrors;
}
status11 = GetStatusFromChain (chain);
return chain;
#endif
}
示例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: BuildX509Chain
static bool BuildX509Chain (XX509CertificateCollection certs, X509Chain chain, ref SslPolicyErrors errors, ref int status11)
{
#if MOBILE
return false;
#else
if (is_macosx)
return false;
var leaf = (X509Certificate2)certs [0];
bool ok;
try {
ok = chain.Build (leaf);
if (!ok)
errors |= GetErrorsFromChain (chain);
} catch (Exception e) {
Console.Error.WriteLine ("ERROR building certificate chain: {0}", e);
Console.Error.WriteLine ("Please, report this problem to the Mono team");
errors |= SslPolicyErrors.RemoteCertificateChainErrors;
ok = false;
}
try {
status11 = GetStatusFromChain (chain);
} catch {
status11 = -2146762485; // TRUST_E_FAIL - generic
}
return ok;
#endif
}