Esempio n. 1
0
 public override void LoadInput(object obj)
 {
     _inputStream?.Close();
     _inputStream = new MemoryStream();
     if (obj is Stream)
     {
         _inputStream = (Stream)obj;
     }
     else if (obj is XmlNodeList)
     {
         CanonicalXml xmlDoc = new CanonicalXml((XmlNodeList)obj, null, _includeComments);
         byte[]       buffer = xmlDoc.GetBytes();
         if (buffer == null)
         {
             return;
         }
         _inputStream.Write(buffer, 0, buffer.Length);
         _inputStream.Flush();
         _inputStream.Position = 0;
     }
     else if (obj is XmlDocument)
     {
         CanonicalXml xmlDoc = new CanonicalXml((XmlDocument)obj, null, _includeComments);
         byte[]       buffer = xmlDoc.GetBytes();
         if (buffer == null)
         {
             return;
         }
         _inputStream.Write(buffer, 0, buffer.Length);
         _inputStream.Flush();
         _inputStream.Position = 0;
     }
 }
        private void LoadXmlNodeListInput(XmlNodeList nodeList)
        {
            // Use C14N to get a document
            XmlResolver  resolver = (ResolverSet ? _xmlResolver : new XmlSecureResolver(new XmlUrlResolver(), BaseURI));
            CanonicalXml c14n     = new CanonicalXml((XmlNodeList)nodeList, resolver, true);

            using (MemoryStream ms = new MemoryStream(c14n.GetBytes()))
            {
                LoadStreamInput(ms);
            }
        }
Esempio n. 3
0
        private void LoadXmlNodeListInput(XmlNodeList nodeList)
        {
            // Use C14N to get a document
            XmlResolver  resolver = (ResolverSet ? _xmlResolver : XmlResolverHelper.GetThrowingResolver());
            CanonicalXml c14n     = new CanonicalXml((XmlNodeList)nodeList, resolver, true);

            using (MemoryStream ms = new MemoryStream(c14n.GetBytes()))
            {
                LoadStreamInput(ms);
            }
        }
        private void LoadXmlNodeListInput(XmlNodeList nodeList)
        {
            XmlResolver  resolver = base.ResolverSet ? base.m_xmlResolver : new XmlSecureResolver(new XmlUrlResolver(), base.BaseURI);
            CanonicalXml xml      = new CanonicalXml(nodeList, resolver, true);

            using (MemoryStream stream = new MemoryStream(xml.GetBytes()))
            {
                this._document = new XmlDocument();
                this._document.PreserveWhitespace = true;
                this._document.Load(stream);
            }
        }
