1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.ServiceModel.Security
{
using System.IO;
using System.ServiceModel.Channels;
using System.ServiceModel;
using System.IdentityModel.Tokens;
using System.IdentityModel.Selectors;
using System.Security.Cryptography;
using System.Xml;
using DictionaryManager = System.IdentityModel.DictionaryManager;
using ISecurityElement = System.IdentityModel.ISecurityElement;
sealed class EncryptedHeaderXml
{
internal static readonly XmlDictionaryString ElementName = XD.SecurityXXX2005Dictionary.EncryptedHeader;
internal static readonly XmlDictionaryString NamespaceUri = XD.SecurityXXX2005Dictionary.Namespace;
const string Prefix = SecurityXXX2005Strings.Prefix;
string id;
bool mustUnderstand;
bool relay;
string actor;
MessageVersion version;
EncryptedData encryptedData;
public EncryptedHeaderXml(MessageVersion version, bool shouldReadXmlReferenceKeyInfoClause)
{
this.version = version;
encryptedData = new EncryptedData();
// This is for the case when the service send an EncryptedHeader to the client where the KeyInfo clause contains referenceXml clause.
encryptedData.ShouldReadXmlReferenceKeyInfoClause = shouldReadXmlReferenceKeyInfoClause;
}
public string Actor
{
get
{
return this.actor;
}
set
{
this.actor = value;
}
}
public string EncryptionMethod
{
get
{
return encryptedData.EncryptionMethod;
}
set
{
encryptedData.EncryptionMethod = value;
}
}
public XmlDictionaryString EncryptionMethodDictionaryString
{
get
{
return encryptedData.EncryptionMethodDictionaryString;
}
set
{
encryptedData.EncryptionMethodDictionaryString = value;
}
}
public bool HasId
{
get
{
return true;
}
}
public string Id
{
get
{
return id;
}
set
{
id = value;
}
}
public SecurityKeyIdentifier KeyIdentifier
{
get
{
return encryptedData.KeyIdentifier;
}
set
{
encryptedData.KeyIdentifier = value;
}
}
public bool MustUnderstand
{
get
{
return this.mustUnderstand;
}
set
{
this.mustUnderstand = value;
}
}
public bool Relay
{
get
{
return this.relay;
}
set
{
this.relay = value;
}
}
public SecurityTokenSerializer SecurityTokenSerializer
{
get
{
return encryptedData.SecurityTokenSerializer;
}
set
{
encryptedData.SecurityTokenSerializer = value;
}
}
public byte[] GetDecryptedBuffer()
{
return encryptedData.GetDecryptedBuffer();
}
public void ReadFrom(XmlDictionaryReader reader, long maxBufferSize)
{
reader.MoveToStartElement(ElementName, NamespaceUri);
bool isReferenceParameter;
MessageHeader.GetHeaderAttributes(reader, version, out this.actor, out this.mustUnderstand, out this.relay, out isReferenceParameter);
this.id = reader.GetAttribute(XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace);
reader.ReadStartElement();
encryptedData.ReadFrom(reader, maxBufferSize);
reader.ReadEndElement();
}
public void SetUpDecryption(SymmetricAlgorithm algorithm)
{
encryptedData.SetUpDecryption(algorithm);
}
public void SetUpEncryption(SymmetricAlgorithm algorithm, MemoryStream source)
{
encryptedData.SetUpEncryption(algorithm, new ArraySegment<byte>(source.GetBuffer(), 0, (int) source.Length));
}
public void WriteHeaderElement(XmlDictionaryWriter writer)
{
writer.WriteStartElement(Prefix, ElementName, NamespaceUri);
}
public void WriteHeaderId(XmlDictionaryWriter writer)
{
writer.WriteAttributeString(XD.UtilityDictionary.Prefix.Value, XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace, id);
}
public void WriteHeaderContents(XmlDictionaryWriter writer)
{
this.encryptedData.WriteTo(writer, ServiceModelDictionaryManager.Instance);
}
}
}
|