Skip to content
Permalink
Browse files

Merge branch 'develop'

# Conflicts:
#	RELEASE-NOTES.txt
#	digidoc4j/src/test/java/org/digidoc4j/impl/bdoc/tsl/TslLoaderTest.java
  • Loading branch information...
siimsuu committed Apr 16, 2019
2 parents 1d88f4e + e275dde commit 3f49ef64ac8d51306b5c307e1ce84596c8276d42
Showing with 1,461 additions and 667 deletions.
  1. +0 −2 .travis.yml
  2. +19 −0 RELEASE-NOTES.txt
  3. +14 −3 ddoc4j/pom.xml
  4. +5 −7 digidoc4j/pom.xml
  5. +48 −10 digidoc4j/src/main/java/org/digidoc4j/ContainerBuilder.java
  6. +51 −41 digidoc4j/src/main/java/org/digidoc4j/ContainerOpener.java
  7. +43 −9 digidoc4j/src/main/java/org/digidoc4j/DetachedXadesSignatureBuilder.java
  8. +16 −0 digidoc4j/src/main/java/org/digidoc4j/SignatureContainerMatcherValidator.java
  9. +8 −0 digidoc4j/src/main/java/org/digidoc4j/exceptions/IllegalSignatureProfileException.java
  10. +66 −24 digidoc4j/src/main/java/org/digidoc4j/impl/asic/AsicContainer.java
  11. +29 −16 digidoc4j/src/main/java/org/digidoc4j/impl/asic/AsicContainerParser.java
  12. +7 −7 digidoc4j/src/main/java/org/digidoc4j/impl/asic/AsicParseResult.java
  13. +44 −26 digidoc4j/src/main/java/org/digidoc4j/impl/asic/AsicSignatureBuilder.java
  14. +18 −0 digidoc4j/src/main/java/org/digidoc4j/impl/asic/AsicSignatureOpener.java
  15. +45 −0 digidoc4j/src/main/java/org/digidoc4j/impl/asic/AsicSignatureParser.java
  16. +1 −5 digidoc4j/src/main/java/org/digidoc4j/impl/asic/SKCommonCertificateVerifier.java
  17. +59 −17 digidoc4j/src/main/java/org/digidoc4j/impl/asic/asice/AsicEContainer.java
  18. +17 −0 digidoc4j/src/main/java/org/digidoc4j/impl/asic/asice/AsicESignatureBuilder.java
  19. +17 −29 digidoc4j/src/main/java/org/digidoc4j/impl/asic/asice/AsicESignatureOpener.java
  20. +17 −16 digidoc4j/src/main/java/org/digidoc4j/impl/asic/asice/bdoc/BDocContainer.java
  21. +16 −27 digidoc4j/src/main/java/org/digidoc4j/impl/asic/asice/bdoc/BDocSignatureOpener.java
  22. +31 −20 digidoc4j/src/main/java/org/digidoc4j/impl/asic/asics/AsicSContainer.java
  23. +0 −98 digidoc4j/src/main/java/org/digidoc4j/impl/asic/tsl/ClonedTslCertificateSource.java
  24. +34 −0 digidoc4j/src/main/java/org/digidoc4j/impl/asic/xades/XadesSignatureWrapper.java
  25. +26 −134 digidoc4j/src/main/java/org/digidoc4j/utils/Helper.java
  26. BIN digidoc4j/src/main/resources/keystore/keystore.jks
  27. +3 −0 digidoc4j/src/main/resources/keystore/keystore_certs/ec.europa.eu.2.crt
  28. +3 −0 digidoc4j/src/main/resources/keystore/keystore_certs/ec.europa.eu.3.crt
  29. +3 −0 digidoc4j/src/main/resources/keystore/keystore_certs/ec.europa.eu.4.crt
  30. +3 −0 digidoc4j/src/main/resources/keystore/keystore_certs/ec.europa.eu.5.crt
  31. +3 −0 digidoc4j/src/main/resources/keystore/keystore_certs/ec.europa.eu.6.crt
  32. +3 −0 digidoc4j/src/main/resources/keystore/keystore_certs/ec.europa.eu.7.crt
  33. +3 −0 digidoc4j/src/main/resources/keystore/keystore_certs/ec.europa.eu.8.crt
  34. +3 −0 digidoc4j/src/main/resources/keystore/keystore_certs/ec.europa.eu.crt
  35. +94 −19 digidoc4j/src/test/java/org/digidoc4j/AbstractTest.java
  36. +126 −39 digidoc4j/src/test/java/org/digidoc4j/ContainerBuilderTest.java
  37. +75 −10 digidoc4j/src/test/java/org/digidoc4j/ContainerOpenerTest.java
  38. +42 −2 digidoc4j/src/test/java/org/digidoc4j/DetachedXadesSignatureBuilderTest.java
  39. +1 −0 digidoc4j/src/test/java/org/digidoc4j/FileWritingOperationsTest.java
  40. +321 −8 digidoc4j/src/test/java/org/digidoc4j/SignatureBuilderTest.java
  41. +61 −23 digidoc4j/src/test/java/org/digidoc4j/impl/bdoc/BDocContainerTest.java
  42. +30 −20 digidoc4j/src/test/java/org/digidoc4j/impl/bdoc/BDocSignatureOpenerTest.java
  43. +7 −7 digidoc4j/src/test/java/org/digidoc4j/impl/bdoc/asic/AsicContainerParserTest.java
  44. +24 −15 digidoc4j/src/test/java/org/digidoc4j/impl/bdoc/manifest/ManifestValidatorTest.java
  45. +6 −5 digidoc4j/src/test/java/org/digidoc4j/impl/bdoc/tsl/TslLoaderTest.java
  46. +11 −4 digidoc4j/src/test/java/org/digidoc4j/main/DigiDoc4JTest.java
  47. +0 −14 digidoc4j/src/test/java/org/digidoc4j/utils/HelperTest.java
  48. +1 −1 digidoc4j/src/test/resources/logback-test.xml
  49. BIN digidoc4j/src/test/resources/testFiles/valid-containers/bdoc-with-b-epes-signature.bdoc
  50. BIN digidoc4j/src/test/resources/testFiles/valid-containers/bdoc-with-tm-and-ts-signature.bdoc
  51. +6 −8 pom.xml
  52. +1 −1 publish.sh
