9 Replies Latest reply on Apr 27, 2016 12:58 PM by IsakTen

    Retrieving signature from CERT or PDF file of signee.

    markv94773548

      How do we return the Name in the signature file? I exported to XML using C# and  no information was in it about the signature. We want to store the signature of each signer of a document we will repeatedly use.Than us his/her name as lookup to refer back to the document he/she signed.  We can store name in a database table with the name of file so pdf could be dynamically be opened by dropdown select.

        • 1. Re: Retrieving signature from CERT or PDF file of signee.
          IsakTen Level 4

          It is very difficult to understand what you're asking. What is the "signature file" you start with? Is it a signed PDF? Have you wrote a program in C# to export, presumably, PDF to XML or did you get the program from someone else?

          Apparently this program did not process the PDF file properly. A digital signature in a PDF is a special type of a form field (see PDF specification). If a program correctly traverses the PDF object tree and writes out all objects it finds, it will write out the content of signature fields.

          From the PDF point of view a Digital Signature in PDF just a Hex string that represents Hex-encoded PKCS#7 object. The program that parses PDF needs to also properly parse the PKSC#7 objects in the signature form fields if you want to extract the certificate with which the signature was signed and the signer's name in it.

          • 2. Re: Retrieving signature from CERT or PDF file of signee.
            markv94773548 Level 1

            I wrote the C# program. When I obtained the XML output from the PDF,  the tabs in the XML were empty even though the
            document had them filled. What I am interested in is getting the name of the
            person who signed the document and storing that info in some data file.  That signature is attached to the Cert file
            with the person’s name associated to it.  I was hoping to either read the name of the
            cert file or the tab would be filled and I could just go to that node and
            obtain the name.  Any suggestions would
            be helpful,

             

            Thanks,

            • 3. Re: Retrieving signature from CERT or PDF file of signee.
              Test Screen Name Most Valuable Participant

              Ah so you wrote the C# program but didn't write the app which made an XML representation of the PDF. There is no standard representation or rule about what should be there.  So, the app you are using to export doesn't export signature info. Probably never intended to, just not a suitable tool for your task. It is, perhaps, a little optimistic to hope that exporting to XML will avoid the need to learn how to parse PDF or use a parser library, when you want such detailed specific info.

              • 4. Re: Retrieving signature from CERT or PDF file of signee.
                markv94773548 Level 1

                Could you direct me to a parsing tool to use? Some add-in from Adobe or third party.

                 

                thanks for your help

                Mark

                • 5. Re: Retrieving signature from CERT or PDF file of signee.
                  IsakTen Level 4

                  If you Google "pdf to xml converter" you'll get many hits for apps that claim that they do that. I doubt that XML they produce is versatile enough for your purposes. My hunch is that at the most you'll get the Hex string that represents the content of the /V entry in the signature form field dictionary.

                  An alternate way to find this Hex string is to open PDF in a text editor and search for a dictionary that represents the signature form field and the /V entry in it (this is what I am doing when I need to examine a signature).

                  If you get this string, then you can do the following:

                  1. Remove any trailing zeros (padding) from the Hex string, Make sure that the Hex string has even number of characters (the last character may be 0 but not a part of the padding).

                  2. Convert the Hex string to binary.

                  3. Use one of the available BER Viewers (Google "ber viewer" to get one) to transform the binary PKCS#7 blob to readable representation.

                  4. Traverse the BER tree to  find the signing certificate and its CN which contains the signer's information.

                  You may need to learn PDF language, PKCS#7 format in order to do that right. If you need to automate this process you need a good PDF parser first and I am not sure how good PDF-to-XML tools are in this regard. Some BER Viewers show you the BER-decoded text on screen but do not save it to a file, which you need in order to automate the process. There is always issue what do to when you have more than one digital signature in a PDF file.

                  • 6. Re: Retrieving signature from CERT or PDF file of signee.
                    IsakTen Level 4

                    First a correction. In my previous posts I called the CMS key in PDF /V. That was an error. The key is /Contents.

                    After thinking more about your problem I found two more solutions that may be easier for you.

                    1. You can use Acrobat JavaScript. You write a JavaScript that loops through all signature fields in a PDF file, gets SignatureInfo object for each signature and the name of the signer property in the SignatureInfo object. Then you can write the PDF filename and signer names to a file.

                    This is the general approach, To automate it you'll place your JavaScript in Acrobat's JavaScripts folder (see Instructions for Installing Folder Level Scripts (Automation Tools) and Plug-ins and https://acrobatusers.com/tutorials/so-where-does-javascript-go-in-acrobat )  and then you can create an Action which will open and close all your PDFs. When each PDF is opened, your JavaScript will be executed.

                    2. If you can extract the /Contents Hex string from a PDF and transform it to a binary you can then write a program using packages like Bouncy Castle (bouncycastle.org ) to write a Java or C# program that would get you a signature's signer. The input to your program will be the Hex /Contents string which your program will convert to binary and then pass it as input to Bouncy Castle method that returns the signer.

                    Neither of the two methods are easy but it is doable.

                    Good luck.

                    • 7. Re: Retrieving signature from CERT or PDF file of signee.
                      markv94773548 Level 1

                      I will attempt to use javascript today and let you know how I did.

                       

                      Thanks,

                      • 8. Re: Retrieving signature from CERT or PDF file of signee.
                        markv94773548 Level 1

                        I was successful in obtaining the name of the signature by putting JavaScript into the form. Now the document was checked out in SharePoint. When it is checked back in I want to place in the signed property the field. Has anyone used JavaScript to communicate with SharePoint?

                         

                        thanks,

                        Mark

                        • 9. Re: Retrieving signature from CERT or PDF file of signee.
                          IsakTen Level 4

                          I do not know. I have not.