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


C# SslPolicyErrors.HasFlag方法代码示例

本文整理汇总了C#中SslPolicyErrors.HasFlag方法的典型用法代码示例。如果您正苦于以下问题:C# SslPolicyErrors.HasFlag方法的具体用法?C# SslPolicyErrors.HasFlag怎么用?C# SslPolicyErrors.HasFlag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SslPolicyErrors的用法示例。


在下文中一共展示了SslPolicyErrors.HasFlag方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ValidateCertificateHttpHandler

        private bool ValidateCertificateHttpHandler(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) {
            if (_cancellationToken.IsCancellationRequested) {
                return false;
            }

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

            if (sslPolicyErrors.HasFlag(SslPolicyErrors.RemoteCertificateNotAvailable)) {
                Log.WriteAsync(LogVerbosity.Minimal, MessageCategory.Error, Resources.Error_NoBrokerCertificate).DoNotWait();
                _console.Write(Resources.Error_NoBrokerCertificate.FormatInvariant(Name));
                return false;
            }

            if (_services.MainThread.ThreadId == Thread.CurrentThread.ManagedThreadId) {
                // Prevent potential deadlock if handler enters on background thread, then re-enters on main thread
                // before ValidateX509CertificateAsync is able to transition to the UI thread.
                // At worst the connection fails
                return _certificateValidationResult.HasValue ? _certificateValidationResult.Value : false;
            }

            lock (_verificationLock) {
                if (_certificateValidationResult.HasValue) {
                    return _certificateValidationResult.Value;
                }

                var hashString = certificate.GetCertHashString();
                if (_certificateHash == null || !_certificateHash.EqualsOrdinal(hashString)) {
                    Log.WriteAsync(LogVerbosity.Minimal, MessageCategory.Warning, Resources.Trace_UntrustedCertificate.FormatInvariant(certificate.Subject)).DoNotWait();

                    var message = Resources.CertificateSecurityWarning.FormatInvariant(Uri.Host);
                    var task = _services.Security.ValidateX509CertificateAsync(certificate, message, _cancellationToken);
                    _services.Tasks.Wait(task, _cancellationToken);

                    _certificateValidationResult = task.Result;
                    if (_certificateValidationResult.Value) {
                        _certificateHash = hashString;
                    }
                }
                return _certificateValidationResult.HasValue ? _certificateValidationResult.Value : false;
            }
        }
开发者ID:Microsoft,项目名称:RTVS,代码行数:44,代码来源:RemoteBrokerClient.cs

示例2: TlsCertificateValidationCallback

        /// <summary>
        /// Called by the US.OpenServer.Server and the US.OpenServer.Client.Client
        /// to verify 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>True if the specified certificate is accepted for authentication, otherwise False.</returns>
        public bool TlsCertificateValidationCallback(
            object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            if (sslPolicyErrors.HasFlag(SslPolicyErrors.RemoteCertificateNameMismatch))
            {
                Log(Level.Error, "[TLS] Remote certificate name mismatch.");
                return false;
            }

            if (sslPolicyErrors.HasFlag(SslPolicyErrors.RemoteCertificateNotAvailable))
            {
                if (TlsConfiguration.RequireRemoteCertificate)
                {
                    Log(Level.Error, "[TLS] Remote certificate not available.");
                    return false;
                }
                else
                {
                    Log(Level.Debug, "[TLS] Remote certificate not available.");
                }
            }

            if (sslPolicyErrors.HasFlag(SslPolicyErrors.RemoteCertificateChainErrors))
            {
                if (!TlsConfiguration.AllowCertificateChainErrors)
                {
                    Log(Level.Error, "[TLS] Remote certificate contains chain errors.");
                    return false;
                }
                else
                {
                    Log(Level.Debug, "[TLS] Remote certificate contains chain errors.");
                }
            }
            Log(Level.Info, "[TLS] Certificate validated.");
            return true;
        }
开发者ID:liemqv,项目名称:DotNetOpenServerSDK,代码行数:47,代码来源:Session.cs

