aboutsummaryrefslogtreecommitdiff
path: root/moaSig/moa-asic/src/main/java/at/gv
diff options
context:
space:
mode:
authorThomas Lenz <thomas.lenz@egiz.gv.at>2017-12-19 07:08:36 +0100
committerThomas Lenz <thomas.lenz@egiz.gv.at>2017-12-19 07:08:36 +0100
commita6570f5174563472cace5f3619779c8a18c407f3 (patch)
tree3a35ed36f6a8bf3f05279dcdc42c9650cc401abc /moaSig/moa-asic/src/main/java/at/gv
parent95ce1a4f7e2b0be1d359e815fe7e631609c44844 (diff)
downloadmoa-sig-a6570f5174563472cace5f3619779c8a18c407f3.tar.gz
moa-sig-a6570f5174563472cace5f3619779c8a18c407f3.tar.bz2
moa-sig-a6570f5174563472cace5f3619779c8a18c407f3.zip
fix bug in ASiC implementation if zip contains same filename twince
Diffstat (limited to 'moaSig/moa-asic/src/main/java/at/gv')
-rw-r--r--moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiC.java3
-rw-r--r--moaSig/moa-asic/src/main/java/at/gv/egiz/asic/exceptions/ASiCContainerInvalidException.java7
-rw-r--r--moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/ASiCBaseFormatFactory.java19
-rw-r--r--moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/ASiCContainer.java3
-rw-r--r--moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/ASiCImpl.java9
-rw-r--r--moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/handler/AllDataHandler.java5
-rw-r--r--moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/verifier/SimpleCAdESVerifier.java3
7 files changed, 36 insertions, 13 deletions
diff --git a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiC.java b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiC.java
index e79d2ca..759e910 100644
--- a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiC.java
+++ b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiC.java
@@ -1,5 +1,6 @@
package at.gv.egiz.asic.api;
+import java.util.Collection;
import java.util.List;
public interface ASiC {
@@ -8,6 +9,6 @@ public interface ASiC {
public boolean isCAdES();
public List<ASiCEntry> getSignaturesEntries();
- public List<ASiCEntry> getDataEntries();
+ public Collection<ASiCEntry> getDataEntries();
public List<ASiCEntry> getInformationEntries();
}
diff --git a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/exceptions/ASiCContainerInvalidException.java b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/exceptions/ASiCContainerInvalidException.java
new file mode 100644
index 0000000..ea6d19c
--- /dev/null
+++ b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/exceptions/ASiCContainerInvalidException.java
@@ -0,0 +1,7 @@
+package at.gv.egiz.asic.exceptions;
+
+public class ASiCContainerInvalidException extends ASiCException {
+ public ASiCContainerInvalidException(String reason) {
+ super();
+ }
+}
diff --git a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/ASiCBaseFormatFactory.java b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/ASiCBaseFormatFactory.java
index bce179d..578371c 100644
--- a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/ASiCBaseFormatFactory.java
+++ b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/ASiCBaseFormatFactory.java
@@ -6,14 +6,18 @@ import at.gv.egiz.asic.api.ASiCFormat;
import at.gv.egiz.asic.impl.handler.*;
import at.gv.egovernment.moa.spss.MOAApplicationException;
import at.gv.egovernment.moa.spss.MOAException;
+import iaik.util.logging.Log;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -31,14 +35,21 @@ public abstract class ASiCBaseFormatFactory implements ASiCContainer {
protected String mimeType = null;
protected List<ASiCEntry> signatureEntries = new ArrayList<ASiCEntry>();
- protected List<ASiCEntry> dataEntries = new ArrayList<ASiCEntry>();
+ protected Map<String, ASiCEntry> dataEntries = new HashMap<String, ASiCEntry>();
protected List<ASiCEntry> informationEntries = new ArrayList<ASiCEntry>();
protected List<EntryHandler> handlers = new ArrayList<EntryHandler>();
@Override
- public void addDataEntry(ASiCEntry entry) {
- this.dataEntries.add(entry);
+ public void addDataEntry(ASiCEntry entry) throws MOAApplicationException {
+ //check if entry with a specific name already exists
+ if (!dataEntries.containsKey(entry.getEntryName())) {
+ this.dataEntries.put(entry.getEntryName(), entry);
+
+ } else {
+ logger.warn("ASiC container already contains a DataEntry with name: " + entry.getEntryName() + " ASiC container is INVALID");
+ throw new MOAApplicationException("asic.0017", new Object[]{entry.getEntryName()});
+ }
}
@Override
@@ -96,7 +107,7 @@ public abstract class ASiCBaseFormatFactory implements ASiCContainer {
this.validate();
// unpack and retrieve all available information on ASiC signature
- return new ASiCImpl(this.factoryFormat(), this.xadesSigned, this.cadesSigned, this.signatureEntries, dataEntries, this.informationEntries);
+ return new ASiCImpl(this.factoryFormat(), this.xadesSigned, this.cadesSigned, this.signatureEntries, dataEntries.values(), this.informationEntries);
}
@Override
diff --git a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/ASiCContainer.java b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/ASiCContainer.java
index 73d1566..3960a37 100644
--- a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/ASiCContainer.java
+++ b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/ASiCContainer.java
@@ -1,6 +1,7 @@
package at.gv.egiz.asic.impl;
import at.gv.egiz.asic.api.ASiCEntry;
+import at.gv.egovernment.moa.spss.MOAApplicationException;
import at.gv.egovernment.moa.spss.MOAException;
/**
@@ -9,7 +10,7 @@ import at.gv.egovernment.moa.spss.MOAException;
public interface ASiCContainer {
public void setMimeType(String mimeType);
- public void addDataEntry(ASiCEntry entry);
+ public void addDataEntry(ASiCEntry entry) throws MOAApplicationException;
public void addSignatureEntry(ASiCEntry entry);
public void addInformationEntry(ASiCEntry entry);
diff --git a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/ASiCImpl.java b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/ASiCImpl.java
index c78385a..34f6343 100644
--- a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/ASiCImpl.java
+++ b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/ASiCImpl.java
@@ -5,6 +5,7 @@ import at.gv.egiz.asic.api.ASiCEntry;
import at.gv.egiz.asic.api.ASiCFormat;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
/**
@@ -17,15 +18,15 @@ public class ASiCImpl implements ASiC {
private boolean cades;
protected List<ASiCEntry> signatureEntries = new ArrayList<ASiCEntry>();
- protected List<ASiCEntry> dataEntries = new ArrayList<ASiCEntry>();
+ protected Collection<ASiCEntry> dataEntries = new ArrayList<ASiCEntry>();
protected List<ASiCEntry> informationEntries = new ArrayList<ASiCEntry>();
- public ASiCImpl(ASiCFormat format, boolean xades, boolean cades, List<ASiCEntry> signatureEntries, List<ASiCEntry> dataEntries, List<ASiCEntry> informationEntries) {
+ public ASiCImpl(ASiCFormat format, boolean xades, boolean cades, List<ASiCEntry> signatureEntries, Collection<ASiCEntry> collection, List<ASiCEntry> informationEntries) {
this.format = format;
this.xades = xades;
this.cades = cades;
this.signatureEntries = signatureEntries;
- this.dataEntries = dataEntries;
+ this.dataEntries = collection;
this.informationEntries = informationEntries;
}
@@ -50,7 +51,7 @@ public class ASiCImpl implements ASiC {
}
@Override
- public List<ASiCEntry> getDataEntries() {
+ public Collection<ASiCEntry> getDataEntries() {
return dataEntries;
}
diff --git a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/handler/AllDataHandler.java b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/handler/AllDataHandler.java
index fa31bfc..cbf7a35 100644
--- a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/handler/AllDataHandler.java
+++ b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/handler/AllDataHandler.java
@@ -4,6 +4,7 @@ import at.gv.egiz.asic.api.ASiCConstants;
import at.gv.egiz.asic.impl.ASiCContainer;
import at.gv.egiz.asic.api.ASiCEntry;
import at.gv.egiz.asic.impl.EntryHandler;
+import at.gv.egovernment.moa.spss.MOAApplicationException;
import java.io.IOException;
import java.io.InputStream;
@@ -18,9 +19,9 @@ public class AllDataHandler extends BaseHandler implements EntryHandler, ASiCCon
}
@Override
- public boolean handle(String entryName, InputStream is, ASiCContainer container) throws IOException {
+ public boolean handle(String entryName, InputStream is, ASiCContainer container) throws IOException, MOAApplicationException {
- ASiCEntry entry = buildASiCEntry(entryName, is);
+ ASiCEntry entry = buildASiCEntry(entryName, is);
container.addDataEntry(entry);
return true;
diff --git a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/verifier/SimpleCAdESVerifier.java b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/verifier/SimpleCAdESVerifier.java
index b86e290..f10fe2f 100644
--- a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/verifier/SimpleCAdESVerifier.java
+++ b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/impl/verifier/SimpleCAdESVerifier.java
@@ -29,7 +29,8 @@ public class SimpleCAdESVerifier extends CAdESVerifier {
public void verify(ASiC asic, String trustProfileID, Date date, List<ASiCVerificationResult> response) throws MOAException {
ASiCEntry cadesSignature = asic.getSignaturesEntries().get(0);
- ASiCEntry dataEntry = asic.getDataEntries().get(0);
+ //get first element
+ ASiCEntry dataEntry = asic.getDataEntries().iterator().next();
List<String> signedFiles = new ArrayList<String>();
signedFiles.add(dataEntry.getEntryName());