| | | 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 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Globalization; |
| | | 6 | | using System.Text; |
| | | 7 | | using CoreWCF.Channels; |
| | | 8 | | using CoreWCF.IdentityModel; |
| | | 9 | | using CoreWCF.IdentityModel.Selectors; |
| | | 10 | | using CoreWCF.IdentityModel.Tokens; |
| | | 11 | | |
| | | 12 | | namespace CoreWCF.Security.Tokens |
| | | 13 | | { |
| | | 14 | | public class SecureConversationSecurityTokenParameters : SecurityTokenParameters |
| | | 15 | | { |
| | | 16 | | internal const bool defaultRequireCancellation = true; |
| | | 17 | | internal const bool defaultCanRenewSession = true; |
| | | 18 | | private BindingContext _issuerBindingContext; |
| | | 19 | | |
| | | 20 | | protected SecureConversationSecurityTokenParameters(SecureConversationSecurityTokenParameters other) |
| | 539 | 21 | | : base(other) |
| | | 22 | | { |
| | 539 | 23 | | RequireCancellation = other.RequireCancellation; |
| | 539 | 24 | | CanRenewSession = other.CanRenewSession; |
| | 539 | 25 | | if (other.BootstrapSecurityBindingElement != null) |
| | | 26 | | { |
| | 539 | 27 | | BootstrapSecurityBindingElement = (SecurityBindingElement)other.BootstrapSecurityBindingElement.Clone(); |
| | | 28 | | } |
| | | 29 | | |
| | 539 | 30 | | if (other.BootstrapProtectionRequirements != null) |
| | | 31 | | { |
| | 539 | 32 | | BootstrapProtectionRequirements = new ChannelProtectionRequirements(other.BootstrapProtectionRequirement |
| | | 33 | | } |
| | | 34 | | |
| | 539 | 35 | | if (other._issuerBindingContext != null) |
| | | 36 | | { |
| | 22 | 37 | | _issuerBindingContext = other._issuerBindingContext.Clone(); |
| | | 38 | | } |
| | 539 | 39 | | } |
| | | 40 | | |
| | | 41 | | public SecureConversationSecurityTokenParameters() |
| | 0 | 42 | | : this(null, defaultRequireCancellation, null) |
| | | 43 | | { |
| | | 44 | | // empty |
| | 0 | 45 | | } |
| | | 46 | | |
| | | 47 | | public SecureConversationSecurityTokenParameters(SecurityBindingElement bootstrapSecurityBindingElement) |
| | 0 | 48 | | : this(bootstrapSecurityBindingElement, defaultRequireCancellation, null) |
| | | 49 | | { |
| | | 50 | | // empty |
| | 0 | 51 | | } |
| | | 52 | | |
| | | 53 | | public SecureConversationSecurityTokenParameters(SecurityBindingElement bootstrapSecurityBindingElement, bool re |
| | 0 | 54 | | : this(bootstrapSecurityBindingElement, requireCancellation, true) |
| | | 55 | | { |
| | | 56 | | // empty |
| | 0 | 57 | | } |
| | | 58 | | |
| | | 59 | | public SecureConversationSecurityTokenParameters(SecurityBindingElement bootstrapSecurityBindingElement, bool re |
| | 0 | 60 | | : this(bootstrapSecurityBindingElement, requireCancellation, canRenewSession, null) |
| | | 61 | | { |
| | | 62 | | // empty |
| | 0 | 63 | | } |
| | | 64 | | |
| | | 65 | | public SecureConversationSecurityTokenParameters(SecurityBindingElement bootstrapSecurityBindingElement, bool re |
| | 123 | 66 | | : this(bootstrapSecurityBindingElement, requireCancellation, defaultCanRenewSession, null) |
| | | 67 | | { |
| | | 68 | | // empty |
| | 123 | 69 | | } |
| | | 70 | | |
| | | 71 | | public SecureConversationSecurityTokenParameters(SecurityBindingElement bootstrapSecurityBindingElement, bool re |
| | 123 | 72 | | : base() |
| | | 73 | | { |
| | 123 | 74 | | BootstrapSecurityBindingElement = bootstrapSecurityBindingElement; |
| | 123 | 75 | | CanRenewSession = canRenewSession; |
| | 123 | 76 | | if (bootstrapProtectionRequirements != null) |
| | | 77 | | { |
| | 0 | 78 | | BootstrapProtectionRequirements = new ChannelProtectionRequirements(bootstrapProtectionRequirements); |
| | | 79 | | } |
| | | 80 | | else |
| | | 81 | | { |
| | 123 | 82 | | BootstrapProtectionRequirements = new ChannelProtectionRequirements(); |
| | 123 | 83 | | BootstrapProtectionRequirements.IncomingEncryptionParts.AddParts(new MessagePartSpecification(true)); |
| | 123 | 84 | | BootstrapProtectionRequirements.IncomingSignatureParts.AddParts(new MessagePartSpecification(true)); |
| | 123 | 85 | | BootstrapProtectionRequirements.OutgoingEncryptionParts.AddParts(new MessagePartSpecification(true)); |
| | 123 | 86 | | BootstrapProtectionRequirements.OutgoingSignatureParts.AddParts(new MessagePartSpecification(true)); |
| | | 87 | | } |
| | 123 | 88 | | RequireCancellation = requireCancellation; |
| | 123 | 89 | | } |
| | | 90 | | |
| | 10 | 91 | | protected internal override bool HasAsymmetricKey => false; |
| | | 92 | | |
| | 1917 | 93 | | public SecurityBindingElement BootstrapSecurityBindingElement { get; set; } |
| | | 94 | | |
| | 1570 | 95 | | public ChannelProtectionRequirements BootstrapProtectionRequirements { get; } |
| | | 96 | | |
| | | 97 | | internal BindingContext IssuerBindingContext |
| | | 98 | | { |
| | | 99 | | get |
| | | 100 | | { |
| | 22 | 101 | | return _issuerBindingContext; |
| | | 102 | | } |
| | | 103 | | set |
| | | 104 | | { |
| | 44 | 105 | | if (value != null) |
| | | 106 | | { |
| | 44 | 107 | | value = value.Clone(); |
| | | 108 | | } |
| | 44 | 109 | | _issuerBindingContext = value; |
| | 44 | 110 | | } |
| | | 111 | | } |
| | | 112 | | |
| | 124 | 113 | | private ISecurityCapabilities BootstrapSecurityCapabilities => BootstrapSecurityBindingElement.GetIndividualProp |
| | | 114 | | |
| | 1254 | 115 | | public bool RequireCancellation { get; set; } |
| | | 116 | | |
| | 1908 | 117 | | public bool CanRenewSession { get; set; } = defaultCanRenewSession; |
| | | 118 | | |
| | 31 | 119 | | protected internal override bool SupportsClientAuthentication => BootstrapSecurityCapabilities == null ? false : |
| | | 120 | | |
| | 0 | 121 | | protected internal override bool SupportsServerAuthentication => BootstrapSecurityCapabilities == null ? false : |
| | | 122 | | |
| | 31 | 123 | | protected internal override bool SupportsClientWindowsIdentity => BootstrapSecurityCapabilities == null ? false |
| | | 124 | | |
| | | 125 | | protected override SecurityTokenParameters CloneCore() |
| | | 126 | | { |
| | 539 | 127 | | return new SecureConversationSecurityTokenParameters(this); |
| | | 128 | | } |
| | | 129 | | |
| | | 130 | | protected internal override SecurityKeyIdentifierClause CreateKeyIdentifierClause(SecurityToken token, SecurityT |
| | | 131 | | { |
| | 30 | 132 | | if (token is GenericXmlSecurityToken) |
| | | 133 | | { |
| | 0 | 134 | | return CreateGenericXmlTokenKeyIdentifierClause(token, referenceStyle); |
| | | 135 | | } |
| | | 136 | | else |
| | | 137 | | { |
| | 30 | 138 | | return CreateKeyIdentifierClause<SecurityContextKeyIdentifierClause, LocalIdKeyIdentifierClause>(token, |
| | | 139 | | } |
| | | 140 | | } |
| | | 141 | | |
| | | 142 | | protected internal override void InitializeSecurityTokenRequirement(SecurityTokenRequirement requirement) |
| | | 143 | | { |
| | 22 | 144 | | requirement.TokenType = ServiceModelSecurityTokenTypes.SecureConversation; |
| | 22 | 145 | | requirement.KeyType = SecurityKeyType.SymmetricKey; |
| | 22 | 146 | | requirement.RequireCryptographicToken = true; |
| | 22 | 147 | | requirement.Properties[ServiceModelSecurityTokenRequirement.SupportSecurityContextCancellationProperty] = Re |
| | 22 | 148 | | requirement.Properties[ServiceModelSecurityTokenRequirement.SecureConversationSecurityBindingElementProperty |
| | 22 | 149 | | requirement.Properties[ServiceModelSecurityTokenRequirement.IssuerBindingContextProperty] = IssuerBindingCon |
| | 22 | 150 | | requirement.Properties[ServiceModelSecurityTokenRequirement.IssuedSecurityTokenParametersProperty] = Clone() |
| | 22 | 151 | | } |
| | | 152 | | |
| | | 153 | | public override string ToString() |
| | | 154 | | { |
| | 0 | 155 | | StringBuilder sb = new StringBuilder(); |
| | 0 | 156 | | sb.AppendLine(base.ToString()); |
| | | 157 | | |
| | 0 | 158 | | sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "RequireCancellation: {0}", RequireCancellation.To |
| | 0 | 159 | | if (BootstrapSecurityBindingElement == null) |
| | | 160 | | { |
| | 0 | 161 | | sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "BootstrapSecurityBindingElement: null")); |
| | | 162 | | } |
| | | 163 | | else |
| | | 164 | | { |
| | 0 | 165 | | sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "BootstrapSecurityBindingElement:")); |
| | 0 | 166 | | sb.AppendLine(" " + BootstrapSecurityBindingElement.ToString().Trim().Replace("\n", "\n ")); |
| | | 167 | | } |
| | | 168 | | |
| | 0 | 169 | | return sb.ToString().Trim(); |
| | | 170 | | } |
| | | 171 | | } |
| | | 172 | | } |