From 1eec6002631e0edde23c23e0314932f7f1277017 Mon Sep 17 00:00:00 2001 From: Mirko Date: Sun, 12 Nov 2023 02:28:54 +0100 Subject: [PATCH 01/14] bump guava and guice --- pom.xml | 7 ++++--- .../xades4j/production/DataGenAllDataObjsTimeStamp.java | 2 +- .../java/xades4j/production/DataGenArchiveTimeStamp.java | 2 +- .../java/xades4j/production/DataGenCompleteCertRefs.java | 2 +- .../java/xades4j/production/DataGenCompleteRevocRefs.java | 2 +- .../xades4j/production/DataGenIndivDataObjsTimeStamp.java | 2 +- .../xades4j/production/DataGenSigAndRefsTimeStamp.java | 2 +- src/main/java/xades4j/production/DataGenSigPolicy.java | 2 +- src/main/java/xades4j/production/DataGenSigTimeStamp.java | 2 +- .../java/xades4j/production/DataGenSigningCertificate.java | 2 +- .../production/PropertiesDataObjectsGeneratorImpl.java | 2 +- .../production/PropertyDataGeneratorsMapperImpl.java | 2 +- .../xades4j/production/SignedDataObjectsProcessor.java | 2 +- src/main/java/xades4j/production/SignerBES.java | 2 +- src/main/java/xades4j/production/SignerC.java | 2 +- src/main/java/xades4j/production/SignerEPES.java | 2 +- src/main/java/xades4j/production/SignerT.java | 2 +- .../production/XadesSignatureFormatExtenderImpl.java | 2 +- .../data/PropertiesDataObjectsStructureVerifier.java | 2 +- .../providers/impl/AbstractTimeStampTokenProvider.java | 2 +- .../impl/DefaultTimeStampVerificationProvider.java | 2 +- .../xades4j/providers/impl/HttpTimeStampTokenProvider.java | 2 +- .../xades4j/utils/TimeStampDigestInputFactoryImpl.java | 2 +- .../xades4j/verification/AllDataObjsTimeStampVerifier.java | 2 +- .../xades4j/verification/CompleteCertRefsVerifier.java | 2 +- .../xades4j/verification/CompleteRevocRefsVerifier.java | 2 +- .../xades4j/verification/CounterSignatureVerifier.java | 2 +- .../xades4j/verification/DistinguishedNameComparer.java | 2 +- .../java/xades4j/verification/GenericDOMDataVerifier.java | 2 +- .../verification/IndivDataObjsTimeStampVerifier.java | 2 +- .../verification/QualifyingPropertiesVerifierImpl.java | 2 +- .../QualifyingPropertyVerifiersMapperImpl.java | 2 +- .../java/xades4j/verification/SignaturePolicyVerifier.java | 2 +- .../xades4j/verification/SignatureTimeStampVerifier.java | 2 +- .../xades4j/verification/SigningCertificateVerifier.java | 2 +- src/main/java/xades4j/verification/XadesVerifierImpl.java | 2 +- .../xml/marshalling/DefaultSignedPropertiesMarshaller.java | 2 +- .../marshalling/DefaultUnsignedPropertiesMarshaller.java | 2 +- .../AlgorithmsParametersMarshallingProviderImpl.java | 2 +- src/test/java/xades4j/utils/XadesProfileCoreTest.java | 2 +- src/test/java/xades4j/verification/OtherVerifierTests.java | 2 +- 41 files changed, 44 insertions(+), 43 deletions(-) diff --git a/pom.xml b/pom.xml index 46fcfe30..b8bac75c 100644 --- a/pom.xml +++ b/pom.xml @@ -58,17 +58,18 @@ - + com.google.guava guava - 32.1.2-jre + 32.1.3-jre com.google.inject guice - 6.0.0 + 7.0.0 org.apache.santuario diff --git a/src/main/java/xades4j/production/DataGenAllDataObjsTimeStamp.java b/src/main/java/xades4j/production/DataGenAllDataObjsTimeStamp.java index a2c39116..e6c0a093 100644 --- a/src/main/java/xades4j/production/DataGenAllDataObjsTimeStamp.java +++ b/src/main/java/xades4j/production/DataGenAllDataObjsTimeStamp.java @@ -17,7 +17,7 @@ package xades4j.production; import xades4j.algorithms.Algorithm; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.util.List; import org.apache.xml.security.signature.Reference; import xades4j.properties.AllDataObjsTimeStampProperty; diff --git a/src/main/java/xades4j/production/DataGenArchiveTimeStamp.java b/src/main/java/xades4j/production/DataGenArchiveTimeStamp.java index 870a64b1..1bc8c23a 100644 --- a/src/main/java/xades4j/production/DataGenArchiveTimeStamp.java +++ b/src/main/java/xades4j/production/DataGenArchiveTimeStamp.java @@ -17,7 +17,7 @@ package xades4j.production; import xades4j.algorithms.Algorithm; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/src/main/java/xades4j/production/DataGenCompleteCertRefs.java b/src/main/java/xades4j/production/DataGenCompleteCertRefs.java index 33420de6..ea3e4cb0 100644 --- a/src/main/java/xades4j/production/DataGenCompleteCertRefs.java +++ b/src/main/java/xades4j/production/DataGenCompleteCertRefs.java @@ -16,7 +16,7 @@ */ package xades4j.production; -import javax.inject.Inject; +import jakarta.inject.Inject; import xades4j.properties.CompleteCertificateRefsProperty; import xades4j.properties.data.CompleteCertificateRefsData; import xades4j.properties.data.PropertyDataObject; diff --git a/src/main/java/xades4j/production/DataGenCompleteRevocRefs.java b/src/main/java/xades4j/production/DataGenCompleteRevocRefs.java index 431a4401..32faaef9 100644 --- a/src/main/java/xades4j/production/DataGenCompleteRevocRefs.java +++ b/src/main/java/xades4j/production/DataGenCompleteRevocRefs.java @@ -16,7 +16,7 @@ */ package xades4j.production; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.io.IOException; import java.math.BigInteger; import java.security.MessageDigest; diff --git a/src/main/java/xades4j/production/DataGenIndivDataObjsTimeStamp.java b/src/main/java/xades4j/production/DataGenIndivDataObjsTimeStamp.java index 8cd694af..08205f0f 100644 --- a/src/main/java/xades4j/production/DataGenIndivDataObjsTimeStamp.java +++ b/src/main/java/xades4j/production/DataGenIndivDataObjsTimeStamp.java @@ -18,7 +18,7 @@ import xades4j.algorithms.Algorithm; import xades4j.properties.DataObjectDesc; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.util.ArrayList; import java.util.Collection; import java.util.List; diff --git a/src/main/java/xades4j/production/DataGenSigAndRefsTimeStamp.java b/src/main/java/xades4j/production/DataGenSigAndRefsTimeStamp.java index ad658893..a42f90a0 100644 --- a/src/main/java/xades4j/production/DataGenSigAndRefsTimeStamp.java +++ b/src/main/java/xades4j/production/DataGenSigAndRefsTimeStamp.java @@ -17,7 +17,7 @@ package xades4j.production; import xades4j.algorithms.Algorithm; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.util.HashMap; import java.util.Map; import org.apache.xml.security.utils.Constants; diff --git a/src/main/java/xades4j/production/DataGenSigPolicy.java b/src/main/java/xades4j/production/DataGenSigPolicy.java index cbd7cd24..5b89943b 100644 --- a/src/main/java/xades4j/production/DataGenSigPolicy.java +++ b/src/main/java/xades4j/production/DataGenSigPolicy.java @@ -16,7 +16,7 @@ */ package xades4j.production; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.io.IOException; import java.security.MessageDigest; import xades4j.properties.SignaturePolicyIdentifierProperty; diff --git a/src/main/java/xades4j/production/DataGenSigTimeStamp.java b/src/main/java/xades4j/production/DataGenSigTimeStamp.java index 5bfb6fe3..9c1ba475 100644 --- a/src/main/java/xades4j/production/DataGenSigTimeStamp.java +++ b/src/main/java/xades4j/production/DataGenSigTimeStamp.java @@ -17,7 +17,7 @@ package xades4j.production; import xades4j.algorithms.Algorithm; -import javax.inject.Inject; +import jakarta.inject.Inject; import org.apache.xml.security.utils.Constants; import org.w3c.dom.Element; import xades4j.utils.CannotAddDataToDigestInputException; diff --git a/src/main/java/xades4j/production/DataGenSigningCertificate.java b/src/main/java/xades4j/production/DataGenSigningCertificate.java index 7bc2125a..d468bb27 100644 --- a/src/main/java/xades4j/production/DataGenSigningCertificate.java +++ b/src/main/java/xades4j/production/DataGenSigningCertificate.java @@ -16,7 +16,7 @@ */ package xades4j.production; -import javax.inject.Inject; +import jakarta.inject.Inject; import xades4j.properties.SigningCertificateProperty; import xades4j.properties.data.PropertyDataObject; import xades4j.properties.data.SigningCertificateData; diff --git a/src/main/java/xades4j/production/PropertiesDataObjectsGeneratorImpl.java b/src/main/java/xades4j/production/PropertiesDataObjectsGeneratorImpl.java index a51aa5f0..ce925c8b 100644 --- a/src/main/java/xades4j/production/PropertiesDataObjectsGeneratorImpl.java +++ b/src/main/java/xades4j/production/PropertiesDataObjectsGeneratorImpl.java @@ -18,7 +18,7 @@ import xades4j.properties.UnsignedProperties; import xades4j.properties.SignedProperties; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.util.ArrayList; import java.util.Collection; import xades4j.properties.QualifyingProperty; diff --git a/src/main/java/xades4j/production/PropertyDataGeneratorsMapperImpl.java b/src/main/java/xades4j/production/PropertyDataGeneratorsMapperImpl.java index 0da947e6..fe7efdde 100644 --- a/src/main/java/xades4j/production/PropertyDataGeneratorsMapperImpl.java +++ b/src/main/java/xades4j/production/PropertyDataGeneratorsMapperImpl.java @@ -16,7 +16,7 @@ */ package xades4j.production; -import javax.inject.Inject; +import jakarta.inject.Inject; import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.TypeLiteral; diff --git a/src/main/java/xades4j/production/SignedDataObjectsProcessor.java b/src/main/java/xades4j/production/SignedDataObjectsProcessor.java index 8d6d3ebb..7b43323d 100644 --- a/src/main/java/xades4j/production/SignedDataObjectsProcessor.java +++ b/src/main/java/xades4j/production/SignedDataObjectsProcessor.java @@ -35,7 +35,7 @@ import xades4j.utils.TransformUtils; import xades4j.xml.marshalling.algorithms.AlgorithmsParametersMarshallingProvider; -import javax.inject.Inject; +import jakarta.inject.Inject; /** * Helper class that processes a set of data object descriptions. diff --git a/src/main/java/xades4j/production/SignerBES.java b/src/main/java/xades4j/production/SignerBES.java index b9ddf261..e6669c16 100644 --- a/src/main/java/xades4j/production/SignerBES.java +++ b/src/main/java/xades4j/production/SignerBES.java @@ -18,7 +18,7 @@ import org.apache.xml.security.transforms.Transforms; import xades4j.properties.QualifyingProperties; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.security.PrivateKey; import java.security.cert.X509Certificate; import java.util.ArrayList; diff --git a/src/main/java/xades4j/production/SignerC.java b/src/main/java/xades4j/production/SignerC.java index 68aa3839..bb7dbb4f 100644 --- a/src/main/java/xades4j/production/SignerC.java +++ b/src/main/java/xades4j/production/SignerC.java @@ -16,7 +16,7 @@ */ package xades4j.production; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.security.cert.X509Certificate; import java.util.Collection; import java.util.List; diff --git a/src/main/java/xades4j/production/SignerEPES.java b/src/main/java/xades4j/production/SignerEPES.java index 84da5a0f..1731b0a5 100644 --- a/src/main/java/xades4j/production/SignerEPES.java +++ b/src/main/java/xades4j/production/SignerEPES.java @@ -16,7 +16,7 @@ */ package xades4j.production; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.security.cert.X509Certificate; import java.util.Collection; import java.util.List; diff --git a/src/main/java/xades4j/production/SignerT.java b/src/main/java/xades4j/production/SignerT.java index 9c15086a..44ec4880 100644 --- a/src/main/java/xades4j/production/SignerT.java +++ b/src/main/java/xades4j/production/SignerT.java @@ -16,7 +16,7 @@ */ package xades4j.production; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.security.cert.X509Certificate; import java.util.Collection; import java.util.List; diff --git a/src/main/java/xades4j/production/XadesSignatureFormatExtenderImpl.java b/src/main/java/xades4j/production/XadesSignatureFormatExtenderImpl.java index 10aa79ea..c41392b6 100644 --- a/src/main/java/xades4j/production/XadesSignatureFormatExtenderImpl.java +++ b/src/main/java/xades4j/production/XadesSignatureFormatExtenderImpl.java @@ -17,7 +17,7 @@ package xades4j.production; import xades4j.properties.UnsignedProperties; -import javax.inject.Inject; +import jakarta.inject.Inject; import org.apache.xml.security.signature.XMLSignature; import org.apache.xml.security.utils.Constants; import org.w3c.dom.Element; diff --git a/src/main/java/xades4j/properties/data/PropertiesDataObjectsStructureVerifier.java b/src/main/java/xades4j/properties/data/PropertiesDataObjectsStructureVerifier.java index d1376ede..7c8ef968 100644 --- a/src/main/java/xades4j/properties/data/PropertiesDataObjectsStructureVerifier.java +++ b/src/main/java/xades4j/properties/data/PropertiesDataObjectsStructureVerifier.java @@ -18,7 +18,7 @@ import xades4j.utils.DataGetterImpl; import xades4j.utils.DataGetter; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.util.Collection; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/xades4j/providers/impl/AbstractTimeStampTokenProvider.java b/src/main/java/xades4j/providers/impl/AbstractTimeStampTokenProvider.java index aa2c4e6d..8410aee2 100644 --- a/src/main/java/xades4j/providers/impl/AbstractTimeStampTokenProvider.java +++ b/src/main/java/xades4j/providers/impl/AbstractTimeStampTokenProvider.java @@ -16,7 +16,7 @@ */ package xades4j.providers.impl; -import javax.inject.Inject; +import jakarta.inject.Inject; import org.apache.xml.security.algorithms.MessageDigestAlgorithm; import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.cmp.PKIStatus; diff --git a/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java b/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java index dd40492b..a8eafa42 100644 --- a/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java +++ b/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java @@ -16,7 +16,7 @@ */ package xades4j.providers.impl; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.io.IOException; import java.security.MessageDigest; import java.security.Provider; diff --git a/src/main/java/xades4j/providers/impl/HttpTimeStampTokenProvider.java b/src/main/java/xades4j/providers/impl/HttpTimeStampTokenProvider.java index d8dca8fd..32b56063 100644 --- a/src/main/java/xades4j/providers/impl/HttpTimeStampTokenProvider.java +++ b/src/main/java/xades4j/providers/impl/HttpTimeStampTokenProvider.java @@ -16,7 +16,7 @@ */ package xades4j.providers.impl; -import javax.inject.Inject; +import jakarta.inject.Inject; import xades4j.providers.MessageDigestEngineProvider; import xades4j.providers.TimeStampTokenGenerationException; import xades4j.utils.Base64; diff --git a/src/main/java/xades4j/utils/TimeStampDigestInputFactoryImpl.java b/src/main/java/xades4j/utils/TimeStampDigestInputFactoryImpl.java index 249f1687..3cf456e4 100644 --- a/src/main/java/xades4j/utils/TimeStampDigestInputFactoryImpl.java +++ b/src/main/java/xades4j/utils/TimeStampDigestInputFactoryImpl.java @@ -16,7 +16,7 @@ */ package xades4j.utils; -import javax.inject.Inject; +import jakarta.inject.Inject; import xades4j.algorithms.Algorithm; import xades4j.UnsupportedAlgorithmException; import xades4j.xml.marshalling.algorithms.AlgorithmsParametersMarshallingProvider; diff --git a/src/main/java/xades4j/verification/AllDataObjsTimeStampVerifier.java b/src/main/java/xades4j/verification/AllDataObjsTimeStampVerifier.java index 37773471..937f834b 100644 --- a/src/main/java/xades4j/verification/AllDataObjsTimeStampVerifier.java +++ b/src/main/java/xades4j/verification/AllDataObjsTimeStampVerifier.java @@ -16,7 +16,7 @@ */ package xades4j.verification; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.util.Collection; import xades4j.properties.AllDataObjsTimeStampProperty; import xades4j.utils.CannotAddDataToDigestInputException; diff --git a/src/main/java/xades4j/verification/CompleteCertRefsVerifier.java b/src/main/java/xades4j/verification/CompleteCertRefsVerifier.java index 9404cc0d..c49f1c43 100644 --- a/src/main/java/xades4j/verification/CompleteCertRefsVerifier.java +++ b/src/main/java/xades4j/verification/CompleteCertRefsVerifier.java @@ -16,7 +16,7 @@ */ package xades4j.verification; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.security.cert.X509Certificate; import java.util.Collection; import java.util.Collections; diff --git a/src/main/java/xades4j/verification/CompleteRevocRefsVerifier.java b/src/main/java/xades4j/verification/CompleteRevocRefsVerifier.java index b22d1880..aa673ed7 100644 --- a/src/main/java/xades4j/verification/CompleteRevocRefsVerifier.java +++ b/src/main/java/xades4j/verification/CompleteRevocRefsVerifier.java @@ -16,7 +16,7 @@ */ package xades4j.verification; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.io.IOException; import java.math.BigInteger; import java.security.MessageDigest; diff --git a/src/main/java/xades4j/verification/CounterSignatureVerifier.java b/src/main/java/xades4j/verification/CounterSignatureVerifier.java index f05fff9a..ad9f15ff 100644 --- a/src/main/java/xades4j/verification/CounterSignatureVerifier.java +++ b/src/main/java/xades4j/verification/CounterSignatureVerifier.java @@ -16,7 +16,7 @@ */ package xades4j.verification; -import javax.inject.Inject; +import jakarta.inject.Inject; import org.apache.xml.security.exceptions.XMLSecurityException; import org.apache.xml.security.signature.Reference; import org.apache.xml.security.signature.SignedInfo; diff --git a/src/main/java/xades4j/verification/DistinguishedNameComparer.java b/src/main/java/xades4j/verification/DistinguishedNameComparer.java index 77922aba..6ab83d02 100644 --- a/src/main/java/xades4j/verification/DistinguishedNameComparer.java +++ b/src/main/java/xades4j/verification/DistinguishedNameComparer.java @@ -16,7 +16,7 @@ */ package xades4j.verification; -import javax.inject.Inject; +import jakarta.inject.Inject; import javax.security.auth.x500.X500Principal; import org.bouncycastle.asn1.x500.X500Name; import xades4j.providers.X500NameStyleProvider; diff --git a/src/main/java/xades4j/verification/GenericDOMDataVerifier.java b/src/main/java/xades4j/verification/GenericDOMDataVerifier.java index 8679f35b..d0fd79a7 100644 --- a/src/main/java/xades4j/verification/GenericDOMDataVerifier.java +++ b/src/main/java/xades4j/verification/GenericDOMDataVerifier.java @@ -16,7 +16,7 @@ */ package xades4j.verification; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.util.Map; import javax.xml.namespace.QName; import org.w3c.dom.Element; diff --git a/src/main/java/xades4j/verification/IndivDataObjsTimeStampVerifier.java b/src/main/java/xades4j/verification/IndivDataObjsTimeStampVerifier.java index 9d309b7a..056b7446 100644 --- a/src/main/java/xades4j/verification/IndivDataObjsTimeStampVerifier.java +++ b/src/main/java/xades4j/verification/IndivDataObjsTimeStampVerifier.java @@ -16,7 +16,7 @@ */ package xades4j.verification; -import javax.inject.Inject; +import jakarta.inject.Inject; import xades4j.utils.CannotAddDataToDigestInputException; import xades4j.properties.IndividualDataObjsTimeStampProperty; import xades4j.properties.QualifyingProperty; diff --git a/src/main/java/xades4j/verification/QualifyingPropertiesVerifierImpl.java b/src/main/java/xades4j/verification/QualifyingPropertiesVerifierImpl.java index d894b1ad..be661121 100644 --- a/src/main/java/xades4j/verification/QualifyingPropertiesVerifierImpl.java +++ b/src/main/java/xades4j/verification/QualifyingPropertiesVerifierImpl.java @@ -16,7 +16,7 @@ */ package xades4j.verification; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; diff --git a/src/main/java/xades4j/verification/QualifyingPropertyVerifiersMapperImpl.java b/src/main/java/xades4j/verification/QualifyingPropertyVerifiersMapperImpl.java index 1b5561d4..ae485de8 100644 --- a/src/main/java/xades4j/verification/QualifyingPropertyVerifiersMapperImpl.java +++ b/src/main/java/xades4j/verification/QualifyingPropertyVerifiersMapperImpl.java @@ -17,7 +17,7 @@ package xades4j.verification; import com.google.inject.ConfigurationException; -import javax.inject.Inject; +import jakarta.inject.Inject; import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.ProvisionException; diff --git a/src/main/java/xades4j/verification/SignaturePolicyVerifier.java b/src/main/java/xades4j/verification/SignaturePolicyVerifier.java index a028bf03..3799d0cf 100644 --- a/src/main/java/xades4j/verification/SignaturePolicyVerifier.java +++ b/src/main/java/xades4j/verification/SignaturePolicyVerifier.java @@ -16,7 +16,7 @@ */ package xades4j.verification; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.io.IOException; import java.io.InputStream; import java.security.MessageDigest; diff --git a/src/main/java/xades4j/verification/SignatureTimeStampVerifier.java b/src/main/java/xades4j/verification/SignatureTimeStampVerifier.java index a5d919be..2385bbd9 100644 --- a/src/main/java/xades4j/verification/SignatureTimeStampVerifier.java +++ b/src/main/java/xades4j/verification/SignatureTimeStampVerifier.java @@ -16,7 +16,7 @@ */ package xades4j.verification; -import javax.inject.Inject; +import jakarta.inject.Inject; import org.apache.xml.security.utils.Constants; import org.w3c.dom.Element; import xades4j.utils.CannotAddDataToDigestInputException; diff --git a/src/main/java/xades4j/verification/SigningCertificateVerifier.java b/src/main/java/xades4j/verification/SigningCertificateVerifier.java index 7c97df96..ce741060 100644 --- a/src/main/java/xades4j/verification/SigningCertificateVerifier.java +++ b/src/main/java/xades4j/verification/SigningCertificateVerifier.java @@ -16,7 +16,7 @@ */ package xades4j.verification; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.security.cert.X509Certificate; import java.util.Collection; import java.util.Iterator; diff --git a/src/main/java/xades4j/verification/XadesVerifierImpl.java b/src/main/java/xades4j/verification/XadesVerifierImpl.java index 5fd857a1..7f8f21fb 100644 --- a/src/main/java/xades4j/verification/XadesVerifierImpl.java +++ b/src/main/java/xades4j/verification/XadesVerifierImpl.java @@ -16,7 +16,7 @@ */ package xades4j.verification; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.io.InputStream; import java.security.cert.X509CRL; import java.security.cert.X509Certificate; diff --git a/src/main/java/xades4j/xml/marshalling/DefaultSignedPropertiesMarshaller.java b/src/main/java/xades4j/xml/marshalling/DefaultSignedPropertiesMarshaller.java index 3c88f748..74d68b3e 100644 --- a/src/main/java/xades4j/xml/marshalling/DefaultSignedPropertiesMarshaller.java +++ b/src/main/java/xades4j/xml/marshalling/DefaultSignedPropertiesMarshaller.java @@ -16,7 +16,7 @@ */ package xades4j.xml.marshalling; -import javax.inject.Inject; +import jakarta.inject.Inject; import xades4j.properties.data.SigAndDataObjsPropertiesData; import org.w3c.dom.Node; import xades4j.properties.QualifyingProperty; diff --git a/src/main/java/xades4j/xml/marshalling/DefaultUnsignedPropertiesMarshaller.java b/src/main/java/xades4j/xml/marshalling/DefaultUnsignedPropertiesMarshaller.java index 8317b5fd..5059a25f 100644 --- a/src/main/java/xades4j/xml/marshalling/DefaultUnsignedPropertiesMarshaller.java +++ b/src/main/java/xades4j/xml/marshalling/DefaultUnsignedPropertiesMarshaller.java @@ -16,7 +16,7 @@ */ package xades4j.xml.marshalling; -import javax.inject.Inject; +import jakarta.inject.Inject; import xades4j.properties.data.SigAndDataObjsPropertiesData; import org.w3c.dom.Node; import xades4j.properties.QualifyingProperty; diff --git a/src/main/java/xades4j/xml/marshalling/algorithms/AlgorithmsParametersMarshallingProviderImpl.java b/src/main/java/xades4j/xml/marshalling/algorithms/AlgorithmsParametersMarshallingProviderImpl.java index f4e9a938..12766449 100644 --- a/src/main/java/xades4j/xml/marshalling/algorithms/AlgorithmsParametersMarshallingProviderImpl.java +++ b/src/main/java/xades4j/xml/marshalling/algorithms/AlgorithmsParametersMarshallingProviderImpl.java @@ -16,7 +16,7 @@ */ package xades4j.xml.marshalling.algorithms; -import javax.inject.Inject; +import jakarta.inject.Inject; import org.w3c.dom.Document; import org.w3c.dom.Node; import xades4j.UnsupportedAlgorithmException; diff --git a/src/test/java/xades4j/utils/XadesProfileCoreTest.java b/src/test/java/xades4j/utils/XadesProfileCoreTest.java index 1aaf76c4..2382be43 100644 --- a/src/test/java/xades4j/utils/XadesProfileCoreTest.java +++ b/src/test/java/xades4j/utils/XadesProfileCoreTest.java @@ -20,7 +20,7 @@ import com.google.inject.Module; import org.junit.jupiter.api.Test; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.util.Map; import java.util.Set; diff --git a/src/test/java/xades4j/verification/OtherVerifierTests.java b/src/test/java/xades4j/verification/OtherVerifierTests.java index 539d6de1..900a868a 100644 --- a/src/test/java/xades4j/verification/OtherVerifierTests.java +++ b/src/test/java/xades4j/verification/OtherVerifierTests.java @@ -22,7 +22,7 @@ import xades4j.properties.data.SigningTimeData; import xades4j.utils.BuiltIn; -import javax.inject.Inject; +import jakarta.inject.Inject; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; From 01cc710734647a8b781745cce1b36a47febb2e95 Mon Sep 17 00:00:00 2001 From: Mirko Date: Sun, 12 Nov 2023 02:38:49 +0100 Subject: [PATCH 02/14] bump xmlsec --- pom.xml | 2 +- src/main/java/xades4j/utils/ResolverAnonymous.java | 3 ++- .../xades4j/utils/TimeStampDigestInputImpl.java | 13 +++++-------- .../java/xades4j/production/OtherSignerTests.java | 8 +++----- .../production/SignedDataObjectsProcessorTest.java | 9 +++------ 5 files changed, 14 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index b8bac75c..66a3c467 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,7 @@ org.apache.santuario xmlsec - 3.0.3 + 4.0.0 org.bouncycastle diff --git a/src/main/java/xades4j/utils/ResolverAnonymous.java b/src/main/java/xades4j/utils/ResolverAnonymous.java index 11cfa8f2..b38d0c73 100644 --- a/src/main/java/xades4j/utils/ResolverAnonymous.java +++ b/src/main/java/xades4j/utils/ResolverAnonymous.java @@ -18,6 +18,7 @@ import java.io.InputStream; import org.apache.xml.security.signature.XMLSignatureInput; +import org.apache.xml.security.signature.XMLSignatureStreamInput; import org.apache.xml.security.utils.resolver.ResourceResolverContext; import org.apache.xml.security.utils.resolver.ResourceResolverException; import org.apache.xml.security.utils.resolver.ResourceResolverSpi; @@ -40,7 +41,7 @@ public ResolverAnonymous(InputStream data) @Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { - return new XMLSignatureInput(this.data); + return new XMLSignatureStreamInput(this.data); } @Override diff --git a/src/main/java/xades4j/utils/TimeStampDigestInputImpl.java b/src/main/java/xades4j/utils/TimeStampDigestInputImpl.java index fc35eedb..ed3d8a7c 100644 --- a/src/main/java/xades4j/utils/TimeStampDigestInputImpl.java +++ b/src/main/java/xades4j/utils/TimeStampDigestInputImpl.java @@ -20,6 +20,7 @@ import org.apache.xml.security.signature.Reference; import org.apache.xml.security.signature.XMLSignatureException; import org.apache.xml.security.signature.XMLSignatureInput; +import org.apache.xml.security.signature.XMLSignatureNodeInput; import org.apache.xml.security.transforms.Transform; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -76,7 +77,7 @@ public void addNode(Node n) throws CannotAddDataToDigestInputException throw new NullPointerException(); } - addToDigestInput(new XMLSignatureInput(n), n.getOwnerDocument()); + addToDigestInput(new XMLSignatureNodeInput(n), n.getOwnerDocument()); } private void addToDigestInput(XMLSignatureInput refData, Document doc) throws CannotAddDataToDigestInputException @@ -90,13 +91,9 @@ private void addToDigestInput(XMLSignatureInput refData, Document doc) throws Ca // Fall through to add the bytes resulting from the canonicalization. } - if (refData.isByteArray()) - { - digestInput.write(refData.getBytes()); - } else if (refData.isOctetStream()) - { - StreamUtils.readWrite(refData.getOctetStream(), digestInput); - } + digestInput.write(refData.getBytes()); + digestInput.close(); + } catch (Exception ex) { diff --git a/src/test/java/xades4j/production/OtherSignerTests.java b/src/test/java/xades4j/production/OtherSignerTests.java index 8adccd23..94141e03 100644 --- a/src/test/java/xades4j/production/OtherSignerTests.java +++ b/src/test/java/xades4j/production/OtherSignerTests.java @@ -16,15 +16,12 @@ */ package xades4j.production; -import org.apache.xml.security.c14n.Canonicalizer; import org.apache.xml.security.signature.XMLSignatureInput; -import org.apache.xml.security.utils.Constants; -import org.apache.xml.security.utils.DOMNamespaceContext; +import org.apache.xml.security.signature.XMLSignatureStreamInput; import org.apache.xml.security.utils.resolver.ResourceResolverContext; import org.apache.xml.security.utils.resolver.ResourceResolverException; import org.apache.xml.security.utils.resolver.ResourceResolverSpi; import org.w3c.dom.Attr; -import org.w3c.dom.Node; import xades4j.algorithms.EnvelopedSignatureTransform; import xades4j.algorithms.ExclusiveCanonicalXMLWithoutComments; import xades4j.properties.DataObjectDesc; @@ -41,6 +38,7 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathFactory; +import java.io.ByteArrayInputStream; import java.util.Iterator; import static org.apache.xml.security.algorithms.MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA256; @@ -112,7 +110,7 @@ static class MyResolverSpi extends ResourceResolverSpi @Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { - XMLSignatureInput input = new XMLSignatureInput(context.attr.getValue().getBytes()); + XMLSignatureInput input = new XMLSignatureStreamInput(new ByteArrayInputStream(context.attr.getValue().getBytes())); resolveCount++; return input; } diff --git a/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java b/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java index dc29ff1f..08ea9f52 100644 --- a/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java +++ b/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java @@ -16,8 +16,7 @@ */ package xades4j.production; -import org.apache.xml.security.signature.Manifest; -import org.apache.xml.security.signature.XMLSignatureInput; +import org.apache.xml.security.signature.*; import org.apache.xml.security.utils.resolver.ResourceResolverContext; import org.apache.xml.security.utils.resolver.ResourceResolverException; import org.apache.xml.security.utils.resolver.ResourceResolverSpi; @@ -25,11 +24,9 @@ import xades4j.algorithms.EnvelopedSignatureTransform; import org.apache.xml.security.utils.Constants; +import java.io.ByteArrayInputStream; import java.util.Map; -import org.apache.xml.security.signature.ObjectContainer; -import org.apache.xml.security.signature.Reference; -import org.apache.xml.security.signature.XMLSignature; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.w3c.dom.Document; @@ -119,7 +116,7 @@ public void testAddManifest() throws Exception @Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) { - return new XMLSignatureInput(context.uriToResolve.getBytes()); + return new XMLSignatureStreamInput(new ByteArrayInputStream(context.uriToResolve.getBytes())); } @Override From 423b4540c0a3b85bb3140c6bcc64e0b349344944 Mon Sep 17 00:00:00 2001 From: Mirko Date: Sun, 12 Nov 2023 04:22:48 +0100 Subject: [PATCH 03/14] code cleanup --- .../production/DataGenArchiveTimeStamp.java | 2 +- .../production/DataGenCommitmentType.java | 5 +- .../DataGenIndivDataObjsTimeStamp.java | 16 +- .../DataGenSigAndRefsTimeStamp.java | 2 +- .../DefaultProductionBindingsModule.java | 42 +--- src/main/java/xades4j/production/Init.java | 2 +- .../PropertiesDataGenerationContext.java | 15 +- .../SignedDataObjectsProcessor.java | 18 +- src/main/java/xades4j/production/SignerC.java | 12 +- src/main/java/xades4j/production/SignerT.java | 23 +- .../CommitmentTypePropertyBase.java | 4 +- .../properties/SignerRoleProperty.java | 11 +- ...omPropertiesDataObjsStructureVerifier.java | 2 +- ...ropertiesDataObjectsStructureVerifier.java | 23 +- .../DataObjectPropertiesProvider.java | 2 +- .../impl/AbstractTimeStampTokenProvider.java | 2 +- .../DefaultTimeStampVerificationProvider.java | 28 +-- .../FileSystemKeyStoreKeyingDataProvider.java | 18 +- .../impl/HttpTimeStampTokenProvider.java | 24 +-- .../impl/KeyStoreKeyingDataProvider.java | 47 ++-- .../PKCS11KeyStoreKeyingDataProvider.java | 34 +-- .../PKIXCertificateValidationProvider.java | 54 ++--- src/main/java/xades4j/utils/Base64.java | 202 +++++++----------- .../java/xades4j/utils/CollectionUtils.java | 25 +-- .../xades4j/utils/CrlExtensionsUtils.java | 13 +- .../java/xades4j/utils/DataGetterImpl.java | 17 +- .../utils/FileSystemDirectoryCertStore.java | 58 ++--- src/main/java/xades4j/utils/ObjectUtils.java | 18 +- .../java/xades4j/utils/PropertiesSet.java | 20 +- .../java/xades4j/utils/ResolverAnonymous.java | 8 +- src/main/java/xades4j/utils/StringUtils.java | 9 +- .../java/xades4j/utils/XadesProfileCore.java | 117 +++------- .../xades4j/verification/CertRefUtils.java | 16 +- .../CompleteRevocRefsVerifier.java | 26 +-- ...erSignatureXadesVerificationException.java | 6 - .../DefaultVerificationBindingsModule.java | 41 +--- ...QualifyingPropertyVerifiersMapperImpl.java | 17 +- .../verification/SignerRoleVerifier.java | 3 +- .../verification/TimeStampVerifierBase.java | 25 +-- .../verification/XAdESFormChecker.java | 26 +-- .../verification/XAdESVerificationResult.java | 32 +-- .../XadesVerificationProfile.java | 2 +- .../verification/XadesVerifierImpl.java | 87 ++------ .../xml/marshalling/BaseJAXBMarshaller.java | 3 +- .../AlgorithmParametersBindingsModule.java | 12 +- .../XPathTransformParamsMarshaller.java | 9 +- .../FromDOMCounterSignatureConverter.java | 3 +- .../FromXmlCompleteCertRefsConverter.java | 3 +- ...FromXmlDataObjFormatPropertyConverter.java | 3 +- .../FromXmlSignaturePolicyConverter.java | 3 +- .../FromXmlSignatureProdPlaceConverter.java | 3 +- .../FromXmlSigningCertificateConverter.java | 3 +- .../FromXmlSigningTimeConverter.java | 3 +- ...omXmlUnknownUnsignedSigPropsConverter.java | 5 +- .../QualifyingPropertyFromDOMConverter.java | 2 +- .../SignedDataObjectsProcessorTest.java | 13 +- .../production/UncheckedSignerBESTest.java | 17 +- 57 files changed, 373 insertions(+), 863 deletions(-) diff --git a/src/main/java/xades4j/production/DataGenArchiveTimeStamp.java b/src/main/java/xades4j/production/DataGenArchiveTimeStamp.java index 1bc8c23a..4790a3e7 100644 --- a/src/main/java/xades4j/production/DataGenArchiveTimeStamp.java +++ b/src/main/java/xades4j/production/DataGenArchiveTimeStamp.java @@ -61,7 +61,7 @@ public DataGenArchiveTimeStamp( protected void addPropSpecificTimeStampInput( ArchiveTimeStampProperty prop, TimeStampDigestInput digestInput, - PropertiesDataGenerationContext ctx) throws CannotAddDataToDigestInputException, PropertyDataGenerationException + PropertiesDataGenerationContext ctx) throws PropertyDataGenerationException { Element unsignedSigPropsElem = DOMHelper.getFirstDescendant( ctx.getTargetXmlSignature().getElement(), diff --git a/src/main/java/xades4j/production/DataGenCommitmentType.java b/src/main/java/xades4j/production/DataGenCommitmentType.java index fec27807..c9709e5f 100644 --- a/src/main/java/xades4j/production/DataGenCommitmentType.java +++ b/src/main/java/xades4j/production/DataGenCommitmentType.java @@ -16,11 +16,8 @@ */ package xades4j.production; -import xades4j.properties.DataObjectDesc; -import java.util.Collection; -import java.util.Map; -import org.apache.xml.security.signature.Reference; import xades4j.properties.CommitmentTypeProperty; +import xades4j.properties.DataObjectDesc; import xades4j.properties.data.CommitmentTypeData; import xades4j.properties.data.PropertyDataObject; diff --git a/src/main/java/xades4j/production/DataGenIndivDataObjsTimeStamp.java b/src/main/java/xades4j/production/DataGenIndivDataObjsTimeStamp.java index 08205f0f..5f2d79c6 100644 --- a/src/main/java/xades4j/production/DataGenIndivDataObjsTimeStamp.java +++ b/src/main/java/xades4j/production/DataGenIndivDataObjsTimeStamp.java @@ -16,23 +16,23 @@ */ package xades4j.production; -import xades4j.algorithms.Algorithm; -import xades4j.properties.DataObjectDesc; import jakarta.inject.Inject; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; import org.apache.xml.security.signature.Reference; -import xades4j.utils.CannotAddDataToDigestInputException; +import xades4j.algorithms.Algorithm; +import xades4j.properties.DataObjectDesc; import xades4j.properties.IndividualDataObjsTimeStampProperty; import xades4j.properties.data.BaseXAdESTimeStampData; -import xades4j.utils.TimeStampDigestInput; import xades4j.properties.data.IndividualDataObjsTimeStampData; import xades4j.providers.TimeStampTokenProvider; import xades4j.providers.TimeStampTokenProvider.TimeStampTokenRes; +import xades4j.utils.CannotAddDataToDigestInputException; +import xades4j.utils.TimeStampDigestInput; import xades4j.utils.TimeStampDigestInputFactory; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + /** * * @author Luís diff --git a/src/main/java/xades4j/production/DataGenSigAndRefsTimeStamp.java b/src/main/java/xades4j/production/DataGenSigAndRefsTimeStamp.java index a42f90a0..84cd95d6 100644 --- a/src/main/java/xades4j/production/DataGenSigAndRefsTimeStamp.java +++ b/src/main/java/xades4j/production/DataGenSigAndRefsTimeStamp.java @@ -55,7 +55,7 @@ public DataGenSigAndRefsTimeStamp( protected void addPropSpecificTimeStampInput( SigAndRefsTimeStampProperty prop, TimeStampDigestInput digestInput, - PropertiesDataGenerationContext ctx) throws CannotAddDataToDigestInputException, PropertyDataGenerationException + PropertiesDataGenerationContext ctx) throws PropertyDataGenerationException { Element unsignedSigPropsElem = DOMHelper.getFirstDescendant( ctx.getTargetXmlSignature().getElement(), diff --git a/src/main/java/xades4j/production/DefaultProductionBindingsModule.java b/src/main/java/xades4j/production/DefaultProductionBindingsModule.java index 39c2ea49..5dbbf159 100644 --- a/src/main/java/xades4j/production/DefaultProductionBindingsModule.java +++ b/src/main/java/xades4j/production/DefaultProductionBindingsModule.java @@ -19,37 +19,10 @@ import com.google.inject.AbstractModule; import com.google.inject.TypeLiteral; import com.google.inject.multibindings.Multibinder; -import xades4j.properties.AllDataObjsCommitmentTypeProperty; -import xades4j.properties.AllDataObjsTimeStampProperty; -import xades4j.properties.ArchiveTimeStampProperty; -import xades4j.properties.CertificateValuesProperty; -import xades4j.properties.CommitmentTypeProperty; -import xades4j.properties.CompleteCertificateRefsProperty; -import xades4j.properties.CompleteRevocationRefsProperty; -import xades4j.properties.CounterSignatureProperty; -import xades4j.properties.DataObjectDesc; -import xades4j.properties.DataObjectFormatProperty; -import xades4j.properties.IndividualDataObjsTimeStampProperty; -import xades4j.properties.RevocationValuesProperty; -import xades4j.properties.SigAndRefsTimeStampProperty; -import xades4j.properties.SignaturePolicyIdentifierProperty; -import xades4j.properties.SignaturePolicyImpliedProperty; -import xades4j.properties.SignatureProductionPlaceProperty; -import xades4j.properties.SignatureTimeStampProperty; -import xades4j.properties.SignerRoleProperty; -import xades4j.properties.SigningCertificateProperty; -import xades4j.properties.SigningTimeProperty; +import xades4j.properties.*; import xades4j.properties.data.CustomPropertiesDataObjsStructureVerifier; -import xades4j.providers.DataObjectPropertiesProvider; -import xades4j.providers.MessageDigestEngineProvider; -import xades4j.providers.SignaturePropertiesProvider; -import xades4j.providers.TimeStampTokenProvider; -import xades4j.providers.X500NameStyleProvider; -import xades4j.providers.impl.DefaultMessageDigestProvider; -import xades4j.providers.impl.DefaultSignaturePropertiesProvider; -import xades4j.providers.impl.DefaultX500NameStyleProvider; -import xades4j.providers.impl.HttpTimeStampTokenProvider; -import xades4j.providers.impl.HttpTsaConfiguration; +import xades4j.providers.*; +import xades4j.providers.impl.*; /** * Contains the Guice bindings for the default components and the bindings for the @@ -64,13 +37,8 @@ protected void configure() { // Defaults for configurable components. bind(SignaturePropertiesProvider.class).to(DefaultSignaturePropertiesProvider.class); - bind(DataObjectPropertiesProvider.class).toInstance(new DataObjectPropertiesProvider() - { - @Override - public void provideProperties(DataObjectDesc dataObj) - { - // By default no properties are specified for a data object. - } + bind(DataObjectPropertiesProvider.class).toInstance(dataObj -> { + // By default no properties are specified for a data object. }); bind(SignatureAlgorithms.class).toInstance(new SignatureAlgorithms()); bind(BasicSignatureOptions.class).toInstance(new BasicSignatureOptions()); diff --git a/src/main/java/xades4j/production/Init.java b/src/main/java/xades4j/production/Init.java index aef6373d..a528127a 100644 --- a/src/main/java/xades4j/production/Init.java +++ b/src/main/java/xades4j/production/Init.java @@ -39,7 +39,7 @@ static void initXMLSec() ElementProxy.setDefaultPrefix(Constants.SignatureSpecNS, "ds"); ElementProxy.setDefaultPrefix(QualifyingProperty.XADES_XMLNS, "xades"); ElementProxy.setDefaultPrefix(QualifyingProperty.XADESV141_XMLNS, "xades141"); - } catch (XMLSecurityException ex) + } catch (XMLSecurityException ignored) { } } diff --git a/src/main/java/xades4j/production/PropertiesDataGenerationContext.java b/src/main/java/xades4j/production/PropertiesDataGenerationContext.java index 25bd9025..b818e96e 100644 --- a/src/main/java/xades4j/production/PropertiesDataGenerationContext.java +++ b/src/main/java/xades4j/production/PropertiesDataGenerationContext.java @@ -16,14 +16,6 @@ */ package xades4j.production; -import xades4j.properties.DataObjectDesc; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; - import org.apache.xml.security.exceptions.XMLSecurityException; import org.apache.xml.security.signature.Reference; import org.apache.xml.security.signature.SignedInfo; @@ -31,8 +23,11 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import xades4j.XAdES4jXMLSigException; +import xades4j.properties.DataObjectDesc; import xades4j.utils.DOMHelper; +import java.util.*; + /** * Context used during the generation of the properties low-level data (property * data objects). Contains informations about the algorithms in use and the resources @@ -53,7 +48,6 @@ public final class PropertiesDataGenerationContext * will be processed. * * @param targetXmlSignature the target signature - * @param algorithmsProvider algorithms in use */ PropertiesDataGenerationContext(XMLSignature targetXmlSignature) throws XAdES4jXMLSigException { @@ -80,8 +74,7 @@ public final class PropertiesDataGenerationContext /** * @param orderedDataObjs * @param referencesMappings should be unmodifiable - * @param elemInSigDoc - * @param algorithmsProvider + * @param sigDocument */ PropertiesDataGenerationContext( Collection orderedDataObjs, diff --git a/src/main/java/xades4j/production/SignedDataObjectsProcessor.java b/src/main/java/xades4j/production/SignedDataObjectsProcessor.java index 7b43323d..ffcf3a0b 100644 --- a/src/main/java/xades4j/production/SignedDataObjectsProcessor.java +++ b/src/main/java/xades4j/production/SignedDataObjectsProcessor.java @@ -16,26 +16,19 @@ */ package xades4j.production; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.IdentityHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import jakarta.inject.Inject; import org.apache.xml.security.signature.*; import org.apache.xml.security.transforms.Transforms; import org.apache.xml.security.utils.resolver.ResourceResolverSpi; import org.w3c.dom.Document; import xades4j.UnsupportedAlgorithmException; -import xades4j.XAdES4jXMLSigException; import xades4j.algorithms.Algorithm; import xades4j.properties.DataObjectDesc; import xades4j.utils.ResolverAnonymous; import xades4j.utils.TransformUtils; import xades4j.xml.marshalling.algorithms.AlgorithmsParametersMarshallingProvider; -import jakarta.inject.Inject; +import java.util.*; /** * Helper class that processes a set of data object descriptions. @@ -74,12 +67,10 @@ public Result(Map referenceMappings, Set ma * @return result with reference mappings resulting from the data object descriptions and manifests to be digested * @throws UnsupportedAlgorithmException if the reference digest algorithm is not supported * @throws IllegalStateException if the signature already contains {@code Reference}s - * @throws XAdES4jXMLSigException if a Manifest cannot be digested */ SignedDataObjectsProcessor.Result process( SignedDataObjects signedDataObjects, - XMLSignature xmlSignature) throws UnsupportedAlgorithmException, XAdES4jXMLSigException - { + XMLSignature xmlSignature) throws UnsupportedAlgorithmException { if (xmlSignature.getSignedInfo().getLength() != 0) { throw new IllegalStateException("XMLSignature already contains references"); @@ -100,8 +91,7 @@ private SignedDataObjectsProcessor.Result process( String idPrefix, List resourceResolvers, XMLSignature xmlSignature, - boolean hasNullURIReference) throws UnsupportedAlgorithmException, XAdES4jXMLSigException - { + boolean hasNullURIReference) throws UnsupportedAlgorithmException { Map referenceMappings = new IdentityHashMap(dataObjects.size()); Set manifests = new HashSet(); diff --git a/src/main/java/xades4j/production/SignerC.java b/src/main/java/xades4j/production/SignerC.java index bb7dbb4f..33eae584 100644 --- a/src/main/java/xades4j/production/SignerC.java +++ b/src/main/java/xades4j/production/SignerC.java @@ -17,20 +17,20 @@ package xades4j.production; import jakarta.inject.Inject; -import java.security.cert.X509Certificate; -import java.util.Collection; -import java.util.List; - -import com.google.common.base.Optional; +import xades4j.XAdES4jException; import xades4j.properties.SignedSignatureProperty; import xades4j.properties.UnsignedSignatureProperty; -import xades4j.XAdES4jException; import xades4j.providers.*; import xades4j.utils.PropertiesUtils; import xades4j.xml.marshalling.SignedPropertiesMarshaller; import xades4j.xml.marshalling.UnsignedPropertiesMarshaller; import xades4j.xml.marshalling.algorithms.AlgorithmsParametersMarshallingProvider; +import java.security.cert.X509Certificate; +import java.util.Collection; +import java.util.List; +import java.util.Optional; + /** * Produces XAdES-C signatures. * @author Luís diff --git a/src/main/java/xades4j/production/SignerT.java b/src/main/java/xades4j/production/SignerT.java index 44ec4880..6c59e9ec 100644 --- a/src/main/java/xades4j/production/SignerT.java +++ b/src/main/java/xades4j/production/SignerT.java @@ -17,24 +17,20 @@ package xades4j.production; import jakarta.inject.Inject; -import java.security.cert.X509Certificate; -import java.util.Collection; -import java.util.List; - -import com.google.common.base.Optional; +import xades4j.XAdES4jException; import xades4j.properties.SignedSignatureProperty; import xades4j.properties.UnsignedSignatureProperty; -import xades4j.XAdES4jException; -import xades4j.providers.DataObjectPropertiesProvider; -import xades4j.providers.KeyingDataProvider; -import xades4j.providers.SignaturePolicyInfoProvider; -import xades4j.providers.SignaturePropertiesProvider; -import xades4j.providers.X500NameStyleProvider; +import xades4j.providers.*; import xades4j.utils.PropertiesUtils; import xades4j.xml.marshalling.SignedPropertiesMarshaller; import xades4j.xml.marshalling.UnsignedPropertiesMarshaller; import xades4j.xml.marshalling.algorithms.AlgorithmsParametersMarshallingProvider; +import java.security.cert.X509Certificate; +import java.util.Collection; +import java.util.List; +import java.util.Optional; + /** * Produces XAdES-T signatures. Doesn't extend SignerEPES because XAdES-T may be * based on XAdES-BES. If T+EPES is needed, a {@code SignaturePolicyInfoProvider} @@ -74,10 +70,7 @@ protected void getFormatSpecificSignatureProperties( formatSpecificSignedSigProps, formatSpecificUnsignedSigProps, signingCertificateChain); // Check if this is based on XAdES-EPES. - if (this.policyInfoProvider.isPresent()) - { - PropertiesUtils.addXadesEpesProperties(formatSpecificSignedSigProps, this.policyInfoProvider.get()); - } + this.policyInfoProvider.ifPresent(signaturePolicyInfoProvider -> PropertiesUtils.addXadesEpesProperties(formatSpecificSignedSigProps, signaturePolicyInfoProvider)); // Add XAdES-T. PropertiesUtils.addXadesTProperties(formatSpecificUnsignedSigProps); } diff --git a/src/main/java/xades4j/properties/CommitmentTypePropertyBase.java b/src/main/java/xades4j/properties/CommitmentTypePropertyBase.java index 7367c7b8..8423c084 100644 --- a/src/main/java/xades4j/properties/CommitmentTypePropertyBase.java +++ b/src/main/java/xades4j/properties/CommitmentTypePropertyBase.java @@ -16,11 +16,11 @@ */ package xades4j.properties; -import java.util.Collection; -import java.util.List; import org.w3c.dom.Element; import xades4j.utils.CollectionUtils; +import java.util.Collection; + /** * Base class for the {@code CommitmentTypeIndication} property. This is a signed property * that qualifies signed data objects. In consequence, XAdES signatures may contain diff --git a/src/main/java/xades4j/properties/SignerRoleProperty.java b/src/main/java/xades4j/properties/SignerRoleProperty.java index 0be43c72..504cf9ec 100644 --- a/src/main/java/xades4j/properties/SignerRoleProperty.java +++ b/src/main/java/xades4j/properties/SignerRoleProperty.java @@ -16,6 +16,7 @@ */ package xades4j.properties; +import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -42,19 +43,13 @@ public SignerRoleProperty() public SignerRoleProperty(String... claimedRoles) { this(); - for (String role : claimedRoles) - { - this.claimedRoles.add(role); - } + this.claimedRoles.addAll(Arrays.asList(claimedRoles)); } public SignerRoleProperty(Collection claimedRoles) { this(); - for (String role : claimedRoles) - { - this.claimedRoles.add(role); - } + this.claimedRoles.addAll(claimedRoles); } public SignerRoleProperty withClaimedRole(String role) diff --git a/src/main/java/xades4j/properties/data/CustomPropertiesDataObjsStructureVerifier.java b/src/main/java/xades4j/properties/data/CustomPropertiesDataObjsStructureVerifier.java index 95f862b2..b00b6b5c 100644 --- a/src/main/java/xades4j/properties/data/CustomPropertiesDataObjsStructureVerifier.java +++ b/src/main/java/xades4j/properties/data/CustomPropertiesDataObjsStructureVerifier.java @@ -24,5 +24,5 @@ */ public interface CustomPropertiesDataObjsStructureVerifier { - public void verifiy(DataGetter dataObjsGetter) throws PropertyDataStructureException; + public void verifiy(DataGetter dataObjsGetter); } diff --git a/src/main/java/xades4j/properties/data/PropertiesDataObjectsStructureVerifier.java b/src/main/java/xades4j/properties/data/PropertiesDataObjectsStructureVerifier.java index 7c8ef968..77a3154c 100644 --- a/src/main/java/xades4j/properties/data/PropertiesDataObjectsStructureVerifier.java +++ b/src/main/java/xades4j/properties/data/PropertiesDataObjectsStructureVerifier.java @@ -16,21 +16,16 @@ */ package xades4j.properties.data; -import xades4j.utils.DataGetterImpl; -import xades4j.utils.DataGetter; import jakarta.inject.Inject; +import xades4j.properties.*; +import xades4j.utils.DataGetter; +import xades4j.utils.DataGetterImpl; + +import java.lang.reflect.InvocationTargetException; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Set; -import xades4j.properties.AllDataObjsTimeStampProperty; -import xades4j.properties.ArchiveTimeStampProperty; -import xades4j.properties.CertificateValuesProperty; -import xades4j.properties.CompleteCertificateRefsProperty; -import xades4j.properties.RevocationValuesProperty; -import xades4j.properties.SigAndRefsTimeStampProperty; -import xades4j.properties.SignatureTimeStampProperty; -import xades4j.properties.SigningCertificateProperty; /** * @@ -156,14 +151,12 @@ private static PropertyDataObjectStructureVerifier getVerifier( throw new PropertyDataStructureVerifierNotAvailableException(propData.getClass().getSimpleName()); try { - v = verifierAnnot.value().newInstance(); + v = verifierAnnot.value().getDeclaredConstructor().newInstance(); structureVerifiers.put(propData.getClass(), v); return v; - } catch (InstantiationException ex) - { - } catch (IllegalAccessException ex) + } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ignored) { } - throw new PropertyDataStructureException("cannot create data structure verifier", propData.getClass().getSimpleName()); + throw new PropertyDataStructureException("cannot create data structure verifier", propData.getClass().getSimpleName()); } } diff --git a/src/main/java/xades4j/providers/DataObjectPropertiesProvider.java b/src/main/java/xades4j/providers/DataObjectPropertiesProvider.java index cef2bdfe..401620c3 100644 --- a/src/main/java/xades4j/providers/DataObjectPropertiesProvider.java +++ b/src/main/java/xades4j/providers/DataObjectPropertiesProvider.java @@ -32,5 +32,5 @@ public interface DataObjectPropertiesProvider * Asks the provider to add properties to the given data object description. * @param dataObj the target data object description */ - public void provideProperties(DataObjectDesc dataObj); + void provideProperties(DataObjectDesc dataObj); } diff --git a/src/main/java/xades4j/providers/impl/AbstractTimeStampTokenProvider.java b/src/main/java/xades4j/providers/impl/AbstractTimeStampTokenProvider.java index 8410aee2..4db93049 100644 --- a/src/main/java/xades4j/providers/impl/AbstractTimeStampTokenProvider.java +++ b/src/main/java/xades4j/providers/impl/AbstractTimeStampTokenProvider.java @@ -43,7 +43,7 @@ public abstract class AbstractTimeStampTokenProvider implements TimeStampTokenPr private static final Map digestUriToOidMappings; static { - digestUriToOidMappings = new HashMap(6); + digestUriToOidMappings = new HashMap<>(6); digestUriToOidMappings.put(MessageDigestAlgorithm.ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5, TSPAlgorithms.MD5); digestUriToOidMappings.put(MessageDigestAlgorithm.ALGO_ID_DIGEST_RIPEMD160, TSPAlgorithms.RIPEMD160); digestUriToOidMappings.put(MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA1, TSPAlgorithms.SHA1); diff --git a/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java b/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java index a8eafa42..b61825db 100644 --- a/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java +++ b/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java @@ -17,17 +17,6 @@ package xades4j.providers.impl; import jakarta.inject.Inject; -import java.io.IOException; -import java.security.MessageDigest; -import java.security.Provider; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Map; import org.apache.xml.security.algorithms.MessageDigestAlgorithm; import org.bouncycastle.asn1.ASN1InputStream; import org.bouncycastle.asn1.ASN1ObjectIdentifier; @@ -44,15 +33,14 @@ import org.bouncycastle.util.Selector; import xades4j.UnsupportedAlgorithmException; import xades4j.XAdES4jException; -import xades4j.providers.CertificateValidationProvider; -import xades4j.providers.MessageDigestEngineProvider; -import xades4j.providers.TimeStampTokenDigestException; -import xades4j.providers.TimeStampTokenSignatureException; -import xades4j.providers.TimeStampTokenStructureException; -import xades4j.providers.TimeStampTokenTSACertException; -import xades4j.providers.TimeStampTokenVerificationException; -import xades4j.providers.TimeStampVerificationProvider; -import xades4j.providers.ValidationData; +import xades4j.providers.*; + +import java.io.IOException; +import java.security.MessageDigest; +import java.security.Provider; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.*; /** * Default implementation of {@code TimeStampVerificationProvider}. It verifies diff --git a/src/main/java/xades4j/providers/impl/FileSystemKeyStoreKeyingDataProvider.java b/src/main/java/xades4j/providers/impl/FileSystemKeyStoreKeyingDataProvider.java index 80aa85bf..84f1e494 100644 --- a/src/main/java/xades4j/providers/impl/FileSystemKeyStoreKeyingDataProvider.java +++ b/src/main/java/xades4j/providers/impl/FileSystemKeyStoreKeyingDataProvider.java @@ -18,7 +18,6 @@ import java.io.File; import java.security.KeyStore; -import java.security.KeyStore.ProtectionParameter; import java.security.Provider; import java.security.cert.X509Certificate; @@ -50,18 +49,11 @@ public static Builder builder(String keyStoreType, String keyStorePath, SigningC private FileSystemKeyStoreKeyingDataProvider(Builder builder) { - super(new KeyStoreBuilderCreator() - { - @Override - public KeyStore.Builder getBuilder(ProtectionParameter loadProtection) - { - return KeyStore.Builder.newInstance( - builder.keyStoreType, - builder.provider, - new File(builder.keyStorePath), - loadProtection); - } - }, + super(loadProtection -> KeyStore.Builder.newInstance( + builder.keyStoreType, + builder.provider, + new File(builder.keyStorePath), + loadProtection), builder.certificateSelector, builder.storePasswordProvider, builder.entryPasswordProvider, diff --git a/src/main/java/xades4j/providers/impl/HttpTimeStampTokenProvider.java b/src/main/java/xades4j/providers/impl/HttpTimeStampTokenProvider.java index 32b56063..40a1d6f1 100644 --- a/src/main/java/xades4j/providers/impl/HttpTimeStampTokenProvider.java +++ b/src/main/java/xades4j/providers/impl/HttpTimeStampTokenProvider.java @@ -69,21 +69,17 @@ protected byte[] getResponse(byte[] encodedRequest) throws TimeStampTokenGenerat throw new TimeStampTokenGenerationException(String.format("TSA returned HTTP %d %s", connection.getResponseCode(), connection.getResponseMessage())); } - BufferedInputStream input = null; - try { - input = new BufferedInputStream(connection.getInputStream()); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - byte[] buffer = new byte[1024]; - int len; - while ((len = input.read(buffer)) > -1) { - baos.write(buffer, 0, len); - } - baos.flush(); - - return baos.toByteArray(); - } finally { - if (input != null) input.close(); + try (BufferedInputStream input = new BufferedInputStream(connection.getInputStream())) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int len; + while ((len = input.read(buffer)) > -1) { + baos.write(buffer, 0, len); } + baos.flush(); + + return baos.toByteArray(); + } } catch (IOException ex) { throw new TimeStampTokenGenerationException("Error when connecting to the TSA", ex); } finally { diff --git a/src/main/java/xades4j/providers/impl/KeyStoreKeyingDataProvider.java b/src/main/java/xades4j/providers/impl/KeyStoreKeyingDataProvider.java index a29d55f9..1219fdbf 100644 --- a/src/main/java/xades4j/providers/impl/KeyStoreKeyingDataProvider.java +++ b/src/main/java/xades4j/providers/impl/KeyStoreKeyingDataProvider.java @@ -16,29 +16,18 @@ */ package xades4j.providers.impl; -import xades4j.providers.*; +import xades4j.providers.KeyingDataProvider; +import xades4j.providers.SigningCertChainException; +import xades4j.providers.SigningKeyException; +import xades4j.verification.UnexpectedJCAException; -import java.io.IOException; -import java.security.GeneralSecurityException; -import java.security.KeyStore; +import javax.security.auth.callback.PasswordCallback; +import java.security.*; import java.security.KeyStore.Builder; import java.security.KeyStore.ProtectionParameter; -import java.security.KeyStoreException; -import java.security.PrivateKey; -import java.security.UnrecoverableKeyException; import java.security.cert.Certificate; import java.security.cert.X509Certificate; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Enumeration; -import java.util.List; -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.CallbackHandler; -import javax.security.auth.callback.PasswordCallback; -import javax.security.auth.callback.UnsupportedCallbackException; - -import xades4j.verification.UnexpectedJCAException; +import java.util.*; /** * A KeyStore-based implementation of {@code KeyingDataProvider}. The keystore is @@ -191,28 +180,18 @@ private void ensureInitialized() throws UnexpectedJCAException if (storePasswordProvider != null) // Create the load protection with callback. { - storeLoadProtec = new KeyStore.CallbackHandlerProtection(new CallbackHandler() - { - @Override - public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException - { - PasswordCallback c = (PasswordCallback) callbacks[0]; - c.setPassword(storePasswordProvider.getPassword()); - } + storeLoadProtec = new KeyStore.CallbackHandlerProtection(callbacks -> { + PasswordCallback c = (PasswordCallback) callbacks[0]; + c.setPassword(storePasswordProvider.getPassword()); }); } else // If no load password provider is supplied is because it shouldn't - // be needed. Create a dummy protection because the keystore + // be needed. Create dummy protection because the keystore // builder needs it to be non-null. { - storeLoadProtec = new KeyStore.CallbackHandlerProtection(new CallbackHandler() - { - @Override - public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException - { - throw new UnsupportedOperationException("No KeyStorePasswordProvider"); - } + storeLoadProtec = new KeyStore.CallbackHandlerProtection(callbacks -> { + throw new UnsupportedOperationException("No KeyStorePasswordProvider"); }); } this.keyStore = builderCreator.getBuilder(storeLoadProtec).getKeyStore(); diff --git a/src/main/java/xades4j/providers/impl/PKCS11KeyStoreKeyingDataProvider.java b/src/main/java/xades4j/providers/impl/PKCS11KeyStoreKeyingDataProvider.java index 6ff09ece..329db8aa 100644 --- a/src/main/java/xades4j/providers/impl/PKCS11KeyStoreKeyingDataProvider.java +++ b/src/main/java/xades4j/providers/impl/PKCS11KeyStoreKeyingDataProvider.java @@ -18,18 +18,13 @@ import xades4j.utils.FileUtils; +import javax.security.auth.callback.PasswordCallback; import java.io.IOException; import java.security.KeyStore; -import java.security.KeyStore.ProtectionParameter; -import java.security.KeyStoreException; import java.security.Provider; import java.security.ProviderException; import java.security.Security; import java.security.cert.X509Certificate; -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.CallbackHandler; -import javax.security.auth.callback.PasswordCallback; -import javax.security.auth.callback.UnsupportedCallbackException; /** * A specification of {@link KeyStoreKeyingDataProvider} for PKCS#11 keystores. @@ -67,18 +62,13 @@ public static Builder builder(String nativeLibraryPath, SigningCertificateSelect private PKCS11KeyStoreKeyingDataProvider(Builder builder) { - super(new KeyStoreBuilderCreator() - { - @Override - public KeyStore.Builder getBuilder(ProtectionParameter loadProtection) + super(loadProtection -> { + Provider provider = createProvider(serializeConfiguration(builder.providerName, builder.nativeLibraryPath, builder.slotId)); + if (Security.addProvider(provider) == -1) { - Provider provider = createProvider(serializeConfiguration(builder.providerName, builder.nativeLibraryPath, builder.slotId)); - if (Security.addProvider(provider) == -1) - { - throw new ProviderException("PKCS11 provider already installed"); - } - return KeyStore.Builder.newInstance("PKCS11", provider, loadProtection); + throw new ProviderException("PKCS11 provider already installed"); } + return KeyStore.Builder.newInstance("PKCS11", provider, loadProtection); }, builder.certificateSelector, builder.storePasswordProvider, builder.entryPasswordProvider, builder.fullChain); } @@ -123,15 +113,9 @@ protected KeyStore.ProtectionParameter getKeyProtection( return null; } - return new KeyStore.CallbackHandlerProtection(new CallbackHandler() - { - - @Override - public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException - { - PasswordCallback c = (PasswordCallback) callbacks[0]; - c.setPassword(entryPasswordProvider.getPassword(entryAlias, entryCert)); - } + return new KeyStore.CallbackHandlerProtection(callbacks -> { + PasswordCallback c = (PasswordCallback) callbacks[0]; + c.setPassword(entryPasswordProvider.getPassword(entryAlias, entryCert)); }); } diff --git a/src/main/java/xades4j/providers/impl/PKIXCertificateValidationProvider.java b/src/main/java/xades4j/providers/impl/PKIXCertificateValidationProvider.java index f69d4eb6..389221c8 100644 --- a/src/main/java/xades4j/providers/impl/PKIXCertificateValidationProvider.java +++ b/src/main/java/xades4j/providers/impl/PKIXCertificateValidationProvider.java @@ -16,40 +16,14 @@ */ package xades4j.providers.impl; -import java.security.InvalidAlgorithmParameterException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.cert.CertPathBuilder; -import java.security.cert.CertPathBuilderException; -import java.security.cert.CertStore; -import java.security.cert.CertStoreException; -import java.security.cert.CollectionCertStoreParameters; -import java.security.cert.PKIXBuilderParameters; -import java.security.cert.PKIXCertPathBuilderResult; -import java.security.cert.X509CRL; -import java.security.cert.X509CRLSelector; -import java.security.cert.X509CertSelector; -import java.security.cert.X509Certificate; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import javax.security.auth.x500.X500Principal; - -import xades4j.providers.CannotBuildCertificationPathException; -import xades4j.providers.CannotSelectCertificateException; -import xades4j.providers.CertificateValidationException; -import xades4j.providers.CertificateValidationProvider; -import xades4j.providers.ValidationData; +import xades4j.providers.*; import xades4j.verification.UnexpectedJCAException; +import javax.security.auth.x500.X500Principal; +import java.security.*; +import java.security.cert.*; +import java.util.*; + /** * Implementation of {@code CertificateValidationProvider} using a PKIX {@code CertPathBuilder}. *

@@ -128,10 +102,9 @@ public ValidationData validate( builderParams.addCertStore(othersCertStore); } // - The external certificates/CRLs. - for (int i = 0; i < intermCertsAndCrls.length; i++) - { - builderParams.addCertStore(intermCertsAndCrls[i]); - } + for (CertStore intermCertsAndCrl : intermCertsAndCrls) { + builderParams.addCertStore(intermCertsAndCrl); + } builderParams.setRevocationEnabled(revocationEnabled); builderParams.setMaxPathLength(maxPathLength); @@ -204,12 +177,11 @@ private Collection getCRLsForCertPath( try { // Get the CRLs on each CertStore. - for (int i = 0; i < intermCertsAndCrls.length; i++) - { - Collection storeCRLs = intermCertsAndCrls[i].getCRLs(crlSelector); - crls.addAll(Collections.checkedCollection(storeCRLs, X509CRL.class)); + for (CertStore intermCertsAndCrl : intermCertsAndCrls) { + Collection storeCRLs = intermCertsAndCrl.getCRLs(crlSelector); + crls.addAll(Collections.checkedCollection(storeCRLs, X509CRL.class)); - } + } } catch (CertStoreException ex) { diff --git a/src/main/java/xades4j/utils/Base64.java b/src/main/java/xades4j/utils/Base64.java index 2b3b4ac2..22b9598e 100644 --- a/src/main/java/xades4j/utils/Base64.java +++ b/src/main/java/xades4j/utils/Base64.java @@ -1,4 +1,11 @@ package xades4j.utils; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.zip.GZIPOutputStream; + /** *

Encodes and decodes to and from Base64 notation.

*

Homepage: http://iharder.net/base64.

@@ -408,7 +415,7 @@ public class Base64 * in which case one of them will be picked, though there is * no guarantee as to which one will be picked. */ - private final static byte[] getAlphabet( int options ) { + private static byte[] getAlphabet(int options) { if ((options & URL_SAFE) == URL_SAFE) { return _URL_SAFE_ALPHABET; } else if ((options & ORDERED) == ORDERED) { @@ -426,7 +433,7 @@ private final static byte[] getAlphabet( int options ) { * in which case one of them will be picked, though there is * no guarantee as to which one will be picked. */ - private final static byte[] getDecodabet( int options ) { + private static byte[] getDecodabet(int options) { if( (options & URL_SAFE) == URL_SAFE) { return _URL_SAFE_DECODABET; } else if ((options & ORDERED) == ORDERED) { @@ -690,11 +697,11 @@ public static String encodeObject( java.io.Serializable serializableObject, int // Return value according to relevant encoding. try { - return new String( baos.toByteArray(), PREFERRED_ENCODING ); + return baos.toString(PREFERRED_ENCODING); } // end try catch (java.io.UnsupportedEncodingException uue){ // Fall back to some Java default - return new String( baos.toByteArray() ); + return baos.toString(); } // end catch } // end encode @@ -905,32 +912,17 @@ public static byte[] encodeBytesToBytes( byte[] source, int off, int len, int op // Compress? if( (options & GZIP) != 0 ) { - java.io.ByteArrayOutputStream baos = null; - java.util.zip.GZIPOutputStream gzos = null; - Base64.OutputStream b64os = null; - try { + try (ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); + OutputStream b64os = new Base64.OutputStream( baos, ENCODE | options ); + GZIPOutputStream gzos = new java.util.zip.GZIPOutputStream( b64os ); +) { // GZip -> Base64 -> ByteArray - baos = new java.io.ByteArrayOutputStream(); - b64os = new Base64.OutputStream( baos, ENCODE | options ); - gzos = new java.util.zip.GZIPOutputStream( b64os ); gzos.write( source, off, len ); - gzos.close(); - } // end try - catch( java.io.IOException e ) { - // Catch it and then throw it immediately so that - // the finally{} block is called for cleanup. - throw e; - } // end catch - finally { - try{ gzos.close(); } catch( Exception e ){} - try{ b64os.close(); } catch( Exception e ){} - try{ baos.close(); } catch( Exception e ){} - } // end finally - - return baos.toByteArray(); - } // end if: compress + return baos.toByteArray(); + } // end try + } // end if: compress // Else, don't compress. Better not to use streams at all then. else { @@ -1257,38 +1249,28 @@ public static byte[] decode( String s, int options ) throws java.io.IOException // Check to see if it's gzip-compressed // GZIP Magic Two-Byte Number: 0x8b1f (35615) boolean dontGunzip = (options & DONT_GUNZIP) != 0; - if( (bytes != null) && (bytes.length >= 4) && (!dontGunzip) ) { + if(bytes.length >= 4 && !dontGunzip) { - int head = ((int)bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); + int head = (bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); if( java.util.zip.GZIPInputStream.GZIP_MAGIC == head ) { - java.io.ByteArrayInputStream bais = null; - java.util.zip.GZIPInputStream gzis = null; - java.io.ByteArrayOutputStream baos = null; - byte[] buffer = new byte[2048]; + byte[] buffer = new byte[2048]; int length = 0; - try { - baos = new java.io.ByteArrayOutputStream(); - bais = new java.io.ByteArrayInputStream( bytes ); - gzis = new java.util.zip.GZIPInputStream( bais ); - - while( ( length = gzis.read( buffer ) ) >= 0 ) { - baos.write(buffer,0,length); - } // end while: reading input - - // No error? Get new bytes. - bytes = baos.toByteArray(); - - } // end try - catch( java.io.IOException e ) { - e.printStackTrace(); - // Just return originally-decoded bytes - } // end catch - finally { - try{ baos.close(); } catch( Exception e ){} - try{ gzis.close(); } catch( Exception e ){} - try{ bais.close(); } catch( Exception e ){} - } // end finally + try (java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + java.util.zip.GZIPInputStream gzis = new java.util.zip.GZIPInputStream(bais)) { + + while ((length = gzis.read(buffer)) >= 0) { + baos.write(buffer, 0, length); + } // end while: reading input + + // No error? Get new bytes. + bytes = baos.toByteArray(); + + } catch (IOException e) { + e.printStackTrace(); + // Just return originally-decoded bytes + } } // end if: gzipped } // end if: bytes.length >= 2 @@ -1339,13 +1321,10 @@ public static Object decodeToObject( // Decode and gunzip if necessary byte[] objBytes = decode( encodedObject, options ); - java.io.ByteArrayInputStream bais = null; java.io.ObjectInputStream ois = null; Object obj = null; - try { - bais = new java.io.ByteArrayInputStream( objBytes ); - + try (final ByteArrayInputStream bais = new ByteArrayInputStream( objBytes )){ // If no custom class loader is provided, use Java's builtin OIS. if( loader == null ){ ois = new java.io.ObjectInputStream( bais ); @@ -1358,7 +1337,7 @@ public static Object decodeToObject( @Override public Class resolveClass(java.io.ObjectStreamClass streamClass) throws java.io.IOException, ClassNotFoundException { - Class c = Class.forName(streamClass.getName(), false, loader); + Class c = Class.forName(streamClass.getName(), false, loader); if( c == null ){ return super.resolveClass(streamClass); } else { @@ -1370,15 +1349,11 @@ public Class resolveClass(java.io.ObjectStreamClass streamClass) obj = ois.readObject(); } // end try - catch( java.io.IOException e ) { - throw e; // Catch and throw in order to execute finally{} - } // end catch - catch( java.lang.ClassNotFoundException e ) { - throw e; // Catch and throw in order to execute finally{} - } // end catch finally { - try{ bais.close(); } catch( Exception e ){} - try{ ois.close(); } catch( Exception e ){} + try{ + assert ois != null; + ois.close(); + } catch(Exception ignored){} } // end finally return obj; @@ -1406,20 +1381,12 @@ public static void encodeToFile( byte[] dataToEncode, String filename ) if( dataToEncode == null ){ throw new NullPointerException( "Data to encode was null." ); } // end iff - - Base64.OutputStream bos = null; - try { - bos = new Base64.OutputStream( - new java.io.FileOutputStream( filename ), Base64.ENCODE ); - bos.write( dataToEncode ); - } // end try - catch( java.io.IOException e ) { - throw e; // Catch and throw to execute finally{} block - } // end catch: java.io.IOException - finally { - try{ bos.close(); } catch( Exception e ){} - } // end finally - + + try (OutputStream bos = new OutputStream( + new java.io.FileOutputStream(filename), Base64.ENCODE)) { + bos.write(dataToEncode); + } + } // end encodeToFile @@ -1438,20 +1405,12 @@ public static void encodeToFile( byte[] dataToEncode, String filename ) */ public static void decodeToFile( String dataToDecode, String filename ) throws java.io.IOException { - - Base64.OutputStream bos = null; - try{ - bos = new Base64.OutputStream( - new java.io.FileOutputStream( filename ), Base64.DECODE ); - bos.write( dataToDecode.getBytes( PREFERRED_ENCODING ) ); - } // end try - catch( java.io.IOException e ) { - throw e; // Catch and throw to execute finally{} block - } // end catch: java.io.IOException - finally { - try{ bos.close(); } catch( Exception e ){} - } // end finally - + + try (OutputStream bos = new OutputStream( + new java.io.FileOutputStream(filename), Base64.DECODE)) { + bos.write(dataToDecode.getBytes(StandardCharsets.US_ASCII)); + } + } // end decodeToFile @@ -1506,11 +1465,11 @@ public static byte[] decodeFromFile( String filename ) System.arraycopy( buffer, 0, decodedData, 0, length ); } // end try - catch( java.io.IOException e ) { - throw e; // Catch and release to execute finally{} - } // end catch: java.io.IOException finally { - try{ bis.close(); } catch( Exception e) {} + try{ + assert bis != null; + bis.close(); + } catch(Exception ignored) {} } // end finally return decodedData; @@ -1556,14 +1515,15 @@ public static String encodeFromFile( String filename ) } // end while // Save in a variable to return - encodedData = new String( buffer, 0, length, Base64.PREFERRED_ENCODING ); + encodedData = new String( buffer, 0, length, StandardCharsets.US_ASCII ); } // end try - catch( java.io.IOException e ) { - throw e; // Catch and release to execute finally{} - } // end catch: java.io.IOException + // end catch: java.io.IOException finally { - try{ bis.close(); } catch( Exception e) {} + try{ + assert bis != null; + bis.close(); + } catch(Exception ignored) {} } // end finally return encodedData; @@ -1581,19 +1541,10 @@ public static void encodeFileToFile( String infile, String outfile ) throws java.io.IOException { String encoded = Base64.encodeFromFile( infile ); - java.io.OutputStream out = null; - try{ - out = new java.io.BufferedOutputStream( - new java.io.FileOutputStream( outfile ) ); - out.write( encoded.getBytes("US-ASCII") ); // Strict, 7-bit output. - } // end try - catch( java.io.IOException e ) { - throw e; // Catch and release to execute finally{} - } // end catch - finally { - try { out.close(); } - catch( Exception ex ){} - } // end finally + try (java.io.OutputStream out = new java.io.BufferedOutputStream( + new java.io.FileOutputStream(outfile))) { + out.write(encoded.getBytes(StandardCharsets.US_ASCII)); // Strict, 7-bit output. + } } // end encodeFileToFile @@ -1609,19 +1560,10 @@ public static void decodeFileToFile( String infile, String outfile ) throws java.io.IOException { byte[] decoded = Base64.decodeFromFile( infile ); - java.io.OutputStream out = null; - try{ - out = new java.io.BufferedOutputStream( - new java.io.FileOutputStream( outfile ) ); - out.write( decoded ); - } // end try - catch( java.io.IOException e ) { - throw e; // Catch and release to execute finally{} - } // end catch - finally { - try { out.close(); } - catch( Exception ex ){} - } // end finally + try (java.io.OutputStream out = new java.io.BufferedOutputStream( + new java.io.FileOutputStream(outfile))) { + out.write(decoded); + } } // end decodeFileToFile diff --git a/src/main/java/xades4j/utils/CollectionUtils.java b/src/main/java/xades4j/utils/CollectionUtils.java index 23904751..0b189038 100644 --- a/src/main/java/xades4j/utils/CollectionUtils.java +++ b/src/main/java/xades4j/utils/CollectionUtils.java @@ -16,12 +16,7 @@ */ package xades4j.utils; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * Provides some utility methods over collections. @@ -152,21 +147,7 @@ public static List project( public static List filterByType(Collection c, final Class clazz){ return project( - filter(c,new Predicate() - { - @Override - public boolean verifiedBy(T elem) - { - return clazz.isAssignableFrom(elem.getClass()); - } - }), - new Projector() - { - @Override - public T1 project(T e) - { - return (T1)e; - } - }); + filter(c, elem -> clazz.isAssignableFrom(elem.getClass())), + e -> (T1)e); } } diff --git a/src/main/java/xades4j/utils/CrlExtensionsUtils.java b/src/main/java/xades4j/utils/CrlExtensionsUtils.java index 928f37af..1eeb2cf8 100644 --- a/src/main/java/xades4j/utils/CrlExtensionsUtils.java +++ b/src/main/java/xades4j/utils/CrlExtensionsUtils.java @@ -17,13 +17,14 @@ package xades4j.utils; +import org.bouncycastle.asn1.ASN1Object; +import org.bouncycastle.asn1.x509.CRLNumber; +import org.bouncycastle.asn1.x509.Extension; +import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils; + import java.io.IOException; import java.math.BigInteger; import java.security.cert.X509CRL; -import org.bouncycastle.asn1.ASN1Object; -import org.bouncycastle.asn1.x509.CRLNumber; -import org.bouncycastle.asn1.x509.X509Extension; -import org.bouncycastle.x509.extension.X509ExtensionUtil; /** * @@ -37,12 +38,12 @@ private CrlExtensionsUtils() public static BigInteger getCrlNumber(X509CRL crl) throws IOException { - byte[] crlNumEnc = crl.getExtensionValue(X509Extension.cRLNumber.getId()); + byte[] crlNumEnc = crl.getExtensionValue(Extension.cRLNumber.getId()); BigInteger crlNum = null; // XAdES 7.4.2: "The 'number' element is an optional hint ..." if (crlNumEnc != null) { - ASN1Object derCrlNum = X509ExtensionUtil.fromExtensionValue(crlNumEnc); + ASN1Object derCrlNum = JcaX509ExtensionUtils.parseExtensionValue(crlNumEnc); crlNum = CRLNumber.getInstance(derCrlNum).getCRLNumber(); } return crlNum; diff --git a/src/main/java/xades4j/utils/DataGetterImpl.java b/src/main/java/xades4j/utils/DataGetterImpl.java index 0569055f..fdf65bc1 100644 --- a/src/main/java/xades4j/utils/DataGetterImpl.java +++ b/src/main/java/xades4j/utils/DataGetterImpl.java @@ -16,14 +16,10 @@ */ package xades4j.utils; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; import xades4j.utils.CollectionUtils.Predicate; +import java.util.*; + /** * * @author Luís @@ -45,13 +41,8 @@ private Map> getAllByType(Collection all) for (T e : all) { - Set typeTs = res.get(e.getClass()); - if (null == typeTs) - { - typeTs = new HashSet(); - res.put(e.getClass(), typeTs); - } - typeTs.add(e); + Set typeTs = res.computeIfAbsent(e.getClass(), k -> new HashSet()); + typeTs.add(e); } return res; } diff --git a/src/main/java/xades4j/utils/FileSystemDirectoryCertStore.java b/src/main/java/xades4j/utils/FileSystemDirectoryCertStore.java index 519ef249..e2370a23 100644 --- a/src/main/java/xades4j/utils/FileSystemDirectoryCertStore.java +++ b/src/main/java/xades4j/utils/FileSystemDirectoryCertStore.java @@ -22,13 +22,7 @@ import java.security.InvalidAlgorithmParameterException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; -import java.security.cert.CRLException; -import java.security.cert.CertStore; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; -import java.security.cert.CollectionCertStoreParameters; -import java.security.cert.X509CRL; -import java.security.cert.X509Certificate; +import java.security.cert.*; import java.util.ArrayList; import java.util.Collection; @@ -138,12 +132,10 @@ protected FileSystemDirectoryCertStore( { this.content = CertStore.getInstance("Collection", new CollectionCertStoreParameters(contentList)); return; - } catch (InvalidAlgorithmParameterException ex) - { - } catch (NoSuchAlgorithmException ex) + } catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException ignored) { } - // ToDo: this is a bit ugly! + // ToDo: this is a bit ugly! throw new CertificateException("Error getting Collection CertStore"); } @@ -155,35 +147,29 @@ private void transverseDirToFindContent( CertificateFactory cf) throws CertificateException, CRLException { File[] dirContents = dir.listFiles(); - for (int i = 0; i < dirContents.length; i++) - { - File f = dirContents[i]; - - if (f.isDirectory()) - transverseDirToFindContent(f, contentList, certsFilesExts, crlsFilesExts, cf); - else if (f.isFile()) - try - { - if (hasExt(f, certsFilesExts)) - contentList.add((X509Certificate)cf.generateCertificate(new FileInputStream(f))); - else if (hasExt(f, crlsFilesExts)) - contentList.add((X509CRL)cf.generateCRL(new FileInputStream(f))); - } catch (FileNotFoundException ex) - { - // The file existed right up there! If somehow it doesn't exist - // now, nevermind. - } - } + assert dirContents != null; + for (File f : dirContents) { + if (f.isDirectory()) + transverseDirToFindContent(f, contentList, certsFilesExts, crlsFilesExts, cf); + else if (f.isFile()) + try { + if (hasExt(f, certsFilesExts)) + contentList.add(cf.generateCertificate(new FileInputStream(f))); + else if (hasExt(f, crlsFilesExts)) + contentList.add(cf.generateCRL(new FileInputStream(f))); + } catch (FileNotFoundException ex) { + // The file existed right up there! If somehow it doesn't exist + // now, nevermind. + } + } } private boolean hasExt(File f, String[] filesExts) { - for (int j = 0; j < - filesExts.length; j++) - { - if (f.getName().endsWith('.' + filesExts[j])) - return true; - } + for (String filesExt : filesExts) { + if (f.getName().endsWith('.' + filesExt)) + return true; + } return false; } diff --git a/src/main/java/xades4j/utils/ObjectUtils.java b/src/main/java/xades4j/utils/ObjectUtils.java index 1811e4a7..c8894b43 100644 --- a/src/main/java/xades4j/utils/ObjectUtils.java +++ b/src/main/java/xades4j/utils/ObjectUtils.java @@ -29,12 +29,11 @@ public class ObjectUtils */ public static boolean allNull(Object... objs) { - for (int i = 0; i < objs.length; i++) - { - if (null != objs[i]) - return false; + for (Object obj : objs) { + if (null != obj) + return false; - } + } return true; } @@ -45,11 +44,10 @@ public static boolean allNull(Object... objs) */ public static boolean anyNull(Object... objs) { - for (int i = 0; i < objs.length; i++) - { - if (null == objs[i]) - return true; - } + for (Object obj : objs) { + if (null == obj) + return true; + } return false; } } diff --git a/src/main/java/xades4j/utils/PropertiesSet.java b/src/main/java/xades4j/utils/PropertiesSet.java index 29a1f278..bd108c11 100644 --- a/src/main/java/xades4j/utils/PropertiesSet.java +++ b/src/main/java/xades4j/utils/PropertiesSet.java @@ -17,13 +17,8 @@ package xades4j.utils; import xades4j.properties.PropertyTargetException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; + +import java.util.*; /** * A generic bag of properties used to store properties that apply to a specific @@ -84,14 +79,9 @@ public void add(T prop) if (null == prop) throw new NullPointerException("Property cannot be null"); - Set propsOfCurrType = properties.get(prop.getClass()); - if (null == propsOfCurrType) - { - // No properties of this type have been added. - propsOfCurrType = new HashSet(1); - properties.put(prop.getClass(), propsOfCurrType); - } - // Repeated instances are not allowed. + Set propsOfCurrType = properties.computeIfAbsent(prop.getClass(), k -> new HashSet(1)); + // No properties of this type have been added. + // Repeated instances are not allowed. if (!propsOfCurrType.add(prop)) throw new PropertyTargetException("Property instance already present"); } diff --git a/src/main/java/xades4j/utils/ResolverAnonymous.java b/src/main/java/xades4j/utils/ResolverAnonymous.java index b38d0c73..b5cb37d3 100644 --- a/src/main/java/xades4j/utils/ResolverAnonymous.java +++ b/src/main/java/xades4j/utils/ResolverAnonymous.java @@ -16,13 +16,12 @@ */ package xades4j.utils; -import java.io.InputStream; -import org.apache.xml.security.signature.XMLSignatureInput; import org.apache.xml.security.signature.XMLSignatureStreamInput; import org.apache.xml.security.utils.resolver.ResourceResolverContext; -import org.apache.xml.security.utils.resolver.ResourceResolverException; import org.apache.xml.security.utils.resolver.ResourceResolverSpi; +import java.io.InputStream; + /** * Resource resolver for References without an URI attribute. * @@ -39,8 +38,7 @@ public ResolverAnonymous(InputStream data) } @Override - public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException - { + public XMLSignatureStreamInput engineResolveURI(ResourceResolverContext context) { return new XMLSignatureStreamInput(this.data); } diff --git a/src/main/java/xades4j/utils/StringUtils.java b/src/main/java/xades4j/utils/StringUtils.java index 2dbd82fc..08ebbb8d 100644 --- a/src/main/java/xades4j/utils/StringUtils.java +++ b/src/main/java/xades4j/utils/StringUtils.java @@ -29,11 +29,10 @@ public static boolean isNullOrEmptyString(String s) public static boolean allNullOrEmptyStrings(String... srts) { - for (int i = 0; i < srts.length; i++) - { - if (!isNullOrEmptyString(srts[i])) - return false; - } + for (String srt : srts) { + if (!isNullOrEmptyString(srt)) + return false; + } return true; } diff --git a/src/main/java/xades4j/utils/XadesProfileCore.java b/src/main/java/xades4j/utils/XadesProfileCore.java index 5ec9c1b9..fee219c0 100644 --- a/src/main/java/xades4j/utils/XadesProfileCore.java +++ b/src/main/java/xades4j/utils/XadesProfileCore.java @@ -16,11 +16,8 @@ */ package xades4j.utils; -import com.google.inject.Binder; -import com.google.inject.Guice; -import com.google.inject.Key; import com.google.inject.Module; -import com.google.inject.TypeLiteral; +import com.google.inject.*; import com.google.inject.multibindings.MapBinder; import com.google.inject.multibindings.Multibinder; import com.google.inject.multibindings.OptionalBinder; @@ -67,14 +64,7 @@ public void addBinding(final Class from, final Class to) if (null == from || null == to) throw new NullPointerException(); - this.bindings.add(new BindingAction() - { - @Override - public void bind(Binder b) - { - b.bind(from).to(to); - } - }); + this.bindings.add(b -> b.bind(from).to(to)); } /** @@ -85,14 +75,7 @@ public void addBinding(final Class from, final T to) if (null == from || null == to) throw new NullPointerException(); - this.bindings.add(new BindingAction() - { - @Override - public void bind(Binder b) - { - b.bind(from).toInstance(to); - } - }); + this.bindings.add(b -> b.bind(from).toInstance(to)); } public void addGenericBinding( @@ -103,15 +86,10 @@ public void addGenericBinding( if (ObjectUtils.anyNull(genericClass, genericClassParams, to)) throw new NullPointerException(); - this.bindings.add(new BindingAction() - { - @Override - public void bind(Binder b) - { - ParameterizedType pt = Types.newParameterizedType(genericClass, genericClassParams); - Key k = Key.get(TypeLiteral.get(pt)); - b.bind(k).to(to); - } + this.bindings.add(b -> { + ParameterizedType pt = Types.newParameterizedType(genericClass, genericClassParams); + Key k = Key.get(TypeLiteral.get(pt)); + b.bind(k).to(to); }); } @@ -123,28 +101,16 @@ public void addGenericBinding( if (ObjectUtils.anyNull(genericClass, genericClassParams, to)) throw new NullPointerException(); - this.bindings.add(new BindingAction() - { - @Override - public void bind(Binder b) - { - ParameterizedType pt = Types.newParameterizedType(genericClass, genericClassParams); - Key k = Key.get(TypeLiteral.get(pt)); - b.bind(k).toInstance(to); - } + this.bindings.add(b -> { + ParameterizedType pt = Types.newParameterizedType(genericClass, genericClassParams); + Key k = Key.get(TypeLiteral.get(pt)); + b.bind(k).toInstance(to); }); } - public final void addOptionalBinding(final Class clazz) + public void addOptionalBinding(final Class clazz) { - this.bindings.add(new BindingAction() - { - @Override - public void bind(Binder b) - { - OptionalBinder.newOptionalBinder(b, clazz); - } - }); + this.bindings.add(b -> OptionalBinder.newOptionalBinder(b, clazz)); } public void addMultibinding(final Class from, final Class to) @@ -152,14 +118,9 @@ public void addMultibinding(final Class from, final Class to if (null == from || null == to) throw new NullPointerException(); - this.bindings.add(new BindingAction() - { - @Override - public void bind(Binder b) - { - Multibinder multibinder = Multibinder.newSetBinder(b, from); - multibinder.addBinding().to(to); - } + this.bindings.add(b -> { + Multibinder multibinder = Multibinder.newSetBinder(b, from); + multibinder.addBinding().to(to); }); } @@ -168,14 +129,9 @@ public void addMultibinding(final Class from, final T to) if (null == from || null == to) throw new NullPointerException(); - this.bindings.add(new BindingAction() - { - @Override - public void bind(Binder b) - { - Multibinder multibinder = Multibinder.newSetBinder(b, from); - multibinder.addBinding().toInstance(to); - } + this.bindings.add(b -> { + Multibinder multibinder = Multibinder.newSetBinder(b, from); + multibinder.addBinding().toInstance(to); }); } @@ -184,14 +140,9 @@ public void addMapBinding(final Class valueClass, final Obj if (null == key || null == value) throw new NullPointerException(); - this.bindings.add(new BindingAction() - { - @Override - public void bind(Binder b) - { - MapBinder mapBinder = MapBinder.newMapBinder(b, key.getClass(), valueClass); - mapBinder.addBinding(key).toInstance(value); - } + this.bindings.add(b -> { + MapBinder mapBinder = MapBinder.newMapBinder(b, key.getClass(), valueClass); + mapBinder.addBinding(key).toInstance(value); }); } @@ -200,14 +151,9 @@ public void addMapBinding(final Class valueClass, final Object key, final if (null == key || null == to) throw new NullPointerException(); - this.bindings.add(new BindingAction() - { - @Override - public void bind(Binder b) - { - MapBinder mapBinder = MapBinder.newMapBinder(b, key.getClass(), valueClass); - mapBinder.addBinding(key).to(to); - } + this.bindings.add(b -> { + MapBinder mapBinder = MapBinder.newMapBinder(b, key.getClass(), valueClass); + mapBinder.addBinding(key).to(to); }); } @@ -216,19 +162,14 @@ public T getInstance( Module[] overridableModules, Module[] sealedModules) throws XadesProfileResolutionException { - Module userBindingsModule = new Module() - { - @Override - public void configure(Binder b) + Module userBindingsModule = b -> { + for (BindingAction ba : bindings) { - for (BindingAction ba : bindings) - { - ba.bind(b); - } + ba.bind(b); } }; Module overridesModule = Modules.override(overridableModules).with(userBindingsModule); - // Concat sealed modules with overrides module + // Concat sealed modules with override module Module[] finalModules = Arrays.copyOf(sealedModules, sealedModules.length + 1); finalModules[finalModules.length - 1] = overridesModule; try diff --git a/src/main/java/xades4j/verification/CertRefUtils.java b/src/main/java/xades4j/verification/CertRefUtils.java index f2f9e5a9..ccd180d3 100644 --- a/src/main/java/xades4j/verification/CertRefUtils.java +++ b/src/main/java/xades4j/verification/CertRefUtils.java @@ -16,15 +16,16 @@ */ package xades4j.verification; +import xades4j.UnsupportedAlgorithmException; +import xades4j.XAdES4jException; +import xades4j.properties.data.CertRef; +import xades4j.providers.MessageDigestEngineProvider; + import java.security.MessageDigest; import java.security.cert.CertificateEncodingException; import java.security.cert.X509Certificate; import java.util.Arrays; import java.util.Collection; -import xades4j.UnsupportedAlgorithmException; -import xades4j.XAdES4jException; -import xades4j.properties.data.CertRef; -import xades4j.providers.MessageDigestEngineProvider; /** * @@ -84,13 +85,10 @@ static void checkCertRef( if (!Arrays.equals(certRef.digestValue, actualDigest)) throw new InvalidCertRefException("digests mismatch"); return; - } catch (UnsupportedAlgorithmException ex) - { - t = ex; - } catch (CertificateEncodingException ex) + } catch (UnsupportedAlgorithmException | CertificateEncodingException ex) { t = ex; } - throw new InvalidCertRefException(t.getMessage()); + throw new InvalidCertRefException(t.getMessage()); } } diff --git a/src/main/java/xades4j/verification/CompleteRevocRefsVerifier.java b/src/main/java/xades4j/verification/CompleteRevocRefsVerifier.java index aa673ed7..61d8db66 100644 --- a/src/main/java/xades4j/verification/CompleteRevocRefsVerifier.java +++ b/src/main/java/xades4j/verification/CompleteRevocRefsVerifier.java @@ -17,6 +17,14 @@ package xades4j.verification; import jakarta.inject.Inject; +import xades4j.UnsupportedAlgorithmException; +import xades4j.properties.CompleteRevocationRefsProperty; +import xades4j.properties.QualifyingProperty; +import xades4j.properties.data.CRLRef; +import xades4j.properties.data.CompleteRevocationRefsData; +import xades4j.providers.MessageDigestEngineProvider; +import xades4j.utils.CrlExtensionsUtils; + import java.io.IOException; import java.math.BigInteger; import java.security.MessageDigest; @@ -26,14 +34,6 @@ import java.util.Arrays; import java.util.Collection; -import xades4j.properties.CompleteRevocationRefsProperty; -import xades4j.properties.QualifyingProperty; -import xades4j.UnsupportedAlgorithmException; -import xades4j.properties.data.CRLRef; -import xades4j.properties.data.CompleteRevocationRefsData; -import xades4j.providers.MessageDigestEngineProvider; -import xades4j.utils.CrlExtensionsUtils; - /** * XAdES G.2.2.13 * @author Luís @@ -97,15 +97,7 @@ public QualifyingProperty verify( break; } } - catch(IOException ex) - { - throw new CompleteRevocRefsReferenceException(crl, ex.getMessage()); - } - catch (CRLException ex) - { - throw new CompleteRevocRefsReferenceException(crl, ex.getMessage()); - } - catch (UnsupportedAlgorithmException ex) + catch(IOException | CRLException | UnsupportedAlgorithmException ex) { throw new CompleteRevocRefsReferenceException(crl, ex.getMessage()); } diff --git a/src/main/java/xades4j/verification/CounterSignatureXadesVerificationException.java b/src/main/java/xades4j/verification/CounterSignatureXadesVerificationException.java index 64887306..a0d3b0eb 100644 --- a/src/main/java/xades4j/verification/CounterSignatureXadesVerificationException.java +++ b/src/main/java/xades4j/verification/CounterSignatureXadesVerificationException.java @@ -29,10 +29,4 @@ public CounterSignatureXadesVerificationException(XAdES4jException cause) { super(cause); } - - @Override - protected String getVerificationMessage() - { - return getCause().getMessage(); - } } diff --git a/src/main/java/xades4j/verification/DefaultVerificationBindingsModule.java b/src/main/java/xades4j/verification/DefaultVerificationBindingsModule.java index 0f8cfeb8..594ebc5c 100644 --- a/src/main/java/xades4j/verification/DefaultVerificationBindingsModule.java +++ b/src/main/java/xades4j/verification/DefaultVerificationBindingsModule.java @@ -21,38 +21,23 @@ import com.google.inject.multibindings.MapBinder; import com.google.inject.multibindings.Multibinder; import com.google.inject.util.Types; -import java.io.InputStream; -import java.lang.reflect.ParameterizedType; -import javax.xml.namespace.QName; import xades4j.properties.CounterSignatureProperty; -import xades4j.properties.ObjectIdentifier; import xades4j.properties.QualifyingProperty; -import xades4j.properties.data.AllDataObjsTimeStampData; -import xades4j.properties.data.CommitmentTypeData; -import xades4j.properties.data.CompleteCertificateRefsData; -import xades4j.properties.data.CompleteRevocationRefsData; -import xades4j.properties.data.CustomPropertiesDataObjsStructureVerifier; -import xades4j.properties.data.DataObjectFormatData; -import xades4j.properties.data.GenericDOMData; -import xades4j.properties.data.IndividualDataObjsTimeStampData; -import xades4j.properties.data.PropertyDataObject; -import xades4j.properties.data.SignaturePolicyData; -import xades4j.properties.data.SignatureProdPlaceData; -import xades4j.properties.data.SignatureTimeStampData; -import xades4j.properties.data.SignerRoleData; -import xades4j.properties.data.SigningCertificateData; -import xades4j.properties.data.SigningTimeData; -import xades4j.providers.X500NameStyleProvider; -import xades4j.providers.impl.DefaultMessageDigestProvider; -import xades4j.providers.impl.DefaultTimeStampVerificationProvider; +import xades4j.properties.data.*; import xades4j.providers.MessageDigestEngineProvider; import xades4j.providers.SignaturePolicyDocumentProvider; import xades4j.providers.TimeStampVerificationProvider; +import xades4j.providers.X500NameStyleProvider; +import xades4j.providers.impl.DefaultMessageDigestProvider; +import xades4j.providers.impl.DefaultTimeStampVerificationProvider; import xades4j.providers.impl.DefaultX500NameStyleProvider; import xades4j.utils.BuiltIn; import xades4j.utils.RFC4519ExtensibleStyle; import xades4j.utils.X500ExtensibleNameStyle; +import javax.xml.namespace.QName; +import java.lang.reflect.ParameterizedType; + /** * Contains the Guice bindings for the default components and the bindings for the * needed internal components. @@ -77,17 +62,9 @@ protected void configure() { bind(MessageDigestEngineProvider.class).to(DefaultMessageDigestProvider.class); bind(TimeStampVerificationProvider.class).to(DefaultTimeStampVerificationProvider.class); - bind(SignaturePolicyDocumentProvider.class).toInstance(new SignaturePolicyDocumentProvider() - { - @Override - public InputStream getSignaturePolicyDocumentStream( - ObjectIdentifier sigPolicyId) - { - return null; - } - }); + bind(SignaturePolicyDocumentProvider.class).toInstance(sigPolicyId -> null); - // QualifyingPropertiesVerifier is not configurable but the individual + // QualifyingPropertiesVerifier is not configurable, but the individual // verifiers may have dependencies. bind(QualifyingPropertiesVerifier.class).to(QualifyingPropertiesVerifierImpl.class); bind(QualifyingPropertyVerifiersMapper.class).to(QualifyingPropertyVerifiersMapperImpl.class); diff --git a/src/main/java/xades4j/verification/QualifyingPropertyVerifiersMapperImpl.java b/src/main/java/xades4j/verification/QualifyingPropertyVerifiersMapperImpl.java index ae485de8..8148fc21 100644 --- a/src/main/java/xades4j/verification/QualifyingPropertyVerifiersMapperImpl.java +++ b/src/main/java/xades4j/verification/QualifyingPropertyVerifiersMapperImpl.java @@ -16,16 +16,13 @@ */ package xades4j.verification; -import com.google.inject.ConfigurationException; -import jakarta.inject.Inject; -import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.ProvisionException; -import com.google.inject.TypeLiteral; +import com.google.inject.*; import com.google.inject.util.Types; -import java.lang.reflect.ParameterizedType; +import jakarta.inject.Inject; import xades4j.properties.data.PropertyDataObject; +import java.lang.reflect.ParameterizedType; + /** * * @author Luís @@ -48,11 +45,9 @@ public QualifyingPropertyVerifier getV { ParameterizedType pt = Types.newParameterizedType(QualifyingPropertyVerifier.class, p.getClass()); return (QualifyingPropertyVerifier)injector.getInstance(Key.get(TypeLiteral.get(pt))); - } catch (ConfigurationException ex) - { - } catch (ProvisionException ex) + } catch (ConfigurationException | ProvisionException ignored) { } - throw new QualifyingPropertyVerifierNotAvailableException(p); + throw new QualifyingPropertyVerifierNotAvailableException(p); } } diff --git a/src/main/java/xades4j/verification/SignerRoleVerifier.java b/src/main/java/xades4j/verification/SignerRoleVerifier.java index 31597caf..6fdc4b0d 100644 --- a/src/main/java/xades4j/verification/SignerRoleVerifier.java +++ b/src/main/java/xades4j/verification/SignerRoleVerifier.java @@ -29,8 +29,7 @@ class SignerRoleVerifier implements QualifyingPropertyVerifier @Override public QualifyingProperty verify( SignerRoleData propData, - QualifyingPropertyVerificationContext ctx) throws InvalidPropertyException - { + QualifyingPropertyVerificationContext ctx) { return new SignerRoleProperty(propData.getClaimedRoles()); } } diff --git a/src/main/java/xades4j/verification/TimeStampVerifierBase.java b/src/main/java/xades4j/verification/TimeStampVerifierBase.java index b1532f71..fa64c5db 100644 --- a/src/main/java/xades4j/verification/TimeStampVerifierBase.java +++ b/src/main/java/xades4j/verification/TimeStampVerifierBase.java @@ -16,21 +16,20 @@ */ package xades4j.verification; -import java.lang.reflect.Method; -import java.util.Date; -import java.util.List; -import xades4j.UnsupportedAlgorithmException; import xades4j.properties.QualifyingProperty; import xades4j.properties.data.BaseXAdESTimeStampData; import xades4j.providers.TimeStampTokenDigestException; import xades4j.providers.TimeStampTokenSignatureException; import xades4j.providers.TimeStampTokenStructureException; -import xades4j.providers.TimeStampTokenVerificationException; import xades4j.providers.TimeStampVerificationProvider; import xades4j.utils.CannotAddDataToDigestInputException; import xades4j.utils.TimeStampDigestInput; import xades4j.utils.TimeStampDigestInputFactory; +import java.lang.reflect.Method; +import java.util.Date; +import java.util.List; + /** * * @author Luís @@ -76,23 +75,11 @@ public final QualifyingProperty verify( setTimeMethod.invoke(prop, ts); return prop; } - catch(UnsupportedAlgorithmException ex) - { - throw getEx(ex, this.propName); - } - catch (CannotAddDataToDigestInputException ex) - { - throw new TimeStampDigestInputException(this.propName, ex); - } - catch (TimeStampTokenVerificationException ex) + catch(Exception ex) { throw getEx(ex, this.propName); } - catch (Exception ex) - { - // Exceptions related to setTimeMethod.invoke(...) - throw getEx(ex, this.propName); - } + } protected abstract QualifyingProperty addPropSpecificTimeStampInputAndCreateProperty( diff --git a/src/main/java/xades4j/verification/XAdESFormChecker.java b/src/main/java/xades4j/verification/XAdESFormChecker.java index f388c405..8c66283e 100644 --- a/src/main/java/xades4j/verification/XAdESFormChecker.java +++ b/src/main/java/xades4j/verification/XAdESFormChecker.java @@ -16,18 +16,11 @@ */ package xades4j.verification; +import xades4j.properties.*; + import java.util.Collection; import java.util.HashSet; import java.util.Set; -import xades4j.properties.ArchiveTimeStampProperty; -import xades4j.properties.CertificateValuesProperty; -import xades4j.properties.CompleteCertificateRefsProperty; -import xades4j.properties.CompleteRevocationRefsProperty; -import xades4j.properties.RevocationValuesProperty; -import xades4j.properties.SigAndRefsTimeStampProperty; -import xades4j.properties.SignaturePolicyBase; -import xades4j.properties.SignatureTimeStampProperty; -import xades4j.properties.SigningCertificateProperty; /** * @@ -95,11 +88,10 @@ boolean check(Set availablePropsNames) throws InvalidXAdESFormException if (baseForms.length == 0) return true; - for (int i = 0; i < baseForms.length; i++) - { - if (baseForms[i].check(availablePropsNames)) - return true; - } + for (XAdESFormDesc baseForm : baseForms) { + if (baseForm.check(availablePropsNames)) + return true; + } throw new InvalidXAdESFormException(String.format("Required base forms for %s are not present", this.getForm().toString())); } @@ -225,8 +217,7 @@ public XAdES_X_Desc() } @Override - protected boolean checkProps(Set availablePropsNames) throws InvalidXAdESFormException - { + protected boolean checkProps(Set availablePropsNames) { return availablePropsNames.contains(SigAndRefsTimeStampProperty.PROP_NAME) || availablePropsNames.contains("RefsOnlyTimeStamp"); } @@ -278,8 +269,7 @@ public XAdES_A_Desc() } @Override - protected boolean checkProps(Set availablePropsNames) throws InvalidXAdESFormException - { + protected boolean checkProps(Set availablePropsNames) { return availablePropsNames.contains(ArchiveTimeStampProperty.PROP_NAME); } diff --git a/src/main/java/xades4j/verification/XAdESVerificationResult.java b/src/main/java/xades4j/verification/XAdESVerificationResult.java index 635dca5f..1b3ddafa 100644 --- a/src/main/java/xades4j/verification/XAdESVerificationResult.java +++ b/src/main/java/xades4j/verification/XAdESVerificationResult.java @@ -16,22 +16,15 @@ */ package xades4j.verification; -import java.security.cert.X509Certificate; -import java.util.Collection; import org.apache.xml.security.signature.XMLSignature; -import xades4j.properties.QualifyingProperties; -import xades4j.properties.QualifyingProperty; -import xades4j.properties.SignedDataObjectProperty; -import xades4j.properties.SignedProperties; -import xades4j.properties.SignedSignatureProperty; -import xades4j.properties.UnsignedDataObjectProperty; -import xades4j.properties.UnsignedProperties; -import xades4j.properties.UnsignedSignatureProperty; -import xades4j.utils.DataGetter; -import xades4j.utils.DataGetterImpl; +import xades4j.properties.*; import xades4j.providers.ValidationData; import xades4j.utils.CollectionUtils; -import xades4j.utils.CollectionUtils.Projector; +import xades4j.utils.DataGetter; +import xades4j.utils.DataGetterImpl; + +import java.security.cert.X509Certificate; +import java.util.Collection; /** * The result of signature verification. It includes the signature form, the qualifying @@ -69,16 +62,9 @@ public class XAdESVerificationResult private DataGetter createPropsGetter( Collection propsInfo) { - Collection props = CollectionUtils.project(propsInfo, new Projector() - { - @Override - public QualifyingProperty project(PropertyInfo e) - { - return e.getProperty(); - } - }); - - return new DataGetterImpl(props); + Collection props = CollectionUtils.project(propsInfo, PropertyInfo::getProperty); + + return new DataGetterImpl<>(props); } private QualifyingProperties createQualifProps() diff --git a/src/main/java/xades4j/verification/XadesVerificationProfile.java b/src/main/java/xades4j/verification/XadesVerificationProfile.java index bd634c98..8df8e9b3 100644 --- a/src/main/java/xades4j/verification/XadesVerificationProfile.java +++ b/src/main/java/xades4j/verification/XadesVerificationProfile.java @@ -145,7 +145,7 @@ public XadesVerificationProfile withBinding( * @return a {@code XadesVerifier} accordingly to this profile. * @throws XadesProfileResolutionException if the dependencies of the signer (direct and indirect) cannot be resolved */ - public final XadesVerifier newVerifier() throws XadesProfileResolutionException + public XadesVerifier newVerifier() throws XadesProfileResolutionException { XadesVerifierImpl v = profileCore.getInstance(XadesVerifierImpl.class, overridableModules, sealedModules); v.setAcceptUnknownProperties(acceptUnknownProperties); diff --git a/src/main/java/xades4j/verification/XadesVerifierImpl.java b/src/main/java/xades4j/verification/XadesVerifierImpl.java index 7f8f21fb..1fab5180 100644 --- a/src/main/java/xades4j/verification/XadesVerifierImpl.java +++ b/src/main/java/xades4j/verification/XadesVerifierImpl.java @@ -17,14 +17,6 @@ package xades4j.verification; import jakarta.inject.Inject; -import java.io.InputStream; -import java.security.cert.X509CRL; -import java.security.cert.X509Certificate; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Set; import org.apache.xml.security.exceptions.XMLSecurityException; import org.apache.xml.security.signature.Reference; import org.apache.xml.security.signature.SignedInfo; @@ -33,15 +25,15 @@ import org.apache.xml.security.utils.resolver.ResourceResolverSpi; import org.w3c.dom.Element; import org.w3c.dom.Node; -import xades4j.properties.QualifyingProperty; -import xades4j.properties.UnsignedSignatureProperty; import xades4j.XAdES4jException; import xades4j.XAdES4jXMLSigException; -import xades4j.properties.data.CertRef; -import xades4j.properties.data.PropertyDataObject; -import xades4j.properties.UnsignedProperties; import xades4j.production.XadesSignatureFormatExtender; +import xades4j.properties.QualifyingProperty; import xades4j.properties.SignatureTimeStampProperty; +import xades4j.properties.UnsignedProperties; +import xades4j.properties.UnsignedSignatureProperty; +import xades4j.properties.data.CertRef; +import xades4j.properties.data.PropertyDataObject; import xades4j.properties.data.SignatureTimeStampData; import xades4j.properties.data.SigningCertificateData; import xades4j.providers.CertificateValidationProvider; @@ -57,6 +49,11 @@ import xades4j.xml.unmarshalling.QualifyingPropertiesUnmarshaller; import xades4j.xml.unmarshalling.UnmarshalException; +import java.io.InputStream; +import java.security.cert.X509CRL; +import java.security.cert.X509Certificate; +import java.util.*; + /** * * @author Luís @@ -377,76 +374,30 @@ private static void initFormExtension() formsExtensionTransitions = new FormExtensionPropsCollector[forms.length][forms.length]; // BES/EPES -> T - FormExtensionPropsCollector tPropsCol = new FormExtensionPropsCollector() - { - - @Override - public void addProps( - Collection usp, - XAdESVerificationResult res) - { - PropertiesUtils.addXadesTProperties(usp); - } - }; + FormExtensionPropsCollector tPropsCol = (usp, res) -> PropertiesUtils.addXadesTProperties(usp); formsExtensionTransitions[XAdESForm.BES.ordinal()][XAdESForm.T.ordinal()] = tPropsCol; formsExtensionTransitions[XAdESForm.EPES.ordinal()][XAdESForm.T.ordinal()] = tPropsCol; // BES/EPES -> C - FormExtensionPropsCollector cAndTPropsCol = new FormExtensionPropsCollector() - { - - @Override - public void addProps( - Collection usp, - XAdESVerificationResult res) - { - PropertiesUtils.addXadesCProperties(usp, res.getValidationData()); - PropertiesUtils.addXadesTProperties(usp); - } + FormExtensionPropsCollector cAndTPropsCol = (usp, res) -> { + PropertiesUtils.addXadesCProperties(usp, res.getValidationData()); + PropertiesUtils.addXadesTProperties(usp); }; formsExtensionTransitions[XAdESForm.BES.ordinal()][XAdESForm.C.ordinal()] = cAndTPropsCol; formsExtensionTransitions[XAdESForm.EPES.ordinal()][XAdESForm.C.ordinal()] = cAndTPropsCol; // T -> C - FormExtensionPropsCollector cPropsCol = new FormExtensionPropsCollector() - { - - @Override - public void addProps( - Collection usp, - XAdESVerificationResult res) - { - PropertiesUtils.addXadesCProperties(usp, res.getValidationData()); - } - }; + FormExtensionPropsCollector cPropsCol = (usp, res) -> PropertiesUtils.addXadesCProperties(usp, res.getValidationData()); formsExtensionTransitions[XAdESForm.T.ordinal()][XAdESForm.C.ordinal()] = cPropsCol; // C -> X - FormExtensionPropsCollector xPropsCol = new FormExtensionPropsCollector() - { - - @Override - public void addProps( - Collection usp, - XAdESVerificationResult res) - { - PropertiesUtils.addXadesXProperties(usp); - } - }; + FormExtensionPropsCollector xPropsCol = (usp, res) -> PropertiesUtils.addXadesXProperties(usp); formsExtensionTransitions[XAdESForm.C.ordinal()][XAdESForm.X.ordinal()] = xPropsCol; // C -> X-L - FormExtensionPropsCollector xlAndXPropsCol = new FormExtensionPropsCollector() - { - - @Override - public void addProps( - Collection usp, - XAdESVerificationResult res) - { - PropertiesUtils.addXadesXLProperties(usp, res.getValidationData()); - PropertiesUtils.addXadesXProperties(usp); - } + FormExtensionPropsCollector xlAndXPropsCol = (usp, res) -> { + PropertiesUtils.addXadesXLProperties(usp, res.getValidationData()); + PropertiesUtils.addXadesXProperties(usp); }; formsExtensionTransitions[XAdESForm.C.ordinal()][XAdESForm.X_L.ordinal()] = xlAndXPropsCol; } diff --git a/src/main/java/xades4j/xml/marshalling/BaseJAXBMarshaller.java b/src/main/java/xades4j/xml/marshalling/BaseJAXBMarshaller.java index e5be3cb9..3e07052b 100644 --- a/src/main/java/xades4j/xml/marshalling/BaseJAXBMarshaller.java +++ b/src/main/java/xades4j/xml/marshalling/BaseJAXBMarshaller.java @@ -136,8 +136,7 @@ protected void doMarshal( private Collection convert( Collection props, TXml xmlProps, - Document doc) throws MarshalException - { + Document doc) { Collection unknownProps = null; // Convert each property to the corresponding JAXB object. Each converter diff --git a/src/main/java/xades4j/xml/marshalling/algorithms/AlgorithmParametersBindingsModule.java b/src/main/java/xades4j/xml/marshalling/algorithms/AlgorithmParametersBindingsModule.java index 1c09c52f..5eaf6536 100644 --- a/src/main/java/xades4j/xml/marshalling/algorithms/AlgorithmParametersBindingsModule.java +++ b/src/main/java/xades4j/xml/marshalling/algorithms/AlgorithmParametersBindingsModule.java @@ -19,12 +19,9 @@ import com.google.inject.AbstractModule; import com.google.inject.TypeLiteral; import com.google.inject.multibindings.MapBinder; -import org.w3c.dom.Document; -import org.w3c.dom.Node; import xades4j.algorithms.*; import javax.annotation.Nullable; -import java.util.List; /** * Contains the Guice bindings for the components on this package. @@ -72,14 +69,7 @@ private void bindMarshaller( } else { - mapBinder.addBinding(algorithmClass).toInstance(new AlgorithmParametersMarshaller() - { - @Override - public List marshalParameters(T alg, Document doc) - { - return null; - } - }); + mapBinder.addBinding(algorithmClass).toInstance((AlgorithmParametersMarshaller) (alg, doc) -> null); } } } diff --git a/src/main/java/xades4j/xml/marshalling/algorithms/XPathTransformParamsMarshaller.java b/src/main/java/xades4j/xml/marshalling/algorithms/XPathTransformParamsMarshaller.java index 2461c6ac..382560b9 100644 --- a/src/main/java/xades4j/xml/marshalling/algorithms/XPathTransformParamsMarshaller.java +++ b/src/main/java/xades4j/xml/marshalling/algorithms/XPathTransformParamsMarshaller.java @@ -17,15 +17,16 @@ package xades4j.xml.marshalling.algorithms; -import java.util.Collections; -import java.util.List; -import java.util.Map; import org.apache.xml.security.exceptions.XMLSecurityException; import org.apache.xml.security.transforms.params.XPathContainer; import org.w3c.dom.Document; import org.w3c.dom.Node; import xades4j.algorithms.XPathTransform; +import java.util.Collections; +import java.util.List; +import java.util.Map; + /** * @author Luís */ @@ -48,6 +49,6 @@ public List marshalParameters(XPathTransform alg, Document doc) } } - return Collections.singletonList((Node)xpathContainer.getElement()); + return Collections.singletonList(xpathContainer.getElement()); } } diff --git a/src/main/java/xades4j/xml/unmarshalling/FromDOMCounterSignatureConverter.java b/src/main/java/xades4j/xml/unmarshalling/FromDOMCounterSignatureConverter.java index d63988a3..93bfbf3b 100644 --- a/src/main/java/xades4j/xml/unmarshalling/FromDOMCounterSignatureConverter.java +++ b/src/main/java/xades4j/xml/unmarshalling/FromDOMCounterSignatureConverter.java @@ -32,8 +32,7 @@ class FromDOMCounterSignatureConverter implements QualifyingPropertyFromDOMConve @Override public void convertFromDOMTree( Element props, - QualifyingPropertiesDataCollector propertyDataCollector) throws PropertyUnmarshalException - { + QualifyingPropertiesDataCollector propertyDataCollector) { Collection counterSigs = DOMHelper.getChildElementsByTagNameNS( props, QualifyingProperty.XADES_XMLNS, diff --git a/src/main/java/xades4j/xml/unmarshalling/FromXmlCompleteCertRefsConverter.java b/src/main/java/xades4j/xml/unmarshalling/FromXmlCompleteCertRefsConverter.java index f856dc66..9422a24e 100644 --- a/src/main/java/xades4j/xml/unmarshalling/FromXmlCompleteCertRefsConverter.java +++ b/src/main/java/xades4j/xml/unmarshalling/FromXmlCompleteCertRefsConverter.java @@ -29,8 +29,7 @@ class FromXmlCompleteCertRefsConverter implements UnsignedSigPropFromXmlConv @Override public void convertFromObjectTree( XmlUnsignedSignaturePropertiesType xmlProps, - QualifyingPropertiesDataCollector propertyDataCollector) throws PropertyUnmarshalException - { + QualifyingPropertiesDataCollector propertyDataCollector) { XmlCompleteCertificateRefsType xmlCompleteCertRefs = xmlProps.getCompleteCertificateRefs(); if (null == xmlCompleteCertRefs) return; diff --git a/src/main/java/xades4j/xml/unmarshalling/FromXmlDataObjFormatPropertyConverter.java b/src/main/java/xades4j/xml/unmarshalling/FromXmlDataObjFormatPropertyConverter.java index 709ac668..868ae5f7 100644 --- a/src/main/java/xades4j/xml/unmarshalling/FromXmlDataObjFormatPropertyConverter.java +++ b/src/main/java/xades4j/xml/unmarshalling/FromXmlDataObjFormatPropertyConverter.java @@ -32,8 +32,7 @@ class FromXmlDataObjFormatPropertyConverter implements SignedDataObjPropFromXmlC @Override public void convertFromObjectTree( XmlSignedDataObjectPropertiesType xmlProps, - QualifyingPropertiesDataCollector propertyDataCollector) throws PropertyUnmarshalException - { + QualifyingPropertiesDataCollector propertyDataCollector) { List xmlFormats = xmlProps.getDataObjectFormat(); if (xmlFormats.isEmpty()) return; diff --git a/src/main/java/xades4j/xml/unmarshalling/FromXmlSignaturePolicyConverter.java b/src/main/java/xades4j/xml/unmarshalling/FromXmlSignaturePolicyConverter.java index d98b887a..612df5b8 100644 --- a/src/main/java/xades4j/xml/unmarshalling/FromXmlSignaturePolicyConverter.java +++ b/src/main/java/xades4j/xml/unmarshalling/FromXmlSignaturePolicyConverter.java @@ -61,8 +61,7 @@ public void convertFromObjectTree( getLocationUrl(xmlPolicyId))); } - private static String getLocationUrl(XmlSignaturePolicyIdType xmlPolicyId) throws PropertyUnmarshalException - { + private static String getLocationUrl(XmlSignaturePolicyIdType xmlPolicyId) { XmlSigPolicyQualifiersListType sigPolicyQualifiers = xmlPolicyId.getSigPolicyQualifiers(); if(null == sigPolicyQualifiers) { diff --git a/src/main/java/xades4j/xml/unmarshalling/FromXmlSignatureProdPlaceConverter.java b/src/main/java/xades4j/xml/unmarshalling/FromXmlSignatureProdPlaceConverter.java index 708e3be2..31de1b0e 100644 --- a/src/main/java/xades4j/xml/unmarshalling/FromXmlSignatureProdPlaceConverter.java +++ b/src/main/java/xades4j/xml/unmarshalling/FromXmlSignatureProdPlaceConverter.java @@ -29,8 +29,7 @@ class FromXmlSignatureProdPlaceConverter implements SignedSigPropFromXmlConv @Override public void convertFromObjectTree( XmlSignedSignaturePropertiesType xmlProps, - QualifyingPropertiesDataCollector propertyDataCollector) throws PropertyUnmarshalException - { + QualifyingPropertiesDataCollector propertyDataCollector) { XmlSignatureProductionPlaceType xmlSigProdPlace = xmlProps.getSignatureProductionPlace(); if (null == xmlSigProdPlace) return; diff --git a/src/main/java/xades4j/xml/unmarshalling/FromXmlSigningCertificateConverter.java b/src/main/java/xades4j/xml/unmarshalling/FromXmlSigningCertificateConverter.java index 5e90e64b..c8eae6ee 100644 --- a/src/main/java/xades4j/xml/unmarshalling/FromXmlSigningCertificateConverter.java +++ b/src/main/java/xades4j/xml/unmarshalling/FromXmlSigningCertificateConverter.java @@ -30,8 +30,7 @@ class FromXmlSigningCertificateConverter @Override public void convertFromObjectTree( XmlSignedSignaturePropertiesType xmlProps, - QualifyingPropertiesDataCollector propertyDataCollector) throws PropertyUnmarshalException - { + QualifyingPropertiesDataCollector propertyDataCollector) { XmlCertIDListType xmlSigningCertificate = xmlProps.getSigningCertificate(); if (null == xmlSigningCertificate) return; diff --git a/src/main/java/xades4j/xml/unmarshalling/FromXmlSigningTimeConverter.java b/src/main/java/xades4j/xml/unmarshalling/FromXmlSigningTimeConverter.java index 559c9fca..c1779fa9 100644 --- a/src/main/java/xades4j/xml/unmarshalling/FromXmlSigningTimeConverter.java +++ b/src/main/java/xades4j/xml/unmarshalling/FromXmlSigningTimeConverter.java @@ -29,8 +29,7 @@ class FromXmlSigningTimeConverter implements SignedSigPropFromXmlConv @Override public void convertFromObjectTree( XmlSignedSignaturePropertiesType xmlProps, - QualifyingPropertiesDataCollector propertyDataCollector) throws PropertyUnmarshalException - { + QualifyingPropertiesDataCollector propertyDataCollector) { Calendar sigTime = xmlProps.getSigningTime(); if (null == sigTime) return; diff --git a/src/main/java/xades4j/xml/unmarshalling/FromXmlUnknownUnsignedSigPropsConverter.java b/src/main/java/xades4j/xml/unmarshalling/FromXmlUnknownUnsignedSigPropsConverter.java index 9589031e..fa8bceb0 100644 --- a/src/main/java/xades4j/xml/unmarshalling/FromXmlUnknownUnsignedSigPropsConverter.java +++ b/src/main/java/xades4j/xml/unmarshalling/FromXmlUnknownUnsignedSigPropsConverter.java @@ -16,11 +16,12 @@ */ package xades4j.xml.unmarshalling; -import java.util.List; import org.w3c.dom.Element; import xades4j.properties.data.GenericDOMData; import xades4j.xml.bind.xades.XmlUnsignedSignaturePropertiesType; +import java.util.List; + /** * * @author Luís @@ -45,7 +46,7 @@ public void convertFromObjectTree( QualifyingPropertiesDataCollector propertyDataCollector) throws PropertyUnmarshalException { List any = xmlProps.getAny(); - if (any.size() > 0 && !this.acceptUnknown) + if (!any.isEmpty() && !this.acceptUnknown) throw new PropertyUnmarshalException("Unknown properties were found", "Unknown"); for (Object anyObj : any) diff --git a/src/main/java/xades4j/xml/unmarshalling/QualifyingPropertyFromDOMConverter.java b/src/main/java/xades4j/xml/unmarshalling/QualifyingPropertyFromDOMConverter.java index 3e5863b1..24b7df5e 100644 --- a/src/main/java/xades4j/xml/unmarshalling/QualifyingPropertyFromDOMConverter.java +++ b/src/main/java/xades4j/xml/unmarshalling/QualifyingPropertyFromDOMConverter.java @@ -25,5 +25,5 @@ interface QualifyingPropertyFromDOMConverter { void convertFromDOMTree(Element props, - QualifyingPropertiesDataCollector propertyDataCollector) throws PropertyUnmarshalException; + QualifyingPropertiesDataCollector propertyDataCollector); } diff --git a/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java b/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java index 08ea9f52..ff505a5c 100644 --- a/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java +++ b/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java @@ -17,24 +17,19 @@ package xades4j.production; import org.apache.xml.security.signature.*; +import org.apache.xml.security.utils.Constants; import org.apache.xml.security.utils.resolver.ResourceResolverContext; -import org.apache.xml.security.utils.resolver.ResourceResolverException; import org.apache.xml.security.utils.resolver.ResourceResolverSpi; -import org.w3c.dom.Element; -import xades4j.algorithms.EnvelopedSignatureTransform; -import org.apache.xml.security.utils.Constants; - -import java.io.ByteArrayInputStream; -import java.util.Map; - import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.w3c.dom.Document; -import xades4j.properties.DataObjectDesc; +import xades4j.algorithms.EnvelopedSignatureTransform; import xades4j.utils.DOMHelper; import xades4j.utils.SignatureServicesTestBase; import xades4j.utils.StringUtils; +import java.io.ByteArrayInputStream; + import static org.junit.jupiter.api.Assertions.*; /** diff --git a/src/test/java/xades4j/production/UncheckedSignerBESTest.java b/src/test/java/xades4j/production/UncheckedSignerBESTest.java index c69f99fe..4d2dd5d5 100644 --- a/src/test/java/xades4j/production/UncheckedSignerBESTest.java +++ b/src/test/java/xades4j/production/UncheckedSignerBESTest.java @@ -16,6 +16,10 @@ */ package xades4j.production; +import org.apache.xml.security.utils.Constants; +import org.junit.jupiter.api.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Element; import xades4j.algorithms.EnvelopedSignatureTransform; import xades4j.algorithms.ExclusiveCanonicalXMLWithoutComments; import xades4j.properties.DataObjectDesc; @@ -24,22 +28,13 @@ import xades4j.providers.KeyingDataProvider; import xades4j.providers.impl.PKIXCertificateValidationProvider; import xades4j.utils.FileSystemDirectoryCertStore; -import xades4j.verification.SignatureSpecificVerificationOptions; -import xades4j.verification.SigningCertificateKeyUsageException; -import xades4j.verification.XAdESForm; -import xades4j.verification.XAdESVerificationResult; -import xades4j.verification.XadesVerificationProfile; +import xades4j.verification.*; import java.io.FileInputStream; import java.security.KeyStore; import java.security.cert.Certificate; import java.security.cert.CertificateFactory; -import org.apache.xml.security.utils.Constants; -import org.junit.jupiter.api.Test; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -99,7 +94,7 @@ private void trySignAndVerify(final KeyingDataProvider signProvider, SignatureSpecificVerificationOptions verifyOpts = new SignatureSpecificVerificationOptions() .checkKeyUsage(verifySignatureKeyUsage); XAdESVerificationResult res = p.newVerifier().verify(sig, verifyOpts); - assertEquals(res.getSignatureForm(), XAdESForm.BES); + assertEquals(XAdESForm.BES, res.getSignatureForm()); } /** From 1d194e94af91a354343edaedbe01c12a440d15f4 Mon Sep 17 00:00:00 2001 From: Mirko Date: Sun, 12 Nov 2023 04:52:28 +0100 Subject: [PATCH 04/14] replace unnecessary explicit type arguments with <> --- .../algorithms/ExclusiveCanonicalXML.java | 2 +- .../algorithms/XPath2FilterTransform.java | 2 +- .../production/DataGenArchiveTimeStamp.java | 2 +- .../production/DataGenCompleteRevocRefs.java | 2 +- .../DataGenIndivDataObjsTimeStamp.java | 2 +- .../production/DataGenSigAndRefsTimeStamp.java | 2 +- .../xades4j/production/EnvelopedManifest.java | 2 +- .../PropertiesDataGenerationContext.java | 4 ++-- .../QualifyingPropertiesProcessor.java | 8 ++++---- .../SignaturePropertiesCollectorImpl.java | 4 ++-- .../xades4j/production/SignedDataObjects.java | 8 ++++---- .../production/SignedDataObjectsProcessor.java | 4 ++-- src/main/java/xades4j/production/SignerBES.java | 4 ++-- .../production/XadesSignatureResult.java | 2 +- .../properties/CommitmentTypeProperty.java | 2 +- .../java/xades4j/properties/DataObjectDesc.java | 4 ++-- .../xades4j/properties/DataObjectProperty.java | 2 +- .../properties/QualifyingProperties.java | 2 +- .../xades4j/properties/SignerRoleProperty.java | 2 +- .../xades4j/properties/UnsignedProperties.java | 2 +- .../properties/data/BaseCertRefsData.java | 4 ++-- .../data/BaseEncapsulatedPKIData.java | 4 ++-- .../properties/data/BaseXAdESTimeStampData.java | 2 +- .../properties/data/CommitmentTypeData.java | 6 ++++-- .../CommitmentTypeDataStructureVerifier.java | 9 +++++---- .../data/CompleteRevocationRefsData.java | 4 ++-- .../data/IndividualDataObjsTimeStampData.java | 2 +- .../PropertiesDataObjectsStructureVerifier.java | 4 ++-- .../DefaultTimeStampVerificationProvider.java | 4 ++-- .../impl/KeyStoreKeyingDataProvider.java | 2 +- .../impl/PKIXCertificateValidationProvider.java | 6 +++--- .../java/xades4j/utils/CollectionUtils.java | 16 ++++++++-------- src/main/java/xades4j/utils/DOMHelper.java | 2 +- src/main/java/xades4j/utils/DataGetterImpl.java | 4 ++-- src/main/java/xades4j/utils/PropertiesSet.java | 6 +++--- .../java/xades4j/utils/PropertiesUtils.java | 2 +- .../xades4j/utils/RFC4519ExtensibleStyle.java | 2 +- .../verification/CompleteRevocRefsVerifier.java | 2 +- .../xades4j/verification/KeyInfoProcessor.java | 2 +- .../QualifPropsDataCollectorImpl.java | 2 +- .../QualifyingPropertiesVerifierImpl.java | 2 +- .../QualifyingPropertyVerificationContext.java | 4 ++-- .../SignatureSpecificVerificationOptions.java | 2 +- .../xades4j/verification/SignatureUtils.java | 4 ++-- .../xades4j/verification/XAdESFormChecker.java | 2 +- .../xades4j/verification/XadesVerifierImpl.java | 8 ++++---- .../java/xades4j/xml/bind/xades/XmlAnyType.java | 4 ++-- .../xades4j/xml/bind/xades/XmlCRLRefsType.java | 2 +- .../xml/bind/xades/XmlCRLValuesType.java | 2 +- .../xml/bind/xades/XmlCertIDListType.java | 2 +- .../bind/xades/XmlCertificateValuesType.java | 2 +- .../bind/xades/XmlCertifiedRolesListType.java | 2 +- .../xml/bind/xades/XmlClaimedRolesListType.java | 2 +- .../xades/XmlCommitmentTypeIndicationType.java | 2 +- .../XmlCommitmentTypeQualifiersListType.java | 2 +- .../xades/XmlDocumentationReferencesType.java | 2 +- .../xml/bind/xades/XmlGenericTimeStampType.java | 6 +++--- .../xml/bind/xades/XmlIntegerListType.java | 2 +- .../xades4j/xml/bind/xades/XmlOCSPRefsType.java | 2 +- .../xml/bind/xades/XmlOCSPValuesType.java | 2 +- .../bind/xades/XmlOtherCertStatusRefsType.java | 2 +- .../xades/XmlOtherCertStatusValuesType.java | 2 +- .../xades/XmlSigPolicyQualifiersListType.java | 2 +- .../XmlSignedDataObjectPropertiesType.java | 8 ++++---- .../XmlUnsignedDataObjectPropertiesType.java | 2 +- .../XmlUnsignedSignaturePropertiesType.java | 12 ++++++------ .../xmldsig/XmlCanonicalizationMethodType.java | 2 +- .../xml/bind/xmldsig/XmlDigestMethodType.java | 2 +- .../xml/bind/xmldsig/XmlKeyInfoType.java | 2 +- .../xml/bind/xmldsig/XmlKeyValueType.java | 2 +- .../xml/bind/xmldsig/XmlManifestType.java | 2 +- .../xades4j/xml/bind/xmldsig/XmlObjectType.java | 2 +- .../xml/bind/xmldsig/XmlPGPDataType.java | 2 +- .../xml/bind/xmldsig/XmlSPKIDataType.java | 2 +- .../bind/xmldsig/XmlSignatureMethodType.java | 2 +- .../xmldsig/XmlSignaturePropertiesType.java | 2 +- .../bind/xmldsig/XmlSignaturePropertyType.java | 2 +- .../xml/bind/xmldsig/XmlSignatureType.java | 2 +- .../xml/bind/xmldsig/XmlSignedInfoType.java | 2 +- .../xml/bind/xmldsig/XmlTransformType.java | 2 +- .../xml/bind/xmldsig/XmlTransformsType.java | 2 +- .../xml/bind/xmldsig/XmlX509DataType.java | 2 +- .../xml/marshalling/BaseJAXBMarshaller.java | 17 +++++++++-------- .../ToXmlSignaturePolicyConverter.java | 2 +- .../AlgorithmParametersBindingsModule.java | 6 ++---- .../GenericAlgorithmParamsMarshaller.java | 2 +- .../XPath2FilterTransformParamsMarshaller.java | 2 +- .../FromXmlSignerRoleConverter.java | 2 +- .../xades4j/xml/unmarshalling/FromXmlUtils.java | 2 +- .../xml/unmarshalling/UnmarshallerModule.java | 7 ++++--- ...msParametersMarshallingProviderImplTest.java | 15 ++++----------- 91 files changed, 157 insertions(+), 161 deletions(-) diff --git a/src/main/java/xades4j/algorithms/ExclusiveCanonicalXML.java b/src/main/java/xades4j/algorithms/ExclusiveCanonicalXML.java index 756d4989..f22959c1 100644 --- a/src/main/java/xades4j/algorithms/ExclusiveCanonicalXML.java +++ b/src/main/java/xades4j/algorithms/ExclusiveCanonicalXML.java @@ -33,7 +33,7 @@ public abstract class ExclusiveCanonicalXML extends Algorithm{ protected ExclusiveCanonicalXML(String uri, String... inclusiveNamespacePrefixes) { - this(uri, new HashSet(Arrays.asList(inclusiveNamespacePrefixes))); + this(uri, new HashSet<>(Arrays.asList(inclusiveNamespacePrefixes))); } protected ExclusiveCanonicalXML(String uri, Set inclusiveNamespacePrefixes) diff --git a/src/main/java/xades4j/algorithms/XPath2FilterTransform.java b/src/main/java/xades4j/algorithms/XPath2FilterTransform.java index 0f65b499..0705b649 100644 --- a/src/main/java/xades4j/algorithms/XPath2FilterTransform.java +++ b/src/main/java/xades4j/algorithms/XPath2FilterTransform.java @@ -117,7 +117,7 @@ public static XPath2FilterTransform union(String xpath) private XPath2FilterTransform() { super(Transforms.TRANSFORM_XPATH2FILTER); - this.filters = new ArrayList(2); + this.filters = new ArrayList<>(2); } /** diff --git a/src/main/java/xades4j/production/DataGenArchiveTimeStamp.java b/src/main/java/xades4j/production/DataGenArchiveTimeStamp.java index 4790a3e7..635dccea 100644 --- a/src/main/java/xades4j/production/DataGenArchiveTimeStamp.java +++ b/src/main/java/xades4j/production/DataGenArchiveTimeStamp.java @@ -94,7 +94,7 @@ protected void addPropSpecificTimeStampInput( digestInput.addNode(ki.getElement()); // Unsigned properties, in order of appearance. - Map propsCnt = new HashMap(5); + Map propsCnt = new HashMap<>(5); propsCnt.put(CertificateValuesProperty.PROP_NAME, 0); propsCnt.put(RevocationValuesProperty.PROP_NAME, 0); propsCnt.put(CompleteCertificateRefsProperty.PROP_NAME, 0); diff --git a/src/main/java/xades4j/production/DataGenCompleteRevocRefs.java b/src/main/java/xades4j/production/DataGenCompleteRevocRefs.java index 32faaef9..44e28643 100644 --- a/src/main/java/xades4j/production/DataGenCompleteRevocRefs.java +++ b/src/main/java/xades4j/production/DataGenCompleteRevocRefs.java @@ -61,7 +61,7 @@ public PropertyDataObject generatePropertyData( PropertiesDataGenerationContext ctx) throws PropertyDataGenerationException { Collection crls = prop.getCrls(); - Collection crlRefs = new ArrayList(crls.size()); + Collection crlRefs = new ArrayList<>(crls.size()); String digestAlgUri = this.signatureAlgorithms.getDigestAlgorithmForReferenceProperties(); try diff --git a/src/main/java/xades4j/production/DataGenIndivDataObjsTimeStamp.java b/src/main/java/xades4j/production/DataGenIndivDataObjsTimeStamp.java index 5f2d79c6..645cd1f3 100644 --- a/src/main/java/xades4j/production/DataGenIndivDataObjsTimeStamp.java +++ b/src/main/java/xades4j/production/DataGenIndivDataObjsTimeStamp.java @@ -70,7 +70,7 @@ protected BaseXAdESTimeStampData createPropDataObj( { Collection targetDataObjs = prop.getTargetDataObjects(); - List includes = new ArrayList(targetDataObjs.size()); + List includes = new ArrayList<>(targetDataObjs.size()); for (DataObjectDesc dataObj : targetDataObjs) { Reference r = ctx.getReference(dataObj); diff --git a/src/main/java/xades4j/production/DataGenSigAndRefsTimeStamp.java b/src/main/java/xades4j/production/DataGenSigAndRefsTimeStamp.java index 84cd95d6..007cb555 100644 --- a/src/main/java/xades4j/production/DataGenSigAndRefsTimeStamp.java +++ b/src/main/java/xades4j/production/DataGenSigAndRefsTimeStamp.java @@ -72,7 +72,7 @@ protected void addPropSpecificTimeStampInput( * "Those (...) that appear before SigAndRefsTimeStamp, in their order of * appearance within the UnsignedSignatureProperties element." */ - Map elegiblePropsCnt = new HashMap(5); + Map elegiblePropsCnt = new HashMap<>(5); elegiblePropsCnt.put(CompleteCertificateRefsProperty.PROP_NAME, 0); elegiblePropsCnt.put(CompleteRevocationRefsProperty.PROP_NAME, 0); elegiblePropsCnt.put(SignatureTimeStampProperty.PROP_NAME, 0); diff --git a/src/main/java/xades4j/production/EnvelopedManifest.java b/src/main/java/xades4j/production/EnvelopedManifest.java index 53b6b52d..57682b86 100644 --- a/src/main/java/xades4j/production/EnvelopedManifest.java +++ b/src/main/java/xades4j/production/EnvelopedManifest.java @@ -37,7 +37,7 @@ public final class EnvelopedManifest extends DataObjectDesc public EnvelopedManifest() { - this.dataObjs = new LinkedHashSet(2); + this.dataObjs = new LinkedHashSet<>(2); } /** diff --git a/src/main/java/xades4j/production/PropertiesDataGenerationContext.java b/src/main/java/xades4j/production/PropertiesDataGenerationContext.java index b818e96e..0b84f96f 100644 --- a/src/main/java/xades4j/production/PropertiesDataGenerationContext.java +++ b/src/main/java/xades4j/production/PropertiesDataGenerationContext.java @@ -56,7 +56,7 @@ public final class PropertiesDataGenerationContext this.referencesMappings = null; SignedInfo signedInfo = targetXmlSignature.getSignedInfo(); - List refs = new ArrayList(signedInfo.getLength()); + List refs = new ArrayList<>(signedInfo.getLength()); for (int i = 0; i < signedInfo.getLength(); i++) { try @@ -84,7 +84,7 @@ public final class PropertiesDataGenerationContext this.referencesMappings = referencesMappings; this.sigDocument = sigDocument; - List orderedRefs = new ArrayList(orderedDataObjs.size()); + List orderedRefs = new ArrayList<>(orderedDataObjs.size()); for (DataObjectDesc dataObjDesc : orderedDataObjs) { orderedRefs.add(referencesMappings.get(dataObjDesc)); diff --git a/src/main/java/xades4j/production/QualifyingPropertiesProcessor.java b/src/main/java/xades4j/production/QualifyingPropertiesProcessor.java index 51a2f005..6daf142a 100644 --- a/src/main/java/xades4j/production/QualifyingPropertiesProcessor.java +++ b/src/main/java/xades4j/production/QualifyingPropertiesProcessor.java @@ -61,13 +61,13 @@ QualifyingProperties getQualifyingProperties( sigPropsProvider.provideProperties(signaturePropsCollector); Collection collectedSignedSigProps = signaturePropsCollector.getSignedSigProps(); - Collection signedSigProps = new ArrayList( + Collection signedSigProps = new ArrayList<>( collectedSignedSigProps.size() + formatSpecificSignedSigProps.size()); signedSigProps.addAll(collectedSignedSigProps); signedSigProps.addAll(formatSpecificSignedSigProps); Collection collectedUnsignedSigProps = signaturePropsCollector.getUnsignedSigProps(); - Collection unsignedSigProps = new ArrayList( + Collection unsignedSigProps = new ArrayList<>( collectedUnsignedSigProps.size() + formatSpecificUnsignedSigProps.size()); unsignedSigProps.addAll(collectedUnsignedSigProps); unsignedSigProps.addAll(formatSpecificUnsignedSigProps); @@ -79,8 +79,8 @@ QualifyingProperties getQualifyingProperties( // The containers for all the specified signed data object properties. Since // some properties can be applied to multiple data objects, we need to rule // out repeated references (a Set is used). - Set signedDataObjProps = new HashSet(dataObjsInfo.size()); - Set unsignedDataObjProps = new HashSet(0); + Set signedDataObjProps = new HashSet<>(dataObjsInfo.size()); + Set unsignedDataObjProps = new HashSet<>(0); // Add the global data object properties. signedDataObjProps.addAll(dataObjs.getSignedDataObjsProperties()); diff --git a/src/main/java/xades4j/production/SignaturePropertiesCollectorImpl.java b/src/main/java/xades4j/production/SignaturePropertiesCollectorImpl.java index bb03c5b6..0b05f5f5 100644 --- a/src/main/java/xades4j/production/SignaturePropertiesCollectorImpl.java +++ b/src/main/java/xades4j/production/SignaturePropertiesCollectorImpl.java @@ -39,8 +39,8 @@ class SignaturePropertiesCollectorImpl implements SignaturePropertiesCollector public SignaturePropertiesCollectorImpl() { - this.signedSigProps = new PropertiesSet(2); - this.unsignedSigProps = new PropertiesSet(0); + this.signedSigProps = new PropertiesSet<>(2); + this.unsignedSigProps = new PropertiesSet<>(0); } /***** Signed signature properties *****/ diff --git a/src/main/java/xades4j/production/SignedDataObjects.java b/src/main/java/xades4j/production/SignedDataObjects.java index 42b36b35..33c02463 100644 --- a/src/main/java/xades4j/production/SignedDataObjects.java +++ b/src/main/java/xades4j/production/SignedDataObjects.java @@ -67,13 +67,13 @@ public final class SignedDataObjects */ public SignedDataObjects() { - this.dataObjs = new ArrayList(); + this.dataObjs = new ArrayList<>(); this.baseUriForRelativeReferences = null; this.hasNullURIReference = false; - this.resourceResolvers = new ArrayList(0); + this.resourceResolvers = new ArrayList<>(0); - this.signedDataObjsProperties = new PropertiesSet(0); - this.unsignedDataObjsProperties = new PropertiesSet(0); + this.signedDataObjsProperties = new PropertiesSet<>(0); + this.unsignedDataObjsProperties = new PropertiesSet<>(0); } /** diff --git a/src/main/java/xades4j/production/SignedDataObjectsProcessor.java b/src/main/java/xades4j/production/SignedDataObjectsProcessor.java index ffcf3a0b..434ba736 100644 --- a/src/main/java/xades4j/production/SignedDataObjectsProcessor.java +++ b/src/main/java/xades4j/production/SignedDataObjectsProcessor.java @@ -92,8 +92,8 @@ private SignedDataObjectsProcessor.Result process( List resourceResolvers, XMLSignature xmlSignature, boolean hasNullURIReference) throws UnsupportedAlgorithmException { - Map referenceMappings = new IdentityHashMap(dataObjects.size()); - Set manifests = new HashSet(); + Map referenceMappings = new IdentityHashMap<>(dataObjects.size()); + Set manifests = new HashSet<>(); for (ResourceResolverSpi resolver : resourceResolvers) { diff --git a/src/main/java/xades4j/production/SignerBES.java b/src/main/java/xades4j/production/SignerBES.java index e6669c16..2ad614e7 100644 --- a/src/main/java/xades4j/production/SignerBES.java +++ b/src/main/java/xades4j/production/SignerBES.java @@ -197,8 +197,8 @@ public final XadesSignatureResult sign( /* Collect the properties */ // Get the format specific signature properties. - Collection fsssp = new ArrayList(2); - Collection fsusp = new ArrayList(2); + Collection fsssp = new ArrayList<>(2); + Collection fsusp = new ArrayList<>(2); getFormatSpecificSignatureProperties(fsssp, fsusp, signingCertificateChain); // Gather all the signature and data objects properties. QualifyingProperties qualifProps = qualifPropsProcessor.getQualifyingProperties( diff --git a/src/main/java/xades4j/production/XadesSignatureResult.java b/src/main/java/xades4j/production/XadesSignatureResult.java index c6e6d052..1607d52b 100644 --- a/src/main/java/xades4j/production/XadesSignatureResult.java +++ b/src/main/java/xades4j/production/XadesSignatureResult.java @@ -39,7 +39,7 @@ public class XadesSignatureResult { this.signature = signature; this.qualifyingProperties = qualifyingProperties; - this.propertyFilter = new DataGetterImpl(qualifyingProperties.all()); + this.propertyFilter = new DataGetterImpl<>(qualifyingProperties.all()); } /** diff --git a/src/main/java/xades4j/properties/CommitmentTypeProperty.java b/src/main/java/xades4j/properties/CommitmentTypeProperty.java index 4dea37d8..f57be34c 100644 --- a/src/main/java/xades4j/properties/CommitmentTypeProperty.java +++ b/src/main/java/xades4j/properties/CommitmentTypeProperty.java @@ -100,6 +100,6 @@ public static CommitmentTypeProperty proofOfCreation() */ public CommitmentTypeProperty(String uri, String description) { - super(uri, description, SignedDataObjectProperty.TargetMultiplicity.N); + super(uri, description, DataObjectProperty.TargetMultiplicity.N); } } diff --git a/src/main/java/xades4j/properties/DataObjectDesc.java b/src/main/java/xades4j/properties/DataObjectDesc.java index 610b114e..4822d5f4 100644 --- a/src/main/java/xades4j/properties/DataObjectDesc.java +++ b/src/main/java/xades4j/properties/DataObjectDesc.java @@ -45,8 +45,8 @@ public abstract class DataObjectDesc protected DataObjectDesc() { - signedDataObjProps = new PropertiesSet(2); - unsignedDataObjProps = new PropertiesSet(0); + signedDataObjProps = new PropertiesSet<>(2); + unsignedDataObjProps = new PropertiesSet<>(0); } /** diff --git a/src/main/java/xades4j/properties/DataObjectProperty.java b/src/main/java/xades4j/properties/DataObjectProperty.java index a83d2da8..1360b987 100644 --- a/src/main/java/xades4j/properties/DataObjectProperty.java +++ b/src/main/java/xades4j/properties/DataObjectProperty.java @@ -72,7 +72,7 @@ protected DataObjectProperty(TargetMultiplicity targetMultiplicity) throw new NullPointerException("Target multiplicity cannot be null"); this.targetMultiplicity = targetMultiplicity; - this.targetDataObjs = new HashSet(targetMultiplicity.initialSize); + this.targetDataObjs = new HashSet<>(targetMultiplicity.initialSize); } @Override diff --git a/src/main/java/xades4j/properties/QualifyingProperties.java b/src/main/java/xades4j/properties/QualifyingProperties.java index 5bbbb824..3fb586eb 100644 --- a/src/main/java/xades4j/properties/QualifyingProperties.java +++ b/src/main/java/xades4j/properties/QualifyingProperties.java @@ -52,7 +52,7 @@ public Collection all() { if (null == allProperties) { - allProperties = new ArrayList(signedProperties.getSigProps()); + allProperties = new ArrayList<>(signedProperties.getSigProps()); allProperties.addAll(signedProperties.getDataObjProps()); allProperties.addAll(unsignedProperties.getSigProps()); allProperties.addAll(unsignedProperties.getDataObjProps()); diff --git a/src/main/java/xades4j/properties/SignerRoleProperty.java b/src/main/java/xades4j/properties/SignerRoleProperty.java index 504cf9ec..4bb25b0d 100644 --- a/src/main/java/xades4j/properties/SignerRoleProperty.java +++ b/src/main/java/xades4j/properties/SignerRoleProperty.java @@ -37,7 +37,7 @@ public final class SignerRoleProperty extends SignedSignatureProperty public SignerRoleProperty() { - this.claimedRoles = new HashSet(); + this.claimedRoles = new HashSet<>(); } public SignerRoleProperty(String... claimedRoles) diff --git a/src/main/java/xades4j/properties/UnsignedProperties.java b/src/main/java/xades4j/properties/UnsignedProperties.java index 17eb352e..4092dc30 100644 --- a/src/main/java/xades4j/properties/UnsignedProperties.java +++ b/src/main/java/xades4j/properties/UnsignedProperties.java @@ -35,6 +35,6 @@ public UnsignedProperties( public UnsignedProperties(Collection sigProps) { - super(sigProps, new ArrayList(0)); + super(sigProps, new ArrayList<>(0)); } } diff --git a/src/main/java/xades4j/properties/data/BaseCertRefsData.java b/src/main/java/xades4j/properties/data/BaseCertRefsData.java index e8aa680b..65880142 100644 --- a/src/main/java/xades4j/properties/data/BaseCertRefsData.java +++ b/src/main/java/xades4j/properties/data/BaseCertRefsData.java @@ -29,12 +29,12 @@ public class BaseCertRefsData implements PropertyDataObject protected BaseCertRefsData(Collection certRefs) { - this.certRefs = new ArrayList(certRefs); + this.certRefs = new ArrayList<>(certRefs); } public BaseCertRefsData() { - this.certRefs = new ArrayList(3); + this.certRefs = new ArrayList<>(3); } public void addCertRef(CertRef ref) diff --git a/src/main/java/xades4j/properties/data/BaseEncapsulatedPKIData.java b/src/main/java/xades4j/properties/data/BaseEncapsulatedPKIData.java index a6f1d497..3535af6e 100644 --- a/src/main/java/xades4j/properties/data/BaseEncapsulatedPKIData.java +++ b/src/main/java/xades4j/properties/data/BaseEncapsulatedPKIData.java @@ -30,12 +30,12 @@ public class BaseEncapsulatedPKIData implements PropertyDataObject public BaseEncapsulatedPKIData(Collection data) { - this.data = new ArrayList(data); + this.data = new ArrayList<>(data); } public BaseEncapsulatedPKIData() { - this.data = new ArrayList(3); + this.data = new ArrayList<>(3); } public void addData(byte[] d) diff --git a/src/main/java/xades4j/properties/data/BaseXAdESTimeStampData.java b/src/main/java/xades4j/properties/data/BaseXAdESTimeStampData.java index e887c8aa..20438abf 100644 --- a/src/main/java/xades4j/properties/data/BaseXAdESTimeStampData.java +++ b/src/main/java/xades4j/properties/data/BaseXAdESTimeStampData.java @@ -42,7 +42,7 @@ protected BaseXAdESTimeStampData(Algorithm c14n, byte[] tsToken) protected BaseXAdESTimeStampData(Algorithm c14n) { this.c14n = c14n; - this.timeStampTokens = new ArrayList(1); + this.timeStampTokens = new ArrayList<>(1); } /** diff --git a/src/main/java/xades4j/properties/data/CommitmentTypeData.java b/src/main/java/xades4j/properties/data/CommitmentTypeData.java index b3d2ebbd..f2c7ab45 100644 --- a/src/main/java/xades4j/properties/data/CommitmentTypeData.java +++ b/src/main/java/xades4j/properties/data/CommitmentTypeData.java @@ -16,16 +16,18 @@ */ package xades4j.properties.data; -import java.util.Collection; import xades4j.utils.CollectionUtils; +import java.util.Collection; + /** * * @author Luís */ public final class CommitmentTypeData implements PropertyDataObject { - private String description, uri; + private String description; + private String uri; private Collection objReferences; private Collection qualifiers; diff --git a/src/main/java/xades4j/properties/data/CommitmentTypeDataStructureVerifier.java b/src/main/java/xades4j/properties/data/CommitmentTypeDataStructureVerifier.java index 4e955fa1..8607e262 100644 --- a/src/main/java/xades4j/properties/data/CommitmentTypeDataStructureVerifier.java +++ b/src/main/java/xades4j/properties/data/CommitmentTypeDataStructureVerifier.java @@ -16,10 +16,11 @@ */ package xades4j.properties.data; -import java.util.Collection; -import xades4j.properties.CommitmentTypeProperty; +import xades4j.properties.CommitmentTypePropertyBase; import xades4j.utils.StringUtils; +import java.util.Collection; + /** * * @author Luís @@ -32,10 +33,10 @@ public void verifyStructure(PropertyDataObject propData) throws PropertyDataStru CommitmentTypeData commTypeData = (CommitmentTypeData)propData; if (StringUtils.isNullOrEmptyString(commTypeData.getUri())) - throw new PropertyDataStructureException("null URI", CommitmentTypeProperty.PROP_NAME); + throw new PropertyDataStructureException("null URI", CommitmentTypePropertyBase.PROP_NAME); Collection objReferences = commTypeData.getObjReferences(); if (objReferences != null && objReferences.isEmpty()) - throw new PropertyDataStructureException("Object references is empty", CommitmentTypeProperty.PROP_NAME); + throw new PropertyDataStructureException("Object references is empty", CommitmentTypePropertyBase.PROP_NAME); } } diff --git a/src/main/java/xades4j/properties/data/CompleteRevocationRefsData.java b/src/main/java/xades4j/properties/data/CompleteRevocationRefsData.java index dd9dcf3b..8c110e21 100644 --- a/src/main/java/xades4j/properties/data/CompleteRevocationRefsData.java +++ b/src/main/java/xades4j/properties/data/CompleteRevocationRefsData.java @@ -29,12 +29,12 @@ public final class CompleteRevocationRefsData implements PropertyDataObject public CompleteRevocationRefsData(Collection crlRefs) { - this.crlRefs = new ArrayList(crlRefs); + this.crlRefs = new ArrayList<>(crlRefs); } public CompleteRevocationRefsData() { - this.crlRefs = new ArrayList(3); + this.crlRefs = new ArrayList<>(3); } public void addCRLRef(CRLRef ref) diff --git a/src/main/java/xades4j/properties/data/IndividualDataObjsTimeStampData.java b/src/main/java/xades4j/properties/data/IndividualDataObjsTimeStampData.java index ebea4e28..023e62f0 100644 --- a/src/main/java/xades4j/properties/data/IndividualDataObjsTimeStampData.java +++ b/src/main/java/xades4j/properties/data/IndividualDataObjsTimeStampData.java @@ -44,7 +44,7 @@ public IndividualDataObjsTimeStampData( public IndividualDataObjsTimeStampData(Algorithm c14n) { super(c14n); - this.includes = new ArrayList(3); + this.includes = new ArrayList<>(3); } public void addInclude(String inc) diff --git a/src/main/java/xades4j/properties/data/PropertiesDataObjectsStructureVerifier.java b/src/main/java/xades4j/properties/data/PropertiesDataObjectsStructureVerifier.java index 77a3154c..d9005d6b 100644 --- a/src/main/java/xades4j/properties/data/PropertiesDataObjectsStructureVerifier.java +++ b/src/main/java/xades4j/properties/data/PropertiesDataObjectsStructureVerifier.java @@ -38,7 +38,7 @@ public class PropertiesDataObjectsStructureVerifier static { - structureVerifiers = new HashMap, PropertyDataObjectStructureVerifier>(10); + structureVerifiers = new HashMap<>(10); structureVerifiers.put(CommitmentTypeData.class, new CommitmentTypeDataStructureVerifier()); @@ -119,7 +119,7 @@ public void verifiyPropertiesDataStructure( if (customGlobalVerifiers.isEmpty()) return; - DataGetter dataGetter = new DataGetterImpl(propsData); + DataGetter dataGetter = new DataGetterImpl<>(propsData); for (CustomPropertiesDataObjsStructureVerifier customVer : customGlobalVerifiers) { diff --git a/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java b/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java index b61825db..e64bbeac 100644 --- a/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java +++ b/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java @@ -56,7 +56,7 @@ public class DefaultTimeStampVerificationProvider implements TimeStampVerificati static { - digestOidToUriMappings = new HashMap(5); + digestOidToUriMappings = new HashMap<>(5); digestOidToUriMappings.put(TSPAlgorithms.MD5, MessageDigestAlgorithm.ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5); digestOidToUriMappings.put(TSPAlgorithms.RIPEMD160, MessageDigestAlgorithm.ALGO_ID_DIGEST_RIPEMD160); digestOidToUriMappings.put(TSPAlgorithms.SHA1, MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA1); @@ -112,7 +112,7 @@ public Date verifyToken(byte[] timeStampToken, byte[] tsDigestInput) throws Time try { /* Validate the TSA certificate */ - LinkedList certs = new LinkedList(); + LinkedList certs = new LinkedList<>(); for (Object certHolder : tsToken.getCertificates().getMatches(new AllCertificatesSelector())) { certs.add(this.x509CertificateConverter.getCertificate((X509CertificateHolder) certHolder)); diff --git a/src/main/java/xades4j/providers/impl/KeyStoreKeyingDataProvider.java b/src/main/java/xades4j/providers/impl/KeyStoreKeyingDataProvider.java index 1219fdbf..1fc954b3 100644 --- a/src/main/java/xades4j/providers/impl/KeyStoreKeyingDataProvider.java +++ b/src/main/java/xades4j/providers/impl/KeyStoreKeyingDataProvider.java @@ -211,7 +211,7 @@ public List getSigningCertificateChain() throws SigningCertChai ensureInitialized(); try { - List availableSignCerts = new ArrayList(keyStore.size()); + List availableSignCerts = new ArrayList<>(keyStore.size()); for (Enumeration aliases = keyStore.aliases(); aliases.hasMoreElements(); ) { diff --git a/src/main/java/xades4j/providers/impl/PKIXCertificateValidationProvider.java b/src/main/java/xades4j/providers/impl/PKIXCertificateValidationProvider.java index 389221c8..17fa625b 100644 --- a/src/main/java/xades4j/providers/impl/PKIXCertificateValidationProvider.java +++ b/src/main/java/xades4j/providers/impl/PKIXCertificateValidationProvider.java @@ -135,7 +135,7 @@ public ValidationData validate( // verification. List certPath = (List) builderRes.getCertPath().getCertificates(); // - Create a new list since the previous is immutable. - certPath = new ArrayList(certPath); + certPath = new ArrayList<>(certPath); // - Add the trust anchor certificate. certPath.add(builderRes.getTrustAnchor().getTrustedCert()); @@ -152,7 +152,7 @@ private Collection getCRLsForCertPath( { // Map the issuers certificates in the chain. This is used to know the issuers // and later to verify the signatures in the CRLs. - Map issuersCerts = new HashMap(certPath.size() - 1); + Map issuersCerts = new HashMap<>(certPath.size() - 1); for (int i = 0; i < certPath.size() - 1; i++) { // The issuer of one certificate is the subject of the following one. @@ -173,7 +173,7 @@ private Collection getCRLsForCertPath( // nextUpdate component." crlSelector.setDateAndTime(validationDate); - Set crls = new HashSet(); + Set crls = new HashSet<>(); try { // Get the CRLs on each CertStore. diff --git a/src/main/java/xades4j/utils/CollectionUtils.java b/src/main/java/xades4j/utils/CollectionUtils.java index 0b189038..ba16eba4 100644 --- a/src/main/java/xades4j/utils/CollectionUtils.java +++ b/src/main/java/xades4j/utils/CollectionUtils.java @@ -34,7 +34,7 @@ public class CollectionUtils public static Collection newIfNull(Collection c, int size) { if (null == c) - c = new ArrayList(size); + c = new ArrayList<>(size); return c; } @@ -48,7 +48,7 @@ public static Map newIfNull( Map m, int size) { if (null == m) - m = new HashMap(size); + m = new HashMap<>(size); return m; } @@ -87,18 +87,18 @@ public static Map emptyIfNull(Map m) public static Collection cloneOrEmptyIfNull(Collection c) { if (null == c) - c = new ArrayList(0); + c = new ArrayList<>(0); else - c = new ArrayList(c); + c = new ArrayList<>(c); return c; } public static Map cloneOrEmptyIfNull(Map m) { if (null == m) - m = new HashMap(0); + m = new HashMap<>(0); else - m = new HashMap(m); + m = new HashMap<>(m); return m; } @@ -119,7 +119,7 @@ public interface Predicate public static List filter(Collection c, Predicate p) { - List filtered = new ArrayList(); + List filtered = new ArrayList<>(); for (T e : c) { if (p.verifiedBy(e)) @@ -137,7 +137,7 @@ public static List project( Collection c, Projector p) { - List projected = new ArrayList(); + List projected = new ArrayList<>(); for (TSrc e : c) { projected.add(p.project(e)); diff --git a/src/main/java/xades4j/utils/DOMHelper.java b/src/main/java/xades4j/utils/DOMHelper.java index 373337a8..bb332500 100644 --- a/src/main/java/xades4j/utils/DOMHelper.java +++ b/src/main/java/xades4j/utils/DOMHelper.java @@ -166,7 +166,7 @@ public static Element getFirstDescendant( public static Collection getChildElementsByTagNameNS(Element e, String namespaceURI, String localName) { Node node = e.getFirstChild(); - Collection elements = new ArrayList(); + Collection elements = new ArrayList<>(); while (node != null) { diff --git a/src/main/java/xades4j/utils/DataGetterImpl.java b/src/main/java/xades4j/utils/DataGetterImpl.java index fdf65bc1..b99fdde3 100644 --- a/src/main/java/xades4j/utils/DataGetterImpl.java +++ b/src/main/java/xades4j/utils/DataGetterImpl.java @@ -37,11 +37,11 @@ public DataGetterImpl(Collection all) private Map> getAllByType(Collection all) { - Map> res = new HashMap>(); + Map> res = new HashMap<>(); for (T e : all) { - Set typeTs = res.computeIfAbsent(e.getClass(), k -> new HashSet()); + Set typeTs = res.computeIfAbsent(e.getClass(), k -> new HashSet<>()); typeTs.add(e); } return res; diff --git a/src/main/java/xades4j/utils/PropertiesSet.java b/src/main/java/xades4j/utils/PropertiesSet.java index bd108c11..2d708e2e 100644 --- a/src/main/java/xades4j/utils/PropertiesSet.java +++ b/src/main/java/xades4j/utils/PropertiesSet.java @@ -37,7 +37,7 @@ public class PropertiesSet */ public PropertiesSet(int initialNPropTypes) { - this.properties = new HashMap>(initialNPropTypes); + this.properties = new HashMap<>(initialNPropTypes); } /** @@ -79,7 +79,7 @@ public void add(T prop) if (null == prop) throw new NullPointerException("Property cannot be null"); - Set propsOfCurrType = properties.computeIfAbsent(prop.getClass(), k -> new HashSet(1)); + Set propsOfCurrType = properties.computeIfAbsent(prop.getClass(), k -> new HashSet<>(1)); // No properties of this type have been added. // Repeated instances are not allowed. if (!propsOfCurrType.add(prop)) @@ -127,7 +127,7 @@ public Collection getProperties() if (properties.isEmpty()) return Collections.emptyList(); - Collection props = new ArrayList(properties.size() + 3); + Collection props = new ArrayList<>(properties.size() + 3); for (Set propsOfType : properties.values()) { props.addAll(propsOfType); diff --git a/src/main/java/xades4j/utils/PropertiesUtils.java b/src/main/java/xades4j/utils/PropertiesUtils.java index c8184a83..14dbde62 100644 --- a/src/main/java/xades4j/utils/PropertiesUtils.java +++ b/src/main/java/xades4j/utils/PropertiesUtils.java @@ -65,7 +65,7 @@ public static void addXadesCProperties( { // Remove the leaf certificate. List caCerts = vData.getCerts(); - caCerts = new ArrayList(caCerts.subList(1, caCerts.size())); + caCerts = new ArrayList<>(caCerts.subList(1, caCerts.size())); usp.add(new CompleteCertificateRefsProperty(caCerts)); usp.add(new CompleteRevocationRefsProperty(vData.getCrls())); diff --git a/src/main/java/xades4j/utils/RFC4519ExtensibleStyle.java b/src/main/java/xades4j/utils/RFC4519ExtensibleStyle.java index d1afb82d..58464761 100644 --- a/src/main/java/xades4j/utils/RFC4519ExtensibleStyle.java +++ b/src/main/java/xades4j/utils/RFC4519ExtensibleStyle.java @@ -57,7 +57,7 @@ public void addSymbol(String oid, String... names) private void updateKeyWordsMap() { Set> es = defaultLookUp.entrySet(); - Map tmpMap = new HashMap(); + Map tmpMap = new HashMap<>(); for(Map.Entry e : es){ tmpMap.put(e.getKey().toUpperCase(), e.getValue().getId()); } diff --git a/src/main/java/xades4j/verification/CompleteRevocRefsVerifier.java b/src/main/java/xades4j/verification/CompleteRevocRefsVerifier.java index 61d8db66..2b604d6a 100644 --- a/src/main/java/xades4j/verification/CompleteRevocRefsVerifier.java +++ b/src/main/java/xades4j/verification/CompleteRevocRefsVerifier.java @@ -58,7 +58,7 @@ public QualifyingProperty verify( QualifyingPropertyVerificationContext ctx) throws InvalidPropertyException { Collection crls = ctx.getCertChainData().getCrls(); - Collection crlRefs = new ArrayList(propData.getCrlRefs()); + Collection crlRefs = new ArrayList<>(propData.getCrlRefs()); if(crls.isEmpty()) throw new CompleteRevocRefsCRLsNotAvailableException(); diff --git a/src/main/java/xades4j/verification/KeyInfoProcessor.java b/src/main/java/xades4j/verification/KeyInfoProcessor.java index 8ea78926..67849052 100644 --- a/src/main/java/xades4j/verification/KeyInfoProcessor.java +++ b/src/main/java/xades4j/verification/KeyInfoProcessor.java @@ -74,7 +74,7 @@ static KeyInfoRes process( return tryUseSigningCertificateReference(signingCertRef, x500NameStyleProvider); } - List keyInfoCerts = new ArrayList(1); + List keyInfoCerts = new ArrayList<>(1); XMLX509IssuerSerial issuerSerial = null; X509CertSelector certSelector = new X509CertSelector(); diff --git a/src/main/java/xades4j/verification/QualifPropsDataCollectorImpl.java b/src/main/java/xades4j/verification/QualifPropsDataCollectorImpl.java index 2388450e..c2ccbb61 100644 --- a/src/main/java/xades4j/verification/QualifPropsDataCollectorImpl.java +++ b/src/main/java/xades4j/verification/QualifPropsDataCollectorImpl.java @@ -45,7 +45,7 @@ class QualifPropsDataCollectorImpl implements QualifyingPropertiesDataCollector public QualifPropsDataCollectorImpl() { - propsData = new PropertiesSet(1); + propsData = new PropertiesSet<>(1); } @Override diff --git a/src/main/java/xades4j/verification/QualifyingPropertiesVerifierImpl.java b/src/main/java/xades4j/verification/QualifyingPropertiesVerifierImpl.java index be661121..af034be3 100644 --- a/src/main/java/xades4j/verification/QualifyingPropertiesVerifierImpl.java +++ b/src/main/java/xades4j/verification/QualifyingPropertiesVerifierImpl.java @@ -50,7 +50,7 @@ public Collection verifyProperties( { dataObjectsStructureVerifier.verifiyPropertiesDataStructure(unmarshalledProperties); - Collection props = new ArrayList(unmarshalledProperties.size()); + Collection props = new ArrayList<>(unmarshalledProperties.size()); for (PropertyDataObject propData : unmarshalledProperties) { diff --git a/src/main/java/xades4j/verification/QualifyingPropertyVerificationContext.java b/src/main/java/xades4j/verification/QualifyingPropertyVerificationContext.java index 95db230c..bddcbe4b 100644 --- a/src/main/java/xades4j/verification/QualifyingPropertyVerificationContext.java +++ b/src/main/java/xades4j/verification/QualifyingPropertyVerificationContext.java @@ -146,7 +146,7 @@ public static class SignedObjectsData this.signatureDoc = signature.getDocument(); // Map elements to References. - this.references = new HashMap(references.size()); + this.references = new HashMap<>(references.size()); for (RawDataObjectDesc obj : references) { this.references.put(obj.getReference().getElement(), obj); @@ -154,7 +154,7 @@ public static class SignedObjectsData // Map elements to XMLObjects. int nXmlObjs = signature.getObjectLength(); - this.objects = new HashMap(nXmlObjs); + this.objects = new HashMap<>(nXmlObjs); for (int i = 0; i < nXmlObjs; i++) { ObjectContainer xmlObj = signature.getObjectItem(i); diff --git a/src/main/java/xades4j/verification/SignatureSpecificVerificationOptions.java b/src/main/java/xades4j/verification/SignatureSpecificVerificationOptions.java index 41366e34..dab9b688 100644 --- a/src/main/java/xades4j/verification/SignatureSpecificVerificationOptions.java +++ b/src/main/java/xades4j/verification/SignatureSpecificVerificationOptions.java @@ -41,7 +41,7 @@ public class SignatureSpecificVerificationOptions private boolean checkKeyUsage = true; private InputStream dataForAnonymousReference; private Date defaultVerificationDate = new Date(); - private final List resolvers = new ArrayList(0); + private final List resolvers = new ArrayList<>(0); private boolean followManifests = false; /** diff --git a/src/main/java/xades4j/verification/SignatureUtils.java b/src/main/java/xades4j/verification/SignatureUtils.java index cd27e1ff..321177e8 100644 --- a/src/main/java/xades4j/verification/SignatureUtils.java +++ b/src/main/java/xades4j/verification/SignatureUtils.java @@ -70,7 +70,7 @@ static ReferencesRes processReferences( { SignedInfo signedInfo = signature.getSignedInfo(); - List dataObjsReferences = new ArrayList(signedInfo.getLength() - 1); + List dataObjsReferences = new ArrayList<>(signedInfo.getLength() - 1); Reference signedPropsRef = null; for (int i = 0; i < signedInfo.getLength(); i++) @@ -193,7 +193,7 @@ static Element getQualifyingPropertiesElement(XMLSignature signature) throws Qua private static Collection getXAdESChildElements( Element xmlObjectElem) { - Collection xadesElems = new ArrayList(1); + Collection xadesElems = new ArrayList<>(1); Node child = xmlObjectElem.getFirstChild(); while (child != null) diff --git a/src/main/java/xades4j/verification/XAdESFormChecker.java b/src/main/java/xades4j/verification/XAdESFormChecker.java index 8c66283e..0121d7ce 100644 --- a/src/main/java/xades4j/verification/XAdESFormChecker.java +++ b/src/main/java/xades4j/verification/XAdESFormChecker.java @@ -34,7 +34,7 @@ private XAdESFormChecker() static XAdESForm checkForm(Collection props) throws InvalidXAdESFormException { - Set availablePropsNames = new HashSet(); + Set availablePropsNames = new HashSet<>(); for (PropertyInfo propInfo : props) { availablePropsNames.add(propInfo.getProperty().getName()); diff --git a/src/main/java/xades4j/verification/XadesVerifierImpl.java b/src/main/java/xades4j/verification/XadesVerifierImpl.java index 1fab5180..03082b42 100644 --- a/src/main/java/xades4j/verification/XadesVerifierImpl.java +++ b/src/main/java/xades4j/verification/XadesVerifierImpl.java @@ -282,13 +282,13 @@ private Date getValidationDate( QualifyingPropertyVerificationContext ctx = new QualifyingPropertyVerificationContext( signature, new QualifyingPropertyVerificationContext.CertificationChainData( - new ArrayList(0), - new ArrayList(0), + new ArrayList<>(0), + new ArrayList<>(0), null, this.x500NameStyleProvider), /**/ new QualifyingPropertyVerificationContext.SignedObjectsData( - new ArrayList(0), + new ArrayList<>(0), signature)); Collection props = this.qualifyingPropertiesVerifier.verifyProperties(sigTsData, ctx); QualifyingProperty sigTs = props.iterator().next().getProperty(); @@ -442,7 +442,7 @@ public XAdESVerificationResult verify( throw new InvalidFormExtensionException(actualForm, finalForm); } - Collection usp = new ArrayList(3); + Collection usp = new ArrayList<>(3); finalFormPropsColector.addProps(usp, res); formatExtender.enrichSignature(res.getXmlSignature(), new UnsignedProperties(usp)); diff --git a/src/main/java/xades4j/xml/bind/xades/XmlAnyType.java b/src/main/java/xades4j/xml/bind/xades/XmlAnyType.java index 6cea29fa..1baeecdd 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlAnyType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlAnyType.java @@ -52,7 +52,7 @@ public class XmlAnyType { @XmlAnyElement(lax = true) protected List content; @XmlAnyAttribute - private Map otherAttributes = new HashMap(); + private Map otherAttributes = new HashMap<>(); /** * Gets the value of the content property. @@ -80,7 +80,7 @@ public class XmlAnyType { */ public List getContent() { if (content == null) { - content = new ArrayList(); + content = new ArrayList<>(); } return this.content; } diff --git a/src/main/java/xades4j/xml/bind/xades/XmlCRLRefsType.java b/src/main/java/xades4j/xml/bind/xades/XmlCRLRefsType.java index f10d5614..c8fc8e59 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlCRLRefsType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlCRLRefsType.java @@ -68,7 +68,7 @@ public class XmlCRLRefsType { */ public List getCRLRef() { if (crlRef == null) { - crlRef = new ArrayList(); + crlRef = new ArrayList<>(); } return this.crlRef; } diff --git a/src/main/java/xades4j/xml/bind/xades/XmlCRLValuesType.java b/src/main/java/xades4j/xml/bind/xades/XmlCRLValuesType.java index 410146ba..6e478ba5 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlCRLValuesType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlCRLValuesType.java @@ -68,7 +68,7 @@ public class XmlCRLValuesType { */ public List getEncapsulatedCRLValue() { if (encapsulatedCRLValue == null) { - encapsulatedCRLValue = new ArrayList(); + encapsulatedCRLValue = new ArrayList<>(); } return this.encapsulatedCRLValue; } diff --git a/src/main/java/xades4j/xml/bind/xades/XmlCertIDListType.java b/src/main/java/xades4j/xml/bind/xades/XmlCertIDListType.java index 522457eb..13f7b46a 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlCertIDListType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlCertIDListType.java @@ -68,7 +68,7 @@ public class XmlCertIDListType { */ public List getCert() { if (cert == null) { - cert = new ArrayList(); + cert = new ArrayList<>(); } return this.cert; } diff --git a/src/main/java/xades4j/xml/bind/xades/XmlCertificateValuesType.java b/src/main/java/xades4j/xml/bind/xades/XmlCertificateValuesType.java index c95ac00a..95cbf5ae 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlCertificateValuesType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlCertificateValuesType.java @@ -85,7 +85,7 @@ public class XmlCertificateValuesType { */ public List getEncapsulatedX509CertificateOrOtherCertificate() { if (encapsulatedX509CertificateOrOtherCertificate == null) { - encapsulatedX509CertificateOrOtherCertificate = new ArrayList(); + encapsulatedX509CertificateOrOtherCertificate = new ArrayList<>(); } return this.encapsulatedX509CertificateOrOtherCertificate; } diff --git a/src/main/java/xades4j/xml/bind/xades/XmlCertifiedRolesListType.java b/src/main/java/xades4j/xml/bind/xades/XmlCertifiedRolesListType.java index 1a4a2fd6..9a1ad1a3 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlCertifiedRolesListType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlCertifiedRolesListType.java @@ -68,7 +68,7 @@ public class XmlCertifiedRolesListType { */ public List getCertifiedRole() { if (certifiedRole == null) { - certifiedRole = new ArrayList(); + certifiedRole = new ArrayList<>(); } return this.certifiedRole; } diff --git a/src/main/java/xades4j/xml/bind/xades/XmlClaimedRolesListType.java b/src/main/java/xades4j/xml/bind/xades/XmlClaimedRolesListType.java index ec33e1c7..c04ba705 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlClaimedRolesListType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlClaimedRolesListType.java @@ -68,7 +68,7 @@ public class XmlClaimedRolesListType { */ public List getClaimedRole() { if (claimedRole == null) { - claimedRole = new ArrayList(); + claimedRole = new ArrayList<>(); } return this.claimedRole; } diff --git a/src/main/java/xades4j/xml/bind/xades/XmlCommitmentTypeIndicationType.java b/src/main/java/xades4j/xml/bind/xades/XmlCommitmentTypeIndicationType.java index 300d2cb1..5fff7e23 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlCommitmentTypeIndicationType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlCommitmentTypeIndicationType.java @@ -109,7 +109,7 @@ public void setCommitmentTypeId(XmlObjectIdentifierType value) public List getObjectReference() { if (objectReference == null) - objectReference = new ArrayList(); + objectReference = new ArrayList<>(); return this.objectReference; } diff --git a/src/main/java/xades4j/xml/bind/xades/XmlCommitmentTypeQualifiersListType.java b/src/main/java/xades4j/xml/bind/xades/XmlCommitmentTypeQualifiersListType.java index 99227f8a..0ad1f75d 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlCommitmentTypeQualifiersListType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlCommitmentTypeQualifiersListType.java @@ -68,7 +68,7 @@ public class XmlCommitmentTypeQualifiersListType { */ public List getCommitmentTypeQualifier() { if (commitmentTypeQualifier == null) { - commitmentTypeQualifier = new ArrayList(); + commitmentTypeQualifier = new ArrayList<>(); } return this.commitmentTypeQualifier; } diff --git a/src/main/java/xades4j/xml/bind/xades/XmlDocumentationReferencesType.java b/src/main/java/xades4j/xml/bind/xades/XmlDocumentationReferencesType.java index 3a282f7a..baf094df 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlDocumentationReferencesType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlDocumentationReferencesType.java @@ -70,7 +70,7 @@ public class XmlDocumentationReferencesType { */ public List getDocumentationReference() { if (documentationReference == null) { - documentationReference = new ArrayList(); + documentationReference = new ArrayList<>(); } return this.documentationReference; } diff --git a/src/main/java/xades4j/xml/bind/xades/XmlGenericTimeStampType.java b/src/main/java/xades4j/xml/bind/xades/XmlGenericTimeStampType.java index e3ef131f..34d525a9 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlGenericTimeStampType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlGenericTimeStampType.java @@ -106,7 +106,7 @@ public abstract class XmlGenericTimeStampType { */ public List getInclude() { if (include == null) { - include = new ArrayList(); + include = new ArrayList<>(); } return this.include; } @@ -135,7 +135,7 @@ public List getInclude() { */ public List getReferenceInfo() { if (referenceInfo == null) { - referenceInfo = new ArrayList(); + referenceInfo = new ArrayList<>(); } return this.referenceInfo; } @@ -189,7 +189,7 @@ public void setCanonicalizationMethod(XmlCanonicalizationMethodType value) { */ public List getEncapsulatedTimeStampOrXMLTimeStamp() { if (encapsulatedTimeStampOrXMLTimeStamp == null) { - encapsulatedTimeStampOrXMLTimeStamp = new ArrayList(); + encapsulatedTimeStampOrXMLTimeStamp = new ArrayList<>(); } return this.encapsulatedTimeStampOrXMLTimeStamp; } diff --git a/src/main/java/xades4j/xml/bind/xades/XmlIntegerListType.java b/src/main/java/xades4j/xml/bind/xades/XmlIntegerListType.java index bca40fdc..0677bb3f 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlIntegerListType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlIntegerListType.java @@ -69,7 +69,7 @@ public class XmlIntegerListType { */ public List getInt() { if (_int == null) { - _int = new ArrayList(); + _int = new ArrayList<>(); } return this._int; } diff --git a/src/main/java/xades4j/xml/bind/xades/XmlOCSPRefsType.java b/src/main/java/xades4j/xml/bind/xades/XmlOCSPRefsType.java index 07dced1d..6c9fcea2 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlOCSPRefsType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlOCSPRefsType.java @@ -68,7 +68,7 @@ public class XmlOCSPRefsType { */ public List getOCSPRef() { if (ocspRef == null) { - ocspRef = new ArrayList(); + ocspRef = new ArrayList<>(); } return this.ocspRef; } diff --git a/src/main/java/xades4j/xml/bind/xades/XmlOCSPValuesType.java b/src/main/java/xades4j/xml/bind/xades/XmlOCSPValuesType.java index 8050b584..7f05b5c7 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlOCSPValuesType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlOCSPValuesType.java @@ -68,7 +68,7 @@ public class XmlOCSPValuesType { */ public List getEncapsulatedOCSPValue() { if (encapsulatedOCSPValue == null) { - encapsulatedOCSPValue = new ArrayList(); + encapsulatedOCSPValue = new ArrayList<>(); } return this.encapsulatedOCSPValue; } diff --git a/src/main/java/xades4j/xml/bind/xades/XmlOtherCertStatusRefsType.java b/src/main/java/xades4j/xml/bind/xades/XmlOtherCertStatusRefsType.java index cc98a545..0fdc4ae0 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlOtherCertStatusRefsType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlOtherCertStatusRefsType.java @@ -68,7 +68,7 @@ public class XmlOtherCertStatusRefsType { */ public List getOtherRef() { if (otherRef == null) { - otherRef = new ArrayList(); + otherRef = new ArrayList<>(); } return this.otherRef; } diff --git a/src/main/java/xades4j/xml/bind/xades/XmlOtherCertStatusValuesType.java b/src/main/java/xades4j/xml/bind/xades/XmlOtherCertStatusValuesType.java index 6e3fd0da..79e9e583 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlOtherCertStatusValuesType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlOtherCertStatusValuesType.java @@ -68,7 +68,7 @@ public class XmlOtherCertStatusValuesType { */ public List getOtherValue() { if (otherValue == null) { - otherValue = new ArrayList(); + otherValue = new ArrayList<>(); } return this.otherValue; } diff --git a/src/main/java/xades4j/xml/bind/xades/XmlSigPolicyQualifiersListType.java b/src/main/java/xades4j/xml/bind/xades/XmlSigPolicyQualifiersListType.java index a28bc29e..2d75e315 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlSigPolicyQualifiersListType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlSigPolicyQualifiersListType.java @@ -68,7 +68,7 @@ public class XmlSigPolicyQualifiersListType { */ public List getSigPolicyQualifier() { if (sigPolicyQualifier == null) { - sigPolicyQualifier = new ArrayList(); + sigPolicyQualifier = new ArrayList<>(); } return this.sigPolicyQualifier; } diff --git a/src/main/java/xades4j/xml/bind/xades/XmlSignedDataObjectPropertiesType.java b/src/main/java/xades4j/xml/bind/xades/XmlSignedDataObjectPropertiesType.java index df583199..0ee85839 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlSignedDataObjectPropertiesType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlSignedDataObjectPropertiesType.java @@ -91,7 +91,7 @@ public class XmlSignedDataObjectPropertiesType { */ public List getDataObjectFormat() { if (dataObjectFormat == null) { - dataObjectFormat = new ArrayList(); + dataObjectFormat = new ArrayList<>(); } return this.dataObjectFormat; } @@ -120,7 +120,7 @@ public List getDataObjectFormat() { */ public List getCommitmentTypeIndication() { if (commitmentTypeIndication == null) { - commitmentTypeIndication = new ArrayList(); + commitmentTypeIndication = new ArrayList<>(); } return this.commitmentTypeIndication; } @@ -149,7 +149,7 @@ public List getCommitmentTypeIndication() { */ public List getAllDataObjectsTimeStamp() { if (allDataObjectsTimeStamp == null) { - allDataObjectsTimeStamp = new ArrayList(); + allDataObjectsTimeStamp = new ArrayList<>(); } return this.allDataObjectsTimeStamp; } @@ -178,7 +178,7 @@ public List getAllDataObjectsTimeStamp() { */ public List getIndividualDataObjectsTimeStamp() { if (individualDataObjectsTimeStamp == null) { - individualDataObjectsTimeStamp = new ArrayList(); + individualDataObjectsTimeStamp = new ArrayList<>(); } return this.individualDataObjectsTimeStamp; } diff --git a/src/main/java/xades4j/xml/bind/xades/XmlUnsignedDataObjectPropertiesType.java b/src/main/java/xades4j/xml/bind/xades/XmlUnsignedDataObjectPropertiesType.java index 6cc8ce95..bb649b06 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlUnsignedDataObjectPropertiesType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlUnsignedDataObjectPropertiesType.java @@ -79,7 +79,7 @@ public class XmlUnsignedDataObjectPropertiesType { */ public List getUnsignedDataObjectProperty() { if (unsignedDataObjectProperty == null) { - unsignedDataObjectProperty = new ArrayList(); + unsignedDataObjectProperty = new ArrayList<>(); } return this.unsignedDataObjectProperty; } diff --git a/src/main/java/xades4j/xml/bind/xades/XmlUnsignedSignaturePropertiesType.java b/src/main/java/xades4j/xml/bind/xades/XmlUnsignedSignaturePropertiesType.java index ecdfc6c3..c3d44c6c 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlUnsignedSignaturePropertiesType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlUnsignedSignaturePropertiesType.java @@ -131,7 +131,7 @@ public class XmlUnsignedSignaturePropertiesType public List getCounterSignature() { if (counterSignature == null) - counterSignature = new ArrayList(); + counterSignature = new ArrayList<>(); return this.counterSignature; } @@ -160,7 +160,7 @@ public List getCounterSignature() public List getSignatureTimeStamp() { if (signatureTimeStamp == null) - signatureTimeStamp = new ArrayList(); + signatureTimeStamp = new ArrayList<>(); return this.signatureTimeStamp; } @@ -293,7 +293,7 @@ public void setAttributeRevocationRefs(XmlCompleteRevocationRefsType value) public List getSigAndRefsTimeStamp() { if (sigAndRefsTimeStamp == null) - sigAndRefsTimeStamp = new ArrayList(); + sigAndRefsTimeStamp = new ArrayList<>(); return this.sigAndRefsTimeStamp; } @@ -322,7 +322,7 @@ public List getSigAndRefsTimeStamp() public List getRefsOnlyTimeStamp() { if (refsOnlyTimeStamp == null) - refsOnlyTimeStamp = new ArrayList(); + refsOnlyTimeStamp = new ArrayList<>(); return this.refsOnlyTimeStamp; } @@ -455,7 +455,7 @@ public void setAttributeRevocationValues(XmlRevocationValuesType value) public List getArchiveTimeStamp() { if (archiveTimeStamp == null) - archiveTimeStamp = new ArrayList(); + archiveTimeStamp = new ArrayList<>(); return this.archiveTimeStamp; } @@ -484,7 +484,7 @@ public List getArchiveTimeStamp() public List getAny() { if (any == null) - any = new ArrayList(); + any = new ArrayList<>(); return this.any; } diff --git a/src/main/java/xades4j/xml/bind/xmldsig/XmlCanonicalizationMethodType.java b/src/main/java/xades4j/xml/bind/xmldsig/XmlCanonicalizationMethodType.java index d343c278..a8671507 100644 --- a/src/main/java/xades4j/xml/bind/xmldsig/XmlCanonicalizationMethodType.java +++ b/src/main/java/xades4j/xml/bind/xmldsig/XmlCanonicalizationMethodType.java @@ -77,7 +77,7 @@ public class XmlCanonicalizationMethodType { */ public List getContent() { if (content == null) { - content = new ArrayList(); + content = new ArrayList<>(); } return this.content; } diff --git a/src/main/java/xades4j/xml/bind/xmldsig/XmlDigestMethodType.java b/src/main/java/xades4j/xml/bind/xmldsig/XmlDigestMethodType.java index 9fb52b97..7b665b42 100644 --- a/src/main/java/xades4j/xml/bind/xmldsig/XmlDigestMethodType.java +++ b/src/main/java/xades4j/xml/bind/xmldsig/XmlDigestMethodType.java @@ -79,7 +79,7 @@ public class XmlDigestMethodType { */ public List getContent() { if (content == null) { - content = new ArrayList(); + content = new ArrayList<>(); } return this.content; } diff --git a/src/main/java/xades4j/xml/bind/xmldsig/XmlKeyInfoType.java b/src/main/java/xades4j/xml/bind/xmldsig/XmlKeyInfoType.java index 57fb4246..42bdf8da 100644 --- a/src/main/java/xades4j/xml/bind/xmldsig/XmlKeyInfoType.java +++ b/src/main/java/xades4j/xml/bind/xmldsig/XmlKeyInfoType.java @@ -110,7 +110,7 @@ public class XmlKeyInfoType { */ public List getContent() { if (content == null) { - content = new ArrayList(); + content = new ArrayList<>(); } return this.content; } diff --git a/src/main/java/xades4j/xml/bind/xmldsig/XmlKeyValueType.java b/src/main/java/xades4j/xml/bind/xmldsig/XmlKeyValueType.java index dd9a3d2f..858a8ca0 100644 --- a/src/main/java/xades4j/xml/bind/xmldsig/XmlKeyValueType.java +++ b/src/main/java/xades4j/xml/bind/xmldsig/XmlKeyValueType.java @@ -84,7 +84,7 @@ public class XmlKeyValueType { */ public List getContent() { if (content == null) { - content = new ArrayList(); + content = new ArrayList<>(); } return this.content; } diff --git a/src/main/java/xades4j/xml/bind/xmldsig/XmlManifestType.java b/src/main/java/xades4j/xml/bind/xmldsig/XmlManifestType.java index 0461b32e..eab23fed 100644 --- a/src/main/java/xades4j/xml/bind/xmldsig/XmlManifestType.java +++ b/src/main/java/xades4j/xml/bind/xmldsig/XmlManifestType.java @@ -79,7 +79,7 @@ public class XmlManifestType { */ public List getReference() { if (reference == null) { - reference = new ArrayList(); + reference = new ArrayList<>(); } return this.reference; } diff --git a/src/main/java/xades4j/xml/bind/xmldsig/XmlObjectType.java b/src/main/java/xades4j/xml/bind/xmldsig/XmlObjectType.java index 9277d2ac..ab12d5ff 100644 --- a/src/main/java/xades4j/xml/bind/xmldsig/XmlObjectType.java +++ b/src/main/java/xades4j/xml/bind/xmldsig/XmlObjectType.java @@ -91,7 +91,7 @@ public class XmlObjectType { */ public List getContent() { if (content == null) { - content = new ArrayList(); + content = new ArrayList<>(); } return this.content; } diff --git a/src/main/java/xades4j/xml/bind/xmldsig/XmlPGPDataType.java b/src/main/java/xades4j/xml/bind/xmldsig/XmlPGPDataType.java index 30b55b91..b72b9c1b 100644 --- a/src/main/java/xades4j/xml/bind/xmldsig/XmlPGPDataType.java +++ b/src/main/java/xades4j/xml/bind/xmldsig/XmlPGPDataType.java @@ -97,7 +97,7 @@ public class XmlPGPDataType { */ public List getContent() { if (content == null) { - content = new ArrayList(); + content = new ArrayList<>(); } return this.content; } diff --git a/src/main/java/xades4j/xml/bind/xmldsig/XmlSPKIDataType.java b/src/main/java/xades4j/xml/bind/xmldsig/XmlSPKIDataType.java index 5ed3507f..72f5c177 100644 --- a/src/main/java/xades4j/xml/bind/xmldsig/XmlSPKIDataType.java +++ b/src/main/java/xades4j/xml/bind/xmldsig/XmlSPKIDataType.java @@ -75,7 +75,7 @@ public class XmlSPKIDataType { */ public List getSPKISexpAndAny() { if (spkiSexpAndAny == null) { - spkiSexpAndAny = new ArrayList(); + spkiSexpAndAny = new ArrayList<>(); } return this.spkiSexpAndAny; } diff --git a/src/main/java/xades4j/xml/bind/xmldsig/XmlSignatureMethodType.java b/src/main/java/xades4j/xml/bind/xmldsig/XmlSignatureMethodType.java index b1ffd5a5..0f2c6269 100644 --- a/src/main/java/xades4j/xml/bind/xmldsig/XmlSignatureMethodType.java +++ b/src/main/java/xades4j/xml/bind/xmldsig/XmlSignatureMethodType.java @@ -83,7 +83,7 @@ public class XmlSignatureMethodType { */ public List getContent() { if (content == null) { - content = new ArrayList(); + content = new ArrayList<>(); } return this.content; } diff --git a/src/main/java/xades4j/xml/bind/xmldsig/XmlSignaturePropertiesType.java b/src/main/java/xades4j/xml/bind/xmldsig/XmlSignaturePropertiesType.java index 5cfa1429..3b96043f 100644 --- a/src/main/java/xades4j/xml/bind/xmldsig/XmlSignaturePropertiesType.java +++ b/src/main/java/xades4j/xml/bind/xmldsig/XmlSignaturePropertiesType.java @@ -79,7 +79,7 @@ public class XmlSignaturePropertiesType { */ public List getSignatureProperty() { if (signatureProperty == null) { - signatureProperty = new ArrayList(); + signatureProperty = new ArrayList<>(); } return this.signatureProperty; } diff --git a/src/main/java/xades4j/xml/bind/xmldsig/XmlSignaturePropertyType.java b/src/main/java/xades4j/xml/bind/xmldsig/XmlSignaturePropertyType.java index 241261d3..bc430962 100644 --- a/src/main/java/xades4j/xml/bind/xmldsig/XmlSignaturePropertyType.java +++ b/src/main/java/xades4j/xml/bind/xmldsig/XmlSignaturePropertyType.java @@ -88,7 +88,7 @@ public class XmlSignaturePropertyType { */ public List getContent() { if (content == null) { - content = new ArrayList(); + content = new ArrayList<>(); } return this.content; } diff --git a/src/main/java/xades4j/xml/bind/xmldsig/XmlSignatureType.java b/src/main/java/xades4j/xml/bind/xmldsig/XmlSignatureType.java index 049899a3..a4feec94 100644 --- a/src/main/java/xades4j/xml/bind/xmldsig/XmlSignatureType.java +++ b/src/main/java/xades4j/xml/bind/xmldsig/XmlSignatureType.java @@ -165,7 +165,7 @@ public void setKeyInfo(XmlKeyInfoType value) { */ public List getObject() { if (object == null) { - object = new ArrayList(); + object = new ArrayList<>(); } return this.object; } diff --git a/src/main/java/xades4j/xml/bind/xmldsig/XmlSignedInfoType.java b/src/main/java/xades4j/xml/bind/xmldsig/XmlSignedInfoType.java index 87180e90..0e1238b1 100644 --- a/src/main/java/xades4j/xml/bind/xmldsig/XmlSignedInfoType.java +++ b/src/main/java/xades4j/xml/bind/xmldsig/XmlSignedInfoType.java @@ -136,7 +136,7 @@ public void setSignatureMethod(XmlSignatureMethodType value) { */ public List getReference() { if (reference == null) { - reference = new ArrayList(); + reference = new ArrayList<>(); } return this.reference; } diff --git a/src/main/java/xades4j/xml/bind/xmldsig/XmlTransformType.java b/src/main/java/xades4j/xml/bind/xmldsig/XmlTransformType.java index 6944d5cb..757202f8 100644 --- a/src/main/java/xades4j/xml/bind/xmldsig/XmlTransformType.java +++ b/src/main/java/xades4j/xml/bind/xmldsig/XmlTransformType.java @@ -84,7 +84,7 @@ public class XmlTransformType { */ public List getContent() { if (content == null) { - content = new ArrayList(); + content = new ArrayList<>(); } return this.content; } diff --git a/src/main/java/xades4j/xml/bind/xmldsig/XmlTransformsType.java b/src/main/java/xades4j/xml/bind/xmldsig/XmlTransformsType.java index 381cb30a..d3723a47 100644 --- a/src/main/java/xades4j/xml/bind/xmldsig/XmlTransformsType.java +++ b/src/main/java/xades4j/xml/bind/xmldsig/XmlTransformsType.java @@ -68,7 +68,7 @@ public class XmlTransformsType { */ public List getTransform() { if (transform == null) { - transform = new ArrayList(); + transform = new ArrayList<>(); } return this.transform; } diff --git a/src/main/java/xades4j/xml/bind/xmldsig/XmlX509DataType.java b/src/main/java/xades4j/xml/bind/xmldsig/XmlX509DataType.java index f4375617..111028fb 100644 --- a/src/main/java/xades4j/xml/bind/xmldsig/XmlX509DataType.java +++ b/src/main/java/xades4j/xml/bind/xmldsig/XmlX509DataType.java @@ -92,7 +92,7 @@ public class XmlX509DataType { */ public List getX509IssuerSerialOrX509SKIOrX509SubjectName() { if (x509IssuerSerialOrX509SKIOrX509SubjectName == null) { - x509IssuerSerialOrX509SKIOrX509SubjectName = new ArrayList(); + x509IssuerSerialOrX509SKIOrX509SubjectName = new ArrayList<>(); } return this.x509IssuerSerialOrX509SKIOrX509SubjectName; } diff --git a/src/main/java/xades4j/xml/marshalling/BaseJAXBMarshaller.java b/src/main/java/xades4j/xml/marshalling/BaseJAXBMarshaller.java index 3e07052b..baddd736 100644 --- a/src/main/java/xades4j/xml/marshalling/BaseJAXBMarshaller.java +++ b/src/main/java/xades4j/xml/marshalling/BaseJAXBMarshaller.java @@ -16,10 +16,6 @@ */ package xades4j.xml.marshalling; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; import jakarta.xml.bind.JAXBContext; import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.Marshaller; @@ -30,11 +26,16 @@ import xades4j.properties.data.GenericDOMData; import xades4j.properties.data.PropertyDataObject; import xades4j.properties.data.SigAndDataObjsPropertiesData; +import xades4j.utils.CollectionUtils; +import xades4j.utils.DOMHelper; import xades4j.xml.bind.xades.ObjectFactory; import xades4j.xml.bind.xades.XmlSignedPropertiesType; import xades4j.xml.bind.xades.XmlUnsignedPropertiesType; -import xades4j.utils.CollectionUtils; -import xades4j.utils.DOMHelper; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; /** * @@ -47,7 +48,7 @@ abstract class BaseJAXBMarshaller { try { - Map contexts = new HashMap(); + Map contexts = new HashMap<>(); contexts.put(XmlSignedPropertiesType.class, JAXBContext.newInstance(XmlSignedPropertiesType.class)); contexts.put(XmlUnsignedPropertiesType.class, JAXBContext.newInstance(XmlUnsignedPropertiesType.class)); jaxbContexts = Collections.unmodifiableMap(contexts); @@ -62,7 +63,7 @@ abstract class BaseJAXBMarshaller protected BaseJAXBMarshaller(int convertersInitialSize, String propsElemName) { - this.converters = new HashMap>(convertersInitialSize); + this.converters = new HashMap<>(convertersInitialSize); this.propsElemName = propsElemName; } diff --git a/src/main/java/xades4j/xml/marshalling/ToXmlSignaturePolicyConverter.java b/src/main/java/xades4j/xml/marshalling/ToXmlSignaturePolicyConverter.java index 0feb76d8..2f6b0f67 100644 --- a/src/main/java/xades4j/xml/marshalling/ToXmlSignaturePolicyConverter.java +++ b/src/main/java/xades4j/xml/marshalling/ToXmlSignaturePolicyConverter.java @@ -75,7 +75,7 @@ private XmlSignaturePolicyIdType getSignaturePolicy(SignaturePolicyData sigPolic String url = sigPolicyData.getLocationUrl(); if (url != null) { - JAXBElement xmlSPURI = new JAXBElement(new QName(QualifyingProperty.XADES_XMLNS, "SPURI"), String.class, url); + JAXBElement xmlSPURI = new JAXBElement<>(new QName(QualifyingProperty.XADES_XMLNS, "SPURI"), String.class, url); XmlAnyType xmlQualifier = new XmlAnyType(); xmlQualifier.getContent().add(xmlSPURI); diff --git a/src/main/java/xades4j/xml/marshalling/algorithms/AlgorithmParametersBindingsModule.java b/src/main/java/xades4j/xml/marshalling/algorithms/AlgorithmParametersBindingsModule.java index 5eaf6536..a71115b4 100644 --- a/src/main/java/xades4j/xml/marshalling/algorithms/AlgorithmParametersBindingsModule.java +++ b/src/main/java/xades4j/xml/marshalling/algorithms/AlgorithmParametersBindingsModule.java @@ -56,11 +56,9 @@ private void bindMarshaller( { MapBinder, AlgorithmParametersMarshaller> mapBinder = MapBinder.newMapBinder( binder(), - new TypeLiteral>() - { + new TypeLiteral<>() { }, - new TypeLiteral>() - { + new TypeLiteral<>() { }); if (marshallerClass != null) diff --git a/src/main/java/xades4j/xml/marshalling/algorithms/GenericAlgorithmParamsMarshaller.java b/src/main/java/xades4j/xml/marshalling/algorithms/GenericAlgorithmParamsMarshaller.java index ac5fdf17..8e7d1f4b 100644 --- a/src/main/java/xades4j/xml/marshalling/algorithms/GenericAlgorithmParamsMarshaller.java +++ b/src/main/java/xades4j/xml/marshalling/algorithms/GenericAlgorithmParamsMarshaller.java @@ -38,7 +38,7 @@ public List marshalParameters(GenericAlgorithm alg, Document doc) return null; } - List result = new ArrayList(originalParams.size()); + List result = new ArrayList<>(originalParams.size()); for (Node node : originalParams) { result.add(node.getOwnerDocument() == doc ? node : doc.importNode(node, true)); diff --git a/src/main/java/xades4j/xml/marshalling/algorithms/XPath2FilterTransformParamsMarshaller.java b/src/main/java/xades4j/xml/marshalling/algorithms/XPath2FilterTransformParamsMarshaller.java index 617b2daa..73ecad69 100644 --- a/src/main/java/xades4j/xml/marshalling/algorithms/XPath2FilterTransformParamsMarshaller.java +++ b/src/main/java/xades4j/xml/marshalling/algorithms/XPath2FilterTransformParamsMarshaller.java @@ -37,7 +37,7 @@ final class XPath2FilterTransformParamsMarshaller implements AlgorithmParameters public List marshalParameters(XPath2FilterTransform alg, Document doc) { List filters = alg.getFilters(); - List params = new ArrayList(filters.size()); + List params = new ArrayList<>(filters.size()); Set> namespaces = alg.getNamespaces().entrySet(); diff --git a/src/main/java/xades4j/xml/unmarshalling/FromXmlSignerRoleConverter.java b/src/main/java/xades4j/xml/unmarshalling/FromXmlSignerRoleConverter.java index 01f9efc1..365e12ca 100644 --- a/src/main/java/xades4j/xml/unmarshalling/FromXmlSignerRoleConverter.java +++ b/src/main/java/xades4j/xml/unmarshalling/FromXmlSignerRoleConverter.java @@ -43,7 +43,7 @@ public void convertFromObjectTree( if(xmlSignerRole.getCertifiedRoles() != null) throw new PropertyUnmarshalException("certified roles not supported", SignerRoleProperty.PROP_NAME); - Set claimedRoles = new HashSet(); + Set claimedRoles = new HashSet<>(); for (XmlAnyType xmlRole : xmlSignerRole.getClaimedRoles().getClaimedRole()) { diff --git a/src/main/java/xades4j/xml/unmarshalling/FromXmlUtils.java b/src/main/java/xades4j/xml/unmarshalling/FromXmlUtils.java index a662e6f4..1cd53f00 100644 --- a/src/main/java/xades4j/xml/unmarshalling/FromXmlUtils.java +++ b/src/main/java/xades4j/xml/unmarshalling/FromXmlUtils.java @@ -65,7 +65,7 @@ static void createAndCertificateRefs( static { - identifierTypeConv = new HashMap(3); + identifierTypeConv = new HashMap<>(3); identifierTypeConv.put(null, IdentifierType.URI); identifierTypeConv.put(XmlQualifierType.OID_AS_URI, IdentifierType.OIDAsURI); identifierTypeConv.put(XmlQualifierType.OID_AS_URN, IdentifierType.OIDAsURN); diff --git a/src/main/java/xades4j/xml/unmarshalling/UnmarshallerModule.java b/src/main/java/xades4j/xml/unmarshalling/UnmarshallerModule.java index 5b87b87d..a5790457 100644 --- a/src/main/java/xades4j/xml/unmarshalling/UnmarshallerModule.java +++ b/src/main/java/xades4j/xml/unmarshalling/UnmarshallerModule.java @@ -16,12 +16,13 @@ */ package xades4j.xml.unmarshalling; -import java.util.ArrayList; -import java.util.Collection; import org.w3c.dom.Element; import xades4j.utils.CollectionUtils; import xades4j.xml.bind.xades.XmlQualifyingPropertiesType; +import java.util.ArrayList; +import java.util.Collection; + /** * Helper class that convertes proeprties of a given type. The converters are * invoked only if the corresponding JAXB parent is present. This way the converters @@ -36,7 +37,7 @@ abstract class UnmarshallerModule protected UnmarshallerModule(int nConvs) { - this.converters = new ArrayList>(nConvs); + this.converters = new ArrayList<>(nConvs); } protected void addConverter(QualifyingPropertyFromXmlConverter c) diff --git a/src/test/java/xades4j/xml/marshalling/algorithms/AlgorithmsParametersMarshallingProviderImplTest.java b/src/test/java/xades4j/xml/marshalling/algorithms/AlgorithmsParametersMarshallingProviderImplTest.java index f1651d39..5647e9da 100644 --- a/src/test/java/xades4j/xml/marshalling/algorithms/AlgorithmsParametersMarshallingProviderImplTest.java +++ b/src/test/java/xades4j/xml/marshalling/algorithms/AlgorithmsParametersMarshallingProviderImplTest.java @@ -22,25 +22,18 @@ import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import org.w3c.dom.Node; -import xades4j.algorithms.Algorithm; -import xades4j.algorithms.CanonicalXMLWithoutComments; -import xades4j.algorithms.EnvelopedSignatureTransform; -import xades4j.algorithms.ExclusiveCanonicalXMLWithComments; -import xades4j.algorithms.GenericAlgorithm; -import xades4j.algorithms.XPathTransform; +import xades4j.algorithms.*; import xades4j.utils.SignatureServicesTestBase; import java.util.List; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.*; /** * * @author Luís */ -public class AlgorithmsParametersMarshallingProviderImplTest +class AlgorithmsParametersMarshallingProviderImplTest { private Document doc; private AlgorithmsParametersMarshallingProviderImpl sut; @@ -54,7 +47,7 @@ public void setUp() throws Exception } @Test - public void testMarshalParametersWithDefaultConfiguration() throws Exception + void testMarshalParametersWithDefaultConfiguration() throws Exception { Algorithm[] algorithms = new Algorithm[] { From 431a4b40083f040b38dbdd642a5f92910fc96356 Mon Sep 17 00:00:00 2001 From: Mirko Date: Sun, 12 Nov 2023 05:27:16 +0100 Subject: [PATCH 05/14] resolve sonar findings --- .../production/DataGenBaseTimeStamp.java | 6 +- .../production/EnvelopedXmlObject.java | 5 +- .../SignedDataObjectsProcessor.java | 3 +- .../java/xades4j/production/SignerBES.java | 40 ++-- src/main/java/xades4j/production/SignerC.java | 4 +- .../java/xades4j/production/SignerEPES.java | 17 +- src/main/java/xades4j/production/SignerT.java | 4 +- .../CommitmentTypePropertyBase.java | 27 +-- .../properties/CounterSignatureProperty.java | 4 +- .../properties/DataObjectFormatProperty.java | 6 +- .../properties/DataObjectProperty.java | 5 +- .../SignatureProductionPlaceProperty.java | 5 +- .../SignatureTimeStampProperty.java | 1 + .../data/BaseXAdESTimeStampData.java | 3 + .../properties/data/DataObjectFormatData.java | 7 +- .../SignaturePolicyDataStructureVerifier.java | 4 +- .../DefaultTimeStampVerificationProvider.java | 4 +- .../PKCS11KeyStoreKeyingDataProvider.java | 2 +- src/main/java/xades4j/utils/Base64.java | 85 ++++---- .../verification/CommitmentTypeVerifier.java | 6 +- .../verification/DataObjFormatVerifier.java | 10 +- .../InvalidFormExtensionException.java | 3 +- ...QualifyingPropertyVerificationContext.java | 17 +- .../verification/SignaturePolicyVerifier.java | 12 +- ...tificateIssuerSerialMismatchException.java | 6 +- .../SigningTimeVerificationException.java | 6 +- .../verification/SigningTimeVerifier.java | 6 +- .../TimeStampVerificationException.java | 2 +- .../verification/TimeStampVerifierBase.java | 2 +- .../java/xades4j/verification/XAdESForm.java | 3 +- .../verification/XAdESFormChecker.java | 16 +- .../verification/XadesVerifierImpl.java | 1 - .../xades4j/xml/bind/xades/ObjectFactory.java | 192 +++++++++--------- .../xml/bind/xades/XmlIntegerListType.java | 7 +- .../xml/bind/xmldsig/ObjectFactory.java | 142 ++++++------- .../ToXmlSignaturePolicyConverter.java | 14 +- .../algorithms/XPath2FilterTransformTest.java | 10 +- .../production/KeyInfoBuilderTest.java | 22 +- .../xades4j/production/OtherSignerTests.java | 22 +- .../xades4j/production/PtCcSignerTests.java | 8 +- .../SignedDataObjectsProcessorTest.java | 8 +- .../xades4j/production/SignerBESTest.java | 22 +- .../java/xades4j/production/SignerCTest.java | 14 +- .../xades4j/production/SignerEPESTest.java | 4 +- .../production/SignerSpecificTest.java | 4 +- .../java/xades4j/production/SignerTTest.java | 6 +- .../production/UncheckedSignerBESTest.java | 24 +-- .../XadesBesSigningProfileTest.java | 11 +- .../XadesSignatureFormatExtenderImplTest.java | 21 +- .../properties/DataObjectDescTest.java | 21 +- .../DataObjectFormatPropertyTest.java | 20 +- ...aultTimeStampVerificationProviderTest.java | 16 +- ...eSystemKeyStoreKeyingDataProviderTest.java | 4 +- .../impl/HttpTimeStampTokenProviderTest.java | 4 +- .../PKCS11KeyStoreKeyingDataProviderTest.java | 8 +- ...PKIXCertificateValidationProviderTest.java | 6 +- .../java/xades4j/utils/DOMHelperTest.java | 13 +- .../FileSystemDirectoryCertStoreTest.java | 20 +- .../java/xades4j/utils/PropertiesBagTest.java | 16 +- .../utils/X500NameStyleProviderTest.java | 10 +- .../xades4j/utils/XadesProfileCoreTest.java | 21 +- .../DistinguishedNameComparerTest.java | 2 +- .../GenericDOMDataVerifierTest.java | 8 +- .../xades4j/verification/Issue166Test.java | 45 ++-- .../verification/OtherVerifierTests.java | 11 +- .../verification/XAdESFormCheckerTest.java | 4 +- .../XadesVerificationProfileTest.java | 4 +- .../verification/XadesVerifierErrorsTest.java | 20 +- .../verification/XadesVerifierImplTest.java | 57 ++---- ...h2FilterTransformParamsMarshallerTest.java | 8 +- .../XPathTransformParamsMarshallerTest.java | 8 +- 71 files changed, 566 insertions(+), 613 deletions(-) diff --git a/src/main/java/xades4j/production/DataGenBaseTimeStamp.java b/src/main/java/xades4j/production/DataGenBaseTimeStamp.java index e9779893..97a40618 100644 --- a/src/main/java/xades4j/production/DataGenBaseTimeStamp.java +++ b/src/main/java/xades4j/production/DataGenBaseTimeStamp.java @@ -17,16 +17,16 @@ package xades4j.production; -import xades4j.algorithms.Algorithm; import xades4j.UnsupportedAlgorithmException; +import xades4j.algorithms.Algorithm; import xades4j.properties.QualifyingProperty; import xades4j.properties.data.BaseXAdESTimeStampData; -import xades4j.utils.TimeStampDigestInput; import xades4j.properties.data.PropertyDataObject; import xades4j.providers.TimeStampTokenGenerationException; import xades4j.providers.TimeStampTokenProvider; import xades4j.providers.TimeStampTokenProvider.TimeStampTokenRes; import xades4j.utils.CannotAddDataToDigestInputException; +import xades4j.utils.TimeStampDigestInput; import xades4j.utils.TimeStampDigestInputFactory; /** @@ -39,7 +39,7 @@ abstract class DataGenBaseTimeStamp implements private final TimeStampTokenProvider tsTokenProvider; private final TimeStampDigestInputFactory tsInputFactory; - public DataGenBaseTimeStamp(SignatureAlgorithms algorithms, TimeStampTokenProvider tsTokenProvider, TimeStampDigestInputFactory tsInputFactory) + protected DataGenBaseTimeStamp(SignatureAlgorithms algorithms, TimeStampTokenProvider tsTokenProvider, TimeStampDigestInputFactory tsInputFactory) { this.algorithms = algorithms; this.tsTokenProvider = tsTokenProvider; diff --git a/src/main/java/xades4j/production/EnvelopedXmlObject.java b/src/main/java/xades4j/production/EnvelopedXmlObject.java index 54b6d39c..ef2d09ac 100644 --- a/src/main/java/xades4j/production/EnvelopedXmlObject.java +++ b/src/main/java/xades4j/production/EnvelopedXmlObject.java @@ -16,8 +16,8 @@ */ package xades4j.production; -import xades4j.properties.DataObjectDesc; import org.w3c.dom.Node; +import xades4j.properties.DataObjectDesc; /** * Represents content (usually XML) that will be enveloped in the signature. @@ -36,7 +36,8 @@ public final class EnvelopedXmlObject extends DataObjectDesc { private final Node content; - private final String mimeType, encoding; + private final String mimeType; + private final String encoding; /** * Creates a new instance with the given context. diff --git a/src/main/java/xades4j/production/SignedDataObjectsProcessor.java b/src/main/java/xades4j/production/SignedDataObjectsProcessor.java index 434ba736..6d034e79 100644 --- a/src/main/java/xades4j/production/SignedDataObjectsProcessor.java +++ b/src/main/java/xades4j/production/SignedDataObjectsProcessor.java @@ -106,7 +106,8 @@ private SignedDataObjectsProcessor.Result process( { for (DataObjectDesc dataObjDesc : dataObjects) { - String refUri, refType; + String refUri; + String refType; int index = container.getLength(); if (dataObjDesc instanceof DataObjectReference) diff --git a/src/main/java/xades4j/production/SignerBES.java b/src/main/java/xades4j/production/SignerBES.java index 2ad614e7..791754d3 100644 --- a/src/main/java/xades4j/production/SignerBES.java +++ b/src/main/java/xades4j/production/SignerBES.java @@ -16,49 +16,38 @@ */ package xades4j.production; -import org.apache.xml.security.transforms.Transforms; -import xades4j.properties.QualifyingProperties; import jakarta.inject.Inject; -import java.security.PrivateKey; -import java.security.cert.X509Certificate; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.UUID; import org.apache.xml.security.exceptions.XMLSecurityException; -import org.apache.xml.security.signature.ObjectContainer; import org.apache.xml.security.signature.Manifest; +import org.apache.xml.security.signature.ObjectContainer; import org.apache.xml.security.signature.XMLSignature; import org.apache.xml.security.signature.XMLSignatureException; +import org.apache.xml.security.transforms.Transforms; import org.apache.xml.security.utils.Constants; import org.apache.xml.security.utils.ElementProxy; import org.apache.xml.security.utils.XMLUtils; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; -import xades4j.algorithms.Algorithm; -import xades4j.properties.QualifyingProperty; -import xades4j.properties.SignedSignatureProperty; -import xades4j.properties.SigningCertificateProperty; -import xades4j.properties.UnsignedSignatureProperty; import xades4j.UnsupportedAlgorithmException; import xades4j.XAdES4jException; import xades4j.XAdES4jXMLSigException; +import xades4j.algorithms.Algorithm; +import xades4j.properties.*; import xades4j.properties.data.SigAndDataObjsPropertiesData; -import xades4j.providers.DataObjectPropertiesProvider; -import xades4j.providers.KeyingDataProvider; -import xades4j.providers.SignaturePropertiesProvider; -import xades4j.providers.SigningCertChainException; -import xades4j.providers.X500NameStyleProvider; -import xades4j.utils.CanonicalizerUtils; -import xades4j.utils.DOMHelper; -import xades4j.utils.ObjectUtils; -import xades4j.utils.StringUtils; -import xades4j.utils.TransformUtils; +import xades4j.providers.*; +import xades4j.utils.*; import xades4j.xml.marshalling.SignedPropertiesMarshaller; import xades4j.xml.marshalling.UnsignedPropertiesMarshaller; import xades4j.xml.marshalling.algorithms.AlgorithmsParametersMarshallingProvider; +import java.security.PrivateKey; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.UUID; + /** * Base logic for producing XAdES signatures (XAdES-BES). * @author Luís @@ -362,8 +351,7 @@ private static void digestManifests(Iterable manifests) throws XAdES4j protected void getFormatSpecificSignatureProperties( Collection formatSpecificSignedSigProps, Collection formatSpecificUnsignedSigProps, - List signingCertificateChain) throws XAdES4jException - { + List signingCertificateChain) throws ValidationDataException { SigningCertificateProperty scp = new SigningCertificateProperty(signingCertificateChain); formatSpecificSignedSigProps.add(scp); } diff --git a/src/main/java/xades4j/production/SignerC.java b/src/main/java/xades4j/production/SignerC.java index 33eae584..1796f001 100644 --- a/src/main/java/xades4j/production/SignerC.java +++ b/src/main/java/xades4j/production/SignerC.java @@ -17,7 +17,6 @@ package xades4j.production; import jakarta.inject.Inject; -import xades4j.XAdES4jException; import xades4j.properties.SignedSignatureProperty; import xades4j.properties.UnsignedSignatureProperty; import xades4j.providers.*; @@ -66,8 +65,7 @@ protected SignerC( protected void getFormatSpecificSignatureProperties( Collection formatSpecificSignedSigProps, Collection formatSpecificUnsignedSigProps, - List signingCertificateChain) throws XAdES4jException - { + List signingCertificateChain) throws ValidationDataException { super.getFormatSpecificSignatureProperties(formatSpecificSignedSigProps, formatSpecificUnsignedSigProps, signingCertificateChain); ValidationData vData = this.validationDataProvider.getValidationData(signingCertificateChain); diff --git a/src/main/java/xades4j/production/SignerEPES.java b/src/main/java/xades4j/production/SignerEPES.java index 1731b0a5..b3e85529 100644 --- a/src/main/java/xades4j/production/SignerEPES.java +++ b/src/main/java/xades4j/production/SignerEPES.java @@ -17,22 +17,18 @@ package xades4j.production; import jakarta.inject.Inject; -import java.security.cert.X509Certificate; -import java.util.Collection; -import java.util.List; import xades4j.properties.SignedSignatureProperty; import xades4j.properties.UnsignedSignatureProperty; -import xades4j.XAdES4jException; -import xades4j.providers.DataObjectPropertiesProvider; -import xades4j.providers.KeyingDataProvider; -import xades4j.providers.SignaturePolicyInfoProvider; -import xades4j.providers.SignaturePropertiesProvider; -import xades4j.providers.X500NameStyleProvider; +import xades4j.providers.*; import xades4j.utils.PropertiesUtils; import xades4j.xml.marshalling.SignedPropertiesMarshaller; import xades4j.xml.marshalling.UnsignedPropertiesMarshaller; import xades4j.xml.marshalling.algorithms.AlgorithmsParametersMarshallingProvider; +import java.security.cert.X509Certificate; +import java.util.Collection; +import java.util.List; + /** * Produces XAdES-EPES signatures. * @author Luís @@ -65,8 +61,7 @@ protected SignerEPES( protected void getFormatSpecificSignatureProperties( Collection formatSpecificSignedSigProps, Collection formatSpecificUnsignedSigProps, - List signingCertificateChain) throws XAdES4jException - { + List signingCertificateChain) throws ValidationDataException { super.getFormatSpecificSignatureProperties(formatSpecificSignedSigProps, formatSpecificUnsignedSigProps, signingCertificateChain); PropertiesUtils.addXadesEpesProperties(formatSpecificSignedSigProps, this.policyInfoProvider); diff --git a/src/main/java/xades4j/production/SignerT.java b/src/main/java/xades4j/production/SignerT.java index 6c59e9ec..4958659c 100644 --- a/src/main/java/xades4j/production/SignerT.java +++ b/src/main/java/xades4j/production/SignerT.java @@ -17,7 +17,6 @@ package xades4j.production; import jakarta.inject.Inject; -import xades4j.XAdES4jException; import xades4j.properties.SignedSignatureProperty; import xades4j.properties.UnsignedSignatureProperty; import xades4j.providers.*; @@ -64,8 +63,7 @@ protected SignerT( protected void getFormatSpecificSignatureProperties( Collection formatSpecificSignedSigProps, Collection formatSpecificUnsignedSigProps, - List signingCertificateChain) throws XAdES4jException - { + List signingCertificateChain) throws ValidationDataException { super.getFormatSpecificSignatureProperties( formatSpecificSignedSigProps, formatSpecificUnsignedSigProps, signingCertificateChain); diff --git a/src/main/java/xades4j/properties/CommitmentTypePropertyBase.java b/src/main/java/xades4j/properties/CommitmentTypePropertyBase.java index 8423c084..0d58d662 100644 --- a/src/main/java/xades4j/properties/CommitmentTypePropertyBase.java +++ b/src/main/java/xades4j/properties/CommitmentTypePropertyBase.java @@ -35,21 +35,22 @@ */ public abstract class CommitmentTypePropertyBase extends SignedDataObjectProperty { - public static final String PROOF_OF_ORIGIN_URI = "http://uri.etsi.org/01903/v1.2.2#ProofOfOrigin", - PROOF_OF_ORIGIN_DESC = "Indicates that the signer recognizes to have created, approved and sent the signed data object", - PROOF_OF_RECEIPT_URI = "http://uri.etsi.org/01903/v1.2.2#ProofOfReceipt", - PROOF_OF_RECEIPT_DESC = "Indicates that signer recognizes to have received the content of the signed data object", - PROOF_OF_DELIVERY_URI = "http://uri.etsi.org/01903/v1.2.2#ProofOfDelivery", - PROOF_OF_DELIVERY_DESC = "Indicates that the TSP providing that indication has delivered a signed data object in a local store accessible to the recipient of the signed data object", - PROOF_OF_SENDER_URI = "http://uri.etsi.org/01903/v1.2.2#ProofOfSender", - PROOF_OF_SENDER_DESC = "Indicates that the entity providing that indication has sent the signed data object (but not necessarily created it)", - PROOF_OF_APPROVAL_URI = "http://uri.etsi.org/01903/v1.2.2#ProofOfApproval", - PROOF_OF_APPROVAL_DESC = "Indicates that the signer has approved the content of the signed data object", - PROOF_OF_CREATION_URI = "http://uri.etsi.org/01903/v1.2.2#ProofOfCreation", - PROOF_OF_CREATION_DESC = "Indicates that the signer has created the signed data object (but not necessarily approved, nor sent it)"; + public static final String PROOF_OF_ORIGIN_URI = "http://uri.etsi.org/01903/v1.2.2#ProofOfOrigin"; + public static final String PROOF_OF_ORIGIN_DESC = "Indicates that the signer recognizes to have created, approved and sent the signed data object"; + public static final String PROOF_OF_RECEIPT_URI = "http://uri.etsi.org/01903/v1.2.2#ProofOfReceipt"; + public static final String PROOF_OF_RECEIPT_DESC = "Indicates that signer recognizes to have received the content of the signed data object"; + public static final String PROOF_OF_DELIVERY_URI = "http://uri.etsi.org/01903/v1.2.2#ProofOfDelivery"; + public static final String PROOF_OF_DELIVERY_DESC = "Indicates that the TSP providing that indication has delivered a signed data object in a local store accessible to the recipient of the signed data object"; + public static final String PROOF_OF_SENDER_URI = "http://uri.etsi.org/01903/v1.2.2#ProofOfSender"; + public static final String PROOF_OF_SENDER_DESC = "Indicates that the entity providing that indication has sent the signed data object (but not necessarily created it)"; + public static final String PROOF_OF_APPROVAL_URI = "http://uri.etsi.org/01903/v1.2.2#ProofOfApproval"; + public static final String PROOF_OF_APPROVAL_DESC = "Indicates that the signer has approved the content of the signed data object"; + public static final String PROOF_OF_CREATION_URI = "http://uri.etsi.org/01903/v1.2.2#ProofOfCreation"; + public static final String PROOF_OF_CREATION_DESC = "Indicates that the signer has created the signed data object (but not necessarily approved, nor sent it)"; public static final String PROP_NAME = "CommitmentTypeIndication"; /**/ - private final String uri, description; + private final String uri; + private final String description; private Collection qualifiers; protected CommitmentTypePropertyBase(String uri, String description, diff --git a/src/main/java/xades4j/properties/CounterSignatureProperty.java b/src/main/java/xades4j/properties/CounterSignatureProperty.java index 931536ad..74d785f3 100644 --- a/src/main/java/xades4j/properties/CounterSignatureProperty.java +++ b/src/main/java/xades4j/properties/CounterSignatureProperty.java @@ -32,8 +32,8 @@ */ public final class CounterSignatureProperty extends UnsignedSignatureProperty { - public static final String COUNTER_SIGNATURE_TYPE_URI = "http://uri.etsi.org/01903#CountersignedSignature", - PROP_NAME = "CounterSignature"; + public static final String COUNTER_SIGNATURE_TYPE_URI = "http://uri.etsi.org/01903#CountersignedSignature"; + public static final String PROP_NAME = "CounterSignature"; private XadesSigner counterSigSigner; private SignedDataObjects signedDataObjectsForCounterSig; private XAdESVerificationResult verificationResult; diff --git a/src/main/java/xades4j/properties/DataObjectFormatProperty.java b/src/main/java/xades4j/properties/DataObjectFormatProperty.java index 50ee888c..b710ac91 100644 --- a/src/main/java/xades4j/properties/DataObjectFormatProperty.java +++ b/src/main/java/xades4j/properties/DataObjectFormatProperty.java @@ -16,9 +16,10 @@ */ package xades4j.properties; -import java.util.Collection; import xades4j.utils.CollectionUtils; +import java.util.Collection; + /** * Represents the DataObjectFormat signed data object property. The DataObjectFormat * element provides information that describes the format of the signed data object. @@ -40,7 +41,8 @@ public class DataObjectFormatProperty extends SignedDataObjectProperty { public static final String PROP_NAME = "DataObjectFormat"; /**/ - private final String mimeType, encoding; + private final String mimeType; + private final String encoding; private String description; private ObjectIdentifier identifier; private Collection documentationUris; diff --git a/src/main/java/xades4j/properties/DataObjectProperty.java b/src/main/java/xades4j/properties/DataObjectProperty.java index 1360b987..1545fc0c 100644 --- a/src/main/java/xades4j/properties/DataObjectProperty.java +++ b/src/main/java/xades4j/properties/DataObjectProperty.java @@ -33,7 +33,7 @@ public abstract class DataObjectProperty implements QualifyingProperty /** * Represents the number of data objects that a property can be applied to. */ - protected static enum TargetMultiplicity + protected enum TargetMultiplicity { /** * The property applies to all the data objects in the signature. It cannot @@ -49,7 +49,8 @@ protected static enum TargetMultiplicity */ N(Integer.MAX_VALUE, 2); /**/ - private final int multiplicity, initialSize; + private final int multiplicity; + private final int initialSize; private TargetMultiplicity(int mult) { diff --git a/src/main/java/xades4j/properties/SignatureProductionPlaceProperty.java b/src/main/java/xades4j/properties/SignatureProductionPlaceProperty.java index 2461aba5..8110cba7 100644 --- a/src/main/java/xades4j/properties/SignatureProductionPlaceProperty.java +++ b/src/main/java/xades4j/properties/SignatureProductionPlaceProperty.java @@ -29,7 +29,10 @@ public final class SignatureProductionPlaceProperty extends SignedSignaturePrope { public static final String PROP_NAME = "SignatureProductionPlace"; /**/ - private final String city, stateOrProvince, postalCode, country; + private final String city; + private final String stateOrProvince; + private final String postalCode; + private final String country; public SignatureProductionPlaceProperty(String city, String country) { diff --git a/src/main/java/xades4j/properties/SignatureTimeStampProperty.java b/src/main/java/xades4j/properties/SignatureTimeStampProperty.java index ca01d980..924635be 100644 --- a/src/main/java/xades4j/properties/SignatureTimeStampProperty.java +++ b/src/main/java/xades4j/properties/SignatureTimeStampProperty.java @@ -31,6 +31,7 @@ public final class SignatureTimeStampProperty extends UnsignedSignatureProperty public SignatureTimeStampProperty() { + // TODO document why this constructor is empty } @Override diff --git a/src/main/java/xades4j/properties/data/BaseXAdESTimeStampData.java b/src/main/java/xades4j/properties/data/BaseXAdESTimeStampData.java index 20438abf..ab1be0d5 100644 --- a/src/main/java/xades4j/properties/data/BaseXAdESTimeStampData.java +++ b/src/main/java/xades4j/properties/data/BaseXAdESTimeStampData.java @@ -60,6 +60,9 @@ public Algorithm getCanonicalizationAlgorithm() return this.c14n; } + /** + * @deprecated + */ @Deprecated public String getCanonicalizationAlgorithmUri() { diff --git a/src/main/java/xades4j/properties/data/DataObjectFormatData.java b/src/main/java/xades4j/properties/data/DataObjectFormatData.java index 8e2d3ded..dc86007e 100644 --- a/src/main/java/xades4j/properties/data/DataObjectFormatData.java +++ b/src/main/java/xades4j/properties/data/DataObjectFormatData.java @@ -16,9 +16,10 @@ */ package xades4j.properties.data; -import java.util.Collection; import xades4j.properties.ObjectIdentifier; +import java.util.Collection; + /** * * @author Luís @@ -27,7 +28,9 @@ public final class DataObjectFormatData implements PropertyDataObject { /**/ private final String objectRef; - private String description, mimeType, encoding; + private String description; + private String mimeType; + private String encoding; private ObjectIdentifier identifier; private Collection documentationUris; diff --git a/src/main/java/xades4j/properties/data/SignaturePolicyDataStructureVerifier.java b/src/main/java/xades4j/properties/data/SignaturePolicyDataStructureVerifier.java index 254a4096..db4dfb6b 100644 --- a/src/main/java/xades4j/properties/data/SignaturePolicyDataStructureVerifier.java +++ b/src/main/java/xades4j/properties/data/SignaturePolicyDataStructureVerifier.java @@ -17,7 +17,7 @@ package xades4j.properties.data; import xades4j.properties.ObjectIdentifier; -import xades4j.properties.SignaturePolicyIdentifierProperty; +import xades4j.properties.SignaturePolicyBase; import xades4j.utils.ObjectUtils; /** @@ -36,6 +36,6 @@ public void verifyStructure(PropertyDataObject propData) throws PropertyDataStru ObjectIdentifier id = sigPolicyData.getIdentifier(); if (!ObjectUtils.allNull(alg, dig, id) && ObjectUtils.anyNull(alg, dig, id)) - throw new PropertyDataStructureException("all the properties must be specified", SignaturePolicyIdentifierProperty.PROP_NAME); + throw new PropertyDataStructureException("all the properties must be specified", SignaturePolicyBase.PROP_NAME); } } diff --git a/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java b/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java index e64bbeac..71b858f2 100644 --- a/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java +++ b/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java @@ -94,11 +94,9 @@ public DefaultTimeStampVerificationProvider( public Date verifyToken(byte[] timeStampToken, byte[] tsDigestInput) throws TimeStampTokenVerificationException { TimeStampToken tsToken; - try + try(ASN1InputStream asn1is = new ASN1InputStream(timeStampToken)) { - ASN1InputStream asn1is = new ASN1InputStream(timeStampToken); ContentInfo tsContentInfo = ContentInfo.getInstance(asn1is.readObject()); - asn1is.close(); tsToken = new TimeStampToken(tsContentInfo); } catch (IOException ex) { diff --git a/src/main/java/xades4j/providers/impl/PKCS11KeyStoreKeyingDataProvider.java b/src/main/java/xades4j/providers/impl/PKCS11KeyStoreKeyingDataProvider.java index 329db8aa..d1d33177 100644 --- a/src/main/java/xades4j/providers/impl/PKCS11KeyStoreKeyingDataProvider.java +++ b/src/main/java/xades4j/providers/impl/PKCS11KeyStoreKeyingDataProvider.java @@ -46,7 +46,7 @@ */ public final class PKCS11KeyStoreKeyingDataProvider extends KeyStoreKeyingDataProvider { - private static String SUN_PKCS11_PROVIDER = "SunPKCS11"; + private static final String SUN_PKCS11_PROVIDER = "SunPKCS11"; /** * Create a builder to configure a new {@link PKCS11KeyStoreKeyingDataProvider}. diff --git a/src/main/java/xades4j/utils/Base64.java b/src/main/java/xades4j/utils/Base64.java index 22b9598e..ebed116b 100644 --- a/src/main/java/xades4j/utils/Base64.java +++ b/src/main/java/xades4j/utils/Base64.java @@ -160,25 +160,25 @@ public class Base64 /** No options specified. Value is zero. */ - public final static int NO_OPTIONS = 0; + public static final int NO_OPTIONS = 0; /** Specify encoding in first bit. Value is one. */ - public final static int ENCODE = 1; + public static final int ENCODE = 1; /** Specify decoding in first bit. Value is zero. */ - public final static int DECODE = 0; + public static final int DECODE = 0; /** Specify that data should be gzip-compressed in second bit. Value is two. */ - public final static int GZIP = 2; + public static final int GZIP = 2; /** Specify that gzipped data should not be automatically gunzipped. */ - public final static int DONT_GUNZIP = 4; + public static final int DONT_GUNZIP = 4; /** Do break lines when encoding. Value is 8. */ - public final static int DO_BREAK_LINES = 8; + public static final int DO_BREAK_LINES = 8; /** * Encode using Base64-like encoding that is URL- and Filename-safe as described @@ -188,44 +188,44 @@ public class Base64 * or at the very least should not be called Base64 without also specifying that is * was encoded using the URL- and Filename-safe dialect. */ - public final static int URL_SAFE = 16; + public static final int URL_SAFE = 16; /** * Encode using the special "ordered" dialect of Base64 described here: * http://www.faqs.org/qa/rfcc-1940.html. */ - public final static int ORDERED = 32; + public static final int ORDERED = 32; /* ******** P R I V A T E F I E L D S ******** */ /** Maximum line length (76) of Base64 output. */ - private final static int MAX_LINE_LENGTH = 76; + private static final int MAX_LINE_LENGTH = 76; /** The equals sign (=) as a byte. */ - private final static byte EQUALS_SIGN = (byte)'='; + private static final byte EQUALS_SIGN = (byte)'='; /** The new line character (\n) as a byte. */ - private final static byte NEW_LINE = (byte)'\n'; + private static final byte NEW_LINE = (byte)'\n'; /** Preferred encoding. */ - private final static String PREFERRED_ENCODING = "US-ASCII"; + private static final String PREFERRED_ENCODING = "US-ASCII"; - private final static byte WHITE_SPACE_ENC = -5; // Indicates white space in encoding - private final static byte EQUALS_SIGN_ENC = -1; // Indicates equals sign in encoding + private static final byte WHITE_SPACE_ENC = -5; // Indicates white space in encoding + private static final byte EQUALS_SIGN_ENC = -1; // Indicates equals sign in encoding /* ******** S T A N D A R D B A S E 6 4 A L P H A B E T ******** */ /** The 64 valid Base64 values. */ /* Host platform me be something funny like EBCDIC, so we hardcode these values. */ - private final static byte[] _STANDARD_ALPHABET = { + private static final byte[] _STANDARD_ALPHABET = { (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', (byte)'G', (byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N', (byte)'O', (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U', @@ -243,7 +243,7 @@ public class Base64 * Translates a Base64 value to either its 6-bit reconstruction value * or a negative number indicating some other meaning. **/ - private final static byte[] _STANDARD_DECODABET = { + private static final byte[] _STANDARD_DECODABET = { -9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 0 - 8 -5,-5, // Whitespace: Tab and Linefeed -9,-9, // Decimal 11 - 12 @@ -285,7 +285,7 @@ public class Base64 * http://www.faqs.org/rfcs/rfc3548.html. * Notice that the last two bytes become "hyphen" and "underscore" instead of "plus" and "slash." */ - private final static byte[] _URL_SAFE_ALPHABET = { + private static final byte[] _URL_SAFE_ALPHABET = { (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', (byte)'G', (byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N', (byte)'O', (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U', @@ -301,7 +301,7 @@ public class Base64 /** * Used in decoding URL- and Filename-safe dialects of Base64. */ - private final static byte[] _URL_SAFE_DECODABET = { + private static final byte[] _URL_SAFE_DECODABET = { -9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 0 - 8 -5,-5, // Whitespace: Tab and Linefeed -9,-9, // Decimal 11 - 12 @@ -348,7 +348,7 @@ public class Base64 * and it is described here: * http://www.faqs.org/qa/rfcc-1940.html. */ - private final static byte[] _ORDERED_ALPHABET = { + private static final byte[] _ORDERED_ALPHABET = { (byte)'-', (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', (byte)'7', (byte)'8', (byte)'9', @@ -366,7 +366,7 @@ public class Base64 /** * Used in decoding the "ordered" dialect of Base64. */ - private final static byte[] _ORDERED_DECODABET = { + private static final byte[] _ORDERED_DECODABET = { -9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 0 - 8 -5,-5, // Whitespace: Tab and Linefeed -9,-9, // Decimal 11 - 12 @@ -663,16 +663,14 @@ public static String encodeObject( java.io.Serializable serializableObject, int } // end if: null // Streams - java.io.ByteArrayOutputStream baos = null; - java.io.OutputStream b64os = null; java.util.zip.GZIPOutputStream gzos = null; java.io.ObjectOutputStream oos = null; - try { + try (final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + final OutputStream b64os = new Base64.OutputStream( baos, ENCODE | options );) { // ObjectOutputStream -> (GZIP) -> Base64 -> ByteArrayOutputStream - baos = new java.io.ByteArrayOutputStream(); - b64os = new Base64.OutputStream( baos, ENCODE | options ); + if( (options & GZIP) != 0 ){ // Gzip gzos = new java.util.zip.GZIPOutputStream(b64os); @@ -682,28 +680,20 @@ public static String encodeObject( java.io.Serializable serializableObject, int oos = new java.io.ObjectOutputStream( b64os ); } oos.writeObject( serializableObject ); + + return baos.toString(StandardCharsets.US_ASCII); + } // end try - catch( java.io.IOException e ) { - // Catch it and then throw it immediately so that - // the finally{} block is called for cleanup. - throw e; - } // end catch + // end catch finally { - try{ oos.close(); } catch( Exception e ){} - try{ gzos.close(); } catch( Exception e ){} - try{ b64os.close(); } catch( Exception e ){} - try{ baos.close(); } catch( Exception e ){} + try{ + assert oos != null; + oos.close(); } catch(Exception ignored){} + try{ + assert gzos != null; + gzos.close(); } catch(Exception ignored){} } // end finally - // Return value according to relevant encoding. - try { - return baos.toString(PREFERRED_ENCODING); - } // end try - catch (java.io.UnsupportedEncodingException uue){ - // Fall back to some Java default - return baos.toString(); - } // end catch - } // end encode @@ -837,13 +827,8 @@ public static String encodeBytes( byte[] source, int off, int len, int options ) byte[] encoded = encodeBytesToBytes( source, off, len, options ); // Return value according to relevant encoding. - try { - return new String( encoded, PREFERRED_ENCODING ); - } // end try - catch (java.io.UnsupportedEncodingException uue) { - return new String( encoded ); - } // end catch - + return new String( encoded, StandardCharsets.US_ASCII ); + } // end encodeBytes diff --git a/src/main/java/xades4j/verification/CommitmentTypeVerifier.java b/src/main/java/xades4j/verification/CommitmentTypeVerifier.java index 9137326b..e620c083 100644 --- a/src/main/java/xades4j/verification/CommitmentTypeVerifier.java +++ b/src/main/java/xades4j/verification/CommitmentTypeVerifier.java @@ -16,7 +16,6 @@ */ package xades4j.verification; -import java.util.Collection; import org.w3c.dom.Element; import xades4j.properties.AllDataObjsCommitmentTypeProperty; import xades4j.properties.CommitmentTypeProperty; @@ -25,6 +24,8 @@ import xades4j.properties.data.CommitmentTypeData; import xades4j.verification.QualifyingPropertyVerificationContext.SignedObjectsData; +import java.util.Collection; + /** * XAdES section G.2.2.9 * @author Luís @@ -36,7 +37,8 @@ public QualifyingProperty verify( CommitmentTypeData propData, QualifyingPropertyVerificationContext ctx) throws CommitmentTypeVerificationException { - String uri = propData.getUri(), desc = propData.getDescription(); + String uri = propData.getUri(); + String desc = propData.getDescription(); Collection objsReferences = propData.getObjReferences(); CommitmentTypePropertyBase property; diff --git a/src/main/java/xades4j/verification/DataObjFormatVerifier.java b/src/main/java/xades4j/verification/DataObjFormatVerifier.java index 1ab43b15..c46839a3 100644 --- a/src/main/java/xades4j/verification/DataObjFormatVerifier.java +++ b/src/main/java/xades4j/verification/DataObjFormatVerifier.java @@ -16,7 +16,6 @@ */ package xades4j.verification; -import java.util.Collection; import org.apache.xml.security.signature.ObjectContainer; import org.apache.xml.security.signature.Reference; import xades4j.properties.DataObjectFormatProperty; @@ -24,6 +23,8 @@ import xades4j.properties.data.DataObjectFormatData; import xades4j.utils.StringUtils; +import java.util.Collection; + /** * XAdES section G.2.2.8 * @author Luís @@ -36,7 +37,8 @@ public QualifyingProperty verify( QualifyingPropertyVerificationContext ctx) throws DataObjectFormatVerificationException { QualifyingPropertyVerificationContext.SignedObjectsData signedObjsData = ctx.getSignedObjectsData(); - String encoding = propData.getEncoding(), mimeType = propData.getMimeType(); + String encoding = propData.getEncoding(); + String mimeType = propData.getMimeType(); // XAdES G.2.2.8: "The verifier should check that the ObjectReference element // actually references one ds:Reference element from the signature." @@ -55,8 +57,8 @@ public QualifyingProperty verify( if (null == signedObjObj) throw new DataObjectFormatReferenceException(signedObjRef.getURI()); - String objEncoding = signedObjObj.getEncoding(), - objMimeType = signedObjObj.getMimeType(); + String objEncoding = signedObjObj.getEncoding(); + String objMimeType = signedObjObj.getMimeType(); // Compare 'encoding' and 'mimeType', if present on both. if (StringUtils.differentStringsIfNotNullNorEmpty(objEncoding, encoding) || StringUtils.differentStringsIfNotNullNorEmpty(objMimeType, mimeType)) diff --git a/src/main/java/xades4j/verification/InvalidFormExtensionException.java b/src/main/java/xades4j/verification/InvalidFormExtensionException.java index a464d725..42a2aa54 100644 --- a/src/main/java/xades4j/verification/InvalidFormExtensionException.java +++ b/src/main/java/xades4j/verification/InvalidFormExtensionException.java @@ -26,7 +26,8 @@ */ public class InvalidFormExtensionException extends XAdES4jException { - private final XAdESForm actualForm, finalForm; + private final XAdESForm actualForm; + private final XAdESForm finalForm; public InvalidFormExtensionException( XAdESForm actualForm, diff --git a/src/main/java/xades4j/verification/QualifyingPropertyVerificationContext.java b/src/main/java/xades4j/verification/QualifyingPropertyVerificationContext.java index bddcbe4b..ddd38ed9 100644 --- a/src/main/java/xades4j/verification/QualifyingPropertyVerificationContext.java +++ b/src/main/java/xades4j/verification/QualifyingPropertyVerificationContext.java @@ -16,15 +16,6 @@ */ package xades4j.verification; -import java.math.BigInteger; -import java.security.cert.X509CRL; -import java.security.cert.X509Certificate; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.security.auth.x500.X500Principal; import org.apache.xml.security.keys.content.x509.XMLX509IssuerSerial; import org.apache.xml.security.signature.ObjectContainer; import org.apache.xml.security.signature.XMLSignature; @@ -38,6 +29,12 @@ import org.w3c.dom.Node; import xades4j.providers.X500NameStyleProvider; +import javax.security.auth.x500.X500Principal; +import java.math.BigInteger; +import java.security.cert.X509CRL; +import java.security.cert.X509Certificate; +import java.util.*; + /** * The context available during the verification of the qualifying properties. * @see QualifyingPropertyVerifier @@ -204,7 +201,7 @@ private TObj getReferencedElement( if (refNode.getNodeType() != Node.ELEMENT_NODE) return null; // May return null. - return mapper.get((Element)refNode); + return mapper.get(refNode); } catch (ResourceResolverException ex) { // Maybe an exception should be thrown... diff --git a/src/main/java/xades4j/verification/SignaturePolicyVerifier.java b/src/main/java/xades4j/verification/SignaturePolicyVerifier.java index 3799d0cf..e5d2eb60 100644 --- a/src/main/java/xades4j/verification/SignaturePolicyVerifier.java +++ b/src/main/java/xades4j/verification/SignaturePolicyVerifier.java @@ -17,20 +17,21 @@ package xades4j.verification; import jakarta.inject.Inject; -import java.io.IOException; -import java.io.InputStream; -import java.security.MessageDigest; -import java.util.Arrays; +import xades4j.UnsupportedAlgorithmException; import xades4j.properties.ObjectIdentifier; import xades4j.properties.QualifyingProperty; import xades4j.properties.SignaturePolicyIdentifierProperty; import xades4j.properties.SignaturePolicyImpliedProperty; -import xades4j.UnsupportedAlgorithmException; import xades4j.properties.data.SignaturePolicyData; import xades4j.providers.MessageDigestEngineProvider; import xades4j.providers.SignaturePolicyDocumentProvider; import xades4j.utils.MessageDigestUtils; +import java.io.IOException; +import java.io.InputStream; +import java.security.MessageDigest; +import java.util.Arrays; + /** * * @author Luís @@ -94,6 +95,7 @@ public QualifyingProperty verify( sigDocStream.close(); } catch (IOException ex) { + // TODO: remove throwing exceptions in finally block throw new SignaturePolicyNotAvailableException(policyId, ex); } } diff --git a/src/main/java/xades4j/verification/SigningCertificateIssuerSerialMismatchException.java b/src/main/java/xades4j/verification/SigningCertificateIssuerSerialMismatchException.java index d9ed8434..0f22ec86 100644 --- a/src/main/java/xades4j/verification/SigningCertificateIssuerSerialMismatchException.java +++ b/src/main/java/xades4j/verification/SigningCertificateIssuerSerialMismatchException.java @@ -26,8 +26,10 @@ */ public class SigningCertificateIssuerSerialMismatchException extends SigningCertificateVerificationException { - private final String signingCertIssuerName, keyInfoIssuerName; - private final BigInteger signingCertSerialNumber, keyInfoSerialNumber; + private final String signingCertIssuerName; + private final String keyInfoIssuerName; + private final BigInteger signingCertSerialNumber; + private final BigInteger keyInfoSerialNumber; public SigningCertificateIssuerSerialMismatchException( String signingCertIssuerName, diff --git a/src/main/java/xades4j/verification/SigningTimeVerificationException.java b/src/main/java/xades4j/verification/SigningTimeVerificationException.java index bc66c6c6..ec8bf77e 100644 --- a/src/main/java/xades4j/verification/SigningTimeVerificationException.java +++ b/src/main/java/xades4j/verification/SigningTimeVerificationException.java @@ -16,10 +16,11 @@ */ package xades4j.verification; +import xades4j.properties.SigningTimeProperty; + import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; -import xades4j.properties.SigningTimeProperty; /** * Thrown during verification of the {@code SigningTime} property if the time contained @@ -28,7 +29,8 @@ */ public class SigningTimeVerificationException extends InvalidPropertyException { - private final Date sigTime, maximumExpectedTime; + private final Date sigTime; + private final Date maximumExpectedTime; public SigningTimeVerificationException( Date sigTime, diff --git a/src/main/java/xades4j/verification/SigningTimeVerifier.java b/src/main/java/xades4j/verification/SigningTimeVerifier.java index a4172e1a..ac122eef 100644 --- a/src/main/java/xades4j/verification/SigningTimeVerifier.java +++ b/src/main/java/xades4j/verification/SigningTimeVerifier.java @@ -16,11 +16,12 @@ */ package xades4j.verification; -import java.util.Date; import xades4j.properties.QualifyingProperty; import xades4j.properties.SigningTimeProperty; import xades4j.properties.data.SigningTimeData; +import java.util.Date; + /** * * @author Luís @@ -32,7 +33,8 @@ public QualifyingProperty verify( SigningTimeData propData, QualifyingPropertyVerificationContext ctx) throws SigningTimeVerificationException { - Date now = new Date(), sigTime = propData.getSigningTime().getTime(); + Date now = new Date(); + Date sigTime = propData.getSigningTime().getTime(); if (!sigTime.before(now)) throw new SigningTimeVerificationException(sigTime, now); return new SigningTimeProperty(propData.getSigningTime()); diff --git a/src/main/java/xades4j/verification/TimeStampVerificationException.java b/src/main/java/xades4j/verification/TimeStampVerificationException.java index 4470506d..dd030448 100644 --- a/src/main/java/xades4j/verification/TimeStampVerificationException.java +++ b/src/main/java/xades4j/verification/TimeStampVerificationException.java @@ -22,7 +22,7 @@ */ public abstract class TimeStampVerificationException extends InvalidPropertyException { - private String propName; + private final String propName; protected TimeStampVerificationException(String propName, Throwable cause) { diff --git a/src/main/java/xades4j/verification/TimeStampVerifierBase.java b/src/main/java/xades4j/verification/TimeStampVerifierBase.java index fa64c5db..e1609fcb 100644 --- a/src/main/java/xades4j/verification/TimeStampVerifierBase.java +++ b/src/main/java/xades4j/verification/TimeStampVerifierBase.java @@ -41,7 +41,7 @@ abstract class TimeStampVerifierBase imple private final TimeStampDigestInputFactory tsInputFactory; private final String propName; - public TimeStampVerifierBase(TimeStampVerificationProvider tsVerifier, TimeStampDigestInputFactory tsInputFactory, String propName) + protected TimeStampVerifierBase(TimeStampVerificationProvider tsVerifier, TimeStampDigestInputFactory tsInputFactory, String propName) { this.tsVerifier = tsVerifier; this.tsInputFactory = tsInputFactory; diff --git a/src/main/java/xades4j/verification/XAdESForm.java b/src/main/java/xades4j/verification/XAdESForm.java index 46a07a8a..ef4b1427 100644 --- a/src/main/java/xades4j/verification/XAdESForm.java +++ b/src/main/java/xades4j/verification/XAdESForm.java @@ -31,7 +31,8 @@ public enum XAdESForm A("A", "Archival electronic signatures"); /**/ - private final String alias, fullName; + private final String alias; + private final String fullName; private XAdESForm(String alias, String fullName) { diff --git a/src/main/java/xades4j/verification/XAdESFormChecker.java b/src/main/java/xades4j/verification/XAdESFormChecker.java index 0121d7ce..0e489ce1 100644 --- a/src/main/java/xades4j/verification/XAdESFormChecker.java +++ b/src/main/java/xades4j/verification/XAdESFormChecker.java @@ -57,18 +57,18 @@ static XAdESForm checkForm(Collection props) throws InvalidXAdESFo throw new InvalidXAdESFormException("Signature doesn't follow any of the XAdES forms"); } - static final XAdESFormDesc XADES_BES_DESC = new XAdES_BES_Desc(), - XADES_EPES_DESC = new XAdES_EPES_Desc(), - XADES_T_DESC = new XAdES_T_Desc(), - XADES_C_DESC = new XAdES_C_Desc(), - XADES_X_DESC = new XAdES_X_Desc(), - XADES_X_L_DESC = new XAdES_X_L_Desc(); + static final XAdESFormDesc XADES_BES_DESC = new XAdES_BES_Desc(); + static final XAdESFormDesc XADES_EPES_DESC = new XAdES_EPES_Desc(); + static final XAdESFormDesc XADES_T_DESC = new XAdES_T_Desc(); + static final XAdESFormDesc XADES_C_DESC = new XAdES_C_Desc(); + static final XAdESFormDesc XADES_X_DESC = new XAdES_X_Desc(); + static final XAdESFormDesc XADES_X_L_DESC = new XAdES_X_L_Desc(); /**************************************************************************/ /**/ - private static abstract class XAdESFormDesc + private abstract static class XAdESFormDesc { - private XAdESFormDesc[] baseForms; + private final XAdESFormDesc[] baseForms; // Ordered from the top format to the lower format. public XAdESFormDesc(XAdESFormDesc... baseForms) diff --git a/src/main/java/xades4j/verification/XadesVerifierImpl.java b/src/main/java/xades4j/verification/XadesVerifierImpl.java index 03082b42..2b52c1f9 100644 --- a/src/main/java/xades4j/verification/XadesVerifierImpl.java +++ b/src/main/java/xades4j/verification/XadesVerifierImpl.java @@ -50,7 +50,6 @@ import xades4j.xml.unmarshalling.UnmarshalException; import java.io.InputStream; -import java.security.cert.X509CRL; import java.security.cert.X509Certificate; import java.util.*; diff --git a/src/main/java/xades4j/xml/bind/xades/ObjectFactory.java b/src/main/java/xades4j/xml/bind/xades/ObjectFactory.java index 83b34ce8..ea96df4e 100644 --- a/src/main/java/xades4j/xml/bind/xades/ObjectFactory.java +++ b/src/main/java/xades4j/xml/bind/xades/ObjectFactory.java @@ -11,6 +11,7 @@ import jakarta.xml.bind.JAXBElement; import jakarta.xml.bind.annotation.XmlElementDecl; import jakarta.xml.bind.annotation.XmlRegistry; + import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.namespace.QName; @@ -32,53 +33,54 @@ @XmlRegistry public class ObjectFactory { - private final static QName _UnsignedDataObjectProperties_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "UnsignedDataObjectProperties"); - private final static QName _SignatureTimeStamp_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SignatureTimeStamp"); - private final static QName _IndividualDataObjectsTimeStamp_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "IndividualDataObjectsTimeStamp"); - private final static QName _AttrAuthoritiesCertValues_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "AttrAuthoritiesCertValues"); - private final static QName _ArchiveTimeStamp_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "ArchiveTimeStamp"); - private final static QName _SPUserNotice_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SPUserNotice"); - private final static QName _UnsignedProperties_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "UnsignedProperties"); - private final static QName _CompleteRevocationRefs_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "CompleteRevocationRefs"); - private final static QName _AttributeRevocationValues_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "AttributeRevocationValues"); - private final static QName _SignedSignatureProperties_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SignedSignatureProperties"); - private final static QName _ObjectIdentifier_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "ObjectIdentifier"); - private final static QName _OtherTimeStamp_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "OtherTimeStamp"); - private final static QName _RefsOnlyTimeStamp_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "RefsOnlyTimeStamp"); - private final static QName _SPURI_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SPURI"); - private final static QName _SignedDataObjectProperties_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SignedDataObjectProperties"); - private final static QName _CounterSignature_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "CounterSignature"); - private final static QName _QualifyingProperties_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "QualifyingProperties"); - private final static QName _SigningCertificate_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SigningCertificate"); - private final static QName _ReferenceInfo_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "ReferenceInfo"); - private final static QName _XAdESTimeStamp_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "XAdESTimeStamp"); - private final static QName _SignatureProductionPlace_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SignatureProductionPlace"); - private final static QName _EncapsulatedPKIData_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "EncapsulatedPKIData"); - private final static QName _UnsignedSignatureProperties_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "UnsignedSignatureProperties"); - private final static QName _CommitmentTypeIndication_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "CommitmentTypeIndication"); - private final static QName _AllDataObjectsTimeStamp_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "AllDataObjectsTimeStamp"); - private final static QName _SignerRole_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SignerRole"); - private final static QName _RevocationValues_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "RevocationValues"); - private final static QName _ArchiveTimeStampV2_QNAME = new QName("http://uri.etsi.org/01903/v1.4.1#", "ArchiveTimeStampV2"); - private final static QName _QualifyingPropertiesReference_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "QualifyingPropertiesReference"); - private final static QName _CertificateValues_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "CertificateValues"); - private final static QName _Any_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "Any"); - private final static QName _SignaturePolicyIdentifier_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SignaturePolicyIdentifier"); - private final static QName _SigningTime_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SigningTime"); - private final static QName _Include_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "Include"); - private final static QName _SigAndRefsTimeStamp_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SigAndRefsTimeStamp"); - private final static QName _DataObjectFormat_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "DataObjectFormat"); - private final static QName _AttributeCertificateRefs_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "AttributeCertificateRefs"); - private final static QName _TimeStampValidationData_QNAME = new QName("http://uri.etsi.org/01903/v1.4.1#", "TimeStampValidationData"); - private final static QName _SignedProperties_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SignedProperties"); - private final static QName _CompleteCertificateRefs_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "CompleteCertificateRefs"); - private final static QName _AttributeRevocationRefs_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "AttributeRevocationRefs"); + private static final QName _UnsignedDataObjectProperties_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "UnsignedDataObjectProperties"); + private static final QName _SignatureTimeStamp_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SignatureTimeStamp"); + private static final QName _IndividualDataObjectsTimeStamp_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "IndividualDataObjectsTimeStamp"); + private static final QName _AttrAuthoritiesCertValues_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "AttrAuthoritiesCertValues"); + private static final QName _ArchiveTimeStamp_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "ArchiveTimeStamp"); + private static final QName _SPUserNotice_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SPUserNotice"); + private static final QName _UnsignedProperties_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "UnsignedProperties"); + private static final QName _CompleteRevocationRefs_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "CompleteRevocationRefs"); + private static final QName _AttributeRevocationValues_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "AttributeRevocationValues"); + private static final QName _SignedSignatureProperties_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SignedSignatureProperties"); + private static final QName _ObjectIdentifier_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "ObjectIdentifier"); + private static final QName _OtherTimeStamp_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "OtherTimeStamp"); + private static final QName _RefsOnlyTimeStamp_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "RefsOnlyTimeStamp"); + private static final QName _SPURI_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SPURI"); + private static final QName _SignedDataObjectProperties_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SignedDataObjectProperties"); + private static final QName _CounterSignature_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "CounterSignature"); + private static final QName _QualifyingProperties_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "QualifyingProperties"); + private static final QName _SigningCertificate_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SigningCertificate"); + private static final QName _ReferenceInfo_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "ReferenceInfo"); + private static final QName _XAdESTimeStamp_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "XAdESTimeStamp"); + private static final QName _SignatureProductionPlace_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SignatureProductionPlace"); + private static final QName _EncapsulatedPKIData_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "EncapsulatedPKIData"); + private static final QName _UnsignedSignatureProperties_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "UnsignedSignatureProperties"); + private static final QName _CommitmentTypeIndication_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "CommitmentTypeIndication"); + private static final QName _AllDataObjectsTimeStamp_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "AllDataObjectsTimeStamp"); + private static final QName _SignerRole_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SignerRole"); + private static final QName _RevocationValues_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "RevocationValues"); + private static final QName _ArchiveTimeStampV2_QNAME = new QName("http://uri.etsi.org/01903/v1.4.1#", "ArchiveTimeStampV2"); + private static final QName _QualifyingPropertiesReference_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "QualifyingPropertiesReference"); + private static final QName _CertificateValues_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "CertificateValues"); + private static final QName _Any_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "Any"); + private static final QName _SignaturePolicyIdentifier_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SignaturePolicyIdentifier"); + private static final QName _SigningTime_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SigningTime"); + private static final QName _Include_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "Include"); + private static final QName _SigAndRefsTimeStamp_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SigAndRefsTimeStamp"); + private static final QName _DataObjectFormat_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "DataObjectFormat"); + private static final QName _AttributeCertificateRefs_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "AttributeCertificateRefs"); + private static final QName _TimeStampValidationData_QNAME = new QName("http://uri.etsi.org/01903/v1.4.1#", "TimeStampValidationData"); + private static final QName _SignedProperties_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "SignedProperties"); + private static final QName _CompleteCertificateRefs_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "CompleteCertificateRefs"); + private static final QName _AttributeRevocationRefs_QNAME = new QName("http://uri.etsi.org/01903/v1.3.2#", "AttributeRevocationRefs"); /** * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: xades4j.marshalling.xades * */ public ObjectFactory() { + // TODO document why this constructor is empty } /** @@ -487,7 +489,7 @@ public XmlValidationDataType createXmlValidationDataType() { */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "UnsignedDataObjectProperties") public JAXBElement createUnsignedDataObjectProperties(XmlUnsignedDataObjectPropertiesType value) { - return new JAXBElement(_UnsignedDataObjectProperties_QNAME, XmlUnsignedDataObjectPropertiesType.class, null, value); + return new JAXBElement<>(_UnsignedDataObjectProperties_QNAME, XmlUnsignedDataObjectPropertiesType.class, null, value); } /** @@ -496,7 +498,7 @@ public JAXBElement createUnsignedDataObject */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "SignatureTimeStamp") public JAXBElement createSignatureTimeStamp(XmlXAdESTimeStampType value) { - return new JAXBElement(_SignatureTimeStamp_QNAME, XmlXAdESTimeStampType.class, null, value); + return new JAXBElement<>(_SignatureTimeStamp_QNAME, XmlXAdESTimeStampType.class, null, value); } /** @@ -505,7 +507,7 @@ public JAXBElement createSignatureTimeStamp(XmlXAdESTimeS */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "IndividualDataObjectsTimeStamp") public JAXBElement createIndividualDataObjectsTimeStamp(XmlXAdESTimeStampType value) { - return new JAXBElement(_IndividualDataObjectsTimeStamp_QNAME, XmlXAdESTimeStampType.class, null, value); + return new JAXBElement<>(_IndividualDataObjectsTimeStamp_QNAME, XmlXAdESTimeStampType.class, null, value); } /** @@ -514,7 +516,7 @@ public JAXBElement createIndividualDataObjectsTimeStamp(X */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "AttrAuthoritiesCertValues") public JAXBElement createAttrAuthoritiesCertValues(XmlCertificateValuesType value) { - return new JAXBElement(_AttrAuthoritiesCertValues_QNAME, XmlCertificateValuesType.class, null, value); + return new JAXBElement<>(_AttrAuthoritiesCertValues_QNAME, XmlCertificateValuesType.class, null, value); } /** @@ -523,7 +525,7 @@ public JAXBElement createAttrAuthoritiesCertValues(Xml */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "ArchiveTimeStamp") public JAXBElement createArchiveTimeStamp(XmlXAdESTimeStampType value) { - return new JAXBElement(_ArchiveTimeStamp_QNAME, XmlXAdESTimeStampType.class, null, value); + return new JAXBElement<>(_ArchiveTimeStamp_QNAME, XmlXAdESTimeStampType.class, null, value); } /** @@ -532,7 +534,7 @@ public JAXBElement createArchiveTimeStamp(XmlXAdESTimeSta */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "SPUserNotice") public JAXBElement createSPUserNotice(XmlSPUserNoticeType value) { - return new JAXBElement(_SPUserNotice_QNAME, XmlSPUserNoticeType.class, null, value); + return new JAXBElement<>(_SPUserNotice_QNAME, XmlSPUserNoticeType.class, null, value); } /** @@ -541,7 +543,7 @@ public JAXBElement createSPUserNotice(XmlSPUserNoticeType v */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "UnsignedProperties") public JAXBElement createUnsignedProperties(XmlUnsignedPropertiesType value) { - return new JAXBElement(_UnsignedProperties_QNAME, XmlUnsignedPropertiesType.class, null, value); + return new JAXBElement<>(_UnsignedProperties_QNAME, XmlUnsignedPropertiesType.class, null, value); } /** @@ -550,7 +552,7 @@ public JAXBElement createUnsignedProperties(XmlUnsign */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "CompleteRevocationRefs") public JAXBElement createCompleteRevocationRefs(XmlCompleteRevocationRefsType value) { - return new JAXBElement(_CompleteRevocationRefs_QNAME, XmlCompleteRevocationRefsType.class, null, value); + return new JAXBElement<>(_CompleteRevocationRefs_QNAME, XmlCompleteRevocationRefsType.class, null, value); } /** @@ -559,7 +561,7 @@ public JAXBElement createCompleteRevocationRefs(X */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "AttributeRevocationValues") public JAXBElement createAttributeRevocationValues(XmlRevocationValuesType value) { - return new JAXBElement(_AttributeRevocationValues_QNAME, XmlRevocationValuesType.class, null, value); + return new JAXBElement<>(_AttributeRevocationValues_QNAME, XmlRevocationValuesType.class, null, value); } /** @@ -568,7 +570,7 @@ public JAXBElement createAttributeRevocationValues(XmlR */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "SignedSignatureProperties") public JAXBElement createSignedSignatureProperties(XmlSignedSignaturePropertiesType value) { - return new JAXBElement(_SignedSignatureProperties_QNAME, XmlSignedSignaturePropertiesType.class, null, value); + return new JAXBElement<>(_SignedSignatureProperties_QNAME, XmlSignedSignaturePropertiesType.class, null, value); } /** @@ -577,7 +579,7 @@ public JAXBElement createSignedSignatureProper */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "ObjectIdentifier") public JAXBElement createObjectIdentifier(XmlObjectIdentifierType value) { - return new JAXBElement(_ObjectIdentifier_QNAME, XmlObjectIdentifierType.class, null, value); + return new JAXBElement<>(_ObjectIdentifier_QNAME, XmlObjectIdentifierType.class, null, value); } /** @@ -586,7 +588,7 @@ public JAXBElement createObjectIdentifier(XmlObjectIden */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "OtherTimeStamp") public JAXBElement createOtherTimeStamp(XmlOtherTimeStampType value) { - return new JAXBElement(_OtherTimeStamp_QNAME, XmlOtherTimeStampType.class, null, value); + return new JAXBElement<>(_OtherTimeStamp_QNAME, XmlOtherTimeStampType.class, null, value); } /** @@ -595,7 +597,7 @@ public JAXBElement createOtherTimeStamp(XmlOtherTimeStamp */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "RefsOnlyTimeStamp") public JAXBElement createRefsOnlyTimeStamp(XmlXAdESTimeStampType value) { - return new JAXBElement(_RefsOnlyTimeStamp_QNAME, XmlXAdESTimeStampType.class, null, value); + return new JAXBElement<>(_RefsOnlyTimeStamp_QNAME, XmlXAdESTimeStampType.class, null, value); } /** @@ -604,7 +606,7 @@ public JAXBElement createRefsOnlyTimeStamp(XmlXAdESTimeSt */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "SPURI") public JAXBElement createSPURI(String value) { - return new JAXBElement(_SPURI_QNAME, String.class, null, value); + return new JAXBElement<>(_SPURI_QNAME, String.class, null, value); } /** @@ -613,7 +615,7 @@ public JAXBElement createSPURI(String value) { */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "SignedDataObjectProperties") public JAXBElement createSignedDataObjectProperties(XmlSignedDataObjectPropertiesType value) { - return new JAXBElement(_SignedDataObjectProperties_QNAME, XmlSignedDataObjectPropertiesType.class, null, value); + return new JAXBElement<>(_SignedDataObjectProperties_QNAME, XmlSignedDataObjectPropertiesType.class, null, value); } /** @@ -622,7 +624,7 @@ public JAXBElement createSignedDataObjectProp */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "CounterSignature") public JAXBElement createCounterSignature(XmlCounterSignatureType value) { - return new JAXBElement(_CounterSignature_QNAME, XmlCounterSignatureType.class, null, value); + return new JAXBElement<>(_CounterSignature_QNAME, XmlCounterSignatureType.class, null, value); } /** @@ -631,7 +633,7 @@ public JAXBElement createCounterSignature(XmlCounterSig */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "QualifyingProperties") public JAXBElement createQualifyingProperties(XmlQualifyingPropertiesType value) { - return new JAXBElement(_QualifyingProperties_QNAME, XmlQualifyingPropertiesType.class, null, value); + return new JAXBElement<>(_QualifyingProperties_QNAME, XmlQualifyingPropertiesType.class, null, value); } /** @@ -640,7 +642,7 @@ public JAXBElement createQualifyingProperties(XmlQu */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "SigningCertificate") public JAXBElement createSigningCertificate(XmlCertIDListType value) { - return new JAXBElement(_SigningCertificate_QNAME, XmlCertIDListType.class, null, value); + return new JAXBElement<>(_SigningCertificate_QNAME, XmlCertIDListType.class, null, value); } /** @@ -649,7 +651,7 @@ public JAXBElement createSigningCertificate(XmlCertIDListType */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "ReferenceInfo") public JAXBElement createReferenceInfo(XmlReferenceInfoType value) { - return new JAXBElement(_ReferenceInfo_QNAME, XmlReferenceInfoType.class, null, value); + return new JAXBElement<>(_ReferenceInfo_QNAME, XmlReferenceInfoType.class, null, value); } /** @@ -658,7 +660,7 @@ public JAXBElement createReferenceInfo(XmlReferenceInfoTyp */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "XAdESTimeStamp") public JAXBElement createXAdESTimeStamp(XmlXAdESTimeStampType value) { - return new JAXBElement(_XAdESTimeStamp_QNAME, XmlXAdESTimeStampType.class, null, value); + return new JAXBElement<>(_XAdESTimeStamp_QNAME, XmlXAdESTimeStampType.class, null, value); } /** @@ -667,7 +669,7 @@ public JAXBElement createXAdESTimeStamp(XmlXAdESTimeStamp */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "SignatureProductionPlace") public JAXBElement createSignatureProductionPlace(XmlSignatureProductionPlaceType value) { - return new JAXBElement(_SignatureProductionPlace_QNAME, XmlSignatureProductionPlaceType.class, null, value); + return new JAXBElement<>(_SignatureProductionPlace_QNAME, XmlSignatureProductionPlaceType.class, null, value); } /** @@ -676,7 +678,7 @@ public JAXBElement createSignatureProductionPla */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "EncapsulatedPKIData") public JAXBElement createEncapsulatedPKIData(XmlEncapsulatedPKIDataType value) { - return new JAXBElement(_EncapsulatedPKIData_QNAME, XmlEncapsulatedPKIDataType.class, null, value); + return new JAXBElement<>(_EncapsulatedPKIData_QNAME, XmlEncapsulatedPKIDataType.class, null, value); } /** @@ -685,7 +687,7 @@ public JAXBElement createEncapsulatedPKIData(XmlEnca */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "UnsignedSignatureProperties") public JAXBElement createUnsignedSignatureProperties(XmlUnsignedSignaturePropertiesType value) { - return new JAXBElement(_UnsignedSignatureProperties_QNAME, XmlUnsignedSignaturePropertiesType.class, null, value); + return new JAXBElement<>(_UnsignedSignatureProperties_QNAME, XmlUnsignedSignaturePropertiesType.class, null, value); } /** @@ -694,7 +696,7 @@ public JAXBElement createUnsignedSignaturePr */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "CommitmentTypeIndication") public JAXBElement createCommitmentTypeIndication(XmlCommitmentTypeIndicationType value) { - return new JAXBElement(_CommitmentTypeIndication_QNAME, XmlCommitmentTypeIndicationType.class, null, value); + return new JAXBElement<>(_CommitmentTypeIndication_QNAME, XmlCommitmentTypeIndicationType.class, null, value); } /** @@ -703,7 +705,7 @@ public JAXBElement createCommitmentTypeIndicati */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "AllDataObjectsTimeStamp") public JAXBElement createAllDataObjectsTimeStamp(XmlXAdESTimeStampType value) { - return new JAXBElement(_AllDataObjectsTimeStamp_QNAME, XmlXAdESTimeStampType.class, null, value); + return new JAXBElement<>(_AllDataObjectsTimeStamp_QNAME, XmlXAdESTimeStampType.class, null, value); } /** @@ -712,7 +714,7 @@ public JAXBElement createAllDataObjectsTimeStamp(XmlXAdES */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "SignerRole") public JAXBElement createSignerRole(XmlSignerRoleType value) { - return new JAXBElement(_SignerRole_QNAME, XmlSignerRoleType.class, null, value); + return new JAXBElement<>(_SignerRole_QNAME, XmlSignerRoleType.class, null, value); } /** @@ -721,7 +723,7 @@ public JAXBElement createSignerRole(XmlSignerRoleType value) */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "RevocationValues") public JAXBElement createRevocationValues(XmlRevocationValuesType value) { - return new JAXBElement(_RevocationValues_QNAME, XmlRevocationValuesType.class, null, value); + return new JAXBElement<>(_RevocationValues_QNAME, XmlRevocationValuesType.class, null, value); } /** @@ -730,7 +732,7 @@ public JAXBElement createRevocationValues(XmlRevocation */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.4.1#", name = "ArchiveTimeStampV2") public JAXBElement createArchiveTimeStampV2(XmlXAdESTimeStampType value) { - return new JAXBElement(_ArchiveTimeStampV2_QNAME, XmlXAdESTimeStampType.class, null, value); + return new JAXBElement<>(_ArchiveTimeStampV2_QNAME, XmlXAdESTimeStampType.class, null, value); } /** @@ -739,7 +741,7 @@ public JAXBElement createArchiveTimeStampV2(XmlXAdESTimeS */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "QualifyingPropertiesReference") public JAXBElement createQualifyingPropertiesReference(XmlQualifyingPropertiesReferenceType value) { - return new JAXBElement(_QualifyingPropertiesReference_QNAME, XmlQualifyingPropertiesReferenceType.class, null, value); + return new JAXBElement<>(_QualifyingPropertiesReference_QNAME, XmlQualifyingPropertiesReferenceType.class, null, value); } /** @@ -748,7 +750,7 @@ public JAXBElement createQualifyingPropert */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "CertificateValues") public JAXBElement createCertificateValues(XmlCertificateValuesType value) { - return new JAXBElement(_CertificateValues_QNAME, XmlCertificateValuesType.class, null, value); + return new JAXBElement<>(_CertificateValues_QNAME, XmlCertificateValuesType.class, null, value); } /** @@ -757,7 +759,7 @@ public JAXBElement createCertificateValues(XmlCertific */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "Any") public JAXBElement createAny(XmlAnyType value) { - return new JAXBElement(_Any_QNAME, XmlAnyType.class, null, value); + return new JAXBElement<>(_Any_QNAME, XmlAnyType.class, null, value); } /** @@ -766,7 +768,7 @@ public JAXBElement createAny(XmlAnyType value) { */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "SignaturePolicyIdentifier") public JAXBElement createSignaturePolicyIdentifier(XmlSignaturePolicyIdentifierType value) { - return new JAXBElement(_SignaturePolicyIdentifier_QNAME, XmlSignaturePolicyIdentifierType.class, null, value); + return new JAXBElement<>(_SignaturePolicyIdentifier_QNAME, XmlSignaturePolicyIdentifierType.class, null, value); } /** @@ -775,7 +777,7 @@ public JAXBElement createSignaturePolicyIdenti */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "SigningTime") public JAXBElement createSigningTime(XMLGregorianCalendar value) { - return new JAXBElement(_SigningTime_QNAME, XMLGregorianCalendar.class, null, value); + return new JAXBElement<>(_SigningTime_QNAME, XMLGregorianCalendar.class, null, value); } /** @@ -784,7 +786,7 @@ public JAXBElement createSigningTime(XMLGregorianCalendar */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "Include") public JAXBElement createInclude(XmlIncludeType value) { - return new JAXBElement(_Include_QNAME, XmlIncludeType.class, null, value); + return new JAXBElement<>(_Include_QNAME, XmlIncludeType.class, null, value); } /** @@ -793,7 +795,7 @@ public JAXBElement createInclude(XmlIncludeType value) { */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "SigAndRefsTimeStamp") public JAXBElement createSigAndRefsTimeStamp(XmlXAdESTimeStampType value) { - return new JAXBElement(_SigAndRefsTimeStamp_QNAME, XmlXAdESTimeStampType.class, null, value); + return new JAXBElement<>(_SigAndRefsTimeStamp_QNAME, XmlXAdESTimeStampType.class, null, value); } /** @@ -802,7 +804,7 @@ public JAXBElement createSigAndRefsTimeStamp(XmlXAdESTime */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "DataObjectFormat") public JAXBElement createDataObjectFormat(XmlDataObjectFormatType value) { - return new JAXBElement(_DataObjectFormat_QNAME, XmlDataObjectFormatType.class, null, value); + return new JAXBElement<>(_DataObjectFormat_QNAME, XmlDataObjectFormatType.class, null, value); } /** @@ -811,7 +813,7 @@ public JAXBElement createDataObjectFormat(XmlDataObject */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "AttributeCertificateRefs") public JAXBElement createAttributeCertificateRefs(XmlCompleteCertificateRefsType value) { - return new JAXBElement(_AttributeCertificateRefs_QNAME, XmlCompleteCertificateRefsType.class, null, value); + return new JAXBElement<>(_AttributeCertificateRefs_QNAME, XmlCompleteCertificateRefsType.class, null, value); } /** @@ -820,7 +822,7 @@ public JAXBElement createAttributeCertificateRef */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.4.1#", name = "TimeStampValidationData") public JAXBElement createTimeStampValidationData(XmlValidationDataType value) { - return new JAXBElement(_TimeStampValidationData_QNAME, XmlValidationDataType.class, null, value); + return new JAXBElement<>(_TimeStampValidationData_QNAME, XmlValidationDataType.class, null, value); } /** @@ -829,7 +831,7 @@ public JAXBElement createTimeStampValidationData(XmlValid */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "SignedProperties") public JAXBElement createSignedProperties(XmlSignedPropertiesType value) { - return new JAXBElement(_SignedProperties_QNAME, XmlSignedPropertiesType.class, null, value); + return new JAXBElement<>(_SignedProperties_QNAME, XmlSignedPropertiesType.class, null, value); } /** @@ -838,7 +840,7 @@ public JAXBElement createSignedProperties(XmlSignedProp */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "CompleteCertificateRefs") public JAXBElement createCompleteCertificateRefs(XmlCompleteCertificateRefsType value) { - return new JAXBElement(_CompleteCertificateRefs_QNAME, XmlCompleteCertificateRefsType.class, null, value); + return new JAXBElement<>(_CompleteCertificateRefs_QNAME, XmlCompleteCertificateRefsType.class, null, value); } /** @@ -847,7 +849,7 @@ public JAXBElement createCompleteCertificateRefs */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "AttributeRevocationRefs") public JAXBElement createAttributeRevocationRefs(XmlCompleteRevocationRefsType value) { - return new JAXBElement(_AttributeRevocationRefs_QNAME, XmlCompleteRevocationRefsType.class, null, value); + return new JAXBElement<>(_AttributeRevocationRefs_QNAME, XmlCompleteRevocationRefsType.class, null, value); } /** @@ -856,7 +858,7 @@ public JAXBElement createAttributeRevocationRefs( */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "SignatureTimeStamp", scope = XmlUnsignedSignaturePropertiesType.class) public JAXBElement createXmlUnsignedSignaturePropertiesTypeSignatureTimeStamp(XmlXAdESTimeStampType value) { - return new JAXBElement(_SignatureTimeStamp_QNAME, XmlXAdESTimeStampType.class, XmlUnsignedSignaturePropertiesType.class, value); + return new JAXBElement<>(_SignatureTimeStamp_QNAME, XmlXAdESTimeStampType.class, XmlUnsignedSignaturePropertiesType.class, value); } /** @@ -865,7 +867,7 @@ public JAXBElement createXmlUnsignedSignaturePropertiesTy */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "CertificateValues", scope = XmlUnsignedSignaturePropertiesType.class) public JAXBElement createXmlUnsignedSignaturePropertiesTypeCertificateValues(XmlCertificateValuesType value) { - return new JAXBElement(_CertificateValues_QNAME, XmlCertificateValuesType.class, XmlUnsignedSignaturePropertiesType.class, value); + return new JAXBElement<>(_CertificateValues_QNAME, XmlCertificateValuesType.class, XmlUnsignedSignaturePropertiesType.class, value); } /** @@ -874,7 +876,7 @@ public JAXBElement createXmlUnsignedSignaturePropertie */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "RefsOnlyTimeStamp", scope = XmlUnsignedSignaturePropertiesType.class) public JAXBElement createXmlUnsignedSignaturePropertiesTypeRefsOnlyTimeStamp(XmlXAdESTimeStampType value) { - return new JAXBElement(_RefsOnlyTimeStamp_QNAME, XmlXAdESTimeStampType.class, XmlUnsignedSignaturePropertiesType.class, value); + return new JAXBElement<>(_RefsOnlyTimeStamp_QNAME, XmlXAdESTimeStampType.class, XmlUnsignedSignaturePropertiesType.class, value); } /** @@ -883,7 +885,7 @@ public JAXBElement createXmlUnsignedSignaturePropertiesTy */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "AttrAuthoritiesCertValues", scope = XmlUnsignedSignaturePropertiesType.class) public JAXBElement createXmlUnsignedSignaturePropertiesTypeAttrAuthoritiesCertValues(XmlCertificateValuesType value) { - return new JAXBElement(_AttrAuthoritiesCertValues_QNAME, XmlCertificateValuesType.class, XmlUnsignedSignaturePropertiesType.class, value); + return new JAXBElement<>(_AttrAuthoritiesCertValues_QNAME, XmlCertificateValuesType.class, XmlUnsignedSignaturePropertiesType.class, value); } /** @@ -892,7 +894,7 @@ public JAXBElement createXmlUnsignedSignaturePropertie */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "ArchiveTimeStamp", scope = XmlUnsignedSignaturePropertiesType.class) public JAXBElement createXmlUnsignedSignaturePropertiesTypeArchiveTimeStamp(XmlXAdESTimeStampType value) { - return new JAXBElement(_ArchiveTimeStamp_QNAME, XmlXAdESTimeStampType.class, XmlUnsignedSignaturePropertiesType.class, value); + return new JAXBElement<>(_ArchiveTimeStamp_QNAME, XmlXAdESTimeStampType.class, XmlUnsignedSignaturePropertiesType.class, value); } /** @@ -901,7 +903,7 @@ public JAXBElement createXmlUnsignedSignaturePropertiesTy */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "SigAndRefsTimeStamp", scope = XmlUnsignedSignaturePropertiesType.class) public JAXBElement createXmlUnsignedSignaturePropertiesTypeSigAndRefsTimeStamp(XmlXAdESTimeStampType value) { - return new JAXBElement(_SigAndRefsTimeStamp_QNAME, XmlXAdESTimeStampType.class, XmlUnsignedSignaturePropertiesType.class, value); + return new JAXBElement<>(_SigAndRefsTimeStamp_QNAME, XmlXAdESTimeStampType.class, XmlUnsignedSignaturePropertiesType.class, value); } /** @@ -910,7 +912,7 @@ public JAXBElement createXmlUnsignedSignaturePropertiesTy */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "CounterSignature", scope = XmlUnsignedSignaturePropertiesType.class) public JAXBElement createXmlUnsignedSignaturePropertiesTypeCounterSignature(XmlCounterSignatureType value) { - return new JAXBElement(_CounterSignature_QNAME, XmlCounterSignatureType.class, XmlUnsignedSignaturePropertiesType.class, value); + return new JAXBElement<>(_CounterSignature_QNAME, XmlCounterSignatureType.class, XmlUnsignedSignaturePropertiesType.class, value); } /** @@ -919,7 +921,7 @@ public JAXBElement createXmlUnsignedSignatureProperties */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "CompleteRevocationRefs", scope = XmlUnsignedSignaturePropertiesType.class) public JAXBElement createXmlUnsignedSignaturePropertiesTypeCompleteRevocationRefs(XmlCompleteRevocationRefsType value) { - return new JAXBElement(_CompleteRevocationRefs_QNAME, XmlCompleteRevocationRefsType.class, XmlUnsignedSignaturePropertiesType.class, value); + return new JAXBElement<>(_CompleteRevocationRefs_QNAME, XmlCompleteRevocationRefsType.class, XmlUnsignedSignaturePropertiesType.class, value); } /** @@ -928,7 +930,7 @@ public JAXBElement createXmlUnsignedSignatureProp */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "AttributeCertificateRefs", scope = XmlUnsignedSignaturePropertiesType.class) public JAXBElement createXmlUnsignedSignaturePropertiesTypeAttributeCertificateRefs(XmlCompleteCertificateRefsType value) { - return new JAXBElement(_AttributeCertificateRefs_QNAME, XmlCompleteCertificateRefsType.class, XmlUnsignedSignaturePropertiesType.class, value); + return new JAXBElement<>(_AttributeCertificateRefs_QNAME, XmlCompleteCertificateRefsType.class, XmlUnsignedSignaturePropertiesType.class, value); } /** @@ -937,7 +939,7 @@ public JAXBElement createXmlUnsignedSignaturePro */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "AttributeRevocationValues", scope = XmlUnsignedSignaturePropertiesType.class) public JAXBElement createXmlUnsignedSignaturePropertiesTypeAttributeRevocationValues(XmlRevocationValuesType value) { - return new JAXBElement(_AttributeRevocationValues_QNAME, XmlRevocationValuesType.class, XmlUnsignedSignaturePropertiesType.class, value); + return new JAXBElement<>(_AttributeRevocationValues_QNAME, XmlRevocationValuesType.class, XmlUnsignedSignaturePropertiesType.class, value); } /** @@ -946,7 +948,7 @@ public JAXBElement createXmlUnsignedSignatureProperties */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "CompleteCertificateRefs", scope = XmlUnsignedSignaturePropertiesType.class) public JAXBElement createXmlUnsignedSignaturePropertiesTypeCompleteCertificateRefs(XmlCompleteCertificateRefsType value) { - return new JAXBElement(_CompleteCertificateRefs_QNAME, XmlCompleteCertificateRefsType.class, XmlUnsignedSignaturePropertiesType.class, value); + return new JAXBElement<>(_CompleteCertificateRefs_QNAME, XmlCompleteCertificateRefsType.class, XmlUnsignedSignaturePropertiesType.class, value); } /** @@ -955,7 +957,7 @@ public JAXBElement createXmlUnsignedSignaturePro */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "RevocationValues", scope = XmlUnsignedSignaturePropertiesType.class) public JAXBElement createXmlUnsignedSignaturePropertiesTypeRevocationValues(XmlRevocationValuesType value) { - return new JAXBElement(_RevocationValues_QNAME, XmlRevocationValuesType.class, XmlUnsignedSignaturePropertiesType.class, value); + return new JAXBElement<>(_RevocationValues_QNAME, XmlRevocationValuesType.class, XmlUnsignedSignaturePropertiesType.class, value); } /** @@ -964,7 +966,7 @@ public JAXBElement createXmlUnsignedSignatureProperties */ @XmlElementDecl(namespace = "http://uri.etsi.org/01903/v1.3.2#", name = "AttributeRevocationRefs", scope = XmlUnsignedSignaturePropertiesType.class) public JAXBElement createXmlUnsignedSignaturePropertiesTypeAttributeRevocationRefs(XmlCompleteRevocationRefsType value) { - return new JAXBElement(_AttributeRevocationRefs_QNAME, XmlCompleteRevocationRefsType.class, XmlUnsignedSignaturePropertiesType.class, value); + return new JAXBElement<>(_AttributeRevocationRefs_QNAME, XmlCompleteRevocationRefsType.class, XmlUnsignedSignaturePropertiesType.class, value); } } diff --git a/src/main/java/xades4j/xml/bind/xades/XmlIntegerListType.java b/src/main/java/xades4j/xml/bind/xades/XmlIntegerListType.java index 0677bb3f..a1e3c722 100644 --- a/src/main/java/xades4j/xml/bind/xades/XmlIntegerListType.java +++ b/src/main/java/xades4j/xml/bind/xades/XmlIntegerListType.java @@ -8,14 +8,15 @@ package xades4j.xml.bind.xades; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlType; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + /** *

Java class for IntegerListType complex type. diff --git a/src/main/java/xades4j/xml/bind/xmldsig/ObjectFactory.java b/src/main/java/xades4j/xml/bind/xmldsig/ObjectFactory.java index 72e5a3a1..09e8e597 100644 --- a/src/main/java/xades4j/xml/bind/xmldsig/ObjectFactory.java +++ b/src/main/java/xades4j/xml/bind/xmldsig/ObjectFactory.java @@ -8,14 +8,15 @@ package xades4j.xml.bind.xmldsig; -import java.math.BigInteger; import jakarta.xml.bind.JAXBElement; import jakarta.xml.bind.annotation.XmlElementDecl; import jakarta.xml.bind.annotation.XmlRegistry; import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import javax.xml.namespace.QName; import xades4j.xml.bind.Base64XmlAdapter; +import javax.xml.namespace.QName; +import java.math.BigInteger; + /** * This object contains factory methods for each @@ -34,46 +35,47 @@ @XmlRegistry public class ObjectFactory { - private final static QName _PGPData_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "PGPData"); - private final static QName _SPKIData_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "SPKIData"); - private final static QName _RetrievalMethod_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "RetrievalMethod"); - private final static QName _CanonicalizationMethod_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "CanonicalizationMethod"); - private final static QName _SignatureProperty_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "SignatureProperty"); - private final static QName _Transforms_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "Transforms"); - private final static QName _Manifest_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "Manifest"); - private final static QName _SignatureMethod_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "SignatureMethod"); - private final static QName _KeyInfo_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "KeyInfo"); - private final static QName _DigestMethod_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "DigestMethod"); - private final static QName _MgmtData_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "MgmtData"); - private final static QName _Reference_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "Reference"); - private final static QName _RSAKeyValue_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "RSAKeyValue"); - private final static QName _Signature_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "Signature"); - private final static QName _DSAKeyValue_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "DSAKeyValue"); - private final static QName _SignedInfo_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "SignedInfo"); - private final static QName _Object_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "Object"); - private final static QName _SignatureValue_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "SignatureValue"); - private final static QName _Transform_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "Transform"); - private final static QName _X509Data_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "X509Data"); - private final static QName _DigestValue_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "DigestValue"); - private final static QName _SignatureProperties_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "SignatureProperties"); - private final static QName _KeyName_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "KeyName"); - private final static QName _KeyValue_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "KeyValue"); - private final static QName _XmlX509DataTypeX509IssuerSerial_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "X509IssuerSerial"); - private final static QName _XmlX509DataTypeX509Certificate_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "X509Certificate"); - private final static QName _XmlX509DataTypeX509SKI_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "X509SKI"); - private final static QName _XmlX509DataTypeX509SubjectName_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "X509SubjectName"); - private final static QName _XmlX509DataTypeX509CRL_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "X509CRL"); - private final static QName _XmlSignatureMethodTypeHMACOutputLength_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "HMACOutputLength"); - private final static QName _XmlPGPDataTypePGPKeyID_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "PGPKeyID"); - private final static QName _XmlPGPDataTypePGPKeyPacket_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "PGPKeyPacket"); - private final static QName _XmlTransformTypeXPath_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "XPath"); - private final static QName _XmlSPKIDataTypeSPKISexp_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "SPKISexp"); + private static final QName _PGPData_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "PGPData"); + private static final QName _SPKIData_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "SPKIData"); + private static final QName _RetrievalMethod_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "RetrievalMethod"); + private static final QName _CanonicalizationMethod_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "CanonicalizationMethod"); + private static final QName _SignatureProperty_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "SignatureProperty"); + private static final QName _Transforms_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "Transforms"); + private static final QName _Manifest_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "Manifest"); + private static final QName _SignatureMethod_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "SignatureMethod"); + private static final QName _KeyInfo_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "KeyInfo"); + private static final QName _DigestMethod_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "DigestMethod"); + private static final QName _MgmtData_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "MgmtData"); + private static final QName _Reference_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "Reference"); + private static final QName _RSAKeyValue_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "RSAKeyValue"); + private static final QName _Signature_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "Signature"); + private static final QName _DSAKeyValue_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "DSAKeyValue"); + private static final QName _SignedInfo_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "SignedInfo"); + private static final QName _Object_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "Object"); + private static final QName _SignatureValue_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "SignatureValue"); + private static final QName _Transform_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "Transform"); + private static final QName _X509Data_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "X509Data"); + private static final QName _DigestValue_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "DigestValue"); + private static final QName _SignatureProperties_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "SignatureProperties"); + private static final QName _KeyName_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "KeyName"); + private static final QName _KeyValue_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "KeyValue"); + private static final QName _XmlX509DataTypeX509IssuerSerial_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "X509IssuerSerial"); + private static final QName _XmlX509DataTypeX509Certificate_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "X509Certificate"); + private static final QName _XmlX509DataTypeX509SKI_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "X509SKI"); + private static final QName _XmlX509DataTypeX509SubjectName_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "X509SubjectName"); + private static final QName _XmlX509DataTypeX509CRL_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "X509CRL"); + private static final QName _XmlSignatureMethodTypeHMACOutputLength_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "HMACOutputLength"); + private static final QName _XmlPGPDataTypePGPKeyID_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "PGPKeyID"); + private static final QName _XmlPGPDataTypePGPKeyPacket_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "PGPKeyPacket"); + private static final QName _XmlTransformTypeXPath_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "XPath"); + private static final QName _XmlSPKIDataTypeSPKISexp_QNAME = new QName("http://www.w3.org/2000/09/xmldsig#", "SPKISexp"); /** * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: xades4j.marshalling.xmldsig * */ public ObjectFactory() { + // TODO document why this constructor is empty } /** @@ -258,7 +260,7 @@ public XmlSignedInfoType createXmlSignedInfoType() { */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "PGPData") public JAXBElement createPGPData(XmlPGPDataType value) { - return new JAXBElement(_PGPData_QNAME, XmlPGPDataType.class, null, value); + return new JAXBElement<>(_PGPData_QNAME, XmlPGPDataType.class, null, value); } /** @@ -267,7 +269,7 @@ public JAXBElement createPGPData(XmlPGPDataType value) { */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "SPKIData") public JAXBElement createSPKIData(XmlSPKIDataType value) { - return new JAXBElement(_SPKIData_QNAME, XmlSPKIDataType.class, null, value); + return new JAXBElement<>(_SPKIData_QNAME, XmlSPKIDataType.class, null, value); } /** @@ -276,7 +278,7 @@ public JAXBElement createSPKIData(XmlSPKIDataType value) { */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "RetrievalMethod") public JAXBElement createRetrievalMethod(XmlRetrievalMethodType value) { - return new JAXBElement(_RetrievalMethod_QNAME, XmlRetrievalMethodType.class, null, value); + return new JAXBElement<>(_RetrievalMethod_QNAME, XmlRetrievalMethodType.class, null, value); } /** @@ -285,7 +287,7 @@ public JAXBElement createRetrievalMethod(XmlRetrievalMet */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "CanonicalizationMethod") public JAXBElement createCanonicalizationMethod(XmlCanonicalizationMethodType value) { - return new JAXBElement(_CanonicalizationMethod_QNAME, XmlCanonicalizationMethodType.class, null, value); + return new JAXBElement<>(_CanonicalizationMethod_QNAME, XmlCanonicalizationMethodType.class, null, value); } /** @@ -294,7 +296,7 @@ public JAXBElement createCanonicalizationMethod(X */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "SignatureProperty") public JAXBElement createSignatureProperty(XmlSignaturePropertyType value) { - return new JAXBElement(_SignatureProperty_QNAME, XmlSignaturePropertyType.class, null, value); + return new JAXBElement<>(_SignatureProperty_QNAME, XmlSignaturePropertyType.class, null, value); } /** @@ -303,7 +305,7 @@ public JAXBElement createSignatureProperty(XmlSignatur */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "Transforms") public JAXBElement createTransforms(XmlTransformsType value) { - return new JAXBElement(_Transforms_QNAME, XmlTransformsType.class, null, value); + return new JAXBElement<>(_Transforms_QNAME, XmlTransformsType.class, null, value); } /** @@ -312,7 +314,7 @@ public JAXBElement createTransforms(XmlTransformsType value) */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "Manifest") public JAXBElement createManifest(XmlManifestType value) { - return new JAXBElement(_Manifest_QNAME, XmlManifestType.class, null, value); + return new JAXBElement<>(_Manifest_QNAME, XmlManifestType.class, null, value); } /** @@ -321,7 +323,7 @@ public JAXBElement createManifest(XmlManifestType value) { */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "SignatureMethod") public JAXBElement createSignatureMethod(XmlSignatureMethodType value) { - return new JAXBElement(_SignatureMethod_QNAME, XmlSignatureMethodType.class, null, value); + return new JAXBElement<>(_SignatureMethod_QNAME, XmlSignatureMethodType.class, null, value); } /** @@ -330,7 +332,7 @@ public JAXBElement createSignatureMethod(XmlSignatureMet */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "KeyInfo") public JAXBElement createKeyInfo(XmlKeyInfoType value) { - return new JAXBElement(_KeyInfo_QNAME, XmlKeyInfoType.class, null, value); + return new JAXBElement<>(_KeyInfo_QNAME, XmlKeyInfoType.class, null, value); } /** @@ -339,7 +341,7 @@ public JAXBElement createKeyInfo(XmlKeyInfoType value) { */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "DigestMethod") public JAXBElement createDigestMethod(XmlDigestMethodType value) { - return new JAXBElement(_DigestMethod_QNAME, XmlDigestMethodType.class, null, value); + return new JAXBElement<>(_DigestMethod_QNAME, XmlDigestMethodType.class, null, value); } /** @@ -348,7 +350,7 @@ public JAXBElement createDigestMethod(XmlDigestMethodType v */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "MgmtData") public JAXBElement createMgmtData(String value) { - return new JAXBElement(_MgmtData_QNAME, String.class, null, value); + return new JAXBElement<>(_MgmtData_QNAME, String.class, null, value); } /** @@ -357,7 +359,7 @@ public JAXBElement createMgmtData(String value) { */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "Reference") public JAXBElement createReference(XmlReferenceType value) { - return new JAXBElement(_Reference_QNAME, XmlReferenceType.class, null, value); + return new JAXBElement<>(_Reference_QNAME, XmlReferenceType.class, null, value); } /** @@ -366,7 +368,7 @@ public JAXBElement createReference(XmlReferenceType value) { */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "RSAKeyValue") public JAXBElement createRSAKeyValue(XmlRSAKeyValueType value) { - return new JAXBElement(_RSAKeyValue_QNAME, XmlRSAKeyValueType.class, null, value); + return new JAXBElement<>(_RSAKeyValue_QNAME, XmlRSAKeyValueType.class, null, value); } /** @@ -375,7 +377,7 @@ public JAXBElement createRSAKeyValue(XmlRSAKeyValueType valu */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "Signature") public JAXBElement createSignature(XmlSignatureType value) { - return new JAXBElement(_Signature_QNAME, XmlSignatureType.class, null, value); + return new JAXBElement<>(_Signature_QNAME, XmlSignatureType.class, null, value); } /** @@ -384,7 +386,7 @@ public JAXBElement createSignature(XmlSignatureType value) { */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "DSAKeyValue") public JAXBElement createDSAKeyValue(XmlDSAKeyValueType value) { - return new JAXBElement(_DSAKeyValue_QNAME, XmlDSAKeyValueType.class, null, value); + return new JAXBElement<>(_DSAKeyValue_QNAME, XmlDSAKeyValueType.class, null, value); } /** @@ -393,7 +395,7 @@ public JAXBElement createDSAKeyValue(XmlDSAKeyValueType valu */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "SignedInfo") public JAXBElement createSignedInfo(XmlSignedInfoType value) { - return new JAXBElement(_SignedInfo_QNAME, XmlSignedInfoType.class, null, value); + return new JAXBElement<>(_SignedInfo_QNAME, XmlSignedInfoType.class, null, value); } /** @@ -402,7 +404,7 @@ public JAXBElement createSignedInfo(XmlSignedInfoType value) */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "Object") public JAXBElement createObject(XmlObjectType value) { - return new JAXBElement(_Object_QNAME, XmlObjectType.class, null, value); + return new JAXBElement<>(_Object_QNAME, XmlObjectType.class, null, value); } /** @@ -411,7 +413,7 @@ public JAXBElement createObject(XmlObjectType value) { */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "SignatureValue") public JAXBElement createSignatureValue(XmlSignatureValueType value) { - return new JAXBElement(_SignatureValue_QNAME, XmlSignatureValueType.class, null, value); + return new JAXBElement<>(_SignatureValue_QNAME, XmlSignatureValueType.class, null, value); } /** @@ -420,7 +422,7 @@ public JAXBElement createSignatureValue(XmlSignatureValue */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "Transform") public JAXBElement createTransform(XmlTransformType value) { - return new JAXBElement(_Transform_QNAME, XmlTransformType.class, null, value); + return new JAXBElement<>(_Transform_QNAME, XmlTransformType.class, null, value); } /** @@ -429,7 +431,7 @@ public JAXBElement createTransform(XmlTransformType value) { */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "X509Data") public JAXBElement createX509Data(XmlX509DataType value) { - return new JAXBElement(_X509Data_QNAME, XmlX509DataType.class, null, value); + return new JAXBElement<>(_X509Data_QNAME, XmlX509DataType.class, null, value); } /** @@ -439,7 +441,7 @@ public JAXBElement createX509Data(XmlX509DataType value) { @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "DigestValue") @XmlJavaTypeAdapter(Base64XmlAdapter .class) public JAXBElement createDigestValue(byte[] value) { - return new JAXBElement(_DigestValue_QNAME, byte[].class, null, value); + return new JAXBElement<>(_DigestValue_QNAME, byte[].class, null, value); } /** @@ -448,7 +450,7 @@ public JAXBElement createDigestValue(byte[] value) { */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "SignatureProperties") public JAXBElement createSignatureProperties(XmlSignaturePropertiesType value) { - return new JAXBElement(_SignatureProperties_QNAME, XmlSignaturePropertiesType.class, null, value); + return new JAXBElement<>(_SignatureProperties_QNAME, XmlSignaturePropertiesType.class, null, value); } /** @@ -457,7 +459,7 @@ public JAXBElement createSignatureProperties(XmlSign */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "KeyName") public JAXBElement createKeyName(String value) { - return new JAXBElement(_KeyName_QNAME, String.class, null, value); + return new JAXBElement<>(_KeyName_QNAME, String.class, null, value); } /** @@ -466,7 +468,7 @@ public JAXBElement createKeyName(String value) { */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "KeyValue") public JAXBElement createKeyValue(XmlKeyValueType value) { - return new JAXBElement(_KeyValue_QNAME, XmlKeyValueType.class, null, value); + return new JAXBElement<>(_KeyValue_QNAME, XmlKeyValueType.class, null, value); } /** @@ -475,7 +477,7 @@ public JAXBElement createKeyValue(XmlKeyValueType value) { */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "X509IssuerSerial", scope = XmlX509DataType.class) public JAXBElement createXmlX509DataTypeX509IssuerSerial(XmlX509IssuerSerialType value) { - return new JAXBElement(_XmlX509DataTypeX509IssuerSerial_QNAME, XmlX509IssuerSerialType.class, XmlX509DataType.class, value); + return new JAXBElement<>(_XmlX509DataTypeX509IssuerSerial_QNAME, XmlX509IssuerSerialType.class, XmlX509DataType.class, value); } /** @@ -485,7 +487,7 @@ public JAXBElement createXmlX509DataTypeX509IssuerSeria @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "X509Certificate", scope = XmlX509DataType.class) @XmlJavaTypeAdapter(Base64XmlAdapter .class) public JAXBElement createXmlX509DataTypeX509Certificate(byte[] value) { - return new JAXBElement(_XmlX509DataTypeX509Certificate_QNAME, byte[].class, XmlX509DataType.class, value); + return new JAXBElement<>(_XmlX509DataTypeX509Certificate_QNAME, byte[].class, XmlX509DataType.class, value); } /** @@ -495,7 +497,7 @@ public JAXBElement createXmlX509DataTypeX509Certificate(byte[] value) { @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "X509SKI", scope = XmlX509DataType.class) @XmlJavaTypeAdapter(Base64XmlAdapter .class) public JAXBElement createXmlX509DataTypeX509SKI(byte[] value) { - return new JAXBElement(_XmlX509DataTypeX509SKI_QNAME, byte[].class, XmlX509DataType.class, value); + return new JAXBElement<>(_XmlX509DataTypeX509SKI_QNAME, byte[].class, XmlX509DataType.class, value); } /** @@ -504,7 +506,7 @@ public JAXBElement createXmlX509DataTypeX509SKI(byte[] value) { */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "X509SubjectName", scope = XmlX509DataType.class) public JAXBElement createXmlX509DataTypeX509SubjectName(String value) { - return new JAXBElement(_XmlX509DataTypeX509SubjectName_QNAME, String.class, XmlX509DataType.class, value); + return new JAXBElement<>(_XmlX509DataTypeX509SubjectName_QNAME, String.class, XmlX509DataType.class, value); } /** @@ -514,7 +516,7 @@ public JAXBElement createXmlX509DataTypeX509SubjectName(String value) { @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "X509CRL", scope = XmlX509DataType.class) @XmlJavaTypeAdapter(Base64XmlAdapter .class) public JAXBElement createXmlX509DataTypeX509CRL(byte[] value) { - return new JAXBElement(_XmlX509DataTypeX509CRL_QNAME, byte[].class, XmlX509DataType.class, value); + return new JAXBElement<>(_XmlX509DataTypeX509CRL_QNAME, byte[].class, XmlX509DataType.class, value); } /** @@ -523,7 +525,7 @@ public JAXBElement createXmlX509DataTypeX509CRL(byte[] value) { */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "HMACOutputLength", scope = XmlSignatureMethodType.class) public JAXBElement createXmlSignatureMethodTypeHMACOutputLength(BigInteger value) { - return new JAXBElement(_XmlSignatureMethodTypeHMACOutputLength_QNAME, BigInteger.class, XmlSignatureMethodType.class, value); + return new JAXBElement<>(_XmlSignatureMethodTypeHMACOutputLength_QNAME, BigInteger.class, XmlSignatureMethodType.class, value); } /** @@ -533,7 +535,7 @@ public JAXBElement createXmlSignatureMethodTypeHMACOutputLength(BigI @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "PGPKeyID", scope = XmlPGPDataType.class) @XmlJavaTypeAdapter(Base64XmlAdapter .class) public JAXBElement createXmlPGPDataTypePGPKeyID(byte[] value) { - return new JAXBElement(_XmlPGPDataTypePGPKeyID_QNAME, byte[].class, XmlPGPDataType.class, value); + return new JAXBElement<>(_XmlPGPDataTypePGPKeyID_QNAME, byte[].class, XmlPGPDataType.class, value); } /** @@ -543,7 +545,7 @@ public JAXBElement createXmlPGPDataTypePGPKeyID(byte[] value) { @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "PGPKeyPacket", scope = XmlPGPDataType.class) @XmlJavaTypeAdapter(Base64XmlAdapter .class) public JAXBElement createXmlPGPDataTypePGPKeyPacket(byte[] value) { - return new JAXBElement(_XmlPGPDataTypePGPKeyPacket_QNAME, byte[].class, XmlPGPDataType.class, value); + return new JAXBElement<>(_XmlPGPDataTypePGPKeyPacket_QNAME, byte[].class, XmlPGPDataType.class, value); } /** @@ -552,7 +554,7 @@ public JAXBElement createXmlPGPDataTypePGPKeyPacket(byte[] value) { */ @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "XPath", scope = XmlTransformType.class) public JAXBElement createXmlTransformTypeXPath(String value) { - return new JAXBElement(_XmlTransformTypeXPath_QNAME, String.class, XmlTransformType.class, value); + return new JAXBElement<>(_XmlTransformTypeXPath_QNAME, String.class, XmlTransformType.class, value); } /** @@ -562,7 +564,7 @@ public JAXBElement createXmlTransformTypeXPath(String value) { @XmlElementDecl(namespace = "http://www.w3.org/2000/09/xmldsig#", name = "SPKISexp", scope = XmlSPKIDataType.class) @XmlJavaTypeAdapter(Base64XmlAdapter .class) public JAXBElement createXmlSPKIDataTypeSPKISexp(byte[] value) { - return new JAXBElement(_XmlSPKIDataTypeSPKISexp_QNAME, byte[].class, XmlSPKIDataType.class, value); + return new JAXBElement<>(_XmlSPKIDataTypeSPKISexp_QNAME, byte[].class, XmlSPKIDataType.class, value); } } diff --git a/src/main/java/xades4j/xml/marshalling/ToXmlSignaturePolicyConverter.java b/src/main/java/xades4j/xml/marshalling/ToXmlSignaturePolicyConverter.java index 2f6b0f67..55c53dac 100644 --- a/src/main/java/xades4j/xml/marshalling/ToXmlSignaturePolicyConverter.java +++ b/src/main/java/xades4j/xml/marshalling/ToXmlSignaturePolicyConverter.java @@ -17,19 +17,15 @@ package xades4j.xml.marshalling; import jakarta.xml.bind.JAXBElement; -import javax.xml.namespace.QName; import org.w3c.dom.Document; import xades4j.properties.QualifyingProperty; import xades4j.properties.data.PropertyDataObject; import xades4j.properties.data.SignaturePolicyData; -import xades4j.xml.bind.xades.XmlAnyType; -import xades4j.xml.bind.xades.XmlDigestAlgAndValueType; -import xades4j.xml.bind.xades.XmlSigPolicyQualifiersListType; -import xades4j.xml.bind.xades.XmlSignaturePolicyIdType; -import xades4j.xml.bind.xades.XmlSignaturePolicyIdentifierType; -import xades4j.xml.bind.xades.XmlSignedPropertiesType; +import xades4j.xml.bind.xades.*; import xades4j.xml.bind.xmldsig.XmlDigestMethodType; +import javax.xml.namespace.QName; + /** * * @author Luís @@ -51,12 +47,12 @@ public void convertIntoObjectTree( } else { - xmlSigPolicy.setSignaturePolicyId(getSignaturePolicy(sigPolicyData, doc)); + xmlSigPolicy.setSignaturePolicyId(getSignaturePolicy(sigPolicyData)); } xmlProps.getSignedSignatureProperties().setSignaturePolicyIdentifier(xmlSigPolicy); } - private XmlSignaturePolicyIdType getSignaturePolicy(SignaturePolicyData sigPolicyData, Document doc) + private XmlSignaturePolicyIdType getSignaturePolicy(SignaturePolicyData sigPolicyData) { XmlSignaturePolicyIdType xmlSigPolicyId = new XmlSignaturePolicyIdType(); diff --git a/src/test/java/xades4j/algorithms/XPath2FilterTransformTest.java b/src/test/java/xades4j/algorithms/XPath2FilterTransformTest.java index 98e52a66..d5eb41b9 100644 --- a/src/test/java/xades4j/algorithms/XPath2FilterTransformTest.java +++ b/src/test/java/xades4j/algorithms/XPath2FilterTransformTest.java @@ -16,20 +16,20 @@ */ package xades4j.algorithms; -import java.util.List; - import org.junit.jupiter.api.Test; import xades4j.algorithms.XPath2FilterTransform.XPath2Filter; +import java.util.List; + import static org.junit.jupiter.api.Assertions.*; /** * @author Luís */ -public class XPath2FilterTransformTest +class XPath2FilterTransformTest { @Test - public void testCreation() + void testCreation() { XPath2FilterTransform t1 = XPath2Filter.intersect("1"); XPath2FilterTransform t2 = t1.union("2"); @@ -55,7 +55,7 @@ public void testCreation() } @Test - public void testChangeFiltersListFails() + void testChangeFiltersListFails() { XPath2FilterTransform t = XPath2Filter.intersect("1").union("2"); assertThrows(UnsupportedOperationException.class, () -> { diff --git a/src/test/java/xades4j/production/KeyInfoBuilderTest.java b/src/test/java/xades4j/production/KeyInfoBuilderTest.java index 15f736d7..2f27fbe4 100644 --- a/src/test/java/xades4j/production/KeyInfoBuilderTest.java +++ b/src/test/java/xades4j/production/KeyInfoBuilderTest.java @@ -16,12 +16,6 @@ */ package xades4j.production; -import java.io.FileInputStream; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; -import java.util.Arrays; -import java.util.List; - import org.apache.xml.security.keys.content.KeyValue; import org.apache.xml.security.keys.content.x509.XMLX509Certificate; import org.apache.xml.security.signature.SignedInfo; @@ -33,6 +27,12 @@ import xades4j.providers.impl.DefaultX500NameStyleProvider; import xades4j.utils.SignatureServicesTestBase; +import java.io.FileInputStream; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; +import java.util.Arrays; +import java.util.List; + import static org.junit.jupiter.api.Assertions.*; /** @@ -56,7 +56,7 @@ public static void setUpClass() throws Exception } @Test - public void testIncludeCertAndKey() throws Exception + void testIncludeCertAndKey() throws Exception { KeyInfoBuilder keyInfoBuilder = new KeyInfoBuilder( new BasicSignatureOptions().includeSigningCertificate(SigningCertificateMode.SIGNING_CERTIFICATE).includePublicKey(true), @@ -77,7 +77,7 @@ public void testIncludeCertAndKey() throws Exception } @Test - public void testIncludeCertChain() throws Exception + void testIncludeCertChain() throws Exception { KeyInfoBuilder keyInfoBuilder = new KeyInfoBuilder( new BasicSignatureOptions().includeSigningCertificate(SigningCertificateMode.FULL_CHAIN), @@ -101,7 +101,7 @@ public void testIncludeCertChain() throws Exception } @Test - public void testIncludeIssuerSerial() throws Exception + void testIncludeIssuerSerial() throws Exception { KeyInfoBuilder keyInfoBuilder = new KeyInfoBuilder( new BasicSignatureOptions().includeIssuerSerial(true), @@ -117,7 +117,7 @@ public void testIncludeIssuerSerial() throws Exception } @Test - public void testIncludeSubjectName() throws Exception + void testIncludeSubjectName() throws Exception { KeyInfoBuilder keyInfoBuilder = new KeyInfoBuilder( new BasicSignatureOptions().includeSubjectName(true), @@ -133,7 +133,7 @@ public void testIncludeSubjectName() throws Exception } @Test - public void testSignKeyInfo() throws Exception + void testSignKeyInfo() throws Exception { KeyInfoBuilder keyInfoBuilder = new KeyInfoBuilder( new BasicSignatureOptions().signKeyInfo(true), diff --git a/src/test/java/xades4j/production/OtherSignerTests.java b/src/test/java/xades4j/production/OtherSignerTests.java index 94141e03..3e5f9b60 100644 --- a/src/test/java/xades4j/production/OtherSignerTests.java +++ b/src/test/java/xades4j/production/OtherSignerTests.java @@ -21,13 +21,13 @@ import org.apache.xml.security.utils.resolver.ResourceResolverContext; import org.apache.xml.security.utils.resolver.ResourceResolverException; import org.apache.xml.security.utils.resolver.ResourceResolverSpi; +import org.junit.jupiter.api.Test; import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; import xades4j.algorithms.EnvelopedSignatureTransform; import xades4j.algorithms.ExclusiveCanonicalXMLWithoutComments; import xades4j.properties.DataObjectDesc; -import org.junit.jupiter.api.Test; -import org.w3c.dom.Document; -import org.w3c.dom.Element; import xades4j.properties.QualifyingProperty; import xades4j.providers.ValidationDataProvider; import xades4j.providers.impl.ValidationDataFromCertValidationProvider; @@ -37,7 +37,6 @@ import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathFactory; - import java.io.ByteArrayInputStream; import java.util.Iterator; @@ -46,16 +45,17 @@ import static org.apache.xml.security.c14n.Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS; import static org.apache.xml.security.c14n.Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS; import static org.apache.xml.security.signature.XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA512; -import static org.apache.xml.security.utils.Constants.*; -import static org.junit.jupiter.api.Assertions.*; +import static org.apache.xml.security.utils.Constants.SignatureSpecNS; +import static org.apache.xml.security.utils.Constants._TAG_SIGNATURE; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Luís */ -public class OtherSignerTests extends SignerTestBase +class OtherSignerTests extends SignerTestBase { @Test - public void testSignAndAppendAsFirstChild() throws Exception + void testSignAndAppendAsFirstChild() throws Exception { Document doc = getTestDocument(); Element root = doc.getDocumentElement(); @@ -72,7 +72,7 @@ public void testSignAndAppendAsFirstChild() throws Exception } @Test - public void testSignWithManifest() throws Exception + void testSignWithManifest() throws Exception { Document doc = getTestDocument(); Element root = doc.getDocumentElement(); @@ -88,7 +88,7 @@ public void testSignWithManifest() throws Exception } @Test - public void testSignUsingCustomResolver() throws Exception + void testSignUsingCustomResolver() throws Exception { Document doc = getNewDocument(); XadesSigner signer = new XadesBesSigningProfile(keyingProviderMy).newSigner(); @@ -123,7 +123,7 @@ public boolean engineCanResolveURI(ResourceResolverContext context) } @Test - public void testSignatureAlgorithms() throws Exception + void testSignatureAlgorithms() throws Exception { Document doc = getTestDocument(); Element elemToSign = doc.getDocumentElement(); diff --git a/src/test/java/xades4j/production/PtCcSignerTests.java b/src/test/java/xades4j/production/PtCcSignerTests.java index 40f7d2ec..2c68df45 100644 --- a/src/test/java/xades4j/production/PtCcSignerTests.java +++ b/src/test/java/xades4j/production/PtCcSignerTests.java @@ -12,10 +12,10 @@ import java.security.cert.X509Certificate; import java.util.List; -public class PtCcSignerTests extends SignerTestBase +class PtCcSignerTests extends SignerTestBase { @Test - public void testSignTPtCC() throws Exception + void testSignTPtCC() throws Exception { assumePtCcPkcs11(); @@ -33,7 +33,7 @@ public void testSignTPtCC() throws Exception } @Test - public void testSignBesPtCCWindowsMy() throws Exception + void testSignBesPtCCWindowsMy() throws Exception { assumeWindows(); assumePtCcPkcs11(); @@ -65,7 +65,7 @@ public Entry selectCertificate(List availableCertificates) { for (Entry e : availableCertificates) { - if (e.getCertificate().getIssuerDN().getName().contains("EC de Assinatura Digital")) + if (e.getCertificate().getIssuerX500Principal().getName().contains("EC de Assinatura Digital")) { return e; } diff --git a/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java b/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java index ff505a5c..95b14583 100644 --- a/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java +++ b/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java @@ -44,7 +44,7 @@ public static void setUpClass() } @Test - public void testProcess() throws Exception + void testProcess() throws Exception { Document doc = getNewDocument(); @@ -94,7 +94,7 @@ public void testProcess() throws Exception } @Test - public void testAddManifest() throws Exception + void testAddManifest() throws Exception { Document doc = getNewDocument(); @@ -171,7 +171,7 @@ public boolean engineCanResolveURI(ResourceResolverContext context) } @Test - public void testAddNullReference() throws Exception + void testAddNullReference() throws Exception { Document doc = SignatureServicesTestBase.getNewDocument(); @@ -193,7 +193,7 @@ public void testAddNullReference() throws Exception } @Test - public void testAddMultipleNullReferencesFails() throws Exception + void testAddMultipleNullReferencesFails() throws Exception { SignedDataObjects dataObjsDescs = new SignedDataObjects(); assertThrows(IllegalStateException.class, () -> { diff --git a/src/test/java/xades4j/production/SignerBESTest.java b/src/test/java/xades4j/production/SignerBESTest.java index cd558318..a4d2cf5f 100644 --- a/src/test/java/xades4j/production/SignerBESTest.java +++ b/src/test/java/xades4j/production/SignerBESTest.java @@ -16,7 +16,6 @@ */ package xades4j.production; -import org.apache.xml.security.stax.impl.resourceResolvers.ResolverHttp; import org.apache.xml.security.utils.resolver.implementations.ResolverDirectHTTP; import org.apache.xml.security.utils.resolver.implementations.ResolverLocalFilesystem; import org.junit.jupiter.api.Test; @@ -26,30 +25,23 @@ import xades4j.algorithms.EnvelopedSignatureTransform; import xades4j.algorithms.XPath2FilterTransform.XPath2Filter; import xades4j.algorithms.XPathTransform; -import xades4j.properties.AllDataObjsCommitmentTypeProperty; -import xades4j.properties.CommitmentTypeProperty; -import xades4j.properties.CounterSignatureProperty; -import xades4j.properties.DataObjectDesc; -import xades4j.properties.DataObjectFormatProperty; -import xades4j.properties.IndividualDataObjsTimeStampProperty; -import xades4j.properties.SignerRoleProperty; +import xades4j.properties.*; import xades4j.providers.SignaturePropertiesCollector; import xades4j.providers.SignaturePropertiesProvider; -import xades4j.providers.impl.HttpTsaConfiguration; import java.io.File; /** * @author Luís */ -public class SignerBESTest extends SignerTestBase +class SignerBESTest extends SignerTestBase { public SignerBESTest() { } @Test - public void testSignBES() throws Exception + void testSignBES() throws Exception { Document doc1 = getTestDocument(); Document doc2 = getDocument("content.xml"); @@ -70,7 +62,7 @@ public void testSignBES() throws Exception } @Test - public void testSignBESWithEllipticCurveKey() throws Exception + void testSignBESWithEllipticCurveKey() throws Exception { Document doc = getTestDocument(); Element elemToSign = doc.getDocumentElement(); @@ -84,7 +76,7 @@ public void testSignBESWithEllipticCurveKey() throws Exception } @Test - public void testSignBESExternalRes() throws Exception + void testSignBESExternalRes() throws Exception { Document doc = getNewDocument(); XadesSigner signer = new XadesBesSigningProfile(keyingProviderNist).with(DEFAULT_TEST_TSA).newSigner(); @@ -101,7 +93,7 @@ public void testSignBESExternalRes() throws Exception } @Test - public void testSignBESWithCounterSig() throws Exception + void testSignBESWithCounterSig() throws Exception { Document doc = getTestDocument(); Element elemToSign = doc.getDocumentElement(); @@ -129,7 +121,7 @@ public void provideProperties( } @Test - public void testSignBESDetachedWithXPathAndNamespaces() throws Exception + void testSignBESDetachedWithXPathAndNamespaces() throws Exception { Document doc = getNewDocument(); diff --git a/src/test/java/xades4j/production/SignerCTest.java b/src/test/java/xades4j/production/SignerCTest.java index 65d29cf8..b078c18c 100644 --- a/src/test/java/xades4j/production/SignerCTest.java +++ b/src/test/java/xades4j/production/SignerCTest.java @@ -16,24 +16,24 @@ */ package xades4j.production; -import java.io.FileInputStream; -import java.io.InputStream; import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import org.w3c.dom.Element; -import xades4j.providers.impl.HttpTsaConfiguration; -import xades4j.providers.impl.ValidationDataFromCertValidationProvider; import xades4j.providers.ValidationDataProvider; +import xades4j.providers.impl.ValidationDataFromCertValidationProvider; import xades4j.verification.VerifierTestBase; +import java.io.FileInputStream; +import java.io.InputStream; + /** * * @author Luís */ -public class SignerCTest extends SignerTestBase +class SignerCTest extends SignerTestBase { @Test - public void testSignC() throws Exception + void testSignC() throws Exception { Document doc = getTestDocument(); Element elemToSign = doc.getDocumentElement(); @@ -46,7 +46,7 @@ public void testSignC() throws Exception } @Test - public void testSignFileDetachedC() throws Exception + void testSignFileDetachedC() throws Exception { ValidationDataProvider vdp = new ValidationDataFromCertValidationProvider(VerifierTestBase.validationProviderNist); XadesSigner signer = new XadesCSigningProfile(keyingProviderNist, vdp).with(DEFAULT_TEST_TSA).newSigner(); diff --git a/src/test/java/xades4j/production/SignerEPESTest.java b/src/test/java/xades4j/production/SignerEPESTest.java index fbd3f5be..6b1ba873 100644 --- a/src/test/java/xades4j/production/SignerEPESTest.java +++ b/src/test/java/xades4j/production/SignerEPESTest.java @@ -31,14 +31,14 @@ /** * @author Luís */ -public class SignerEPESTest extends SignerTestBase +class SignerEPESTest extends SignerTestBase { @ParameterizedTest @CsvSource({ "http://www.example.com/policy, document.signed.epes_1.xml", ", document.signed.epes_2.xml" }) - public void testSignEPES(String locationUrl, String output) throws Exception + void testSignEPES(String locationUrl, String output) throws Exception { Document doc = getTestDocument(); Element elemToSign = doc.getDocumentElement(); diff --git a/src/test/java/xades4j/production/SignerSpecificTest.java b/src/test/java/xades4j/production/SignerSpecificTest.java index 08d7172c..a2425458 100644 --- a/src/test/java/xades4j/production/SignerSpecificTest.java +++ b/src/test/java/xades4j/production/SignerSpecificTest.java @@ -56,13 +56,13 @@ public static List data() @ParameterizedTest @MethodSource("data") - public void signWithNationalCertificate(ASN1Encodable commonName) throws Exception + void signWithNationalCertificate(ASN1Encodable commonName) throws Exception { Security.addProvider(new BouncyCastleProvider()); KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", BouncyCastleProvider.PROVIDER_NAME); keyGen.initialize(1024, new SecureRandom()); Date validityBeginDate = new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000); - long add = (1L * 365L * 24L * 60L * 60L * 1000L); //1 year + long add = (365L * 24L * 60L * 60L * 1000L); //1 year Date validityEndDate = new Date(System.currentTimeMillis() + add); KeyPair keyPair = keyGen.generateKeyPair(); diff --git a/src/test/java/xades4j/production/SignerTTest.java b/src/test/java/xades4j/production/SignerTTest.java index 9a55a3ee..b7bcffe9 100644 --- a/src/test/java/xades4j/production/SignerTTest.java +++ b/src/test/java/xades4j/production/SignerTTest.java @@ -28,10 +28,10 @@ /** * @author Luís */ -public class SignerTTest extends SignerTestBase +class SignerTTest extends SignerTestBase { @Test - public void testSignTExclusiveC14NWithoutPolicy() throws Exception + void testSignTExclusiveC14NWithoutPolicy() throws Exception { Document doc = getTestDocument(); Element elemToSign = doc.getDocumentElement(); @@ -50,7 +50,7 @@ public void testSignTExclusiveC14NWithoutPolicy() throws Exception } @Test - public void testSignTWithPolicy() throws Exception + void testSignTWithPolicy() throws Exception { Document doc = getTestDocument(); Element elemToSign = doc.getDocumentElement(); diff --git a/src/test/java/xades4j/production/UncheckedSignerBESTest.java b/src/test/java/xades4j/production/UncheckedSignerBESTest.java index 4d2dd5d5..2fee96e7 100644 --- a/src/test/java/xades4j/production/UncheckedSignerBESTest.java +++ b/src/test/java/xades4j/production/UncheckedSignerBESTest.java @@ -43,13 +43,13 @@ * * @author Fiona Klute */ -public class UncheckedSignerBESTest extends SignerTestBase +class UncheckedSignerBESTest extends SignerTestBase { - private KeyingDataProvider keyingProviderGood; - private KeyingDataProvider keyingProviderNoSign; - private KeyingDataProvider keyingProviderExp; - private KeyingDataProvider keyingProviderNyv; - private CertificateValidationProvider validationProvider; + private final KeyingDataProvider keyingProviderGood; + private final KeyingDataProvider keyingProviderNoSign; + private final KeyingDataProvider keyingProviderExp; + private final KeyingDataProvider keyingProviderNyv; + private final CertificateValidationProvider validationProvider; public UncheckedSignerBESTest() throws Exception { @@ -127,20 +127,20 @@ private CertificateValidationProvider genValidationProvider(final String root, f } @Test - public void testUncheckedSignBes() throws Exception + void testUncheckedSignBes() throws Exception { CertificateValidationProvider prov = genValidationProvider("my/TestCA.cer", "my"); trySignAndVerify(keyingProviderMy, prov, "document.unchecked.signed.bes.xml"); } @Test - public void testUncheckedSignBesGood() throws Exception + void testUncheckedSignBesGood() throws Exception { trySignAndVerify(keyingProviderGood, validationProvider, "document.unchecked.signed.bes.good.xml"); } @Test - public void testUncheckedSignBesNoSignKeyUsage() throws Exception + void testUncheckedSignBesNoSignKeyUsage() throws Exception { assertThrows(SigningCertificateKeyUsageException.class, () -> { trySignAndVerify(keyingProviderNoSign, validationProvider, "document.unchecked.signed.bes.nosign.xml"); @@ -148,7 +148,7 @@ public void testUncheckedSignBesNoSignKeyUsage() throws Exception } @Test - public void testUncheckedSignBesNoSignKeyUsageUncheckedVerify() throws Exception + void testUncheckedSignBesNoSignKeyUsageUncheckedVerify() throws Exception { // same certificate as in testUncheckedSignBesNoSignKeyUsage(), but keyUsage // check disabled during verification @@ -156,7 +156,7 @@ public void testUncheckedSignBesNoSignKeyUsageUncheckedVerify() throws Exception } @Test - public void testUncheckedSignBesExpired() throws Exception + void testUncheckedSignBesExpired() throws Exception { assertThrows(CannotBuildCertificationPathException.class, () -> { trySignAndVerify(keyingProviderExp, validationProvider, "document.unchecked.signed.bes.expired.xml"); @@ -164,7 +164,7 @@ public void testUncheckedSignBesExpired() throws Exception } @Test - public void testUncheckedSignBesNyv() throws Exception + void testUncheckedSignBesNyv() throws Exception { assertThrows(CannotBuildCertificationPathException.class, () -> { trySignAndVerify(keyingProviderNyv, validationProvider, "document.unchecked.signed.bes.nyv.xml"); diff --git a/src/test/java/xades4j/production/XadesBesSigningProfileTest.java b/src/test/java/xades4j/production/XadesBesSigningProfileTest.java index 60410421..5ad3561a 100644 --- a/src/test/java/xades4j/production/XadesBesSigningProfileTest.java +++ b/src/test/java/xades4j/production/XadesBesSigningProfileTest.java @@ -16,12 +16,13 @@ */ package xades4j.production; +import org.junit.jupiter.api.Test; +import xades4j.providers.KeyingDataProvider; +import xades4j.utils.XadesProfileResolutionException; + import java.security.PrivateKey; import java.security.cert.X509Certificate; import java.util.List; -import org.junit.jupiter.api.Test; -import xades4j.utils.XadesProfileResolutionException; -import xades4j.providers.KeyingDataProvider; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -29,10 +30,10 @@ * * @author Luís */ -public class XadesBesSigningProfileTest +class XadesBesSigningProfileTest { @Test - public void testGetSigner() throws XadesProfileResolutionException + void testGetSigner() throws XadesProfileResolutionException { XadesSigner s = new XadesBesSigningProfile(new KeyingDataProvider() { diff --git a/src/test/java/xades4j/production/XadesSignatureFormatExtenderImplTest.java b/src/test/java/xades4j/production/XadesSignatureFormatExtenderImplTest.java index 5ce7d29e..33bf31e0 100644 --- a/src/test/java/xades4j/production/XadesSignatureFormatExtenderImplTest.java +++ b/src/test/java/xades4j/production/XadesSignatureFormatExtenderImplTest.java @@ -16,30 +16,25 @@ */ package xades4j.production; -import xades4j.properties.UnsignedProperties; -import java.util.ArrayList; -import java.util.Collection; import org.apache.xml.security.signature.XMLSignature; import org.apache.xml.security.utils.Constants; import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; -import static xades4j.production.SignerTestBase.keyingProviderMy; -import xades4j.properties.ArchiveTimeStampProperty; -import xades4j.properties.CounterSignatureProperty; -import xades4j.properties.SignatureTimeStampProperty; -import xades4j.properties.UnsignedSignatureProperty; -import xades4j.providers.impl.HttpTsaConfiguration; +import xades4j.properties.*; + +import java.util.ArrayList; +import java.util.Collection; /** * * @author Luís */ -public class XadesSignatureFormatExtenderImplTest extends SignerTestBase +class XadesSignatureFormatExtenderImplTest extends SignerTestBase { @Test - public void testEnrichSignatureWithNestedCounterSig() throws Exception + void testEnrichSignatureWithNestedCounterSig() throws Exception { Document doc = getDocument("document.signed.bes.cs.xml"); NodeList signatures = doc.getElementsByTagNameNS(Constants.SignatureSpecNS, Constants._TAG_SIGNATURE); @@ -60,7 +55,7 @@ public void testEnrichSignatureWithNestedCounterSig() throws Exception } @Test - public void testEnrichSignatureWithT() throws Exception + void testEnrichSignatureWithT() throws Exception { Document doc = getDocument("document.signed.bes.xml"); Element signatureNode = (Element)doc.getElementsByTagNameNS(Constants.SignatureSpecNS, "Signature").item(0); @@ -77,7 +72,7 @@ public void testEnrichSignatureWithT() throws Exception } @Test - public void testEnrichSignatureWithA() throws Exception + void testEnrichSignatureWithA() throws Exception { Document doc = getDocument("document.verified.c.xl.xml"); Element signatureNode = (Element)doc.getElementsByTagNameNS(Constants.SignatureSpecNS, "Signature").item(0); diff --git a/src/test/java/xades4j/properties/DataObjectDescTest.java b/src/test/java/xades4j/properties/DataObjectDescTest.java index 98876b92..0bf44bf2 100644 --- a/src/test/java/xades4j/properties/DataObjectDescTest.java +++ b/src/test/java/xades4j/properties/DataObjectDescTest.java @@ -16,6 +16,7 @@ */ package xades4j.properties; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import xades4j.algorithms.Algorithm; @@ -31,10 +32,10 @@ /** * @author Luís */ -public class DataObjectDescTest +class DataObjectDescTest { @Test - public void testWithTransform() throws Exception + void testWithTransform() throws Exception { Document doc = SignatureServicesTestBase.getNewDocument(); DataObjectDesc instance = new DataObjectDescTestImpl() @@ -51,7 +52,7 @@ public void testWithTransform() throws Exception } @Test - public void testWithDataObjectFormatRepeatedInstance() + void testWithDataObjectFormatRepeatedInstance() { DataObjectFormatProperty format = new DataObjectFormatProperty(); DataObjectDesc instance = new DataObjectDescTestImpl(); @@ -66,7 +67,9 @@ public void testWithDataObjectFormatRepeatedInstance() /** * Test of withDataObjectFormat method, of class DataObjectDesc. */ - public void testWithDataObjectFormatMultipleTargets() + @Test + @Disabled("test is failing") + void testWithDataObjectFormatMultipleTargets() { DataObjectFormatProperty format = new DataObjectFormatProperty(); DataObjectDesc instance = new DataObjectDescTestImpl(); @@ -80,7 +83,7 @@ public void testWithDataObjectFormatMultipleTargets() * Test of withCommitmentType method, of class DataObjectDesc. */ @Test - public void testWithCommitmentType() + void testWithCommitmentType() { CommitmentTypeProperty commitment1 = CommitmentTypeProperty.proofOfApproval(); CommitmentTypeProperty commitment2 = CommitmentTypeProperty.proofOfCreation(); @@ -94,20 +97,20 @@ public void testWithCommitmentType() * Test of hasProperties method, of class DataObjectDesc. */ @Test - public void testHasProperties() + void testHasProperties() { DataObjectDesc instance = new DataObjectDescTestImpl(); - assertEquals(instance.hasProperties(), false); + assertEquals(false, instance.hasProperties()); instance.withDataObjectFormat(new DataObjectFormatProperty()); - assertEquals(instance.hasProperties(), true); + assertEquals(true, instance.hasProperties()); } /** * Test of getSignedDataObjProps method, of class DataObjectDesc. */ @Test - public void testGetSignedDataObjProps() + void testGetSignedDataObjProps() { DataObjectDesc instance = new DataObjectDescTestImpl(); assertEquals(instance.getSignedDataObjProps().size(), 0); diff --git a/src/test/java/xades4j/properties/DataObjectFormatPropertyTest.java b/src/test/java/xades4j/properties/DataObjectFormatPropertyTest.java index ad23c09a..66570a35 100644 --- a/src/test/java/xades4j/properties/DataObjectFormatPropertyTest.java +++ b/src/test/java/xades4j/properties/DataObjectFormatPropertyTest.java @@ -21,21 +21,18 @@ import java.util.ArrayList; import java.util.Collection; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @author Luís */ -public class DataObjectFormatPropertyTest +class DataObjectFormatPropertyTest { /** * Test of withIdentifier method, of class DataObjectFormatProperty. */ @Test - public void testWithIdentifier_String() + void testWithIdentifier_String() { String uri = "uri"; @@ -50,7 +47,8 @@ public void testWithIdentifier_String() /** * Test of withIdentifier method, of class DataObjectFormatProperty. */ - public void testWithIdentifier_String_IdentifierType() + @Test + void testWithIdentifier_String_IdentifierType() { String identifier = "uri"; IdentifierType type = IdentifierType.URI; @@ -66,7 +64,7 @@ public void testWithIdentifier_String_IdentifierType() * Test of withDocumentationUri method, of class DataObjectFormatProperty. */ @Test - public void testWithDocumentationUri() + void testWithDocumentationUri() { String documentationUri = "doc"; DataObjectFormatProperty instance = new DataObjectFormatProperty(); @@ -75,14 +73,14 @@ public void testWithDocumentationUri() assertTrue(instance.getDocumentationUris().isEmpty()); instance.withDocumentationUri(documentationUri); - assertEquals(instance.getDocumentationUris().size(), 1); + assertEquals(1, instance.getDocumentationUris().size()); } /** * Test of withDocumentationUris method, of class DataObjectFormatProperty. */ @Test - public void testWithDocumentationUris() + void testWithDocumentationUris() { Collection documentationUris = new ArrayList(1); DataObjectFormatProperty instance = new DataObjectFormatProperty(); @@ -100,7 +98,7 @@ public void testWithDocumentationUris() * Test of withDocumentationUris method, of class DataObjectFormatProperty. */ @Test - public void testWithDocumentationUris_Null() + void testWithDocumentationUris_Null() { DataObjectFormatProperty instance = new DataObjectFormatProperty(); assertThrows(NullPointerException.class, () -> { diff --git a/src/test/java/xades4j/providers/impl/DefaultTimeStampVerificationProviderTest.java b/src/test/java/xades4j/providers/impl/DefaultTimeStampVerificationProviderTest.java index a5810db0..e7cd1250 100644 --- a/src/test/java/xades4j/providers/impl/DefaultTimeStampVerificationProviderTest.java +++ b/src/test/java/xades4j/providers/impl/DefaultTimeStampVerificationProviderTest.java @@ -16,32 +16,32 @@ */ package xades4j.providers.impl; -import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; -import java.security.KeyStore; - import org.junit.jupiter.api.Test; import xades4j.providers.TimeStampTokenDigestException; import xades4j.providers.TimeStampTokenVerificationException; import xades4j.utils.StreamUtils; import xades4j.verification.VerifierTestBase; +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.security.KeyStore; + import static org.junit.jupiter.api.Assertions.assertThrows; /** * @author Luís */ -public class DefaultTimeStampVerificationProviderTest extends VerifierTestBase +class DefaultTimeStampVerificationProviderTest extends VerifierTestBase { @Test - public void testVerifyTokenSucceeds() throws Exception + void testVerifyTokenSucceeds() throws Exception { byte[] tsDigestInput = "TestDigestInput".getBytes(); doVerifyToken(tsDigestInput, getTestToken()); } @Test - public void testVerifyTokenFailsWithDifferentDigestInput() throws Exception + void testVerifyTokenFailsWithDifferentDigestInput() throws Exception { byte[] tsDigestInput = "Invalid".getBytes(); assertThrows(TimeStampTokenDigestException.class, () -> { @@ -50,7 +50,7 @@ public void testVerifyTokenFailsWithDifferentDigestInput() throws Exception } @Test - public void testVerifyTokenFailsWithTamperedToken() throws Exception + void testVerifyTokenFailsWithTamperedToken() throws Exception { byte[] tsDigestInput = "TestDigestInput".getBytes(); byte[] tsToken = getTestToken(); diff --git a/src/test/java/xades4j/providers/impl/FileSystemKeyStoreKeyingDataProviderTest.java b/src/test/java/xades4j/providers/impl/FileSystemKeyStoreKeyingDataProviderTest.java index 241a1116..da5e3a47 100644 --- a/src/test/java/xades4j/providers/impl/FileSystemKeyStoreKeyingDataProviderTest.java +++ b/src/test/java/xades4j/providers/impl/FileSystemKeyStoreKeyingDataProviderTest.java @@ -92,14 +92,14 @@ public static Collection data() throws Exception @ParameterizedTest @MethodSource("data") - public void testGetSigningKey(FileSystemKeyStoreKeyingDataProvider keyingProvider, X509Certificate signCert) throws Exception + void testGetSigningKey(FileSystemKeyStoreKeyingDataProvider keyingProvider, X509Certificate signCert) throws Exception { keyingProvider.getSigningKey(signCert); } @ParameterizedTest @MethodSource("data") - public void testGetSigningCertificateChain(FileSystemKeyStoreKeyingDataProvider keyingProvider, X509Certificate signCert) throws Exception + void testGetSigningCertificateChain(FileSystemKeyStoreKeyingDataProvider keyingProvider, X509Certificate signCert) throws Exception { List certChain = keyingProvider.getSigningCertificateChain(); assertEquals(certChain.size(), 3); diff --git a/src/test/java/xades4j/providers/impl/HttpTimeStampTokenProviderTest.java b/src/test/java/xades4j/providers/impl/HttpTimeStampTokenProviderTest.java index e1af5d5e..38e8c826 100644 --- a/src/test/java/xades4j/providers/impl/HttpTimeStampTokenProviderTest.java +++ b/src/test/java/xades4j/providers/impl/HttpTimeStampTokenProviderTest.java @@ -22,10 +22,10 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; -public class HttpTimeStampTokenProviderTest +class HttpTimeStampTokenProviderTest { @Test - public void testGetTimeStampToken() throws Exception + void testGetTimeStampToken() throws Exception { byte[] tsDigestInput = "TestDigestInput".getBytes(); String digestAlgUri = MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA1; diff --git a/src/test/java/xades4j/providers/impl/PKCS11KeyStoreKeyingDataProviderTest.java b/src/test/java/xades4j/providers/impl/PKCS11KeyStoreKeyingDataProviderTest.java index 6d36ee0b..edd6f9ac 100644 --- a/src/test/java/xades4j/providers/impl/PKCS11KeyStoreKeyingDataProviderTest.java +++ b/src/test/java/xades4j/providers/impl/PKCS11KeyStoreKeyingDataProviderTest.java @@ -32,17 +32,15 @@ import java.util.List; import java.util.UUID; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @author Luís */ -public class PKCS11KeyStoreKeyingDataProviderTest extends SignerTestBase +class PKCS11KeyStoreKeyingDataProviderTest extends SignerTestBase { @Test - public void testCertAndKeyMatch() throws Exception + void testCertAndKeyMatch() throws Exception { assumePtCcPkcs11(); diff --git a/src/test/java/xades4j/providers/impl/PKIXCertificateValidationProviderTest.java b/src/test/java/xades4j/providers/impl/PKIXCertificateValidationProviderTest.java index c8b97443..582336eb 100644 --- a/src/test/java/xades4j/providers/impl/PKIXCertificateValidationProviderTest.java +++ b/src/test/java/xades4j/providers/impl/PKIXCertificateValidationProviderTest.java @@ -34,10 +34,10 @@ /** * @author Luís */ -public class PKIXCertificateValidationProviderTest +class PKIXCertificateValidationProviderTest { @Test - public void testValidateMy() throws Exception + void testValidateMy() throws Exception { FileSystemDirectoryCertStore certStore = new FileSystemDirectoryCertStore("./src/test/cert/my"); KeyStore ks = KeyStore.getInstance("jks"); @@ -59,7 +59,7 @@ public void testValidateMy() throws Exception } @Test - public void testValidateNist() throws Exception + void testValidateNist() throws Exception { FileSystemDirectoryCertStore certStore = new FileSystemDirectoryCertStore("./src/test/cert/csrc.nist"); KeyStore ks = KeyStore.getInstance("jks"); diff --git a/src/test/java/xades4j/utils/DOMHelperTest.java b/src/test/java/xades4j/utils/DOMHelperTest.java index 4fe0eb2c..c8b3d55e 100644 --- a/src/test/java/xades4j/utils/DOMHelperTest.java +++ b/src/test/java/xades4j/utils/DOMHelperTest.java @@ -16,15 +16,16 @@ */ package xades4j.utils; -import java.io.StringReader; -import java.util.Collection; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.InputSource; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import java.io.StringReader; +import java.util.Collection; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -32,10 +33,10 @@ * * @author luis */ -public class DOMHelperTest +class DOMHelperTest { @Test - public void testGetChildElementsByTagNameNS() throws Exception + void testGetChildElementsByTagNameNS() throws Exception { String xml = ""; diff --git a/src/test/java/xades4j/utils/FileSystemDirectoryCertStoreTest.java b/src/test/java/xades4j/utils/FileSystemDirectoryCertStoreTest.java index 3325b34e..4fa0ab20 100644 --- a/src/test/java/xades4j/utils/FileSystemDirectoryCertStoreTest.java +++ b/src/test/java/xades4j/utils/FileSystemDirectoryCertStoreTest.java @@ -18,6 +18,8 @@ import org.junit.jupiter.api.Test; +import java.security.cert.CRL; +import java.security.cert.Certificate; import java.util.Collection; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -25,23 +27,23 @@ /** * @author Luís */ -public class FileSystemDirectoryCertStoreTest +class FileSystemDirectoryCertStoreTest { @Test - public void testGetStoreMy() throws Exception + void testGetStoreMy() throws Exception { FileSystemDirectoryCertStore certStore = new FileSystemDirectoryCertStore("./src/test/cert/my"); - Collection certs = certStore.getStore().getCertificates(null); - assertEquals(certs.size(), 4); + Collection certs = certStore.getStore().getCertificates(null); + assertEquals(4, certs.size()); } @Test - public void testGetStoreNist() throws Exception + void testGetStoreNist() throws Exception { FileSystemDirectoryCertStore certStore = new FileSystemDirectoryCertStore("./src/test/cert/csrc.nist"); - Collection certs = certStore.getStore().getCertificates(null); - assertEquals(certs.size(), 4); - Collection crls = certStore.getStore().getCRLs(null); - assertEquals(crls.size(), 3); + Collection certs = certStore.getStore().getCertificates(null); + assertEquals(4, certs.size()); + Collection crls = certStore.getStore().getCRLs(null); + assertEquals(3, crls.size()); } } \ No newline at end of file diff --git a/src/test/java/xades4j/utils/PropertiesBagTest.java b/src/test/java/xades4j/utils/PropertiesBagTest.java index 281e6ad3..57cb8b60 100644 --- a/src/test/java/xades4j/utils/PropertiesBagTest.java +++ b/src/test/java/xades4j/utils/PropertiesBagTest.java @@ -20,14 +20,12 @@ import xades4j.properties.DataObjectFormatProperty; import xades4j.properties.SigningTimeProperty; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @author Luís */ -public class PropertiesBagTest +class PropertiesBagTest { // @Test // public void jaxbTest() throws Exception @@ -59,7 +57,7 @@ public class PropertiesBagTest * Test of put method, of class PropertiesSet. */ @Test - public void testPut() + void testPut() { SigningTimeProperty prop1 = new SigningTimeProperty(), prop2 = new SigningTimeProperty(); DataObjectFormatProperty prop3 = new DataObjectFormatProperty(); @@ -77,7 +75,7 @@ public void testPut() * Test of add method, of class PropertiesSet, with {@code null} value. */ @Test - public void testAddNull() + void testAddNull() { PropertiesSet instance = new PropertiesSet(0); assertThrows(NullPointerException.class, () -> { @@ -89,7 +87,7 @@ public void testAddNull() * Test of add method, of class PropertiesSet. */ @Test - public void testAdd() + void testAdd() { SigningTimeProperty prop1 = new SigningTimeProperty(), prop2 = new SigningTimeProperty(); PropertiesSet instance = new PropertiesSet(1); @@ -118,7 +116,7 @@ public void testRemove() * Test of remove method, of class PropertiesSet. */ @Test - public void testRemoveNotPresent() + void testRemoveNotPresent() { SigningTimeProperty prop1 = new SigningTimeProperty(), prop2 = new SigningTimeProperty(); PropertiesSet instance = new PropertiesSet(1); @@ -133,7 +131,7 @@ public void testRemoveNotPresent() * Test of isEmpty method, of class PropertiesSet. */ @Test - public void testIsEmpty() + void testIsEmpty() { System.out.println("isEmpty"); diff --git a/src/test/java/xades4j/utils/X500NameStyleProviderTest.java b/src/test/java/xades4j/utils/X500NameStyleProviderTest.java index 4beac3a3..da01a85d 100644 --- a/src/test/java/xades4j/utils/X500NameStyleProviderTest.java +++ b/src/test/java/xades4j/utils/X500NameStyleProviderTest.java @@ -15,14 +15,14 @@ * @see Issues-157 */ -public class X500NameStyleProviderTest +class X500NameStyleProviderTest { private static final String NAME_SIMPLE = "C=CO,L=Bogota D.C.,O=Andes SCD.,OU=Division de certificacion entidad final,CN=CA ANDES SCD S.A. Clase II, E=info@andesscd.com.co"; private static final String NAME_SIMPLE_NORMAL = "C=CO,L=Bogota D.C.,O=Andes SCD.,OU=Division de certificacion entidad final,CN=CA ANDES SCD S.A. Clase II, EMAILADDRESS=info@andesscd.com.co"; private static final String NAME_CANONICAL = "C=CO,L=Bogota D.C.,O=Andes SCD.,OU=Division de certificacion entidad final,CN=CA ANDES SCD S.A. Clase II, 1.2.840.113549.1.9.1=#1614696e666f40616e6465737363642e636f6d2e636f"; @Test - public void errorDefaultParsing() + void errorDefaultParsing() { assertThrows(Exception.class, () -> { new X500Principal(NAME_SIMPLE); @@ -30,7 +30,7 @@ public void errorDefaultParsing() } @Test - public void errorParsingWithProvider() + void errorParsingWithProvider() { assertThrows(Exception.class, () -> { new DefaultX500NameStyleProvider().fromString(NAME_SIMPLE); @@ -38,14 +38,14 @@ public void errorParsingWithProvider() } @Test - public void normal() + void normal() { new X500Principal(NAME_CANONICAL); new X500Principal(NAME_SIMPLE_NORMAL); } @Test - public void normalWithExtendKeywords() + void normalWithExtendKeywords() { X500NameStyleProvider x500NameStyleProvider = new DefaultX500NameStyleProvider(); X500Principal name1 = x500NameStyleProvider.fromString(NAME_CANONICAL); diff --git a/src/test/java/xades4j/utils/XadesProfileCoreTest.java b/src/test/java/xades4j/utils/XadesProfileCoreTest.java index 2382be43..d44b216a 100644 --- a/src/test/java/xades4j/utils/XadesProfileCoreTest.java +++ b/src/test/java/xades4j/utils/XadesProfileCoreTest.java @@ -18,16 +18,13 @@ import com.google.inject.AbstractModule; import com.google.inject.Module; +import jakarta.inject.Inject; import org.junit.jupiter.api.Test; -import jakarta.inject.Inject; import java.util.Map; import java.util.Set; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /* Test classes/interfaces */ interface A @@ -102,10 +99,10 @@ public E(Map as) /** * @author Luís */ -public class XadesProfileCoreTest +class XadesProfileCoreTest { @Test - public void testGetInstance() throws XadesProfileResolutionException + void testGetInstance() throws XadesProfileResolutionException { Module module = new AbstractModule() { @@ -122,7 +119,7 @@ protected void configure() } @Test - public void testGetInstanceException() throws XadesProfileResolutionException + void testGetInstanceException() throws XadesProfileResolutionException { XadesProfileCore instance = new XadesProfileCore(); assertThrows(XadesProfileResolutionException.class, () -> { @@ -131,7 +128,7 @@ public void testGetInstanceException() throws XadesProfileResolutionException } @Test - public void testAddBinding() throws XadesProfileResolutionException + void testAddBinding() throws XadesProfileResolutionException { Module module = new AbstractModule() { @@ -155,7 +152,7 @@ protected void configure() } @Test - public void testAddGenericBinding() throws XadesProfileResolutionException + void testAddGenericBinding() throws XadesProfileResolutionException { XadesProfileCore instance = new XadesProfileCore(); instance.addGenericBinding(Action.class, ActionOfA.class, A.class); @@ -164,7 +161,7 @@ public void testAddGenericBinding() throws XadesProfileResolutionException } @Test - public void testAddMultibinding() throws Exception + void testAddMultibinding() throws Exception { XadesProfileCore instance = new XadesProfileCore(); instance.addMultibinding(A.class, AImpl1.class); @@ -176,7 +173,7 @@ public void testAddMultibinding() throws Exception } @Test - public void testAddMapBinding() throws Exception + void testAddMapBinding() throws Exception { XadesProfileCore instance = new XadesProfileCore(); instance.addMapBinding(A.class, "A1", AImpl1.class); diff --git a/src/test/java/xades4j/verification/DistinguishedNameComparerTest.java b/src/test/java/xades4j/verification/DistinguishedNameComparerTest.java index a8f9ed67..cf778410 100644 --- a/src/test/java/xades4j/verification/DistinguishedNameComparerTest.java +++ b/src/test/java/xades4j/verification/DistinguishedNameComparerTest.java @@ -80,7 +80,7 @@ public DistinguishedNameComparerTest() throws IOException @ParameterizedTest @MethodSource("data") - public void canCompare(String issuerDn, X509Certificate cert) + void canCompare(String issuerDn, X509Certificate cert) { X500Principal principal = cert.getIssuerX500Principal(); DistinguishedNameComparer comparer = new DistinguishedNameComparer(this.nameStyle, this.x500NameStyleProvider); diff --git a/src/test/java/xades4j/verification/GenericDOMDataVerifierTest.java b/src/test/java/xades4j/verification/GenericDOMDataVerifierTest.java index 0a0a1b0e..25d71217 100644 --- a/src/test/java/xades4j/verification/GenericDOMDataVerifierTest.java +++ b/src/test/java/xades4j/verification/GenericDOMDataVerifierTest.java @@ -41,7 +41,7 @@ public class GenericDOMDataVerifierTest @BeforeAll public static void setUpClass() throws Exception { - customElemVerifiers = new HashMap(1); + customElemVerifiers = new HashMap<>(1); customElemVerifiers.put(new QName("http://test.generic.dom", "Elem"), new TestElemDOMVerifier()); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); @@ -50,18 +50,18 @@ public static void setUpClass() throws Exception } @Test - public void testVerify() throws Exception + void testVerify() throws Exception { GenericDOMData propData = new GenericDOMData(testDocument.createElementNS("http://test.generic.dom", "Elem")); QualifyingPropertyVerificationContext ctx = null; GenericDOMDataVerifier instance = new GenericDOMDataVerifier(customElemVerifiers); QualifyingProperty result = instance.verify(propData, ctx); - assertEquals(result.getName(), "Elem"); + assertEquals("Elem", result.getName()); } @Test - public void testVerifyNoVerifier() throws Exception + void testVerifyNoVerifier() throws Exception { GenericDOMData propData = new GenericDOMData(testDocument.createElementNS("http://test.generic.dom", "Elem")); QualifyingPropertyVerificationContext ctx = null; diff --git a/src/test/java/xades4j/verification/Issue166Test.java b/src/test/java/xades4j/verification/Issue166Test.java index 8da7eabf..9a6e2bc6 100644 --- a/src/test/java/xades4j/verification/Issue166Test.java +++ b/src/test/java/xades4j/verification/Issue166Test.java @@ -11,14 +11,13 @@ import java.security.cert.X509Certificate; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotEquals; /** * Investigation for issue 166. * @author luis */ -public class Issue166Test extends SignatureServicesTestBase +class Issue166Test extends SignatureServicesTestBase { private final String dnUtf8 = "2.5.4.97=#0c0f56415445532d413636373231343939,CN=UANATACA CA1 2016,OU=TSP-UANATACA,O=UANATACA S.A.,L=Barcelona (see current address at www.uanataca.com/address),C=ES"; private final String dnPrintable = "2.5.4.97=#130f56415445532d413636373231343939,CN=UANATACA CA1 2016,OU=TSP-UANATACA,O=UANATACA S.A.,L=Barcelona (see current address at www.uanataca.com/address),C=ES"; @@ -38,18 +37,18 @@ public void setUp() throws Exception } @Test - public void javaCannotCompareStrings() throws Exception + void javaCannotCompareStrings() throws Exception { X500Principal principal1 = new X500Principal(dnUtf8); X500Principal principal2 = new X500Principal(dnPrintable); X500Principal principal3 = new X500Principal(dnPlain); - assertFalse(principal1.equals(principal2)); - assertFalse(principal1.equals(principal3)); + assertNotEquals(principal1, principal2); + assertNotEquals(principal1, principal3); } @Test - public void javaCanComparePrintableAndPlainStrings() throws Exception + void javaCanComparePrintableAndPlainStrings() throws Exception { X500Principal principal1 = new X500Principal(dnPrintable); X500Principal principal2 = new X500Principal(dnPlain); @@ -58,68 +57,68 @@ public void javaCanComparePrintableAndPlainStrings() throws Exception } @Test - public void javaCannotCompareCertAndPrintableString() throws Exception + void javaCannotCompareCertAndPrintableString() throws Exception { X500Principal principal1 = cert.getIssuerX500Principal(); X500Principal principal2 = new X500Principal(dnPrintable); - assertFalse(principal1.equals(principal2)); + assertNotEquals(principal1, principal2); } @Test - public void javaCanCompareCertAndUtf8String() throws Exception + void javaCanCompareCertAndUtf8String() throws Exception { X500Principal principal1 = cert.getIssuerX500Principal(); X500Principal principal2 = new X500Principal(dnUtf8); - assertTrue(principal1.equals(principal2)); + assertEquals(principal1, principal2); } @Test - public void javaCannotCompareCertAndPlainString() throws Exception + void javaCannotCompareCertAndPlainString() throws Exception { X500Principal principal1 = cert.getIssuerX500Principal(); X500Principal principal2 = new X500Principal(dnPlain); - assertFalse(principal1.equals(principal2)); + assertNotEquals(principal1, principal2); } @Test - public void bcCanCompareStrings() throws Exception + void bcCanCompareStrings() throws Exception { X500Name principal1 = new X500Name(dnUtf8); X500Name principal2 = new X500Name(dnPrintable); X500Name principal3 = new X500Name(dnPlain); - assertTrue(principal1.equals(principal2)); - assertTrue(principal1.equals(principal3)); - assertTrue(principal2.equals(principal3)); + assertEquals(principal1, principal2); + assertEquals(principal1, principal3); + assertEquals(principal2, principal3); } @Test - public void bcCanCompareCertAndPrintableString() throws Exception + void bcCanCompareCertAndPrintableString() throws Exception { X500Name principal1 = X500Name.getInstance(cert.getIssuerX500Principal().getEncoded()); X500Name principal2 = new X500Name(dnPrintable); - assertTrue(principal1.equals(principal2)); + assertEquals(principal1, principal2); } @Test - public void bcCanCompareCertAndUtf8String() throws Exception + void bcCanCompareCertAndUtf8String() throws Exception { X500Name principal1 = X500Name.getInstance(cert.getIssuerX500Principal().getEncoded()); X500Name principal2 = new X500Name(dnUtf8); - assertTrue(principal1.equals(principal2)); + assertEquals(principal1, principal2); } @Test - public void bcCanCompareCertAndPlainString() throws Exception + void bcCanCompareCertAndPlainString() throws Exception { X500Name principal1 = X500Name.getInstance(cert.getIssuerX500Principal().getEncoded()); X500Name principal2 = new X500Name(dnPlain); - assertTrue(principal1.equals(principal2)); + assertEquals(principal1, principal2); } } diff --git a/src/test/java/xades4j/verification/OtherVerifierTests.java b/src/test/java/xades4j/verification/OtherVerifierTests.java index 900a868a..f42bac2b 100644 --- a/src/test/java/xades4j/verification/OtherVerifierTests.java +++ b/src/test/java/xades4j/verification/OtherVerifierTests.java @@ -16,14 +16,13 @@ */ package xades4j.verification; +import jakarta.inject.Inject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import xades4j.properties.QualifyingProperty; import xades4j.properties.data.SigningTimeData; import xades4j.utils.BuiltIn; -import jakarta.inject.Inject; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -49,7 +48,7 @@ public QualifyingProperty verify(SigningTimeData propData, QualifyingPropertyVer /** * @author Luís */ -public class OtherVerifierTests extends VerifierTestBase +class OtherVerifierTests extends VerifierTestBase { XadesVerificationProfile mySigsVerificationProfile; @@ -60,7 +59,7 @@ public void initialize() } @Test - public void testVerifyBESCustomPropVer() throws Exception + void testVerifyBESCustomPropVer() throws Exception { mySigsVerificationProfile.withQualifyingPropertyVerifier(SigningTimeData.class, new QualifyingPropertyVerifier() { @@ -82,7 +81,7 @@ public QualifyingProperty verify( } @Test - public void testCustomVerifierCanUseBuiltInVerifier() throws Exception + void testCustomVerifierCanUseBuiltInVerifier() throws Exception { mySigsVerificationProfile.withQualifyingPropertyVerifier( SigningTimeData.class, @@ -94,7 +93,7 @@ public void testCustomVerifierCanUseBuiltInVerifier() throws Exception } @Test - public void testVerifyWithManifest() throws Exception + void testVerifyWithManifest() throws Exception { SignatureSpecificVerificationOptions options = new SignatureSpecificVerificationOptions() .followManifests(true); diff --git a/src/test/java/xades4j/verification/XAdESFormCheckerTest.java b/src/test/java/xades4j/verification/XAdESFormCheckerTest.java index 53a512a6..0e54c597 100644 --- a/src/test/java/xades4j/verification/XAdESFormCheckerTest.java +++ b/src/test/java/xades4j/verification/XAdESFormCheckerTest.java @@ -25,10 +25,10 @@ /** * @author luis */ -public class XAdESFormCheckerTest +class XAdESFormCheckerTest { @Test - public void checkFormThrowsIfMinimumPropertiesAreNotPresent() throws InvalidXAdESFormException + void checkFormThrowsIfMinimumPropertiesAreNotPresent() throws InvalidXAdESFormException { assertThrows(InvalidXAdESFormException.class, () -> { XAdESFormChecker.checkForm(new ArrayList(0)); diff --git a/src/test/java/xades4j/verification/XadesVerificationProfileTest.java b/src/test/java/xades4j/verification/XadesVerificationProfileTest.java index d3ddd36e..db8e3201 100644 --- a/src/test/java/xades4j/verification/XadesVerificationProfileTest.java +++ b/src/test/java/xades4j/verification/XadesVerificationProfileTest.java @@ -24,10 +24,10 @@ /** * @author Luís */ -public class XadesVerificationProfileTest +class XadesVerificationProfileTest { @Test - public void testGetVerifier() throws XadesProfileResolutionException + void testGetVerifier() throws XadesProfileResolutionException { XadesVerificationProfile instance = new XadesVerificationProfile(VerifierTestBase.validationProviderMySigs); XadesVerifier result = instance.newVerifier(); diff --git a/src/test/java/xades4j/verification/XadesVerifierErrorsTest.java b/src/test/java/xades4j/verification/XadesVerifierErrorsTest.java index 92e0822d..0d404956 100644 --- a/src/test/java/xades4j/verification/XadesVerifierErrorsTest.java +++ b/src/test/java/xades4j/verification/XadesVerifierErrorsTest.java @@ -28,7 +28,7 @@ /** * @author Luís */ -public class XadesVerifierErrorsTest extends VerifierTestBase +class XadesVerifierErrorsTest extends VerifierTestBase { XadesVerificationProfile mySigsVerificationProfile; XadesVerificationProfile nistVerificationProfile; @@ -41,7 +41,7 @@ public void initialize() } @Test - public void testErrVerifySignedPropsIncorp() throws Exception + void testErrVerifySignedPropsIncorp() throws Exception { assertThrows(QualifyingPropertiesIncorporationException.class, () -> { verifyBadSignature("document.signed.t.bes.badsignedprops.xml", mySigsVerificationProfile); @@ -49,7 +49,7 @@ public void testErrVerifySignedPropsIncorp() throws Exception } @Test - public void testErrVerifySignedPropsIncorpNoRefType() throws Exception + void testErrVerifySignedPropsIncorpNoRefType() throws Exception { assertThrows(QualifyingPropertiesIncorporationException.class, () -> { verifyBadSignature("document.signed.bes.signedpropsrefnotype.xml", @@ -58,7 +58,7 @@ public void testErrVerifySignedPropsIncorpNoRefType() throws Exception } @Test - public void testErrVerifyIncorrectC() throws Exception + void testErrVerifyIncorrectC() throws Exception { assertThrows(InvalidXAdESFormException.class, () -> { verifyBadSignature("document.signed.c.bad.xml", nistVerificationProfile); @@ -66,7 +66,7 @@ public void testErrVerifyIncorrectC() throws Exception } @Test - public void testErrVerifyNoSignCert() throws Exception + void testErrVerifyNoSignCert() throws Exception { KeyStore ks = createAndLoadJKSKeyStore("be/beStore", "bestorepass"); PKIXCertificateValidationProvider cvp = PKIXCertificateValidationProvider.builder(ks).checkRevocation(false).build(); @@ -76,7 +76,7 @@ public void testErrVerifyNoSignCert() throws Exception } @Test - public void testErrVerifyChangedDataObj() throws Exception + void testErrVerifyChangedDataObj() throws Exception { assertThrows(ReferenceValueException.class, () -> { verifyBadSignature("document.signed.bes.invaliddataobj.xml", mySigsVerificationProfile); @@ -84,7 +84,7 @@ public void testErrVerifyChangedDataObj() throws Exception } @Test - public void testErrVerifyChangedSigValue() throws Exception + void testErrVerifyChangedSigValue() throws Exception { assertThrows(SignatureValueException.class, () -> { verifyBadSignature("document.signed.bes.invalidsigvalue.xml", mySigsVerificationProfile); @@ -92,7 +92,7 @@ public void testErrVerifyChangedSigValue() throws Exception } @Test - public void testErrVerifyCMissingCertRef() throws Exception + void testErrVerifyCMissingCertRef() throws Exception { assertThrows(CompleteCertRefsCertNotFoundException.class, () -> { verifyBadSignature("document.signed.c.missingcertref.xml", nistVerificationProfile); @@ -100,7 +100,7 @@ public void testErrVerifyCMissingCertRef() throws Exception } @Test - public void testErrVerifyUnmatchSigTSDigest() throws Exception + void testErrVerifyUnmatchSigTSDigest() throws Exception { // DefaultTimeStampTokenProvider tsProv = new DefaultTimeStampTokenProvider(new DefaultMessageDigestProvider()); // byte[] tkn = tsProv.getTimeStampToken("badTimeStamp".getBytes(), Constants.ALGO_ID_DIGEST_SHA1).encodedTimeStampToken; @@ -116,7 +116,7 @@ public void testErrVerifyUnmatchSigTSDigest() throws Exception } @Test - public void testErrVerifyCounterSigWithUnallowedTransforms() throws Exception + void testErrVerifyCounterSigWithUnallowedTransforms() throws Exception { assertThrows(CounterSignatureSigValueRefException.class, () -> { verifyBadSignature("document.signed.bes.cs.invalidtransforms.xml", mySigsVerificationProfile); diff --git a/src/test/java/xades4j/verification/XadesVerifierImplTest.java b/src/test/java/xades4j/verification/XadesVerifierImplTest.java index 14417b7b..3b0b4e51 100644 --- a/src/test/java/xades4j/verification/XadesVerifierImplTest.java +++ b/src/test/java/xades4j/verification/XadesVerifierImplTest.java @@ -27,19 +27,7 @@ import xades4j.algorithms.CanonicalXMLWithoutComments; import xades4j.production.XadesFormatExtenderProfile; import xades4j.production.XadesSignatureFormatExtender; -import xades4j.properties.CertificateValuesProperty; -import xades4j.properties.CommitmentTypeProperty; -import xades4j.properties.CommitmentTypePropertyBase; -import xades4j.properties.CompleteCertificateRefsProperty; -import xades4j.properties.CounterSignatureProperty; -import xades4j.properties.DataObjectFormatProperty; -import xades4j.properties.IndividualDataObjsTimeStampProperty; -import xades4j.properties.QualifyingProperty; -import xades4j.properties.RevocationValuesProperty; -import xades4j.properties.SigAndRefsTimeStampProperty; -import xades4j.properties.SignatureTimeStampProperty; -import xades4j.properties.SigningCertificateProperty; -import xades4j.properties.SigningTimeProperty; +import xades4j.properties.*; import xades4j.providers.CannotBuildCertificationPathException; import java.io.File; @@ -49,15 +37,12 @@ import java.util.Date; import java.util.GregorianCalendar; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @author Luís */ -public class XadesVerifierImplTest extends VerifierTestBase +class XadesVerifierImplTest extends VerifierTestBase { XadesVerificationProfile verificationProfile; XadesVerificationProfile nistVerificationProfile; @@ -70,7 +55,7 @@ public void initialize() } @Test - public void testVerifyBES() throws Exception + void testVerifyBES() throws Exception { var result = verifySignature("document.signed.bes.xml"); assertEquals(XAdESForm.BES, result.getSignatureForm()); @@ -113,7 +98,7 @@ public void testVerifyBES() throws Exception } @Test - public void testVerifyBESWithoutKeyInfo() throws Exception + void testVerifyBESWithoutKeyInfo() throws Exception { var result = verifySignature("document.signed.bes.no-ki.xml"); assertEquals(XAdESForm.BES, result.getSignatureForm()); @@ -124,7 +109,7 @@ public void testVerifyBESWithoutKeyInfo() throws Exception * can't build the certificate path because certificates are expired. */ @Test - public void testVerifyBESWithVerificationDate() throws Exception + void testVerifyBESWithVerificationDate() throws Exception { String sigFilename = "document.signed.bes.xml"; Element signatureNode = getSigElement(getDocument(sigFilename)); @@ -139,7 +124,7 @@ public void testVerifyBESWithVerificationDate() throws Exception } @Test - public void testVerifyWithCustomRawVerifier() throws Exception + void testVerifyWithCustomRawVerifier() throws Exception { verificationProfile.withRawSignatureVerifier(new RawSignatureVerifier() { @@ -158,7 +143,7 @@ public void verify(RawSignatureVerifierContext ctx) throws InvalidSignatureExcep } @Test - public void testVerifyBESPTCC() throws Exception + void testVerifyBESPTCC() throws Exception { var result = verifySignature( "document.signed.bes.ptcc.xml", @@ -169,7 +154,7 @@ public void testVerifyBESPTCC() throws Exception } @Test - public void testVerifyDetachedBES() throws Exception + void testVerifyDetachedBES() throws Exception { var result = verifySignature( "detached.bes.xml", @@ -187,7 +172,7 @@ public void testVerifyDetachedBES() throws Exception } @Test - public void testVerifyBESCounterSig() throws Exception + void testVerifyBESCounterSig() throws Exception { var result = verifySignature("document.signed.bes.cs.xml"); @@ -201,14 +186,14 @@ public void testVerifyBESCounterSig() throws Exception } @Test - public void testVerifyBESCounterSigCounterSig() throws Exception + void testVerifyBESCounterSigCounterSig() throws Exception { var result = verifySignature("document.signed.bes.cs.cs.xml"); assertEquals(XAdESForm.BES, result.getSignatureForm()); } @Test - public void testVerifyBESEnrichT() throws Exception + void testVerifyBESEnrichT() throws Exception { Document doc = getDocument("document.signed.bes.xml"); Element signatureNode = getSigElement(doc); @@ -224,7 +209,7 @@ public void testVerifyBESEnrichT() throws Exception } @Test - public void testVerifyBESExtrnlResEnrichC() throws Exception + void testVerifyBESExtrnlResEnrichC() throws Exception { Document doc = getDocument("document.signed.bes.extres.xml"); Element signatureNode = getSigElement(doc); @@ -244,7 +229,7 @@ public void testVerifyBESExtrnlResEnrichC() throws Exception } @Test - public void testVerifyTBES() throws Exception + void testVerifyTBES() throws Exception { var result = verifySignature("document.signed.t.bes.xml"); @@ -255,7 +240,7 @@ public void testVerifyTBES() throws Exception } @Test - public void testVerifyEPES1() throws Exception + void testVerifyEPES1() throws Exception { verificationProfile.withPolicyDocumentProvider(VerifierTestBase.policyDocumentFinder); var result = verifySignature("document.signed.epes_1.xml", verificationProfile); @@ -264,7 +249,7 @@ public void testVerifyEPES1() throws Exception } @Test - public void testVerifyEPES2() throws Exception + void testVerifyEPES2() throws Exception { verificationProfile.withPolicyDocumentProvider(VerifierTestBase.policyDocumentFinder); var result = verifySignature("document.signed.epes_2.xml", verificationProfile); @@ -272,7 +257,7 @@ public void testVerifyEPES2() throws Exception } @Test - public void testVerifyTEPES() throws Exception + void testVerifyTEPES() throws Exception { var result = verifySignature("document.signed.t.epes.xml"); @@ -283,7 +268,7 @@ public void testVerifyTEPES() throws Exception } @Test - public void testVerifyC() throws Exception + void testVerifyC() throws Exception { var result = verifySignature( "document.signed.c.xml", @@ -304,7 +289,7 @@ public void testVerifyC() throws Exception } @Test - public void testVerifyDetachedC() throws Exception + void testVerifyDetachedC() throws Exception { Document doc = getDocument("detached.c.xml"); Element signatureNode = getSigElement(doc); @@ -321,7 +306,7 @@ public void testVerifyDetachedC() throws Exception } @Test - public void testVerifyCEnrichXL() throws Exception + void testVerifyCEnrichXL() throws Exception { Document doc = getDocument("document.signed.c.xml"); Element signatureNode = getSigElement(doc); @@ -342,6 +327,6 @@ private static void assertPropElementPresent( String elemName) { NodeList props = sigElem.getElementsByTagNameNS(QualifyingProperty.XADES_XMLNS, elemName); - assertFalse(props.getLength() == 0); + assertNotEquals(0, props.getLength()); } } diff --git a/src/test/java/xades4j/xml/marshalling/algorithms/XPath2FilterTransformParamsMarshallerTest.java b/src/test/java/xades4j/xml/marshalling/algorithms/XPath2FilterTransformParamsMarshallerTest.java index ac44a976..7b2ab125 100644 --- a/src/test/java/xades4j/xml/marshalling/algorithms/XPath2FilterTransformParamsMarshallerTest.java +++ b/src/test/java/xades4j/xml/marshalling/algorithms/XPath2FilterTransformParamsMarshallerTest.java @@ -14,15 +14,13 @@ import java.util.Map; import java.util.Set; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.*; /** * * @author Luís */ -public class XPath2FilterTransformParamsMarshallerTest { +class XPath2FilterTransformParamsMarshallerTest { private Document doc; private XPath2FilterTransformParamsMarshaller sut; @@ -34,7 +32,7 @@ public void setUp() throws Exception { } @Test - public void testMarshalXPathParametersWithNamespacePrefixes() throws Exception { + void testMarshalXPathParametersWithNamespacePrefixes() throws Exception { XPath2FilterTransform xpath = XPath2Filter .intersect("foo:elem1") .union("bar:elem2") diff --git a/src/test/java/xades4j/xml/marshalling/algorithms/XPathTransformParamsMarshallerTest.java b/src/test/java/xades4j/xml/marshalling/algorithms/XPathTransformParamsMarshallerTest.java index a93e64ac..e6255769 100644 --- a/src/test/java/xades4j/xml/marshalling/algorithms/XPathTransformParamsMarshallerTest.java +++ b/src/test/java/xades4j/xml/marshalling/algorithms/XPathTransformParamsMarshallerTest.java @@ -12,14 +12,12 @@ import java.util.List; import java.util.Map; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.*; /** * @author Luís */ -public class XPathTransformParamsMarshallerTest +class XPathTransformParamsMarshallerTest { private Document doc; private XPathTransformParamsMarshaller sut; @@ -32,7 +30,7 @@ public void setUp() throws Exception } @Test - public void testMarshalXPathParametersWithNamespacePrefixes() throws Exception + void testMarshalXPathParametersWithNamespacePrefixes() throws Exception { XPathTransform xpath = new XPathTransform("foo:elem1/bar:elem2") .withNamespace("foo", "http://test.xades4j/ns1") From e6b55dd526936056ec39e8b7dbbd6bafa652e27a Mon Sep 17 00:00:00 2001 From: Mirko Date: Mon, 13 Nov 2023 21:26:40 +0100 Subject: [PATCH 06/14] remove Base64 class and use java.util instead --- .../impl/HttpTimeStampTokenProvider.java | 4 +- src/main/java/xades4j/utils/Base64.java | 1991 ----------------- .../xades4j/xml/bind/Base64XmlAdapter.java | 13 +- 3 files changed, 10 insertions(+), 1998 deletions(-) delete mode 100644 src/main/java/xades4j/utils/Base64.java diff --git a/src/main/java/xades4j/providers/impl/HttpTimeStampTokenProvider.java b/src/main/java/xades4j/providers/impl/HttpTimeStampTokenProvider.java index 40a1d6f1..0e53b4a2 100644 --- a/src/main/java/xades4j/providers/impl/HttpTimeStampTokenProvider.java +++ b/src/main/java/xades4j/providers/impl/HttpTimeStampTokenProvider.java @@ -19,7 +19,6 @@ import jakarta.inject.Inject; import xades4j.providers.MessageDigestEngineProvider; import xades4j.providers.TimeStampTokenGenerationException; -import xades4j.utils.Base64; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; @@ -27,6 +26,7 @@ import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; +import java.util.Base64; /** * Implementation of {@code AbstractTimeStampTokenProvider} that gets time-stamp tokens @@ -45,7 +45,7 @@ public HttpTimeStampTokenProvider(MessageDigestEngineProvider messageDigestProvi this.tsaHttpData = tsaHttpData; if (tsaHttpData.getUsername() != null) { String usrAndPwd = tsaHttpData.getUsername() + ":" + tsaHttpData.getPassword(); - base64TsaUsrAndPwd = Base64.encodeBytes(usrAndPwd.getBytes()); + base64TsaUsrAndPwd = Base64.getMimeEncoder().encodeToString(usrAndPwd.getBytes()); } else { base64TsaUsrAndPwd = null; } diff --git a/src/main/java/xades4j/utils/Base64.java b/src/main/java/xades4j/utils/Base64.java deleted file mode 100644 index ebed116b..00000000 --- a/src/main/java/xades4j/utils/Base64.java +++ /dev/null @@ -1,1991 +0,0 @@ -package xades4j.utils; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.zip.GZIPOutputStream; - -/** - *

Encodes and decodes to and from Base64 notation.

- *

Homepage: http://iharder.net/base64.

- * - *

Example:

- * - * String encoded = Base64.encode( myByteArray ); - *
- * byte[] myByteArray = Base64.decode( encoded ); - * - *

The options parameter, which appears in a few places, is used to pass - * several pieces of information to the encoder. In the "higher level" methods such as - * encodeBytes( bytes, options ) the options parameter can be used to indicate such - * things as first gzipping the bytes before encoding them, not inserting linefeeds, - * and encoding using the URL-safe and Ordered dialects.

- * - *

Note, according to RFC3548, - * Section 2.1, implementations should not add line feeds unless explicitly told - * to do so. I've got Base64 set to this behavior now, although earlier versions - * broke lines by default.

- * - *

The constants defined in Base64 can be OR-ed together to combine options, so you - * might make a call like this:

- * - * String encoded = Base64.encodeBytes( mybytes, Base64.GZIP | Base64.DO_BREAK_LINES ); - *

to compress the data before encoding it and then making the output have newline characters.

- *

Also...

- * String encoded = Base64.encodeBytes( crazyString.getBytes() ); - * - * - * - *

- * Change Log: - *

- *
    - *
  • v2.3.7 - Fixed subtle bug when base 64 input stream contained the - * value 01111111, which is an invalid base 64 character but should not - * throw an ArrayIndexOutOfBoundsException either. Led to discovery of - * mishandling (or potential for better handling) of other bad input - * characters. You should now get an IOException if you try decoding - * something that has bad characters in it.
  • - *
  • v2.3.6 - Fixed bug when breaking lines and the final byte of the encoded - * string ended in the last column; the buffer was not properly shrunk and - * contained an extra (null) byte that made it into the string.
  • - *
  • v2.3.5 - Fixed bug in {@link #encodeFromFile} where estimated buffer size - * was wrong for files of size 31, 34, and 37 bytes.
  • - *
  • v2.3.4 - Fixed bug when working with gzipped streams whereby flushing - * the Base64.OutputStream closed the Base64 encoding (by padding with equals - * signs) too soon. Also added an option to suppress the automatic decoding - * of gzipped streams. Also added experimental support for specifying a - * class loader when using the - * {@link #decodeToObject(java.lang.String, int, java.lang.ClassLoader)} - * method.
  • - *
  • v2.3.3 - Changed default char encoding to US-ASCII which reduces the internal Java - * footprint with its CharEncoders and so forth. Fixed some javadocs that were - * inconsistent. Removed imports and specified things like java.io.IOException - * explicitly inline.
  • - *
  • v2.3.2 - Reduced memory footprint! Finally refined the "guessing" of how big the - * final encoded data will be so that the code doesn't have to create two output - * arrays: an oversized initial one and then a final, exact-sized one. Big win - * when using the {@link #encodeBytesToBytes(byte[])} family of methods (and not - * using the gzip options which uses a different mechanism with streams and stuff).
  • - *
  • v2.3.1 - Added {@link #encodeBytesToBytes(byte[], int, int, int)} and some - * similar helper methods to be more efficient with memory by not returning a - * String but just a byte array.
  • - *
  • v2.3 - This is not a drop-in replacement! This is two years of comments - * and bug fixes queued up and finally executed. Thanks to everyone who sent - * me stuff, and I'm sorry I wasn't able to distribute your fixes to everyone else. - * Much bad coding was cleaned up including throwing exceptions where necessary - * instead of returning null values or something similar. Here are some changes - * that may affect you: - *
      - *
    • Does not break lines, by default. This is to keep in compliance with - * RFC3548.
    • - *
    • Throws exceptions instead of returning null values. Because some operations - * (especially those that may permit the GZIP option) use IO streams, there - * is a possiblity of an java.io.IOException being thrown. After some discussion and - * thought, I've changed the behavior of the methods to throw java.io.IOExceptions - * rather than return null if ever there's an error. I think this is more - * appropriate, though it will require some changes to your code. Sorry, - * it should have been done this way to begin with.
    • - *
    • Removed all references to System.out, System.err, and the like. - * Shame on me. All I can say is sorry they were ever there.
    • - *
    • Throws NullPointerExceptions and IllegalArgumentExceptions as needed - * such as when passed arrays are null or offsets are invalid.
    • - *
    • Cleaned up as much javadoc as I could to avoid any javadoc warnings. - * This was especially annoying before for people who were thorough in their - * own projects and then had gobs of javadoc warnings on this file.
    • - *
    - *
  • v2.2.1 - Fixed bug using URL_SAFE and ORDERED encodings. Fixed bug - * when using very small files (~< 40 bytes).
  • - *
  • v2.2 - Added some helper methods for encoding/decoding directly from - * one file to the next. Also added a main() method to support command line - * encoding/decoding from one file to the next. Also added these Base64 dialects: - *
      - *
    1. The default is RFC3548 format.
    2. - *
    3. Calling Base64.setFormat(Base64.BASE64_FORMAT.URLSAFE_FORMAT) generates - * URL and file name friendly format as described in Section 4 of RFC3548. - * http://www.faqs.org/rfcs/rfc3548.html
    4. - *
    5. Calling Base64.setFormat(Base64.BASE64_FORMAT.ORDERED_FORMAT) generates - * URL and file name friendly format that preserves lexical ordering as described - * in http://www.faqs.org/qa/rfcc-1940.html
    6. - *
    - * Special thanks to Jim Kellerman at http://www.powerset.com/ - * for contributing the new Base64 dialects. - *
  • - * - *
  • v2.1 - Cleaned up javadoc comments and unused variables and methods. Added - * some convenience methods for reading and writing to and from files.
  • - *
  • v2.0.2 - Now specifies UTF-8 encoding in places where the code fails on systems - * with other encodings (like EBCDIC).
  • - *
  • v2.0.1 - Fixed an error when decoding a single byte, that is, when the - * encoded data was a single byte.
  • - *
  • v2.0 - I got rid of methods that used booleans to set options. - * Now everything is more consolidated and cleaner. The code now detects - * when data that's being decoded is gzip-compressed and will decompress it - * automatically. Generally things are cleaner. You'll probably have to - * change some method calls that you were making to support the new - * options format (ints that you "OR" together).
  • - *
  • v1.5.1 - Fixed bug when decompressing and decoding to a - * byte[] using decode( String s, boolean gzipCompressed ). - * Added the ability to "suspend" encoding in the Output Stream so - * you can turn on and off the encoding if you need to embed base64 - * data in an otherwise "normal" stream (like an XML file).
  • - *
  • v1.5 - Output stream pases on flush() command but doesn't do anything itself. - * This helps when using GZIP streams. - * Added the ability to GZip-compress objects before encoding them.
  • - *
  • v1.4 - Added helper methods to read/write files.
  • - *
  • v1.3.6 - Fixed OutputStream.flush() so that 'position' is reset.
  • - *
  • v1.3.5 - Added flag to turn on and off line breaks. Fixed bug in input stream - * where last buffer being read, if not completely full, was not returned.
  • - *
  • v1.3.4 - Fixed when "improperly padded stream" error was thrown at the wrong time.
  • - *
  • v1.3.3 - Fixed I/O streams which were totally messed up.
  • - *
- * - *

- * I am placing this code in the Public Domain. Do with it as you will. - * This software comes with no guarantees or warranties but with - * plenty of well-wishing instead! - * Please visit http://iharder.net/base64 - * periodically to check for updates or to contribute improvements. - *

- * - * @author Robert Harder - * @author rob@iharder.net - * @version 2.3.7 - */ -public class Base64 -{ - -/* ******** P U B L I C F I E L D S ******** */ - - - /** No options specified. Value is zero. */ - public static final int NO_OPTIONS = 0; - - /** Specify encoding in first bit. Value is one. */ - public static final int ENCODE = 1; - - - /** Specify decoding in first bit. Value is zero. */ - public static final int DECODE = 0; - - - /** Specify that data should be gzip-compressed in second bit. Value is two. */ - public static final int GZIP = 2; - - /** Specify that gzipped data should not be automatically gunzipped. */ - public static final int DONT_GUNZIP = 4; - - - /** Do break lines when encoding. Value is 8. */ - public static final int DO_BREAK_LINES = 8; - - /** - * Encode using Base64-like encoding that is URL- and Filename-safe as described - * in Section 4 of RFC3548: - * http://www.faqs.org/rfcs/rfc3548.html. - * It is important to note that data encoded this way is not officially valid Base64, - * or at the very least should not be called Base64 without also specifying that is - * was encoded using the URL- and Filename-safe dialect. - */ - public static final int URL_SAFE = 16; - - - /** - * Encode using the special "ordered" dialect of Base64 described here: - * http://www.faqs.org/qa/rfcc-1940.html. - */ - public static final int ORDERED = 32; - - -/* ******** P R I V A T E F I E L D S ******** */ - - - /** Maximum line length (76) of Base64 output. */ - private static final int MAX_LINE_LENGTH = 76; - - - /** The equals sign (=) as a byte. */ - private static final byte EQUALS_SIGN = (byte)'='; - - - /** The new line character (\n) as a byte. */ - private static final byte NEW_LINE = (byte)'\n'; - - - /** Preferred encoding. */ - private static final String PREFERRED_ENCODING = "US-ASCII"; - - - private static final byte WHITE_SPACE_ENC = -5; // Indicates white space in encoding - private static final byte EQUALS_SIGN_ENC = -1; // Indicates equals sign in encoding - - -/* ******** S T A N D A R D B A S E 6 4 A L P H A B E T ******** */ - - /** The 64 valid Base64 values. */ - /* Host platform me be something funny like EBCDIC, so we hardcode these values. */ - private static final byte[] _STANDARD_ALPHABET = { - (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', (byte)'G', - (byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N', - (byte)'O', (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U', - (byte)'V', (byte)'W', (byte)'X', (byte)'Y', (byte)'Z', - (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f', (byte)'g', - (byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n', - (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', - (byte)'v', (byte)'w', (byte)'x', (byte)'y', (byte)'z', - (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', - (byte)'6', (byte)'7', (byte)'8', (byte)'9', (byte)'+', (byte)'/' - }; - - - /** - * Translates a Base64 value to either its 6-bit reconstruction value - * or a negative number indicating some other meaning. - **/ - private static final byte[] _STANDARD_DECODABET = { - -9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 0 - 8 - -5,-5, // Whitespace: Tab and Linefeed - -9,-9, // Decimal 11 - 12 - -5, // Whitespace: Carriage Return - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 14 - 26 - -9,-9,-9,-9,-9, // Decimal 27 - 31 - -5, // Whitespace: Space - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 33 - 42 - 62, // Plus sign at decimal 43 - -9,-9,-9, // Decimal 44 - 46 - 63, // Slash at decimal 47 - 52,53,54,55,56,57,58,59,60,61, // Numbers zero through nine - -9,-9,-9, // Decimal 58 - 60 - -1, // Equals sign at decimal 61 - -9,-9,-9, // Decimal 62 - 64 - 0,1,2,3,4,5,6,7,8,9,10,11,12,13, // Letters 'A' through 'N' - 14,15,16,17,18,19,20,21,22,23,24,25, // Letters 'O' through 'Z' - -9,-9,-9,-9,-9,-9, // Decimal 91 - 96 - 26,27,28,29,30,31,32,33,34,35,36,37,38, // Letters 'a' through 'm' - 39,40,41,42,43,44,45,46,47,48,49,50,51, // Letters 'n' through 'z' - -9,-9,-9,-9,-9 // Decimal 123 - 127 - ,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 128 - 139 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 140 - 152 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 153 - 165 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 166 - 178 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 179 - 191 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 192 - 204 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 205 - 217 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 218 - 230 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 231 - 243 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 - }; - - -/* ******** U R L S A F E B A S E 6 4 A L P H A B E T ******** */ - - /** - * Used in the URL- and Filename-safe dialect described in Section 4 of RFC3548: - * http://www.faqs.org/rfcs/rfc3548.html. - * Notice that the last two bytes become "hyphen" and "underscore" instead of "plus" and "slash." - */ - private static final byte[] _URL_SAFE_ALPHABET = { - (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', (byte)'G', - (byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N', - (byte)'O', (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U', - (byte)'V', (byte)'W', (byte)'X', (byte)'Y', (byte)'Z', - (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f', (byte)'g', - (byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n', - (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', - (byte)'v', (byte)'w', (byte)'x', (byte)'y', (byte)'z', - (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', - (byte)'6', (byte)'7', (byte)'8', (byte)'9', (byte)'-', (byte)'_' - }; - - /** - * Used in decoding URL- and Filename-safe dialects of Base64. - */ - private static final byte[] _URL_SAFE_DECODABET = { - -9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 0 - 8 - -5,-5, // Whitespace: Tab and Linefeed - -9,-9, // Decimal 11 - 12 - -5, // Whitespace: Carriage Return - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 14 - 26 - -9,-9,-9,-9,-9, // Decimal 27 - 31 - -5, // Whitespace: Space - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 33 - 42 - -9, // Plus sign at decimal 43 - -9, // Decimal 44 - 62, // Minus sign at decimal 45 - -9, // Decimal 46 - -9, // Slash at decimal 47 - 52,53,54,55,56,57,58,59,60,61, // Numbers zero through nine - -9,-9,-9, // Decimal 58 - 60 - -1, // Equals sign at decimal 61 - -9,-9,-9, // Decimal 62 - 64 - 0,1,2,3,4,5,6,7,8,9,10,11,12,13, // Letters 'A' through 'N' - 14,15,16,17,18,19,20,21,22,23,24,25, // Letters 'O' through 'Z' - -9,-9,-9,-9, // Decimal 91 - 94 - 63, // Underscore at decimal 95 - -9, // Decimal 96 - 26,27,28,29,30,31,32,33,34,35,36,37,38, // Letters 'a' through 'm' - 39,40,41,42,43,44,45,46,47,48,49,50,51, // Letters 'n' through 'z' - -9,-9,-9,-9,-9 // Decimal 123 - 127 - ,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 128 - 139 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 140 - 152 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 153 - 165 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 166 - 178 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 179 - 191 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 192 - 204 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 205 - 217 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 218 - 230 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 231 - 243 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 - }; - - - -/* ******** O R D E R E D B A S E 6 4 A L P H A B E T ******** */ - - /** - * I don't get the point of this technique, but someone requested it, - * and it is described here: - * http://www.faqs.org/qa/rfcc-1940.html. - */ - private static final byte[] _ORDERED_ALPHABET = { - (byte)'-', - (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', - (byte)'5', (byte)'6', (byte)'7', (byte)'8', (byte)'9', - (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', (byte)'G', - (byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N', - (byte)'O', (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U', - (byte)'V', (byte)'W', (byte)'X', (byte)'Y', (byte)'Z', - (byte)'_', - (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f', (byte)'g', - (byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n', - (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', - (byte)'v', (byte)'w', (byte)'x', (byte)'y', (byte)'z' - }; - - /** - * Used in decoding the "ordered" dialect of Base64. - */ - private static final byte[] _ORDERED_DECODABET = { - -9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 0 - 8 - -5,-5, // Whitespace: Tab and Linefeed - -9,-9, // Decimal 11 - 12 - -5, // Whitespace: Carriage Return - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 14 - 26 - -9,-9,-9,-9,-9, // Decimal 27 - 31 - -5, // Whitespace: Space - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 33 - 42 - -9, // Plus sign at decimal 43 - -9, // Decimal 44 - 0, // Minus sign at decimal 45 - -9, // Decimal 46 - -9, // Slash at decimal 47 - 1,2,3,4,5,6,7,8,9,10, // Numbers zero through nine - -9,-9,-9, // Decimal 58 - 60 - -1, // Equals sign at decimal 61 - -9,-9,-9, // Decimal 62 - 64 - 11,12,13,14,15,16,17,18,19,20,21,22,23, // Letters 'A' through 'M' - 24,25,26,27,28,29,30,31,32,33,34,35,36, // Letters 'N' through 'Z' - -9,-9,-9,-9, // Decimal 91 - 94 - 37, // Underscore at decimal 95 - -9, // Decimal 96 - 38,39,40,41,42,43,44,45,46,47,48,49,50, // Letters 'a' through 'm' - 51,52,53,54,55,56,57,58,59,60,61,62,63, // Letters 'n' through 'z' - -9,-9,-9,-9,-9 // Decimal 123 - 127 - ,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 128 - 139 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 140 - 152 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 153 - 165 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 166 - 178 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 179 - 191 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 192 - 204 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 205 - 217 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 218 - 230 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 231 - 243 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 - }; - - -/* ******** D E T E R M I N E W H I C H A L H A B E T ******** */ - - - /** - * Returns one of the _SOMETHING_ALPHABET byte arrays depending on - * the options specified. - * It's possible, though silly, to specify ORDERED and URLSAFE - * in which case one of them will be picked, though there is - * no guarantee as to which one will be picked. - */ - private static byte[] getAlphabet(int options) { - if ((options & URL_SAFE) == URL_SAFE) { - return _URL_SAFE_ALPHABET; - } else if ((options & ORDERED) == ORDERED) { - return _ORDERED_ALPHABET; - } else { - return _STANDARD_ALPHABET; - } - } // end getAlphabet - - - /** - * Returns one of the _SOMETHING_DECODABET byte arrays depending on - * the options specified. - * It's possible, though silly, to specify ORDERED and URL_SAFE - * in which case one of them will be picked, though there is - * no guarantee as to which one will be picked. - */ - private static byte[] getDecodabet(int options) { - if( (options & URL_SAFE) == URL_SAFE) { - return _URL_SAFE_DECODABET; - } else if ((options & ORDERED) == ORDERED) { - return _ORDERED_DECODABET; - } else { - return _STANDARD_DECODABET; - } - } // end getAlphabet - - - - /** Defeats instantiation. */ - private Base64(){} - - - - -/* ******** E N C O D I N G M E T H O D S ******** */ - - - /** - * Encodes up to the first three bytes of array threeBytes - * and returns a four-byte array in Base64 notation. - * The actual number of significant bytes in your array is - * given by numSigBytes. - * The array threeBytes needs only be as big as - * numSigBytes. - * Code can reuse a byte array by passing a four-byte array as b4. - * - * @param b4 A reusable byte array to reduce array instantiation - * @param threeBytes the array to convert - * @param numSigBytes the number of significant bytes in your array - * @return four byte array in Base64 notation. - * @since 1.5.1 - */ - private static byte[] encode3to4( byte[] b4, byte[] threeBytes, int numSigBytes, int options ) { - encode3to4( threeBytes, 0, numSigBytes, b4, 0, options ); - return b4; - } // end encode3to4 - - - /** - *

Encodes up to three bytes of the array source - * and writes the resulting four Base64 bytes to destination. - * The source and destination arrays can be manipulated - * anywhere along their length by specifying - * srcOffset and destOffset. - * This method does not check to make sure your arrays - * are large enough to accomodate srcOffset + 3 for - * the source array or destOffset + 4 for - * the destination array. - * The actual number of significant bytes in your array is - * given by numSigBytes.

- *

This is the lowest level of the encoding methods with - * all possible parameters.

- * - * @param source the array to convert - * @param srcOffset the index where conversion begins - * @param numSigBytes the number of significant bytes in your array - * @param destination the array to hold the conversion - * @param destOffset the index where output will be put - * @return the destination array - * @since 1.3 - */ - private static byte[] encode3to4( - byte[] source, int srcOffset, int numSigBytes, - byte[] destination, int destOffset, int options ) { - - byte[] ALPHABET = getAlphabet( options ); - - // 1 2 3 - // 01234567890123456789012345678901 Bit position - // --------000000001111111122222222 Array position from threeBytes - // --------| || || || | Six bit groups to index ALPHABET - // >>18 >>12 >> 6 >> 0 Right shift necessary - // 0x3f 0x3f 0x3f Additional AND - - // Create buffer with zero-padding if there are only one or two - // significant bytes passed in the array. - // We have to shift left 24 in order to flush out the 1's that appear - // when Java treats a value as negative that is cast from a byte to an int. - int inBuff = ( numSigBytes > 0 ? ((source[ srcOffset ] << 24) >>> 8) : 0 ) - | ( numSigBytes > 1 ? ((source[ srcOffset + 1 ] << 24) >>> 16) : 0 ) - | ( numSigBytes > 2 ? ((source[ srcOffset + 2 ] << 24) >>> 24) : 0 ); - - switch( numSigBytes ) - { - case 3: - destination[ destOffset ] = ALPHABET[ (inBuff >>> 18) ]; - destination[ destOffset + 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ]; - destination[ destOffset + 2 ] = ALPHABET[ (inBuff >>> 6) & 0x3f ]; - destination[ destOffset + 3 ] = ALPHABET[ (inBuff ) & 0x3f ]; - return destination; - - case 2: - destination[ destOffset ] = ALPHABET[ (inBuff >>> 18) ]; - destination[ destOffset + 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ]; - destination[ destOffset + 2 ] = ALPHABET[ (inBuff >>> 6) & 0x3f ]; - destination[ destOffset + 3 ] = EQUALS_SIGN; - return destination; - - case 1: - destination[ destOffset ] = ALPHABET[ (inBuff >>> 18) ]; - destination[ destOffset + 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ]; - destination[ destOffset + 2 ] = EQUALS_SIGN; - destination[ destOffset + 3 ] = EQUALS_SIGN; - return destination; - - default: - return destination; - } // end switch - } // end encode3to4 - - - - /** - * Performs Base64 encoding on the raw ByteBuffer, - * writing it to the encoded ByteBuffer. - * This is an experimental feature. Currently it does not - * pass along any options (such as {@link #DO_BREAK_LINES} - * or {@link #GZIP}. - * - * @param raw input buffer - * @param encoded output buffer - * @since 2.3 - */ - public static void encode( java.nio.ByteBuffer raw, java.nio.ByteBuffer encoded ){ - byte[] raw3 = new byte[3]; - byte[] enc4 = new byte[4]; - - while( raw.hasRemaining() ){ - int rem = Math.min(3,raw.remaining()); - raw.get(raw3,0,rem); - Base64.encode3to4(enc4, raw3, rem, Base64.NO_OPTIONS ); - encoded.put(enc4); - } // end input remaining - } - - - /** - * Performs Base64 encoding on the raw ByteBuffer, - * writing it to the encoded CharBuffer. - * This is an experimental feature. Currently it does not - * pass along any options (such as {@link #DO_BREAK_LINES} - * or {@link #GZIP}. - * - * @param raw input buffer - * @param encoded output buffer - * @since 2.3 - */ - public static void encode( java.nio.ByteBuffer raw, java.nio.CharBuffer encoded ){ - byte[] raw3 = new byte[3]; - byte[] enc4 = new byte[4]; - - while( raw.hasRemaining() ){ - int rem = Math.min(3,raw.remaining()); - raw.get(raw3,0,rem); - Base64.encode3to4(enc4, raw3, rem, Base64.NO_OPTIONS ); - for( int i = 0; i < 4; i++ ){ - encoded.put( (char)(enc4[i] & 0xFF) ); - } - } // end input remaining - } - - - - - /** - * Serializes an object and returns the Base64-encoded - * version of that serialized object. - * - *

As of v 2.3, if the object - * cannot be serialized or there is another error, - * the method will throw an java.io.IOException. This is new to v2.3! - * In earlier versions, it just returned a null value, but - * in retrospect that's a pretty poor way to handle it.

- * - * The object is not GZip-compressed before being encoded. - * - * @param serializableObject The object to encode - * @return The Base64-encoded object - * @throws java.io.IOException if there is an error - * @throws NullPointerException if serializedObject is null - * @since 1.4 - */ - public static String encodeObject( java.io.Serializable serializableObject ) - throws java.io.IOException { - return encodeObject( serializableObject, NO_OPTIONS ); - } // end encodeObject - - - - /** - * Serializes an object and returns the Base64-encoded - * version of that serialized object. - * - *

As of v 2.3, if the object - * cannot be serialized or there is another error, - * the method will throw an java.io.IOException. This is new to v2.3! - * In earlier versions, it just returned a null value, but - * in retrospect that's a pretty poor way to handle it.

- * - * The object is not GZip-compressed before being encoded. - *

- * Example options:

-     *   GZIP: gzip-compresses object before encoding it.
-     *   DO_BREAK_LINES: break lines at 76 characters
-     * 
- *

- * Example: encodeObject( myObj, Base64.GZIP ) or - *

- * Example: encodeObject( myObj, Base64.GZIP | Base64.DO_BREAK_LINES ) - * - * @param serializableObject The object to encode - * @param options Specified options - * @return The Base64-encoded object - * @see Base64#GZIP - * @see Base64#DO_BREAK_LINES - * @throws java.io.IOException if there is an error - * @since 2.0 - */ - public static String encodeObject( java.io.Serializable serializableObject, int options ) - throws java.io.IOException { - - if( serializableObject == null ){ - throw new NullPointerException( "Cannot serialize a null object." ); - } // end if: null - - // Streams - java.util.zip.GZIPOutputStream gzos = null; - java.io.ObjectOutputStream oos = null; - - - try (final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - final OutputStream b64os = new Base64.OutputStream( baos, ENCODE | options );) { - // ObjectOutputStream -> (GZIP) -> Base64 -> ByteArrayOutputStream - - if( (options & GZIP) != 0 ){ - // Gzip - gzos = new java.util.zip.GZIPOutputStream(b64os); - oos = new java.io.ObjectOutputStream( gzos ); - } else { - // Not gzipped - oos = new java.io.ObjectOutputStream( b64os ); - } - oos.writeObject( serializableObject ); - - return baos.toString(StandardCharsets.US_ASCII); - - } // end try - // end catch - finally { - try{ - assert oos != null; - oos.close(); } catch(Exception ignored){} - try{ - assert gzos != null; - gzos.close(); } catch(Exception ignored){} - } // end finally - - } // end encode - - - - /** - * Encodes a byte array into Base64 notation. - * Does not GZip-compress data. - * - * @param source The data to convert - * @return The data in Base64-encoded form - * @throws NullPointerException if source array is null - * @since 1.4 - */ - public static String encodeBytes( byte[] source ) { - // Since we're not going to have the GZIP encoding turned on, - // we're not going to have an java.io.IOException thrown, so - // we should not force the user to have to catch it. - String encoded = null; - try { - encoded = encodeBytes(source, 0, source.length, NO_OPTIONS); - } catch (java.io.IOException ex) { - assert false : ex.getMessage(); - } // end catch - assert encoded != null; - return encoded; - } // end encodeBytes - - - - /** - * Encodes a byte array into Base64 notation. - *

- * Example options:

-     *   GZIP: gzip-compresses object before encoding it.
-     *   DO_BREAK_LINES: break lines at 76 characters
-     *     Note: Technically, this makes your encoding non-compliant.
-     * 
- *

- * Example: encodeBytes( myData, Base64.GZIP ) or - *

- * Example: encodeBytes( myData, Base64.GZIP | Base64.DO_BREAK_LINES ) - * - * - *

As of v 2.3, if there is an error with the GZIP stream, - * the method will throw an java.io.IOException. This is new to v2.3! - * In earlier versions, it just returned a null value, but - * in retrospect that's a pretty poor way to handle it.

- * - * - * @param source The data to convert - * @param options Specified options - * @return The Base64-encoded data as a String - * @see Base64#GZIP - * @see Base64#DO_BREAK_LINES - * @throws java.io.IOException if there is an error - * @throws NullPointerException if source array is null - * @since 2.0 - */ - public static String encodeBytes( byte[] source, int options ) throws java.io.IOException { - return encodeBytes( source, 0, source.length, options ); - } // end encodeBytes - - - /** - * Encodes a byte array into Base64 notation. - * Does not GZip-compress data. - * - *

As of v 2.3, if there is an error, - * the method will throw an java.io.IOException. This is new to v2.3! - * In earlier versions, it just returned a null value, but - * in retrospect that's a pretty poor way to handle it.

- * - * - * @param source The data to convert - * @param off Offset in array where conversion should begin - * @param len Length of data to convert - * @return The Base64-encoded data as a String - * @throws NullPointerException if source array is null - * @throws IllegalArgumentException if source array, offset, or length are invalid - * @since 1.4 - */ - public static String encodeBytes( byte[] source, int off, int len ) { - // Since we're not going to have the GZIP encoding turned on, - // we're not going to have an java.io.IOException thrown, so - // we should not force the user to have to catch it. - String encoded = null; - try { - encoded = encodeBytes( source, off, len, NO_OPTIONS ); - } catch (java.io.IOException ex) { - assert false : ex.getMessage(); - } // end catch - assert encoded != null; - return encoded; - } // end encodeBytes - - - - /** - * Encodes a byte array into Base64 notation. - *

- * Example options:

-     *   GZIP: gzip-compresses object before encoding it.
-     *   DO_BREAK_LINES: break lines at 76 characters
-     *     Note: Technically, this makes your encoding non-compliant.
-     * 
- *

- * Example: encodeBytes( myData, Base64.GZIP ) or - *

- * Example: encodeBytes( myData, Base64.GZIP | Base64.DO_BREAK_LINES ) - * - * - *

As of v 2.3, if there is an error with the GZIP stream, - * the method will throw an java.io.IOException. This is new to v2.3! - * In earlier versions, it just returned a null value, but - * in retrospect that's a pretty poor way to handle it.

- * - * - * @param source The data to convert - * @param off Offset in array where conversion should begin - * @param len Length of data to convert - * @param options Specified options - * @return The Base64-encoded data as a String - * @see Base64#GZIP - * @see Base64#DO_BREAK_LINES - * @throws java.io.IOException if there is an error - * @throws NullPointerException if source array is null - * @throws IllegalArgumentException if source array, offset, or length are invalid - * @since 2.0 - */ - public static String encodeBytes( byte[] source, int off, int len, int options ) throws java.io.IOException { - byte[] encoded = encodeBytesToBytes( source, off, len, options ); - - // Return value according to relevant encoding. - return new String( encoded, StandardCharsets.US_ASCII ); - - } // end encodeBytes - - - - - /** - * Similar to {@link #encodeBytes(byte[])} but returns - * a byte array instead of instantiating a String. This is more efficient - * if you're working with I/O streams and have large data sets to encode. - * - * - * @param source The data to convert - * @return The Base64-encoded data as a byte[] (of ASCII characters) - * @throws NullPointerException if source array is null - * @since 2.3.1 - */ - public static byte[] encodeBytesToBytes( byte[] source ) { - byte[] encoded = null; - try { - encoded = encodeBytesToBytes( source, 0, source.length, Base64.NO_OPTIONS ); - } catch( java.io.IOException ex ) { - assert false : "IOExceptions only come from GZipping, which is turned off: " + ex.getMessage(); - } - return encoded; - } - - - /** - * Similar to {@link #encodeBytes(byte[], int, int, int)} but returns - * a byte array instead of instantiating a String. This is more efficient - * if you're working with I/O streams and have large data sets to encode. - * - * - * @param source The data to convert - * @param off Offset in array where conversion should begin - * @param len Length of data to convert - * @param options Specified options - * @return The Base64-encoded data as a String - * @see Base64#GZIP - * @see Base64#DO_BREAK_LINES - * @throws java.io.IOException if there is an error - * @throws NullPointerException if source array is null - * @throws IllegalArgumentException if source array, offset, or length are invalid - * @since 2.3.1 - */ - public static byte[] encodeBytesToBytes( byte[] source, int off, int len, int options ) throws java.io.IOException { - - if( source == null ){ - throw new NullPointerException( "Cannot serialize a null array." ); - } // end if: null - - if( off < 0 ){ - throw new IllegalArgumentException( "Cannot have negative offset: " + off ); - } // end if: off < 0 - - if( len < 0 ){ - throw new IllegalArgumentException( "Cannot have length offset: " + len ); - } // end if: len < 0 - - if( off + len > source.length ){ - throw new IllegalArgumentException( - String.format( "Cannot have offset of %d and length of %d with array of length %d", off,len,source.length)); - } // end if: off < 0 - - - - // Compress? - if( (options & GZIP) != 0 ) { - - try (ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); - OutputStream b64os = new Base64.OutputStream( baos, ENCODE | options ); - GZIPOutputStream gzos = new java.util.zip.GZIPOutputStream( b64os ); -) { - // GZip -> Base64 -> ByteArray - - gzos.write( source, off, len ); - return baos.toByteArray(); - } // end try - } // end if: compress - - // Else, don't compress. Better not to use streams at all then. - else { - boolean breakLines = (options & DO_BREAK_LINES) != 0; - - //int len43 = len * 4 / 3; - //byte[] outBuff = new byte[ ( len43 ) // Main 4:3 - // + ( (len % 3) > 0 ? 4 : 0 ) // Account for padding - // + (breakLines ? ( len43 / MAX_LINE_LENGTH ) : 0) ]; // New lines - // Try to determine more precisely how big the array needs to be. - // If we get it right, we don't have to do an array copy, and - // we save a bunch of memory. - int encLen = ( len / 3 ) * 4 + ( len % 3 > 0 ? 4 : 0 ); // Bytes needed for actual encoding - if( breakLines ){ - encLen += encLen / MAX_LINE_LENGTH; // Plus extra newline characters - } - byte[] outBuff = new byte[ encLen ]; - - - int d = 0; - int e = 0; - int len2 = len - 2; - int lineLength = 0; - for( ; d < len2; d+=3, e+=4 ) { - encode3to4( source, d+off, 3, outBuff, e, options ); - - lineLength += 4; - if( breakLines && lineLength >= MAX_LINE_LENGTH ) - { - outBuff[e+4] = NEW_LINE; - e++; - lineLength = 0; - } // end if: end of line - } // en dfor: each piece of array - - if( d < len ) { - encode3to4( source, d+off, len - d, outBuff, e, options ); - e += 4; - } // end if: some padding needed - - - // Only resize array if we didn't guess it right. - if( e <= outBuff.length - 1 ){ - // If breaking lines and the last byte falls right at - // the line length (76 bytes per line), there will be - // one extra byte, and the array will need to be resized. - // Not too bad of an estimate on array size, I'd say. - byte[] finalOut = new byte[e]; - System.arraycopy(outBuff,0, finalOut,0,e); - //System.err.println("Having to resize array from " + outBuff.length + " to " + e ); - return finalOut; - } else { - //System.err.println("No need to resize array."); - return outBuff; - } - - } // end else: don't compress - - } // end encodeBytesToBytes - - - - - -/* ******** D E C O D I N G M E T H O D S ******** */ - - - /** - * Decodes four bytes from array source - * and writes the resulting bytes (up to three of them) - * to destination. - * The source and destination arrays can be manipulated - * anywhere along their length by specifying - * srcOffset and destOffset. - * This method does not check to make sure your arrays - * are large enough to accomodate srcOffset + 4 for - * the source array or destOffset + 3 for - * the destination array. - * This method returns the actual number of bytes that - * were converted from the Base64 encoding. - *

This is the lowest level of the decoding methods with - * all possible parameters.

- * - * - * @param source the array to convert - * @param srcOffset the index where conversion begins - * @param destination the array to hold the conversion - * @param destOffset the index where output will be put - * @param options alphabet type is pulled from this (standard, url-safe, ordered) - * @return the number of decoded bytes converted - * @throws NullPointerException if source or destination arrays are null - * @throws IllegalArgumentException if srcOffset or destOffset are invalid - * or there is not enough room in the array. - * @since 1.3 - */ - private static int decode4to3( - byte[] source, int srcOffset, - byte[] destination, int destOffset, int options ) { - - // Lots of error checking and exception throwing - if( source == null ){ - throw new NullPointerException( "Source array was null." ); - } // end if - if( destination == null ){ - throw new NullPointerException( "Destination array was null." ); - } // end if - if( srcOffset < 0 || srcOffset + 3 >= source.length ){ - throw new IllegalArgumentException( String.format( - "Source array with length %d cannot have offset of %d and still process four bytes.", source.length, srcOffset ) ); - } // end if - if( destOffset < 0 || destOffset +2 >= destination.length ){ - throw new IllegalArgumentException( String.format( - "Destination array with length %d cannot have offset of %d and still store three bytes.", destination.length, destOffset ) ); - } // end if - - - byte[] DECODABET = getDecodabet( options ); - - // Example: Dk== - if( source[ srcOffset + 2] == EQUALS_SIGN ) { - // Two ways to do the same thing. Don't know which way I like best. - //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 ) - // | ( ( DECODABET[ source[ srcOffset + 1] ] << 24 ) >>> 12 ); - int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 ) - | ( ( DECODABET[ source[ srcOffset + 1] ] & 0xFF ) << 12 ); - - destination[ destOffset ] = (byte)( outBuff >>> 16 ); - return 1; - } - - // Example: DkL= - else if( source[ srcOffset + 3 ] == EQUALS_SIGN ) { - // Two ways to do the same thing. Don't know which way I like best. - //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 ) - // | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 ) - // | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 ); - int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 ) - | ( ( DECODABET[ source[ srcOffset + 1 ] ] & 0xFF ) << 12 ) - | ( ( DECODABET[ source[ srcOffset + 2 ] ] & 0xFF ) << 6 ); - - destination[ destOffset ] = (byte)( outBuff >>> 16 ); - destination[ destOffset + 1 ] = (byte)( outBuff >>> 8 ); - return 2; - } - - // Example: DkLE - else { - // Two ways to do the same thing. Don't know which way I like best. - //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 ) - // | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 ) - // | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 ) - // | ( ( DECODABET[ source[ srcOffset + 3 ] ] << 24 ) >>> 24 ); - int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 ) - | ( ( DECODABET[ source[ srcOffset + 1 ] ] & 0xFF ) << 12 ) - | ( ( DECODABET[ source[ srcOffset + 2 ] ] & 0xFF ) << 6) - | ( ( DECODABET[ source[ srcOffset + 3 ] ] & 0xFF ) ); - - - destination[ destOffset ] = (byte)( outBuff >> 16 ); - destination[ destOffset + 1 ] = (byte)( outBuff >> 8 ); - destination[ destOffset + 2 ] = (byte)( outBuff ); - - return 3; - } - } // end decodeToBytes - - - - - - /** - * Low-level access to decoding ASCII characters in - * the form of a byte array. Ignores GUNZIP option, if - * it's set. This is not generally a recommended method, - * although it is used internally as part of the decoding process. - * Special case: if len = 0, an empty array is returned. Still, - * if you need more speed and reduced memory footprint (and aren't - * gzipping), consider this method. - * - * @param source The Base64 encoded data - * @return decoded data - * @since 2.3.1 - */ - public static byte[] decode( byte[] source ) - throws java.io.IOException { - byte[] decoded = null; -// try { - decoded = decode( source, 0, source.length, Base64.NO_OPTIONS ); -// } catch( java.io.IOException ex ) { -// assert false : "IOExceptions only come from GZipping, which is turned off: " + ex.getMessage(); -// } - return decoded; - } - - - - /** - * Low-level access to decoding ASCII characters in - * the form of a byte array. Ignores GUNZIP option, if - * it's set. This is not generally a recommended method, - * although it is used internally as part of the decoding process. - * Special case: if len = 0, an empty array is returned. Still, - * if you need more speed and reduced memory footprint (and aren't - * gzipping), consider this method. - * - * @param source The Base64 encoded data - * @param off The offset of where to begin decoding - * @param len The length of characters to decode - * @param options Can specify options such as alphabet type to use - * @return decoded data - * @throws java.io.IOException If bogus characters exist in source data - * @since 1.3 - */ - public static byte[] decode( byte[] source, int off, int len, int options ) - throws java.io.IOException { - - // Lots of error checking and exception throwing - if( source == null ){ - throw new NullPointerException( "Cannot decode null source array." ); - } // end if - if( off < 0 || off + len > source.length ){ - throw new IllegalArgumentException( String.format( - "Source array with length %d cannot have offset of %d and process %d bytes.", source.length, off, len ) ); - } // end if - - if( len == 0 ){ - return new byte[0]; - }else if( len < 4 ){ - throw new IllegalArgumentException( - "Base64-encoded string must have at least four characters, but length specified was " + len ); - } // end if - - byte[] DECODABET = getDecodabet( options ); - - int len34 = len * 3 / 4; // Estimate on array size - byte[] outBuff = new byte[ len34 ]; // Upper limit on size of output - int outBuffPosn = 0; // Keep track of where we're writing - - byte[] b4 = new byte[4]; // Four byte buffer from source, eliminating white space - int b4Posn = 0; // Keep track of four byte input buffer - int i = 0; // Source array counter - byte sbiDecode = 0; // Special value from DECODABET - - for( i = off; i < off+len; i++ ) { // Loop through source - - sbiDecode = DECODABET[ source[i]&0xFF ]; - - // White space, Equals sign, or legit Base64 character - // Note the values such as -5 and -9 in the - // DECODABETs at the top of the file. - if( sbiDecode >= WHITE_SPACE_ENC ) { - if( sbiDecode >= EQUALS_SIGN_ENC ) { - b4[ b4Posn++ ] = source[i]; // Save non-whitespace - if( b4Posn > 3 ) { // Time to decode? - outBuffPosn += decode4to3( b4, 0, outBuff, outBuffPosn, options ); - b4Posn = 0; - - // If that was the equals sign, break out of 'for' loop - if( source[i] == EQUALS_SIGN ) { - break; - } // end if: equals sign - } // end if: quartet built - } // end if: equals sign or better - } // end if: white space, equals sign or better - else { - // There's a bad input character in the Base64 stream. - throw new java.io.IOException( String.format( - "Bad Base64 input character decimal %d in array position %d", ((int)source[i])&0xFF, i ) ); - } // end else: - } // each input character - - byte[] out = new byte[ outBuffPosn ]; - System.arraycopy( outBuff, 0, out, 0, outBuffPosn ); - return out; - } // end decode - - - - - /** - * Decodes data from Base64 notation, automatically - * detecting gzip-compressed data and decompressing it. - * - * @param s the string to decode - * @return the decoded data - * @throws java.io.IOException If there is a problem - * @since 1.4 - */ - public static byte[] decode( String s ) throws java.io.IOException { - return decode( s, NO_OPTIONS ); - } - - - - /** - * Decodes data from Base64 notation, automatically - * detecting gzip-compressed data and decompressing it. - * - * @param s the string to decode - * @param options encode options such as URL_SAFE - * @return the decoded data - * @throws java.io.IOException if there is an error - * @throws NullPointerException if s is null - * @since 1.4 - */ - public static byte[] decode( String s, int options ) throws java.io.IOException { - - if( s == null ){ - throw new NullPointerException( "Input string was null." ); - } // end if - - byte[] bytes; - try { - bytes = s.getBytes( PREFERRED_ENCODING ); - } // end try - catch( java.io.UnsupportedEncodingException uee ) { - bytes = s.getBytes(); - } // end catch - // - - // Decode - bytes = decode( bytes, 0, bytes.length, options ); - - // Check to see if it's gzip-compressed - // GZIP Magic Two-Byte Number: 0x8b1f (35615) - boolean dontGunzip = (options & DONT_GUNZIP) != 0; - if(bytes.length >= 4 && !dontGunzip) { - - int head = (bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); - if( java.util.zip.GZIPInputStream.GZIP_MAGIC == head ) { - byte[] buffer = new byte[2048]; - int length = 0; - - try (java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); - ByteArrayInputStream bais = new ByteArrayInputStream(bytes); - java.util.zip.GZIPInputStream gzis = new java.util.zip.GZIPInputStream(bais)) { - - while ((length = gzis.read(buffer)) >= 0) { - baos.write(buffer, 0, length); - } // end while: reading input - - // No error? Get new bytes. - bytes = baos.toByteArray(); - - } catch (IOException e) { - e.printStackTrace(); - // Just return originally-decoded bytes - } - - } // end if: gzipped - } // end if: bytes.length >= 2 - - return bytes; - } // end decode - - - - /** - * Attempts to decode Base64 data and deserialize a Java - * Object within. Returns null if there was an error. - * - * @param encodedObject The Base64 data to decode - * @return The decoded and deserialized object - * @throws NullPointerException if encodedObject is null - * @throws java.io.IOException if there is a general error - * @throws ClassNotFoundException if the decoded object is of a - * class that cannot be found by the JVM - * @since 1.5 - */ - public static Object decodeToObject( String encodedObject ) - throws java.io.IOException, java.lang.ClassNotFoundException { - return decodeToObject(encodedObject,NO_OPTIONS,null); - } - - - /** - * Attempts to decode Base64 data and deserialize a Java - * Object within. Returns null if there was an error. - * If loader is not null, it will be the class loader - * used when deserializing. - * - * @param encodedObject The Base64 data to decode - * @param options Various parameters related to decoding - * @param loader Optional class loader to use in deserializing classes. - * @return The decoded and deserialized object - * @throws NullPointerException if encodedObject is null - * @throws java.io.IOException if there is a general error - * @throws ClassNotFoundException if the decoded object is of a - * class that cannot be found by the JVM - * @since 2.3.4 - */ - public static Object decodeToObject( - String encodedObject, int options, final ClassLoader loader ) - throws java.io.IOException, java.lang.ClassNotFoundException { - - // Decode and gunzip if necessary - byte[] objBytes = decode( encodedObject, options ); - - java.io.ObjectInputStream ois = null; - Object obj = null; - - try (final ByteArrayInputStream bais = new ByteArrayInputStream( objBytes )){ - // If no custom class loader is provided, use Java's builtin OIS. - if( loader == null ){ - ois = new java.io.ObjectInputStream( bais ); - } // end if: no loader provided - - // Else make a customized object input stream that uses - // the provided class loader. - else { - ois = new java.io.ObjectInputStream(bais){ - @Override - public Class resolveClass(java.io.ObjectStreamClass streamClass) - throws java.io.IOException, ClassNotFoundException { - Class c = Class.forName(streamClass.getName(), false, loader); - if( c == null ){ - return super.resolveClass(streamClass); - } else { - return c; // Class loader knows of this class. - } // end else: not null - } // end resolveClass - }; // end ois - } // end else: no custom class loader - - obj = ois.readObject(); - } // end try - finally { - try{ - assert ois != null; - ois.close(); - } catch(Exception ignored){} - } // end finally - - return obj; - } // end decodeObject - - - - /** - * Convenience method for encoding data to a file. - * - *

As of v 2.3, if there is a error, - * the method will throw an java.io.IOException. This is new to v2.3! - * In earlier versions, it just returned false, but - * in retrospect that's a pretty poor way to handle it.

- * - * @param dataToEncode byte array of data to encode in base64 form - * @param filename Filename for saving encoded data - * @throws java.io.IOException if there is an error - * @throws NullPointerException if dataToEncode is null - * @since 2.1 - */ - public static void encodeToFile( byte[] dataToEncode, String filename ) - throws java.io.IOException { - - if( dataToEncode == null ){ - throw new NullPointerException( "Data to encode was null." ); - } // end iff - - try (OutputStream bos = new OutputStream( - new java.io.FileOutputStream(filename), Base64.ENCODE)) { - bos.write(dataToEncode); - } - - } // end encodeToFile - - - /** - * Convenience method for decoding data to a file. - * - *

As of v 2.3, if there is a error, - * the method will throw an java.io.IOException. This is new to v2.3! - * In earlier versions, it just returned false, but - * in retrospect that's a pretty poor way to handle it.

- * - * @param dataToDecode Base64-encoded data as a string - * @param filename Filename for saving decoded data - * @throws java.io.IOException if there is an error - * @since 2.1 - */ - public static void decodeToFile( String dataToDecode, String filename ) - throws java.io.IOException { - - try (OutputStream bos = new OutputStream( - new java.io.FileOutputStream(filename), Base64.DECODE)) { - bos.write(dataToDecode.getBytes(StandardCharsets.US_ASCII)); - } - - } // end decodeToFile - - - - - /** - * Convenience method for reading a base64-encoded - * file and decoding it. - * - *

As of v 2.3, if there is a error, - * the method will throw an java.io.IOException. This is new to v2.3! - * In earlier versions, it just returned false, but - * in retrospect that's a pretty poor way to handle it.

- * - * @param filename Filename for reading encoded data - * @return decoded byte array - * @throws java.io.IOException if there is an error - * @since 2.1 - */ - public static byte[] decodeFromFile( String filename ) - throws java.io.IOException { - - byte[] decodedData = null; - Base64.InputStream bis = null; - try - { - // Set up some useful variables - java.io.File file = new java.io.File( filename ); - byte[] buffer = null; - int length = 0; - int numBytes = 0; - - // Check for size of file - if( file.length() > Integer.MAX_VALUE ) - { - throw new java.io.IOException( "File is too big for this convenience method (" + file.length() + " bytes)." ); - } // end if: file too big for int index - buffer = new byte[ (int)file.length() ]; - - // Open a stream - bis = new Base64.InputStream( - new java.io.BufferedInputStream( - new java.io.FileInputStream( file ) ), Base64.DECODE ); - - // Read until done - while( ( numBytes = bis.read( buffer, length, 4096 ) ) >= 0 ) { - length += numBytes; - } // end while - - // Save in a variable to return - decodedData = new byte[ length ]; - System.arraycopy( buffer, 0, decodedData, 0, length ); - - } // end try - finally { - try{ - assert bis != null; - bis.close(); - } catch(Exception ignored) {} - } // end finally - - return decodedData; - } // end decodeFromFile - - - - /** - * Convenience method for reading a binary file - * and base64-encoding it. - * - *

As of v 2.3, if there is a error, - * the method will throw an java.io.IOException. This is new to v2.3! - * In earlier versions, it just returned false, but - * in retrospect that's a pretty poor way to handle it.

- * - * @param filename Filename for reading binary data - * @return base64-encoded string - * @throws java.io.IOException if there is an error - * @since 2.1 - */ - public static String encodeFromFile( String filename ) - throws java.io.IOException { - - String encodedData = null; - Base64.InputStream bis = null; - try - { - // Set up some useful variables - java.io.File file = new java.io.File( filename ); - byte[] buffer = new byte[ Math.max((int)(file.length() * 1.4+1),40) ]; // Need max() for math on small files (v2.2.1); Need +1 for a few corner cases (v2.3.5) - int length = 0; - int numBytes = 0; - - // Open a stream - bis = new Base64.InputStream( - new java.io.BufferedInputStream( - new java.io.FileInputStream( file ) ), Base64.ENCODE ); - - // Read until done - while( ( numBytes = bis.read( buffer, length, 4096 ) ) >= 0 ) { - length += numBytes; - } // end while - - // Save in a variable to return - encodedData = new String( buffer, 0, length, StandardCharsets.US_ASCII ); - - } // end try - // end catch: java.io.IOException - finally { - try{ - assert bis != null; - bis.close(); - } catch(Exception ignored) {} - } // end finally - - return encodedData; - } // end encodeFromFile - - /** - * Reads infile and encodes it to outfile. - * - * @param infile Input file - * @param outfile Output file - * @throws java.io.IOException if there is an error - * @since 2.2 - */ - public static void encodeFileToFile( String infile, String outfile ) - throws java.io.IOException { - - String encoded = Base64.encodeFromFile( infile ); - try (java.io.OutputStream out = new java.io.BufferedOutputStream( - new java.io.FileOutputStream(outfile))) { - out.write(encoded.getBytes(StandardCharsets.US_ASCII)); // Strict, 7-bit output. - } - } // end encodeFileToFile - - - /** - * Reads infile and decodes it to outfile. - * - * @param infile Input file - * @param outfile Output file - * @throws java.io.IOException if there is an error - * @since 2.2 - */ - public static void decodeFileToFile( String infile, String outfile ) - throws java.io.IOException { - - byte[] decoded = Base64.decodeFromFile( infile ); - try (java.io.OutputStream out = new java.io.BufferedOutputStream( - new java.io.FileOutputStream(outfile))) { - out.write(decoded); - } - } // end decodeFileToFile - - - /* ******** I N N E R C L A S S I N P U T S T R E A M ******** */ - - - - /** - * A {@link Base64.InputStream} will read data from another - * java.io.InputStream, given in the constructor, - * and encode/decode to/from Base64 notation on the fly. - * - * @see Base64 - * @since 1.3 - */ - public static class InputStream extends java.io.FilterInputStream { - - private boolean encode; // Encoding or decoding - private int position; // Current position in the buffer - private byte[] buffer; // Small buffer holding converted data - private int bufferLength; // Length of buffer (3 or 4) - private int numSigBytes; // Number of meaningful bytes in the buffer - private int lineLength; - private boolean breakLines; // Break lines at less than 80 characters - private int options; // Record options used to create the stream. - private byte[] decodabet; // Local copies to avoid extra method calls - - - /** - * Constructs a {@link Base64.InputStream} in DECODE mode. - * - * @param in the java.io.InputStream from which to read data. - * @since 1.3 - */ - public InputStream( java.io.InputStream in ) { - this( in, DECODE ); - } // end constructor - - - /** - * Constructs a {@link Base64.InputStream} in - * either ENCODE or DECODE mode. - *

- * Valid options:

-         *   ENCODE or DECODE: Encode or Decode as data is read.
-         *   DO_BREAK_LINES: break lines at 76 characters
-         *     (only meaningful when encoding)
-         * 
- *

- * Example: new Base64.InputStream( in, Base64.DECODE ) - * - * - * @param in the java.io.InputStream from which to read data. - * @param options Specified options - * @see Base64#ENCODE - * @see Base64#DECODE - * @see Base64#DO_BREAK_LINES - * @since 2.0 - */ - public InputStream( java.io.InputStream in, int options ) { - - super( in ); - this.options = options; // Record for later - this.breakLines = (options & DO_BREAK_LINES) > 0; - this.encode = (options & ENCODE) > 0; - this.bufferLength = encode ? 4 : 3; - this.buffer = new byte[ bufferLength ]; - this.position = -1; - this.lineLength = 0; - this.decodabet = getDecodabet(options); - } // end constructor - - /** - * Reads enough of the input stream to convert - * to/from Base64 and returns the next byte. - * - * @return next byte - * @since 1.3 - */ - @Override - public int read() throws java.io.IOException { - - // Do we need to get data? - if( position < 0 ) { - if( encode ) { - byte[] b3 = new byte[3]; - int numBinaryBytes = 0; - for( int i = 0; i < 3; i++ ) { - int b = in.read(); - - // If end of stream, b is -1. - if( b >= 0 ) { - b3[i] = (byte)b; - numBinaryBytes++; - } else { - break; // out of for loop - } // end else: end of stream - - } // end for: each needed input byte - - if( numBinaryBytes > 0 ) { - encode3to4( b3, 0, numBinaryBytes, buffer, 0, options ); - position = 0; - numSigBytes = 4; - } // end if: got data - else { - return -1; // Must be end of stream - } // end else - } // end if: encoding - - // Else decoding - else { - byte[] b4 = new byte[4]; - int i = 0; - for( i = 0; i < 4; i++ ) { - // Read four "meaningful" bytes: - int b = 0; - do{ b = in.read(); } - while( b >= 0 && decodabet[ b & 0x7f ] <= WHITE_SPACE_ENC ); - - if( b < 0 ) { - break; // Reads a -1 if end of stream - } // end if: end of stream - - b4[i] = (byte)b; - } // end for: each needed input byte - - if( i == 4 ) { - numSigBytes = decode4to3( b4, 0, buffer, 0, options ); - position = 0; - } // end if: got four characters - else if( i == 0 ){ - return -1; - } // end else if: also padded correctly - else { - // Must have broken out from above. - throw new java.io.IOException( "Improperly padded Base64 input." ); - } // end - - } // end else: decode - } // end else: get data - - // Got data? - if( position >= 0 ) { - // End of relevant data? - if( /*!encode &&*/ position >= numSigBytes ){ - return -1; - } // end if: got data - - if( encode && breakLines && lineLength >= MAX_LINE_LENGTH ) { - lineLength = 0; - return '\n'; - } // end if - else { - lineLength++; // This isn't important when decoding - // but throwing an extra "if" seems - // just as wasteful. - - int b = buffer[ position++ ]; - - if( position >= bufferLength ) { - position = -1; - } // end if: end - - return b & 0xFF; // This is how you "cast" a byte that's - // intended to be unsigned. - } // end else - } // end if: position >= 0 - - // Else error - else { - throw new java.io.IOException( "Error in Base64 code reading stream." ); - } // end else - } // end read - - - /** - * Calls {@link #read()} repeatedly until the end of stream - * is reached or len bytes are read. - * Returns number of bytes read into array or -1 if - * end of stream is encountered. - * - * @param dest array to hold values - * @param off offset for array - * @param len max number of bytes to read into array - * @return bytes read into array or -1 if end of stream is encountered. - * @since 1.3 - */ - @Override - public int read( byte[] dest, int off, int len ) - throws java.io.IOException { - int i; - int b; - for( i = 0; i < len; i++ ) { - b = read(); - - if( b >= 0 ) { - dest[off + i] = (byte) b; - } - else if( i == 0 ) { - return -1; - } - else { - break; // Out of 'for' loop - } // Out of 'for' loop - } // end for: each byte read - return i; - } // end read - - } // end inner class InputStream - - - - - - - /* ******** I N N E R C L A S S O U T P U T S T R E A M ******** */ - - - - /** - * A {@link Base64.OutputStream} will write data to another - * java.io.OutputStream, given in the constructor, - * and encode/decode to/from Base64 notation on the fly. - * - * @see Base64 - * @since 1.3 - */ - public static class OutputStream extends java.io.FilterOutputStream { - - private boolean encode; - private int position; - private byte[] buffer; - private int bufferLength; - private int lineLength; - private boolean breakLines; - private byte[] b4; // Scratch used in a few places - private boolean suspendEncoding; - private int options; // Record for later - private byte[] decodabet; // Local copies to avoid extra method calls - - /** - * Constructs a {@link Base64.OutputStream} in ENCODE mode. - * - * @param out the java.io.OutputStream to which data will be written. - * @since 1.3 - */ - public OutputStream( java.io.OutputStream out ) { - this( out, ENCODE ); - } // end constructor - - - /** - * Constructs a {@link Base64.OutputStream} in - * either ENCODE or DECODE mode. - *

- * Valid options:

-         *   ENCODE or DECODE: Encode or Decode as data is read.
-         *   DO_BREAK_LINES: don't break lines at 76 characters
-         *     (only meaningful when encoding)
-         * 
- *

- * Example: new Base64.OutputStream( out, Base64.ENCODE ) - * - * @param out the java.io.OutputStream to which data will be written. - * @param options Specified options. - * @see Base64#ENCODE - * @see Base64#DECODE - * @see Base64#DO_BREAK_LINES - * @since 1.3 - */ - public OutputStream( java.io.OutputStream out, int options ) { - super( out ); - this.breakLines = (options & DO_BREAK_LINES) != 0; - this.encode = (options & ENCODE) != 0; - this.bufferLength = encode ? 3 : 4; - this.buffer = new byte[ bufferLength ]; - this.position = 0; - this.lineLength = 0; - this.suspendEncoding = false; - this.b4 = new byte[4]; - this.options = options; - this.decodabet = getDecodabet(options); - } // end constructor - - - /** - * Writes the byte to the output stream after - * converting to/from Base64 notation. - * When encoding, bytes are buffered three - * at a time before the output stream actually - * gets a write() call. - * When decoding, bytes are buffered four - * at a time. - * - * @param theByte the byte to write - * @since 1.3 - */ - @Override - public void write(int theByte) - throws java.io.IOException { - // Encoding suspended? - if( suspendEncoding ) { - this.out.write( theByte ); - return; - } // end if: supsended - - // Encode? - if( encode ) { - buffer[ position++ ] = (byte)theByte; - if( position >= bufferLength ) { // Enough to encode. - - this.out.write( encode3to4( b4, buffer, bufferLength, options ) ); - - lineLength += 4; - if( breakLines && lineLength >= MAX_LINE_LENGTH ) { - this.out.write( NEW_LINE ); - lineLength = 0; - } // end if: end of line - - position = 0; - } // end if: enough to output - } // end if: encoding - - // Else, Decoding - else { - // Meaningful Base64 character? - if( decodabet[ theByte & 0x7f ] > WHITE_SPACE_ENC ) { - buffer[ position++ ] = (byte)theByte; - if( position >= bufferLength ) { // Enough to output. - - int len = Base64.decode4to3( buffer, 0, b4, 0, options ); - out.write( b4, 0, len ); - position = 0; - } // end if: enough to output - } // end if: meaningful base64 character - else if( decodabet[ theByte & 0x7f ] != WHITE_SPACE_ENC ) { - throw new java.io.IOException( "Invalid character in Base64 data." ); - } // end else: not white space either - } // end else: decoding - } // end write - - - - /** - * Calls {@link #write(int)} repeatedly until len - * bytes are written. - * - * @param theBytes array from which to read bytes - * @param off offset for array - * @param len max number of bytes to read into array - * @since 1.3 - */ - @Override - public void write( byte[] theBytes, int off, int len ) - throws java.io.IOException { - // Encoding suspended? - if( suspendEncoding ) { - this.out.write( theBytes, off, len ); - return; - } // end if: supsended - - for( int i = 0; i < len; i++ ) { - write( theBytes[ off + i ] ); - } // end for: each byte written - - } // end write - - - - /** - * Method added by PHIL. [Thanks, PHIL. -Rob] - * This pads the buffer without closing the stream. - * @throws java.io.IOException if there's an error. - */ - public void flushBase64() throws java.io.IOException { - if( position > 0 ) { - if( encode ) { - out.write( encode3to4( b4, buffer, position, options ) ); - position = 0; - } // end if: encoding - else { - throw new java.io.IOException( "Base64 input not properly padded." ); - } // end else: decoding - } // end if: buffer partially full - - } // end flush - - - /** - * Flushes and closes (I think, in the superclass) the stream. - * - * @since 1.3 - */ - @Override - public void close() throws java.io.IOException { - // 1. Ensure that pending characters are written - flushBase64(); - - // 2. Actually close the stream - // Base class both flushes and closes. - super.close(); - - buffer = null; - out = null; - } // end close - - - - /** - * Suspends encoding of the stream. - * May be helpful if you need to embed a piece of - * base64-encoded data in a stream. - * - * @throws java.io.IOException if there's an error flushing - * @since 1.5.1 - */ - public void suspendEncoding() throws java.io.IOException { - flushBase64(); - this.suspendEncoding = true; - } // end suspendEncoding - - - /** - * Resumes encoding of the stream. - * May be helpful if you need to embed a piece of - * base64-encoded data in a stream. - * - * @since 1.5.1 - */ - public void resumeEncoding() { - this.suspendEncoding = false; - } // end resumeEncoding - - - - } // end inner class OutputStream - - -} // end class Base64 diff --git a/src/main/java/xades4j/xml/bind/Base64XmlAdapter.java b/src/main/java/xades4j/xml/bind/Base64XmlAdapter.java index 0fb06fc1..6ecd6efb 100644 --- a/src/main/java/xades4j/xml/bind/Base64XmlAdapter.java +++ b/src/main/java/xades4j/xml/bind/Base64XmlAdapter.java @@ -8,22 +8,25 @@ package xades4j.xml.bind; -import java.io.IOException; import jakarta.xml.bind.annotation.adapters.XmlAdapter; +import java.util.Base64; + public class Base64XmlAdapter extends XmlAdapter { @Override - public byte[] unmarshal(String value) throws Exception { - return (xades4j.utils.Base64.decode(value)); + public byte[] unmarshal(String value) { + return Base64.getMimeDecoder().decode(value); } @Override - public String marshal(byte[] value) throws IOException { - return (xades4j.utils.Base64.encodeBytes(value, xades4j.utils.Base64.DO_BREAK_LINES)); + public String marshal(byte[] value) { + + return Base64.getMimeEncoder().encodeToString(value); + } } From 73f475f12f6149f0e7c3b53ac58b718fb34aabb9 Mon Sep 17 00:00:00 2001 From: Mirko Date: Mon, 13 Nov 2023 21:00:25 +0100 Subject: [PATCH 07/14] optimize imports --- .../DefaultProductionBindingsModule.java | 32 +++++++++++++-- .../PropertiesDataGenerationContext.java | 6 ++- .../SignedDataObjectsProcessor.java | 14 ++++++- .../java/xades4j/production/SignerBES.java | 22 +++++++++-- src/main/java/xades4j/production/SignerC.java | 9 ++++- .../java/xades4j/production/SignerEPES.java | 7 +++- src/main/java/xades4j/production/SignerT.java | 7 +++- ...ropertiesDataObjectsStructureVerifier.java | 9 ++++- .../impl/AbstractTimeStampTokenProvider.java | 7 +++- .../impl/DefaultMessageDigestProvider.java | 5 +-- .../DefaultSignaturePropertiesProvider.java | 3 +- .../DefaultTimeStampVerificationProvider.java | 16 +++++++- .../impl/KeyStoreKeyingDataProvider.java | 12 +++++- .../PKIXCertificateValidationProvider.java | 34 ++++++++++++++-- ...idationDataFromCertValidationProvider.java | 8 +++- .../java/xades4j/utils/CollectionUtils.java | 7 +++- .../java/xades4j/utils/DataGetterImpl.java | 7 +++- .../utils/FileSystemDirectoryCertStore.java | 6 ++- .../java/xades4j/utils/PropertiesSet.java | 8 +++- .../java/xades4j/utils/XadesProfileCore.java | 5 ++- .../DefaultVerificationBindingsModule.java | 16 +++++++- ...QualifyingPropertyVerificationContext.java | 6 ++- ...QualifyingPropertyVerifiersMapperImpl.java | 6 ++- .../verification/XAdESFormChecker.java | 10 ++++- .../verification/XAdESVerificationResult.java | 9 ++++- .../verification/XadesVerifierImpl.java | 6 ++- .../xml/bind/xmldsig/XmlReferenceType.java | 1 - .../xml/bind/xmldsig/XmlSignatureType.java | 7 ++-- .../xml/bind/xmldsig/XmlSignedInfoType.java | 6 +-- .../ToXmlSignaturePolicyConverter.java | 7 +++- .../AlgorithmParametersBindingsModule.java | 10 ++++- .../algorithms/XPath2FilterTransformTest.java | 23 ++++++----- .../production/KeyInfoBuilderTest.java | 4 +- .../SignedDataObjectsProcessorTest.java | 13 ++++++- .../xades4j/production/SignerBESTest.java | 8 +++- .../production/SignerSpecificTest.java | 2 +- .../production/UncheckedSignerBESTest.java | 6 ++- .../XadesSignatureFormatExtenderImplTest.java | 6 ++- .../DataObjectFormatPropertyTest.java | 5 ++- .../PKCS11KeyStoreKeyingDataProviderTest.java | 4 +- .../java/xades4j/utils/PropertiesBagTest.java | 7 +++- .../utils/SignatureServicesTestBase.java | 39 ++++++++----------- .../xades4j/utils/XadesProfileCoreTest.java | 5 ++- .../verification/XadesVerifierImplTest.java | 19 ++++++++- ...ParametersMarshallingProviderImplTest.java | 11 +++++- ...h2FilterTransformParamsMarshallerTest.java | 4 +- .../XPathTransformParamsMarshallerTest.java | 4 +- 47 files changed, 368 insertions(+), 100 deletions(-) diff --git a/src/main/java/xades4j/production/DefaultProductionBindingsModule.java b/src/main/java/xades4j/production/DefaultProductionBindingsModule.java index 5dbbf159..06c660b3 100644 --- a/src/main/java/xades4j/production/DefaultProductionBindingsModule.java +++ b/src/main/java/xades4j/production/DefaultProductionBindingsModule.java @@ -19,10 +19,36 @@ import com.google.inject.AbstractModule; import com.google.inject.TypeLiteral; import com.google.inject.multibindings.Multibinder; -import xades4j.properties.*; +import xades4j.properties.AllDataObjsCommitmentTypeProperty; +import xades4j.properties.AllDataObjsTimeStampProperty; +import xades4j.properties.ArchiveTimeStampProperty; +import xades4j.properties.CertificateValuesProperty; +import xades4j.properties.CommitmentTypeProperty; +import xades4j.properties.CompleteCertificateRefsProperty; +import xades4j.properties.CompleteRevocationRefsProperty; +import xades4j.properties.CounterSignatureProperty; +import xades4j.properties.DataObjectFormatProperty; +import xades4j.properties.IndividualDataObjsTimeStampProperty; +import xades4j.properties.RevocationValuesProperty; +import xades4j.properties.SigAndRefsTimeStampProperty; +import xades4j.properties.SignaturePolicyIdentifierProperty; +import xades4j.properties.SignaturePolicyImpliedProperty; +import xades4j.properties.SignatureProductionPlaceProperty; +import xades4j.properties.SignatureTimeStampProperty; +import xades4j.properties.SignerRoleProperty; +import xades4j.properties.SigningCertificateProperty; +import xades4j.properties.SigningTimeProperty; import xades4j.properties.data.CustomPropertiesDataObjsStructureVerifier; -import xades4j.providers.*; -import xades4j.providers.impl.*; +import xades4j.providers.DataObjectPropertiesProvider; +import xades4j.providers.MessageDigestEngineProvider; +import xades4j.providers.SignaturePropertiesProvider; +import xades4j.providers.TimeStampTokenProvider; +import xades4j.providers.X500NameStyleProvider; +import xades4j.providers.impl.DefaultMessageDigestProvider; +import xades4j.providers.impl.DefaultSignaturePropertiesProvider; +import xades4j.providers.impl.DefaultX500NameStyleProvider; +import xades4j.providers.impl.HttpTimeStampTokenProvider; +import xades4j.providers.impl.HttpTsaConfiguration; /** * Contains the Guice bindings for the default components and the bindings for the diff --git a/src/main/java/xades4j/production/PropertiesDataGenerationContext.java b/src/main/java/xades4j/production/PropertiesDataGenerationContext.java index 0b84f96f..7af3c528 100644 --- a/src/main/java/xades4j/production/PropertiesDataGenerationContext.java +++ b/src/main/java/xades4j/production/PropertiesDataGenerationContext.java @@ -26,7 +26,11 @@ import xades4j.properties.DataObjectDesc; import xades4j.utils.DOMHelper; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; /** * Context used during the generation of the properties low-level data (property diff --git a/src/main/java/xades4j/production/SignedDataObjectsProcessor.java b/src/main/java/xades4j/production/SignedDataObjectsProcessor.java index 6d034e79..eb0f5834 100644 --- a/src/main/java/xades4j/production/SignedDataObjectsProcessor.java +++ b/src/main/java/xades4j/production/SignedDataObjectsProcessor.java @@ -17,7 +17,11 @@ package xades4j.production; import jakarta.inject.Inject; -import org.apache.xml.security.signature.*; +import org.apache.xml.security.signature.Manifest; +import org.apache.xml.security.signature.ObjectContainer; +import org.apache.xml.security.signature.Reference; +import org.apache.xml.security.signature.XMLSignature; +import org.apache.xml.security.signature.XMLSignatureException; import org.apache.xml.security.transforms.Transforms; import org.apache.xml.security.utils.resolver.ResourceResolverSpi; import org.w3c.dom.Document; @@ -28,7 +32,13 @@ import xades4j.utils.TransformUtils; import xades4j.xml.marshalling.algorithms.AlgorithmsParametersMarshallingProvider; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * Helper class that processes a set of data object descriptions. diff --git a/src/main/java/xades4j/production/SignerBES.java b/src/main/java/xades4j/production/SignerBES.java index 791754d3..0b746f86 100644 --- a/src/main/java/xades4j/production/SignerBES.java +++ b/src/main/java/xades4j/production/SignerBES.java @@ -33,10 +33,22 @@ import xades4j.XAdES4jException; import xades4j.XAdES4jXMLSigException; import xades4j.algorithms.Algorithm; -import xades4j.properties.*; +import xades4j.properties.QualifyingProperties; +import xades4j.properties.QualifyingProperty; +import xades4j.properties.SignedSignatureProperty; +import xades4j.properties.SigningCertificateProperty; +import xades4j.properties.UnsignedSignatureProperty; import xades4j.properties.data.SigAndDataObjsPropertiesData; -import xades4j.providers.*; -import xades4j.utils.*; +import xades4j.providers.DataObjectPropertiesProvider; +import xades4j.providers.KeyingDataProvider; +import xades4j.providers.SignaturePropertiesProvider; +import xades4j.providers.SigningCertChainException; +import xades4j.providers.ValidationDataException; +import xades4j.providers.X500NameStyleProvider; +import xades4j.utils.DOMHelper; +import xades4j.utils.ObjectUtils; +import xades4j.utils.StringUtils; +import xades4j.utils.TransformUtils; import xades4j.xml.marshalling.SignedPropertiesMarshaller; import xades4j.xml.marshalling.UnsignedPropertiesMarshaller; import xades4j.xml.marshalling.algorithms.AlgorithmsParametersMarshallingProvider; @@ -48,6 +60,8 @@ import java.util.List; import java.util.UUID; +import static xades4j.utils.CanonicalizerUtils.checkC14NAlgorithm; + /** * Base logic for producing XAdES signatures (XAdES-BES). * @author Luís @@ -238,7 +252,7 @@ public final XadesSignatureResult sign( try { - CanonicalizerUtils.checkC14NAlgorithm(canonAlg); + checkC14NAlgorithm(canonAlg); Transforms transforms = TransformUtils.createTransforms(canonAlg, this.algorithmsParametersMarshaller, signatureDocument); signature.addDocument('#' + signedPropsId, transforms, digestAlgUri, null, QualifyingProperty.SIGNED_PROPS_TYPE_URI); diff --git a/src/main/java/xades4j/production/SignerC.java b/src/main/java/xades4j/production/SignerC.java index 1796f001..b3328bef 100644 --- a/src/main/java/xades4j/production/SignerC.java +++ b/src/main/java/xades4j/production/SignerC.java @@ -19,7 +19,14 @@ import jakarta.inject.Inject; import xades4j.properties.SignedSignatureProperty; import xades4j.properties.UnsignedSignatureProperty; -import xades4j.providers.*; +import xades4j.providers.DataObjectPropertiesProvider; +import xades4j.providers.KeyingDataProvider; +import xades4j.providers.SignaturePolicyInfoProvider; +import xades4j.providers.SignaturePropertiesProvider; +import xades4j.providers.ValidationData; +import xades4j.providers.ValidationDataException; +import xades4j.providers.ValidationDataProvider; +import xades4j.providers.X500NameStyleProvider; import xades4j.utils.PropertiesUtils; import xades4j.xml.marshalling.SignedPropertiesMarshaller; import xades4j.xml.marshalling.UnsignedPropertiesMarshaller; diff --git a/src/main/java/xades4j/production/SignerEPES.java b/src/main/java/xades4j/production/SignerEPES.java index b3e85529..075edbff 100644 --- a/src/main/java/xades4j/production/SignerEPES.java +++ b/src/main/java/xades4j/production/SignerEPES.java @@ -19,7 +19,12 @@ import jakarta.inject.Inject; import xades4j.properties.SignedSignatureProperty; import xades4j.properties.UnsignedSignatureProperty; -import xades4j.providers.*; +import xades4j.providers.DataObjectPropertiesProvider; +import xades4j.providers.KeyingDataProvider; +import xades4j.providers.SignaturePolicyInfoProvider; +import xades4j.providers.SignaturePropertiesProvider; +import xades4j.providers.ValidationDataException; +import xades4j.providers.X500NameStyleProvider; import xades4j.utils.PropertiesUtils; import xades4j.xml.marshalling.SignedPropertiesMarshaller; import xades4j.xml.marshalling.UnsignedPropertiesMarshaller; diff --git a/src/main/java/xades4j/production/SignerT.java b/src/main/java/xades4j/production/SignerT.java index 4958659c..f810be41 100644 --- a/src/main/java/xades4j/production/SignerT.java +++ b/src/main/java/xades4j/production/SignerT.java @@ -19,7 +19,12 @@ import jakarta.inject.Inject; import xades4j.properties.SignedSignatureProperty; import xades4j.properties.UnsignedSignatureProperty; -import xades4j.providers.*; +import xades4j.providers.DataObjectPropertiesProvider; +import xades4j.providers.KeyingDataProvider; +import xades4j.providers.SignaturePolicyInfoProvider; +import xades4j.providers.SignaturePropertiesProvider; +import xades4j.providers.ValidationDataException; +import xades4j.providers.X500NameStyleProvider; import xades4j.utils.PropertiesUtils; import xades4j.xml.marshalling.SignedPropertiesMarshaller; import xades4j.xml.marshalling.UnsignedPropertiesMarshaller; diff --git a/src/main/java/xades4j/properties/data/PropertiesDataObjectsStructureVerifier.java b/src/main/java/xades4j/properties/data/PropertiesDataObjectsStructureVerifier.java index d9005d6b..fefd68aa 100644 --- a/src/main/java/xades4j/properties/data/PropertiesDataObjectsStructureVerifier.java +++ b/src/main/java/xades4j/properties/data/PropertiesDataObjectsStructureVerifier.java @@ -17,7 +17,14 @@ package xades4j.properties.data; import jakarta.inject.Inject; -import xades4j.properties.*; +import xades4j.properties.AllDataObjsTimeStampProperty; +import xades4j.properties.ArchiveTimeStampProperty; +import xades4j.properties.CertificateValuesProperty; +import xades4j.properties.CompleteCertificateRefsProperty; +import xades4j.properties.RevocationValuesProperty; +import xades4j.properties.SigAndRefsTimeStampProperty; +import xades4j.properties.SignatureTimeStampProperty; +import xades4j.properties.SigningCertificateProperty; import xades4j.utils.DataGetter; import xades4j.utils.DataGetterImpl; diff --git a/src/main/java/xades4j/providers/impl/AbstractTimeStampTokenProvider.java b/src/main/java/xades4j/providers/impl/AbstractTimeStampTokenProvider.java index 4db93049..dfdd90ec 100644 --- a/src/main/java/xades4j/providers/impl/AbstractTimeStampTokenProvider.java +++ b/src/main/java/xades4j/providers/impl/AbstractTimeStampTokenProvider.java @@ -20,7 +20,12 @@ import org.apache.xml.security.algorithms.MessageDigestAlgorithm; import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.cmp.PKIStatus; -import org.bouncycastle.tsp.*; +import org.bouncycastle.tsp.TSPAlgorithms; +import org.bouncycastle.tsp.TSPException; +import org.bouncycastle.tsp.TimeStampRequest; +import org.bouncycastle.tsp.TimeStampRequestGenerator; +import org.bouncycastle.tsp.TimeStampResponse; +import org.bouncycastle.tsp.TimeStampToken; import xades4j.UnsupportedAlgorithmException; import xades4j.providers.MessageDigestEngineProvider; import xades4j.providers.TimeStampTokenGenerationException; diff --git a/src/main/java/xades4j/providers/impl/DefaultMessageDigestProvider.java b/src/main/java/xades4j/providers/impl/DefaultMessageDigestProvider.java index f1b510d5..e5f15709 100644 --- a/src/main/java/xades4j/providers/impl/DefaultMessageDigestProvider.java +++ b/src/main/java/xades4j/providers/impl/DefaultMessageDigestProvider.java @@ -18,15 +18,14 @@ import org.apache.xml.security.Init; import org.apache.xml.security.algorithms.JCEMapper; -import xades4j.providers.*; +import xades4j.UnsupportedAlgorithmException; +import xades4j.providers.MessageDigestEngineProvider; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.Security; -import xades4j.UnsupportedAlgorithmException; - /** * The default implementation of {@code MessageDigestEngineProvider}. It supports * Apache Santuario available algorithms diff --git a/src/main/java/xades4j/providers/impl/DefaultSignaturePropertiesProvider.java b/src/main/java/xades4j/providers/impl/DefaultSignaturePropertiesProvider.java index fa1a1d77..2df2e1bb 100644 --- a/src/main/java/xades4j/providers/impl/DefaultSignaturePropertiesProvider.java +++ b/src/main/java/xades4j/providers/impl/DefaultSignaturePropertiesProvider.java @@ -16,8 +16,9 @@ */ package xades4j.providers.impl; -import xades4j.providers.*; import xades4j.properties.SigningTimeProperty; +import xades4j.providers.SignaturePropertiesCollector; +import xades4j.providers.SignaturePropertiesProvider; /** * The default implementation of {@link SignaturePropertiesProvider}. It provides diff --git a/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java b/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java index 71b858f2..ac248e05 100644 --- a/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java +++ b/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java @@ -33,14 +33,26 @@ import org.bouncycastle.util.Selector; import xades4j.UnsupportedAlgorithmException; import xades4j.XAdES4jException; -import xades4j.providers.*; +import xades4j.providers.CertificateValidationProvider; +import xades4j.providers.MessageDigestEngineProvider; +import xades4j.providers.TimeStampTokenDigestException; +import xades4j.providers.TimeStampTokenSignatureException; +import xades4j.providers.TimeStampTokenStructureException; +import xades4j.providers.TimeStampTokenTSACertException; +import xades4j.providers.TimeStampTokenVerificationException; +import xades4j.providers.TimeStampVerificationProvider; +import xades4j.providers.ValidationData; import java.io.IOException; import java.security.MessageDigest; import java.security.Provider; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; -import java.util.*; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; /** * Default implementation of {@code TimeStampVerificationProvider}. It verifies diff --git a/src/main/java/xades4j/providers/impl/KeyStoreKeyingDataProvider.java b/src/main/java/xades4j/providers/impl/KeyStoreKeyingDataProvider.java index 1fc954b3..99f56b4b 100644 --- a/src/main/java/xades4j/providers/impl/KeyStoreKeyingDataProvider.java +++ b/src/main/java/xades4j/providers/impl/KeyStoreKeyingDataProvider.java @@ -22,12 +22,20 @@ import xades4j.verification.UnexpectedJCAException; import javax.security.auth.callback.PasswordCallback; -import java.security.*; +import java.security.GeneralSecurityException; +import java.security.KeyStore; import java.security.KeyStore.Builder; import java.security.KeyStore.ProtectionParameter; +import java.security.KeyStoreException; +import java.security.PrivateKey; +import java.security.UnrecoverableKeyException; import java.security.cert.Certificate; import java.security.cert.X509Certificate; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; /** * A KeyStore-based implementation of {@code KeyingDataProvider}. The keystore is diff --git a/src/main/java/xades4j/providers/impl/PKIXCertificateValidationProvider.java b/src/main/java/xades4j/providers/impl/PKIXCertificateValidationProvider.java index 17fa625b..0ed145e5 100644 --- a/src/main/java/xades4j/providers/impl/PKIXCertificateValidationProvider.java +++ b/src/main/java/xades4j/providers/impl/PKIXCertificateValidationProvider.java @@ -16,13 +16,39 @@ */ package xades4j.providers.impl; -import xades4j.providers.*; +import xades4j.providers.CannotBuildCertificationPathException; +import xades4j.providers.CannotSelectCertificateException; +import xades4j.providers.CertificateValidationException; +import xades4j.providers.CertificateValidationProvider; +import xades4j.providers.ValidationData; import xades4j.verification.UnexpectedJCAException; import javax.security.auth.x500.X500Principal; -import java.security.*; -import java.security.cert.*; -import java.util.*; +import java.security.InvalidAlgorithmParameterException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.cert.CertPathBuilder; +import java.security.cert.CertPathBuilderException; +import java.security.cert.CertStore; +import java.security.cert.CertStoreException; +import java.security.cert.CollectionCertStoreParameters; +import java.security.cert.PKIXBuilderParameters; +import java.security.cert.PKIXCertPathBuilderResult; +import java.security.cert.X509CRL; +import java.security.cert.X509CRLSelector; +import java.security.cert.X509CertSelector; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * Implementation of {@code CertificateValidationProvider} using a PKIX {@code CertPathBuilder}. diff --git a/src/main/java/xades4j/providers/impl/ValidationDataFromCertValidationProvider.java b/src/main/java/xades4j/providers/impl/ValidationDataFromCertValidationProvider.java index 68309a89..28229792 100644 --- a/src/main/java/xades4j/providers/impl/ValidationDataFromCertValidationProvider.java +++ b/src/main/java/xades4j/providers/impl/ValidationDataFromCertValidationProvider.java @@ -16,12 +16,16 @@ */ package xades4j.providers.impl; -import xades4j.providers.*; +import xades4j.XAdES4jException; +import xades4j.providers.CertificateValidationProvider; +import xades4j.providers.ValidationData; +import xades4j.providers.ValidationDataException; +import xades4j.providers.ValidationDataProvider; + import java.security.cert.X509CertSelector; import java.security.cert.X509Certificate; import java.util.Date; import java.util.List; -import xades4j.XAdES4jException; /** * An implementation of {@code ValidationDataProvider} that obtains the validation diff --git a/src/main/java/xades4j/utils/CollectionUtils.java b/src/main/java/xades4j/utils/CollectionUtils.java index ba16eba4..6cc6b6d2 100644 --- a/src/main/java/xades4j/utils/CollectionUtils.java +++ b/src/main/java/xades4j/utils/CollectionUtils.java @@ -16,7 +16,12 @@ */ package xades4j.utils; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * Provides some utility methods over collections. diff --git a/src/main/java/xades4j/utils/DataGetterImpl.java b/src/main/java/xades4j/utils/DataGetterImpl.java index b99fdde3..7708ce4b 100644 --- a/src/main/java/xades4j/utils/DataGetterImpl.java +++ b/src/main/java/xades4j/utils/DataGetterImpl.java @@ -18,7 +18,12 @@ import xades4j.utils.CollectionUtils.Predicate; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; /** * diff --git a/src/main/java/xades4j/utils/FileSystemDirectoryCertStore.java b/src/main/java/xades4j/utils/FileSystemDirectoryCertStore.java index e2370a23..c78ec5e0 100644 --- a/src/main/java/xades4j/utils/FileSystemDirectoryCertStore.java +++ b/src/main/java/xades4j/utils/FileSystemDirectoryCertStore.java @@ -22,7 +22,11 @@ import java.security.InvalidAlgorithmParameterException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; -import java.security.cert.*; +import java.security.cert.CRLException; +import java.security.cert.CertStore; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.security.cert.CollectionCertStoreParameters; import java.util.ArrayList; import java.util.Collection; diff --git a/src/main/java/xades4j/utils/PropertiesSet.java b/src/main/java/xades4j/utils/PropertiesSet.java index 2d708e2e..959b87b8 100644 --- a/src/main/java/xades4j/utils/PropertiesSet.java +++ b/src/main/java/xades4j/utils/PropertiesSet.java @@ -18,7 +18,13 @@ import xades4j.properties.PropertyTargetException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; /** * A generic bag of properties used to store properties that apply to a specific diff --git a/src/main/java/xades4j/utils/XadesProfileCore.java b/src/main/java/xades4j/utils/XadesProfileCore.java index fee219c0..d1a4cbc8 100644 --- a/src/main/java/xades4j/utils/XadesProfileCore.java +++ b/src/main/java/xades4j/utils/XadesProfileCore.java @@ -16,8 +16,11 @@ */ package xades4j.utils; +import com.google.inject.Binder; +import com.google.inject.Guice; +import com.google.inject.Key; import com.google.inject.Module; -import com.google.inject.*; +import com.google.inject.TypeLiteral; import com.google.inject.multibindings.MapBinder; import com.google.inject.multibindings.Multibinder; import com.google.inject.multibindings.OptionalBinder; diff --git a/src/main/java/xades4j/verification/DefaultVerificationBindingsModule.java b/src/main/java/xades4j/verification/DefaultVerificationBindingsModule.java index 594ebc5c..6da9af2e 100644 --- a/src/main/java/xades4j/verification/DefaultVerificationBindingsModule.java +++ b/src/main/java/xades4j/verification/DefaultVerificationBindingsModule.java @@ -23,7 +23,21 @@ import com.google.inject.util.Types; import xades4j.properties.CounterSignatureProperty; import xades4j.properties.QualifyingProperty; -import xades4j.properties.data.*; +import xades4j.properties.data.AllDataObjsTimeStampData; +import xades4j.properties.data.CommitmentTypeData; +import xades4j.properties.data.CompleteCertificateRefsData; +import xades4j.properties.data.CompleteRevocationRefsData; +import xades4j.properties.data.CustomPropertiesDataObjsStructureVerifier; +import xades4j.properties.data.DataObjectFormatData; +import xades4j.properties.data.GenericDOMData; +import xades4j.properties.data.IndividualDataObjsTimeStampData; +import xades4j.properties.data.PropertyDataObject; +import xades4j.properties.data.SignaturePolicyData; +import xades4j.properties.data.SignatureProdPlaceData; +import xades4j.properties.data.SignatureTimeStampData; +import xades4j.properties.data.SignerRoleData; +import xades4j.properties.data.SigningCertificateData; +import xades4j.properties.data.SigningTimeData; import xades4j.providers.MessageDigestEngineProvider; import xades4j.providers.SignaturePolicyDocumentProvider; import xades4j.providers.TimeStampVerificationProvider; diff --git a/src/main/java/xades4j/verification/QualifyingPropertyVerificationContext.java b/src/main/java/xades4j/verification/QualifyingPropertyVerificationContext.java index ddd38ed9..9bd2a54a 100644 --- a/src/main/java/xades4j/verification/QualifyingPropertyVerificationContext.java +++ b/src/main/java/xades4j/verification/QualifyingPropertyVerificationContext.java @@ -33,7 +33,11 @@ import java.math.BigInteger; import java.security.cert.X509CRL; import java.security.cert.X509Certificate; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * The context available during the verification of the qualifying properties. diff --git a/src/main/java/xades4j/verification/QualifyingPropertyVerifiersMapperImpl.java b/src/main/java/xades4j/verification/QualifyingPropertyVerifiersMapperImpl.java index 8148fc21..bc3d3e36 100644 --- a/src/main/java/xades4j/verification/QualifyingPropertyVerifiersMapperImpl.java +++ b/src/main/java/xades4j/verification/QualifyingPropertyVerifiersMapperImpl.java @@ -16,7 +16,11 @@ */ package xades4j.verification; -import com.google.inject.*; +import com.google.inject.ConfigurationException; +import com.google.inject.Injector; +import com.google.inject.Key; +import com.google.inject.ProvisionException; +import com.google.inject.TypeLiteral; import com.google.inject.util.Types; import jakarta.inject.Inject; import xades4j.properties.data.PropertyDataObject; diff --git a/src/main/java/xades4j/verification/XAdESFormChecker.java b/src/main/java/xades4j/verification/XAdESFormChecker.java index 0e489ce1..ed68a21a 100644 --- a/src/main/java/xades4j/verification/XAdESFormChecker.java +++ b/src/main/java/xades4j/verification/XAdESFormChecker.java @@ -16,7 +16,15 @@ */ package xades4j.verification; -import xades4j.properties.*; +import xades4j.properties.ArchiveTimeStampProperty; +import xades4j.properties.CertificateValuesProperty; +import xades4j.properties.CompleteCertificateRefsProperty; +import xades4j.properties.CompleteRevocationRefsProperty; +import xades4j.properties.RevocationValuesProperty; +import xades4j.properties.SigAndRefsTimeStampProperty; +import xades4j.properties.SignaturePolicyBase; +import xades4j.properties.SignatureTimeStampProperty; +import xades4j.properties.SigningCertificateProperty; import java.util.Collection; import java.util.HashSet; diff --git a/src/main/java/xades4j/verification/XAdESVerificationResult.java b/src/main/java/xades4j/verification/XAdESVerificationResult.java index 1b3ddafa..10c2f6c7 100644 --- a/src/main/java/xades4j/verification/XAdESVerificationResult.java +++ b/src/main/java/xades4j/verification/XAdESVerificationResult.java @@ -17,7 +17,14 @@ package xades4j.verification; import org.apache.xml.security.signature.XMLSignature; -import xades4j.properties.*; +import xades4j.properties.QualifyingProperties; +import xades4j.properties.QualifyingProperty; +import xades4j.properties.SignedDataObjectProperty; +import xades4j.properties.SignedProperties; +import xades4j.properties.SignedSignatureProperty; +import xades4j.properties.UnsignedDataObjectProperty; +import xades4j.properties.UnsignedProperties; +import xades4j.properties.UnsignedSignatureProperty; import xades4j.providers.ValidationData; import xades4j.utils.CollectionUtils; import xades4j.utils.DataGetter; diff --git a/src/main/java/xades4j/verification/XadesVerifierImpl.java b/src/main/java/xades4j/verification/XadesVerifierImpl.java index 2b52c1f9..a5c9225f 100644 --- a/src/main/java/xades4j/verification/XadesVerifierImpl.java +++ b/src/main/java/xades4j/verification/XadesVerifierImpl.java @@ -51,7 +51,11 @@ import java.io.InputStream; import java.security.cert.X509Certificate; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Set; /** * diff --git a/src/main/java/xades4j/xml/bind/xmldsig/XmlReferenceType.java b/src/main/java/xades4j/xml/bind/xmldsig/XmlReferenceType.java index d8f37849..67eb420a 100644 --- a/src/main/java/xades4j/xml/bind/xmldsig/XmlReferenceType.java +++ b/src/main/java/xades4j/xml/bind/xmldsig/XmlReferenceType.java @@ -8,7 +8,6 @@ package xades4j.xml.bind.xmldsig; -import xades4j.xml.bind.xmldsig.XmlDigestMethodType; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlAttribute; diff --git a/src/main/java/xades4j/xml/bind/xmldsig/XmlSignatureType.java b/src/main/java/xades4j/xml/bind/xmldsig/XmlSignatureType.java index a4feec94..d333a3d4 100644 --- a/src/main/java/xades4j/xml/bind/xmldsig/XmlSignatureType.java +++ b/src/main/java/xades4j/xml/bind/xmldsig/XmlSignatureType.java @@ -8,10 +8,6 @@ package xades4j.xml.bind.xmldsig; -import xades4j.xml.bind.xmldsig.XmlKeyInfoType; -import xades4j.xml.bind.xmldsig.XmlObjectType; -import java.util.ArrayList; -import java.util.List; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlAttribute; @@ -22,6 +18,9 @@ import jakarta.xml.bind.annotation.adapters.CollapsedStringAdapter; import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.ArrayList; +import java.util.List; + /** *

Java class for SignatureType complex type. diff --git a/src/main/java/xades4j/xml/bind/xmldsig/XmlSignedInfoType.java b/src/main/java/xades4j/xml/bind/xmldsig/XmlSignedInfoType.java index 0e1238b1..25fc1a93 100644 --- a/src/main/java/xades4j/xml/bind/xmldsig/XmlSignedInfoType.java +++ b/src/main/java/xades4j/xml/bind/xmldsig/XmlSignedInfoType.java @@ -8,9 +8,6 @@ package xades4j.xml.bind.xmldsig; -import xades4j.xml.bind.xmldsig.XmlCanonicalizationMethodType; -import java.util.ArrayList; -import java.util.List; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlAttribute; @@ -21,6 +18,9 @@ import jakarta.xml.bind.annotation.adapters.CollapsedStringAdapter; import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.ArrayList; +import java.util.List; + /** *

Java class for SignedInfoType complex type. diff --git a/src/main/java/xades4j/xml/marshalling/ToXmlSignaturePolicyConverter.java b/src/main/java/xades4j/xml/marshalling/ToXmlSignaturePolicyConverter.java index 55c53dac..908b61b6 100644 --- a/src/main/java/xades4j/xml/marshalling/ToXmlSignaturePolicyConverter.java +++ b/src/main/java/xades4j/xml/marshalling/ToXmlSignaturePolicyConverter.java @@ -21,7 +21,12 @@ import xades4j.properties.QualifyingProperty; import xades4j.properties.data.PropertyDataObject; import xades4j.properties.data.SignaturePolicyData; -import xades4j.xml.bind.xades.*; +import xades4j.xml.bind.xades.XmlAnyType; +import xades4j.xml.bind.xades.XmlDigestAlgAndValueType; +import xades4j.xml.bind.xades.XmlSigPolicyQualifiersListType; +import xades4j.xml.bind.xades.XmlSignaturePolicyIdType; +import xades4j.xml.bind.xades.XmlSignaturePolicyIdentifierType; +import xades4j.xml.bind.xades.XmlSignedPropertiesType; import xades4j.xml.bind.xmldsig.XmlDigestMethodType; import javax.xml.namespace.QName; diff --git a/src/main/java/xades4j/xml/marshalling/algorithms/AlgorithmParametersBindingsModule.java b/src/main/java/xades4j/xml/marshalling/algorithms/AlgorithmParametersBindingsModule.java index a71115b4..09511a95 100644 --- a/src/main/java/xades4j/xml/marshalling/algorithms/AlgorithmParametersBindingsModule.java +++ b/src/main/java/xades4j/xml/marshalling/algorithms/AlgorithmParametersBindingsModule.java @@ -19,7 +19,15 @@ import com.google.inject.AbstractModule; import com.google.inject.TypeLiteral; import com.google.inject.multibindings.MapBinder; -import xades4j.algorithms.*; +import xades4j.algorithms.Algorithm; +import xades4j.algorithms.CanonicalXMLWithComments; +import xades4j.algorithms.CanonicalXMLWithoutComments; +import xades4j.algorithms.EnvelopedSignatureTransform; +import xades4j.algorithms.ExclusiveCanonicalXMLWithComments; +import xades4j.algorithms.ExclusiveCanonicalXMLWithoutComments; +import xades4j.algorithms.GenericAlgorithm; +import xades4j.algorithms.XPath2FilterTransform; +import xades4j.algorithms.XPathTransform; import javax.annotation.Nullable; diff --git a/src/test/java/xades4j/algorithms/XPath2FilterTransformTest.java b/src/test/java/xades4j/algorithms/XPath2FilterTransformTest.java index d5eb41b9..8670948a 100644 --- a/src/test/java/xades4j/algorithms/XPath2FilterTransformTest.java +++ b/src/test/java/xades4j/algorithms/XPath2FilterTransformTest.java @@ -21,13 +21,25 @@ import java.util.List; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; + /** * @author Luís */ class XPath2FilterTransformTest { + @Test + void testChangeFiltersListFails() + { + XPath2FilterTransform t = XPath2Filter.intersect("1").union("2"); + assertThrows(UnsupportedOperationException.class, () -> { + t.getFilters().clear(); + }); + } + @Test void testCreation() { @@ -53,13 +65,4 @@ void testCreation() assertEquals("3", f.getXPath()); assertEquals("subtract", f.getFilterType()); } - - @Test - void testChangeFiltersListFails() - { - XPath2FilterTransform t = XPath2Filter.intersect("1").union("2"); - assertThrows(UnsupportedOperationException.class, () -> { - t.getFilters().clear(); - }); - } } diff --git a/src/test/java/xades4j/production/KeyInfoBuilderTest.java b/src/test/java/xades4j/production/KeyInfoBuilderTest.java index 2f27fbe4..7e7d91d2 100644 --- a/src/test/java/xades4j/production/KeyInfoBuilderTest.java +++ b/src/test/java/xades4j/production/KeyInfoBuilderTest.java @@ -33,7 +33,9 @@ import java.util.Arrays; import java.util.List; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Luís diff --git a/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java b/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java index 95b14583..679587cc 100644 --- a/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java +++ b/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java @@ -16,7 +16,12 @@ */ package xades4j.production; -import org.apache.xml.security.signature.*; +import org.apache.xml.security.signature.Manifest; +import org.apache.xml.security.signature.ObjectContainer; +import org.apache.xml.security.signature.Reference; +import org.apache.xml.security.signature.XMLSignature; +import org.apache.xml.security.signature.XMLSignatureInput; +import org.apache.xml.security.signature.XMLSignatureStreamInput; import org.apache.xml.security.utils.Constants; import org.apache.xml.security.utils.resolver.ResourceResolverContext; import org.apache.xml.security.utils.resolver.ResourceResolverSpi; @@ -30,7 +35,11 @@ import java.io.ByteArrayInputStream; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Luís diff --git a/src/test/java/xades4j/production/SignerBESTest.java b/src/test/java/xades4j/production/SignerBESTest.java index a4d2cf5f..293ad89f 100644 --- a/src/test/java/xades4j/production/SignerBESTest.java +++ b/src/test/java/xades4j/production/SignerBESTest.java @@ -25,7 +25,13 @@ import xades4j.algorithms.EnvelopedSignatureTransform; import xades4j.algorithms.XPath2FilterTransform.XPath2Filter; import xades4j.algorithms.XPathTransform; -import xades4j.properties.*; +import xades4j.properties.AllDataObjsCommitmentTypeProperty; +import xades4j.properties.CommitmentTypeProperty; +import xades4j.properties.CounterSignatureProperty; +import xades4j.properties.DataObjectDesc; +import xades4j.properties.DataObjectFormatProperty; +import xades4j.properties.IndividualDataObjsTimeStampProperty; +import xades4j.properties.SignerRoleProperty; import xades4j.providers.SignaturePropertiesCollector; import xades4j.providers.SignaturePropertiesProvider; diff --git a/src/test/java/xades4j/production/SignerSpecificTest.java b/src/test/java/xades4j/production/SignerSpecificTest.java index a2425458..50c63d30 100644 --- a/src/test/java/xades4j/production/SignerSpecificTest.java +++ b/src/test/java/xades4j/production/SignerSpecificTest.java @@ -100,7 +100,7 @@ void signWithNationalCertificate(ASN1Encodable commonName) throws Exception signer.sign(signDataObject, doc1.getDocumentElement()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); outputDOM(doc1, baos); - String str = new String(baos.toByteArray()); + String str = baos.toString(); //expected without parsing exception Document doc = parseDocument(new ByteArrayInputStream(baos.toByteArray())); } diff --git a/src/test/java/xades4j/production/UncheckedSignerBESTest.java b/src/test/java/xades4j/production/UncheckedSignerBESTest.java index 2fee96e7..c6f735ca 100644 --- a/src/test/java/xades4j/production/UncheckedSignerBESTest.java +++ b/src/test/java/xades4j/production/UncheckedSignerBESTest.java @@ -28,7 +28,11 @@ import xades4j.providers.KeyingDataProvider; import xades4j.providers.impl.PKIXCertificateValidationProvider; import xades4j.utils.FileSystemDirectoryCertStore; -import xades4j.verification.*; +import xades4j.verification.SignatureSpecificVerificationOptions; +import xades4j.verification.SigningCertificateKeyUsageException; +import xades4j.verification.XAdESForm; +import xades4j.verification.XAdESVerificationResult; +import xades4j.verification.XadesVerificationProfile; import java.io.FileInputStream; import java.security.KeyStore; diff --git a/src/test/java/xades4j/production/XadesSignatureFormatExtenderImplTest.java b/src/test/java/xades4j/production/XadesSignatureFormatExtenderImplTest.java index 33bf31e0..003ec92a 100644 --- a/src/test/java/xades4j/production/XadesSignatureFormatExtenderImplTest.java +++ b/src/test/java/xades4j/production/XadesSignatureFormatExtenderImplTest.java @@ -22,7 +22,11 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; -import xades4j.properties.*; +import xades4j.properties.ArchiveTimeStampProperty; +import xades4j.properties.CounterSignatureProperty; +import xades4j.properties.SignatureTimeStampProperty; +import xades4j.properties.UnsignedProperties; +import xades4j.properties.UnsignedSignatureProperty; import java.util.ArrayList; import java.util.Collection; diff --git a/src/test/java/xades4j/properties/DataObjectFormatPropertyTest.java b/src/test/java/xades4j/properties/DataObjectFormatPropertyTest.java index 66570a35..bd59289c 100644 --- a/src/test/java/xades4j/properties/DataObjectFormatPropertyTest.java +++ b/src/test/java/xades4j/properties/DataObjectFormatPropertyTest.java @@ -21,7 +21,10 @@ import java.util.ArrayList; import java.util.Collection; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Luís diff --git a/src/test/java/xades4j/providers/impl/PKCS11KeyStoreKeyingDataProviderTest.java b/src/test/java/xades4j/providers/impl/PKCS11KeyStoreKeyingDataProviderTest.java index edd6f9ac..301a3aa6 100644 --- a/src/test/java/xades4j/providers/impl/PKCS11KeyStoreKeyingDataProviderTest.java +++ b/src/test/java/xades4j/providers/impl/PKCS11KeyStoreKeyingDataProviderTest.java @@ -32,7 +32,9 @@ import java.util.List; import java.util.UUID; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Luís diff --git a/src/test/java/xades4j/utils/PropertiesBagTest.java b/src/test/java/xades4j/utils/PropertiesBagTest.java index 57cb8b60..25c31114 100644 --- a/src/test/java/xades4j/utils/PropertiesBagTest.java +++ b/src/test/java/xades4j/utils/PropertiesBagTest.java @@ -20,7 +20,9 @@ import xades4j.properties.DataObjectFormatProperty; import xades4j.properties.SigningTimeProperty; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Luís @@ -102,7 +104,8 @@ void testAdd() /** * Test of remove method, of class PropertiesSet. */ - public void testRemove() + @Test + void testRemove() { System.out.println("remove"); SigningTimeProperty prop1 = new SigningTimeProperty(); diff --git a/src/test/java/xades4j/utils/SignatureServicesTestBase.java b/src/test/java/xades4j/utils/SignatureServicesTestBase.java index f6c1a7b6..cabfa9e9 100644 --- a/src/test/java/xades4j/utils/SignatureServicesTestBase.java +++ b/src/test/java/xades4j/utils/SignatureServicesTestBase.java @@ -16,21 +16,22 @@ */ package xades4j.utils; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.io.OutputStream; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import xades4j.providers.impl.HttpTsaConfiguration; + import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import xades4j.providers.impl.HttpTsaConfiguration; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; /** * @author Luís @@ -39,7 +40,7 @@ public class SignatureServicesTestBase { static protected HttpTsaConfiguration DEFAULT_TEST_TSA = new HttpTsaConfiguration("http://tss.accv.es:8318/tsa"); - static private DocumentBuilder db; + static private final DocumentBuilder db; static { @@ -86,12 +87,9 @@ public static boolean onMacOs() public static Document getDocument(String fileName) throws Exception { String path = toPlatformSpecificXMLDirFilePath(fileName); - FileInputStream fis = new FileInputStream(path); - try { - return parseDocument(fis); - } finally { - fis.close(); - } + try (FileInputStream fis = new FileInputStream(path)) { + return parseDocument(fis); + } } public static Document parseDocument(InputStream is) throws Exception @@ -111,12 +109,9 @@ public static Document getNewDocument() throws Exception protected static void outputDocument(Document doc, String fileName) throws Exception { File outDir = ensureOutputDir(); - FileOutputStream out = new FileOutputStream(new File(outDir, fileName)); - try { - outputDOM(doc, out); - } finally { - out.close(); - } + try (FileOutputStream out = new FileOutputStream(new File(outDir, fileName))) { + outputDOM(doc, out); + } } diff --git a/src/test/java/xades4j/utils/XadesProfileCoreTest.java b/src/test/java/xades4j/utils/XadesProfileCoreTest.java index d44b216a..81b78a95 100644 --- a/src/test/java/xades4j/utils/XadesProfileCoreTest.java +++ b/src/test/java/xades4j/utils/XadesProfileCoreTest.java @@ -24,7 +24,10 @@ import java.util.Map; import java.util.Set; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /* Test classes/interfaces */ interface A diff --git a/src/test/java/xades4j/verification/XadesVerifierImplTest.java b/src/test/java/xades4j/verification/XadesVerifierImplTest.java index 3b0b4e51..18da2848 100644 --- a/src/test/java/xades4j/verification/XadesVerifierImplTest.java +++ b/src/test/java/xades4j/verification/XadesVerifierImplTest.java @@ -27,7 +27,19 @@ import xades4j.algorithms.CanonicalXMLWithoutComments; import xades4j.production.XadesFormatExtenderProfile; import xades4j.production.XadesSignatureFormatExtender; -import xades4j.properties.*; +import xades4j.properties.CertificateValuesProperty; +import xades4j.properties.CommitmentTypeProperty; +import xades4j.properties.CommitmentTypePropertyBase; +import xades4j.properties.CompleteCertificateRefsProperty; +import xades4j.properties.CounterSignatureProperty; +import xades4j.properties.DataObjectFormatProperty; +import xades4j.properties.IndividualDataObjsTimeStampProperty; +import xades4j.properties.QualifyingProperty; +import xades4j.properties.RevocationValuesProperty; +import xades4j.properties.SigAndRefsTimeStampProperty; +import xades4j.properties.SignatureTimeStampProperty; +import xades4j.properties.SigningCertificateProperty; +import xades4j.properties.SigningTimeProperty; import xades4j.providers.CannotBuildCertificationPathException; import java.io.File; @@ -37,7 +49,10 @@ import java.util.Date; import java.util.GregorianCalendar; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Luís diff --git a/src/test/java/xades4j/xml/marshalling/algorithms/AlgorithmsParametersMarshallingProviderImplTest.java b/src/test/java/xades4j/xml/marshalling/algorithms/AlgorithmsParametersMarshallingProviderImplTest.java index 5647e9da..1711568c 100644 --- a/src/test/java/xades4j/xml/marshalling/algorithms/AlgorithmsParametersMarshallingProviderImplTest.java +++ b/src/test/java/xades4j/xml/marshalling/algorithms/AlgorithmsParametersMarshallingProviderImplTest.java @@ -22,12 +22,19 @@ import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import org.w3c.dom.Node; -import xades4j.algorithms.*; +import xades4j.algorithms.Algorithm; +import xades4j.algorithms.CanonicalXMLWithoutComments; +import xades4j.algorithms.EnvelopedSignatureTransform; +import xades4j.algorithms.ExclusiveCanonicalXMLWithComments; +import xades4j.algorithms.GenericAlgorithm; +import xades4j.algorithms.XPathTransform; import xades4j.utils.SignatureServicesTestBase; import java.util.List; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; /** * diff --git a/src/test/java/xades4j/xml/marshalling/algorithms/XPath2FilterTransformParamsMarshallerTest.java b/src/test/java/xades4j/xml/marshalling/algorithms/XPath2FilterTransformParamsMarshallerTest.java index 7b2ab125..64258734 100644 --- a/src/test/java/xades4j/xml/marshalling/algorithms/XPath2FilterTransformParamsMarshallerTest.java +++ b/src/test/java/xades4j/xml/marshalling/algorithms/XPath2FilterTransformParamsMarshallerTest.java @@ -14,7 +14,9 @@ import java.util.Map; import java.util.Set; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * diff --git a/src/test/java/xades4j/xml/marshalling/algorithms/XPathTransformParamsMarshallerTest.java b/src/test/java/xades4j/xml/marshalling/algorithms/XPathTransformParamsMarshallerTest.java index e6255769..665b41f3 100644 --- a/src/test/java/xades4j/xml/marshalling/algorithms/XPathTransformParamsMarshallerTest.java +++ b/src/test/java/xades4j/xml/marshalling/algorithms/XPathTransformParamsMarshallerTest.java @@ -12,7 +12,9 @@ import java.util.List; import java.util.Map; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @author Luís From ed3faec51486d81c93a32e3fd7e886182f4beeaa Mon Sep 17 00:00:00 2001 From: Mirko Date: Mon, 13 Nov 2023 21:29:53 +0100 Subject: [PATCH 08/14] use lambdas in test classes --- .../algorithms/XPath2FilterTransformTest.java | 4 +- .../xades4j/production/PtCcSignerTests.java | 25 +++--------- .../SignedDataObjectsProcessorTest.java | 8 ++-- .../xades4j/production/SignerBESTest.java | 14 ++----- .../xades4j/production/SignerEPESTest.java | 16 ++------ .../java/xades4j/production/SignerTTest.java | 11 +----- .../production/UncheckedSignerBESTest.java | 12 ++---- .../properties/DataObjectDescTest.java | 4 +- .../DataObjectFormatPropertyTest.java | 4 +- ...aultTimeStampVerificationProviderTest.java | 8 +--- .../java/xades4j/utils/PropertiesBagTest.java | 16 ++------ .../utils/X500NameStyleProviderTest.java | 8 +--- .../xades4j/utils/XadesProfileCoreTest.java | 4 +- .../GenericDOMDataVerifierTest.java | 4 +- .../verification/OtherVerifierTests.java | 21 +++------- .../verification/VerifierTestBase.java | 27 +++++-------- .../verification/XAdESFormCheckerTest.java | 5 +-- .../verification/XadesVerifierErrorsTest.java | 38 +++++-------------- .../verification/XadesVerifierImplTest.java | 20 +++------- 19 files changed, 64 insertions(+), 185 deletions(-) diff --git a/src/test/java/xades4j/algorithms/XPath2FilterTransformTest.java b/src/test/java/xades4j/algorithms/XPath2FilterTransformTest.java index 8670948a..4a878e2d 100644 --- a/src/test/java/xades4j/algorithms/XPath2FilterTransformTest.java +++ b/src/test/java/xades4j/algorithms/XPath2FilterTransformTest.java @@ -35,9 +35,7 @@ class XPath2FilterTransformTest void testChangeFiltersListFails() { XPath2FilterTransform t = XPath2Filter.intersect("1").union("2"); - assertThrows(UnsupportedOperationException.class, () -> { - t.getFilters().clear(); - }); + assertThrows(UnsupportedOperationException.class, () -> t.getFilters().clear()); } @Test diff --git a/src/test/java/xades4j/production/PtCcSignerTests.java b/src/test/java/xades4j/production/PtCcSignerTests.java index 2c68df45..127fa083 100644 --- a/src/test/java/xades4j/production/PtCcSignerTests.java +++ b/src/test/java/xades4j/production/PtCcSignerTests.java @@ -10,7 +10,6 @@ import java.security.KeyStore; import java.security.cert.X509Certificate; -import java.util.List; class PtCcSignerTests extends SignerTestBase { @@ -51,28 +50,16 @@ private static class WindowsMyKeyingDataProvider extends KeyStoreKeyingDataProvi { public WindowsMyKeyingDataProvider() { - super(new KeyStoreBuilderCreator() - { - @Override - public KeyStore.Builder getBuilder(KeyStore.ProtectionParameter loadProtection) + super(loadProtection -> KeyStore.Builder.newInstance("Windows-MY", null, loadProtection), availableCertificates -> { + for (SigningCertificateSelector.Entry e : availableCertificates) { - return KeyStore.Builder.newInstance("Windows-MY", null, loadProtection); - } - }, new SigningCertificateSelector() - { - @Override - public Entry selectCertificate(List availableCertificates) - { - for (Entry e : availableCertificates) + if (e.getCertificate().getIssuerX500Principal().getName().contains("EC de Assinatura Digital")) { - if (e.getCertificate().getIssuerX500Principal().getName().contains("EC de Assinatura Digital")) - { - return e; - } + return e; } - - throw new RuntimeException("Cannot find PT CC certificate"); } + + throw new RuntimeException("Cannot find PT CC certificate"); }, new DirectPasswordProvider(""), null, true); } diff --git a/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java b/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java index 679587cc..bab47737 100644 --- a/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java +++ b/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java @@ -205,10 +205,8 @@ void testAddNullReference() throws Exception void testAddMultipleNullReferencesFails() throws Exception { SignedDataObjects dataObjsDescs = new SignedDataObjects(); - assertThrows(IllegalStateException.class, () -> { - dataObjsDescs - .withSignedDataObject(new AnonymousDataObjectReference("data1".getBytes())) - .withSignedDataObject(new AnonymousDataObjectReference("data2".getBytes())); - }); + assertThrows(IllegalStateException.class, () -> dataObjsDescs + .withSignedDataObject(new AnonymousDataObjectReference("data1".getBytes())) + .withSignedDataObject(new AnonymousDataObjectReference("data2".getBytes()))); } } diff --git a/src/test/java/xades4j/production/SignerBESTest.java b/src/test/java/xades4j/production/SignerBESTest.java index 293ad89f..997f97e0 100644 --- a/src/test/java/xades4j/production/SignerBESTest.java +++ b/src/test/java/xades4j/production/SignerBESTest.java @@ -32,8 +32,6 @@ import xades4j.properties.DataObjectFormatProperty; import xades4j.properties.IndividualDataObjsTimeStampProperty; import xades4j.properties.SignerRoleProperty; -import xades4j.providers.SignaturePropertiesCollector; -import xades4j.providers.SignaturePropertiesProvider; import java.io.File; @@ -106,15 +104,9 @@ void testSignBESWithCounterSig() throws Exception XadesBesSigningProfile profile = new XadesBesSigningProfile(keyingProviderMy); final XadesSigner counterSigner = profile.newSigner(); - profile.withSignaturePropertiesProvider(new SignaturePropertiesProvider() - { - @Override - public void provideProperties( - SignaturePropertiesCollector signedPropsCol) - { - signedPropsCol.addCounterSignature(new CounterSignatureProperty(counterSigner)); - signedPropsCol.setSignerRole(new SignerRoleProperty("CounterSignature maniac")); - } + profile.withSignaturePropertiesProvider(signedPropsCol -> { + signedPropsCol.addCounterSignature(new CounterSignatureProperty(counterSigner)); + signedPropsCol.setSignerRole(new SignerRoleProperty("CounterSignature maniac")); }); XadesSigner signer = profile.newSigner(); diff --git a/src/test/java/xades4j/production/SignerEPESTest.java b/src/test/java/xades4j/production/SignerEPESTest.java index 6b1ba873..ef53a9ac 100644 --- a/src/test/java/xades4j/production/SignerEPESTest.java +++ b/src/test/java/xades4j/production/SignerEPESTest.java @@ -22,7 +22,6 @@ import org.w3c.dom.Element; import xades4j.properties.IdentifierType; import xades4j.properties.ObjectIdentifier; -import xades4j.properties.SignaturePolicyBase; import xades4j.properties.SignaturePolicyIdentifierProperty; import xades4j.providers.SignaturePolicyInfoProvider; @@ -43,17 +42,10 @@ void testSignEPES(String locationUrl, String output) throws Exception Document doc = getTestDocument(); Element elemToSign = doc.getDocumentElement(); - SignaturePolicyInfoProvider policyInfoProvider = new SignaturePolicyInfoProvider() - { - @Override - public SignaturePolicyBase getSignaturePolicy() - { - return new SignaturePolicyIdentifierProperty( - new ObjectIdentifier("oid:/1.2.4.0.9.4.5", IdentifierType.OIDAsURI, "Policy description"), - new ByteArrayInputStream("Test policy input stream".getBytes())) - .withLocationUrl(locationUrl); - } - }; + SignaturePolicyInfoProvider policyInfoProvider = () -> new SignaturePolicyIdentifierProperty( + new ObjectIdentifier("oid:/1.2.4.0.9.4.5", IdentifierType.OIDAsURI, "Policy description"), + new ByteArrayInputStream("Test policy input stream".getBytes())) + .withLocationUrl(locationUrl); SignerEPES signer = (SignerEPES) new XadesEpesSigningProfile(keyingProviderMy, policyInfoProvider).newSigner(); new Enveloped(signer).sign(elemToSign); diff --git a/src/test/java/xades4j/production/SignerTTest.java b/src/test/java/xades4j/production/SignerTTest.java index b7bcffe9..7ad37d52 100644 --- a/src/test/java/xades4j/production/SignerTTest.java +++ b/src/test/java/xades4j/production/SignerTTest.java @@ -20,9 +20,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import xades4j.algorithms.ExclusiveCanonicalXMLWithoutComments; -import xades4j.properties.SignaturePolicyBase; import xades4j.properties.SignaturePolicyImpliedProperty; -import xades4j.providers.SignaturePolicyInfoProvider; import xades4j.providers.impl.HttpTsaConfiguration; /** @@ -56,14 +54,7 @@ void testSignTWithPolicy() throws Exception Element elemToSign = doc.getDocumentElement(); XadesSigner signer = new XadesTSigningProfile(keyingProviderMy) - .withPolicyProvider(new SignaturePolicyInfoProvider() - { - @Override - public SignaturePolicyBase getSignaturePolicy() - { - return new SignaturePolicyImpliedProperty(); - } - }) + .withPolicyProvider(() -> new SignaturePolicyImpliedProperty()) .with(DEFAULT_TEST_TSA) .newSigner(); diff --git a/src/test/java/xades4j/production/UncheckedSignerBESTest.java b/src/test/java/xades4j/production/UncheckedSignerBESTest.java index c6f735ca..82ed48ec 100644 --- a/src/test/java/xades4j/production/UncheckedSignerBESTest.java +++ b/src/test/java/xades4j/production/UncheckedSignerBESTest.java @@ -146,9 +146,7 @@ void testUncheckedSignBesGood() throws Exception @Test void testUncheckedSignBesNoSignKeyUsage() throws Exception { - assertThrows(SigningCertificateKeyUsageException.class, () -> { - trySignAndVerify(keyingProviderNoSign, validationProvider, "document.unchecked.signed.bes.nosign.xml"); - }); + assertThrows(SigningCertificateKeyUsageException.class, () -> trySignAndVerify(keyingProviderNoSign, validationProvider, "document.unchecked.signed.bes.nosign.xml")); } @Test @@ -162,16 +160,12 @@ void testUncheckedSignBesNoSignKeyUsageUncheckedVerify() throws Exception @Test void testUncheckedSignBesExpired() throws Exception { - assertThrows(CannotBuildCertificationPathException.class, () -> { - trySignAndVerify(keyingProviderExp, validationProvider, "document.unchecked.signed.bes.expired.xml"); - }); + assertThrows(CannotBuildCertificationPathException.class, () -> trySignAndVerify(keyingProviderExp, validationProvider, "document.unchecked.signed.bes.expired.xml")); } @Test void testUncheckedSignBesNyv() throws Exception { - assertThrows(CannotBuildCertificationPathException.class, () -> { - trySignAndVerify(keyingProviderNyv, validationProvider, "document.unchecked.signed.bes.nyv.xml"); - }); + assertThrows(CannotBuildCertificationPathException.class, () -> trySignAndVerify(keyingProviderNyv, validationProvider, "document.unchecked.signed.bes.nyv.xml")); } } diff --git a/src/test/java/xades4j/properties/DataObjectDescTest.java b/src/test/java/xades4j/properties/DataObjectDescTest.java index 0bf44bf2..101c1af0 100644 --- a/src/test/java/xades4j/properties/DataObjectDescTest.java +++ b/src/test/java/xades4j/properties/DataObjectDescTest.java @@ -59,9 +59,7 @@ void testWithDataObjectFormatRepeatedInstance() instance.withDataObjectFormat(format); - assertThrows(IllegalStateException.class, () -> { - instance.withDataObjectFormat(format); - }); + assertThrows(IllegalStateException.class, () -> instance.withDataObjectFormat(format)); } /** diff --git a/src/test/java/xades4j/properties/DataObjectFormatPropertyTest.java b/src/test/java/xades4j/properties/DataObjectFormatPropertyTest.java index bd59289c..f3b19863 100644 --- a/src/test/java/xades4j/properties/DataObjectFormatPropertyTest.java +++ b/src/test/java/xades4j/properties/DataObjectFormatPropertyTest.java @@ -104,8 +104,6 @@ void testWithDocumentationUris() void testWithDocumentationUris_Null() { DataObjectFormatProperty instance = new DataObjectFormatProperty(); - assertThrows(NullPointerException.class, () -> { - instance.withDocumentationUris(null); - }); + assertThrows(NullPointerException.class, () -> instance.withDocumentationUris(null)); } } diff --git a/src/test/java/xades4j/providers/impl/DefaultTimeStampVerificationProviderTest.java b/src/test/java/xades4j/providers/impl/DefaultTimeStampVerificationProviderTest.java index e7cd1250..3b64e7f7 100644 --- a/src/test/java/xades4j/providers/impl/DefaultTimeStampVerificationProviderTest.java +++ b/src/test/java/xades4j/providers/impl/DefaultTimeStampVerificationProviderTest.java @@ -44,9 +44,7 @@ void testVerifyTokenSucceeds() throws Exception void testVerifyTokenFailsWithDifferentDigestInput() throws Exception { byte[] tsDigestInput = "Invalid".getBytes(); - assertThrows(TimeStampTokenDigestException.class, () -> { - doVerifyToken(tsDigestInput, getTestToken()); - }); + assertThrows(TimeStampTokenDigestException.class, () -> doVerifyToken(tsDigestInput, getTestToken())); } @Test @@ -63,9 +61,7 @@ void testVerifyTokenFailsWithTamperedToken() throws Exception } } - assertThrows(TimeStampTokenVerificationException.class, () -> { - doVerifyToken(tsDigestInput, tsToken); - }); + assertThrows(TimeStampTokenVerificationException.class, () -> doVerifyToken(tsDigestInput, tsToken)); } private byte[] getTestToken() throws Exception diff --git a/src/test/java/xades4j/utils/PropertiesBagTest.java b/src/test/java/xades4j/utils/PropertiesBagTest.java index 25c31114..65b3d593 100644 --- a/src/test/java/xades4j/utils/PropertiesBagTest.java +++ b/src/test/java/xades4j/utils/PropertiesBagTest.java @@ -68,9 +68,7 @@ void testPut() instance.put(prop1); instance.put(prop3); - assertThrows(IllegalStateException.class, () -> { - instance.put(prop2); - }); + assertThrows(IllegalStateException.class, () -> instance.put(prop2)); } /** @@ -80,9 +78,7 @@ void testPut() void testAddNull() { PropertiesSet instance = new PropertiesSet(0); - assertThrows(NullPointerException.class, () -> { - instance.add(null); - }); + assertThrows(NullPointerException.class, () -> instance.add(null)); } /** @@ -96,9 +92,7 @@ void testAdd() instance.add(prop1); instance.add(prop2); - assertThrows(IllegalStateException.class, () -> { - instance.add(prop1); - }); + assertThrows(IllegalStateException.class, () -> instance.add(prop1)); } /** @@ -125,9 +119,7 @@ void testRemoveNotPresent() PropertiesSet instance = new PropertiesSet(1); instance.add(prop1); - assertThrows(IllegalStateException.class, () -> { - instance.remove(prop2); - }); + assertThrows(IllegalStateException.class, () -> instance.remove(prop2)); } /** diff --git a/src/test/java/xades4j/utils/X500NameStyleProviderTest.java b/src/test/java/xades4j/utils/X500NameStyleProviderTest.java index da01a85d..d999247b 100644 --- a/src/test/java/xades4j/utils/X500NameStyleProviderTest.java +++ b/src/test/java/xades4j/utils/X500NameStyleProviderTest.java @@ -24,17 +24,13 @@ class X500NameStyleProviderTest @Test void errorDefaultParsing() { - assertThrows(Exception.class, () -> { - new X500Principal(NAME_SIMPLE); - }); + assertThrows(Exception.class, () -> new X500Principal(NAME_SIMPLE)); } @Test void errorParsingWithProvider() { - assertThrows(Exception.class, () -> { - new DefaultX500NameStyleProvider().fromString(NAME_SIMPLE); - }); + assertThrows(Exception.class, () -> new DefaultX500NameStyleProvider().fromString(NAME_SIMPLE)); } @Test diff --git a/src/test/java/xades4j/utils/XadesProfileCoreTest.java b/src/test/java/xades4j/utils/XadesProfileCoreTest.java index 81b78a95..3677085d 100644 --- a/src/test/java/xades4j/utils/XadesProfileCoreTest.java +++ b/src/test/java/xades4j/utils/XadesProfileCoreTest.java @@ -125,9 +125,7 @@ protected void configure() void testGetInstanceException() throws XadesProfileResolutionException { XadesProfileCore instance = new XadesProfileCore(); - assertThrows(XadesProfileResolutionException.class, () -> { - instance.getInstance(A.class, new Module[0], new Module[0]); - }); + assertThrows(XadesProfileResolutionException.class, () -> instance.getInstance(A.class, new Module[0], new Module[0])); } @Test diff --git a/src/test/java/xades4j/verification/GenericDOMDataVerifierTest.java b/src/test/java/xades4j/verification/GenericDOMDataVerifierTest.java index 25d71217..0f7dd5ed 100644 --- a/src/test/java/xades4j/verification/GenericDOMDataVerifierTest.java +++ b/src/test/java/xades4j/verification/GenericDOMDataVerifierTest.java @@ -67,9 +67,7 @@ void testVerifyNoVerifier() throws Exception QualifyingPropertyVerificationContext ctx = null; GenericDOMDataVerifier instance = new GenericDOMDataVerifier(new HashMap(0)); - assertThrows(InvalidPropertyException.class, () -> { - instance.verify(propData, ctx); - }); + assertThrows(InvalidPropertyException.class, () -> instance.verify(propData, ctx)); } } diff --git a/src/test/java/xades4j/verification/OtherVerifierTests.java b/src/test/java/xades4j/verification/OtherVerifierTests.java index f42bac2b..bb75d568 100644 --- a/src/test/java/xades4j/verification/OtherVerifierTests.java +++ b/src/test/java/xades4j/verification/OtherVerifierTests.java @@ -61,21 +61,11 @@ public void initialize() @Test void testVerifyBESCustomPropVer() throws Exception { - mySigsVerificationProfile.withQualifyingPropertyVerifier(SigningTimeData.class, new QualifyingPropertyVerifier() - { - - @Override - public QualifyingProperty verify( - SigningTimeData propData, - QualifyingPropertyVerificationContext ctx) - { - throw new UnsupportedOperationException("Yeah!"); - } + mySigsVerificationProfile.withQualifyingPropertyVerifier(SigningTimeData.class, (propData, ctx) -> { + throw new UnsupportedOperationException("Yeah!"); }); - Exception e = assertThrows(UnsupportedOperationException.class, () -> { - verifySignature("document.signed.bes.xml", mySigsVerificationProfile); - }); + Exception e = assertThrows(UnsupportedOperationException.class, () -> verifySignature("document.signed.bes.xml", mySigsVerificationProfile)); assertEquals("Yeah!", e.getMessage()); } @@ -87,9 +77,8 @@ void testCustomVerifierCanUseBuiltInVerifier() throws Exception SigningTimeData.class, SigningTimeVerifierThatDependsOnBuiltInVerifier.class); - assertThrows(SigningTimeVerificationException.class, () -> { - verifySignature("document.signed.bes.xml", mySigsVerificationProfile); - }); + assertThrows(SigningTimeVerificationException.class, () -> + verifySignature("document.signed.bes.xml", mySigsVerificationProfile)); } @Test diff --git a/src/test/java/xades4j/verification/VerifierTestBase.java b/src/test/java/xades4j/verification/VerifierTestBase.java index dcc01543..c282f30d 100644 --- a/src/test/java/xades4j/verification/VerifierTestBase.java +++ b/src/test/java/xades4j/verification/VerifierTestBase.java @@ -16,22 +16,21 @@ */ package xades4j.verification; -import java.io.ByteArrayInputStream; -import java.io.FileInputStream; -import java.io.InputStream; -import java.security.KeyStore; -import java.security.cert.CRLException; -import java.security.cert.CertificateException; import org.apache.xml.security.utils.Constants; import org.w3c.dom.Document; import org.w3c.dom.Element; -import xades4j.properties.ObjectIdentifier; import xades4j.providers.CertificateValidationProvider; -import xades4j.utils.FileSystemDirectoryCertStore; -import xades4j.providers.impl.PKIXCertificateValidationProvider; import xades4j.providers.SignaturePolicyDocumentProvider; +import xades4j.providers.impl.PKIXCertificateValidationProvider; +import xades4j.utils.FileSystemDirectoryCertStore; import xades4j.utils.SignatureServicesTestBase; +import java.io.ByteArrayInputStream; +import java.io.FileInputStream; +import java.security.KeyStore; +import java.security.cert.CRLException; +import java.security.cert.CertificateException; + /** * * @author Luís @@ -47,15 +46,7 @@ public class VerifierTestBase extends SignatureServicesTestBase { try { - policyDocumentFinder = new SignaturePolicyDocumentProvider() - { - @Override - public InputStream getSignaturePolicyDocumentStream( - ObjectIdentifier sigPolicyId) - { - return new ByteArrayInputStream("Test policy input stream".getBytes()); - } - }; + policyDocumentFinder = sigPolicyId -> new ByteArrayInputStream("Test policy input stream".getBytes()); // Validation provider with certificates from "my" folder. Used for // signatures without revocation data. diff --git a/src/test/java/xades4j/verification/XAdESFormCheckerTest.java b/src/test/java/xades4j/verification/XAdESFormCheckerTest.java index 0e54c597..36772361 100644 --- a/src/test/java/xades4j/verification/XAdESFormCheckerTest.java +++ b/src/test/java/xades4j/verification/XAdESFormCheckerTest.java @@ -30,9 +30,6 @@ class XAdESFormCheckerTest @Test void checkFormThrowsIfMinimumPropertiesAreNotPresent() throws InvalidXAdESFormException { - assertThrows(InvalidXAdESFormException.class, () -> { - XAdESFormChecker.checkForm(new ArrayList(0)); - - }); + assertThrows(InvalidXAdESFormException.class, () -> XAdESFormChecker.checkForm(new ArrayList(0))); } } diff --git a/src/test/java/xades4j/verification/XadesVerifierErrorsTest.java b/src/test/java/xades4j/verification/XadesVerifierErrorsTest.java index 0d404956..14353060 100644 --- a/src/test/java/xades4j/verification/XadesVerifierErrorsTest.java +++ b/src/test/java/xades4j/verification/XadesVerifierErrorsTest.java @@ -43,26 +43,20 @@ public void initialize() @Test void testErrVerifySignedPropsIncorp() throws Exception { - assertThrows(QualifyingPropertiesIncorporationException.class, () -> { - verifyBadSignature("document.signed.t.bes.badsignedprops.xml", mySigsVerificationProfile); - }); + assertThrows(QualifyingPropertiesIncorporationException.class, () -> verifyBadSignature("document.signed.t.bes.badsignedprops.xml", mySigsVerificationProfile)); } @Test void testErrVerifySignedPropsIncorpNoRefType() throws Exception { - assertThrows(QualifyingPropertiesIncorporationException.class, () -> { - verifyBadSignature("document.signed.bes.signedpropsrefnotype.xml", - new XadesVerificationProfile(validationProviderPtCc)); - }); + assertThrows(QualifyingPropertiesIncorporationException.class, () -> verifyBadSignature("document.signed.bes.signedpropsrefnotype.xml", + new XadesVerificationProfile(validationProviderPtCc))); } @Test void testErrVerifyIncorrectC() throws Exception { - assertThrows(InvalidXAdESFormException.class, () -> { - verifyBadSignature("document.signed.c.bad.xml", nistVerificationProfile); - }); + assertThrows(InvalidXAdESFormException.class, () -> verifyBadSignature("document.signed.c.bad.xml", nistVerificationProfile)); } @Test @@ -70,33 +64,25 @@ void testErrVerifyNoSignCert() throws Exception { KeyStore ks = createAndLoadJKSKeyStore("be/beStore", "bestorepass"); PKIXCertificateValidationProvider cvp = PKIXCertificateValidationProvider.builder(ks).checkRevocation(false).build(); - assertThrows(CannotSelectCertificateException.class, () -> { - verifyBadSignature("TSL_BE.nocert.xml", new XadesVerificationProfile(cvp)); - }); + assertThrows(CannotSelectCertificateException.class, () -> verifyBadSignature("TSL_BE.nocert.xml", new XadesVerificationProfile(cvp))); } @Test void testErrVerifyChangedDataObj() throws Exception { - assertThrows(ReferenceValueException.class, () -> { - verifyBadSignature("document.signed.bes.invaliddataobj.xml", mySigsVerificationProfile); - }); + assertThrows(ReferenceValueException.class, () -> verifyBadSignature("document.signed.bes.invaliddataobj.xml", mySigsVerificationProfile)); } @Test void testErrVerifyChangedSigValue() throws Exception { - assertThrows(SignatureValueException.class, () -> { - verifyBadSignature("document.signed.bes.invalidsigvalue.xml", mySigsVerificationProfile); - }); + assertThrows(SignatureValueException.class, () -> verifyBadSignature("document.signed.bes.invalidsigvalue.xml", mySigsVerificationProfile)); } @Test void testErrVerifyCMissingCertRef() throws Exception { - assertThrows(CompleteCertRefsCertNotFoundException.class, () -> { - verifyBadSignature("document.signed.c.missingcertref.xml", nistVerificationProfile); - }); + assertThrows(CompleteCertRefsCertNotFoundException.class, () -> verifyBadSignature("document.signed.c.missingcertref.xml", nistVerificationProfile)); } @Test @@ -110,17 +96,13 @@ void testErrVerifyUnmatchSigTSDigest() throws Exception // encTS.setTextContent(Base64.encodeBytes(tkn)); // outputDocument(doc, "bad/document.signed.t.bes.badtsdigest.xml"); - assertThrows(TimeStampDigestMismatchException.class, () -> { - verifyBadSignature("document.signed.t.bes.badtsdigest.xml", mySigsVerificationProfile); - }); + assertThrows(TimeStampDigestMismatchException.class, () -> verifyBadSignature("document.signed.t.bes.badtsdigest.xml", mySigsVerificationProfile)); } @Test void testErrVerifyCounterSigWithUnallowedTransforms() throws Exception { - assertThrows(CounterSignatureSigValueRefException.class, () -> { - verifyBadSignature("document.signed.bes.cs.invalidtransforms.xml", mySigsVerificationProfile); - }); + assertThrows(CounterSignatureSigValueRefException.class, () -> verifyBadSignature("document.signed.bes.cs.invalidtransforms.xml", mySigsVerificationProfile)); } private static void verifyBadSignature(String sigFileName, XadesVerificationProfile p) throws Exception diff --git a/src/test/java/xades4j/verification/XadesVerifierImplTest.java b/src/test/java/xades4j/verification/XadesVerifierImplTest.java index 18da2848..c2938e67 100644 --- a/src/test/java/xades4j/verification/XadesVerifierImplTest.java +++ b/src/test/java/xades4j/verification/XadesVerifierImplTest.java @@ -139,22 +139,14 @@ void testVerifyBESWithVerificationDate() throws Exception } @Test - void testVerifyWithCustomRawVerifier() throws Exception - { - verificationProfile.withRawSignatureVerifier(new RawSignatureVerifier() - { - @Override - public void verify(RawSignatureVerifierContext ctx) throws InvalidSignatureException - { - // Do something usefull with the signature - // ctx.getSignature().getSignedInfo().item(0)... - throw new InvalidSignatureException("Rejected by RawSignatureVerifier"); - } + void testVerifyWithCustomRawVerifier() { + verificationProfile.withRawSignatureVerifier(ctx -> { + // Do something usefull with the signature + // ctx.getSignature().getSignedInfo().item(0)... + throw new InvalidSignatureException("Rejected by RawSignatureVerifier"); }); - assertThrows(InvalidSignatureException.class, () -> { - verifySignature("document.signed.bes.xml", verificationProfile); - }); + assertThrows(InvalidSignatureException.class, () -> verifySignature("document.signed.bes.xml", verificationProfile)); } @Test From 7ba8313ba42ea7202b332d740b81fd5a77c6e964 Mon Sep 17 00:00:00 2001 From: Mirko Date: Mon, 13 Nov 2023 21:31:25 +0100 Subject: [PATCH 09/14] replace unnecessary explicit type arguments with <> in test classes --- .../production/XadesSignatureFormatExtenderImplTest.java | 6 +++--- .../xades4j/properties/DataObjectFormatPropertyTest.java | 2 +- .../xades4j/verification/GenericDOMDataVerifierTest.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/xades4j/production/XadesSignatureFormatExtenderImplTest.java b/src/test/java/xades4j/production/XadesSignatureFormatExtenderImplTest.java index 003ec92a..56a1b77a 100644 --- a/src/test/java/xades4j/production/XadesSignatureFormatExtenderImplTest.java +++ b/src/test/java/xades4j/production/XadesSignatureFormatExtenderImplTest.java @@ -50,7 +50,7 @@ void testEnrichSignatureWithNestedCounterSig() throws Exception XadesSignatureFormatExtender extender = new XadesFormatExtenderProfile().getFormatExtender(); XMLSignature sig = new XMLSignature(signatureNode, signatureNode.getOwnerDocument().getBaseURI()); - Collection usp = new ArrayList(1); + Collection usp = new ArrayList<>(1); usp.add(new CounterSignatureProperty(signer)); extender.enrichSignature(sig, new UnsignedProperties(usp)); @@ -67,7 +67,7 @@ void testEnrichSignatureWithT() throws Exception XadesSignatureFormatExtender instance = new XadesFormatExtenderProfile().with(DEFAULT_TEST_TSA).getFormatExtender(); XMLSignature sig = new XMLSignature(signatureNode, ""); - Collection usp = new ArrayList(1); + Collection usp = new ArrayList<>(1); usp.add(new SignatureTimeStampProperty()); instance.enrichSignature(sig, new UnsignedProperties(usp)); @@ -84,7 +84,7 @@ void testEnrichSignatureWithA() throws Exception XadesSignatureFormatExtender instance = new XadesFormatExtenderProfile().with(DEFAULT_TEST_TSA).getFormatExtender(); XMLSignature sig = new XMLSignature(signatureNode, ""); - Collection usp = new ArrayList(1); + Collection usp = new ArrayList<>(1); usp.add(new ArchiveTimeStampProperty()); instance.enrichSignature(sig, new UnsignedProperties(usp)); diff --git a/src/test/java/xades4j/properties/DataObjectFormatPropertyTest.java b/src/test/java/xades4j/properties/DataObjectFormatPropertyTest.java index f3b19863..1ec1c4e6 100644 --- a/src/test/java/xades4j/properties/DataObjectFormatPropertyTest.java +++ b/src/test/java/xades4j/properties/DataObjectFormatPropertyTest.java @@ -85,7 +85,7 @@ void testWithDocumentationUri() @Test void testWithDocumentationUris() { - Collection documentationUris = new ArrayList(1); + Collection documentationUris = new ArrayList<>(1); DataObjectFormatProperty instance = new DataObjectFormatProperty(); instance.withDocumentationUris(documentationUris); diff --git a/src/test/java/xades4j/verification/GenericDOMDataVerifierTest.java b/src/test/java/xades4j/verification/GenericDOMDataVerifierTest.java index 0f7dd5ed..b2c05b07 100644 --- a/src/test/java/xades4j/verification/GenericDOMDataVerifierTest.java +++ b/src/test/java/xades4j/verification/GenericDOMDataVerifierTest.java @@ -65,7 +65,7 @@ void testVerifyNoVerifier() throws Exception { GenericDOMData propData = new GenericDOMData(testDocument.createElementNS("http://test.generic.dom", "Elem")); QualifyingPropertyVerificationContext ctx = null; - GenericDOMDataVerifier instance = new GenericDOMDataVerifier(new HashMap(0)); + GenericDOMDataVerifier instance = new GenericDOMDataVerifier(new HashMap<>(0)); assertThrows(InvalidPropertyException.class, () -> instance.verify(propData, ctx)); } From 6cefd4ce002a7a5baa2b61f711869a9f7e9e3d55 Mon Sep 17 00:00:00 2001 From: Mirko Date: Mon, 13 Nov 2023 23:59:15 +0100 Subject: [PATCH 10/14] add types to raw parameters --- .../PropertyDataGeneratorsMapperImpl.java | 7 +++-- .../CommitmentTypePropertyBase.java | 6 ++-- .../properties/data/CommitmentTypeData.java | 8 +++--- .../impl/KeyStoreKeyingDataProvider.java | 28 +++++++++++++++---- .../utils/FileSystemDirectoryCertStore.java | 4 +-- .../verification/GenericDOMDataVerifier.java | 5 ++-- ...QualifyingPropertyVerifiersMapperImpl.java | 2 +- .../ToXmlCertificateValuesConverter.java | 7 +++-- .../ToXmlCommitmentTypeConverter.java | 7 +++-- .../ToXmlRevocationValuesConverter.java | 7 +++-- .../xades4j/xml/marshalling/ToXmlUtils.java | 7 +++-- .../FromXmlBaseTimeStampConverter.java | 7 +++-- .../FromXmlCommitmentTypeConverter.java | 15 +++++----- .../FromXmlSignaturePolicyConverter.java | 7 +++-- .../FromXmlSignerRoleConverter.java | 9 +++--- ...eSystemKeyStoreKeyingDataProviderTest.java | 3 +- .../java/xades4j/utils/PropertiesBagTest.java | 13 +++++---- .../DistinguishedNameComparerTest.java | 3 +- 18 files changed, 88 insertions(+), 57 deletions(-) diff --git a/src/main/java/xades4j/production/PropertyDataGeneratorsMapperImpl.java b/src/main/java/xades4j/production/PropertyDataGeneratorsMapperImpl.java index fe7efdde..8325771f 100644 --- a/src/main/java/xades4j/production/PropertyDataGeneratorsMapperImpl.java +++ b/src/main/java/xades4j/production/PropertyDataGeneratorsMapperImpl.java @@ -16,14 +16,15 @@ */ package xades4j.production; -import jakarta.inject.Inject; import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.TypeLiteral; import com.google.inject.util.Types; -import java.lang.reflect.ParameterizedType; +import jakarta.inject.Inject; import xades4j.properties.QualifyingProperty; +import java.lang.reflect.ParameterizedType; + /** * Resolves the generators through the injector. * @author Luís @@ -45,7 +46,7 @@ public PropertyDataObjectGenerator get try { ParameterizedType pt = Types.newParameterizedType(PropertyDataObjectGenerator.class, p.getClass()); - return (PropertyDataObjectGenerator)injector.getInstance(Key.get(TypeLiteral.get(pt))); + return (PropertyDataObjectGenerator)injector.getInstance(Key.get(TypeLiteral.get(pt))); } catch (RuntimeException ex) { throw new PropertyDataGeneratorNotAvailableException(p, ex); diff --git a/src/main/java/xades4j/properties/CommitmentTypePropertyBase.java b/src/main/java/xades4j/properties/CommitmentTypePropertyBase.java index 0d58d662..a40163eb 100644 --- a/src/main/java/xades4j/properties/CommitmentTypePropertyBase.java +++ b/src/main/java/xades4j/properties/CommitmentTypePropertyBase.java @@ -51,7 +51,7 @@ public abstract class CommitmentTypePropertyBase extends SignedDataObjectPropert /**/ private final String uri; private final String description; - private Collection qualifiers; + private Collection qualifiers; protected CommitmentTypePropertyBase(String uri, String description, TargetMultiplicity targetMult) @@ -94,11 +94,11 @@ public CommitmentTypePropertyBase withQualifier(Element qualifier){ private CommitmentTypePropertyBase addQualifier(Object qualifier){ this.qualifiers = CollectionUtils.newIfNull(this.qualifiers, 2); - this.qualifiers.add(qualifier); + this.qualifiers.add((String) qualifier); return this; } - public Collection getQualifiers(){ + public Collection getQualifiers(){ return CollectionUtils.emptyIfNull(this.qualifiers); } } diff --git a/src/main/java/xades4j/properties/data/CommitmentTypeData.java b/src/main/java/xades4j/properties/data/CommitmentTypeData.java index f2c7ab45..947e5cd8 100644 --- a/src/main/java/xades4j/properties/data/CommitmentTypeData.java +++ b/src/main/java/xades4j/properties/data/CommitmentTypeData.java @@ -27,9 +27,9 @@ public final class CommitmentTypeData implements PropertyDataObject { private String description; - private String uri; + private final String uri; private Collection objReferences; - private Collection qualifiers; + private Collection qualifiers; public CommitmentTypeData(String uri) { @@ -73,11 +73,11 @@ public String getUri() return uri; } - public void setQualifiers(Collection qualifiers){ + public void setQualifiers(Collection qualifiers){ this.qualifiers = qualifiers; } - public Collection getQualifiers(){ + public Collection getQualifiers(){ return this.qualifiers; } } diff --git a/src/main/java/xades4j/providers/impl/KeyStoreKeyingDataProvider.java b/src/main/java/xades4j/providers/impl/KeyStoreKeyingDataProvider.java index 99f56b4b..030dc0dd 100644 --- a/src/main/java/xades4j/providers/impl/KeyStoreKeyingDataProvider.java +++ b/src/main/java/xades4j/providers/impl/KeyStoreKeyingDataProvider.java @@ -22,6 +22,8 @@ import xades4j.verification.UnexpectedJCAException; import javax.security.auth.callback.PasswordCallback; +import java.io.ByteArrayInputStream; +import java.io.IOException; import java.security.GeneralSecurityException; import java.security.KeyStore; import java.security.KeyStore.Builder; @@ -30,6 +32,8 @@ import java.security.PrivateKey; import java.security.UnrecoverableKeyException; import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Arrays; @@ -37,6 +41,8 @@ import java.util.Enumeration; import java.util.List; +import static xades4j.providers.impl.KeyStoreKeyingDataProvider.SigningCertificateSelector.Entry; + /** * A KeyStore-based implementation of {@code KeyingDataProvider}. The keystore is * loaded on first access (thread-safe). @@ -229,7 +235,7 @@ public List getSigningCertificateChain() throws SigningCertChai Certificate cer = keyStore.getCertificate(alias); if (cer instanceof X509Certificate) { - availableSignCerts.add(new SigningCertificateSelector.Entry(alias, (X509Certificate) cer)); + availableSignCerts.add(new Entry(alias, (X509Certificate) cer)); } } } @@ -239,7 +245,7 @@ public List getSigningCertificateChain() throws SigningCertChai throw new SigningCertChainException("No certificates available in the key store"); } - var selectedCertificate = this.certificateSelector.selectCertificate(availableSignCerts); + Entry selectedCertificate = this.certificateSelector.selectCertificate(availableSignCerts); Certificate[] signingCertChain = this.keyStore.getCertificateChain(selectedCertificate.getAlias()); if (null == signingCertChain) @@ -249,8 +255,8 @@ public List getSigningCertificateChain() throws SigningCertChai if (this.returnFullChain) { - List lChain = Arrays.asList(signingCertChain); - return Collections.checkedList(lChain, X509Certificate.class); + List lChain = Arrays.asList( signingCertChain); + return Collections.checkedList(getX509Certificates(lChain), X509Certificate.class); } else { @@ -258,7 +264,7 @@ public List getSigningCertificateChain() throws SigningCertChai } } - catch (KeyStoreException ex) + catch (KeyStoreException | CertificateException | IOException ex) { // keyStore.getCertificateAlias, keyStore.getCertificateChain -> if the // keystore is not loaded. @@ -266,6 +272,18 @@ public List getSigningCertificateChain() throws SigningCertChai } } + private static List getX509Certificates(List lChain) throws CertificateException, IOException { + List lChainX509 = new ArrayList<>(); + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + for(Certificate certificate : lChain) { + try (ByteArrayInputStream bais = new ByteArrayInputStream(certificate.getEncoded())) { + X509Certificate x509 = (X509Certificate) cf.generateCertificate(bais); + lChainX509.add(x509); + } + } + return lChainX509; + } + @Override public PrivateKey getSigningKey(X509Certificate signingCert) throws SigningKeyException, UnexpectedJCAException { diff --git a/src/main/java/xades4j/utils/FileSystemDirectoryCertStore.java b/src/main/java/xades4j/utils/FileSystemDirectoryCertStore.java index c78ec5e0..a1073864 100644 --- a/src/main/java/xades4j/utils/FileSystemDirectoryCertStore.java +++ b/src/main/java/xades4j/utils/FileSystemDirectoryCertStore.java @@ -129,7 +129,7 @@ protected FileSystemDirectoryCertStore( if (!dir.exists() || !dir.isDirectory()) throw new IllegalArgumentException("Specified path doesn't exist or doesn't refer a directory"); - Collection contentList = new ArrayList(); + Collection contentList = new ArrayList<>(); transverseDirToFindContent(dir, contentList, certsFilesExts, crlsFilesExts, cf); try @@ -145,7 +145,7 @@ protected FileSystemDirectoryCertStore( private void transverseDirToFindContent( File dir, - Collection contentList, + Collection contentList, String[] certsFilesExts, String[] crlsFilesExts, CertificateFactory cf) throws CertificateException, CRLException diff --git a/src/main/java/xades4j/verification/GenericDOMDataVerifier.java b/src/main/java/xades4j/verification/GenericDOMDataVerifier.java index d0fd79a7..b2208cc7 100644 --- a/src/main/java/xades4j/verification/GenericDOMDataVerifier.java +++ b/src/main/java/xades4j/verification/GenericDOMDataVerifier.java @@ -17,12 +17,13 @@ package xades4j.verification; import jakarta.inject.Inject; -import java.util.Map; -import javax.xml.namespace.QName; import org.w3c.dom.Element; import xades4j.properties.QualifyingProperty; import xades4j.properties.data.GenericDOMData; +import javax.xml.namespace.QName; +import java.util.Map; + /** * * @author Luís diff --git a/src/main/java/xades4j/verification/QualifyingPropertyVerifiersMapperImpl.java b/src/main/java/xades4j/verification/QualifyingPropertyVerifiersMapperImpl.java index bc3d3e36..60326331 100644 --- a/src/main/java/xades4j/verification/QualifyingPropertyVerifiersMapperImpl.java +++ b/src/main/java/xades4j/verification/QualifyingPropertyVerifiersMapperImpl.java @@ -48,7 +48,7 @@ public QualifyingPropertyVerifier getV try { ParameterizedType pt = Types.newParameterizedType(QualifyingPropertyVerifier.class, p.getClass()); - return (QualifyingPropertyVerifier)injector.getInstance(Key.get(TypeLiteral.get(pt))); + return (QualifyingPropertyVerifier)injector.getInstance(Key.get(TypeLiteral.get(pt))); } catch (ConfigurationException | ProvisionException ignored) { } diff --git a/src/main/java/xades4j/xml/marshalling/ToXmlCertificateValuesConverter.java b/src/main/java/xades4j/xml/marshalling/ToXmlCertificateValuesConverter.java index 5fbf3091..89a41314 100644 --- a/src/main/java/xades4j/xml/marshalling/ToXmlCertificateValuesConverter.java +++ b/src/main/java/xades4j/xml/marshalling/ToXmlCertificateValuesConverter.java @@ -16,8 +16,6 @@ */ package xades4j.xml.marshalling; -import java.util.Collection; -import java.util.List; import org.w3c.dom.Document; import xades4j.properties.data.CertificateValuesData; import xades4j.properties.data.PropertyDataObject; @@ -25,6 +23,9 @@ import xades4j.xml.bind.xades.XmlEncapsulatedPKIDataType; import xades4j.xml.bind.xades.XmlUnsignedPropertiesType; +import java.util.Collection; +import java.util.List; + /** * * @author Luís @@ -40,7 +41,7 @@ public void convertIntoObjectTree( Collection certValues = ((CertificateValuesData)propData).getData(); XmlCertificateValuesType xmlCertValues = new XmlCertificateValuesType(); - List xmlCerts = xmlCertValues.getEncapsulatedX509CertificateOrOtherCertificate(); + List xmlCerts = xmlCertValues.getEncapsulatedX509CertificateOrOtherCertificate(); for (byte[] encodCer : certValues) { diff --git a/src/main/java/xades4j/xml/marshalling/ToXmlCommitmentTypeConverter.java b/src/main/java/xades4j/xml/marshalling/ToXmlCommitmentTypeConverter.java index a869b074..54b262ae 100644 --- a/src/main/java/xades4j/xml/marshalling/ToXmlCommitmentTypeConverter.java +++ b/src/main/java/xades4j/xml/marshalling/ToXmlCommitmentTypeConverter.java @@ -16,10 +16,9 @@ */ package xades4j.xml.marshalling; -import java.util.Collection; import org.w3c.dom.Document; -import xades4j.properties.data.PropertyDataObject; import xades4j.properties.data.CommitmentTypeData; +import xades4j.properties.data.PropertyDataObject; import xades4j.xml.bind.xades.XmlAnyType; import xades4j.xml.bind.xades.XmlCommitmentTypeIndicationType; import xades4j.xml.bind.xades.XmlCommitmentTypeQualifiersListType; @@ -27,6 +26,8 @@ import xades4j.xml.bind.xades.XmlObjectIdentifierType; import xades4j.xml.bind.xades.XmlSignedPropertiesType; +import java.util.Collection; + /** * * @author Luís @@ -62,7 +63,7 @@ public void convertIntoObjectTree( xmlCommitmentTypeProp.getObjectReference().addAll(refsUris); } - Collection qualifiers = commitmentTypeData.getQualifiers(); + Collection qualifiers = commitmentTypeData.getQualifiers(); if (!qualifiers.isEmpty()) { XmlCommitmentTypeQualifiersListType xmlQualifiers = new XmlCommitmentTypeQualifiersListType(); diff --git a/src/main/java/xades4j/xml/marshalling/ToXmlRevocationValuesConverter.java b/src/main/java/xades4j/xml/marshalling/ToXmlRevocationValuesConverter.java index f4071d88..c814ef43 100644 --- a/src/main/java/xades4j/xml/marshalling/ToXmlRevocationValuesConverter.java +++ b/src/main/java/xades4j/xml/marshalling/ToXmlRevocationValuesConverter.java @@ -16,8 +16,6 @@ */ package xades4j.xml.marshalling; -import java.util.Collection; -import java.util.List; import org.w3c.dom.Document; import xades4j.properties.data.PropertyDataObject; import xades4j.properties.data.RevocationValuesData; @@ -26,6 +24,9 @@ import xades4j.xml.bind.xades.XmlRevocationValuesType; import xades4j.xml.bind.xades.XmlUnsignedPropertiesType; +import java.util.Collection; +import java.util.List; + /** * * @author Luís @@ -44,7 +45,7 @@ public void convertIntoObjectTree( XmlCRLValuesType xmlCRLValues = new XmlCRLValuesType(); xmlRevocValues.setCRLValues(xmlCRLValues); - List xmlCRLs = xmlCRLValues.getEncapsulatedCRLValue(); + List xmlCRLs = xmlCRLValues.getEncapsulatedCRLValue(); for (byte[] encodCrl : crlValues) { diff --git a/src/main/java/xades4j/xml/marshalling/ToXmlUtils.java b/src/main/java/xades4j/xml/marshalling/ToXmlUtils.java index f0e8a813..69335263 100644 --- a/src/main/java/xades4j/xml/marshalling/ToXmlUtils.java +++ b/src/main/java/xades4j/xml/marshalling/ToXmlUtils.java @@ -16,8 +16,6 @@ */ package xades4j.xml.marshalling; -import java.util.EnumMap; -import java.util.List; import xades4j.properties.IdentifierType; import xades4j.properties.ObjectIdentifier; import xades4j.properties.data.BaseCertRefsData; @@ -31,6 +29,9 @@ import xades4j.xml.bind.xmldsig.XmlDigestMethodType; import xades4j.xml.bind.xmldsig.XmlX509IssuerSerialType; +import java.util.EnumMap; +import java.util.List; + /** * @author Luís */ @@ -43,7 +44,7 @@ class ToXmlUtils static { - identifierTypeConv = new EnumMap(IdentifierType.class); + identifierTypeConv = new EnumMap<>(IdentifierType.class); identifierTypeConv.put(IdentifierType.OIDAsURI, XmlQualifierType.OID_AS_URI); identifierTypeConv.put(IdentifierType.OIDAsURN, XmlQualifierType.OID_AS_URN); } diff --git a/src/main/java/xades4j/xml/unmarshalling/FromXmlBaseTimeStampConverter.java b/src/main/java/xades4j/xml/unmarshalling/FromXmlBaseTimeStampConverter.java index 207838a6..e712067f 100644 --- a/src/main/java/xades4j/xml/unmarshalling/FromXmlBaseTimeStampConverter.java +++ b/src/main/java/xades4j/xml/unmarshalling/FromXmlBaseTimeStampConverter.java @@ -16,9 +16,8 @@ */ package xades4j.xml.unmarshalling; -import java.util.List; import org.apache.xml.security.c14n.Canonicalizer; -import org.w3c.dom.Element; +import org.w3c.dom.Node; import xades4j.algorithms.Algorithm; import xades4j.algorithms.GenericAlgorithm; import xades4j.properties.data.BaseXAdESTimeStampData; @@ -27,6 +26,8 @@ import xades4j.xml.bind.xades.XmlXAdESTimeStampType; import xades4j.xml.bind.xmldsig.XmlCanonicalizationMethodType; +import java.util.List; + /** * * @author Luís @@ -60,7 +61,7 @@ protected void convertTimeStamps( } else { - List params = CollectionUtils.filterByType(xmlCanonMethod.getContent(), Element.class); + List params = CollectionUtils.filterByType(xmlCanonMethod.getContent(), Node.class); c14n = new GenericAlgorithm(xmlCanonMethod.getAlgorithm(), params); } TPropData tsData = createTSData(c14n); diff --git a/src/main/java/xades4j/xml/unmarshalling/FromXmlCommitmentTypeConverter.java b/src/main/java/xades4j/xml/unmarshalling/FromXmlCommitmentTypeConverter.java index f9335bcd..dd1be923 100644 --- a/src/main/java/xades4j/xml/unmarshalling/FromXmlCommitmentTypeConverter.java +++ b/src/main/java/xades4j/xml/unmarshalling/FromXmlCommitmentTypeConverter.java @@ -16,15 +16,16 @@ */ package xades4j.xml.unmarshalling; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; import xades4j.properties.CommitmentTypePropertyBase; -import xades4j.xml.bind.xades.XmlCommitmentTypeIndicationType; -import xades4j.xml.bind.xades.XmlSignedDataObjectPropertiesType; import xades4j.properties.data.CommitmentTypeData; import xades4j.xml.bind.xades.XmlAnyType; +import xades4j.xml.bind.xades.XmlCommitmentTypeIndicationType; import xades4j.xml.bind.xades.XmlCommitmentTypeQualifiersListType; +import xades4j.xml.bind.xades.XmlSignedDataObjectPropertiesType; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; /** * @@ -69,7 +70,7 @@ public void convertFromObjectTree( XmlCommitmentTypeQualifiersListType xmlQualifiers = xmlCommitment.getCommitmentTypeQualifiers(); if (xmlQualifiers != null) { - Collection qualifiers = new ArrayList(); + Collection qualifiers = new ArrayList<>(); for (XmlAnyType xmlQualifier : xmlQualifiers.getCommitmentTypeQualifier()) { if (!xmlQualifier.getContent().isEmpty()) @@ -79,7 +80,7 @@ public void convertFromObjectTree( throw new PropertyUnmarshalException("Qualifiers with multiple children are not support", CommitmentTypePropertyBase.PROP_NAME); } - qualifiers.add(xmlQualifier.getContent().get(0)); + qualifiers.add((String) xmlQualifier.getContent().get(0)); } } diff --git a/src/main/java/xades4j/xml/unmarshalling/FromXmlSignaturePolicyConverter.java b/src/main/java/xades4j/xml/unmarshalling/FromXmlSignaturePolicyConverter.java index 612df5b8..0bf836a9 100644 --- a/src/main/java/xades4j/xml/unmarshalling/FromXmlSignaturePolicyConverter.java +++ b/src/main/java/xades4j/xml/unmarshalling/FromXmlSignaturePolicyConverter.java @@ -16,7 +16,6 @@ */ package xades4j.xml.unmarshalling; -import java.util.List; import jakarta.xml.bind.JAXBElement; import xades4j.properties.QualifyingProperty; import xades4j.properties.SignaturePolicyBase; @@ -27,6 +26,8 @@ import xades4j.xml.bind.xades.XmlSignaturePolicyIdentifierType; import xades4j.xml.bind.xades.XmlSignedSignaturePropertiesType; +import java.util.List; + /** * * @author Luís @@ -71,13 +72,13 @@ private static String getLocationUrl(XmlSignaturePolicyIdType xmlPolicyId) { List xmlQualifiers = sigPolicyQualifiers.getSigPolicyQualifier(); for (XmlAnyType xmlQualifier : xmlQualifiers) { - List content = xmlQualifier.getContent(); + List content = xmlQualifier.getContent(); if (content.size() == 1 && content.get(0) instanceof JAXBElement) { JAXBElement xmlSPURI = (JAXBElement)content.get(0); if (xmlSPURI.getName().getLocalPart().equals("SPURI") && xmlSPURI.getName().getNamespaceURI().equals(QualifyingProperty.XADES_XMLNS)) { - return (String)xmlSPURI.getValue(); + return (String) xmlSPURI.getValue(); } } } diff --git a/src/main/java/xades4j/xml/unmarshalling/FromXmlSignerRoleConverter.java b/src/main/java/xades4j/xml/unmarshalling/FromXmlSignerRoleConverter.java index 365e12ca..9fd4f7b9 100644 --- a/src/main/java/xades4j/xml/unmarshalling/FromXmlSignerRoleConverter.java +++ b/src/main/java/xades4j/xml/unmarshalling/FromXmlSignerRoleConverter.java @@ -16,15 +16,16 @@ */ package xades4j.xml.unmarshalling; -import java.util.HashSet; -import java.util.List; -import java.util.Set; import xades4j.properties.SignerRoleProperty; import xades4j.properties.data.SignerRoleData; import xades4j.xml.bind.xades.XmlAnyType; import xades4j.xml.bind.xades.XmlSignedSignaturePropertiesType; import xades4j.xml.bind.xades.XmlSignerRoleType; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + /** * * @author Luís @@ -47,7 +48,7 @@ public void convertFromObjectTree( for (XmlAnyType xmlRole : xmlSignerRole.getClaimedRoles().getClaimedRole()) { - List contents = xmlRole.getContent(); + List contents = xmlRole.getContent(); if(contents.size() != 1 || !(contents.get(0) instanceof String)) throw new PropertyUnmarshalException("unsupported claimed role. Only one string is supported", SignerRoleProperty.PROP_NAME); claimedRoles.add((String)contents.get(0)); diff --git a/src/test/java/xades4j/providers/impl/FileSystemKeyStoreKeyingDataProviderTest.java b/src/test/java/xades4j/providers/impl/FileSystemKeyStoreKeyingDataProviderTest.java index da5e3a47..2da632b3 100644 --- a/src/test/java/xades4j/providers/impl/FileSystemKeyStoreKeyingDataProviderTest.java +++ b/src/test/java/xades4j/providers/impl/FileSystemKeyStoreKeyingDataProviderTest.java @@ -20,6 +20,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import xades4j.utils.SignatureServicesTestBase; @@ -50,7 +51,7 @@ public static void cleanup() Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME); } - public static Collection data() throws Exception + public static Collection data() throws Exception { FileSystemKeyStoreKeyingDataProvider keyingProviderPkcs12 = FileSystemKeyStoreKeyingDataProvider .builder("pkcs12", diff --git a/src/test/java/xades4j/utils/PropertiesBagTest.java b/src/test/java/xades4j/utils/PropertiesBagTest.java index 65b3d593..1278cd0f 100644 --- a/src/test/java/xades4j/utils/PropertiesBagTest.java +++ b/src/test/java/xades4j/utils/PropertiesBagTest.java @@ -18,6 +18,7 @@ import org.junit.jupiter.api.Test; import xades4j.properties.DataObjectFormatProperty; +import xades4j.properties.QualifyingProperty; import xades4j.properties.SigningTimeProperty; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -64,7 +65,7 @@ void testPut() SigningTimeProperty prop1 = new SigningTimeProperty(), prop2 = new SigningTimeProperty(); DataObjectFormatProperty prop3 = new DataObjectFormatProperty(); - PropertiesSet instance = new PropertiesSet(2); + PropertiesSet instance = new PropertiesSet<>(2); instance.put(prop1); instance.put(prop3); @@ -77,7 +78,7 @@ void testPut() @Test void testAddNull() { - PropertiesSet instance = new PropertiesSet(0); + PropertiesSet instance = new PropertiesSet<>(0); assertThrows(NullPointerException.class, () -> instance.add(null)); } @@ -88,7 +89,7 @@ void testAddNull() void testAdd() { SigningTimeProperty prop1 = new SigningTimeProperty(), prop2 = new SigningTimeProperty(); - PropertiesSet instance = new PropertiesSet(1); + PropertiesSet instance = new PropertiesSet<>(1); instance.add(prop1); instance.add(prop2); @@ -103,7 +104,7 @@ void testRemove() { System.out.println("remove"); SigningTimeProperty prop1 = new SigningTimeProperty(); - PropertiesSet instance = new PropertiesSet(1); + PropertiesSet instance = new PropertiesSet<>(1); instance.add(prop1); instance.remove(prop1); assertTrue(instance.isEmpty()); @@ -116,7 +117,7 @@ void testRemove() void testRemoveNotPresent() { SigningTimeProperty prop1 = new SigningTimeProperty(), prop2 = new SigningTimeProperty(); - PropertiesSet instance = new PropertiesSet(1); + PropertiesSet instance = new PropertiesSet<>(1); instance.add(prop1); assertThrows(IllegalStateException.class, () -> instance.remove(prop2)); @@ -131,7 +132,7 @@ void testIsEmpty() System.out.println("isEmpty"); SigningTimeProperty prop = new SigningTimeProperty(); - PropertiesSet instance = new PropertiesSet(1); + PropertiesSet instance = new PropertiesSet<>(1); assertTrue(instance.isEmpty()); instance.add(prop); assertFalse(instance.isEmpty()); diff --git a/src/test/java/xades4j/verification/DistinguishedNameComparerTest.java b/src/test/java/xades4j/verification/DistinguishedNameComparerTest.java index cf778410..67525cec 100644 --- a/src/test/java/xades4j/verification/DistinguishedNameComparerTest.java +++ b/src/test/java/xades4j/verification/DistinguishedNameComparerTest.java @@ -1,6 +1,7 @@ package xades4j.verification; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import xades4j.providers.X500NameStyleProvider; import xades4j.providers.impl.DefaultX500NameStyleProvider; @@ -24,7 +25,7 @@ */ public class DistinguishedNameComparerTest extends SignatureServicesTestBase { - public static Collection data() throws Exception + public static Collection data() throws Exception { return List.of( // Certificate includes the value of OID.2.5.4.97 as UTF8String From 4b83a38e69d2da9a0d241aad44698bf7e7eac436 Mon Sep 17 00:00:00 2001 From: Mirko Date: Thu, 16 Nov 2023 17:14:06 +0100 Subject: [PATCH 11/14] prevent CWE-208: Observable Timing Discrepancy --- .../providers/impl/DefaultTimeStampVerificationProvider.java | 4 +--- .../java/xades4j/verification/CompleteRevocRefsVerifier.java | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java b/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java index ac248e05..7fbb95df 100644 --- a/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java +++ b/src/main/java/xades4j/providers/impl/DefaultTimeStampVerificationProvider.java @@ -48,7 +48,6 @@ import java.security.Provider; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; -import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.LinkedList; @@ -163,8 +162,7 @@ public Date verifyToken(byte[] timeStampToken, byte[] tsDigestInput) throws Time { String digestAlgUri = uriForDigest(tsTokenInfo.getMessageImprintAlgOID()); MessageDigest md = messageDigestProvider.getEngine(digestAlgUri); - - if (!Arrays.equals(md.digest(tsDigestInput), tsTokenInfo.getMessageImprintDigest())) + if (!MessageDigest.isEqual(md.digest(tsDigestInput), tsTokenInfo.getMessageImprintDigest())) { throw new TimeStampTokenDigestException(); } diff --git a/src/main/java/xades4j/verification/CompleteRevocRefsVerifier.java b/src/main/java/xades4j/verification/CompleteRevocRefsVerifier.java index 2b604d6a..12c42819 100644 --- a/src/main/java/xades4j/verification/CompleteRevocRefsVerifier.java +++ b/src/main/java/xades4j/verification/CompleteRevocRefsVerifier.java @@ -31,7 +31,6 @@ import java.security.cert.CRLException; import java.security.cert.X509CRL; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; /** @@ -91,7 +90,7 @@ public QualifyingProperty verify( // Check digest value. MessageDigest md = this.digestEngineProvider.getEngine(crlRef.digestAlgUri); - if (Arrays.equals(md.digest(crl.getEncoded()), crlRef.digestValue)) + if (MessageDigest.isEqual(md.digest(crl.getEncoded()), crlRef.digestValue)) { match = crlRef; break; From d1442cfc3e02d4004387ea21630a77c7e5e22f77 Mon Sep 17 00:00:00 2001 From: Mirko Date: Sat, 18 Nov 2023 23:34:31 +0100 Subject: [PATCH 12/14] resolve PR comments --- .../SignatureTimeStampProperty.java | 5 --- ...omPropertiesDataObjsStructureVerifier.java | 2 +- .../impl/HttpTimeStampTokenProvider.java | 2 +- .../utils/FileSystemDirectoryCertStore.java | 33 ++++++++++--------- .../java/xades4j/utils/PropertiesSet.java | 2 +- .../verification/TimeStampVerifierBase.java | 14 ++++++-- .../FromXmlBaseTimeStampConverter.java | 4 +-- 7 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/main/java/xades4j/properties/SignatureTimeStampProperty.java b/src/main/java/xades4j/properties/SignatureTimeStampProperty.java index 924635be..23e4312a 100644 --- a/src/main/java/xades4j/properties/SignatureTimeStampProperty.java +++ b/src/main/java/xades4j/properties/SignatureTimeStampProperty.java @@ -29,11 +29,6 @@ public final class SignatureTimeStampProperty extends UnsignedSignatureProperty /**/ private Date time; - public SignatureTimeStampProperty() - { - // TODO document why this constructor is empty - } - @Override public String getName() { diff --git a/src/main/java/xades4j/properties/data/CustomPropertiesDataObjsStructureVerifier.java b/src/main/java/xades4j/properties/data/CustomPropertiesDataObjsStructureVerifier.java index b00b6b5c..95f862b2 100644 --- a/src/main/java/xades4j/properties/data/CustomPropertiesDataObjsStructureVerifier.java +++ b/src/main/java/xades4j/properties/data/CustomPropertiesDataObjsStructureVerifier.java @@ -24,5 +24,5 @@ */ public interface CustomPropertiesDataObjsStructureVerifier { - public void verifiy(DataGetter dataObjsGetter); + public void verifiy(DataGetter dataObjsGetter) throws PropertyDataStructureException; } diff --git a/src/main/java/xades4j/providers/impl/HttpTimeStampTokenProvider.java b/src/main/java/xades4j/providers/impl/HttpTimeStampTokenProvider.java index 0e53b4a2..8ddeb58f 100644 --- a/src/main/java/xades4j/providers/impl/HttpTimeStampTokenProvider.java +++ b/src/main/java/xades4j/providers/impl/HttpTimeStampTokenProvider.java @@ -45,7 +45,7 @@ public HttpTimeStampTokenProvider(MessageDigestEngineProvider messageDigestProvi this.tsaHttpData = tsaHttpData; if (tsaHttpData.getUsername() != null) { String usrAndPwd = tsaHttpData.getUsername() + ":" + tsaHttpData.getPassword(); - base64TsaUsrAndPwd = Base64.getMimeEncoder().encodeToString(usrAndPwd.getBytes()); + base64TsaUsrAndPwd = Base64.getEncoder().encodeToString(usrAndPwd.getBytes()); } else { base64TsaUsrAndPwd = null; } diff --git a/src/main/java/xades4j/utils/FileSystemDirectoryCertStore.java b/src/main/java/xades4j/utils/FileSystemDirectoryCertStore.java index a1073864..ec1cbe52 100644 --- a/src/main/java/xades4j/utils/FileSystemDirectoryCertStore.java +++ b/src/main/java/xades4j/utils/FileSystemDirectoryCertStore.java @@ -151,21 +151,24 @@ private void transverseDirToFindContent( CertificateFactory cf) throws CertificateException, CRLException { File[] dirContents = dir.listFiles(); - assert dirContents != null; - for (File f : dirContents) { - if (f.isDirectory()) - transverseDirToFindContent(f, contentList, certsFilesExts, crlsFilesExts, cf); - else if (f.isFile()) - try { - if (hasExt(f, certsFilesExts)) - contentList.add(cf.generateCertificate(new FileInputStream(f))); - else if (hasExt(f, crlsFilesExts)) - contentList.add(cf.generateCRL(new FileInputStream(f))); - } catch (FileNotFoundException ex) { - // The file existed right up there! If somehow it doesn't exist - // now, nevermind. - } - } + assert dirContents != null; + for (File f : dirContents) + { + if (f.isDirectory()) + transverseDirToFindContent(f, contentList, certsFilesExts, crlsFilesExts, cf); + else if (f.isFile()) + { + try { + if (hasExt(f, certsFilesExts)) + contentList.add(cf.generateCertificate(new FileInputStream(f))); + else if (hasExt(f, crlsFilesExts)) + contentList.add(cf.generateCRL(new FileInputStream(f))); + } catch (FileNotFoundException ex) { + // The file existed right up there! If somehow it doesn't exist + // now, nevermind. + } + } + } } private boolean hasExt(File f, String[] filesExts) diff --git a/src/main/java/xades4j/utils/PropertiesSet.java b/src/main/java/xades4j/utils/PropertiesSet.java index 959b87b8..1328495f 100644 --- a/src/main/java/xades4j/utils/PropertiesSet.java +++ b/src/main/java/xades4j/utils/PropertiesSet.java @@ -86,7 +86,7 @@ public void add(T prop) throw new NullPointerException("Property cannot be null"); Set propsOfCurrType = properties.computeIfAbsent(prop.getClass(), k -> new HashSet<>(1)); - // No properties of this type have been added. + // Repeated instances are not allowed. if (!propsOfCurrType.add(prop)) throw new PropertyTargetException("Property instance already present"); diff --git a/src/main/java/xades4j/verification/TimeStampVerifierBase.java b/src/main/java/xades4j/verification/TimeStampVerifierBase.java index e1609fcb..109c0c88 100644 --- a/src/main/java/xades4j/verification/TimeStampVerifierBase.java +++ b/src/main/java/xades4j/verification/TimeStampVerifierBase.java @@ -16,16 +16,19 @@ */ package xades4j.verification; +import xades4j.UnsupportedAlgorithmException; import xades4j.properties.QualifyingProperty; import xades4j.properties.data.BaseXAdESTimeStampData; import xades4j.providers.TimeStampTokenDigestException; import xades4j.providers.TimeStampTokenSignatureException; import xades4j.providers.TimeStampTokenStructureException; +import xades4j.providers.TimeStampTokenVerificationException; import xades4j.providers.TimeStampVerificationProvider; import xades4j.utils.CannotAddDataToDigestInputException; import xades4j.utils.TimeStampDigestInput; import xades4j.utils.TimeStampDigestInputFactory; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Date; import java.util.List; @@ -59,7 +62,7 @@ public final QualifyingProperty verify( QualifyingProperty prop = addPropSpecificTimeStampInputAndCreateProperty(propData, digestInput, ctx); byte[] data = digestInput.getBytes(); - /** + /* * Verify the time-stamp tokens on a time-stamp property data object. All * the tokens are verified, but the returned time-stamp is from the last token. */ @@ -70,15 +73,20 @@ public final QualifyingProperty verify( ts = this.tsVerifier.verifyToken(tkn, data); } - // By convention all timestamp property types have a setTime(Date) method + // By convention, all timestamp property types have a setTime(Date) method Method setTimeMethod = prop.getClass().getMethod("setTime", Date.class); setTimeMethod.invoke(prop, ts); return prop; } - catch(Exception ex) + catch(UnsupportedAlgorithmException | IllegalAccessException | InvocationTargetException | + NoSuchMethodException | TimeStampTokenVerificationException ex) { throw getEx(ex, this.propName); } + catch (final CannotAddDataToDigestInputException e) + { + throw new TimeStampDigestInputException(this.propName, e); + } } diff --git a/src/main/java/xades4j/xml/unmarshalling/FromXmlBaseTimeStampConverter.java b/src/main/java/xades4j/xml/unmarshalling/FromXmlBaseTimeStampConverter.java index e712067f..8035d13c 100644 --- a/src/main/java/xades4j/xml/unmarshalling/FromXmlBaseTimeStampConverter.java +++ b/src/main/java/xades4j/xml/unmarshalling/FromXmlBaseTimeStampConverter.java @@ -17,7 +17,7 @@ package xades4j.xml.unmarshalling; import org.apache.xml.security.c14n.Canonicalizer; -import org.w3c.dom.Node; +import org.w3c.dom.Element; import xades4j.algorithms.Algorithm; import xades4j.algorithms.GenericAlgorithm; import xades4j.properties.data.BaseXAdESTimeStampData; @@ -61,7 +61,7 @@ protected void convertTimeStamps( } else { - List params = CollectionUtils.filterByType(xmlCanonMethod.getContent(), Node.class); + List params = CollectionUtils.filterByType(xmlCanonMethod.getContent(), Element.class); c14n = new GenericAlgorithm(xmlCanonMethod.getAlgorithm(), params); } TPropData tsData = createTSData(c14n); From 2cf10926a2e6a6a661355e72ef7c824e86306cc4 Mon Sep 17 00:00:00 2001 From: Mirko Date: Sun, 19 Nov 2023 00:47:36 +0100 Subject: [PATCH 13/14] Revert "bump xmlsec" This reverts commit 01cc710734647a8b781745cce1b36a47febb2e95. --- pom.xml | 2 +- src/main/java/xades4j/utils/ResolverAnonymous.java | 9 +++++---- .../xades4j/utils/TimeStampDigestInputImpl.java | 13 ++++++++----- .../java/xades4j/production/OtherSignerTests.java | 4 +--- .../production/SignedDataObjectsProcessorTest.java | 5 +---- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index 66a3c467..b8bac75c 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,7 @@ org.apache.santuario xmlsec - 4.0.0 + 3.0.3 org.bouncycastle diff --git a/src/main/java/xades4j/utils/ResolverAnonymous.java b/src/main/java/xades4j/utils/ResolverAnonymous.java index b5cb37d3..5115a0cd 100644 --- a/src/main/java/xades4j/utils/ResolverAnonymous.java +++ b/src/main/java/xades4j/utils/ResolverAnonymous.java @@ -16,14 +16,14 @@ */ package xades4j.utils; -import org.apache.xml.security.signature.XMLSignatureStreamInput; +import org.apache.xml.security.signature.XMLSignatureInput; import org.apache.xml.security.utils.resolver.ResourceResolverContext; import org.apache.xml.security.utils.resolver.ResourceResolverSpi; import java.io.InputStream; /** - * Resource resolver for References without an URI attribute. + * Resource resolver for References without a URI attribute. * * @author luis */ @@ -38,8 +38,9 @@ public ResolverAnonymous(InputStream data) } @Override - public XMLSignatureStreamInput engineResolveURI(ResourceResolverContext context) { - return new XMLSignatureStreamInput(this.data); + public XMLSignatureInput engineResolveURI(ResourceResolverContext context) + { + return new XMLSignatureInput(this.data); } @Override diff --git a/src/main/java/xades4j/utils/TimeStampDigestInputImpl.java b/src/main/java/xades4j/utils/TimeStampDigestInputImpl.java index ed3d8a7c..fc35eedb 100644 --- a/src/main/java/xades4j/utils/TimeStampDigestInputImpl.java +++ b/src/main/java/xades4j/utils/TimeStampDigestInputImpl.java @@ -20,7 +20,6 @@ import org.apache.xml.security.signature.Reference; import org.apache.xml.security.signature.XMLSignatureException; import org.apache.xml.security.signature.XMLSignatureInput; -import org.apache.xml.security.signature.XMLSignatureNodeInput; import org.apache.xml.security.transforms.Transform; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -77,7 +76,7 @@ public void addNode(Node n) throws CannotAddDataToDigestInputException throw new NullPointerException(); } - addToDigestInput(new XMLSignatureNodeInput(n), n.getOwnerDocument()); + addToDigestInput(new XMLSignatureInput(n), n.getOwnerDocument()); } private void addToDigestInput(XMLSignatureInput refData, Document doc) throws CannotAddDataToDigestInputException @@ -91,9 +90,13 @@ private void addToDigestInput(XMLSignatureInput refData, Document doc) throws Ca // Fall through to add the bytes resulting from the canonicalization. } - digestInput.write(refData.getBytes()); - digestInput.close(); - + if (refData.isByteArray()) + { + digestInput.write(refData.getBytes()); + } else if (refData.isOctetStream()) + { + StreamUtils.readWrite(refData.getOctetStream(), digestInput); + } } catch (Exception ex) { diff --git a/src/test/java/xades4j/production/OtherSignerTests.java b/src/test/java/xades4j/production/OtherSignerTests.java index 3e5f9b60..4231bd92 100644 --- a/src/test/java/xades4j/production/OtherSignerTests.java +++ b/src/test/java/xades4j/production/OtherSignerTests.java @@ -17,7 +17,6 @@ package xades4j.production; import org.apache.xml.security.signature.XMLSignatureInput; -import org.apache.xml.security.signature.XMLSignatureStreamInput; import org.apache.xml.security.utils.resolver.ResourceResolverContext; import org.apache.xml.security.utils.resolver.ResourceResolverException; import org.apache.xml.security.utils.resolver.ResourceResolverSpi; @@ -37,7 +36,6 @@ import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathFactory; -import java.io.ByteArrayInputStream; import java.util.Iterator; import static org.apache.xml.security.algorithms.MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA256; @@ -110,7 +108,7 @@ static class MyResolverSpi extends ResourceResolverSpi @Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { - XMLSignatureInput input = new XMLSignatureStreamInput(new ByteArrayInputStream(context.attr.getValue().getBytes())); + XMLSignatureInput input = new XMLSignatureInput(context.attr.getValue().getBytes()); resolveCount++; return input; } diff --git a/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java b/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java index bab47737..35fad8c4 100644 --- a/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java +++ b/src/test/java/xades4j/production/SignedDataObjectsProcessorTest.java @@ -21,7 +21,6 @@ import org.apache.xml.security.signature.Reference; import org.apache.xml.security.signature.XMLSignature; import org.apache.xml.security.signature.XMLSignatureInput; -import org.apache.xml.security.signature.XMLSignatureStreamInput; import org.apache.xml.security.utils.Constants; import org.apache.xml.security.utils.resolver.ResourceResolverContext; import org.apache.xml.security.utils.resolver.ResourceResolverSpi; @@ -33,8 +32,6 @@ import xades4j.utils.SignatureServicesTestBase; import xades4j.utils.StringUtils; -import java.io.ByteArrayInputStream; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNull; @@ -120,7 +117,7 @@ void testAddManifest() throws Exception @Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) { - return new XMLSignatureStreamInput(new ByteArrayInputStream(context.uriToResolve.getBytes())); + return new XMLSignatureInput(context.uriToResolve.getBytes()); } @Override From 210c1cc59b85fef07e259f878ad4f9b7e3f7875a Mon Sep 17 00:00:00 2001 From: Mirko Date: Mon, 20 Nov 2023 16:10:31 +0100 Subject: [PATCH 14/14] resolve PR comments pt.2 --- .../xades4j/algorithms/GenericAlgorithm.java | 2 +- .../CommitmentTypePropertyBase.java | 9 ++--- .../properties/data/CommitmentTypeData.java | 9 ++--- .../impl/KeyStoreKeyingDataProvider.java | 37 ++++++------------- .../ToXmlCommitmentTypeConverter.java | 5 +-- .../FromXmlBaseTimeStampConverter.java | 5 +-- .../FromXmlCommitmentTypeConverter.java | 9 ++--- 7 files changed, 28 insertions(+), 48 deletions(-) diff --git a/src/main/java/xades4j/algorithms/GenericAlgorithm.java b/src/main/java/xades4j/algorithms/GenericAlgorithm.java index da4d62f6..fc68e52d 100644 --- a/src/main/java/xades4j/algorithms/GenericAlgorithm.java +++ b/src/main/java/xades4j/algorithms/GenericAlgorithm.java @@ -50,7 +50,7 @@ public GenericAlgorithm(String uri, Node... params) * @param uri the algorithm's URI * @param params the algorithm parameter nodes */ - public GenericAlgorithm(String uri, List params) + public GenericAlgorithm(String uri, List params) { super(uri); this.params = params.isEmpty() ? null : Collections.unmodifiableList(params); diff --git a/src/main/java/xades4j/properties/CommitmentTypePropertyBase.java b/src/main/java/xades4j/properties/CommitmentTypePropertyBase.java index a40163eb..37ffe44c 100644 --- a/src/main/java/xades4j/properties/CommitmentTypePropertyBase.java +++ b/src/main/java/xades4j/properties/CommitmentTypePropertyBase.java @@ -16,11 +16,10 @@ */ package xades4j.properties; +import java.util.Collection; import org.w3c.dom.Element; import xades4j.utils.CollectionUtils; -import java.util.Collection; - /** * Base class for the {@code CommitmentTypeIndication} property. This is a signed property * that qualifies signed data objects. In consequence, XAdES signatures may contain @@ -51,7 +50,7 @@ public abstract class CommitmentTypePropertyBase extends SignedDataObjectPropert /**/ private final String uri; private final String description; - private Collection qualifiers; + private Collection qualifiers; protected CommitmentTypePropertyBase(String uri, String description, TargetMultiplicity targetMult) @@ -94,11 +93,11 @@ public CommitmentTypePropertyBase withQualifier(Element qualifier){ private CommitmentTypePropertyBase addQualifier(Object qualifier){ this.qualifiers = CollectionUtils.newIfNull(this.qualifiers, 2); - this.qualifiers.add((String) qualifier); + this.qualifiers.add(qualifier); return this; } - public Collection getQualifiers(){ + public Collection getQualifiers(){ return CollectionUtils.emptyIfNull(this.qualifiers); } } diff --git a/src/main/java/xades4j/properties/data/CommitmentTypeData.java b/src/main/java/xades4j/properties/data/CommitmentTypeData.java index 947e5cd8..afd092d6 100644 --- a/src/main/java/xades4j/properties/data/CommitmentTypeData.java +++ b/src/main/java/xades4j/properties/data/CommitmentTypeData.java @@ -16,9 +16,8 @@ */ package xades4j.properties.data; -import xades4j.utils.CollectionUtils; - import java.util.Collection; +import xades4j.utils.CollectionUtils; /** * @@ -29,7 +28,7 @@ public final class CommitmentTypeData implements PropertyDataObject private String description; private final String uri; private Collection objReferences; - private Collection qualifiers; + private Collection qualifiers; public CommitmentTypeData(String uri) { @@ -73,11 +72,11 @@ public String getUri() return uri; } - public void setQualifiers(Collection qualifiers){ + public void setQualifiers(Collection qualifiers){ this.qualifiers = qualifiers; } - public Collection getQualifiers(){ + public Collection getQualifiers(){ return this.qualifiers; } } diff --git a/src/main/java/xades4j/providers/impl/KeyStoreKeyingDataProvider.java b/src/main/java/xades4j/providers/impl/KeyStoreKeyingDataProvider.java index 030dc0dd..97e7c014 100644 --- a/src/main/java/xades4j/providers/impl/KeyStoreKeyingDataProvider.java +++ b/src/main/java/xades4j/providers/impl/KeyStoreKeyingDataProvider.java @@ -16,14 +16,8 @@ */ package xades4j.providers.impl; -import xades4j.providers.KeyingDataProvider; -import xades4j.providers.SigningCertChainException; -import xades4j.providers.SigningKeyException; -import xades4j.verification.UnexpectedJCAException; +import static xades4j.providers.impl.KeyStoreKeyingDataProvider.SigningCertificateSelector.Entry; -import javax.security.auth.callback.PasswordCallback; -import java.io.ByteArrayInputStream; -import java.io.IOException; import java.security.GeneralSecurityException; import java.security.KeyStore; import java.security.KeyStore.Builder; @@ -32,16 +26,18 @@ import java.security.PrivateKey; import java.security.UnrecoverableKeyException; import java.security.cert.Certificate; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; import java.util.List; - -import static xades4j.providers.impl.KeyStoreKeyingDataProvider.SigningCertificateSelector.Entry; +import java.util.stream.Collectors; +import javax.security.auth.callback.PasswordCallback; +import xades4j.providers.KeyingDataProvider; +import xades4j.providers.SigningCertChainException; +import xades4j.providers.SigningKeyException; +import xades4j.verification.UnexpectedJCAException; /** * A KeyStore-based implementation of {@code KeyingDataProvider}. The keystore is @@ -255,8 +251,9 @@ public List getSigningCertificateChain() throws SigningCertChai if (this.returnFullChain) { - List lChain = Arrays.asList( signingCertChain); - return Collections.checkedList(getX509Certificates(lChain), X509Certificate.class); + return Arrays.stream(signingCertChain) + .map(it -> (X509Certificate)it) + .collect(Collectors.toList()); } else { @@ -264,7 +261,7 @@ public List getSigningCertificateChain() throws SigningCertChai } } - catch (KeyStoreException | CertificateException | IOException ex) + catch (KeyStoreException ex) { // keyStore.getCertificateAlias, keyStore.getCertificateChain -> if the // keystore is not loaded. @@ -272,18 +269,6 @@ public List getSigningCertificateChain() throws SigningCertChai } } - private static List getX509Certificates(List lChain) throws CertificateException, IOException { - List lChainX509 = new ArrayList<>(); - CertificateFactory cf = CertificateFactory.getInstance("X.509"); - for(Certificate certificate : lChain) { - try (ByteArrayInputStream bais = new ByteArrayInputStream(certificate.getEncoded())) { - X509Certificate x509 = (X509Certificate) cf.generateCertificate(bais); - lChainX509.add(x509); - } - } - return lChainX509; - } - @Override public PrivateKey getSigningKey(X509Certificate signingCert) throws SigningKeyException, UnexpectedJCAException { diff --git a/src/main/java/xades4j/xml/marshalling/ToXmlCommitmentTypeConverter.java b/src/main/java/xades4j/xml/marshalling/ToXmlCommitmentTypeConverter.java index 54b262ae..3fdcf33c 100644 --- a/src/main/java/xades4j/xml/marshalling/ToXmlCommitmentTypeConverter.java +++ b/src/main/java/xades4j/xml/marshalling/ToXmlCommitmentTypeConverter.java @@ -16,6 +16,7 @@ */ package xades4j.xml.marshalling; +import java.util.Collection; import org.w3c.dom.Document; import xades4j.properties.data.CommitmentTypeData; import xades4j.properties.data.PropertyDataObject; @@ -26,8 +27,6 @@ import xades4j.xml.bind.xades.XmlObjectIdentifierType; import xades4j.xml.bind.xades.XmlSignedPropertiesType; -import java.util.Collection; - /** * * @author Luís @@ -63,7 +62,7 @@ public void convertIntoObjectTree( xmlCommitmentTypeProp.getObjectReference().addAll(refsUris); } - Collection qualifiers = commitmentTypeData.getQualifiers(); + Collection qualifiers = commitmentTypeData.getQualifiers(); if (!qualifiers.isEmpty()) { XmlCommitmentTypeQualifiersListType xmlQualifiers = new XmlCommitmentTypeQualifiersListType(); diff --git a/src/main/java/xades4j/xml/unmarshalling/FromXmlBaseTimeStampConverter.java b/src/main/java/xades4j/xml/unmarshalling/FromXmlBaseTimeStampConverter.java index 8035d13c..985f20a1 100644 --- a/src/main/java/xades4j/xml/unmarshalling/FromXmlBaseTimeStampConverter.java +++ b/src/main/java/xades4j/xml/unmarshalling/FromXmlBaseTimeStampConverter.java @@ -16,6 +16,7 @@ */ package xades4j.xml.unmarshalling; +import java.util.List; import org.apache.xml.security.c14n.Canonicalizer; import org.w3c.dom.Element; import xades4j.algorithms.Algorithm; @@ -26,8 +27,6 @@ import xades4j.xml.bind.xades.XmlXAdESTimeStampType; import xades4j.xml.bind.xmldsig.XmlCanonicalizationMethodType; -import java.util.List; - /** * * @author Luís @@ -61,7 +60,7 @@ protected void convertTimeStamps( } else { - List params = CollectionUtils.filterByType(xmlCanonMethod.getContent(), Element.class); + List params = CollectionUtils.filterByType(xmlCanonMethod.getContent(), Element.class); c14n = new GenericAlgorithm(xmlCanonMethod.getAlgorithm(), params); } TPropData tsData = createTSData(c14n); diff --git a/src/main/java/xades4j/xml/unmarshalling/FromXmlCommitmentTypeConverter.java b/src/main/java/xades4j/xml/unmarshalling/FromXmlCommitmentTypeConverter.java index dd1be923..465764ea 100644 --- a/src/main/java/xades4j/xml/unmarshalling/FromXmlCommitmentTypeConverter.java +++ b/src/main/java/xades4j/xml/unmarshalling/FromXmlCommitmentTypeConverter.java @@ -16,6 +16,9 @@ */ package xades4j.xml.unmarshalling; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import xades4j.properties.CommitmentTypePropertyBase; import xades4j.properties.data.CommitmentTypeData; import xades4j.xml.bind.xades.XmlAnyType; @@ -23,10 +26,6 @@ import xades4j.xml.bind.xades.XmlCommitmentTypeQualifiersListType; import xades4j.xml.bind.xades.XmlSignedDataObjectPropertiesType; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - /** * * @author Luís @@ -70,7 +69,7 @@ public void convertFromObjectTree( XmlCommitmentTypeQualifiersListType xmlQualifiers = xmlCommitment.getCommitmentTypeQualifiers(); if (xmlQualifiers != null) { - Collection qualifiers = new ArrayList<>(); + Collection qualifiers = new ArrayList<>(); for (XmlAnyType xmlQualifier : xmlQualifiers.getCommitmentTypeQualifier()) { if (!xmlQualifier.getContent().isEmpty())