From 4d5019da1d4c1f3a3cfa7097300c4962879f3868 Mon Sep 17 00:00:00 2001 From: Christian Maierhofer Date: Mon, 20 Apr 2015 15:14:26 +0200 Subject: pdf/ua docs - added parameter in profiles --- .../java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java | 2 ++ .../gv/egiz/pdfas/common/settings/SignatureProfileSettings.java | 9 +++++++++ 2 files changed, 11 insertions(+) (limited to 'pdf-as-common/src') diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java index 6cdfa0b3..2c2b941b 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java @@ -92,4 +92,6 @@ public interface IProfileConstants { public final static String SIGNFIELD_VALUE = "adobeSignFieldValue"; public final static String TIMEZONE_BASE = "timezone"; public final static String SIG_PDFA1B_VALID = "SIG_PDFA1B_VALID"; + public final static String SIG_PDFUA_FORCE = "SIG_PDFUA_FORCE"; + } diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java index dc1250fb..cbc1d601 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java @@ -212,4 +212,13 @@ public class SignatureProfileSettings implements IProfileConstants { } return false; } + + public boolean isPDFUA() { + SignatureProfileEntry entry = profileInformations.get(SIG_PDFUA_FORCE); + if (entry != null) { + String value = entry.getCaption(); + return "true".equals(value); + } + return false; + } } -- cgit v1.2.3 From 38b9dbc224d7be54dba23d04529df07f6fd0db51 Mon Sep 17 00:00:00 2001 From: Christian Maierhofer Date: Thu, 23 Apr 2015 09:50:54 +0200 Subject: error handling --- .../resources/resources/messages/common.properties | 1 + .../lib/impl/signing/pdfbox/PADESPDFBOXSigner.java | 153 +++++++++++---------- 2 files changed, 78 insertions(+), 76 deletions(-) (limited to 'pdf-as-common/src') diff --git a/pdf-as-common/src/main/resources/resources/messages/common.properties b/pdf-as-common/src/main/resources/resources/messages/common.properties index 19371573..8ddfe312 100644 --- a/pdf-as-common/src/main/resources/resources/messages/common.properties +++ b/pdf-as-common/src/main/resources/resources/messages/common.properties @@ -44,6 +44,7 @@ error.pdf.sig.15=Keystore password is null error.pdf.sig.16=Keyentry password is null error.pdf.sig.17=Failed to retrieve certificate error.pdf.sig.18=Given Alias contains no private key +error.pdf.sig.pdfua.1=Could not create PDF-UA conform document #Signature verification errors error.pdf.verify.01=No signed data available diff --git a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java index fcea384a..250d1242 100644 --- a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java +++ b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java @@ -477,95 +477,96 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { } // PDF-UA - if (signatureProfileSettings.isPDFUA()==true) { - logger.info("Adding pdf/ua content."); - try{ - PDDocumentCatalog root = doc.getDocumentCatalog(); - PDStructureTreeRoot treeRoot = root.getStructureTreeRoot(); + logger.info("Adding pdf/ua content."); + try{ + PDDocumentCatalog root = doc.getDocumentCatalog(); + PDStructureTreeRoot treeRoot = root.getStructureTreeRoot(); - if (treeRoot != null) { //check if structure tree available in pdf document - logger.info("Tree Root: {}", treeRoot.toString()); - List kids = treeRoot.getKids(); + logger.info("Tree Root: {}", treeRoot.toString()); + List kids = treeRoot.getKids(); - if(kids==null){ - logger.info("No kid-elements in structure tree Root, maybe not PDF/UA document"); - } + if(kids==null){ + logger.info("No kid-elements in structure tree Root, maybe not PDF/UA document"); + } - PDStructureElement docElement = null; - for(Object k: kids){ - if(k instanceof PDStructureElement){ - docElement=(PDStructureElement) k; - break; - // if(((PDStructureElement) k).getStructureType().equals("Document")){ - // docElement=(PDStructureElement) k; - // } - } - } + PDStructureElement docElement = null; + for(Object k: kids){ + if(k instanceof PDStructureElement){ + docElement=(PDStructureElement) k; + break; + // if(((PDStructureElement) k).getStructureType().equals("Document")){ + // docElement=(PDStructureElement) k; + // } + } + } - PDStructureElement sigBlock = new PDStructureElement( - "Form", docElement); + PDStructureElement sigBlock = new PDStructureElement( + "Form", docElement); - //create object dictionary and add as child element - COSDictionary objectdic= new COSDictionary(); - objectdic.setName("Type", "OBJR"); - objectdic.setItem("Pg", signatureField.getWidget().getPage()); - objectdic.setItem("Obj", signatureField.getWidget()); + //create object dictionary and add as child element + COSDictionary objectdic= new COSDictionary(); + objectdic.setName("Type", "OBJR"); + objectdic.setItem("Pg", signatureField.getWidget().getPage()); + objectdic.setItem("Obj", signatureField.getWidget()); - List l = new ArrayList(); - l.add(objectdic); - sigBlock.setKids(l); + List l = new ArrayList(); + l.add(objectdic); + sigBlock.setKids(l); - sigBlock.setTitle("Signature Table"); - sigBlock.setParent(docElement); - docElement.appendKid(sigBlock); + sigBlock.setTitle("Signature Table"); + sigBlock.setParent(docElement); + docElement.appendKid(sigBlock); - //Create and add Attribute dictionary to mitigate PAC warning - COSDictionary sigBlockDic = (COSDictionary) sigBlock.getCOSObject(); - COSDictionary sub = new COSDictionary(); + //Create and add Attribute dictionary to mitigate PAC warning + COSDictionary sigBlockDic = (COSDictionary) sigBlock.getCOSObject(); + COSDictionary sub = new COSDictionary(); - sub.setName("O", "Layout"); - sub.setName("Placement", "Block"); - sigBlockDic.setItem(COSName.A, sub); - sigBlockDic.setNeedToBeUpdate(true); + sub.setName("O", "Layout"); + sub.setName("Placement", "Block"); + sigBlockDic.setItem(COSName.A, sub); + sigBlockDic.setNeedToBeUpdate(true); - //Modify number tree - PDNumberTreeNode ntn = treeRoot.getParentTree(); - if(ntn==null){ - ntn = new PDNumberTreeNode(objectdic, null); - logger.info("No number-tree-node found!"); - } + //Modify number tree + PDNumberTreeNode ntn = treeRoot.getParentTree(); + if(ntn==null){ + ntn = new PDNumberTreeNode(objectdic, null); + logger.info("No number-tree-node found!"); + } - COSDictionary ntndic=ntn.getCOSDictionary(); - COSArray ntndicnumbersarray = (COSArray)ntndic.getDictionaryObject(COSName.NUMS); - int arrindex = ntndicnumbersarray.size(); - int treeindex = arrindex/2; - - ntndicnumbersarray.add(arrindex, COSInteger.get(treeindex)); - ntndicnumbersarray.add(arrindex+1, sigBlock.getCOSObject()); - - treeRoot.setParentTree(ntn); - treeRoot.setParentTreeNextKey(treeindex+1); - - //setStructureParent - PDAnnotationWidget widg=signatureField.getWidget(); - widg.setStructParent(treeindex); - - //add the Tabs /S Element for Tabbing through annots - PDPage p = signatureField.getWidget().getPage(); - p.getCOSDictionary().setName("Tabs", "S"); - p.getCOSObject().setNeedToBeUpdate(true); - - ntndic.setNeedToBeUpdate(true); - sigBlock.getCOSObject().setNeedToBeUpdate(true); - treeRoot.getCOSObject().setNeedToBeUpdate(true); - objectdic.getCOSObject().setNeedToBeUpdate(true); - docElement.getCOSObject().setNeedToBeUpdate(true); - - } - }catch(Exception e){ + COSDictionary ntndic=ntn.getCOSDictionary(); + COSArray ntndicnumbersarray = (COSArray)ntndic.getDictionaryObject(COSName.NUMS); + int arrindex = ntndicnumbersarray.size(); + int treeindex = arrindex/2; + + ntndicnumbersarray.add(arrindex, COSInteger.get(treeindex)); + ntndicnumbersarray.add(arrindex+1, sigBlock.getCOSObject()); + + treeRoot.setParentTree(ntn); + treeRoot.setParentTreeNextKey(treeindex+1); + + //setStructureParent + PDAnnotationWidget widg=signatureField.getWidget(); + widg.setStructParent(treeindex); + + //add the Tabs /S Element for Tabbing through annots + PDPage p = signatureField.getWidget().getPage(); + p.getCOSDictionary().setName("Tabs", "S"); + p.getCOSObject().setNeedToBeUpdate(true); + + ntndic.setNeedToBeUpdate(true); + sigBlock.getCOSObject().setNeedToBeUpdate(true); + treeRoot.getCOSObject().setNeedToBeUpdate(true); + objectdic.getCOSObject().setNeedToBeUpdate(true); + docElement.getCOSObject().setNeedToBeUpdate(true); + + + }catch(Throwable e){ + if (signatureProfileSettings.isPDFUA()==true){ logger.error("Could not create PDF-UA conform document!"); - logger.error(e.getMessage()); + throw new PdfAsException("error.pdf.sig.pdfua.1", e); + }else{ + logger.info("Could not create PDF-UA conform signature"); } } -- cgit v1.2.3