示例3: RemoteCertificateValidationCallback

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

            var validation = true;

            if (sslPolicyErrors.HasFlag(SslPolicyErrors.RemoteCertificateChainErrors))
            {
                var isValidateChain = clientNetworkConfig.GetSSLConfig().IsValidateCertificateChain();
                if (isValidateChain)
                {
                    Logger.Warning("Certificate error:" + sslPolicyErrors);
                    validation = false;
                }
                else
                {
                    Logger.Info("SSL Configured to ignore Certificate chain validation. Ignoring:");
                }
                foreach (var status in chain.ChainStatus)
                {
                    Logger.Info("Certificate chain status:" + status.StatusInformation);
                }
            }
            if (sslPolicyErrors.HasFlag(SslPolicyErrors.RemoteCertificateNameMismatch))
            {
                var isValidateName = clientNetworkConfig.GetSSLConfig().IsValidateCertificateName();
                if (isValidateName)
                {
                    Logger.Warning("Certificate error:" + sslPolicyErrors);
                    validation = false;
                }
                else
                {
                    Logger.Info("Certificate name mismatched but client is configured to ignore Certificate name validation.");
                }
            }
            if (sslPolicyErrors.HasFlag(SslPolicyErrors.RemoteCertificateNotAvailable))
            {
                Logger.Warning("Certificate error:" + sslPolicyErrors);
                validation = false;
            }
            return validation;
        }
开发者ID:hazelcast,项目名称:hazelcast-csharp-client,代码行数:46,代码来源:ClientConnection.cs

示例4: ValidateCertificate

        private bool ValidateCertificate(object s, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
        {
            if (error.HasFlag(SslPolicyErrors.RemoteCertificateNameMismatch) || error.HasFlag(SslPolicyErrors.RemoteCertificateChainErrors))
            {

                // This is for local deployments. DevFabric generates its own certificate for load-balancing / port forwarding.
                const string AzureDevFabricCertificateSubject = "CN=127.0.0.1, O=TESTING ONLY, OU=Windows Azure DevFabric";
                if (cert.Subject == AzureDevFabricCertificateSubject)
                {
                    return true;
                }
                var cert2 = new X509Certificate2(cert);
                if (this._trustedRestSubject == cert2.Subject && cert2.Thumbprint == this._trustedRestCertificateHash)
                {
                    return true;
                }
            }

            return error == SslPolicyErrors.None;
        }
开发者ID:votrongdao,项目名称:azure-sdk-for-media-services,代码行数:20,代码来源:OAuthDataServiceAdapter.cs

示例5: ValidateCertificate

        bool ValidateCertificate(object sender, X509Certificate clientCertificate, X509Chain chain, SslPolicyErrors sslpolicyerrors)
        {
            if (sslpolicyerrors.HasFlag(SslPolicyErrors.RemoteCertificateNotAvailable))
                return false;

            return options.ClientCertificateValidator(new X509Certificate2(clientCertificate)) == CertificateValidationResult.Valid;
        }
开发者ID:ZeroBugBounce,项目名称:Halibut,代码行数:7,代码来源:HalibutServer.cs

示例6: CheckServerCertificate

        private bool CheckServerCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            var serverName = (sender is string) ? sender : ((WebRequest)sender).RequestUri.Host;
            _strategy.LogAction("verifying the server certificate for requested server '{0}'", serverName);
            if (sslPolicyErrors != SslPolicyErrors.None)
            {
                var reasons = new List<string>();
                if (sslPolicyErrors.HasFlag(SslPolicyErrors.RemoteCertificateNotAvailable))
                    reasons.Add("the certificate was not returned");
                if (sslPolicyErrors.HasFlag(SslPolicyErrors.RemoteCertificateNameMismatch))
                    reasons.Add(string.Format("the certificate name ({0}) does not match the requested server name",
                                              cert.Subject));
                if (sslPolicyErrors.HasFlag(SslPolicyErrors.RemoteCertificateChainErrors))
                {
                    reasons.Add(string.Format("the certificate chain has errors ({0})",
                                              string.Join("; ", chain.ChainStatus.Select(x => x.StatusInformation))));
                }
                _strategy.LogStatus("The server is not trusted: {0}.", string.Join("; ", reasons));
                return false;
            }

            _strategy.LogAction("verifying that actual server '{0}' was trusted", cert.Subject);
            var m = Regex.Match(cert.Subject, "O=(?'orgid'[^,]+)");
            if (!m.Success)
            {
                _strategy.LogStatus("could not find the organization ID in the certificate subject");
                return false;
            }
            var g = m.Groups["orgid"];
            if (g == null)
            {
                _strategy.LogStatus("could not find the organization ID in the certificate subject (regex said it was there but didn't return it)");
                return false;
            }

            var orgId = g.Value;

            /* TODO
            if (!_info.TrustedOrgIds.Contains(orgId))
            {
                _environment.LogStatus("organization '{0}' is not trusted", orgId);
                return false;
            }
            */
            _strategy.LogStatus("the server is trusted.");
            return true;
        }
开发者ID:skw0rm,项目名称:Xtall,代码行数:47,代码来源:Xtaller.cs


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