| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- //------------------------------------------------------------
- // 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);
- }
- }
- }
|