aboutsummaryrefslogtreecommitdiff
path: root/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2016-06-20 12:45:07 +0200
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2016-06-20 12:45:07 +0200
commit53ae98cdfa510650c1e015efd0d11a96ad4dc87a (patch)
tree8e7ab77a9208b541416d14bbdb15e7211ff40c5b /moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api
parentacf1b849ab835bc6797adfb91f8ab4fa88f0aff5 (diff)
downloadmoa-sig-53ae98cdfa510650c1e015efd0d11a96ad4dc87a.tar.gz
moa-sig-53ae98cdfa510650c1e015efd0d11a96ad4dc87a.tar.bz2
moa-sig-53ae98cdfa510650c1e015efd0d11a96ad4dc87a.zip
ASiC Library added
Diffstat (limited to 'moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api')
-rw-r--r--moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiC.java13
-rw-r--r--moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCConstants.java9
-rw-r--r--moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCEntry.java38
-rw-r--r--moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCFactory.java159
-rw-r--r--moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCFormat.java9
-rw-r--r--moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCVerificationResult.java40
-rw-r--r--moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCVerifier.java16
7 files changed, 283 insertions, 1 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
new file mode 100644
index 0000000..e79d2ca
--- /dev/null
+++ b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiC.java
@@ -0,0 +1,13 @@
+package at.gv.egiz.asic.api;
+
+import java.util.List;
+
+public interface ASiC {
+ public ASiCFormat getFormat();
+ public boolean isXAdES();
+ public boolean isCAdES();
+
+ public List<ASiCEntry> getSignaturesEntries();
+ public List<ASiCEntry> getDataEntries();
+ public List<ASiCEntry> getInformationEntries();
+}
diff --git a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCConstants.java b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCConstants.java
new file mode 100644
index 0000000..02baf40
--- /dev/null
+++ b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCConstants.java
@@ -0,0 +1,9 @@
+package at.gv.egiz.asic.api;
+
+/**
+ * Created by afitzek on 6/15/16.
+ */
+public interface ASiCConstants {
+ public static final String FILE_MIME_TYPE = "mimetype";
+ public static final String FILE_META_INF = "META-INF/";
+}
diff --git a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCEntry.java b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCEntry.java
new file mode 100644
index 0000000..7c026cf
--- /dev/null
+++ b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCEntry.java
@@ -0,0 +1,38 @@
+package at.gv.egiz.asic.api;
+
+import java.io.InputStream;
+
+/**
+ * Created by afitzek on 6/15/16.
+ */
+public class ASiCEntry {
+
+ private String entryName;
+ private InputStream contents;
+
+ public ASiCEntry() {
+ }
+
+ public String getEntryName() {
+ return entryName;
+ }
+
+ public void setEntryName(String entryName) {
+ this.entryName = entryName;
+ }
+
+ public InputStream getContents() {
+ return contents;
+ }
+
+ public void setContents(InputStream contents) {
+ this.contents = contents;
+ }
+
+ @Override
+ public String toString() {
+ return "ASiCEntry{" +
+ "entryName='" + entryName + '\'' +
+ '}';
+ }
+}
diff --git a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCFactory.java b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCFactory.java
index e9ad9dc..6b067f7 100644
--- a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCFactory.java
+++ b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCFactory.java
@@ -1,7 +1,164 @@
package at.gv.egiz.asic.api;
+import at.gv.egiz.asic.exceptions.ASiCException;
+import at.gv.egiz.asic.impl.ASiCBaseFormatFactory;
+import at.gv.egiz.asic.impl.ASiCExtendedFormatFactory;
+import at.gv.egiz.asic.impl.ASiCSimpleFormatFactory;
+import at.gv.egiz.asic.impl.ZipCommentReaderStream;
+import at.gv.egovernment.moa.spss.MOAApplicationException;
+import at.gv.egovernment.moa.spss.MOAException;
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
/**
* Created by afitzek on 6/15/16.
*/
-public interface ASiCFactory {
+public class ASiCFactory {
+
+ private static final Logger logger = LoggerFactory.getLogger(ASiCFactory.class);
+
+ private static final String MIMETYPE_FORMAT_E = "application/vnd.etsi.asic-e+zip";
+ private static final String MIMETYPE_FORMAT_S = "application/vnd.etsi.asic-s+zip";
+
+ public static ASiC parseASiC(InputStream is, ASiCFormat format) throws MOAException {
+
+ InputStream newInputStream = is;
+
+
+ // Try to determine the asic format!
+ if (!newInputStream.markSupported()) {
+ ByteArrayOutputStream asicContainer = new ByteArrayOutputStream();
+
+ try {
+ IOUtils.copy(newInputStream, asicContainer);
+ } catch (IOException e) {
+ throw new MOAApplicationException("asic.0003", null);
+ }
+ newInputStream = new ByteArrayInputStream(asicContainer.toByteArray());
+ }
+
+ String mimeTypeFile = null;
+ ZipCommentReaderStream commentReaderStream = new ZipCommentReaderStream(newInputStream);
+ byte[] buffer = new byte[8096];
+ try {
+ while (commentReaderStream.read(buffer) >= 0) {
+ }
+ newInputStream.reset();
+ } catch (IOException e) {
+ throw new MOAApplicationException("asic.0003", null);
+ }
+
+ ZipInputStream zipInputStream = new ZipInputStream(newInputStream);
+
+ try {
+ for (ZipEntry entry = zipInputStream.getNextEntry(); entry != null; entry = zipInputStream.getNextEntry()) {
+ String entryName = entry.getName();
+
+ if("mimetype".equalsIgnoreCase(entryName)) {
+ if(mimeTypeFile == null) {
+ mimeTypeFile = IOUtils.toString(zipInputStream, "UTF-8");
+ } else {
+ logger.warn("multiple mimetype files found in archiv");
+ }
+ }
+ }
+ newInputStream.reset();
+ } catch (IOException e) {
+ throw new MOAApplicationException("asic.0007", null);
+ }
+
+ String fileComment = commentReaderStream.getFileComment();
+ ASiCFormat fileCommentFormat = null;
+ if (fileComment != null) {
+ logger.info("Found file comment in ASiC {}", fileComment);
+ if(fileComment.startsWith("mimetype=")) {
+ String fileCommentMimeType = fileComment.substring("mimetype=".length());
+ if(fileCommentMimeType.startsWith(MIMETYPE_FORMAT_E)) {
+ fileCommentFormat = ASiCFormat.ASiCE;
+ } else if(fileCommentMimeType.startsWith(MIMETYPE_FORMAT_S)) {
+ fileCommentFormat = ASiCFormat.ASiCS;
+ }
+ }
+ } else {
+ logger.info("No file comment in ASiC");
+ }
+
+
+ ASiCFormat mimeTypeFileFormat = null;
+ if (mimeTypeFile != null) {
+ logger.info("Found mimetype file in ASiC {}", mimeTypeFile);
+ if(MIMETYPE_FORMAT_E.equalsIgnoreCase(mimeTypeFile)) {
+ mimeTypeFileFormat = ASiCFormat.ASiCE;
+ } else if(MIMETYPE_FORMAT_S.equalsIgnoreCase(mimeTypeFile)) {
+ mimeTypeFileFormat = ASiCFormat.ASiCS;
+ }
+ } else {
+ logger.info("No mimetype file in ASiC");
+ }
+
+ if (format == null) {
+ if (fileCommentFormat != null && mimeTypeFileFormat != null) {
+ // both are set
+ if (fileCommentFormat == mimeTypeFileFormat) {
+ format = fileCommentFormat;
+ } else {
+ throw new MOAApplicationException("asic.0009", null);
+ }
+ } else if (fileCommentFormat != null) {
+ format = fileCommentFormat;
+ } else if (mimeTypeFileFormat != null) {
+ format = mimeTypeFileFormat;
+ } else {
+ throw new MOAApplicationException("asic.0008", null);
+ }
+ } else {
+ // format is provided, only check for missmatches
+ if (fileCommentFormat != null && fileCommentFormat != format) {
+ logger.warn("ASiC format missmatch file comment {} vs provided {}", fileCommentFormat, format);
+ throw new MOAApplicationException("asic.0009", null);
+ }
+ if (mimeTypeFileFormat != null && mimeTypeFileFormat != format) {
+ logger.warn("ASiC format missmatch mimetype file {} vs provided {}", mimeTypeFileFormat, format);
+ throw new MOAApplicationException("asic.0009", null);
+ }
+
+ if (fileCommentFormat != null && mimeTypeFileFormat != null) {
+ // both are set
+ if (fileCommentFormat != mimeTypeFileFormat) {
+ logger.warn("ASiC format missmatch file comment {} vs mimetype file {}", fileCommentFormat, mimeTypeFileFormat);
+ throw new MOAApplicationException("asic.0009", null);
+ }
+ }
+ }
+
+ ASiCBaseFormatFactory formatFactory = null;
+
+ if (format == null) {
+ throw new MOAApplicationException("asic.0008", null);
+ }
+
+ switch (format) {
+ case ASiCE:
+ formatFactory = new ASiCExtendedFormatFactory();
+ break;
+ case ASiCS:
+ formatFactory = new ASiCSimpleFormatFactory();
+ break;
+ }
+
+ if (formatFactory == null) {
+ throw new MOAApplicationException("asic.0008", null);
+ }
+
+ return formatFactory.createASiC(newInputStream);
+ }
+
}
diff --git a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCFormat.java b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCFormat.java
new file mode 100644
index 0000000..8106944
--- /dev/null
+++ b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCFormat.java
@@ -0,0 +1,9 @@
+package at.gv.egiz.asic.api;
+
+/**
+ * Created by Andreas Fitzek on 6/15/16.
+ */
+public enum ASiCFormat {
+ ASiCS,
+ ASiCE
+}
diff --git a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCVerificationResult.java b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCVerificationResult.java
new file mode 100644
index 0000000..a350f18
--- /dev/null
+++ b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCVerificationResult.java
@@ -0,0 +1,40 @@
+package at.gv.egiz.asic.api;
+
+import at.gv.egovernment.moa.spss.api.cmsverify.VerifyCMSSignatureResponse;
+import at.gv.egovernment.moa.spss.api.xmlverify.VerifyXMLSignatureResponse;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by Andreas Fitzek on 6/16/16.
+ */
+public class ASiCVerificationResult {
+
+ private List<String> signedFiles = new ArrayList<String>();
+
+ private VerifyCMSSignatureResponse cmsResult = null;
+ private VerifyXMLSignatureResponse xmlResult = null;
+
+ public ASiCVerificationResult(List<String> references, VerifyCMSSignatureResponse cmsResult) {
+ this.signedFiles = references;
+ this.cmsResult = cmsResult;
+ }
+
+ public ASiCVerificationResult(List<String> references, VerifyXMLSignatureResponse xmlResult) {
+ this.signedFiles = references;
+ this.xmlResult = xmlResult;
+ }
+
+ public List<String> getSignedFiles() {
+ return signedFiles;
+ }
+
+ public VerifyXMLSignatureResponse getXmlResult() {
+ return xmlResult;
+ }
+
+ public VerifyCMSSignatureResponse getCmsResult() {
+ return cmsResult;
+ }
+}
diff --git a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCVerifier.java b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCVerifier.java
new file mode 100644
index 0000000..77bc61d
--- /dev/null
+++ b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCVerifier.java
@@ -0,0 +1,16 @@
+package at.gv.egiz.asic.api;
+
+import at.gv.egovernment.moa.spss.MOAException;
+import at.gv.egovernment.moa.spss.api.cmsverify.VerifyCMSSignatureResponse;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Created by Andreas Fitzek on 6/15/16.
+ */
+public interface ASiCVerifier {
+
+ public List<ASiCVerificationResult> verify(ASiC asic, String trustProfileID, Date date) throws MOAException;
+
+}