Programmatically signing an InfoPath form

M

MarcusRosen

Hi,

I'm attempting to programmatically sign an infopath form (bypassing the
Digital Signing Wizard) but I keep getting an invalid signature error
after the form has been signed.

I'm using the code found in the following two articles, expect for
changing the certificate name and passing the name of the section to be
signed rather than hard-coding it, etc:

Digitally Signing Data in InfoPath 2003
http://msdn.microsoft.com/library/d...2003_ta/html/ODC_INFDigitallySigningData1.asp

Verify and Add Digital Signatures to Form Data in InfoPath 2003 Using
MSXML 5.0 or .NET Framework Managed Code
http://msdn.microsoft.com/library/d...2003_ta/html/ODC_INFDigitallySigningData2.asp

At first I thought maybe my certificate (self-created) was corrupt but
I can sign a form using the digital signing wizard with the same
certificates.

The form has been set up in the following way:

The form has got a section called UserData that has been configured to
be signed with 1 signature through the section properties.

The form has got a button which event handler invokes the OnSign event
like this:

[InfoPathEventHandler(MatchPath="CTRL37",
EventType=InfoPathEventType.OnClick)]
public void CTRL15_5_OnClick(DocActionEvent e)
{

thisXDocument.SignedDataBlocks[0].Sign();
}


My OnSign Event creates an instance of my signaturehelper class,
passing a reference to the infopath document instance, along with the
certificate name and store name and the name of the section to be
signed (for creation of the signature ID). The code inside the external
assembly (SignatureHelper) contains the code from the articles above.

[InfoPathEventHandler(EventType=InfoPathEventType.OnSign)]
public void OnSign(SignEvent e)
{
// create Digital Signature Helper and pass document instance
SignatureHelper helper = new SignatureHelper( ref thisXDocument );
helper.SignForm(e, "My", "mrosen",
thisXDocument.SignedDataBlocks[0].Name);

// Set return status to ignore invoking the Wizard
e.ReturnStatus = true;
}

I have made the form trusted through by using the Macro described in
the InfoPath SDK documentation and I can step through all the code etc.


The code executes fine, no errors occurs but after the code finishes
its execution, the area that normally holds the signature details etc
says "There is a problem with the signature" and clicking to see more
details it comes up with ??? for the certificate name and some of the
properties populated like date of signing etc

I have at this point serialised the instance out to a file and it
contains all the signature sections, with the certificate and other
details.

It seems like the form is modified after it has been signed making the
signature invalid or somthing similar.

Any help would be appreciated as I feel I'm running out of options.

Cheers,
Marcus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top