Exemplo n.º 1
0
        public void WriteBodyToSignThenEncryptWithFragments(Stream stream, bool includeComments, string[] inclusivePrefixes, EncryptedData encryptedData, SymmetricAlgorithm algorithm, XmlDictionaryWriter writer)
        {
            int num;
            IFragmentCapableXmlDictionaryWriter writer2 = (IFragmentCapableXmlDictionaryWriter)writer;

            this.SetBodyId();
            encryptedData.Id       = this.securityHeader.GenerateId();
            this.startBodyFragment = new MemoryStream();
            BufferedOutputStream stream2 = new BufferManagerOutputStream("XmlBufferQuotaExceeded", 0x400, 0x7fffffff, BufferManager.CreateBufferManager(0L, 0x7fffffff));

            this.endBodyFragment = new MemoryStream();
            writer.StartCanonicalization(stream, includeComments, inclusivePrefixes);
            writer2.StartFragment(this.startBodyFragment, false);
            this.WriteStartInnerMessageWithId(writer);
            writer2.EndFragment();
            writer2.StartFragment(stream2, true);
            base.InnerMessage.WriteBodyContents(writer);
            writer2.EndFragment();
            writer2.StartFragment(this.endBodyFragment, false);
            writer.WriteEndElement();
            writer2.EndFragment();
            writer.EndCanonicalization();
            byte[] array = stream2.ToArray(out num);
            encryptedData.SetUpEncryption(algorithm, new ArraySegment <byte>(array, 0, num));
            this.encryptedBodyContent = encryptedData;
            this.state = BodyState.SignedThenEncrypted;
        }
Exemplo n.º 2
0
        public void WriteBodyToEncryptThenSign(Stream canonicalStream, EncryptedData encryptedData, SymmetricAlgorithm algorithm)
        {
            encryptedData.Id = this.securityHeader.GenerateId();
            this.SetBodyId();
            XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(Stream.Null);

            writer.WriteStartElement("a");
            MemoryStream stream = new MemoryStream();

            ((IFragmentCapableXmlDictionaryWriter)writer).StartFragment(stream, true);
            base.InnerMessage.WriteBodyContents(writer);
            ((IFragmentCapableXmlDictionaryWriter)writer).EndFragment();
            writer.WriteEndElement();
            stream.Flush();
            encryptedData.SetUpEncryption(algorithm, new ArraySegment <byte>(stream.GetBuffer(), 0, (int)stream.Length));
            this.fullBodyBuffer = new XmlBuffer(0x7fffffff);
            XmlDictionaryWriter writer2 = this.fullBodyBuffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            writer2.StartCanonicalization(canonicalStream, false, null);
            this.WriteStartInnerMessageWithId(writer2);
            encryptedData.WriteTo(writer2, ServiceModelDictionaryManager.Instance);
            writer2.WriteEndElement();
            writer2.EndCanonicalization();
            writer2.Flush();
            this.fullBodyBuffer.CloseSection();
            this.fullBodyBuffer.Close();
            this.state = BodyState.EncryptedThenSigned;
        }
