diff options
Diffstat (limited to 'pdf-as-legacy/src/main/java/at/gv')
10 files changed, 424 insertions, 57 deletions
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; + } + +} |