EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Invalid PDF signature on OS X

Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages
#35013
Posted: 11/13/2015 09:26:08
by David ErÅ¡il (Standard support level)
Joined: 01/15/2013
Posts: 34

Dear SBB support,
We are currently implementing PDF signature tool that uses your C++ library for OS X. Unfortunately the pdf produced is broken and does not contain the signature. Below is the code snippet, we use to sign pdf. During the signing process, no exception is thrown.

Please rename attached signed.txt to signed.pdf for reference.

We would really appreciate any advice.

Code
  NSData* derCert; // X509 struct in DER format
  NSData* binKey; //private key in PEM format, not binary as the name could associate

  std::fstream fs;
    fs.open(path.UTF8String, std::ios::binary | std::ios::in | std::ios::out);

    if(!fs.is_open())
        return nil;

    SecureBlackbox::TElCallbackStream cs(fs);
    SecureBlackbox::TElPDFDocument Document(NULL);
    try
    {
        Document.Open(cs);
        if (Document.get_Encrypted())
        {
            std::cout << "The document is encrypted and cannot be signed" << std::endl;
            Document.Close(false);
            return nil;
        }

        SecureBlackbox::TElPDFPublicKeySecurityHandler PublicKeyHandler(NULL);
        int index = Document.AddSignature();
        SecureBlackbox::TElPDFSignature *Sig = Document.get_Signatures(index);
        Sig->set_Handler(PublicKeyHandler);

        time_t timer;
        time(&timer);
        Sig->set_SigningTime(timer);
        Sig->set_EmptyField(false);
        Sig->set_SignatureType(SecureBlackbox::stDocument);

        SecureBlackbox::TElX509Certificate Cert(NULL);

        Cert.LoadFromBufferAuto((void*)derCert.bytes, (int)derCert.length, "");
        Cert.LoadKeyFromBufferAuto((void*)binKey.bytes, (int)binKey.length, "12345Software602Passphrase!@#$%");

        SecureBlackbox::TElMemoryCertStorage CertStorage(NULL);
        CertStorage.Add(Cert, true);

        PublicKeyHandler.set_CertStorage(CertStorage);
PublicKeyHandler.set_SignatureType(SecureBlackbox::pstPKCS7SHA1);
        PublicKeyHandler.set_CustomName("Adobe.PPKMS");

        Document.Close(true);
    }


[ Download ]
#35014
Posted: 11/13/2015 09:54:16
by Dmytro Bogatskyy (EldoS Corp.)

Thank you for contacting us.

Quote
Unfortunately the pdf produced is broken and does not contain the signature. Below is the code snippet, we use to sign pdf. During the signing process, no exception is thrown.

It seems that the file is truncated. Do you call fstream::close() method after Document.Close()?
For example:
Code
fs.close();

Reply

Statistics

Topic viewed 661 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!