< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Security.SecurityUtils
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/SecurityUtils.cs
Line coverage
32%
Covered lines: 176
Uncovered lines: 371
Coverable lines: 547
Total lines: 1696
Line coverage: 32.1%
Branch coverage
29%
Covered branches: 115
Total branches: 384
Branch coverage: 29.9%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
ReadContentAsBase64(...)100%110%
EncryptKey(...)100%110%
CreateSymmetricSecurityKeys(...)100%11100%
CreateSecurityKeyIdentifier(...)62.5%8875%
CreateIdentity(...)100%11100%
CreateWindowsIdentity()100%110%
GetSpnFromIdentity(...)0%10100%
IsSystemAccount(...)0%880%
CreateWindowsIdentity(...)0%440%
GetMaxNegotiationBufferSize(...)100%11100%
CloneWindowsIdentityIfNecessary(...)100%110%
CloneWindowsIdentityIfNecessary(...)0%440%
UnsafeGetWindowsIdentityToken(...)100%110%
UnsafeCreateWindowsIdentityFromToken(...)0%220%
GetPrimaryIdentityClaim(...)100%11100%
GetPrimaryIdentityClaim(...)50%6685.71%
GetPrimaryDomain()100%110%
GetPrimaryDomain(...)0%660%
EnsureCertificateCanDoKeyExchange(...)66.66%6657.14%
CreateTokenFromEncryptedKeyClause(...)100%110%
CanKeyDoKeyExchange(...)75%8890%
DecryptKey(...)0%880%
CreateSecurityContextNotFoundFault(...)0%220%
CreateSecurityMessageFault(...)66.66%242471.05%
GenerateId()100%11100%
GenerateDerivedKey(...)0%440%
TryCreateKeyFromIntrinsicKeyClause(...)0%880%
HasSymmetricSecurityKey(...)100%110%
CloneBuffer(...)100%11100%
CloneBuffer(...)100%110%
IsSupportedAlgorithm(...)0%660%
GetSecurityKey(...)0%880%
TryCreateX509CertificateFromRawData(...)50%66100%
GetKeyDerivationAlgorithm(...)0%440%
CreateIdentity(...)100%11100%
CloneAuthorizationPoliciesIfNecessary(...)62.5%161642.85%
DisposeAuthorizationPoliciesIfNecessary(...)100%66100%
DisposeIfNecessary(...)100%22100%
GetChannelBindingFromMessage(...)50%4471.42%
GetNetworkCredentialsCopy(...)50%4475%
IsNullOrEmpty(...)0%660%
IsDefault(...)100%110%
UnsafeGetUsername(...)100%110%
UnsafeGetPassword(...)100%110%
UnsafeGetDomain(...)100%110%
UnsafeGetDefaultNetworkCredentials()100%110%
GetCertificateFromStore(...)0%220%
GetCertificateFromStoreCore(...)0%660%
CreateCertificateLoadException(...)0%660%
GenerateUniqueId()100%11100%
ResetAllCertificates(...)0%440%
ErasePasswordInUsernameTokenIfPresent(...)100%110%
ResetCertificate(...)100%11100%
OpenTokenAuthenticatorIfRequiredAsync(...)100%11100%
OpenTokenProviderIfRequiredAsync(...)100%110%
CloseTokenProviderIfRequiredAsync(...)100%110%
AbortTokenAuthenticatorIfRequired(...)100%110%
AbortTokenProviderIfRequired(...)100%110%
CloseTokenAuthenticatorIfRequiredAsync(...)100%110%
CloseTokenAuthenticatorIfRequiredAsync(...)100%110%
OpenCommunicationObjectAsync(...)100%22100%
CloseCommunicationObjectAsync(...)0%880%
ValidateAnonymityConstraint(...)0%440%
GetIssuerSecurityBindingElement(...)25%4437.5%
CreateSecurityStandardsManager(...)100%11100%
CreateSecurityStandardsManager(...)58.33%121264.28%
CreateSecurityStandardsManager(...)0%440%
MatchRstWithEndpointFilter(...)25%4433.33%
IsEqual(...)0%10100%
IsCurrentlyTimeEffective(...)66.66%66100%
ShouldMatchRstWithEndpointFilter(...)100%44100%
GetIdentityNamesFromPolicies(...)100%110%
GetIdentityNamesFromContext(...)0%26260%
AppendIdentityName(...)0%10100%
AppendCertificateIdentityName(...)0%10100%
GetCertificateId(...)0%220%
MatchesBuffer(...)100%110%
MatchesBuffer(...)61.11%181866.66%
ClaimSetToString(...)0%10100%
CreateAuthorizationPolicies(...)100%11100%
CreateAuthorizationPolicies(...)100%11100%
CloneIdentityIfNecessary(...)0%440%
CloneClaimSetIfNecessary(...)0%440%
CloneClaimSetsIfNecessary(...)0%10100%
DisposeClaimSetIfNecessary(...)0%220%
DisposeClaimSetsIfNecessary(...)0%440%
.ctor(...)100%44100%
CreateDefaultAuthorizationContext(...)95%202089.47%
IsRequestSecurityContextIssuance(...)0%440%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/SecurityUtils.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.ComponentModel;
 8using System.Diagnostics;
 9using System.DirectoryServices.ActiveDirectory;
 10using System.Globalization;
 11using System.Net;
 12using System.Net.Security;
 13using System.Runtime.InteropServices;
 14using System.Security.Authentication.ExtendedProtection;
 15using System.Security.Cryptography;
 16using System.Security.Cryptography.X509Certificates;
 17using System.Security.Principal;
 18using System.Text;
 19using System.Threading;
 20using System.Threading.Tasks;
 21using System.Xml;
 22using CoreWCF.Channels;
 23using CoreWCF.Dispatcher;
 24using CoreWCF.IdentityModel;
 25using CoreWCF.IdentityModel.Claims;
 26using CoreWCF.IdentityModel.Policy;
 27using CoreWCF.IdentityModel.Selectors;
 28using CoreWCF.IdentityModel.Tokens;
 29using CoreWCF.Runtime;
 30using CoreWCF.Security.Tokens;
 31
 32namespace CoreWCF.Security
 33{
 34    internal static class ProtectionLevelHelper
 35    {
 36        internal static bool IsDefined(ProtectionLevel value)
 37        {
 38            return (value == ProtectionLevel.None
 39                || value == ProtectionLevel.Sign
 40                || value == ProtectionLevel.EncryptAndSign);
 41        }
 42
 43        internal static void Validate(ProtectionLevel value)
 44        {
 45            if (!IsDefined(value))
 46            {
 47                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidEnumArgumentException(nameof(value)
 48                    typeof(ProtectionLevel)));
 49            }
 50        }
 51
 52        internal static bool IsStronger(ProtectionLevel v1, ProtectionLevel v2)
 53        {
 54            return ((v1 == ProtectionLevel.EncryptAndSign && v2 != ProtectionLevel.EncryptAndSign)
 55                    || (v1 == ProtectionLevel.Sign && v2 == ProtectionLevel.None));
 56        }
 57
 58        internal static bool IsStrongerOrEqual(ProtectionLevel v1, ProtectionLevel v2)
 59        {
 60            return (v1 == ProtectionLevel.EncryptAndSign
 61                    || (v1 == ProtectionLevel.Sign && v2 != ProtectionLevel.EncryptAndSign));
 62        }
 63
 64        internal static ProtectionLevel Max(ProtectionLevel v1, ProtectionLevel v2)
 65        {
 66            return IsStronger(v1, v2) ? v1 : v2;
 67        }
 68
 69        internal static int GetOrdinal(Nullable<ProtectionLevel> p)
 70        {
 71            if (p.HasValue)
 72            {
 73                switch ((ProtectionLevel)p)
 74                {
 75                    default:
 76                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidEnumArgumentException(nameo
 77                    case ProtectionLevel.None:
 78                        return 2;
 79                    case ProtectionLevel.Sign:
 80                        return 3;
 81                    case ProtectionLevel.EncryptAndSign:
 82                        return 4;
 83                }
 84            }
 85            else
 86            {
 87                return 1;
 88            }
 89        }
 90    }
 91
 92    internal class ServiceModelDictionaryManager
 93    {
 94        private static DictionaryManager s_dictionaryManager;
 95
 96        public static DictionaryManager Instance
 97        {
 98            get
 99            {
 100                if (s_dictionaryManager == null)
 101                {
 102                    s_dictionaryManager = new DictionaryManager((ServiceModelDictionary)BinaryMessageEncoderFactory.XmlD
 103                }
 104
 105                return s_dictionaryManager;
 106            }
 107        }
 108    }
 109
 110    internal class SecurityUtils
 111    {
 112        public const string Principal = "Principal";
 113        public const string Identities = "Identities";
 114        public const string AuthTypeCertMap = "SSL/PCT";
 115        private static SecurityIdentifier s_administratorsSid;
 116        internal static byte[] ReadContentAsBase64(XmlDictionaryReader reader, long maxBufferSize)
 117        {
 0118            throw new PlatformNotSupportedException();
 119        }
 120
 121        private static bool s_computedDomain;
 122
 123        internal static byte[] EncryptKey(SecurityToken wrappingToken, string wrappingAlgorithm, byte[] keyToWrap)
 124        {
 0125            throw new PlatformNotSupportedException();
 126        }
 127
 128        private static string s_currentDomain;
 129        private static IIdentity s_anonymousIdentity;
 130        private static X509SecurityTokenAuthenticator s_nonValidatingX509Authenticator;
 131        private static byte[] s_combinedHashLabel;
 132
 133        internal static byte[] CombinedHashLabel
 134        {
 135            get
 136            {
 0137                if (s_combinedHashLabel == null)
 0138                    s_combinedHashLabel = Encoding.UTF8.GetBytes(TrustApr2004Strings.CombinedHashLabel);
 0139                return s_combinedHashLabel;
 140            }
 141        }
 142
 143        internal static IIdentity AnonymousIdentity
 144        {
 145            get
 146            {
 86147                if (s_anonymousIdentity == null)
 148                {
 4149                    s_anonymousIdentity = CreateIdentity(string.Empty);
 150                }
 86151                return s_anonymousIdentity;
 152            }
 153        }
 154
 155        internal static X509SecurityTokenAuthenticator NonValidatingX509Authenticator
 156        {
 157            get
 158            {
 0159                if (s_nonValidatingX509Authenticator == null)
 160                {
 0161                    s_nonValidatingX509Authenticator = new X509SecurityTokenAuthenticator(X509CertificateValidator.None)
 162                }
 0163                return s_nonValidatingX509Authenticator;
 164            }
 165        }
 166
 60167        public static DateTime MinUtcDateTime => new DateTime(DateTime.MinValue.Ticks + TimeSpan.TicksPerDay, DateTimeKi
 168
 169        public static DateTime MaxUtcDateTime =>
 170                // + and -  TimeSpan.TicksPerDay is to compensate the DateTime.ParseExact (to localtime) overflow.
 165171                new DateTime(DateTime.MaxValue.Ticks - TimeSpan.TicksPerDay, DateTimeKind.Utc);
 172
 173        public static SecurityIdentifier AdministratorsSid
 174        {
 175            get
 176            {
 0177                if (s_administratorsSid == null)
 178                {
 0179                    s_administratorsSid = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);
 180                }
 181
 0182                return s_administratorsSid;
 183            }
 184        }
 185
 186
 187
 188        internal static ReadOnlyCollection<SecurityKey> CreateSymmetricSecurityKeys(byte[] key)
 189        {
 2190            List<SecurityKey> temp = new List<SecurityKey>(1)
 2191            {
 2192                new InMemorySymmetricSecurityKey(key)
 2193            };
 2194            return temp.AsReadOnly();
 195        }
 196
 197        internal static SecurityKeyIdentifier CreateSecurityKeyIdentifier(Microsoft.IdentityModel.Xml.KeyInfo keyInfo)
 198        {
 50199            if(keyInfo!=null && keyInfo.RSAKeyValue !=null)
 200            {
 0201                throw new NotSupportedException("RSA key not supported.");
 202            }
 203
 150204            foreach (var objdata in keyInfo.X509Data)
 205            {
 150206                foreach (string certificateStr in objdata.Certificates)
 207                {
 50208                    byte[] data = Convert.FromBase64String(certificateStr);
 50209                    return new SecurityKeyIdentifier(new X509RawDataKeyIdentifierClause(data, false));;
 210                }
 211            }
 212
 0213            return null;
 50214        }
 215
 216        internal static IIdentity CreateIdentity(string name)
 217        {
 4218            return new GenericIdentity(name);
 219        }
 220
 221        internal static EndpointIdentity CreateWindowsIdentity()
 222        {
 0223            return CreateWindowsIdentity(false);
 224        }
 225
 226        internal static string GetSpnFromIdentity(EndpointIdentity identity, EndpointAddress target)
 227        {
 0228            bool foundSpn = false;
 0229            string spn = null;
 0230            if (identity != null)
 231            {
 0232                if (ClaimTypes.Spn.Equals(identity.IdentityClaim.ClaimType))
 233                {
 0234                    spn = (string)identity.IdentityClaim.Resource;
 0235                    foundSpn = true;
 236                }
 0237                else if (ClaimTypes.Upn.Equals(identity.IdentityClaim.ClaimType))
 238                {
 0239                    spn = (string)identity.IdentityClaim.Resource;
 0240                    foundSpn = true;
 241                }
 0242                else if (ClaimTypes.Dns.Equals(identity.IdentityClaim.ClaimType))
 243                {
 0244                    spn = string.Format(CultureInfo.InvariantCulture, "host/{0}", (string)identity.IdentityClaim.Resourc
 0245                    foundSpn = true;
 246                }
 247            }
 0248            if (!foundSpn)
 249            {
 0250                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.Format(SR.Cann
 251            }
 0252            return spn;
 253        }
 254
 255        private static bool IsSystemAccount(WindowsIdentity self)
 256        {
 0257            SecurityIdentifier sid = self.User;
 0258            if (sid == null)
 259            {
 0260                return false;
 261            }
 262            // S-1-5-82 is the prefix for the sid that represents the identity that IIS 7.5 Apppool thread runs under.
 0263            return (sid.IsWellKnown(WellKnownSidType.LocalSystemSid)
 0264                    || sid.IsWellKnown(WellKnownSidType.NetworkServiceSid)
 0265                    || sid.IsWellKnown(WellKnownSidType.LocalServiceSid)
 0266                    || self.User.Value.StartsWith("S-1-5-82", StringComparison.OrdinalIgnoreCase));
 267        }
 268
 269        internal static EndpointIdentity CreateWindowsIdentity(bool spnOnly)
 270        {
 271            // This is used by SspiNegotiationTokenAuthenticator to calculate the
 272            // DefaultServiceBinding value. On Linux, we cannot use the current Windows Identity,
 273            // so we will return an Spn based on the machine name. It's quite a bit of work to
 274            // get Windows authentication to work on Linux, so if a developer has gone to that
 275            // kind of effort to use Windows authentication on Linux, they can provide an
 276            // explicit value to SspiNegotiationTokenAuthenticator.DefaultServiceBinding and
 277            // this code won't be needed.
 0278            EndpointIdentity identity = null;
 0279            using (WindowsIdentity self = WindowsIdentity.GetCurrent())
 280            {
 0281                bool isSystemAccount = IsSystemAccount(self);
 0282                if (spnOnly || isSystemAccount || !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
 283                {
 284                    // If we're running on a non-Windows platform, we can't use the current Windows identity.
 285                    // If we're running on Windows and the current identity is a system account, we also can't use it.
 286                    // In both cases, we create an SPN identity based on the machine name.
 0287                    identity = new SpnEndpointIdentity(string.Format(CultureInfo.InvariantCulture, "host/{0}", DnsCache.
 288                }
 289                else
 290                {
 291                    // Fallback to using the current WindowsIdentity Name, which will be in the form DOMAIN\username.
 0292                    identity = new UpnEndpointIdentity(self.Name);
 293                }
 0294            }
 295
 0296            return identity;
 297        }
 298
 299        internal static int GetMaxNegotiationBufferSize(BindingContext bindingContext)
 300        {
 1301            TransportBindingElement transport = bindingContext.RemainingBindingElements.Find<TransportBindingElement>();
 302            Fx.Assert(transport != null, "TransportBindingElement is null!");
 303            int maxNegoMessageSize;
 304            //TODO move below binding elements to Primitives
 305            //if (transport is ConnectionOrientedTransportBindingElement)
 306            //{
 307            //    maxNegoMessageSize = ((ConnectionOrientedTransportBindingElement)transport).MaxBufferSize;
 308            //}
 309            //else if (transport is HttpTransportBindingElement)
 310            //{
 311            //    maxNegoMessageSize = ((HttpTransportBindingElement)transport).MaxBufferSize;
 312            //}
 313            //else
 314            //{
 1315                maxNegoMessageSize = TransportDefaults.MaxBufferSize;
 316           // }
 1317            return maxNegoMessageSize;
 318        }
 319
 320        internal static WindowsIdentity CloneWindowsIdentityIfNecessary(WindowsIdentity wid)
 321        {
 0322            return CloneWindowsIdentityIfNecessary(wid, null);
 323        }
 324
 325        internal static WindowsIdentity CloneWindowsIdentityIfNecessary(WindowsIdentity wid, string authType)
 326        {
 0327            if (wid != null)
 328            {
 0329                IntPtr token = UnsafeGetWindowsIdentityToken(wid);
 0330                if (token != IntPtr.Zero)
 331                {
 0332                    return UnsafeCreateWindowsIdentityFromToken(token, authType);
 333                }
 334            }
 0335            return wid;
 336        }
 337
 338        private static IntPtr UnsafeGetWindowsIdentityToken(WindowsIdentity wid)
 339        {
 0340            return wid.Token;
 341        }
 342
 343        private static WindowsIdentity UnsafeCreateWindowsIdentityFromToken(IntPtr token, string authType)
 344        {
 0345            if (authType != null)
 346            {
 0347                return new WindowsIdentity(token, authType);
 348            }
 349            else
 350            {
 0351                return new WindowsIdentity(token);
 352            }
 353        }
 354
 355        internal static Claim GetPrimaryIdentityClaim(ReadOnlyCollection<IAuthorizationPolicy> authorizationPolicies)
 356        {
 10357            return GetPrimaryIdentityClaim(AuthorizationContext.CreateDefaultAuthorizationContext(authorizationPolicies)
 358        }
 359
 360        internal static Claim GetPrimaryIdentityClaim(AuthorizationContext authContext)
 361        {
 10362            if (authContext != null)
 363            {
 20364                for (int i = 0; i < authContext.ClaimSets.Count; ++i)
 365                {
 10366                    ClaimSet claimSet = authContext.ClaimSets[i];
 30367                    foreach (Claim claim in claimSet.FindClaims(null, Rights.Identity))
 368                    {
 10369                        return claim;
 370                    }
 371                }
 372            }
 0373            return null;
 10374        }
 375
 376        internal static string GetPrimaryDomain()
 377        {
 0378            using (WindowsIdentity wid = WindowsIdentity.GetCurrent())
 379            {
 0380                return GetPrimaryDomain(IsSystemAccount(wid));
 381            }
 0382        }
 383
 384        internal static string GetPrimaryDomain(bool isSystemAccount)
 385        {
 0386            if (s_computedDomain == false)
 387            {
 388                try
 389                {
 0390                    if (isSystemAccount)
 391                    {
 0392                        s_currentDomain = Domain.GetComputerDomain().Name;
 393                    }
 394                    else
 395                    {
 0396                        s_currentDomain = Domain.GetCurrentDomain().Name;
 397                    }
 0398                }
 399                catch (Exception e)
 400                {
 0401                    if (Fx.IsFatal(e))
 402                    {
 0403                        throw;
 404                    }
 0405                    DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning);
 0406                }
 407                finally
 408                {
 0409                    s_computedDomain = true;
 0410                }
 411            }
 0412            return s_currentDomain;
 413        }
 414
 415        internal static void EnsureCertificateCanDoKeyExchange(X509Certificate2 certificate)
 416        {
 5417            if (certificate == null)
 418            {
 0419                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(certificate));
 420            }
 5421            bool canDoKeyExchange = false;
 5422            Exception innerException = null;
 5423            if (certificate.HasPrivateKey)
 424            {
 425                try
 426                {
 5427                    canDoKeyExchange = CanKeyDoKeyExchange(certificate);
 5428                }
 429                // exceptions can be due to ACLs on the key etc
 430                catch (System.Security.SecurityException e)
 431                {
 0432                    innerException = e;
 0433                }
 434                catch (CryptographicException e)
 435                {
 0436                    innerException = e;
 0437                }
 438            }
 5439            if (!canDoKeyExchange)
 440            {
 0441                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.SslCertMayN
 442            }
 5443        }
 444
 445        public static WrappedKeySecurityToken CreateTokenFromEncryptedKeyClause(EncryptedKeyIdentifierClause keyClause, 
 446        {
 0447            SecurityKeyIdentifier wrappingTokenReference = keyClause.EncryptingKeyIdentifier;
 0448            byte[] wrappedKey = keyClause.GetEncryptedKey();
 0449            SecurityKey unwrappingSecurityKey = unwrappingToken.SecurityKeys[0];
 0450            string wrappingAlgorithm = keyClause.EncryptionMethod;
 0451            byte[] unwrappedKey = unwrappingSecurityKey.DecryptKey(wrappingAlgorithm, wrappedKey);
 452            //TODO, check value for XmlDictionaryString Symmetric or else
 0453            return new WrappedKeySecurityToken(SecurityUtils.GenerateId(), unwrappedKey, wrappingAlgorithm,
 0454               XmlDictionaryString.Empty, unwrappingToken, wrappingTokenReference, wrappedKey, unwrappingSecurityKey
 0455                    );
 456        }
 457
 458        private static bool CanKeyDoKeyExchange(X509Certificate2 certificate)
 459        {
 5460            X509KeyUsageExtension keyUsageExtension = null;
 20461            for (int i = 0; i < certificate.Extensions.Count; i++)
 462            {
 10463                keyUsageExtension = certificate.Extensions[i] as X509KeyUsageExtension;
 10464                if (keyUsageExtension != null)
 465                {
 466                    break;
 467                }
 468            }
 469
 470            // No KeyUsage extension means most usages are permitted including key exchange.
 471            // See RFC 5280 section 4.2.1.3 (Key Usage) for details. If the extension is non-critical
 472            // then it's non-enforcing and meant as an aid in choosing the best certificate when
 473            // there are multiple certificates to choose from.
 5474            if (keyUsageExtension == null || !keyUsageExtension.Critical)
 475            {
 0476                return true;
 477            }
 478
 479            // One of KeyAgreement, KeyEncipherment or DigitalSignature need to be allowed depending on the cipher
 480            // being used. See RFC 5246 section 7.4.6 for more details.
 481            // Additionally, according to msdn docs for PFXImportCertStore, the key specification is set to AT_KEYEXCHAN
 482            // when the data encipherment usage is set.
 5483            bool canDoKeyExchange = (keyUsageExtension.KeyUsages &
 5484                (X509KeyUsageFlags.KeyAgreement | X509KeyUsageFlags.KeyEncipherment |
 5485                    X509KeyUsageFlags.DigitalSignature | X509KeyUsageFlags.DataEncipherment)) != X509KeyUsageFlags.None;
 5486            return canDoKeyExchange;
 487        }
 488
 489        internal static byte[] DecryptKey(SecurityToken unwrappingToken, string encryptionMethod, byte[] wrappedKey, out
 490        {
 0491            unwrappingSecurityKey = null;
 0492            if (unwrappingToken.SecurityKeys != null)
 493            {
 0494                for (int i = 0; i < unwrappingToken.SecurityKeys.Count; ++i)
 495                {
 0496                    if (unwrappingToken.SecurityKeys[i].IsSupportedAlgorithm(encryptionMethod))
 497                    {
 0498                        unwrappingSecurityKey = unwrappingToken.SecurityKeys[i];
 0499                        break;
 500                    }
 501                }
 502            }
 0503            if (unwrappingSecurityKey == null)
 504            {
 0505                throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new MessageSecurityException(SR.Format(SR.Ca
 506            }
 0507            return unwrappingSecurityKey.DecryptKey(encryptionMethod, wrappedKey);
 508        }
 509
 510        internal static MessageFault CreateSecurityContextNotFoundFault(SecurityStandardsManager standardsManager, strin
 511        {
 0512            SecureConversationDriver scDriver = standardsManager.SecureConversationDriver;
 0513            FaultCode subCode = new FaultCode(scDriver.BadContextTokenFaultCode.Value, scDriver.Namespace.Value);
 514            FaultReason reason;
 0515            if (action != null)
 516            {
 0517                reason = new FaultReason(SR.Format(SR.BadContextTokenOrActionFaultReason, action), CultureInfo.CurrentCu
 518            }
 519            else
 520            {
 0521                reason = new FaultReason(SR.Format(SR.BadContextTokenFaultReason), CultureInfo.CurrentCulture);
 522            }
 0523            FaultCode senderCode = FaultCode.CreateSenderFaultCode(subCode);
 0524            return MessageFault.CreateFault(senderCode, reason);
 525        }
 526
 527        internal static MessageFault CreateSecurityMessageFault(Exception e, SecurityStandardsManager standardsManager)
 528        {
 31529            bool isSecurityError = false;
 31530            bool isTokenValidationError = false;
 31531            bool isGenericTokenError = false;
 31532            FaultException faultException = null;
 84533            while (e != null)
 534            {
 62535                if (e is SecurityTokenValidationException)
 536                {
 9537                    if (e is SecurityContextTokenValidationException)
 538                    {
 0539                        return CreateSecurityContextNotFoundFault(SecurityStandardsManager.DefaultInstance, null);
 540                    }
 9541                    isSecurityError = true;
 9542                    isTokenValidationError = true;
 9543                    break;
 544                }
 53545                else if (e is SecurityTokenException)
 546                {
 0547                    isSecurityError = true;
 0548                    isGenericTokenError = true;
 0549                    break;
 550                }
 53551                else if (e is MessageSecurityException ms)
 552                {
 31553                    if (ms.Fault != null)
 554                    {
 0555                        return ms.Fault;
 556                    }
 31557                    isSecurityError = true;
 558                }
 22559                else if (e is FaultException fe)
 560                {
 0561                    faultException = fe;
 0562                    break;
 563                }
 53564                e = e.InnerException;
 565            }
 31566            if (!isSecurityError && faultException == null)
 567            {
 0568                return null;
 569            }
 570            FaultCode subCode;
 571            FaultReason reason;
 31572            SecurityVersion wss = standardsManager.SecurityVersion;
 31573            if (isTokenValidationError)
 574            {
 9575                subCode = new FaultCode(wss.FailedAuthenticationFaultCode.Value, wss.HeaderNamespace.Value);
 9576                reason = new FaultReason(SR.Format(SR.FailedAuthenticationFaultReason), CultureInfo.CurrentCulture);
 577            }
 22578            else if (isGenericTokenError)
 579            {
 0580                subCode = new FaultCode(wss.InvalidSecurityFaultCode.Value, wss.HeaderNamespace.Value);
 0581                reason = new FaultReason(SR.Format(SR.InvalidSecurityTokenFaultReason), CultureInfo.CurrentCulture);
 582            }
 22583            else if (faultException != null)
 584            {
 585                // Only support Code and Reason.  No detail or action customization.
 0586                return MessageFault.CreateFault(faultException.Code, faultException.Reason);
 587            }
 588            else
 589            {
 22590                subCode = new FaultCode(wss.InvalidSecurityFaultCode.Value, wss.HeaderNamespace.Value);
 22591                reason = new FaultReason(SR.Format(SR.InvalidSecurityFaultReason), CultureInfo.CurrentCulture);
 592            }
 31593            FaultCode senderCode = FaultCode.CreateSenderFaultCode(subCode);
 31594            return MessageFault.CreateFault(senderCode, reason);
 595        }
 596
 10597        internal static string GenerateId() => SecurityUniqueId.Create().Value;
 598
 599        internal static byte[] GenerateDerivedKey(SecurityToken tokenToDerive, string derivationAlgorithm, byte[] label,
 600        {
 0601            SymmetricSecurityKey symmetricSecurityKey = GetSecurityKey<SymmetricSecurityKey>(tokenToDerive);
 0602            if (symmetricSecurityKey == null || !symmetricSecurityKey.IsSupportedAlgorithm(derivationAlgorithm))
 603            {
 0604                throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new MessageSecurityException(SR.Format(SR.Ca
 605            }
 0606            return symmetricSecurityKey.GenerateDerivedKey(derivationAlgorithm, label, nonce, keySize, offset);
 607        }
 608
 609        public static bool TryCreateKeyFromIntrinsicKeyClause(SecurityKeyIdentifierClause keyIdentifierClause, SecurityT
 610        {
 0611            key = null;
 0612            if (keyIdentifierClause.CanCreateKey)
 613            {
 0614                key = keyIdentifierClause.CreateKey();
 0615                return true;
 616            }
 0617            if (keyIdentifierClause is EncryptedKeyIdentifierClause keyClause)
 618            {
 0619                for (int i = 0; i < keyClause.EncryptingKeyIdentifier.Count; i++)
 620                {
 0621                    if (resolver.TryResolveSecurityKey(keyClause.EncryptingKeyIdentifier[i], out SecurityKey unwrappingS
 622                    {
 0623                        byte[] wrappedKey = keyClause.GetEncryptedKey();
 0624                        string wrappingAlgorithm = keyClause.EncryptionMethod;
 0625                        byte[] unwrappedKey = unwrappingSecurityKey.DecryptKey(wrappingAlgorithm, wrappedKey);
 0626                        key = new InMemorySymmetricSecurityKey(unwrappedKey, false);
 0627                        return true;
 628                    }
 629                }
 630            }
 0631            return false;
 632        }
 633
 634        internal static bool HasSymmetricSecurityKey(SecurityToken sourceEncryptionToken)
 635        {
 0636            return GetSecurityKey<SymmetricSecurityKey>(sourceEncryptionToken) != null;
 637        }
 638
 639        internal static byte[] CloneBuffer(byte[] buffer)
 640        {
 26641            byte[] copy = Fx.AllocateByteArray(buffer.Length);
 26642            Buffer.BlockCopy(buffer, 0, copy, 0, buffer.Length);
 26643            return copy;
 644        }
 645
 646        internal static byte[] CloneBuffer(byte[] buffer, int offset, int len)
 647        {
 648            DiagnosticUtility.DebugAssert(offset >= 0, "Negative offset passed to CloneBuffer.");
 649            DiagnosticUtility.DebugAssert(len >= 0, "Negative len passed to CloneBuffer.");
 650            DiagnosticUtility.DebugAssert(buffer.Length - offset >= len, "Invalid parameters to CloneBuffer.");
 651
 0652            byte[] copy = Fx.AllocateByteArray(len);
 0653            Buffer.BlockCopy(buffer, offset, copy, 0, len);
 0654            return copy;
 655        }
 656
 657        internal static bool IsSupportedAlgorithm(string algorithm, SecurityToken token)
 658        {
 0659            if (token.SecurityKeys == null)
 660            {
 0661                return false;
 662            }
 0663            for (int i = 0; i < token.SecurityKeys.Count; ++i)
 664            {
 0665                if (token.SecurityKeys[i].IsSupportedAlgorithm(algorithm))
 666                {
 0667                    return true;
 668                }
 669            }
 0670            return false;
 671        }
 672        internal static T GetSecurityKey<T>(SecurityToken token) where T : SecurityKey
 673        {
 0674            T result = null;
 0675            if (token.SecurityKeys != null)
 676            {
 0677                for (int i = 0; i < token.SecurityKeys.Count; ++i)
 678                {
 0679                    T temp = (token.SecurityKeys[i] as T);
 0680                    if (temp != null)
 681                    {
 0682                        if (result != null)
 683                        {
 0684                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new MessageSecurityException(SR.
 685                        }
 686                        else
 687                        {
 0688                            result = temp;
 689                        }
 690                    }
 691                }
 692            }
 0693            return result;
 694        }
 695
 696        internal static bool TryCreateX509CertificateFromRawData(byte[] rawData, out X509Certificate2 certificate)
 697        {
 3698            certificate = (rawData == null || rawData.Length == 0) ? null : new X509Certificate2(rawData);
 3699            return certificate != null && certificate.Handle != IntPtr.Zero;
 700        }
 701
 702        internal static string GetKeyDerivationAlgorithm(SecureConversationVersion version)
 703        {
 704            string derivationAlgorithm;
 0705            if (version == SecureConversationVersion.WSSecureConversationFeb2005)
 706            {
 0707                derivationAlgorithm = SecurityAlgorithms.Psha1KeyDerivation;
 708            }
 0709            else if (version == SecureConversationVersion.WSSecureConversation13)
 710            {
 0711                derivationAlgorithm = SecurityAlgorithms.Psha1KeyDerivationDec2005;
 712            }
 713            else
 714            {
 0715                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
 716            }
 717
 0718            return derivationAlgorithm;
 719        }
 720
 721        internal static IIdentity CreateIdentity(string name, string authenticationType)
 722        {
 12723            return new GenericIdentity(name, authenticationType);
 724        }
 725
 726        internal static ReadOnlyCollection<IAuthorizationPolicy> CloneAuthorizationPoliciesIfNecessary(ReadOnlyCollectio
 727        {
 30728            if (authorizationPolicies != null && authorizationPolicies.Count > 0)
 729            {
 30730                bool clone = false;
 132731                for (int i = 0; i < authorizationPolicies.Count; ++i)
 732                {
 36733                    if (authorizationPolicies[i] is UnconditionalPolicy policy && policy.IsDisposable)
 734                    {
 0735                        clone = true;
 0736                        break;
 737                    }
 738                }
 30739                if (clone)
 740                {
 0741                    List<IAuthorizationPolicy> ret = new List<IAuthorizationPolicy>(authorizationPolicies.Count);
 0742                    for (int i = 0; i < authorizationPolicies.Count; ++i)
 743                    {
 0744                        if (authorizationPolicies[i] is UnconditionalPolicy policy)
 745                        {
 0746                            ret.Add(policy.Clone());
 747                        }
 748                        else
 749                        {
 0750                            ret.Add(authorizationPolicies[i]);
 751                        }
 752                    }
 0753                    return ret.AsReadOnly();
 754                }
 755            }
 30756            return authorizationPolicies;
 757        }
 758
 759        public static void DisposeAuthorizationPoliciesIfNecessary(ReadOnlyCollection<IAuthorizationPolicy> authorizatio
 760        {
 10761            if (authorizationPolicies != null && authorizationPolicies.Count > 0)
 762            {
 44763                for (int i = 0; i < authorizationPolicies.Count; ++i)
 764                {
 12765                    DisposeIfNecessary(authorizationPolicies[i] as UnconditionalPolicy);
 766                }
 767            }
 10768        }
 769
 770        public static void DisposeIfNecessary(IDisposable obj)
 771        {
 17772            if (obj != null)
 773            {
 10774                obj.Dispose();
 775            }
 17776        }
 777
 778        public static ChannelBinding GetChannelBindingFromMessage(Message message)
 779        {
 94780            if (message == null)
 781            {
 0782                return null;
 783            }
 784
 94785            ChannelBindingMessageProperty.TryGet(message, out ChannelBindingMessageProperty channelBindingMessagePropert
 94786            ChannelBinding channelBinding = null;
 787
 94788            if (channelBindingMessageProperty != null)
 789            {
 0790                channelBinding = channelBindingMessageProperty.ChannelBinding;
 791            }
 792
 94793            return channelBinding;
 794        }
 795
 796        internal static NetworkCredential GetNetworkCredentialsCopy(NetworkCredential networkCredential)
 797        {
 798            NetworkCredential result;
 12799            if (networkCredential != null && !NetworkCredentialHelper.IsDefault(networkCredential))
 800            {
 0801                result = new NetworkCredential(NetworkCredentialHelper.UnsafeGetUsername(networkCredential), NetworkCred
 802            }
 803            else
 804            {
 12805                result = networkCredential;
 806            }
 12807            return result;
 808        }
 809
 810        private static class NetworkCredentialHelper
 811        {
 812            internal static bool IsNullOrEmpty(NetworkCredential credential)
 813            {
 0814                return credential == null ||
 0815                        (
 0816                            string.IsNullOrEmpty(UnsafeGetUsername(credential)) &&
 0817                            string.IsNullOrEmpty(UnsafeGetDomain(credential)) &&
 0818                            string.IsNullOrEmpty(UnsafeGetPassword(credential))
 0819                        );
 820            }
 821
 822            internal static bool IsDefault(NetworkCredential credential)
 823            {
 0824                return UnsafeGetDefaultNetworkCredentials().Equals(credential);
 825            }
 826
 827            internal static string UnsafeGetUsername(NetworkCredential credential)
 828            {
 0829                return credential.UserName;
 830            }
 831
 832            internal static string UnsafeGetPassword(NetworkCredential credential)
 833            {
 0834                return credential.Password;
 835            }
 836
 837            internal static string UnsafeGetDomain(NetworkCredential credential)
 838            {
 0839                return credential.Domain;
 840            }
 841
 842            private static NetworkCredential UnsafeGetDefaultNetworkCredentials()
 843            {
 0844                return CredentialCache.DefaultNetworkCredentials;
 845            }
 846        }
 847
 848        internal static X509Certificate2 GetCertificateFromStore(StoreName storeName, StoreLocation storeLocation,
 849            X509FindType findType, object findValue, EndpointAddress target)
 850        {
 0851            X509Certificate2 certificate = GetCertificateFromStoreCore(storeName, storeLocation, findType, findValue, ta
 0852            if (certificate == null)
 853            {
 0854                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.Can
 855            }
 856
 0857            return certificate;
 858        }
 859
 860        private static X509Certificate2 GetCertificateFromStoreCore(StoreName storeName, StoreLocation storeLocation,
 861            X509FindType findType, object findValue, EndpointAddress target, bool throwIfMultipleOrNoMatch)
 862        {
 0863            if (findValue == null)
 864            {
 0865                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(findValue));
 866            }
 0867            X509Store store = new X509Store(storeName, storeLocation);
 0868            X509Certificate2Collection certs = null;
 869            try
 870            {
 0871                store.Open(OpenFlags.ReadOnly);
 0872                certs = store.Certificates.Find(findType, findValue, false);
 0873                if (certs.Count == 1)
 874                {
 0875                    return new X509Certificate2(certs[0]);
 876                }
 0877                if (throwIfMultipleOrNoMatch)
 878                {
 0879                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateCertificateLoadException(
 0880                        storeName, storeLocation, findType, findValue, target, certs.Count));
 881                }
 882                else
 883                {
 0884                    return null;
 885                }
 886            }
 887            finally
 888            {
 0889                ResetAllCertificates(certs);
 0890                store.Close();
 0891            }
 0892        }
 893
 894        private static Exception CreateCertificateLoadException(StoreName storeName, StoreLocation storeLocation,
 895            X509FindType findType, object findValue, EndpointAddress target, int certCount)
 896        {
 0897            if (certCount == 0)
 898            {
 0899                if (target == null)
 900                {
 0901                    return new InvalidOperationException(SR.Format(SR.CannotFindCert, storeName, storeLocation, findType
 902                }
 903                else
 904                {
 0905                    return new InvalidOperationException(SR.Format(SR.CannotFindCertForTarget, storeName, storeLocation,
 906                }
 907            }
 908            else
 909            {
 0910                if (target == null)
 911                {
 0912                    return new InvalidOperationException(SR.Format(SR.FoundMultipleCerts, storeName, storeLocation, find
 913                }
 914                else
 915                {
 0916                    return new InvalidOperationException(SR.Format(SR.FoundMultipleCertsForTarget, storeName, storeLocat
 917                }
 918            }
 919        }
 920
 921        internal static UniqueId GenerateUniqueId()
 922        {
 10923            return new UniqueId();
 924        }
 925
 926        // This is the workaround, Since store.Certificates returns a full collection
 927        // of certs in store.  These are holding native resources.
 928        internal static void ResetAllCertificates(X509Certificate2Collection certificates)
 929        {
 0930            if (certificates != null)
 931            {
 0932                for (int i = 0; i < certificates.Count; ++i)
 933                {
 0934                    ResetCertificate(certificates[i]);
 935                }
 936            }
 0937        }
 938
 939        internal static void ErasePasswordInUsernameTokenIfPresent(SecurityMessageProperty bootstrapMessageProperty)
 940        {
 0941            throw new NotImplementedException();
 942        }
 943
 944        internal static void ResetCertificate(X509Certificate2 certificate)
 945        {
 10946            certificate.Reset();
 10947        }
 948
 949        internal static Task OpenTokenAuthenticatorIfRequiredAsync(SecurityTokenAuthenticator tokenAuthenticator, Cancel
 950        {
 77951            return OpenCommunicationObjectAsync(tokenAuthenticator as ICommunicationObject, token);
 952        }
 953
 954        internal static Task OpenTokenProviderIfRequiredAsync(SecurityTokenProvider tokenProvider, CancellationToken tok
 955        {
 0956            return OpenCommunicationObjectAsync(tokenProvider as ICommunicationObject, token);
 957        }
 958
 959        internal static Task CloseTokenProviderIfRequiredAsync(SecurityTokenProvider tokenProvider, CancellationToken to
 960        {
 0961            return CloseCommunicationObjectAsync(tokenProvider, false, token);
 962        }
 963
 964        internal static void AbortTokenAuthenticatorIfRequired(SecurityTokenAuthenticator tokenAuthenticator)
 965        {
 0966            CloseCommunicationObjectAsync(tokenAuthenticator, true, CancellationToken.None).GetAwaiter().GetResult();
 0967        }
 968
 969        internal static void AbortTokenProviderIfRequired(SecurityTokenProvider tokenProvider)
 970        {
 0971            CloseCommunicationObjectAsync(tokenProvider, true, CancellationToken.None).GetAwaiter().GetResult();
 0972        }
 973
 974
 975        internal static Task CloseTokenAuthenticatorIfRequiredAsync(SecurityTokenAuthenticator tokenAuthenticator, Cance
 976        {
 0977            return CloseTokenAuthenticatorIfRequiredAsync(tokenAuthenticator, false, token);
 978        }
 979
 980        internal static Task CloseTokenAuthenticatorIfRequiredAsync(SecurityTokenAuthenticator tokenAuthenticator, bool 
 981        {
 0982            return CloseCommunicationObjectAsync(tokenAuthenticator, aborted, token);
 983        }
 984
 985        private static Task OpenCommunicationObjectAsync(ICommunicationObject obj, CancellationToken token)
 986        {
 77987            if (obj != null)
 988            {
 23989                return obj.OpenAsync(token);
 990            }
 991
 54992            return Task.CompletedTask;
 993        }
 994
 995        private static Task CloseCommunicationObjectAsync(object obj, bool aborted, CancellationToken token)
 996        {
 0997            if (obj != null)
 998            {
 0999                if (obj is ICommunicationObject co)
 1000                {
 01001                    if (aborted)
 1002                    {
 1003                        try
 1004                        {
 01005                            co.Abort();
 01006                        }
 1007                        catch (CommunicationException e)
 1008                        {
 01009                            DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
 01010                        }
 1011                    }
 1012                    else
 1013                    {
 01014                        return co.CloseAsync(token);
 1015                    }
 1016                }
 01017                else if (obj is IDisposable disposable)
 1018                {
 01019                    disposable.Dispose();
 1020                }
 1021            }
 1022
 01023            return Task.CompletedTask;
 1024        }
 1025
 1026        public static void ValidateAnonymityConstraint(WindowsIdentity identity, bool allowUnauthenticatedCallers)
 1027        {
 01028            if (!allowUnauthenticatedCallers && identity.User.IsWellKnown(WellKnownSidType.AnonymousSid))
 1029            {
 01030                throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(
 01031                    new SecurityTokenValidationException(SR.AnonymousLogonsAreNotAllowed));
 1032            }
 01033        }
 1034
 1035        /*internal static ReadOnlyCollection<IAuthorizationPolicy> CreatePrincipalNameAuthorizationPolicies(string princ
 1036        {
 1037            if (principalName == null)
 1038            {
 1039                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(principalName));
 1040            }
 1041
 1042            Claim identityClaim;
 1043            Claim primaryPrincipal;
 1044            if (principalName.Contains("@") || principalName.Contains(@"\"))
 1045            {
 1046                identityClaim = new Claim(ClaimTypes.Upn, principalName, Rights.Identity);
 1047                primaryPrincipal = Claim.CreateUpnClaim(principalName);
 1048            }
 1049            else
 1050            {
 1051                identityClaim = new Claim(ClaimTypes.Spn, principalName, Rights.Identity);
 1052                primaryPrincipal = Claim.CreateSpnClaim(principalName);
 1053            }
 1054
 1055            List<Claim> claims = new List<Claim>(2)
 1056            {
 1057                identityClaim,
 1058                primaryPrincipal
 1059            };
 1060
 1061
 1062            List<IAuthorizationPolicy> policies = new List<IAuthorizationPolicy>(1)
 1063            {
 1064                new UnconditionalPolicy(CreateIdentity(principalName), new DefaultClaimSet(ClaimSet.Anonymous, claims))
 1065            };
 1066            return policies.AsReadOnly();
 1067        }*/
 1068
 1069        public static SecurityBindingElement GetIssuerSecurityBindingElement(ServiceModelSecurityTokenRequirement requir
 1070        {
 221071            SecurityBindingElement bindingElement = requirement.SecureConversationSecurityBindingElement;
 221072            if (bindingElement != null)
 1073            {
 221074                return bindingElement;
 1075            }
 1076
 01077            Binding binding = requirement.IssuerBinding;
 01078            if (binding == null)
 1079            {
 01080                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.Format(SR.IssuerBindingNotPresentInToken
 1081            }
 01082            BindingElementCollection bindingElements = binding.CreateBindingElements();
 01083            return bindingElements.Find<SecurityBindingElement>();
 1084        }
 1085
 1086        internal static SecurityStandardsManager CreateSecurityStandardsManager(MessageSecurityVersion securityVersion, 
 1087        {
 231088            SecurityTokenSerializer tokenSerializer = tokenManager.CreateSecurityTokenSerializer(securityVersion.Securit
 231089            return new SecurityStandardsManager(securityVersion, tokenSerializer);
 1090        }
 1091
 1092        internal static SecurityStandardsManager CreateSecurityStandardsManager(SecurityTokenRequirement requirement, Se
 1093        {
 231094            MessageSecurityTokenVersion securityVersion = (MessageSecurityTokenVersion)requirement.GetProperty<MessageSe
 231095            if (securityVersion == MessageSecurityTokenVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebrua
 1096            {
 01097                return CreateSecurityStandardsManager(MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConv
 1098            }
 231099            else if (securityVersion == MessageSecurityTokenVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationF
 1100            {
 31101                return CreateSecurityStandardsManager(MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConv
 1102            }
 201103            else if (securityVersion == MessageSecurityTokenVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationF
 1104            {
 151105                return CreateSecurityStandardsManager(MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConv
 1106            }
 51107            else if (securityVersion == MessageSecurityTokenVersion.WSSecurity10WSTrust13WSSecureConversation13BasicSecu
 1108            {
 01109                return CreateSecurityStandardsManager(MessageSecurityVersion.WSSecurity10WSTrust13WSSecureConversation13
 1110            }
 51111            else if (securityVersion == MessageSecurityTokenVersion.WSSecurity11WSTrust13WSSecureConversation13)
 1112            {
 01113                return CreateSecurityStandardsManager(MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13
 1114            }
 51115            else if (securityVersion == MessageSecurityTokenVersion.WSSecurity11WSTrust13WSSecureConversation13BasicSecu
 1116            {
 51117                return CreateSecurityStandardsManager(MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13
 1118            }
 1119            else
 1120            {
 01121                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
 1122            }
 1123        }
 1124
 1125        internal static SecurityStandardsManager CreateSecurityStandardsManager(MessageSecurityVersion messageSecurityVe
 1126        {
 01127            if (messageSecurityVersion == null)
 1128            {
 01129                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(messageSecuri
 1130            }
 01131            if (securityTokenSerializer == null)
 1132            {
 01133                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(securityTokenSerializer));
 1134            }
 01135            return new SecurityStandardsManager(messageSecurityVersion, securityTokenSerializer);
 1136        }
 1137
 1138        internal static void MatchRstWithEndpointFilter(Message request, IMessageFilterTable<EndpointAddress> endpointFi
 1139        {
 21140            if (endpointFilterTable == null)
 1141            {
 21142                return;
 1143            }
 01144            Collection<EndpointAddress> result = new Collection<EndpointAddress>();
 01145            if (!endpointFilterTable.GetMatchingValues(request, result))
 1146            {
 01147                throw new SecurityNegotiationException(SR.Format(SR.RequestSecurityTokenDoesNotMatchEndpointFilters, lis
 1148            }
 01149        }
 1150
 1151        internal static bool IsEqual(byte[] a, byte[] b)
 1152        {
 01153            if (a == null || b == null || a.Length != b.Length)
 1154            {
 01155                return false;
 1156            }
 1157
 01158            for (int i = 0; i < a.Length; i++)
 1159            {
 01160                if (a[i] != b[i])
 1161                {
 01162                    return false;
 1163                }
 1164            }
 01165            return true;
 1166        }
 1167
 1168        internal static bool IsCurrentlyTimeEffective(DateTime effectiveTime, DateTime expirationTime, TimeSpan maxClock
 1169        {
 201170            DateTime curEffectiveTime = (effectiveTime < DateTime.MinValue.Add(maxClockSkew)) ? effectiveTime : effectiv
 201171            DateTime curExpirationTime = (expirationTime > DateTime.MaxValue.Subtract(maxClockSkew)) ? expirationTime : 
 201172            DateTime curTime = DateTime.UtcNow;
 1173
 201174            return (curEffectiveTime.ToUniversalTime() <= curTime) && (curTime < curExpirationTime.ToUniversalTime());
 1175        }
 1176
 1177        // match the RST with the endpoint filters in case there is at least 1 asymmetric signature in the message
 1178        internal static bool ShouldMatchRstWithEndpointFilter(SecurityBindingElement sbe)
 1179        {
 791180            foreach (SecurityTokenParameters parameters in new SecurityTokenParametersEnumerable(sbe, true))
 1181            {
 221182                if (parameters.HasAsymmetricKey)
 1183                {
 91184                    return true;
 1185                }
 1186            }
 131187            return false;
 91188        }
 1189
 1190        internal static string GetIdentityNamesFromPolicies(ReadOnlyCollection<IAuthorizationPolicy> authorizationPolici
 1191        {
 01192            return GetIdentityNamesFromContext(AuthorizationContext.CreateDefaultAuthorizationContext(authorizationPolic
 1193        }
 1194
 1195        internal static string GetIdentityNamesFromContext(AuthorizationContext authContext)
 1196        {
 01197            if (authContext == null)
 01198                return string.Empty;
 1199
 01200            StringBuilder str = new StringBuilder(256);
 01201            for (int i = 0; i < authContext.ClaimSets.Count; ++i)
 1202            {
 01203                ClaimSet claimSet = authContext.ClaimSets[i];
 1204
 1205                // Windows
 01206                if (claimSet is WindowsClaimSet windows)
 1207                {
 01208                    if (str.Length > 0)
 01209                        str.Append(", ");
 1210
 01211                    AppendIdentityName(str, windows.WindowsIdentity);
 1212                }
 1213                else
 1214                {
 1215                    // X509
 01216                    if (claimSet is X509CertificateClaimSet x509)
 1217                    {
 01218                        if (str.Length > 0)
 01219                            str.Append(", ");
 1220
 01221                        AppendCertificateIdentityName(str, x509.X509Certificate);
 1222                    }
 1223                }
 1224            }
 1225
 01226            if (str.Length <= 0)
 1227            {
 01228                List<IIdentity> identities = null;
 01229                if (authContext.Properties.TryGetValue(SecurityUtils.Identities, out object obj))
 1230                {
 01231                    identities = obj as List<IIdentity>;
 1232                }
 01233                if (identities != null)
 1234                {
 01235                    for (int i = 0; i < identities.Count; ++i)
 1236                    {
 01237                        IIdentity identity = identities[i];
 01238                        if (identity != null)
 1239                        {
 01240                            if (str.Length > 0)
 01241                                str.Append(", ");
 1242
 01243                            AppendIdentityName(str, identity);
 1244                        }
 1245                    }
 1246                }
 1247            }
 01248            return str.Length <= 0 ? string.Empty : str.ToString();
 1249        }
 1250
 1251        internal static void AppendIdentityName(StringBuilder str, IIdentity identity)
 1252        {
 01253            string name = null;
 1254            try
 1255            {
 01256                name = identity.Name;
 01257            }
 1258            catch (Exception e)
 1259            {
 01260                if (Fx.IsFatal(e))
 1261                {
 01262                    throw;
 1263                }
 1264                // suppress exception, this is just info.
 01265            }
 1266
 01267            str.Append(string.IsNullOrEmpty(name) ? "<null>" : name);
 1268
 01269            if (identity is WindowsIdentity windows)
 1270            {
 01271                if (windows.User != null)
 1272                {
 01273                    str.Append("; ");
 01274                    str.Append(windows.User.ToString());
 1275                }
 1276            }
 1277            else
 1278            {
 01279                if (identity is WindowsSidIdentity sid)
 1280                {
 01281                    str.Append("; ");
 01282                    str.Append(sid.SecurityIdentifier.ToString());
 1283                }
 1284            }
 01285        }
 1286
 1287        internal static void AppendCertificateIdentityName(StringBuilder str, X509Certificate2 certificate)
 1288        {
 01289            string value = certificate.SubjectName.Name;
 01290            if (string.IsNullOrEmpty(value))
 1291            {
 01292                value = certificate.GetNameInfo(X509NameType.DnsName, false);
 01293                if (string.IsNullOrEmpty(value))
 1294                {
 01295                    value = certificate.GetNameInfo(X509NameType.SimpleName, false);
 01296                    if (string.IsNullOrEmpty(value))
 1297                    {
 01298                        value = certificate.GetNameInfo(X509NameType.EmailName, false);
 01299                        if (string.IsNullOrEmpty(value))
 1300                        {
 01301                            value = certificate.GetNameInfo(X509NameType.UpnName, false);
 1302                        }
 1303                    }
 1304                }
 1305            }
 1306            // Same format as X509Identity
 01307            str.Append(string.IsNullOrEmpty(value) ? "<x509>" : value);
 01308            str.Append("; ");
 01309            str.Append(certificate.Thumbprint);
 01310        }
 1311
 1312        internal static string GetCertificateId(X509Certificate2 certificate)
 1313        {
 01314            string certificateId = certificate.SubjectName.Name;
 01315            if (string.IsNullOrEmpty(certificateId))
 1316            {
 01317                certificateId = certificate.Thumbprint;
 1318            }
 1319
 01320            return certificateId;
 1321        }
 1322
 1323        internal static bool MatchesBuffer(byte[] src, byte[] dst)
 1324        {
 01325            return MatchesBuffer(src, 0, dst, 0);
 1326        }
 1327
 1328        internal static bool MatchesBuffer(byte[] src, int srcOffset, byte[] dst, int dstOffset)
 1329        {
 1330            DiagnosticUtility.DebugAssert(dstOffset >= 0, "Negative dstOffset passed to MatchesBuffer.");
 1331            DiagnosticUtility.DebugAssert(srcOffset >= 0, "Negative srcOffset passed to MatchesBuffer.");
 1332
 1333            // defensive programming
 531334            if ((dstOffset < 0) || (srcOffset < 0))
 1335            {
 01336                return false;
 1337            }
 1338
 531339            if (src == null || srcOffset >= src.Length)
 1340            {
 01341                return false;
 1342            }
 1343
 531344            if (dst == null || dstOffset >= dst.Length)
 1345            {
 01346                return false;
 1347            }
 1348
 531349            if ((src.Length - srcOffset) != (dst.Length - dstOffset))
 1350            {
 21351                return false;
 1352            }
 1353
 1098601354            for (int i = srcOffset, j = dstOffset; i < src.Length; i++, j++)
 1355            {
 365691356                if (src[i] != dst[j])
 1357                {
 01358                    return false;
 1359                }
 1360            }
 511361            return true;
 1362        }
 1363
 1364        internal static string ClaimSetToString(ClaimSet claimSet)
 1365        {
 01366            StringBuilder sb = new StringBuilder();
 01367            sb.AppendLine("ClaimSet [");
 01368            for (int i = 0; i < claimSet.Count; i++)
 1369            {
 01370                Claim claim = claimSet[i];
 01371                if (claim != null)
 1372                {
 01373                    sb.Append("  ");
 01374                    sb.AppendLine(claim.ToString());
 1375                }
 1376            }
 01377            string prefix = "] by ";
 01378            ClaimSet issuer = claimSet;
 1379            do
 1380            {
 01381                issuer = issuer.Issuer;
 01382                sb.AppendFormat("{0}{1}", prefix, issuer == claimSet ? "Self" : (issuer.Count <= 0 ? "Unknown" : issuer[
 01383                prefix = " -> ";
 01384            } while (issuer.Issuer != issuer);
 01385            return sb.ToString();
 1386        }
 1387
 1388        internal static ReadOnlyCollection<IAuthorizationPolicy> CreateAuthorizationPolicies(ClaimSet claimSet)
 1389        {
 131390            return CreateAuthorizationPolicies(claimSet, MaxUtcDateTime);
 1391        }
 1392
 1393        internal static ReadOnlyCollection<IAuthorizationPolicy> CreateAuthorizationPolicies(ClaimSet claimSet, DateTime
 1394        {
 181395            List<IAuthorizationPolicy> policies = new List<IAuthorizationPolicy>(1)
 181396            {
 181397                new UnconditionalPolicy(claimSet, expirationTime)
 181398            };
 181399            return policies.AsReadOnly();
 1400        }
 1401
 1402        internal static IIdentity CloneIdentityIfNecessary(IIdentity identity)
 1403        {
 01404            if (identity != null)
 1405            {
 01406                if (identity is WindowsIdentity wid)
 1407                {
 01408                    return CloneWindowsIdentityIfNecessary(wid);
 1409                }
 1410            }
 01411            return identity;
 1412        }
 1413
 1414        internal static ClaimSet CloneClaimSetIfNecessary(ClaimSet claimSet)
 1415        {
 01416            if (claimSet != null)
 1417            {
 01418                if (claimSet is WindowsClaimSet wic)
 1419                {
 01420                    return wic.Clone();
 1421                }
 1422            }
 01423            return claimSet;
 1424        }
 1425
 1426        internal static ReadOnlyCollection<ClaimSet> CloneClaimSetsIfNecessary(ReadOnlyCollection<ClaimSet> claimSets)
 1427        {
 01428            if (claimSets != null)
 1429            {
 01430                bool clone = false;
 01431                for (int i = 0; i < claimSets.Count; ++i)
 1432                {
 01433                    if (claimSets[i] is WindowsClaimSet)
 1434                    {
 01435                        clone = true;
 01436                        break;
 1437                    }
 1438                }
 01439                if (clone)
 1440                {
 01441                    List<ClaimSet> ret = new List<ClaimSet>(claimSets.Count);
 01442                    for (int i = 0; i < claimSets.Count; ++i)
 1443                    {
 01444                        ret.Add(CloneClaimSetIfNecessary(claimSets[i]));
 1445                    }
 01446                    return ret.AsReadOnly();
 1447                }
 1448            }
 01449            return claimSets;
 1450        }
 1451
 1452        internal static void DisposeClaimSetIfNecessary(ClaimSet claimSet)
 1453        {
 01454            if (claimSet != null)
 1455            {
 01456                DisposeIfNecessary(claimSet as WindowsClaimSet);
 1457            }
 01458        }
 1459
 1460        internal static void DisposeClaimSetsIfNecessary(ReadOnlyCollection<ClaimSet> claimSets)
 1461        {
 01462            if (claimSets != null)
 1463            {
 01464                for (int i = 0; i < claimSets.Count; ++i)
 1465                {
 01466                    DisposeIfNecessary(claimSets[i] as WindowsClaimSet);
 1467                }
 1468            }
 01469        }
 1470
 1471        private class SimpleAuthorizationContext : AuthorizationContext
 1472        {
 1473            private SecurityUniqueId _id;
 1474            private readonly UnconditionalPolicy _policy;
 1475            private readonly IDictionary<string, object> _properties;
 1476
 231477            public SimpleAuthorizationContext(IList<IAuthorizationPolicy> authorizationPolicies)
 1478            {
 231479                _policy = (UnconditionalPolicy)authorizationPolicies[0];
 231480                Dictionary<string, object> properties = new Dictionary<string, object>();
 231481                if (_policy.PrimaryIdentity != null && _policy.PrimaryIdentity != AnonymousIdentity)
 1482                {
 231483                    List<IIdentity> identities = new List<IIdentity>
 231484                    {
 231485                        _policy.PrimaryIdentity
 231486                    };
 231487                    properties.Add(Identities, identities);
 1488                }
 1489                // Might need to port ReadOnlyDictionary?
 231490                _properties = properties;
 231491            }
 1492
 1493            public override string Id
 1494            {
 1495                get
 1496                {
 01497                    if (_id == null)
 1498                    {
 01499                        _id = SecurityUniqueId.Create();
 1500                    }
 1501
 01502                    return _id.Value;
 1503                }
 1504            }
 161505            public override ReadOnlyCollection<ClaimSet> ClaimSets { get { return _policy.Issuances; } }
 01506            public override DateTime ExpirationTime { get { return _policy.ExpirationTime; } }
 151507            public override IDictionary<string, object> Properties { get { return _properties; } }
 1508        }
 1509        internal static AuthorizationContext CreateDefaultAuthorizationContext(IList<IAuthorizationPolicy> authorization
 1510        {
 1511            AuthorizationContext authorizationContext;
 1512            // This is faster than Policy evaluation.
 1291513            if (authorizationPolicies != null && authorizationPolicies.Count == 1 && authorizationPolicies[0] is Uncondi
 1514            {
 231515                authorizationContext = new SimpleAuthorizationContext(authorizationPolicies);
 1516            }
 1517            // degenerate case
 1061518            else if (authorizationPolicies == null || authorizationPolicies.Count <= 0)
 1519            {
 571520                return DefaultAuthorizationContext.Empty;
 1521            }
 1522            else
 1523            {
 1524                // there are some policies, run them until they are all done
 491525                DefaultEvaluationContext evaluationContext = new DefaultEvaluationContext();
 491526                object[] policyState = new object[authorizationPolicies.Count];
 491527                object done = new object();
 1528
 1529                int oldContextCount;
 1530                do
 1531                {
 671532                    oldContextCount = evaluationContext.Generation;
 1533
 2841534                    for (int i = 0; i < authorizationPolicies.Count; i++)
 1535                    {
 751536                        if (policyState[i] == done)
 1537                        {
 1538                            continue;
 1539                        }
 1540
 531541                        IAuthorizationPolicy policy = authorizationPolicies[i];
 531542                        if (policy == null)
 1543                        {
 01544                            policyState[i] = done;
 01545                            continue;
 1546                        }
 1547
 531548                        if (policy.Evaluate(evaluationContext, ref policyState[i]))
 1549                        {
 531550                            policyState[i] = done;
 1551
 1552                            /* if (DiagnosticUtility.ShouldTraceVerbose)
 1553                             {
 1554                                 TraceUtility.TraceEvent(TraceEventType.Verbose, TraceCode.AuthorizationPolicyEvaluated,
 1555                                     SR.GetString(SR.AuthorizationPolicyEvaluated, policy.Id));
 1556                             }*/
 1557                        }
 1558                    }
 671559                } while (oldContextCount < evaluationContext.Generation);
 1560
 491561                authorizationContext = new DefaultAuthorizationContext(evaluationContext);
 1562            }
 1563
 1564            /*  if (DiagnosticUtility.ShouldTraceInformation)
 1565              {
 1566                  TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.AuthorizationContextCreated,
 1567                      SR.GetString(SR.AuthorizationContextCreated, authorizationContext.Id));
 1568              }*/
 1569
 721570            return authorizationContext;
 1571        }
 1572        public static bool IsRequestSecurityContextIssuance(string actionString)
 1573        {
 01574            if (string.CompareOrdinal(actionString, XD.SecureConversationFeb2005Dictionary
 01575                .RequestSecurityContextIssuance.Value) == 0 ||
 01576                string.CompareOrdinal(actionString, XD.SecureConversationApr2004Dictionary
 01577                .RequestSecurityContextIssuance.Value) == 0)
 1578            {
 01579                return true;
 1580            }
 1581
 01582            return false;
 1583        }
 1584    }
 1585
 1586    internal static class EmptyReadOnlyCollection<T>
 1587    {
 1588        public static ReadOnlyCollection<T> Instance = new ReadOnlyCollection<T>(new List<T>());
 1589    }
 1590
 1591    internal class Sha1CryptoProviderFactory : Microsoft.IdentityModel.Tokens.CryptoProviderFactory
 1592    {
 1593        public Sha1CryptoProviderFactory() : base(new Microsoft.IdentityModel.Tokens.InMemoryCryptoProviderCache(new Mic
 1594        {
 1595        }
 1596
 1597        public Sha1CryptoProviderFactory(Microsoft.IdentityModel.Tokens.ICryptoProvider cryptoProvider)
 1598        {
 1599            CustomCryptoProvider = cryptoProvider;
 1600        }
 1601
 1602        public override Microsoft.IdentityModel.Tokens.SignatureProvider CreateForSigning(Microsoft.IdentityModel.Tokens
 1603        {
 1604            if (algorithm == "http://www.w3.org/2000/09/xmldsig#rsa-sha1")
 1605                return null;
 1606            else
 1607                return base.CreateForSigning(key, algorithm);
 1608        }
 1609
 1610        public override Microsoft.IdentityModel.Tokens.SignatureProvider CreateForVerifying(Microsoft.IdentityModel.Toke
 1611        {
 1612            if (algorithm == "http://www.w3.org/2000/09/xmldsig#rsa-sha1")
 1613            {
 1614                return new RSASha1SignatureProvider(key, algorithm);
 1615            }
 1616            else
 1617                return base.CreateForVerifying(key, algorithm);
 1618        }
 1619
 1620        public override HashAlgorithm CreateHashAlgorithm(string algorithm)
 1621        {
 1622            if (algorithm == "http://www.w3.org/2000/09/xmldsig#sha1")
 1623                return SHA1.Create();
 1624
 1625            return base.CreateHashAlgorithm(algorithm);
 1626        }
 1627
 1628        public override bool IsSupportedAlgorithm(string algorithm)
 1629        {
 1630
 1631            if (algorithm == "http://www.w3.org/2000/09/xmldsig#sha1")
 1632                return true;
 1633            else if (algorithm == "http://www.w3.org/2000/09/xmldsig#rsa-sha1")
 1634                return true;
 1635            else
 1636                return base.IsSupportedAlgorithm(algorithm);
 1637        }
 1638
 1639        public override bool IsSupportedAlgorithm(string algorithm, Microsoft.IdentityModel.Tokens.SecurityKey key)
 1640        {
 1641            if (algorithm == "http://www.w3.org/2000/09/xmldsig#rsa-sha1")
 1642                return true;
 1643            else if (algorithm == "http://www.w3.org/2000/09/xmldsig#sha1")
 1644                return true;
 1645            else
 1646                return base.IsSupportedAlgorithm(algorithm, key);
 1647        }
 1648
 1649        public override void ReleaseHashAlgorithm(HashAlgorithm hashAlgorithm)
 1650        {
 1651            hashAlgorithm.Dispose();
 1652        }
 1653
 1654        public override void ReleaseSignatureProvider(Microsoft.IdentityModel.Tokens.SignatureProvider signatureProvider
 1655        {
 1656            if (CustomCryptoProvider != null)
 1657                CustomCryptoProvider.Release(signatureProvider);
 1658            else
 1659                signatureProvider.Dispose();
 1660        }
 1661    }
 1662
 1663    internal class RSASha1SignatureProvider : Microsoft.IdentityModel.Tokens.SignatureProvider
 1664    {
 1665        private Microsoft.IdentityModel.Tokens.X509SecurityKey _key;
 1666
 1667        public RSASha1SignatureProvider(Microsoft.IdentityModel.Tokens.SecurityKey key, string algorithm) : base(key, al
 1668        {
 1669            _key = key as Microsoft.IdentityModel.Tokens.X509SecurityKey;
 1670        }
 1671
 1672        public override byte[] Sign(byte[] input)
 1673        {
 1674            throw new NotImplementedException();
 1675        }
 1676
 1677        public override bool Verify(byte[] input, byte[] signature)
 1678        {
 1679            RSA rsa = _key.PublicKey as RSA;
 1680            if (rsa == null)
 1681                return false;
 1682
 1683            // TODO: dispose of the hash, use pool
 1684            SHA1 sha1 = SHA1.Create();
 1685            byte[] hash = sha1.ComputeHash(input);
 1686            if (rsa.VerifyHash(hash, signature, HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1))
 1687                return true;
 1688
 1689            return false;
 1690        }
 1691
 1692        protected override void Dispose(bool disposing)
 1693        {
 1694        }
 1695    }
 1696}

Methods/Properties

ReadContentAsBase64(System.Xml.XmlDictionaryReader,System.Int64)
EncryptKey(CoreWCF.IdentityModel.Tokens.SecurityToken,System.String,System.Byte[])
CombinedHashLabel()
AnonymousIdentity()
NonValidatingX509Authenticator()
MinUtcDateTime()
MaxUtcDateTime()
AdministratorsSid()
CreateSymmetricSecurityKeys(System.Byte[])
CreateSecurityKeyIdentifier(Microsoft.IdentityModel.Xml.KeyInfo)
CreateIdentity(System.String)
CreateWindowsIdentity()
GetSpnFromIdentity(CoreWCF.EndpointIdentity,CoreWCF.EndpointAddress)
IsSystemAccount(System.Security.Principal.WindowsIdentity)
CreateWindowsIdentity(System.Boolean)
GetMaxNegotiationBufferSize(CoreWCF.Channels.BindingContext)
CloneWindowsIdentityIfNecessary(System.Security.Principal.WindowsIdentity)
CloneWindowsIdentityIfNecessary(System.Security.Principal.WindowsIdentity,System.String)
UnsafeGetWindowsIdentityToken(System.Security.Principal.WindowsIdentity)
UnsafeCreateWindowsIdentityFromToken(System.IntPtr,System.String)
GetPrimaryIdentityClaim(System.Collections.ObjectModel.ReadOnlyCollection`1<CoreWCF.IdentityModel.Policy.IAuthorizationPolicy>)
GetPrimaryIdentityClaim(CoreWCF.IdentityModel.Policy.AuthorizationContext)
GetPrimaryDomain()
GetPrimaryDomain(System.Boolean)
EnsureCertificateCanDoKeyExchange(System.Security.Cryptography.X509Certificates.X509Certificate2)
CreateTokenFromEncryptedKeyClause(CoreWCF.IdentityModel.Tokens.EncryptedKeyIdentifierClause,CoreWCF.IdentityModel.Tokens.SecurityToken)
CanKeyDoKeyExchange(System.Security.Cryptography.X509Certificates.X509Certificate2)
DecryptKey(CoreWCF.IdentityModel.Tokens.SecurityToken,System.String,System.Byte[],CoreWCF.IdentityModel.Tokens.SecurityKey&)
CreateSecurityContextNotFoundFault(CoreWCF.Security.SecurityStandardsManager,System.String)
CreateSecurityMessageFault(System.Exception,CoreWCF.Security.SecurityStandardsManager)
GenerateId()
GenerateDerivedKey(CoreWCF.IdentityModel.Tokens.SecurityToken,System.String,System.Byte[],System.Byte[],System.Int32,System.Int32)
TryCreateKeyFromIntrinsicKeyClause(CoreWCF.IdentityModel.SecurityKeyIdentifierClause,CoreWCF.IdentityModel.Selectors.SecurityTokenResolver,CoreWCF.IdentityModel.Tokens.SecurityKey&)
HasSymmetricSecurityKey(CoreWCF.IdentityModel.Tokens.SecurityToken)
CloneBuffer(System.Byte[])
CloneBuffer(System.Byte[],System.Int32,System.Int32)
IsSupportedAlgorithm(System.String,CoreWCF.IdentityModel.Tokens.SecurityToken)
GetSecurityKey(CoreWCF.IdentityModel.Tokens.SecurityToken)
TryCreateX509CertificateFromRawData(System.Byte[],System.Security.Cryptography.X509Certificates.X509Certificate2&)
GetKeyDerivationAlgorithm(CoreWCF.Security.SecureConversationVersion)
CreateIdentity(System.String,System.String)
CloneAuthorizationPoliciesIfNecessary(System.Collections.ObjectModel.ReadOnlyCollection`1<CoreWCF.IdentityModel.Policy.IAuthorizationPolicy>)
DisposeAuthorizationPoliciesIfNecessary(System.Collections.ObjectModel.ReadOnlyCollection`1<CoreWCF.IdentityModel.Policy.IAuthorizationPolicy>)
DisposeIfNecessary(System.IDisposable)
GetChannelBindingFromMessage(CoreWCF.Channels.Message)
GetNetworkCredentialsCopy(System.Net.NetworkCredential)
IsNullOrEmpty(System.Net.NetworkCredential)
IsDefault(System.Net.NetworkCredential)
UnsafeGetUsername(System.Net.NetworkCredential)
UnsafeGetPassword(System.Net.NetworkCredential)
UnsafeGetDomain(System.Net.NetworkCredential)
UnsafeGetDefaultNetworkCredentials()
GetCertificateFromStore(System.Security.Cryptography.X509Certificates.StoreName,System.Security.Cryptography.X509Certificates.StoreLocation,System.Security.Cryptography.X509Certificates.X509FindType,System.Object,CoreWCF.EndpointAddress)
GetCertificateFromStoreCore(System.Security.Cryptography.X509Certificates.StoreName,System.Security.Cryptography.X509Certificates.StoreLocation,System.Security.Cryptography.X509Certificates.X509FindType,System.Object,CoreWCF.EndpointAddress,System.Boolean)
CreateCertificateLoadException(System.Security.Cryptography.X509Certificates.StoreName,System.Security.Cryptography.X509Certificates.StoreLocation,System.Security.Cryptography.X509Certificates.X509FindType,System.Object,CoreWCF.EndpointAddress,System.Int32)
GenerateUniqueId()
ResetAllCertificates(System.Security.Cryptography.X509Certificates.X509Certificate2Collection)
ErasePasswordInUsernameTokenIfPresent(CoreWCF.Security.SecurityMessageProperty)
ResetCertificate(System.Security.Cryptography.X509Certificates.X509Certificate2)
OpenTokenAuthenticatorIfRequiredAsync(CoreWCF.IdentityModel.Selectors.SecurityTokenAuthenticator,System.Threading.CancellationToken)
OpenTokenProviderIfRequiredAsync(CoreWCF.IdentityModel.Selectors.SecurityTokenProvider,System.Threading.CancellationToken)
CloseTokenProviderIfRequiredAsync(CoreWCF.IdentityModel.Selectors.SecurityTokenProvider,System.Threading.CancellationToken)
AbortTokenAuthenticatorIfRequired(CoreWCF.IdentityModel.Selectors.SecurityTokenAuthenticator)
AbortTokenProviderIfRequired(CoreWCF.IdentityModel.Selectors.SecurityTokenProvider)
CloseTokenAuthenticatorIfRequiredAsync(CoreWCF.IdentityModel.Selectors.SecurityTokenAuthenticator,System.Threading.CancellationToken)
CloseTokenAuthenticatorIfRequiredAsync(CoreWCF.IdentityModel.Selectors.SecurityTokenAuthenticator,System.Boolean,System.Threading.CancellationToken)
OpenCommunicationObjectAsync(CoreWCF.ICommunicationObject,System.Threading.CancellationToken)
CloseCommunicationObjectAsync(System.Object,System.Boolean,System.Threading.CancellationToken)
ValidateAnonymityConstraint(System.Security.Principal.WindowsIdentity,System.Boolean)
GetIssuerSecurityBindingElement(CoreWCF.Security.Tokens.ServiceModelSecurityTokenRequirement)
CreateSecurityStandardsManager(CoreWCF.MessageSecurityVersion,CoreWCF.IdentityModel.Selectors.SecurityTokenManager)
CreateSecurityStandardsManager(CoreWCF.IdentityModel.Selectors.SecurityTokenRequirement,CoreWCF.IdentityModel.Selectors.SecurityTokenManager)
CreateSecurityStandardsManager(CoreWCF.MessageSecurityVersion,CoreWCF.IdentityModel.Selectors.SecurityTokenSerializer)
MatchRstWithEndpointFilter(CoreWCF.Channels.Message,CoreWCF.Dispatcher.IMessageFilterTable`1<CoreWCF.EndpointAddress>,System.Uri)
IsEqual(System.Byte[],System.Byte[])
IsCurrentlyTimeEffective(System.DateTime,System.DateTime,System.TimeSpan)
ShouldMatchRstWithEndpointFilter(CoreWCF.Channels.SecurityBindingElement)
GetIdentityNamesFromPolicies(System.Collections.ObjectModel.ReadOnlyCollection`1<CoreWCF.IdentityModel.Policy.IAuthorizationPolicy>)
GetIdentityNamesFromContext(CoreWCF.IdentityModel.Policy.AuthorizationContext)
AppendIdentityName(System.Text.StringBuilder,System.Security.Principal.IIdentity)
AppendCertificateIdentityName(System.Text.StringBuilder,System.Security.Cryptography.X509Certificates.X509Certificate2)
GetCertificateId(System.Security.Cryptography.X509Certificates.X509Certificate2)
MatchesBuffer(System.Byte[],System.Byte[])
MatchesBuffer(System.Byte[],System.Int32,System.Byte[],System.Int32)
ClaimSetToString(CoreWCF.IdentityModel.Claims.ClaimSet)
CreateAuthorizationPolicies(CoreWCF.IdentityModel.Claims.ClaimSet)
CreateAuthorizationPolicies(CoreWCF.IdentityModel.Claims.ClaimSet,System.DateTime)
CloneIdentityIfNecessary(System.Security.Principal.IIdentity)
CloneClaimSetIfNecessary(CoreWCF.IdentityModel.Claims.ClaimSet)
CloneClaimSetsIfNecessary(System.Collections.ObjectModel.ReadOnlyCollection`1<CoreWCF.IdentityModel.Claims.ClaimSet>)
DisposeClaimSetIfNecessary(CoreWCF.IdentityModel.Claims.ClaimSet)
DisposeClaimSetsIfNecessary(System.Collections.ObjectModel.ReadOnlyCollection`1<CoreWCF.IdentityModel.Claims.ClaimSet>)
.ctor(System.Collections.Generic.IList`1<CoreWCF.IdentityModel.Policy.IAuthorizationPolicy>)
Id()
ClaimSets()
ExpirationTime()
Properties()
CreateDefaultAuthorizationContext(System.Collections.Generic.IList`1<CoreWCF.IdentityModel.Policy.IAuthorizationPolicy>)
IsRequestSecurityContextIssuance(System.String)