private void CompleteEncryption()
        {
            ISecurityElement element = this.CompleteEncryptionCore(this.elementContainer.PrimarySignature, this.elementContainer.GetBasicSupportingTokens(), this.elementContainer.GetSignatureConfirmations(), this.elementContainer.GetEndorsingSignatures());

            if (element == null)
            {
                this.elementContainer.SourceEncryptionToken  = null;
                this.elementContainer.WrappedEncryptionToken = null;
                this.elementContainer.DerivedEncryptionToken = null;
            }
            else
            {
                if (this.skipKeyInfoForEncryption)
                {
                    WrappedKeySecurityToken encryptingToken = this.encryptingToken as WrappedKeySecurityToken;
                    encryptingToken.EnsureEncryptedKeySetUp();
                    encryptingToken.EncryptedKey.ReferenceList = (ReferenceList)element;
                }
                else
                {
                    this.elementContainer.ReferenceList = element;
                }
                this.basicTokenEncrypted = true;
            }
        }
Beispiel #2
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;
        }
Beispiel #3
0
 public bool IsSameItem(ISecurityElement item)
 {
     if (this.item != item)
     {
         return(this.item.Equals(item));
     }
     return(true);
 }
 public bool IsSameItem(ISecurityElement item)
 {
     if (this.item != item)
     {
         return this.item.Equals(item);
     }
     return true;
 }
        private void EncryptElement(SendSecurityHeaderElement element)
        {
            string           id   = base.GenerateId();
            ISecurityElement item = this.CreateEncryptedData(CaptureSecurityElement(element.Item), id, true);

            this.referenceList.AddReferredId(id);
            element.Replace(id, item);
        }
        protected static MemoryStream CaptureSecurityElement(ISecurityElement element)
        {
            MemoryStream        stream = new MemoryStream();
            XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(stream);

            element.WriteTo(writer, ServiceModelDictionaryManager.Instance);
            writer.Flush();
            stream.Seek(0L, SeekOrigin.Begin);
            return(stream);
        }
Beispiel #7
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;
        }
Beispiel #8
0
 protected override void OnClose()
 {
     try
     {
         base.InnerMessage.Close();
     }
     finally
     {
         this.fullBodyBuffer       = null;
         this.bodyAttributes       = null;
         this.encryptedBodyContent = null;
         this.state = BodyState.Disposed;
     }
 }
        protected override ISignatureValueSecurityElement CreateSupportingSignature(SecurityToken token, SecurityKeyIdentifier identifier, ISecurityElement elementToSign)
        {
            string str;
            XmlDictionaryString    str2;
            SecurityKey            key;
            SecurityAlgorithmSuite algorithmSuite = base.AlgorithmSuite;

            algorithmSuite.GetSignatureAlgorithmAndKey(token, out str, out key, out str2);
            SignedXml  xml        = new SignedXml(ServiceModelDictionaryManager.Instance, base.StandardsManager.SecurityTokenSerializer);
            SignedInfo signedInfo = xml.Signature.SignedInfo;

            signedInfo.CanonicalizationMethod = algorithmSuite.DefaultCanonicalizationAlgorithm;
            signedInfo.CanonicalizationMethodDictionaryString = algorithmSuite.DefaultCanonicalizationAlgorithmDictionaryString;
            signedInfo.SignatureMethod = str;
            signedInfo.SignatureMethodDictionaryString = str2;
            if (elementToSign.Id == null)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("ElementToSignMustHaveId")));
            }
            Reference reference = new Reference(ServiceModelDictionaryManager.Instance, "#" + elementToSign.Id, elementToSign)
            {
                DigestMethod = algorithmSuite.DefaultDigestAlgorithm,
                DigestMethodDictionaryString = algorithmSuite.DefaultDigestAlgorithmDictionaryString
            };

            reference.AddTransform(new ExclusiveCanonicalizationTransform());
            ((StandardSignedInfo)signedInfo).AddReference(reference);
            xml.ComputeSignature(key);
            if (identifier != null)
            {
                xml.Signature.KeyIdentifier = identifier;
            }
            return(xml);
        }
 protected abstract ISignatureValueSecurityElement CreateSupportingSignature(SecurityToken token, SecurityKeyIdentifier identifier, ISecurityElement primarySignature);
Beispiel #11
0
 public void Replace(string id, ISecurityElement item)
 {
     this.item = item;
     this.id   = id;
 }
 protected static MemoryStream CaptureSecurityElement(ISecurityElement element)
 {
     MemoryStream stream = new MemoryStream();
     XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(stream);
     element.WriteTo(writer, ServiceModelDictionaryManager.Instance);
     writer.Flush();
     stream.Seek(0L, SeekOrigin.Begin);
     return stream;
 }
 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 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;
 }
 public void Replace(string id, ISecurityElement item)
 {
     this.item = item;
     this.id = id;
 }
 public SendSecurityHeaderElement(string id, ISecurityElement item)
 {
     this.id = id;
     this.item = item;
     this.markedForEncryption = false;
 }
Beispiel #17
0
 protected abstract ISignatureValueSecurityElement CreateSupportingSignature(SecurityToken token, SecurityKeyIdentifier identifier, ISecurityElement primarySignature);
 protected override void OnClose()
 {
     try
     {
         base.InnerMessage.Close();
     }
     finally
     {
         this.fullBodyBuffer = null;
         this.bodyAttributes = null;
         this.encryptedBodyContent = null;
         this.state = BodyState.Disposed;
     }
 }
 protected override ISignatureValueSecurityElement CreateSupportingSignature(SecurityToken token, SecurityKeyIdentifier identifier, ISecurityElement elementToSign)
 {
     string str;
     XmlDictionaryString str2;
     SecurityKey key;
     SecurityAlgorithmSuite algorithmSuite = base.AlgorithmSuite;
     algorithmSuite.GetSignatureAlgorithmAndKey(token, out str, out key, out str2);
     SignedXml xml = new SignedXml(ServiceModelDictionaryManager.Instance, base.StandardsManager.SecurityTokenSerializer);
     SignedInfo signedInfo = xml.Signature.SignedInfo;
     signedInfo.CanonicalizationMethod = algorithmSuite.DefaultCanonicalizationAlgorithm;
     signedInfo.CanonicalizationMethodDictionaryString = algorithmSuite.DefaultCanonicalizationAlgorithmDictionaryString;
     signedInfo.SignatureMethod = str;
     signedInfo.SignatureMethodDictionaryString = str2;
     if (elementToSign.Id == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("ElementToSignMustHaveId")));
     }
     Reference reference = new Reference(ServiceModelDictionaryManager.Instance, "#" + elementToSign.Id, elementToSign) {
         DigestMethod = algorithmSuite.DefaultDigestAlgorithm,
         DigestMethodDictionaryString = algorithmSuite.DefaultDigestAlgorithmDictionaryString
     };
     reference.AddTransform(new ExclusiveCanonicalizationTransform());
     ((StandardSignedInfo) signedInfo).AddReference(reference);
     xml.ComputeSignature(key);
     if (identifier != null)
     {
         xml.Signature.KeyIdentifier = identifier;
     }
     return xml;
 }
Beispiel #20
0
 public SendSecurityHeaderElement(string id, ISecurityElement item)
 {
     this.id   = id;
     this.item = item;
     this.markedForEncryption = false;
 }