Exemplo n.º 3
0
        public void WriteBodyToEncrypt(EncryptedData encryptedData, SymmetricAlgorithm algorithm)
        {
            encryptedData.Id = this.securityHeader.GenerateId();
            BodyContentHelper   helper = new BodyContentHelper();
            XmlDictionaryWriter writer = helper.CreateWriter();

            base.InnerMessage.WriteBodyContents(writer);
            encryptedData.SetUpEncryption(algorithm, helper.ExtractResult());
            this.encryptedBodyContent = encryptedData;
            this.state = BodyState.Encrypted;
        }
        private EncryptedData CreateEncryptedData(MemoryStream stream, string id, bool typeElement)
        {
            EncryptedData data = this.CreateEncryptedData();

            data.Id = id;
            data.SetUpEncryption(this.encryptingSymmetricAlgorithm, new ArraySegment <byte>(stream.GetBuffer(), 0, (int)stream.Length));
            if (typeElement)
            {
                data.Type = EncryptedData.ElementType;
            }
            return(data);
        }
        public void WriteBodyToSignThenEncryptWithFragments(
            Stream stream, bool includeComments, string[] inclusivePrefixes,
            EncryptedData encryptedData, SymmetricAlgorithm algorithm, XmlDictionaryWriter writer)
        {
            IFragmentCapableXmlDictionaryWriter fragmentingWriter = (IFragmentCapableXmlDictionaryWriter)writer;

            SetBodyId();
            encryptedData.Id = this.securityHeader.GenerateId();

            this.startBodyFragment = new MemoryStream();
            BufferedOutputStream bodyContentFragment = new BufferManagerOutputStream(SR.XmlBufferQuotaExceeded, 1024, int.MaxValue, this.securityHeader.StreamBufferManager);

            this.endBodyFragment = new MemoryStream();

            writer.StartCanonicalization(stream, includeComments, inclusivePrefixes);

            fragmentingWriter.StartFragment(this.startBodyFragment, false);
            WriteStartInnerMessageWithId(writer);
            fragmentingWriter.EndFragment();

            fragmentingWriter.StartFragment(bodyContentFragment, true);
            this.InnerMessage.WriteBodyContents(writer);
            fragmentingWriter.EndFragment();

            fragmentingWriter.StartFragment(this.endBodyFragment, false);
            writer.WriteEndElement();
            fragmentingWriter.EndFragment();

            writer.EndCanonicalization();

            int bodyLength;

            byte[] bodyBuffer = bodyContentFragment.ToArray(out bodyLength);

            encryptedData.SetUpEncryption(algorithm, new ArraySegment <byte>(bodyBuffer, 0, bodyLength));
            this.encryptedBodyContent = encryptedData;

            this.state = BodyState.SignedThenEncrypted;
        }
        public void WriteBodyToEncryptThenSign(Stream canonicalStream, EncryptedData encryptedData, SymmetricAlgorithm algorithm)
        {
            encryptedData.Id = this.securityHeader.GenerateId();
            SetBodyId();

            XmlDictionaryWriter encryptingWriter = XmlDictionaryWriter.CreateTextWriter(Stream.Null);

            // The XmlSerializer body formatter would add a
            // document declaration to the body fragment when a fresh writer
            // is provided. Hence, insert a dummy element here and capture
            // the body contents as a fragment.
            encryptingWriter.WriteStartElement("a");
            MemoryStream ms = new MemoryStream();

            ((IFragmentCapableXmlDictionaryWriter)encryptingWriter).StartFragment(ms, true);

            this.InnerMessage.WriteBodyContents(encryptingWriter);
            ((IFragmentCapableXmlDictionaryWriter)encryptingWriter).EndFragment();
            encryptingWriter.WriteEndElement();
            ms.Flush();
            encryptedData.SetUpEncryption(algorithm, new ArraySegment <byte>(ms.GetBuffer(), 0, (int)ms.Length));

            this.fullBodyBuffer = new XmlBuffer(int.MaxValue);
            XmlDictionaryWriter canonicalWriter = this.fullBodyBuffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            canonicalWriter.StartCanonicalization(canonicalStream, false, null);
            WriteStartInnerMessageWithId(canonicalWriter);
            encryptedData.WriteTo(canonicalWriter, ServiceModelDictionaryManager.Instance);
            canonicalWriter.WriteEndElement();
            canonicalWriter.EndCanonicalization();
            canonicalWriter.Flush();

            this.fullBodyBuffer.CloseSection();
            this.fullBodyBuffer.Close();

            this.state = BodyState.EncryptedThenSigned;
        }
        public void WriteBodyToSignThenEncryptWithFragments(
            Stream stream, bool includeComments, string[] inclusivePrefixes,
            EncryptedData encryptedData, SymmetricAlgorithm algorithm, XmlDictionaryWriter writer)
        {
            IFragmentCapableXmlDictionaryWriter fragmentingWriter = (IFragmentCapableXmlDictionaryWriter) writer;

            SetBodyId();
            encryptedData.Id = this.securityHeader.GenerateId();

            this.startBodyFragment = new MemoryStream();
            BufferedOutputStream bodyContentFragment = new BufferManagerOutputStream(SR.XmlBufferQuotaExceeded, 1024, int.MaxValue, this.securityHeader.StreamBufferManager);
            this.endBodyFragment = new MemoryStream();

            writer.StartCanonicalization(stream, includeComments, inclusivePrefixes);

            fragmentingWriter.StartFragment(this.startBodyFragment, false);
            WriteStartInnerMessageWithId(writer);
            fragmentingWriter.EndFragment();

            fragmentingWriter.StartFragment(bodyContentFragment, true);
            this.InnerMessage.WriteBodyContents(writer);
            fragmentingWriter.EndFragment();

            fragmentingWriter.StartFragment(this.endBodyFragment, false);
            writer.WriteEndElement();
            fragmentingWriter.EndFragment();

            writer.EndCanonicalization();

            int bodyLength;
            byte[] bodyBuffer = bodyContentFragment.ToArray(out bodyLength);

            encryptedData.SetUpEncryption(algorithm, new ArraySegment<byte>(bodyBuffer, 0, bodyLength));
            this.encryptedBodyContent = encryptedData;

            this.state = BodyState.SignedThenEncrypted;
        }
        public void WriteBodyToEncryptThenSign(Stream canonicalStream, EncryptedData encryptedData, SymmetricAlgorithm algorithm)
        {
            encryptedData.Id = this.securityHeader.GenerateId();
            SetBodyId();

            XmlDictionaryWriter encryptingWriter = XmlDictionaryWriter.CreateTextWriter(Stream.Null);
            // The XmlSerializer body formatter would add a
            // document declaration to the body fragment when a fresh writer 
            // is provided. Hence, insert a dummy element here and capture 
            // the body contents as a fragment.
            encryptingWriter.WriteStartElement("a");
            MemoryStream ms = new MemoryStream();
            ((IFragmentCapableXmlDictionaryWriter)encryptingWriter).StartFragment(ms, true);

            this.InnerMessage.WriteBodyContents(encryptingWriter);
            ((IFragmentCapableXmlDictionaryWriter)encryptingWriter).EndFragment();
            encryptingWriter.WriteEndElement();
            ms.Flush();
            encryptedData.SetUpEncryption(algorithm, new ArraySegment<byte>(ms.GetBuffer(), 0, (int) ms.Length));

            this.fullBodyBuffer = new XmlBuffer(int.MaxValue);
            XmlDictionaryWriter canonicalWriter = this.fullBodyBuffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            canonicalWriter.StartCanonicalization(canonicalStream, false, null);
            WriteStartInnerMessageWithId(canonicalWriter);
            encryptedData.WriteTo(canonicalWriter, ServiceModelDictionaryManager.Instance);
            canonicalWriter.WriteEndElement();
            canonicalWriter.EndCanonicalization();
            canonicalWriter.Flush();

            this.fullBodyBuffer.CloseSection();
            this.fullBodyBuffer.Close();

            this.state = BodyState.EncryptedThenSigned;
        }
        public void WriteBodyToEncrypt(EncryptedData encryptedData, SymmetricAlgorithm algorithm)
        {
            encryptedData.Id = this.securityHeader.GenerateId();

            BodyContentHelper helper = new BodyContentHelper();
            XmlDictionaryWriter encryptingWriter = helper.CreateWriter();
            this.InnerMessage.WriteBodyContents(encryptingWriter);
            encryptedData.SetUpEncryption(algorithm, helper.ExtractResult());
            this.encryptedBodyContent = encryptedData;

            this.state = BodyState.Encrypted;
        }
 public void WriteBodyToSignThenEncryptWithFragments(Stream stream, bool includeComments, string[] inclusivePrefixes, EncryptedData encryptedData, SymmetricAlgorithm algorithm, XmlDictionaryWriter writer)
 {
     int num;
     IFragmentCapableXmlDictionaryWriter writer2 = (IFragmentCapableXmlDictionaryWriter) writer;
     this.SetBodyId();
     encryptedData.Id = this.securityHeader.GenerateId();
     this.startBodyFragment = new MemoryStream();
     BufferedOutputStream stream2 = new BufferManagerOutputStream("XmlBufferQuotaExceeded", 0x400, 0x7fffffff, BufferManager.CreateBufferManager(0L, 0x7fffffff));
     this.endBodyFragment = new MemoryStream();
     writer.StartCanonicalization(stream, includeComments, inclusivePrefixes);
     writer2.StartFragment(this.startBodyFragment, false);
     this.WriteStartInnerMessageWithId(writer);
     writer2.EndFragment();
     writer2.StartFragment(stream2, true);
     base.InnerMessage.WriteBodyContents(writer);
     writer2.EndFragment();
     writer2.StartFragment(this.endBodyFragment, false);
     writer.WriteEndElement();
     writer2.EndFragment();
     writer.EndCanonicalization();
     byte[] array = stream2.ToArray(out num);
     encryptedData.SetUpEncryption(algorithm, new ArraySegment<byte>(array, 0, num));
     this.encryptedBodyContent = encryptedData;
     this.state = BodyState.SignedThenEncrypted;
 }
 public void WriteBodyToEncryptThenSign(Stream canonicalStream, EncryptedData encryptedData, SymmetricAlgorithm algorithm)
 {
     encryptedData.Id = this.securityHeader.GenerateId();
     this.SetBodyId();
     XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(Stream.Null);
     writer.WriteStartElement("a");
     MemoryStream stream = new MemoryStream();
     ((IFragmentCapableXmlDictionaryWriter) writer).StartFragment(stream, true);
     base.InnerMessage.WriteBodyContents(writer);
     ((IFragmentCapableXmlDictionaryWriter) writer).EndFragment();
     writer.WriteEndElement();
     stream.Flush();
     encryptedData.SetUpEncryption(algorithm, new ArraySegment<byte>(stream.GetBuffer(), 0, (int) stream.Length));
     this.fullBodyBuffer = new XmlBuffer(0x7fffffff);
     XmlDictionaryWriter writer2 = this.fullBodyBuffer.OpenSection(XmlDictionaryReaderQuotas.Max);
     writer2.StartCanonicalization(canonicalStream, false, null);
     this.WriteStartInnerMessageWithId(writer2);
     encryptedData.WriteTo(writer2, ServiceModelDictionaryManager.Instance);
     writer2.WriteEndElement();
     writer2.EndCanonicalization();
     writer2.Flush();
     this.fullBodyBuffer.CloseSection();
     this.fullBodyBuffer.Close();
     this.state = BodyState.EncryptedThenSigned;
 }
Exemplo n.º 12
0
 public void SetUpEncryption(SymmetricAlgorithm algorithm, MemoryStream source)
 {
     encryptedData.SetUpEncryption(algorithm, new ArraySegment <byte>(source.GetBuffer(), 0, (int)source.Length));
 }