diff options
Diffstat (limited to 'pdf-as-legacy/src/main/java')
60 files changed, 5354 insertions, 0 deletions
| diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/PdfAsFactory.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/PdfAsFactory.java new file mode 100644 index 00000000..95ffa42b --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/PdfAsFactory.java @@ -0,0 +1,126 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas;
 +
 +import java.io.File;
 +
 +import at.gv.egiz.pdfas.api.PdfAs;
 +import at.gv.egiz.pdfas.api.exceptions.PdfAsException;
 +import at.gv.egiz.pdfas.wrapper.PdfAsObject;
 +
 +/**
 + * Main factory for creating a PDF-AS API Instance (PdfAs Interface).
 + * 
 + * @see PdfAs
 + * 
 + * @author wprinz
 + */
 +public class PdfAsFactory
 +{
 +   /**
 +    * Creates a PDF-AS API instance for the given work directory.
 +    * 
 +    * @param workDirectory
 +    *          The work directory. If <code>null</code> the configuration is assumed to be located
 +    *          within the user's home directory. Note: IAIK JCE and IAIK ECC security provders are
 +    *          automatically registered.
 +    * 
 +    * @return Returns an instance of the PDF-AS API.
 +    * @throws IllegalArgumentException
 +    *           Thrown, if the workDirectory doesn't exist.
 +    * @throws PdfAsException
 +    *           Thrown, if the work directory does not meet its requirements, or
 +    *           if the config file is invalid.
 +    * @see PdfAS#USERHOME_CONFIG_FOLDER          
 +    */
 +   public static PdfAs createPdfAs(File workDirectory) throws PdfAsException
 +   {
 +      return createPdfAs(workDirectory);
 +   }
 +   
 +   /**
 +    * Creates a PDF-AS API instance for the given work directory.
 +    * 
 +    * WARNING registerProvider is IGNORED as ov Version 4.0
 +    * 
 +    * @param workDirectory
 +    *          The work directory. If <code>null</code> the configuration is assumed to be located
 +    *          within the user's home directory.
 +    * 
 +   * @param registerProvider <code>true</code>: automatically registers IAIK JCE and ECC Provider;
 +   * <code>false</code>: providers will NOT be automatically registered, providers
 +   * needed have to be registered by the API user 
 +    * @return Returns an instance of the PDF-AS API.
 +    * @throws IllegalArgumentException
 +    *           Thrown, if the workDirectory doesn't exist.
 +    * @throws PdfAsException
 +    *           Thrown, if the work directory does not meet its requirements, or
 +    *           if the config file is invalid.
 +    * @see PdfAS#USERHOME_CONFIG_FOLDER          
 +    */
 +   public static PdfAs createPdfAs(File workDirectory, boolean registerProvider) throws PdfAsException
 +   {
 +     return new PdfAsObject(workDirectory);
 +   }
 +   
 +   /**
 +    * Creates a PDF-AS API instance assuming that the configuration is located within the user's
 +    * home directory. Note: IAIK JCE and IAIK ECC security providers are automatically registered.
 +    * 
 +    * @return Returns an instance of the PDF-AS API.
 +    * @throws IllegalArgumentException
 +    *           Thrown, if the work directory doesn't exist within the user's home directory.
 +    * @throws PdfAsException
 +    *           Thrown, if the work directory does not meet its requirements, or
 +    *           if the config file is invalid.
 +    * @see PdfAS#USERHOME_CONFIG_FOLDER          
 +    */
 +   public static PdfAs createPdfAs() throws PdfAsException
 +   {
 +      return createPdfAs(null);
 +   }
 +   
 +   /**
 +    * Creates a PDF-AS API instance assuming that the configuration is located within the user's
 +    * home directory.
 +    * 
 +    * WARNING registerProvider is IGNORED as ov Version 4.0
 +    * 
 +    * @return Returns an instance of the PDF-AS API.
 +    * @param registerProvider <code>true</code>: automatically registers IAIK JCE and ECC Provider;
 +    * <code>false</code>: providers will NOT be automatically registered, providers
 +    * needed have to be registered by the API user 
 +    * @throws IllegalArgumentException
 +    *           Thrown, if the work directory doesn't exist within the user's home directory.
 +    * @throws PdfAsException
 +    *           Thrown, if the work directory does not meet its requirements, or
 +    *           if the config file is invalid.
 +    * @see PdfAS#USERHOME_CONFIG_FOLDER          
 +    */
 +   public static PdfAs createPdfAs(boolean registerProvider) throws PdfAsException
 +   {
 +     return createPdfAs(null, registerProvider);
 +   }
 +
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/PdfAs.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/PdfAs.java new file mode 100644 index 00000000..3fda87c3 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/PdfAs.java @@ -0,0 +1,285 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api;
 +
 +import java.util.List;
 +
 +import at.gv.egiz.pdfas.api.analyze.AnalyzeParameters;
 +import at.gv.egiz.pdfas.api.analyze.AnalyzeResult;
 +import at.gv.egiz.pdfas.api.commons.DynamicSignatureLifetimeEnum;
 +import at.gv.egiz.pdfas.api.commons.DynamicSignatureProfile;
 +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;
 +import at.gv.egiz.pdfas.api.verify.VerifyResult;
 +import at.gv.egiz.pdfas.api.verify.VerifyResults;
 +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.framework.signator.SignatorInformation;
 +
 +/**
 + * The PDF-AS API main interface.
 + * 
 + * <p>
 + * Create an Object implementing this interface using the proper factory.
 + * </p>
 + * 
 + * @author wprinz
 + * @author exthex
 + */
 +public interface PdfAs
 +{
 +// 23.11.2010 changed by exthex - added:
 +// reconstructXMLDSIG(ReconstructXMLDsigParameters reconstructXMLDsigParameters)
 +// reconstructXMLDSIG(ReconstructXMLDsigAfterAnalysisParameters reconstructXMLDsigParameters)
 +// verify(VerifyAfterReconstructXMLDsigParameters verifyAfterReconstructXMLDsigParameters)
 +
 +// 16.12.2010 changed by exthex - added:
 +// prepareSign(SignParameters signParameters)
 +// sign(SignParameters signParameters, SignatureDetailInformation signatureDetailInformation)
 +// finishSign(SignParameters signParameters, SignatureDetailInformation signatureDetailInformation)
 +
 +  /**
 +   * Signs a PDF document using PDF-AS.
 +   * 
 +   * @param signParameters
 +   *          The sign parameters.
 +   * @return Returns the signed document plus additional information.
 +   * @throws PdfAsException
 +   *           Thrown, if an error occurs.
 +   * 
 +   * @see SignParameters
 +   * @see SignResult
 +   */
 +  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
 +   *          The verify parameters.
 +   * @return Returns the verification results.
 +   * @throws PdfAsException
 +   *           Thrown, if an error occurs.
 +   * 
 +   * @see VerifyParameters
 +   * @see VerifyResults
 +   * @see VerifyResult
 +   */
 +  public VerifyResults verify(VerifyParameters verifyParameters) throws PdfAsException;
 +
 +  /**
 +   * Analyzes a document for signatures and returns a verify-able list of such.
 +   * 
 +   * @param analyzeParameters
 +   *          The analyzation parameters.
 +   * @return Returns a list of verify-able signatures that were found in the
 +   *         document.
 +   * @throws PdfAsException
 +   *           Thrown on error.
 +   * 
 +   * @see AnalyzeParameters
 +   * @see AnalyzeResult
 +   * @see {@link #verify(AnalyzeResult)}
 +   */
 +  public AnalyzeResult analyze(AnalyzeParameters analyzeParameters) throws PdfAsException;
 +
 +  /**
 +   * Reconstruct the <xmldsig:Signature> from the given parameters.
 +   * 
 +   * @param reconstructXMLDsigParameters
 +   *         The data from which to reconstruct the xmldsig
 +   * @return a list of xmldsigs, one for each signature in the document
 +   * @throws PdfAsException if the reconstruction fails
 +   */
 +  public ReconstructXMLDsigResult reconstructXMLDSIG(ReconstructXMLDsigParameters reconstructXMLDsigParameters) throws PdfAsException;
 +
 +  /**
 +   * Reconstruct the <xmldsig:Signature> from the given parameters.
 +   * 
 +   * @param reconstructXMLDsigParameters
 +   *         The data from which to reconstruct the xmldsigs
 +   * @return a list of xmldsigs, one for each signature in the document
 +   * @throws PdfAsException
 +   */
 +  public ReconstructXMLDsigResult reconstructXMLDSIG(ReconstructXMLDsigAfterAnalysisParameters reconstructXMLDsigParameters) throws PdfAsException;
 +  
 +  /**
 +   * Verifies a list of signatures that have been analyzed previously.
 +   * 
 +   * @param verifyAfterAnalysisParameters The parameters.
 +   * 
 +   * @return Returns the verification results.
 +   * @throws PdfAsException
 +   *           Thrown on error.
 +   * 
 +   * @see AnalyzeResult
 +   * @see VerifyAfterAnalysisParameters
 +   * @see VerifyResults
 +   * @see VerifyResult
 +   * @see {@link #analyze(AnalyzeParameters)}
 +   */
 +  public VerifyResults verify(VerifyAfterAnalysisParameters verifyAfterAnalysisParameters) throws PdfAsException;
 +
 +  /**
 +   * Verifies a list of signatures that have been analyzed previously and the xmldsigs have been reconstructed.
 +   * 
 +   * @param verifyAfterReconstructXMLDsigParameters
 +   *           The parameters.
 +   * @return the verification results.
 +   * @throws PdfAsException
 +   *           Thrown on error.
 +   */
 +  public VerifyResults verify(VerifyAfterReconstructXMLDsigParameters verifyAfterReconstructXMLDsigParameters) throws PdfAsException;
 +  
 +  /**
 +   * Reloads the configuration from the work directory.
 +   * 
 +   * @throws PdfAsException
 +   *           Thrown, if an error occurs.
 +   */
 +  public void reloadConfig() throws PdfAsException;
 +
 +  /**
 +   * Returns the list of information objects about activated profiles available in the
 +   * configuration.
 +   * 
 +   * <p>
 +   * Note: Currently the profile information consists of the profile Id and the
 +   * MOA Key Id only.
 +   * </p>
 +   * <p>
 +   * Note: In near future the profile management will be moved out of the config
 +   * file into an API class representation of the profiles which may render this
 +   * (and related) methods obsolete.
 +   * </p>
 +   * 
 +   * @return Returns the list of {@link SignatureProfile} objects with
 +   *         information about active profiles available in the configuration.
 +   * @throws PdfAsException
 +   *           Thrown on error.
 +   * 
 +   * @see SignatureProfile
 +   */
 +  public List getProfileInformation() throws PdfAsException;
 +
 +  /**
 +   * Create a signature profile dynamically. You have do apply() it for usage. See {@link SignatureProfile}.
 +   * @param parentProfile a parent profile id to inherit all properties
 +   * @param mode lifetime mode
 +   * @return the created signature profile to work with.
 +   */
 +  public DynamicSignatureProfile createDynamicSignatureProfile(String parentProfile, DynamicSignatureLifetimeEnum mode);
 +
 +  /**
 +   * Create a signature profile dynamically. You have to provide a unique name and have do apply() it for usage. See {@link SignatureProfile}.
 +   * It is recommended to use {@link #createDynamicSignatureProfile(String, DynamicSignatureLifetimeEnum)} that generates 
 +   * a unique name on its own.
 +   * @see DynamicSignatureProfile
 +   * @param parentProfile a parent profile id to inherit all properties
 +   * @param myUniqueName a unique name for the profile
 +   * @param mode lifetime mode
 +   * @return the created signature profile to work with.
 +   */
 +  public DynamicSignatureProfile createDynamicSignatureProfile(String myUniqueName, String parentProfile, DynamicSignatureLifetimeEnum mode);
 +  
 +  /**
 +   * Create a signature profile dynamically. You have fill it with properties and apply() it for usage. See {@link SignatureProfile}.
 +   * <br> 
 +   * It is recommended to use {@link #createDynamicSignatureProfile(String, DynamicSignatureLifetimeEnum)} that inherits from an 
 +   * existing profile saving you a lot of work.
 +   * @param mode lifetime mode
 +   * @return the created signature profile to work with.
 +   * @see DynamicSignatureProfile
 +   */
 +  public DynamicSignatureProfile createEmptyDynamicSignatureProfile(DynamicSignatureLifetimeEnum mode);
 +  
 +  /**
 +   * Create a signature profile dynamically. You have fill it with properties and apply() it for usage. See {@link SignatureProfile}.
 +   * <br> 
 +   * It is recommended to use {@link #createDynamicSignatureProfile(String, DynamicSignatureLifetimeEnum)} that inherits from an 
 +   * existing profile saving you a lot of work.
 +   * @param myUniqueName a unique name for the profile
 +   * @param mode lifetime mode
 +   * @return the created signature profile to work with.
 +   */
 +  public DynamicSignatureProfile createEmptyDynamicSignatureProfile(String myUniqueName, DynamicSignatureLifetimeEnum mode);
 +
 +  /**
 +   * Loads an existing dynamic signature profile by its name. Profiles are saved when they are applied 
 +   * and it has {@link DynamicSignatureLifetimeEnum#MANUAL}
 +   * @param profileName
 +   * @return the signature profile or <code>null</code> if not found.
 +   * @see DynamicSignatureProfile
 +   */
 +  public DynamicSignatureProfile loadDynamicSignatureProfile(String profileName);
 +  
 +  /**
 +   * Prepares the signature of the given PDF document. The table for the signature data is placed but not filled.<br/>
 +   * Usually used for preview.
 +   * 
 +   * @param signParameters
 +   *          The sign parameters.
 +   * @return Only the {@link SignatureDetailInformation#getSignaturePosition()}, {@link SignatureDetailInformation#getNonTextualObjects()}, {@link SignatureDetailInformation#getSignatureData()} are filled.
 +   * @throws PdfAsException if something goes wrong during the process
 +   */
 +  public SignatureDetailInformation prepareSign(SignParameters signParameters) throws PdfAsException;
 +  
 +  /**
 +   * Finish the signature process. The PDF is filled with the signature data.<br/>
 +   * Usually used if some steps like the actual signing are to be performed externally.
 +   * 
 +   * @param signParameters
 +   *          The sign parameters.
 +   * @param signatureDetailInformation
 +   *          The signature detail information.
 +   * @return
 +   * @throws PdfAsException
 +   */
 +  public SignResult finishSign(SignParameters signParameters, SignatureDetailInformation signatureDetailInformation) throws PdfAsException;
 +
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/analyze/AnalyzeParameters.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/analyze/AnalyzeParameters.java new file mode 100644 index 00000000..1ce7057f --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/analyze/AnalyzeParameters.java @@ -0,0 +1,107 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.analyze;
 +
 +import at.gv.egiz.pdfas.api.commons.Constants;
 +import at.gv.egiz.pdfas.api.io.DataSource;
 +
 +/**
 + * Parameter object that holds the analyze parameters.
 + * 
 + * @author wprinz
 + */
 +public class AnalyzeParameters
 +{
 +
 +  /**
 +   * The document to be analyzed.
 +   */
 +  protected DataSource document = null;
 +
 +  /**
 +   * The mode of operation how the document is analyzed.
 +   * 
 +   * <p>
 +   * May be {@link Constants#VERIFY_MODE_BINARY_ONLY} to check the document for
 +   * binary signatures only (very fast). Or may be
 +   * {@link Constants#VERIFY_MODE_SEMI_CONSERVATIVE} to perform a semi
 +   * conservative (optimized) text and binary verification (slow). Or may be
 +   * {@link Constants#VERIFY_MODE_FULL_CONSERVATIVE} to perform a full
 +   * conservative text and binary verification (very slow).
 +   * </p>
 +   */
 +  protected String verifyMode = Constants.VERIFY_MODE_FULL_CONSERVATIVE;
 +
 +  protected boolean returnNonTextualObjects = false;
 +  
 +  protected boolean hasBeenCorrected = false;
 +  
 +  /**
 +   * @return the document
 +   */
 +  public DataSource getDocument()
 +  {
 +    return this.document;
 +  }
 +
 +  /**
 +   * @param document the document to set
 +   */
 +  public void setDocument(DataSource document)
 +  {
 +    this.document = document;
 +  }
 +
 +  /**
 +   * @return the verifyMode
 +   */
 +  public String getVerifyMode()
 +  {
 +    return this.verifyMode;
 +  }
 +
 +  /**
 +   * @param verifyMode the verifyMode to set
 +   */
 +  public void setVerifyMode(String verifyMode)
 +  {
 +    this.verifyMode = verifyMode;
 +  }
 +
 +  public boolean isReturnNonTextualObjects() {
 +     return this.returnNonTextualObjects;
 +  }
 +  
 +  /**
 +   * Tells if non text object of the signed pdf should be extracted and returned.
 +   * One should show this to the user, especially in case of textual signature.
 +   * Defaults to <tt>false</tt>
 +   * 
 +   * @param returnNonTextualObjects
 +   */
 +  public void setReturnNonTextualObjects(boolean returnNonTextualObjects) {
 +     this.returnNonTextualObjects = returnNonTextualObjects;
 +  }
 +  
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/analyze/AnalyzeResult.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/analyze/AnalyzeResult.java new file mode 100644 index 00000000..9b913ae4 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/analyze/AnalyzeResult.java @@ -0,0 +1,63 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.analyze;
 +
 +import java.util.List;
 +
 +import at.gv.egiz.pdfas.api.commons.SignatureInformation;
 +import at.gv.egiz.pdfas.api.exceptions.PdfAsException;
 +
 +/**
 + * The result of an analyze operation, which is a list of verifyable signatures.
 + * 
 + * @author wprinz
 + * 
 + */
 +public interface AnalyzeResult
 +{
 +  /**
 +   * Returns the list of found signatures.
 +   * 
 +   * @return Returns a list of {@link SignatureInformation} objects representing all
 +   *         found signatures.
 +   * @throws PdfAsException
 +   *           Thrown on error.
 +   * 
 +   * @see SignatureInformation
 +   */
 +  public List getSignatures() throws PdfAsException;
 +  
 +  public List getNoSignatures();
 +  
 +  /**
 +   * Tells if the document has been corrected before verification. The correction maybe done
 +   * after a first failing parse to repair a document (if enabled in the configuration 
 +   * <code>correct_document_on_verify_if_necessary</code>). The correction can only work for textual 
 +   * signatures. Binary signatures are lost anyhow.
 +   * @return
 +   */
 +  public boolean hasBeenCorrected();
 +
 +  
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/analyze/NonTextObjectInfo.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/analyze/NonTextObjectInfo.java new file mode 100644 index 00000000..08297b7a --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/analyze/NonTextObjectInfo.java @@ -0,0 +1,99 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.analyze;
 +
 +/**
 + * Encapsulates information about non textual objects in a pdf document.
 + * 
 + * @author dferbas
 + *
 + */
 +public class NonTextObjectInfo {
 +   public static final String TYPE_IMAGE = "image";
 +   public static final String TYPE_ANNOTATION = "annotation";
 +   
 +   private String objectType;
 +   private String subType;
 +   private String name;
 +   private int pageNr;
 +   private double width;
 +   private double height;
 +   
 +   public String getObjectType() {
 +      return this.objectType;
 +   }
 +   
 +   public void setObjectType(String objectType) {
 +      this.objectType = objectType;
 +   }
 +   
 +   public String getName() {
 +      return this.name;
 +   }
 +   
 +   public void setName(String name) {
 +      this.name = name;
 +   }
 +   
 +   public int getPageNr() {
 +      return this.pageNr;
 +   }
 +   
 +   public void setPageNr(int pageNr) {
 +      this.pageNr = pageNr;
 +   }
 +   
 +   public double getWidth() {
 +      return this.width;
 +   }
 +   
 +   public void setWidth(double width) {
 +      this.width = width;
 +   }
 +   
 +   public double getHeight() {
 +      return this.height;
 +   }
 +   
 +   public void setHeight(double height) {
 +      this.height = height;
 +   }
 +   
 +   public String getSubType() {
 +      return this.subType;
 +   }
 +
 +   public void setSubType(String subType) {
 +      this.subType = subType;
 +   }
 +   
 +   
 +
 +   public String toString() {
 +      return "NonTextObjectInfo [height=" + this.height + ", name=" + this.name + ", objectType="
 +            + this.objectType + ", pageNr=" + this.pageNr + ", subType=" + this.subType
 +            + ", width=" + this.width + "]";
 +   }  
 +
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/analyze/package-info.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/analyze/package-info.java new file mode 100644 index 00000000..9c56d142 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/analyze/package-info.java @@ -0,0 +1,8 @@ +/** + *  + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas.api.analyze;
\ No newline at end of file diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/Constants.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/Constants.java new file mode 100644 index 00000000..2bc68ea0 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/Constants.java @@ -0,0 +1,189 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.commons;
 +
 +
 +/**
 + * Contains commonly used constants.
 + *
 + * @author wprinz
 + */
 +public final class Constants
 +{
 +
 +  /**
 +   * Hidden default constructor.
 +   */
 +  private Constants()
 +  {
 +    // empty
 +  }
 +
 +  /**
 +   * A binary signature.
 +   * This value should not be modified due to external dependencies!
 +   */
 +  public static final String SIGNATURE_TYPE_BINARY = "binary";
 +
 +  /**
 +   * A textual signature.
 +   * This value should not be modified due to external dependencies!
 +   */
 +  public static final String SIGNATURE_TYPE_TEXTUAL = "textual";
 +
 +  /**
 +   * The default signature type (one of "textual", "binary", "detachedtextual").
 +   */
 +  public static final String DEFAULT_SIGNATURE_TYPE = SIGNATURE_TYPE_BINARY;
 +
 +  /**
 +   * A "detached" textual signature.
 +   *
 +   * <p>
 +   * The document text is signed, but instead of returning the pdf with the signature block,
 +   * the sign result XML of the connector is returned.
 +   * </p>
 +   */
 +  public static final String SIGNATURE_TYPE_DETACHEDTEXTUAL = "detachedtextual";
 +
 +  /**
 +   * The signature device moa.
 +   * This value should not be modified due to external dependencies!
 +   */
 +  public static final String SIGNATURE_DEVICE_MOA = "moa";
 +
 +  /**
 +   * The signature device bku.
 +   * This value should not be modified due to external dependencies!
 +   */
 +  public static final String SIGNATURE_DEVICE_BKU = "bku";
 +
 +  /**
 +   * The signature device a1.
 +   * This value should not be modified due to external dependencies!
 +   */
 +  public static final String SIGNATURE_DEVICE_A1 = "a1";
 +
 +  /**
 +   * The signature device MOCCA (online bku).
 +   * This value should not be modified due to external dependencies!
 +   */
 +  public static final String SIGNATURE_DEVICE_MOC = "moc";
 +
 +  /**
 +   * Added by rpiazzi
 +   * The signature device MOBILE.
 +   * This value should not be modified due to external dependencies!
 +   */
 +  public static final String SIGNATURE_DEVICE_MOBILE = "mobile";
 +
 +  /**
 +   * Added by rpiazzi
 +   * The signature device MOBILETEST for the test version of the MOBILE CCS.
 +   * This value should not be modified due to external dependencies!
 +   */
 +  public static final String SIGNATURE_DEVICE_MOBILETEST = "mobiletest";
 +
 +  /**
 +   * Only binary signatures are verified.
 +   */
 +  public static final String VERIFY_MODE_BINARY_ONLY = "binaryOnly";
 +
 +  /**
 +   * Binary and textual signatures are verified with time optimization.
 +   *
 +   * <p>
 +   * This mode of operation tries to minimize the numbers of text extractions,
 +   * which are very time intensive, at the cost of some rare cases, in which some
 +   * signatures may not be found.
 +   * </p>
 +   */
 +  public static final String VERIFY_MODE_SEMI_CONSERVATIVE = "semiConservative";
 +
 +  /**
 +   * Binary and textual signatures are verified.
 +   */
 +  public static final String VERIFY_MODE_FULL_CONSERVATIVE = "fullConservative";
 +
 +  /**
 +   * All signatures are verified.
 +   */
 +  public static final int VERIFY_ALL = -1;
 +
 +  /**
 +   * The system property that may be used to declare the pdf-as configuration folder.
 +   */
 +  public static final String CONFIG_DIR_SYSTEM_PROPERTY = "pdf-as.work-dir";
 +
 +  /**
 +   * The zip file containing the default configuration.
 +   */
 +  public static final String DEFAULT_CONFIGURATION_ZIP_RESOURCE = "DefaultConfiguration.zip";
 +
 +  /**
 +   * The configuration folder for pdf-as within the user's home folder.
 +   */
 +  public static final String USERHOME_CONFIG_FOLDER = "PDF-AS";
 +
 +  /**
 +   * The name of the directory, where temporary files are stored.
 +   */
 +  public static final String TEMP_DIR_NAME = "pdfastmp";
 +
 +  public static final String BKU_HEADER_SIGNATURE_LAYOUT = "SignatureLayout";
 +
 +  public static final String ADOBE_SIG_FILTER = "Adobe.PDF-AS";
 +
 +  /**
 +   * Strict matching mode for placeholder extraction.<br/>
 +   * If the placeholder with the given id is not found in the document, an exception will be thrown.
 +   */
 +  public static final int PLACEHOLDER_MATCH_MODE_STRICT = 0;
 +
 +  /**
 +   * A moderate matching mode for placeholder extraction.<br/>
 +   * If the placeholder with the given id is not found in the document, the first placeholder without an id will be taken.<br/>
 +   * If there is no such placeholder, the signature will be placed as usual, according to the pos parameter of the signature profile used.
 +   */
 +  public static final int PLACEHOLDER_MATCH_MODE_MODERATE = 1;
 +
 +  /**
 +   * A more lenient matching mode for placeholder extraction.<br/>
 +   * If the placeholder with the given id is not found in the document, the first found placeholder will be taken, regardless if it has an id set, or not.<br/>
 +   * If there is no placeholder at all, the signature will be placed as usual, according to the pos parameter of the signature profile used.
 +   */
 +  public static final int PLACEHOLDER_MATCH_MODE_LENIENT = 2;
 +
 +  /**
 +   * Identifier for QR based placeholders.
 +   */
 +  public static final String QR_PLACEHOLDER_IDENTIFIER = "PDF-AS-POS";
 +
 +  /**
 +   * The name of a logger used for statistical logging.
 +   */
 +  public static final String STATISTIC_LOGGER_NAME = "statistic";
 +
 +}
 +
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/DynamicSignatureLifetimeEnum.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/DynamicSignatureLifetimeEnum.java new file mode 100644 index 00000000..7b3d17b2 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/DynamicSignatureLifetimeEnum.java @@ -0,0 +1,72 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.commons;
 +
 +import java.io.Serializable;
 +
 +/**
 + * Pseudo enum defining lifetime models for {@link DynamicSignatureProfile}s.
 + * 
 + * @author exthex
 + *
 + */
 +public final class DynamicSignatureLifetimeEnum implements Serializable {
 +   private static final long serialVersionUID = 1L;
 +   
 +   private int value;
 +   
 +   /**
 +    * Automatic lifetime bound to one sign process
 +    */   
 +   public static final DynamicSignatureLifetimeEnum AUTO = new DynamicSignatureLifetimeEnum(1);
 +   
 +   /**
 +    * Manual lifetime making YOU responsible for calling {@link DynamicSignatureProfile#dispose()}.
 +    */
 +   public static final DynamicSignatureLifetimeEnum MANUAL = new DynamicSignatureLifetimeEnum(2);
 +   
 +   private DynamicSignatureLifetimeEnum(int val) {
 +      this.value = val;      
 +   }
 +
 +   public int hashCode() {
 +      return value;
 +   }
 +
 +   public boolean equals(Object obj) {
 +      if (this == obj)
 +         return true;
 +      if (obj == null)
 +         return false;
 +      if (getClass() != obj.getClass())
 +         return false;
 +      DynamicSignatureLifetimeEnum other = (DynamicSignatureLifetimeEnum) obj;
 +      if (value != other.value)
 +         return false;
 +      return true;
 +   }
 +   
 +   
 +
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/DynamicSignatureProfile.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/DynamicSignatureProfile.java new file mode 100644 index 00000000..7418f4dc --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/DynamicSignatureProfile.java @@ -0,0 +1,125 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.commons;
 +
 +import at.gv.egiz.pdfas.api.PdfAs;
 +import at.gv.egiz.pdfas.api.sign.SignParameters;
 +
 +/**
 + * A dynamic signature profile. It is used to define a signature profile like the ones from pdf-as/config.properties at runtime.
 + * After creation via {@link PdfAs} you can set properties via {@link #setPropertyRaw(String, String)} 
 + * or {@link #setFieldValue(String, String)}.<br>
 + * You have to call {@link #apply()} to use the profile. The identifying name (e.g. for {@link SignParameters#setSignatureProfileId(String)}
 + * can be obtained via {@link #getName()}.<br>
 + * Depending on the {@link DynamicSignatureLifetimeEnum} the profile can be alive and usable till you {@link #dispose()} it manually.
 + * <p>
 + * Sample usage:<br>
 + *  <pre>
 +      SignParameters sp = new SignParameters();
 +      . . .           
 +      sp.setSignatureType(Constants.SIGNATURE_TYPE_TEXTUAL);
 +      sp.setSignatureDevice(Constants.SIGNATURE_DEVICE_MOA);
 +
 +      // create a new dynamic profile based on SIGNATURBLOCK_DE (every property is copied) with manual lifetime
 +      DynamicSignatureProfile dsp = pdfAs.createDynamicSignatureProfile("myUniqueName", "SIGNATURBLOCK_DE", 
 +            DynamicSignatureLifetimeEnum.MANUAL);  
 +            
 +      // set something
 +      dsp.setPropertyRaw("key.SIG_META", "Statement");
 +      dsp.setPropertyRaw("value.SIG_META", "respect to the man in the icecream van ${subject.EMAIL}");
 +      dsp.setPropertyRaw("value.SIG_LABEL", "./images/signatur-logo_en.png");
 +      dsp.setPropertyRaw("table.main.Style.halign", "right");
 +      
 +      // mandatory: apply the profile, you have to apply again after changes (overriding your previous setting)
 +      dsp.apply();                 
 +      sp.setSignatureProfileId(dsp.getName());            
 +      
 +      // execute PDF-AS
 +      pdfAs.sign(sp);              
 +      
 +      . . .
 +                       
 +     // your profile is saved and you can obtain it again anytime later:
 +      dsp = pdfAs.loadDynamicSignatureProfile("myUniqueName");
 +      // use it for another sign.
 +      // dont forget to dispose() sometimes because it was manual lifetime
 +      System.out.println(dsp.getName());
 + *  </pre>
 + *  </p>
 + * 
 + * @author exthex
 + *
 + */
 +public interface DynamicSignatureProfile {
 +
 +   /**
 +    * Get the name of the dynamic signature profile. Equals the <b>SignatureProfileId</b>
 +    * @return
 +    */
 +   public abstract String getName();   
 +
 +   /**
 +    * Set a field value for the profile. Use {@link #setPropertyRaw(String, String)} for setting any property.<br>
 +    * For example to set <code>sig_obj.MEIN_DYN_SIGNATURBLOCK.value.SIG_META</code> just use <code>SIG_META</code> as fieldName. 
 +    * @param fieldName the name of the field
 +    * @param value the value to set
 +    */
 +   public abstract void setFieldValue(String fieldName, String value);
 +
 +   /**
 +    * Get a field value from the profile. See {@link #setFieldValue(String, String)}
 +    * @param fieldName
 +    * @return
 +    */
 +   public abstract String getFieldValue(String fieldName);
 +   
 +   /**
 +    * Set any property for the signature profile. 
 +    * Uses the same keys as the property file without the "prefix" for the profile.
 +    * For example to set <code>sig_obj.MEIN_DYN_SIGNATURBLOCK.key.SIG_META</code> use <code>key.SIG_META</code>
 +    * @param key property key
 +    * @param val property value
 +    */
 +   public void setPropertyRaw(String key, String val);
 +
 +   /**
 +    * Get any property from the signature profile. See {@link #setPropertyRaw(String, String)} for details.
 +    * @param key
 +    * @return
 +    */
 +   public String getPropertyRaw(String key);      
 +
 +   /**
 +    * Apply the signature profile. Call this after all properties are set and you want to use the profile. It is then added
 +    * to the globally available signature profiles. Depending on the lifetime model {@link DynamicSignatureLifetimeEnum} you
 +    * have to {@link #dispose()} it manually when not needed anymore.
 +    */
 +   public abstract void apply();
 +
 +   /**
 +    * Disposes the signature profile from the global store. Call this for {@link DynamicSignatureLifetimeEnum#MANUAL} only. 
 +    */
 +   public abstract void dispose();
 +  
 +}
\ No newline at end of file diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/DynamicSignatureProfileImpl.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/DynamicSignatureProfileImpl.java new file mode 100644 index 00000000..e1f31f7a --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/DynamicSignatureProfileImpl.java @@ -0,0 +1,217 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.commons;
 +
 +import java.util.Enumeration;
 +import java.util.HashMap;
 +import java.util.Map;
 +import java.util.Properties;
 +
 +import org.apache.commons.lang.StringUtils;
 +
 +import at.gv.egiz.pdfas.api.PdfAs;
 +import at.knowcenter.wag.egov.egiz.cfg.PropertyTree;
 +import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
 +import at.knowcenter.wag.egov.egiz.sig.SignatureTypes;
 +
 +// TODO exception types?
 +/**
 + * Implementation class of the {@link DynamicSignatureProfile}. Don't use this class directly. Use {@link PdfAs} to create and the 
 + * {@link DynamicSignatureProfile} interface for manipulation.
 + * @author exthex
 + *
 + */
 +public class DynamicSignatureProfileImpl implements DynamicSignatureProfile {
 +   private String name;   
 +   private Properties newProps = new Properties();
 +   private int dynamicTypeCounter = 0;   
 +   private static Map profiles = new HashMap();
 +   private static ThreadLocal localProfiles = new ThreadLocal();
 +   private DynamicSignatureLifetimeEnum lifeMode; 
 +   
 +
 +   private DynamicSignatureProfileImpl(DynamicSignatureLifetimeEnum mode, String name) {
 +      if (name != null) {
 +         this.name = name;
 +      } else {
 +         this.name = createDynamicTypeName();
 +      }
 +      this.lifeMode = mode;
 +   }
 +   
 +   public static DynamicSignatureProfileImpl createFromParent(String myUniqueName, String parentProfile, DynamicSignatureLifetimeEnum mode) {
 +      DynamicSignatureProfileImpl res = new DynamicSignatureProfileImpl(mode, myUniqueName);
 +      res.initFromParent(parentProfile);
 +      return res;
 +   }
 +   
 +   private void store() {
 +      if (lifeMode.equals(DynamicSignatureLifetimeEnum.MANUAL)) {
 +         profiles.put(this.getName(), this);
 +      } else if (lifeMode.equals(DynamicSignatureLifetimeEnum.AUTO)) {
 +         localProfiles.set(this);
 +      }
 +   }
 +   
 +   private void remove() {
 +      if (lifeMode.equals(DynamicSignatureLifetimeEnum.MANUAL)) {
 +         profiles.remove(this);
 +      } else if (lifeMode.equals(DynamicSignatureLifetimeEnum.AUTO)) {
 +         localProfiles.set(null);
 +      }
 +   }
 +   
 +   public static void disposeLocalProfile() {
 +      DynamicSignatureProfileImpl profile = (DynamicSignatureProfileImpl) localProfiles.get();
 +      if (profile != null) {       
 +         profile.dispose();
 +      }
 +   }
 +   
 +   public static DynamicSignatureProfileImpl createEmptyProfile(String myUniqueName, DynamicSignatureLifetimeEnum mode) {
 +      return new DynamicSignatureProfileImpl(mode, myUniqueName);      
 +   }
 +   
 +   public static DynamicSignatureProfileImpl loadProfile(String name) {
 +      return (DynamicSignatureProfileImpl) profiles.get(name);
 +   }
 +   
 +   private synchronized String createDynamicTypeName() {
 +      return "dynprofile__#" + this.dynamicTypeCounter++;     
 +   }
 +
 +   /* (non-Javadoc)
 +    * @see at.gv.egiz.pdfas.api.commons.DynamicSignatureProfile#getName()
 +    */
 +   public String getName() {
 +      return name;
 +   }
 +   
 +   /* (non-Javadoc)
 +    * @see at.gv.egiz.pdfas.api.commons.DynamicSignatureProfile#setName(String)
 +    */
 +   public void setName(String uniqueName) {
 +      this.name = uniqueName;
 +   }
 +
 +   public void setPropertyRaw(String key, String val) {
 +      this.newProps.setProperty(localPropName(key), val);
 +   }
 +   
 +   public String getPropertyRaw(String key) {
 +      return this.newProps.getProperty(localPropName(key));
 +   }
 +   
 +   private void assertPropExists(String key) {
 +      if (!this.newProps.containsKey(localPropName(key))) {
 +         throw new RuntimeException("property '" + key + "'not existing, cannot add one");
 +      }
 +   }
 +
 +   private String localPropName(String key) {
 +      return "sig_obj." + this.name + "." + key;
 +   }
 +   
 +   /* (non-Javadoc)
 +    * @see at.gv.egiz.pdfas.api.commons.DynamicSignatureProfile#setFieldValue(java.lang.String, java.lang.String)
 +    */
 +   public void setFieldValue(String fieldName, String value) {
 +      if (SignatureTypes.isRequredSigTypeKey(fieldName)) {
 +         throw new RuntimeException("cannot set value for pre defined signature field names");
 +      }
 +      
 +      String key = "value." +fieldName;
 +      assertPropExists(key);
 +      setPropertyRaw(key, value);
 +   }
 +   
 +   /* (non-Javadoc)
 +    * @see at.gv.egiz.pdfas.api.commons.DynamicSignatureProfile#getFieldValue(java.lang.String)
 +    */
 +   public String getFieldValue(String fieldName) {
 +      return getPropertyRaw("value."+fieldName);           
 +   }
 +
 +   private void initFromParent(String parentProfile) {
 +      try {
 +         SettingsReader cfg = null;
 +
 +         cfg = SettingsReader.getInstance();         
 +
 +         Properties props = cfg.getProperties();
 +         // DTI: props.keys() does not support default properties, therefore we should better use props.propertyNames()
 +//         for (Enumeration e = props.keys(); e.hasMoreElements();) {
 +         for (Enumeration e = props.propertyNames(); e.hasMoreElements();) {
 +            String oldKey = (String) e.nextElement();
 +            if (oldKey.startsWith("sig_obj." + parentProfile + ".")) {
 +               String newKey = StringUtils.replace(oldKey, parentProfile, name);
 +               String val = props.getProperty(oldKey);
 +               this.newProps.put(newKey, val);
 +            }
 +         }
 +         this.newProps.put("sig_obj.types." + name, "on");
 +      } catch (Exception e) {
 +         throw new RuntimeException(e);
 +      }
 +   }
 +   
 +   /* (non-Javadoc)
 +    * @see at.gv.egiz.pdfas.api.commons.DynamicSignatureProfile#register()
 +    */
 +   public synchronized void apply() {
 +      try {
 +         SettingsReader settings = SettingsReader.getInstance();         
 +
 +         settings.getProperties().putAll(this.newProps);
 +
 +         for (Enumeration e = newProps.keys(); e.hasMoreElements();) {
 +            String key = (String) e.nextElement();
 +            settings.getPTree().setKeyValue(key, newProps.getProperty(key));
 +         }
 +     
 +         SignatureTypes.getInstance().addSignatureType(this.name);
 +         store();
 +      } catch (Exception e) {
 +         throw new RuntimeException(e);
 +      }
 +   }
 +   
 +   /* (non-Javadoc)
 +    * @see at.gv.egiz.pdfas.api.commons.DynamicSignatureProfile#dispose()
 +    */
 +   public synchronized void dispose() {
 +      try {
 +         SettingsReader.getInstance().getProperties().keySet().removeAll(newProps.keySet());
 +         
 +         PropertyTree root = SettingsReader.getInstance().getPTree();
 +         root.getSubTree("sig_obj").removeEntry(this.name);         
 +         
 +         SignatureTypes.getInstance().removeSignatureType(this.name);
 +         remove();
 +      } catch (Exception e) {
 +         throw new RuntimeException(e);
 +      }
 +   }
 +   
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/SignatureInformation.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/SignatureInformation.java new file mode 100644 index 00000000..7315af6a --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/SignatureInformation.java @@ -0,0 +1,129 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + *
 + * $Id: SignatureHolder.java,v 1.3 2006/10/11 07:57:58 wprinz Exp $
 + */
 +package at.gv.egiz.pdfas.api.commons;
 +
 +import java.security.cert.X509Certificate;
 +import java.util.Date;
 +import java.util.List;
 +
 +import at.gv.egiz.pdfas.api.analyze.NonTextObjectInfo;
 +import at.gv.egiz.pdfas.api.io.DataSource;
 +
 +/**
 + * Holds the information of one found signature block, which is the signed data
 + * and the corresponding signature information.
 + * 
 + * @author wprinz
 + */
 +public interface SignatureInformation
 +{
 +  /**
 +   * Returns the type of this signature (binary/textual).
 +   * 
 +   * <p>
 +   * May be {@link Constants#SIGNATURE_TYPE_BINARY} or
 +   * {@link Constants#SIGNATURE_TYPE_TEXTUAL}.
 +   * </p>
 +   * 
 +   * @return Returns the type of this signature (binary/textual).
 +   */
 +  public String getSignatureType();
 +
 +  /**
 +   * Returns the DataSource providing the data that was signed.
 +   * 
 +   * <p>
 +   * Note that this is the signed data as sent to the verification device by
 +   * PDF-AS. The verification device (e.g. MOA) may perform several other
 +   * transformations on the data before feeding it to the signature hash
 +   * function. To get the actual hashed data use the ReturnHashInputData mechanism (which is very slow).
 +   * </p>
 +   * 
 +   * @return Returns the DataSource providing the data that was signed.
 +   * 
 +   * @see at.gv.egiz.pdfas.api.verify.VerifyParameters#setReturnHashInputData(boolean)
 +   * @see at.gv.egiz.pdfas.api.verify.VerifyResult#getHashInputData()
 +   * 
 +   */
 +  public DataSource getSignedData();
 +
 +  /**
 +   * Returns the certificate of the signer.
 +   * 
 +   * <p>
 +   * Information like subject name, issuer name or serial number can be
 +   * retrieved form this certificate.
 +   * </p>
 +   * 
 +   * @return Returns the certificate of the signer.
 +   */
 +  public X509Certificate getSignerCertificate();
 +
 +  /**
 +   * Returns the signing time, which is the time when the signature was created.
 +   * 
 +   * @return Returns the signing time, which is the time when the signature was
 +   *         created.
 +   */
 +  public Date getSigningTime();
 +
 +  /**
 +   * Returns additional, internal information about the found signature.
 +   * 
 +   * <p>
 +   * Note that this provides a way for developers to gather core information
 +   * about the signature. What information is returned strongly depends on the
 +   * core implementation.
 +   * </p>
 +   * 
 +   * @return Returns additional, internal information about the signature. Null
 +   *         means that no additional information is available.
 +   */
 +  public Object getInternalSignatureInformation();
 +  
 +  /**
 +   * Returns the embedded /TimeStamp value (b64 encoded) from the signature if available.
 +   * @return 
 +   */
 +  public String getTimeStampValue();
 +  
 +  /**
 +   * 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();
 +  
 +  public void setNonTextualObjects(List nonTextualObjects);
 +
 +  /**
 +   * Returns <code>true</code> if non textual objects have been found, <code>false</code> if not.
 +   * @return <code>true</code> if non textual objects have been found, <code>false</code> if not.
 +   */
 +  public boolean hasNonTextualObjects();
 +
 +
 +}
\ No newline at end of file diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/SignatureProfile.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/SignatureProfile.java new file mode 100644 index 00000000..1325d04f --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/SignatureProfile.java @@ -0,0 +1,87 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.commons;
 +
 +import java.util.Properties;
 +
 +import at.knowcenter.wag.egov.egiz.sig.SignatureTypes.State;
 +
 +/**
 + * Definition of a signature profile.
 + * 
 + * @author wprinz
 + */
 +public interface SignatureProfile {
 +
 +   // TODO: implement full profile support
 +
 +   /**
 +    * Returns the profile id.
 +    * 
 +    * @return Returns the profile id.
 +    */
 +   public String getProfileId();
 +
 +   /**
 +    * Returns the MOA KeyIdentifier.
 +    * 
 +    * @return Returns the MOA KeyIdentifier.
 +    */
 +   public String getMOAKeyIdentifier();
 +
 +   /**
 +    * Returns the entries relevant to the search algorithm for signature blocks.<br/>
 +    * e.g. properties starting with <code>sig_obj.PROFILE.key.</code> and
 +    * properties of the form <code>sig_obj.PROFILE.table.TABLENAME.NUMBER</code>
 +    * where <code>PROFILE</code> is the name of the current profile,
 +    * <code>TABLENAME</code> is the name of a table and <code>NUMBER</code>
 +    * is the number of the specific row within the table <code>TABLENAME</code>.
 +    * 
 +    * @return The entries relevant to the signature block search algorithm as
 +    *         Java properties.
 +    */
 +   public Properties getSignatureBlockEntries();
 +
 +   /**
 +    * Returns the profile description.
 +    * 
 +    * @return The profile description.
 +    */
 +   public String getProfileDescription();
 +
 +   /**
 +    * True only if this is the default profile according to config.
 +    * @return
 +    */
 +   public boolean isDefault();
 +   
 +	/**
 +	 * Returns the state of the signature profile. Signature profiles may be restricted to signature (
 +	 * {@link State#SIGN_ONLY}) or to verification ({@link State#VERIFY_ONLY}).
 +	 * 
 +	 * @return The state of the profile.
 +	 */
 +	public State getState();
 +   
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/package-info.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/package-info.java new file mode 100644 index 00000000..a439a40f --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/commons/package-info.java @@ -0,0 +1,8 @@ +/** + *  + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas.api.commons;
\ No newline at end of file diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/exceptions/ConfigUtilsException.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/exceptions/ConfigUtilsException.java new file mode 100644 index 00000000..644f74ee --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/exceptions/ConfigUtilsException.java @@ -0,0 +1,122 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.exceptions;
 +
 +/**
 + * @author <a href="mailto:thomas.knall@egiz.gv.at">Thomas Knall</a>
 + */
 +public class ConfigUtilsException extends Exception {
 +
 +   /**
 +    * Marker for serialization.
 +    */
 +   private static final long serialVersionUID = 1L;
 +
 +   /**
 +    * The underlying exception.
 +    */
 +   private Exception wrappedException;
 +
 +   /**
 +    * Returns the underlying exception.
 +    *
 +    * @return The underlying exception.
 +    */
 +   public Exception getException() {
 +      return this.wrappedException;
 +   }
 +
 +   /**
 +    * Returns the message of the wrapped exception.
 +    *
 +    * @return The message of the wrapped exception.
 +    */
 +   public String getMessage() {
 +      String message = super.getMessage();
 +      if (message == null && this.wrappedException != null) {
 +         return this.wrappedException.getMessage();
 +      } else {
 +         return message;
 +      }
 +   }
 +
 +   /**
 +    * Instantiation of a new exception based on a message and another (wrapped)
 +    * exception.
 +    *
 +    * @param message
 +    *           The exception message.
 +    * @param exception
 +    *           Another exception.
 +    */
 +   public ConfigUtilsException(final String message, final Exception exception) {
 +      super(message);
 +      this.wrappedException = exception;
 +   }
 +
 +   /**
 +    * Instantiated a new exception based on a message.
 +    *
 +    * @param message
 +    *           The message of the new exception.
 +    */
 +   public ConfigUtilsException(final String message) {
 +      super(message);
 +      this.wrappedException = null;
 +   }
 +
 +   /**
 +    * Instantiates a new exception based on another (wrapped) exception.
 +    *
 +    * @param exception
 +    *           The wrapped exception.
 +    */
 +   public ConfigUtilsException(final Exception exception) {
 +      super();
 +      this.wrappedException = exception;
 +   }
 +
 +   /**
 +    * Instantiates a new (unspecified) exception.
 +    */
 +   public ConfigUtilsException() {
 +      super();
 +      this.wrappedException = null;
 +
 +   }
 +
 +   /**
 +    * Returns the text representation of this instance.
 +    *
 +    * @return The text representation of this instance.
 +    */
 +   public String toString() {
 +      if (this.wrappedException != null) {
 +         return this.wrappedException.toString();
 +      } else {
 +         return super.toString();
 +      }
 +   }
 +
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/exceptions/ErrorCode.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/exceptions/ErrorCode.java new file mode 100644 index 00000000..91dd8d8a --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/exceptions/ErrorCode.java @@ -0,0 +1,115 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.exceptions;
 +
 +/**
 + * Contains constants for the error codes.
 + * 
 + * <p>
 + * In Java 1.5 this would be an enum.
 + * </p>
 + * 
 + * @author wprinz
 + */
 +public final class ErrorCode
 +{
 +  public static final int EXTERNAL_ERROR = 0;
 +  public static final int UNKNOWN_ERROR = 6;
 +  public static final int OUT_OF_MEMORY_ERROR = 7;
 +
 +  public static final int SETTING_NOT_FOUND = 100;
 +  public static final int SETTINGS_EXCEPTION = 101;
 +  public static final int KZ_SETTING_NOT_FOUND = 102;
 +  public static final int NO_EMBEDABLE_TTF_CONFIGURED_FOR_PDFA = 103;
 +  public static final int INVALID_SIGNATURE_LAYOUT_IMPL_CONFIGURED = 104;
 +  public static final int MISSING_HEADER_SERVER_USER_AGENT = 105;
 +  public static final int CIRCULAR_INCLUDE_INSTRUCTION_DETECTED = 106;
 +  public static final int UNABLE_TO_LOAD_DEFAULT_CONFIG = 107;
 +
 +  public static final int DOCUMENT_CANNOT_BE_READ = 201;
 +  public static final int TEXT_EXTRACTION_EXCEPTION = 202;
 +  public static final int CANNOT_WRITE_PDF = 205;
 +  public static final int DOCUMENT_NOT_SIGNED = 206;
 +  public static final int SIGNATURE_TYPES_EXCEPTION = 223;
 +  public static final int FONT_NOT_FOUND = 230;
 +  public static final int DOCUMENT_IS_PROTECTED = 231;
 +  public static final int INVALID_SIGNATURE_DICTIONARY = 232;
 +//23.11.2010 changed by exthex - added error code for failed extraction
 +  public static final int SIGNATURE_PLACEHOLDER_EXTRACTION_FAILED = 233;
 +  
 +	/**
 +	 * Error code for {@code SignatureException}s occurring when trying to sign with a certain signature profile that
 +	 * is not allowed to be used for signature, e.g. because ist has been set to
 +	 * <p/>
 +	 * {@code sig_obj.types.<PROFILE_ID> = verify_only}
 +	 * @author Datentechnik Innovation GmbH
 +	 */
 +  public static final int SIGNATURE_PROFILE_IS_NOT_ALLOWED_FOR_SIGNATURE = 234;
 +  
 +  public static final int INVALID_SIGNATURE_POSITION = 224;
 +  public static final int NO_TEXTUAL_CONTENT = 251;
 +
 +  public static final int SIGNATURE_COULDNT_BE_CREATED = 300;
 +  public static final int SIGNED_TEXT_EMPTY = 301;
 +  public static final int PROFILE_NOT_DEFINED = 302;
 +  public static final int SERIAL_NUMBER_INVALID = 303;
 +  public static final int SIG_CERTIFICATE_CANNOT_BE_READ = 304;
 +  public static final int PROFILE_NOT_USABLE_FOR_TEXT = 305;
 +  
 +  public static final int COULDNT_VERIFY = 310;
 +  
 +  public static final int CERTIFICATE_NOT_FOUND = 313;
 +  public static final int NOT_SEMANTICALLY_EQUAL = 314;
 +
 +  public static final int MODIFIED_AFTER_SIGNATION = 316;
 +  public static final int NON_BINARY_SIGNATURES_PRESENT = 317;  
 +  
 +  public static final int UNSUPPORTED_REPLACES_NAME = 318;
 +  public static final int UNSUPPORTED_SIGNATURE = 319;
 +
 +  public static final int DETACHED_SIGNATURE_NOT_SUPPORTED = 370;
 +  
 +  public static final int SIGNATURE_VERIFICATION_NOT_SUPPORTED = 371;  
 +  public static final int INVALID_SIGNING_TIME = 372;
 +
 +  public static final int BKU_NOT_SUPPORTED = 373;
 +  
 +  public static final int WEB_EXCEPTION = 330;
 +  public static final int UNABLE_TO_RECEIVE_SUITABLE_RESPONSE = 340;
 +
 +  
 +  public static final int NORMALIZER_EXCEPTION = 400;
 +  
 +  public static final int SESSION_EXPIRED = 600;
 +  
 +  public static final int PLACEHOLDER_EXCEPTION = 700;
 +  public static final int CAPTION_NOT_FOUND_EXCEPTION = 701;
 +
 +  public static final int UNABLE_TO_PARSE_ID = 800;
 +  public static final int CORRECTOR_EXCEPTION = 801;
 +  public static final int EXTERNAL_CORRECTOR_TIMEOUT_REACHED = 802;  
 +
 +  
 +  public static final int FUNCTION_NOT_AVAILABLE = 999;
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/exceptions/PdfAsException.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/exceptions/PdfAsException.java new file mode 100644 index 00000000..1fb556a5 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/exceptions/PdfAsException.java @@ -0,0 +1,98 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.exceptions;
 +
 +/**
 + * This exception is the base for all PDF-AS exceptions.
 + * 
 + * <p>
 + * Every PDF-AS Exception has an error code.
 + * </p>
 + * 
 + * @author wprinz
 + */
 +public class PdfAsException extends Exception
 +{
 +  /**
 +   * The error code.
 +   */
 +  protected int errorCode = -1;
 +
 +  /**
 +   * Constructor.
 +   * 
 +   * @param errorCode
 +   *          The error code.
 +   * @param message
 +   *          The detail message.
 +   */
 +  public PdfAsException(int errorCode, String message)
 +  {
 +    super(message);
 +
 +    this.errorCode = errorCode;
 +  }
 +
 +  /**
 +   * Constructor.
 +   * 
 +   * @param errorCode
 +   *          The error code.
 +   * @param message
 +   *          The detail message.
 +   * @param cause
 +   *          The cause.
 +   */
 +  public PdfAsException(int errorCode, String message, Throwable cause)
 +  {
 +    super(message, cause);
 +
 +    this.errorCode = errorCode;
 +  }
 +
 +  /**
 +   * Constructor.
 +   * 
 +   * @param errorCode
 +   *          The error code.
 +   * @param cause
 +   *          The cause.
 +   */
 +  public PdfAsException(int errorCode, Throwable cause)
 +  {
 +    super(cause);
 +
 +    this.errorCode = errorCode;
 +  }
 +
 +  /**
 +   * Returns the error code of this exception.
 +   * 
 +   * @return Returns the error code of this exception.
 +   */
 +  public int getErrorCode()
 +  {
 +    return this.errorCode;
 +  }
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/exceptions/package-info.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/exceptions/package-info.java new file mode 100644 index 00000000..51f23335 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/exceptions/package-info.java @@ -0,0 +1,8 @@ +/** + *  + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas.api.exceptions;
\ No newline at end of file diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/io/DataSink.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/io/DataSink.java new file mode 100644 index 00000000..a539ce03 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/io/DataSink.java @@ -0,0 +1,98 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.io;
 +
 +import java.io.IOException;
 +import java.io.OutputStream;
 +
 +/**
 + * Output document data sink.
 + * 
 + * <p>
 + * Actually, the DataSink can be seen as a factory for creating OutputStreams
 + * with mime type and character encoding provided. This allows the API user to
 + * decide how data is to be stored (e.g. in a file, in a byte array, etc.).
 + * </p>
 + * 
 + * @author wprinz
 + */
 +public interface DataSink
 +{
 +  /**
 +   * Creates an OutputStream for binary data.
 +   * 
 +   * <p>
 +   * Note that the stream may be written only once. Creating another stream
 +   * overwrites the existing one.
 +   * </p>
 +   * 
 +   * @param mimeType
 +   *          The mime type of the output data.
 +   * @return Returns the created output stream.
 +   * @throws IOException
 +   *           Thrown if the stream cannot be created.
 +   */
 +  public OutputStream createOutputStream(String mimeType) throws IOException;
 +
 +  /**
 +   * Creates an OutputStream for character data.
 +   * 
 +   * <p>
 +   * This is basically the same as {@link #createOutputStream(String)}, but
 +   * allows to specify the character encoding.
 +   * </p>
 +   * 
 +   * @param mimeType
 +   *          The mime type of the output data.
 +   * @param characterEncoding
 +   *          The character encoding of the data.
 +   * @return Returns the created output stream.
 +   * @throws IOException
 +   *           Thrown if the stream cannot be created.
 +   */
 +  public OutputStream createOutputStream(String mimeType, String characterEncoding) throws IOException;
 +
 +  /**
 +   * Returns the mime type of the data stream.
 +   * 
 +   * <p>
 +   * This is only valid after a stream has been created.
 +   * </p>
 +   * 
 +   * @return Returns the mime type of the data stream.
 +   */
 +  public String getMimeType();
 +
 +  /**
 +   * Returns the character encoding of the data stream.
 +   * 
 +   * <p>
 +   * This is only valid after a stream has been created. Null means that no
 +   * character encoding was specified for the data (e.g. if the data is binary).
 +   * </p>
 +   * 
 +   * @return Returns the character encoding of the data stream.
 +   */
 +  public String getCharacterEncoding();
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/io/DataSource.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/io/DataSource.java new file mode 100644 index 00000000..41502558 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/io/DataSource.java @@ -0,0 +1,94 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.io;
 +
 +import java.io.InputStream;
 +
 +/**
 + * Input document data source.
 + * 
 + * <p>
 + * This allows the holder of the data to decide how the data is to be stored (e.g. in a File or in a byte array).
 + * </p>
 + * 
 + * @author wprinz
 + * 
 + */
 +public interface DataSource
 +{
 +  /**
 +   * Creates a new InputStream that allows to read out the document's binary
 +   * data from the beginning.
 +   * 
 +   * @return Returns the InputStream with the binary data.
 +   */
 +  public InputStream createInputStream();
 +
 +  /**
 +   * Returns the length (number of bytes) of the stream.
 +   * 
 +   * @return Returns the length (number of bytes) of the stream.
 +   */
 +  public int getLength();
 +
 +  /**
 +   * Returns the data of this DataSource as a byte array for random read only access.
 +   * 
 +   * <p>
 +   * Calling this method indicates that you need a byte array for random
 +   * <strong>read only</strong> access. The DataSource implementation should of
 +   * course cache this byte array to avoid too much memory usage.
 +   * </p>
 +   * <p>
 +   * Performance analysis has shown that the libraries internally convert the
 +   * streams to byte arrays and that file system access is very slow.
 +   * </p>
 +   * <p>
 +   * Never write to this byte array!
 +   * </p>
 +   * 
 +   * @return Returns the data of this DataSource as a byte array for random read only access.
 +   */
 +  public byte[] getAsByteArray();
 +
 +  /**
 +   * Returns the mime type of the data.
 +   * 
 +   * @return Returns the mime type of the data.
 +   */
 +  public String getMimeType();
 +
 +  /**
 +   * Returns the character encoding of the data.
 +   * 
 +   * <p>
 +   * This makes only sense for character based mime types.
 +   * </p>
 +   * 
 +   * @return Returns the character encoding of the data or null if no encoding
 +   *         is applicable (e.g. if the data is binary).
 +   */
 +  public String getCharacterEncoding();
 +
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/io/FileBased.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/io/FileBased.java new file mode 100644 index 00000000..f3d0d0e6 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/io/FileBased.java @@ -0,0 +1,51 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.io;
 +
 +import java.io.File;
 +
 +/**
 + * Tells that the IO element (DataSink or DataSource) is backed by a file in the local file system.
 + * 
 + * <p>
 + * This is a hint that may be used by PDF-AS to optimize data access.
 + * </p>
 + * 
 + * @author wprinz
 + */
 +public interface FileBased
 +{
 +  
 +  /**
 +   * Returns the File "behind" this io element.
 +   * 
 +   * <p>
 +   * This is usually used to determine the file name itself.
 +   * </p>
 +   * 
 +   * @return Returns the File "behind" this io element.
 +   */
 +  public File getFile ();
 +
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/io/TextBased.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/io/TextBased.java new file mode 100644 index 00000000..39602ff4 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/io/TextBased.java @@ -0,0 +1,50 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.io;
 +
 +/**
 + * Tells, that the IO Element (DataSink - but mostly DataSource) is based upon
 + * character data.
 + * 
 + * <p>
 + * This can be used to retrieve the character text directly with the correct
 + * encoding etc.
 + * </p>
 + * <p>
 + * This makes most sense for text DataSources.
 + * </p>
 + * 
 + * @author wprinz
 + */
 +public interface TextBased
 +{
 +
 +  /**
 +   * Returns the text.
 +   * 
 +   * @return Returns the text.
 +   */
 +  public String getText();
 +
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/io/package-info.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/io/package-info.java new file mode 100644 index 00000000..0831b9b9 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/io/package-info.java @@ -0,0 +1,8 @@ +/** + *  + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas.api.io;
\ No newline at end of file diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/package-info.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/package-info.java new file mode 100644 index 00000000..0a065481 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/package-info.java @@ -0,0 +1,8 @@ +/** + *  + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas.api;
\ No newline at end of file diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/SignParameters.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/SignParameters.java new file mode 100644 index 00000000..5533b8b3 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/SignParameters.java @@ -0,0 +1,393 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.sign;
 +
 +import java.util.Properties;
 +
 +import at.gv.egiz.pdfas.api.commons.Constants;
 +import at.gv.egiz.pdfas.api.io.DataSink;
 +import at.gv.egiz.pdfas.api.io.DataSource;
 +import at.gv.egiz.pdfas.api.sign.pos.SignaturePositioning;
 +import at.gv.egiz.pdfas.api.timestamp.TimeStamper;
 +import at.knowcenter.wag.egov.egiz.sig.SignatureTypes;
 +
 +/**
 + * Parameter object that holds the sign parameters.
 + *
 + * @author wprinz
 + */
 +public class SignParameters
 +{
 +// 23.11.2010 changed by exthex - added parameters for placeholder handling
 +
 +  /**
 +   * The document to be signed.
 +   *
 +   * <p>
 +   * The DataSource implementation encapsulates the actual representaion of the
 +   * data. E.g. the DataSource may be File based or byte array based. See
 +   * package at.gv.egiz.pdfas.framework.input and at.gv.pdfas.impl.input
 +   * </p>
 +   */
 +  protected DataSource document = null;
 +
 +  /**
 +   * The type of the signature.
 +   *
 +   * <p>
 +   * May be {@link Constants#SIGNATURE_TYPE_BINARY} or
 +   * {@link Constants#SIGNATURE_TYPE_TEXTUAL}.
 +   * </p>
 +   */
 +  protected String signatureType = Constants.DEFAULT_SIGNATURE_TYPE;
 +
 +  /**
 +   * The signature device to perform the actual signature.
 +   *
 +   * <p>
 +   * May be {@link Constants#SIGNATURE_DEVICE_MOA} or
 +   * {@link Constants#SIGNATURE_DEVICE_BKU}.
 +   * </p>
 +   */
 +  protected String signatureDevice = Constants.SIGNATURE_DEVICE_MOA;
 +
 +  /**
 +   * The signature profile identifier identifying the profile to be used in the
 +   * config file.
 +   *
 +   * <p>
 +   * Note: In near future it will be possible to provide a full specified
 +   * profile here instead of the profile id.
 +   * </p>
 +   */
 +  protected String signatureProfileId = null;
 +
 +  /**
 +   * The signature key identifier specifying which signature key should be used
 +   * by the signature device to perform the signature.
 +   *
 +   * <p>
 +   * Providing a null value (default) means that no explicit signature key
 +   * identifier is provided. The selected signature device will then use its
 +   * default mechanism for retrieving this information (which is usually to read
 +   * the key from the provided signature profile).
 +   * </p>
 +   * <p>
 +   * Note that not all signature devices may support this parameter.
 +   * If a signature device doesn't support this parameter the value should be null.
 +   * </p>
 +   * <p>
 +   * This key is usually passed straight through to the signature device and
 +   * thereby has to contain an appropriate value for the signature device
 +   * chosen.
 +   * </p>
 +   * <p>
 +   * Currently, only the {@link Constants#SIGNATURE_DEVICE_MOA} signature device
 +   * evaluates this parameter and passes the provided String to MOA as the MOA
 +   * key group identifier. If null is provided, the MOA signature device will
 +   * determine the signature key identifier to be used from the provided profile
 +   * and, if not specified there either, from the MOA default configuration.
 +   * </p>
 +   */
 +  protected String signatureKeyIdentifier = null;
 +
 +  /**
 +   * The signature position. Consult the PDF-AS documentation section
 +   * Commandline.
 +   */
 +  protected SignaturePositioning signaturePositioning = null;
 +
 +  /**
 +   * The output DataSink that will receive the signed document.
 +   */
 +  protected DataSink output = null;
 +
 +  protected TimeStamper timeStamperImpl;
 +
 +  /**
 +   * The flag to de-/activate placeholder search
 +   */
 +  protected Boolean checkForPlaceholder = null;
 +
 +  /**
 +   * The id of the placeholder which should be replaced.
 +   */
 +  protected String placeholderId;
 +
 +  /**
 +   * The matching mode for placeholder extraction.<br/>
 +   * If a {@link SignParameters#placeholderId} is set, the match mode determines what is to be done, if no matching placeholder is found in the document.
 +   * <br/>
 +   * Defaults to {@link Constants#PLACEHOLDER_MATCH_MODE_MODERATE}.
 +   */
 +  protected int placeholderMatchMode = Constants.PLACEHOLDER_MATCH_MODE_MODERATE;
 +
 +  protected Properties overrideProps = new Properties();
 +
 +
 +
 +
 +
 +  /**
 +   * {@link #setTimeStamperImpl(TimeStamper)}
 +   * @return
 +   */
 +  public TimeStamper getTimeStamperImpl() {
 +     return this.timeStamperImpl;
 +  }
 +
 +  /**
 +   * Set a {@link TimeStamper} to create a timestamp on the signature value. Will be
 +   * called after sign. For binary signatures only. Timestamp will be embedded in egiz dict /TimeStamp.
 +   * @param timeStamperImpl
 +   */
 +  public void setTimeStamperImpl(TimeStamper timeStamperImpl) {
 +     this.timeStamperImpl = timeStamperImpl;
 +  }
 +
 +/**
 +   * @return the document
 +   */
 +  public DataSource getDocument()
 +  {
 +    return document;
 +  }
 +
 +  /**
 +   * @param document
 +   *          the document to set
 +   */
 +  public void setDocument(DataSource document)
 +  {
 +    this.document = document;
 +  }
 +
 +  /**
 +   * @return the signatureType
 +   */
 +  public String getSignatureType()
 +  {
 +    return signatureType;
 +  }
 +
 +  /**
 +   * @param signatureType
 +   *          the signatureType to set
 +   */
 +  public void setSignatureType(String signatureType)
 +  {
 +    this.signatureType = signatureType;
 +  }
 +
 +  /**
 +   * @return the signatureDevice
 +   */
 +  public String getSignatureDevice()
 +  {
 +    return signatureDevice;
 +  }
 +
 +  /**
 +   * @param signatureDevice
 +   *          the signatureDevice to set
 +   */
 +  public void setSignatureDevice(String signatureDevice)
 +  {
 +    this.signatureDevice = signatureDevice;
 +  }
 +
 +  /**
 +   * @return the signatureProfileId
 +   */
 +  public String getSignatureProfileId()
 +  {
 +    return signatureProfileId;
 +  }
 +
 +  /**
 +   * @param signatureProfileId
 +   *          the signatureProfileId to set
 +   */
 +  public void setSignatureProfileId(String signatureProfileId)
 +  {
 +    this.signatureProfileId = signatureProfileId;
 +  }
 +
 +  /**
 +   * @return the signaturePositioning
 +   */
 +  public SignaturePositioning getSignaturePositioning()
 +  {
 +    return this.signaturePositioning;
 +  }
 +
 +  /**
 +   * @param signaturePositioning
 +   *          the signaturePositioning to set
 +   */
 +  public void setSignaturePositioning(SignaturePositioning signaturePositioning)
 +  {
 +    this.signaturePositioning = signaturePositioning;
 +  }
 +
 +  /**
 +   * @return the output
 +   */
 +  public DataSink getOutput()
 +  {
 +    return output;
 +  }
 +
 +  /**
 +   * @param output
 +   *          the output to set
 +   */
 +  public void setOutput(DataSink output)
 +  {
 +    this.output = output;
 +  }
 +
 +  /**
 +   * @return the signatureKeyIdentifier
 +   */
 +  public String getSignatureKeyIdentifier()
 +  {
 +    return this.signatureKeyIdentifier;
 +  }
 +
 +  /**
 +   * @param signatureKeyIdentifier the signatureKeyIdentifier to set
 +   */
 +  public void setSignatureKeyIdentifier(String signatureKeyIdentifier)
 +  {
 +    this.signatureKeyIdentifier = signatureKeyIdentifier;
 +  }
 +
 +  /**
 +   * Override user defined values from the used signature profile like "value.SIG_META".
 +   * You cannot override pre defined values like SIG_VALUE, SIG_DATE {@link SignatureTypes#REQUIRED_SIG_KEYS}.
 +   * The override values are bound to the {@link SignParameters} instance.
 +   * <p>
 +   * Sample usage:
 +   * <pre>
 +      SignParameters sp = new SignParameters();
 +      . . .
 +
 +      sp.setSignatureProfileId("SIGNATURBLOCK_DE");
 +
 +      // expressions do not work on binary signature fields without phlength setting!!
 +      sp.setProfileOverrideValue("SIG_META", "It's nice to be important, but it is more important to be nice ${subject.L}");;
 +      sp.setProfileOverrideValue("SIG_LABEL", "./images/signatur-logo_en.png");
 +
 +      // execute sign using the overrides
 +      pdfAs.sign(sp);
 +  </pre>
 +   * </p>
 +   * @param key the name of the setting to override e.g. "SIG_META"
 +   * @param value The new value
 +   */
 +   public void setProfileOverrideValue(String key, String value) {
 +      if (SignatureTypes.isRequredSigTypeKey(key)) {
 +         throw new RuntimeException("cannot set value for pre defined signature field names");
 +      }
 +      this.overrideProps.put(key, value);
 +   }
 +
 +   /**
 +    * Get override values created via {@link #setProfileOverrideValue(String, String)}
 +    * @return
 +    */
 +   public Properties getProfileOverrideProperties() {
 +      return this.overrideProps;
 +
 +   }
 +
 +  /**
 +   * Get the value of the checkForPlaceholder flag.
 +   *
 +   * @return
 +   */
 +  public Boolean isCheckForPlaceholder() {
 +    return this.checkForPlaceholder;
 +  }
 +
 +  /**
 +   * Set this to true, if you want a search for placeholder images to be performed and
 +   * appropriate images to be replaced.
 +   * If this is not set, a search will only be performed if the configuration property "enable_placeholder_search" is set to true.
 +   *
 +   * @param check
 +   */
 +  public void setCheckForPlaceholder(Boolean searchForPlaceHolder) {
 +    this.checkForPlaceholder = searchForPlaceHolder;
 +  }
 +
 +  /**
 +   * Set an explicit placeholder id.
 +   * Only placeholder images that have a matching ID property embedded will be considered for replacement.
 +   *
 +   * @param placeholderId
 +   */
 +  public void setPlaceholderId(String placeholderId) {
 +    this.placeholderId = placeholderId;
 +  }
 +
 +  /**
 +   * The id of the placeholder to replace.
 +   *
 +   * @return the placeholderId
 +   */
 +  public String getPlaceholderId() {
 +    return placeholderId;
 +  }
 +
 +  /**
 +   * Set the behavior if no exactly matching placeholder could be found.<br/>
 +   * Exactly matching meaning:<br/>
 +   * <ul><li>If a placeholderId is set: a placeholder which has exactly this id embedded</li>
 +   * <li>If no placeholderId is set: a placeholder without an embedded id is found</li></ul>
 +   *
 +   * @see Constants#PLACEHOLDER_MATCH_MODE_LENIENT
 +   * @see Constants#PLACEHOLDER_MATCH_MODE_MODERATE
 +   * @see Constants#PLACEHOLDER_MATCH_MODE_STRICT
 +   *
 +   * Defaults to {@link Constants#PLACEHOLDER_MATCH_MODE_MODERATE}.
 +   *
 +   * @param placeholderMatchMode
 +   */
 +  public void setPlaceholderMatchMode(int placeholderMatchMode) {
 +    this.placeholderMatchMode = placeholderMatchMode;
 +  }
 +
 +  /**
 +   * Get the placeholder matching mode.
 +   *
 +   * @see SignParameters#getPlaceholderMatchMode()
 +   * @return the placeholderMatchMode
 +   */
 +  public int getPlaceholderMatchMode() {
 +    return this.placeholderMatchMode;
 +  }
 +
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/SignResult.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/SignResult.java new file mode 100644 index 00000000..fa0282f9 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/SignResult.java @@ -0,0 +1,84 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.sign;
 +
 +import java.security.cert.X509Certificate;
 +import java.util.List;
 +
 +import at.gv.egiz.pdfas.api.analyze.NonTextObjectInfo;
 +import at.gv.egiz.pdfas.api.io.DataSink;
 +import at.gv.egiz.pdfas.api.sign.pos.SignaturePosition;
 +
 +/**
 + * The result of a sign operation.
 + * 
 + * @author wprinz
 + */
 +public interface SignResult
 +{
 +
 +  /**
 +   * Returns the filled output data sink.
 +   * 
 +   * @return Returns the filled output data sink.
 +   */
 +  public DataSink getOutputDocument();
 +
 +  /**
 +   * Returns the certificate of the signer.
 +   * 
 +   * @return Returns the certificate of the signer.
 +   */
 +  public X509Certificate getSignerCertificate();
 +
 +  /**
 +   * Returns the position where the signature is finally placed.
 +   * 
 +   * <p>
 +   * This information can be useful for post-processing the document.
 +   * </p>
 +   * 
 +   * <p>
 +   * Consult the PDF-AS documentation section Commandline for further
 +   * information about positioning.
 +   * </p>
 +   * 
 +   * @return Returns the position where the signature is finally placed. May
 +   *         return null if no position information is available.
 +   */
 +  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 if pdf has non textual objects (only for textual signature available).
 +   * @return
 +   */
 +  public boolean hasNonTextualObjects();
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/SignatureDetailInformation.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/SignatureDetailInformation.java new file mode 100644 index 00000000..c5a0263b --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/SignatureDetailInformation.java @@ -0,0 +1,147 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +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/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/package-info.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/package-info.java new file mode 100644 index 00000000..95c97422 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/package-info.java @@ -0,0 +1,8 @@ +/** + *  + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas.api.sign;
\ No newline at end of file diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePosition.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePosition.java new file mode 100644 index 00000000..eee62cd8 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePosition.java @@ -0,0 +1,72 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.sign.pos;
 +
 +/**
 + * Holds the actual, absolute signature position where a signature was placed.
 + * 
 + * <p>
 + * This is usually returned after signing.
 + * </p>
 + * 
 + * @author wprinz
 + */
 +public interface SignaturePosition
 +{
 +  /**
 +   * Returns the page on which the signature was placed.
 +   * 
 +   * @return Returns the page on which the signature was placed.
 +   */
 +  public int getPage();
 +
 +  /**
 +   * Returns the x position.
 +   * 
 +   * @return Returns the x position.
 +   */
 +  public float getX();
 +
 +  /**
 +   * Returns the y position.
 +   * 
 +   * @return Returns the y position.
 +   */
 +  public float getY();
 +
 +  /**
 +   * Returns the width of the signature.
 +   * 
 +   * @return Returns the width of the signature.
 +   */
 +  public float getWidth();
 +
 +  /**
 +   * Returns the height of the signature.
 +   * 
 +   * @return Returns the height of the signature.
 +   */
 +  public float getHeight();
 +
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java new file mode 100644 index 00000000..eb9b9de4 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java @@ -0,0 +1,296 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.sign.pos;
 +
 +import java.io.Serializable;
 +import java.util.StringTokenizer;
 +
 +import at.gv.egiz.pdfas.api.exceptions.ErrorCode;
 +import at.gv.egiz.pdfas.api.exceptions.PdfAsException;
 +import at.gv.egiz.pdfas.api.sign.pos.axis.AbsoluteAxisAlgorithm;
 +import at.gv.egiz.pdfas.api.sign.pos.axis.AutoAxisAlgorithm;
 +import at.gv.egiz.pdfas.api.sign.pos.axis.AxisAlgorithm;
 +import at.gv.egiz.pdfas.api.sign.pos.page.AbsolutePageAlgorithm;
 +import at.gv.egiz.pdfas.api.sign.pos.page.AutoPageAlgorithm;
 +import at.gv.egiz.pdfas.api.sign.pos.page.NewPageAlgorithm;
 +import at.gv.egiz.pdfas.api.sign.pos.page.PageAlgorithm;
 +
 +/**
 + * Defines how the signature positioning is to be performed.
 + * 
 + * <p>
 + * This positioning allows to select the location where the signature block is
 + * placed in the document.
 + * </p>
 + * 
 + * @author wprinz
 + */
 +public class SignaturePositioning implements Serializable
 +{
 +  
 +  /**
 +    * 
 +    */
 +  private static final long serialVersionUID = 1L;
 +
 +  /**
 +   * The x axis algorithm.
 +   * 
 +   * <p>
 +   * May be {@link AutoAxisAlgorithm} or {@link AbsoluteAxisAlgorithm}
 +   * </p>
 +   */
 +  protected AxisAlgorithm xAlgorithm = new AutoAxisAlgorithm();
 +
 +  /**
 +   * The y axis algorithm.
 +   * 
 +   * <p>
 +   * May be {@link AutoAxisAlgorithm} or {@link AbsoluteAxisAlgorithm}
 +   * </p>
 +   */
 +  protected AxisAlgorithm yAlgorithm = new AutoAxisAlgorithm();
 +
 +  /**
 +   * The width algorithm.
 +   * 
 +   * <p>
 +   * May be {@link AutoAxisAlgorithm} or {@link AbsoluteAxisAlgorithm}
 +   * </p>
 +   */
 +  protected AxisAlgorithm widthAlgorithm = new AutoAxisAlgorithm();
 +
 +  /**
 +   * The page algorithm.
 +   * 
 +   * <p>
 +   * May be {@link AutoPageAlgorithm}, {@link AbsolutePageAlgorithm} or
 +   * {@link NewPageAlgorithm}
 +   * </p>
 +   */
 +  protected PageAlgorithm pageAlgorithm = new AutoPageAlgorithm();
 +
 +  /**
 +   * Provides the position of the footline.
 +   * 
 +   * <p>
 +   * Only used if the pageAlgorithm is {@link AutoPageAlgorithm} and the
 +   * yAlgorithm is {@link AutoAxisAlgorithm}
 +   * </p>
 +   */
 +  protected float footerLine = 0.0f;
 +
 +  protected void checkAxisAlgorithm(AxisAlgorithm algorithm)
 +  {
 +    if (algorithm == null)
 +    {
 +      throw new IllegalArgumentException("The algorithm must not be null.");
 +    }
 +    if (!(algorithm instanceof AutoAxisAlgorithm) && !(algorithm instanceof AbsoluteAxisAlgorithm))
 +    {
 +      throw new IllegalArgumentException("The algorithm must be either Auto or Absolute.");
 +    }
 +  }
 +
 +  protected void checkPageAlgorithm(PageAlgorithm algorithm)
 +  {
 +    if (algorithm == null)
 +    {
 +      throw new IllegalArgumentException("The algorithm must not be null.");
 +    }
 +    if (!(algorithm instanceof AutoPageAlgorithm) && !(algorithm instanceof AbsolutePageAlgorithm) && !(algorithm instanceof NewPageAlgorithm))
 +    {
 +      throw new IllegalArgumentException("The algorithm must be either Auto or Absolute.");
 +    }
 +
 +  }
 +
 +  /**
 +   * @return the xAlgorithm
 +   */
 +  public AxisAlgorithm getXAlgorithm()
 +  {
 +    return this.xAlgorithm;
 +  }
 +
 +  /**
 +   * @param algorithm
 +   *          the xAlgorithm to set
 +   */
 +  public void setXAlgorithm(AxisAlgorithm algorithm)
 +  {
 +    checkAxisAlgorithm(algorithm);
 +    xAlgorithm = algorithm;
 +  }
 +
 +  /**
 +   * @return the yAlgorithm
 +   */
 +  public AxisAlgorithm getYAlgorithm()
 +  {
 +    return this.yAlgorithm;
 +  }
 +
 +  /**
 +   * @param algorithm
 +   *          the yAlgorithm to set
 +   */
 +  public void setYAlgorithm(AxisAlgorithm algorithm)
 +  {
 +    checkAxisAlgorithm(algorithm);
 +
 +    yAlgorithm = algorithm;
 +  }
 +
 +  /**
 +   * @return the widthAlgorithm
 +   */
 +  public AxisAlgorithm getWidthAlgorithm()
 +  {
 +    return this.widthAlgorithm;
 +  }
 +
 +  /**
 +   * @param widthAlgorithm
 +   *          the widthAlgorithm to set
 +   */
 +  public void setWidthAlgorithm(AxisAlgorithm widthAlgorithm)
 +  {
 +    checkAxisAlgorithm(widthAlgorithm);
 +
 +    this.widthAlgorithm = widthAlgorithm;
 +  }
 +
 +  /**
 +   * @return the pageAlgorithm
 +   */
 +  public PageAlgorithm getPageAlgorithm()
 +  {
 +    return this.pageAlgorithm;
 +  }
 +
 +  /**
 +   * @param pageAlgorithm
 +   *          the pageAlgorithm to set
 +   */
 +  public void setPageAlgorithm(PageAlgorithm pageAlgorithm)
 +  {
 +    checkPageAlgorithm(pageAlgorithm);
 +    this.pageAlgorithm = pageAlgorithm;
 +  }
 +
 +  /**
 +   * @return the footerLine
 +   */
 +  public float getFooterLine()
 +  {
 +    return this.footerLine;
 +  }
 +
 +  /**
 +   * @param footerLine
 +   *          the footerLine to set
 +   */
 +  public void setFooterLine(float footerLine)
 +  {
 +    this.footerLine = footerLine;
 +  }
 +
 +   public SignaturePositioning() {
 +   }
 +   
 +   public SignaturePositioning(String position) throws PdfAsException {
 +      if (position != null) {
 +         StringTokenizer tokenizer = new StringTokenizer(position, ";");
 +         while (tokenizer.hasMoreTokens()) {
 +            String token = tokenizer.nextToken().replaceAll(" ", "");
 +            String[] sToken = token.split(":");
 +            if (sToken == null || sToken.length != 2 || sToken[0].length() != 1) {
 +               throw new PdfAsException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);               
 +            }
 +            char cmd = sToken[0].toLowerCase().charAt(0);
 +            String value = sToken[1];
 +            switch (cmd) {
 +            case 'x':
 +               if ("auto".equalsIgnoreCase(value)) {
 +                  this.setXAlgorithm(new AutoAxisAlgorithm());
 +               } else {
 +                  try {
 +                     this.setXAlgorithm(new AbsoluteAxisAlgorithm(Float.parseFloat(value)));
 +                  } catch (NumberFormatException e) {
 +                     throw new PdfAsException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);               
 +                  }
 +               }
 +               break;
 +            case 'y':
 +               if ("auto".equalsIgnoreCase(value)) {
 +                  this.setYAlgorithm(new AutoAxisAlgorithm());
 +               } else {
 +                  try {
 +                     this.setYAlgorithm(new AbsoluteAxisAlgorithm(Float.parseFloat(value)));
 +                  } catch (NumberFormatException e) {
 +                     throw new PdfAsException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);               
 +                  }
 +               }
 +               break;
 +            case 'w':
 +               if ("auto".equalsIgnoreCase(value)) {
 +                  this.setWidthAlgorithm(new AutoAxisAlgorithm());
 +               } else {
 +                  try {
 +                     this.setWidthAlgorithm(new AbsoluteAxisAlgorithm(Float.parseFloat(value)));
 +                  } catch (NumberFormatException e) {
 +                     throw new PdfAsException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);               
 +                  }
 +               }
 +               break;
 +            case 'p':
 +               if ("auto".equalsIgnoreCase(value)) {
 +                  this.setPageAlgorithm(new AutoPageAlgorithm());
 +               } else if ("new".equalsIgnoreCase(value)) {
 +                     this.setPageAlgorithm(new NewPageAlgorithm());
 +               } else {
 +                  try {
 +                     this.setPageAlgorithm(new AbsolutePageAlgorithm(Integer.parseInt(value)));
 +                  } catch (NumberFormatException e) {
 +                     throw new PdfAsException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);               
 +                  }
 +               }
 +               break;
 +            case 'f':
 +               try {
 +                  this.setFooterLine(Float.parseFloat(value));
 +               } catch (NumberFormatException e) {
 +                  throw new PdfAsException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);               
 +               }
 +               break;
 +            default:
 +               throw new PdfAsException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);               
 +            }
 +         }
 +      }
 +   }
 +  
 +
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AbsoluteAxisAlgorithm.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AbsoluteAxisAlgorithm.java new file mode 100644 index 00000000..ea2143dd --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AbsoluteAxisAlgorithm.java @@ -0,0 +1,62 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.sign.pos.axis;
 +
 +import java.io.Serializable;
 +
 +/**
 + * An absolute positioned element.
 + * @author wprinz
 + */
 +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;
 +  
 +  /**
 +   * Constructor.
 +   * @param absoluteValue The absolute positioning value on the axis.
 +   */
 +  public AbsoluteAxisAlgorithm (float absoluteValue)
 +  {
 +    this.absoluteValue = absoluteValue;
 +  }
 +
 +  /**
 +   * Returns absolute positioning value on the axis.
 +   * @return the absoluteValue Returns absolute positioning value on the axis.
 +   */
 +  public float getAbsoluteValue()
 +  {
 +    return this.absoluteValue;
 +  }
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AutoAxisAlgorithm.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AutoAxisAlgorithm.java new file mode 100644 index 00000000..a9857b42 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AutoAxisAlgorithm.java @@ -0,0 +1,41 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +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 implements Serializable
 +{
 +
 +   /**
 +    * 
 +    */
 +   private static final long serialVersionUID = 1L;
 +// empty
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AxisAlgorithm.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AxisAlgorithm.java new file mode 100644 index 00000000..dd1d1700 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AxisAlgorithm.java @@ -0,0 +1,41 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +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 implements Serializable
 +{
 +
 +   /**
 +    * 
 +    */
 +   private static final long serialVersionUID = 1L;
 +// base class
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/package-info.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/package-info.java new file mode 100644 index 00000000..c4f24440 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/package-info.java @@ -0,0 +1,8 @@ +/** + *  + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas.api.sign.pos.axis;
\ No newline at end of file diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/package-info.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/package-info.java new file mode 100644 index 00000000..80914293 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/package-info.java @@ -0,0 +1,8 @@ +/** + *  + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas.api.sign.pos;
\ No newline at end of file diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AbsolutePageAlgorithm.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AbsolutePageAlgorithm.java new file mode 100644 index 00000000..434c20c4 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AbsolutePageAlgorithm.java @@ -0,0 +1,64 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +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 implements Serializable
 +{
 +  /**
 +    * 
 +    */
 +   private static final long serialVersionUID = 1L;
 +
 +  /**
 +   * The page.
 +   */
 +  protected int page = -1;
 +
 +  /**
 +   * Constructor.
 +   * 
 +   * @param page
 +   *          The page.
 +   */
 +  public AbsolutePageAlgorithm(int page)
 +  {
 +    this.page = page;
 +  }
 +
 +  /**
 +   * @return the page
 +   */
 +  public int getPage()
 +  {
 +    return this.page;
 +  }
 +
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AutoPageAlgorithm.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AutoPageAlgorithm.java new file mode 100644 index 00000000..fffcbad0 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AutoPageAlgorithm.java @@ -0,0 +1,47 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.sign.pos.page;
 +
 +import java.io.Serializable;
 +
 +/**
 + * The page for placing the signature is selected automatically.
 + * 
 + * <p>
 + * The algorithm first tries to place the signature on the free space of the
 + * last page (considering the footer). If there is not enough space on the last
 + * page, a new page is appended and the signature is placed there.
 + * </p>
 + * 
 + * @author wprinz
 + */
 +public class AutoPageAlgorithm extends PageAlgorithm implements Serializable
 +{
 +
 +   /**
 +    * 
 +    */
 +   private static final long serialVersionUID = 1L;
 +// empty
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/NewPageAlgorithm.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/NewPageAlgorithm.java new file mode 100644 index 00000000..ded9f618 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/NewPageAlgorithm.java @@ -0,0 +1,41 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +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 implements Serializable
 +{
 +
 +   /**
 +    * 
 +    */
 +   private static final long serialVersionUID = 1L;
 +  // empty block
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/PageAlgorithm.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/PageAlgorithm.java new file mode 100644 index 00000000..16aa72ca --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/PageAlgorithm.java @@ -0,0 +1,41 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +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 implements Serializable
 +{
 +
 +   /**
 +    * 
 +    */
 +   private static final long serialVersionUID = 1L;
 +  // empty
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/package-info.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/package-info.java new file mode 100644 index 00000000..fec6dbea --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/package-info.java @@ -0,0 +1,8 @@ +/** + *  + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas.api.sign.pos.page;
\ No newline at end of file diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/timestamp/DummyTimeStamper.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/timestamp/DummyTimeStamper.java new file mode 100644 index 00000000..0245a7ca --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/timestamp/DummyTimeStamper.java @@ -0,0 +1,63 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.timestamp;
 +
 +import java.text.SimpleDateFormat;
 +import java.util.Date;
 +
 +import org.apache.commons.codec.binary.Base64;
 +import org.apache.commons.logging.Log;
 +import org.apache.commons.logging.LogFactory;
 +
 +/**
 + * Dummy/test implementation of the timestamper. Logs and stores test-timestamp for assertion {@link #getLastTimeStamp()}
 + * 
 + * @author dferbas
 + *
 + */
 +public class DummyTimeStamper implements TimeStamper {
 +   private static Log log = LogFactory.getLog(DummyTimeStamper.class);
 +   
 +   private String lastTimeStamp;
 +
 +   public String applyTimeStamp(String b64SignatureValue) {
 +      log.debug("Applying dummy timestamp on signature value: " + b64SignatureValue);
 +      SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSZ");
 +      String ts = formater.format(new Date());
 +      log.debug("Timestamp: " + ts);
 +      ts = new String(Base64.encodeBase64(ts.getBytes()));
 +      log.debug("Timestamp value (base64): " + ts);
 +      this.lastTimeStamp  = ts;
 +      return ts;
 +   }
 +
 +   public String getLastTimeStamp() {
 +      return this.lastTimeStamp;
 +   }
 +
 +   public void setLastTimeStamp(String lastTimeStamp) {
 +      this.lastTimeStamp = lastTimeStamp;
 +   }
 +   
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/timestamp/TimeStamper.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/timestamp/TimeStamper.java new file mode 100644 index 00000000..99bda3a7 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/timestamp/TimeStamper.java @@ -0,0 +1,41 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.timestamp;
 +
 +/**
 + * Interface for timestamper implementations/handlers
 + * 
 + * @author dferbas
 + *
 + */
 +public interface TimeStamper {
 +   
 +   /**
 +    * Implement timestamp in this method. 
 +    * @param b64SignatureValue signature value, base64 encoded
 +    * @return timestamp to be embedded in egiz dictionary base64 encoded (following RFC3161).
 +    */
 +   public String applyTimeStamp(String b64SignatureValue);
 +
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/timestamp/package-info.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/timestamp/package-info.java new file mode 100644 index 00000000..30b76e0c --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/timestamp/package-info.java @@ -0,0 +1,8 @@ +/** + *  + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas.api.timestamp;
\ No newline at end of file diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/SignatureCheck.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/SignatureCheck.java new file mode 100644 index 00000000..c1690774 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/SignatureCheck.java @@ -0,0 +1,51 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.verify;
 +
 +/**
 + * The result of a signature check performed by a verification device.
 + * 
 + * @see VerifyResult
 + * 
 + * @author wprinz
 + */
 +public interface SignatureCheck
 +{
 +  /**
 +   * Returns the response code of the check.
 +   * 
 +   * @return Returns the response code of the check.
 +   */
 +  public int getCode();
 +
 +  /**
 +   * Returns the textual response message of the check (corresponding to the
 +   * code).
 +   * 
 +   * @return Returns the textual response message of the check (corresponding to
 +   *         the code).
 +   */
 +  public String getMessage();
 +
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyAfterAnalysisParameters.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyAfterAnalysisParameters.java new file mode 100644 index 00000000..8b9e2c6a --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyAfterAnalysisParameters.java @@ -0,0 +1,166 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.verify;
 +
 +import java.util.Date;
 +
 +import at.gv.egiz.pdfas.api.analyze.AnalyzeResult;
 +import at.gv.egiz.pdfas.api.commons.Constants;
 +
 +/**
 + * Parameter object that holds the verify after analysis parameters.
 + * 
 + * @author wprinz
 + */
 +public class VerifyAfterAnalysisParameters
 +{
 +
 +  /**
 +   * The list of signatures to be verified.
 +   */
 +  protected AnalyzeResult analyzeResult = null;
 +
 +  /**
 +   * The signature device to perform the actual signature.
 +   * 
 +   * <p>
 +   * May be {@link Constants#SIGNATURE_DEVICE_MOA} or
 +   * {@link Constants#SIGNATURE_DEVICE_BKU}.
 +   * </p>
 +   */
 +  protected String signatureDevice = Constants.SIGNATURE_DEVICE_MOA;
 +
 +  /**
 +   * Allows to pass a VerificationTime to the signature device.
 +   */
 +  protected Date verificationTime = null;
 +
 +  /**
 +   * Tells the signature device (e.g. MOA) to return the signature hash input
 +   * data (which is the probably transformed signed data).
 +   * 
 +   * <p>
 +   * Note that this forces MOA to return the potentially large signature data to
 +   * be returned in the result XML, which may result in very bad performance.
 +   * </p>
 +   */
 +  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()
 +  {
 +    return this.analyzeResult;
 +  }
 +
 +  /**
 +   * @param analyzeResult
 +   *          the analyzeResult to set
 +   */
 +  public void setAnalyzeResult(AnalyzeResult analyzeResult)
 +  {
 +    this.analyzeResult = analyzeResult;
 +  }
 +
 +  /**
 +   * @return the signatureDevice
 +   */
 +  public String getSignatureDevice()
 +  {
 +    return this.signatureDevice;
 +  }
 +
 +  /**
 +   * @param signatureDevice
 +   *          the signatureDevice to set
 +   */
 +  public void setSignatureDevice(String signatureDevice)
 +  {
 +    this.signatureDevice = signatureDevice;
 +  }
 +
 +  /**
 +   * @return the verificationTime
 +   */
 +  public Date getVerificationTime()
 +  {
 +    return this.verificationTime;
 +  }
 +
 +  /**
 +   * @param verificationTime the verificationTime to set
 +   */
 +  public void setVerificationTime(Date verificationTime)
 +  {
 +    this.verificationTime = verificationTime;
 +  }
 +
 +  /**
 +   * @return the returnHashInputData
 +   */
 +  public boolean isReturnHashInputData()
 +  {
 +    return this.returnHashInputData;
 +  }
 +
 +  /**
 +   * @param returnHashInputData
 +   *          the returnHashInputData to set
 +   */
 +  public void setReturnHashInputData(boolean returnHashInputData)
 +  {
 +    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;
 +  }
 +
 +  /**
 +   * @see VerifyParameters#setSuppressVerifyExceptions(boolean)
 +   * @param suppress
 +   */
 +  public void setSuppressVerifyExceptions(boolean suppress) {
 +     VerifyParameters.setSuppressVerify(suppress);
 +  }
 +
 +  public boolean isSuppressVerifyExceptions() {
 +     return VerifyParameters.isSuppressVerifyExceptions();
 +  }
 +
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyAfterReconstructXMLDsigParameters.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyAfterReconstructXMLDsigParameters.java new file mode 100644 index 00000000..8f8d17c7 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyAfterReconstructXMLDsigParameters.java @@ -0,0 +1,169 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.verify;
 +
 +import java.util.Date;
 +
 +import at.gv.egiz.pdfas.api.commons.Constants;
 +import at.gv.egiz.pdfas.api.xmldsig.ReconstructXMLDsigResult;
 +
 +/**
 + * This class represents the parameters needed for verify after reconstructXMLDsig has already been executed. 
 + * 
 + * @author exthex
 + *
 + */
 +public class VerifyAfterReconstructXMLDsigParameters {
 +
 +   /**
 +    * The list of signatures to be verified.
 +    */
 +   protected ReconstructXMLDsigResult reconstructXMLDsigResult = null;
 +
 +   /**
 +    * The signature device to perform the actual signature.
 +    * 
 +    * <p>
 +    * May be {@link Constants#SIGNATURE_DEVICE_MOA} or
 +    * {@link Constants#SIGNATURE_DEVICE_BKU}.
 +    * </p>
 +    */
 +   protected String signatureDevice;
 +
 +   /**
 +    * Allows to pass a VerificationTime to the signature device.
 +    */
 +   protected Date verificationTime = null;
 +
 +   /**
 +    * Tells the signature device (e.g. MOA) to return the signature hash input
 +    * data (which is the probably transformed signed data).
 +    * 
 +    * <p>
 +    * Note that this forces MOA to return the potentially large signature data to
 +    * be returned in the result XML, which may result in very bad performance.
 +    * </p>
 +    */
 +   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()
 +   {
 +     return this.reconstructXMLDsigResult;
 +   }
 +
 +   /**
 +    * @param reconstructXMLDsigResult
 +    *          the reconstructXMLDsigResult to set
 +    */
 +   public void setReconstructXMLDsigResult(ReconstructXMLDsigResult reconstructXMLDsigResult)
 +   {
 +     this.reconstructXMLDsigResult = reconstructXMLDsigResult;
 +   }
 +
 +   /**
 +    * @return the signatureDevice
 +    */
 +   public String getSignatureDevice()
 +   {
 +     return this.signatureDevice;
 +   }
 +
 +   /**
 +    * Set the signature device to use for verification. 
 +    * If none is set here, the signature device that was used for reconstructXMLDsig will be used.
 +    *  
 +    * @param signatureDevice
 +    *          the signatureDevice to set
 +    */
 +   public void setSignatureDevice(String signatureDevice)
 +   {
 +     this.signatureDevice = signatureDevice;
 +   }
 +
 +   /**
 +    * @return the verificationTime
 +    */
 +   public Date getVerificationTime()
 +   {
 +     return this.verificationTime;
 +   }
 +
 +   /**
 +    * @param verificationTime the verificationTime to set
 +    */
 +   public void setVerificationTime(Date verificationTime)
 +   {
 +     this.verificationTime = verificationTime;
 +   }
 +
 +   /**
 +    * @return the returnHashInputData
 +    */
 +   public boolean isReturnHashInputData()
 +   {
 +     return this.returnHashInputData;
 +   }
 +
 +   /**
 +    * @param returnHashInputData
 +    *          the returnHashInputData to set
 +    */
 +   public void setReturnHashInputData(boolean returnHashInputData)
 +   {
 +     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;
 +   }
 +
 +   /**
 +    * @see VerifyParameters#setSuppressVerifyExceptions(boolean)
 +    * @param suppress
 +    */
 +   public void setSuppressVerifyExceptions(boolean suppress) {
 +      VerifyParameters.setSuppressVerify(suppress);
 +   }
 +
 +   public boolean isSuppressVerifyExceptions() {
 +      return VerifyParameters.isSuppressVerifyExceptions();
 +   }
 +
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyParameters.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyParameters.java new file mode 100644 index 00000000..e7301dc4 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyParameters.java @@ -0,0 +1,249 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.verify;
 +
 +import java.util.Date;
 +
 +import at.gv.egiz.pdfas.api.commons.Constants;
 +import at.gv.egiz.pdfas.api.io.DataSource;
 +
 +/**
 + * Parameter object that holds the verify parameters.
 + * 
 + * @author wprinz
 + */
 +public class VerifyParameters
 +{
 +  // This would be a perfect point for multiple inheritance in Java.
 +  // VerifyParameters extends AnalyzeParameters, VerifyAfterAnalysisParameters
 +  // Then a lot of code could be easily reused in the PdfAsObject's check*Parameters methods.
 +
 +  /**
 +   * The document to be verified.
 +   */
 +  protected DataSource document = null;
 +
 +  /**
 +   * The signature device to perform the actual signature.
 +   * 
 +   * <p>
 +   * May be {@link Constants#SIGNATURE_DEVICE_MOA} or
 +   * {@link Constants#SIGNATURE_DEVICE_BKU}.
 +   * </p>
 +   */
 +  protected String signatureDevice = Constants.SIGNATURE_DEVICE_MOA;
 +
 +  /**
 +   * The mode of operation how the document is analyzed.
 +   * 
 +   * <p>
 +   * May be {@link Constants#VERIFY_MODE_BINARY_ONLY} to check the document for
 +   * binary signatures only (very fast). Or may be
 +   * {@link Constants#VERIFY_MODE_SEMI_CONSERVATIVE} to perform a semi
 +   * conservative (optimized) text and binary verification (slow). Or may be
 +   * {@link Constants#VERIFY_MODE_FULL_CONSERVATIVE} to perform a full
 +   * conservative text and binary verification (very slow).
 +   * </p>
 +   */
 +  protected String verifyMode = Constants.VERIFY_MODE_FULL_CONSERVATIVE;
 +
 +  /**
 +   * The (zero based) index of the signature to verify.
 +   * 
 +   * <p>
 +   * This allows to verify only one found signature instead of all. {@link Constants#VERIFY_ALL} means to
 +   * verify all found signatures.
 +   * </p>
 +   */
 +  protected int signatureToVerify = Constants.VERIFY_ALL;
 +
 +  /**
 +   * Allows to pass a VerificationTime to the verification device.
 +   * 
 +   * <p>
 +   * Note that the actual usage of this parameter depends on the verification device.
 +   * </p>
 +   */
 +  protected Date verificationTime = null;
 +
 +  /**
 +   * Tells the signature device (e.g. MOA) to return the signature hash input
 +   * data (which is the probably transformed signed data).
 +   * 
 +   * <p>
 +   * Note that this forces MOA to return the potentially large signature data to
 +   * be returned in the result XML, which may result in very bad performance.
 +   * </p>
 +   */
 +  protected boolean returnHashInputData = false;
 +    
 +  protected boolean returnNonTextualObjects = false;
 +  
 +  private static ThreadLocal suppressVerifyExceptions = new ThreadLocal();
 +
 +  
 +  public VerifyParameters() {
 +     suppressVerifyExceptions.set(Boolean.FALSE);
 +  }
 +  /**
 +   * @return the document
 +   */
 +  public DataSource getDocument()
 +  {
 +    return this.document;
 +  }
 +
 +  /**
 +   * @param document
 +   *          the document to set
 +   */
 +  public void setDocument(DataSource document)
 +  {
 +    this.document = document;
 +  }
 +
 +  /**
 +   * @return the signatureDevice
 +   */
 +  public String getSignatureDevice()
 +  {
 +    return this.signatureDevice;
 +  }
 +
 +  /**
 +   * @param signatureDevice
 +   *          the signatureDevice to set
 +   */
 +  public void setSignatureDevice(String signatureDevice)
 +  {
 +    this.signatureDevice = signatureDevice;
 +  }
 +
 +  /**
 +   * @return the verifyMode
 +   */
 +  public String getVerifyMode()
 +  {
 +    return this.verifyMode;
 +  }
 +
 +  /**
 +   * @param verifyMode
 +   *          the verifyMode to set
 +   */
 +  public void setVerifyMode(String verifyMode)
 +  {
 +    this.verifyMode = verifyMode;
 +  }
 +
 +  /**
 +   * @return the signatureToVerify
 +   */
 +  public int getSignatureToVerify()
 +  {
 +    return this.signatureToVerify;
 +  }
 +
 +  /**
 +   * @param signatureToVerify
 +   *          the signatureToVerify to set
 +   */
 +  public void setSignatureToVerify(int signatureToVerify)
 +  {
 +    this.signatureToVerify = signatureToVerify;
 +  }
 +
 +  /**
 +   * @return the verificationTime
 +   */
 +  public Date getVerificationTime()
 +  {
 +    return this.verificationTime;
 +  }
 +
 +  /**
 +   * @param verificationTime
 +   *          the verificationTime to set
 +   */
 +  public void setVerificationTime(Date verificationTime)
 +  {
 +    this.verificationTime = verificationTime;
 +  }
 +
 +  /**
 +   * @return the returnHashInputData
 +   */
 +  public boolean isReturnHashInputData()
 +  {
 +    return this.returnHashInputData;
 +  }
 +
 +  /**
 +   * @param returnHashInputData
 +   *          the returnHashInputData to set
 +   */
 +  public void setReturnHashInputData(boolean returnHashInputData)
 +  {
 +    this.returnHashInputData = returnHashInputData;
 +  }
 +
 +   public boolean isReturnNonTextualObjects() {
 +      return this.returnNonTextualObjects;
 +   }
 +   
 +   /**
 +    * Tells if non text object of the signed pdf should be extracted and returned.
 +    * One should show this to the user, especially in case of textual signature.
 +    * Defaults to <tt>false</tt>
 +    * 
 +    * @param returnNonTextualObjects
 +    */
 +   public void setReturnNonTextualObjects(boolean returnNonTextualObjects) {
 +      this.returnNonTextualObjects = returnNonTextualObjects;
 +   }
 +   
 +   /**
 +    * Set if verify exceptions (because of unknown signatures) are suppressed or not (default).
 +    * Suppressing can be helpful for multiple signatures if you want to verify the working rest. Unsupported
 +    * Signatures are reported without throwing an exception via {@link VerifyResult#getVerificationException()}
 +    * @param suppress
 +    */
 +   public void setSuppressVerifyExceptions(boolean suppress) {      
 +      setSuppressVerify(suppress);     
 +   }
 +   
 +   /**
 +    * See {@link #setSuppressVerifyExceptions(boolean)}
 +    * @return
 +    */
 +   public static boolean isSuppressVerifyExceptions() {
 +      if (suppressVerifyExceptions.get() == null) return false;
 +      return ((Boolean) suppressVerifyExceptions.get()).booleanValue(); 
 +   }
 +  
 +   static void setSuppressVerify(boolean suppress) {
 +	   suppressVerifyExceptions.set(new Boolean(suppress)); 
 +   }
 +
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyResult.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyResult.java new file mode 100644 index 00000000..fb48e5ee --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyResult.java @@ -0,0 +1,179 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.verify;
 +
 +import java.util.Date;
 +import java.util.List;
 +
 +import at.gv.egiz.pdfas.api.PdfAs;
 +import at.gv.egiz.pdfas.api.analyze.NonTextObjectInfo;
 +import at.gv.egiz.pdfas.api.commons.SignatureInformation;
 +import at.gv.egiz.pdfas.api.exceptions.PdfAsException;
 +import at.gv.egiz.pdfas.api.xmldsig.XMLDsigData;
 +
 +/**
 + * Encapsulates the data of a verification of one signature.
 + * 
 + * @author wprinz
 + */
 +public interface VerifyResult extends SignatureInformation
 +{
 +   /**
 +    * Returns if the verification was possible or could not even be startet. see {@link #getVerificationException()} for details.
 +    * @return
 +    */
 +   public boolean isVerificationDone();
 +   
 +   /**
 +    * Returns a verification exception if any. Shows that the verification could not be started. See {@link #isVerificationDone()}.
 +    * @return
 +    */
 +   public PdfAsException getVerificationException();
 +   
 +  /**
 +   * Returns the result of the certificate check.
 +   * 
 +   * @return Returns the result of the certificate check.
 +   */
 +  public SignatureCheck getCertificateCheck();
 +
 +  /**
 +   * Returns the result of the value (and hash) check.
 +   * 
 +   * @return Returns the result of the value (and hash) check.
 +   */
 +  public SignatureCheck getValueCheckCode();
 +
 +  /**
 +   * Returns the result of the manifest check.
 +   * 
 +   * @return Returns the result of the manifest check.
 +   */
 +  public SignatureCheck getManifestCheckCode();
 +
 +  /**
 +   * Returns true, if the signer's certificate is a qualified certificate.
 +   * 
 +   * @return Returns true, if the signer's certificate is a qualified
 +   *         certificate.
 +   */
 +  public boolean isQualifiedCertificate();
 +  
 +  /**
 +   * Returns {@code true} if public authority is indicated.
 +   * @return {@code true} if public authority.
 +   */
 +  public boolean isPublicAuthority();
 +  
 +  /**
 +   * Returns the public authority code or {@code null}.
 +   * @return The public authority code or {@code null}.
 +   */
 +  public String getPublicAuthorityCode();
 +
 +  /**
 +   * Returns a list of Strings each stating one public property of the
 +   * certificate.
 +   * 
 +   * <p>
 +   * Such public properties are certificate extensions each being assigned an
 +   * own OID. For example the public property "Verwaltungseigenschaft" has the
 +   * OID "1.2.40.0.10.1.1.1".
 +   * </p>
 +   * 
 +   * @return Returns the list of Strings representing the public properties of
 +   *         this certificate, if any.
 +   */
 +  public List getPublicProperties();
 +
 +  /**
 +   * Returns the verification time, which is the time when the signature was
 +   * verified.
 +   * 
 +   * <p>
 +   * Note that this is actually the Date passed to the verify methods over
 +   * {@link VerifyParameters#setVerificationTime(Date)} or
 +   * {@link VerifyAfterAnalysisParameters#setVerificationTime(Date)}. The
 +   * signature devices don't respond the actual verification time so there is no
 +   * guarantee that the set verification time was actually used as time of
 +   * verification. Please consult the device's documentation for more
 +   * information.
 +   * </p>
 +   * <p>
 +   * If the verification device does not return a verification time and no
 +   * verification time was set in the
 +   * {@link VerifyParameters#setVerificationTime(Date)} or
 +   * {@link VerifyAfterAnalysisParameters#setVerificationTime(Date)}, the time
 +   * returned by this method will be equal to the signing time (
 +   * {@link SignatureInformation#getSigningTime()}).
 +   * </p>
 +   * 
 +   * @return Returns the verification time, which is the time when the signature
 +   *         was verified.
 +   */
 +  public Date getVerificationTime();
 +
 +  /**
 +   * Returns the hash input data as returned by MOA as Base64-encoded String.
 +   * 
 +   * <p>
 +   * This will only return a value other than null if the corresponding
 +   * {@link VerifyParameters} has been set to true.
 +   * </p>
 +   * <p>
 +   * Note that the HashInputData does not necessarily have to be exactly the
 +   * same as the signed data return by the
 +   * {@link SignatureInformation#getSignedData()} method.
 +   * </p>
 +   * 
 +   * @return Returns the base64 encoded hash input data as returned by MOA.
 +   * 
 +   * @see SignatureInformation#getSignedData()
 +   */
 +  public String getHashInputData();
 +  
 +  /**
 +   * 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 <code>true</code> if non textual objects have been found, <code>false</code> if not.
 +   * @return <code>true</code> if non textual objects have been found, <code>false</code> if not.
 +   */
 +  public boolean hasNonTextualObjects();
 +
 +  /**
 +   * Get the reconstructed xmldsig XML data. The reconstruction is done during the verification process.
 +   * 
 +   * @see PdfAs#reconstructXMLDSIG(at.gv.egiz.pdfas.api.xmldsig.ReconstructXMLDsigParameters)
 +   * @see PdfAs#reconstructXMLDSIG(at.gv.egiz.pdfas.api.xmldsig.ReconstructXMLDsigAfterAnalysisParameters)
 +   * @return
 +   */
 +  public XMLDsigData getReconstructedXMLDsig();
 +
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyResults.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyResults.java new file mode 100644 index 00000000..44b62a78 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/VerifyResults.java @@ -0,0 +1,48 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.verify;
 +
 +import java.util.List;
 +
 +/**
 + * The result of the verification of a document.
 + * 
 + * <p>
 + * Currently, this is not more than a list of VerifyResult objects, one for each
 + * verified signature. There may be additional items in future PDF-AS versions.
 + * </p>
 + * 
 + * @author wprinz
 + */
 +public interface VerifyResults
 +{
 +  /**
 +   * Returns the List of VerifyResult objects, one for each verified signature.
 +   * 
 +   * @return Returns the List of VerifyResult objects, one for each verified
 +   *         signature.
 +   */
 +  public List getResults();
 +    
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/package-info.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/package-info.java new file mode 100644 index 00000000..be2cc3d4 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/verify/package-info.java @@ -0,0 +1,8 @@ +/** + *  + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas.api.verify;
\ No newline at end of file diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/xmldsig/ExtendedSignatureInformation.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/xmldsig/ExtendedSignatureInformation.java new file mode 100644 index 00000000..df12b529 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/xmldsig/ExtendedSignatureInformation.java @@ -0,0 +1,69 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.xmldsig;
 +
 +import at.gv.egiz.pdfas.api.commons.SignatureInformation;
 +
 +/**
 + * A wrapper to combine {@link SignatureInformation} and {@link XMLDsigData}
 + * 
 + * @author exthex
 + *
 + */
 +public class ExtendedSignatureInformation {
 +
 +   private final SignatureInformation signatureInformation;
 +   
 +   private final XMLDsigData xmlDsigData;
 +   
 +   /**
 +    * Constructor.
 +    * 
 +    * @param siginfo
 +    *          The signature information
 +    * @param dsigData
 +    *          The matching xmldsig to the signature information.
 +    */
 +   public ExtendedSignatureInformation(SignatureInformation siginfo, XMLDsigData dsigData) {
 +      this.signatureInformation = siginfo;
 +      this.xmlDsigData = dsigData;
 +   }
 +
 +   /**
 +    * 
 +    * @return the signatureInformation
 +    */
 +   public SignatureInformation getSignatureInformation() {
 +      return signatureInformation;
 +   }
 +
 +   /**
 +    * 
 +    * @return the xmlDsigData
 +    */
 +   public XMLDsigData getXmlDsigData() {
 +      return xmlDsigData;
 +   }
 +   
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/xmldsig/ReconstructXMLDsigAfterAnalysisParameters.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/xmldsig/ReconstructXMLDsigAfterAnalysisParameters.java new file mode 100644 index 00000000..229fba04 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/xmldsig/ReconstructXMLDsigAfterAnalysisParameters.java @@ -0,0 +1,86 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.xmldsig;
 +
 +import at.gv.egiz.pdfas.api.analyze.AnalyzeResult;
 +import at.gv.egiz.pdfas.api.commons.Constants;
 +
 +/**
 + * Parameters for the reconstructXMLDsig method which is to be called after a analyze call.
 + * 
 + * @author exthex
 + *
 + */
 +public class ReconstructXMLDsigAfterAnalysisParameters {
 +   
 +
 +   /**
 +    * The list of signatures to be verified.
 +    */
 +   protected AnalyzeResult analyzeResult = null;
 +
 +   /**
 +    * The signature device to perform the actual signature.
 +    * 
 +    * <p>
 +    * May be {@link Constants#SIGNATURE_DEVICE_MOA} or
 +    * {@link Constants#SIGNATURE_DEVICE_BKU}.
 +    * </p>
 +    */
 +   protected String signatureDevice = Constants.SIGNATURE_DEVICE_MOA;
 +
 +   /**
 +    * @return the analyzeResult
 +    */
 +   public AnalyzeResult getAnalyzeResult()
 +   {
 +     return this.analyzeResult;
 +   }
 +
 +   /**
 +    * @param analyzeResult
 +    *          the analyzeResult to set
 +    */
 +   public void setAnalyzeResult(AnalyzeResult analyzeResult)
 +   {
 +     this.analyzeResult = analyzeResult;
 +   }
 +
 +   /**
 +    * @return the signatureDevice
 +    */
 +   public String getSignatureDevice()
 +   {
 +     return this.signatureDevice;
 +   }
 +
 +   /**
 +    * @param signatureDevice
 +    *          the signatureDevice to set
 +    */
 +   public void setSignatureDevice(String signatureDevice)
 +   {
 +     this.signatureDevice = signatureDevice;
 +   }
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/xmldsig/ReconstructXMLDsigParameters.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/xmldsig/ReconstructXMLDsigParameters.java new file mode 100644 index 00000000..445d7ae4 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/xmldsig/ReconstructXMLDsigParameters.java @@ -0,0 +1,218 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.xmldsig;
 +
 +import java.util.Date;
 +
 +import at.gv.egiz.pdfas.api.PdfAs;
 +import at.gv.egiz.pdfas.api.commons.Constants;
 +import at.gv.egiz.pdfas.api.io.DataSource;
 +
 +/**
 + * Parameters for the {@link PdfAs#reconstructXMLDSIG(ReconstructXMLDsigParameters)} method.
 + * No need to call analyze before calling this method.  
 + * 
 + * @author exthex
 + *
 + */
 +public class ReconstructXMLDsigParameters {
 +   
 +   /**
 +    * The document to be verified.
 +    */
 +   protected DataSource document = null;
 +
 +   /**
 +    * The signature device to perform the actual signature.
 +    * 
 +    * <p>
 +    * May be {@link Constants#SIGNATURE_DEVICE_MOA} or
 +    * {@link Constants#SIGNATURE_DEVICE_BKU}.
 +    * </p>
 +    */
 +   protected String signatureDevice = Constants.SIGNATURE_DEVICE_MOA;
 +
 +   /**
 +    * The mode of operation how the document is analyzed.
 +    * 
 +    * <p>
 +    * May be {@link Constants#VERIFY_MODE_BINARY_ONLY} to check the document for
 +    * binary signatures only (very fast). Or may be
 +    * {@link Constants#VERIFY_MODE_SEMI_CONSERVATIVE} to perform a semi
 +    * conservative (optimized) text and binary verification (slow). Or may be
 +    * {@link Constants#VERIFY_MODE_FULL_CONSERVATIVE} to perform a full
 +    * conservative text and binary verification (very slow).
 +    * </p>
 +    */
 +   protected String verifyMode = Constants.VERIFY_MODE_FULL_CONSERVATIVE;
 +
 +   /**
 +    * The (zero based) index of the signature to verify.
 +    * 
 +    * <p>
 +    * This allows to verify only one found signature instead of all. {@link Constants#VERIFY_ALL} means to
 +    * verify all found signatures.
 +    * </p>
 +    */
 +   protected int signatureToVerify = Constants.VERIFY_ALL;
 +
 +   /**
 +    * Allows to pass a VerificationTime to the verification device.
 +    * 
 +    * <p>
 +    * Note that the actual usage of this parameter depends on the verification device.
 +    * </p>
 +    */
 +   protected Date verificationTime = null;
 +
 +   /**
 +    * Tells the signature device (e.g. MOA) to return the signature hash input
 +    * data (which is the probably transformed signed data).
 +    * 
 +    * <p>
 +    * Note that this forces MOA to return the potentially large signature data to
 +    * be returned in the result XML, which may result in very bad performance.
 +    * </p>
 +    */
 +   protected boolean returnHashInputData = false;
 +     
 +   protected boolean returnNonTextualObjects = false;
 +
 +   /**
 +    * @return the document
 +    */
 +   public DataSource getDocument()
 +   {
 +     return this.document;
 +   }
 +
 +   /**
 +    * @param document
 +    *          the document to set
 +    */
 +   public void setDocument(DataSource document)
 +   {
 +     this.document = document;
 +   }
 +
 +   /**
 +    * @return the signatureDevice
 +    */
 +   public String getSignatureDevice()
 +   {
 +     return this.signatureDevice;
 +   }
 +
 +   /**
 +    * @param signatureDevice
 +    *          the signatureDevice to set
 +    */
 +   public void setSignatureDevice(String signatureDevice)
 +   {
 +     this.signatureDevice = signatureDevice;
 +   }
 +
 +   /**
 +    * @return the verifyMode
 +    */
 +   public String getVerifyMode()
 +   {
 +     return this.verifyMode;
 +   }
 +
 +   /**
 +    * @param verifyMode
 +    *          the verifyMode to set
 +    */
 +   public void setVerifyMode(String verifyMode)
 +   {
 +     this.verifyMode = verifyMode;
 +   }
 +
 +   /**
 +    * @return the signatureToVerify
 +    */
 +   public int getSignatureToVerify()
 +   {
 +     return this.signatureToVerify;
 +   }
 +
 +   /**
 +    * @param signatureToVerify
 +    *          the signatureToVerify to set
 +    */
 +   public void setSignatureToVerify(int signatureToVerify)
 +   {
 +     this.signatureToVerify = signatureToVerify;
 +   }
 +
 +   /**
 +    * @return the verificationTime
 +    */
 +   public Date getVerificationTime()
 +   {
 +     return this.verificationTime;
 +   }
 +
 +   /**
 +    * @param verificationTime
 +    *          the verificationTime to set
 +    */
 +   public void setVerificationTime(Date verificationTime)
 +   {
 +     this.verificationTime = verificationTime;
 +   }
 +
 +   /**
 +    * @return the returnHashInputData
 +    */
 +   public boolean isReturnHashInputData()
 +   {
 +     return this.returnHashInputData;
 +   }
 +
 +   /**
 +    * @param returnHashInputData
 +    *          the returnHashInputData to set
 +    */
 +   public void setReturnHashInputData(boolean returnHashInputData)
 +   {
 +     this.returnHashInputData = returnHashInputData;
 +   }
 +
 +    public boolean isReturnNonTextualObjects() {
 +       return this.returnNonTextualObjects;
 +    }
 +    
 +    /**
 +     * Tells if non text object of the signed pdf should be extracted and returned.
 +     * One should show this to the user, especially in case of textual signature.
 +     * Defaults to <tt>false</tt>
 +     * 
 +     * @param returnNonTextualObjects
 +     */
 +    public void setReturnNonTextualObjects(boolean returnNonTextualObjects) {
 +       this.returnNonTextualObjects = returnNonTextualObjects;
 +    }
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/xmldsig/ReconstructXMLDsigResult.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/xmldsig/ReconstructXMLDsigResult.java new file mode 100644 index 00000000..580f3af6 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/xmldsig/ReconstructXMLDsigResult.java @@ -0,0 +1,74 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.xmldsig;
 +
 +import java.util.List;
 +
 +import at.gv.egiz.pdfas.api.commons.Constants;
 +import at.gv.egiz.pdfas.api.commons.SignatureInformation;
 +
 +/**
 + * The result of a reconstructXMLDsig call.<br/>
 + * This is just a wrapper for a list of {@link ExtendedSignatureInformation}s
 + * 
 + * 
 + * @author exthex
 + */
 +public class ReconstructXMLDsigResult {
 +
 +   private List extendedSignatures;
 +   
 +   private String device;
 +   
 +   /**
 +    * 
 +    * @param extendedSignatureInfos
 +    * @param signatureDevice
 +    */
 +   public ReconstructXMLDsigResult(List extendedSignatureInfos, String signatureDevice) {
 +      this.extendedSignatures = extendedSignatureInfos;
 +      this.device = signatureDevice;
 +   }
 +
 +   /**
 +    * Get the signature device that was used to create this result.
 +    * 
 +    * @return {@link Constants#SIGNATURE_DEVICE_MOA} or {@link Constants#SIGNATURE_DEVICE_BKU}
 +    */
 +   public String getDevice() {
 +      return device;
 +   }
 +   
 +   /**
 +    * Returns the list of found signatures.
 +    * 
 +    * @return Returns a list of {@link ExtendedSignatureInformation} objects representing all
 +    *         found signatures + {@link XMLDsigData}.
 +    * @see SignatureInformation
 +    */
 +   public List getExtendedSignatures() {
 +      return this.extendedSignatures;
 +   }
 +   
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/xmldsig/XMLDsigData.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/xmldsig/XMLDsigData.java new file mode 100644 index 00000000..0449cfa2 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/xmldsig/XMLDsigData.java @@ -0,0 +1,83 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + */
 +package at.gv.egiz.pdfas.api.xmldsig;
 +
 +/**
 + * A container for XMLDsig data.
 + * 
 + * @author exthex
 + *
 + */
 +public class XMLDsigData {
 +
 +   private String xmlDsig;
 +   
 +   private boolean detached;
 +   
 +   /**
 +    * Constructor.
 +    * 
 +    * @param xmldsig the xml string of the xmldsig. 
 +    * @param detached true if detached, false otherwise
 +    */
 +   public XMLDsigData(String xmldsig, boolean detached) {
 +      this.xmlDsig = xmldsig;
 +      this.detached = detached;
 +   }
 +
 +   /**
 +    * Get the xmldsig string
 +    * @return
 +    */
 +   public String getXmlDsig() {
 +      return xmlDsig;
 +   }
 +
 +   /**
 +    * Set the xmldsig string.
 +    * 
 +    * @param xmlDsig
 +    */
 +   public void setXmlDsig(String xmlDsig) {
 +      this.xmlDsig = xmlDsig;
 +   }
 +
 +   /**
 +    * 
 +    * @return true if detached, false otherwise
 +    */
 +   public boolean isDetached() {
 +      return detached;
 +   }
 +
 +   /**
 +    * Set the detached.
 +    * 
 +    * @param detached
 +    */
 +   public void setDetached(boolean detached) {
 +      this.detached = detached;
 +   }
 +
 +}
 diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/xmldsig/package-info.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/xmldsig/package-info.java new file mode 100644 index 00000000..a34405a8 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/xmldsig/package-info.java @@ -0,0 +1,8 @@ +/** + *  + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas.api.xmldsig;
\ No newline at end of file diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/package-info.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/package-info.java new file mode 100644 index 00000000..073f3ce2 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/package-info.java @@ -0,0 +1,8 @@ +/** + *  + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas;
\ No newline at end of file diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/PdfAsObject.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/PdfAsObject.java new file mode 100644 index 00000000..6606ec4a --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/PdfAsObject.java @@ -0,0 +1,138 @@ +package at.gv.egiz.pdfas.wrapper; + +import java.io.File; +import java.util.List; + +import com.sun.org.apache.xml.internal.utils.UnImplNode; + +import at.gv.egiz.pdfas.api.PdfAs; +import at.gv.egiz.pdfas.api.analyze.AnalyzeParameters; +import at.gv.egiz.pdfas.api.analyze.AnalyzeResult; +import at.gv.egiz.pdfas.api.commons.DynamicSignatureLifetimeEnum; +import at.gv.egiz.pdfas.api.commons.DynamicSignatureProfile; +import at.gv.egiz.pdfas.api.exceptions.ErrorCode; +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; +import at.gv.egiz.pdfas.api.verify.VerifyResults; +import at.gv.egiz.pdfas.api.xmldsig.ReconstructXMLDsigAfterAnalysisParameters; +import at.gv.egiz.pdfas.api.xmldsig.ReconstructXMLDsigParameters; +import at.gv.egiz.pdfas.api.xmldsig.ReconstructXMLDsigResult; + +public class PdfAsObject implements PdfAs { + +	public SignResult sign(SignParameters signParameters) throws PdfAsException { +		// TODO Auto-generated method stub +		return null; +	} + +	public SignResult sign(SignParameters signParameters, +			SignatureDetailInformation signatureDetailInformation) +			throws PdfAsException { +		// TODO Auto-generated method stub +		return null; +	} + +	public VerifyResults verify(VerifyParameters verifyParameters) +			throws PdfAsException { +		// TODO Auto-generated method stub +		return null; +	} + +	public AnalyzeResult analyze(AnalyzeParameters analyzeParameters) +			throws PdfAsException { +		throw new PdfAsException(ErrorCode.FUNCTION_NOT_AVAILABLE, +				new RuntimeException()); +	} + +	public ReconstructXMLDsigResult reconstructXMLDSIG( +			ReconstructXMLDsigParameters reconstructXMLDsigParameters) +			throws PdfAsException { +		throw new PdfAsException(ErrorCode.FUNCTION_NOT_AVAILABLE, +				new RuntimeException()); +	} + +	public ReconstructXMLDsigResult reconstructXMLDSIG( +			ReconstructXMLDsigAfterAnalysisParameters reconstructXMLDsigParameters) +			throws PdfAsException { +		throw new PdfAsException(ErrorCode.FUNCTION_NOT_AVAILABLE, +				new RuntimeException()); +	} + +	public VerifyResults verify( +			VerifyAfterAnalysisParameters verifyAfterAnalysisParameters) +			throws PdfAsException { +		throw new PdfAsException(ErrorCode.FUNCTION_NOT_AVAILABLE, +				new RuntimeException()); +	} + +	public VerifyResults verify( +			VerifyAfterReconstructXMLDsigParameters verifyAfterReconstructXMLDsigParameters) +			throws PdfAsException { +		throw new PdfAsException(ErrorCode.FUNCTION_NOT_AVAILABLE, +				new RuntimeException()); +	} + +	public void reloadConfig() throws PdfAsException { +		// TODO Auto-generated method stub + +	} + +	public List getProfileInformation() throws PdfAsException { +		// TODO Auto-generated method stub +		return null; +	} + +	public DynamicSignatureProfile createDynamicSignatureProfile( +			String parentProfile, DynamicSignatureLifetimeEnum mode) { +		// TODO Auto-generated method stub +		return null; +	} + +	public DynamicSignatureProfile createDynamicSignatureProfile( +			String myUniqueName, String parentProfile, +			DynamicSignatureLifetimeEnum mode) { +		// TODO Auto-generated method stub +		return null; +	} + +	public DynamicSignatureProfile createEmptyDynamicSignatureProfile( +			DynamicSignatureLifetimeEnum mode) { +		// TODO Auto-generated method stub +		return null; +	} + +	public DynamicSignatureProfile createEmptyDynamicSignatureProfile( +			String myUniqueName, DynamicSignatureLifetimeEnum mode) { +		// TODO Auto-generated method stub +		return null; +	} + +	public DynamicSignatureProfile loadDynamicSignatureProfile( +			String profileName) { +		// TODO Auto-generated method stub +		return null; +	} + +	public SignatureDetailInformation prepareSign(SignParameters signParameters) +			throws PdfAsException { +		// TODO Auto-generated method stub +		return null; +	} + +	public SignResult finishSign(SignParameters signParameters, +			SignatureDetailInformation signatureDetailInformation) +			throws PdfAsException { +		// TODO Auto-generated method stub +		return null; +	} + +	public PdfAsObject(File workdirectory) { +		//TODO +	} + +} diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/package-info.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/package-info.java new file mode 100644 index 00000000..37867d98 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/package-info.java @@ -0,0 +1,8 @@ +/** + *  + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas.wrapper;
\ No newline at end of file diff --git a/pdf-as-legacy/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureTypes.java b/pdf-as-legacy/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureTypes.java new file mode 100644 index 00000000..0897608b --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureTypes.java @@ -0,0 +1,144 @@ +/**
 + * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
 + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
 + * joint initiative of the Federal Chancellery Austria and Graz University of
 + * Technology.
 + *
 + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 + * the European Commission - subsequent versions of the EUPL (the "Licence");
 + * You may not use this work except in compliance with the Licence.
 + * You may obtain a copy of the Licence at:
 + * http://www.osor.eu/eupl/
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the Licence is distributed on an "AS IS" basis,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the Licence for the specific language governing permissions and
 + * limitations under the Licence.
 + *
 + * This product combines work with different licenses. See the "NOTICE" text
 + * file for details on the various modules and licenses.
 + * The "NOTICE" text file is part of the distribution. Any derivative works
 + * that you distribute must include a readable copy of the "NOTICE" text file.
 + *
 + * $Id: SignatureTypes.java,v 1.5 2006/10/31 08:18:56 wprinz Exp $
 + */
 +package at.knowcenter.wag.egov.egiz.sig;
 +
 +
 +public class SignatureTypes
 +{
 +
 +	/**
 +	 * Defines all supported states for {@link SignatureTypes} (signature profiles). Signature types can be enabled
 +	 * ("on"), can be set to support signature only ("sign_only"), to verification only ("verify_only") or can be
 +	 * disabled ("off" or any other value not covered by other enum values).
 +	 * 
 +	 * @author Datentechnik Innovation GmbH
 +	 */
 +	public enum State {
 +		
 +		/**
 +		 * Enables a signature profile.
 +		 */
 +		ON ("on", "yes", "true", "enabled"),
 +		
 +		/**
 +		 * Disables a signature profile.
 +		 */
 +		OFF (),
 +		
 +		/**
 +		 * Restricts the signature profile so that is can only be used for verification purposes and not for signature.
 +		 */
 +		VERIFY_ONLY ("verify_only", "verify-only", "verifyonly", "verify only", "verify"),
 +		
 +		/**
 +		 * Allows the signature profile to be used for signature but not for verification. 
 +		 */
 +		SIGN_ONLY ("sign_only", "sign-only", "signonly", "sign only", "sign");
 +		
 +		/**
 +		 * Sets the default state when no valid value was provided.
 +		 */
 +		private static final State DEFAULT = OFF;
 +		
 +		/**
 +		 * States that allow signatures.
 +		 */
 +		private static final State[] CAN_SIGN = { ON, SIGN_ONLY };
 +		
 +		/**
 +		 * States that allow verification.
 +		 */
 +		private static final State[] CAN_VERIFY = { ON, VERIFY_ONLY };
 +		
 +		private String[] keyWords;
 +
 +		private State(String... keyWords) {
 +			this.keyWords = keyWords;
 +		}
 +		
 +		/**
 +		 * Returns a valid State from a given {@code keyWord}. If the {@code keyWord} cannot be matched to a certain
 +		 * state, the default State {@link #OFF} is returned.
 +		 * 
 +		 * @param keyWord
 +		 *            A valid keyword like "on", "sign_only"...
 +		 * @return The enum State.
 +		 */
 +		public static State fromString(String keyWord) {
 +			if (keyWord == null) {
 +				return DEFAULT;
 +			}
 +			try {
 +				return valueOf(keyWord.toUpperCase());
 +			} catch (IllegalArgumentException e) {
 +				for (State candidate : values()) {
 +					for (String candidateKeyWord : candidate.keyWords) {
 +						if (keyWord.equalsIgnoreCase(candidateKeyWord)) {
 +							return candidate;
 +						}
 +					}
 +				}
 +				return DEFAULT;
 +			}
 +		}
 +		
 +		/**
 +		 * Returns {@code true} when the current state is one of the given candidate {@code states}.
 +		 * 
 +		 * @param states
 +		 *            The candidate states.
 +		 * @return {@code true} when the current state is one of the given candidate states, {@code false} if not.
 +		 */
 +		public boolean in(State... states) {
 +			if (states != null) {
 +				for (State state : states) {
 +					if (this == state) {
 +						return true;
 +					}
 +				}
 +			}
 +			return false;
 +		}
 +		
 +		/**
 +		 * Returns if the respective state allows signatures.
 +		 * @return {@code true} if signatures are allowed, {@code false} if not.
 +		 */
 +		public boolean canSign() {
 +			return in(CAN_SIGN);
 +		}
 +		
 +		/**
 +		 * Returns if the respective state allows verification.
 +		 * @return {@code true} if verification is allowed, {@code false} if not.
 +		 */
 +		public boolean canVerify() {
 +			return in(CAN_VERIFY);
 +		}
 +
 +	}
 +
 +}
\ No newline at end of file diff --git a/pdf-as-legacy/src/main/java/at/knowcenter/wag/egov/egiz/sig/package-info.java b/pdf-as-legacy/src/main/java/at/knowcenter/wag/egov/egiz/sig/package-info.java new file mode 100644 index 00000000..cf2d67f1 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/knowcenter/wag/egov/egiz/sig/package-info.java @@ -0,0 +1,8 @@ +/** + *  + */ +/** + * @author afitzek + * + */ +package at.knowcenter.wag.egov.egiz.sig;
\ No newline at end of file | 
