Skip to content

Commit

Permalink
Upgrade Apache Santuario to version 4.X.X - issue luisgoncalves#277
Browse files Browse the repository at this point in the history
  • Loading branch information
mjechow committed Nov 21, 2023
1 parent ecc634c commit 622a244
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 36 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<dependency>
<groupId>org.apache.santuario</groupId>
<artifactId>xmlsec</artifactId>
<version>3.0.3</version>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/xades4j/utils/ResolverAnonymous.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +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.ResourceResolverSpi;

import java.io.InputStream;

/**
* Resource resolver for References without a URI attribute.
*
Expand All @@ -40,7 +40,7 @@ public ResolverAnonymous(InputStream data)
@Override
public XMLSignatureInput engineResolveURI(ResourceResolverContext context)
{
return new XMLSignatureInput(this.data);
return new XMLSignatureStreamInput(this.data);
}

@Override
Expand Down
12 changes: 3 additions & 9 deletions src/main/java/xades4j/utils/TimeStampDigestInputImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -89,14 +90,7 @@ private void addToDigestInput(XMLSignatureInput refData, Document doc) throws Ca
refData = c14nTransform.performTransform(refData, true);
// 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());
}
catch (Exception ex)
{
Expand Down
32 changes: 16 additions & 16 deletions src/test/java/xades4j/production/OtherSignerTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@
*/
package xades4j.production;

import static org.apache.xml.security.algorithms.MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA256;
import static org.apache.xml.security.algorithms.MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA512;
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.SignatureSpecNS;
import static org.apache.xml.security.utils.Constants._TAG_SIGNATURE;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Iterator;
import javax.xml.namespace.NamespaceContext;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import org.apache.xml.security.signature.XMLSignatureByteInput;
import org.apache.xml.security.signature.XMLSignatureInput;
import org.apache.xml.security.utils.resolver.ResourceResolverContext;
import org.apache.xml.security.utils.resolver.ResourceResolverException;
Expand All @@ -32,21 +47,6 @@
import xades4j.providers.impl.ValidationDataFromCertValidationProvider;
import xades4j.verification.VerifierTestBase;

import javax.xml.namespace.NamespaceContext;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import java.util.Iterator;

import static org.apache.xml.security.algorithms.MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA256;
import static org.apache.xml.security.algorithms.MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA512;
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.SignatureSpecNS;
import static org.apache.xml.security.utils.Constants._TAG_SIGNATURE;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* @author Luís
*/
Expand Down Expand Up @@ -108,7 +108,7 @@ static class MyResolverSpi extends ResourceResolverSpi
@Override
public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException
{
XMLSignatureInput input = new XMLSignatureInput(context.attr.getValue().getBytes());
XMLSignatureByteInput input = new XMLSignatureByteInput(context.attr.getValue().getBytes());
resolveCount++;
return input;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@
*/
package xades4j.production;

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;

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.XMLSignatureByteInput;
import org.apache.xml.security.signature.XMLSignatureInput;
import org.apache.xml.security.utils.Constants;
import org.apache.xml.security.utils.resolver.ResourceResolverContext;
Expand All @@ -32,12 +39,6 @@
import xades4j.utils.SignatureServicesTestBase;
import xades4j.utils.StringUtils;

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
*/
Expand Down Expand Up @@ -117,7 +118,7 @@ void testAddManifest() throws Exception
@Override
public XMLSignatureInput engineResolveURI(ResourceResolverContext context)
{
return new XMLSignatureInput(context.uriToResolve.getBytes());
return new XMLSignatureByteInput(context.uriToResolve.getBytes());
}

@Override
Expand Down

0 comments on commit 622a244

Please sign in to comment.