< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.SecurityBindingElement
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/SecurityBindingElement.cs
Line coverage
66%
Covered lines: 323
Uncovered lines: 161
Coverable lines: 484
Total lines: 1093
Line coverage: 66.7%
Branch coverage
47%
Covered branches: 136
Total branches: 284
Branch coverage: 47.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%11100%
.ctor()100%11100%
.ctor(...)50%6688%
GetSupportingTokensCapabilities(...)100%66100%
GetSupportingTokensCapabilities(...)100%11100%
GetSupportingTokensCapabilities(...)100%11100%
AddDemuxerForSecureConversation(...)100%11100%
ApplyPropertiesOnDemuxer(...)100%11100%
CreateIssuerBindingContextForNegotiation(...)50%4489.47%
CreateIssuedTokenOverTransportBindingElement(...)50%4475%
CreateIssuedTokenForCertificateBindingElement(...)0%440%
CreateIssuedTokenForSslBindingElement(...)0%440%
RequiresChannelDemuxer(...)100%44100%
RequiresChannelDemuxer()33.33%363635.71%
IsUnderlyingDispatcherDuplex(...)50%44100%
ConfigureProtocolFactory(...)50%6685.71%
BuildServiceDispatcher(...)70%101076.92%
CanBuildServiceDispatcher(...)61.11%181885.71%
SetKeyDerivation(...)50%4471.42%
GetProtectionRequirements(...)21.42%141428.12%
GetProperty(...)75%4480%
GetSecurityCapabilities(...)25%4440%
SetIssuerBindingContextIfRequired(...)50%4471.42%
SetIssuerBindingContextIfRequired(...)75%4480%
SetIssuerBindingContextIfRequired(...)87.5%8888.88%
CreateUserNameOverTransportBindingElement()100%11100%
CreateSecureConversationBindingElement(...)100%11100%
CreateSecureConversationBindingElement(...)100%11100%
CreateCertificateOverTransportBindingElement()100%11100%
CreateCertificateOverTransportBindingElement(...)50%4488.23%
CreateSecureConversationBindingElement(...)50%4459.25%
CreateSspiNegotiationOverTransportBindingElement(...)100%11100%
ExportPolicyForTransportTokenAssertionProviders(...)55.55%363666.66%
RequiresWsspTrust(...)50%2266.66%
ExportTransportSecurityBindingElement(...)53.84%262679.41%
HasEndorsingSupportingTokensAtOperationScope(...)33.33%6640%
ExportOperationScopeSupportingTokensPolicy(...)5.88%343412.5%
AddAssertionIfNotNull(...)100%44100%
AddAssertionIfNotNull(...)100%66100%
AddAssertionIfNotNull(...)0%660%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/SecurityBindingElement.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Collections.ObjectModel;
 7using System.Net.Security;
 8using System.Xml;
 9using CoreWCF.Configuration;
 10using CoreWCF.Description;
 11using CoreWCF.IdentityModel.Selectors;
 12using CoreWCF.IdentityModel.Tokens;
 13using CoreWCF.Runtime;
 14using CoreWCF.Runtime.Diagnostics;
 15using CoreWCF.Security;
 16using CoreWCF.Security.Tokens;
 17
 18namespace CoreWCF.Channels
 19{
 20    public abstract class SecurityBindingElement : BindingElement
 21    {
 22        internal const string DefaultAlgorithmSuiteString = "Default";
 423        internal static readonly SecurityAlgorithmSuite s_defaultDefaultAlgorithmSuite = SecurityAlgorithmSuite.Default;
 24        internal const bool DefaultIncludeTimestamp = true;
 25        internal const bool DefaultAllowInsecureTransport = false;
 26        internal const MessageProtectionOrder DefaultMessageProtectionOrder = MessageProtectionOrder.SignBeforeEncryptAn
 27        internal const bool DefaultRequireSignatureConfirmation = false;
 28        internal const bool DefaultEnableUnsecuredResponse = false;
 29        internal const bool DefaultProtectTokens = false;
 30        private SecurityAlgorithmSuite _defaultAlgorithmSuite;
 31        private SecurityKeyEntropyMode _keyEntropyMode;
 32        private readonly Dictionary<string, SupportingTokenParameters> _operationSupportingTokenParameters;
 33        private readonly Dictionary<string, SupportingTokenParameters> _optionalOperationSupportingTokenParameters;
 34        private MessageSecurityVersion _messageSecurityVersion;
 35        private SecurityHeaderLayout _securityHeaderLayout;
 36
 37        internal SecurityBindingElement()
 37238            : base()
 39        {
 37240            _messageSecurityVersion = MessageSecurityVersion.Default;
 37241            _keyEntropyMode = SecurityKeyEntropyMode.CombinedEntropy; // AcceleratedTokenProvider.defaultKeyEntropyMode;
 37242            IncludeTimestamp = DefaultIncludeTimestamp;
 37243            _defaultAlgorithmSuite = s_defaultDefaultAlgorithmSuite;
 37244            LocalServiceSettings = new LocalServiceSecuritySettings();
 37245            EndpointSupportingTokenParameters = new SupportingTokenParameters();
 37246            OptionalEndpointSupportingTokenParameters = new SupportingTokenParameters();
 37247            _operationSupportingTokenParameters = new Dictionary<string, SupportingTokenParameters>();
 37248            _optionalOperationSupportingTokenParameters = new Dictionary<string, SupportingTokenParameters>();
 37249            _securityHeaderLayout = SecurityHeaderLayout.Strict; // SecurityProtocolFactory.defaultSecurityHeaderLayout;
 37250            AllowInsecureTransport = DefaultAllowInsecureTransport;
 37251            EnableUnsecuredResponse = DefaultEnableUnsecuredResponse;
 37252            ProtectTokens = DefaultProtectTokens;
 37253        }
 54
 55        internal SecurityBindingElement(SecurityBindingElement elementToBeCloned)
 139256            : base(elementToBeCloned)
 57        {
 139258            if (elementToBeCloned == null)
 59            {
 060                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(elementToBeCloned));
 61            }
 62
 139263            _defaultAlgorithmSuite = elementToBeCloned._defaultAlgorithmSuite;
 139264            IncludeTimestamp = elementToBeCloned.IncludeTimestamp;
 139265            _keyEntropyMode = elementToBeCloned._keyEntropyMode;
 139266            _messageSecurityVersion = elementToBeCloned._messageSecurityVersion;
 139267            _securityHeaderLayout = elementToBeCloned._securityHeaderLayout;
 139268            EndpointSupportingTokenParameters = (SupportingTokenParameters)elementToBeCloned.EndpointSupportingTokenPara
 139269            OptionalEndpointSupportingTokenParameters = (SupportingTokenParameters)elementToBeCloned.OptionalEndpointSup
 139270            _operationSupportingTokenParameters = new Dictionary<string, SupportingTokenParameters>();
 278471            foreach (string key in elementToBeCloned._operationSupportingTokenParameters.Keys)
 72            {
 073                _operationSupportingTokenParameters[key] = (SupportingTokenParameters)elementToBeCloned._operationSuppor
 74            }
 139275            _optionalOperationSupportingTokenParameters = new Dictionary<string, SupportingTokenParameters>();
 278476            foreach (string key in elementToBeCloned._optionalOperationSupportingTokenParameters.Keys)
 77            {
 078                _optionalOperationSupportingTokenParameters[key] = (SupportingTokenParameters)elementToBeCloned._optiona
 79            }
 139280            LocalServiceSettings = (LocalServiceSecuritySettings)elementToBeCloned.LocalServiceSettings.Clone();
 81            // this.internalDuplexBindingElement = elementToBeCloned.internalDuplexBindingElement;
 139282            MaxReceivedMessageSize = elementToBeCloned.MaxReceivedMessageSize;
 139283            ReaderQuotas = elementToBeCloned.ReaderQuotas;
 139284            DoNotEmitTrust = elementToBeCloned.DoNotEmitTrust;
 139285            AllowInsecureTransport = elementToBeCloned.AllowInsecureTransport;
 139286            EnableUnsecuredResponse = elementToBeCloned.EnableUnsecuredResponse;
 139287            SupportsExtendedProtectionPolicy = elementToBeCloned.SupportsExtendedProtectionPolicy;
 139288            ProtectTokens = elementToBeCloned.ProtectTokens;
 139289        }
 90
 278691        internal bool SupportsExtendedProtectionPolicy { get; set; }
 92
 251493        public SupportingTokenParameters EndpointSupportingTokenParameters { get; }
 94
 168395        public SupportingTokenParameters OptionalEndpointSupportingTokenParameters { get; }
 96
 97        public IDictionary<string, SupportingTokenParameters> OperationSupportingTokenParameters
 98        {
 99            get
 100            {
 293101                return _operationSupportingTokenParameters;
 102            }
 103        }
 104
 105        public IDictionary<string, SupportingTokenParameters> OptionalOperationSupportingTokenParameters
 106        {
 107            get
 108            {
 211109                return _optionalOperationSupportingTokenParameters;
 110            }
 111        }
 112
 113        public SecurityHeaderLayout SecurityHeaderLayout
 114        {
 115            get
 116            {
 77117                return _securityHeaderLayout;
 118            }
 119            set
 120            {
 71121                if (!SecurityHeaderLayoutHelper.IsDefined(value))
 122                {
 0123                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 124                }
 125
 71126                _securityHeaderLayout = value;
 71127            }
 128        }
 129
 130        public MessageSecurityVersion MessageSecurityVersion
 131        {
 132            get
 133            {
 110134                return _messageSecurityVersion;
 135            }
 136            set
 137            {
 502138                _messageSecurityVersion = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Argumen
 502139            }
 140        }
 141
 3221142        public bool EnableUnsecuredResponse { get; set; }
 143
 3780144        public bool IncludeTimestamp { get; set; }
 145
 3158146        public bool AllowInsecureTransport { get; set; }
 147
 148        public SecurityAlgorithmSuite DefaultAlgorithmSuite
 149        {
 150            get
 151            {
 133152                return _defaultAlgorithmSuite;
 153            }
 154            set
 155            {
 419156                _defaultAlgorithmSuite = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Argument
 419157            }
 158        }
 159
 3157160        public bool ProtectTokens { get; set; } = DefaultProtectTokens;
 161
 2549162        public LocalServiceSecuritySettings LocalServiceSettings { get; }
 163
 164        public SecurityKeyEntropyMode KeyEntropyMode
 165        {
 166            get
 167            {
 41168                return _keyEntropyMode;
 169            }
 170            set
 171            {
 1172                if (!SecurityKeyEntropyModeHelper.IsDefined(value))
 173                {
 0174                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 175                }
 1176                _keyEntropyMode = value;
 1177            }
 178        }
 179
 180        internal virtual bool SessionMode
 181        {
 0182            get { return false; }
 183        }
 184
 185        internal virtual bool SupportsDuplex
 186        {
 0187            get { return false; }
 188        }
 189
 190        internal virtual bool SupportsRequestReply
 191        {
 0192            get { return false; }
 193        }
 194
 4677195        internal long MaxReceivedMessageSize { get; set; } = TransportDefaults.MaxReceivedMessageSize;
 196
 2803197        internal bool DoNotEmitTrust { get; set; } = false;
 198
 2988199        internal XmlDictionaryReaderQuotas ReaderQuotas { get; set; }
 200
 201        private void GetSupportingTokensCapabilities(ICollection<SecurityTokenParameters> parameters, out bool supportsC
 202        {
 555203            supportsClientAuth = false;
 555204            supportsWindowsIdentity = false;
 1476205            foreach (SecurityTokenParameters p in parameters)
 206            {
 183207                if (p.SupportsClientAuthentication)
 208                {
 183209                    supportsClientAuth = true;
 210                }
 211
 183212                if (p.SupportsClientWindowsIdentity)
 213                {
 183214                    supportsWindowsIdentity = true;
 215                }
 216            }
 555217        }
 218
 219        private void GetSupportingTokensCapabilities(SupportingTokenParameters requirements, out bool supportsClientAuth
 220        {
 185221            supportsClientAuth = false;
 185222            supportsWindowsIdentity = false;
 185223            GetSupportingTokensCapabilities(requirements.Endorsing, out bool tmpSupportsClientAuth, out bool tmpSupports
 185224            supportsClientAuth = supportsClientAuth || tmpSupportsClientAuth;
 185225            supportsWindowsIdentity = supportsWindowsIdentity || tmpSupportsWindowsIdentity;
 226
 185227            GetSupportingTokensCapabilities(requirements.SignedEndorsing, out tmpSupportsClientAuth, out tmpSupportsWind
 185228            supportsClientAuth = supportsClientAuth || tmpSupportsClientAuth;
 185229            supportsWindowsIdentity = supportsWindowsIdentity || tmpSupportsWindowsIdentity;
 230
 185231            GetSupportingTokensCapabilities(requirements.SignedEncrypted, out tmpSupportsClientAuth, out tmpSupportsWind
 185232            supportsClientAuth = supportsClientAuth || tmpSupportsClientAuth;
 185233            supportsWindowsIdentity = supportsWindowsIdentity || tmpSupportsWindowsIdentity;
 185234        }
 235
 236        internal void GetSupportingTokensCapabilities(out bool supportsClientAuth, out bool supportsWindowsIdentity)
 237        {
 185238            GetSupportingTokensCapabilities(EndpointSupportingTokenParameters, out supportsClientAuth, out supportsWindo
 185239        }
 240
 241        internal void AddDemuxerForSecureConversation(ChannelBuilder builder, BindingContext secureConversationBindingCo
 242        {
 243            //new way
 22244            secureConversationBindingContext.BindingParameters.Add(builder);
 22245        }
 246
 247            // SecureConversation needs a demuxer below security to 1) demux between the security sessions and 2) demux 
 248            // to the authenticator
 249        internal void ApplyPropertiesOnDemuxer(ChannelBuilder builder, BindingContext context)
 250        {
 251            /* TODO later
 252             Collection<ChannelDemuxerBindingElement> demuxerElements = builder.Binding.Elements.FindAll<ChannelDemuxerB
 253             foreach (ChannelDemuxerBindingElement element in demuxerElements)
 254             {
 255                 if (element != null)
 256                 {
 257                     element.MaxPendingSessions = this.LocalServiceSettings.MaxPendingSessions;
 258                     element.PeekTimeout = this.LocalServiceSettings.NegotiationTimeout;
 259                 }
 260             }*/
 22261        }
 262
 263        private static BindingContext CreateIssuerBindingContextForNegotiation(BindingContext issuerBindingContext)
 264        {
 1265            TransportBindingElement transport = issuerBindingContext.RemainingBindingElements.Find<TransportBindingEleme
 1266            if (transport == null)
 267            {
 0268                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.Tra
 269            }
 270            //ChannelDemuxerBindingElement demuxer = null;
 271            //// pick the demuxer above transport (i.e. the last demuxer in the array)
 272            //for (int i = 0; i < issuerBindingContext.RemainingBindingElements.Count; ++i)
 273            //{
 274            //    if (issuerBindingContext.RemainingBindingElements[i] is ChannelDemuxerBindingElement)
 275            //    {
 276            //        demuxer = (ChannelDemuxerBindingElement)issuerBindingContext.RemainingBindingElements[i];
 277            //    }
 278            //}
 279            //if (demuxer == null)
 280            //{
 281            //    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(S
 282            //}
 1283            BindingElementCollection negotiationBindingElements = new BindingElementCollection
 1284            {
 1285                //negotiationBindingElements.Add(demuxer.Clone());
 1286                transport.Clone()
 1287            };
 1288            CustomBinding binding = new CustomBinding(negotiationBindingElements)
 1289            {
 1290                OpenTimeout = issuerBindingContext.Binding.OpenTimeout,
 1291                CloseTimeout = issuerBindingContext.Binding.CloseTimeout,
 1292                SendTimeout = issuerBindingContext.Binding.SendTimeout,
 1293                ReceiveTimeout = issuerBindingContext.Binding.ReceiveTimeout
 1294            };
 1295            if (issuerBindingContext.ListenUriBaseAddress != null)
 296            {
 1297                return new BindingContext(binding, new BindingParameterCollection(issuerBindingContext.BindingParameters
 1298                    issuerBindingContext.ListenUriRelativeAddress);//, issuerBindingContext.ListenUriMode);
 299            }
 300            else
 301            {
 0302                return new BindingContext(binding, new BindingParameterCollection(issuerBindingContext.BindingParameters
 303            }
 304        }
 305
 306        public static TransportSecurityBindingElement CreateIssuedTokenOverTransportBindingElement(IssuedSecurityTokenPa
 307        {
 50308            if (issuedTokenParameters == null)
 309            {
 0310                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(issuedTokenParameters));
 311            }
 312
 50313            issuedTokenParameters.RequireDerivedKeys = false;
 50314            TransportSecurityBindingElement result = new TransportSecurityBindingElement();
 50315            if (issuedTokenParameters.KeyType == SecurityKeyType.BearerKey)
 316            {
 50317                result.EndpointSupportingTokenParameters.Signed.Add(issuedTokenParameters);
 50318                result.MessageSecurityVersion = MessageSecurityVersion.WSSXDefault;
 319            }
 320            else
 321            {
 0322                result.EndpointSupportingTokenParameters.Endorsing.Add(issuedTokenParameters);
 0323                result.MessageSecurityVersion = MessageSecurityVersion.Default;
 324            }
 325
 50326            result.LocalServiceSettings.DetectReplays = false;
 50327            result.IncludeTimestamp = true;
 328
 50329            return result;
 330        }
 331
 332        public static SymmetricSecurityBindingElement CreateIssuedTokenForCertificateBindingElement(IssuedSecurityTokenP
 333        {
 0334            if (issuedTokenParameters == null)
 0335                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(issuedTokenParameters));
 336
 0337            SymmetricSecurityBindingElement result = new SymmetricSecurityBindingElement(
 0338                new X509SecurityTokenParameters(
 0339                    X509KeyIdentifierClauseType.Thumbprint,
 0340                    SecurityTokenInclusionMode.Never));
 0341            if (issuedTokenParameters.KeyType == SecurityKeyType.BearerKey)
 342            {
 0343                result.EndpointSupportingTokenParameters.SignedEncrypted.Add(issuedTokenParameters);
 0344                result.MessageSecurityVersion = MessageSecurityVersion.WSSXDefault;
 345            }
 346            else
 347            {
 0348                result.EndpointSupportingTokenParameters.Endorsing.Add(issuedTokenParameters);
 0349                result.MessageSecurityVersion = MessageSecurityVersion.Default;
 350            }
 0351            result.RequireSignatureConfirmation = true;
 0352            return result;
 353        }
 354
 355        public static SymmetricSecurityBindingElement CreateIssuedTokenForSslBindingElement(IssuedSecurityTokenParameter
 356        {
 0357            if (issuedTokenParameters == null)
 0358                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(issuedTokenParameters));
 359
 0360            SymmetricSecurityBindingElement result = new SymmetricSecurityBindingElement(
 0361                new SslSecurityTokenParameters(false, requireCancellation));
 0362            if (issuedTokenParameters.KeyType == SecurityKeyType.BearerKey)
 363            {
 0364                result.EndpointSupportingTokenParameters.SignedEncrypted.Add(issuedTokenParameters);
 0365                result.MessageSecurityVersion = MessageSecurityVersion.WSSXDefault;
 366            }
 367            else
 368            {
 0369                result.EndpointSupportingTokenParameters.Endorsing.Add(issuedTokenParameters);
 0370                result.MessageSecurityVersion = MessageSecurityVersion.Default;
 371            }
 0372            result.RequireSignatureConfirmation = true;
 0373            return result;
 374        }
 375
 376        internal bool RequiresChannelDemuxer(SecurityTokenParameters parameters)
 377        {
 24378            return (parameters is SecureConversationSecurityTokenParameters)
 24379                    || (parameters is SslSecurityTokenParameters)
 24380                    || (parameters is SspiSecurityTokenParameters);
 381        }
 382
 383        internal virtual bool RequiresChannelDemuxer()
 384        {
 92385            foreach (SecurityTokenParameters parameters in EndpointSupportingTokenParameters.Endorsing)
 386            {
 24387                if (RequiresChannelDemuxer(parameters))
 388                {
 22389                    return true;
 390                }
 391            }
 22392            foreach (SecurityTokenParameters parameters in EndpointSupportingTokenParameters.SignedEndorsing)
 393            {
 0394                if (RequiresChannelDemuxer(parameters))
 395                {
 0396                    return true;
 397                }
 398            }
 22399            foreach (SecurityTokenParameters parameters in OptionalEndpointSupportingTokenParameters.Endorsing)
 400            {
 0401                if (RequiresChannelDemuxer(parameters))
 402                {
 0403                    return true;
 404                }
 405            }
 22406            foreach (SecurityTokenParameters parameters in OptionalEndpointSupportingTokenParameters.SignedEndorsing)
 407            {
 0408                if (RequiresChannelDemuxer(parameters))
 409                {
 0410                    return true;
 411                }
 412            }
 22413            foreach (SupportingTokenParameters supportingParameters in OperationSupportingTokenParameters.Values)
 414            {
 0415                foreach (SecurityTokenParameters parameters in supportingParameters.Endorsing)
 416                {
 0417                    if (RequiresChannelDemuxer(parameters))
 418                    {
 0419                        return true;
 420                    }
 421                }
 0422                foreach (SecurityTokenParameters parameters in supportingParameters.SignedEndorsing)
 423                {
 0424                    if (RequiresChannelDemuxer(parameters))
 425                    {
 0426                        return true;
 427                    }
 428                }
 429            }
 22430            foreach (SupportingTokenParameters supportingParameters in OptionalOperationSupportingTokenParameters.Values
 431            {
 0432                foreach (SecurityTokenParameters parameters in supportingParameters.Endorsing)
 433                {
 0434                    if (RequiresChannelDemuxer(parameters))
 435                    {
 0436                        return true;
 437                    }
 438                }
 0439                foreach (SecurityTokenParameters parameters in supportingParameters.SignedEndorsing)
 440                {
 0441                    if (RequiresChannelDemuxer(parameters))
 442                    {
 0443                        return true;
 444                    }
 445                }
 446            }
 11447            return false;
 22448        }
 449
 450        internal bool IsUnderlyingDispatcherDuplex<TChannel>(BindingContext context)
 451        {
 22452            return (typeof(TChannel) == typeof(IDuplexSessionChannel)) && context.CanBuildNextServiceDispatcher<IDuplexC
 22453                && !context.CanBuildNextServiceDispatcher<IDuplexSessionChannel>();
 454        }
 455
 456        internal void ConfigureProtocolFactory(SecurityProtocolFactory factory, SecurityCredentialsManager credentialsMa
 457        {
 55458            if (factory == null)
 459            {
 0460                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(factory)));
 461            }
 462
 55463            if (credentialsManager == null)
 464            {
 0465                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(credentialsMa
 466            }
 467
 55468            factory.AddTimestamp = IncludeTimestamp;
 55469            factory.IncomingAlgorithmSuite = DefaultAlgorithmSuite;
 55470            factory.OutgoingAlgorithmSuite = DefaultAlgorithmSuite;
 55471            factory.SecurityHeaderLayout = SecurityHeaderLayout;
 55472            factory.TimestampValidityDuration = LocalServiceSettings.TimestampValidityDuration;
 55473            factory.DetectReplays = LocalServiceSettings.DetectReplays;
 55474            factory.MaxCachedNonces = LocalServiceSettings.ReplayCacheSize;
 55475            factory.MaxClockSkew = LocalServiceSettings.MaxClockSkew;
 55476            factory.ReplayWindow = LocalServiceSettings.ReplayWindow;
 477
 55478            if (LocalServiceSettings.DetectReplays)
 479            {
 0480                factory.NonceCache = LocalServiceSettings.NonceCache;
 481            }
 55482            factory.SecurityBindingElement = (SecurityBindingElement)Clone();
 55483            factory.SecurityBindingElement.SetIssuerBindingContextIfRequired(issuerBindingContext);
 55484            factory.SecurityTokenManager = credentialsManager.CreateSecurityTokenManager();
 55485            SecurityTokenSerializer tokenSerializer = factory.SecurityTokenManager.CreateSecurityTokenSerializer(_messag
 55486            factory.StandardsManager = new SecurityStandardsManager(_messageSecurityVersion, tokenSerializer);
 55487        }
 488
 489        internal abstract SecurityProtocolFactory CreateSecurityProtocolFactory<TChannel>(BindingContext context, Securi
 490        bool isForService, BindingContext issuanceBindingContext);
 491
 492        public override IServiceDispatcher BuildServiceDispatcher<TChannel>(BindingContext context, IServiceDispatcher i
 493        {
 33494            if (context == null)
 495            {
 0496                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
 497            }
 498
 33499            if (!CanBuildServiceDispatcher<TChannel>(context))
 500            {
 0501                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.ChannelType
 502            }
 503
 33504            ReaderQuotas = context.GetInnerProperty<XmlDictionaryReaderQuotas>();
 33505            if (ReaderQuotas == null)
 506            {
 0507                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.Enc
 508            }
 509
 33510            TransportBindingElement transportBindingElement = null;
 33511            if (context.RemainingBindingElements != null)
 512            {
 33513                transportBindingElement = context.RemainingBindingElements.Find<TransportBindingElement>();
 514            }
 515
 33516            if (transportBindingElement != null)
 517            {
 33518                MaxReceivedMessageSize = transportBindingElement.MaxReceivedMessageSize;
 519            }
 520
 33521            return BuildServiceDispatcherCore<TChannel>(context, innerDispatcher);
 522        }
 523        protected abstract IServiceDispatcher BuildServiceDispatcherCore<TChannel>(BindingContext context, IServiceDispa
 524            where TChannel : class, IChannel;
 525        public override bool CanBuildServiceDispatcher<TChannel>(BindingContext context)
 526        {
 156527            if (context == null)
 528            {
 0529                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
 530            }
 531
 532            // InternalDuplexBindingElement.AddDuplexListenerSupport(context, ref this.internalDuplexBindingElement);
 533
 534            //  if (this.SessionMode)
 535            //  {
 536            //      return this.CanBuildSessionChannelListener<TChannel>(context);
 537            //  }
 538
 156539            if (!context.CanBuildNextServiceDispatcher<TChannel>())
 540            {
 90541                return false;
 542            }
 543
 66544            return typeof(TChannel) == typeof(IInputChannel) || typeof(TChannel) == typeof(IInputSessionChannel) ||
 66545                (SupportsDuplex && (typeof(TChannel) == typeof(IDuplexChannel) || typeof(TChannel) == typeof(IDuplexSess
 66546                (SupportsRequestReply && (typeof(TChannel) == typeof(IReplyChannel) || typeof(TChannel) == typeof(IReply
 547        }
 548
 549
 550        public virtual void SetKeyDerivation(bool requireDerivedKeys)
 551        {
 71552            EndpointSupportingTokenParameters.SetKeyDerivation(requireDerivedKeys);
 71553            OptionalEndpointSupportingTokenParameters.SetKeyDerivation(requireDerivedKeys);
 142554            foreach (SupportingTokenParameters t in OperationSupportingTokenParameters.Values)
 555            {
 0556                t.SetKeyDerivation(requireDerivedKeys);
 557            }
 558
 142559            foreach (SupportingTokenParameters t in OptionalOperationSupportingTokenParameters.Values)
 560            {
 0561                t.SetKeyDerivation(requireDerivedKeys);
 562            }
 71563        }
 564
 565        internal ChannelProtectionRequirements GetProtectionRequirements(AddressingVersion addressing, ProtectionLevel d
 566        {
 9567            if (addressing == null)
 568            {
 0569                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addressing));
 570            }
 571
 9572            ChannelProtectionRequirements result = new ChannelProtectionRequirements();
 9573            ProtectionLevel supportedRequestProtectionLevel = GetIndividualProperty<ISecurityCapabilities>().SupportedRe
 9574            ProtectionLevel supportedResponseProtectionLevel = GetIndividualProperty<ISecurityCapabilities>().SupportedR
 575
 9576            bool canSupportMoreThanTheDefault =
 9577                ProtectionLevelHelper.IsStrongerOrEqual(supportedRequestProtectionLevel, defaultProtectionLevel)
 9578                && ProtectionLevelHelper.IsStrongerOrEqual(supportedResponseProtectionLevel, defaultProtectionLevel);
 9579            if (canSupportMoreThanTheDefault)
 580            {
 0581                MessagePartSpecification signedParts = new MessagePartSpecification();
 0582                MessagePartSpecification encryptedParts = new MessagePartSpecification();
 0583                if (defaultProtectionLevel != ProtectionLevel.None)
 584                {
 0585                    signedParts.IsBodyIncluded = true;
 0586                    if (defaultProtectionLevel == ProtectionLevel.EncryptAndSign)
 587                    {
 0588                        encryptedParts.IsBodyIncluded = true;
 589                    }
 590                }
 0591                signedParts.MakeReadOnly();
 0592                encryptedParts.MakeReadOnly();
 0593                if (addressing.FaultAction != null)
 594                {
 595                    // Addressing faults
 0596                    result.IncomingSignatureParts.AddParts(signedParts, addressing.FaultAction);
 0597                    result.OutgoingSignatureParts.AddParts(signedParts, addressing.FaultAction);
 0598                    result.IncomingEncryptionParts.AddParts(encryptedParts, addressing.FaultAction);
 0599                    result.OutgoingEncryptionParts.AddParts(encryptedParts, addressing.FaultAction);
 600                }
 0601                if (addressing.DefaultFaultAction != null)
 602                {
 603                    // Faults that do not specify a particular action
 0604                    result.IncomingSignatureParts.AddParts(signedParts, addressing.DefaultFaultAction);
 0605                    result.OutgoingSignatureParts.AddParts(signedParts, addressing.DefaultFaultAction);
 0606                    result.IncomingEncryptionParts.AddParts(encryptedParts, addressing.DefaultFaultAction);
 0607                    result.OutgoingEncryptionParts.AddParts(encryptedParts, addressing.DefaultFaultAction);
 608                }
 609                // Infrastructure faults
 0610                result.IncomingSignatureParts.AddParts(signedParts, FaultCodeConstants.Actions.NetDispatcher);
 0611                result.OutgoingSignatureParts.AddParts(signedParts, FaultCodeConstants.Actions.NetDispatcher);
 0612                result.IncomingEncryptionParts.AddParts(encryptedParts, FaultCodeConstants.Actions.NetDispatcher);
 0613                result.OutgoingEncryptionParts.AddParts(encryptedParts, FaultCodeConstants.Actions.NetDispatcher);
 614            }
 615
 9616            return result;
 617        }
 618
 619        public override T GetProperty<T>(BindingContext context)
 620        {
 432621            if (context == null)
 622            {
 0623                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
 624            }
 432625            if (typeof(T) == typeof(ISecurityCapabilities))
 626            {
 185627                return (T)(object)GetSecurityCapabilities(context);
 628            }
 629            else
 630            {
 247631                return context.GetInnerProperty<T>();
 632            }
 633        }
 634
 635        internal abstract ISecurityCapabilities GetIndividualISecurityCapabilities();
 636
 637        private ISecurityCapabilities GetSecurityCapabilities(BindingContext context)
 638        {
 185639            ISecurityCapabilities thisSecurityCapability = GetIndividualISecurityCapabilities();
 185640            ISecurityCapabilities lowerSecurityCapability = context.GetInnerProperty<ISecurityCapabilities>();
 185641            if (lowerSecurityCapability == null)
 642            {
 185643                return thisSecurityCapability;
 644            }
 645            else
 646            {
 0647                bool supportsClientAuth = thisSecurityCapability.SupportsClientAuthentication;
 0648                bool supportsClientWindowsIdentity = thisSecurityCapability.SupportsClientWindowsIdentity;
 0649                bool supportsServerAuth = thisSecurityCapability.SupportsServerAuthentication || lowerSecurityCapability
 0650                ProtectionLevel requestProtectionLevel = ProtectionLevelHelper.Max(thisSecurityCapability.SupportedReque
 0651                ProtectionLevel responseProtectionLevel = ProtectionLevelHelper.Max(thisSecurityCapability.SupportedResp
 0652                return new SecurityCapabilities(supportsClientAuth, supportsServerAuth, supportsClientWindowsIdentity, r
 653            }
 654        }
 655
 656        private void SetIssuerBindingContextIfRequired(BindingContext issuerBindingContext)
 657        {
 55658            SetIssuerBindingContextIfRequired(EndpointSupportingTokenParameters, issuerBindingContext);
 55659            SetIssuerBindingContextIfRequired(OptionalEndpointSupportingTokenParameters, issuerBindingContext);
 110660            foreach (SupportingTokenParameters parameters in OperationSupportingTokenParameters.Values)
 661            {
 0662                SetIssuerBindingContextIfRequired(parameters, issuerBindingContext);
 663            }
 110664            foreach (SupportingTokenParameters parameters in OptionalOperationSupportingTokenParameters.Values)
 665            {
 0666                SetIssuerBindingContextIfRequired(parameters, issuerBindingContext);
 667            }
 55668        }
 669
 670
 671        protected static void SetIssuerBindingContextIfRequired(SecurityTokenParameters parameters, BindingContext issue
 672        {
 33673            if (parameters is SslSecurityTokenParameters parameters1)
 674            {
 0675                parameters1.IssuerBindingContext = CreateIssuerBindingContextForNegotiation(issuerBindingContext);
 676            }
 33677            else if (parameters is SspiSecurityTokenParameters parameters2)
 678            {
 1679                parameters2.IssuerBindingContext = CreateIssuerBindingContextForNegotiation(issuerBindingContext);
 680            }
 33681        }
 682
 683        private static void SetIssuerBindingContextIfRequired(SupportingTokenParameters supportingParameters, BindingCon
 684        {
 244685            for (int i = 0; i < supportingParameters.Endorsing.Count; ++i)
 686            {
 12687                SetIssuerBindingContextIfRequired(supportingParameters.Endorsing[i], issuerBindingContext);
 688            }
 220689            for (int i = 0; i < supportingParameters.SignedEndorsing.Count; ++i)
 690            {
 0691                SetIssuerBindingContextIfRequired(supportingParameters.SignedEndorsing[i], issuerBindingContext);
 692            }
 224693            for (int i = 0; i < supportingParameters.Signed.Count; ++i)
 694            {
 2695                SetIssuerBindingContextIfRequired(supportingParameters.Signed[i], issuerBindingContext);
 696            }
 258697            for (int i = 0; i < supportingParameters.SignedEncrypted.Count; ++i)
 698            {
 19699                SetIssuerBindingContextIfRequired(supportingParameters.SignedEncrypted[i], issuerBindingContext);
 700            }
 110701        }
 702
 703        // If any changes are made to this method, please make sure that they are
 704        // reflected in the corresponding IsUserNameOverTransportBinding() method.
 705        public static TransportSecurityBindingElement CreateUserNameOverTransportBindingElement()
 706        {
 161707            TransportSecurityBindingElement result = new TransportSecurityBindingElement();
 161708            result.EndpointSupportingTokenParameters.SignedEncrypted.Add(
 161709                new UserNameSecurityTokenParameters());
 161710            result.IncludeTimestamp = true;
 711            //result.LocalClientSettings.DetectReplays = false;
 161712            result.LocalServiceSettings.DetectReplays = false;
 161713            return result;
 714        }
 715
 716        // If any changes are made to this method, please make sure that they are
 717        // reflected in the corresponding IsSecureConversationBinding() method.
 718        public static SecurityBindingElement CreateSecureConversationBindingElement(SecurityBindingElement bootstrapSecu
 719        {
 37720            return CreateSecureConversationBindingElement(bootstrapSecurity, SecureConversationSecurityTokenParameters.d
 721        }
 722
 723        public static SecurityBindingElement CreateSecureConversationBindingElement(SecurityBindingElement bootstrapSecu
 724        {
 86725            return CreateSecureConversationBindingElement(bootstrapSecurity, requireCancellation, null);
 726        }
 727
 728        // If any changes are made to this method, please make sure that they are
 729        // reflected in the corresponding IsCertificateOverTransportBinding() method.
 730        public static TransportSecurityBindingElement CreateCertificateOverTransportBindingElement()
 731        {
 33732            return CreateCertificateOverTransportBindingElement(MessageSecurityVersion.Default);
 733        }
 734
 735        // If any changes are made to this method, please make sure that they are
 736        // reflected in the corresponding IsCertificateOverTransportBinding() method.
 737        public static TransportSecurityBindingElement CreateCertificateOverTransportBindingElement(MessageSecurityVersio
 738        {
 33739            if (version == null)
 740            {
 0741                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(version));
 742            }
 743            X509KeyIdentifierClauseType x509ReferenceType;
 744
 33745            if (version.SecurityVersion == SecurityVersion.WSSecurity10)
 746            {
 0747                x509ReferenceType = X509KeyIdentifierClauseType.Any;
 748            }
 749            else
 750            {
 33751                x509ReferenceType = X509KeyIdentifierClauseType.Thumbprint;
 752            }
 753
 33754            TransportSecurityBindingElement result = new TransportSecurityBindingElement();
 33755            X509SecurityTokenParameters x509Parameters = new X509SecurityTokenParameters(
 33756                    x509ReferenceType,
 33757                    SecurityTokenInclusionMode.AlwaysToRecipient,
 33758                    false);
 33759            result.EndpointSupportingTokenParameters.Endorsing.Add(
 33760                x509Parameters
 33761                );
 33762            result.IncludeTimestamp = true;
 763            // result.LocalClientSettings.DetectReplays = false;
 33764            result.LocalServiceSettings.DetectReplays = false;
 33765            result.MessageSecurityVersion = version;
 766
 33767            return result;
 768        }
 769
 770        // If any changes are made to this method, please make sure that they are
 771        // reflected in the corresponding IsSecureConversationBinding() method.
 772        public static SecurityBindingElement CreateSecureConversationBindingElement(SecurityBindingElement bootstrapSecu
 773        {
 123774            if (bootstrapSecurity == null)
 775            {
 0776                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(bootstrapSecurity));
 777            }
 778
 779            SecurityBindingElement result;
 780
 123781            if (bootstrapSecurity is TransportSecurityBindingElement)
 782            {
 783                // there is no need to do replay detection or key derivation for transport bindings
 123784                TransportSecurityBindingElement primary = new TransportSecurityBindingElement();
 123785                SecureConversationSecurityTokenParameters scParameters = new SecureConversationSecurityTokenParameters(
 123786                        bootstrapSecurity,
 123787                        requireCancellation,
 123788                        bootstrapProtectionRequirements)
 123789                {
 123790                    RequireDerivedKeys = false
 123791                };
 123792                primary.EndpointSupportingTokenParameters.Endorsing.Add(
 123793                    scParameters);
 794                // primary.LocalClientSettings.DetectReplays = false;
 123795                primary.LocalServiceSettings.DetectReplays = false;
 123796                primary.IncludeTimestamp = true;
 123797                result = primary;
 798            }
 799            else // Symmetric- or AsymmetricSecurityBindingElement
 800            {
 0801                SymmetricSecurityBindingElement primary = new SymmetricSecurityBindingElement(
 0802                    new SecureConversationSecurityTokenParameters(
 0803                        bootstrapSecurity,
 0804                        requireCancellation,
 0805                        bootstrapProtectionRequirements))
 0806                {
 0807                    // there is no need for signature confirmation on the steady state binding
 0808                    RequireSignatureConfirmation = false
 0809                };
 0810                result = primary;
 811            }
 123812            return result;
 813        }
 814
 815        // If any changes are made to this method, please make sure that they are
 816        // reflected in the corresponding IsSspiNegotiationOverTransportBinding() method.
 817        public static TransportSecurityBindingElement CreateSspiNegotiationOverTransportBindingElement(bool requireCance
 818        {
 2819            TransportSecurityBindingElement result = new TransportSecurityBindingElement();
 2820            SspiSecurityTokenParameters sspiParameters = new SspiSecurityTokenParameters(requireCancellation)
 2821            {
 2822                RequireDerivedKeys = false
 2823            };
 2824            result.EndpointSupportingTokenParameters.Endorsing.Add(
 2825                sspiParameters);
 2826            result.IncludeTimestamp = true;
 827           // result.LocalClientSettings.DetectReplays = false;
 2828            result.LocalServiceSettings.DetectReplays = false;
 2829            result.SupportsExtendedProtectionPolicy = true;
 830
 2831            return result;
 832        }
 833
 834        //TODO other security mode
 835
 836        public static void ExportPolicyForTransportTokenAssertionProviders(MetadataExporter exporter, PolicyConversionCo
 837        {
 19838            if (exporter == null)
 839            {
 0840                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(exporter));
 841            }
 842
 19843            if (context == null)
 844            {
 0845                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
 846            }
 847
 19848            SecurityTraceRecordHelper.TraceExportChannelBindingEntry();
 849
 19850            SecurityBindingElement binding = null;
 19851            ITransportTokenAssertionProvider transportTokenAssertionProvider = null;
 19852            BindingElementCollection bindingElementsBelowSecurity = new BindingElementCollection();
 19853            if ((context != null) && (context.BindingElements != null))
 854            {
 152855                foreach (BindingElement be in context.BindingElements)
 856                {
 57857                    if (be is SecurityBindingElement element)
 858                    {
 19859                        binding = element;
 860                    }
 861                    else
 862                    {
 38863                        if (binding != null || be is MessageEncodingBindingElement || be is ITransportTokenAssertionProv
 864                        {
 38865                            bindingElementsBelowSecurity.Add(be);
 866                        }
 38867                        if (be is ITransportTokenAssertionProvider provider)
 868                        {
 19869                            transportTokenAssertionProvider = provider;
 870                        }
 871                    }
 872                }
 873            }
 874
 875            // this is used when exporting bootstrap policy for secure conversation in SecurityPolicy11.CreateWsspBootst
 19876            exporter.State[SecurityPolicyStrings.SecureConversationBootstrapBindingElementsBelowSecurityKey] = bindingEl
 877
 19878            bool hasCompletedSuccessfully = false;
 879            try
 880            {
 19881                if (binding is TransportSecurityBindingElement element)
 882                {
 19883                    if (transportTokenAssertionProvider == null && !binding.AllowInsecureTransport)
 884                    {
 0885                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Expor
 886                    }
 887
 19888                    ExportTransportSecurityBindingElement(element, transportTokenAssertionProvider, exporter, context);
 19889                    ExportOperationScopeSupportingTokensPolicy(binding, exporter, context);
 890                }
 0891                else if (transportTokenAssertionProvider != null)
 892                {
 0893                    TransportSecurityBindingElement dummyTransportBindingElement = new TransportSecurityBindingElement()
 0894                    if (binding == null)
 895                    {
 0896                        dummyTransportBindingElement.IncludeTimestamp = false;
 897                    }
 898
 0899                    if (transportTokenAssertionProvider.GetType().Name.Equals("HttpsTransportBindingElement"))
 900                    {
 901                        // This case is handled by HttpsTransportBindingElement
 0902                        return;
 903                    }
 904
 0905                    ExportTransportSecurityBindingElement(dummyTransportBindingElement, transportTokenAssertionProvider,
 906                }
 907
 19908                hasCompletedSuccessfully = true;
 19909            }
 910            finally
 911            {
 912                try
 913                {
 19914                    exporter.State.Remove(SecurityPolicyStrings.SecureConversationBootstrapBindingElementsBelowSecurityK
 19915                }
 0916                catch (Exception e)
 917                {
 918                    // Always immediately rethrow fatal exceptions.
 0919                    if (hasCompletedSuccessfully || Fx.IsFatal(e)) throw;
 0920                }
 19921            }
 19922        }
 923
 924        //
 925        // We will emit the wssp trust 10 assertion for all the case except for the basic http binding
 926        // created through the BasicHttpBinding class.  The reason for this exception is to allow better
 927        // interop with third party when the third party doesn't understand the trust asserion
 928        //
 929        private static bool RequiresWsspTrust(SecurityBindingElement sbe)
 930        {
 19931            if (sbe == null)
 0932                return false;
 933
 19934            return !sbe.DoNotEmitTrust;
 935        }
 936
 937        public static void ExportTransportSecurityBindingElement(TransportSecurityBindingElement binding, ITransportToke
 938        {
 22939            WSSecurityPolicy sp = WSSecurityPolicy.GetSecurityPolicyDriver(binding.MessageSecurityVersion);
 940
 22941            if (transportTokenAssertionProvider == null && binding.AllowInsecureTransport)
 942            {
 0943                if ((policyContext != null) && (policyContext.BindingElements != null))
 944                {
 0945                    foreach (BindingElement be in policyContext.BindingElements)
 946                    {
 0947                        if (be.GetType().FullName.Equals("CoreWCF.Channels.HttpTransportBindingElement"))
 948                        {
 949                            Fx.Assert("This could shouldn't be reachable");
 0950                            throw new NotSupportedException("WSDL generation for binding not supported");
 951                            //transportTokenAssertionProvider = new HttpsTransportBindingElement();
 952                            //break;
 953                        }
 954
 0955                        if (be.GetType().FullName.Equals("CoreWCF.Channels.TcpTransportBindingElement"))
 956                        {
 0957                            throw new Exception("Resolve this");
 958                            //transportTokenAssertionProvider = new SslStreamSecurityBindingElement();
 959                            //break;
 960                        }
 961                    }
 962                }
 963            }
 964
 22965            XmlElement transportTokenAssertion = transportTokenAssertionProvider?.GetTransportTokenAssertion();
 966
 22967            if (transportTokenAssertion == null)
 0968                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.NoT
 969
 22970            AddressingVersion addressingVersion = AddressingVersion.WSAddressing10;
 22971            MessageEncodingBindingElement messageEncoderBindingElement = policyContext.BindingElements.Find<MessageEncod
 22972            if (messageEncoderBindingElement != null)
 973            {
 22974                addressingVersion = messageEncoderBindingElement.MessageVersion.Addressing;
 975            }
 976
 22977            AddAssertionIfNotNull(policyContext, sp.CreateWsspTransportBindingAssertion(exporter, binding, transportToke
 978
 22979            Collection<XmlElement> supportingTokenAssertions = sp.CreateWsspSupportingTokensAssertion(
 22980                exporter,
 22981                binding.EndpointSupportingTokenParameters.Signed,
 22982                binding.EndpointSupportingTokenParameters.SignedEncrypted,
 22983                binding.EndpointSupportingTokenParameters.Endorsing,
 22984                binding.EndpointSupportingTokenParameters.SignedEndorsing,
 22985                binding.OptionalEndpointSupportingTokenParameters.Signed,
 22986                binding.OptionalEndpointSupportingTokenParameters.SignedEncrypted,
 22987                binding.OptionalEndpointSupportingTokenParameters.Endorsing,
 22988                binding.OptionalEndpointSupportingTokenParameters.SignedEndorsing,
 22989                addressingVersion);
 990
 22991            AddAssertionIfNotNull(policyContext, supportingTokenAssertions);
 992
 22993            if (supportingTokenAssertions.Count > 0
 22994                || HasEndorsingSupportingTokensAtOperationScope(binding))
 995            {
 19996                AddAssertionIfNotNull(policyContext, sp.CreateWsspWssAssertion(exporter, binding));
 19997                if (RequiresWsspTrust(binding))
 998                {
 19999                    AddAssertionIfNotNull(policyContext, sp.CreateWsspTrustAssertion(exporter, binding.KeyEntropyMode));
 1000                }
 1001            }
 221002        }
 1003
 1004        private static bool HasEndorsingSupportingTokensAtOperationScope(SecurityBindingElement binding)
 1005        {
 61006            foreach (SupportingTokenParameters r in binding.OperationSupportingTokenParameters.Values)
 1007            {
 01008                if (r.Endorsing.Count > 0 || r.SignedEndorsing.Count > 0)
 1009                {
 01010                    return true;
 1011                }
 1012            }
 1013
 31014            return false;
 01015        }
 1016
 1017        private static void ExportOperationScopeSupportingTokensPolicy(SecurityBindingElement binding, MetadataExporter 
 1018        {
 191019            WSSecurityPolicy sp = WSSecurityPolicy.GetSecurityPolicyDriver(binding.MessageSecurityVersion);
 1020
 191021            if (binding.OperationSupportingTokenParameters.Count == 0 && binding.OptionalOperationSupportingTokenParamet
 1022            {
 191023                return;
 1024            }
 1025
 01026            foreach (OperationDescription operation in policyContext.Contract.Operations)
 1027            {
 01028                foreach (MessageDescription message in operation.Messages)
 1029                {
 1030
 01031                    if (message.Direction == MessageDirection.Input)
 1032                    {
 01033                        SupportingTokenParameters requirements = null;
 01034                        SupportingTokenParameters optionalRequirements = null;
 1035
 01036                        if (binding.OperationSupportingTokenParameters.ContainsKey(message.Action))
 1037                        {
 01038                            requirements = binding.OperationSupportingTokenParameters[message.Action];
 1039                        }
 01040                        if (binding.OptionalOperationSupportingTokenParameters.ContainsKey(message.Action))
 1041                        {
 01042                            optionalRequirements = binding.OptionalOperationSupportingTokenParameters[message.Action];
 1043                        }
 1044
 01045                        if (requirements == null && optionalRequirements == null)
 1046                        {
 1047                            continue;
 1048                        }
 1049
 01050                        AddAssertionIfNotNull(policyContext, operation, sp.CreateWsspSupportingTokensAssertion(
 01051                            exporter,
 01052                            requirements?.Signed,
 01053                            requirements?.SignedEncrypted,
 01054                            requirements?.Endorsing,
 01055                            requirements?.SignedEndorsing,
 01056                            optionalRequirements?.Signed,
 01057                            optionalRequirements?.SignedEncrypted,
 01058                            optionalRequirements?.Endorsing,
 01059                            optionalRequirements?.SignedEndorsing));
 1060                    }
 1061                }
 1062            }
 01063        }
 1064
 1065        private static void AddAssertionIfNotNull(PolicyConversionContext policyContext, XmlElement assertion)
 1066        {
 601067            if (policyContext != null && assertion != null)
 1068            {
 601069                policyContext.GetBindingAssertions().Add(assertion);
 1070            }
 601071        }
 1072
 1073        private static void AddAssertionIfNotNull(PolicyConversionContext policyContext, Collection<XmlElement> assertio
 1074        {
 221075            if (policyContext != null && assertions != null)
 1076            {
 221077                PolicyAssertionCollection existingAssertions = policyContext.GetBindingAssertions();
 821078                for (int i = 0; i < assertions.Count; ++i)
 191079                    existingAssertions.Add(assertions[i]);
 1080            }
 221081        }
 1082
 1083        private static void AddAssertionIfNotNull(PolicyConversionContext policyContext, OperationDescription operation,
 1084        {
 01085            if (policyContext != null && assertions != null)
 1086            {
 01087                PolicyAssertionCollection existingAssertions = policyContext.GetOperationBindingAssertions(operation);
 01088                for (int i = 0; i < assertions.Count; ++i)
 01089                    existingAssertions.Add(assertions[i]);
 1090            }
 01091        }
 1092    }
 1093}

Methods/Properties

.cctor()
.ctor()
.ctor(CoreWCF.Channels.SecurityBindingElement)
SupportsExtendedProtectionPolicy()
EndpointSupportingTokenParameters()
OptionalEndpointSupportingTokenParameters()
OperationSupportingTokenParameters()
OptionalOperationSupportingTokenParameters()
SecurityHeaderLayout()
SecurityHeaderLayout(CoreWCF.Channels.SecurityHeaderLayout)
MessageSecurityVersion()
MessageSecurityVersion(CoreWCF.MessageSecurityVersion)
EnableUnsecuredResponse()
IncludeTimestamp()
AllowInsecureTransport()
DefaultAlgorithmSuite()
DefaultAlgorithmSuite(CoreWCF.Security.SecurityAlgorithmSuite)
ProtectTokens()
LocalServiceSettings()
KeyEntropyMode()
KeyEntropyMode(CoreWCF.Security.SecurityKeyEntropyMode)
SessionMode()
SupportsDuplex()
SupportsRequestReply()
MaxReceivedMessageSize()
DoNotEmitTrust()
ReaderQuotas()
GetSupportingTokensCapabilities(System.Collections.Generic.ICollection`1<CoreWCF.Security.Tokens.SecurityTokenParameters>,System.Boolean&,System.Boolean&)
GetSupportingTokensCapabilities(CoreWCF.Security.Tokens.SupportingTokenParameters,System.Boolean&,System.Boolean&)
GetSupportingTokensCapabilities(System.Boolean&,System.Boolean&)
AddDemuxerForSecureConversation(CoreWCF.Channels.ChannelBuilder,CoreWCF.Channels.BindingContext)
ApplyPropertiesOnDemuxer(CoreWCF.Channels.ChannelBuilder,CoreWCF.Channels.BindingContext)
CreateIssuerBindingContextForNegotiation(CoreWCF.Channels.BindingContext)
CreateIssuedTokenOverTransportBindingElement(CoreWCF.Security.Tokens.IssuedSecurityTokenParameters)
CreateIssuedTokenForCertificateBindingElement(CoreWCF.Security.Tokens.IssuedSecurityTokenParameters)
CreateIssuedTokenForSslBindingElement(CoreWCF.Security.Tokens.IssuedSecurityTokenParameters,System.Boolean)
RequiresChannelDemuxer(CoreWCF.Security.Tokens.SecurityTokenParameters)
RequiresChannelDemuxer()
IsUnderlyingDispatcherDuplex(CoreWCF.Channels.BindingContext)
ConfigureProtocolFactory(CoreWCF.Security.SecurityProtocolFactory,CoreWCF.Security.SecurityCredentialsManager,System.Boolean,CoreWCF.Channels.BindingContext,CoreWCF.Channels.Binding)
BuildServiceDispatcher(CoreWCF.Channels.BindingContext,CoreWCF.Configuration.IServiceDispatcher)
CanBuildServiceDispatcher(CoreWCF.Channels.BindingContext)
SetKeyDerivation(System.Boolean)
GetProtectionRequirements(CoreWCF.Channels.AddressingVersion,System.Net.Security.ProtectionLevel)
GetProperty(CoreWCF.Channels.BindingContext)
GetSecurityCapabilities(CoreWCF.Channels.BindingContext)
SetIssuerBindingContextIfRequired(CoreWCF.Channels.BindingContext)
SetIssuerBindingContextIfRequired(CoreWCF.Security.Tokens.SecurityTokenParameters,CoreWCF.Channels.BindingContext)
SetIssuerBindingContextIfRequired(CoreWCF.Security.Tokens.SupportingTokenParameters,CoreWCF.Channels.BindingContext)
CreateUserNameOverTransportBindingElement()
CreateSecureConversationBindingElement(CoreWCF.Channels.SecurityBindingElement)
CreateSecureConversationBindingElement(CoreWCF.Channels.SecurityBindingElement,System.Boolean)
CreateCertificateOverTransportBindingElement()
CreateCertificateOverTransportBindingElement(CoreWCF.MessageSecurityVersion)
CreateSecureConversationBindingElement(CoreWCF.Channels.SecurityBindingElement,System.Boolean,CoreWCF.Security.ChannelProtectionRequirements)
CreateSspiNegotiationOverTransportBindingElement(System.Boolean)
ExportPolicyForTransportTokenAssertionProviders(CoreWCF.Description.MetadataExporter,CoreWCF.Description.PolicyConversionContext)
RequiresWsspTrust(CoreWCF.Channels.SecurityBindingElement)
ExportTransportSecurityBindingElement(CoreWCF.Channels.TransportSecurityBindingElement,CoreWCF.Channels.ITransportTokenAssertionProvider,CoreWCF.Description.MetadataExporter,CoreWCF.Description.PolicyConversionContext)
HasEndorsingSupportingTokensAtOperationScope(CoreWCF.Channels.SecurityBindingElement)
ExportOperationScopeSupportingTokensPolicy(CoreWCF.Channels.SecurityBindingElement,CoreWCF.Description.MetadataExporter,CoreWCF.Description.PolicyConversionContext)
AddAssertionIfNotNull(CoreWCF.Description.PolicyConversionContext,System.Xml.XmlElement)
AddAssertionIfNotNull(CoreWCF.Description.PolicyConversionContext,System.Collections.ObjectModel.Collection`1<System.Xml.XmlElement>)
AddAssertionIfNotNull(CoreWCF.Description.PolicyConversionContext,CoreWCF.Description.OperationDescription,System.Collections.ObjectModel.Collection`1<System.Xml.XmlElement>)