Ejemplo n.º 1
0
        public override byte[] ProcessAndDigest(object input, SignatureResourcePool resourcePool, string digestAlgorithm, DictionaryManager dictionaryManager)
        {
            HashAlgorithm hash = resourcePool.TakeHashAlgorithm(digestAlgorithm);

            this.ProcessAndDigest(input, resourcePool, hash, dictionaryManager);
            return(hash.Hash);
        }
        public override object Process(object input, SignatureResourcePool resourcePool, DictionaryManager dictionaryManager)
        {
            XmlTokenStream tokenStream = input as XmlTokenStream;

            if (tokenStream != null)
            {
                tokenStream.SetElementExclusion(XmlSignatureStrings.Signature, XmlSignatureStrings.Namespace);
                return(tokenStream);
            }

            WrappedReader reader = input as WrappedReader;

            if (reader != null)
            {
                // The Enveloped Signature Transform is supposed to remove the
                // Signature which encloses the transform element. Previous versions
                // of this code stripped out all Signature elements at any depth,
                // which did not allow nested signed structures. By specifying '1'
                // as the depth, we narrow our range of support so that we require
                // that the enveloped signature be a direct child of the element
                // being signed.
                reader.XmlTokens.SetElementExclusion(XmlSignatureConstants.Elements.Signature, XmlSignatureConstants.Namespace, 1);
                return(reader);
            }

            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.UnsupportedInputTypeForTransform, input.GetType())));
        }
        public override object Process(object input, SignatureResourcePool resourcePool, DictionaryManager dictionaryManager)
        {
            XmlTokenStream tokenStream = input as XmlTokenStream;
            if (tokenStream != null)
            {
                tokenStream.SetElementExclusion(XmlSignatureStrings.Signature, XmlSignatureStrings.Namespace);
                return tokenStream;
            }

            WrappedReader reader = input as WrappedReader;
            if ( reader != null )
            {
                // The Enveloped Signature Transform is supposed to remove the
                // Signature which encloses the transform element. Previous versions
                // of this code stripped out all Signature elements at any depth, 
                // which did not allow nested signed structures. By specifying '1' 
                // as the depth, we narrow our range of support so that we require
                // that the enveloped signature be a direct child of the element
                // being signed.
                reader.XmlTokens.SetElementExclusion( XmlSignatureConstants.Elements.Signature, XmlSignatureConstants.Namespace, 1 );
                return reader;
            }

            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.UnsupportedInputTypeForTransform, input.GetType())));
        }
 CanonicalizationDriver GetConfiguredDriver(SignatureResourcePool resourcePool)
 {
     CanonicalizationDriver driver = resourcePool.TakeCanonicalizationDriver();
     driver.IncludeComments = this.IncludeComments;
     driver.SetInclusivePrefixes(this.inclusivePrefixes);
     return driver;
 }
Ejemplo n.º 5
0
 public byte[] TransformToDigest(object data, SignatureResourcePool resourcePool, string digestMethod, DictionaryManager dictionaryManager)
 {
     for (int i = 0; i < (this.TransformCount - 1); i++)
     {
         data = this[i].Process(data, resourcePool, dictionaryManager);
     }
     return(this[this.TransformCount - 1].ProcessAndDigest(data, resourcePool, digestMethod, dictionaryManager));
 }
 public byte[] TransformToDigest(object data, SignatureResourcePool resourcePool, string digestMethod, DictionaryManager dictionaryManager)
 {
     for (int i = 0; i < (this.TransformCount - 1); i++)
     {
         data = this[i].Process(data, resourcePool, dictionaryManager);
     }
     return this[this.TransformCount - 1].ProcessAndDigest(data, resourcePool, digestMethod, dictionaryManager);
 }