Esempio n. 5
0
        // The goal behind this method is to pump the input stream through the transforms and get back something that
        // can be hashed
        internal Stream TransformToOctetStream(object inputObject, Type inputType, XmlResolver resolver, string baseUri)
        {
            object currentInput = inputObject;

            foreach (Transform transform in _transforms)
            {
                if (currentInput == null || transform.AcceptsType(currentInput.GetType()))
                {
                    //in this case, no translation necessary, pump it through
                    transform.Resolver = resolver;
                    transform.BaseURI  = baseUri;
                    transform.LoadInput(currentInput);
                    currentInput = transform.GetOutput();
                }
                else
                {
                    // We need translation
                    // For now, we just know about Stream->{XmlNodeList,XmlDocument} and {XmlNodeList,XmlDocument}->Stream
                    if (currentInput is Stream)
                    {
                        if (transform.AcceptsType(typeof(XmlDocument)))
                        {
                            Stream      currentInputStream = currentInput as Stream;
                            XmlDocument doc = new XmlDocument();
                            doc.PreserveWhitespace = true;
                            XmlReader valReader = Utils.PreProcessStreamInput(currentInputStream, resolver, baseUri);
                            doc.Load(valReader);
                            transform.LoadInput(doc);
                            currentInputStream.Close();
                            currentInput = transform.GetOutput();
                            continue;
                        }
                        else
                        {
                            throw new CryptographicException(SR.Cryptography_Xml_TransformIncorrectInputType);
                        }
                    }
                    if (currentInput is XmlNodeList)
                    {
                        if (transform.AcceptsType(typeof(Stream)))
                        {
                            CanonicalXml c14n = new CanonicalXml((XmlNodeList)currentInput, resolver, false);
                            MemoryStream ms   = new MemoryStream(c14n.GetBytes());
                            transform.LoadInput(ms);
                            currentInput = transform.GetOutput();
                            ms.Close();
                            continue;
                        }
                        else
                        {
                            throw new CryptographicException(SR.Cryptography_Xml_TransformIncorrectInputType);
                        }
                    }
                    if (currentInput is XmlDocument)
                    {
                        if (transform.AcceptsType(typeof(Stream)))
                        {
                            CanonicalXml c14n = new CanonicalXml((XmlDocument)currentInput, resolver);
                            MemoryStream ms   = new MemoryStream(c14n.GetBytes());
                            transform.LoadInput(ms);
                            currentInput = transform.GetOutput();
                            ms.Close();
                            continue;
                        }
                        else
                        {
                            throw new CryptographicException(SR.Cryptography_Xml_TransformIncorrectInputType);
                        }
                    }
                    throw new CryptographicException(SR.Cryptography_Xml_TransformIncorrectInputType);
                }
            }

            // Final processing, either we already have a stream or have to canonicalize
            if (currentInput is Stream)
            {
                return(currentInput as Stream);
            }
            if (currentInput is XmlNodeList)
            {
                CanonicalXml c14n = new CanonicalXml((XmlNodeList)currentInput, resolver, false);
                MemoryStream ms   = new MemoryStream(c14n.GetBytes());
                return(ms);
            }
            if (currentInput is XmlDocument)
            {
                CanonicalXml c14n = new CanonicalXml((XmlDocument)currentInput, resolver);
                MemoryStream ms   = new MemoryStream(c14n.GetBytes());
                return(ms);
            }
            throw new CryptographicException(SR.Cryptography_Xml_TransformIncorrectInputType);
        }
Esempio n. 6
0
 public override void LoadInput(Object obj) {
     if (_inputStream != null)
         _inputStream.Close();
     _inputStream = new MemoryStream();
     if (obj is Stream) {
         _inputStream = (Stream) obj;
     }
     else if (obj is XmlNodeList) {
         CanonicalXml xmlDoc = new CanonicalXml((XmlNodeList) obj, null, _includeComments);
         byte[] buffer = xmlDoc.GetBytes();
         if (buffer == null) return;
         _inputStream.Write(buffer, 0, buffer.Length);
         _inputStream.Flush();
         _inputStream.Position = 0;
     }
     else if (obj is XmlDocument) {
         CanonicalXml xmlDoc = new CanonicalXml((XmlDocument) obj, null, _includeComments);
         byte[] buffer = xmlDoc.GetBytes();
         if (buffer == null) return;
         _inputStream.Write(buffer, 0, buffer.Length);
         _inputStream.Flush();
         _inputStream.Position = 0;
     }
 }
Esempio n. 7
0
 private void LoadXmlNodeListInput(XmlNodeList nodeList) {
     // Use C14N to get a document
     XmlResolver resolver = (this.ResolverSet ? this.m_xmlResolver : new XmlSecureResolver(new XmlUrlResolver(), this.BaseURI));
     CanonicalXml c14n = new CanonicalXml((XmlNodeList) nodeList, resolver, true);
     using (MemoryStream ms = new MemoryStream(c14n.GetBytes())) {
         LoadStreamInput(ms);
     }
 }
