Codebase list libxml-security-java / 68a6890
New upstream version 2.0.4 Emmanuel Bourg 5 years ago
93 changed file(s) with 1224 addition(s) and 603 deletion(s). Raw diff Collapse all Expand all
00 Apache Santuario - XML Security for Java
1 Copyright 1999-2014 The Apache Software Foundation
1 Copyright 1999-2015 The Apache Software Foundation
22
33 This product includes software developed at
44 The Apache Software Foundation (http://www.apache.org/).
2121 <artifactId>xmlsec</artifactId>
2222 <packaging>bundle</packaging>
2323 <name>Apache XML Security for Java</name>
24 <version>2.0.3</version>
24 <version>2.0.4</version>
2525 <description>
2626 Apache XML Security for Java supports XML-Signature Syntax and Processing,
2727 W3C Recommendation 12 February 2002, and XML Encryption Syntax and
5656 </licenses>
5757 <scm>
5858 <connection>
59 scm:svn:http://svn.apache.org/repos/asf/santuario/xml-security-java/tags/xmlsec-2.0.3
59 scm:svn:http://svn.apache.org/repos/asf/santuario/xml-security-java/tags/xmlsec-2.0.4
6060 </connection>
6161 <developerConnection>
62 scm:svn:https://svn.apache.org/repos/asf/santuario/xml-security-java/tags/xmlsec-2.0.3
62 scm:svn:https://svn.apache.org/repos/asf/santuario/xml-security-java/tags/xmlsec-2.0.4
6363 </developerConnection>
64 <url>http://svn.apache.org/repos/asf/santuario/xml-security-java/tags/xmlsec-2.0.3</url>
64 <url>http://svn.apache.org/repos/asf/santuario/xml-security-java/tags/xmlsec-2.0.4</url>
6565 </scm>
6666 <organization>
6767 <name>The Apache Software Foundation</name>
7171 <parent>
7272 <groupId>org.apache</groupId>
7373 <artifactId>apache</artifactId>
74 <version>14</version>
74 <version>16</version>
7575 </parent>
7676
7777 <build>
132132 <plugin>
133133 <groupId>org.apache.maven.plugins</groupId>
134134 <artifactId>maven-compiler-plugin</artifactId>
135 <version>3.1</version>
135 <version>3.3</version>
136136 <configuration>
137137 <source>1.6</source>
138138 <target>1.6</target>
267267 <plugin>
268268 <groupId>org.apache.maven.plugins</groupId>
269269 <artifactId>maven-javadoc-plugin</artifactId>
270 <version>2.9.1</version>
270 <version>2.10.1</version>
271271 </plugin>
272272
273273 </plugins>
277277 <plugin>
278278 <groupId>org.apache.maven.plugins</groupId>
279279 <artifactId>maven-javadoc-plugin</artifactId>
280 <version>2.9.1</version>
280 <version>2.10.1</version>
281281 <executions>
282282 <execution>
283283 <goals>
411411 <xerces.version>2.11.0</xerces.version>
412412 <junit.version>4.12</junit.version>
413413 <log4j.version>1.2.17</log4j.version>
414 <bcprov.version>1.51</bcprov.version>
415 <xmlunit.version>1.5</xmlunit.version>
414 <bcprov.version>1.52</bcprov.version>
415 <xmlunit.version>1.6</xmlunit.version>
416416 <commons.codec.version>1.10</commons.codec.version>
417417 <woodstox.core.asl.version>4.4.1</woodstox.core.asl.version>
418418 <jetty.version>8.1.4.v20120524</jetty.version>
3333
3434 /**
3535 * This class has been modified slightly to use java.security.MessageDigest
36 * objects as input, rather than
36 * objects as input, rather than
3737 * org.apache.xml.security.algorithms.MessageDigestAlgorithm objects.
3838 * It also optionally caches the input bytes.
3939 *
7777 }
7878 md.update((byte)input);
7979 }
80
80
8181 @Override
8282 public void write(byte[] input, int offset, int len) {
8383 if (buffer) {
9393 }
9494 md.update(input, offset, len);
9595 }
96
96
9797 /**
98 * @return the digest value
98 * @return the digest value
9999 */
100100 public byte[] getDigestValue() {
101 return md.digest();
101 return md.digest();
102102 }
103103
104104 /**
112112 return null;
113113 }
114114 }
115
115
116116 @Override
117117 public void close() throws IOException {
118118 if (buffer) {
2121 import javax.crypto.Mac;
2222
2323 /**
24 * Derived from Apache sources and changed to use Mac objects instead of
24 * Derived from Apache sources and changed to use Mac objects instead of
2525 * org.apache.xml.security.algorithms.SignatureAlgorithm objects.
2626 *
2727 * @author raul
4040 super.write(arg0);
4141 mac.update((byte) arg0);
4242 }
43
43
4444 @Override
4545 public void write(byte[] arg0, int arg1, int arg2) {
4646 super.write(arg0, arg1, arg2);
2828 import java.security.SignatureException;
2929
3030 /**
31 * Derived from Apache sources and changed to use java.security.Signature
32 * objects as input instead of
31 * Derived from Apache sources and changed to use java.security.Signature
32 * objects as input instead of
3333 * org.apache.xml.security.algorithms.SignatureAlgorithm objects.
3434 *
3535 * @author raul
8282 throws InvalidKeyException, XMLSignatureException;
8383
8484 /**
85 * Returns the java.security.Signature or javax.crypto.Mac standard
85 * Returns the java.security.Signature or javax.crypto.Mac standard
8686 * algorithm name.
8787 */
8888 abstract String getJCAAlgorithm();
179179 return getAlgorithm().equals(osm.getAlgorithm()) &&
180180 paramsEqual(osm.getParameterSpec());
181181 }
182
182
183183 @Override
184184 public int hashCode() {
185185 int result = 17;
188188 if (spec != null) {
189189 result = 31 * result + spec.hashCode();
190190 }
191
191
192192 return result;
193193 }
194194
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: ApacheCanonicalizer.java 1537965 2013-11-01 15:49:08Z coheigea $
22 * $Id: ApacheCanonicalizer.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
5858 protected C14NMethodParameterSpec params;
5959 protected Document ownerDoc;
6060 protected Element transformElem;
61
61
6262 public final AlgorithmParameterSpec getParameterSpec()
6363 {
6464 return params;
101101 ((javax.xml.crypto.dom.DOMStructure)parent).getNode();
102102 ownerDoc = DOMUtils.getOwnerDocument(transformElem);
103103 }
104
105 public Data canonicalize(Data data, XMLCryptoContext xc)
104
105 public Data canonicalize(Data data, XMLCryptoContext xc)
106106 throws TransformException
107107 {
108108 return canonicalize(data, xc, null);
109109 }
110110
111 public Data canonicalize(Data data, XMLCryptoContext xc, OutputStream os)
111 public Data canonicalize(Data data, XMLCryptoContext xc, OutputStream os)
112112 throws TransformException
113113 {
114114 if (apacheCanonicalizer == null) {
135135 try {
136136 Set<Node> nodeSet = null;
137137 if (data instanceof ApacheData) {
138 XMLSignatureInput in =
138 XMLSignatureInput in =
139139 ((ApacheData)data).getXMLSignatureInput();
140140 if (in.isElement()) {
141141 if (inclusiveNamespaces != null) {
209209
210210 if (apacheTransform == null) {
211211 try {
212 apacheTransform =
212 apacheTransform =
213213 new Transform(ownerDoc, getAlgorithm(), transformElem.getChildNodes());
214214 apacheTransform.setElement(transformElem, xc.getBaseURI());
215215 boolean secVal = Utils.secureValidation(xc);
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: ApacheData.java 1333869 2012-05-04 10:42:44Z coheigea $
22 * $Id: ApacheData.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
2727 import org.apache.xml.security.signature.XMLSignatureInput;
2828
2929 /**
30 * XMLSignatureInput Data wrapper.
30 * XMLSignatureInput Data wrapper.
3131 *
3232 * @author Sean Mullan
3333 */
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: ApacheOctetStreamData.java 1423915 2012-12-19 16:17:25Z coheigea $
22 * $Id: ApacheOctetStreamData.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
2828 import org.apache.xml.security.c14n.CanonicalizationException;
2929 import org.apache.xml.security.signature.XMLSignatureInput;
3030
31 public class ApacheOctetStreamData extends OctetStreamData
31 public class ApacheOctetStreamData extends OctetStreamData
3232 implements ApacheData {
3333
3434 private XMLSignatureInput xi;
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: ApacheTransform.java 1537965 2013-11-01 15:49:08Z coheigea $
22 * $Id: ApacheTransform.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
7979 if (!(parent instanceof javax.xml.crypto.dom.DOMStructure)) {
8080 throw new ClassCastException("parent must be of type DOMStructure");
8181 }
82 transformElem = (Element)
82 transformElem = (Element)
8383 ((javax.xml.crypto.dom.DOMStructure) parent).getNode();
8484 ownerDoc = DOMUtils.getOwnerDocument(transformElem);
8585 }
9898 if (!(parent instanceof javax.xml.crypto.dom.DOMStructure)) {
9999 throw new ClassCastException("parent must be of type DOMStructure");
100100 }
101 transformElem = (Element)
101 transformElem = (Element)
102102 ((javax.xml.crypto.dom.DOMStructure) parent).getNode();
103103 ownerDoc = DOMUtils.getOwnerDocument(transformElem);
104104 }
135135
136136 if (apacheTransform == null) {
137137 try {
138 apacheTransform =
138 apacheTransform =
139139 new Transform(ownerDoc, getAlgorithm(), transformElem.getChildNodes());
140140 apacheTransform.setElement(transformElem, xc.getBaseURI());
141141 boolean secVal = Utils.secureValidation(xc);
147147 } catch (Exception ex) {
148148 throw new TransformException("Couldn't find Transform for: " +
149149 getAlgorithm(), ex);
150 }
151 }
152
150 }
151 }
152
153153 if (Utils.secureValidation(xc)) {
154154 String algorithm = getAlgorithm();
155155 if (Transforms.TRANSFORM_XSLT.equals(algorithm)) {
4141 public final class DOMCanonicalXMLC14N11Method extends ApacheCanonicalizer {
4242
4343 public static final String C14N_11 = "http://www.w3.org/2006/12/xml-c14n11";
44 public static final String C14N_11_WITH_COMMENTS
44 public static final String C14N_11_WITH_COMMENTS
4545 = "http://www.w3.org/2006/12/xml-c14n11#WithComments";
4646
4747 @Override
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMCanonicalizationMethod.java 1585385 2014-04-07 05:12:23Z coheigea $
22 * $Id: DOMCanonicalizationMethod.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
3838 *
3939 * @author Sean Mullan
4040 */
41 public class DOMCanonicalizationMethod extends DOMTransform
41 public class DOMCanonicalizationMethod extends DOMTransform
4242 implements CanonicalizationMethod {
4343
4444 /**
6868 super(cmElem, context, provider);
6969 if (!(spi instanceof ApacheCanonicalizer) && !isC14Nalg(spi.getAlgorithm())) {
7070 throw new MarshalException("Illegal CanonicalizationMethod");
71 }
71 }
7272 }
7373
7474 /**
110110 return getAlgorithm().equals(ocm.getAlgorithm()) &&
111111 DOMUtils.paramsEqual(getParameterSpec(), ocm.getParameterSpec());
112112 }
113
113
114114 @Override
115115 public int hashCode() {
116116 int result = 17;
122122
123123 return result;
124124 }
125
125
126126 private static boolean isC14Nalg(String alg) {
127127 return alg.equals(CanonicalizationMethod.INCLUSIVE)
128128 || alg.equals(CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS)
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMDigestMethod.java 1596535 2014-05-21 10:43:40Z coheigea $
22 * $Id: DOMDigestMethod.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
149149 }
150150
151151 /**
152 * Unmarshals <code>DigestMethodParameterSpec</code> from the specified
152 * Unmarshals <code>DigestMethodParameterSpec</code> from the specified
153153 * <code>Element</code>. By default, this method throws an exception since
154 * most DigestMethod algorithms do not have parameters. Subclasses should
154 * most DigestMethod algorithms do not have parameters. Subclasses should
155155 * override it if they have parameters.
156156 *
157157 * @param paramsElem the <code>Element</code> holding the input params
168168 }
169169
170170 /**
171 * This method invokes the abstract {@link #marshalParams marshalParams}
171 * This method invokes the abstract {@link #marshalParams marshalParams}
172172 * method to marshal any algorithm-specific parameters.
173173 */
174174 public static void marshal(XmlWriter xwriter, DigestMethod digest, String prefix)
200200
201201 return getAlgorithm().equals(odm.getAlgorithm()) && paramsEqual;
202202 }
203
203
204204 @Override
205205 public int hashCode() {
206206 int result = 17;
208208 result = 31 * result + params.hashCode();
209209 }
210210 result = 31 * result + getAlgorithm().hashCode();
211
211
212212 return result;
213213 }
214214
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMHMACSignatureMethod.java 1596803 2014-05-22 10:31:25Z coheigea $
22 * $Id: DOMHMACSignatureMethod.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
6969 private SignatureMethodParameterSpec params;
7070
7171 /**
72 * Creates a <code>DOMHMACSignatureMethod</code> with the specified params
72 * Creates a <code>DOMHMACSignatureMethod</code> with the specified params
7373 *
7474 * @param params algorithm-specific parameters (may be <code>null</code>)
7575 * @throws InvalidAlgorithmParameterException if params are inappropriate
9999 }
100100
101101 @Override
102 void checkParams(SignatureMethodParameterSpec params)
102 void checkParams(SignatureMethodParameterSpec params)
103103 throws InvalidAlgorithmParameterException
104104 {
105105 if (params != null) {
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMKeyInfo.java 1602377 2014-06-13 11:20:43Z coheigea $
22 * $Id: DOMKeyInfo.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
197197
198198 return keyInfoTypes.equals(oki.getContent()) && idsEqual;
199199 }
200
200
201201 @Override
202202 public int hashCode() {
203203 int result = 17;
205205 result = 31 * result + id.hashCode();
206206 }
207207 result = 31 * result + keyInfoTypes.hashCode();
208
208
209209 return result;
210210 }
211211 }
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMKeyInfoFactory.java 1602127 2014-06-12 11:33:42Z coheigea $
22 * $Id: DOMKeyInfoFactory.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
147147 if (!(xmlStructure instanceof javax.xml.crypto.dom.DOMStructure)) {
148148 throw new ClassCastException("xmlStructure must be of type DOMStructure");
149149 }
150 Node node =
150 Node node =
151151 ((javax.xml.crypto.dom.DOMStructure) xmlStructure).getNode();
152152 node.normalize();
153153
174174 throw new MarshalException("invalid KeyInfo tag: " + namespace + ":" + tag);
175175 }
176176 }
177
177
178178 private static class UnmarshalContext extends DOMCryptoContext {
179179 UnmarshalContext() {}
180180 }
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMKeyName.java 1496610 2013-06-25 19:44:49Z mullan $
22 * $Id: DOMKeyName.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
3737 private final String name;
3838
3939 /**
40 * Creates a <code>DOMKeyName</code>.
40 * Creates a <code>DOMKeyName</code>.
4141 *
4242 * @param name the name of the key identifier
4343 * @throws NullPointerException if <code>name</code> is null
7474 KeyName okn = (KeyName)obj;
7575 return name.equals(okn.getName());
7676 }
77
77
7878 @Override
7979 public int hashCode() {
8080 int result = 17;
8181 result = 31 * result + name.hashCode();
82
82
8383 return result;
8484 }
8585 }
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMKeyValue.java 1602376 2014-06-13 11:20:10Z mullan $
22 * $Id: DOMKeyValue.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
6565 */
6666 public abstract class DOMKeyValue<K extends PublicKey> extends BaseStructure implements KeyValue {
6767
68 private static final String XMLDSIG_11_XMLNS
68 private static final String XMLDSIG_11_XMLNS
6969 = "http://www.w3.org/2009/xmldsig11#";
7070 private final K publicKey;
7171
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMManifest.java 1634871 2014-10-28 13:13:52Z mullan $
22 * $Id: DOMManifest.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
154154
155155 return idsEqual && references.equals(oman.getReferences());
156156 }
157
157
158158 @Override
159159 public int hashCode() {
160160 int result = 17;
162162 result = 31 * result + id.hashCode();
163163 }
164164 result = 31 * result + references.hashCode();
165
165
166166 return result;
167167 }
168168 }
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMPGPData.java 1602377 2014-06-13 11:20:43Z coheigea $
22 * $Id: DOMPGPData.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
4646 private final List<XMLStructure> externalElements;
4747
4848 /**
49 * Creates a <code>DOMPGPData</code> containing the specified key packet.
49 * Creates a <code>DOMPGPData</code> containing the specified key packet.
5050 * and optional list of external elements.
5151 *
52 * @param keyPacket a PGP Key Material Packet as defined in section 5.5 of
53 * <a href="http://www.ietf.org/rfc/rfc2440.txt"/>RFC 2440</a>. The
52 * @param keyPacket a PGP Key Material Packet as defined in section 5.5 of
53 * <a href="http://www.ietf.org/rfc/rfc2440.txt"/>RFC 2440</a>. The
5454 * array is cloned to prevent subsequent modification.
5555 * @param other a list of {@link XMLStructure}s representing elements from
5656 * an external namespace. The list is defensively copied to prevent
5757 * subsequent modification. May be <code>null</code> or empty.
58 * @throws NullPointerException if <code>keyPacket</code> is
58 * @throws NullPointerException if <code>keyPacket</code> is
5959 * <code>null</code>
60 * @throws IllegalArgumentException if the key packet is not in the
60 * @throws IllegalArgumentException if the key packet is not in the
6161 * correct format
6262 * @throws ClassCastException if <code>other</code> contains any
6363 * entries that are not of type {@link XMLStructure}
8787 * Creates a <code>DOMPGPData</code> containing the specified key id and
8888 * optional key packet and list of external elements.
8989 *
90 * @param keyId a PGP public key id as defined in section 11.2 of
91 * <a href="http://www.ietf.org/rfc/rfc2440.txt"/>RFC 2440</a>. The
90 * @param keyId a PGP public key id as defined in section 11.2 of
91 * <a href="http://www.ietf.org/rfc/rfc2440.txt"/>RFC 2440</a>. The
9292 * array is cloned to prevent subsequent modification.
93 * @param keyPacket a PGP Key Material Packet as defined in section 5.5 of
93 * @param keyPacket a PGP Key Material Packet as defined in section 5.5 of
9494 * <a href="http://www.ietf.org/rfc/rfc2440.txt"/>RFC 2440</a> (may
95 * be <code>null</code>). The array is cloned to prevent subsequent
95 * be <code>null</code>). The array is cloned to prevent subsequent
9696 * modification.
9797 * @param other a list of {@link XMLStructure}s representing elements from
9898 * an external namespace. The list is defensively copied to prevent
9999 * subsequent modification. May be <code>null</code> or empty.
100100 * @throws NullPointerException if <code>keyId</code> is <code>null</code>
101 * @throws IllegalArgumentException if the key id or packet is not in the
101 * @throws IllegalArgumentException if the key id or packet is not in the
102102 * correct format
103103 * @throws ClassCastException if <code>other</code> contains any
104104 * entries that are not of type {@link XMLStructure}
105105 */
106106 public DOMPGPData(byte[] keyId, byte[] keyPacket,
107 List<? extends XMLStructure> other)
107 List<? extends XMLStructure> other)
108108 {
109109 if (keyId == null) {
110110 throw new NullPointerException("keyId cannot be null");
190190 * section 4 of RFC 2440.
191191 *
192192 * This method only checks if the packet contains a valid tag. The
193 * contents of the packet should be checked by the application.
193 * contents of the packet should be checked by the application.
194194 */
195195 private void checkKeyPacket(byte[] keyPacket) {
196196 // length must be at least 3 (one byte for tag, one byte for length,
2626 * ===========================================================================
2727 */
2828 /*
29 * $Id: DOMReference.java 1602127 2014-06-12 11:33:42Z coheigea $
29 * $Id: DOMReference.java 1667527 2015-03-18 12:54:20Z mullan $
3030 */
3131 package org.apache.jcp.xml.dsig.internal.dom;
3232
5656 * @author Sean Mullan
5757 * @author Joyce Leung
5858 */
59 public final class DOMReference extends DOMStructure
59 public final class DOMReference extends DOMStructure
6060 implements Reference, DOMURIReference {
61
61
6262 /**
6363 * The maximum number of transforms per reference, if secure validation is enabled.
6464 */
181181 this.appliedTransformData = result;
182182 this.provider = provider;
183183 }
184
184
185185 /**
186186 * Creates a <code>DOMReference</code> from an element.
187187 *
188188 * @param refElem a Reference element
189189 */
190 public DOMReference(Element refElem, XMLCryptoContext context,
190 public DOMReference(Element refElem, XMLCryptoContext context,
191191 Provider provider)
192192 throws MarshalException
193193 {
194194 boolean secVal = Utils.secureValidation(context);
195
195
196196 // unmarshal Transforms, if specified
197197 Element nextSibling = DOMUtils.getFirstChildElement(refElem);
198198 List<Transform> transforms = new ArrayList<Transform>(5);
233233 Element dmElem = nextSibling;
234234 this.digestMethod = DOMDigestMethod.unmarshal(dmElem);
235235 String digestMethodAlgorithm = this.digestMethod.getAlgorithm();
236 if (secVal
236 if (secVal
237237 && MessageDigestAlgorithm.ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5.equals(digestMethodAlgorithm)) {
238238 throw new MarshalException(
239239 "It is forbidden to use algorithm " + digestMethod + " when secure validation is enabled"
343343 xwriter.writeEndElement(); // "Reference"
344344 }
345345
346 public void digest(XMLSignContext signContext)
346 public void digest(XMLSignContext signContext)
347347 throws XMLSignatureException
348348 {
349349 Data data = null;
406406 return dis;
407407 }
408408
409 private Data dereference(XMLCryptoContext context)
409 private Data dereference(XMLCryptoContext context)
410410 throws XMLSignatureException
411411 {
412412 Data data = null;
429429 return data;
430430 }
431431
432 private byte[] transform(Data dereferencedData,
432 private byte[] transform(Data dereferencedData,
433433 XMLCryptoContext context)
434434 throws XMLSignatureException
435435 {
463463 data = transform.transform(data, context, os);
464464 }
465465 }
466
466
467467 if (data != null) {
468468 XMLSignatureInput xi;
469469 // explicitly use C14N 1.1 when generating signature
519519 spi = TransformService.getInstance(c14nalg, "DOM");
520520 }
521521 }
522
522
523523 DOMTransform t = new DOMTransform(spi);
524524 Element transformsElem = null;
525525 String dsPrefix = DOMUtils.getSignaturePrefix(context);
526526 if (allTransforms.isEmpty()) {
527527 transformsElem = DOMUtils.createElement(
528 refElem.getOwnerDocument(),
528 refElem.getOwnerDocument(),
529529 "Transforms", XMLSignature.XMLNS, dsPrefix);
530 refElem.insertBefore(transformsElem,
530 refElem.insertBefore(transformsElem,
531531 DOMUtils.getFirstChildElement(refElem));
532532 } else {
533533 transformsElem = DOMUtils.getFirstChildElement(refElem);
561561 os.close();
562562 } catch (IOException e) {
563563 throw new XMLSignatureException(e);
564 }
564 }
565565 }
566566 if (dos != null) {
567567 try {
568568 dos.close();
569569 } catch (IOException e) {
570570 throw new XMLSignatureException(e);
571 }
571 }
572572 }
573573 }
574574 }
599599 Arrays.equals(digestValue, oref.getDigestValue());
600600
601601 return digestMethod.equals(oref.getDigestMethod()) && idsEqual &&
602 urisEqual && typesEqual &&
602 urisEqual && typesEqual &&
603603 allTransforms.equals(oref.getTransforms()) && digestValuesEqual;
604604 }
605
605
606606 @Override
607607 public int hashCode() {
608608 int result = 17;
620620 }
621621 result = 31 * result + digestMethod.hashCode();
622622 result = 31 * result + allTransforms.hashCode();
623
623
624624 return result;
625625 }
626626
2626 * ===========================================================================
2727 */
2828 /*
29 * $Id: DOMRetrievalMethod.java 1650331 2015-01-08 17:03:10Z coheigea $
29 * $Id: DOMRetrievalMethod.java 1667527 2015-03-18 12:54:20Z mullan $
3030 */
3131 package org.apache.jcp.xml.dsig.internal.dom;
3232
7373 private Attr here;
7474
7575 /**
76 * Creates a <code>DOMRetrievalMethod</code> containing the specified
76 * Creates a <code>DOMRetrievalMethod</code> containing the specified
7777 * URIReference and List of Transforms.
7878 *
7979 * @param uri the URI
8181 * @param transforms a list of {@link Transform}s. The list is defensively
8282 * copied to prevent subsequent modification. May be <code>null</code>
8383 * or empty.
84 * @throws IllegalArgumentException if the format of <code>uri</code> is
84 * @throws IllegalArgumentException if the format of <code>uri</code> is
8585 * invalid, as specified by Reference's URI attribute in the W3C
8686 * specification for XML-Signature Syntax and Processing
8787 * @throws NullPointerException if <code>uriReference</code>
88 * is <code>null</code>
88 * is <code>null</code>
8989 * @throws ClassCastException if <code>transforms</code> contains any
9090 * entries that are not of type {@link Transform}
9191 */
118118
119119 this.type = type;
120120 }
121
121
122122 /**
123123 * Creates a <code>DOMRetrievalMethod</code> from an element.
124124 *
134134
135135 // get here node
136136 here = rmElem.getAttributeNodeNS(null, "URI");
137
137
138138 boolean secVal = Utils.secureValidation(context);
139139
140140 // get Transforms, if specified
141141 List<Transform> transforms = new ArrayList<Transform>();
142142 Element transformsElem = DOMUtils.getFirstChildElement(rmElem);
143
143
144144 if (transformsElem != null) {
145145 String localName = transformsElem.getLocalName();
146146 String namespace = transformsElem.getNamespaceURI();
226226 }
227227
228228 /*
229 * If URIDereferencer is specified in context; use it, otherwise use
229 * If URIDereferencer is specified in context; use it, otherwise use
230230 * built-in.
231231 */
232232 URIDereferencer deref = context.getURIDereferencer();
304304 return uri.equals(orm.getURI()) &&
305305 transforms.equals(orm.getTransforms()) && typesEqual;
306306 }
307
307
308308 @Override
309309 public int hashCode() {
310310 int result = 17;
313313 }
314314 result = 31 * result + uri.hashCode();
315315 result = 31 * result + transforms.hashCode();
316
316
317317 return result;
318318 }
319319 }
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMSignatureMethod.java 1599464 2014-06-03 10:12:00Z coheigea $
22 * $Id: DOMSignatureMethod.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
4949
5050 private SignatureMethodParameterSpec params;
5151 private Signature signature;
52
52
5353 // see RFC 4051 for these algorithm definitions
5454 static final String RSA_SHA224 =
5555 "http://www.w3.org/2001/04/xmldsig-more#rsa-sha224";
9797 * @throws InvalidAlgorithmParameterException if the parameters are not
9898 * appropriate for this signature method
9999 */
100 DOMSignatureMethod(AlgorithmParameterSpec params)
100 DOMSignatureMethod(AlgorithmParameterSpec params)
101101 throws InvalidAlgorithmParameterException
102102 {
103 if (params != null &&
103 if (params != null &&
104104 !(params instanceof SignatureMethodParameterSpec)) {
105105 throw new InvalidAlgorithmParameterException
106106 ("params must be of type SignatureMethodParameterSpec");
726726 return Type.ECDSA;
727727 }
728728 }
729
729
730730 }
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMSignatureProperties.java 1602377 2014-06-13 11:20:43Z coheigea $
22 * $Id: DOMSignatureProperties.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
3838 */
3939 public final class DOMSignatureProperties extends BaseStructure
4040 implements SignatureProperties {
41
41
4242 private final String id;
4343 private final List<SignatureProperty> properties;
4444
4545 /**
46 * Creates a <code>DOMSignatureProperties</code> from the specified
46 * Creates a <code>DOMSignatureProperties</code> from the specified
4747 * parameters.
4848 *
49 * @param properties a list of one or more {@link SignatureProperty}s. The
49 * @param properties a list of one or more {@link SignatureProperty}s. The
5050 * list is defensively copied to protect against subsequent modification.
5151 * @param id the Id (may be <code>null</code>)
5252 * @throws ClassCastException if <code>properties</code> contains any
151151
152152 return properties.equals(osp.getProperties()) && idsEqual;
153153 }
154
154
155155 @Override
156156 public int hashCode() {
157157 int result = 17;
159159 result = 31 * result + id.hashCode();
160160 }
161161 result = 31 * result + properties.hashCode();
162
162
163163 return result;
164164 }
165165 }
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMSignatureProperty.java 1602377 2014-06-13 11:20:43Z coheigea $
22 * $Id: DOMSignatureProperty.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
3838 */
3939 public final class DOMSignatureProperty extends BaseStructure
4040 implements SignatureProperty {
41
41
4242 private final String id;
4343 private final String target;
4444 private final List<XMLStructure> content;
5353 * @throws ClassCastException if <code>content</code> contains any
5454 * entries that are not of type {@link XMLStructure}
5555 * @throws IllegalArgumentException if <code>content</code> is empty
56 * @throws NullPointerException if <code>content</code> or
56 * @throws NullPointerException if <code>content</code> or
5757 * <code>target</code> is <code>null</code>
5858 */
5959 public DOMSignatureProperty(List<? extends XMLStructure> content,
159159 return equalsContent(ospContent) &&
160160 target.equals(osp.getTarget()) && idsEqual;
161161 }
162
162
163163 @Override
164164 public int hashCode() {
165165 int result = 17;
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMSignedInfo.java 1602353 2014-06-13 09:52:36Z coheigea $
22 * $Id: DOMSignedInfo.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
4545 * @author Sean Mullan
4646 */
4747 public final class DOMSignedInfo extends DOMStructure implements SignedInfo {
48
48
4949 /**
5050 * The maximum number of references per Manifest, if secure validation is enabled.
5151 */
5555 org.slf4j.LoggerFactory.getLogger(DOMSignedInfo.class);
5656
5757 /** Signature - NOT Recommended RSAwithMD5 */
58 private static final String ALGO_ID_SIGNATURE_NOT_RECOMMENDED_RSA_MD5 =
58 private static final String ALGO_ID_SIGNATURE_NOT_RECOMMENDED_RSA_MD5 =
5959 Constants.MoreAlgorithmsSpecNS + "rsa-md5";
60
60
6161 /** HMAC - NOT Recommended HMAC-MD5 */
62 private static final String ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5 =
62 private static final String ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5 =
6363 Constants.MoreAlgorithmsSpecNS + "hmac-md5";
64
64
6565 private List<Reference> references;
6666 private CanonicalizationMethod canonicalizationMethod;
6767 private SignatureMethod signatureMethod;
7777 * @param sm the signature method
7878 * @param references the list of references. The list is copied.
7979 * @throws NullPointerException if
80 * <code>cm</code>, <code>sm</code>, or <code>references</code> is
80 * <code>cm</code>, <code>sm</code>, or <code>references</code> is
8181 * <code>null</code>
8282 * @throws IllegalArgumentException if <code>references</code> is empty
8383 * @throws ClassCastException if any of the references are not of
120120 * @throws ClassCastException if any of the references are not of
121121 * type <code>Reference</code>
122122 */
123 public DOMSignedInfo(CanonicalizationMethod cm, SignatureMethod sm,
123 public DOMSignedInfo(CanonicalizationMethod cm, SignatureMethod sm,
124124 List<? extends Reference> references, String id) {
125125 this(cm, sm, references);
126126 this.id = id;
150150 "SignatureMethod",
151151 XMLSignature.XMLNS);
152152 signatureMethod = DOMSignatureMethod.unmarshal(smElem);
153
153
154154 boolean secVal = Utils.secureValidation(context);
155155
156156 String signatureMethodAlgorithm = signatureMethod.getAlgorithm();
160160 "It is forbidden to use algorithm " + signatureMethod + " when secure validation is enabled"
161161 );
162162 }
163
163
164164 // unmarshal References
165165 ArrayList<Reference> refList = new ArrayList<Reference>(5);
166166 Element refElem = DOMUtils.getNextSiblingElement(smElem, "Reference", XMLSignature.XMLNS);
167167 refList.add(new DOMReference(refElem, context, provider));
168
168
169169 refElem = DOMUtils.getNextSiblingElement(refElem);
170170 while (refElem != null) {
171171 String name = refElem.getLocalName();
217217 }
218218
219219 OutputStream os = new UnsyncBufferedOutputStream(bos);
220
220
221221 DOMSubTreeData subTree = new DOMSubTreeData(localSiElem, true);
222222 try {
223 ((DOMCanonicalizationMethod)
223 ((DOMCanonicalizationMethod)
224224 canonicalizationMethod).canonicalize(subTree, context, os);
225225 } catch (TransformException te) {
226226 throw new XMLSignatureException(te);
227227 }
228
228
229229 try {
230230 os.flush();
231231 } catch (IOException e) {
249249 }
250250
251251 this.canonData = new ByteArrayInputStream(signedInfoBytes);
252
252
253253 try {
254254 os.close();
255255 } catch (IOException e) {
322322 result = 31 * result + canonicalizationMethod.hashCode();
323323 result = 31 * result + signatureMethod.hashCode();
324324 result = 31 * result + references.hashCode();
325
325
326326 return result;
327327 }
328328 }
171171 nodeSet.add(node);
172172 break;
173173 case Node.COMMENT_NODE:
174 if (withComments) {
174 if (withComments) {
175175 nodeSet.add(node);
176176 }
177177 }
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMTransform.java 1585385 2014-04-07 05:12:23Z coheigea $
22 * $Id: DOMTransform.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
186186
187187 return result;
188188 }
189
189
190190 /**
191191 * Transforms the specified data using the underlying transform algorithm.
192192 * This method invokes the {@link #marshal marshal} method and passes it
198198 * @param context the marshalling context
199199 * @return the transformed data
200200 * @throws MarshalException if an exception occurs while marshalling
201 * @throws NullPointerException if <code>data</code> or <code>context</code>
201 * @throws NullPointerException if <code>data</code> or <code>context</code>
202202 * is <code>null</code>
203203 * @throws XMLSignatureException if an unexpected error occurs while
204204 * executing the transform
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMURIDereferencer.java 1537952 2013-11-01 15:17:16Z coheigea $
22 * $Id: DOMURIDereferencer.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
4141 * @author Sean Mullan
4242 */
4343 public class DOMURIDereferencer implements URIDereferencer {
44
44
4545 static final URIDereferencer INSTANCE = new DOMURIDereferencer();
4646
4747 private DOMURIDereferencer() {
6666 String uri = uriRef.getURI();
6767 DOMCryptoContext dcc = (DOMCryptoContext) context;
6868 String baseURI = context.getBaseURI();
69
69
7070 boolean secVal = Utils.secureValidation(context);
71
71
7272 // Check if same-document URI and already registered on the context
7373 if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') {
7474 String id = uri.substring(1);
8888 throw new URIReferenceException(error);
8989 }
9090 }
91
91
9292 XMLSignatureInput result = new XMLSignatureInput(referencedElem);
9393 result.setSecureValidation(secVal);
9494 if (!uri.substring(1).startsWith("xpointer(id(")) {
9797
9898 result.setMIMEType("text/xml");
9999 if (baseURI != null && baseURI.length() > 0) {
100 result.setSourceURI(baseURI.concat(uriAttr.getNodeValue()));
100 result.setSourceURI(baseURI.concat(uriAttr.getNodeValue()));
101101 } else {
102 result.setSourceURI(uriAttr.getNodeValue());
102 result.setSourceURI(uriAttr.getNodeValue());
103103 }
104104 return new ApacheNodeSetData(result);
105105 }
106 }
106 }
107107
108108 try {
109 ResourceResolver apacheResolver =
109 ResourceResolver apacheResolver =
110110 ResourceResolver.getInstance(uriAttr, baseURI, secVal);
111111 XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI, secVal);
112112 if (in.isOctetStream()) {
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMUtils.java 1602377 2014-06-13 11:20:43Z coheigea $
22 * $Id: DOMUtils.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
4444 public final class DOMUtils {
4545
4646 // class cannot be instantiated
47 private DOMUtils() {}
47 private DOMUtils() {}
4848
4949 /**
5050 * Returns the owner document of the specified node.
9292 }
9393
9494 /**
95 * Sets an element's attribute (using DOM level 2) with the
95 * Sets an element's attribute (using DOM level 2) with the
9696 * specified value and namespace prefix.
9797 *
9898 * @param elem the element to set the attribute on
9999 * @param name the name of the attribute
100 * @param value the attribute value. If null, no attribute is set.
100 * @param value the attribute value. If null, no attribute is set.
101101 */
102102 public static void setAttribute(Element elem, String name, String value) {
103103 if (value == null) {
107107 }
108108
109109 /**
110 * Sets an element's attribute (using DOM level 2) with the
110 * Sets an element's attribute (using DOM level 2) with the
111111 * specified value and namespace prefix AND registers the ID value with
112112 * the specified element. This is for resolving same-document
113113 * ID references.
114114 *
115115 * @param elem the element to set the attribute on
116116 * @param name the name of the attribute
117 * @param value the attribute value. If null, no attribute is set.
117 * @param value the attribute value. If null, no attribute is set.
118118 */
119119 public static void setAttributeID(Element elem, String name, String value) {
120120 if (value == null) {
125125 }
126126
127127 /**
128 * Returns the first child element of the specified node, or null if there
128 * Returns the first child element of the specified node, or null if there
129129 * is no such element.
130130 *
131131 * @param node the node
132 * @return the first child element of the specified node, or null if there
132 * @return the first child element of the specified node, or null if there
133133 * is no such element
134134 * @throws NullPointerException if <code>node == null</code>
135135 */
206206 }
207207
208208 /**
209 * Returns the last child element of the specified node, or null if there
209 * Returns the last child element of the specified node, or null if there
210210 * is no such element.
211211 *
212212 * @param node the node
213 * @return the last child element of the specified node, or null if there
213 * @return the last child element of the specified node, or null if there
214214 * is no such element
215215 * @throws NullPointerException if <code>node == null</code>
216216 */
223223 }
224224
225225 /**
226 * Returns the next sibling element of the specified node, or null if there
226 * Returns the next sibling element of the specified node, or null if there
227227 * is no such element.
228228 *
229229 * @param node the node
230 * @return the next sibling element of the specified node, or null if there
230 * @return the next sibling element of the specified node, or null if there
231231 * is no such element
232232 * @throws NullPointerException if <code>node == null</code>
233233 */
238238 }
239239 return (Element)sibling;
240240 }
241
241
242242 /**
243243 * Returns the next sibling element of the specified node and checks that
244244 * the local name is equal to {@code localName}.
275275
276276 /**
277277 * Returns the attribute value for the attribute with the specified name.
278 * Returns null if there is no such attribute, or
278 * Returns null if there is no such attribute, or
279279 * the empty string if the attribute value is empty.
280280 *
281281 * <p>This works around a limitation of the DOM
356356 };
357357 }
358358 }
359
359
360360 /**
361361 * Returns the prefix associated with the specified namespace URI
362362 *
384384 public static String getSignaturePrefix(XMLCryptoContext context) {
385385 return getNSPrefix(context, XMLSignature.XMLNS);
386386 }
387
387
388388 /**
389389 * Removes all children nodes from the specified node.
390390 *
414414 }
415415
416416 /**
417 * Checks if child element has same owner document before
417 * Checks if child element has same owner document before
418418 * appending to the parent, and imports it to the parent's document
419419 * if necessary.
420420 */
501501 }
502502 Node ostylesheetElem =
503503 ((javax.xml.crypto.dom.DOMStructure) ostylesheet).getNode();
504 XMLStructure stylesheet = spec1.getStylesheet();
504 XMLStructure stylesheet = spec1.getStylesheet();
505505 Node stylesheetElem =
506506 ((javax.xml.crypto.dom.DOMStructure) stylesheet).getNode();
507507 return nodesEqual(stylesheetElem, ostylesheetElem);
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMX509Data.java 1602377 2014-06-13 11:20:43Z coheigea $
22 * $Id: DOMX509Data.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
5555 * {@link String} (subject names), <code>byte[]</code> (subject key ids),
5656 * {@link java.security.cert.X509Certificate}, {@link X509CRL},
5757 * or {@link javax.xml.dsig.XMLStructure}
58 * objects or elements from an external namespace). The list is
58 * objects or elements from an external namespace). The list is
5959 * defensively copied to protect against subsequent modification.
6060 * @throws NullPointerException if <code>content</code> is <code>null</code>
6161 * @throws IllegalArgumentException if <code>content</code> is empty
185185 }
186186 }
187187
188 private X509Certificate unmarshalX509Certificate(Element elem)
188 private X509Certificate unmarshalX509Certificate(Element elem)
189189 throws MarshalException
190190 {
191191 try {
205205 }
206206 }
207207
208 private ByteArrayInputStream unmarshalBase64Binary(Element elem)
208 private ByteArrayInputStream unmarshalBase64Binary(Element elem)
209209 throws MarshalException {
210210 try {
211211 if (cf == null) {
240240 Object x = content.get(i);
241241 Object ox = ocontent.get(i);
242242 if (x instanceof byte[]) {
243 if (!(ox instanceof byte[]) ||
243 if (!(ox instanceof byte[]) ||
244244 !Arrays.equals((byte[])x, (byte[])ox)) {
245245 return false;
246 }
246 }
247247 } else {
248248 if (!(x.equals(ox))) {
249249 return false;
253253
254254 return true;
255255 }
256
256
257257 @Override
258258 public int hashCode() {
259259 int result = 17;
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMX509IssuerSerial.java 1602127 2014-06-12 11:33:42Z coheigea $
22 * $Id: DOMX509IssuerSerial.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
4545 private final BigInteger serialNumber;
4646
4747 /**
48 * Creates a <code>DOMX509IssuerSerial</code> containing the specified
48 * Creates a <code>DOMX509IssuerSerial</code> containing the specified
4949 * issuer distinguished name/serial number pair.
5050 *
51 * @param issuerName the X.509 issuer distinguished name in RFC 2253
51 * @param issuerName the X.509 issuer distinguished name in RFC 2253
5252 * String format
5353 * @param serialNumber the serial number
5454 * @throws IllegalArgumentException if the format of <code>issuerName</code>
5555 * is not RFC 2253 compliant
56 * @throws NullPointerException if <code>issuerName</code> or
57 * <code>serialNumber</code> is <code>null</code>
56 * @throws NullPointerException if <code>issuerName</code> or
57 * <code>serialNumber</code> is <code>null</code>
5858 */
5959 public DOMX509IssuerSerial(String issuerName, BigInteger serialNumber) {
6060 if (issuerName == null) {
107107 return issuerName.equals(ois.getIssuerName()) &&
108108 serialNumber.equals(ois.getSerialNumber());
109109 }
110
110
111111 @Override
112112 public int hashCode() {
113113 int result = 17;
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMXMLObject.java 1602377 2014-06-13 11:20:43Z coheigea $
22 * $Id: DOMXMLObject.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
9090 {
9191 // unmarshal attributes
9292 this.encoding = DOMUtils.getAttributeValue(objElem, "Encoding");
93
93
9494 Attr attr = objElem.getAttributeNodeNS(null, "Id");
9595 if (attr != null) {
9696 this.id = attr.getValue();
206206 return idsEqual && encodingsEqual && mimeTypesEqual &&
207207 equalsContent(getXmlObjectContent(oxo));
208208 }
209
209
210210 @Override
211211 public int hashCode() {
212212 int result = 17;
2626 * ===========================================================================
2727 */
2828 /*
29 * $Id: DOMXMLSignature.java 1602127 2014-06-12 11:33:42Z coheigea $
29 * $Id: DOMXMLSignature.java 1667527 2015-03-18 12:54:20Z mullan $
3030 */
3131 package org.apache.jcp.xml.dsig.internal.dom;
3232
7474 static {
7575 org.apache.xml.security.Init.init();
7676 }
77
77
7878 /**
7979 * Creates a <code>DOMXMLSignature</code> from the specified components.
8080 *
133133 XMLSignature.XMLNS);
134134 si = new DOMSignedInfo(siElem, context, provider);
135135
136 // unmarshal SignatureValue
136 // unmarshal SignatureValue
137137 Element sigValElem = DOMUtils.getNextSiblingElement(siElem,
138138 "SignatureValue",
139139 XMLSignature.XMLNS);
163163 context, provider));
164164 nextSibling = DOMUtils.getNextSiblingElement(nextSibling);
165165 }
166 objects = Collections.unmodifiableList(tempObjects);
166 objects = Collections.unmodifiableList(tempObjects);
167167 }
168168 }
169169
232232 }
233233
234234 @Override
235 public boolean validate(XMLValidateContext vc)
235 public boolean validate(XMLValidateContext vc)
236236 throws XMLSignatureException
237237 {
238238 if (vc == null) {
315315 }
316316
317317 @Override
318 public void sign(XMLSignContext signContext)
318 public void sign(XMLSignContext signContext)
319319 throws MarshalException, XMLSignatureException
320320 {
321321 if (signContext == null) {
426426 si.equals(osig.getSignedInfo()) &&
427427 objects.equals(osig.getObjects());
428428 }
429
429
430430 @Override
431431 public int hashCode() {
432432 int result = 17;
483483 ref.digest(signContext);
484484 }
485485
486 public class DOMSignatureValue extends DOMStructure
486 public class DOMSignatureValue extends DOMStructure
487487 implements SignatureValue
488488 {
489489 private String id;
587587 //XXX compare signature values?
588588 return idEqual;
589589 }
590
590
591591 @Override
592592 public int hashCode() {
593593 int result = 17;
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMXMLSignatureFactory.java 1602127 2014-06-12 11:33:42Z coheigea $
22 * $Id: DOMXMLSignatureFactory.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
171171 throw new ClassCastException("xmlStructure must be of type DOMStructure");
172172 }
173173 return unmarshal
174 (((javax.xml.crypto.dom.DOMStructure) xmlStructure).getNode(),
174 (((javax.xml.crypto.dom.DOMStructure) xmlStructure).getNode(),
175175 new UnmarshalContext());
176176 }
177177
179179 UnmarshalContext() {}
180180 }
181181
182 private XMLSignature unmarshal(Node node, XMLCryptoContext context)
182 private XMLSignature unmarshal(Node node, XMLCryptoContext context)
183183 throws MarshalException {
184184
185185 node.normalize();
186
186
187187 Element element = null;
188188 if (node.getNodeType() == Node.DOCUMENT_NODE) {
189189 element = ((Document) node).getDocumentElement();
321321 public Transform newTransform(String algorithm,
322322 TransformParameterSpec params) throws NoSuchAlgorithmException,
323323 InvalidAlgorithmParameterException {
324
324
325325 TransformService spi;
326326 if (getProvider() == null) {
327327 spi = TransformService.getInstance(algorithm, "DOM");
332332 spi = TransformService.getInstance(algorithm, "DOM");
333333 }
334334 }
335
335
336336 spi.init(params);
337337 return new DOMTransform(spi);
338338 }
351351 spi = TransformService.getInstance(algorithm, "DOM");
352352 }
353353 }
354
354
355355 if (params == null) {
356356 spi.init(null);
357357 } else {
374374 spi = TransformService.getInstance(algorithm, "DOM");
375375 }
376376 }
377
377
378378 spi.init(params);
379379 return new DOMCanonicalizationMethod(spi);
380380 }
383383 public CanonicalizationMethod newCanonicalizationMethod(String algorithm,
384384 XMLStructure params) throws NoSuchAlgorithmException,
385385 InvalidAlgorithmParameterException {
386 TransformService spi;
386 TransformService spi;
387387 if (getProvider() == null) {
388388 spi = TransformService.getInstance(algorithm, "DOM");
389389 } else {
398398 } else {
399399 spi.init(params, null);
400400 }
401
401
402402 return new DOMCanonicalizationMethod(spi);
403403 }
404404
2626 * Portions copyright 2005 Sun Microsystems, Inc. All rights reserved.
2727 */
2828 /*
29 * $Id: DOMXPathFilter2Transform.java 1511298 2013-08-07 13:17:53Z coheigea $
29 * $Id: DOMXPathFilter2Transform.java 1667527 2015-03-18 12:54:20Z mullan $
3030 */
3131 package org.apache.jcp.xml.dsig.internal.dom;
3232
9191 XPathType.Filter filter = null;
9292 if (filterVal.equals("intersect")) {
9393 filter = XPathType.Filter.INTERSECT;
94 } else if (filterVal.equals("subtract")) {
94 } else if (filterVal.equals("subtract")) {
9595 filter = XPathType.Filter.SUBTRACT;
9696 } else if (filterVal.equals("union")) {
9797 filter = XPathType.Filter.UNION;
126126 throws MarshalException
127127 {
128128 super.marshalParams(parent, context);
129 XPathFilter2ParameterSpec xp =
129 XPathFilter2ParameterSpec xp =
130130 (XPathFilter2ParameterSpec)getParameterSpec();
131131 String prefix = DOMUtils.getNSPrefix(context, Transform.XPATH2);
132132 String qname = prefix == null || prefix.length() == 0
149149 xpathType.getNamespaceMap().entrySet();
150150 for (Map.Entry<String, String> entry : entries) {
151151 elem.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" +
152 entry.getKey(),
152 entry.getKey(),
153153 entry.getValue());
154154 }
155155
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMXPathTransform.java 1423915 2012-12-19 16:17:25Z coheigea $
22 * $Id: DOMXPathTransform.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
9090 throws MarshalException
9191 {
9292 super.marshalParams(parent, context);
93 XPathFilterParameterSpec xp =
93 XPathFilterParameterSpec xp =
9494 (XPathFilterParameterSpec)getParameterSpec();
9595 Element xpathElem = DOMUtils.createElement(ownerDoc, "XPath",
9696 XMLSignature.XMLNS, DOMUtils.getSignaturePrefix(context));
1919 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2020 */
2121 /*
22 * $Id: DOMXSLTTransform.java 1423915 2012-12-19 16:17:25Z coheigea $
22 * $Id: DOMXSLTTransform.java 1667527 2015-03-18 12:54:20Z mullan $
2323 */
2424 package org.apache.jcp.xml.dsig.internal.dom;
2525
6868 public void marshalParams(XMLStructure parent, XMLCryptoContext context)
6969 throws MarshalException {
7070 super.marshalParams(parent, context);
71 XSLTTransformParameterSpec xp =
71 XSLTTransformParameterSpec xp =
7272 (XSLTTransformParameterSpec) getParameterSpec();
73 Node xsltElem =
73 Node xsltElem =
7474 ((javax.xml.crypto.dom.DOMStructure) xp.getStylesheet()).getNode();
7575 DOMUtils.appendChild(transformElem, xsltElem);
7676 }
2626 * Portions copyright 2005 Sun Microsystems, Inc. All rights reserved.
2727 */
2828 /*
29 * $Id: XMLDSigRI.java 1626713 2014-09-22 09:40:15Z coheigea $
29 * $Id: XMLDSigRI.java 1667527 2015-03-18 12:54:20Z mullan $
3030 */
3131 package org.apache.jcp.xml.dsig.internal.dom;
3232
5656
5757 public XMLDSigRI() {
5858 /* We are the ApacheXMLDSig provider */
59 super("ApacheXMLDSig", 2.03, INFO);
59 super("ApacheXMLDSig", 2.04, INFO);
6060
6161 final Map<Object, Object> map = new HashMap<Object, Object>();
6262 map.put("XMLSignatureFactory.DOM",
8989 map.put("TransformService.http://www.w3.org/2006/12/xml-c14n11" +
9090 " MechanismType", "DOM");
9191
92 // InclusiveWithComments C14N 1.1
92 // InclusiveWithComments C14N 1.1
9393 map.put("TransformService.http://www.w3.org/2006/12/xml-c14n11#WithComments",
9494 "org.apache.jcp.xml.dsig.internal.dom.DOMCanonicalXMLC14N11Method");
9595 map.put("TransformService.http://www.w3.org/2006/12/xml-c14n11#WithComments" +
5959 // Digest algorithms
6060 algorithmsMap.put(
6161 MessageDigestAlgorithm.ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5,
62 new Algorithm("MD5", "MD5", "MessageDigest")
62 new Algorithm("", "MD5", "MessageDigest")
6363 );
6464 algorithmsMap.put(
6565 MessageDigestAlgorithm.ALGO_ID_DIGEST_RIPEMD160,
66 new Algorithm("RIPEMD160", "RIPEMD160", "MessageDigest")
66 new Algorithm("", "RIPEMD160", "MessageDigest")
6767 );
6868 algorithmsMap.put(
6969 MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA1,
70 new Algorithm("SHA-1", "SHA-1", "MessageDigest")
70 new Algorithm("", "SHA-1", "MessageDigest")
7171 );
7272 algorithmsMap.put(
7373 MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA224,
74 new Algorithm("SHA-224", "SHA-224", "MessageDigest")
74 new Algorithm("", "SHA-224", "MessageDigest")
7575 );
7676 algorithmsMap.put(
7777 MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA256,
78 new Algorithm("SHA-256", "SHA-256", "MessageDigest")
78 new Algorithm("", "SHA-256", "MessageDigest")
7979 );
8080 algorithmsMap.put(
8181 MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA384,
82 new Algorithm("SHA-384", "SHA-384", "MessageDigest")
82 new Algorithm("", "SHA-384", "MessageDigest")
8383 );
8484 algorithmsMap.put(
8585 MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA512,
86 new Algorithm("SHA-512", "SHA-512", "MessageDigest")
86 new Algorithm("", "SHA-512", "MessageDigest")
8787 );
8888 algorithmsMap.put(
8989 MessageDigestAlgorithm.ALGO_ID_DIGEST_WHIRLPOOL,
90 new Algorithm("WHIRLPOOL", "WHIRLPOOL", "MessageDigest")
90 new Algorithm("", "WHIRLPOOL", "MessageDigest")
9191 );
9292 algorithmsMap.put(
9393 MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA3_224,
94 new Algorithm("SHA3-224", "SHA3-224", "MessageDigest")
94 new Algorithm("", "SHA3-224", "MessageDigest")
9595 );
9696 algorithmsMap.put(
9797 MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA3_256,
98 new Algorithm("SHA3-256", "SHA3-256", "MessageDigest")
98 new Algorithm("", "SHA3-256", "MessageDigest")
9999 );
100100 algorithmsMap.put(
101101 MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA3_384,
102 new Algorithm("SHA3-384", "SHA3-384", "MessageDigest")
102 new Algorithm("", "SHA3-384", "MessageDigest")
103103 );
104104 algorithmsMap.put(
105105 MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA3_512,
106 new Algorithm("SHA3-512", "SHA3-512", "MessageDigest")
106 new Algorithm("", "SHA3-512", "MessageDigest")
107107 );
108108 // Signature algorithms
109109 algorithmsMap.put(
110110 XMLSignature.ALGO_ID_SIGNATURE_DSA,
111 new Algorithm("SHA1withDSA", "SHA1withDSA", "Signature")
111 new Algorithm("DSA", "SHA1withDSA", "Signature")
112112 );
113113 algorithmsMap.put(
114114 XMLSignature.ALGO_ID_SIGNATURE_DSA_SHA256,
115 new Algorithm("", "SHA256withDSA", "Signature")
115 new Algorithm("DSA", "SHA256withDSA", "Signature")
116116 );
117117 algorithmsMap.put(
118118 XMLSignature.ALGO_ID_SIGNATURE_NOT_RECOMMENDED_RSA_MD5,
119 new Algorithm("MD5withRSA", "MD5withRSA", "Signature")
119 new Algorithm("RSA", "MD5withRSA", "Signature")
120120 );
121121 algorithmsMap.put(
122122 XMLSignature.ALGO_ID_SIGNATURE_RSA_RIPEMD160,
123 new Algorithm("RIPEMD160withRSA", "RIPEMD160withRSA", "Signature")
123 new Algorithm("RSA", "RIPEMD160withRSA", "Signature")
124124 );
125125 algorithmsMap.put(
126126 XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1,
127 new Algorithm("SHA1withRSA", "SHA1withRSA", "Signature")
127 new Algorithm("RSA", "SHA1withRSA", "Signature")
128128 );
129129 algorithmsMap.put(
130130 XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA224,
131 new Algorithm("SHA224withRSA", "SHA224withRSA", "Signature")
131 new Algorithm("RSA", "SHA224withRSA", "Signature")
132132 );
133133 algorithmsMap.put(
134134 XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256,
135 new Algorithm("SHA256withRSA", "SHA256withRSA", "Signature")
135 new Algorithm("RSA", "SHA256withRSA", "Signature")
136136 );
137137 algorithmsMap.put(
138138 XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA384,
139 new Algorithm("SHA384withRSA", "SHA384withRSA", "Signature")
139 new Algorithm("RSA", "SHA384withRSA", "Signature")
140140 );
141141 algorithmsMap.put(
142142 XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA512,
143 new Algorithm("SHA512withRSA", "SHA512withRSA", "Signature")
143 new Algorithm("RSA", "SHA512withRSA", "Signature")
144144 );
145145 algorithmsMap.put(
146146 XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1_MGF1,
147 new Algorithm("SHA1withRSAandMGF1", "SHA1withRSAandMGF1", "Signature")
147 new Algorithm("RSA", "SHA1withRSAandMGF1", "Signature")
148148 );
149149 algorithmsMap.put(
150150 XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA224_MGF1,
151 new Algorithm("SHA224withRSAandMGF1", "SHA224withRSAandMGF1", "Signature")
151 new Algorithm("RSA", "SHA224withRSAandMGF1", "Signature")
152152 );
153153 algorithmsMap.put(
154154 XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256_MGF1,
155 new Algorithm("SHA256withRSAandMGF1", "SHA256withRSAandMGF1", "Signature")
155 new Algorithm("RSA", "SHA256withRSAandMGF1", "Signature")
156156 );
157157 algorithmsMap.put(
158158 XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA384_MGF1,
159 new Algorithm("SHA384withRSAandMGF1", "SHA384withRSAandMGF1", "Signature")
159 new Algorithm("RSA", "SHA384withRSAandMGF1", "Signature")
160160 );
161161 algorithmsMap.put(
162162 XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA512_MGF1,
163 new Algorithm("SHA512withRSAandMGF1", "SHA512withRSAandMGF1", "Signature")
163 new Algorithm("RSA", "SHA512withRSAandMGF1", "Signature")
164164 );
165165 algorithmsMap.put(
166166 XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA1,
167 new Algorithm("SHA1withECDSA", "SHA1withECDSA", "Signature")
167 new Algorithm("EC", "SHA1withECDSA", "Signature")
168168 );
169169 algorithmsMap.put(
170170 XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA224,
171 new Algorithm("SHA224withECDSA", "SHA224withECDSA", "Signature")
171 new Algorithm("EC", "SHA224withECDSA", "Signature")
172172 );
173173 algorithmsMap.put(
174174 XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA256,
175 new Algorithm("SHA256withECDSA", "SHA256withECDSA", "Signature")
175 new Algorithm("EC", "SHA256withECDSA", "Signature")
176176 );
177177 algorithmsMap.put(
178178 XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA384,
179 new Algorithm("SHA384withECDSA", "SHA384withECDSA", "Signature")
179 new Algorithm("EC", "SHA384withECDSA", "Signature")
180180 );
181181 algorithmsMap.put(
182182 XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA512,
183 new Algorithm("SHA512withECDSA", "SHA512withECDSA", "Signature")
183 new Algorithm("EC", "SHA512withECDSA", "Signature")
184184 );
185185 algorithmsMap.put(
186186 XMLSignature.ALGO_ID_SIGNATURE_ECDSA_RIPEMD160,
187 new Algorithm("RIPEMD160withECDSA", "RIPEMD160withECDSA", "Signature")
187 new Algorithm("EC", "RIPEMD160withECDSA", "Signature")
188188 );
189189 algorithmsMap.put(
190190 XMLSignature.ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5,
191 new Algorithm("HmacMD5", "HmacMD5", "Mac", 128, 0)
191 new Algorithm("", "HmacMD5", "Mac", 128, 0)
192192 );
193193 algorithmsMap.put(
194194 XMLSignature.ALGO_ID_MAC_HMAC_RIPEMD160,
195 new Algorithm("HMACRIPEMD160", "HMACRIPEMD160", "Mac", 160, 0)
195 new Algorithm("", "HMACRIPEMD160", "Mac", 160, 0)
196196 );
197197 algorithmsMap.put(
198198 XMLSignature.ALGO_ID_MAC_HMAC_SHA1,
199 new Algorithm("HmacSHA1", "HmacSHA1", "Mac", 160, 0)
199 new Algorithm("", "HmacSHA1", "Mac", 160, 0)
200200 );
201201 algorithmsMap.put(
202202 XMLSignature.ALGO_ID_MAC_HMAC_SHA224,
203 new Algorithm("HmacSHA224", "HmacSHA224", "Mac", 224, 0)
203 new Algorithm("", "HmacSHA224", "Mac", 224, 0)
204204 );
205205 algorithmsMap.put(
206206 XMLSignature.ALGO_ID_MAC_HMAC_SHA256,
207 new Algorithm("HmacSHA256", "HmacSHA256", "Mac", 256, 0)
207 new Algorithm("", "HmacSHA256", "Mac", 256, 0)
208208 );
209209 algorithmsMap.put(
210210 XMLSignature.ALGO_ID_MAC_HMAC_SHA384,
211 new Algorithm("HmacSHA384", "HmacSHA384", "Mac", 384, 0)
211 new Algorithm("", "HmacSHA384", "Mac", 384, 0)
212212 );
213213 algorithmsMap.put(
214214 XMLSignature.ALGO_ID_MAC_HMAC_SHA512,
215 new Algorithm("HmacSHA512", "HmacSHA512", "Mac", 512, 0)
215 new Algorithm("", "HmacSHA512", "Mac", 512, 0)
216216 );
217217 // Encryption algorithms
218218 algorithmsMap.put(
352352 Element HMElem =
353353 XMLUtils.createElementInSignatureSpace(doc, Constants._TAG_HMACOUTPUTLENGTH);
354354 Text HMText =
355 doc.createTextNode(Integer.valueOf(this.HMACOutputLength).toString());
355 doc.createTextNode("" + this.HMACOutputLength);
356356
357357 HMElem.appendChild(HMText);
358358 XMLUtils.addReturnToElement(element);
+0
-3
src/main/java/org/apache/xml/security/algorithms/implementations/package.html less more
0 <HTML> <HEAD> </HEAD> <BODY> <P>
1 implementations of {@link org.apache.xml.security.algorithms.SignatureAlgorithmSpi}.
2 </P></BODY> </HTML>
+0
-3
src/main/java/org/apache/xml/security/algorithms/package.html less more
0 <HTML><HEAD></HEAD><BODY><P>
1 algorithm factories.
2 </P></BODY></HTML>
+0
-3
src/main/java/org/apache/xml/security/c14n/helper/package.html less more
0 <HTML> <HEAD> </HEAD> <BODY> <P>
1 helper classes for canonicalization.
2 </P></BODY> </HTML>
4949 * <i>THIS </i> implementation is a complete rewrite of the algorithm.
5050 *
5151 * @author Christian Geuer-Pollmann <geuerp@apache.org>
52 * @version $Revision: 1558567 $
52 * @version $Revision: 1657393 $
5353 * @see <a href="http://www.w3.org/TR/2002/REC-xml-exc-c14n-20020718/ Exclusive#">
5454 * XML Canonicalization, Version 1.0</a>
5555 */
+0
-3
src/main/java/org/apache/xml/security/c14n/implementations/package.html less more
0 <HTML> <HEAD> </HEAD> <BODY> <P>
1 canonicalization implementations.
2 </P></BODY> </HTML>
+0
-3
src/main/java/org/apache/xml/security/c14n/package.html less more
0 <HTML><HEAD></HEAD><BODY><P>
1 Canonicalization related material and algorithms.
2 </P></BODY></HTML>
251251 CAMELLIA_128_KeyWrap + "\n" + CAMELLIA_192_KeyWrap + "\n" + CAMELLIA_256_KeyWrap + "\n" +
252252 SEED_128_KeyWrap + "\n";
253253
254 private static final boolean HAVE_FUNCTIONAL_IDENTITY_TRANSFORMER = haveFunctionalIdentityTransformer();
255
254256 /** Cipher created during initialisation that is used for encryption */
255257 private Cipher contextCipher;
256258
356358 }
357359
358360 if (serializer == null) {
359 serializer = new TransformSerializer();
361 if (HAVE_FUNCTIONAL_IDENTITY_TRANSFORMER) {
362 serializer = new TransformSerializer();
363 } else {
364 serializer = new DocumentSerializer();
365 }
360366 }
361367 serializer.setCanonicalizer(this.canon);
362368
36673673 }
36683674 }
36693675 }
3676
3677 private static boolean haveFunctionalIdentityTransformer() {
3678 final String xml =
3679 "<a:e1 xmlns:a=\"a\" xmlns:b=\"b\">"
3680 + "<a xmlns=\"a\" xmlns:b=\"b\"/>"
3681 + "</a:e1>";
3682
3683 try {
3684 final javax.xml.transform.dom.DOMResult domResult = new javax.xml.transform.dom.DOMResult();
3685 final javax.xml.transform.TransformerFactory transformerFactory =
3686 javax.xml.transform.TransformerFactory.newInstance();
3687 transformerFactory.newTransformer().transform(
3688 new javax.xml.transform.stream.StreamSource(
3689 new java.io.ByteArrayInputStream(xml.getBytes("UTF-8"))), domResult);
3690
3691 final boolean result = "http://www.w3.org/2000/xmlns/".equals(
3692 domResult.getNode().getFirstChild().getFirstChild().getAttributes().item(1).getNamespaceURI());
3693 log.debug("Have functional IdentityTransformer: " + result);
3694 return result;
3695
3696 } catch (Exception e) {
3697 log.debug(e.getMessage(), e);
3698 return false;
3699 }
3700 }
36703701 }
+0
-25
src/main/java/org/apache/xml/security/encryption/package.html less more
0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
1 <html>
2 <head>
3 <title></title>
4 </head>
5 <body>
6 Provides classes for implementing XML Encryption applications. There are two
7 main families of classes in this package. The first group of classes is an
8 XML Schema to Java mapping of &nbsp;the complex types and elements of the
9 XML Encryption Schema as outllined at <a
10 href="http://www.w3.org/Encryption/2001/Drafts/xmlenc-core/">XML Encrtypyion
11 Specification</a>. The second group of classes are used to perform encryption
12 operations, and to manipulate the first group of classes. The most important
13 classes in this second group is <code><a
14 href="file://./org/apache/xml/security/encryption/XMLCipher.html">XMLCipher</a></code>,
15 <code><a
16 href="file://./org/apache/xml/security/encryption/XMLEncryptionFactory.html">XMLEncryptionFactory</a></code>
17 and <code>XMLSerializer</code>. <code>XMLCipher</code> was designed to resemble
18 <code>javax.crypto.Cipher</code>. The aforementioned classes were desinged
19 with ease-of-use and configurability in mind. Becuase of this, the programmer
20 may at times be exposed to lower level programming tasks. This library strives
21 to be as simple as possible to use, but no simpler.<br>
22 <br>
23 </body>
24 </html>
+0
-3
src/main/java/org/apache/xml/security/exceptions/package.html less more
0 <HTML><HEAD></HEAD><BODY><P>
1 general exceptions used by this library.
2 </P></BODY></HTML>
+0
-3
src/main/java/org/apache/xml/security/keys/content/keyvalues/package.html less more
0 <HTML><HEAD></HEAD><BODY><P>
1 basic handlers for elements that can occur inside <CODE>ds:KeyValue</CODE>.
2 </P></BODY></HTML>
+0
-3
src/main/java/org/apache/xml/security/keys/content/package.html less more
0 <HTML><HEAD></HEAD><BODY><P>
1 basic handlers for elements that can occur inside <CODE>ds:KeyInfo</CODE>.
2 </P></BODY></HTML>
+0
-3
src/main/java/org/apache/xml/security/keys/content/x509/package.html less more
0 <HTML><HEAD></HEAD><BODY><P>
1 basic handlers for elements that can occur inside <CODE>ds:X509Data</CODE>.
2 </P></BODY></HTML>
+0
-3
src/main/java/org/apache/xml/security/keys/keyresolver/implementations/package.html less more
0 <HTML><HEAD></HEAD><BODY><P>
1 implementations for retrieval of certificates and public keys from elements.
2 </P></BODY></HTML>
+0
-3
src/main/java/org/apache/xml/security/keys/keyresolver/package.html less more
0 <HTML><HEAD></HEAD><BODY><P>
1 the resolver framework for retrieval of certificates and public keys from elements.
2 </P></BODY></HTML>
+0
-3
src/main/java/org/apache/xml/security/keys/package.html less more
0 <HTML><HEAD></HEAD><BODY><P>
1 general key related material.
2 </P></BODY></HTML>
+0
-3
src/main/java/org/apache/xml/security/keys/storage/implementations/package.html less more
0 <HTML><HEAD></HEAD><BODY><P>
1 implementations of resolvers for retrieval for certificates and public keys from user-specified locations.
2 </P></BODY></HTML>
+0
-3
src/main/java/org/apache/xml/security/keys/storage/package.html less more
0 <HTML><HEAD></HEAD><BODY><P>
1 a resolver framework for certificates and public keys from user-specified locations.
2 </P></BODY></HTML>
+0
-33
src/main/java/org/apache/xml/security/package.html less more
0 <HTML>
1 <HEAD>
2 <TITLE>org.apache.xml.security</TITLE>
3 </HEAD>
4 <BODY>
5 <H1>Canonical XML and XML Signature Implementation</H1>
6 <H2>Needs the following packages</H2>
7 <UL>
8 <LI>Xerces v2.0.0 <A HREF="http://xml.apache.org/dist/xerces-j/">http://xml.apache.org/dist/xerces-j/</A></LI>
9 <LI>Xalan 2.2.0 <A HREF="http://xml.apache.org/dist/xalan-j/">http://xml.apache.org/dist/xalan-j/</A></LI>
10 <LI>JUnit 3.7 <A HREF="http://download.sourceforge.net/junit/junit3.7.zip">http://download.sourceforge.net/junit/junit3.5.zip</A></LI>
11 <LI>Jakarta Log4J 1.1.2 <A HREF="http://jakarta.apache.org/log4j/">http://jakarta.apache.org/log4j/</A></LI>
12 <LI>ANT <A HREF="http://jakarta.apache.org/builds/jakarta-ant/release/">http://jakarta.apache.org/builds/jakarta-ant/release/</A></LI>
13 </UL>
14 <H1>Packages</H1>
15 <UL>
16 <LI>{@link org.apache.xml.security.algorithms} contains algorithm factories </LI>
17 <LI>{@link org.apache.xml.security.c14n} contains Canonicalization related material and algorithms </LI>
18 <LI>{@link org.apache.xml.security.exceptions} contains all exceptions used by this library </LI>
19 <LI>{@link org.apache.xml.security.keys} contains key related material </LI>
20 <LI>{@link org.apache.xml.security.signature} contains the XML Signature specific classes </LI>
21 <LI>{@link org.apache.xml.security.transforms} XML Signature transformations </LI>
22 <LI>{@link org.apache.xml.security.utils} contains all utility classes </LI>
23 </UL>
24 <H2>Support</H2>
25 <P>See <A HREF="http://xml.apache.org/security/">the xml-security project</A> for further assistence</P>
26 <H2>Author</H2>
27 <P>Christian Geuer-Pollmann geuer-pollmann@nue.et-inf.uni-siegen.de<BR>
28 University of Siegen<BR>
29 Institute for Data Communications Systems<BR>
30 </P>
31 </BODY>
32 </HTML>
214214 Description="Digital Signature Algorithm with SHA-1 message digest"
215215 AlgorithmClass="Signature"
216216 RequirementLevel="REQUIRED"
217 RequiredKey="DSA"
217218 JCEName="SHA1withDSA"/>
218219
219220 <Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#rsa-md5"
221222 AlgorithmClass="Signature"
222223 RequirementLevel="NOT RECOMMENDED"
223224 SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
225 RequiredKey="RSA"
224226 JCEName="MD5withRSA"/>
225227
226228 <Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#rsa-ripemd160"
228230 AlgorithmClass="Signature"
229231 RequirementLevel="OPTIONAL"
230232 SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
233 RequiredKey="RSA"
231234 JCEName="RIPEMD160withRSA"/>
232235
233236 <Algorithm URI="http://www.w3.org/2000/09/xmldsig#rsa-sha1"
234237 Description="RSA Signature with SHA-1 message digest"
235238 AlgorithmClass="Signature"
236239 RequirementLevel="RECOMMENDED"
240 RequiredKey="RSA"
237241 JCEName="SHA1withRSA"/>
238242
239243 <Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#rsa-sha2224"
241245 AlgorithmClass="Signature"
242246 RequirementLevel="OPTIONAL"
243247 SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
248 RequiredKey="RSA"
244249 JCEName="SHA224withRSA"/>
245250
246251 <Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"
248253 AlgorithmClass="Signature"
249254 RequirementLevel="OPTIONAL"
250255 SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
256 RequiredKey="RSA"
251257 JCEName="SHA256withRSA"/>
252258
253259 <Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#rsa-sha384"
255261 AlgorithmClass="Signature"
256262 RequirementLevel="OPTIONAL"
257263 SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
264 RequiredKey="RSA"
258265 JCEName="SHA384withRSA"/>
259266
260267 <Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#rsa-sha512"
262269 AlgorithmClass="Signature"
263270 RequirementLevel="OPTIONAL"
264271 SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
272 RequiredKey="RSA"
265273 JCEName="SHA512withRSA"/>
266274
267275 <Algorithm URI="http://www.w3.org/2007/05/xmldsig-more#sha1-rsa-MGF1"
268276 Description="RSASSA-PSS Signature with SHA-1 message digest"
269277 AlgorithmClass="Signature"
270278 RequirementLevel="RECOMMENDED"
279 RequiredKey="RSA"
271280 JCEName="SHA1withRSAandMGF1"/>
272281
273282 <Algorithm URI="http://www.w3.org/2007/05/xmldsig-more#sha224-rsa-MGF1"
275284 AlgorithmClass="Signature"
276285 RequirementLevel="OPTIONAL"
277286 SpecificationURL="http://www.ietf.org/rfc/rfc6931.txt"
287 RequiredKey="RSA"
278288 JCEName="SHA224withRSAandMGF1"/>
279289
280290 <Algorithm URI="http://www.w3.org/2007/05/xmldsig-more#sha256-rsa-MGF1"
282292 AlgorithmClass="Signature"
283293 RequirementLevel="OPTIONAL"
284294 SpecificationURL="http://www.ietf.org/rfc/rfc6931.txt"
295 RequiredKey="RSA"
285296 JCEName="SHA256withRSAandMGF1"/>
286297
287298 <Algorithm URI="http://www.w3.org/2007/05/xmldsig-more#sha384-rsa-MGF1"
289300 AlgorithmClass="Signature"
290301 RequirementLevel="OPTIONAL"
291302 SpecificationURL="http://www.ietf.org/rfc/rfc6931.txt"
303 RequiredKey="RSA"
292304 JCEName="SHA384withRSAandMGF1"/>
293305
294306 <Algorithm URI="http://www.w3.org/2007/05/xmldsig-more#sha512-rsa-MGF1"
296308 AlgorithmClass="Signature"
297309 RequirementLevel="OPTIONAL"
298310 SpecificationURL="http://www.ietf.org/rfc/rfc6931.txt"
311 RequiredKey="RSA"
299312 JCEName="SHA512withRSAandMGF1"/>
300313
301314 <Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha1"
310323 AlgorithmClass="Signature"
311324 RequirementLevel="OPTIONAL"
312325 SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
326 RequiredKey="EC"
313327 JCEName="SHA224withECDSA"/>
314328
315329 <Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256"
317331 AlgorithmClass="Signature"
318332 RequirementLevel="OPTIONAL"
319333 SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
334 RequiredKey="EC"
320335 JCEName="SHA256withECDSA"/>
321336
322337 <Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha384"
324339 AlgorithmClass="Signature"
325340 RequirementLevel="OPTIONAL"
326341 SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
342 RequiredKey="EC"
327343 JCEName="SHA384withECDSA"/>
328344
329345 <Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha512"
338354 AlgorithmClass="Signature"
339355 RequirementLevel="OPTIONAL"
340356 SpecificationURL="https://tools.ietf.org/html/rfc6931"
357 RequiredKey="EC"
341358 JCEName="RIPEMD160withECDSA"/>
342359
343360 <!-- MAC Algorithms -->
+0
-3
src/main/java/org/apache/xml/security/resource/package.html less more
0 <HTML> <HEAD> </HEAD> <BODY> <P>
1 software configuration and internationalization ({@link org.apache.xml.security.utils.I18n}).
2 </P></BODY> </HTML>
264264
265265 String uri = digestMethodElem.getAttributeNS(null, Constants._ATT_ALGORITHM);
266266
267 if (uri == null) {
267 if ("".equals(uri)) {
268268 return null;
269269 }
270270
+0
-3
src/main/java/org/apache/xml/security/signature/package.html less more
0 <HTML><HEAD></HEAD><BODY><P>
1 XML Signature specific classes.
2 </P></BODY></HTML>
3131
3232 /**
3333 * @author $Author: giger $
34 * @version $Revision: 1399272 $ $Date: 2012-10-17 16:02:10 +0200 (Wed, 17 Oct 2012) $
34 * @version $Revision: 1659901 $ $Date: 2015-02-15 10:11:24 +0100 (Sun, 15 Feb 2015) $
3535 */
3636 public class XMLSecEventFactory {
3737
7474 return new XMLSecCharactersImpl(xmlStreamReader.getText(), false, true, xmlStreamReader.isWhiteSpace(), parentXMLSecStartElement);
7575 case XMLStreamConstants.START_DOCUMENT:
7676 String systemId = xmlStreamReader.getLocation() != null ? xmlStreamReader.getLocation().getSystemId() : null;
77 return new XMLSecStartDocumentImpl(systemId, xmlStreamReader.getEncoding(),
77 return new XMLSecStartDocumentImpl(systemId, xmlStreamReader.getCharacterEncodingScheme(),
7878 xmlStreamReader.standaloneSet() ? xmlStreamReader.isStandalone() : null, xmlStreamReader.getVersion());
7979 case XMLStreamConstants.END_DOCUMENT:
8080 return new XMLSecEndDocumentImpl();
2222
2323 import javax.xml.namespace.QName;
2424 import javax.xml.stream.XMLStreamConstants;
25 import javax.xml.stream.XMLStreamException;
26 import java.io.IOException;
27 import java.io.Writer;
2528
2629 /**
2730 * Class to let XML-Attributes be comparable how it is requested by C14N
2831 *
2932 * @author $Author: giger $
30 * @version $Revision: 1399606 $ $Date: 2012-10-18 14:17:41 +0200 (Thu, 18 Oct 2012) $
33 * @version $Revision: 1659901 $ $Date: 2015-02-15 10:11:24 +0100 (Sun, 15 Feb 2015) $
3134 */
3235 public class XMLSecAttributeImpl extends XMLSecEventBaseImpl implements XMLSecAttribute {
3336
107110 public boolean isAttribute() {
108111 return true;
109112 }
113
114 @Override
115 public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
116 try {
117 final String prefix = getName().getPrefix();
118 if (prefix != null && !prefix.isEmpty()) {
119 writer.write(prefix);
120 writer.write(':');
121 }
122 writer.write(getName().getLocalPart());
123 writer.write("=\"");
124 writeEncoded(writer, getValue());
125 writer.write("\"");
126 } catch (IOException e) {
127 throw new XMLStreamException(e);
128 }
129 }
130
131 private void writeEncoded(Writer writer, String text) throws IOException {
132 final int length = text.length();
133
134 int i = 0;
135 int idx = 0;
136 while (i < length) {
137 char c = text.charAt(i);
138 switch (c) {
139 case '&':
140 writer.write(text, idx, i - idx);
141 writer.write("&amp;");
142 idx = i + 1;
143 break;
144 case '"':
145 writer.write(text, idx, i - idx);
146 writer.write("&quot;");
147 idx = i + 1;
148 break;
149 }
150 i++;
151 }
152 writer.write(text, idx, length - idx);
153 }
110154 }
2121 import org.apache.xml.security.stax.ext.stax.XMLSecStartElement;
2222
2323 import javax.xml.stream.XMLStreamConstants;
24 import javax.xml.stream.XMLStreamException;
25 import java.io.IOException;
26 import java.io.Writer;
2427
2528 /**
2629 * @author $Author: giger $
27 * @version $Revision: 1399606 $ $Date: 2012-10-18 14:17:41 +0200 (Thu, 18 Oct 2012) $
30 * @version $Revision: 1659901 $ $Date: 2015-02-15 10:11:24 +0100 (Sun, 15 Feb 2015) $
2831 */
2932 public class XMLSecCharactersImpl extends XMLSecEventBaseImpl implements XMLSecCharacters {
3033
98101 public XMLSecCharacters asCharacters() {
99102 return this;
100103 }
104
105 @Override
106 public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
107 try {
108 if (isCData) {
109 writer.write("<![CDATA[");
110 writer.write(getText());
111 writer.write("]]>");
112 } else {
113 writeEncoded(writer, getText());
114 }
115 } catch (IOException e) {
116 throw new XMLStreamException(e);
117 }
118 }
119
120 private void writeEncoded(Writer writer, char[] text) throws IOException {
121 final int length = text.length;
122
123 int i = 0;
124 int idx = 0;
125 while (i < length) {
126 char c = text[i];
127 switch (c) {
128 case '<':
129 writer.write(text, idx, i - idx);
130 writer.write("&lt;");
131 idx = i + 1;
132 break;
133 case '>':
134 writer.write(text, idx, i - idx);
135 writer.write("&gt;");
136 idx = i + 1;
137 break;
138 case '&':
139 writer.write(text, idx, i - idx);
140 writer.write("&amp;");
141 idx = i + 1;
142 break;
143 }
144 i++;
145 }
146 writer.write(text, idx, length - idx);
147 }
101148 }
2121 import org.apache.xml.security.stax.ext.stax.XMLSecStartElement;
2222
2323 import javax.xml.stream.XMLStreamConstants;
24 import javax.xml.stream.XMLStreamException;
25 import java.io.IOException;
26 import java.io.Writer;
2427
2528 /**
26 * @author $Author: coheigea $
27 * @version $Revision: 1354896 $ $Date: 2012-06-28 12:11:05 +0200 (Thu, 28 Jun 2012) $
29 * @author $Author: giger $
30 * @version $Revision: 1659901 $ $Date: 2015-02-15 10:11:24 +0100 (Sun, 15 Feb 2015) $
2831 */
2932 public class XMLSecCommentImpl extends XMLSecEventBaseImpl implements XMLSecComment {
3033
4447 public int getEventType() {
4548 return XMLStreamConstants.COMMENT;
4649 }
50
51 @Override
52 public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
53 try {
54 writer.write("<!--");
55 writer.write(getText());
56 writer.write("-->");
57 } catch (IOException e) {
58 throw new XMLStreamException(e);
59 }
60 }
4761 }
2121 import org.apache.xml.security.stax.ext.stax.XMLSecStartElement;
2222
2323 import javax.xml.stream.XMLStreamConstants;
24 import javax.xml.stream.XMLStreamException;
25 import java.io.IOException;
26 import java.io.Writer;
2427 import java.util.Collections;
2528 import java.util.List;
2629
2730 /**
28 * @author $Author: coheigea $
29 * @version $Revision: 1354896 $ $Date: 2012-06-28 12:11:05 +0200 (Thu, 28 Jun 2012) $
31 * @author $Author: giger $
32 * @version $Revision: 1659901 $ $Date: 2015-02-15 10:11:24 +0100 (Sun, 15 Feb 2015) $
3033 */
3134 public class XMLSecDTDImpl extends XMLSecEventBaseImpl implements XMLSecDTD {
3235
6164 public int getEventType() {
6265 return XMLStreamConstants.DTD;
6366 }
67
68 @Override
69 public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
70 try {
71 writer.write(getDocumentTypeDeclaration());
72 } catch (IOException e) {
73 throw new XMLStreamException(e);
74 }
75 }
6476 }
2020 import org.apache.xml.security.stax.ext.stax.XMLSecEndDocument;
2121
2222 import javax.xml.stream.XMLStreamConstants;
23 import javax.xml.stream.XMLStreamException;
24 import java.io.Writer;
2325
2426 /**
25 * @author $Author: coheigea $
26 * @version $Revision: 1354896 $ $Date: 2012-06-28 12:11:05 +0200 (Thu, 28 Jun 2012) $
27 * @author $Author: giger $
28 * @version $Revision: 1659901 $ $Date: 2015-02-15 10:11:24 +0100 (Sun, 15 Feb 2015) $
2729 */
2830 public class XMLSecEndDocumentImpl extends XMLSecEventBaseImpl implements XMLSecEndDocument {
2931
4143 public XMLSecEndDocument asEndEndDocument() {
4244 return this;
4345 }
46
47 @Override
48 public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
49 // nothing to write.
50 }
4451 }
2222
2323 import javax.xml.namespace.QName;
2424 import javax.xml.stream.XMLStreamConstants;
25 import javax.xml.stream.XMLStreamException;
26 import java.io.IOException;
27 import java.io.Writer;
2528 import java.util.Iterator;
2629
2730 /**
2831 * @author $Author: giger $
29 * @version $Revision: 1393096 $ $Date: 2012-10-02 20:59:13 +0200 (Tue, 02 Oct 2012) $
32 * @version $Revision: 1659901 $ $Date: 2015-02-15 10:11:24 +0100 (Sun, 15 Feb 2015) $
3033 */
3134 public class XMLSecEndElementImpl extends XMLSecEventBaseImpl implements XMLSecEndElement {
3235
6164 public XMLSecEndElement asEndElement() {
6265 return this;
6366 }
67
68 @Override
69 public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
70 try {
71 writer.write("</");
72 final String prefix = getName().getPrefix();
73 if (prefix != null && !prefix.isEmpty()) {
74 writer.write(getName().getPrefix());
75 writer.write(':');
76 }
77 writer.write(getName().getLocalPart());
78 writer.write('>');
79 } catch (IOException e) {
80 throw new XMLStreamException(e);
81 }
82 }
6483 }
2020 import org.apache.xml.security.stax.ext.stax.XMLSecEntityDeclaration;
2121
2222 import javax.xml.stream.XMLStreamConstants;
23 import javax.xml.stream.XMLStreamException;
24 import java.io.IOException;
25 import java.io.Writer;
2326
2427 /**
2528 * @author $Author: giger $
26 * @version $Revision: 1399272 $ $Date: 2012-10-17 16:02:10 +0200 (Wed, 17 Oct 2012) $
29 * @version $Revision: 1659901 $ $Date: 2015-02-15 10:11:24 +0100 (Sun, 15 Feb 2015) $
2730 */
2831 public class XMLSecEntityDeclarationImpl extends XMLSecEventBaseImpl implements XMLSecEntityDeclaration {
2932
7275 public boolean isEntityReference() {
7376 return true;
7477 }
78
79 @Override
80 public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
81 try {
82 writer.write("<!ENTITY ");
83 writer.write(getName());
84 writer.write(" \"");
85 final String replacementText = getReplacementText();
86 if (replacementText != null) {
87 writer.write(replacementText);
88 }
89 writer.write("\">");
90 } catch (IOException e) {
91 throw new XMLStreamException(e);
92 }
93 }
7594 }
2121 import org.apache.xml.security.stax.ext.stax.XMLSecStartElement;
2222
2323 import javax.xml.stream.XMLStreamConstants;
24 import javax.xml.stream.XMLStreamException;
2425 import javax.xml.stream.events.EntityDeclaration;
26 import java.io.IOException;
27 import java.io.Writer;
2528
2629 /**
27 * @author $Author: coheigea $
28 * @version $Revision: 1354896 $ $Date: 2012-06-28 12:11:05 +0200 (Thu, 28 Jun 2012) $
30 * @author $Author: giger $
31 * @version $Revision: 1659901 $ $Date: 2015-02-15 10:11:24 +0100 (Sun, 15 Feb 2015) $
2932 */
3033 public class XMLSecEntityReferenceImpl extends XMLSecEventBaseImpl implements XMLSecEntityReference {
3134
5760 public boolean isEntityReference() {
5861 return true;
5962 }
63
64 @Override
65 public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
66 try {
67 writer.write('&');
68 writer.write(getName());
69 writer.write(';');
70 } catch (IOException e) {
71 throw new XMLStreamException(e);
72 }
73 }
6074 }
3333
3434 /**
3535 * @author $Author: giger $
36 * @version $Revision: 1393096 $ $Date: 2012-10-02 20:59:13 +0200 (Tue, 02 Oct 2012) $
36 * @version $Revision: 1659901 $ $Date: 2015-02-15 10:11:24 +0100 (Sun, 15 Feb 2015) $
3737 */
3838 public abstract class XMLSecEventBaseImpl implements XMLSecEvent {
3939
157157
158158 @Override
159159 public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
160 throw new UnsupportedOperationException();
160 throw new UnsupportedOperationException(
161 "writeAsEncodedUnicode not implemented for " + this.getClass().getName());
161162 }
162163
163164 static final class LocationImpl implements Location {
2222 import javax.xml.XMLConstants;
2323 import javax.xml.namespace.QName;
2424 import javax.xml.stream.XMLStreamConstants;
25 import javax.xml.stream.XMLStreamException;
26 import java.io.IOException;
27 import java.io.Writer;
2528 import java.util.Map;
2629 import java.util.WeakHashMap;
2730
2831 /**
2932 * Class to let XML-Namespaces be comparable how it is requested by C14N
3033 *
31 * @author $Author: coheigea $
32 * @version $Revision: 1513098 $ $Date: 2013-08-12 12:28:33 +0200 (Mon, 12 Aug 2013) $
34 * @author $Author: giger $
35 * @version $Revision: 1659901 $ $Date: 2015-02-15 10:11:24 +0100 (Sun, 15 Feb 2015) $
3336 */
3437 public class XMLSecNamespaceImpl extends XMLSecEventBaseImpl implements XMLSecNamespace {
3538
148151 }
149152
150153 @Override
154 public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
155 try {
156 writer.write("xmlns");
157 if (getPrefix() != null && !getPrefix().isEmpty()) {
158 writer.write(':');
159 writer.write(getPrefix());
160 }
161 writer.write("=\"");
162 writeEncoded(writer, getValue());
163 writer.write("\"");
164 } catch (IOException e) {
165 throw new XMLStreamException(e);
166 }
167 }
168
169 private void writeEncoded(Writer writer, String text) throws IOException {
170 final int length = text.length();
171
172 int i = 0;
173 int idx = 0;
174 while (i < length) {
175 char c = text.charAt(i);
176 switch (c) {
177 case '&':
178 writer.write(text, idx, i - idx);
179 writer.write("&amp;");
180 idx = i + 1;
181 break;
182 case '"':
183 writer.write(text, idx, i - idx);
184 writer.write("&quot;");
185 idx = i + 1;
186 break;
187 }
188 i++;
189 }
190 writer.write(text, idx, length - idx);
191 }
192
193 @Override
151194 public String toString() {
152195 if (this.prefix == null || this.prefix.isEmpty()) {
153196 return "xmlns=\"" + this.uri + "\"";
2121 import org.apache.xml.security.stax.ext.stax.XMLSecStartElement;
2222
2323 import javax.xml.stream.XMLStreamConstants;
24 import javax.xml.stream.XMLStreamException;
25 import java.io.IOException;
26 import java.io.Writer;
2427
2528 /**
26 * @author $Author: coheigea $
27 * @version $Revision: 1354896 $ $Date: 2012-06-28 12:11:05 +0200 (Thu, 28 Jun 2012) $
29 * @author $Author: giger $
30 * @version $Revision: 1659901 $ $Date: 2015-02-15 10:11:24 +0100 (Sun, 15 Feb 2015) $
2831 */
2932 public class XMLSecProcessingInstructionImpl extends XMLSecEventBaseImpl implements XMLSecProcessingInstruction {
3033
5659 public boolean isProcessingInstruction() {
5760 return true;
5861 }
62
63 @Override
64 public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
65 try {
66 writer.write("<?");
67 writer.write(getTarget());
68 final String data = getData();
69 if (data != null && !data.isEmpty()) {
70 writer.write(' ');
71 writer.write(data);
72 }
73 writer.write("?>");
74 } catch (IOException e) {
75 throw new XMLStreamException(e);
76 }
77 }
5978 }
2020 import org.apache.xml.security.stax.ext.stax.XMLSecStartDocument;
2121
2222 import javax.xml.stream.XMLStreamConstants;
23 import javax.xml.stream.XMLStreamException;
24 import java.io.IOException;
25 import java.io.Writer;
2326
2427 /**
25 * @author $Author: coheigea $
26 * @version $Revision: 1354896 $ $Date: 2012-06-28 12:11:05 +0200 (Thu, 28 Jun 2012) $
28 * @author $Author: giger $
29 * @version $Revision: 1659901 $ $Date: 2015-02-15 10:11:24 +0100 (Sun, 15 Feb 2015) $
2730 */
2831 public class XMLSecStartDocumentImpl extends XMLSecEventBaseImpl implements XMLSecStartDocument {
2932
8386 public XMLSecStartDocument asStartDocument() {
8487 return this;
8588 }
89
90 @Override
91 public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
92 try {
93 writer.write("<?xml version=\"");
94 if (getVersion() == null || getVersion().isEmpty()) {
95 writer.write("1.0");
96 } else {
97 writer.write(getVersion());
98 }
99 writer.write('"');
100 if (encodingSet()) {
101 writer.write(" encoding=\"");
102 writer.write(getCharacterEncodingScheme());
103 writer.write('"');
104 }
105 if (standaloneSet()) {
106 if (isStandalone()) {
107 writer.write(" standalone=\"yes\"");
108 } else {
109 writer.write(" standalone=\"no\"");
110 }
111 }
112 writer.write(" ?>");
113 } catch (IOException e) {
114 throw new XMLStreamException(e);
115 }
116 }
86117 }
2424 import javax.xml.namespace.NamespaceContext;
2525 import javax.xml.namespace.QName;
2626 import javax.xml.stream.XMLStreamConstants;
27
27 import javax.xml.stream.XMLStreamException;
28
29 import java.io.IOException;
30 import java.io.Writer;
2831 import java.util.*;
2932
3033 /**
31 * @author $Author: coheigea $
32 * @version $Revision: 1545342 $ $Date: 2013-11-25 18:01:00 +0100 (Mon, 25 Nov 2013) $
34 * @author $Author: giger $
35 * @version $Revision: 1659901 $ $Date: 2015-02-15 10:11:24 +0100 (Sun, 15 Feb 2015) $
3336 */
3437 public class XMLSecStartElementImpl extends XMLSecEventBaseImpl implements XMLSecStartElement {
3538
243246 public XMLSecStartElement asStartElement() {
244247 return this;
245248 }
249
250 @Override
251 public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
252 try {
253 writer.write('<');
254 final String prefix = getName().getPrefix();
255 if (prefix != null && !prefix.isEmpty()) {
256 writer.write(prefix);
257 writer.write(':');
258 }
259 writer.write(getName().getLocalPart());
260
261 for (XMLSecNamespace xmlSecNamespace : namespaces) {
262 writer.write(" xmlns");
263
264 final String nsPrefix = xmlSecNamespace.getPrefix();
265 if (nsPrefix != null && !nsPrefix.isEmpty()) {
266 writer.write(':');
267 writer.write(nsPrefix);
268 }
269 writer.write("=\"");
270 writer.write(xmlSecNamespace.getValue());
271 writer.write('"');
272 }
273
274 for (XMLSecAttribute xmlSecAttribute : attributes) {
275 writer.write(' ');
276 final String attrPrefix = xmlSecAttribute.getName().getPrefix();
277 if (attrPrefix != null && !attrPrefix.isEmpty()) {
278 writer.write(attrPrefix);
279 writer.write(':');
280 }
281 writer.write(xmlSecAttribute.getName().getLocalPart());
282 writer.write("=\"");
283 writer.write(xmlSecAttribute.getValue());
284 writer.write('"');
285 }
286
287 writer.write('>');
288 } catch (IOException e) {
289 throw new XMLStreamException(e);
290 }
291 }
246292 }
2525 import java.util.*;
2626
2727 /**
28 * @author $Author: giger $
29 * @version $Revision: 1460408 $ $Date: 2013-03-24 16:47:32 +0100 (Sun, 24 Mar 2013) $
28 * @author $Author: coheigea $
29 * @version $Revision: 1661635 $ $Date: 2015-02-23 12:01:42 +0100 (Mon, 23 Feb 2015) $
3030 */
3131 public class Canonicalizer11 extends CanonicalizerBase {
3232 public Canonicalizer11(boolean includeComments) {
1919
2020 /**
2121 * @author $Author: coheigea $
22 * @version $Revision: 1354896 $ $Date: 2012-06-28 12:11:05 +0200 (Thu, 28 Jun 2012) $
22 * @version $Revision: 1661635 $ $Date: 2015-02-23 12:01:42 +0100 (Mon, 23 Feb 2015) $
2323 */
2424 public abstract class Canonicalizer20010315 extends CanonicalizerBase {
2525
2424
2525 /**
2626 * @author $Author: coheigea $
27 * @version $Revision: 1556187 $ $Date: 2014-01-07 12:46:31 +0100 (Tue, 07 Jan 2014) $
27 * @version $Revision: 1661635 $ $Date: 2015-02-23 12:01:42 +0100 (Mon, 23 Feb 2015) $
2828 */
2929 public abstract class Canonicalizer20010315_Excl extends CanonicalizerBase {
3030
262262 int last = this.getLength() - 1;
263263 for (int i = 0; i < last; i++) {
264264 Transform t = this.item(i);
265 String uri = t.getURI();
266265 if (log.isDebugEnabled()) {
266 String uri = t.getURI();
267267 log.debug("Perform the (" + i + ")th " + uri + " transform");
268268 }
269269 checkSecureValidation(t);
271271 }
272272 if (last >= 0) {
273273 Transform t = this.item(last);
274 if (log.isDebugEnabled()) {
275 String uri = t.getURI();
276 log.debug("Perform the (" + last + ")th " + uri + " transform");
277 }
274278 checkSecureValidation(t);
275279 xmlSignatureInput = t.performTransform(xmlSignatureInput, os);
276280 }
+0
-3
src/main/java/org/apache/xml/security/transforms/implementations/package.html less more
0 <HTML><HEAD></HEAD><BODY><P>
1 implementations of XML Signature transforms.
2 </P></BODY></HTML>
+0
-3
src/main/java/org/apache/xml/security/transforms/package.html less more
0 <HTML><HEAD></HEAD><BODY><P>
1 the framework for XML Signature transforms.
2 </P></BODY></HTML>
2626
2727 /**
2828 * Abstract base class for pooling objects. The two public methods are
29 * {@link #getObject()} and ({@link #repool()}. Objects are held through
29 * {@link #getObject()} and ({@link #repool(Object)}. Objects are held through
3030 * weak references so even objects that are not repooled are subject to garbage collection.
3131 *
3232 * Subclasses must implement the abstract {@link #createObject()}.
3838 public abstract class WeakObjectPool<T, E extends Throwable> {
3939
4040 private static final Integer MARKER_VALUE = Integer.MAX_VALUE;//once here rather than auto-box it?
41
42 /** created, available objects to be checked out to clients */
43 private final BlockingQueue<WeakReference<T>> available;
44
45 /**
46 * Synchronized, identity map of loaned out objects (WeakHashMap);
47 * use to ensure we repool only object originating from here
48 * and do it once.
49 */
50 private final Map<T, Integer> onLoan;
4151
4252 /**
4353 * The lone constructor.
7585 if (retValue == null) {
7686 //empty pool; create & add new one
7787 retValue = createObject();
78 ref = new WeakReference<T>(retValue);
7988 }
8089 onLoan.put(retValue, MARKER_VALUE);
8190 return retValue;
101110 }
102111 return false;
103112 }
104
105 /** created, available objects to be checked out to clients */
106 private final BlockingQueue<WeakReference<T>> available;
107
108 /**
109 * Synchronized, identity map of loaned out objects (WeakHashMap);
110 * use to ensure we repool only object originating from here
111 * and do it once.
112 */
113 private final Map<T, Integer> onLoan;
114113 }
10731073 /**
10741074 * Return this document builder to be reused
10751075 * @param db DocumentBuilder returned from any of {@link #createDocumentBuilder} methods.
1076 * @param disAllowDocTypeDeclarations We can't figure out its value from the documentBuilder itself
1077 * @return whether it was successfully returned to the pool
1076 * @return whether it was successfully returned to the pool
10781077 */
10791078 public static boolean repoolDocumentBuilder(DocumentBuilder db) {
1080 if (db == null || !(db instanceof DocumentBuilderProxy)) {
1079 if (!(db instanceof DocumentBuilderProxy)) {
10811080 return false;
10821081 }
10831082 db.reset();
11061105 return disAllowDocTypeDeclarations;
11071106 }
11081107
1109 public int hashCode() {
1110 return delegate.hashCode();
1111 }
1112
11131108 public void reset() {
11141109 delegate.reset();
11151110 }
11161111
11171112 public Document parse(InputStream is) throws SAXException, IOException {
11181113 return delegate.parse(is);
1119 }
1120
1121 public boolean equals(Object obj) {
1122 return delegate.equals(obj);
11231114 }
11241115
11251116 public Document parse(InputStream is, String systemId)
11331124
11341125 public Document parse(File f) throws SAXException, IOException {
11351126 return delegate.parse(f);
1136 }
1137
1138 public String toString() {
1139 return delegate.toString();
11401127 }
11411128
11421129 public Schema getSchema() {
+0
-3
src/main/java/org/apache/xml/security/utils/package.html less more
0 <HTML><HEAD></HEAD><BODY><P>
1 general utility classes.
2 </P></BODY></HTML>
+0
-8
src/main/java/org/apache/xml/security/utils/resolver/implementations/package.html less more
0 <HTML>
1 <HEAD> </HEAD>
2 <BODY>
3 <P>
4 implememtations of different ResourceResolver classes used to resolve ds:Reference URIs.
5 </P>
6 </BODY>
7 </HTML>
+0
-8
src/main/java/org/apache/xml/security/utils/resolver/package.html less more
0 <HTML>
1 <HEAD> </HEAD>
2 <BODY>
3 <P>
4 the ResourceResolver classes used to resolve ds:Reference URIs.
5 </P>
6 </BODY>
7 </HTML>
0 /**
1 * Licensed to the Apache Software Foundation (ASF) under one
2 * or more contributor license agreements. See the NOTICE file
3 * distributed with this work for additional information
4 * regarding copyright ownership. The ASF licenses this file
5 * to you under the Apache License, Version 2.0 (the
6 * "License"); you may not use this file except in compliance
7 * with the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18 package org.apache.xml.security.test.dom.encryption;
19
20 import org.apache.xml.security.encryption.DocumentSerializer;
21 import org.apache.xml.security.encryption.TransformSerializer;
22 import org.apache.xml.security.encryption.XMLCipher;
23 import org.apache.xml.security.signature.XMLSignature;
24 import org.apache.xml.security.test.dom.DSNamespaceContext;
25 import org.apache.xml.security.transforms.Transforms;
26 import org.apache.xml.security.utils.Constants;
27 import org.apache.xml.security.utils.XMLUtils;
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Ignore;
31 import org.junit.Test;
32 import org.w3c.dom.Document;
33 import org.w3c.dom.Element;
34
35 import javax.crypto.KeyGenerator;
36 import javax.crypto.SecretKey;
37 import javax.xml.parsers.DocumentBuilder;
38 import javax.xml.transform.TransformerFactory;
39 import javax.xml.xpath.XPath;
40 import javax.xml.xpath.XPathConstants;
41 import javax.xml.xpath.XPathFactory;
42 import java.io.ByteArrayInputStream;
43 import java.lang.reflect.Field;
44 import java.security.KeyPair;
45 import java.security.KeyPairGenerator;
46 import java.security.PrivateKey;
47 import java.security.PublicKey;
48 import java.util.UUID;
49
50 /**
51 * @author $Author: giger $
52 * @version $Revision: 1656895 $ $Date: 2015-02-03 20:20:08 +0100 (Tue, 03 Feb 2015) $
53 */
54 public class SignedEncryptedTest extends Assert {
55
56 private static final String SAMPLE_MSG = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
57 + "<SOAP-ENV:Envelope "
58 + "xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" "
59 + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
60 + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
61 + "<SOAP-ENV:Body xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">"
62 + "<add xmlns=\"http://ws.apache.org/counter/counter_port_type\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">"
63 + "<value xmlns=\"http://blah.com\">15</value>"
64 + "<o:other xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:o=\"http://other.com\" xmlns=\"\">0</o:other>"
65 + "</add>"
66 + "</SOAP-ENV:Body>"
67 + "</SOAP-ENV:Envelope>";
68
69 @Before
70 public void setUp() throws Exception {
71 org.apache.xml.security.Init.init();
72 }
73
74 /**
75 * This test uses the oracle jdk "built-in" identity-transformer to
76 * insert the decrypted content into the original document.
77 *
78 * @throws Exception
79 */
80 @Ignore
81 @Test
82 public void decryptUsingSunTransformer() throws Exception {
83 try {
84 Class<?> tf = getClass().getClassLoader().loadClass(
85 "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
86 secureAndVerify((TransformerFactory) tf.newInstance(), false);
87 } catch (ClassNotFoundException e) {
88 System.out.println(
89 "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl not found, skipping test");
90 }
91 }
92
93 /**
94 * This test uses the xalan identity-transformer to insert the decrypted content into the original document.
95 *
96 * @throws Exception
97 */
98 @Test
99 public void decryptUsingXalanTransformer() throws Exception {
100 try {
101 Class<?> tf = getClass().getClassLoader().loadClass(
102 "org.apache.xalan.processor.TransformerFactoryImpl");
103 secureAndVerify((TransformerFactory) tf.newInstance(), false);
104 } catch (ClassNotFoundException e) {
105 System.out.println(
106 "org.apache.xalan.processor.TransformerFactoryImpl not found, skipping test");
107 }
108 }
109
110 /**
111 * This test does not use the IdentityTransformer but instead it uses the DocumentSerializer
112 * which uses the DocumentBuilder to read in the decrypted content and then does a DOM2DOM copy.
113 *
114 * @throws Exception
115 */
116 @Test
117 public void decryptUsingSunDOMSerializer() throws Exception {
118 secureAndVerify(null, true);
119 }
120
121 public void secureAndVerify(TransformerFactory transformerFactory, boolean useDocumentSerializer) throws Exception {
122 DocumentBuilder builder = XMLUtils.createDocumentBuilder(false);
123 Document document = builder.parse(new ByteArrayInputStream(SAMPLE_MSG.getBytes("UTF-8")));
124
125 // Set up the Key
126 KeyPairGenerator rsaKeygen = KeyPairGenerator.getInstance("RSA");
127 KeyPair kp = rsaKeygen.generateKeyPair();
128 PrivateKey priv = kp.getPrivate();
129 PublicKey pub = kp.getPublic();
130
131 XMLSignature sig = new XMLSignature(document, "", XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1,
132 Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
133 Element sigElement = sig.getElement();
134 document.getDocumentElement().appendChild(sigElement);
135
136 XPathFactory xpf = XPathFactory.newInstance();
137 XPath xpath = xpf.newXPath();
138 xpath.setNamespaceContext(new DSNamespaceContext());
139
140 Element element =
141 (Element) xpath.evaluate("//*[local-name()='Body']", document, XPathConstants.NODE);
142
143 String id = UUID.randomUUID().toString();
144 element.setAttributeNS(null, "Id", id);
145 element.setIdAttributeNS(null, "Id", true);
146
147 Transforms transforms = new Transforms(document);
148 transforms.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
149 sig.addDocument("#" + id, transforms, Constants.ALGO_ID_DIGEST_SHA1);
150
151 sig.addKeyInfo(pub);
152 sig.sign(priv);
153
154 KeyGenerator keygen = KeyGenerator.getInstance("AES");
155 keygen.init(256);
156 SecretKey secretKey = keygen.generateKey();
157
158 XMLCipher cipher = XMLCipher.getInstance(XMLCipher.AES_128);
159 cipher.init(XMLCipher.ENCRYPT_MODE, secretKey);
160
161 document = cipher.doFinal(document, element, true);
162
163 XMLCipher deCipher = XMLCipher.getInstance(XMLCipher.AES_128);
164 if (transformerFactory != null) {
165 if (deCipher.getSerializer() instanceof TransformSerializer) {
166 Field f = deCipher.getSerializer().getClass().getDeclaredField("transformerFactory");
167 f.setAccessible(true);
168 f.set(deCipher.getSerializer(), transformerFactory);
169 }
170 }
171 if (useDocumentSerializer) {
172 deCipher.setSerializer(new DocumentSerializer());
173 }
174 deCipher.init(XMLCipher.DECRYPT_MODE, secretKey);
175 deCipher.doFinal(document, element, true);
176
177 XMLSignature xmlSignatureVerifier = new XMLSignature(sigElement, "");
178 Assert.assertTrue(xmlSignatureVerifier.checkSignatureValue(pub));
179 }
180 }
0 /**
1 * Licensed to the Apache Software Foundation (ASF) under one
2 * or more contributor license agreements. See the NOTICE file
3 * distributed with this work for additional information
4 * regarding copyright ownership. The ASF licenses this file
5 * to you under the Apache License, Version 2.0 (the
6 * "License"); you may not use this file except in compliance
7 * with the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18 package org.apache.xml.security.test.dom.utils;
19
20 import org.apache.xml.security.utils.WeakObjectPool;
21 import org.apache.xml.security.utils.XMLUtils;
22 import org.junit.Test;
23
24 import javax.xml.parsers.DocumentBuilder;
25 import java.lang.ref.WeakReference;
26 import java.lang.reflect.Field;
27 import java.util.Iterator;
28 import java.util.concurrent.*;
29
30 import static org.junit.Assert.*;
31
32 public class DocumentBuilderPoolingTest {
33
34 private static final String DOCUMENTBUILDERPROXY_CLASSNAME =
35 "org.apache.xml.security.utils.XMLUtils$DocumentBuilderProxy";
36
37 @Test
38 public void testEquals() throws Exception {
39 DocumentBuilder documentBuilder = XMLUtils.createDocumentBuilder(true);
40 assertEquals(documentBuilder, documentBuilder);
41 assertSame(documentBuilder, documentBuilder);
42 }
43
44 @Test
45 public void testGetValidatingDocumentBuilder() throws Exception {
46 DocumentBuilder documentBuilder = XMLUtils.createDocumentBuilder(true);
47 assertTrue(documentBuilder.isValidating());
48 }
49
50 @Test
51 public void testGetNonValidatingDocumentBuilder() throws Exception {
52 DocumentBuilder documentBuilder = XMLUtils.createDocumentBuilder(false);
53 assertFalse(documentBuilder.isValidating());
54 }
55
56 @Test
57 public void testGetValidatingAndAllowDocTypeDeclarationsDocumentBuilder() throws Exception {
58 DocumentBuilder documentBuilder = XMLUtils.createDocumentBuilder(true, false);
59 assertTrue(documentBuilder.isValidating());
60 assertEquals(documentBuilder.getClass().getName(), DOCUMENTBUILDERPROXY_CLASSNAME);
61 assertAllowDocTypeDeclarations(documentBuilder, false);
62 }
63
64 @Test
65 public void testGetValidatingAndDisAllowDocTypeDeclarationsDocumentBuilder() throws Exception {
66 DocumentBuilder documentBuilder = XMLUtils.createDocumentBuilder(true, true);
67 assertTrue(documentBuilder.isValidating());
68 assertEquals(documentBuilder.getClass().getName(), DOCUMENTBUILDERPROXY_CLASSNAME);
69 assertAllowDocTypeDeclarations(documentBuilder, true);
70 }
71
72 private void assertAllowDocTypeDeclarations(DocumentBuilder documentBuilder, boolean allow) throws Exception {
73 Field field = documentBuilder.getClass().getDeclaredField("disAllowDocTypeDeclarations");
74 field.setAccessible(true);
75 assertEquals(allow, field.get(documentBuilder));
76 }
77
78 @Test
79 public void testNewDocumentBuilderInstances() throws Exception {
80 int count = 4;
81
82 // get all possible combinations of DocumentBuilders:
83 DocumentBuilder[] documentBuilders = new DocumentBuilder[count];
84 for (int i = 0; i < count; i++) {
85 documentBuilders[i] = XMLUtils.createDocumentBuilder(i / 2 > 0, i % 2 == 1);
86 }
87
88 //test that we got always a new instance:
89 for (int i = 0; i < count; i++) {
90 for (int j = i + 1; j < count; j++) {
91 assertNotEquals(documentBuilders[i], documentBuilders[j]);
92 assertNotSame(documentBuilders[i], documentBuilders[j]);
93 }
94 }
95 }
96
97 @Test
98 public void testRepoolingTwice() throws Exception {
99 DocumentBuilder documentBuilder = XMLUtils.createDocumentBuilder(true);
100 assertTrue(XMLUtils.repoolDocumentBuilder(documentBuilder));
101 assertFalse("can't repool the same object twice!", XMLUtils.repoolDocumentBuilder(documentBuilder));
102 }
103
104 @Test(timeout = 30000)
105 public void testPooling() throws Exception {
106 int nThreads = 8;
107 ExecutorService exec = Executors.newFixedThreadPool(nThreads);
108 Future<?>[] results = new Future[nThreads];
109 for (int i = 0; i < nThreads - 1; i++) {
110 results[i] = exec.submit(new Runnable() {
111 @Override
112 public void run() {
113 try {
114 while (true) {
115 // retrieve some DocumentBuilders...
116 DocumentBuilder documentBuilders[] = new DocumentBuilder[10];
117 for (int i = 0; i < documentBuilders.length; i++) {
118 documentBuilders[i] = XMLUtils.createDocumentBuilder(false);
119 assertNotNull(documentBuilders[i]);
120 }
121 // ...then repool them so that another thread may pickup them again
122 for (int i = 0; i < documentBuilders.length; i++) {
123 assertTrue(XMLUtils.repoolDocumentBuilder(documentBuilders[i]));
124 }
125 }
126 } catch (Exception e) {
127 throw new RuntimeException(e);
128 }
129 }
130 });
131 }
132 // more or less mimic gc
133 results[nThreads - 1] = exec.submit(new Runnable() {
134 @Override
135 public void run() {
136 try {
137 final Field poolField = XMLUtils.class.getDeclaredField("pools");
138 poolField.setAccessible(true);
139 final WeakObjectPool[] weakObjectPools = (WeakObjectPool[]) poolField.get(null);
140
141 final Field availableField = WeakObjectPool.class.getDeclaredField("available");
142 availableField.setAccessible(true);
143
144 while (true) {
145 final BlockingDeque blockingDeque = (BlockingDeque) availableField.get(weakObjectPools[1]);
146 Iterator iterator = blockingDeque.iterator();
147 while (iterator.hasNext()) {
148 ((WeakReference) iterator.next()).clear();
149 }
150 Thread.sleep(200);
151 }
152 } catch (InterruptedException e) {
153 return;
154 } catch (Exception e) {
155 throw new RuntimeException(e);
156 }
157 }
158 });
159
160 exec.shutdown();
161 exec.awaitTermination(5, TimeUnit.SECONDS);
162 for (Future<?> f : results) {
163 if (!f.isDone()) {
164 f.cancel(false);
165 }
166 try {
167 assertNull(f.get(1000, TimeUnit.MILLISECONDS));
168 } catch (CancellationException ce) {
169 ;//expected since we did cancel it
170 } catch (TimeoutException e) {
171 fail(f + "didn't cancel after timeout?");
172 }
173 }
174 }
175 }
+0
-149
src/test/java/org/apache/xml/security/test/dom/utils/PoolingTest.java less more
0 /**
1 * Licensed to the Apache Software Foundation (ASF) under one
2 * or more contributor license agreements. See the NOTICE file
3 * distributed with this work for additional information
4 * regarding copyright ownership. The ASF licenses this file
5 * to you under the Apache License, Version 2.0 (the
6 * "License"); you may not use this file except in compliance
7 * with the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18 package org.apache.xml.security.test.dom.utils;
19
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertNotEquals;
22 import static org.junit.Assert.assertNotNull;
23 import static org.junit.Assert.assertNotSame;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.assertSame;
26 import static org.junit.Assert.assertTrue;
27 import static org.junit.Assert.fail;
28
29 import java.util.Random;
30 import java.util.concurrent.CancellationException;
31 import java.util.concurrent.ExecutionException;
32 import java.util.concurrent.ExecutorService;
33 import java.util.concurrent.Executors;
34 import java.util.concurrent.Future;
35 import java.util.concurrent.TimeUnit;
36 import java.util.concurrent.TimeoutException;
37
38 import javax.xml.parsers.DocumentBuilder;
39 import javax.xml.parsers.ParserConfigurationException;
40
41 import org.apache.xml.security.utils.XMLUtils;
42 import org.junit.Test;
43
44 public class PoolingTest {
45
46 @Test
47 public void testPooling() throws ParserConfigurationException, InterruptedException, ExecutionException {
48 //assert parameters
49 DocumentBuilder db = XMLUtils.createDocumentBuilder(true);
50 assertTrue(db.isValidating());
51 DocumentBuilder db2 = XMLUtils.createDocumentBuilder(false);
52 assertFalse(db2.isValidating());
53 assertNotEquals(db2, db);
54 DocumentBuilder db3 = XMLUtils.createDocumentBuilder(true, false);
55 assertTrue(db3.isValidating());
56 DocumentBuilder db4 = XMLUtils.createDocumentBuilder(false, false);
57 assertFalse(db4.isValidating());
58
59 //assert get
60 DocumentBuilder db_ = XMLUtils.createDocumentBuilder(true);
61 assertNotSame("db wasn't returned", db, db_);
62 DocumentBuilder db2_ = XMLUtils.createDocumentBuilder(false);
63 assertNotSame(db2, db2_);
64 DocumentBuilder db3_ = XMLUtils.createDocumentBuilder(true, false);
65 assertNotSame(db3, db3_);
66 DocumentBuilder db4_ = XMLUtils.createDocumentBuilder(false, false);
67 assertNotSame(db4, db4_);
68
69 //assert get after return
70 assertTrue(XMLUtils.repoolDocumentBuilder(db_));
71 assertFalse("can't repool the same object twice!", XMLUtils.repoolDocumentBuilder(db_));
72 DocumentBuilder db_1 = XMLUtils.createDocumentBuilder(true);
73 assertSame(db_, db_1);
74
75 assertTrue(XMLUtils.repoolDocumentBuilder(db2_));
76 assertFalse("can't repool the same object twice!", XMLUtils.repoolDocumentBuilder(db2_));
77 DocumentBuilder db_2 = XMLUtils.createDocumentBuilder(false);
78 assertSame(db2_, db_2);
79
80 assertTrue(XMLUtils.repoolDocumentBuilder(db3_));
81 assertFalse("can't repool the same object twice!", XMLUtils.repoolDocumentBuilder(db3_));
82 DocumentBuilder db_3 = XMLUtils.createDocumentBuilder(true, false);
83 assertSame(db3_, db_3);
84
85 assertTrue(XMLUtils.repoolDocumentBuilder(db4_));
86 assertFalse("can't repool the same object twice!", XMLUtils.repoolDocumentBuilder(db4_));
87 DocumentBuilder db_4 = XMLUtils.createDocumentBuilder(false, false);
88 assertSame(db4_, db_4);
89
90 // final byte[] largeArrays[] = new byte[1024][];
91 // final DocumentBuilder[] dbLargeArrays = new DocumentBuilder[largeArrays.length];
92
93 int nThreads = Runtime.getRuntime().availableProcessors();
94 ExecutorService exec = Executors.newFixedThreadPool(nThreads);
95 Future<?>[] results = new Future[nThreads];
96 for(int i = 0; i < nThreads-1; i++) {
97 results[i] = exec.submit(new Runnable() {
98 @Override
99 public void run() {
100 for(;;) {
101 DocumentBuilder dbA[] = new DocumentBuilder[10];
102 for (int i = 0; i < dbA.length; i++) {
103 try {
104 dbA[i] = XMLUtils.createDocumentBuilder(false);
105 assertNotNull(dbA[i]);
106 } catch (ParserConfigurationException e) {
107 e.printStackTrace();
108 fail(e.toString());
109 }
110 assertNotNull(dbA[i]);
111 }
112 for(int i = 0; i < new Random().nextInt(dbA.length); i++) {
113 assertTrue(XMLUtils.repoolDocumentBuilder(dbA[i]));
114 }
115 }
116 }
117 });
118 }
119 results[nThreads-1] = exec.submit(new Runnable() {
120 @Override
121 public void run() {
122 for(;;) {
123 byte[] largeArrays[] = new byte[1024][];
124 for (int i = 0; i < largeArrays.length; i++)
125 try {
126 largeArrays[i] = new byte[1024*1024];
127 } catch (OutOfMemoryError e) {
128 System.out.println("OOM from largeArray");
129 break;
130 }
131 }
132 }
133 });
134 exec.shutdown();
135 exec.awaitTermination(5, TimeUnit.SECONDS);
136 for(Future<?> f : results) {
137 if (!f.isDone())
138 f.cancel(false);
139 try {
140 assertNull(f.get(1000, TimeUnit.MILLISECONDS));
141 } catch (CancellationException ce) {
142 ;//expected since we did cancel it
143 } catch (TimeoutException e) {
144 fail(f + "didn't cancel after timeout?");
145 }
146 }
147 }
148 }
0 /**
1 * Licensed to the Apache Software Foundation (ASF) under one
2 * or more contributor license agreements. See the NOTICE file
3 * distributed with this work for additional information
4 * regarding copyright ownership. The ASF licenses this file
5 * to you under the Apache License, Version 2.0 (the
6 * "License"); you may not use this file except in compliance
7 * with the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18 package org.apache.xml.security.test.stax;
19
20 import org.apache.xml.security.stax.ext.stax.*;
21 import org.apache.xml.security.stax.impl.XMLSecurityEventReader;
22 import org.apache.xml.security.stax.impl.stax.*;
23 import org.codehaus.stax2.ri.evt.CharactersEventImpl;
24 import org.junit.Assert;
25 import org.junit.Test;
26
27 import javax.xml.namespace.QName;
28 import javax.xml.stream.XMLEventReader;
29 import javax.xml.stream.XMLInputFactory;
30 import javax.xml.stream.XMLStreamReader;
31 import javax.xml.stream.events.XMLEvent;
32 import java.io.PrintWriter;
33 import java.io.StringWriter;
34 import java.io.Writer;
35 import java.util.ArrayDeque;
36 import java.util.Deque;
37
38 /**
39 * @author $Author: giger $
40 * @version $Revision: 1659901 $ $Date: 2015-02-15 10:11:24 +0100 (Sun, 15 Feb 2015) $
41 */
42 public class XMLSecEventTest extends Assert {
43
44 @Test
45 public void testWriteCharactersEncoded() throws Exception {
46 StringWriter stringWriter = new StringWriter();
47 XMLSecCharacters xmlSecCharacters = new XMLSecCharactersImpl("test", false, false, false, null);
48 xmlSecCharacters.writeAsEncodedUnicode(stringWriter);
49 Assert.assertEquals("test", stringWriter.toString());
50
51 stringWriter = new StringWriter();
52 xmlSecCharacters = new XMLSecCharactersImpl("<", false, false, false, null);
53 xmlSecCharacters.writeAsEncodedUnicode(stringWriter);
54 Assert.assertEquals("&lt;", stringWriter.toString());
55
56 stringWriter = new StringWriter();
57 xmlSecCharacters = new XMLSecCharactersImpl(">", false, false, false, null);
58 xmlSecCharacters.writeAsEncodedUnicode(stringWriter);
59 Assert.assertEquals("&gt;", stringWriter.toString());
60
61 stringWriter = new StringWriter();
62 xmlSecCharacters = new XMLSecCharactersImpl("&", false, false, false, null);
63 xmlSecCharacters.writeAsEncodedUnicode(stringWriter);
64 Assert.assertEquals("&amp;", stringWriter.toString());
65
66 stringWriter = new StringWriter();
67 xmlSecCharacters = new XMLSecCharactersImpl("<&>", false, false, false, null);
68 xmlSecCharacters.writeAsEncodedUnicode(stringWriter);
69 Assert.assertEquals("&lt;&amp;&gt;", stringWriter.toString());
70
71 stringWriter = new StringWriter();
72 xmlSecCharacters = new XMLSecCharactersImpl(" < & > ", false, false, false, null);
73 xmlSecCharacters.writeAsEncodedUnicode(stringWriter);
74 Assert.assertEquals(" &lt; &amp; &gt; ", stringWriter.toString());
75 }
76
77 @Test
78 public void testWriteAttributeEncoded() throws Exception {
79 StringWriter stringWriter = new StringWriter();
80 XMLSecAttribute xmlSecAttribute = new XMLSecAttributeImpl(new QName("test", "test", "test"), "test");
81 xmlSecAttribute.writeAsEncodedUnicode(stringWriter);
82 Assert.assertEquals("test:test=\"test\"", stringWriter.toString());
83
84 stringWriter = new StringWriter();
85 xmlSecAttribute = new XMLSecAttributeImpl(new QName("test"), "\"");
86 xmlSecAttribute.writeAsEncodedUnicode(stringWriter);
87 Assert.assertEquals("test=\"&quot;\"", stringWriter.toString());
88
89 stringWriter = new StringWriter();
90 xmlSecAttribute = new XMLSecAttributeImpl(new QName("test"), "&");
91 xmlSecAttribute.writeAsEncodedUnicode(stringWriter);
92 Assert.assertEquals("test=\"&amp;\"", stringWriter.toString());
93
94 stringWriter = new StringWriter();
95 xmlSecAttribute = new XMLSecAttributeImpl(new QName("test"), " & \" > < ");
96 xmlSecAttribute.writeAsEncodedUnicode(stringWriter);
97 Assert.assertEquals("test=\" &amp; &quot; > < \"", stringWriter.toString());
98 }
99
100 @Test
101 public void testWriteComment() throws Exception {
102 StringWriter stringWriter = new StringWriter();
103 XMLSecComment xmlSecAttribute = new XMLSecCommentImpl(" < > & \" '", null);
104 xmlSecAttribute.writeAsEncodedUnicode(stringWriter);
105 Assert.assertEquals("<!-- < > & \" '-->", stringWriter.toString());
106 }
107
108 @Test
109 public void testWriteEntityDeclaration() throws Exception {
110 StringWriter stringWriter = new StringWriter();
111 XMLSecEntityDeclaration xmlSecEntityDeclaration = new XMLSecEntityDeclarationImpl("test");
112 xmlSecEntityDeclaration.writeAsEncodedUnicode(stringWriter);
113 Assert.assertEquals("<!ENTITY test \"\">", stringWriter.toString());
114 }
115
116 @Test
117 public void testWriteEntityReference() throws Exception {
118 StringWriter stringWriter = new StringWriter();
119 XMLSecEntityReference xmlSecEntityReference = new XMLSecEntityReferenceImpl("test", null, null);
120 xmlSecEntityReference.writeAsEncodedUnicode(stringWriter);
121 Assert.assertEquals("&test;", stringWriter.toString());
122 }
123
124 @Test
125 public void testWriteNamespaceEncoded() throws Exception {
126 StringWriter stringWriter = new StringWriter();
127 XMLSecNamespace xmlSecNamespace = XMLSecNamespaceImpl.getInstance("test", "test");
128 xmlSecNamespace.writeAsEncodedUnicode(stringWriter);
129 Assert.assertEquals("xmlns:test=\"test\"", stringWriter.toString());
130
131 stringWriter = new StringWriter();
132 xmlSecNamespace = XMLSecNamespaceImpl.getInstance("", "\"");
133 xmlSecNamespace.writeAsEncodedUnicode(stringWriter);
134 Assert.assertEquals("xmlns=\"&quot;\"", stringWriter.toString());
135
136 stringWriter = new StringWriter();
137 xmlSecNamespace = XMLSecNamespaceImpl.getInstance("test", "&");
138 xmlSecNamespace.writeAsEncodedUnicode(stringWriter);
139 Assert.assertEquals("xmlns:test=\"&amp;\"", stringWriter.toString());
140
141 stringWriter = new StringWriter();
142 xmlSecNamespace = XMLSecNamespaceImpl.getInstance("test", " & \" > < ");
143 xmlSecNamespace.writeAsEncodedUnicode(stringWriter);
144 Assert.assertEquals("xmlns:test=\" &amp; &quot; > < \"", stringWriter.toString());
145 }
146
147 @Test
148 public void testWriteProcessingInstruction() throws Exception {
149 StringWriter stringWriter = new StringWriter();
150 XMLSecProcessingInstruction xmlSecProcessingInstruction =
151 new XMLSecProcessingInstructionImpl("test", "test", null);
152 xmlSecProcessingInstruction.writeAsEncodedUnicode(stringWriter);
153 Assert.assertEquals("<?test test?>", stringWriter.toString());
154 }
155
156 @Test
157 public void testwWiteAsEncodedUnicode() throws Exception {
158 XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
159 XMLStreamReader xmlStreamReader =
160 xmlInputFactory.createXMLStreamReader(this.getClass().getClassLoader().getResourceAsStream(
161 "org/apache/xml/security/c14n/inExcl/plain-soap-1.1.xml"));
162
163 Deque<XMLSecEvent> xmlSecEventDeque = new ArrayDeque<XMLSecEvent>();
164 do {
165 xmlSecEventDeque.push(XMLSecEventFactory.allocate(xmlStreamReader, null));
166 xmlStreamReader.next();
167 }
168 while (xmlStreamReader.hasNext());
169 xmlSecEventDeque.push((XMLSecEventFactory.allocate(xmlStreamReader, null)));//EndDocumentEvent
170
171 XMLSecurityEventReader xmlSecurityEventReader = new XMLSecurityEventReader(xmlSecEventDeque, 0);
172
173 XMLEventReader xmlEventReader =
174 xmlInputFactory.createXMLEventReader(this.getClass().getClassLoader().getResourceAsStream(
175 "org/apache/xml/security/c14n/inExcl/plain-soap-1.1.xml"));
176
177 final StringWriter stdWriter = new StringWriter();
178 final StringWriter secWriter = new StringWriter();
179 while (xmlEventReader.hasNext()) {
180 XMLEvent stdXmlEvent = xmlEventReader.nextEvent();
181 XMLEvent secXmlEvent = xmlSecurityEventReader.nextEvent();
182
183 stdXmlEvent.writeAsEncodedUnicode(stdWriter);
184 secXmlEvent.writeAsEncodedUnicode(secWriter);
185 }
186
187 Assert.assertEquals(secWriter.toString(), stdWriter.toString());
188 }
189 }