diff options
author | pdanner <pdanner@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c> | 2010-12-06 17:02:56 +0000 |
---|---|---|
committer | pdanner <pdanner@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c> | 2010-12-06 17:02:56 +0000 |
commit | 73c30d3a15a33d02f7ea675e267b39310913ba4d (patch) | |
tree | fc72a053d82bb1feb40a3ad79bfcfaee110a9bf4 /src | |
parent | 96d7b2b6f4fe8d797b2b2f8e14a94c9dcb221c97 (diff) | |
download | pdf-as-3-73c30d3a15a33d02f7ea675e267b39310913ba4d.tar.gz pdf-as-3-73c30d3a15a33d02f7ea675e267b39310913ba4d.tar.bz2 pdf-as-3-73c30d3a15a33d02f7ea675e267b39310913ba4d.zip |
Necessary changes for separation of pdf-as-web and rest of the project
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@680 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src')
27 files changed, 1359 insertions, 139 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/api/PdfAs.java b/src/main/java/at/gv/egiz/pdfas/api/PdfAs.java index a488bcd..66035db 100644 --- a/src/main/java/at/gv/egiz/pdfas/api/PdfAs.java +++ b/src/main/java/at/gv/egiz/pdfas/api/PdfAs.java @@ -13,6 +13,7 @@ import at.gv.egiz.pdfas.api.commons.SignatureProfile; 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.sign.SignatureDetailInformation;
import at.gv.egiz.pdfas.api.verify.VerifyAfterAnalysisParameters;
import at.gv.egiz.pdfas.api.verify.VerifyAfterReconstructXMLDsigParameters;
import at.gv.egiz.pdfas.api.verify.VerifyParameters;
@@ -39,6 +40,7 @@ public interface PdfAs // reconstructXMLDSIG(ReconstructXMLDsigAfterAnalysisParameters reconstructXMLDsigParameters)
// verify(VerifyAfterReconstructXMLDsigParameters verifyAfterReconstructXMLDsigParameters)
+
/**
* Signs a PDF document using PDF-AS.
*
@@ -54,6 +56,23 @@ public interface PdfAs public SignResult sign(SignParameters signParameters) throws PdfAsException;
/**
+ * Signs a PDF document using PDF-AS.<br/>
+ * This uses the {@link SignatorInformation} which was obtained by a call to {@link PdfAs#prepareSign(SignParameters)}
+ *
+ * @param signParameters
+ * The sign parameters.
+ * @param signatureDetailInformation
+ * The signature information which was previously obtained by a call to {@link PdfAs#prepareSign(SignParameters)}
+ * @return Returns the signed document plus additional information.
+ * @throws PdfAsException
+ * Thrown, if an error occurs.
+ *
+ * @see SignParameters
+ * @see SignResult
+ */
+ public SignResult sign(SignParameters signParameters, SignatureDetailInformation signatureDetailInformation) throws PdfAsException;
+
+ /**
* Verifies a document with (potentially multiple) PDF-AS signatures.
*
* @param verifyParameters
@@ -210,4 +229,24 @@ public interface PdfAs * @return the signature profile or <code>null</code> if not found.
*/
public DynamicSignatureProfile loadDynamicSignatureProfile(String profileName);
+
+ /**
+ * TODO doc
+ *
+ * @param signParameters
+ * @return
+ * @throws PdfAsException
+ */
+ public SignatureDetailInformation prepareSign(SignParameters signParameters) throws PdfAsException;
+
+ /**
+ * TODO doc
+ *
+ * @param signParameters
+ * @param signatureDetailInformation
+ * @return
+ * @throws PdfAsException
+ */
+ public SignResult finishSign(SignParameters signParameters, SignatureDetailInformation signatureDetailInformation) throws PdfAsException;
+
}
diff --git a/src/main/java/at/gv/egiz/pdfas/api/commons/SignatureProfile.java b/src/main/java/at/gv/egiz/pdfas/api/commons/SignatureProfile.java index d018050..c806822 100644 --- a/src/main/java/at/gv/egiz/pdfas/api/commons/SignatureProfile.java +++ b/src/main/java/at/gv/egiz/pdfas/api/commons/SignatureProfile.java @@ -48,4 +48,9 @@ public interface SignatureProfile { */
public String getProfileDescription();
+ /**
+ * True only if this is the default profile according to config.
+ * @return
+ */
+ public boolean isDefault();
}
diff --git a/src/main/java/at/gv/egiz/pdfas/api/internal/LocalBKUParams.java b/src/main/java/at/gv/egiz/pdfas/api/internal/LocalBKUParams.java new file mode 100644 index 0000000..114788c --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/api/internal/LocalBKUParams.java @@ -0,0 +1,41 @@ +package at.gv.egiz.pdfas.api.internal;
+
+
+/**
+ * Parameter container for local BKUs. (BKU, Mocca)
+ *
+ * @author exthex
+ *
+ */
+public class LocalBKUParams {
+
+ private String server;
+ private String userAgent;
+ private String signatureLayout;
+
+ public LocalBKUParams(String server, String userAgent, String signatureLayout) {
+ this.server = server;
+ this.userAgent = userAgent;
+ this.signatureLayout = signatureLayout;
+ }
+
+ public String getServer() {
+ return server;
+ }
+ public void setServer(String server) {
+ this.server = server;
+ }
+ public String getUserAgent() {
+ return userAgent;
+ }
+ public void setUserAgent(String userAgent) {
+ this.userAgent = userAgent;
+ }
+ public String getSignatureLayout() {
+ return signatureLayout;
+ }
+ public void setSignatureLayout(String signatureLayout) {
+ this.signatureLayout = signatureLayout;
+ }
+
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/api/internal/PdfAsInternal.java b/src/main/java/at/gv/egiz/pdfas/api/internal/PdfAsInternal.java new file mode 100644 index 0000000..f3a4962 --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/api/internal/PdfAsInternal.java @@ -0,0 +1,138 @@ +package at.gv.egiz.pdfas.api.internal;
+
+import java.util.Map;
+
+import at.gv.egiz.pdfas.api.PdfAs;
+import at.gv.egiz.pdfas.api.analyze.AnalyzeResult;
+import at.gv.egiz.pdfas.api.commons.SignatureInformation;
+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.sign.SignatureDetailInformation;
+import at.gv.egiz.pdfas.api.verify.VerifyResult;
+import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
+import at.knowcenter.wag.egov.egiz.exceptions.ConnectorFactoryException;
+import at.knowcenter.wag.egov.egiz.exceptions.NormalizeException;
+import at.knowcenter.wag.egov.egiz.exceptions.SettingsException;
+import at.knowcenter.wag.egov.egiz.exceptions.SignatureException;
+import at.knowcenter.wag.egov.egiz.exceptions.SignatureTypesException;
+
+/**
+ * The methods of this interface are used by the pdf-as-web project and are not for external use.<br/>
+ * Using this API is inadvisable as its functionality might change without notice from release to release.
+ *
+ * @author exthex
+ *
+ */
+public interface PdfAsInternal {
+
+ /**
+ * Check if a BKU with the given parameters is supported.
+ *
+ * @param bkuParams
+ * @throws ConnectorException if the BKU is not supported
+ * @throws SettingsException if the BKU is not supported
+ */
+ public void verifyBKUSupport(LocalBKUParams bkuParams) throws ConnectorException, SettingsException;
+
+ /**
+ * Finish the sign process.
+ *
+ * @param pdfAs
+ * @param signParameters
+ * @param sdi This info will most likely come from a {@link PdfAs#prepareSign(SignParameters)} call
+ * @param bkuParams
+ * @param xmlResponse the SecurityLayer response from the BKU
+ * @return the signed document + additional info
+ * @throws PdfAsException
+ */
+ public SignResult finishLocalSign(PdfAs pdfAs, SignParameters signParameters, SignatureDetailInformation sdi, LocalBKUParams bkuParams, String xmlResponse) throws PdfAsException;
+
+ /**
+ * Get the security layer address for the given connector. (zB: http://127.0.0.1:3495/http-security-layer-request)
+ *
+ * @param profile
+ * @param device
+ * @return
+ * @throws SettingsException
+ */
+ public String getLocalServiceAddress(String profile, String device) throws SettingsException;
+
+ /**
+ * Get the CreateXMLSignatureRequest for the given parameters.
+ *
+ * @param signParameters the sign parameters. {@link SignParameters#getSignatureDevice()} determines the connector to use.
+ * @param loc_ref_url the URL where to retrieve the PDF to sign
+ * @param sdi {@link SignatureDetailInformation#getSignatureData()} provides the data to be signed.
+ * @return
+ * @throws ConnectorException
+ */
+ public String prepareLocalSignRequest(SignParameters signParameters, String loc_ref_url, SignatureDetailInformation sdi) throws ConnectorException;
+
+ /**
+ * Create an AnalyzeResult from raw text, instead of a PDF.
+ *
+ * @param rawText
+ * @param sigValues the signature values
+ * @return
+ * @throws SignatureException
+ * @throws SettingsException
+ * @throws SignatureTypesException
+ * @throws NormalizeException
+ */
+ public AnalyzeResult analyzeFromRawText(String rawText, Map sigValues) throws SignatureException, SettingsException, SignatureTypesException, NormalizeException;
+
+ /**
+ * Create the SecurityLayer VerifyXMLSignatureRequest for the given parameters.
+ *
+ * @param sigInfo
+ * @param connector
+ * @param profile
+ * @param loc_ref_url
+ * @return
+ * @throws SignatureException
+ * @throws ConnectorException
+ */
+ public String prepareLocalVerifyRequest(SignatureInformation sigInfo, String connector, String profile, String loc_ref_url) throws SignatureException, ConnectorException;
+
+ /**
+ * Parse the given xml_response - must be a VerifyXMLSignatureResponse - from the BKU or Mocca and generates a VerifyResult from it.
+ *
+ * @param sigInfo
+ * @param connector
+ * @param profile
+ * @param loc_ref_url
+ * @param xmlResponse
+ * @return
+ * @throws SignatureException
+ * @throws ConnectorException
+ */
+ public VerifyResult finishLocalVerify(SignatureInformation sigInfo, String connector, String profile, String loc_ref_url, String xmlResponse) throws SignatureException, ConnectorException;
+
+ /**
+ * Get the {@link SignatureEntry} corresponding to a given {@link SignatureInformation}
+ *
+ * @param key
+ * @param sigInfo
+ * @return
+ */
+ public SignatureEntry getSignatureEntryFromSignatureInformation(String key, SignatureInformation sigInfo);
+
+ /**
+ * Get the signed text for a given sigInfo.<br/>
+ * If this signature is not text based this method will return null.
+ *
+ * @param sigInfo
+ * @return
+ */
+ public String getSignedText(SignatureInformation sigInfo);
+
+ /**
+ * Get a map of all connectors available for web.
+ * The key is the connector id, the value is the description.
+ *
+ * @return
+ * @throws ConnectorFactoryException
+ */
+ public Map getConnectorsAvailableForWeb() throws ConnectorFactoryException;
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/api/internal/SignatureEntry.java b/src/main/java/at/gv/egiz/pdfas/api/internal/SignatureEntry.java new file mode 100644 index 0000000..3b039ab --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/api/internal/SignatureEntry.java @@ -0,0 +1,131 @@ +/*
+ * <copyright>
+ * Copyright (c) 2006 by Know-Center, Graz, Austria
+ * </copyright>
+ *
+ * This software is the confidential and proprietary information of Know-Center,
+ * Graz, Austria. You shall not disclose such Confidential Information and shall
+ * use it only in accordance with the terms of the license agreement you entered
+ * into with Know-Center.
+ *
+ * KNOW-CENTER MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
+ * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+ * OR NON-INFRINGEMENT. KNOW-CENTER SHALL NOT BE LIABLE FOR ANY DAMAGES
+ * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
+ * THIS SOFTWARE OR ITS DERIVATIVES.
+ *
+ * $Id: SignatureEntry.java,v 1.3 2006/08/25 17:09:41 wprinz Exp $
+ */
+package at.gv.egiz.pdfas.api.internal;
+
+import java.io.Serializable;
+
+/**
+ * A container for signature entries.
+ * Copied to internal api from {@link at.knowcenter.wag.egov.egiz.sig.SignatureEntry}
+ *
+ * @author exthex
+ * @see at.knowcenter.wag.egov.egiz.sig.SignatureEntry
+ */
+public class SignatureEntry implements Serializable {
+
+ /**
+ * SVUID.
+ */
+ private static final long serialVersionUID = -1L;
+
+ /**
+ * The signature key.
+ */
+ private String key_ = null;
+ /**
+ * The signature caption for the key found or set in the signature text.
+ */
+ private String caption_ = null;
+ /**
+ * The signature value for the key found or set in the signature text.
+ */
+ private String value_ = null;
+
+ /**
+ * The empty constructor.
+ */
+ public SignatureEntry() {
+ }
+
+ /**
+ * A new <code>SignatureEntry</code> init with the key.
+ *
+ * @param key
+ */
+ public SignatureEntry(String key) {
+ key_ = key;
+ }
+
+ /**
+ * Returns the caption off the current key.
+ *
+ * @return Returns the caption.
+ */
+ public String getCaption() {
+ return caption_;
+ }
+
+ /**
+ * Set the caption of the current key.
+ *
+ * @param caption The caption to set.
+ */
+ public void setCaption(String caption) {
+ caption_ = caption;
+ }
+
+ /**
+ * Return the current key.
+ *
+ * @return Returns the key.
+ */
+ public String getKey() {
+ return key_;
+ }
+
+ /**
+ * Set the current key.
+ *
+ * @param key The key to set.
+ */
+ public void setKey(String key) {
+ key_ = key;
+ }
+
+ /**
+ * Return the value of the current key.
+ *
+ * @return Returns the value.
+ */
+ public String getValue() {
+ return value_;
+ }
+
+ /**
+ * Set the value of the current key.
+ *
+ * @param value The value to set.
+ */
+ public void setValue(String value) {
+ value_ = value;
+ }
+
+ /**
+ * The toString method, used for tests or debugging.
+ */
+ public String toString() {
+ String the_string = "";
+ the_string += "\n Key:" + key_;
+ the_string += "\nCaption:" + caption_;
+ the_string += "\n Value:" + value_;
+// the_string += "\nStart I:" + startIndex_;
+ return the_string;
+ }
+}
\ No newline at end of file diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/SignatureDetailInformation.java b/src/main/java/at/gv/egiz/pdfas/api/sign/SignatureDetailInformation.java new file mode 100644 index 0000000..0865be1 --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/api/sign/SignatureDetailInformation.java @@ -0,0 +1,127 @@ +/**
+ *
+ */
+package at.gv.egiz.pdfas.api.sign;
+
+import java.security.cert.X509Certificate;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import at.gv.egiz.pdfas.api.analyze.NonTextObjectInfo;
+import at.gv.egiz.pdfas.api.io.DataSource;
+import at.gv.egiz.pdfas.api.sign.pos.SignaturePosition;
+
+/**
+ * A container for all relevant signature related data.
+ *
+ * @author exthex
+ */
+public interface SignatureDetailInformation
+{
+ public DataSource getSignatureData();
+
+ /**
+ * Returns the position where the signature table was actually placed.
+ *
+ * @return Returns the position where the signature table was actually placed.
+ */
+ public SignaturePosition getSignaturePosition();
+
+ /**
+ * Returns a list<{@link NonTextObjectInfo} of non textual objects in the pdf document.
+ * Only available for textual signatures. Show this to the user who signed the textual content only!
+ * @return List<{@link NonTextObjectInfo} or <tt>null</tt> of not available (binary signature)
+ */
+ public List getNonTextualObjects();
+
+ /**
+ * Returns the date of signature extracted from the signature.
+ * @return
+ */
+ public Date getSignDate();
+
+ /**
+ * Get the name of the issuer.
+ * Short for {@link SignatureDetailInformation#getX509Certificate()#getIssuer()#getName()}
+ *
+ * @return
+ */
+ public String getIssuer();
+
+ /**
+ * Short for {@link SignatureDetailInformation#getX509Certificate()#getIssuerDNMap()}
+ *
+ * @return
+ */
+ public Map getIssuerDNMap();
+
+ /**
+ * Short for {@link SignatureDetailInformation#getX509Certificate()#getSubjectName()#toString()}
+ *
+ * @return
+ */
+ public String getSubjectName();
+
+ /**
+ * Short for {@link SignatureDetailInformation#getX509Certificate()#getSerialNumber()#toString()}
+ *
+ * @return
+ */
+ public String getSerialNumber();
+
+ /**
+ * Get the algorithm the signature was created with.
+ * @return
+ */
+ public String getSigAlgorithm();
+
+ /**
+ *
+ * @return the signature id.
+ */
+ public String getSigID();
+
+ /**
+ *
+ * @return the signature method.
+ */
+ public String getSigKZ();
+
+ /**
+ *
+ * @return the signature value.
+ */
+ public String getSignatureValue();
+
+ /**
+ *
+ * @return the signature time stamp.
+ */
+ public String getSigTimeStamp();
+
+ /**
+ * Short for {@link SignatureDetailInformation#getX509Certificate()#getSubjectDNMap()}
+ *
+ * @return
+ */
+ public Map getSubjectDNMap();
+
+ /**
+ *
+ * @return the certificate used for signature.
+ */
+ public X509Certificate getX509Certificate();
+
+ /**
+ *
+ * @return true if the signature is textual, false otherwise.
+ */
+ public boolean isTextual();
+
+ /**
+ *
+ * @return true if this signature is binary, false otherwise.
+ */
+ public boolean isBinary();
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java index 42b02eb..1368fcd 100644 --- a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java +++ b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java @@ -3,6 +3,7 @@ */
package at.gv.egiz.pdfas.api.sign.pos;
+import java.io.Serializable;
import java.util.StringTokenizer;
import at.gv.egiz.pdfas.api.sign.pos.axis.AbsoluteAxisAlgorithm;
@@ -25,8 +26,14 @@ import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException; *
* @author wprinz
*/
-public class SignaturePositioning
+public class SignaturePositioning implements Serializable
{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
/**
* The x axis algorithm.
*
diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AbsoluteAxisAlgorithm.java b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AbsoluteAxisAlgorithm.java index 234484c..3e8bc04 100644 --- a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AbsoluteAxisAlgorithm.java +++ b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AbsoluteAxisAlgorithm.java @@ -3,14 +3,21 @@ */
package at.gv.egiz.pdfas.api.sign.pos.axis;
+import java.io.Serializable;
+
/**
* An absolute positioned element.
* @author wprinz
*/
-public class AbsoluteAxisAlgorithm extends AxisAlgorithm
+public class AbsoluteAxisAlgorithm extends AxisAlgorithm implements Serializable
{
/**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
* The absolute positioning value on the axis.
*/
protected float absoluteValue = 0.0f;
diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AutoAxisAlgorithm.java b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AutoAxisAlgorithm.java index 4c5459f..0d1f80d 100644 --- a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AutoAxisAlgorithm.java +++ b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AutoAxisAlgorithm.java @@ -3,12 +3,19 @@ */
package at.gv.egiz.pdfas.api.sign.pos.axis;
+import java.io.Serializable;
+
/**
* Auto positioning for this element.
*
* @author wprinz
*/
-public class AutoAxisAlgorithm extends AxisAlgorithm
+public class AutoAxisAlgorithm extends AxisAlgorithm implements Serializable
{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
// empty
}
diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AxisAlgorithm.java b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AxisAlgorithm.java index a4baac6..40f614d 100644 --- a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AxisAlgorithm.java +++ b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AxisAlgorithm.java @@ -3,12 +3,19 @@ */
package at.gv.egiz.pdfas.api.sign.pos.axis;
+import java.io.Serializable;
+
/**
* Determines how a certain position is chosen on the axis (x, y, width).
*
* @author wprinz
*/
-public abstract class AxisAlgorithm
+public abstract class AxisAlgorithm implements Serializable
{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
// base class
}
diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AbsolutePageAlgorithm.java b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AbsolutePageAlgorithm.java index 206aa19..5940031 100644 --- a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AbsolutePageAlgorithm.java +++ b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AbsolutePageAlgorithm.java @@ -3,14 +3,21 @@ */
package at.gv.egiz.pdfas.api.sign.pos.page;
+import java.io.Serializable;
+
/**
* The page is selected absolutely by giving the page number directly.
*
* @author wprinz
*/
-public class AbsolutePageAlgorithm extends PageAlgorithm
+public class AbsolutePageAlgorithm extends PageAlgorithm implements Serializable
{
/**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
* The page.
*/
protected int page = -1;
diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AutoPageAlgorithm.java b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AutoPageAlgorithm.java index 0070d5e..dff678c 100644 --- a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AutoPageAlgorithm.java +++ b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AutoPageAlgorithm.java @@ -3,6 +3,8 @@ */
package at.gv.egiz.pdfas.api.sign.pos.page;
+import java.io.Serializable;
+
/**
* The page for placing the signature is selected automatically.
*
@@ -14,7 +16,12 @@ package at.gv.egiz.pdfas.api.sign.pos.page; *
* @author wprinz
*/
-public class AutoPageAlgorithm extends PageAlgorithm
+public class AutoPageAlgorithm extends PageAlgorithm implements Serializable
{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
// empty
}
diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/NewPageAlgorithm.java b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/NewPageAlgorithm.java index 2a8f67c..050be91 100644 --- a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/NewPageAlgorithm.java +++ b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/NewPageAlgorithm.java @@ -3,12 +3,19 @@ */
package at.gv.egiz.pdfas.api.sign.pos.page;
+import java.io.Serializable;
+
/**
* Places the signature on a new Page.
*
* @author wprinz
*/
-public class NewPageAlgorithm extends PageAlgorithm
+public class NewPageAlgorithm extends PageAlgorithm implements Serializable
{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
// empty block
}
diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/PageAlgorithm.java b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/PageAlgorithm.java index 9b0fe8a..14bd02e 100644 --- a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/PageAlgorithm.java +++ b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/PageAlgorithm.java @@ -3,12 +3,19 @@ */
package at.gv.egiz.pdfas.api.sign.pos.page;
+import java.io.Serializable;
+
/**
* Determines how the page on which the signature is to be placed is selected.
*
* @author wprinz
*/
-public abstract class PageAlgorithm
+public abstract class PageAlgorithm implements Serializable
{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
// empty
}
diff --git a/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyAfterAnalysisParameters.java b/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyAfterAnalysisParameters.java index dd50d79..836bc13 100644 --- a/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyAfterAnalysisParameters.java +++ b/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyAfterAnalysisParameters.java @@ -48,6 +48,11 @@ public class VerifyAfterAnalysisParameters protected boolean returnHashInputData = false;
/**
+ * The index of the signature to be verified. A value < 0 indicates to verify all signatures.
+ */
+ protected int verifySignatureIndex = -1;
+
+ /**
* @return the analyzeResult
*/
public AnalyzeResult getAnalyzeResult()
@@ -114,4 +119,16 @@ public class VerifyAfterAnalysisParameters this.returnHashInputData = returnHashInputData;
}
+ /**
+ * Set the index of the signature to verify (index starting at 0). A value < 0 indicates to verify all values.
+ * @param verify_which
+ */
+ public void setVerifySignatureIndex(int verify_which) {
+ this.verifySignatureIndex = verify_which;
+ }
+
+ public int getVerifySignatureIndex() {
+ return verifySignatureIndex;
+ }
+
}
diff --git a/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyAfterReconstructXMLDsigParameters.java b/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyAfterReconstructXMLDsigParameters.java index 11ddb28..24bba20 100644 --- a/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyAfterReconstructXMLDsigParameters.java +++ b/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyAfterReconstructXMLDsigParameters.java @@ -45,6 +45,11 @@ public class VerifyAfterReconstructXMLDsigParameters { protected boolean returnHashInputData = false;
/**
+ * The index of the signature to be verified. A value < 0 indicates to verify all signatures.
+ */
+ protected int verifySignatureIndex = -1;
+
+ /**
* @return the reconstructXMLDsigResult
*/
public ReconstructXMLDsigResult getReconstructXMLDsigResult()
@@ -111,4 +116,16 @@ public class VerifyAfterReconstructXMLDsigParameters { this.returnHashInputData = returnHashInputData;
}
+ /**
+ * Set the index of the signature to verify (index starting at 0). A value < 0 indicates to verify all values.
+ * @param verify_which
+ */
+ public void setVerifySignatureIndex(int verify_which) {
+ this.verifySignatureIndex = verify_which;
+ }
+
+ public int getVerifySignatureIndex() {
+ return verifySignatureIndex;
+ }
+
}
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/api/CheckHelper.java b/src/main/java/at/gv/egiz/pdfas/impl/api/CheckHelper.java index 83a0565..d48435a 100644 --- a/src/main/java/at/gv/egiz/pdfas/impl/api/CheckHelper.java +++ b/src/main/java/at/gv/egiz/pdfas/impl/api/CheckHelper.java @@ -10,9 +10,12 @@ import at.gv.egiz.pdfas.api.analyze.AnalyzeParameters; import at.gv.egiz.pdfas.api.commons.Constants;
import at.gv.egiz.pdfas.api.io.DataSource;
import at.gv.egiz.pdfas.api.sign.SignParameters;
+import at.gv.egiz.pdfas.api.sign.SignatureDetailInformation;
import at.gv.egiz.pdfas.api.sign.pos.SignaturePositioning;
import at.gv.egiz.pdfas.api.verify.VerifyAfterAnalysisParameters;
import at.gv.egiz.pdfas.api.verify.VerifyParameters;
+import at.gv.egiz.pdfas.framework.signator.SignatorInformation;
+import at.gv.egiz.pdfas.impl.api.sign.SignatureDetailInformationImpl;
import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
import at.knowcenter.wag.egov.egiz.exceptions.SignatureTypesException;
import at.knowcenter.wag.egov.egiz.sig.SignatureTypes;
@@ -44,8 +47,9 @@ public final class CheckHelper *
* @param sp
* The {@link SignParameters}
+ * @param allowAllDevices if true, no check for non local BKUs will be done
*/
- public static void checkSignParameters(SignParameters sp)
+ public static void checkSignParameters(SignParameters sp, boolean allowAllDevices)
{
if (sp == null)
{
@@ -58,7 +62,8 @@ public final class CheckHelper throw new IllegalArgumentException("The output DataSink must not be null.");
}
checkSignatureType(sp.getSignatureType());
- checkSignatureDevice(sp.getSignatureDevice());
+ if (!allowAllDevices)
+ checkSignatureDevice(sp.getSignatureDevice());
if (sp.getSignatureProfileId() != null)
{
checkProfileId(sp.getSignatureProfileId());
@@ -226,4 +231,23 @@ public final class CheckHelper throw new IllegalArgumentException("The signatureDevice must be one of the Constants.SIGNATURE_DEVICE_* constants. " + signatureDevice);
}
}
+
+ protected static void checkSignParametersForSignAfterPrepare(SignParameters signParameters, boolean allowAllDevices) {
+ checkSignParameters(signParameters, allowAllDevices);
+ checkProfileId(signParameters.getSignatureProfileId());
+ }
+
+ public static void checkSignatorInformation(SignatorInformation signatorInfo) {
+ if (signatorInfo.getSignSignatureObject() == null)
+ {
+ throw new IllegalArgumentException("The signatorInformation.getSignSignatureObject() must not be null.");
+ }
+ }
+
+ public static void checkSignatureDetailInformation(SignatureDetailInformation signatureDetailInformation) {
+ if (!(signatureDetailInformation instanceof SignatureDetailInformationImpl)){
+ throw new IllegalArgumentException("SignatureDetailInformation is of unsupported type. Must be " + SignatureDetailInformationImpl.class.getName());
+ }
+
+ }
}
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 90e7986..e630aa3 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 @@ -26,6 +26,7 @@ import at.gv.egiz.pdfas.api.commons.SignatureInformation; 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.sign.SignatureDetailInformation;
import at.gv.egiz.pdfas.api.verify.VerifyAfterAnalysisParameters;
import at.gv.egiz.pdfas.api.verify.VerifyAfterReconstructXMLDsigParameters;
import at.gv.egiz.pdfas.api.verify.VerifyParameters;
@@ -38,10 +39,12 @@ 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.ConnectorParameters;
import at.gv.egiz.pdfas.framework.DataSourceHolder;
import at.gv.egiz.pdfas.framework.config.SettingsHelper;
import at.gv.egiz.pdfas.framework.input.ExtractionStage;
import at.gv.egiz.pdfas.framework.input.PdfDataSource;
+import at.gv.egiz.pdfas.framework.signator.Signator;
import at.gv.egiz.pdfas.framework.signator.SignatorInformation;
import at.gv.egiz.pdfas.framework.vfilter.VerificationFilterParameters;
import at.gv.egiz.pdfas.impl.api.analyze.AnalyzeResultImpl;
@@ -52,6 +55,7 @@ import at.gv.egiz.pdfas.impl.api.commons.SignatureProfileImpl; import at.gv.egiz.pdfas.impl.api.commons.TextDataSourceAdapter;
import at.gv.egiz.pdfas.impl.api.sign.ActualSignaturePositionAdapter;
import at.gv.egiz.pdfas.impl.api.sign.SignResultImpl;
+import at.gv.egiz.pdfas.impl.api.sign.SignatureDetailInformationImpl;
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;
@@ -63,11 +67,13 @@ 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;
+import at.knowcenter.wag.egov.egiz.cfg.OverridePropertyHolder;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
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.SignatorFactoryException;
import at.knowcenter.wag.egov.egiz.exceptions.SignatureException;
import at.knowcenter.wag.egov.egiz.framework.SignatorFactory;
import at.knowcenter.wag.egov.egiz.pdf.BinarySignatureHolder;
@@ -76,9 +82,13 @@ import at.knowcenter.wag.egov.egiz.pdf.ObjectExtractor; import at.knowcenter.wag.egov.egiz.pdf.SignatureHolder;
import at.knowcenter.wag.egov.egiz.pdf.TablePos;
import at.knowcenter.wag.egov.egiz.pdf.TextualSignatureHolder;
+import at.knowcenter.wag.egov.egiz.sig.SignatureData;
+import at.knowcenter.wag.egov.egiz.sig.SignatureDataImpl;
import at.knowcenter.wag.egov.egiz.sig.SignatureResponse;
import at.knowcenter.wag.egov.egiz.sig.SignatureTypeDefinition;
import at.knowcenter.wag.egov.egiz.sig.SignatureTypes;
+import at.knowcenter.wag.egov.egiz.sig.connectors.Connector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.SignSignatureObject;
/**
* Implementation of the {@link PdfAs} interface.
@@ -180,6 +190,8 @@ public class PdfAsObject implements PdfAs List profileInformation = new ArrayList(profiles.size());
+ String default_type = settings.getValueFromKey(SignatureTypes.DEFAULT_TYPE);
+
Iterator it = profiles.iterator();
while (it.hasNext())
{
@@ -190,8 +202,9 @@ public class PdfAsObject implements PdfAs final String moaKeyIdentifier = settings.getSetting("sig_obj." + profileId + "." + MOA_SIGN_KEY_IDENTIFIER_KEY, defaultMoaKeyIdentifiert);
final String profileDescription = settings.getSetting("sig_obj." + profileId + "." + SignatureTypes.SIG_DESCR, null);
+ boolean isDefault = (default_type != null && default_type.equals(profileId));
// modified by tknall
- SignatureProfileImpl signatureProfile = new SignatureProfileImpl(profileId, profileDescription, moaKeyIdentifier);
+ SignatureProfileImpl signatureProfile = new SignatureProfileImpl(profileId, profileDescription, moaKeyIdentifier, isDefault);
// start - added by tknall
@@ -262,68 +275,13 @@ public class PdfAsObject implements PdfAs */
public SignResult sign(SignParameters signParameters) throws PdfAsException
{
- CheckHelper.checkSignParameters(signParameters);
-
- 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);
+ CheckHelper.checkSignParameters(signParameters, false);
- if (signParameters.getSignatureProfileId() == null)
- {
- SettingsReader settings = SettingsReader.getInstance();
- String defaultProfile = settings.getValueFromKey(SignatureTypes.DEFAULT_TYPE);
- signParameters.setSignatureProfileId(defaultProfile);
- }
-
- PdfASID signatorId = null;
- if (signParameters.getSignatureType().equals(Constants.SIGNATURE_TYPE_BINARY))
- {
- signatorId = SignatorFactory.MOST_RECENT_BINARY_SIGNATOR_ID;
- }
- if (signParameters.getSignatureType().equals(Constants.SIGNATURE_TYPE_TEXTUAL))
- {
- signatorId = SignatorFactory.MOST_RECENT_TEXTUAL_SIGNATOR_ID;
- }
- if (signParameters.getSignatureType().equals(Constants.SIGNATURE_TYPE_DETACHEDTEXTUAL))
- {
- signatorId = SignatorFactory.MOST_RECENT_DETACHEDTEXT_SIGNATOR_ID;
- }
-
- TablePos pos = null;
- if (spd != null && spd.getTablePos() != null)
- pos = spd.getTablePos();
- else
- pos = PosHelper.formTablePos(signParameters.getSignaturePositioning());
-
- String connectorId = CommandlineConnectorChooser.chooseCommandlineConnectorForSign(signParameters.getSignatureDevice());
-
try {
- SignatorInformation si = PdfAS.signCommandline(
- new PdfDataSourceAdapter(signParameters.getDocument()),
- new DataSinkAdapter(signParameters.getOutput()),
- signatorId,
- connectorId,
- signParameters.getSignatureProfileId(),
- signParameters.getSignatureKeyIdentifier(),
- pos,
- signParameters.getTimeStamperImpl(),
- signParameters.getProfileOverrideProperties()
- );
- return new SignResultImpl(signParameters.getOutput(), si.getSignSignatureObject().getX509Certificate(),
- new ActualSignaturePositionAdapter(si.getActualTablePos()), si.getNonTextualObjects());
+ SignatureDetailInformation signatorInfo = prepareSign(signParameters);
+
+ return sign(signParameters, signatorInfo);
+
} 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);
}
@@ -538,8 +496,12 @@ public class PdfAsObject implements PdfAs varxp.setReturnHashInputData(verifyAfterAnalysisParameters.isReturnHashInputData());
varxp.setSignatureDevice(verifyAfterAnalysisParameters.getSignatureDevice());
varxp.setVerificationTime(verifyAfterAnalysisParameters.getVerificationTime());
+ varxp.setVerifySignatureIndex(verifyAfterAnalysisParameters.getVerifySignatureIndex());
}
+ /**
+ * @see PdfAs#reconstructXMLDSIG(ReconstructXMLDsigParameters)
+ */
public ReconstructXMLDsigResult reconstructXMLDSIG(
ReconstructXMLDsigParameters reconstructXMLDsigParameters)
throws PdfAsException {
@@ -563,6 +525,9 @@ public class PdfAsObject implements PdfAs rxaap.setVerificationTime(reconstructXMLDsigParameters.getVerificationTime());
}
+ /**
+ * @see PdfAs#reconstructXMLDSIG(ReconstructXMLDsigAfterAnalysisParameters)
+ */
public ReconstructXMLDsigResult reconstructXMLDSIG(
ReconstructXMLDsigAfterAnalysisParameters reconstructXMLDsigParameters)
throws PdfAsException {
@@ -585,6 +550,9 @@ public class PdfAsObject implements PdfAs return new ReconstructXMLDsigResult().setExtendedSignatures(extendedSignatureInfos);
}
+ /**
+ * @see PdfAs#verify(VerifyAfterReconstructXMLDsigParameters)
+ */
public VerifyResults verify(
VerifyAfterReconstructXMLDsigParameters verifyAfterReconstructXMLDsigParameters)
throws PdfAsException {
@@ -594,22 +562,33 @@ public class PdfAsObject implements PdfAs List results = PdfAS.verifyExtendedSignatureHolders(extSignatures,
verifyAfterReconstructXMLDsigParameters.getSignatureDevice(),
verifyAfterReconstructXMLDsigParameters.isReturnHashInputData(),
- verifyAfterReconstructXMLDsigParameters.getVerificationTime());
+ verifyAfterReconstructXMLDsigParameters.getVerificationTime(), verifyAfterReconstructXMLDsigParameters.getVerifySignatureIndex());
List vrs = new ArrayList(results.size());
- assert extSignatures.size() == results.size() : "Not all signatures were verified.";
-
- for (int i = 0; i < extSignatures.size(); i++)
+ int verifySignatureIndex = verifyAfterReconstructXMLDsigParameters.getVerifySignatureIndex();
+ if (verifySignatureIndex < 0)
{
- SignatureResponse response = (SignatureResponse) results.get(i);
- ExtendedSignatureInformation extSigInfo = (ExtendedSignatureInformation)extSignatures.get(i);
- SignatureHolder holder = (SignatureHolder) extSigInfo.getSignatureInformation().getInternalSignatureInformation();
+ 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());
+ VerifyResult vr = new VerifyResultAdapter(response, holder, verifyAfterReconstructXMLDsigParameters.getVerificationTime());
+ vr.setNonTextualObjects( extSigInfo.getSignatureInformation().getNonTextualObjects());
- vrs.add(vr);
+ vrs.add(vr);
+ }
+ }else{
+ SignatureResponse response = (SignatureResponse) results.get(0);
+ ExtendedSignatureInformation extSigInfo = (ExtendedSignatureInformation)extSignatures.get(verifySignatureIndex);
+ 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);
@@ -640,6 +619,136 @@ public class PdfAsObject implements PdfAs DynamicSignatureLifetimeEnum mode) {
return DynamicSignatureProfileImpl.createEmptyProfile(myUniqueName, mode);
}
+
+ /**
+ * @see PdfAs#prepareSign(SignParameters)
+ */
+ public SignatureDetailInformation prepareSign(SignParameters signParameters) throws PdfAsException {
+ try{
+ CheckHelper.checkSignParameters(signParameters, true);
+
+ if (signParameters.getProfileOverrideProperties() != null) {
+ OverridePropertyHolder.setOverrideProps(signParameters.getProfileOverrideProperties());
+ }
+ 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, true);
+
+ if (signParameters.getSignatureProfileId() == null)
+ {
+ SettingsReader settings = SettingsReader.getInstance();
+ String defaultProfile = settings.getValueFromKey(SignatureTypes.DEFAULT_TYPE);
+ signParameters.setSignatureProfileId(defaultProfile);
+ }
+
+ TablePos pos = null;
+ if (spd != null && spd.getTablePos() != null)
+ pos = spd.getTablePos();
+ else
+ pos = PosHelper.formTablePos(signParameters.getSignaturePositioning());
+
+ Signator signator = createSignator(signParameters.getSignatureType());
+
+ SignatorInformation signatorInfo = signator.prepareSign(
+ new PdfDataSourceAdapter(signParameters.getDocument()),
+ signParameters.getSignatureProfileId(),
+ pos,
+ signParameters.getTimeStamperImpl());
+
+ SignatureDetailInformationImpl ret = new SignatureDetailInformationImpl();
+ ret.setSignatorInformation(signatorInfo);
+ return ret;
+ } finally {
+ OverridePropertyHolder.removeProperties();
+ DynamicSignatureProfileImpl.disposeLocalProfile();
+ }
+
+ }
+
+ private Signator createSignator(String signatureType) throws SignatorFactoryException {
+ PdfASID signatorId = null;
+ if (signatureType.equals(Constants.SIGNATURE_TYPE_BINARY))
+ {
+ signatorId = SignatorFactory.MOST_RECENT_BINARY_SIGNATOR_ID;
+ }
+ if (signatureType.equals(Constants.SIGNATURE_TYPE_TEXTUAL))
+ {
+ signatorId = SignatorFactory.MOST_RECENT_TEXTUAL_SIGNATOR_ID;
+ }
+ if (signatureType.equals(Constants.SIGNATURE_TYPE_DETACHEDTEXTUAL))
+ {
+ signatorId = SignatorFactory.MOST_RECENT_DETACHEDTEXT_SIGNATOR_ID;
+ }
+
+ return at.gv.egiz.pdfas.framework.SignatorFactory.createSignator(signatorId);
+
+ }
+
+ public SignResult sign(SignParameters signParameters, SignatureDetailInformation signatorInfo)
+ throws PdfAsException {
+ try {
+ CheckHelper.checkSignParametersForSignAfterPrepare(signParameters, false);
+
+ if (signParameters.getProfileOverrideProperties() != null) {
+ OverridePropertyHolder.setOverrideProps(signParameters.getProfileOverrideProperties());
+ }
+
+ String connectorId = CommandlineConnectorChooser.chooseCommandlineConnectorForSign(signParameters.getSignatureDevice());
+
+ ConnectorParameters cp = new ConnectorParameters();
+ cp.setProfileId(signParameters.getSignatureProfileId());
+ cp.setSignatureKeyIdentifier(signParameters.getSignatureKeyIdentifier());
+ Connector c = at.gv.egiz.pdfas.framework.ConnectorFactory.createConnector(connectorId, cp);
+
+ SignatureData sd = new SignatureDataImpl(new PdfDataSourceAdapter(signatorInfo.getSignatureData()), signatorInfo.getSignatureData().getMimeType());
+ SignSignatureObject sso = PdfAS.sign(sd, c, signParameters.getTimeStamperImpl());
+ ((SignatureDetailInformationImpl)signatorInfo).setSignSignatureObject(sso);
+
+ return finishSign(signParameters, signatorInfo);
+ } finally {
+ OverridePropertyHolder.removeProperties();
+ DynamicSignatureProfileImpl.disposeLocalProfile();
+ }
+ }
+
+ public SignResult finishSign(SignParameters signParameters, SignatureDetailInformation signatureDetailInformation)
+ throws PdfAsException {
+ try {
+ CheckHelper.checkSignParametersForSignAfterPrepare(signParameters, true);
+ CheckHelper.checkSignatureDetailInformation(signatureDetailInformation);
+
+ if (signParameters.getProfileOverrideProperties() != null) {
+ OverridePropertyHolder.setOverrideProps(signParameters.getProfileOverrideProperties());
+ }
+
+ Signator signator = createSignator(signParameters.getSignatureType());
+
+ SignatorInformation signatorInfo = ((SignatureDetailInformationImpl)signatureDetailInformation).getSignatorInfo();
+ signator.finishSign(signatorInfo, new DataSinkAdapter(signParameters.getOutput()));
+
+ return new SignResultImpl(
+ signParameters.getOutput(),
+ signatorInfo.getSignSignatureObject().getX509Certificate(),
+ new ActualSignaturePositionAdapter(signatorInfo.getActualTablePos()),
+ signatorInfo.getNonTextualObjects());
+ } finally {
+ OverridePropertyHolder.removeProperties();
+ DynamicSignatureProfileImpl.disposeLocalProfile();
+ }
+ }
}
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/api/commons/SignatureProfileImpl.java b/src/main/java/at/gv/egiz/pdfas/impl/api/commons/SignatureProfileImpl.java index 90e2ca0..b825c82 100644 --- a/src/main/java/at/gv/egiz/pdfas/impl/api/commons/SignatureProfileImpl.java +++ b/src/main/java/at/gv/egiz/pdfas/impl/api/commons/SignatureProfileImpl.java @@ -36,6 +36,11 @@ public class SignatureProfileImpl implements SignatureProfile { * Short description of the profile.
*/
protected String profileDescription;
+
+ /**
+ * true if this is the default profile, false otherwise.
+ */
+ protected boolean defaultProfile = false;
/**
* Constructor.
@@ -60,12 +65,14 @@ public class SignatureProfileImpl implements SignatureProfile { * The profile description.
* @param moaKeyIdentifier
* The MOA key identifier of this profile.
+ * @param isDefault
*/
- public SignatureProfileImpl(String profileId, String profileDescription, String moaKeyIdentifier) {
+ public SignatureProfileImpl(String profileId, String profileDescription, String moaKeyIdentifier, boolean isDefault) {
this.profileId = profileId;
this.moaKeyIdentifier = moaKeyIdentifier;
this.profileDescription = profileDescription;
this.signatureBlockEntries = new Properties();
+ this.defaultProfile = isDefault;
}
/**
@@ -121,4 +128,11 @@ public class SignatureProfileImpl implements SignatureProfile { .toString();
}
+ /**
+ *
+ */
+ public boolean isDefault() {
+ return this.defaultProfile;
+ }
+
}
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/api/commons/TextBasedDataSourceApiAdapter.java b/src/main/java/at/gv/egiz/pdfas/impl/api/commons/TextBasedDataSourceApiAdapter.java new file mode 100644 index 0000000..5363c42 --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/impl/api/commons/TextBasedDataSourceApiAdapter.java @@ -0,0 +1,72 @@ +/**
+ *
+ */
+package at.gv.egiz.pdfas.impl.api.commons;
+
+import java.io.InputStream;
+
+import at.gv.egiz.pdfas.api.io.TextBased;
+import at.gv.egiz.pdfas.framework.input.TextDataSource;
+
+/**
+ * Adapter that converts a framework DataSource to an API PdfDataSource.
+ *
+ * @author wprinz
+ */
+public class TextBasedDataSourceApiAdapter implements at.gv.egiz.pdfas.api.io.DataSource, TextBased
+{
+ /**
+ * The framework DataSource to be adapted to an API DataSource.
+ */
+ protected TextDataSource frameworkDataSource = null;
+
+ /**
+ * Constructor.
+ *
+ * @param frameworkDataSource
+ * The framework DataSource to be adapted to an API DataSource.
+ */
+ public TextBasedDataSourceApiAdapter(TextDataSource frameworkDataSource)
+ {
+ this.frameworkDataSource = frameworkDataSource;
+ }
+
+ /**
+ * @see at.gv.egiz.pdfas.api.io.DataSource#createInputStream()
+ */
+ public InputStream createInputStream()
+ {
+ return this.frameworkDataSource.createInputStream();
+ }
+
+ /**
+ * @see at.gv.egiz.pdfas.api.io.DataSource#getAsByteArray()
+ */
+ public byte[] getAsByteArray()
+ {
+ return this.frameworkDataSource.getAsByteArray();
+ }
+
+ /**
+ * @see at.gv.egiz.pdfas.api.io.DataSource#getLength()
+ */
+ public int getLength()
+ {
+ return this.frameworkDataSource.getLength();
+ }
+
+ public String getCharacterEncoding()
+ {
+ return "UTF-8";
+ }
+
+ public String getMimeType()
+ {
+ return "text/plain";
+ }
+
+ public String getText() {
+ return this.frameworkDataSource.getText();
+ }
+
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/api/internal/PdfAsInternalObject.java b/src/main/java/at/gv/egiz/pdfas/impl/api/internal/PdfAsInternalObject.java new file mode 100644 index 0000000..c457bd3 --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/impl/api/internal/PdfAsInternalObject.java @@ -0,0 +1,293 @@ +package at.gv.egiz.pdfas.impl.api.internal;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Vector;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import at.gv.egiz.pdfas.api.PdfAs;
+import at.gv.egiz.pdfas.api.analyze.AnalyzeResult;
+import at.gv.egiz.pdfas.api.commons.Constants;
+import at.gv.egiz.pdfas.api.commons.SignatureInformation;
+import at.gv.egiz.pdfas.api.exceptions.PdfAsException;
+import at.gv.egiz.pdfas.api.internal.LocalBKUParams;
+import at.gv.egiz.pdfas.api.internal.PdfAsInternal;
+import at.gv.egiz.pdfas.api.internal.SignatureEntry;
+import at.gv.egiz.pdfas.api.sign.SignParameters;
+import at.gv.egiz.pdfas.api.sign.SignResult;
+import at.gv.egiz.pdfas.api.sign.SignatureDetailInformation;
+import at.gv.egiz.pdfas.api.verify.VerifyResult;
+import at.gv.egiz.pdfas.exceptions.ErrorCode;
+import at.gv.egiz.pdfas.framework.ConnectorParameters;
+import at.gv.egiz.pdfas.framework.input.TextDataSource;
+import at.gv.egiz.pdfas.impl.api.CheckHelper;
+import at.gv.egiz.pdfas.impl.api.analyze.AnalyzeResultImpl;
+import at.gv.egiz.pdfas.impl.api.commons.PdfDataSourceAdapter;
+import at.gv.egiz.pdfas.impl.api.commons.SignatureInformationAdapter;
+import at.gv.egiz.pdfas.impl.api.sign.SignatureDetailInformationImpl;
+import at.gv.egiz.pdfas.impl.api.verify.VerifyResultAdapter;
+import at.gv.egiz.pdfas.impl.input.TextDataSourceImpl;
+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.ConnectorException;
+import at.knowcenter.wag.egov.egiz.exceptions.ConnectorFactoryException;
+import at.knowcenter.wag.egov.egiz.exceptions.NormalizeException;
+import at.knowcenter.wag.egov.egiz.exceptions.SettingsException;
+import at.knowcenter.wag.egov.egiz.exceptions.SignatureException;
+import at.knowcenter.wag.egov.egiz.exceptions.SignatureTypesException;
+import at.knowcenter.wag.egov.egiz.framework.SignatorFactory;
+import at.knowcenter.wag.egov.egiz.pdf.SignatureHolder;
+import at.knowcenter.wag.egov.egiz.pdf.TextualSignatureHolder;
+import at.knowcenter.wag.egov.egiz.sig.ConnectorFactory;
+import at.knowcenter.wag.egov.egiz.sig.ConnectorInformation;
+import at.knowcenter.wag.egov.egiz.sig.SignatureData;
+import at.knowcenter.wag.egov.egiz.sig.SignatureDataImpl;
+import at.knowcenter.wag.egov.egiz.sig.SignatureObject;
+import at.knowcenter.wag.egov.egiz.sig.SignatureResponse;
+import at.knowcenter.wag.egov.egiz.sig.SignatureTypes;
+import at.knowcenter.wag.egov.egiz.sig.connectors.LocalConnector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.BKUHelper;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.BKUPostConnection;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.EnvelopedBase64BKUConnector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.LocRefDetachedBKUConnector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.OldEnvelopingBase64BKUConnector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.SignSignatureObject;
+import at.knowcenter.wag.egov.egiz.sig.connectors.mocca.LocRefDetachedMOCCAConnector;
+import at.knowcenter.wag.egov.egiz.sig.sigid.HotfixIdFormatter;
+import at.knowcenter.wag.egov.egiz.sig.signaturelayout.SignatureLayoutHandlerFactory;
+import at.knowcenter.wag.egov.egiz.sig.signatureobject.SignatureObjectHelper;
+
+/**
+ *
+ * @author mmocnik
+ *
+ */
+public class PdfAsInternalObject implements PdfAsInternal {
+ /**
+ * The log.
+ */
+ private static Log log = LogFactory.getLog(CheckHelper.class);
+
+ public void verifyBKUSupport(LocalBKUParams bkuParams) throws ConnectorException, SettingsException {
+ String bkuIdentifier = BKUHelper.getBKUIdentifier(bkuParams);
+ SignatureLayoutHandlerFactory.verifyBKUSupport(bkuIdentifier);
+ }
+
+ public SignResult finishLocalSign(PdfAs pdfAs, SignParameters signParameters, SignatureDetailInformation sdi, LocalBKUParams bkuParams, String xmlResponse) throws PdfAsException {
+ LocalConnector c = chooseLocalConnectorForSign(signParameters.getSignatureDevice(), signParameters.getSignatureProfileId(), "not needed");
+ SignSignatureObject sso = c.analyzeSignResponse(buildResponseProperties(bkuParams, xmlResponse));
+ ((SignatureDetailInformationImpl)sdi).setSignSignatureObject(sso);
+
+ return pdfAs.finishSign(signParameters, sdi);
+ }
+
+ private Properties buildResponseProperties(LocalBKUParams bkuParams, String xmlResponse) {
+ Properties ret = new Properties();
+ if (bkuParams.getServer() != null)
+ ret.setProperty(BKUPostConnection.BKU_SERVER_HEADER_KEY, bkuParams.getServer());
+ if (bkuParams.getUserAgent() != null)
+ ret.setProperty(BKUPostConnection.BKU_USER_AGENT_HEADER_KEY, bkuParams.getUserAgent());
+ if (bkuParams.getSignatureLayout() != null)
+ ret.setProperty(BKUPostConnection.BKU_SIGNATURE_LAYOUT_HEADER_KEY, bkuParams.getSignatureLayout());
+ ret.setProperty(BKUPostConnection.RESPONSE_STRING_KEY, xmlResponse);
+ return ret;
+ }
+
+ private LocalConnector chooseLocalConnectorForSign(String connector, String profile, String loc_ref_url) throws ConnectorException{
+ ConnectorParameters cp = new ConnectorParameters();
+ cp.setProfileId(profile);
+
+ if (Constants.SIGNATURE_DEVICE_MOC.equals(connector)) {
+
+ return new LocRefDetachedMOCCAConnector(cp, loc_ref_url);
+
+ } else if (Constants.SIGNATURE_DEVICE_BKU.equals(connector)){
+
+ return new LocRefDetachedBKUConnector(cp, loc_ref_url);
+
+ }
+
+ log.error("Currently only the BKU connector is fully implemented.");
+ return new LocRefDetachedBKUConnector(cp, loc_ref_url);
+ }
+
+ private LocalConnector chooseLocalConnectorForVerify(String connector,
+ PdfASID sig_kz, String sig_id, String profile, String loc_ref_url) throws ConnectorException
+ {
+ log.debug("Choosing LocalConnector for verification...");
+
+ log.debug("connector type = " + connector);
+ log.debug("sig_kz = " + sig_kz);
+ log.debug("sig_id = " + sig_id);
+
+ if (!connector.equals("bku"))
+ {
+ log.error("Currently only the BKU connector is fully implemented.");
+ }
+
+ if (sig_kz == null)
+ {
+ log.debug("sig_kz is null -> must be old signature -> choosing old Base64 connector.");
+
+ return new OldEnvelopingBase64BKUConnector(profile);
+ }
+
+ log.debug("sig_kz is not null -> must be one of the newer ... base64, base64 hotfix, or detached");
+
+ if (sig_kz.getVersion().equals(SignatorFactory.VERSION_1_0_0))
+ {
+ log.debug("sig_kz version is 1.0.0 -> choosing base64 (old or hotfix)");
+
+ if (sig_id == null)
+ {
+ log.debug("sig_id is null, which means that it is a MOA signature -> choose a hotfix base64 connector (thus it is moa - it doesn't matter).");
+
+ return new EnvelopedBase64BKUConnector(profile);
+ }
+
+ String[] sig_id_parts = sig_id.split("@");
+ if (sig_id_parts.length == 2)
+ {
+ log.debug("sig_id has 2 @-separated parts -> choosing old base64 connector");
+
+ return new OldEnvelopingBase64BKUConnector(profile);
+ }
+ if (sig_id_parts[0].equals(HotfixIdFormatter.SIG_ID_PREFIX))
+ {
+ log.debug("sig_id prefix is hotfix -> choosing hotfix base64 connector");
+
+ return new EnvelopedBase64BKUConnector(profile);
+ }
+
+ throw new ConnectorException(300, "The SIG_KZ version is 1.0.0, but SIG_ID is neither MOA nor Old base64 nor Hotfix base64 ???'");
+ }
+ if (sig_kz.getVersion().equals(SignatorFactory.VERSION_1_1_0) || sig_kz.getVersion().equals(SignatorFactory.VERSION_1_2_0))
+ {
+ log.debug("sig_kz version is 1.1.0/1.2.0 -> choosing detached (loc ref) connector.");
+
+ ConnectorParameters cp = new ConnectorParameters();
+ cp.setProfileId(profile);
+ return new LocRefDetachedBKUConnector(cp, loc_ref_url);
+ }
+
+ throw new ConnectorException(ErrorCode.UNSUPPORTED_SIGNATURE, "The SIG_KZ version '" + sig_kz.getVersion() + "' is unknown.");
+ }
+
+
+ public String getLocalServiceAddress(String profile, String device) throws SettingsException {
+ SettingsReader settings = SettingsReader.getInstance();
+
+ String key = device + ".sign.url";
+ String value = settings.getValueFromKey("sig_obj." + profile + "." + key); //$NON-NLS-1$//$NON-NLS-2$
+ if (value == null)
+ {
+ value = settings.getValueFromKey(key);
+ }
+ return value;
+ }
+
+ public String prepareLocalSignRequest(SignParameters signParameters, String loc_ref_url,
+ SignatureDetailInformation sdi) throws ConnectorException {
+ LocalConnector c = chooseLocalConnectorForSign(signParameters.getSignatureDevice(), signParameters.getSignatureProfileId(), loc_ref_url);
+ SignatureData sd = new SignatureDataImpl(new PdfDataSourceAdapter(sdi.getSignatureData()), sdi.getSignatureData().getMimeType(), sdi.getSignatureData().getCharacterEncoding());
+ String sign_request = c.prepareSignRequest(sd);
+ return sign_request;
+ }
+
+ public AnalyzeResult analyzeFromRawText(String rawText, Map sigValues) throws SignatureException, SettingsException, SignatureTypesException, NormalizeException {
+ String normalizedText = PdfAS.normalizeText(rawText);
+
+ SignatureObject signature_object = new SignatureObject();
+
+ String default_type = SettingsReader.getInstance().getValueFromKey(SignatureTypes.DEFAULT_TYPE);
+ signature_object.setSigType(default_type);
+ signature_object.initByType();
+
+ Iterator sigKeys = sigValues.keySet().iterator();
+ while (sigKeys.hasNext()){
+ String key = (String)sigKeys.next();
+ signature_object.setSigValue(key, (String)sigValues.get(key));
+ }
+
+ TextDataSource tds = new TextDataSourceImpl(normalizedText);
+ SignatureHolder new_holder = new TextualSignatureHolder(tds, signature_object);
+
+ SignatureInformation si = new SignatureInformationAdapter(new_holder);
+ List signatures = new Vector();
+ signatures.add(si);
+ AnalyzeResult ret = new AnalyzeResultImpl(signatures);
+ return ret;
+ }
+
+ public String prepareLocalVerifyRequest(SignatureInformation sigInfo, String connector, String profile, String loc_ref_url) throws SignatureException, ConnectorException {
+
+ SignatureHolder holder = (SignatureHolder)sigInfo.getInternalSignatureInformation();
+ SignatureObject s = holder.getSignatureObject();
+
+ SignatureData sd = PdfAS.convertSignatureHolderToSignatureData(holder);
+
+ SignSignatureObject so = SignatureObjectHelper.convertSignatureObjectToSignSignatureObject(s);
+
+ LocalConnector local_conn = chooseLocalConnectorForVerify(connector, s.getKZ(), so.id, profile, loc_ref_url);
+
+ String request_string = local_conn.prepareVerifyRequest(sd, so, null);
+ return request_string;
+ }
+
+ public VerifyResult finishLocalVerify(SignatureInformation sigInfo, String connector, String profile, String loc_ref_url, String xmlResponse) throws SignatureException, ConnectorException {
+ SignatureHolder holder = (SignatureHolder)sigInfo.getInternalSignatureInformation();
+ SignatureObject s = holder.getSignatureObject();
+
+ SignSignatureObject so = SignatureObjectHelper.convertSignatureObjectToSignSignatureObject(s);
+
+ LocalConnector local_conn = chooseLocalConnectorForVerify(connector, s.getKZ(), so.id, profile, loc_ref_url);
+
+ Properties props = new Properties();
+ props.setProperty(BKUPostConnection.RESPONSE_STRING_KEY, xmlResponse);
+ SignatureResponse sigResponse = local_conn.analyzeVerifyResponse(props);
+ return new VerifyResultAdapter(sigResponse, holder, null);
+ }
+
+ public SignatureEntry getSignatureEntryFromSignatureInformation(String key,
+ SignatureInformation sigInfo) {
+
+ SignatureHolder holder = (SignatureHolder)sigInfo.getInternalSignatureInformation();
+ SignatureObject s = holder.getSignatureObject();
+ at.knowcenter.wag.egov.egiz.sig.SignatureEntry internalEntry = s.getSigEntry(key);
+ if (internalEntry == null)
+ return null;
+ SignatureEntry ret = new SignatureEntry(key);
+ ret.setCaption(internalEntry.getCaption());
+ ret.setValue(internalEntry.getValue());
+ return ret;
+ }
+
+ public String getSignedText(SignatureInformation sigInfo) {
+ SignatureHolder holder = (SignatureHolder)sigInfo.getInternalSignatureInformation();
+ if (holder instanceof TextualSignatureHolder)
+ return ((TextualSignatureHolder)holder).getSignedText();
+ return null;
+ }
+
+ public Map getConnectorsAvailableForWeb() throws ConnectorFactoryException {
+ ConnectorInformation ci[] = ConnectorFactory.getConnectorInformationArray();
+
+ Map ret = new HashMap();
+ for (int i = 0; i < ci.length; i++)
+ {
+ String id = ci[i].getIdentifier();
+ if (ConnectorFactory.isAvailableForWeb(id))
+ {
+ ret.put(id, ci[i].getDescription());
+ }
+ }
+ return ret;
+ }
+
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/api/sign/SignatureDetailInformationImpl.java b/src/main/java/at/gv/egiz/pdfas/impl/api/sign/SignatureDetailInformationImpl.java new file mode 100644 index 0000000..d893411 --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/impl/api/sign/SignatureDetailInformationImpl.java @@ -0,0 +1,167 @@ +package at.gv.egiz.pdfas.impl.api.sign;
+
+import java.security.cert.X509Certificate;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import at.gv.egiz.pdfas.api.io.DataSource;
+import at.gv.egiz.pdfas.api.sign.SignatureDetailInformation;
+import at.gv.egiz.pdfas.api.sign.pos.SignaturePosition;
+import at.gv.egiz.pdfas.framework.input.TextDataSource;
+import at.gv.egiz.pdfas.framework.signator.SignatorInformation;
+import at.gv.egiz.pdfas.impl.api.commons.DataSourceApiAdapter;
+import at.gv.egiz.pdfas.impl.api.commons.TextBasedDataSourceApiAdapter;
+import at.knowcenter.wag.egov.egiz.pdf.EGIZDate;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.SignSignatureObject;
+
+/**
+ *
+ * @author exthex
+ *
+ */
+public class SignatureDetailInformationImpl implements SignatureDetailInformation {
+
+ private DataSource signatureData;
+ private SignaturePosition signaturePosition;
+ private List nonTextualObjects;
+ private String dateString;
+ private Date signDate;
+ private String issuer;
+ private Map issuerDNMap;
+ private String name;
+ private String serialNumber;
+ private String sigAlgorithm;
+ private String sigID;
+ private String sigKZ;
+ private String signatureValue;
+ private String sigTimeStamp;
+ private Map subjectDNMap;
+ private X509Certificate x509Certificate;
+ private boolean textual;
+ private Properties responseProperties;
+ private SignatorInformation signatorInfo;
+
+ public DataSource getSignatureData() {
+ return this.signatureData;
+ }
+
+ public SignaturePosition getSignaturePosition() {
+ return this.signaturePosition;
+ }
+
+ public List getNonTextualObjects() {
+ return this.nonTextualObjects;
+ }
+
+ public Date getSignDate() {
+ return this.signDate;
+ }
+
+ public String getIssuer() {
+ return this.issuer;
+ }
+
+ public Map getIssuerDNMap() {
+ return this.issuerDNMap;
+ }
+
+ public String getSubjectName() {
+ return this.name;
+ }
+
+ public String getSerialNumber() {
+ return this.serialNumber;
+ }
+
+ public String getSigAlgorithm() {
+ return this.sigAlgorithm;
+ }
+
+ public String getSigID() {
+ return this.sigID;
+ }
+
+ public String getSigKZ() {
+ return this.sigKZ;
+ }
+
+ public String getSignatureValue() {
+ return this.signatureValue;
+ }
+
+ public String getSigTimeStamp() {
+ return this.sigTimeStamp;
+ }
+
+ public Map getSubjectDNMap() {
+ return this.subjectDNMap;
+ }
+
+ public X509Certificate getX509Certificate() {
+ return this.x509Certificate;
+ }
+
+ public boolean isTextual() {
+ return textual;
+ }
+
+ public boolean isBinary() {
+ return !textual;
+ }
+
+ public void setSignSignatureObject(SignSignatureObject sso) {
+ this.dateString = sso.getDate();
+ if (this.dateString != null){
+ this.signDate = EGIZDate.parseDateFromString(this.dateString);
+ }
+ this.issuer = sso.getIssuer();
+ this.issuerDNMap = sso.getIssuerDNMap();
+ this.name = sso.getName(); //extracted from x509Certificate
+ this.serialNumber = sso.getSerialNumber(); //extracted from x509Certificate
+ this.sigAlgorithm = sso.getSigAlgorithm();
+ this.sigID = sso.getSigID();
+ this.sigKZ = sso.getSigKZ();
+ this.signatureValue = sso.getSignatureValue();
+ this.sigTimeStamp = sso.getSigTimeStamp();
+ this.subjectDNMap = sso.getSubjectDNMap();
+ this.x509Certificate = sso.getX509Certificate();
+ this.responseProperties = sso.response_properties;
+ if (this.signatorInfo != null){
+ this.signatorInfo.setSignSignatureObject(sso);
+ }
+ }
+
+ public SignSignatureObject getSignSignatureObject() {
+ SignSignatureObject ret = new SignSignatureObject();
+ ret.date = this.dateString;
+ ret.id = this.sigID;
+ ret.issuer = this.issuer;
+ ret.issuerDNMap = this.issuerDNMap;
+ ret.kz = this.sigKZ;
+ ret.response_properties = this.responseProperties;
+ ret.sigAlgorithm = this.sigAlgorithm;
+ ret.signatureValue = this.signatureValue;
+ ret.sigTimeStamp = this.sigTimeStamp;
+ ret.subjectDNMap = this.subjectDNMap;
+ ret.x509Certificate = this.x509Certificate;
+
+ return ret;
+ }
+
+ public SignatorInformation getSignatorInfo() {
+ return this.signatorInfo;
+ }
+
+ public void setSignatorInformation(SignatorInformation signatorInformation){
+ this.signatorInfo = signatorInformation;
+ this.signaturePosition = new ActualSignaturePositionAdapter(signatorInformation.getActualTablePos());
+ this.nonTextualObjects = signatorInformation.getNonTextualObjects();
+ at.gv.egiz.pdfas.framework.input.DataSource dataSource = signatorInformation.getSignatureData().getDataSource();
+ if (dataSource instanceof TextDataSource)
+ this.signatureData = new TextBasedDataSourceApiAdapter((TextDataSource)dataSource);
+ else
+ this.signatureData = new DataSourceApiAdapter(dataSource);
+ }
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/input/correction/ExternalCorrector.java b/src/main/java/at/gv/egiz/pdfas/impl/input/correction/ExternalCorrector.java index 25df6a8..998277a 100644 --- a/src/main/java/at/gv/egiz/pdfas/impl/input/correction/ExternalCorrector.java +++ b/src/main/java/at/gv/egiz/pdfas/impl/input/correction/ExternalCorrector.java @@ -17,7 +17,7 @@ import at.gv.egiz.pdfas.framework.input.PdfDataSource; import at.gv.egiz.pdfas.framework.input.correction.Corrector;
import at.gv.egiz.pdfas.impl.input.FileBased;
import at.gv.egiz.pdfas.impl.input.FileBasedPdfDataSourceImpl;
-import at.gv.egiz.pdfas.web.helper.TempDirHelper;
+import at.gv.egiz.pdfas.utils.TempDirHelper;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
import at.knowcenter.wag.egov.egiz.exceptions.SettingNotFoundException;
import at.knowcenter.wag.egov.egiz.exceptions.SettingsException;
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java index 9315477..6a19b42 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java @@ -50,7 +50,6 @@ import at.gv.egiz.pdfas.impl.api.commons.PdfDataSourceAdapter; import at.gv.egiz.pdfas.impl.input.ByteArrayPdfDataSourceImpl;
import at.gv.egiz.pdfas.impl.input.helper.DataSourceHelper;
import at.gv.egiz.pdfas.utils.PDFASUtils;
-import at.gv.egiz.pdfas.web.VerifySessionInformation;
import at.knowcenter.wag.egov.egiz.cfg.OverridePropertyHolder;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
@@ -824,50 +823,35 @@ public abstract class PdfAS }
/**
+ * Verify a list of signatures
*
- * @param extended_signature_info
- * @param connectorType
+ * @param extended_signature_info a list of {@link ExtendedSignatureInformation} to be verified
+ * @param connectorType the connector to use for verification
* @param returnHashInputData
* @param verificationTime
- * @return
+ * @param verifySignatureAtIndex only verify the signature at the given index in the extended_signature_info list. A value < 0 means to verify all signatures in the list.
+ * @return a list of {@link SignatureResponse}s
* @throws PDFDocumentException
* @throws NormalizeException
* @throws SignatureException
* @throws ConnectorException
* @throws ConnectorFactoryException
*/
- public static List verifyExtendedSignatureHolders(List extended_signature_info, String connectorType, boolean returnHashInputData, Date verificationTime) throws PDFDocumentException, NormalizeException, SignatureException, ConnectorException, ConnectorFactoryException
+ public static List verifyExtendedSignatureHolders(List extended_signature_info, String connectorType, boolean returnHashInputData, Date verificationTime, int verifySignatureAtIndex) throws PDFDocumentException, NormalizeException, SignatureException, ConnectorException, ConnectorFactoryException
{
List results = new ArrayList();
for (int i = 0; i < extended_signature_info.size(); i++)
{
- ExtendedSignatureInformation sigInfo = (ExtendedSignatureInformation) extended_signature_info.get(i);
- SignatureInformation si = sigInfo.getSignatureInformation();
- SignatureHolder holder = (SignatureHolder) si.getInternalSignatureInformation();
-
- SignatureResponse result = verify(holder, connectorType, returnHashInputData, verificationTime, sigInfo.getXmlDsigData());
- results.add(result);
- }
- return results;
- }
-
- public static List verifySignatureHoldersWeb(List signature_holders,
- VerifySessionInformation si, String loc_ref) throws PDFDocumentException, NormalizeException, SignatureException, ConnectorException
- {
- List results = new ArrayList();
-
- for (int i = 0; i < signature_holders.size(); i++)
- {
- SignatureHolder holder = (SignatureHolder) signature_holders.get(i);
+ if (verifySignatureAtIndex < 0 || verifySignatureAtIndex == i)
+ {
+ ExtendedSignatureInformation sigInfo = (ExtendedSignatureInformation) extended_signature_info.get(i);
+ SignatureInformation si = sigInfo.getSignatureInformation();
+ SignatureHolder holder = (SignatureHolder) si.getInternalSignatureInformation();
- // store the current holder on the session so that moa can obtain
- // it from the RetrieveSignatureDataServlet.
- si.moa_holder = holder;
-
- SignatureResponse result = verifyWeb(holder, si.connector, loc_ref);
- results.add(result);
+ SignatureResponse result = verify(holder, connectorType, returnHashInputData, verificationTime, sigInfo.getXmlDsigData());
+ results.add(result);
+ }
}
-
return results;
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java b/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java index 6151b24..1bd6c03 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java @@ -42,7 +42,7 @@ import org.apache.commons.logging.LogFactory; import at.gv.egiz.pdfas.api.commons.Constants;
import at.gv.egiz.pdfas.api.exceptions.ConfigUtilsException;
import at.gv.egiz.pdfas.utils.ConfigUtils;
-import at.gv.egiz.pdfas.web.helper.TempDirHelper;
+import at.gv.egiz.pdfas.utils.TempDirHelper;
import at.knowcenter.wag.egov.egiz.PdfAS;
import at.knowcenter.wag.egov.egiz.exceptions.SettingNotFoundException;
import at.knowcenter.wag.egov.egiz.exceptions.SettingsException;
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUHelper.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUHelper.java index ac6e221..da98d47 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUHelper.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUHelper.java @@ -14,8 +14,6 @@ import java.util.TimeZone; import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import javax.servlet.http.HttpServletRequest;
-
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -24,6 +22,7 @@ import at.gv.egiz.pdfas.algorithmSuite.AlgorithmMapper; import at.gv.egiz.pdfas.algorithmSuite.AlgorithmSuiteObject;
import at.gv.egiz.pdfas.algorithmSuite.AlgorithmSuiteUtil;
import at.gv.egiz.pdfas.api.commons.Constants;
+import at.gv.egiz.pdfas.api.internal.LocalBKUParams;
import at.gv.egiz.pdfas.exceptions.ErrorCode;
import at.gv.egiz.pdfas.exceptions.external.ExternalErrorException;
import at.gv.egiz.pdfas.impl.input.helper.DataSourceHelper;
@@ -626,6 +625,11 @@ public final class BKUHelper String bkuUserAgentHeader = parsedResponseProperties.getProperty(BKUPostConnection.BKU_USER_AGENT_HEADER_KEY);
String bkuSignatureLayout = parsedResponseProperties.getProperty(BKUPostConnection.BKU_SIGNATURE_LAYOUT_HEADER_KEY);
+
+ return getBKUIdentifier(bkuServerHeader, bkuUserAgentHeader, bkuSignatureLayout);
+ }
+
+ public static String getBKUIdentifier(String bkuServerHeader, String bkuUserAgentHeader, String bkuSignatureLayout) {
log.debug("BKU response header \"user-agent\": " + bkuUserAgentHeader);
log.debug("BKU response header \"server\": " + bkuServerHeader);
@@ -660,27 +664,9 @@ public final class BKUHelper return result;
}
-
- public static String getBKUIdentifier(HttpServletRequest request) {
- return getBKUIdentifier(getBKUProperties(request));
- }
-
- public static Properties getBKUProperties(HttpServletRequest request) {
- Properties props = new Properties();
- String server = request.getHeader("server");
- String userAgent = request.getHeader("user-agent");
- String signatureLayout = request.getHeader(Constants.BKU_HEADER_SIGNATURE_LAYOUT);
- if (server != null) {
- props.setProperty(BKUPostConnection.BKU_SERVER_HEADER_KEY, server);
- }
- if (userAgent != null) {
- props.setProperty(BKUPostConnection.BKU_USER_AGENT_HEADER_KEY, userAgent);
- }
- if (signatureLayout != null) {
- props.setProperty(BKUPostConnection.BKU_SIGNATURE_LAYOUT_HEADER_KEY, signatureLayout);
- }
- return props;
+
+ public static String getBKUIdentifier(LocalBKUParams bkuParams) {
+ return getBKUIdentifier(bkuParams.getServer(), bkuParams.getUserAgent(), bkuParams.getSignatureLayout());
}
-
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/SignSignatureObject.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/SignSignatureObject.java index 09b7e6b..cbe9aaa 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/SignSignatureObject.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/SignSignatureObject.java @@ -53,8 +53,8 @@ public class SignSignatureObject implements Serializable, MandatorySignatureInfo public X509Certificate x509Certificate = null;
// dferbas
- private Map subjectDNMap = new HashMap();
- private Map issuerDNMap = new HashMap();
+ public Map subjectDNMap = new HashMap();
+ public Map issuerDNMap = new HashMap();
/**
* @see at.knowcenter.wag.egov.egiz.sig.signatureobject.MandatorySignatureInformation#getDate()
|