| | | 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.Xml; |
| | | 7 | | using CoreWCF.Security.Tokens; |
| | | 8 | | using TokenEntry = CoreWCF.Security.WSSecurityTokenSerializer.TokenEntry; |
| | | 9 | | |
| | | 10 | | namespace CoreWCF.Security |
| | | 11 | | { |
| | | 12 | | internal class WSSecureConversationFeb2005 : WSSecureConversation |
| | | 13 | | { |
| | | 14 | | private readonly SecurityStateEncoder _securityStateEncoder; |
| | | 15 | | private readonly IList<Type> _knownClaimTypes; |
| | | 16 | | |
| | | 17 | | public WSSecureConversationFeb2005(WSSecurityTokenSerializer tokenSerializer, SecurityStateEncoder securityState |
| | | 18 | | int maxKeyDerivationOffset, int maxKeyDerivationLabelLength, int maxKeyDerivationNonceLength) |
| | 65 | 19 | | : base(tokenSerializer, maxKeyDerivationOffset, maxKeyDerivationLabelLength, maxKeyDerivationNonceLength) |
| | | 20 | | { |
| | 65 | 21 | | if (securityStateEncoder != null) |
| | | 22 | | { |
| | 61 | 23 | | _securityStateEncoder = securityStateEncoder; |
| | | 24 | | } |
| | | 25 | | else |
| | | 26 | | { |
| | 4 | 27 | | _securityStateEncoder = new DataProtectionSecurityStateEncoder(); |
| | | 28 | | } |
| | | 29 | | |
| | 65 | 30 | | _knownClaimTypes = new List<Type>(); |
| | 65 | 31 | | if (knownTypes != null) |
| | | 32 | | { |
| | | 33 | | // Clone this collection. |
| | 122 | 34 | | foreach (Type knownType in knownTypes) |
| | | 35 | | { |
| | 0 | 36 | | _knownClaimTypes.Add(knownType); |
| | | 37 | | } |
| | | 38 | | } |
| | 65 | 39 | | } |
| | | 40 | | |
| | 144 | 41 | | public override SecureConversationDictionary SerializerDictionary => XD.SecureConversationFeb2005Dictionary; |
| | | 42 | | |
| | | 43 | | public override void PopulateTokenEntries(IList<TokenEntry> tokenEntryList) |
| | | 44 | | { |
| | 65 | 45 | | base.PopulateTokenEntries(tokenEntryList); |
| | 65 | 46 | | tokenEntryList.Add(new SecurityContextTokenEntryFeb2005(this, _securityStateEncoder, _knownClaimTypes)); |
| | 65 | 47 | | } |
| | | 48 | | |
| | | 49 | | private class SecurityContextTokenEntryFeb2005 : SecurityContextTokenEntry |
| | | 50 | | { |
| | | 51 | | public SecurityContextTokenEntryFeb2005(WSSecureConversationFeb2005 parent, SecurityStateEncoder securitySta |
| | 65 | 52 | | : base(parent, securityStateEncoder, knownClaimTypes) |
| | | 53 | | { |
| | 65 | 54 | | } |
| | | 55 | | |
| | | 56 | | protected override bool CanReadGeneration(XmlDictionaryReader reader) |
| | | 57 | | { |
| | 12 | 58 | | return reader.IsStartElement(DXD.SecureConversationDec2005Dictionary.Instance, XD.SecureConversationFeb2 |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | protected override bool CanReadGeneration(XmlElement element) |
| | | 62 | | { |
| | 0 | 63 | | return (element.LocalName == DXD.SecureConversationDec2005Dictionary.Instance.Value && |
| | 0 | 64 | | element.NamespaceURI == XD.SecureConversationFeb2005Dictionary.Namespace.Value); |
| | | 65 | | } |
| | | 66 | | |
| | | 67 | | protected override UniqueId ReadGeneration(XmlDictionaryReader reader) |
| | | 68 | | { |
| | 0 | 69 | | return reader.ReadElementContentAsUniqueId(); |
| | | 70 | | } |
| | | 71 | | |
| | | 72 | | protected override UniqueId ReadGeneration(XmlElement element) |
| | | 73 | | { |
| | 0 | 74 | | return XmlHelper.ReadTextElementAsUniqueId(element); |
| | | 75 | | } |
| | | 76 | | |
| | | 77 | | protected override void WriteGeneration(XmlDictionaryWriter writer, SecurityContextSecurityToken sct) |
| | | 78 | | { |
| | | 79 | | // serialize the generation |
| | 6 | 80 | | if (sct.KeyGeneration != null) |
| | | 81 | | { |
| | 0 | 82 | | writer.WriteStartElement(XD.SecureConversationFeb2005Dictionary.Prefix.Value, DXD.SecureConversation |
| | 0 | 83 | | XD.SecureConversationFeb2005Dictionary.Namespace); |
| | 0 | 84 | | XmlHelper.WriteStringAsUniqueId(writer, sct.KeyGeneration); |
| | 0 | 85 | | writer.WriteEndElement(); |
| | | 86 | | } |
| | 6 | 87 | | } |
| | | 88 | | } |
| | | 89 | | |
| | | 90 | | public class DriverFeb2005 : Driver |
| | | 91 | | { |
| | 64 | 92 | | public DriverFeb2005() |
| | | 93 | | { |
| | 64 | 94 | | } |
| | | 95 | | |
| | 125 | 96 | | protected override SecureConversationDictionary DriverDictionary => XD.SecureConversationFeb2005Dictionary; |
| | | 97 | | |
| | 41 | 98 | | public override XmlDictionaryString CloseAction => XD.SecureConversationFeb2005Dictionary.RequestSecurityCon |
| | | 99 | | |
| | 12 | 100 | | public override XmlDictionaryString CloseResponseAction => XD.SecureConversationFeb2005Dictionary.RequestSec |
| | | 101 | | |
| | 17 | 102 | | public override bool IsSessionSupported => true; |
| | | 103 | | |
| | 40 | 104 | | public override XmlDictionaryString RenewAction => XD.SecureConversationFeb2005Dictionary.RequestSecurityCon |
| | | 105 | | |
| | 6 | 106 | | public override XmlDictionaryString RenewResponseAction => XD.SecureConversationFeb2005Dictionary.RequestSec |
| | | 107 | | |
| | 0 | 108 | | public override XmlDictionaryString Namespace => XD.SecureConversationFeb2005Dictionary.Namespace; |
| | | 109 | | |
| | 18 | 110 | | public override string TokenTypeUri => XD.SecureConversationFeb2005Dictionary.SecurityContextTokenType.Value |
| | | 111 | | } |
| | | 112 | | } |
| | | 113 | | } |