Пример #1
0
        public void GetXmlWithoutSetProperty()
        {
            string      result = @"<dsig:SignedInfo xmlns:dsig=""http://www.w3.org/2000/09/xmldsig#""><dsig:CanonicalizationMethod Algorithm=""http://www.w3.org/TR/2001/REC-xml-c14n-withcomments-20010315"" /><dsig:SignatureMethod Algorithm=""http://www.w3.org/2000/09/xmldsig#rsa-sha1"" /><dsig:Reference URI=""""><dsig:Transforms><dsig:Transform Algorithm=""http://www.w3.org/2000/09/xmldsig#enveloped-signature"" /></dsig:Transforms><dsig:DigestMethod Algorithm=""http://www.w3.org/2000/09/xmldsig#sha1"" /><dsig:DigestValue>nDF2V/bzRd0VE3EwShWtsBzTEDc=</dsig:DigestValue></dsig:Reference></dsig:SignedInfo>";
            XmlDocument doc    = new XmlDocument();

            doc.LoadXml(xmlForGetXml);
            SignedInfo sig = new SignedInfo();

            sig.LoadXml((XmlElement)doc.SelectSingleNode("//*[local-name()='SignedInfo']"));
            XmlElement el = sig.GetXml();

            Assert.Equal(doc, el.OwnerDocument);
            Assert.Equal(result, el.OuterXml);
        }
Пример #2
0
        [Test]         // never fails
        public void EmptyReferenceWithoutSetProperty()
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xmlForGetXml);
            XmlNode n = doc.SelectSingleNode("//*[local-name()='Reference']");

            n.ParentNode.RemoveChild(n);

            SignedInfo sig = new SignedInfo();

            sig.LoadXml((XmlElement)doc.SelectSingleNode("//*[local-name()='SignedInfo']"));
            XmlElement el = sig.GetXml();
        }
Пример #3
0
        public void EmptyReferenceWithSetProperty()
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xmlForGetXml);
            XmlNode n = doc.SelectSingleNode("//*[local-name()='Reference']");

            n.ParentNode.RemoveChild(n);

            SignedInfo sig = new SignedInfo();

            sig.LoadXml((XmlElement)doc.SelectSingleNode("//*[local-name()='SignedInfo']"));
            sig.CanonicalizationMethod = "urn:foo";
            Assert.Throws <CryptographicException>(() => sig.GetXml());
        }
Пример #4
0
        private byte[] GetC14NDigest(HashAlgorithm hash, string prefix)
        {
            var xmlDocument = new XmlDocument
            {
                PreserveWhitespace = true
            };
            var xml = SignedInfo.GetXml();

            xmlDocument.AppendChild(xmlDocument.ImportNode(xml, true));
            var canonicalizationMethodObject = SignedInfo.CanonicalizationMethodObject;

            SetPrefix(prefix, xmlDocument.DocumentElement);
            canonicalizationMethodObject.LoadInput(xmlDocument);
            return(canonicalizationMethodObject.GetDigestedOutput(hash));
        }
        private void GetC14NDigest(HashAlgorithm hash, string prefix)
        {
            var document = new XmlDocument();

            document.PreserveWhitespace = true;

            var e = SignedInfo.GetXml();

            document.AppendChild(document.ImportNode(e, true));

            var canonicalizationMethodObject = SignedInfo.CanonicalizationMethodObject;

            SetPrefix(prefix, document.DocumentElement);
            canonicalizationMethodObject.LoadInput(document);

            canonicalizationMethodObject.GetDigestedOutput(hash);
        }
Пример #6
0
        private byte[] GetC14NDigest(HashAlgorithm hash, string prefix)
        {
            XmlDocument doc = new XmlDocument
            {
                PreserveWhitespace = false
            };
            XmlElement e = SignedInfo.GetXml();

            doc.AppendChild(doc.ImportNode(e, true));

            List <XmlAttribute> namespaces = Utils.GetPropagatedAttributes(_xmlElement);

            Utils.AddNamespaces(doc.DocumentElement, namespaces);

            Transform canonicalizationMethodObject = SignedInfo.CanonicalizationMethodObject;

            SetPrefix(prefix, doc.DocumentElement);
            canonicalizationMethodObject.LoadInput(doc);
            return(canonicalizationMethodObject.GetDigestedOutput(hash));
        }
Пример #7
0
        private byte[] GetC14NDigest(HashAlgorithm hash, string prefix)
        {
            //string securityUrl = (this.m_containingDocument == null) ? null : this.m_containingDocument.BaseURI;
            //XmlResolver xmlResolver = new XmlSecureResolver(new XmlUrlResolver(), securityUrl);
            var document = new XmlDocument();

            document.PreserveWhitespace = true;
            var e = SignedInfo.GetXml();

            document.AppendChild(document.ImportNode(e, true));
            //CanonicalXmlNodeList namespaces = (this.m_context == null) ? null : Utils.GetPropagatedAttributes(this.m_context);
            //Utils.AddNamespaces(document.DocumentElement, namespaces);

            var canonicalizationMethodObject = SignedInfo.CanonicalizationMethodObject;

            //canonicalizationMethodObject.Resolver = xmlResolver;
            //canonicalizationMethodObject.BaseURI = securityUrl;
            SetPrefix(prefix, document.DocumentElement); //establecemos el prefijo antes de se que calcule el hash (o de lo contrario la firma no será válida)
            canonicalizationMethodObject.LoadInput(document);
            return(canonicalizationMethodObject.GetDigestedOutput(hash));
        }
Пример #8
0
 public void EmptyException()
 {
     Assert.Throws <CryptographicException>(() => info.GetXml().OuterXml);
 }
Пример #9
0
 public void EmptyException()
 {
     Assert.Throws <System.Security.Cryptography.CryptographicException>(() => info.GetXml().OuterXml);
 }
Пример #10
0
 public void EmptyException()
 {
     string xml = info.GetXml().OuterXml;
 }