@@ -1,9 +1,7 @@
dist: xenial
language: java
jdk:
- openjdk7
- openjdk8
- openjdk11
branches:
only:
- develop
@@ -1,5 +1,24 @@
DigiDoc4J Java library release notes
------------------------------------

Release 3.1.1
------------------
Summary of the major changes since 3.1.0
------------------------------------------
* Fix for BDOC/ASIC-E container detection
* Fix for not able to remove signatures from ASIC-E container
* Performance improvement
* New LOTL signer certs added to truststore

Known issues
------------
* While upgrading from version older than 2.1.1 be sure that your integration :
- doesn't use Xalan or XercesImpl dependencies
- uses a patched Java version (JDK7u40+, JDK8 or higher)
Xalan and XercesImpl were used to patch XML vulnerabilities in older java versions. They should be discarded with higher versions because they override default Java XML security.
If it is not possible to remove Xalan, then you can set your system property to override TransformerFactory : System.setProperty("javax.xml.transform.TransformerFactory","com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");


Release 3.1.0
------------------
Summary of the major changes since 3.0.0
@@ -6,7 +6,7 @@
<groupId>org.digidoc4j</groupId>
<artifactId>ddoc4j</artifactId>
<packaging>jar</packaging>
<version>3.1.0</version>
<version>3.1.1</version>

<name>DDoc4J</name>
<description>DDoc4J is Java Library for validating DDOC documents. It's not recommended to use it directly but rather through DigiDoc4J's API.</description>
@@ -15,7 +15,7 @@
<parent>
<artifactId>digidoc4j-parent</artifactId>
<groupId>org.digidoc4j</groupId>
<version>3.1.0</version>
<version>3.1.1</version>
</parent>

<dependencies>
@@ -50,6 +50,17 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<doclint>${javadocOpt}</doclint>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -61,4 +72,4 @@
</plugins>
</build>

</project>
</project>
@@ -7,7 +7,7 @@
<groupId>org.digidoc4j</groupId>
<artifactId>digidoc4j</artifactId>
<packaging>jar</packaging>
<version>3.1.0</version>
<version>3.1.1</version>

<name>DigiDoc4j</name>
<description>DigiDoc4j is a Java library for digitally signing documents and creating digital signature containers
@@ -18,7 +18,7 @@
<parent>
<artifactId>digidoc4j-parent</artifactId>
<groupId>org.digidoc4j</groupId>
<version>3.1.0</version>
<version>3.1.1</version>
</parent>

<properties>
@@ -43,7 +43,7 @@
<dependency>
<artifactId>ddoc4j</artifactId>
<groupId>org.digidoc4j</groupId>
<version>3.1.0</version>
<version>3.1.1</version>
</dependency>