Ejemplo n.º 7
0
        private CanonicalizationDriver GetConfiguredDriver(SignatureResourcePool resourcePool)
        {
            CanonicalizationDriver driver = resourcePool.TakeCanonicalizationDriver();

            driver.IncludeComments = this.IncludeComments;
            driver.SetInclusivePrefixes(this.inclusivePrefixes);
            return(driver);
        }
 public override object Process(object input, SignatureResourcePool resourcePool, DictionaryManager dictionaryManager)
 {
     XmlTokenStream stream = input as XmlTokenStream;
     if (stream == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(System.IdentityModel.SR.GetString("UnsupportedInputTypeForTransform", new object[] { input.GetType() })));
     }
     stream.SetElementExclusion("Signature", "http://www.w3.org/2000/09/xmldsig#");
     return stream;
 }
        public override object Process(object input, SignatureResourcePool resourcePool, DictionaryManager dictionaryManager)
        {
            XmlTokenStream stream = input as XmlTokenStream;

            if (stream == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(System.IdentityModel.SR.GetString("UnsupportedInputTypeForTransform", new object[] { input.GetType() })));
            }
            stream.SetElementExclusion("Signature", "http://www.w3.org/2000/09/xmldsig#");
            return(stream);
        }
Ejemplo n.º 10
0
        private void ProcessReaderInput(XmlReader reader, SignatureResourcePool resourcePool, HashStream hashStream)
        {
            reader.MoveToContent();
            XmlDictionaryReader reader2 = reader as XmlDictionaryReader;

            if ((reader2 != null) && reader2.CanCanonicalize)
            {
                reader2.StartCanonicalization(hashStream, this.IncludeComments, this.GetInclusivePrefixes());
                reader2.Skip();
                reader2.EndCanonicalization();
            }
            else
            {
                CanonicalizationDriver configuredDriver = this.GetConfiguredDriver(resourcePool);
                configuredDriver.SetInput(reader);
                configuredDriver.WriteTo(hashStream);
            }
        }
 public override object Process(object input, SignatureResourcePool resourcePool, DictionaryManager dictionaryManager)
 {
     if (input is XmlReader)
     {
         CanonicalizationDriver configuredDriver = this.GetConfiguredDriver(resourcePool);
         configuredDriver.SetInput(input as XmlReader);
         return configuredDriver.GetMemoryStream();
     }
     if (!(input is ISecurityElement))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(System.IdentityModel.SR.GetString("UnsupportedInputTypeForTransform", new object[] { input.GetType() })));
     }
     MemoryStream stream = new MemoryStream();
     XmlDictionaryWriter writer = resourcePool.TakeUtf8Writer();
     writer.StartCanonicalization(stream, false, null);
     (input as ISecurityElement).WriteTo(writer, dictionaryManager);
     writer.EndCanonicalization();
     stream.Seek(0L, SeekOrigin.Begin);
     return stream;
 }
Ejemplo n.º 12
0
        public override object Process(object input, SignatureResourcePool resourcePool, DictionaryManager dictionaryManager)
        {
            if (input is XmlReader)
            {
                CanonicalizationDriver configuredDriver = this.GetConfiguredDriver(resourcePool);
                configuredDriver.SetInput(input as XmlReader);
                return(configuredDriver.GetMemoryStream());
            }
            if (!(input is ISecurityElement))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(System.IdentityModel.SR.GetString("UnsupportedInputTypeForTransform", new object[] { input.GetType() })));
            }
            MemoryStream        stream = new MemoryStream();
            XmlDictionaryWriter writer = resourcePool.TakeUtf8Writer();

            writer.StartCanonicalization(stream, false, null);
            (input as ISecurityElement).WriteTo(writer, dictionaryManager);
            writer.EndCanonicalization();
            stream.Seek(0L, SeekOrigin.Begin);
            return(stream);
        }
 public void ProcessAndDigest(object input, SignatureResourcePool resourcePool, HashAlgorithm hash, DictionaryManager dictionaryManger)
 {
     HashStream hashStream = resourcePool.TakeHashStream(hash);
     XmlReader reader = input as XmlReader;
     if (reader != null)
     {
         this.ProcessReaderInput(reader, resourcePool, hashStream);
     }
     else
     {
         if (!(input is ISecurityElement))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(System.IdentityModel.SR.GetString("UnsupportedInputTypeForTransform", new object[] { input.GetType() })));
         }
         XmlDictionaryWriter writer = resourcePool.TakeUtf8Writer();
         writer.StartCanonicalization(hashStream, this.IncludeComments, this.GetInclusivePrefixes());
         (input as ISecurityElement).WriteTo(writer, dictionaryManger);
         writer.EndCanonicalization();
     }
     hashStream.FlushHash();
 }
