aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/pdfas/impl
diff options
context:
space:
mode:
authortknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2010-03-16 12:07:29 +0000
committertknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2010-03-16 12:07:29 +0000
commit11b5950be66bcc9d6f0bb28d3fc9d211bc70f4d9 (patch)
tree5a48a33069a318e269245998ecf89b387f331f67 /src/main/java/at/gv/egiz/pdfas/impl
parentda4926845267ca8bedf34917bd3bfb94aeafa153 (diff)
downloadpdf-as-3-11b5950be66bcc9d6f0bb28d3fc9d211bc70f4d9.tar.gz
pdf-as-3-11b5950be66bcc9d6f0bb28d3fc9d211bc70f4d9.tar.bz2
pdf-as-3-11b5950be66bcc9d6f0bb28d3fc9d211bc70f4d9.zip
Catching OutOfMemory exceptions, returning appropriate error message/code
Binary signature: bug concerning indirect pdf objects fixed SignaturePositioning improved (Signature position can be declared by String which is parsed) Some more error codes (Out of memory, Invalid signature position) iText utility for creation of pdf files added ConfigUtils updated (destination of configuration to be extracted can now be chosen) PDFASUtils updated (more tools) WebApplication: Freetext pdf creation implemented WebApplication: XSS security updates git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@580 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java/at/gv/egiz/pdfas/impl')
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java124
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/signator/binary/BinarySignator_1_0_0.java5
2 files changed, 73 insertions, 56 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java b/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java
index 824416f..2ccc1b7 100644
--- a/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java
+++ b/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java
@@ -50,6 +50,7 @@ import at.gv.egiz.pdfas.utils.ConfigUtils;
import at.knowcenter.wag.egov.egiz.PdfAS;
import at.knowcenter.wag.egov.egiz.PdfASID;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
+import at.knowcenter.wag.egov.egiz.exceptions.OutOfMemoryException;
import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
import at.knowcenter.wag.egov.egiz.exceptions.SignatureException;
@@ -240,20 +241,24 @@ public class PdfAsObject implements PdfAs
TablePos pos = PosHelper.formTablePos(signParameters.getSignaturePositioning());
String connectorId = CommandlineConnectorChooser.chooseCommandlineConnectorForSign(signParameters.getSignatureDevice());
-
- SignatorInformation si = PdfAS.signCommandline(
- new PdfDataSourceAdapter(signParameters.getDocument()),
- new DataSinkAdapter(signParameters.getOutput()),
- signatorId,
- connectorId,
- signParameters.getSignatureProfileId(),
- signParameters.getSignatureKeyIdentifier(),
- pos,
- signParameters.getTimeStamperImpl()
- );
-
- return new SignResultImpl(signParameters.getOutput(), si.getSignSignatureObject().getX509Certificate(),
- new ActualSignaturePositionAdapter(si.getActualTablePos()), si.getNonTextualObjects());
+
+ try {
+ SignatorInformation si = PdfAS.signCommandline(
+ new PdfDataSourceAdapter(signParameters.getDocument()),
+ new DataSinkAdapter(signParameters.getOutput()),
+ signatorId,
+ connectorId,
+ signParameters.getSignatureProfileId(),
+ signParameters.getSignatureKeyIdentifier(),
+ pos,
+ signParameters.getTimeStamperImpl()
+ );
+ return new SignResultImpl(signParameters.getOutput(), si.getSignSignatureObject().getX509Certificate(),
+ new ActualSignaturePositionAdapter(si.getActualTablePos()), si.getNonTextualObjects());
+ } catch (java.lang.OutOfMemoryError e) {
+ throw new OutOfMemoryException(ErrorCode.OUT_OF_MEMORY_ERROR, "Insufficient memory allocated to virtual machine. Start Java with parameters \"-Xms128m -Xmx786m -XX:MaxPermSize=256m\".", e);
+ }
+
}
/**
@@ -364,31 +369,35 @@ public class PdfAsObject implements PdfAs
}
assert inputDataSource != null;
- ExtractionStage es = new ExtractionStage();
- List signature_holders = es.extractSignatureHolders(inputDataSource, parameters);
-
-// List sigInfs = new ArrayList(signature_holders.size());
- List sigInfs = new ArrayList();
- List noSigs = new ArrayList();
- Iterator it = signature_holders.iterator();
- while (it.hasNext())
- {
- SignatureHolder sh = (SignatureHolder)it.next();
-
- if(sh instanceof NoSignatureHolder) {
- noSigs.add(sh);
- } else {
-
- SignatureInformation si = new SignatureInformationAdapter(sh);
- sigInfs.add(si);
- if (analyzeParameters.isReturnNonTextualObjects()) {
- si.setNonTextualObjects(doExtractNonTexualObjects(sh, (PdfDataSource) inputDataSource));
- }
-
- }
+ try {
+ ExtractionStage es = new ExtractionStage();
+ List signature_holders = es.extractSignatureHolders(inputDataSource, parameters);
+
+ // List sigInfs = new ArrayList(signature_holders.size());
+ List sigInfs = new ArrayList();
+ List noSigs = new ArrayList();
+ Iterator it = signature_holders.iterator();
+ while (it.hasNext())
+ {
+ SignatureHolder sh = (SignatureHolder)it.next();
+
+ if(sh instanceof NoSignatureHolder) {
+ noSigs.add(sh);
+ } else {
+
+ SignatureInformation si = new SignatureInformationAdapter(sh);
+ sigInfs.add(si);
+ if (analyzeParameters.isReturnNonTextualObjects()) {
+ si.setNonTextualObjects(doExtractNonTexualObjects(sh, (PdfDataSource) inputDataSource));
+ }
+
+ }
+ }
+ return new AnalyzeResultImpl(sigInfs, noSigs);
+ } catch (java.lang.OutOfMemoryError e) {
+ throw new OutOfMemoryException(ErrorCode.OUT_OF_MEMORY_ERROR, "Insufficient memory allocated to virtual machine. Start Java with parameters \"-Xms128m -Xmx786m -XX:MaxPermSize=256m\".", e);
}
- return new AnalyzeResultImpl(sigInfs, noSigs);
}
private List doExtractNonTexualObjects(SignatureHolder sh, PdfDataSource pdfDataSource) {
@@ -433,25 +442,30 @@ public class PdfAsObject implements PdfAs
}
assert signature_holders.size() == signatures.size();
- List results = PdfAS.verifySignatureHolders(signature_holders, verifyAfterAnalysisParameters.getSignatureDevice(), verifyAfterAnalysisParameters.isReturnHashInputData(), verifyAfterAnalysisParameters.getVerificationTime());
-
- List vrs = new ArrayList(results.size());
-
- assert signature_holders.size() == results.size() : "Not all signatures were verified.";
-
- for (int i = 0; i < signature_holders.size(); i++)
- {
- SignatureResponse response = (SignatureResponse) results.get(i);
- SignatureHolder holder = (SignatureHolder) signature_holders.get(i);
-
- VerifyResult vr = new VerifyResultAdapter(response, holder, verifyAfterAnalysisParameters.getVerificationTime());
- vr.setNonTextualObjects( ((SignatureInformation) signatures.get(i)).getNonTextualObjects());
-
- vrs.add(vr);
+ try {
+ List results = PdfAS.verifySignatureHolders(signature_holders, verifyAfterAnalysisParameters.getSignatureDevice(), verifyAfterAnalysisParameters.isReturnHashInputData(), verifyAfterAnalysisParameters.getVerificationTime());
+
+ List vrs = new ArrayList(results.size());
+
+ assert signature_holders.size() == results.size() : "Not all signatures were verified.";
+
+ for (int i = 0; i < signature_holders.size(); i++)
+ {
+ SignatureResponse response = (SignatureResponse) results.get(i);
+ SignatureHolder holder = (SignatureHolder) signature_holders.get(i);
+
+ VerifyResult vr = new VerifyResultAdapter(response, holder, verifyAfterAnalysisParameters.getVerificationTime());
+ vr.setNonTextualObjects( ((SignatureInformation) signatures.get(i)).getNonTextualObjects());
+
+ vrs.add(vr);
+ }
+
+ VerifyResultsImpl verifyResults = new VerifyResultsImpl(vrs);
+ return verifyResults;
+ } catch (java.lang.OutOfMemoryError e) {
+ throw new OutOfMemoryException(ErrorCode.OUT_OF_MEMORY_ERROR, "Insufficient memory allocated to virtual machine. Start Java with parameters \"-Xms128m -Xmx786m -XX:MaxPermSize=256m\".", e);
}
-
- VerifyResultsImpl verifyResults = new VerifyResultsImpl(vrs);
- return verifyResults;
+
}
}
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/signator/binary/BinarySignator_1_0_0.java b/src/main/java/at/gv/egiz/pdfas/impl/signator/binary/BinarySignator_1_0_0.java
index 36d3764..bdb5fdb 100644
--- a/src/main/java/at/gv/egiz/pdfas/impl/signator/binary/BinarySignator_1_0_0.java
+++ b/src/main/java/at/gv/egiz/pdfas/impl/signator/binary/BinarySignator_1_0_0.java
@@ -17,6 +17,7 @@
*/
package at.gv.egiz.pdfas.impl.signator.binary;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -26,6 +27,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -40,6 +42,7 @@ import at.gv.egiz.pdfas.framework.signator.SignatorInformation;
import at.gv.egiz.pdfas.impl.input.CompoundPdfDataSourceImpl;
import at.gv.egiz.pdfas.impl.signator.IncrementalUpdateHelper;
import at.gv.egiz.pdfas.utils.OgnlUtil;
+import at.gv.egiz.pdfas.utils.PDFASUtils;
import at.knowcenter.wag.egov.egiz.PdfAS;
import at.knowcenter.wag.egov.egiz.PdfASID;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
@@ -199,7 +202,7 @@ public class BinarySignator_1_0_0 implements Signator
iui.invisibleKZString = invKZString;
String temp_string = iui.temp_ir_number + " " + iui.temp_ir_generation + " obj"; //$NON-NLS-1$//$NON-NLS-2$
- byte[] temp_bytes = temp_string.getBytes("US-ASCII"); //$NON-NLS-1$
+ byte[] temp_bytes = ArrayUtils.add(temp_string.getBytes("US-ASCII"), 0, (byte) 0x0A);
int temp_start = ByteArrayUtils.lastIndexOf(iui.signed_pdf, temp_bytes);
byte[] stream_bytes = new byte[] { '>', '>', 's', 't', 'r', 'e', 'a', 'm', 0x0A };
int stream_start = ByteArrayUtils.indexOf(iui.signed_pdf, temp_start, stream_bytes);