You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by gi...@apache.org on 2012/07/23 20:43:18 UTC
svn commit: r1364748 - in /santuario/xml-security-java/trunk/src:
main/java/org/apache/xml/security/stax/impl/processor/input/
test/java/org/apache/xml/security/test/stax/signature/
Author: giger
Date: Mon Jul 23 18:43:17 2012
New Revision: 1364748
URL: http://svn.apache.org/viewvc?rev=1364748&view=rev
Log:
do c14n for enveloped signatures when no c14n is specified, Fix for SANTUARIO-320
Modified:
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureInputHandler.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/PhaosTest.java
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureInputHandler.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureInputHandler.java?rev=1364748&r1=1364747&r2=1364748&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureInputHandler.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureInputHandler.java Mon Jul 23 18:43:17 2012
@@ -168,10 +168,16 @@ public abstract class AbstractSignatureI
retrieveSecurityToken(keyInfoType, securityProperties, securityContext);
securityToken.verify();
+ handleSecurityToken(securityToken);
try {
- handleSecurityToken(securityToken);
createSignatureAlgorithm(securityToken, signatureType);
- } catch (Exception e) {
+ } catch (InvalidKeyException e) {
+ throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
+ } catch (NoSuchAlgorithmException e) {
+ throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
+ } catch (NoSuchProviderException e) {
+ throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
+ } catch (CertificateException e) {
throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
}
this.securityToken = securityToken;
@@ -243,14 +249,14 @@ public abstract class AbstractSignatureI
try {
transformer.doFinal();
bufferedSignerOutputStream.close();
- if (!signerOutputStream.verify(signatureType.getSignatureValue().getValue())) {
- throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK);
- }
} catch (IOException e) {
throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
} catch (XMLStreamException e) {
throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, e);
}
+ if (!signerOutputStream.verify(signatureType.getSignatureValue().getValue())) {
+ throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK);
+ }
}
}
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java?rev=1364748&r1=1364747&r2=1364748&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java Mon Jul 23 18:43:17 2012
@@ -285,7 +285,7 @@ public abstract class AbstractSignatureR
throws XMLSecurityException, XMLStreamException, NoSuchMethodException, InstantiationException,
IllegalAccessException, InvocationTargetException {
- if (referenceType.getTransforms() == null) {
+ if (referenceType.getTransforms() == null || referenceType.getTransforms().getTransform().isEmpty()) {
// If no Transforms then just default to an Inclusive without comments transform
Transformer transformer = new Canonicalizer20010315_OmitCommentsTransformer();
transformer.setOutputStream(outputStream);
@@ -295,6 +295,13 @@ public abstract class AbstractSignatureR
List<TransformType> transformTypeList = referenceType.getTransforms().getTransform();
+ if (transformTypeList.size() == 1 &&
+ XMLSecurityConstants.NS_XMLDSIG_ENVELOPED_SIGNATURE.equals(transformTypeList.get(0).getAlgorithm())) {
+ TransformType transformType = new TransformType();
+ transformType.setAlgorithm("http://www.w3.org/TR/2001/REC-xml-c14n-20010315");
+ transformTypeList.add(transformType);
+ }
+
Transformer parentTransformer = null;
for (int i = transformTypeList.size() - 1; i >= 0; i--) {
TransformType transformType = transformTypeList.get(i);
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/PhaosTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/PhaosTest.java?rev=1364748&r1=1364747&r2=1364748&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/PhaosTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/PhaosTest.java Mon Jul 23 18:43:17 2012
@@ -36,9 +36,11 @@ import javax.xml.transform.stream.Stream
import org.apache.xml.security.stax.config.Init;
import org.apache.xml.security.stax.ext.InboundXMLSec;
import org.apache.xml.security.stax.ext.XMLSec;
+import org.apache.xml.security.stax.ext.XMLSecurityException;
import org.apache.xml.security.stax.ext.XMLSecurityProperties;
import org.apache.xml.security.test.stax.utils.StAX2DOM;
import org.apache.xml.security.test.stax.utils.XMLSecEventAllocator;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -102,7 +104,6 @@ public class PhaosTest extends org.junit
// See Santuario-320
@Test
- @org.junit.Ignore
public void test_signature_dsa_enveloped() throws Exception {
// Read in plaintext document
InputStream sourceDocument =
@@ -195,7 +196,6 @@ public class PhaosTest extends org.junit
// See Santuario-320
@Test
- @org.junit.Ignore
public void test_signature_hmac_sha1_exclusive_c14n_enveloped() throws Exception {
// Read in plaintext document
InputStream sourceDocument =
@@ -293,7 +293,6 @@ public class PhaosTest extends org.junit
// See Santuario-320
@Test
- @org.junit.Ignore
public void test_signature_rsa_enveloped_bad_digest_val() throws Exception {
// Read in plaintext document
InputStream sourceDocument =
@@ -315,17 +314,18 @@ public class PhaosTest extends org.junit
XMLSecurityProperties properties = new XMLSecurityProperties();
InboundXMLSec inboundXMLSec = XMLSec.getInboundWSSec(properties);
TestSecurityEventListener securityEventListener = new TestSecurityEventListener();
+ XMLStreamReader securityStreamReader = inboundXMLSec.processInMessage(xmlStreamReader, null, securityEventListener);
try {
- inboundXMLSec.processInMessage(xmlStreamReader, null, securityEventListener);
+ StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), securityStreamReader);
fail("Failure expected on a bad digest");
} catch (XMLStreamException ex) {
- // expected
+ Assert.assertTrue(ex.getCause() instanceof XMLSecurityException);
+ Assert.assertEquals("The signature or decryption was invalid", ex.getCause().getMessage());
}
}
// See Santuario-320
@Test
- @org.junit.Ignore
public void test_signature_rsa_enveloped() throws Exception {
// Read in plaintext document
InputStream sourceDocument =