Digital Signature/Certificate

PDF-XChange Drivers API (only) V4/V5
This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-XChange Printer Drivers SDK (only) - VERSION 4 & 5 - Please use the PDF-Tools SDK Forum for Library DLL assistance.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan

Post Reply
Guillermo
User
Posts: 13
Joined: Thu Apr 24, 2014 3:58 pm

Digital Signature/Certificate

Post by Guillermo » Tue Jan 10, 2017 3:28 pm

:roll: Sorry if repeated, I think I replied an old topic (http://www.tracker-software.com/forum3/ ... 39&t=22906), dup here for clarity:

Hi to All!

I would like the code sample for Digital Signature in vb.net or vb6, thus signing and how to convert the hash text to binary in order to pass the info to the driver.

This code in the related post...

Code: Select all

m_pPrinter->Option[L"Digisig.Enabled"]	= TRUE;
const char *hash="\xa2\xaa\xa1\x4e\xca\x9d\x3c\xee\xf1\x2b\x6b\xf4\x2f\x4f\x6c\x86\x0d\x5e\xf3\xf1";
m_pPrinter->Option[L"Digisig.Hash"]	= hash;
m_pPrinter->ApplyOptions(0);
And this comment:
To specify binary data, you can pass them as a SAFEARRAY or BSTR.
Also, as some people has commented, there is an error in the name, sometimes DigSig and others DigiSig
http://help.tracker-software.com/DEV/de ... natures.29
(not sure if linking help pages works)
please see the attached image
Image

Thanks in advance.
Happy new year!

Guillermo
User
Posts: 13
Joined: Thu Apr 24, 2014 3:58 pm

Re: Digital Signature/Certificate

Post by Guillermo » Wed Jan 11, 2017 7:05 pm

Try to explain a little more the task.

I have string of hex values provided by the certificate (the hash/sha1/thumb...) as

Code: Select all

40 cd dd 28 ae 91 60 2e dd 74 e3 09 bc 5e 09 8f 84 58 77 b7
or
9D 62 47 14 C7 6F B3 A1 65 75 E2 15 04 77 9F 4A 77 F2 31 DB
and so on
Thus, 20 hex values in a string with or without blanks separators, blanks will be removed obviously.

But your Hash property "possible value" (¿DataType?) requires "BINARY"
"Hash Binary This property specifies the hash value of the certificate to be used for signing the document."

Nice if this property (or other as HashString...) would be capable to move the 40char string,
but not, then
¿how can convert/format the 20hex string to your "binary" hash property?

:shock: Urgent, as usual.

Thanks.
Guillermo.

Ivan - Tracker Software
Site Admin
Posts: 3607
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Digital Signature/Certificate

Post by Ivan - Tracker Software » Fri Jan 13, 2017 6:09 pm

Right now, DigiSig.Hash can be set using SAFEARRAY or Byte BSTR (see SysAllocStringByteLen).
Your proposal to use hex string is excellent, thanks, and I will implement it in a new build.

Right now you can use byte BSTR as I mentioned above, or use save array:

Code: Select all

#include <atlsafe.h>
// ...
        CComSafeArray<BYTE> arrHash;
        int nLen = strlen(hash);
        HRESULT hr = arrHash.Create(nLen);
        if (FAILED(hr))
                return hr;
        memcpy(arrHash.m_psa->pvData, hash, nLen);
        CComVariant vHash(arrHash);
        m_pPrinter->Option[L"DigiSig.Hash"] = vHash;
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.

Guillermo
User
Posts: 13
Joined: Thu Apr 24, 2014 3:58 pm

Re: Digital Signature/Certificate

Post by Guillermo » Thu Feb 09, 2017 3:02 pm

Ivan - Tracker Software wrote:Right now, DigiSig.Hash can be set using SAFEARRAY or Byte BSTR (see SysAllocStringByteLen).
Your proposal to use hex string is excellent, thanks, and I will implement it in a new build.

Right now you can use byte BSTR as I mentioned above, or use save array:

Code: Select all

#include <atlsafe.h>
// ...
        CComSafeArray<BYTE> arrHash;
        int nLen = strlen(hash);
        HRESULT hr = arrHash.Create(nLen);
        if (FAILED(hr))
                return hr;
        memcpy(arrHash.m_psa->pvData, hash, nLen);
        CComVariant vHash(arrHash);
        m_pPrinter->Option[L"DigiSig.Hash"] = vHash;
Sorry but we are unable to get it working, now the customer want to try implement in an very old vb6 program.

¿There is a way to simplify this code?
Would be great if I could pass the hash as an hex string as the original can be viewed in the certificate info.

Thanks.

Guillermo
User
Posts: 13
Joined: Thu Apr 24, 2014 3:58 pm

Re: Digital Signature/Certificate

Post by Guillermo » Fri Feb 10, 2017 8:53 pm

¿There is any way to know if the hash passed to Digisig.Hash was successful?
I think the only way is manually open the generated pdf and look for the signature.
Using pdfXchange Editor you can see info about signature i the header, but I would like to show a error window if the pdf was not signed.

¿any event or way to know in the program if the sign was applied or not or any error?

Thanks.

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13424
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Digital Signature/Certificate

Post by Tracker Supp-Stefan » Mon May 08, 2017 12:53 pm

Hello Guillermo,

I've passed this to Ivan, who will follow up a bit later (it's still the middle of the night where he is).

Regards,
Stefan

Guillermo
User
Posts: 13
Joined: Thu Apr 24, 2014 3:58 pm

Re: Digital Signature/Certificate

Post by Guillermo » Mon May 08, 2017 1:57 pm

Tracker Supp-Stefan wrote:Hello Guillermo,
I've passed this to Ivan, who will follow up a bit later (it's still the middle of the night where he is).
Regards,
Stefan
Hi Stefan,
These can be an fine improvement, along with a simple way to call with hex-string text and you made the convertion internally.
Also the way the signature is printed will be better, in a way more similar to how you sign documents using pdfXchange editor (square with border, colors, fonts...)

I finally was using sign from code but a bit spartan/plain.

Best regards,
Guillermo.

Ivan - Tracker Software
Site Admin
Posts: 3607
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Digital Signature/Certificate

Post by Ivan - Tracker Software » Mon May 08, 2017 4:42 pm

put_Options will return an error (or wrapper Options will generate an exception) only when you pass the wrong type of variant. But this method does not validate the value that has been passed.

In a case of "DigiSig.Hash" if you pass a proper hash value (in either way - BSTR or SaveArray), put_Options will return S_OK without checking if there is digital certificated with such hash value.
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.

Guillermo
User
Posts: 13
Joined: Thu Apr 24, 2014 3:58 pm

Re: Digital Signature/Certificate

Post by Guillermo » Mon May 08, 2017 7:24 pm

Ivan - Tracker Software wrote:put_Options will return an error (or wrapper Options will generate an exception) only when you pass the wrong type of variant. But this method does not validate the value that has been passed.
In a case of "DigiSig.Hash" if you pass a proper hash value (in either way - BSTR or SaveArray), put_Options will return S_OK without checking if there is digital certificated with such hash value.
if I understand correctly
no way to know if the document was really signed.

Ivan - Tracker Software
Site Admin
Posts: 3607
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Digital Signature/Certificate

Post by Ivan - Tracker Software » Tue May 09, 2017 6:49 pm

You right. Document is signed at the moment of saving file on a disk, not when the option is set.
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.

Post Reply