<dependency>
@@ -58,7 +58,7 @@
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>

<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
@@ -634,9 +634,7 @@
<goal>jar</goal>
</goals>
<configuration>
<additionalOptions>
<additionalOption>${javadocOpt}</additionalOption>
</additionalOptions>
<doclint>${javadocOpt}</doclint>
</configuration>
</execution>
</executions>
@@ -10,20 +10,19 @@

package org.digidoc4j;

import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import eu.europa.esig.dss.DigestAlgorithm;
import org.apache.commons.lang3.StringUtils;
import org.digidoc4j.exceptions.DigiDoc4JException;
import org.digidoc4j.exceptions.InvalidDataFileException;
import org.digidoc4j.exceptions.NotSupportedException;
import org.digidoc4j.impl.CustomContainerBuilder;
import org.digidoc4j.impl.asic.AsicContainer;
import org.digidoc4j.impl.asic.AsicParseResult;
import org.digidoc4j.impl.asic.asice.AsicEContainer;
import org.digidoc4j.impl.asic.asice.AsicEContainerBuilder;
import org.digidoc4j.impl.asic.asice.bdoc.BDocContainer;
import org.digidoc4j.impl.asic.asice.bdoc.BDocContainerBuilder;
import org.digidoc4j.impl.asic.asics.AsicSContainer;
import org.digidoc4j.impl.asic.asics.AsicSContainerBuilder;
import org.digidoc4j.impl.ddoc.DDocContainerBuilder;
import org.digidoc4j.impl.pades.PadesContainerBuilder;
@@ -32,7 +31,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import eu.europa.esig.dss.DigestAlgorithm;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Class for creating and opening containers.
@@ -130,9 +134,9 @@ public static ContainerBuilder aContainer(Container.DocumentType type) {
*/
public Container build() {
if (shouldOpenContainerFromFile()) {
return openContainerFromFile();
return overrideContainerIfNeeded(openContainerFromFile());
} else if (shouldOpenContainerFromStream()) {
return openContainerFromStream();
return overrideContainerIfNeeded(openContainerFromStream());
}
Container container = createNewContainer();
addDataFilesToContainer(container);
@@ -373,4 +377,38 @@ private void validateFileName() {
}
}
}

/**
* DD4J-414 - hackish solution for building BDoc container from existing container with no signatures.
* ContainerOpener considers any Asic container without signatures that is not ASiCS, a ASiCE by default.
* In the future ContainerOpener should take container type as an input to force BDoc when needed.
* At the moment did not want to change ContainerOpener API, that will be done with major release with
* more API changes.
*
* TODO: Should be refactored away in task -
*/
private Container overrideContainerIfNeeded(Container container) {
if (container instanceof AsicContainer && container.getSignatures().isEmpty()) {
return overrideContainerIfDifferentType((AsicContainer) container);
} else {
return container;
}
}

private Container overrideContainerIfDifferentType(AsicContainer container) {
if (container instanceof AsicSContainer || containerType.equalsIgnoreCase(container.getType())) {
return container;
} else {
AsicParseResult containerParseResult = container.getContainerParseResult();
Configuration configuration = container.getConfiguration();

if (containerType.equals(Container.DocumentType.BDOC.name())) {
return new BDocContainer(containerParseResult, configuration);
} else if (containerType.equals(Container.DocumentType.ASICE.name())) {
return new AsicEContainer(containerParseResult, configuration);
} else {
return container;
}
}
}
}
@@ -10,23 +10,29 @@

package org.digidoc4j;

import java.io.BufferedInputStream;
import java.io.EOFException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;
import eu.europa.esig.dss.MimeType;
import org.digidoc4j.exceptions.DigiDoc4JException;
import org.digidoc4j.impl.asic.AsicFileContainerParser;
import org.digidoc4j.impl.asic.AsicParseResult;
import org.digidoc4j.impl.asic.AsicStreamContainerParser;
import org.digidoc4j.impl.asic.asice.AsicEContainer;
import org.digidoc4j.impl.asic.asice.bdoc.BDocContainer;
import org.digidoc4j.impl.asic.asics.AsicSContainer;
import org.digidoc4j.impl.asic.xades.XadesSignatureWrapper;
import org.digidoc4j.impl.ddoc.DDocOpener;
import org.digidoc4j.impl.pades.PadesContainer;
import org.digidoc4j.utils.Helper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedInputStream;
import java.io.EOFException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;