Ejemplo n.º 14
0
        public void ProcessAndDigest(object input, SignatureResourcePool resourcePool, HashAlgorithm hash, DictionaryManager dictionaryManger)
        {
            HashStream hashStream = resourcePool.TakeHashStream(hash);
            XmlReader  reader     = input as XmlReader;

            if (reader != null)
            {
                this.ProcessReaderInput(reader, resourcePool, hashStream);
            }
            else
            {
                if (!(input is ISecurityElement))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(System.IdentityModel.SR.GetString("UnsupportedInputTypeForTransform", new object[] { input.GetType() })));
                }
                XmlDictionaryWriter writer = resourcePool.TakeUtf8Writer();
                writer.StartCanonicalization(hashStream, this.IncludeComments, this.GetInclusivePrefixes());
                (input as ISecurityElement).WriteTo(writer, dictionaryManger);
                writer.EndCanonicalization();
            }
            hashStream.FlushHash();
        }
Ejemplo n.º 15
0
 public override object Process(object input, SignatureResourcePool resourcePool, DictionaryManager dictionaryManager)
 {
     if (input is XmlReader)
     {
         CanonicalizationDriver driver = GetConfiguredDriver(resourcePool);
         driver.SetInput(input as XmlReader);
         return driver.GetMemoryStream();
     }
     else if (input is ISecurityElement)
     {
         MemoryStream stream = new MemoryStream();
         XmlDictionaryWriter utf8Writer = resourcePool.TakeUtf8Writer();
         utf8Writer.StartCanonicalization(stream, false, null);
         (input as ISecurityElement).WriteTo(utf8Writer, dictionaryManager);
         utf8Writer.EndCanonicalization();
         stream.Seek(0, SeekOrigin.Begin);
         return stream;
     }
     else
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.UnsupportedInputTypeForTransform, input.GetType())));
     }
 }
 // multi-transform case, inefficient path
 public override object Process(object input, SignatureResourcePool resourcePool, DictionaryManager dictionaryManager)
 {
     if (input is XmlReader)
     {
         CanonicalizationDriver driver = GetConfiguredDriver(resourcePool);
         driver.SetInput(input as XmlReader);
         return(driver.GetMemoryStream());
     }
     else if (input is ISecurityElement)
     {
         MemoryStream        stream     = new MemoryStream();
         XmlDictionaryWriter utf8Writer = resourcePool.TakeUtf8Writer();
         utf8Writer.StartCanonicalization(stream, false, null);
         (input as ISecurityElement).WriteTo(utf8Writer, dictionaryManager);
         utf8Writer.EndCanonicalization();
         stream.Seek(0, SeekOrigin.Begin);
         return(stream);
     }
     else
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.UnsupportedInputTypeForTransform, input.GetType())));
     }
 }
 // common single-transform case; fold directly into a digest
 public override byte[] ProcessAndDigest(object input, SignatureResourcePool resourcePool, string digestAlgorithm, DictionaryManager dictionaryManager)
 {
     HashAlgorithm hash = resourcePool.TakeHashAlgorithm(digestAlgorithm);
     ProcessAndDigest(input, resourcePool, hash, dictionaryManager);
     return hash.Hash;
 }
