diff options
author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2013-10-16 10:30:10 +0200 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2013-10-16 10:30:10 +0200 |
commit | 07cfc175c86eec0def3cd7376e0697317d3d7b26 (patch) | |
tree | c1336c67023b508a8a662ed1d9f42707295d0591 | |
parent | 62434d4f7d4bf80b4c236c4153bffab703916ee3 (diff) | |
download | pdf-as-4-07cfc175c86eec0def3cd7376e0697317d3d7b26.tar.gz pdf-as-4-07cfc175c86eec0def3cd7376e0697317d3d7b26.tar.bz2 pdf-as-4-07cfc175c86eec0def3cd7376e0697317d3d7b26.zip |
Legacy API changes
17 files changed, 654 insertions, 157 deletions
diff --git a/pdf-as-legacy/.gitignore b/pdf-as-legacy/.gitignore new file mode 100644 index 00000000..5e56e040 --- /dev/null +++ b/pdf-as-legacy/.gitignore @@ -0,0 +1 @@ +/bin 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 index e1f31f7a..dd336707 100644 --- 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 @@ -25,14 +25,13 @@ package at.gv.egiz.pdfas.api.commons; import java.util.Enumeration;
import java.util.HashMap;
+import java.util.Iterator;
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.gv.egiz.pdfas.common.settings.ISettings;
+import at.gv.egiz.pdfas.lib.api.Configuration;
import at.knowcenter.wag.egov.egiz.sig.SignatureTypes;
// TODO exception types?
@@ -46,22 +45,26 @@ 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 static Map<String, DynamicSignatureProfile> profiles =
+ new HashMap<String, DynamicSignatureProfile>();
+ private static ThreadLocal<DynamicSignatureProfile> localProfiles = new ThreadLocal<DynamicSignatureProfile>();
private DynamicSignatureLifetimeEnum lifeMode;
-
+ private Configuration configuration;
- private DynamicSignatureProfileImpl(DynamicSignatureLifetimeEnum mode, String name) {
+ private DynamicSignatureProfileImpl(DynamicSignatureLifetimeEnum mode, String name,
+ Configuration configuration) {
if (name != null) {
this.name = name;
} else {
this.name = createDynamicTypeName();
}
+ this.configuration = configuration;
this.lifeMode = mode;
}
- public static DynamicSignatureProfileImpl createFromParent(String myUniqueName, String parentProfile, DynamicSignatureLifetimeEnum mode) {
- DynamicSignatureProfileImpl res = new DynamicSignatureProfileImpl(mode, myUniqueName);
+ public static DynamicSignatureProfileImpl createFromParent(String myUniqueName, String parentProfile,
+ DynamicSignatureLifetimeEnum mode, Configuration configuration) {
+ DynamicSignatureProfileImpl res = new DynamicSignatureProfileImpl(mode, myUniqueName, configuration);
res.initFromParent(parentProfile);
return res;
}
@@ -89,8 +92,9 @@ public class DynamicSignatureProfileImpl implements DynamicSignatureProfile { }
}
- public static DynamicSignatureProfileImpl createEmptyProfile(String myUniqueName, DynamicSignatureLifetimeEnum mode) {
- return new DynamicSignatureProfileImpl(mode, myUniqueName);
+ public static DynamicSignatureProfileImpl createEmptyProfile(String myUniqueName, DynamicSignatureLifetimeEnum mode,
+ Configuration configuration) {
+ return new DynamicSignatureProfileImpl(mode, myUniqueName, configuration);
}
public static DynamicSignatureProfileImpl loadProfile(String name) {
@@ -155,21 +159,32 @@ public class DynamicSignatureProfileImpl implements DynamicSignatureProfile { private void initFromParent(String parentProfile) {
try {
- SettingsReader cfg = null;
-
- cfg = SettingsReader.getInstance();
+ ISettings cfg = null;
- Properties props = cfg.getProperties();
+ cfg = (ISettings)configuration;
+ String parentKey = "sig_obj." + parentProfile + ".";
+ Map<String, String> properties = cfg.getValuesPrefix(parentKey);
+ //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();) {
+ /*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);
}
+ }*/
+
+ Iterator<String> keyIt = properties.keySet().iterator();
+
+ while(keyIt.hasNext()) {
+ String oldKey = keyIt.next();
+ String newKey = oldKey.replaceAll(parentProfile, name);
+ String val = properties.get(oldKey);
+ this.newProps.put(newKey, val);
}
+
this.newProps.put("sig_obj.types." + name, "on");
} catch (Exception e) {
throw new RuntimeException(e);
@@ -181,16 +196,12 @@ public class DynamicSignatureProfileImpl implements DynamicSignatureProfile { */
public synchronized void apply() {
try {
- SettingsReader settings = SettingsReader.getInstance();
-
- settings.getProperties().putAll(this.newProps);
-
- for (Enumeration e = newProps.keys(); e.hasMoreElements();) {
+ Configuration cfg = this.configuration;
+ for (Enumeration<Object> e = newProps.keys(); e.hasMoreElements();) {
String key = (String) e.nextElement();
- settings.getPTree().setKeyValue(key, newProps.getProperty(key));
+ cfg.setValue(key, newProps.getProperty(key));
}
- SignatureTypes.getInstance().addSignatureType(this.name);
store();
} catch (Exception e) {
throw new RuntimeException(e);
@@ -202,12 +213,11 @@ public class DynamicSignatureProfileImpl implements DynamicSignatureProfile { */
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);
+ Configuration cfg = this.configuration;
+ for (Enumeration<Object> e = newProps.keys(); e.hasMoreElements();) {
+ String key = (String) e.nextElement();
+ cfg.setValue(key, null);
+ }
remove();
} catch (Exception e) {
throw new RuntimeException(e);
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 index 91dd8d8a..790ce9e0 100644 --- 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 @@ -110,6 +110,6 @@ public final class ErrorCode public static final int CORRECTOR_EXCEPTION = 801;
public static final int EXTERNAL_CORRECTOR_TIMEOUT_REACHED = 802;
-
+ public static final int WRAPPED_ERROR_CODE = 998;
public static final int FUNCTION_NOT_AVAILABLE = 999;
}
diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/exceptions/PdfAsWrappedException.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/exceptions/PdfAsWrappedException.java new file mode 100644 index 00000000..2ddd1146 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/api/exceptions/PdfAsWrappedException.java @@ -0,0 +1,14 @@ +package at.gv.egiz.pdfas.api.exceptions; + +public class PdfAsWrappedException extends PdfAsException { + + /** + * + */ + private static final long serialVersionUID = -3947240372353864753L; + + public PdfAsWrappedException(Throwable e) { + super(ErrorCode.WRAPPED_ERROR_CODE, e.getMessage(), e); + } + +} 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 index 6606ec4a..067021b2 100644 --- 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 @@ -1,15 +1,16 @@ package at.gv.egiz.pdfas.wrapper; import java.io.File; +import java.util.ArrayList; +import java.util.Iterator; 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.commons.DynamicSignatureProfileImpl; import at.gv.egiz.pdfas.api.exceptions.ErrorCode; import at.gv.egiz.pdfas.api.exceptions.PdfAsException; import at.gv.egiz.pdfas.api.sign.SignParameters; @@ -22,25 +23,59 @@ 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.lib.api.ByteArrayDataSource; +import at.gv.egiz.pdfas.lib.api.Configuration; +import at.gv.egiz.pdfas.lib.api.PdfAsFactory; +import at.gv.egiz.pdfas.lib.api.StatusRequest; +import at.gv.egiz.pdfas.lib.api.sign.SignParameter; +import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter; +import at.gv.egiz.pdfas.lib.api.verify.VerifyResult; public class PdfAsObject implements PdfAs { + private at.gv.egiz.pdfas.lib.api.PdfAs pdfas4; + private Configuration configuration; + private File workdir; + public SignResult sign(SignParameters signParameters) throws PdfAsException { - // TODO Auto-generated method stub - return null; + SignatureDetailInformation signatureDetailInformation = this + .prepareSign(signParameters); + return this.sign(signParameters, signatureDetailInformation); } public SignResult sign(SignParameters signParameters, SignatureDetailInformation signatureDetailInformation) throws PdfAsException { - // TODO Auto-generated method stub + + // Create the signature .... + + // TODO wait for SL wrapper implementation return null; } public VerifyResults verify(VerifyParameters verifyParameters) throws PdfAsException { - // TODO Auto-generated method stub - return null; + try { + VerifyParameter newParameter = VerifyParameterWrapper.toNewParameters(verifyParameters); + + List<VerifyResult> results = this.pdfas4.verify(newParameter); + + Iterator<VerifyResult> it = results.iterator(); + + List<at.gv.egiz.pdfas.api.verify.VerifyResult> resultList = + new ArrayList<at.gv.egiz.pdfas.api.verify.VerifyResult>(); + + while(it.hasNext()) { + VerifyResult newResult = it.next(); + at.gv.egiz.pdfas.api.verify.VerifyResult oldResult = + new VerifyResultWrapper(newResult); + resultList.add(oldResult); + } + + return new VerifyResultsImpl(resultList); + } catch(at.gv.egiz.pdfas.common.exceptions.PdfAsException e) { + throw new PdfAsException(0, e.getMessage()); + } } public AnalyzeResult analyze(AnalyzeParameters analyzeParameters) @@ -78,61 +113,78 @@ public class PdfAsObject implements PdfAs { } public void reloadConfig() throws PdfAsException { - // TODO Auto-generated method stub - + this.pdfas4 = at.gv.egiz.pdfas.lib.api.PdfAsFactory + .createPdfAs(this.workdir); + this.configuration = this.pdfas4.getConfiguration(); } public List getProfileInformation() throws PdfAsException { - // TODO Auto-generated method stub - return null; + throw new PdfAsException(ErrorCode.FUNCTION_NOT_AVAILABLE, + new RuntimeException()); } public DynamicSignatureProfile createDynamicSignatureProfile( String parentProfile, DynamicSignatureLifetimeEnum mode) { - // TODO Auto-generated method stub - return null; + return DynamicSignatureProfileImpl.createFromParent(null, + parentProfile, mode, configuration); } public DynamicSignatureProfile createDynamicSignatureProfile( String myUniqueName, String parentProfile, DynamicSignatureLifetimeEnum mode) { - // TODO Auto-generated method stub - return null; + return DynamicSignatureProfileImpl.createFromParent(myUniqueName, + parentProfile, mode, configuration); } public DynamicSignatureProfile createEmptyDynamicSignatureProfile( DynamicSignatureLifetimeEnum mode) { - // TODO Auto-generated method stub - return null; + return DynamicSignatureProfileImpl.createEmptyProfile(null, mode, + configuration); } public DynamicSignatureProfile createEmptyDynamicSignatureProfile( String myUniqueName, DynamicSignatureLifetimeEnum mode) { - // TODO Auto-generated method stub - return null; + return DynamicSignatureProfileImpl.createEmptyProfile(myUniqueName, + mode, configuration); } public DynamicSignatureProfile loadDynamicSignatureProfile( String profileName) { - // TODO Auto-generated method stub - return null; + return DynamicSignatureProfileImpl.loadProfile(profileName); } public SignatureDetailInformation prepareSign(SignParameters signParameters) throws PdfAsException { - // TODO Auto-generated method stub - return null; + try { + // Prepare Signature + + SignParameter signParameter4 = PdfAsFactory.createSignParameter( + this.configuration, new ByteArrayDataSource(signParameters + .getDocument().getAsByteArray())); + + SignParameterWrapper wrapper = new SignParameterWrapper(signParameters, signParameter4); + + // TODO: wrapper sync old to new + StatusRequest request = this.pdfas4.startSign(wrapper.getSignParameter4()); + // TODO: wait for SL implementation wrapper + return null; + + } catch (at.gv.egiz.pdfas.common.exceptions.PdfAsException e) { + throw new PdfAsException(0, e.getMessage()); + } } public SignResult finishSign(SignParameters signParameters, SignatureDetailInformation signatureDetailInformation) throws PdfAsException { - // TODO Auto-generated method stub - return null; + return sign(signParameters, signatureDetailInformation); } public PdfAsObject(File workdirectory) { - //TODO + this.workdir = workdirectory; + this.pdfas4 = at.gv.egiz.pdfas.lib.api.PdfAsFactory + .createPdfAs(workdirectory); + this.configuration = this.pdfas4.getConfiguration(); } } diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/SignParameterWrapper.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/SignParameterWrapper.java new file mode 100644 index 00000000..b51896bd --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/SignParameterWrapper.java @@ -0,0 +1,32 @@ +package at.gv.egiz.pdfas.wrapper; + +import at.gv.egiz.pdfas.api.sign.SignParameters; +import at.gv.egiz.pdfas.lib.api.sign.SignParameter; + +public class SignParameterWrapper { + + private SignParameter signParameter4; + private SignParameters signParameters; + + public SignParameterWrapper(SignParameters signParameters, SignParameter signParameter4) { + this.signParameter4 = signParameter4; + this.signParameters = signParameters; + } + + private void syncOldToNew() { + // TODO + } + + private void syncNewToOld() { + // TODO + } + + + public SignParameter getSignParameter4() { + return this.signParameter4; + } + + public SignParameters getSignParameters() { + return this.signParameters; + } +} diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/SignatureCheckWrapper.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/SignatureCheckWrapper.java new file mode 100644 index 00000000..04b0dd3c --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/SignatureCheckWrapper.java @@ -0,0 +1,21 @@ +package at.gv.egiz.pdfas.wrapper; + +import at.gv.egiz.pdfas.api.verify.SignatureCheck; + +public class SignatureCheckWrapper implements SignatureCheck { + + private at.gv.egiz.pdfas.lib.api.verify.SignatureCheck newCheck; + + public SignatureCheckWrapper(at.gv.egiz.pdfas.lib.api.verify.SignatureCheck newCheck) { + this.newCheck = newCheck; + } + + public int getCode() { + return this.newCheck.getCode(); + } + + public String getMessage() { + return this.newCheck.getMessage(); + } + +} diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/SignatureDetailInformationWrapper.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/SignatureDetailInformationWrapper.java new file mode 100644 index 00000000..683e083f --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/SignatureDetailInformationWrapper.java @@ -0,0 +1,88 @@ +package at.gv.egiz.pdfas.wrapper; + +import java.security.cert.X509Certificate; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import at.gv.egiz.pdfas.api.io.DataSource; +import at.gv.egiz.pdfas.api.sign.SignatureDetailInformation; +import at.gv.egiz.pdfas.api.sign.pos.SignaturePosition; + +public class SignatureDetailInformationWrapper implements SignatureDetailInformation { + + private SignParameterWrapper wrapper; + + public DataSource getSignatureData() { + // TODO + return null; + } + + public SignaturePosition getSignaturePosition() { + // TODO Auto-generated method stub + return null; + } + + public List getNonTextualObjects() { + return null; + } + + public Date getSignDate() { + return null; + } + + public String getIssuer() { + return null; + } + + public Map getIssuerDNMap() { + return null; + } + + public String getSubjectName() { + return null; + } + + public String getSerialNumber() { + return null; + } + + public String getSigAlgorithm() { + return null; + } + + public String getSigID() { + return null; + } + + public String getSigKZ() { + return null; + } + + public String getSignatureValue() { + return null; + } + + public String getSigTimeStamp() { + // TODO Auto-generated method stub + return null; + } + + public Map getSubjectDNMap() { + return null; + } + + public X509Certificate getX509Certificate() { + return null; + } + + public boolean isTextual() { + // TODO Auto-generated method stub + return false; + } + + public boolean isBinary() { + return true; + } + +} diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/VerifyParameterWrapper.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/VerifyParameterWrapper.java new file mode 100644 index 00000000..387d9ea4 --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/VerifyParameterWrapper.java @@ -0,0 +1,14 @@ +package at.gv.egiz.pdfas.wrapper; + +import at.gv.egiz.pdfas.api.verify.VerifyParameters; +import at.gv.egiz.pdfas.lib.api.PdfAsFactory; +import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter; + +public class VerifyParameterWrapper { + + public static VerifyParameter toNewParameters(VerifyParameters oldParameters) { + //TODO + return null; + } + +} diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/VerifyResultWrapper.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/VerifyResultWrapper.java new file mode 100644 index 00000000..0364be9b --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/VerifyResultWrapper.java @@ -0,0 +1,116 @@ +package at.gv.egiz.pdfas.wrapper; + +import java.security.cert.X509Certificate; +import java.util.Date; +import java.util.List; + +import at.gv.egiz.pdfas.api.exceptions.PdfAsException; +import at.gv.egiz.pdfas.api.exceptions.PdfAsWrappedException; +import at.gv.egiz.pdfas.api.io.DataSource; +import at.gv.egiz.pdfas.api.verify.SignatureCheck; +import at.gv.egiz.pdfas.api.verify.VerifyResult; +import at.gv.egiz.pdfas.api.xmldsig.XMLDsigData; + +public class VerifyResultWrapper implements VerifyResult { + + private at.gv.egiz.pdfas.lib.api.verify.VerifyResult newResult; + + public VerifyResultWrapper(at.gv.egiz.pdfas.lib.api.verify.VerifyResult newResult) { + this.newResult = newResult; + } + + public String getSignatureType() { + // TODO Auto-generated method stub + return null; + } + + public DataSource getSignedData() { + // TODO Auto-generated method stub + return null; + } + + public X509Certificate getSignerCertificate() { + return this.newResult.getSignerCertificate(); + } + + public Date getSigningTime() { + // TODO Auto-generated method stub + return null; + } + + public Object getInternalSignatureInformation() { + // TODO Auto-generated method stub + return null; + } + + public String getTimeStampValue() { + // TODO Auto-generated method stub + return null; + } + + public void setNonTextualObjects(List nonTextualObjects) { + } + + public boolean isVerificationDone() { + return this.newResult.isVerificationDone(); + } + + public PdfAsException getVerificationException() { + return new PdfAsWrappedException(this.newResult.getVerificationException()); + } + + public SignatureCheck getCertificateCheck() { + return new SignatureCheckWrapper(this.newResult.getCertificateCheck()); + } + + public SignatureCheck getValueCheckCode() { + return new SignatureCheckWrapper(this.newResult.getValueCheckCode()); + } + + public SignatureCheck getManifestCheckCode() { + return new SignatureCheckWrapper(this.newResult.getManifestCheckCode()); + } + + public boolean isQualifiedCertificate() { + return this.newResult.isQualifiedCertificate(); + } + + public boolean isPublicAuthority() { + // TODO Auto-generated method stub + return false; + } + + public String getPublicAuthorityCode() { + // TODO Auto-generated method stub + return null; + } + + public List getPublicProperties() { + // TODO Auto-generated method stub + return null; + } + + public Date getVerificationTime() { + // TODO Auto-generated method stub + return null; + } + + public String getHashInputData() { + return null; + } + + public List getNonTextualObjects() { + return null; + } + + public boolean hasNonTextualObjects() { + return false; + } + + public XMLDsigData getReconstructedXMLDsig() { + return null; + } + + + +} diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/VerifyResultsImpl.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/VerifyResultsImpl.java new file mode 100644 index 00000000..d20da58b --- /dev/null +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/VerifyResultsImpl.java @@ -0,0 +1,20 @@ +package at.gv.egiz.pdfas.wrapper; + +import java.util.List; + +import at.gv.egiz.pdfas.api.verify.VerifyResult; +import at.gv.egiz.pdfas.api.verify.VerifyResults; + +public class VerifyResultsImpl implements VerifyResults { + + private List<VerifyResult> list; + + public VerifyResultsImpl(List<VerifyResult> list) { + this.list = list; + } + + public List getResults() { + return this.list; + } + +} diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/SignaturePosition.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/SignaturePosition.java new file mode 100644 index 00000000..477d798f --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/SignaturePosition.java @@ -0,0 +1,38 @@ +package at.gv.egiz.pdfas.lib.api; + +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-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignResult.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignResult.java index 03e48d73..d994c3e1 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignResult.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignResult.java @@ -3,6 +3,7 @@ package at.gv.egiz.pdfas.lib.api.sign; import java.security.cert.X509Certificate; import at.gv.egiz.pdfas.lib.api.DataSink; +import at.gv.egiz.pdfas.lib.api.SignaturePosition; public interface SignResult { /** @@ -34,5 +35,5 @@ public interface SignResult { * @return Returns the position where the signature is finally placed. May * return null if no position information is available. */ - //public SignaturePosition getSignaturePosition(); + public SignaturePosition getSignaturePosition(); } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java index c83d3bf7..6f74303c 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java @@ -1,17 +1,10 @@ package at.gv.egiz.pdfas.lib.impl; -import iaik.cms.CMSException; -import iaik.cms.CMSParsingException; -import iaik.cms.SignedData; -import iaik.cms.SignerInfo; -import iaik.x509.X509Certificate; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.OutputStream; -import java.security.SignatureException; import java.util.ArrayList; import java.util.Calendar; import java.util.List; @@ -25,13 +18,11 @@ import org.apache.pdfbox.pdmodel.PDDocument; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import sun.misc.Regexp; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; import at.gv.egiz.pdfas.common.exceptions.PdfAsSettingsException; import at.gv.egiz.pdfas.common.settings.ISettings; import at.gv.egiz.pdfas.common.settings.Settings; import at.gv.egiz.pdfas.common.settings.SignatureProfileSettings; -import at.gv.egiz.pdfas.common.utils.StringUtils; import at.gv.egiz.pdfas.lib.api.Configuration; import at.gv.egiz.pdfas.lib.api.IConfigurationConstants; import at.gv.egiz.pdfas.lib.api.PdfAs; @@ -48,7 +39,6 @@ import at.gv.egiz.pdfas.lib.impl.signing.IPdfSigner; import at.gv.egiz.pdfas.lib.impl.signing.PdfSignerFactory; import at.gv.egiz.pdfas.lib.impl.signing.pdfbox.PdfboxSignerWrapper; import at.gv.egiz.pdfas.lib.impl.signing.sig_interface.SignatureDataExtractor; -import at.gv.egiz.pdfas.lib.impl.signing.sig_interface.SignatureDataInjector; import at.gv.egiz.pdfas.lib.impl.stamping.IPDFStamper; import at.gv.egiz.pdfas.lib.impl.stamping.IPDFVisualObject; import at.gv.egiz.pdfas.lib.impl.stamping.StamperFactory; @@ -103,8 +93,9 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { logger.info("Selected signature Profile: " + signatureProfileID); - SignatureProfileConfiguration signatureProfileConfiguration = status - .getSignatureProfileConfiguration(signatureProfileID); + // SignatureProfileConfiguration signatureProfileConfiguration = + // status + // .getSignatureProfileConfiguration(signatureProfileID); // set Original PDF Document Data status.getPdfObject().setOriginalDocument( @@ -115,65 +106,62 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { // TODO: Do placeholder search } - if (requestedSignature.isVisual()) { - logger.info("Creating visual siganture block"); - // ================================================================ - // SignBlockCreationStage (visual) -> create visual signature - // block (logicaly) - SignatureProfileSettings signatureProfileSettings = TableFactory - .createProfile(signatureProfileID, settings); - - Table main = TableFactory.createSigTable( - signatureProfileSettings, MAIN, settings, - requestedSignature); - - IPDFStamper stamper = StamperFactory - .createDefaultStamper(settings); - IPDFVisualObject visualObject = stamper.createVisualPDFObject( - status.getPdfObject(), main); - - // ================================================================ - // PositioningStage (visual) -> find position or use fixed - // position - - String posString = status.getSignParamter() - .getSignaturePosition(); - - if (posString == null) { - posString = signatureProfileConfiguration - .getDefaultPositioning(); - } - - TablePos tablePos = null; - - if (posString == null) { - tablePos = new TablePos(); - } else { - tablePos = new TablePos(posString); - } - - PDDocument originalDocument = PDDocument - .load(new ByteArrayInputStream(status.getPdfObject() - .getOriginalDocument())); - - PositioningInstruction positioningInstruction = Positioning - .determineTablePositioning(tablePos, "", - originalDocument, visualObject); + this.stampPdf(status); - // ================================================================ - // StampingStage (visual) -> stamp logical signature block to - // location (itext) - - byte[] incrementalUpdate = stamper.writeVisualObject( - visualObject, positioningInstruction, status - .getPdfObject().getOriginalDocument()); - status.getPdfObject().setStampedDocument(incrementalUpdate); - } else { - logger.info("No visual siganture block"); - // Stamped Object is equal to original - status.getPdfObject().setStampedDocument( - status.getPdfObject().getOriginalDocument()); - } + /* + * if (requestedSignature.isVisual()) { + * logger.info("Creating visual siganture block"); // + * ================================================================ + * // SignBlockCreationStage (visual) -> create visual signature // + * block (logicaly) SignatureProfileSettings + * signatureProfileSettings = TableFactory + * .createProfile(signatureProfileID, settings); + * + * Table main = TableFactory.createSigTable( + * signatureProfileSettings, MAIN, settings, requestedSignature); + * + * IPDFStamper stamper = StamperFactory + * .createDefaultStamper(settings); IPDFVisualObject visualObject = + * stamper.createVisualPDFObject( status.getPdfObject(), main); + * + * // + * ================================================================ + * // PositioningStage (visual) -> find position or use fixed // + * position + * + * String posString = status.getSignParamter() + * .getSignaturePosition(); + * + * if (posString == null) { posString = + * signatureProfileConfiguration .getDefaultPositioning(); } + * + * TablePos tablePos = null; + * + * if (posString == null) { tablePos = new TablePos(); } else { + * tablePos = new TablePos(posString); } + * + * PDDocument originalDocument = PDDocument .load(new + * ByteArrayInputStream(status.getPdfObject() + * .getOriginalDocument())); + * + * PositioningInstruction positioningInstruction = Positioning + * .determineTablePositioning(tablePos, "", originalDocument, + * visualObject); + * + * // + * ================================================================ + * // StampingStage (visual) -> stamp logical signature block to // + * location (itext) + * + * byte[] incrementalUpdate = stamper.writeVisualObject( + * visualObject, positioningInstruction, status + * .getPdfObject().getOriginalDocument()); + * status.getPdfObject().setStampedDocument(incrementalUpdate); } + * else { logger.info("No visual siganture block"); // Stamped + * Object is equal to original + * status.getPdfObject().setStampedDocument( + * status.getPdfObject().getOriginalDocument()); } + */ // TODO: Create signature IPdfSigner signer = PdfSignerFactory.createPdfSigner(); @@ -269,8 +257,8 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { result.addAll(results); } - return result; } + return result; } catch (IOException e) { e.printStackTrace(); } catch (PdfAsException e) { @@ -327,24 +315,25 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { try { status.getRequestedSignature().setCertificate( request.getCertificate()); - + // set Original PDF Document Data status.getPdfObject().setOriginalDocument( status.getSignParamter().getDataSource().getByteData()); - + // STAMPER! stampPdf(status); request.setNeedCertificate(false); status.setSigningDate(Calendar.getInstance()); - + // GET Signature DATA String pdfFilter = status.getSignParamter().getPlainSigner() .getPDFFilter(); String pdfSubFilter = status.getSignParamter().getPlainSigner() .getPDFSubFilter(); SignatureDataExtractor signatureDataExtractor = new SignatureDataExtractor( - request.getCertificate(), pdfFilter, pdfSubFilter, status.getSigningDate()); + request.getCertificate(), pdfFilter, pdfSubFilter, + status.getSigningDate()); IPdfSigner signer = PdfSignerFactory.createPdfSigner(); signer.signPDF(status.getPdfObject(), @@ -362,23 +351,25 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { request.setNeedSignature(false); // TODO: Inject signature byte[] into signedDocument int offset = request.getSignatureData().length; - - for(int i = 0; i < request.getSignature().length; i++) { - status.getPdfObject().getSignedDocument()[offset + i] = request.getSignature()[i]; + + for (int i = 0; i < request.getSignature().length; i++) { + status.getPdfObject().getSignedDocument()[offset + i] = request + .getSignature()[i]; } /* - - String pdfFilter = status.getSignParamter().getPlainSigner() - .getPDFFilter(); - String pdfSubFilter = status.getSignParamter().getPlainSigner() - .getPDFSubFilter(); - SignatureDataInjector injector = new SignatureDataInjector( - request.getCertificate(), pdfFilter, pdfSubFilter, status.getSigningDate(), - request.getSignature(), request.getSignatureData()); - - IPdfSigner signer = PdfSignerFactory.createPdfSigner(); - signer.signPDF(status.getPdfObject(), - status.getRequestedSignature(), injector);*/ + * + * String pdfFilter = status.getSignParamter().getPlainSigner() + * .getPDFFilter(); String pdfSubFilter = + * status.getSignParamter().getPlainSigner() .getPDFSubFilter(); + * SignatureDataInjector injector = new SignatureDataInjector( + * request.getCertificate(), pdfFilter, pdfSubFilter, + * status.getSigningDate(), request.getSignature(), + * request.getSignatureData()); + * + * IPdfSigner signer = PdfSignerFactory.createPdfSigner(); + * signer.signPDF(status.getPdfObject(), + * status.getRequestedSignature(), injector); + */ request.setIsReady(true); } else { throw new PdfAsException("Invalid Status"); @@ -399,10 +390,10 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { if (!request.isReady()) { throw new PdfAsException("Invalid Status"); } - + try { return createSignResult(status); - } catch(IOException e) { + } catch (IOException e) { throw new PdfAsException("Invalid Status", e); } } @@ -464,6 +455,16 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { byte[] incrementalUpdate = stamper.writeVisualObject(visualObject, positioningInstruction, status.getPdfObject() .getOriginalDocument()); + + SignaturePositionImpl position = new SignaturePositionImpl(); + position.setX(positioningInstruction.getX()); + position.setY(positioningInstruction.getY()); + position.setPage(positioningInstruction.getPage()); + position.setHeight(visualObject.getHeight()); + position.setWidth(visualObject.getWidth()); + + requestedSignature.setSignaturePosition(position); + status.getPdfObject().setStampedDocument(incrementalUpdate); } else { logger.info("No visual siganture block"); @@ -473,7 +474,8 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { } } - private SignResult createSignResult(OperationStatus status) throws IOException { + private SignResult createSignResult(OperationStatus status) + throws IOException { // ================================================================ // Create SignResult SignResultImpl result = new SignResultImpl(status.getSignParamter() @@ -485,6 +487,13 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { outputStream.close(); + // result.setSignaturePosition(status.getRequestedSignature().); + + result.setSignerCertificate(status.getRequestedSignature() + .getCertificate()); + result.setSignaturePosition(status.getRequestedSignature() + .getSignaturePosition()); + return result; } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java index dcb27be9..28a2a33b 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java @@ -3,11 +3,14 @@ package at.gv.egiz.pdfas.lib.impl; import java.security.cert.X509Certificate; import at.gv.egiz.pdfas.lib.api.DataSink; +import at.gv.egiz.pdfas.lib.api.SignaturePosition; import at.gv.egiz.pdfas.lib.api.sign.SignResult; public class SignResultImpl implements SignResult { protected DataSink dataSink; + protected X509Certificate certificate; + protected SignaturePosition position; public SignResultImpl(DataSink dataSink) { this.dataSink = dataSink; @@ -18,8 +21,19 @@ public class SignResultImpl implements SignResult { } public X509Certificate getSignerCertificate() { - // TODO Auto-generated method stub - return null; + return this.certificate; + } + + public SignaturePosition getSignaturePosition() { + return this.position; + } + + public void setSignerCertificate(X509Certificate certificate) { + this.certificate = certificate; + } + + public void setSignaturePosition(SignaturePosition position) { + this.position = position; } } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignaturePositionImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignaturePositionImpl.java new file mode 100644 index 00000000..7ad8174b --- /dev/null +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignaturePositionImpl.java @@ -0,0 +1,55 @@ +package at.gv.egiz.pdfas.lib.impl; + +import at.gv.egiz.pdfas.lib.api.SignaturePosition; + +public class SignaturePositionImpl implements SignaturePosition { + + protected int page; + protected float x; + protected float y; + protected float width; + protected float height; + + + + public void setPage(int page) { + this.page = page; + } + + public void setX(float x) { + this.x = x; + } + + public void setY(float y) { + this.y = y; + } + + public void setWidth(float width) { + this.width = width; + } + + public void setHeight(float height) { + this.height = height; + } + + public int getPage() { + return page; + } + + public float getX() { + return x; + } + + public float getY() { + return y; + } + + public float getWidth() { + return width; + } + + public float getHeight() { + return height; + } + +} diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/RequestedSignature.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/RequestedSignature.java index a1820104..8bf56259 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/RequestedSignature.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/RequestedSignature.java @@ -3,14 +3,16 @@ package at.gv.egiz.pdfas.lib.impl.status; import iaik.x509.X509Certificate; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; import at.gv.egiz.pdfas.common.exceptions.PdfAsSettingsException; +import at.gv.egiz.pdfas.lib.api.SignaturePosition; import at.knowcenter.wag.egov.egiz.pdf.TablePos; public class RequestedSignature { private String signatureProfile; - private TablePos signaturePosition; + private TablePos tablePosition; private OperationStatus status; private X509Certificate certificate; + private SignaturePosition signaturePosition = null; //private IPlainSigner signer = null; public RequestedSignature(OperationStatus status) throws PdfAsException { @@ -30,9 +32,9 @@ public class RequestedSignature { this.signatureProfile = profileID; if(status.getSignParamter().getSignaturePosition() == null) { - this.signaturePosition = new TablePos(); + this.tablePosition = new TablePos(); } else { - this.signaturePosition = new TablePos(status.getSignParamter().getSignaturePosition()); + this.tablePosition = new TablePos(status.getSignParamter().getSignaturePosition()); } } @@ -41,7 +43,7 @@ public class RequestedSignature { } public TablePos getTablePos() { - return this.signaturePosition; + return this.tablePosition; } public String getSignatureProfileID() { @@ -55,5 +57,15 @@ public class RequestedSignature { public void setCertificate(X509Certificate certificate) { this.certificate = certificate; } + + public SignaturePosition getSignaturePosition() { + return signaturePosition; + } + + public void setSignaturePosition(SignaturePosition signaturePosition) { + this.signaturePosition = signaturePosition; + } + + } |