Esempio n. 8
0
        // The goal behind this method is to pump the input stream through the transforms and get back something that
        // can be hashed
        internal Stream TransformToOctetStream(Object inputObject, Type inputType, XmlResolver resolver, string baseUri) {
            Object currentInput = inputObject;
            foreach (Transform transform in m_transforms) {
                if (currentInput == null || transform.AcceptsType(currentInput.GetType())) {
                    //in this case, no translation necessary, pump it through
                    transform.Resolver = resolver;
                    transform.BaseURI = baseUri;
                    transform.LoadInput(currentInput);
                    currentInput = transform.GetOutput();
                } else {
                    // We need translation 
                    // For now, we just know about Stream->{XmlNodeList,XmlDocument} and {XmlNodeList,XmlDocument}->Stream
                    if (currentInput is Stream) {
                        if (transform.AcceptsType(typeof(XmlDocument))) {
                            Stream currentInputStream = currentInput as Stream;
                            XmlDocument doc = new XmlDocument();
                            doc.PreserveWhitespace = true;
                            XmlReader valReader = Utils.PreProcessStreamInput(currentInputStream, resolver, baseUri);
                            doc.Load(valReader);
                            transform.LoadInput(doc);
                            currentInputStream.Close();
                            currentInput = transform.GetOutput();
                            continue;
                        } else {
                            throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_TransformIncorrectInputType"));
                        }
                    } 
                    if (currentInput is XmlNodeList) {
                        if (transform.AcceptsType(typeof(Stream))) {
                            CanonicalXml c14n = new CanonicalXml((XmlNodeList) currentInput, resolver, false);
                            MemoryStream ms = new MemoryStream(c14n.GetBytes());
                            transform.LoadInput(ms);
                            currentInput = transform.GetOutput();
                            ms.Close();
                            continue;
                        } else {
                            throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_TransformIncorrectInputType"));
                        }
                    }
                    if (currentInput is XmlDocument) {
                        if (transform.AcceptsType(typeof(Stream))) {
                            CanonicalXml c14n = new CanonicalXml((XmlDocument) currentInput, resolver);
                            MemoryStream ms = new MemoryStream(c14n.GetBytes());
                            transform.LoadInput(ms);
                            currentInput = transform.GetOutput();
                            ms.Close();
                            continue;
                        } else {
                            throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_TransformIncorrectInputType"));
                        }
                    }
                    throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_TransformIncorrectInputType"));
                }
            }

            // Final processing, either we already have a stream or have to canonicalize
            if (currentInput is Stream) {
                return currentInput as Stream;
            }
            if (currentInput is XmlNodeList) {
                CanonicalXml c14n = new CanonicalXml((XmlNodeList) currentInput, resolver, false);
                MemoryStream ms = new MemoryStream(c14n.GetBytes());
                return ms;
            }
            if (currentInput is XmlDocument) {
                CanonicalXml c14n = new CanonicalXml((XmlDocument) currentInput, resolver);
                MemoryStream ms = new MemoryStream(c14n.GetBytes());
                return ms;
            }
            throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_TransformIncorrectInputType"));
        }
 internal Stream TransformToOctetStream(object inputObject, Type inputType, XmlResolver resolver, string baseUri)
 {
     object output = inputObject;
     foreach (Transform transform in this.m_transforms)
     {
         if ((output == null) || transform.AcceptsType(output.GetType()))
         {
             transform.Resolver = resolver;
             transform.BaseURI = baseUri;
             transform.LoadInput(output);
             output = transform.GetOutput();
         }
         else if (output is Stream)
         {
             if (!transform.AcceptsType(typeof(XmlDocument)))
             {
                 throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_TransformIncorrectInputType"));
             }
             Stream inputStream = output as Stream;
             XmlDocument document = new XmlDocument {
                 PreserveWhitespace = true
             };
             XmlReader reader = System.Security.Cryptography.Xml.Utils.PreProcessStreamInput(inputStream, resolver, baseUri);
             document.Load(reader);
             transform.LoadInput(document);
             inputStream.Close();
             output = transform.GetOutput();
         }
         else if (output is XmlNodeList)
         {
             if (!transform.AcceptsType(typeof(Stream)))
             {
                 throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_TransformIncorrectInputType"));
             }
             CanonicalXml xml = new CanonicalXml((XmlNodeList) output, resolver, false);
             MemoryStream stream2 = new MemoryStream(xml.GetBytes());
             transform.LoadInput(stream2);
             output = transform.GetOutput();
             stream2.Close();
         }
         else
         {
             if (!(output is XmlDocument))
             {
                 throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_TransformIncorrectInputType"));
             }
             if (!transform.AcceptsType(typeof(Stream)))
             {
                 throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_TransformIncorrectInputType"));
             }
             CanonicalXml xml2 = new CanonicalXml((XmlDocument) output, resolver);
             MemoryStream stream3 = new MemoryStream(xml2.GetBytes());
             transform.LoadInput(stream3);
             output = transform.GetOutput();
             stream3.Close();
         }
     }
     if (output is Stream)
     {
         return (output as Stream);
     }
     if (output is XmlNodeList)
     {
         CanonicalXml xml3 = new CanonicalXml((XmlNodeList) output, resolver, false);
         return new MemoryStream(xml3.GetBytes());
     }
     if (!(output is XmlDocument))
     {
         throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_TransformIncorrectInputType"));
     }
     CanonicalXml xml4 = new CanonicalXml((XmlDocument) output, resolver);
     return new MemoryStream(xml4.GetBytes());
 }
 public override object GetOutput()
 {
     return(new MemoryStream(_cXml.GetBytes()));
 }
