Hello,
I am trying to get a LTV enabled signature to work in a deferred signing process but both examples from the documentation do not work and somehow produce an invalid signature.
Please refer to the Ticket at https://www.syncfusion.com/forums/160161/prepare-pdf-hash-to-be-signed-and-sign-externally-with-smart-card-not-on-the-same-system for more information on my implementation.
I know there are two different ways of enabling LTV as explained at https://www.syncfusion.com/forums/154546/pdfsignature-enableltv-vs-createlongtermvalidity.
(1) PdfSignature.EnableLTV = true;
(2) PdfSignature.CreateLongTermValidity(certs)
Here is how I would use (1):
// Create a PdfCertificate instance with X509Certificate2 created from certificates stored on USB tokens or elsewhere (deferred sign - no physical access)
PdfCertificate cert = new PdfCertificate(certificate);
PdfSignature signature = new PdfSignature(loadedDocument, loadedDocument.Pages[0], cert, signatureName);
signature.EnableLtv = true;
Here is how I would use (2):
X509Certificate2 certificate = new X509Certificate2(sig.certificateValue); // sig.certificateValue holds the certificate data sent by client
PdfSignature signature = new PdfSignature(loadedDocument, loadedDocument.Pages[0], null, signatureName);
//Create LTV with public certificates
signature.CreateLongTermValidity(new List<X509Certificate2> { certificate });
Both ways produce the following result in the PDF:
"Signature is invalid", "Document has been altered or corrupted since it was signed"
Please let me know if I am doing something wrong here or if there is another way of enabling LTV in deferred signing of PDF.
Thank you and best regards,
Marko
Hi Gowthamraj,
Thank you for getting back to me.
I have checked the provided sample, and would like to note the differences between having a physical .pfx file accessible on the same system and signing in a deferred process (example: smart card on different system).
In the provided sample you setup the X509Certificate2 and certificate list as follows:
X509Certificate2 digitalID = new X509Certificate2(path, "password");
List<X509Certificate2> certificates = new List<X509Certificate2>();
certificates.Add(digitalID);
I can not do that, as I do not have access to the .pfx file, nor do I have the password, so I do:
X509Certificate2 digitalID = new 509Certificate2(Convert.FromBase64String(sig.certificateValue));
List<X509Certificate2> certificates = new List<X509Certificate2>();
certificates.Add(digitalID);
I would also like to note, that I sign PDF documents in a 2-step deferred process. First the PDF is prepared with an empty signature, and bytes are then signed by a client program. Afterwards the empty signature is replaced with the signed one.
IPdfExternalSigner externalSigner = new ExternalSigner("SHA256", Convert.FromBase64String(sig.base64data));
List<X509Certificate2> publicCertificates = new List<X509Certificate2>();
X509Certificate2 certificate = new X509Certificate2(Convert.FromBase64String(sig.certificateValue));
publicCertificates.Add(certificate);
PdfSignature.ReplaceEmptySignature(inputFileStream, "", outputFileStream, "Signature", externalSigner, publicCertificates);
- Other than LTV, the described process works well and we can successfully sign PDF documents.
Please let me know if there is any more code or information that you would need. The main difference between the sample and how I do it, is that I sign PDF documents in a deferred process.
Best regards,
Marko
|
|
Hi Gowthamraj,
Thank you for the provided sample.
I can confirm that the sample defines the exact process I am using.
There are two differences though. I use the CMS cryptographic standard and SHA256 digest algorithm.
What I can definitely confirm at this point is that my issue is directly connected to missing OCSP/CLR information.
If I sign the same PDF document directly in Adobe Reader DC the text in the Revocation tab of the certificate information says:
"The selected certificate is considered valid because it has not been revoked as verified using the Online Certificate Status Protocol (OCSP) response that was embedded in the signature."
While the text in the revocation tab of the document signed with our code says:
"The selected certificate is considered valid because it has not been revoked as verified in real-time using the Online Certificate Status Protocol (OCSP) obtained on-line."
So from my understanding, the OCSP had to be obtained in real-time online, thus meaning that the document is not LTV enabled, as it does not embed the required OCSP response.
I hope this helps out a bit.
Best regards,
Marko
Hi Marko,
Thank you for your patience.
We confirmed the issue “Signature is invalid while enabling LTV with deferred signing” as a defect in our product. We will include the fix for this issue in our weekly NuGet release, which will be available on October 12th, 2021.
Please use the below feedback link to track the status of the reported bug.
Note: If you require patch for the reported issue in any of our Essential Studio Main or SP release version, then kindly let us know the version, so that we can provide a patch in that version based on our SLA policy.
Please let us know if you need any further assistances in this.
Regards,
Surya V