aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/pdfas/impl
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/gv/egiz/pdfas/impl')
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java167
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/xmldsig/XMLDsigReconstructor.java53
2 files changed, 188 insertions, 32 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 2923347..c5322e7 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
@@ -24,9 +24,15 @@ import at.gv.egiz.pdfas.api.exceptions.PdfAsException;
import at.gv.egiz.pdfas.api.sign.SignParameters;
import at.gv.egiz.pdfas.api.sign.SignResult;
import at.gv.egiz.pdfas.api.verify.VerifyAfterAnalysisParameters;
+import at.gv.egiz.pdfas.api.verify.VerifyAfterReconstructXMLDsigParameters;
import at.gv.egiz.pdfas.api.verify.VerifyParameters;
import at.gv.egiz.pdfas.api.verify.VerifyResult;
import at.gv.egiz.pdfas.api.verify.VerifyResults;
+import at.gv.egiz.pdfas.api.xmldsig.ExtendedSignatureInformation;
+import at.gv.egiz.pdfas.api.xmldsig.ReconstructXMLDsigAfterAnalysisParameters;
+import at.gv.egiz.pdfas.api.xmldsig.ReconstructXMLDsigParameters;
+import at.gv.egiz.pdfas.api.xmldsig.ReconstructXMLDsigResult;
+import at.gv.egiz.pdfas.api.xmldsig.XMLDsigData;
import at.gv.egiz.pdfas.commandline.CommandlineConnectorChooser;
import at.gv.egiz.pdfas.exceptions.ErrorCode;
import at.gv.egiz.pdfas.framework.config.SettingsHelper;
@@ -46,6 +52,10 @@ import at.gv.egiz.pdfas.impl.api.verify.VerifyResultAdapter;
import at.gv.egiz.pdfas.impl.api.verify.VerifyResultsImpl;
import at.gv.egiz.pdfas.impl.input.DelimitedPdfDataSource;
import at.gv.egiz.pdfas.impl.vfilter.VerificationFilterParametersImpl;
+import at.gv.egiz.pdfas.impl.xmldsig.XMLDsigReconstructor;
+import at.gv.egiz.pdfas.placeholder.SignaturePlaceholderContext;
+import at.gv.egiz.pdfas.placeholder.SignaturePlaceholderData;
+import at.gv.egiz.pdfas.placeholder.SignaturePlaceholderExtractor;
import at.gv.egiz.pdfas.utils.ConfigUtils;
import at.knowcenter.wag.egov.egiz.PdfAS;
import at.knowcenter.wag.egov.egiz.PdfASID;
@@ -72,6 +82,7 @@ import at.knowcenter.wag.egov.egiz.sig.SignatureTypes;
*/
public class PdfAsObject implements PdfAs
{
+//23.11.2010 changed by exthex - added methods for reconstructXMLDsig
/**
* The log.
@@ -250,6 +261,21 @@ public class PdfAsObject implements PdfAs
signParameters.setDocument(PdfAS.applyStrictMode(signParameters.getDocument()));
+ SignaturePlaceholderData spd = null;
+ SignaturePlaceholderContext.setSignaturePlaceholderData(null);
+ if (signParameters.isCheckForPlaceholder()) {
+ spd = SignaturePlaceholderExtractor.extract(signParameters.getDocument().createInputStream(), signParameters.getPlaceholderId(), signParameters.getPlaceholderMatchMode());
+ if (spd != null){
+ if (spd.getProfile() != null)
+ signParameters.setSignatureProfileId(spd.getProfile());
+ if (spd.getType() != null)
+ signParameters.setSignatureType(spd.getType());
+ if (spd.getKey() != null)
+ signParameters.setSignatureKeyIdentifier(spd.getKey());
+ }
+ }
+ CheckHelper.checkSignParameters(signParameters);
+
if (signParameters.getSignatureProfileId() == null)
{
SettingsReader settings = SettingsReader.getInstance();
@@ -271,7 +297,11 @@ public class PdfAsObject implements PdfAs
signatorId = SignatorFactory.MOST_RECENT_DETACHEDTEXT_SIGNATOR_ID;
}
- TablePos pos = PosHelper.formTablePos(signParameters.getSignaturePositioning());
+ TablePos pos = null;
+ if (spd != null && spd.getTablePos() != null)
+ pos = spd.getTablePos();
+ else
+ pos = PosHelper.formTablePos(signParameters.getSignaturePositioning());
String connectorId = CommandlineConnectorChooser.chooseCommandlineConnectorForSign(signParameters.getSignatureDevice());
@@ -344,6 +374,13 @@ public class PdfAsObject implements PdfAs
ap.setReturnNonTextualObjects(vp.isReturnNonTextualObjects());
}
+ protected void fillAnalyzeParametersWithReconstructXMLDsigParameters(AnalyzeParameters ap, ReconstructXMLDsigParameters rxp)
+ {
+ ap.setDocument(rxp.getDocument());
+ ap.setVerifyMode(rxp.getVerifyMode());
+ ap.setReturnNonTextualObjects(rxp.isReturnNonTextualObjects());
+ }
+
/**
* Copies all adequate parameters from the {@link VerifyParameters} to the
* {@link VerifyAfterAnalysisParameters}.
@@ -360,6 +397,16 @@ public class PdfAsObject implements PdfAs
vaap.setReturnHashInputData(vp.isReturnHashInputData());
}
+
+ protected void fillReconstructXMLDsigAfterAnalysisParametersWithVerifyAfterAnalysisParameters(
+ ReconstructXMLDsigAfterAnalysisParameters reconstructParams,
+ VerifyAfterAnalysisParameters verifyAfterAnalysisParameters) {
+ reconstructParams.setAnalyzeResult(verifyAfterAnalysisParameters.getAnalyzeResult());
+ reconstructParams.setReturnHashInputData(verifyAfterAnalysisParameters.isReturnHashInputData());
+ reconstructParams.setSignatureDevice(verifyAfterAnalysisParameters.getSignatureDevice());
+ reconstructParams.setVerificationTime(verifyAfterAnalysisParameters.getVerificationTime());
+ }
+
/**
* @see at.gv.egiz.pdfas.api.PdfAs#analyze(at.gv.egiz.pdfas.api.analyze.AnalyzeParameters)
*/
@@ -465,40 +512,96 @@ public class PdfAsObject implements PdfAs
throw new PDFDocumentException(ErrorCode.DOCUMENT_NOT_SIGNED, "PDF document not signed."); //$NON-NLS-1$
}
- List signature_holders = new ArrayList(signatures.size());
- Iterator it = signatures.iterator();
- while (it.hasNext())
- {
- SignatureInformation si = (SignatureInformation) it.next();
- SignatureHolder sh = (SignatureHolder) si.getInternalSignatureInformation();
- signature_holders.add(sh);
- }
- assert signature_holders.size() == signatures.size();
+ ReconstructXMLDsigAfterAnalysisParameters rxaap = new ReconstructXMLDsigAfterAnalysisParameters();
+ fillReconstructXMLDsigAfterAnalysisParametersWithVerifyAfterAnalysisParameters(rxaap, verifyAfterAnalysisParameters);
+ ReconstructXMLDsigResult reconstructResult = reconstructXMLDSIG(rxaap);
- 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);
- }
+ VerifyAfterReconstructXMLDsigParameters varxp = new VerifyAfterReconstructXMLDsigParameters();
+ fillVerifyAfterReconstructXMLDsigParametersWithVerifyAfterAnalysisParameters(varxp, verifyAfterAnalysisParameters);
+ varxp.setReconstructXMLDsigResult(reconstructResult);
+
+ return verify(varxp);
- 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);
+ }
+
+ protected void fillVerifyAfterReconstructXMLDsigParametersWithVerifyAfterAnalysisParameters(
+ VerifyAfterReconstructXMLDsigParameters varxp,
+ VerifyAfterAnalysisParameters verifyAfterAnalysisParameters) {
+ varxp.setReturnHashInputData(verifyAfterAnalysisParameters.isReturnHashInputData());
+ varxp.setSignatureDevice(verifyAfterAnalysisParameters.getSignatureDevice());
+ varxp.setVerificationTime(verifyAfterAnalysisParameters.getVerificationTime());
+ }
+
+ public ReconstructXMLDsigResult reconstructXMLDSIG(
+ ReconstructXMLDsigParameters reconstructXMLDsigParameters)
+ throws PdfAsException {
+
+ AnalyzeParameters analyzeParameters = new AnalyzeParameters();
+ fillAnalyzeParametersWithReconstructXMLDsigParameters(analyzeParameters, reconstructXMLDsigParameters);
+ AnalyzeResult ar = analyze(analyzeParameters);
+
+ ReconstructXMLDsigAfterAnalysisParameters rxaap = new ReconstructXMLDsigAfterAnalysisParameters();
+ fillReconstructXMLDsigAfterAnalysisParametersWithReconstructXMLDsigParameters(rxaap, reconstructXMLDsigParameters);
+ rxaap.setAnalyzeResult(ar);
+
+ return reconstructXMLDSIG(rxaap);
+ }
+
+ protected void fillReconstructXMLDsigAfterAnalysisParametersWithReconstructXMLDsigParameters(
+ ReconstructXMLDsigAfterAnalysisParameters rxaap,
+ ReconstructXMLDsigParameters reconstructXMLDsigParameters) {
+ rxaap.setReturnHashInputData(reconstructXMLDsigParameters.isReturnHashInputData());
+ rxaap.setSignatureDevice(reconstructXMLDsigParameters.getSignatureDevice());
+ rxaap.setVerificationTime(reconstructXMLDsigParameters.getVerificationTime());
+ }
+
+ public ReconstructXMLDsigResult reconstructXMLDSIG(
+ ReconstructXMLDsigAfterAnalysisParameters reconstructXMLDsigParameters)
+ throws PdfAsException {
+
+ AnalyzeResult ar = reconstructXMLDsigParameters.getAnalyzeResult();
+ List extendedSignatureInfos = new Vector();
+ for (int i = 0; i < ar.getSignatures().size(); i++)
+ {
+ SignatureInformation si = (SignatureInformation)ar.getSignatures().get(i);
+ XMLDsigData dsigData = XMLDsigReconstructor.reconstruct(si, reconstructXMLDsigParameters.getSignatureDevice());
+ extendedSignatureInfos.add(new ExtendedSignatureInformation(si, dsigData));
}
-
+ return new ReconstructXMLDsigResult().setExtendedSignatures(extendedSignatureInfos);
+ }
+
+ public VerifyResults verify(
+ VerifyAfterReconstructXMLDsigParameters verifyAfterReconstructXMLDsigParameters)
+ throws PdfAsException {
+
+ try {
+ List extSignatures = verifyAfterReconstructXMLDsigParameters.getReconstructXMLDsigResult().getExtendedSignatures();
+ List results = PdfAS.verifyExtendedSignatureHolders(extSignatures,
+ verifyAfterReconstructXMLDsigParameters.getSignatureDevice(),
+ verifyAfterReconstructXMLDsigParameters.isReturnHashInputData(),
+ verifyAfterReconstructXMLDsigParameters.getVerificationTime());
+
+ List vrs = new ArrayList(results.size());
+
+ assert extSignatures.size() == results.size() : "Not all signatures were verified.";
+
+ for (int i = 0; i < extSignatures.size(); i++)
+ {
+ SignatureResponse response = (SignatureResponse) results.get(i);
+ ExtendedSignatureInformation extSigInfo = (ExtendedSignatureInformation)extSignatures.get(i);
+ SignatureHolder holder = (SignatureHolder) extSigInfo.getSignatureInformation().getInternalSignatureInformation();
+
+ VerifyResult vr = new VerifyResultAdapter(response, holder, verifyAfterReconstructXMLDsigParameters.getVerificationTime());
+ vr.setNonTextualObjects( extSigInfo.getSignatureInformation().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);
+ }
}
}
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/xmldsig/XMLDsigReconstructor.java b/src/main/java/at/gv/egiz/pdfas/impl/xmldsig/XMLDsigReconstructor.java
new file mode 100644
index 0000000..86c6e43
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/impl/xmldsig/XMLDsigReconstructor.java
@@ -0,0 +1,53 @@
+package at.gv.egiz.pdfas.impl.xmldsig;
+
+import at.gv.egiz.pdfas.api.commons.SignatureInformation;
+import at.gv.egiz.pdfas.api.xmldsig.XMLDsigData;
+import at.gv.egiz.pdfas.commandline.CommandlineConnectorChooser;
+import at.gv.egiz.pdfas.framework.ConnectorParameters;
+import at.knowcenter.wag.egov.egiz.PdfAS;
+import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
+import at.knowcenter.wag.egov.egiz.exceptions.ConnectorFactoryException;
+import at.knowcenter.wag.egov.egiz.exceptions.SignatureException;
+import at.knowcenter.wag.egov.egiz.pdf.SignatureHolder;
+import at.knowcenter.wag.egov.egiz.sig.SignatureData;
+import at.knowcenter.wag.egov.egiz.sig.SignatureObject;
+import at.knowcenter.wag.egov.egiz.sig.connectors.Connector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.SignSignatureObject;
+import at.knowcenter.wag.egov.egiz.sig.signatureobject.SignatureObjectHelper;
+
+/**
+ * Utility class for reconstructing xmldsig
+ *
+ * @author exthex
+ *
+ */
+public class XMLDsigReconstructor {
+
+ /**
+ * Reconstructs the xmldsig from the given parameters.
+ *
+ * @param si the signature information from which to reconstruct the xmldsig
+ * @param connectorType the type of connector (usually BKU or MOA) to use to create the xmldsig
+ * @return
+ * @throws ConnectorException
+ * @throws ConnectorFactoryException
+ * @throws SignatureException
+ */
+ public static XMLDsigData reconstruct(SignatureInformation si, String connectorType) throws ConnectorException, ConnectorFactoryException, SignatureException {
+ SignatureHolder holder = (SignatureHolder)si.getInternalSignatureInformation();
+ SignatureObject sigObject = holder.getSignatureObject();
+
+ SignSignatureObject so = SignatureObjectHelper.convertSignatureObjectToSignSignatureObject(sigObject);
+ SignatureData sd = PdfAS.convertSignatureHolderToSignatureData(holder);
+
+ String profile = sigObject.getSignatureTypeDefinition().getType();
+ String connectorId = CommandlineConnectorChooser.chooseCommandlineConnectorForVerify(connectorType, sigObject.getKZ(), so.id, profile);
+
+ ConnectorParameters cp = new ConnectorParameters();
+ cp.setProfileId(profile);
+ Connector c = at.gv.egiz.pdfas.framework.ConnectorFactory.createConnector(connectorId, cp);
+
+ return c.reconstructXMLDsig(sd, so);
+ }
+
+}