Ejemplo n.º 18
0
 public byte[] TransformToDigest(object data, SignatureResourcePool resourcePool, string digestMethod, DictionaryManager dictionaryManager)
 {
     DiagnosticUtility.DebugAssert(TransformCount > 0, "");
     for (int i = 0; i < this.TransformCount - 1; i++)
     {
         data = this[i].Process(data, resourcePool, dictionaryManager);
     }
     return this[this.TransformCount - 1].ProcessAndDigest(data, resourcePool, digestMethod, dictionaryManager);
 }
 internal abstract SecurityTimestamp ReadTimestamp(XmlDictionaryReader reader, string digestAlgorithm, SignatureResourcePool resourcePool);
 internal override SecurityTimestamp ReadTimestamp(XmlDictionaryReader reader, string digestAlgorithm, SignatureResourcePool resourcePool)
 {
     DateTime maxUtcDateTime;
     byte[] buffer;
     bool flag = (digestAlgorithm != null) && reader.CanCanonicalize;
     HashStream stream = null;
     reader.MoveToStartElement(System.ServiceModel.XD.UtilityDictionary.Timestamp, System.ServiceModel.XD.UtilityDictionary.Namespace);
     if (flag)
     {
         stream = resourcePool.TakeHashStream(digestAlgorithm);
         reader.StartCanonicalization(stream, false, null);
     }
     string attribute = reader.GetAttribute(System.ServiceModel.XD.UtilityDictionary.IdAttribute, System.ServiceModel.XD.UtilityDictionary.Namespace);
     reader.ReadStartElement();
     reader.ReadStartElement(System.ServiceModel.XD.UtilityDictionary.CreatedElement, System.ServiceModel.XD.UtilityDictionary.Namespace);
     DateTime creationTimeUtc = reader.ReadContentAsDateTime().ToUniversalTime();
     reader.ReadEndElement();
     if (reader.IsStartElement(System.ServiceModel.XD.UtilityDictionary.ExpiresElement, System.ServiceModel.XD.UtilityDictionary.Namespace))
     {
         reader.ReadStartElement();
         maxUtcDateTime = reader.ReadContentAsDateTime().ToUniversalTime();
         reader.ReadEndElement();
     }
     else
     {
         maxUtcDateTime = System.ServiceModel.Security.SecurityUtils.MaxUtcDateTime;
     }
     reader.ReadEndElement();
     if (flag)
     {
         reader.EndCanonicalization();
         buffer = stream.FlushHashAndGetValue();
     }
     else
     {
         buffer = null;
     }
     return new SecurityTimestamp(creationTimeUtc, maxUtcDateTime, attribute, digestAlgorithm, buffer);
 }
 public override byte[] ProcessAndDigest(object input, SignatureResourcePool resourcePool, string digestAlgorithm, DictionaryManager dictionaryManager)
 {
     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(System.IdentityModel.SR.GetString("UnsupportedLastTransform")));
 }
 // this transform is not allowed as the last one in a chain
 public override byte[] ProcessAndDigest(object input, SignatureResourcePool resourcePool, string digestAlgorithm, DictionaryManager dictionaryManager)
 {
     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.UnsupportedLastTransform)));
 }
 public abstract object Process(object input, SignatureResourcePool resourcePool, DictionaryManager dictionaryManager);
 void ProcessReaderInput(XmlReader reader, SignatureResourcePool resourcePool, HashStream hashStream)
 {
     reader.MoveToContent();
     XmlDictionaryReader dictionaryReader = reader as XmlDictionaryReader;
     if (dictionaryReader != null && dictionaryReader.CanCanonicalize)
     {
         dictionaryReader.StartCanonicalization(hashStream, this.IncludeComments, GetInclusivePrefixes());
         dictionaryReader.Skip();
         dictionaryReader.EndCanonicalization();
     }
     else
     {
         CanonicalizationDriver driver = GetConfiguredDriver(resourcePool);
         driver.SetInput(reader);
         driver.WriteTo(hashStream);
     }
 }
Ejemplo n.º 25
0
 public abstract byte[] ProcessAndDigest(object input, SignatureResourcePool resourcePool, string digestAlgorithm, DictionaryManager dictionaryManager);
Ejemplo n.º 26
0
 public abstract object Process(object input, SignatureResourcePool resourcePool, DictionaryManager dictionaryManager);
 public abstract byte[] ProcessAndDigest(object input, SignatureResourcePool resourcePool, string digestAlgorithm, DictionaryManager dictionaryManager);