| | | 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.Collections.Generic; |
| | | 6 | | using System.Collections.ObjectModel; |
| | | 7 | | using System.Globalization; |
| | | 8 | | using System.IO; |
| | | 9 | | using System.Runtime.Serialization; |
| | | 10 | | using System.Security.Cryptography; |
| | | 11 | | using System.Text; |
| | | 12 | | using System.Xml; |
| | | 13 | | using CoreWCF.Description; |
| | | 14 | | using CoreWCF.Dispatcher; |
| | | 15 | | using CoreWCF.IdentityModel; |
| | | 16 | | using CoreWCF.IdentityModel.Policy; |
| | | 17 | | using CoreWCF.IdentityModel.Selectors; |
| | | 18 | | using CoreWCF.IdentityModel.Tokens; |
| | | 19 | | using CoreWCF.Runtime; |
| | | 20 | | using CoreWCF.Security.Tokens; |
| | | 21 | | using HexBinary = CoreWCF.Security.SoapHexBinary; |
| | | 22 | | using TokenEntry = CoreWCF.Security.WSSecurityTokenSerializer.TokenEntry; |
| | | 23 | | |
| | | 24 | | namespace CoreWCF.Security |
| | | 25 | | { |
| | | 26 | | internal abstract class WSTrust : WSSecurityTokenSerializer.SerializerEntries |
| | | 27 | | { |
| | 132 | 28 | | public WSTrust(WSSecurityTokenSerializer tokenSerializer) |
| | | 29 | | { |
| | 132 | 30 | | WSSecurityTokenSerializer = tokenSerializer; |
| | 132 | 31 | | } |
| | | 32 | | |
| | 0 | 33 | | public WSSecurityTokenSerializer WSSecurityTokenSerializer { get; } |
| | | 34 | | |
| | | 35 | | public abstract TrustDictionary SerializerDictionary |
| | | 36 | | { |
| | | 37 | | get; |
| | | 38 | | } |
| | | 39 | | |
| | | 40 | | public override void PopulateTokenEntries(IList<TokenEntry> tokenEntryList) |
| | | 41 | | { |
| | 132 | 42 | | tokenEntryList.Add(new BinarySecretTokenEntry(this)); |
| | 132 | 43 | | } |
| | | 44 | | |
| | | 45 | | private class BinarySecretTokenEntry : TokenEntry |
| | | 46 | | { |
| | | 47 | | private readonly WSTrust _parent; |
| | | 48 | | private readonly TrustDictionary _otherDictionary; |
| | | 49 | | |
| | 132 | 50 | | public BinarySecretTokenEntry(WSTrust parent) |
| | | 51 | | { |
| | 132 | 52 | | _parent = parent; |
| | 132 | 53 | | _otherDictionary = null; |
| | | 54 | | |
| | 132 | 55 | | if (parent.SerializerDictionary is TrustDec2005Dictionary) |
| | | 56 | | { |
| | 67 | 57 | | _otherDictionary = XD.TrustFeb2005Dictionary; |
| | | 58 | | } |
| | | 59 | | |
| | 132 | 60 | | if (parent.SerializerDictionary is TrustFeb2005Dictionary) |
| | | 61 | | { |
| | 65 | 62 | | _otherDictionary = DXD.TrustDec2005Dictionary; |
| | | 63 | | } |
| | | 64 | | |
| | | 65 | | // always set it, so we don't have to worry about null |
| | 132 | 66 | | if (_otherDictionary == null) |
| | | 67 | | { |
| | 0 | 68 | | _otherDictionary = _parent.SerializerDictionary; |
| | | 69 | | } |
| | 132 | 70 | | } |
| | | 71 | | |
| | 10 | 72 | | protected override XmlDictionaryString LocalName => _parent.SerializerDictionary.BinarySecret; |
| | 10 | 73 | | protected override XmlDictionaryString NamespaceUri => _parent.SerializerDictionary.Namespace; |
| | 10 | 74 | | protected override Type[] GetTokenTypesCore() { return new Type[] { typeof(BinarySecretSecurityToken) }; } |
| | 0 | 75 | | public override string TokenTypeUri => null; |
| | 10 | 76 | | protected override string ValueTypeUri => null; |
| | | 77 | | |
| | | 78 | | public override bool CanReadTokenCore(XmlElement element) |
| | | 79 | | { |
| | 0 | 80 | | string valueTypeUri = null; |
| | | 81 | | |
| | 0 | 82 | | if (element.HasAttribute(SecurityJan2004Strings.ValueType, null)) |
| | | 83 | | { |
| | 0 | 84 | | valueTypeUri = element.GetAttribute(SecurityJan2004Strings.ValueType, null); |
| | | 85 | | } |
| | | 86 | | |
| | 0 | 87 | | return element.LocalName == LocalName.Value && (element.NamespaceURI == NamespaceUri.Value || element.Na |
| | | 88 | | } |
| | | 89 | | |
| | | 90 | | public override bool CanReadTokenCore(XmlDictionaryReader reader) |
| | | 91 | | { |
| | 10 | 92 | | return (reader.IsStartElement(LocalName, NamespaceUri) || reader.IsStartElement(LocalName, _otherDiction |
| | 10 | 93 | | reader.GetAttribute(XD.SecurityJan2004Dictionary.ValueType, null) == ValueTypeUri; |
| | | 94 | | } |
| | | 95 | | |
| | | 96 | | |
| | | 97 | | public override SecurityKeyIdentifierClause CreateKeyIdentifierClauseFromTokenXmlCore(XmlElement issuedToken |
| | | 98 | | SecurityTokenReferenceStyle tokenReferenceStyle) |
| | | 99 | | { |
| | 0 | 100 | | TokenReferenceStyleHelper.Validate(tokenReferenceStyle); |
| | | 101 | | |
| | | 102 | | switch (tokenReferenceStyle) |
| | | 103 | | { |
| | | 104 | | case SecurityTokenReferenceStyle.Internal: |
| | 0 | 105 | | return CreateDirectReference(issuedTokenXml, UtilityStrings.IdAttribute, UtilityStrings.Namespac |
| | | 106 | | case SecurityTokenReferenceStyle.External: |
| | | 107 | | // Binary Secret tokens aren't referred to externally |
| | 0 | 108 | | return null; |
| | | 109 | | default: |
| | 0 | 110 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof |
| | | 111 | | } |
| | | 112 | | } |
| | | 113 | | |
| | | 114 | | public override SecurityToken ReadTokenCore(XmlDictionaryReader reader, SecurityTokenResolver tokenResolver) |
| | | 115 | | { |
| | 10 | 116 | | string secretType = reader.GetAttribute(XD.SecurityJan2004Dictionary.TypeAttribute, null); |
| | 10 | 117 | | string id = reader.GetAttribute(XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace); |
| | 10 | 118 | | bool isNonce = false; |
| | | 119 | | |
| | 10 | 120 | | if (secretType != null && secretType.Length > 0) |
| | | 121 | | { |
| | 10 | 122 | | if (secretType == _parent.SerializerDictionary.NonceBinarySecret.Value || secretType == _otherDictio |
| | | 123 | | { |
| | 10 | 124 | | isNonce = true; |
| | | 125 | | } |
| | 0 | 126 | | else if (secretType != _parent.SerializerDictionary.SymmetricKeyBinarySecret.Value && secretType != |
| | | 127 | | { |
| | 0 | 128 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.Format |
| | | 129 | | } |
| | | 130 | | } |
| | | 131 | | |
| | 10 | 132 | | byte[] secret = reader.ReadElementContentAsBase64(); |
| | 10 | 133 | | if (isNonce) |
| | | 134 | | { |
| | 10 | 135 | | return new NonceToken(id, secret); |
| | | 136 | | } |
| | | 137 | | else |
| | | 138 | | { |
| | 0 | 139 | | return new BinarySecretSecurityToken(id, secret); |
| | | 140 | | } |
| | | 141 | | } |
| | | 142 | | |
| | | 143 | | public override void WriteTokenCore(XmlDictionaryWriter writer, SecurityToken token) |
| | | 144 | | { |
| | 10 | 145 | | BinarySecretSecurityToken simpleToken = token as BinarySecretSecurityToken; |
| | 10 | 146 | | byte[] secret = simpleToken.GetKeyBytes(); |
| | 10 | 147 | | writer.WriteStartElement(_parent.SerializerDictionary.Prefix.Value, _parent.SerializerDictionary.BinaryS |
| | 10 | 148 | | if (simpleToken.Id != null) |
| | | 149 | | { |
| | 10 | 150 | | writer.WriteAttributeString(XD.UtilityDictionary.Prefix.Value, XD.UtilityDictionary.IdAttribute, XD. |
| | | 151 | | } |
| | 10 | 152 | | if (token is NonceToken) |
| | | 153 | | { |
| | 10 | 154 | | writer.WriteAttributeString(XD.SecurityJan2004Dictionary.TypeAttribute, null, _parent.SerializerDict |
| | | 155 | | } |
| | 10 | 156 | | writer.WriteBase64(secret, 0, secret.Length); |
| | 10 | 157 | | writer.WriteEndElement(); |
| | 10 | 158 | | } |
| | | 159 | | } |
| | | 160 | | |
| | | 161 | | public abstract class Driver : TrustDriver |
| | | 162 | | { |
| | | 163 | | private const string Base64Uri = SecurityJan2004Strings.EncodingTypeValueBase64Binary; |
| | | 164 | | private const string HexBinaryUri = SecurityJan2004Strings.EncodingTypeValueHexBinary; |
| | | 165 | | private readonly SecurityStandardsManager _standardsManager; |
| | | 166 | | private readonly List<SecurityTokenAuthenticator> _entropyAuthenticators; |
| | | 167 | | |
| | 131 | 168 | | public Driver(SecurityStandardsManager standardsManager) |
| | | 169 | | { |
| | 131 | 170 | | _standardsManager = standardsManager; |
| | 131 | 171 | | _entropyAuthenticators = new List<SecurityTokenAuthenticator>(2); |
| | 131 | 172 | | } |
| | | 173 | | |
| | | 174 | | public abstract TrustDictionary DriverDictionary |
| | | 175 | | { |
| | | 176 | | get; |
| | | 177 | | } |
| | | 178 | | |
| | 0 | 179 | | public override XmlDictionaryString RequestSecurityTokenAction => DriverDictionary.RequestSecurityTokenIssua |
| | | 180 | | |
| | 0 | 181 | | public override XmlDictionaryString RequestSecurityTokenResponseAction => DriverDictionary.RequestSecurityTo |
| | | 182 | | |
| | 10 | 183 | | public override string RequestTypeIssue => DriverDictionary.RequestTypeIssue.Value; |
| | | 184 | | |
| | 0 | 185 | | public override string ComputedKeyAlgorithm => DriverDictionary.Psha1ComputedKeyUri.Value; |
| | | 186 | | |
| | 30 | 187 | | public override SecurityStandardsManager StandardsManager => _standardsManager; |
| | | 188 | | |
| | 0 | 189 | | public override XmlDictionaryString Namespace => DriverDictionary.Namespace; |
| | | 190 | | |
| | | 191 | | public override RequestSecurityToken CreateRequestSecurityToken(XmlReader xmlReader) |
| | | 192 | | { |
| | 20 | 193 | | XmlDictionaryReader reader = XmlDictionaryReader.CreateDictionaryReader(xmlReader); |
| | 20 | 194 | | reader.MoveToStartElement(DriverDictionary.RequestSecurityToken, DriverDictionary.Namespace); |
| | 20 | 195 | | string context = null; |
| | 20 | 196 | | string tokenTypeUri = null; |
| | 20 | 197 | | string requestType = null; |
| | 20 | 198 | | int keySize = 0; |
| | 20 | 199 | | XmlDocument doc = new XmlDocument(); |
| | 20 | 200 | | XmlElement rstXml = (doc.ReadNode(reader) as XmlElement); |
| | 80 | 201 | | for (int i = 0; i < rstXml.Attributes.Count; ++i) |
| | | 202 | | { |
| | 20 | 203 | | XmlAttribute attr = rstXml.Attributes[i]; |
| | 20 | 204 | | if (attr.LocalName == DriverDictionary.Context.Value) |
| | | 205 | | { |
| | 0 | 206 | | context = attr.Value; |
| | | 207 | | } |
| | | 208 | | } |
| | 160 | 209 | | for (int i = 0; i < rstXml.ChildNodes.Count; ++i) |
| | | 210 | | { |
| | 60 | 211 | | XmlElement child = (rstXml.ChildNodes[i] as XmlElement); |
| | 60 | 212 | | if (child != null) |
| | | 213 | | { |
| | 60 | 214 | | if (child.LocalName == DriverDictionary.TokenType.Value && child.NamespaceURI == DriverDictionar |
| | | 215 | | { |
| | 10 | 216 | | tokenTypeUri = XmlHelper.ReadTextElementAsTrimmedString(child); |
| | | 217 | | } |
| | 50 | 218 | | else if (child.LocalName == DriverDictionary.RequestType.Value && child.NamespaceURI == DriverDi |
| | | 219 | | { |
| | 20 | 220 | | requestType = XmlHelper.ReadTextElementAsTrimmedString(child); |
| | | 221 | | } |
| | 30 | 222 | | else if (child.LocalName == DriverDictionary.KeySize.Value && child.NamespaceURI == DriverDictio |
| | | 223 | | { |
| | 10 | 224 | | keySize = int.Parse(XmlHelper.ReadTextElementAsTrimmedString(child), NumberFormatInfo.Invari |
| | | 225 | | } |
| | | 226 | | } |
| | | 227 | | } |
| | | 228 | | |
| | 20 | 229 | | ReadTargets(rstXml, out SecurityKeyIdentifierClause renewTarget, out SecurityKeyIdentifierClause closeTa |
| | | 230 | | |
| | 20 | 231 | | RequestSecurityToken rst = new RequestSecurityToken(_standardsManager, rstXml, context, tokenTypeUri, re |
| | 20 | 232 | | return rst; |
| | | 233 | | } |
| | | 234 | | |
| | | 235 | | private CoreWCF.XmlBuffer GetIssuedTokenBuffer(CoreWCF.XmlBuffer rstrBuffer) |
| | | 236 | | { |
| | 0 | 237 | | CoreWCF.XmlBuffer issuedTokenBuffer = null; |
| | 0 | 238 | | using (XmlDictionaryReader reader = rstrBuffer.GetReader(0)) |
| | | 239 | | { |
| | 0 | 240 | | reader.ReadFullStartElement(); |
| | 0 | 241 | | while (reader.IsStartElement()) |
| | | 242 | | { |
| | 0 | 243 | | if (reader.IsStartElement(DriverDictionary.RequestedSecurityToken, DriverDictionary.Namespace)) |
| | | 244 | | { |
| | 0 | 245 | | reader.ReadStartElement(); |
| | 0 | 246 | | reader.MoveToContent(); |
| | 0 | 247 | | issuedTokenBuffer = new CoreWCF.XmlBuffer(int.MaxValue); |
| | 0 | 248 | | using (XmlDictionaryWriter writer = issuedTokenBuffer.OpenSection(reader.Quotas)) |
| | | 249 | | { |
| | 0 | 250 | | writer.WriteNode(reader, false); |
| | 0 | 251 | | issuedTokenBuffer.CloseSection(); |
| | 0 | 252 | | issuedTokenBuffer.Close(); |
| | 0 | 253 | | } |
| | 0 | 254 | | reader.ReadEndElement(); |
| | 0 | 255 | | break; |
| | | 256 | | } |
| | | 257 | | else |
| | | 258 | | { |
| | 0 | 259 | | reader.Skip(); |
| | | 260 | | } |
| | | 261 | | } |
| | 0 | 262 | | } |
| | 0 | 263 | | return issuedTokenBuffer; |
| | | 264 | | } |
| | | 265 | | |
| | | 266 | | public override RequestSecurityTokenResponse CreateRequestSecurityTokenResponse(XmlReader xmlReader) |
| | | 267 | | { |
| | 0 | 268 | | if (xmlReader == null) |
| | | 269 | | { |
| | 0 | 270 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(xmlReader)); |
| | | 271 | | } |
| | 0 | 272 | | XmlDictionaryReader reader = XmlDictionaryReader.CreateDictionaryReader(xmlReader); |
| | 0 | 273 | | if (reader.IsStartElement(DriverDictionary.RequestSecurityTokenResponse, DriverDictionary.Namespace) == |
| | | 274 | | { |
| | 0 | 275 | | XmlHelper.OnRequiredElementMissing(DriverDictionary.RequestSecurityTokenResponse.Value, DriverDictio |
| | | 276 | | } |
| | | 277 | | |
| | 0 | 278 | | CoreWCF.XmlBuffer rstrBuffer = new CoreWCF.XmlBuffer(int.MaxValue); |
| | 0 | 279 | | using (XmlDictionaryWriter writer = rstrBuffer.OpenSection(reader.Quotas)) |
| | | 280 | | { |
| | 0 | 281 | | writer.WriteNode(reader, false); |
| | 0 | 282 | | rstrBuffer.CloseSection(); |
| | 0 | 283 | | rstrBuffer.Close(); |
| | 0 | 284 | | } |
| | 0 | 285 | | XmlDocument doc = new XmlDocument(); |
| | | 286 | | XmlElement rstrXml; |
| | 0 | 287 | | using (XmlReader reader2 = rstrBuffer.GetReader(0)) |
| | | 288 | | { |
| | 0 | 289 | | rstrXml = (doc.ReadNode(reader2) as XmlElement); |
| | 0 | 290 | | } |
| | | 291 | | |
| | 0 | 292 | | CoreWCF.XmlBuffer issuedTokenBuffer = GetIssuedTokenBuffer(rstrBuffer); |
| | 0 | 293 | | string context = null; |
| | 0 | 294 | | string tokenTypeUri = null; |
| | 0 | 295 | | int keySize = 0; |
| | 0 | 296 | | bool computeKey = false; |
| | 0 | 297 | | DateTime created = DateTime.UtcNow; |
| | 0 | 298 | | DateTime expires = SecurityUtils.MaxUtcDateTime; |
| | 0 | 299 | | for (int i = 0; i < rstrXml.Attributes.Count; ++i) |
| | | 300 | | { |
| | 0 | 301 | | XmlAttribute attr = rstrXml.Attributes[i]; |
| | 0 | 302 | | if (attr.LocalName == DriverDictionary.Context.Value) |
| | | 303 | | { |
| | 0 | 304 | | context = attr.Value; |
| | | 305 | | } |
| | | 306 | | } |
| | | 307 | | |
| | 0 | 308 | | for (int i = 0; i < rstrXml.ChildNodes.Count; ++i) |
| | | 309 | | { |
| | 0 | 310 | | XmlElement child = (rstrXml.ChildNodes[i] as XmlElement); |
| | 0 | 311 | | if (child != null) |
| | | 312 | | { |
| | 0 | 313 | | if (child.LocalName == DriverDictionary.TokenType.Value && child.NamespaceURI == DriverDictionar |
| | | 314 | | { |
| | 0 | 315 | | tokenTypeUri = XmlHelper.ReadTextElementAsTrimmedString(child); |
| | | 316 | | } |
| | 0 | 317 | | else if (child.LocalName == DriverDictionary.KeySize.Value && child.NamespaceURI == DriverDictio |
| | | 318 | | { |
| | 0 | 319 | | keySize = int.Parse(XmlHelper.ReadTextElementAsTrimmedString(child), NumberFormatInfo.Invari |
| | | 320 | | } |
| | 0 | 321 | | else if (child.LocalName == DriverDictionary.RequestedProofToken.Value && child.NamespaceURI == |
| | | 322 | | { |
| | 0 | 323 | | XmlElement proofXml = XmlHelper.GetChildElement(child); |
| | 0 | 324 | | if (proofXml.LocalName == DriverDictionary.ComputedKey.Value && proofXml.NamespaceURI == Dri |
| | | 325 | | { |
| | 0 | 326 | | string computedKeyAlgorithm = XmlHelper.ReadTextElementAsTrimmedString(proofXml); |
| | 0 | 327 | | if (computedKeyAlgorithm != DriverDictionary.Psha1ComputedKeyUri.Value) |
| | | 328 | | { |
| | 0 | 329 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new SecurityNegotiationE |
| | | 330 | | } |
| | 0 | 331 | | computeKey = true; |
| | | 332 | | } |
| | | 333 | | } |
| | 0 | 334 | | else if (child.LocalName == DriverDictionary.Lifetime.Value && child.NamespaceURI == DriverDicti |
| | | 335 | | { |
| | 0 | 336 | | XmlElement createdXml = XmlHelper.GetChildElement(child, UtilityStrings.CreatedElement, Util |
| | 0 | 337 | | if (createdXml != null) |
| | | 338 | | { |
| | 0 | 339 | | created = DateTime.ParseExact(XmlHelper.ReadTextElementAsTrimmedString(createdXml), |
| | 0 | 340 | | WSUtilitySpecificationVersion.AcceptedDateTimeFormats, DateTimeFormatInfo.InvariantI |
| | | 341 | | } |
| | 0 | 342 | | XmlElement expiresXml = XmlHelper.GetChildElement(child, UtilityStrings.ExpiresElement, Util |
| | 0 | 343 | | if (expiresXml != null) |
| | | 344 | | { |
| | 0 | 345 | | expires = DateTime.ParseExact(XmlHelper.ReadTextElementAsTrimmedString(expiresXml), |
| | 0 | 346 | | WSUtilitySpecificationVersion.AcceptedDateTimeFormats, DateTimeFormatInfo.InvariantI |
| | | 347 | | } |
| | | 348 | | } |
| | | 349 | | } |
| | | 350 | | } |
| | | 351 | | |
| | 0 | 352 | | bool isRequestedTokenClosed = ReadRequestedTokenClosed(rstrXml); |
| | 0 | 353 | | ReadReferences(rstrXml, out SecurityKeyIdentifierClause requestedAttachedReference, out SecurityKeyIdent |
| | | 354 | | |
| | 0 | 355 | | return new RequestSecurityTokenResponse(_standardsManager, rstrXml, context, tokenTypeUri, keySize, requ |
| | 0 | 356 | | computeKey, created, expires, isRequestedTokenClosed, issuedToke |
| | | 357 | | } |
| | | 358 | | |
| | | 359 | | public override RequestSecurityTokenResponseCollection CreateRequestSecurityTokenResponseCollection(XmlReade |
| | | 360 | | { |
| | 0 | 361 | | XmlDictionaryReader reader = XmlDictionaryReader.CreateDictionaryReader(xmlReader); |
| | 0 | 362 | | List<RequestSecurityTokenResponse> rstrCollection = new List<RequestSecurityTokenResponse>(2); |
| | 0 | 363 | | string rootName = reader.Name; |
| | 0 | 364 | | reader.ReadStartElement(DriverDictionary.RequestSecurityTokenResponseCollection, DriverDictionary.Namesp |
| | 0 | 365 | | while (reader.IsStartElement(DriverDictionary.RequestSecurityTokenResponse.Value, DriverDictionary.Names |
| | | 366 | | { |
| | 0 | 367 | | RequestSecurityTokenResponse rstr = CreateRequestSecurityTokenResponse(reader); |
| | 0 | 368 | | rstrCollection.Add(rstr); |
| | | 369 | | } |
| | 0 | 370 | | reader.ReadEndElement(); |
| | 0 | 371 | | if (rstrCollection.Count == 0) |
| | | 372 | | { |
| | 0 | 373 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.NoRequestSec |
| | | 374 | | } |
| | | 375 | | |
| | 0 | 376 | | return new RequestSecurityTokenResponseCollection(rstrCollection.AsReadOnly(), StandardsManager); |
| | | 377 | | } |
| | | 378 | | |
| | | 379 | | private XmlElement GetAppliesToElement(XmlElement rootElement) |
| | | 380 | | { |
| | 10 | 381 | | if (rootElement == null) |
| | | 382 | | { |
| | 0 | 383 | | return null; |
| | | 384 | | } |
| | 100 | 385 | | for (int i = 0; i < rootElement.ChildNodes.Count; ++i) |
| | | 386 | | { |
| | 40 | 387 | | XmlElement elem = (rootElement.ChildNodes[i] as XmlElement); |
| | 40 | 388 | | if (elem != null) |
| | | 389 | | { |
| | 40 | 390 | | if (elem.LocalName == DriverDictionary.AppliesTo.Value && elem.NamespaceURI == Namespaces.WSPoli |
| | | 391 | | { |
| | 0 | 392 | | return elem; |
| | | 393 | | } |
| | | 394 | | } |
| | | 395 | | } |
| | 10 | 396 | | return null; |
| | | 397 | | } |
| | | 398 | | |
| | | 399 | | private T GetAppliesTo<T>(XmlElement rootXml, XmlObjectSerializer serializer) |
| | | 400 | | { |
| | 0 | 401 | | XmlElement appliesToElement = GetAppliesToElement(rootXml); |
| | 0 | 402 | | if (appliesToElement != null) |
| | | 403 | | { |
| | 0 | 404 | | using (XmlReader reader = new XmlNodeReader(appliesToElement)) |
| | | 405 | | { |
| | 0 | 406 | | reader.ReadStartElement(); |
| | 0 | 407 | | lock (serializer) |
| | | 408 | | { |
| | 0 | 409 | | return (T)serializer.ReadObject(reader); |
| | | 410 | | } |
| | | 411 | | } |
| | | 412 | | } |
| | | 413 | | else |
| | | 414 | | { |
| | 0 | 415 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR |
| | | 416 | | } |
| | 0 | 417 | | } |
| | | 418 | | |
| | | 419 | | public override T GetAppliesTo<T>(RequestSecurityToken rst, XmlObjectSerializer serializer) |
| | | 420 | | { |
| | 0 | 421 | | if (rst == null) |
| | | 422 | | { |
| | 0 | 423 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(rst)); |
| | | 424 | | } |
| | | 425 | | |
| | 0 | 426 | | return GetAppliesTo<T>(rst.RequestSecurityTokenXml, serializer); |
| | | 427 | | } |
| | | 428 | | |
| | | 429 | | public override T GetAppliesTo<T>(RequestSecurityTokenResponse rstr, XmlObjectSerializer serializer) |
| | | 430 | | { |
| | 0 | 431 | | if (rstr == null) |
| | | 432 | | { |
| | 0 | 433 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(rstr)); |
| | | 434 | | } |
| | | 435 | | |
| | 0 | 436 | | return GetAppliesTo<T>(rstr.RequestSecurityTokenResponseXml, serializer); |
| | | 437 | | } |
| | | 438 | | |
| | | 439 | | public override bool IsAppliesTo(string localName, string namespaceUri) |
| | | 440 | | { |
| | 0 | 441 | | return (localName == DriverDictionary.AppliesTo.Value && namespaceUri == Namespaces.WSPolicy); |
| | | 442 | | } |
| | | 443 | | |
| | | 444 | | private void GetAppliesToQName(XmlElement rootElement, out string localName, out string namespaceUri) |
| | | 445 | | { |
| | 10 | 446 | | localName = namespaceUri = null; |
| | 10 | 447 | | XmlElement appliesToElement = GetAppliesToElement(rootElement); |
| | 10 | 448 | | if (appliesToElement != null) |
| | | 449 | | { |
| | 0 | 450 | | using (XmlReader reader = new XmlNodeReader(appliesToElement)) |
| | | 451 | | { |
| | 0 | 452 | | reader.ReadStartElement(); |
| | 0 | 453 | | reader.MoveToContent(); |
| | 0 | 454 | | localName = reader.LocalName; |
| | 0 | 455 | | namespaceUri = reader.NamespaceURI; |
| | 0 | 456 | | } |
| | | 457 | | } |
| | 10 | 458 | | } |
| | | 459 | | |
| | | 460 | | public override void GetAppliesToQName(RequestSecurityToken rst, out string localName, out string namespaceU |
| | | 461 | | { |
| | 10 | 462 | | if (rst == null) |
| | | 463 | | { |
| | 0 | 464 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(rst)); |
| | | 465 | | } |
| | | 466 | | |
| | 10 | 467 | | GetAppliesToQName(rst.RequestSecurityTokenXml, out localName, out namespaceUri); |
| | 10 | 468 | | } |
| | | 469 | | |
| | | 470 | | public override void GetAppliesToQName(RequestSecurityTokenResponse rstr, out string localName, out string n |
| | | 471 | | { |
| | 0 | 472 | | if (rstr == null) |
| | | 473 | | { |
| | 0 | 474 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(rstr)); |
| | | 475 | | } |
| | | 476 | | |
| | 0 | 477 | | GetAppliesToQName(rstr.RequestSecurityTokenResponseXml, out localName, out namespaceUri); |
| | 0 | 478 | | } |
| | | 479 | | |
| | | 480 | | public override byte[] GetAuthenticator(RequestSecurityTokenResponse rstr) |
| | | 481 | | { |
| | 0 | 482 | | if (rstr != null && rstr.RequestSecurityTokenResponseXml != null && rstr.RequestSecurityTokenResponseXml |
| | | 483 | | { |
| | 0 | 484 | | for (int i = 0; i < rstr.RequestSecurityTokenResponseXml.ChildNodes.Count; ++i) |
| | | 485 | | { |
| | 0 | 486 | | if (rstr.RequestSecurityTokenResponseXml.ChildNodes[i] is XmlElement element) |
| | | 487 | | { |
| | 0 | 488 | | if (element.LocalName == DriverDictionary.Authenticator.Value && element.NamespaceURI == Dri |
| | | 489 | | { |
| | 0 | 490 | | XmlElement combinedHashElement = XmlHelper.GetChildElement(element); |
| | 0 | 491 | | if (combinedHashElement.LocalName == DriverDictionary.CombinedHash.Value && combinedHash |
| | | 492 | | { |
| | 0 | 493 | | string authenticatorString = XmlHelper.ReadTextElementAsTrimmedString(combinedHashEl |
| | 0 | 494 | | return Convert.FromBase64String(authenticatorString); |
| | | 495 | | } |
| | | 496 | | } |
| | | 497 | | } |
| | | 498 | | } |
| | | 499 | | } |
| | 0 | 500 | | return null; |
| | | 501 | | } |
| | | 502 | | |
| | | 503 | | public override BinaryNegotiation GetBinaryNegotiation(RequestSecurityTokenResponse rstr) |
| | | 504 | | { |
| | 0 | 505 | | if (rstr == null) |
| | | 506 | | { |
| | 0 | 507 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(rstr)); |
| | | 508 | | } |
| | | 509 | | |
| | 0 | 510 | | return GetBinaryNegotiation(rstr.RequestSecurityTokenResponseXml); |
| | | 511 | | } |
| | | 512 | | |
| | | 513 | | public override BinaryNegotiation GetBinaryNegotiation(RequestSecurityToken rst) |
| | | 514 | | { |
| | 0 | 515 | | if (rst == null) |
| | | 516 | | { |
| | 0 | 517 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(rst)); |
| | | 518 | | } |
| | | 519 | | |
| | 0 | 520 | | return GetBinaryNegotiation(rst.RequestSecurityTokenXml); |
| | | 521 | | } |
| | | 522 | | |
| | | 523 | | private BinaryNegotiation GetBinaryNegotiation(XmlElement rootElement) |
| | | 524 | | { |
| | 0 | 525 | | if (rootElement == null) |
| | | 526 | | { |
| | 0 | 527 | | return null; |
| | | 528 | | } |
| | 0 | 529 | | for (int i = 0; i < rootElement.ChildNodes.Count; ++i) |
| | | 530 | | { |
| | 0 | 531 | | if (rootElement.ChildNodes[i] is XmlElement elem) |
| | | 532 | | { |
| | 0 | 533 | | if (elem.LocalName == DriverDictionary.BinaryExchange.Value && elem.NamespaceURI == DriverDictio |
| | | 534 | | { |
| | 0 | 535 | | return ReadBinaryNegotiation(elem); |
| | | 536 | | } |
| | | 537 | | } |
| | | 538 | | } |
| | 0 | 539 | | return null; |
| | | 540 | | } |
| | | 541 | | |
| | | 542 | | public override SecurityToken GetEntropy(RequestSecurityToken rst, SecurityTokenResolver resolver) |
| | | 543 | | { |
| | 10 | 544 | | if (rst == null) |
| | | 545 | | { |
| | 0 | 546 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(rst)); |
| | | 547 | | } |
| | | 548 | | |
| | 10 | 549 | | return GetEntropy(rst.RequestSecurityTokenXml, resolver); |
| | | 550 | | } |
| | | 551 | | |
| | | 552 | | public override SecurityToken GetEntropy(RequestSecurityTokenResponse rstr, SecurityTokenResolver resolver) |
| | | 553 | | { |
| | 0 | 554 | | if (rstr == null) |
| | | 555 | | { |
| | 0 | 556 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(rstr)); |
| | | 557 | | } |
| | | 558 | | |
| | 0 | 559 | | return GetEntropy(rstr.RequestSecurityTokenResponseXml, resolver); |
| | | 560 | | } |
| | | 561 | | |
| | | 562 | | private SecurityToken GetEntropy(XmlElement rootElement, SecurityTokenResolver resolver) |
| | | 563 | | { |
| | 10 | 564 | | if (rootElement == null || rootElement.ChildNodes == null) |
| | | 565 | | { |
| | 0 | 566 | | return null; |
| | | 567 | | } |
| | 60 | 568 | | for (int i = 0; i < rootElement.ChildNodes.Count; ++i) |
| | | 569 | | { |
| | 30 | 570 | | if (rootElement.ChildNodes[i] is XmlElement element) |
| | | 571 | | { |
| | 30 | 572 | | if (element.LocalName == DriverDictionary.Entropy.Value && element.NamespaceURI == DriverDiction |
| | | 573 | | { |
| | 10 | 574 | | XmlElement tokenXml = XmlHelper.GetChildElement(element); |
| | 10 | 575 | | string valueTypeUri = element.GetAttribute(SecurityJan2004Strings.ValueType); |
| | 10 | 576 | | if (valueTypeUri.Length == 0) |
| | | 577 | | { |
| | | 578 | | } |
| | | 579 | | |
| | 10 | 580 | | return _standardsManager.SecurityTokenSerializer.ReadToken(new XmlNodeReader(tokenXml), reso |
| | | 581 | | } |
| | | 582 | | } |
| | | 583 | | } |
| | 0 | 584 | | return null; |
| | | 585 | | } |
| | | 586 | | |
| | | 587 | | private void GetIssuedAndProofXml(RequestSecurityTokenResponse rstr, out XmlElement issuedTokenXml, out XmlE |
| | | 588 | | { |
| | 0 | 589 | | issuedTokenXml = null; |
| | 0 | 590 | | proofTokenXml = null; |
| | 0 | 591 | | if ((rstr.RequestSecurityTokenResponseXml != null) && (rstr.RequestSecurityTokenResponseXml.ChildNodes ! |
| | | 592 | | { |
| | 0 | 593 | | for (int i = 0; i < rstr.RequestSecurityTokenResponseXml.ChildNodes.Count; ++i) |
| | | 594 | | { |
| | 0 | 595 | | if (rstr.RequestSecurityTokenResponseXml.ChildNodes[i] is XmlElement elem) |
| | | 596 | | { |
| | 0 | 597 | | if (elem.LocalName == DriverDictionary.RequestedSecurityToken.Value && elem.NamespaceURI == |
| | | 598 | | { |
| | 0 | 599 | | if (issuedTokenXml != null) |
| | | 600 | | { |
| | 0 | 601 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationExcept |
| | | 602 | | } |
| | 0 | 603 | | issuedTokenXml = XmlHelper.GetChildElement(elem); |
| | | 604 | | } |
| | 0 | 605 | | else if (elem.LocalName == DriverDictionary.RequestedProofToken.Value && elem.NamespaceURI = |
| | | 606 | | { |
| | 0 | 607 | | if (proofTokenXml != null) |
| | | 608 | | { |
| | 0 | 609 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationExcept |
| | | 610 | | } |
| | 0 | 611 | | proofTokenXml = XmlHelper.GetChildElement(elem); |
| | | 612 | | } |
| | | 613 | | } |
| | | 614 | | } |
| | | 615 | | } |
| | 0 | 616 | | } |
| | | 617 | | |
| | | 618 | | /// <summary> |
| | | 619 | | /// The algorithm for computing the key is: |
| | | 620 | | /// 1. If there is requestorEntropy: |
| | | 621 | | /// a. If there is no <RequestedProofToken> use the requestorEntropy as the key |
| | | 622 | | /// b. If there is a <RequestedProofToken> with a ComputedKeyUri, combine the client and server entropies |
| | | 623 | | /// c. Anything else, throw |
| | | 624 | | /// 2. If there is no requestorEntropy: |
| | | 625 | | /// a. THere has to be a <RequestedProofToken> that contains the proof key |
| | | 626 | | /// </summary> |
| | | 627 | | public override GenericXmlSecurityToken GetIssuedToken(RequestSecurityTokenResponse rstr, SecurityTokenResol |
| | | 628 | | ReadOnlyCollection<IAuthorizationPolicy> authorizationPolicies, int defaultKeySize, bool isBearerKeyType |
| | | 629 | | { |
| | 0 | 630 | | SecurityKeyEntropyModeHelper.Validate(keyEntropyMode); |
| | | 631 | | |
| | 0 | 632 | | if (defaultKeySize < 0) |
| | | 633 | | { |
| | 0 | 634 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(def |
| | | 635 | | } |
| | | 636 | | |
| | 0 | 637 | | if (rstr == null) |
| | | 638 | | { |
| | 0 | 639 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(rstr)); |
| | | 640 | | } |
| | | 641 | | |
| | | 642 | | string tokenType; |
| | 0 | 643 | | if (rstr.TokenType != null) |
| | | 644 | | { |
| | 0 | 645 | | if (expectedTokenType != null && expectedTokenType != rstr.TokenType) |
| | | 646 | | { |
| | 0 | 647 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma |
| | | 648 | | } |
| | 0 | 649 | | tokenType = rstr.TokenType; |
| | | 650 | | } |
| | | 651 | | else |
| | | 652 | | { |
| | | 653 | | } |
| | | 654 | | |
| | | 655 | | // search the response elements for licenseXml, proofXml, and lifetime |
| | 0 | 656 | | DateTime created = rstr.ValidFrom; |
| | 0 | 657 | | DateTime expires = rstr.ValidTo; |
| | 0 | 658 | | GetIssuedAndProofXml(rstr, out XmlElement issuedTokenXml, out XmlElement proofXml); |
| | | 659 | | |
| | 0 | 660 | | if (issuedTokenXml == null) |
| | | 661 | | { |
| | 0 | 662 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR |
| | | 663 | | } |
| | | 664 | | |
| | 0 | 665 | | if (isBearerKeyType) |
| | | 666 | | { |
| | 0 | 667 | | if (proofXml != null) |
| | | 668 | | { |
| | 0 | 669 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma |
| | | 670 | | } |
| | | 671 | | |
| | 0 | 672 | | return new GenericXmlSecurityToken(issuedTokenXml, null, created, expires, rstr.RequestedAttachedRef |
| | | 673 | | } |
| | | 674 | | |
| | | 675 | | SecurityToken proofToken; |
| | 0 | 676 | | SecurityToken entropyToken = GetEntropy(rstr, resolver); |
| | 0 | 677 | | if (keyEntropyMode == SecurityKeyEntropyMode.ClientEntropy) |
| | | 678 | | { |
| | 0 | 679 | | if (requestorEntropy == null) |
| | | 680 | | { |
| | 0 | 681 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma |
| | | 682 | | } |
| | | 683 | | // enforce that there is no entropy or proof token in the RSTR |
| | 0 | 684 | | if (proofXml != null || entropyToken != null) |
| | | 685 | | { |
| | 0 | 686 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma |
| | | 687 | | } |
| | 0 | 688 | | proofToken = new BinarySecretSecurityToken(requestorEntropy); |
| | | 689 | | } |
| | 0 | 690 | | else if (keyEntropyMode == SecurityKeyEntropyMode.ServerEntropy) |
| | | 691 | | { |
| | 0 | 692 | | if (requestorEntropy != null) |
| | | 693 | | { |
| | 0 | 694 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma |
| | | 695 | | } |
| | 0 | 696 | | if (rstr.ComputeKey || entropyToken != null) |
| | | 697 | | { |
| | 0 | 698 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma |
| | | 699 | | } |
| | 0 | 700 | | if (proofXml == null) |
| | | 701 | | { |
| | 0 | 702 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma |
| | | 703 | | } |
| | 0 | 704 | | string valueTypeUri = proofXml.GetAttribute(SecurityJan2004Strings.ValueType); |
| | 0 | 705 | | if (valueTypeUri.Length == 0) |
| | | 706 | | { |
| | | 707 | | } |
| | | 708 | | |
| | 0 | 709 | | proofToken = _standardsManager.SecurityTokenSerializer.ReadToken(new XmlNodeReader(proofXml), resolv |
| | | 710 | | } |
| | | 711 | | else |
| | | 712 | | { |
| | 0 | 713 | | if (!rstr.ComputeKey) |
| | | 714 | | { |
| | 0 | 715 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma |
| | | 716 | | } |
| | 0 | 717 | | if (entropyToken == null) |
| | | 718 | | { |
| | 0 | 719 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma |
| | | 720 | | } |
| | 0 | 721 | | if (requestorEntropy == null) |
| | | 722 | | { |
| | 0 | 723 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma |
| | | 724 | | } |
| | 0 | 725 | | if (rstr.KeySize == 0 && defaultKeySize == 0) |
| | | 726 | | { |
| | 0 | 727 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma |
| | | 728 | | } |
| | 0 | 729 | | int issuedKeySize = (rstr.KeySize != 0) ? rstr.KeySize : defaultKeySize; |
| | | 730 | | byte[] issuerEntropy; |
| | 0 | 731 | | if (entropyToken is BinarySecretSecurityToken) |
| | | 732 | | { |
| | 0 | 733 | | issuerEntropy = ((BinarySecretSecurityToken)entropyToken).GetKeyBytes(); |
| | | 734 | | } |
| | 0 | 735 | | else if (entropyToken is WrappedKeySecurityToken) |
| | | 736 | | { |
| | 0 | 737 | | issuerEntropy = ((WrappedKeySecurityToken)entropyToken).GetWrappedKey(); |
| | | 738 | | } |
| | | 739 | | else |
| | | 740 | | { |
| | 0 | 741 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.Format(SR |
| | | 742 | | } |
| | | 743 | | // compute the PSHA1 derived key |
| | 0 | 744 | | byte[] issuedKey = RequestSecurityTokenResponse.ComputeCombinedKey(requestorEntropy, issuerEntropy, |
| | 0 | 745 | | proofToken = new BinarySecretSecurityToken(issuedKey); |
| | | 746 | | } |
| | | 747 | | |
| | 0 | 748 | | SecurityKeyIdentifierClause internalReference = rstr.RequestedAttachedReference; |
| | 0 | 749 | | SecurityKeyIdentifierClause externalReference = rstr.RequestedUnattachedReference; |
| | | 750 | | |
| | 0 | 751 | | return new BufferedGenericXmlSecurityToken(issuedTokenXml, proofToken, created, expires, internalReferen |
| | | 752 | | } |
| | | 753 | | |
| | | 754 | | public override GenericXmlSecurityToken GetIssuedToken(RequestSecurityTokenResponse rstr, string expectedTok |
| | | 755 | | ReadOnlyCollection<IAuthorizationPolicy> authorizationPolicies, RSA clientKey) |
| | | 756 | | { |
| | 0 | 757 | | if (rstr == null) |
| | | 758 | | { |
| | 0 | 759 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(rstr))); |
| | | 760 | | } |
| | | 761 | | |
| | | 762 | | string tokenType; |
| | 0 | 763 | | if (rstr.TokenType != null) |
| | | 764 | | { |
| | 0 | 765 | | if (expectedTokenType != null && expectedTokenType != rstr.TokenType) |
| | | 766 | | { |
| | 0 | 767 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma |
| | | 768 | | } |
| | 0 | 769 | | tokenType = rstr.TokenType; |
| | | 770 | | } |
| | | 771 | | else |
| | | 772 | | { |
| | | 773 | | } |
| | | 774 | | |
| | | 775 | | // search the response elements for licenseXml, proofXml, and lifetime |
| | 0 | 776 | | DateTime created = rstr.ValidFrom; |
| | 0 | 777 | | DateTime expires = rstr.ValidTo; |
| | 0 | 778 | | GetIssuedAndProofXml(rstr, out XmlElement issuedTokenXml, out XmlElement proofXml); |
| | | 779 | | |
| | 0 | 780 | | if (issuedTokenXml == null) |
| | | 781 | | { |
| | 0 | 782 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR |
| | | 783 | | } |
| | | 784 | | |
| | | 785 | | // enforce that there is no proof token in the RSTR |
| | 0 | 786 | | if (proofXml != null) |
| | | 787 | | { |
| | 0 | 788 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR |
| | | 789 | | } |
| | 0 | 790 | | SecurityKeyIdentifierClause internalReference = rstr.RequestedAttachedReference; |
| | 0 | 791 | | SecurityKeyIdentifierClause externalReference = rstr.RequestedUnattachedReference; |
| | | 792 | | |
| | 0 | 793 | | SecurityToken proofToken = new RsaSecurityToken(clientKey); |
| | 0 | 794 | | return new BufferedGenericXmlSecurityToken(issuedTokenXml, proofToken, created, expires, internalReferen |
| | | 795 | | } |
| | | 796 | | |
| | | 797 | | public override bool IsAtRequestSecurityTokenResponse(XmlReader reader) |
| | | 798 | | { |
| | 0 | 799 | | if (reader == null) |
| | | 800 | | { |
| | 0 | 801 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader)); |
| | | 802 | | } |
| | | 803 | | |
| | 0 | 804 | | return reader.IsStartElement(DriverDictionary.RequestSecurityTokenResponse.Value, DriverDictionary.Names |
| | | 805 | | } |
| | | 806 | | |
| | | 807 | | public override bool IsAtRequestSecurityTokenResponseCollection(XmlReader reader) |
| | | 808 | | { |
| | 0 | 809 | | if (reader == null) |
| | | 810 | | { |
| | 0 | 811 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader)); |
| | | 812 | | } |
| | | 813 | | |
| | 0 | 814 | | return reader.IsStartElement(DriverDictionary.RequestSecurityTokenResponseCollection.Value, DriverDictio |
| | | 815 | | } |
| | | 816 | | |
| | | 817 | | public override bool IsRequestedSecurityTokenElement(string name, string nameSpace) |
| | | 818 | | { |
| | 0 | 819 | | return (name == DriverDictionary.RequestedSecurityToken.Value && nameSpace == DriverDictionary.Namespace |
| | | 820 | | } |
| | | 821 | | |
| | | 822 | | public override bool IsRequestedProofTokenElement(string name, string nameSpace) |
| | | 823 | | { |
| | 0 | 824 | | return (name == DriverDictionary.RequestedProofToken.Value && nameSpace == DriverDictionary.Namespace.Va |
| | | 825 | | } |
| | | 826 | | |
| | | 827 | | public static BinaryNegotiation ReadBinaryNegotiation(XmlElement elem) |
| | | 828 | | { |
| | 0 | 829 | | if (elem == null) |
| | | 830 | | { |
| | 0 | 831 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(elem)); |
| | | 832 | | } |
| | | 833 | | |
| | | 834 | | // get the encoding and valueType attributes |
| | 0 | 835 | | string encodingUri = null; |
| | 0 | 836 | | string valueTypeUri = null; |
| | 0 | 837 | | if (elem.Attributes != null) |
| | | 838 | | { |
| | 0 | 839 | | for (int i = 0; i < elem.Attributes.Count; ++i) |
| | | 840 | | { |
| | 0 | 841 | | XmlAttribute attr = elem.Attributes[i]; |
| | 0 | 842 | | if (attr.LocalName == SecurityJan2004Strings.EncodingType && attr.NamespaceURI.Length == 0) |
| | | 843 | | { |
| | 0 | 844 | | encodingUri = attr.Value; |
| | 0 | 845 | | if (encodingUri != Base64Uri && encodingUri != HexBinaryUri) |
| | | 846 | | { |
| | 0 | 847 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR. |
| | | 848 | | } |
| | | 849 | | } |
| | 0 | 850 | | else if (attr.LocalName == SecurityJan2004Strings.ValueType && attr.NamespaceURI.Length == 0) |
| | | 851 | | { |
| | 0 | 852 | | valueTypeUri = attr.Value; |
| | | 853 | | } |
| | | 854 | | // ignore all other attributes |
| | | 855 | | } |
| | | 856 | | } |
| | 0 | 857 | | if (encodingUri == null) |
| | | 858 | | { |
| | 0 | 859 | | XmlHelper.OnRequiredAttributeMissing("EncodingType", elem.Name); |
| | | 860 | | } |
| | 0 | 861 | | if (valueTypeUri == null) |
| | | 862 | | { |
| | 0 | 863 | | XmlHelper.OnRequiredAttributeMissing("ValueType", elem.Name); |
| | | 864 | | } |
| | 0 | 865 | | string encodedBlob = XmlHelper.ReadTextElementAsTrimmedString(elem); |
| | | 866 | | byte[] negotiationData; |
| | 0 | 867 | | if (encodingUri == Base64Uri) |
| | | 868 | | { |
| | 0 | 869 | | negotiationData = Convert.FromBase64String(encodedBlob); |
| | | 870 | | } |
| | | 871 | | else |
| | | 872 | | { |
| | 0 | 873 | | negotiationData = HexBinary.Parse(encodedBlob).Value; |
| | | 874 | | } |
| | 0 | 875 | | return new BinaryNegotiation(valueTypeUri, negotiationData); |
| | | 876 | | } |
| | | 877 | | |
| | | 878 | | // Note in Apr2004, internal & external references aren't supported - |
| | | 879 | | // our strategy is to see if there's a token reference (and use it for external ref) and backup is to scan t |
| | | 880 | | protected virtual void ReadReferences(XmlElement rstrXml, out SecurityKeyIdentifierClause requestedAttachedR |
| | | 881 | | out SecurityKeyIdentifierClause requestedUnattachedReference) |
| | | 882 | | { |
| | 0 | 883 | | XmlElement issuedTokenXml = null; |
| | 0 | 884 | | requestedAttachedReference = null; |
| | 0 | 885 | | requestedUnattachedReference = null; |
| | 0 | 886 | | for (int i = 0; i < rstrXml.ChildNodes.Count; ++i) |
| | | 887 | | { |
| | 0 | 888 | | if (rstrXml.ChildNodes[i] is XmlElement child) |
| | | 889 | | { |
| | 0 | 890 | | if (child.LocalName == DriverDictionary.RequestedSecurityToken.Value && child.NamespaceURI == Dr |
| | | 891 | | { |
| | 0 | 892 | | issuedTokenXml = XmlHelper.GetChildElement(child); |
| | | 893 | | } |
| | 0 | 894 | | else if (child.LocalName == DriverDictionary.RequestedTokenReference.Value && child.NamespaceURI |
| | | 895 | | { |
| | 0 | 896 | | requestedUnattachedReference = GetKeyIdentifierXmlReferenceClause(XmlHelper.GetChildElement( |
| | | 897 | | } |
| | | 898 | | } |
| | | 899 | | } |
| | | 900 | | |
| | 0 | 901 | | if (issuedTokenXml != null) |
| | | 902 | | { |
| | 0 | 903 | | requestedAttachedReference = _standardsManager.CreateKeyIdentifierClauseFromTokenXml(issuedTokenXml, |
| | 0 | 904 | | if (requestedUnattachedReference == null) |
| | | 905 | | { |
| | | 906 | | try |
| | | 907 | | { |
| | 0 | 908 | | requestedUnattachedReference = _standardsManager.CreateKeyIdentifierClauseFromTokenXml(issue |
| | 0 | 909 | | } |
| | 0 | 910 | | catch (XmlException) |
| | | 911 | | { |
| | 0 | 912 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.Trus |
| | | 913 | | } |
| | | 914 | | } |
| | | 915 | | } |
| | 0 | 916 | | } |
| | | 917 | | |
| | | 918 | | internal bool TryReadKeyIdentifierClause(XmlNodeReader reader, out SecurityKeyIdentifierClause keyIdentifier |
| | | 919 | | { |
| | | 920 | | try |
| | | 921 | | { |
| | 0 | 922 | | keyIdentifierClause = _standardsManager.SecurityTokenSerializer.ReadKeyIdentifierClause(reader); |
| | 0 | 923 | | } |
| | | 924 | | catch (XmlException e) |
| | | 925 | | { |
| | 0 | 926 | | if (Fx.IsFatal(e)) |
| | | 927 | | { |
| | 0 | 928 | | throw; |
| | | 929 | | } |
| | | 930 | | |
| | 0 | 931 | | keyIdentifierClause = null; |
| | 0 | 932 | | return false; |
| | | 933 | | } |
| | | 934 | | catch (Exception e) |
| | | 935 | | { |
| | 0 | 936 | | if (Fx.IsFatal(e)) |
| | | 937 | | { |
| | 0 | 938 | | throw; |
| | | 939 | | } |
| | | 940 | | |
| | 0 | 941 | | keyIdentifierClause = null; |
| | 0 | 942 | | return false; |
| | | 943 | | } |
| | | 944 | | |
| | 0 | 945 | | return true; |
| | 0 | 946 | | } |
| | | 947 | | |
| | | 948 | | internal SecurityKeyIdentifierClause CreateGenericXmlSecurityKeyIdentifierClause(XmlNodeReader reader, XmlEl |
| | | 949 | | { |
| | 0 | 950 | | XmlDictionaryReader localReader = XmlDictionaryReader.CreateDictionaryReader(reader); |
| | 0 | 951 | | string strId = localReader.GetAttribute(XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace |
| | 0 | 952 | | SecurityKeyIdentifierClause keyIdentifierClause = new GenericXmlSecurityKeyIdentifierClause(keyIdentifie |
| | 0 | 953 | | if (!string.IsNullOrEmpty(strId)) |
| | | 954 | | { |
| | 0 | 955 | | keyIdentifierClause.Id = strId; |
| | | 956 | | } |
| | 0 | 957 | | return keyIdentifierClause; |
| | | 958 | | } |
| | | 959 | | |
| | | 960 | | internal SecurityKeyIdentifierClause GetKeyIdentifierXmlReferenceClause(XmlElement keyIdentifierReferenceXml |
| | | 961 | | { |
| | 0 | 962 | | XmlNodeReader reader = new XmlNodeReader(keyIdentifierReferenceXmlElement); |
| | 0 | 963 | | if (!TryReadKeyIdentifierClause(reader, out SecurityKeyIdentifierClause keyIdentifierClause)) |
| | | 964 | | { |
| | 0 | 965 | | keyIdentifierClause = CreateGenericXmlSecurityKeyIdentifierClause(new XmlNodeReader(keyIdentifierRef |
| | | 966 | | } |
| | | 967 | | |
| | 0 | 968 | | return keyIdentifierClause; |
| | | 969 | | } |
| | | 970 | | |
| | | 971 | | protected virtual bool ReadRequestedTokenClosed(XmlElement rstrXml) |
| | | 972 | | { |
| | 0 | 973 | | return false; |
| | | 974 | | } |
| | | 975 | | |
| | | 976 | | protected virtual void ReadTargets(XmlElement rstXml, out SecurityKeyIdentifierClause renewTarget, out Secur |
| | | 977 | | { |
| | 0 | 978 | | renewTarget = null; |
| | 0 | 979 | | closeTarget = null; |
| | 0 | 980 | | } |
| | | 981 | | |
| | | 982 | | public override void OnRSTRorRSTRCMissingException() |
| | | 983 | | { |
| | 0 | 984 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.ExpectedOneOfTwo |
| | 0 | 985 | | DriverDictionary.RequestSecurityTokenResponse, DriverDictionary.RequestSecurityTokenResponseCollecti |
| | 0 | 986 | | DriverDictionary.Namespace))); |
| | | 987 | | } |
| | | 988 | | |
| | | 989 | | private void WriteAppliesTo(object appliesTo, Type appliesToType, XmlObjectSerializer serializer, XmlWriter |
| | | 990 | | { |
| | 0 | 991 | | XmlDictionaryWriter writer = XmlDictionaryWriter.CreateDictionaryWriter(xmlWriter); |
| | 0 | 992 | | writer.WriteStartElement(Namespaces.WSPolicyPrefix, DriverDictionary.AppliesTo.Value, Namespaces.WSPolic |
| | 0 | 993 | | lock (serializer) |
| | | 994 | | { |
| | 0 | 995 | | serializer.WriteObject(writer, appliesTo); |
| | 0 | 996 | | } |
| | 0 | 997 | | writer.WriteEndElement(); |
| | 0 | 998 | | } |
| | | 999 | | |
| | | 1000 | | public void WriteBinaryNegotiation(BinaryNegotiation negotiation, XmlWriter xmlWriter) |
| | | 1001 | | { |
| | 0 | 1002 | | if (negotiation == null) |
| | | 1003 | | { |
| | 0 | 1004 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(negotiation)); |
| | | 1005 | | } |
| | | 1006 | | |
| | 0 | 1007 | | XmlDictionaryWriter writer = XmlDictionaryWriter.CreateDictionaryWriter(xmlWriter); |
| | 0 | 1008 | | negotiation.WriteTo(writer, DriverDictionary.Prefix.Value, |
| | 0 | 1009 | | DriverDictionary.BinaryExchange, DriverDictionary.Namespace, |
| | 0 | 1010 | | XD.SecurityJan2004Dictionary.ValueType, null); |
| | 0 | 1011 | | } |
| | | 1012 | | |
| | | 1013 | | public override void WriteRequestSecurityToken(RequestSecurityToken rst, XmlWriter xmlWriter) |
| | | 1014 | | { |
| | 0 | 1015 | | if (rst == null) |
| | | 1016 | | { |
| | 0 | 1017 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(rst)); |
| | | 1018 | | } |
| | 0 | 1019 | | if (xmlWriter == null) |
| | | 1020 | | { |
| | 0 | 1021 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(xmlWriter)); |
| | | 1022 | | } |
| | 0 | 1023 | | XmlDictionaryWriter writer = XmlDictionaryWriter.CreateDictionaryWriter(xmlWriter); |
| | 0 | 1024 | | if (rst.IsReceiver) |
| | | 1025 | | { |
| | 0 | 1026 | | rst.WriteTo(writer); |
| | 0 | 1027 | | return; |
| | | 1028 | | } |
| | 0 | 1029 | | writer.WriteStartElement(DriverDictionary.Prefix.Value, DriverDictionary.RequestSecurityToken, DriverDic |
| | 0 | 1030 | | XmlHelper.AddNamespaceDeclaration(writer, DriverDictionary.Prefix.Value, DriverDictionary.Namespace); |
| | 0 | 1031 | | if (rst.Context != null) |
| | | 1032 | | { |
| | 0 | 1033 | | writer.WriteAttributeString(DriverDictionary.Context, null, rst.Context); |
| | | 1034 | | } |
| | | 1035 | | |
| | 0 | 1036 | | rst.OnWriteCustomAttributes(writer); |
| | 0 | 1037 | | if (rst.TokenType != null) |
| | | 1038 | | { |
| | 0 | 1039 | | writer.WriteStartElement(DriverDictionary.Prefix.Value, DriverDictionary.TokenType, DriverDictionary |
| | 0 | 1040 | | writer.WriteString(rst.TokenType); |
| | 0 | 1041 | | writer.WriteEndElement(); |
| | | 1042 | | } |
| | 0 | 1043 | | if (rst.RequestType != null) |
| | | 1044 | | { |
| | 0 | 1045 | | writer.WriteStartElement(DriverDictionary.Prefix.Value, DriverDictionary.RequestType, DriverDictiona |
| | 0 | 1046 | | writer.WriteString(rst.RequestType); |
| | 0 | 1047 | | writer.WriteEndElement(); |
| | | 1048 | | } |
| | | 1049 | | |
| | 0 | 1050 | | if (rst.AppliesTo != null) |
| | | 1051 | | { |
| | 0 | 1052 | | WriteAppliesTo(rst.AppliesTo, rst.AppliesToType, rst.AppliesToSerializer, writer); |
| | | 1053 | | } |
| | | 1054 | | |
| | 0 | 1055 | | SecurityToken entropyToken = rst.GetRequestorEntropy(); |
| | 0 | 1056 | | if (entropyToken != null) |
| | | 1057 | | { |
| | 0 | 1058 | | writer.WriteStartElement(DriverDictionary.Prefix.Value, DriverDictionary.Entropy, DriverDictionary.N |
| | 0 | 1059 | | _standardsManager.SecurityTokenSerializer.WriteToken(writer, entropyToken); |
| | 0 | 1060 | | writer.WriteEndElement(); |
| | | 1061 | | } |
| | | 1062 | | |
| | 0 | 1063 | | if (rst.KeySize != 0) |
| | | 1064 | | { |
| | 0 | 1065 | | writer.WriteStartElement(DriverDictionary.Prefix.Value, DriverDictionary.KeySize, DriverDictionary.N |
| | 0 | 1066 | | writer.WriteValue(rst.KeySize); |
| | 0 | 1067 | | writer.WriteEndElement(); |
| | | 1068 | | } |
| | | 1069 | | |
| | 0 | 1070 | | BinaryNegotiation negotiationData = rst.GetBinaryNegotiation(); |
| | 0 | 1071 | | if (negotiationData != null) |
| | | 1072 | | { |
| | 0 | 1073 | | WriteBinaryNegotiation(negotiationData, writer); |
| | | 1074 | | } |
| | | 1075 | | |
| | 0 | 1076 | | WriteTargets(rst, writer); |
| | | 1077 | | |
| | 0 | 1078 | | if (rst.RequestProperties != null) |
| | | 1079 | | { |
| | 0 | 1080 | | foreach (XmlElement property in rst.RequestProperties) |
| | | 1081 | | { |
| | 0 | 1082 | | property.WriteTo(writer); |
| | | 1083 | | } |
| | | 1084 | | } |
| | | 1085 | | |
| | 0 | 1086 | | rst.OnWriteCustomElements(writer); |
| | 0 | 1087 | | writer.WriteEndElement(); |
| | 0 | 1088 | | } |
| | | 1089 | | |
| | | 1090 | | protected virtual void WriteTargets(RequestSecurityToken rst, XmlDictionaryWriter writer) |
| | | 1091 | | { |
| | 0 | 1092 | | } |
| | | 1093 | | |
| | | 1094 | | // Note in Apr2004, internal & external references aren't supported - our strategy is to generate the extern |
| | | 1095 | | protected virtual void WriteReferences(RequestSecurityTokenResponse rstr, XmlDictionaryWriter writer) |
| | | 1096 | | { |
| | 0 | 1097 | | if (rstr.RequestedUnattachedReference != null) |
| | | 1098 | | { |
| | 0 | 1099 | | writer.WriteStartElement(DriverDictionary.Prefix.Value, DriverDictionary.RequestedTokenReference, Dr |
| | 0 | 1100 | | _standardsManager.SecurityTokenSerializer.WriteKeyIdentifierClause(writer, rstr.RequestedUnattachedR |
| | 0 | 1101 | | writer.WriteEndElement(); |
| | | 1102 | | } |
| | 0 | 1103 | | } |
| | | 1104 | | |
| | | 1105 | | protected virtual void WriteRequestedTokenClosed(RequestSecurityTokenResponse rstr, XmlDictionaryWriter writ |
| | | 1106 | | { |
| | 0 | 1107 | | } |
| | | 1108 | | |
| | | 1109 | | public override void WriteRequestSecurityTokenResponse(RequestSecurityTokenResponse rstr, XmlWriter xmlWrite |
| | | 1110 | | { |
| | 20 | 1111 | | if (rstr == null) |
| | | 1112 | | { |
| | 0 | 1113 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(rstr)); |
| | | 1114 | | } |
| | | 1115 | | |
| | 20 | 1116 | | if (xmlWriter == null) |
| | | 1117 | | { |
| | 0 | 1118 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(xmlWriter)); |
| | | 1119 | | } |
| | | 1120 | | |
| | 20 | 1121 | | XmlDictionaryWriter writer = XmlDictionaryWriter.CreateDictionaryWriter(xmlWriter); |
| | 20 | 1122 | | if (rstr.IsReceiver) |
| | | 1123 | | { |
| | 0 | 1124 | | rstr.WriteTo(writer); |
| | 0 | 1125 | | return; |
| | | 1126 | | } |
| | 20 | 1127 | | writer.WriteStartElement(DriverDictionary.Prefix.Value, DriverDictionary.RequestSecurityTokenResponse, D |
| | 20 | 1128 | | if (rstr.Context != null) |
| | | 1129 | | { |
| | 0 | 1130 | | writer.WriteAttributeString(DriverDictionary.Context, null, rstr.Context); |
| | | 1131 | | } |
| | | 1132 | | // define WSUtility at the top level to avoid multiple definitions below |
| | 20 | 1133 | | XmlHelper.AddNamespaceDeclaration(writer, UtilityStrings.Prefix, XD.UtilityDictionary.Namespace); |
| | 20 | 1134 | | rstr.OnWriteCustomAttributes(writer); |
| | | 1135 | | |
| | 20 | 1136 | | if (rstr.TokenType != null) |
| | | 1137 | | { |
| | 10 | 1138 | | writer.WriteElementString(DriverDictionary.Prefix.Value, DriverDictionary.TokenType, DriverDictionar |
| | | 1139 | | } |
| | | 1140 | | |
| | 20 | 1141 | | if (rstr.RequestedSecurityToken != null) |
| | | 1142 | | { |
| | 10 | 1143 | | writer.WriteStartElement(DriverDictionary.Prefix.Value, DriverDictionary.RequestedSecurityToken, Dri |
| | 10 | 1144 | | _standardsManager.SecurityTokenSerializer.WriteToken(writer, rstr.RequestedSecurityToken); |
| | 10 | 1145 | | writer.WriteEndElement(); |
| | | 1146 | | } |
| | | 1147 | | |
| | 20 | 1148 | | if (rstr.AppliesTo != null) |
| | | 1149 | | { |
| | 0 | 1150 | | WriteAppliesTo(rstr.AppliesTo, rstr.AppliesToType, rstr.AppliesToSerializer, writer); |
| | | 1151 | | } |
| | | 1152 | | |
| | 20 | 1153 | | WriteReferences(rstr, writer); |
| | | 1154 | | |
| | 20 | 1155 | | if (rstr.ComputeKey || rstr.RequestedProofToken != null) |
| | | 1156 | | { |
| | 10 | 1157 | | writer.WriteStartElement(DriverDictionary.Prefix.Value, DriverDictionary.RequestedProofToken, Driver |
| | 10 | 1158 | | if (rstr.ComputeKey) |
| | | 1159 | | { |
| | 10 | 1160 | | writer.WriteElementString(DriverDictionary.Prefix.Value, DriverDictionary.ComputedKey, DriverDic |
| | | 1161 | | } |
| | | 1162 | | else |
| | | 1163 | | { |
| | 0 | 1164 | | _standardsManager.SecurityTokenSerializer.WriteToken(writer, rstr.RequestedProofToken); |
| | | 1165 | | } |
| | 10 | 1166 | | writer.WriteEndElement(); |
| | | 1167 | | } |
| | | 1168 | | |
| | 20 | 1169 | | SecurityToken entropyToken = rstr.GetIssuerEntropy(); |
| | 20 | 1170 | | if (entropyToken != null) |
| | | 1171 | | { |
| | 10 | 1172 | | writer.WriteStartElement(DriverDictionary.Prefix.Value, DriverDictionary.Entropy, DriverDictionary.N |
| | 10 | 1173 | | _standardsManager.SecurityTokenSerializer.WriteToken(writer, entropyToken); |
| | 10 | 1174 | | writer.WriteEndElement(); |
| | | 1175 | | } |
| | | 1176 | | |
| | | 1177 | | // To write out the lifetime, the following algorithm is used |
| | | 1178 | | // 1. If the lifetime is explicitly set, write it out. |
| | | 1179 | | // 2. Else, if a token/tokenbuilder has been set, use the lifetime in that. |
| | | 1180 | | // 3. Else do not serialize lifetime |
| | 20 | 1181 | | if (rstr.IsLifetimeSet || rstr.RequestedSecurityToken != null) |
| | | 1182 | | { |
| | 10 | 1183 | | DateTime effectiveTime = SecurityUtils.MinUtcDateTime; |
| | 10 | 1184 | | DateTime expirationTime = SecurityUtils.MaxUtcDateTime; |
| | | 1185 | | |
| | 10 | 1186 | | if (rstr.IsLifetimeSet) |
| | | 1187 | | { |
| | 10 | 1188 | | effectiveTime = rstr.ValidFrom.ToUniversalTime(); |
| | 10 | 1189 | | expirationTime = rstr.ValidTo.ToUniversalTime(); |
| | | 1190 | | } |
| | 0 | 1191 | | else if (rstr.RequestedSecurityToken != null) |
| | | 1192 | | { |
| | 0 | 1193 | | effectiveTime = rstr.RequestedSecurityToken.ValidFrom.ToUniversalTime(); |
| | 0 | 1194 | | expirationTime = rstr.RequestedSecurityToken.ValidTo.ToUniversalTime(); |
| | | 1195 | | } |
| | | 1196 | | |
| | | 1197 | | // write out the lifetime |
| | 10 | 1198 | | writer.WriteStartElement(DriverDictionary.Prefix.Value, DriverDictionary.Lifetime, DriverDictionary. |
| | | 1199 | | // write out Created |
| | 10 | 1200 | | writer.WriteStartElement(XD.UtilityDictionary.Prefix.Value, XD.UtilityDictionary.CreatedElement, XD. |
| | 10 | 1201 | | writer.WriteString(effectiveTime.ToString("yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture.D |
| | 10 | 1202 | | writer.WriteEndElement(); // wsu:Created |
| | | 1203 | | // write out Expires |
| | 10 | 1204 | | writer.WriteStartElement(XD.UtilityDictionary.Prefix.Value, XD.UtilityDictionary.ExpiresElement, XD. |
| | 10 | 1205 | | writer.WriteString(expirationTime.ToString("yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture. |
| | 10 | 1206 | | writer.WriteEndElement(); // wsu:Expires |
| | 10 | 1207 | | writer.WriteEndElement(); // wsse:Lifetime |
| | | 1208 | | } |
| | | 1209 | | |
| | 20 | 1210 | | byte[] authenticator = rstr.GetAuthenticator(); |
| | 20 | 1211 | | if (authenticator != null) |
| | | 1212 | | { |
| | 0 | 1213 | | writer.WriteStartElement(DriverDictionary.Prefix.Value, DriverDictionary.Authenticator, DriverDictio |
| | 0 | 1214 | | writer.WriteStartElement(DriverDictionary.Prefix.Value, DriverDictionary.CombinedHash, DriverDiction |
| | 0 | 1215 | | writer.WriteBase64(authenticator, 0, authenticator.Length); |
| | 0 | 1216 | | writer.WriteEndElement(); |
| | 0 | 1217 | | writer.WriteEndElement(); |
| | | 1218 | | } |
| | | 1219 | | |
| | 20 | 1220 | | if (rstr.KeySize > 0) |
| | | 1221 | | { |
| | 10 | 1222 | | writer.WriteStartElement(DriverDictionary.Prefix.Value, DriverDictionary.KeySize, DriverDictionary.N |
| | 10 | 1223 | | writer.WriteValue(rstr.KeySize); |
| | 10 | 1224 | | writer.WriteEndElement(); |
| | | 1225 | | } |
| | | 1226 | | |
| | 20 | 1227 | | WriteRequestedTokenClosed(rstr, writer); |
| | | 1228 | | |
| | 20 | 1229 | | BinaryNegotiation negotiationData = rstr.GetBinaryNegotiation(); |
| | 20 | 1230 | | if (negotiationData != null) |
| | | 1231 | | { |
| | 0 | 1232 | | WriteBinaryNegotiation(negotiationData, writer); |
| | | 1233 | | } |
| | | 1234 | | |
| | 20 | 1235 | | rstr.OnWriteCustomElements(writer); |
| | 20 | 1236 | | writer.WriteEndElement(); |
| | 20 | 1237 | | } |
| | | 1238 | | |
| | | 1239 | | public override void WriteRequestSecurityTokenResponseCollection(RequestSecurityTokenResponseCollection rstr |
| | | 1240 | | { |
| | 8 | 1241 | | if (rstrCollection == null) |
| | | 1242 | | { |
| | 0 | 1243 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(rstrCollection)); |
| | | 1244 | | } |
| | | 1245 | | |
| | 8 | 1246 | | XmlDictionaryWriter writer = XmlDictionaryWriter.CreateDictionaryWriter(xmlWriter); |
| | 8 | 1247 | | writer.WriteStartElement(DriverDictionary.Prefix.Value, DriverDictionary.RequestSecurityTokenResponseCol |
| | 32 | 1248 | | foreach (RequestSecurityTokenResponse rstr in rstrCollection.RstrCollection) |
| | | 1249 | | { |
| | 8 | 1250 | | rstr.WriteTo(writer); |
| | | 1251 | | } |
| | 8 | 1252 | | writer.WriteEndElement(); |
| | 8 | 1253 | | } |
| | | 1254 | | |
| | | 1255 | | protected void SetProtectionLevelForFederation(OperationDescriptionCollection operations) |
| | | 1256 | | { |
| | 0 | 1257 | | foreach (OperationDescription operation in operations) |
| | | 1258 | | { |
| | 0 | 1259 | | foreach (MessageDescription message in operation.Messages) |
| | | 1260 | | { |
| | 0 | 1261 | | if (message.Body.Parts.Count > 0) |
| | | 1262 | | { |
| | 0 | 1263 | | foreach (MessagePartDescription part in message.Body.Parts) |
| | | 1264 | | { |
| | 0 | 1265 | | part.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign; |
| | | 1266 | | } |
| | | 1267 | | } |
| | 0 | 1268 | | if (OperationFormatter.IsValidReturnValue(message.Body.ReturnValue)) |
| | | 1269 | | { |
| | 0 | 1270 | | message.Body.ReturnValue.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSig |
| | | 1271 | | } |
| | | 1272 | | } |
| | | 1273 | | } |
| | 0 | 1274 | | } |
| | | 1275 | | |
| | | 1276 | | public override bool TryParseKeySizeElement(XmlElement element, out int keySize) |
| | | 1277 | | { |
| | 0 | 1278 | | if (element == null) |
| | | 1279 | | { |
| | 0 | 1280 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(element)); |
| | | 1281 | | } |
| | | 1282 | | |
| | 0 | 1283 | | if (element.LocalName == DriverDictionary.KeySize.Value |
| | 0 | 1284 | | && element.NamespaceURI == DriverDictionary.Namespace.Value) |
| | | 1285 | | { |
| | 0 | 1286 | | keySize = int.Parse(XmlHelper.ReadTextElementAsTrimmedString(element), NumberFormatInfo.InvariantInf |
| | 0 | 1287 | | return true; |
| | | 1288 | | } |
| | | 1289 | | |
| | 0 | 1290 | | keySize = 0; |
| | 0 | 1291 | | return false; |
| | | 1292 | | } |
| | | 1293 | | |
| | | 1294 | | public override XmlElement CreateKeySizeElement(int keySize) |
| | | 1295 | | { |
| | 0 | 1296 | | if (keySize < 0) |
| | | 1297 | | { |
| | 0 | 1298 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(key |
| | | 1299 | | } |
| | 0 | 1300 | | XmlDocument doc = new XmlDocument(); |
| | 0 | 1301 | | XmlElement result = doc.CreateElement(DriverDictionary.Prefix.Value, DriverDictionary.KeySize.Value, |
| | 0 | 1302 | | DriverDictionary.Namespace.Value); |
| | 0 | 1303 | | result.AppendChild(doc.CreateTextNode(keySize.ToString(CultureInfo.InvariantCulture.NumberFormat))); |
| | 0 | 1304 | | return result; |
| | | 1305 | | } |
| | | 1306 | | |
| | | 1307 | | public override XmlElement CreateKeyTypeElement(SecurityKeyType keyType) |
| | | 1308 | | { |
| | 0 | 1309 | | if (keyType == SecurityKeyType.SymmetricKey) |
| | | 1310 | | { |
| | 0 | 1311 | | return CreateSymmetricKeyTypeElement(); |
| | | 1312 | | } |
| | 0 | 1313 | | else if (keyType == SecurityKeyType.AsymmetricKey) |
| | | 1314 | | { |
| | 0 | 1315 | | return CreatePublicKeyTypeElement(); |
| | | 1316 | | } |
| | | 1317 | | else |
| | | 1318 | | { |
| | 0 | 1319 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR |
| | | 1320 | | } |
| | | 1321 | | } |
| | | 1322 | | |
| | | 1323 | | public override bool TryParseKeyTypeElement(XmlElement element, out SecurityKeyType keyType) |
| | | 1324 | | { |
| | 0 | 1325 | | if (element == null) |
| | | 1326 | | { |
| | 0 | 1327 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(element)); |
| | | 1328 | | } |
| | | 1329 | | |
| | 0 | 1330 | | if (TryParseSymmetricKeyElement(element)) |
| | | 1331 | | { |
| | 0 | 1332 | | keyType = SecurityKeyType.SymmetricKey; |
| | 0 | 1333 | | return true; |
| | | 1334 | | } |
| | 0 | 1335 | | else if (TryParsePublicKeyElement(element)) |
| | | 1336 | | { |
| | 0 | 1337 | | keyType = SecurityKeyType.AsymmetricKey; |
| | 0 | 1338 | | return true; |
| | | 1339 | | } |
| | | 1340 | | |
| | 0 | 1341 | | keyType = SecurityKeyType.SymmetricKey; |
| | 0 | 1342 | | return false; |
| | | 1343 | | } |
| | | 1344 | | |
| | | 1345 | | public bool TryParseSymmetricKeyElement(XmlElement element) |
| | | 1346 | | { |
| | 0 | 1347 | | if (element == null) |
| | | 1348 | | { |
| | 0 | 1349 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(element)); |
| | | 1350 | | } |
| | | 1351 | | |
| | 0 | 1352 | | return element.LocalName == DriverDictionary.KeyType.Value |
| | 0 | 1353 | | && element.NamespaceURI == DriverDictionary.Namespace.Value |
| | 0 | 1354 | | && element.InnerText == DriverDictionary.SymmetricKeyType.Value; |
| | | 1355 | | } |
| | | 1356 | | |
| | | 1357 | | private XmlElement CreateSymmetricKeyTypeElement() |
| | | 1358 | | { |
| | 0 | 1359 | | XmlDocument doc = new XmlDocument(); |
| | 0 | 1360 | | XmlElement result = doc.CreateElement(DriverDictionary.Prefix.Value, DriverDictionary.KeyType.Value, |
| | 0 | 1361 | | DriverDictionary.Namespace.Value); |
| | 0 | 1362 | | result.AppendChild(doc.CreateTextNode(DriverDictionary.SymmetricKeyType.Value)); |
| | 0 | 1363 | | return result; |
| | | 1364 | | } |
| | | 1365 | | |
| | | 1366 | | private bool TryParsePublicKeyElement(XmlElement element) |
| | | 1367 | | { |
| | 0 | 1368 | | if (element == null) |
| | | 1369 | | { |
| | 0 | 1370 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(element)); |
| | | 1371 | | } |
| | | 1372 | | |
| | 0 | 1373 | | return element.LocalName == DriverDictionary.KeyType.Value |
| | 0 | 1374 | | && element.NamespaceURI == DriverDictionary.Namespace.Value |
| | 0 | 1375 | | && element.InnerText == DriverDictionary.PublicKeyType.Value; |
| | | 1376 | | } |
| | | 1377 | | |
| | | 1378 | | private XmlElement CreatePublicKeyTypeElement() |
| | | 1379 | | { |
| | 0 | 1380 | | XmlDocument doc = new XmlDocument(); |
| | 0 | 1381 | | XmlElement result = doc.CreateElement(DriverDictionary.Prefix.Value, DriverDictionary.KeyType.Value, |
| | 0 | 1382 | | DriverDictionary.Namespace.Value); |
| | 0 | 1383 | | result.AppendChild(doc.CreateTextNode(DriverDictionary.PublicKeyType.Value)); |
| | 0 | 1384 | | return result; |
| | | 1385 | | } |
| | | 1386 | | |
| | | 1387 | | public override bool TryParseTokenTypeElement(XmlElement element, out string tokenType) |
| | | 1388 | | { |
| | 0 | 1389 | | if (element == null) |
| | | 1390 | | { |
| | 0 | 1391 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(element)); |
| | | 1392 | | } |
| | | 1393 | | |
| | 0 | 1394 | | if (element.LocalName == DriverDictionary.TokenType.Value |
| | 0 | 1395 | | && element.NamespaceURI == DriverDictionary.Namespace.Value) |
| | | 1396 | | { |
| | 0 | 1397 | | tokenType = element.InnerText; |
| | 0 | 1398 | | return true; |
| | | 1399 | | } |
| | | 1400 | | |
| | 0 | 1401 | | tokenType = null; |
| | 0 | 1402 | | return false; |
| | | 1403 | | } |
| | | 1404 | | |
| | | 1405 | | public override XmlElement CreateTokenTypeElement(string tokenTypeUri) |
| | | 1406 | | { |
| | 0 | 1407 | | if (tokenTypeUri == null) |
| | | 1408 | | { |
| | 0 | 1409 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(tokenTypeUri)); |
| | | 1410 | | } |
| | 0 | 1411 | | XmlDocument doc = new XmlDocument(); |
| | 0 | 1412 | | XmlElement result = doc.CreateElement(DriverDictionary.Prefix.Value, DriverDictionary.TokenType.Value, |
| | 0 | 1413 | | DriverDictionary.Namespace.Value); |
| | 0 | 1414 | | result.AppendChild(doc.CreateTextNode(tokenTypeUri)); |
| | 0 | 1415 | | return result; |
| | | 1416 | | } |
| | | 1417 | | |
| | | 1418 | | public override XmlElement CreateUseKeyElement(SecurityKeyIdentifier keyIdentifier, SecurityStandardsManager |
| | | 1419 | | { |
| | 0 | 1420 | | if (keyIdentifier == null) |
| | | 1421 | | { |
| | 0 | 1422 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(keyIdentifier)); |
| | | 1423 | | } |
| | 0 | 1424 | | if (standardsManager == null) |
| | | 1425 | | { |
| | 0 | 1426 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(standardsManager)); |
| | | 1427 | | } |
| | 0 | 1428 | | XmlDocument doc = new XmlDocument(); |
| | 0 | 1429 | | XmlElement result = doc.CreateElement(DriverDictionary.UseKey.Value, DriverDictionary.Namespace.Value); |
| | 0 | 1430 | | MemoryStream stream = new MemoryStream(); |
| | 0 | 1431 | | using (XmlDictionaryWriter writer = XmlDictionaryWriter.CreateDictionaryWriter(new XmlTextWriter(stream, |
| | | 1432 | | { |
| | 0 | 1433 | | standardsManager.SecurityTokenSerializer.WriteKeyIdentifier(writer, keyIdentifier); |
| | 0 | 1434 | | writer.Flush(); |
| | 0 | 1435 | | stream.Seek(0, SeekOrigin.Begin); |
| | | 1436 | | XmlNode skiNode; |
| | 0 | 1437 | | using (XmlDictionaryReader reader = XmlDictionaryReader.CreateDictionaryReader(new XmlTextReader(str |
| | | 1438 | | { |
| | 0 | 1439 | | reader.MoveToContent(); |
| | 0 | 1440 | | skiNode = doc.ReadNode(reader); |
| | 0 | 1441 | | } |
| | 0 | 1442 | | result.AppendChild(skiNode); |
| | 0 | 1443 | | } |
| | 0 | 1444 | | return result; |
| | | 1445 | | } |
| | | 1446 | | |
| | | 1447 | | public override XmlElement CreateSignWithElement(string signatureAlgorithm) |
| | | 1448 | | { |
| | 0 | 1449 | | if (signatureAlgorithm == null) |
| | | 1450 | | { |
| | 0 | 1451 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(signatureAlgorithm)); |
| | | 1452 | | } |
| | 0 | 1453 | | XmlDocument doc = new XmlDocument(); |
| | 0 | 1454 | | XmlElement result = doc.CreateElement(DriverDictionary.Prefix.Value, DriverDictionary.SignWith.Value, |
| | 0 | 1455 | | DriverDictionary.Namespace.Value); |
| | 0 | 1456 | | result.AppendChild(doc.CreateTextNode(signatureAlgorithm)); |
| | 0 | 1457 | | return result; |
| | | 1458 | | } |
| | | 1459 | | |
| | | 1460 | | internal override bool IsSignWithElement(XmlElement element, out string signatureAlgorithm) |
| | | 1461 | | { |
| | 0 | 1462 | | return CheckElement(element, DriverDictionary.SignWith.Value, DriverDictionary.Namespace.Value, out sign |
| | | 1463 | | } |
| | | 1464 | | |
| | | 1465 | | public override XmlElement CreateEncryptWithElement(string encryptionAlgorithm) |
| | | 1466 | | { |
| | 0 | 1467 | | if (encryptionAlgorithm == null) |
| | | 1468 | | { |
| | 0 | 1469 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(encryptionAlgorithm)); |
| | | 1470 | | } |
| | 0 | 1471 | | XmlDocument doc = new XmlDocument(); |
| | 0 | 1472 | | XmlElement result = doc.CreateElement(DriverDictionary.Prefix.Value, DriverDictionary.EncryptWith.Value, |
| | 0 | 1473 | | DriverDictionary.Namespace.Value); |
| | 0 | 1474 | | result.AppendChild(doc.CreateTextNode(encryptionAlgorithm)); |
| | 0 | 1475 | | return result; |
| | | 1476 | | } |
| | | 1477 | | |
| | | 1478 | | public override XmlElement CreateEncryptionAlgorithmElement(string encryptionAlgorithm) |
| | | 1479 | | { |
| | 50 | 1480 | | if (encryptionAlgorithm == null) |
| | | 1481 | | { |
| | 0 | 1482 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(encryptionAlgorithm)); |
| | | 1483 | | } |
| | 50 | 1484 | | XmlDocument doc = new XmlDocument(); |
| | 50 | 1485 | | XmlElement result = doc.CreateElement(DriverDictionary.Prefix.Value, DriverDictionary.EncryptionAlgorith |
| | 50 | 1486 | | DriverDictionary.Namespace.Value); |
| | 50 | 1487 | | result.AppendChild(doc.CreateTextNode(encryptionAlgorithm)); |
| | 50 | 1488 | | return result; |
| | | 1489 | | } |
| | | 1490 | | |
| | | 1491 | | internal override bool IsEncryptWithElement(XmlElement element, out string encryptWithAlgorithm) |
| | | 1492 | | { |
| | 0 | 1493 | | return CheckElement(element, DriverDictionary.EncryptWith.Value, DriverDictionary.Namespace.Value, out e |
| | | 1494 | | } |
| | | 1495 | | |
| | | 1496 | | internal override bool IsEncryptionAlgorithmElement(XmlElement element, out string encryptionAlgorithm) |
| | | 1497 | | { |
| | 0 | 1498 | | return CheckElement(element, DriverDictionary.EncryptionAlgorithm.Value, DriverDictionary.Namespace.Valu |
| | | 1499 | | } |
| | | 1500 | | |
| | | 1501 | | public override XmlElement CreateComputedKeyAlgorithmElement(string algorithm) |
| | | 1502 | | { |
| | 0 | 1503 | | if (algorithm == null) |
| | | 1504 | | { |
| | 0 | 1505 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(algorithm)); |
| | | 1506 | | } |
| | 0 | 1507 | | XmlDocument doc = new XmlDocument(); |
| | 0 | 1508 | | XmlElement result = doc.CreateElement(DriverDictionary.Prefix.Value, DriverDictionary.ComputedKeyAlgorit |
| | 0 | 1509 | | DriverDictionary.Namespace.Value); |
| | 0 | 1510 | | result.AppendChild(doc.CreateTextNode(algorithm)); |
| | 0 | 1511 | | return result; |
| | | 1512 | | } |
| | | 1513 | | |
| | | 1514 | | public override XmlElement CreateCanonicalizationAlgorithmElement(string algorithm) |
| | | 1515 | | { |
| | 50 | 1516 | | if (algorithm == null) |
| | | 1517 | | { |
| | 0 | 1518 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(algorithm)); |
| | | 1519 | | } |
| | 50 | 1520 | | XmlDocument doc = new XmlDocument(); |
| | 50 | 1521 | | XmlElement result = doc.CreateElement(DriverDictionary.Prefix.Value, DriverDictionary.CanonicalizationAl |
| | 50 | 1522 | | DriverDictionary.Namespace.Value); |
| | 50 | 1523 | | result.AppendChild(doc.CreateTextNode(algorithm)); |
| | 50 | 1524 | | return result; |
| | | 1525 | | } |
| | | 1526 | | |
| | | 1527 | | internal override bool IsCanonicalizationAlgorithmElement(XmlElement element, out string canonicalizationAlg |
| | | 1528 | | { |
| | 0 | 1529 | | return CheckElement(element, DriverDictionary.CanonicalizationAlgorithm.Value, DriverDictionary.Namespac |
| | | 1530 | | } |
| | | 1531 | | |
| | | 1532 | | public override bool TryParseRequiredClaimsElement(XmlElement element, out System.Collections.ObjectModel.Co |
| | | 1533 | | { |
| | 0 | 1534 | | if (element == null) |
| | | 1535 | | { |
| | 0 | 1536 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(element)); |
| | | 1537 | | } |
| | | 1538 | | |
| | 0 | 1539 | | if (element.LocalName == DriverDictionary.Claims.Value |
| | 0 | 1540 | | && element.NamespaceURI == DriverDictionary.Namespace.Value) |
| | | 1541 | | { |
| | 0 | 1542 | | requiredClaims = new System.Collections.ObjectModel.Collection<XmlElement>(); |
| | 0 | 1543 | | foreach (XmlNode node in element.ChildNodes) |
| | | 1544 | | { |
| | 0 | 1545 | | if (node is XmlElement) |
| | | 1546 | | { |
| | 0 | 1547 | | requiredClaims.Add((XmlElement)node); |
| | | 1548 | | } |
| | | 1549 | | } |
| | | 1550 | | |
| | 0 | 1551 | | return true; |
| | | 1552 | | } |
| | | 1553 | | |
| | 0 | 1554 | | requiredClaims = null; |
| | 0 | 1555 | | return false; |
| | | 1556 | | } |
| | | 1557 | | |
| | | 1558 | | public override XmlElement CreateRequiredClaimsElement(IEnumerable<XmlElement> claimsList) |
| | | 1559 | | { |
| | 0 | 1560 | | if (claimsList == null) |
| | | 1561 | | { |
| | 0 | 1562 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(claimsList)); |
| | | 1563 | | } |
| | 0 | 1564 | | XmlDocument doc = new XmlDocument(); |
| | 0 | 1565 | | XmlElement result = doc.CreateElement(DriverDictionary.Prefix.Value, DriverDictionary.Claims.Value, |
| | 0 | 1566 | | DriverDictionary.Namespace.Value); |
| | 0 | 1567 | | foreach (XmlElement claimElement in claimsList) |
| | | 1568 | | { |
| | 0 | 1569 | | XmlElement element = (XmlElement)doc.ImportNode(claimElement, true); |
| | 0 | 1570 | | result.AppendChild(element); |
| | | 1571 | | } |
| | 0 | 1572 | | return result; |
| | | 1573 | | } |
| | | 1574 | | |
| | | 1575 | | internal static void ValidateRequestedKeySize(int keySize, SecurityAlgorithmSuite algorithmSuite) |
| | | 1576 | | { |
| | 10 | 1577 | | if ((keySize % 8 == 0) && algorithmSuite.IsSymmetricKeyLengthSupported(keySize)) |
| | | 1578 | | { |
| | 10 | 1579 | | return; |
| | | 1580 | | } |
| | | 1581 | | else |
| | | 1582 | | { |
| | 0 | 1583 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new SecurityNegotiationException(SR.Form |
| | | 1584 | | } |
| | | 1585 | | } |
| | | 1586 | | |
| | | 1587 | | private static void ValidateRequestorEntropy(SecurityToken entropy, SecurityKeyEntropyMode mode) |
| | | 1588 | | { |
| | 10 | 1589 | | if ((mode == SecurityKeyEntropyMode.ClientEntropy || mode == SecurityKeyEntropyMode.CombinedEntropy) |
| | 10 | 1590 | | && (entropy == null)) |
| | | 1591 | | { |
| | 0 | 1592 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR.Format( |
| | | 1593 | | } |
| | 10 | 1594 | | if (mode == SecurityKeyEntropyMode.ServerEntropy && entropy != null) |
| | | 1595 | | { |
| | 0 | 1596 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR.Format( |
| | | 1597 | | } |
| | 10 | 1598 | | } |
| | | 1599 | | |
| | | 1600 | | internal static void ProcessRstAndIssueKey(RequestSecurityToken requestSecurityToken, SecurityTokenResolver |
| | | 1601 | | out SecurityToken proofToken) |
| | | 1602 | | { |
| | 10 | 1603 | | SecurityToken requestorEntropyToken = requestSecurityToken.GetRequestorEntropy(resolver); |
| | 10 | 1604 | | ValidateRequestorEntropy(requestorEntropyToken, keyEntropyMode); |
| | | 1605 | | byte[] requestorEntropy; |
| | 10 | 1606 | | if (requestorEntropyToken != null) |
| | | 1607 | | { |
| | 10 | 1608 | | if (requestorEntropyToken is BinarySecretSecurityToken skToken) |
| | | 1609 | | { |
| | 10 | 1610 | | requestorEntropy = skToken.GetKeyBytes(); |
| | | 1611 | | } |
| | 0 | 1612 | | else if (requestorEntropyToken is WrappedKeySecurityToken) |
| | | 1613 | | { |
| | 0 | 1614 | | requestorEntropy = ((WrappedKeySecurityToken)requestorEntropyToken).GetWrappedKey(); |
| | | 1615 | | } |
| | | 1616 | | else |
| | | 1617 | | { |
| | 0 | 1618 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR.For |
| | | 1619 | | } |
| | | 1620 | | } |
| | | 1621 | | else |
| | | 1622 | | { |
| | 0 | 1623 | | requestorEntropy = null; |
| | | 1624 | | } |
| | | 1625 | | |
| | 10 | 1626 | | if (keyEntropyMode == SecurityKeyEntropyMode.ClientEntropy) |
| | | 1627 | | { |
| | 0 | 1628 | | if (requestorEntropy != null) |
| | | 1629 | | { |
| | | 1630 | | // validate that the entropy length matches the algorithm suite |
| | 0 | 1631 | | ValidateRequestedKeySize(requestorEntropy.Length * 8, algorithmSuite); |
| | | 1632 | | } |
| | 0 | 1633 | | proofKey = requestorEntropy; |
| | 0 | 1634 | | issuerEntropy = null; |
| | 0 | 1635 | | issuedKeySize = 0; |
| | 0 | 1636 | | proofToken = null; |
| | | 1637 | | } |
| | | 1638 | | else |
| | | 1639 | | { |
| | 10 | 1640 | | if (requestSecurityToken.KeySize != 0) |
| | | 1641 | | { |
| | 10 | 1642 | | ValidateRequestedKeySize(requestSecurityToken.KeySize, algorithmSuite); |
| | 10 | 1643 | | issuedKeySize = requestSecurityToken.KeySize; |
| | | 1644 | | } |
| | | 1645 | | else |
| | | 1646 | | { |
| | 0 | 1647 | | issuedKeySize = algorithmSuite.DefaultSymmetricKeyLength; |
| | | 1648 | | } |
| | 10 | 1649 | | RNGCryptoServiceProvider random = new RNGCryptoServiceProvider(); |
| | 10 | 1650 | | if (keyEntropyMode == SecurityKeyEntropyMode.ServerEntropy) |
| | | 1651 | | { |
| | 0 | 1652 | | proofKey = new byte[issuedKeySize / 8]; |
| | | 1653 | | // proof key is completely issued by the server |
| | 0 | 1654 | | random.GetNonZeroBytes(proofKey); |
| | 0 | 1655 | | issuerEntropy = null; |
| | 0 | 1656 | | proofToken = new BinarySecretSecurityToken(proofKey); |
| | | 1657 | | } |
| | | 1658 | | else |
| | | 1659 | | { |
| | 10 | 1660 | | issuerEntropy = new byte[issuedKeySize / 8]; |
| | 10 | 1661 | | random.GetNonZeroBytes(issuerEntropy); |
| | 10 | 1662 | | proofKey = RequestSecurityTokenResponse.ComputeCombinedKey(requestorEntropy, issuerEntropy, issu |
| | 10 | 1663 | | proofToken = null; |
| | | 1664 | | } |
| | | 1665 | | } |
| | 10 | 1666 | | } |
| | | 1667 | | } |
| | | 1668 | | |
| | | 1669 | | protected static bool CheckElement(XmlElement element, string name, string ns, out string value) |
| | | 1670 | | { |
| | 0 | 1671 | | value = null; |
| | 0 | 1672 | | if (element.LocalName != name || element.NamespaceURI != ns) |
| | | 1673 | | { |
| | 0 | 1674 | | return false; |
| | | 1675 | | } |
| | | 1676 | | |
| | 0 | 1677 | | if (element.FirstChild is XmlText) |
| | | 1678 | | { |
| | 0 | 1679 | | value = ((XmlText)element.FirstChild).Value; |
| | 0 | 1680 | | return true; |
| | | 1681 | | } |
| | 0 | 1682 | | return false; |
| | | 1683 | | } |
| | | 1684 | | } |
| | | 1685 | | } |