Пример #1
0
		public void NewDataObject () 
		{
			string test = "<Test>DataObject</Test>";
			XmlDocument doc = new XmlDocument ();
			doc.LoadXml (test);

			DataObject obj1 = new DataObject ();
			Assert.IsTrue ((obj1.Data.Count == 0), "Data.Count==0");
			Assert.AreEqual ("<Object xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (obj1.GetXml ().OuterXml), "Just constructed");

			obj1.Id = "id";
			obj1.MimeType = "mime";
			obj1.Encoding = "encoding";
			Assert.AreEqual ("<Object Id=\"id\" MimeType=\"mime\" Encoding=\"encoding\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (obj1.GetXml ().OuterXml), "Only attributes");

			obj1.Data = doc.ChildNodes;
			Assert.IsTrue ((obj1.Data.Count == 1), "Data.Count==1");

			XmlElement xel = obj1.GetXml ();

			DataObject obj2 = new DataObject ();
			obj2.LoadXml (xel);
			Assert.AreEqual ((obj1.GetXml ().OuterXml), (obj2.GetXml ().OuterXml), "obj1==obj2");

			DataObject obj3 = new DataObject (obj1.Id, obj1.MimeType, obj1.Encoding, doc.DocumentElement);
			Assert.AreEqual ((obj2.GetXml ().OuterXml), (obj3.GetXml ().OuterXml), "obj2==obj3");
		}
Пример #2
0
        internal XmlElement GetXml(XmlDocument document)
        {
            // Create the Signature
            XmlElement signatureElement = (XmlElement)document.CreateElement("Signature", SignedXml.XmlDsigNamespaceUrl);

            if (!String.IsNullOrEmpty(m_id))
            {
                signatureElement.SetAttribute("Id", m_id);
            }

            // Add the SignedInfo
            if (m_signedInfo == null)
            {
                throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_SignedInfoRequired"));
            }

            signatureElement.AppendChild(m_signedInfo.GetXml(document));

            // Add the SignatureValue
            if (m_signatureValue == null)
            {
                throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_SignatureValueRequired"));
            }

            XmlElement signatureValueElement = document.CreateElement("SignatureValue", SignedXml.XmlDsigNamespaceUrl);

            signatureValueElement.AppendChild(document.CreateTextNode(Convert.ToBase64String(m_signatureValue)));
            if (!String.IsNullOrEmpty(m_signatureValueId))
            {
                signatureValueElement.SetAttribute("Id", m_signatureValueId);
            }
            signatureElement.AppendChild(signatureValueElement);

            // Add the KeyInfo
            if (this.KeyInfo.Count > 0)
            {
                signatureElement.AppendChild(this.KeyInfo.GetXml(document));
            }

            // Add the Objects
            foreach (Object obj in m_embeddedObjects)
            {
                DataObject dataObj = obj as DataObject;
                if (dataObj != null)
                {
                    signatureElement.AppendChild(dataObj.GetXml(document));
                }
            }

            return(signatureElement);
        }
Пример #3
0
        /// <include file='doc\Signature.uex' path='docs/doc[@for="Signature.GetXml"]/*' />
        public XmlElement GetXml()
        {
            XmlDocument document = new XmlDocument();

            // Create the Signature
            XmlElement signatureElement = (XmlElement)document.CreateElement("Signature", SignedXml.XmlDsigNamespaceUrl);

            //XmlElement signatureElement = (XmlElement)document.CreateElement("Signature");

            if (m_strId != null)
            {
                signatureElement.SetAttribute("Id", m_strId);
            }

            // Add the SignedInfo
            if (m_signedInfo == null)
            {
                throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_SignedInfoRequired"));
            }

            signatureElement.AppendChild(document.ImportNode(m_signedInfo.GetXml(), true));

            // Add the SignatureValue
            if (m_rgbSignatureValue == null)
            {
                throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_SignatureValueRequired"));
            }

            XmlElement signatureValueElement = document.CreateElement("SignatureValue", SignedXml.XmlDsigNamespaceUrl);

            signatureValueElement.AppendChild(document.CreateTextNode(Convert.ToBase64String(m_rgbSignatureValue)));
            signatureElement.AppendChild(signatureValueElement);

            // Add the KeyInfo
            if (m_keyInfo != null)
            {
                signatureElement.AppendChild(document.ImportNode(m_keyInfo.GetXml(), true));
            }

            // Add the Objects
            foreach (Object obj in m_embeddedObjects)
            {
                DataObject dataObj = obj as DataObject;
                if (dataObj != null)
                {
                    signatureElement.AppendChild(document.ImportNode(dataObj.GetXml(), true));
                }
            }
            return(signatureElement);
        }
Пример #4
0
		public void ImportDataObject () 
		{
			string value1 = "<Object Id=\"id\" MimeType=\"mime\" Encoding=\"encoding\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><Test xmlns=\"\">DataObject1</Test><Test xmlns=\"\">DataObject2</Test></Object>";
			XmlDocument doc = new XmlDocument ();
			doc.LoadXml (value1);

			DataObject obj1 = new DataObject ();
			obj1.LoadXml (doc.DocumentElement);
			Assert.IsTrue ((obj1.Data.Count == 2), "Data.Count==2");

			string s = (obj1.GetXml ().OuterXml);
			Assert.AreEqual (value1, s, "DataObject 1");

			string value2 = "<Object xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><Test xmlns=\"\" /></Object>";
			doc = new XmlDocument ();
			doc.LoadXml (value2);

			DataObject obj2 = new DataObject ();
			obj2.LoadXml (doc.DocumentElement);

			s = (obj2.GetXml ().OuterXml);
			Assert.AreEqual (value2, s, "DataObject 2");

			string value3 = "<Object Id=\"id\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><Test xmlns=\"\" /></Object>";
			doc = new XmlDocument ();
			doc.LoadXml (value3);

			DataObject obj3 = new DataObject ();
			obj3.LoadXml (doc.DocumentElement);

			s = (obj3.GetXml ().OuterXml);
			Assert.AreEqual (value3, s, "DataObject 3");

			string value4 = "<Object MimeType=\"mime\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><Test xmlns=\"\" /></Object>";
			doc = new XmlDocument ();
			doc.LoadXml (value4);

			DataObject obj4 = new DataObject ();
			obj4.LoadXml (doc.DocumentElement);

			s = (obj4.GetXml ().OuterXml);
			Assert.AreEqual (value4, s, "DataObject 4");
		}
        internal XmlElement GetXml(XmlDocument document)
        {
            XmlElement element = document.CreateElement("Signature", "http://www.w3.org/2000/09/xmldsig#");

            if (!string.IsNullOrEmpty(this.m_id))
            {
                element.SetAttribute("Id", this.m_id);
            }
            if (this.m_signedInfo == null)
            {
                throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_SignedInfoRequired"));
            }
            element.AppendChild(this.m_signedInfo.GetXml(document));
            if (this.m_signatureValue == null)
            {
                throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_SignatureValueRequired"));
            }
            XmlElement newChild = document.CreateElement("SignatureValue", "http://www.w3.org/2000/09/xmldsig#");

            newChild.AppendChild(document.CreateTextNode(Convert.ToBase64String(this.m_signatureValue)));
            if (!string.IsNullOrEmpty(this.m_signatureValueId))
            {
                newChild.SetAttribute("Id", this.m_signatureValueId);
            }
            element.AppendChild(newChild);
            if (this.KeyInfo.Count > 0)
            {
                element.AppendChild(this.KeyInfo.GetXml(document));
            }
            foreach (object obj2 in this.m_embeddedObjects)
            {
                DataObject obj3 = obj2 as DataObject;
                if (obj3 != null)
                {
                    element.AppendChild(obj3.GetXml(document));
                }
            }
            return(element);
        }
Пример #6
0
		public void EnvelopedObject ()
		{
			XmlDocument doc = new XmlDocument ();
			doc.LoadXml ("<envelope><Object xmlns:dsig='http://www.w3.org/2000/09/xmldsig#' xmlns='http://www.w3.org/2000/09/xmldsig#'>test</Object></envelope>");
			DataObject obj = new DataObject ();
			obj.LoadXml (doc.DocumentElement.FirstChild as XmlElement);
			obj.Id = "hoge";
			obj.MimeType = "application/octet-stream";
			obj.Encoding = "euc-kr";
			XmlElement el1 = obj.GetXml ();
			Assert.AreEqual ("<Object Id=\"hoge\" MimeType=\"application/octet-stream\" Encoding=\"euc-kr\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\">test</Object>", el1.OuterXml);
			/* looks curious? but the element does not look to 
			   be appended to the document.
			   Just commented out since it is not fixed.
			Assert.AreEqual (String.Empty, el1.OwnerDocument.OuterXml);
			*/
		}
Пример #7
0
		public void PropertySetMakesDocumentDifferent ()
		{
			XmlDocument doc = new XmlDocument ();
			doc.LoadXml ("<Object xmlns='http://www.w3.org/2000/09/xmldsig#'>test</Object>");
			DataObject obj = new DataObject ();
			XmlElement el1 = obj.GetXml ();
			obj.LoadXml (doc.DocumentElement);
			obj.Id = "hogehoge";
			XmlElement el2 = obj.GetXml ();
			Assert.IsTrue (doc != el2.OwnerDocument, "Document is not kept when properties are set");
		}
Пример #8
0
		public void GetXmlKeepDocument ()
		{
			XmlDocument doc = new XmlDocument ();
			doc.LoadXml ("<Object xmlns='http://www.w3.org/2000/09/xmldsig#'>test</Object>");
			DataObject obj = new DataObject ();
			XmlElement el1 = obj.GetXml ();
			obj.LoadXml (doc.DocumentElement);
//			obj.Id = "hogehoge";
			XmlElement el2 = obj.GetXml ();
			Assert.AreEqual (doc, el2.OwnerDocument, "Document is kept unless setting properties");
		}
Пример #9
0
		public void InvalidDataObject3 () 
		{
			DataObject obj1 = new DataObject ();
			// seems this isn't invalid !?!
			// but no exception is thrown
			string value = "<Test>Bad</Test>";
			XmlDocument doc = new XmlDocument ();
			doc.LoadXml (value);
			obj1.LoadXml (doc.DocumentElement);
			string s = (obj1.GetXml ().OuterXml);
			Assert.AreEqual (value, s, "DataObject Bad");
		}