Skip to content

Commit

Permalink
Upgrade Apache Santuario to 2.3.0 (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
luisgoncalves committed Jun 28, 2022
1 parent aeb11ad commit 076f1d4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<dependency>
<groupId>org.apache.santuario</groupId>
<artifactId>xmlsec</artifactId>
<version>2.2.3</version>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
Expand Down
Binary file added src/test/cert/gva/raizaccv1_der_11.crl
Binary file not shown.
45 changes: 26 additions & 19 deletions src/test/java/xades4j/production/SignerBESTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
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.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Expand All @@ -37,15 +40,14 @@
import java.io.File;

/**
*
* @author Luís
*/
public class SignerBESTest extends SignerTestBase
{
public SignerBESTest()
{
}

@Test
public void testSignBES() throws Exception
{
Expand All @@ -59,7 +61,7 @@ public void testSignBES() throws Exception

IndividualDataObjsTimeStampProperty dataObjsTimeStamp = new IndividualDataObjsTimeStampProperty();
AllDataObjsCommitmentTypeProperty globalCommitment = AllDataObjsCommitmentTypeProperty.proofOfApproval();
CommitmentTypeProperty commitment = (CommitmentTypeProperty)CommitmentTypeProperty.proofOfCreation().withQualifier("MyQualifier");
CommitmentTypeProperty commitment = (CommitmentTypeProperty) CommitmentTypeProperty.proofOfCreation().withQualifier("MyQualifier");
DataObjectDesc obj1 = new DataObjectReference('#' + elemToSign.getAttribute("Id")).withTransform(new EnvelopedSignatureTransform()).withDataObjectFormat(new DataObjectFormatProperty("text/xml", "MyEncoding").withDescription("Isto é uma descrição do elemento raiz").withDocumentationUri("http://doc1.txt").withDocumentationUri("http://doc2.txt").withIdentifier("http://elem.root")).withCommitmentType(commitment).withDataObjectTimeStamp(dataObjsTimeStamp);
DataObjectDesc obj2 = new EnvelopedXmlObject(objectContent, "text/xml", null).withDataObjectFormat(new DataObjectFormatProperty("text/xml", "MyEncoding").withDescription("Isto é uma descrição do elemento dentro do object").withDocumentationUri("http://doc3.txt").withDocumentationUri("http://doc4.txt").withIdentifier("http://elem.in.object")).withCommitmentType(commitment).withDataObjectTimeStamp(dataObjsTimeStamp);
SignedDataObjects dataObjs = new SignedDataObjects(obj1, obj2).withCommitmentType(globalCommitment).withDataObjectsTimeStamp();
Expand Down Expand Up @@ -96,7 +98,10 @@ public void testSignBESExternalRes() throws Exception
DataObjectDesc obj1 = new DataObjectReference("logo-01.png")
.withDataObjectFormat(new DataObjectFormatProperty("image/png").withDescription("XAdES4j logo"))
.withDataObjectTimeStamp(new IndividualDataObjsTimeStampProperty());
signer.sign(new SignedDataObjects(obj1).withBaseUri("http://luisgoncalves.github.io/xades4j/images/"), doc);
signer.sign(new SignedDataObjects(obj1)
.withBaseUri("http://luisgoncalves.github.io/xades4j/images/")
.withResourceResolver(new ResolverDirectHTTP()),
doc);

outputDocument(doc, "document.signed.bes.extres.xml");
}
Expand Down Expand Up @@ -135,31 +140,33 @@ public void provideProperties(
public void testSignBESDetachedWithXPathAndNamespaces() throws Exception
{
System.out.println("signBESDetachedWithXPathAndNamespaces");

Document doc = getNewDocument();

XadesSigner signer = new XadesBesSigningProfile(keyingProviderMy)
.withBasicSignatureOptions(new BasicSignatureOptions()
.includeSigningCertificate(SigningCertificateMode.SIGNING_CERTIFICATE)
.includeIssuerSerial(true)
.includeSubjectName(true)
.signKeyInfo(true))
.includeSigningCertificate(SigningCertificateMode.SIGNING_CERTIFICATE)
.includeIssuerSerial(true)
.includeSubjectName(true)
.signKeyInfo(true))
.newSigner();

DataObjectDesc obj1 = new DataObjectReference("document.xml")
.withTransform(
new XPathTransform("/collection/album/foo:tracks")
.withNamespace("foo", "http://test.xades4j/tracks"))
new XPathTransform("/collection/album/foo:tracks")
.withNamespace("foo", "http://test.xades4j/tracks"))
.withDataObjectFormat(new DataObjectFormatProperty("text/xml"));

DataObjectDesc obj2 = new DataObjectReference("document.xml")
.withTransform(
XPath2Filter.intersect("/collection/album/bar:tracks/bar:song[@tracknumber = 1]")
.withNamespace("bar", "http://test.xades4j/tracks"));

SignedDataObjects objs = new SignedDataObjects(obj1, obj2).withBaseUri(new File("src/test/xml/").toURI().toString());
XPath2Filter.intersect("/collection/album/bar:tracks/bar:song[@tracknumber = 1]")
.withNamespace("bar", "http://test.xades4j/tracks"));

SignedDataObjects objs = new SignedDataObjects(obj1, obj2)
.withBaseUri(new File("src/test/xml/").toURI().toString())
.withResourceResolver(new ResolverLocalFilesystem());
signer.sign(objs, doc);

outputDocument(doc, "detached.bes.xml");
}
}
10 changes: 8 additions & 2 deletions src/test/java/xades4j/verification/XadesVerifierImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import java.util.stream.Collectors;

import org.apache.xml.security.signature.XMLSignature;
import org.apache.xml.security.utils.resolver.implementations.ResolverDirectHTTP;
import org.apache.xml.security.utils.resolver.implementations.ResolverLocalFilesystem;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
Expand Down Expand Up @@ -171,7 +173,9 @@ public void testVerifyDetachedBES() throws Exception
{
var result = verifySignature(
"detached.bes.xml",
new SignatureSpecificVerificationOptions().useBaseUri(new File("src/test/xml/").toURI().toString()));
new SignatureSpecificVerificationOptions()
.useBaseUri(new File("src/test/xml/").toURI().toString())
.useResourceResolver(new ResolverLocalFilesystem()));

assertEquals(XAdESForm.BES, result.getSignatureForm());

Expand Down Expand Up @@ -229,7 +233,9 @@ public void testVerifyBESExtrnlResEnrichC() throws Exception

Document doc = getDocument("document.signed.bes.extres.xml");
Element signatureNode = getSigElement(doc);
SignatureSpecificVerificationOptions options = new SignatureSpecificVerificationOptions().useBaseUri("http://luisgoncalves.github.io/xades4j/images/");
SignatureSpecificVerificationOptions options = new SignatureSpecificVerificationOptions()
.useBaseUri("http://luisgoncalves.github.io/xades4j/images/")
.useResourceResolver(new ResolverDirectHTTP());

XadesSignatureFormatExtender formExt = new XadesFormatExtenderProfile().with(DEFAULT_TEST_TSA).getFormatExtender();

Expand Down

0 comments on commit 076f1d4

Please sign in to comment.