/**
* Helper class for opening containers. The proper way of opening containers would be using {@link ContainerBuilder},
* for example using {@link ContainerBuilder#fromExistingFile(String)} and {@link ContainerBuilder#fromStream(InputStream)}.
@@ -52,7 +58,7 @@ public static Container open(String path, Configuration configuration) throws Di
if (Helper.isPdfFile(path)){
return openPadesContainer(path, configuration);
} else if (Helper.isZipFile(new File(path))) {
return openBDocContainer(path, configuration);
return openAsicContainer(path, configuration);
} else {
return new DDocOpener().open(path, configuration);
}
@@ -85,24 +91,7 @@ public static Container open(String path) throws DigiDoc4JException {
* @see ContainerBuilder
*/
public static Container open(InputStream stream, boolean actAsBigFilesSupportEnabled) {
logger.debug("Opening container from stream");
BufferedInputStream bufferedInputStream = new BufferedInputStream(stream);
try {
if (Helper.isZipFile(bufferedInputStream)) {
if (Helper.isAsicSContainer(bufferedInputStream)){
return new AsicSContainer(bufferedInputStream);
} else if (Helper.isAsicEContainer(bufferedInputStream)) {
return new AsicEContainer(bufferedInputStream);
}
return new BDocContainer(bufferedInputStream);
} else {
return new DDocOpener().open(bufferedInputStream);
}
} catch (IOException e) {
throw new DigiDoc4JException(e);
} finally {
IOUtils.closeQuietly(bufferedInputStream);
}
return open(stream, Configuration.getInstance());
}

/**
@@ -115,38 +104,59 @@ public static Container open(InputStream stream, boolean actAsBigFilesSupportEna
*/
public static Container open(InputStream stream, Configuration configuration) {
logger.debug("Opening container from stream");
BufferedInputStream bufferedInputStream = new BufferedInputStream(stream);
try {
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(stream)) {
if (Helper.isZipFile(bufferedInputStream)) {
if (Helper.isAsicSContainer(bufferedInputStream)){
return new AsicSContainer(bufferedInputStream, configuration);
} else if (Helper.isAsicEContainer(bufferedInputStream)) {
return new AsicEContainer(bufferedInputStream, configuration);
AsicParseResult parseResult = new AsicStreamContainerParser(bufferedInputStream, configuration).read();
if (isAsicSContainer(parseResult)){
return new AsicSContainer(parseResult, configuration);
}
if (isBDocContainer(parseResult)) {
return new BDocContainer(parseResult, configuration);
}
return new BDocContainer(bufferedInputStream, configuration);

return new AsicEContainer(parseResult, configuration);
} else {
return new DDocOpener().open(bufferedInputStream, configuration);
}
} catch (IOException e) {
throw new DigiDoc4JException(e);
} finally {
IOUtils.closeQuietly(bufferedInputStream);
}
}

private static Container openBDocContainer(String path, Configuration configuration) {
private static Container openAsicContainer(String path, Configuration configuration) {
configuration.loadConfiguration("digidoc4j.yaml", false);
if (Helper.isAsicSContainer(path)){
return new AsicSContainer(path, configuration);
} else if (Helper.isAsicEContainer(path)) {
return new AsicEContainer(path, configuration);
AsicParseResult parseResult = new AsicFileContainerParser(path, configuration).read();
if (isAsicSContainer(parseResult)){
return new AsicSContainer(parseResult, configuration);
}
if (isBDocContainer(parseResult)) {
return new BDocContainer(parseResult, configuration);
}
return new BDocContainer(path, configuration);

return new AsicEContainer(parseResult, configuration);
}

private static Container openPadesContainer(String path, Configuration configuration) {
configuration.loadConfiguration("digidoc4j.yaml", false);
return new PadesContainer(configuration, path);
}

private static boolean isAsicSContainer(AsicParseResult parseResult) {
return parseResult.getMimeType().equals(MimeType.ASICS.getMimeTypeString());
}

private static boolean isBDocContainer(AsicParseResult parseResult) {
return hasBDocOnlySignature(parseResult.getSignatures());
}

private static boolean hasBDocOnlySignature(List<XadesSignatureWrapper> signatureWrappers) {
for (XadesSignatureWrapper signatureWrapper : signatureWrappers) {
if (SignatureContainerMatcherValidator.isBDocOnlySignature(signatureWrapper.getSignature().getProfile())) {
return true;
}
}

return false;
}

}
Oops, something went wrong.

0 comments on commit 3f49ef6

Please sign in to comment.
You can’t perform that action at this time.