| | | 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.IdentityModel.Tokens; |
| | | 8 | | using CoreWCF.Security.Tokens; |
| | | 9 | | using TokenEntry = CoreWCF.Security.WSSecurityTokenSerializer.TokenEntry; |
| | | 10 | | |
| | | 11 | | namespace CoreWCF.Security |
| | | 12 | | { |
| | | 13 | | internal class WSSecureConversationDec2005 : WSSecureConversation |
| | | 14 | | { |
| | | 15 | | private readonly SecurityStateEncoder _securityStateEncoder; |
| | | 16 | | private readonly IList<Type> _knownClaimTypes; |
| | | 17 | | |
| | | 18 | | public WSSecureConversationDec2005(WSSecurityTokenSerializer tokenSerializer, SecurityStateEncoder securityState |
| | | 19 | | int maxKeyDerivationOffset, int maxKeyDerivationLabelLength, int maxKeyDerivationNonceLength) |
| | 67 | 20 | | : base(tokenSerializer, maxKeyDerivationOffset, maxKeyDerivationLabelLength, maxKeyDerivationNonceLength) |
| | | 21 | | { |
| | 67 | 22 | | if (securityStateEncoder != null) |
| | | 23 | | { |
| | 17 | 24 | | _securityStateEncoder = securityStateEncoder; |
| | | 25 | | } |
| | | 26 | | else |
| | | 27 | | { |
| | 50 | 28 | | _securityStateEncoder = new DataProtectionSecurityStateEncoder(); |
| | | 29 | | } |
| | | 30 | | |
| | 67 | 31 | | _knownClaimTypes = new List<Type>(); |
| | 67 | 32 | | if (knownTypes != null) |
| | | 33 | | { |
| | | 34 | | // Clone this collection. |
| | 34 | 35 | | foreach (Type knownType in knownTypes) |
| | | 36 | | { |
| | 0 | 37 | | _knownClaimTypes.Add(knownType); |
| | | 38 | | } |
| | | 39 | | } |
| | 67 | 40 | | } |
| | | 41 | | |
| | | 42 | | public override SecureConversationDictionary SerializerDictionary |
| | | 43 | | { |
| | 96 | 44 | | get { return DXD.SecureConversationDec2005Dictionary; } |
| | | 45 | | } |
| | | 46 | | |
| | | 47 | | public override void PopulateTokenEntries(IList<TokenEntry> tokenEntryList) |
| | | 48 | | { |
| | 67 | 49 | | base.PopulateTokenEntries(tokenEntryList); |
| | 67 | 50 | | tokenEntryList.Add(new SecurityContextTokenEntryDec2005(this, _securityStateEncoder, _knownClaimTypes)); |
| | 67 | 51 | | } |
| | | 52 | | |
| | | 53 | | public override string DerivationAlgorithm |
| | | 54 | | { |
| | | 55 | | get |
| | | 56 | | { |
| | 0 | 57 | | return SecurityAlgorithms.Psha1KeyDerivationDec2005; |
| | | 58 | | } |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | private class SecurityContextTokenEntryDec2005 : SecurityContextTokenEntry |
| | | 62 | | { |
| | | 63 | | public SecurityContextTokenEntryDec2005(WSSecureConversationDec2005 parent, SecurityStateEncoder securitySta |
| | 67 | 64 | | : base(parent, securityStateEncoder, knownClaimTypes) |
| | | 65 | | { |
| | 67 | 66 | | } |
| | | 67 | | |
| | | 68 | | protected override bool CanReadGeneration(XmlDictionaryReader reader) |
| | | 69 | | { |
| | 8 | 70 | | return reader.IsStartElement(DXD.SecureConversationDec2005Dictionary.Instance, DXD.SecureConversationDec |
| | | 71 | | } |
| | | 72 | | |
| | | 73 | | protected override bool CanReadGeneration(XmlElement element) |
| | | 74 | | { |
| | 0 | 75 | | return (element.LocalName == DXD.SecureConversationDec2005Dictionary.Instance.Value && |
| | 0 | 76 | | element.NamespaceURI == DXD.SecureConversationDec2005Dictionary.Namespace.Value); |
| | | 77 | | } |
| | | 78 | | |
| | | 79 | | protected override UniqueId ReadGeneration(XmlDictionaryReader reader) |
| | | 80 | | { |
| | 0 | 81 | | return reader.ReadElementContentAsUniqueId(); |
| | | 82 | | } |
| | | 83 | | |
| | | 84 | | protected override UniqueId ReadGeneration(XmlElement element) |
| | | 85 | | { |
| | 0 | 86 | | return XmlHelper.ReadTextElementAsUniqueId(element); |
| | | 87 | | } |
| | | 88 | | |
| | | 89 | | protected override void WriteGeneration(XmlDictionaryWriter writer, SecurityContextSecurityToken sct) |
| | | 90 | | { |
| | | 91 | | // serialize the generation |
| | 4 | 92 | | if (sct.KeyGeneration != null) |
| | | 93 | | { |
| | 0 | 94 | | writer.WriteStartElement(DXD.SecureConversationDec2005Dictionary.Prefix.Value, |
| | 0 | 95 | | DXD.SecureConversationDec2005Dictionary.Instance, |
| | 0 | 96 | | DXD.SecureConversationDec2005Dictionary.Namespace); |
| | 0 | 97 | | XmlHelper.WriteStringAsUniqueId(writer, sct.KeyGeneration); |
| | 0 | 98 | | writer.WriteEndElement(); |
| | | 99 | | } |
| | 4 | 100 | | } |
| | | 101 | | } |
| | | 102 | | |
| | | 103 | | public class DriverDec2005 : Driver |
| | | 104 | | { |
| | 67 | 105 | | public DriverDec2005() |
| | | 106 | | { |
| | 67 | 107 | | } |
| | | 108 | | |
| | | 109 | | protected override SecureConversationDictionary DriverDictionary |
| | | 110 | | { |
| | 77 | 111 | | get { return DXD.SecureConversationDec2005Dictionary; } |
| | | 112 | | } |
| | | 113 | | |
| | | 114 | | public override XmlDictionaryString CloseAction |
| | | 115 | | { |
| | 23 | 116 | | get { return DXD.SecureConversationDec2005Dictionary.RequestSecurityContextClose; } |
| | | 117 | | } |
| | | 118 | | |
| | | 119 | | public override XmlDictionaryString CloseResponseAction |
| | | 120 | | { |
| | 8 | 121 | | get { return DXD.SecureConversationDec2005Dictionary.RequestSecurityContextCloseResponse; } |
| | | 122 | | } |
| | | 123 | | |
| | | 124 | | public override bool IsSessionSupported |
| | | 125 | | { |
| | 5 | 126 | | get { return true; } |
| | | 127 | | } |
| | | 128 | | |
| | | 129 | | public override XmlDictionaryString RenewAction |
| | | 130 | | { |
| | 14 | 131 | | get { return DXD.SecureConversationDec2005Dictionary.RequestSecurityContextRenew; } |
| | | 132 | | } |
| | | 133 | | |
| | | 134 | | public override XmlDictionaryString RenewResponseAction |
| | | 135 | | { |
| | 4 | 136 | | get { return DXD.SecureConversationDec2005Dictionary.RequestSecurityContextRenewResponse; } |
| | | 137 | | } |
| | | 138 | | |
| | | 139 | | public override XmlDictionaryString Namespace |
| | | 140 | | { |
| | 0 | 141 | | get { return DXD.SecureConversationDec2005Dictionary.Namespace; } |
| | | 142 | | } |
| | | 143 | | |
| | | 144 | | public override string TokenTypeUri |
| | | 145 | | { |
| | 5 | 146 | | get { return DXD.SecureConversationDec2005Dictionary.SecurityContextTokenType.Value; } |
| | | 147 | | } |
| | | 148 | | } |
| | | 149 | | } |
| | | 150 | | } |
| | | 151 | | |