本文整理汇总了C#中SslPolicyErrors类的典型用法代码示例。如果您正苦于以下问题:C# SslPolicyErrors类的具体用法?C# SslPolicyErrors怎么用?C# SslPolicyErrors使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SslPolicyErrors类属于命名空间,在下文中一共展示了SslPolicyErrors类的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: 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;
}
开发者ID:haiyangIt,项目名称:Haiyang,代码行数:32,代码来源:CertificateValidationHelper.cs
示例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;
}
开发者ID:pengweiqhca,项目名称:Security,代码行数:37,代码来源:CertificateSubjectKeyIdentifierValidator.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: 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
示例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;
}
开发者ID:jmloeffler,项目名称:Security,代码行数:35,代码来源:CertificateSubjectPublicKeyInfoValidator.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: 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;
}
开发者ID:cstick,项目名称:MassTransit,代码行数:45,代码来源:SslConnectionFactoryConfiguratorImpl.cs
示例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
}
开发者ID:Test-Classroom-1,项目名称:a-64gigs,代码行数:33,代码来源:SystemCertificateValidator.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: 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
}
开发者ID:razzfazz,项目名称:mono,代码行数:31,代码来源:SystemCertificateValidator.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: 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
示例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: 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
示例20: ValidateServerCertificate
// The following method is invoked by the RemoteCertificateValidationDelegate.
public static bool ValidateServerCertificate(
object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
if(sslPolicyErrors == SslPolicyErrors.None)
{
return true;
}
byte[] receivedCertificateHash = certificate.GetCertHash();
//If length differs, obviously different hash.
if(receivedCertificateHash.Length != hardCodedServerCertificateHash.Length)
{
return false;
}
//Check that each byte is the same
for (int i = 0; i < hardCodedServerCertificateHash.Length; i++)
{
if(receivedCertificateHash[i] != hardCodedServerCertificateHash[i])
{
return false;
}
}
//Equality of the certificates confirmed.
return true;
}
开发者ID:Tsarpf,项目名称:Mobile-MMO,代码行数:31,代码来源:Program.cs
注:本文中的SslPolicyErrors类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论