Issue in retrieving pdf Signature Information

Hi,

The attached PDF file cannot be processed by Aspose. The ClassCastException (shown below) happens with 9.0 and 9.3 versions. Is there any workaround for this, in case this is a bug in Aspose.

java.lang.ClassCastException: com.aspose.pdf.kit.oe cannot be cast to com.aspose.pdf.kit.my

at com.aspose.pdf.kit.xa.(Unknown Source)

at com.aspose.pdf.kit.h.(Unknown Source)

at com.aspose.pdf.kit.pd.M(Unknown Source)

at com.aspose.pdf.kit.PdfFileSignature.bindPdf(Unknown Source)

at com.aspose.pdf.kit.PdfFileSignature.bindPdf(Unknown Source)

at gov.nih.era.sciencecv.pdf.metadata.AsposeXMP.verifySignature(AsposeXMP.java:40)

at gov.nih.era.sciencecv.pdf.metadata.AsposeXMP.main(AsposeXMP.java:85)


Regards,
Rajeev

Hi Rajeev,


We are sorry for the inconvenience caused. I am afraid I’m unable to replicate the issue and moreover, your source PDF document has no signature field. Please share your sample code here, we will look into it and will guide you accordingly.

Best Regards,

<span style=“font-size:11.0pt;font-family:“Calibri”,“sans-serif”;
mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-font-family:
“Times New Roman”;color:#1F497D;mso-ansi-language:EN-US;mso-fareast-language:
EN-US;mso-bidi-language:AR-SA”>Hi,

<span style=“font-size:11.0pt;font-family:“Calibri”,“sans-serif”;
mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-font-family:
“Times New Roman”;color:#1F497D;mso-ansi-language:EN-US;mso-fareast-language:
EN-US;mso-bidi-language:AR-SA”>I have attached the code file. You are correct there is no signature in the pdf I provided, but <!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><span style=“font-size:11.0pt;font-family:“Calibri”,“sans-serif”;
mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-font-family:
“Times New Roman”;color:#1F497D;mso-ansi-language:EN-US;mso-fareast-language:
EN-US;mso-bidi-language:AR-SA”>It is our understanding that the function isContainsSignature
should return false in this case. However, the code throws exception in
bindPdf function before we can call isContainsSignature.

Thanks
Rajeev Mathur
<!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman","serif";}

<![endif]–>

Hi Rajeev,

Thanks for sharing your source code. While testing the scenario with the latest version of Aspose.Pdf for Java 9.3.1, we have managed to reproduce the reported issue and logged it in our bug tracking system as PDFNEWJAVA-34377 for further investigation and resolution. We will notify you via this thread as soon as it is resolved.

We are sorry for the inconvenience caused.

Best Regards,

Hi Rajeev,


Thanks for your patience. We have investigated the issue, please note com.aspose.pdf.kit has been migrated to com.aspose.pdf.facades, so please use PdfFileSignature class from com.aspose.pdf.facades package as following

com.aspose.pdf.facades.PdfFileSignature pdfSign = new
com.aspose.pdf.facades.PdfFileSignature();


Moreover, please note getX509Certificate() method is not supported in new merged version of Aspose.Pdf for Java, so this code needs to replace

java.security.cert.X509Certificate pdfCert = pdfSign.getX509Certificate(sv);

by the following code:

InputStream pdfCertStream =
pdfSign.extractCertificate(sv);

byte[] _cert = null;

javax.security.cert.X509Certificate pdfCert = null;

try

{

_cert = new byte[pdfCertStream.available()];

pdfCertStream.read(_cert, 0, pdfCertStream.available());

pdfCert = javax.security.cert.X509Certificate.getInstance(_cert);

} catch (IOException e)

{

e.printStackTrace();

} catch (javax.security.cert.CertificateException e)

{

e.printStackTrace();

}


Please feel free to contact us for any further assistance.


Best Regards,

Hi Tilal,

Thanks for your response, but the above code works fine if the pdf document has been signed by a document and if we need to retrieve the certificate.

But if the pdf file is not signed or signed name is incorrect it throws an error stating the Form field is not available. The error occurs on the following line of code.

InputStream pdfCertStream =
pdfSign.extractCertificate(sv);

Is there a way to find out that the pdf is signed and it is signed by the correct signed name.

Thanks
Rajeev Mathur

Hi Rajeev,


Thanks for your inquiry. Please check following code snippet to check whether a File is signed or not and validate signature as well. Hopefully it will help you to accomplish the task.


PdfFileSignature pdfSign = new PdfFileSignature();<o:p></o:p>

pdfSign.bindPdf(myDir + "DigitalSign_visible.pdf");

List sigNames = pdfSign.getSignNames();

if (sigNames.size() > 0)

{

sigName = (String) sigNames.get(0);

//verify whether sigature is valid or not

if (pdfSign.verifySignature(sigName)) {

System.out.print("Signature Verified");

} else {

System.out.print("Invalid Signature");

}

}

else {

System.out.print("File is Not signed");

}

pdfSign.dispose();


Please feel free to contact us for any further assistance.


Best Regards,

Hi Tilal,

I have attached a document with signature, the verifySignature method always give invalid signature.

Thanks
Rajeev Mathur

Hi Rajeev,


Thanks for your feedback. It seems your document has invalid signature, as when I open the document in Adobe it shows message that “At least one signature has problems.”. I have tested the code with one of my signed document and it shows correct results. Can you please try code with some other PDF file and share the results.

We are sorry for the inconvenience caused.

Best Regards,

The issues you have found earlier (filed as PDFNEWJAVA-34377) have been fixed in Aspose.Pdf for Java 9.5.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan