CreaSign

Verify a Signature of a CreaDoc Document

A CreaDoc document can contain multiple signatures. To verify the signatures, follow these steps:

  1. Load the XML document.
  2. Create a new CreaDoc object and attach it to the document.
  3. If the document contains external references, attach the appropriate resolver.
  4. Call the Verify method.
fileToVerify = "files/signedDataAndVis.xml"
if WScript.Arguments.Count>0 then fileToVerify=WScript.Arguments(0)

set doc=CreateObject("Msxml2.FreeThreadedDOMDocument.4.0")
doc.preserveWhiteSpace=true ' Important!
if not doc.load(fileToVerify) then Err.Raise 8, "" , doc.parseError.reason

' Create a CreaDoc object and attach it to the document set cd = CreateObject("CreaSignClientIE.CreaDoc") set cd.XmlNode=doc.documentElement


' Create a file system resolver, initialize it and attach it to CreaSign ' If there are no external references, you do not need the resolver Set r = CreateObject("CreaSignClientIE.FileSystemResolver") rootPath = Mid(WScript.ScriptFullName,1,InStrRev(WScript.ScriptFullName,"\")) r.RootPath = rootPath
set cd.Resolver = r

set vrs=cd.Verify(0)

Wscript.Echo "Number of signatures: " & vrs.Count
for sig=0 to vrs.Count-1 WScript.Echo vbNewLine & "----- Signature #" & sig+1 & " " & vrs(sig).Source.Id
PrintVerifyResult vrs(sig) PrintHierarchy vrs(sig).Source
Next

See a sample code in "Verify a Signature" for the definition of PrintVerifyResult.

To print a hierarchy of signatures, you can use the SignedBefore and SignedAfter properties.

Sub PrintHierarchy(s)
if s.SignedBefore.Count>0 then
WScript.Echo " The following signatures were created BEFORE this one: "
PrintSignatureList s.SignedBefore
End If
if s.SignedAfter.Count>0 then
WScript.Echo " The following signatures were created AFTER this one: "
PrintSignatureList s.SignedAfter
End If
End Sub
Sub PrintSignatureList(s)
For i=0 to s.Count-1
WScript.Echo " - " & s(i).Id
Next
End Sub

When the document contains a visualisation, you should show it to the user. The following code snippet saves the visualisation to the disk and opens it with the default viewer.

if cd.Visualisations.Count>0 Then

  fn=cd.Visualisations(0).Filename
WScript.Echo
WScript.Echo "Press ENTER to save visualisation to file and open it. File: " & fn
WScript.Echo "WARNING: Abort the program if you do not trust the signer of the message" WScript.Echo "WARNING: Untrusted visualisation might contain a script or program that could damage" WScript.Echo "WARNING: your data" WScript.StdIn.ReadLine

' Save data to disk cd.Visualisations(0).GetEmbeddedData().Save(fn) Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run fn
End If


Send comments on this topic.

(c) Crea 2002-2006