You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by mu...@apache.org on 2011/07/11 17:32:14 UTC
svn commit: r1145204 - in /santuario/xml-security-java/trunk: ./
src/main/java/org/jcp/xml/dsig/internal/dom/
src/test/java/javax/xml/crypto/test/dsig/
src/test/resources/javax/xml/crypto/dsig/
Author: mullan
Date: Mon Jul 11 15:32:14 2011
New Revision: 1145204
URL: http://svn.apache.org/viewvc?rev=1145204&view=rev
Log:
Fixed SANTUARIO-283: JSR105 does not retain namespace definitions on Object element when unmarshalling
Added:
santuario/xml-security-java/trunk/src/test/resources/javax/xml/crypto/dsig/signature-enveloping-rsa-template.xml
Modified:
santuario/xml-security-java/trunk/CHANGELOG.txt
santuario/xml-security-java/trunk/src/main/java/org/jcp/xml/dsig/internal/dom/DOMXMLObject.java
santuario/xml-security-java/trunk/src/main/java/org/jcp/xml/dsig/internal/dom/DOMXMLSignatureFactory.java
santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignatureTest.java
Modified: santuario/xml-security-java/trunk/CHANGELOG.txt
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/CHANGELOG.txt?rev=1145204&r1=1145203&r2=1145204&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/CHANGELOG.txt (original)
+++ santuario/xml-security-java/trunk/CHANGELOG.txt Mon Jul 11 15:32:14 2011
@@ -1,6 +1,7 @@
Changelog for "Apache xml-security" <http://santuario.apache.org/>
New in v1.5.0-SNAPSHOT
+ Fixed SANTUARIO-283: JSR105 does not retain namespace definitions on Object element when unmarshalling
Fixed SANTUARIO-250: VerifyMerlinsExamplesFifteen/TwentyThree.java samples should ignore signature-enveloping-hmac-sha1-40.xml
Fixed SANTUARIO-191: xml:id attributes are not correctly handled when using c14n11.
Fixed SANTUARIO-266: c14n11 produces different signatures using version 1.4.3 and 1.4.4.
Modified: santuario/xml-security-java/trunk/src/main/java/org/jcp/xml/dsig/internal/dom/DOMXMLObject.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/jcp/xml/dsig/internal/dom/DOMXMLObject.java?rev=1145204&r1=1145203&r2=1145204&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/jcp/xml/dsig/internal/dom/DOMXMLObject.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/jcp/xml/dsig/internal/dom/DOMXMLObject.java Mon Jul 11 15:32:14 2011
@@ -46,6 +46,7 @@ public final class DOMXMLObject extends
private final String mimeType;
private final String encoding;
private final List<XMLStructure> content;
+ private Element objectElem;
/**
* Creates an <code>XMLObject</code> from the specified parameters.
@@ -127,6 +128,7 @@ public final class DOMXMLObject extends
} else {
this.content = Collections.unmodifiableList(content);
}
+ this.objectElem = objElem;
}
public List getContent() {
@@ -149,22 +151,25 @@ public final class DOMXMLObject extends
throws MarshalException {
Document ownerDoc = DOMUtils.getOwnerDocument(parent);
- Element objElem = DOMUtils.createElement(ownerDoc, "Object",
- XMLSignature.XMLNS, dsPrefix);
-
- // set attributes
- DOMUtils.setAttributeID(objElem, "Id", id);
- DOMUtils.setAttribute(objElem, "MimeType", mimeType);
- DOMUtils.setAttribute(objElem, "Encoding", encoding);
-
- // create and append any elements and mixed content, if necessary
- for (XMLStructure object : content) {
- if (object instanceof DOMStructure) {
- ((DOMStructure)object).marshal(objElem, dsPrefix, context);
- } else {
- javax.xml.crypto.dom.DOMStructure domObject =
- (javax.xml.crypto.dom.DOMStructure)object;
- DOMUtils.appendChild(objElem, domObject.getNode());
+ Element objElem = objectElem != null ? objectElem : null;
+ if (objElem == null) {
+ objElem = DOMUtils.createElement(ownerDoc, "Object",
+ XMLSignature.XMLNS, dsPrefix);
+
+ // set attributes
+ DOMUtils.setAttributeID(objElem, "Id", id);
+ DOMUtils.setAttribute(objElem, "MimeType", mimeType);
+ DOMUtils.setAttribute(objElem, "Encoding", encoding);
+
+ // create and append any elements and mixed content, if necessary
+ for (XMLStructure object : content) {
+ if (object instanceof DOMStructure) {
+ ((DOMStructure)object).marshal(objElem, dsPrefix, context);
+ } else {
+ javax.xml.crypto.dom.DOMStructure domObject =
+ (javax.xml.crypto.dom.DOMStructure)object;
+ DOMUtils.appendChild(objElem, domObject.getNode());
+ }
}
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/jcp/xml/dsig/internal/dom/DOMXMLSignatureFactory.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/jcp/xml/dsig/internal/dom/DOMXMLSignatureFactory.java?rev=1145204&r1=1145203&r2=1145204&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/jcp/xml/dsig/internal/dom/DOMXMLSignatureFactory.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/jcp/xml/dsig/internal/dom/DOMXMLSignatureFactory.java Mon Jul 11 15:32:14 2011
@@ -25,6 +25,7 @@
package org.jcp.xml.dsig.internal.dom;
import javax.xml.crypto.*;
+import javax.xml.crypto.dom.DOMCryptoContext;
import javax.xml.crypto.dsig.*;
import javax.xml.crypto.dsig.dom.DOMValidateContext;
import javax.xml.crypto.dsig.keyinfo.*;
@@ -142,10 +143,14 @@ public final class DOMXMLSignatureFactor
}
return unmarshal
(((javax.xml.crypto.dom.DOMStructure) xmlStructure).getNode(),
- null);
+ new UnmarshalContext());
}
- private XMLSignature unmarshal(Node node, XMLValidateContext context)
+ private static class UnmarshalContext extends DOMCryptoContext {
+ UnmarshalContext() {}
+ }
+
+ private XMLSignature unmarshal(Node node, XMLCryptoContext context)
throws MarshalException {
node.normalize();
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignatureTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignatureTest.java?rev=1145204&r1=1145203&r2=1145204&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignatureTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignatureTest.java Mon Jul 11 15:32:14 2011
@@ -21,6 +21,7 @@
*/
package javax.xml.crypto.test.dsig;
+import java.io.*;
import java.util.*;
import java.security.*;
import javax.xml.crypto.URIDereferencer;
@@ -30,10 +31,10 @@ import javax.xml.crypto.dsig.keyinfo.*;
import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec;
import javax.xml.crypto.dsig.dom.DOMSignContext;
import javax.xml.crypto.dsig.dom.DOMValidateContext;
+import javax.xml.parsers.*;
import javax.crypto.spec.SecretKeySpec;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
+import org.w3c.dom.*;
import junit.framework.*;
@@ -297,6 +298,46 @@ public class XMLSignatureTest extends Te
}
}
+ public void testSignTemplateWithObjectNSDefs() throws Exception {
+ String base = System.getProperty("basedir") == null ? "./"
+ : System.getProperty("basedir");
+
+ File f = new File(base + "/src/test/resources/javax/xml/crypto/dsig/" +
+ "signature-enveloping-rsa-template.xml");
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ Document doc = dbf.newDocumentBuilder().parse(new FileInputStream(f));
+
+ // Find Signature element
+ NodeList nl =
+ doc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
+ if (nl.getLength() == 0) {
+ throw new Exception("Cannot find Signature element");
+ }
+ DOMStructure domSignature = new DOMStructure(nl.item(0));
+ // unmarshal the XMLSignature
+ XMLSignature signature = fac.unmarshalXMLSignature(domSignature);
+
+ // create copy of Signature
+ XMLSignature newSignature = fac.newXMLSignature
+ (signature.getSignedInfo(), null, signature.getObjects(),
+ signature.getId(), signature.getSignatureValue().getId());
+
+ // Sign the template
+ Node parent = domSignature.getNode().getParentNode();
+ DOMSignContext signContext = new DOMSignContext(SIGN_KEYS[0], parent);
+ // remove the signature node (since it will get recreated)
+ parent.removeChild(domSignature.getNode());
+ newSignature.sign(signContext);
+
+ // check that Object element retained namespace definitions
+ Element objElem = (Element)parent.getFirstChild().getLastChild();
+ Attr a = objElem.getAttributeNode("xmlns:test");
+ if (!a.getValue().equals("http://www.example.org/ns"))
+ throw new Exception("Object namespace definition not retained");
+ }
+
private SignedInfo createSignedInfo(SignatureMethod sm) throws Exception {
// set up the building blocks
CanonicalizationMethod cm = fac.newCanonicalizationMethod
Added: santuario/xml-security-java/trunk/src/test/resources/javax/xml/crypto/dsig/signature-enveloping-rsa-template.xml
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/resources/javax/xml/crypto/dsig/signature-enveloping-rsa-template.xml?rev=1145204&view=auto
==============================================================================
--- santuario/xml-security-java/trunk/src/test/resources/javax/xml/crypto/dsig/signature-enveloping-rsa-template.xml (added)
+++ santuario/xml-security-java/trunk/src/test/resources/javax/xml/crypto/dsig/signature-enveloping-rsa-template.xml Mon Jul 11 15:32:14 2011
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
+ <SignedInfo>
+ <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
+ <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1" />
+ <Reference URI="#object">
+ <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
+ <DigestValue></DigestValue>
+ </Reference>
+ </SignedInfo>
+ <SignatureValue>
+ </SignatureValue>
+ <Object xmlns:test="http://www.example.org/ns" Id="object">
+ <test:someElem />
+ <test:someElem />
+ </Object>
+</Signature>