Esempio n. 11
0
        internal Stream TransformToOctetStream(object inputObject, Type inputType, XmlResolver resolver, string baseUri)
        {
            object output = inputObject;

            foreach (Transform transform in this.m_transforms)
            {
                if ((output == null) || transform.AcceptsType(output.GetType()))
                {
                    transform.Resolver = resolver;
                    transform.BaseURI  = baseUri;
                    transform.LoadInput(output);
                    output = transform.GetOutput();
                }
                else if (output is Stream)
                {
                    if (!transform.AcceptsType(typeof(XmlDocument)))
                    {
                        throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_TransformIncorrectInputType"));
                    }
                    Stream      inputStream = output as Stream;
                    XmlDocument document    = new XmlDocument {
                        PreserveWhitespace = true
                    };
                    XmlReader reader = System.Security.Cryptography.Xml.Utils.PreProcessStreamInput(inputStream, resolver, baseUri);
                    document.Load(reader);
                    transform.LoadInput(document);
                    inputStream.Close();
                    output = transform.GetOutput();
                }
                else if (output is XmlNodeList)
                {
                    if (!transform.AcceptsType(typeof(Stream)))
                    {
                        throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_TransformIncorrectInputType"));
                    }
                    CanonicalXml xml     = new CanonicalXml((XmlNodeList)output, resolver, false);
                    MemoryStream stream2 = new MemoryStream(xml.GetBytes());
                    transform.LoadInput(stream2);
                    output = transform.GetOutput();
                    stream2.Close();
                }
                else
                {
                    if (!(output is XmlDocument))
                    {
                        throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_TransformIncorrectInputType"));
                    }
                    if (!transform.AcceptsType(typeof(Stream)))
                    {
                        throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_TransformIncorrectInputType"));
                    }
                    CanonicalXml xml2    = new CanonicalXml((XmlDocument)output, resolver);
                    MemoryStream stream3 = new MemoryStream(xml2.GetBytes());
                    transform.LoadInput(stream3);
                    output = transform.GetOutput();
                    stream3.Close();
                }
            }
            if (output is Stream)
            {
                return(output as Stream);
            }
            if (output is XmlNodeList)
            {
                CanonicalXml xml3 = new CanonicalXml((XmlNodeList)output, resolver, false);
                return(new MemoryStream(xml3.GetBytes()));
            }
            if (!(output is XmlDocument))
            {
                throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_TransformIncorrectInputType"));
            }
            CanonicalXml xml4 = new CanonicalXml((XmlDocument)output, resolver);

            return(new MemoryStream(xml4.GetBytes()));
        }
