Codebase list libxml-security-java / ec07696
New upstream version 2.0.2 Emmanuel Bourg 5 years ago
19 changed file(s) with 272 addition(s) and 99 deletion(s). Raw diff Collapse all Expand all
2121 <artifactId>xmlsec</artifactId>
2222 <packaging>bundle</packaging>
2323 <name>Apache XML Security for Java</name>
24 <version>2.0.1</version>
24 <version>2.0.2</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.1
59 scm:svn:http://svn.apache.org/repos/asf/santuario/xml-security-java/tags/xmlsec-2.0.2
6060 </connection>
6161 <developerConnection>
62 scm:svn:https://svn.apache.org/repos/asf/santuario/xml-security-java/tags/xmlsec-2.0.1
62 scm:svn:https://svn.apache.org/repos/asf/santuario/xml-security-java/tags/xmlsec-2.0.2
6363 </developerConnection>
64 <url>http://svn.apache.org/repos/asf/santuario/xml-security-java/tags/xmlsec-2.0.1</url>
64 <url>http://svn.apache.org/repos/asf/santuario/xml-security-java/tags/xmlsec-2.0.2</url>
6565 </scm>
6666 <organization>
6767 <name>The Apache Software Foundation</name>
142142 <plugin>
143143 <groupId>org.apache.maven.plugins</groupId>
144144 <artifactId>maven-jar-plugin</artifactId>
145 <version>2.4</version>
145 <version>2.5</version>
146146 <executions>
147147 <execution>
148148 <phase>test-compile</phase>
252252 <plugin>
253253 <groupId>org.apache.maven.plugins</groupId>
254254 <artifactId>maven-source-plugin</artifactId>
255 <version>2.2.1</version>
255 <version>2.3</version>
256256 <executions>
257257 <execution>
258258 <goals>
407407 <xml.apis.version>1.4.01</xml.apis.version>
408408 <oldxmlsec.version>1.5.6</oldxmlsec.version>
409409 <slf4j.version>1.7.7</slf4j.version>
410 <xalan.version>2.7.1</xalan.version>
410 <xalan.version>2.7.2</xalan.version>
411411 <xerces.version>2.11.0</xerces.version>
412412 <junit.version>4.11</junit.version>
413413 <log4j.version>1.2.17</log4j.version>
414 <bcprov.version>1.50</bcprov.version>
414 <bcprov.version>1.51</bcprov.version>
415415 <xmlunit.version>1.5</xmlunit.version>
416416 <commons.codec.version>1.9</commons.codec.version>
417 <woodstox.core.asl.version>4.4.0</woodstox.core.asl.version>
417 <woodstox.core.asl.version>4.4.1</woodstox.core.asl.version>
418418 <jetty.version>8.1.4.v20120524</jetty.version>
419419 <xmlsec.jaxb.context.class />
420420 </properties>
2626 * Portions copyright 2005 Sun Microsystems, Inc. All rights reserved.
2727 */
2828 /*
29 * $Id: XMLDSigRI.java 1590588 2014-04-28 10:29:52Z coheigea $
29 * $Id: XMLDSigRI.java 1626703 2014-09-22 09:05:28Z coheigea $
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.01, INFO);
59 super("ApacheXMLDSig", 2.02, INFO);
6060
6161 final Map<Object, Object> map = new HashMap<Object, Object>();
6262 map.put("XMLSignatureFactory.DOM",
7878 public void writeStartElement(String prefix, String localName, String namespaceURI) {
7979 Element newElem = m_factory.createElementNS(namespaceURI, DOMUtils.getQNameString(prefix, localName));
8080 if (m_nextSibling != null) {
81 m_nextSibling.getParentNode().insertBefore(newElem, m_nextSibling);
81 newElem = (Element)m_nextSibling.getParentNode().insertBefore(newElem, m_nextSibling);
8282 }
8383 else {
84 m_currentNode.appendChild(newElem);
84 newElem = (Element)m_currentNode.appendChild(newElem);
8585 }
8686 m_nextSibling = null;
8787 m_currentNode = newElem;
133133 */
134134 protected void engineInitVerify(Key secretKey) throws XMLSignatureException {
135135 if (!(secretKey instanceof SecretKey)) {
136 String supplied = secretKey.getClass().getName();
136 String supplied = null;
137 if (secretKey != null) {
138 supplied = secretKey.getClass().getName();
139 }
137140 String needed = SecretKey.class.getName();
138141 Object exArgs[] = { supplied, needed };
139142
189192 * @throws XMLSignatureException
190193 */
191194 protected void engineInitSign(Key secretKey) throws XMLSignatureException {
192 if (!(secretKey instanceof SecretKey)) {
193 String supplied = secretKey.getClass().getName();
194 String needed = SecretKey.class.getName();
195 Object exArgs[] = { supplied, needed };
196
197 throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
198 }
199
200 try {
201 this.macAlgorithm.init(secretKey);
202 } catch (InvalidKeyException ex) {
203 throw new XMLSignatureException("empty", ex);
204 }
195 engineInitSign(secretKey, (AlgorithmParameterSpec)null);
205196 }
206197
207198 /**
215206 Key secretKey, AlgorithmParameterSpec algorithmParameterSpec
216207 ) throws XMLSignatureException {
217208 if (!(secretKey instanceof SecretKey)) {
218 String supplied = secretKey.getClass().getName();
209 String supplied = null;
210 if (secretKey != null) {
211 supplied = secretKey.getClass().getName();
212 }
219213 String needed = SecretKey.class.getName();
220214 Object exArgs[] = { supplied, needed };
221215
223217 }
224218
225219 try {
226 this.macAlgorithm.init(secretKey, algorithmParameterSpec);
220 if (algorithmParameterSpec == null) {
221 this.macAlgorithm.init(secretKey);
222 } else {
223 this.macAlgorithm.init(secretKey, algorithmParameterSpec);
224 }
227225 } catch (InvalidKeyException ex) {
228226 throw new XMLSignatureException("empty", ex);
229227 } catch (InvalidAlgorithmParameterException ex) {
9595 /** @inheritDoc */
9696 protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
9797 if (!(publicKey instanceof PublicKey)) {
98 String supplied = publicKey.getClass().getName();
98 String supplied = null;
99 if (publicKey != null) {
100 supplied = publicKey.getClass().getName();
101 }
99102 String needed = PublicKey.class.getName();
100103 Object exArgs[] = { supplied, needed };
101104
135138 protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
136139 throws XMLSignatureException {
137140 if (!(privateKey instanceof PrivateKey)) {
138 String supplied = privateKey.getClass().getName();
141 String supplied = null;
142 if (privateKey != null) {
143 supplied = privateKey.getClass().getName();
144 }
139145 String needed = PrivateKey.class.getName();
140146 Object exArgs[] = { supplied, needed };
141147
143149 }
144150
145151 try {
146 this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
152 if (secureRandom == null) {
153 this.signatureAlgorithm.initSign((PrivateKey) privateKey);
154 } else {
155 this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
156 }
147157 } catch (InvalidKeyException ex) {
148158 throw new XMLSignatureException("empty", ex);
149159 }
151161
152162 /** @inheritDoc */
153163 protected void engineInitSign(Key privateKey) throws XMLSignatureException {
154 if (!(privateKey instanceof PrivateKey)) {
155 String supplied = privateKey.getClass().getName();
156 String needed = PrivateKey.class.getName();
157 Object exArgs[] = { supplied, needed };
158
159 throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
160 }
161
162 try {
163 this.signatureAlgorithm.initSign((PrivateKey) privateKey);
164 } catch (InvalidKeyException ex) {
165 throw new XMLSignatureException("empty", ex);
166 }
164 engineInitSign(privateKey, (SecureRandom)null);
167165 }
168166
169167 /** @inheritDoc */
122122 */
123123 protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
124124 if (!(publicKey instanceof PublicKey)) {
125 String supplied = publicKey.getClass().getName();
125 String supplied = null;
126 if (publicKey != null) {
127 supplied = publicKey.getClass().getName();
128 }
126129 String needed = PublicKey.class.getName();
127130 Object exArgs[] = { supplied, needed };
128131
171174 protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
172175 throws XMLSignatureException {
173176 if (!(privateKey instanceof PrivateKey)) {
174 String supplied = privateKey.getClass().getName();
177 String supplied = null;
178 if (privateKey != null) {
179 supplied = privateKey.getClass().getName();
180 }
175181 String needed = PrivateKey.class.getName();
176182 Object exArgs[] = { supplied, needed };
177183
179185 }
180186
181187 try {
182 this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
188 if (secureRandom == null) {
189 this.signatureAlgorithm.initSign((PrivateKey) privateKey);
190 } else {
191 this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
192 }
183193 } catch (InvalidKeyException ex) {
184194 throw new XMLSignatureException("empty", ex);
185195 }
190200 * @inheritDoc
191201 */
192202 protected void engineInitSign(Key privateKey) throws XMLSignatureException {
193 if (!(privateKey instanceof PrivateKey)) {
194 String supplied = privateKey.getClass().getName();
195 String needed = PrivateKey.class.getName();
196 Object exArgs[] = { supplied, needed };
197
198 throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
199 }
200
201 try {
202 this.signatureAlgorithm.initSign((PrivateKey) privateKey);
203 } catch (InvalidKeyException ex) {
204 throw new XMLSignatureException("empty", ex);
205 }
206 size = ((DSAKey)privateKey).getParams().getQ().bitLength();
203 engineInitSign(privateKey, (SecureRandom)null);
207204 }
208205
209206 /**
235235 protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
236236
237237 if (!(publicKey instanceof PublicKey)) {
238 String supplied = publicKey.getClass().getName();
238 String supplied = null;
239 if (publicKey != null) {
240 supplied = publicKey.getClass().getName();
241 }
239242 String needed = PublicKey.class.getName();
240243 Object exArgs[] = { supplied, needed };
241244
279282 protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
280283 throws XMLSignatureException {
281284 if (!(privateKey instanceof PrivateKey)) {
282 String supplied = privateKey.getClass().getName();
285 String supplied = null;
286 if (privateKey != null) {
287 supplied = privateKey.getClass().getName();
288 }
283289 String needed = PrivateKey.class.getName();
284290 Object exArgs[] = { supplied, needed };
285291
287293 }
288294
289295 try {
290 this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
296 if (secureRandom == null) {
297 this.signatureAlgorithm.initSign((PrivateKey) privateKey);
298 } else {
299 this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
300 }
291301 } catch (InvalidKeyException ex) {
292302 throw new XMLSignatureException("empty", ex);
293303 }
295305
296306 /** @inheritDoc */
297307 protected void engineInitSign(Key privateKey) throws XMLSignatureException {
298 if (!(privateKey instanceof PrivateKey)) {
299 String supplied = privateKey.getClass().getName();
300 String needed = PrivateKey.class.getName();
301 Object exArgs[] = { supplied, needed };
302
303 throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
304 }
305
306 try {
307 this.signatureAlgorithm.initSign((PrivateKey) privateKey);
308 } catch (InvalidKeyException ex) {
309 throw new XMLSignatureException("empty", ex);
310 }
308 engineInitSign(privateKey, (SecureRandom)null);
311309 }
312310
313311 /** @inheritDoc */
32173217 Element digestElement =
32183218 XMLUtils.createElementInSignatureSpace(contextDocument, Constants._TAG_DIGESTMETHOD);
32193219 digestElement.setAttributeNS(null, "Algorithm", digestAlgorithm);
3220 digestElement.setAttributeNS(
3221 Constants.NamespaceSpecNS,
3222 "xmlns:" + ElementProxy.getDefaultPrefix(Constants.SignatureSpecNS),
3223 Constants.SignatureSpecNS
3224 );
32203225 result.appendChild(digestElement);
32213226 }
32223227 if (mgfAlgorithm != null) {
270270 Canonicalizer.getInstance(this.getCanonicalizationMethodURI());
271271 c14nizer.setSecureValidation(isSecureValidation());
272272
273 this.c14nizedBytes =
274 c14nizer.canonicalizeSubtree(getElement());
273 String inclusiveNamespaces = this.getInclusiveNamespaces();
274 if (inclusiveNamespaces == null) {
275 this.c14nizedBytes = c14nizer.canonicalizeSubtree(getElement());
276 } else {
277 this.c14nizedBytes = c14nizer.canonicalizeSubtree(getElement(), inclusiveNamespaces);
278 }
275279 }
276280
277281 // make defensive copy
352356 return new SecretKeySpec(secretKeyBytes, this.signatureAlgorithm.getJCEAlgorithmString());
353357 }
354358
355 protected SignatureAlgorithm getSignatureAlgorithm() {
359 public SignatureAlgorithm getSignatureAlgorithm() {
356360 return signatureAlgorithm;
357361 }
358362
139139 createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_KeyInfo, true, null);
140140
141141 List<XMLSecAttribute> attributes = new ArrayList<XMLSecAttribute>(1);
142 String keyId = getEncryptionPartDef().getKeyId();
143 if (keyId == null) {
144 keyId = IDGenerator.generateID("EK");
145 }
142 String keyId = IDGenerator.generateID("EK");
146143 attributes.add(createAttribute(XMLSecurityConstants.ATT_NULL_Id, keyId));
147144 createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_xenc_EncryptedKey, true, attributes);
148145
133133
134134 kvks = new KeySelectors.KeyValueKeySelector();
135135
136 rsaKeyPair = KeyPairGenerator.getInstance("RSA").genKeyPair();
136 KeyPairGenerator rsaKpg = KeyPairGenerator.getInstance("RSA");
137 rsaKpg.initialize(2048);
138 rsaKeyPair = rsaKpg.genKeyPair();
139
137140 ecKeyPair = KeyPairGenerator.getInstance("EC").genKeyPair();
138141
139142 KeyInfoFactory kifac = fac.getKeyInfoFactory();
7575 }
7676 }
7777
78 rsaKeyPair = KeyPairGenerator.getInstance("RSA").genKeyPair();
78 KeyPairGenerator rsaKpg = KeyPairGenerator.getInstance("RSA");
79 rsaKpg.initialize(2048);
80 rsaKeyPair = rsaKpg.genKeyPair();
81
7982 ecKeyPair = KeyPairGenerator.getInstance("EC").genKeyPair();
8083 }
8184
3535 import org.apache.xml.security.c14n.Canonicalizer;
3636 import org.apache.xml.security.keys.KeyInfo;
3737 import org.apache.xml.security.signature.ObjectContainer;
38 import org.apache.xml.security.signature.SignedInfo;
39 import org.apache.xml.security.signature.XMLSignature;
3840 import org.apache.xml.security.test.dom.DSNamespaceContext;
3941 import org.apache.xml.security.transforms.Transforms;
4042 import org.apache.xml.security.transforms.params.XPath2FilterContainer;
4143 import org.apache.xml.security.transforms.params.XPathContainer;
42 import org.apache.xml.security.signature.XMLSignature;
4344 import org.apache.xml.security.utils.Constants;
4445 import org.apache.xml.security.utils.ElementProxy;
4546 import org.apache.xml.security.utils.XMLUtils;
204205 XMLSignature signature = new XMLSignature(sigElement, "");
205206 assertTrue(signature.checkSignatureValue(ks.getCertificate("test").getPublicKey()));
206207 }
208
209 @org.junit.Test
210 public void testCanonicalizedOctetStream() throws Exception {
211 String signedXML = doSign();
212
213 org.w3c.dom.Document doc = db.parse(new ByteArrayInputStream(signedXML.getBytes()));
214
215 XPathFactory xpf = XPathFactory.newInstance();
216 XPath xpath = xpf.newXPath();
217 xpath.setNamespaceContext(new DSNamespaceContext());
218
219 String expression = "//ds:Signature[1]";
220 Element sigElement =
221 (Element) xpath.evaluate(expression, doc, XPathConstants.NODE);
222
223 XMLSignature signature = new XMLSignature(sigElement, "");
224 KeyInfo ki = signature.getKeyInfo();
225
226 if (ki == null) {
227 throw new RuntimeException("No keyinfo");
228 }
229 PublicKey pk = signature.getKeyInfo().getPublicKey();
230
231 if (pk == null) {
232 throw new RuntimeException("No public key");
233 }
234
235 SignedInfo si = signature.getSignedInfo();
236 SignatureAlgorithm sa = si.getSignatureAlgorithm();
237 sa.initVerify(pk);
238
239 byte[] sigBytes = signature.getSignatureValue();
240
241 byte[] canonicalizedBytes = si.getCanonicalizedOctetStream();
242 sa.update(canonicalizedBytes, 0, canonicalizedBytes.length);
243
244 assertTrue(sa.verify(sigBytes));
245 assertTrue(si.verify(false));
246 }
247
207248
208249 private String doSign() throws Exception {
209250 PrivateKey privateKey = kp.getPrivate();
1717 */
1818 package org.apache.xml.security.test.stax.c14n;
1919
20 import org.apache.xml.security.test.stax.utils.UnixInputStream;
2021 import org.junit.Test;
2122
2223 import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
3738
3839 /**
3940 * @author $Author: giger $
40 * @version $Revision: 1399606 $ $Date: 2012-10-18 14:17:41 +0200 (Thu, 18 Oct 2012) $
41 * @version $Revision: 1612074 $ $Date: 2014-07-20 13:02:41 +0200 (Sun, 20 Jul 2014) $
4142 */
4243 public class Canonicalizer20010315Test extends org.junit.Assert {
4344
392393
393394 byte[] reference =
394395 getBytesFromResource(this.getClass().getClassLoader().getResource(
395 "org/apache/xml/security/c14n/in/default_ns_redefinition_c14n.xml"));
396 "org/apache/xml/security/c14n/in/default_ns_redefinition_c14n.xml"), true);
396397 boolean equals = java.security.MessageDigest.isEqual(reference, baos.toByteArray());
397398
398399 if (!equals) {
717718 assertTrue(result);
718719 }
719720
720
721721 public static byte[] getBytesFromResource(URL resource) throws IOException {
722 return getBytesFromResource(resource, false);
723 }
724
725 public static byte[] getBytesFromResource(URL resource, boolean unix) throws IOException {
722726
723727 ByteArrayOutputStream baos = new ByteArrayOutputStream();
724728 InputStream inputStream = resource.openStream();
729 if (unix) {
730 inputStream = new UnixInputStream(inputStream);
731 }
725732 try {
726733 byte buf[] = new byte[1024];
727734 int len;
587587 }
588588
589589 @Test
590 public void testEncryptedKeyMultipleElements() throws Exception {
591 // Set up the Configuration
592 XMLSecurityProperties properties = new XMLSecurityProperties();
593 List<XMLSecurityConstants.Action> actions = new ArrayList<XMLSecurityConstants.Action>();
594 actions.add(XMLSecurityConstants.ENCRYPT);
595 properties.setActions(actions);
596
597 // Set the key up
598 // Generate an RSA key
599 KeyPairGenerator rsaKeygen = KeyPairGenerator.getInstance("RSA");
600 KeyPair kp = rsaKeygen.generateKeyPair();
601 PrivateKey priv = kp.getPrivate();
602 PublicKey pub = kp.getPublic();
603 properties.setEncryptionTransportKey(pub);
604 properties.setEncryptionKeyTransportAlgorithm("http://www.w3.org/2001/04/xmlenc#rsa-1_5");
605
606 KeyGenerator keygen = KeyGenerator.getInstance("AES");
607 keygen.init(256);
608 SecretKey key = keygen.generateKey();
609 properties.setEncryptionKey(key);
610 properties.setEncryptionSymAlgorithm("http://www.w3.org/2001/04/xmlenc#aes256-cbc");
611 properties.setEncryptionKeyIdentifier(SecurityTokenConstants.KeyIdentifier_KeyValue);
612
613 SecurePart securePart =
614 new SecurePart(new QName("urn:example:po", "PaymentInfo"), SecurePart.Modifier.Content);
615 properties.addEncryptionPart(securePart);
616 securePart =
617 new SecurePart(new QName("urn:example:po", "ShippingAddress"), SecurePart.Modifier.Content);
618 properties.addEncryptionPart(securePart);
619
620 OutboundXMLSec outboundXMLSec = XMLSec.getOutboundXMLSec(properties);
621 ByteArrayOutputStream baos = new ByteArrayOutputStream();
622 XMLStreamWriter xmlStreamWriter = outboundXMLSec.processOutMessage(baos, "UTF-8");
623
624 InputStream sourceDocument =
625 this.getClass().getClassLoader().getResourceAsStream(
626 "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
627 XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(sourceDocument);
628
629 XmlReaderToWriter.writeAll(xmlStreamReader, xmlStreamWriter);
630 xmlStreamWriter.close();
631
632 // System.out.println("Got:\n" + new String(baos.toByteArray(), "UTF-8"));
633
634 Document document =
635 XMLUtils.createDocumentBuilder(false).parse(new ByteArrayInputStream(baos.toByteArray()));
636
637 // Check the CreditCard encrypted ok
638 NodeList nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
639 Assert.assertEquals(nodeList.getLength(), 0);
640
641 nodeList = document.getElementsByTagNameNS(
642 XMLSecurityConstants.TAG_xenc_EncryptedData.getNamespaceURI(),
643 XMLSecurityConstants.TAG_xenc_EncryptedData.getLocalPart()
644 );
645 Assert.assertEquals(nodeList.getLength(), 2);
646
647 // Decrypt using DOM API
648 decryptUsingDOM("http://www.w3.org/2001/04/xmlenc#tripledes-cbc", null, priv, document);
649 }
650
651 @Test
590652 public void testEncryptedKeyIssuerSerialReference() throws Exception {
591653 // Set up the Configuration
592654 XMLSecurityProperties properties = new XMLSecurityProperties();
7272 }
7373 }
7474
75 rsaKeyPair = KeyPairGenerator.getInstance("RSA").genKeyPair();
75 KeyPairGenerator rsaKpg = KeyPairGenerator.getInstance("RSA");
76 rsaKpg.initialize(2048);
77 rsaKeyPair = rsaKpg.genKeyPair();
78
7679 ecKeyPair = KeyPairGenerator.getInstance("EC").genKeyPair();
7780 }
7881
8585 }
8686 }
8787
88 rsaKeyPair = KeyPairGenerator.getInstance("RSA").genKeyPair();
88 KeyPairGenerator rsaKpg = KeyPairGenerator.getInstance("RSA");
89 rsaKpg.initialize(2048);
90 rsaKeyPair = rsaKpg.genKeyPair();
91
8992 ecKeyPair = KeyPairGenerator.getInstance("EC").genKeyPair();
9093 }
9194
2424 import org.apache.xml.security.stax.ext.XMLSecurityUtils;
2525 import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
2626 import org.apache.xml.security.stax.impl.transformer.TransformIdentity;
27 import org.apache.xml.security.test.stax.utils.UnixInputStream;
2728 import org.apache.xml.security.test.stax.utils.XMLSecEventAllocator;
2829 import org.junit.Assert;
2930 import org.junit.Before;
4344 import java.util.Map;
4445
4546 /**
46 * @author $Author: coheigea $
47 * @version $Revision: 1584089 $ $Date: 2014-04-02 18:46:35 +0200 (Wed, 02 Apr 2014) $
47 * @author $Author: giger $
48 * @version $Revision: 1612074 $ $Date: 2014-07-20 13:02:41 +0200 (Sun, 20 Jul 2014) $
4849 */
4950 public class TransformIdentityTest extends org.junit.Assert {
5051
230231 final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
231232 transformIdentity.setOutputStream(byteArrayOutputStream);
232233
233 transformIdentity.transform(this.getClass().getClassLoader().getResourceAsStream(
234 "ie/baltimore/merlin-examples/merlin-xmldsig-twenty-three/xml-stylesheet.b64"));
234 transformIdentity.transform(new UnixInputStream(this.getClass().getClassLoader().getResourceAsStream(
235 "ie/baltimore/merlin-examples/merlin-xmldsig-twenty-three/xml-stylesheet.b64")));
235236
236237 Assert.assertEquals(17786, byteArrayOutputStream.size());
237238 }
276277
277278 transformIdentity.setTransformer(transformer);
278279
279 transformIdentity.transform(this.getClass().getClassLoader().getResourceAsStream(
280 "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml"));
280 transformIdentity.transform(new UnixInputStream(this.getClass().getClassLoader().getResourceAsStream(
281 "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml")));
281282
282283 transformIdentity.doFinal();
283284
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.utils;
19
20 import java.io.IOException;
21 import java.io.InputStream;
22
23 /**
24 * Simple and stupid dos/windows to unix line ending converter.
25 * It's used to convert testdata to unix style independent on the
26 * platform running on. This is just a workaround for "svn:eol-style" set
27 * to native
28 *
29 * It's inefficient and simply suppresses the output of '\r' which
30 * is not correct in every case. So do not use it in productive code.
31 *
32 * @author $Author: giger $
33 * @version $Revision: 1612074 $ $Date: 2014-07-20 13:02:41 +0200 (Sun, 20 Jul 2014) $
34 */
35 public class UnixInputStream extends InputStream {
36
37 private InputStream inputStream;
38
39 public UnixInputStream(InputStream in) {
40 super();
41 this.inputStream = in;
42 }
43
44 @Override
45 public int read() throws IOException {
46 int read = inputStream.read();
47 if (read == '\r') {
48 return inputStream.read();
49 }
50 return read;
51 }
52 }