Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / March 2008

Tip: Looking for answers? Try searching our database.

dsig prefix

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ken Lemieux - 03 Mar 2008 16:08 GMT
Hi,

I have a Clickonce application that contains a file element:

 <file name="Properties\Resources\wecan32.ico" size="3262">
   <hash>
     <dsig:Transforms>
       <dsig:Transform
Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
     </dsig:Transforms>
     <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
     <dsig:DigestValue>hKQC+HwduEy3n7PERz4GD3tPgME=</dsig:DigestValue>
   </hash>
 </file>

I've coded a routine that tries to duplicate the above XmlNode:

      void FormFileAssociationCreator_IconFileElementEvent(object sender,
ResultsEventArgs e)
       {
           Cursor = Cursors.WaitCursor;
buildOutput.AppendLine(Resources.CreatingIconElement);
           XmlDocument applicationManifestDoc = new XmlDocument();

           try
           {
               textBoxOutput.Text =
buildOutput.AppendLine(Resources.AddingIconFileElement).ToString();
               applicationManifestDoc.Load(comboBoxApplicationManifest.Text);
               XmlNamespaceManager namespaceManager;
               namespaceManager = new XmlNamespaceManager(new NameTable());
               namespaceManager.AddNamespace("asmv1",
"urn:schemas-microsoft-com:asm.v1");
               namespaceManager.AddNamespace("asmv2",
"urn:schemas-microsoft-com:asm.v2");

               XmlNode applicationNode =
applicationManifestDoc.SelectSingleNode("/asmv1:assembly/asmv2:application",
namespaceManager);

               //create the icon node and add it following the application
node
               XmlNode iconNode = CreateIconElement(applicationManifestDoc);
               applicationNode.ParentNode.InsertAfter(iconNode,
applicationNode);

               XmlNode hashNode =
applicationManifestDoc.CreateNode(XmlNodeType.Element, "hash", null);
               iconNode.AppendChild(hashNode);
               XmlNode transformsNode =
applicationManifestDoc.CreateNode(XmlNodeType.Element, @"dsig:Transforms",
null);
               hashNode.AppendChild(transformsNode);
               XmlNode transformNode =
applicationManifestDoc.CreateNode(XmlNodeType.Element, @"dsig:Transform",
null);
               XmlNode transformAlgorithmAttrib =
applicationManifestDoc.CreateNode(XmlNodeType.Attribute, "Algorithm", null);
               transformAlgorithmAttrib.Value =
"urn:schemas-microsoft-com:HashTransforms.Identity";
               
transformNode.Attributes.SetNamedItem(transformAlgorithmAttrib);
               transformsNode.AppendChild(transformNode);
               XmlNode digestMethodNode =
applicationManifestDoc.CreateNode(XmlNodeType.Element, @"dsig:DigestMethod",
null);
               XmlNode digestMethodAttrib =
applicationManifestDoc.CreateNode(XmlNodeType.Attribute, "Algorithm", null);
               digestMethodAttrib.Value =
"http://www.w3.org/2000/09/xmldsig#sha1";
               digestMethodNode.Attributes.SetNamedItem(digestMethodAttrib);
               hashNode.AppendChild(digestMethodNode);
               XmlNode digestValueNode =
applicationManifestDoc.CreateNode(XmlNodeType.Element, @"dsig:DigestValue",
null);
               hashNode.AppendChild(digestValueNode);
               XmlNode digestValueTextNode =
applicationManifestDoc.CreateNode(XmlNodeType.Text, @"dsig:DigestValue",
null);
               hashNode.AppendChild(digestValueTextNode);

               FileInfo iconFileInfo = new
FileInfo(comboBoxIconFile.SelectedItem.ToString());
               Stream iconStream = iconFileInfo.OpenRead();
               SHA1Managed iconHash = new SHA1Managed();
               byte[] iconHashBytes = iconHash.ComputeHash(iconStream);

               digestValueTextNode.Value =
Convert.ToBase64String(iconHashBytes);

               applicationManifestDoc.Save(comboBoxApplicationManifest.Text);
               textBoxOutput.Text =
buildOutput.AppendLine(Resources.AddedIconFileElement).ToString();
           }

My out put is nearly whats expected except absent is the dsig: prefix on the
hash elements nodes:

 <file name="\Properties\Resources\wecan32.ico" size="3262" xmlns="">
   <hash>
     <Transforms>
       <Transform
Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
     </Transforms>
     <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
     <DigestValue />hKQC+HwduEy3n7PERz4GD3tPgME=
   </hash>
 </file>

So my question is how can my impementation be changed so dsig: prefix is
added?
Signature

Kenneth Lemieux
Project Engineer
Whelen Engineering Co., Inc.

Martin Honnen - 03 Mar 2008 17:30 GMT
> I have a Clickonce application that contains a file element:
>
[quoted text clipped - 8 lines]
>     </hash>
>   </file>

That is an excerpt from an XML document, you need to check which
namespace URI the prefix dsig is bound to on the ancestor(s) of the
dsig:Transform element. Use that namespace URI to create elements in
that namespace e.g. assuming the namespace URI is
http://example.com/dsig then you need

>                 XmlNode transformsNode =
> applicationManifestDoc.CreateNode(XmlNodeType.Element, @"dsig:Transforms",
> null);

  const string dsig = "http://example.com/dsig";

  XmlElement transforms = applicationManifestDoc.CreateElement("dsig",
"Transforms", dsig);
>                 hashNode.AppendChild(transformsNode);
>                 XmlNode transformNode =
> applicationManifestDoc.CreateNode(XmlNodeType.Element, @"dsig:Transform",
> null);

Same here
  XmlElement transforms = applicationManifestDoc.CreateElement("dsig",
"Transform", dsig);

Then apply the same changes to the other elements you need to create in
that namespace.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

Ken Lemieux - 03 Mar 2008 21:03 GMT
Thanks Martin, your post answered my question perfectly.

One more question if I may, Could and would you recommend a comprehensive
book on Xml. I'm particular intrested in securing the xml data and its
applications.

Thanks again.
Signature

Kenneth Lemieux
Project Engineer
Whelen Engineering Co., Inc.

> > I have a Clickonce application that contains a file element:
> >
[quoted text clipped - 34 lines]
> Then apply the same changes to the other elements you need to create in
> that namespace.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.