Esempio n. 12
0
        // The goal behind this method is to pump the input stream through the transforms and get back something that
        // can be hashed
        internal Stream TransformToOctetStream(Object inputObject, Type inputType, XmlResolver resolver, string strBaseUri)
        {
            Object currentInput = inputObject;

            foreach (Object obj in m_transforms)
            {
                Transform transform = obj as Transform;
                if (transform.AcceptsType(currentInput.GetType()))
                {
                    //in this case, no translation necessary, pump it through
                    transform.Resolver = resolver;
                    transform.BaseURI  = strBaseUri;
                    transform.LoadInput(currentInput);
                    currentInput = transform.GetOutput();
                }
                else
                {
                    // We need translation
                    // For now, we just know about Stream->{XmlNodeList,XmlDocument} and {XmlNodeList,XmlDocument}->Stream
                    if (currentInput is Stream)
                    {
                        if (transform.AcceptsType(typeof(XmlDocument)))
                        {
                            XmlDocument doc = new XmlDocument();
                            doc.PreserveWhitespace = true;
                            XmlValidatingReader valReader = SignedXml.PreProcessStreamInput((Stream)currentInput, resolver, strBaseUri);
                            doc.Load(valReader);
                            transform.LoadInput(doc);
                            currentInput = transform.GetOutput();
                            continue;
                        }
                        else
                        {
                            throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_TransformIncorrectInputType"));
                        }
                    }
                    if (currentInput is XmlNodeList)
                    {
                        if (transform.AcceptsType(typeof(Stream)))
                        {
                            CanonicalXml c14n = new CanonicalXml((XmlNodeList)currentInput, false);
                            MemoryStream ms   = new MemoryStream(c14n.GetBytes());
                            transform.LoadInput((Stream)ms);
                            currentInput = transform.GetOutput();
                            continue;
                        }
                        else
                        {
                            throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_TransformIncorrectInputType"));
                        }
                    }
                    if (currentInput is XmlDocument)
                    {
                        if (transform.AcceptsType(typeof(Stream)))
                        {
                            CanonicalXml c14n = new CanonicalXml((XmlDocument)currentInput);
                            MemoryStream ms   = new MemoryStream(c14n.GetBytes());
                            transform.LoadInput((Stream)ms);
                            currentInput = transform.GetOutput();
                            continue;
                        }
                        else
                        {
                            throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_TransformIncorrectInputType"));
                        }
                    }
                    throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_TransformIncorrectInputType"));
                }
            }

            // Final processing, either we already have a stream or have to canonicalize
            if (currentInput is Stream)
            {
                return(currentInput as Stream);
            }
            if (currentInput is XmlNodeList)
            {
                CanonicalXml c14n = new CanonicalXml((XmlNodeList)currentInput, false);
                MemoryStream ms   = new MemoryStream(c14n.GetBytes());
                return(ms);
            }
            if (currentInput is XmlDocument)
            {
                CanonicalXml c14n = new CanonicalXml((XmlDocument)currentInput);
                MemoryStream ms   = new MemoryStream(c14n.GetBytes());
                return(ms);
            }
            throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_TransformIncorrectInputType"));
        }
 private void LoadXmlNodeListInput(XmlNodeList nodeList)
 {
     XmlResolver resolver = base.ResolverSet ? base.m_xmlResolver : new XmlSecureResolver(new XmlUrlResolver(), base.BaseURI);
     CanonicalXml xml = new CanonicalXml(nodeList, resolver, true);
     using (MemoryStream stream = new MemoryStream(xml.GetBytes()))
     {
         this._document = new XmlDocument();
         this._document.PreserveWhitespace = true;
         this._document.Load(stream);
     }
 }