Using InstallAware to Verify a Signed XML License
Posted: Wed Oct 24, 2007 8:36 am
What is the best way for an InstallAware installer to verify a license key-- which is in the form of a signed xml document?
The scenario is as follows:
1.) User runs the installer which goes to a "license entry" page
2.) User pastes a license key (in the form of a signed xml document) into a field
3.) Installer verifys the license by
a.) xsd validating the xml
b.) signature validating the xml
********************
Following is the VB.NET code we use in the code to signature validate the XML:
' Verify the signature of an XML file against an asymetric algorithm and return the result.
Private Shared Function VerifyXmlDocument(ByVal xmlDocument1 As System.Xml.XmlDocument, _
ByVal key As System.Security.Cryptography.AsymmetricAlgorithm) As Boolean
' Create a new SignedXml object and pass it the XML document class.
Dim signedXml As New System.Security.Cryptography.Xml.SignedXml(xmlDocument1)
' Find the "Signature" node and create a new XmlNodeList object.
Dim nodeList As System.Xml.XmlNodeList = xmlDocument1.GetElementsByTagName(SignatureElement)
' Load the signature node.
signedXml.LoadXml(CType(nodeList(0), System.Xml.XmlElement))
' Check the signature and return the result.
Return signedXml.CheckSignature(key)
End Function
The scenario is as follows:
1.) User runs the installer which goes to a "license entry" page
2.) User pastes a license key (in the form of a signed xml document) into a field
3.) Installer verifys the license by
a.) xsd validating the xml
b.) signature validating the xml
********************
Following is the VB.NET code we use in the code to signature validate the XML:
' Verify the signature of an XML file against an asymetric algorithm and return the result.
Private Shared Function VerifyXmlDocument(ByVal xmlDocument1 As System.Xml.XmlDocument, _
ByVal key As System.Security.Cryptography.AsymmetricAlgorithm) As Boolean
' Create a new SignedXml object and pass it the XML document class.
Dim signedXml As New System.Security.Cryptography.Xml.SignedXml(xmlDocument1)
' Find the "Signature" node and create a new XmlNodeList object.
Dim nodeList As System.Xml.XmlNodeList = xmlDocument1.GetElementsByTagName(SignatureElement)
' Load the signature node.
signedXml.LoadXml(CType(nodeList(0), System.Xml.XmlElement))
' Check the signature and return the result.
Return signedXml.CheckSignature(key)
End Function