From a6570f5174563472cace5f3619779c8a18c407f3 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Tue, 19 Dec 2017 07:08:36 +0100 Subject: fix bug in ASiC implementation if zip contains same filename twince --- .../src/main/java/at/gv/egiz/asic/api/ASiC.java | 3 ++- .../exceptions/ASiCContainerInvalidException.java | 7 +++++++ .../at/gv/egiz/asic/impl/ASiCBaseFormatFactory.java | 19 +++++++++++++++---- .../main/java/at/gv/egiz/asic/impl/ASiCContainer.java | 3 ++- .../src/main/java/at/gv/egiz/asic/impl/ASiCImpl.java | 9 +++++---- .../at/gv/egiz/asic/impl/handler/AllDataHandler.java | 5 +++-- .../egiz/asic/impl/verifier/SimpleCAdESVerifier.java | 3 ++- .../resources/properties/spss_messages_de.properties | 3 ++- 8 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 moaSig/moa-asic/src/main/java/at/gv/egiz/asic/exceptions/ASiCContainerInvalidException.java (limited to 'moaSig') 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 getSignaturesEntries(); - public List getDataEntries(); + public Collection getDataEntries(); public List 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 signatureEntries = new ArrayList(); - protected List dataEntries = new ArrayList(); + protected Map dataEntries = new HashMap(); protected List informationEntries = new ArrayList(); protected List handlers = new ArrayList(); @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 signatureEntries = new ArrayList(); - protected List dataEntries = new ArrayList(); + protected Collection dataEntries = new ArrayList(); protected List informationEntries = new ArrayList(); - public ASiCImpl(ASiCFormat format, boolean xades, boolean cades, List signatureEntries, List dataEntries, List informationEntries) { + public ASiCImpl(ASiCFormat format, boolean xades, boolean cades, List signatureEntries, Collection collection, List 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 getDataEntries() { + public Collection 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 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 signedFiles = new ArrayList(); signedFiles.add(dataEntry.getEntryName()); diff --git a/moaSig/moa-sig-lib/src/main/resources/resources/properties/spss_messages_de.properties b/moaSig/moa-sig-lib/src/main/resources/resources/properties/spss_messages_de.properties index 76a635a..6971f56 100644 --- a/moaSig/moa-sig-lib/src/main/resources/resources/properties/spss_messages_de.properties +++ b/moaSig/moa-sig-lib/src/main/resources/resources/properties/spss_messages_de.properties @@ -195,4 +195,5 @@ asic.0012=Evidence Record (XML) not supported asic.0013=Timestamp Tokens not supported asic.0014=ASiC-S can only contain one data object file asic.0015=ASiC-S can only contain one signature file -asic.0016=Provided ASiC format is not supported for verification \ No newline at end of file +asic.0016=Provided ASiC format is not supported for verification +asic.0017=ASiC container is corrupt. More then one entry with name {0} \ No newline at end of file -- cgit v1.2.3