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 2008/02/25 21:55:51 UTC
svn commit: r630988 [2/2] - in /xml/security/trunk/src/org:
apache/xml/security/c14n/ apache/xml/security/c14n/implementations/
apache/xml/security/resource/ apache/xml/security/signature/
apache/xml/security/transforms/ apache/xml/security/transforms/...
Modified: xml/security/trunk/src/org/apache/xml/security/transforms/Transforms.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/apache/xml/security/transforms/Transforms.java?rev=630988&r1=630987&r2=630988&view=diff
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/transforms/Transforms.java (original)
+++ xml/security/trunk/src/org/apache/xml/security/transforms/Transforms.java Mon Feb 25 12:55:47 2008
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2008 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
*/
package org.apache.xml.security.transforms;
-
-
import java.io.IOException;
import java.io.OutputStream;
@@ -35,11 +33,13 @@
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
-
/**
- * Holder of the {@link org.apache.xml.security.transforms.Transform} steps to be performed on the data.
- * The input to the first Transform is the result of dereferencing the <code>URI</code> attribute of the <code>Reference</code> element.
- * The output from the last Transform is the input for the <code>DigestMethod algorithm</code>
+ * Holder of the {@link org.apache.xml.security.transforms.Transform} steps to
+ * be performed on the data.
+ * The input to the first Transform is the result of dereferencing the
+ * <code>URI</code> attribute of the <code>Reference</code> element.
+ * The output from the last Transform is the input for the
+ * <code>DigestMethod algorithm</code>
*
* @author Christian Geuer-Pollmann
* @see Transform
@@ -47,248 +47,273 @@
*/
public class Transforms extends SignatureElementProxy {
- /** {@link org.apache.commons.logging} logging facility */
+ /** {@link org.apache.commons.logging} logging facility */
static org.apache.commons.logging.Log log =
org.apache.commons.logging.LogFactory.getLog(Transforms.class.getName());
- //J-
- /** Canonicalization - Required Canonical XML (omits comments) */
- public static final String TRANSFORM_C14N_OMIT_COMMENTS = Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS;
- /** Canonicalization - Recommended Canonical XML with Comments */
- public static final String TRANSFORM_C14N_WITH_COMMENTS = Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS;
- /** Canonicalization - Required Exclusive Canonicalization (omits comments) */
- public static final String TRANSFORM_C14N_EXCL_OMIT_COMMENTS = Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS;
- /** Canonicalization - Recommended Exclusive Canonicalization with Comments */
- public static final String TRANSFORM_C14N_EXCL_WITH_COMMENTS = Canonicalizer.ALGO_ID_C14N_EXCL_WITH_COMMENTS;
- /** Transform - Optional XSLT */
- public static final String TRANSFORM_XSLT = "http://www.w3.org/TR/1999/REC-xslt-19991116";
- /** Transform - Required base64 decoding */
- public static final String TRANSFORM_BASE64_DECODE = Constants.SignatureSpecNS + "base64";
- /** Transform - Recommended XPath */
- public static final String TRANSFORM_XPATH = "http://www.w3.org/TR/1999/REC-xpath-19991116";
- /** Transform - Required Enveloped Signature */
- public static final String TRANSFORM_ENVELOPED_SIGNATURE = Constants.SignatureSpecNS + "enveloped-signature";
- /** Transform - XPointer */
- public static final String TRANSFORM_XPOINTER = "http://www.w3.org/TR/2001/WD-xptr-20010108";
- /** Transform - XPath Filter v2.0 */
- public static final String TRANSFORM_XPATH2FILTER04 = "http://www.w3.org/2002/04/xmldsig-filter2";
- /** Transform - XPath Filter */
- public static final String TRANSFORM_XPATH2FILTER = "http://www.w3.org/2002/06/xmldsig-filter2";
- /** Transform - XPath Filter CHGP private*/
- public static final String TRANSFORM_XPATHFILTERCHGP = "http://www.nue.et-inf.uni-siegen.de/~geuer-pollmann/#xpathFilter";
- //J+
- Element []transforms;
- protected Transforms() {
- };
- /**
- * Consturcts {@link Transforms}
- *
- * @param doc the {@link Document} in which <code>XMLsignature</code> will be placed
- */
- public Transforms(Document doc) {
-
- super(doc);
-
- XMLUtils.addReturnToElement(this._constructionElement);
- }
-
- /**
- * Consturcts {@link Transforms} from {@link Element} which is <code>Transforms</code> Element
- *
- * @param element is <code>Transforms</code> element
- * @param BaseURI the URI where the XML instance was stored
- * @throws DOMException
- * @throws InvalidTransformException
- * @throws TransformationException
- * @throws XMLSecurityException
- * @throws XMLSignatureException
- */
- public Transforms(Element element, String BaseURI)
+ /** Canonicalization - Required Canonical XML (omits comments) */
+ public static final String TRANSFORM_C14N_OMIT_COMMENTS
+ = Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS;
+ /** Canonicalization - Recommended Canonical XML with Comments */
+ public static final String TRANSFORM_C14N_WITH_COMMENTS
+ = Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS;
+ /** Canonicalization - Required Canonical XML 1.1 (omits comments) */
+ public static final String TRANSFORM_C14N11_OMIT_COMMENTS
+ = Canonicalizer.ALGO_ID_C14N11_OMIT_COMMENTS;
+ /** Canonicalization - Recommended Canonical XML 1.1 with Comments */
+ public static final String TRANSFORM_C14N11_WITH_COMMENTS
+ = Canonicalizer.ALGO_ID_C14N11_WITH_COMMENTS;
+ /** Canonicalization - Required Exclusive Canonicalization (omits comments) */
+ public static final String TRANSFORM_C14N_EXCL_OMIT_COMMENTS
+ = Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS;
+ /** Canonicalization - Recommended Exclusive Canonicalization with Comments */
+ public static final String TRANSFORM_C14N_EXCL_WITH_COMMENTS
+ = Canonicalizer.ALGO_ID_C14N_EXCL_WITH_COMMENTS;
+ /** Transform - Optional XSLT */
+ public static final String TRANSFORM_XSLT
+ = "http://www.w3.org/TR/1999/REC-xslt-19991116";
+ /** Transform - Required base64 decoding */
+ public static final String TRANSFORM_BASE64_DECODE
+ = Constants.SignatureSpecNS + "base64";
+ /** Transform - Recommended XPath */
+ public static final String TRANSFORM_XPATH
+ = "http://www.w3.org/TR/1999/REC-xpath-19991116";
+ /** Transform - Required Enveloped Signature */
+ public static final String TRANSFORM_ENVELOPED_SIGNATURE
+ = Constants.SignatureSpecNS + "enveloped-signature";
+ /** Transform - XPointer */
+ public static final String TRANSFORM_XPOINTER
+ = "http://www.w3.org/TR/2001/WD-xptr-20010108";
+ /** Transform - XPath Filter v2.0 */
+ public static final String TRANSFORM_XPATH2FILTER04
+ = "http://www.w3.org/2002/04/xmldsig-filter2";
+ /** Transform - XPath Filter */
+ public static final String TRANSFORM_XPATH2FILTER
+ = "http://www.w3.org/2002/06/xmldsig-filter2";
+ /** Transform - XPath Filter CHGP private */
+ public static final String TRANSFORM_XPATHFILTERCHGP
+ = "http://www.nue.et-inf.uni-siegen.de/~geuer-pollmann/#xpathFilter";
+
+ Element []transforms;
+
+ protected Transforms() { };
+
+ /**
+ * Constructs {@link Transforms}.
+ *
+ * @param doc the {@link Document} in which <code>XMLSignature</code> will
+ * be placed
+ */
+ public Transforms(Document doc) {
+ super(doc);
+ XMLUtils.addReturnToElement(this._constructionElement);
+ }
+
+ /**
+ * Constructs {@link Transforms} from {@link Element} which is
+ * <code>Transforms</code> Element
+ *
+ * @param element is <code>Transforms</code> element
+ * @param BaseURI the URI where the XML instance was stored
+ * @throws DOMException
+ * @throws InvalidTransformException
+ * @throws TransformationException
+ * @throws XMLSecurityException
+ * @throws XMLSignatureException
+ */
+ public Transforms(Element element, String BaseURI)
throws DOMException, XMLSignatureException,
InvalidTransformException, TransformationException,
XMLSecurityException {
- super(element, BaseURI);
+ super(element, BaseURI);
- int numberOfTransformElems = this.getLength();
+ int numberOfTransformElems = this.getLength();
- if (numberOfTransformElems == 0) {
+ if (numberOfTransformElems == 0) {
- // At least ont Transform element must be present. Bad.
- Object exArgs[] = { Constants._TAG_TRANSFORM,
- Constants._TAG_TRANSFORMS };
-
- throw new TransformationException("xml.WrongContent", exArgs);
- }
- }
-
- /**
- * Adds the <code>Transform</code> with the specified <code>Transform algorithm URI</code>
- *
- * @param transformURI the URI form of transform that indicates which transformation is applied to data
- * @throws TransformationException
- */
- public void addTransform(String transformURI)
+ // At least one Transform element must be present. Bad.
+ Object exArgs[] = { Constants._TAG_TRANSFORM,
+ Constants._TAG_TRANSFORMS };
+
+ throw new TransformationException("xml.WrongContent", exArgs);
+ }
+ }
+
+ /**
+ * Adds the <code>Transform</code> with the specified <code>Transform
+ * algorithm URI</code>
+ *
+ * @param transformURI the URI form of transform that indicates which
+ * transformation is applied to data
+ * @throws TransformationException
+ */
+ public void addTransform(String transformURI)
throws TransformationException {
- try {
- if (log.isDebugEnabled())
+ try {
+ if (log.isDebugEnabled())
log.debug("Transforms.addTransform(" + transformURI + ")");
- Transform transform = Transform.getInstance(this._doc, transformURI);
+ Transform transform =
+ Transform.getInstance(this._doc, transformURI);
- this.addTransform(transform);
- } catch (InvalidTransformException ex) {
- throw new TransformationException("empty", ex);
- }
- }
-
- /**
- * Adds the <code>Transform</code> with the specified <code>Transform algorithm URI</code>
- *
- * @param transformURI the URI form of transform that indicates which transformation is applied to data
- * @param contextElement
- * @throws TransformationException
- * @see Transform#getInstance(Document doc, String algorithmURI, Element childElement)
- */
- public void addTransform(String transformURI, Element contextElement)
+ this.addTransform(transform);
+ } catch (InvalidTransformException ex) {
+ throw new TransformationException("empty", ex);
+ }
+ }
+
+ /**
+ * Adds the <code>Transform</code> with the specified <code>Transform
+ * algorithm URI</code>
+ *
+ * @param transformURI the URI form of transform that indicates which
+ * transformation is applied to data
+ * @param contextElement
+ * @throws TransformationException
+ * @see Transform#getInstance(Document doc, String algorithmURI, Element childElement)
+ */
+ public void addTransform(String transformURI, Element contextElement)
throws TransformationException {
- try {
- if (log.isDebugEnabled())
+ try {
+ if (log.isDebugEnabled())
log.debug("Transforms.addTransform(" + transformURI + ")");
- Transform transform = Transform.getInstance(this._doc, transformURI,
- contextElement);
+ Transform transform =
+ Transform.getInstance(this._doc, transformURI, contextElement);
- this.addTransform(transform);
- } catch (InvalidTransformException ex) {
- throw new TransformationException("empty", ex);
- }
- }
-
- /**
- * Adds the <code>Transform</code> with the specified <code>Transform algorithm URI</code>
- *
- * @param transformURI the URI form of transform that indicates which transformation is applied to data
- * @param contextNodes
- * @throws TransformationException
- * @see Transform#getInstance(Document doc, String algorithmURI, NodeList contextNodes)
- */
- public void addTransform(String transformURI, NodeList contextNodes)
+ this.addTransform(transform);
+ } catch (InvalidTransformException ex) {
+ throw new TransformationException("empty", ex);
+ }
+ }
+
+ /**
+ * Adds the <code>Transform</code> with the specified <code>Transform
+ * algorithm URI</code>.
+ *
+ * @param transformURI the URI form of transform that indicates which
+ * transformation is applied to data
+ * @param contextNodes
+ * @throws TransformationException
+ * @see Transform#getInstance(Document doc, String algorithmURI, NodeList contextNodes)
+ */
+ public void addTransform(String transformURI, NodeList contextNodes)
throws TransformationException {
- try {
- Transform transform = Transform.getInstance(this._doc, transformURI,
- contextNodes);
-
- this.addTransform(transform);
- } catch (InvalidTransformException ex) {
- throw new TransformationException("empty", ex);
- }
- }
-
- /**
- * Adds a user-provided Transform step.
- *
- * @param transform {@link Transform} object
- */
- private void addTransform(Transform transform) {
- if (log.isDebugEnabled())
- log.debug("Transforms.addTransform(" + transform.getURI() + ")");
-
- Element transformElement = transform.getElement();
-
- this._constructionElement.appendChild(transformElement);
- XMLUtils.addReturnToElement(this._constructionElement);
- }
-
- /**
- * Applies all included <code>Transform</code>s to xmlSignatureInput and returns the result of these transformations.
- *
- * @param xmlSignatureInput the input for the <code>Transform</code>s
- * @return the result of the <code>Transforms</code>
- * @throws TransformationException
- */
- public XMLSignatureInput performTransforms(
- XMLSignatureInput xmlSignatureInput) throws TransformationException {
- return performTransforms(xmlSignatureInput,null);
- }
+ try {
+ Transform transform =
+ Transform.getInstance(this._doc, transformURI, contextNodes);
+ this.addTransform(transform);
+ } catch (InvalidTransformException ex) {
+ throw new TransformationException("empty", ex);
+ }
+ }
+
+ /**
+ * Adds a user-provided Transform step.
+ *
+ * @param transform {@link Transform} object
+ */
+ private void addTransform(Transform transform) {
+ if (log.isDebugEnabled())
+ log.debug("Transforms.addTransform(" + transform.getURI() + ")");
+
+ Element transformElement = transform.getElement();
+
+ this._constructionElement.appendChild(transformElement);
+ XMLUtils.addReturnToElement(this._constructionElement);
+ }
+
+ /**
+ * Applies all included <code>Transform</code>s to xmlSignatureInput and
+ * returns the result of these transformations.
+ *
+ * @param xmlSignatureInput the input for the <code>Transform</code>s
+ * @return the result of the <code>Transforms</code>
+ * @throws TransformationException
+ */
+ public XMLSignatureInput performTransforms(
+ XMLSignatureInput xmlSignatureInput) throws TransformationException {
+ return performTransforms(xmlSignatureInput, null);
+ }
- /**
- * Applies all included <code>Transform</code>s to xmlSignatureInput and returns the result of these transformations.
- *
- * @param xmlSignatureInput the input for the <code>Transform</code>s
- * @param os where to output the last transformation.
- * @return the result of the <code>Transforms</code>
- * @throws TransformationException
- */
+ /**
+ * Applies all included <code>Transform</code>s to xmlSignatureInput and
+ * returns the result of these transformations.
+ *
+ * @param xmlSignatureInput the input for the <code>Transform</code>s
+ * @param os where to output the last transformation.
+ * @return the result of the <code>Transforms</code>
+ * @throws TransformationException
+ */
public XMLSignatureInput performTransforms(
- XMLSignatureInput xmlSignatureInput,OutputStream os) throws TransformationException {
+ XMLSignatureInput xmlSignatureInput, OutputStream os)
+ throws TransformationException {
- try {
- int last=this.getLength()-1;
- for (int i = 0; i < last; i++) {
- Transform t = this.item(i);
- if (log.isDebugEnabled()) {
- log.debug("Preform the (" + i + ")th " + t.getURI() + " transform");
+ try {
+ int last=this.getLength()-1;
+ for (int i = 0; i < last; i++) {
+ Transform t = this.item(i);
+ if (log.isDebugEnabled()) {
+ log.debug("Perform the (" + i + ")th " + t.getURI()
+ + " transform");
+ }
+ xmlSignatureInput = t.performTransform(xmlSignatureInput);
+ }
+ if (last>=0) {
+ Transform t = this.item(last);
+ xmlSignatureInput = t.performTransform(xmlSignatureInput, os);
}
- xmlSignatureInput = t.performTransform(xmlSignatureInput);
- }
- if (last>=0) {
- Transform t = this.item(last);
- xmlSignatureInput = t.performTransform(xmlSignatureInput, os);
- }
-
-
- return xmlSignatureInput;
- } catch (IOException ex) {
- throw new TransformationException("empty", ex);
- // } catch (ParserConfigurationException ex) { throw new TransformationException("empty", ex);
- // } catch (SAXException ex) { throw new TransformationException("empty", ex);
- } catch (CanonicalizationException ex) {
- throw new TransformationException("empty", ex);
- } catch (InvalidCanonicalizerException ex) {
- throw new TransformationException("empty", ex);
- }
- }
-
- /**
- * Return the nonnegative number of transformations.
- *
- * @return the number of transformations
- */
- public int getLength()
- {
- if (transforms==null) {
- transforms=XMLUtils.selectDsNodes(this._constructionElement.getFirstChild(),
- "Transform");
- }
- return transforms.length;
- }
-
- /**
- * Return the <it>i</it><sup>th</sup> <code>{@link Transform}</code>.
- * Valid <code>i</code> values are 0 to <code>{@link #getLength}-1</code>.
- *
- * @param i index of {@link Transform} to return
- * @return the <it>i</it><sup>th</sup> transforms
- * @throws TransformationException
- */
- public Transform item(int i) throws TransformationException {
+
+ return xmlSignatureInput;
+ } catch (IOException ex) {
+ throw new TransformationException("empty", ex);
+ } catch (CanonicalizationException ex) {
+ throw new TransformationException("empty", ex);
+ } catch (InvalidCanonicalizerException ex) {
+ throw new TransformationException("empty", ex);
+ }
+ }
+
+ /**
+ * Return the nonnegative number of transformations.
+ *
+ * @return the number of transformations
+ */
+ public int getLength()
+ {
+ if (transforms == null) {
+ transforms = XMLUtils.selectDsNodes
+ (this._constructionElement.getFirstChild(), "Transform");
+ }
+ return transforms.length;
+ }
+
+ /**
+ * Return the <it>i</it><sup>th</sup> <code>{@link Transform}</code>.
+ * Valid <code>i</code> values are 0 to <code>{@link #getLength}-1</code>.
+ *
+ * @param i index of {@link Transform} to return
+ * @return the <it>i</it><sup>th</sup> Transform
+ * @throws TransformationException
+ */
+ public Transform item(int i) throws TransformationException {
- try {
- if (transforms==null) {
- transforms=XMLUtils.selectDsNodes(this._constructionElement.getFirstChild(),
- "Transform");
- }
- return new Transform(transforms[i], this._baseURI);
- } catch (XMLSecurityException ex) {
- throw new TransformationException("empty", ex);
- }
- }
-
- /** @inheritDoc */
- public String getBaseLocalName() {
- return Constants._TAG_TRANSFORMS;
- }
+ try {
+ if (transforms == null) {
+ transforms = XMLUtils.selectDsNodes
+ (this._constructionElement.getFirstChild(), "Transform");
+ }
+ return new Transform(transforms[i], this._baseURI);
+ } catch (XMLSecurityException ex) {
+ throw new TransformationException("empty", ex);
+ }
+ }
+
+ /** @inheritDoc */
+ public String getBaseLocalName() {
+ return Constants._TAG_TRANSFORMS;
+ }
}
Added: xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformC14N11.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformC14N11.java?rev=630988&view=auto
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformC14N11.java (added)
+++ xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformC14N11.java Mon Feb 25 12:55:47 2008
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2008 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.xml.security.transforms.implementations;
+
+import java.io.OutputStream;
+
+import org.apache.xml.security.c14n.CanonicalizationException;
+import org.apache.xml.security.c14n.implementations.Canonicalizer11_OmitComments;
+import org.apache.xml.security.signature.XMLSignatureInput;
+import org.apache.xml.security.transforms.Transform;
+import org.apache.xml.security.transforms.TransformSpi;
+import org.apache.xml.security.transforms.Transforms;
+
+/**
+ * Implements the <CODE>http://www.w3.org/2006/12/xml-c14n11</CODE>
+ * (C14N 1.1) transform.
+ *
+ * @author Sean Mullan
+ */
+public class TransformC14N11 extends TransformSpi {
+
+ protected String engineGetURI() {
+ return Transforms.TRANSFORM_C14N11_OMIT_COMMENTS;
+ }
+
+ protected XMLSignatureInput enginePerformTransform
+ (XMLSignatureInput input, Transform transform)
+ throws CanonicalizationException {
+ return enginePerformTransform(input, null, transform);
+ }
+
+ protected XMLSignatureInput enginePerformTransform
+ (XMLSignatureInput input, OutputStream os, Transform transform)
+ throws CanonicalizationException {
+ Canonicalizer11_OmitComments c14n = new Canonicalizer11_OmitComments();
+ if (os != null) {
+ c14n.setWriter(os);
+ }
+ byte[] result = null;
+ result = c14n.engineCanonicalize(input);
+ XMLSignatureInput output = new XMLSignatureInput(result);
+ if (os != null) {
+ output.setOutputStream(os);
+ }
+ return output;
+ }
+}
Added: xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformC14N11_WithComments.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformC14N11_WithComments.java?rev=630988&view=auto
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformC14N11_WithComments.java (added)
+++ xml/security/trunk/src/org/apache/xml/security/transforms/implementations/TransformC14N11_WithComments.java Mon Feb 25 12:55:47 2008
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2008 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.xml.security.transforms.implementations;
+
+import java.io.OutputStream;
+
+import org.apache.xml.security.c14n.CanonicalizationException;
+import org.apache.xml.security.c14n.implementations.Canonicalizer11_WithComments;
+import org.apache.xml.security.signature.XMLSignatureInput;
+import org.apache.xml.security.transforms.Transform;
+import org.apache.xml.security.transforms.TransformSpi;
+import org.apache.xml.security.transforms.Transforms;
+
+/**
+ * Implements the <CODE>http://www.w3.org/2006/12/xml-c14n-11#WithComments</CODE>
+ * (C14N 1.1 With Comments) transform.
+ *
+ * @author Sean Mullan
+ */
+public class TransformC14N11_WithComments extends TransformSpi {
+
+ protected String engineGetURI() {
+ return Transforms.TRANSFORM_C14N11_WITH_COMMENTS;
+ }
+
+ protected XMLSignatureInput enginePerformTransform
+ (XMLSignatureInput input, Transform transform)
+ throws CanonicalizationException {
+ return enginePerformTransform(input, null, transform);
+ }
+
+ protected XMLSignatureInput enginePerformTransform
+ (XMLSignatureInput input, OutputStream os, Transform transform)
+ throws CanonicalizationException {
+
+ Canonicalizer11_WithComments c14n = new Canonicalizer11_WithComments();
+ if (os != null) {
+ c14n.setWriter(os);
+ }
+
+ byte[] result = null;
+ result = c14n.engineCanonicalize(input);
+ XMLSignatureInput output = new XMLSignatureInput(result);
+ if (os != null) {
+ output.setOutputStream(os);
+ }
+ return output;
+ }
+}
Modified: xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/ApacheCanonicalizer.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/ApacheCanonicalizer.java?rev=630988&r1=630987&r2=630988&view=diff
==============================================================================
--- xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/ApacheCanonicalizer.java (original)
+++ xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/ApacheCanonicalizer.java Mon Feb 25 12:55:47 2008
@@ -48,6 +48,10 @@
public abstract class ApacheCanonicalizer extends TransformService {
+ static {
+ org.apache.xml.security.Init.init();
+ }
+
private static Logger log = Logger.getLogger("org.jcp.xml.dsig.internal.dom");
protected Canonicalizer apacheCanonicalizer;
private Transform apacheTransform;
Modified: xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/ApacheTransform.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/ApacheTransform.java?rev=630988&r1=630987&r2=630988&view=diff
==============================================================================
--- xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/ApacheTransform.java (original)
+++ xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/ApacheTransform.java Mon Feb 25 12:55:47 2008
@@ -49,6 +49,10 @@
*/
public abstract class ApacheTransform extends TransformService {
+ static {
+ org.apache.xml.security.Init.init();
+ }
+
private static Logger log = Logger.getLogger("org.jcp.xml.dsig.internal.dom");
private Transform apacheTransform;
protected Document ownerDoc;
Added: xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMCanonicalXMLC14N11Method.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMCanonicalXMLC14N11Method.java?rev=630988&view=auto
==============================================================================
--- xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMCanonicalXMLC14N11Method.java (added)
+++ xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMCanonicalXMLC14N11Method.java Mon Feb 25 12:55:47 2008
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2008 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ */
+/*
+ * $Id$
+ */
+package org.jcp.xml.dsig.internal.dom;
+
+import javax.xml.crypto.*;
+import javax.xml.crypto.dsig.*;
+import javax.xml.crypto.dsig.spec.TransformParameterSpec;
+
+import java.security.InvalidAlgorithmParameterException;
+
+import org.apache.xml.security.c14n.Canonicalizer;
+import org.apache.xml.security.c14n.InvalidCanonicalizerException;
+
+/**
+ * DOM-based implementation of CanonicalizationMethod for Canonical XML 1.1
+ * (with or without comments). Uses Apache XML-Sec Canonicalizer.
+ *
+ * @author Sean Mullan
+ */
+public final class DOMCanonicalXMLC14N11Method extends ApacheCanonicalizer {
+
+ public static final String C14N_11 = "http://www.w3.org/2006/12/xml-c14n11";
+ public static final String C14N_11_WITH_COMMENTS
+ = "http://www.w3.org/2006/12/xml-c14n11#WithComments";
+
+ public void init(TransformParameterSpec params)
+ throws InvalidAlgorithmParameterException {
+ if (params != null) {
+ throw new InvalidAlgorithmParameterException("no parameters " +
+ "should be specified for Canonical XML 1.1 algorithm");
+ }
+ }
+
+ public Data transform(Data data, XMLCryptoContext xc)
+ throws TransformException {
+
+ // ignore comments if dereferencing same-document URI that requires
+ // you to omit comments, even if the Transform says otherwise -
+ // this is to be compliant with section 4.3.3.3 of W3C Rec.
+ if (data instanceof DOMSubTreeData) {
+ DOMSubTreeData subTree = (DOMSubTreeData) data;
+ if (subTree.excludeComments()) {
+ try {
+ apacheCanonicalizer = Canonicalizer.getInstance(C14N_11);
+ } catch (InvalidCanonicalizerException ice) {
+ throw new TransformException
+ ("Couldn't find Canonicalizer for: " +
+ C14N_11 + ": " + ice.getMessage(), ice);
+ }
+ }
+ }
+
+ return canonicalize(data, xc);
+ }
+}
Modified: xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMReference.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMReference.java?rev=630988&r1=630987&r2=630988&view=diff
==============================================================================
--- xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMReference.java (original)
+++ xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMReference.java Mon Feb 25 12:55:47 2008
@@ -416,6 +416,16 @@
try {
if (data != null) {
XMLSignatureInput xi;
+ // explicitly use C14N 1.1 when generating signature
+ Boolean c14n11 = (Boolean)
+ context.getProperty("org.apache.xml.security.useC14N11");
+ String c14nalg = null;
+ if (context instanceof XMLSignContext && c14n11 != null
+ && c14n11.booleanValue() == true) {
+ c14nalg = "http://www.w3.org/2006/12/xml-c14n11";
+ } else {
+ c14nalg = CanonicalizationMethod.INCLUSIVE;
+ }
if (data instanceof ApacheData) {
xi = ((ApacheData) data).getXMLSignatureInput();
} else if (data instanceof OctetStreamData) {
@@ -424,11 +434,10 @@
} else if (data instanceof NodeSetData) {
TransformService spi = null;
try {
- spi = TransformService.getInstance
- (CanonicalizationMethod.INCLUSIVE, "DOM");
+ spi = TransformService.getInstance(c14nalg, "DOM");
} catch (NoSuchAlgorithmException nsae) {
spi = TransformService.getInstance
- (CanonicalizationMethod.INCLUSIVE, "DOM", provider);
+ (c14nalg, "DOM", provider);
}
data = spi.transform(data, context);
xi = new XMLSignatureInput
@@ -436,7 +445,20 @@
} else {
throw new XMLSignatureException("unrecognized Data type");
}
- xi.updateOutputStream(os);
+ if (context instanceof XMLSignContext && c14n11 != null
+ && c14n11.booleanValue() == true && !xi.isOctetStream()) {
+ Element transformsElem =
+ DOMUtils.getFirstChildElement(refElem);
+ Element transformElem = DOMUtils.createElement
+ (refElem.getOwnerDocument(), "Transform",
+ XMLSignature.XMLNS,
+ DOMUtils.getSignaturePrefix(context));
+ DOMUtils.setAttribute(transformElem, "Algorithm", c14nalg);
+ transformsElem.appendChild(transformElem);
+ xi.updateOutputStream(os, true);
+ } else {
+ xi.updateOutputStream(os);
+ }
}
os.flush();
if (cache != null && cache.booleanValue() == true) {
Modified: xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/XMLDSigRI.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/XMLDSigRI.java?rev=630988&r1=630987&r2=630988&view=diff
==============================================================================
--- xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/XMLDSigRI.java (original)
+++ xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/XMLDSigRI.java Mon Feb 25 12:55:47 2008
@@ -80,6 +80,22 @@
CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS +
" MechanismType", "DOM");
+ // Inclusive C14N 1.1
+ map.put((String)"TransformService." +
+ "http://www.w3.org/2006/12/xml-c14n11",
+ "org.jcp.xml.dsig.internal.dom.DOMCanonicalXMLC14N11Method");
+ map.put((String)"TransformService." +
+ "http://www.w3.org/2006/12/xml-c14n11" +
+ " MechanismType", "DOM");
+
+ // InclusiveWithComments C14N 1.1
+ map.put((String)"TransformService." +
+ "http://www.w3.org/2006/12/xml-c14n11#WithComments",
+ "org.jcp.xml.dsig.internal.dom.DOMCanonicalXMLC14N11Method");
+ map.put((String)"TransformService." +
+ "http://www.w3.org/2006/12/xml-c14n11#WithComments" +
+ " MechanismType", "DOM");
+
// Exclusive C14N
map.put((String) "TransformService." + CanonicalizationMethod.EXCLUSIVE,
"org.jcp.xml.dsig.internal.dom.DOMExcC14NMethod");