Codebase list libxml-security-java / 97bed96
New upstream version 2.0.10 Emmanuel Bourg 5 years ago
29 changed file(s) with 493 addition(s) and 181 deletion(s). Raw diff Collapse all Expand all
00 Apache Santuario - XML Security for Java
1 Copyright 1999-2017 The Apache Software Foundation
1 Copyright 1999-2018 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.9</version>
24 <version>2.0.10</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.9
59 scm:svn:http://svn.apache.org/repos/asf/santuario/xml-security-java/tags/xmlsec-2.0.10
6060 </connection>
6161 <developerConnection>
62 scm:svn:https://svn.apache.org/repos/asf/santuario/xml-security-java/tags/xmlsec-2.0.9
62 scm:svn:https://svn.apache.org/repos/asf/santuario/xml-security-java/tags/xmlsec-2.0.10
6363 </developerConnection>
64 <url>http://svn.apache.org/repos/asf/santuario/xml-security-java/tags/xmlsec-2.0.9</url>
64 <url>http://svn.apache.org/repos/asf/santuario/xml-security-java/tags/xmlsec-2.0.10</url>
6565 </scm>
6666 <organization>
6767 <name>The Apache Software Foundation</name>
136136 <plugin>
137137 <groupId>org.apache.maven.plugins</groupId>
138138 <artifactId>maven-compiler-plugin</artifactId>
139 <version>3.6.0</version>
139 <version>3.6.2</version>
140140 <configuration>
141141 <source>${targetJdk}</source>
142142 <target>${targetJdk}</target>
345345 <plugin>
346346 <groupId>org.apache.maven.plugins</groupId>
347347 <artifactId>maven-surefire-plugin</artifactId>
348 <version>2.19.1</version>
348 <version>2.20.1</version>
349349 <configuration>
350350 <reportFormat>brief</reportFormat>
351351 <useFile>false</useFile>
471471 <properties>
472472 <xml.apis.version>1.4.01</xml.apis.version>
473473 <oldxmlsec.version>1.5.8</oldxmlsec.version>
474 <slf4j.version>1.7.22</slf4j.version>
474 <slf4j.version>1.7.25</slf4j.version>
475475 <xalan.version>2.7.2</xalan.version>
476476 <xerces.version>2.11.0</xerces.version>
477477 <junit.version>4.12</junit.version>
478478 <log4j.version>1.2.17</log4j.version>
479 <bcprov.version>1.57</bcprov.version>
479 <bcprov.version>1.59</bcprov.version>
480480 <xmlunit.version>1.6</xmlunit.version>
481 <commons.codec.version>1.10</commons.codec.version>
482 <woodstox.core.asl.version>4.4.1</woodstox.core.asl.version>
481 <commons.codec.version>1.11</commons.codec.version>
482 <woodstox.core.version>5.0.3</woodstox.core.version>
483483 <jetty.version>8.1.22.v20160922</jetty.version>
484484 <xmlsec.jaxb.context.class />
485485 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
498498 <scope>compile</scope>
499499 </dependency>
500500 <dependency>
501 <groupId>org.codehaus.woodstox</groupId>
502 <artifactId>woodstox-core-asl</artifactId>
503 <version>${woodstox.core.asl.version}</version>
501 <groupId>com.fasterxml.woodstox</groupId>
502 <artifactId>woodstox-core</artifactId>
503 <version>${woodstox.core.version}</version>
504504 <scope>compile</scope>
505505 </dependency>
506506 <dependency>
2626 * Portions copyright 2005 Sun Microsystems, Inc. All rights reserved.
2727 */
2828 /*
29 * $Id: XMLDSigRI.java 1772201 2016-12-01 13:37:09Z coheigea $
29 * $Id: XMLDSigRI.java 1804980 2017-08-14 11:05:09Z 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.09, INFO);
59 super("ApacheXMLDSig", 2.010, INFO);
6060
6161 final Map<Object, Object> map = new HashMap<Object, Object>();
6262 map.put("XMLSignatureFactory.DOM",
163163 new Algorithm("RSA", "SHA512withRSAandMGF1", "Signature")
164164 );
165165 algorithmsMap.put(
166 XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA3_224_MGF1,
167 new Algorithm("RSA", "SHA3-224withRSAandMGF1", "Signature")
168 );
169 algorithmsMap.put(
170 XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA3_256_MGF1,
171 new Algorithm("RSA", "SHA3-256withRSAandMGF1", "Signature")
172 );
173 algorithmsMap.put(
174 XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA3_384_MGF1,
175 new Algorithm("RSA", "SHA3-384withRSAandMGF1", "Signature")
176 );
177 algorithmsMap.put(
178 XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA3_512_MGF1,
179 new Algorithm("RSA", "SHA3-512withRSAandMGF1", "Signature")
180 );
181 algorithmsMap.put(
166182 XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA1,
167183 new Algorithm("EC", "SHA1withECDSA", "Signature")
168184 );
147147 log.debug("Create URI \"" + algorithmURI + "\" class \""
148148 + implementingClass + "\"");
149149 }
150 if (implementingClass == null) {
151 Object exArgs[] = { algorithmURI };
152 throw new XMLSignatureException("algorithms.NoSuchAlgorithmNoEx", exArgs);
153 }
150154 return implementingClass.newInstance();
151155 } catch (IllegalAccessException ex) {
152156 Object exArgs[] = { algorithmURI, ex.getMessage() };
153157 throw new XMLSignatureException(ex, "algorithms.NoSuchAlgorithm", exArgs);
154 } catch (InstantiationException ex) {
158 } catch (InstantiationException ex) {
155159 Object exArgs[] = { algorithmURI, ex.getMessage() };
156160 throw new XMLSignatureException(ex, "algorithms.NoSuchAlgorithm", exArgs);
157 } catch (NullPointerException ex) {
161 } catch (NullPointerException ex) {
158162 Object exArgs[] = { algorithmURI, ex.getMessage() };
159163 throw new XMLSignatureException(ex, "algorithms.NoSuchAlgorithm", exArgs);
160164 }
430434 XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA512_MGF1, SignatureBaseRSA.SignatureRSASHA512MGF1.class
431435 );
432436 algorithmHash.put(
437 XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA3_224_MGF1, SignatureBaseRSA.SignatureRSASHA3_224MGF1.class
438 );
439 algorithmHash.put(
440 XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA3_256_MGF1, SignatureBaseRSA.SignatureRSASHA3_256MGF1.class
441 );
442 algorithmHash.put(
443 XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA3_384_MGF1, SignatureBaseRSA.SignatureRSASHA3_384MGF1.class
444 );
445 algorithmHash.put(
446 XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA3_512_MGF1, SignatureBaseRSA.SignatureRSASHA3_512MGF1.class
447 );
448 algorithmHash.put(
433449 XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA1, SignatureECDSA.SignatureECDSASHA1.class
434450 );
435451 algorithmHash.put(
453453 return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA512_MGF1;
454454 }
455455 }
456
457 /**
458 * Class SignatureRSA3_SHA224MGF1
459 */
460 public static class SignatureRSASHA3_224MGF1 extends SignatureBaseRSA {
461
462 /**
463 * Constructor SignatureRSASHA3_224MGF1
464 *
465 * @throws XMLSignatureException
466 */
467 public SignatureRSASHA3_224MGF1() throws XMLSignatureException {
468 super();
469 }
470
471 /** {@inheritDoc} */
472 public String engineGetURI() {
473 return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA3_224_MGF1;
474 }
475 }
476
477 /**
478 * Class SignatureRSA3_SHA256MGF1
479 */
480 public static class SignatureRSASHA3_256MGF1 extends SignatureBaseRSA {
481
482 /**
483 * Constructor SignatureRSASHA3_256MGF1
484 *
485 * @throws XMLSignatureException
486 */
487 public SignatureRSASHA3_256MGF1() throws XMLSignatureException {
488 super();
489 }
490
491 /** {@inheritDoc} */
492 public String engineGetURI() {
493 return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA3_256_MGF1;
494 }
495 }
496
497 /**
498 * Class SignatureRSA3_SHA384MGF1
499 */
500 public static class SignatureRSASHA3_384MGF1 extends SignatureBaseRSA {
501
502 /**
503 * Constructor SignatureRSASHA3_384MGF1
504 *
505 * @throws XMLSignatureException
506 */
507 public SignatureRSASHA3_384MGF1() throws XMLSignatureException {
508 super();
509 }
510
511 /** {@inheritDoc} */
512 public String engineGetURI() {
513 return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA3_384_MGF1;
514 }
515 }
516
517 /**
518 * Class SignatureRSASHA3_512MGF1
519 */
520 public static class SignatureRSASHA3_512MGF1 extends SignatureBaseRSA {
521
522 /**
523 * Constructor SignatureRSASHA3_512MGF1
524 *
525 * @throws XMLSignatureException
526 */
527 public SignatureRSASHA3_512MGF1() throws XMLSignatureException {
528 super();
529 }
530
531 /** {@inheritDoc} */
532 public String engineGetURI() {
533 return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA3_512_MGF1;
534 }
535 }
456536 }
107107 JAVACLASS="org.apache.xml.security.algorithms.implementations.SignatureBaseRSA$SignatureRSASHA384MGF1" />
108108 <SignatureAlgorithm URI="http://www.w3.org/2007/05/xmldsig-more#sha512-rsa-MGF1"
109109 JAVACLASS="org.apache.xml.security.algorithms.implementations.SignatureBaseRSA$SignatureRSASHA512MGF1" />
110
111 <SignatureAlgorithm URI="http://www.w3.org/2007/05/xmldsig-more#sha3-224-rsa-MGF1"
112 JAVACLASS="org.apache.xml.security.algorithms.implementations.SignatureBaseRSA$SignatureRSASHA3_224MGF1" />
113 <SignatureAlgorithm URI="http://www.w3.org/2007/05/xmldsig-more#sha3-256-rsa-MGF1"
114 JAVACLASS="org.apache.xml.security.algorithms.implementations.SignatureBaseRSA$SignatureRSASHA3_256MGF1" />
115 <SignatureAlgorithm URI="http://www.w3.org/2007/05/xmldsig-more#sha3-384-rsa-MGF1"
116 JAVACLASS="org.apache.xml.security.algorithms.implementations.SignatureBaseRSA$SignatureRSASHA3_384MGF1" />
117 <SignatureAlgorithm URI="http://www.w3.org/2007/05/xmldsig-more#sha3-512-rsa-MGF1"
118 JAVACLASS="org.apache.xml.security.algorithms.implementations.SignatureBaseRSA$SignatureRSASHA3_512MGF1" />
110119
111120 <SignatureAlgorithm URI="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha1"
112121 JAVACLASS="org.apache.xml.security.algorithms.implementations.SignatureECDSA$SignatureECDSASHA1" />
2727 algorithms.CannotUseSecureRandomOnMAC = SecureRandom kann nicht f\u00fcr MAC's angewandt werden.
2828 algorithms.HMACOutputLengthMin = HMACOutputLength darf nicht kleiner als {0} sein
2929 algorithms.HMACOutputLengthOnlyForHMAC = Die HMACOutputLength kann nur bei HMAC integrit\u00e4ts Algorithmen angegeben werden
30 algorithms.NoSuchAlgorithm = Der Algorithmus {0} ist nicht verf\u00fcgbar.
3031 algorithms.NoSuchAlgorithm = Der Algorithmus {0} ist nicht verf\u00fcgbar. Original Nachricht war\: {1}
3132 algorithms.NoSuchMap = Algorithmus URI "{0}" konnte auf keinen JCE Algorithmus gemappt werden
3233 algorithms.NoSuchProvider = Der angegebene Provider {0} existiert nicht. Original Nachricht war\: {1}
2727 algorithms.CannotUseSecureRandomOnMAC = Sorry, but you cannot use a SecureRandom object for creating MACs.
2828 algorithms.HMACOutputLengthMin = HMACOutputLength must not be less than {0}
2929 algorithms.HMACOutputLengthOnlyForHMAC = A HMACOutputLength can only be specified for HMAC integrity algorithms
30 algorithms.NoSuchAlgorithmNoEx = The requested algorithm {0} does not exist.
3031 algorithms.NoSuchAlgorithm = The requested algorithm {0} does not exist. Original Message was: {1}
3132 algorithms.NoSuchMap = The algorithm URI "{0}" could not be mapped to a JCE algorithm
3233 algorithms.NoSuchProvider = The specified Provider {0} does not exist. Original Message was: {1}
135135 public static final String ALGO_ID_SIGNATURE_RSA_SHA512_MGF1 =
136136 Constants.XML_DSIG_NS_MORE_07_05 + "sha512-rsa-MGF1";
137137
138 /** Signature - Optional RSAwithSHA3_224andMGF1 */
139 public static final String ALGO_ID_SIGNATURE_RSA_SHA3_224_MGF1 =
140 Constants.XML_DSIG_NS_MORE_07_05 + "sha3-224-rsa-MGF1";
141
142 /** Signature - Optional RSAwithSHA3_256andMGF1 */
143 public static final String ALGO_ID_SIGNATURE_RSA_SHA3_256_MGF1 =
144 Constants.XML_DSIG_NS_MORE_07_05 + "sha3-256-rsa-MGF1";
145
146 /** Signature - Optional RSAwithSHA3_384andMGF1 */
147 public static final String ALGO_ID_SIGNATURE_RSA_SHA3_384_MGF1 =
148 Constants.XML_DSIG_NS_MORE_07_05 + "sha3-384-rsa-MGF1";
149
150 /** Signature - Optional RSAwithSHA3_512andMGF1 */
151 public static final String ALGO_ID_SIGNATURE_RSA_SHA3_512_MGF1 =
152 Constants.XML_DSIG_NS_MORE_07_05 + "sha3-512-rsa-MGF1";
153
138154 /** HMAC - NOT Recommended HMAC-MD5 */
139155 public static final String ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5 =
140156 Constants.MoreAlgorithmsSpecNS + "hmac-md5";
3131 * This class is subject to change in the future.
3232 *
3333 * @author $Author: coheigea $
34 * @version $Revision: 1779473 $ $Date: 2017-01-19 15:54:13 +0100 (Thu, 19 Jan 2017) $
34 * @version $Revision: 1817216 $ $Date: 2017-12-05 17:54:49 +0100 (Tue, 05 Dec 2017) $
3535 */
3636 public class XMLSecurityProperties {
3737
7676
7777 private boolean signatureGenerateIds = true;
7878 private boolean signatureIncludeDigestTransform = true;
79
79
80 private QName signaturePositionQName;
81 private boolean signaturePositionStart = false;
82
8083 public XMLSecurityProperties() {
8184 }
8285
113116 this.keyNameMap.putAll(xmlSecurityProperties.keyNameMap);
114117 this.signatureGenerateIds = xmlSecurityProperties.signatureGenerateIds;
115118 this.signatureIncludeDigestTransform = xmlSecurityProperties.signatureIncludeDigestTransform;
119 this.signaturePositionQName = xmlSecurityProperties.signaturePositionQName;
120 this.signaturePositionStart = xmlSecurityProperties.signaturePositionStart;
121 }
122
123 public boolean isSignaturePositionStart() {
124 return signaturePositionStart;
125 }
126
127 public void setSignaturePositionStart(boolean signaturePositionStart) {
128 this.signaturePositionStart = signaturePositionStart;
116129 }
117130
118131 public SecurityTokenConstants.KeyIdentifier getSignatureKeyIdentifier() {
494507 public void setSignatureIncludeDigestTransform(boolean signatureIncludeDigestTransform) {
495508 this.signatureIncludeDigestTransform = signatureIncludeDigestTransform;
496509 }
510
511 public QName getSignaturePositionQName() {
512 return signaturePositionQName;
513 }
514
515 public void setSignaturePositionQName(QName signaturePositionQName) {
516 this.signaturePositionQName = signaturePositionQName;
517 }
497518 }
2222 import java.util.Deque;
2323 import java.util.List;
2424
25 import javax.xml.namespace.QName;
2526 import javax.xml.stream.XMLStreamException;
2627
2728 import org.apache.xml.security.exceptions.XMLSecurityException;
7778 OutputProcessorChain outputProcessorChain, Deque<XMLSecEvent> xmlSecEventDeque)
7879 throws XMLStreamException, XMLSecurityException {
7980
80 // @see SANTUARIO-405
81 // Enhances SANTUARIO-324
82 // Output the signature at a specific position.
83 // By default, this is just after the root element
84 int signaturePosition = getSecurityProperties().getSignaturePosition();
85 if (signaturePosition < 0) {
86 signaturePosition = 0;
87 }
88
8981 // forward to the root element and output it
9082 XMLSecEvent xmlSecEvent = xmlSecEventDeque.pop();
9183 while (!xmlSecEvent.isStartElement()) {
9890
9991 // search the specified position
10092 int depth = 0;
101 int position = 0;
102 while (position != signaturePosition) {
103 xmlSecEvent = xmlSecEventDeque.pop();
104
105 if (xmlSecEvent.isStartElement()) {
106 depth++;
107 } else if (xmlSecEvent.isEndElement()) {
108 depth--;
109 if (depth == 0) {
110 position++;
111 } else if (depth < 0) {
112 // root-end-element reached
113 xmlSecEventDeque.push(xmlSecEvent);
114 break;
115 }
116 }
117
118 outputProcessorChain.reset();
119 outputProcessorChain.processEvent(xmlSecEvent);
93 QName signaturePositionQName = getSecurityProperties().getSignaturePositionQName();
94 boolean start = getSecurityProperties().isSignaturePositionStart();
95 if (signaturePositionQName != null) {
96 while (!xmlSecEventDeque.isEmpty()
97 && !(start && xmlSecEvent.isStartElement() && xmlSecEvent.asStartElement().getName().equals(signaturePositionQName)
98 || !start && xmlSecEvent.isEndElement() && xmlSecEvent.asEndElement().getName().equals(signaturePositionQName))) {
99 xmlSecEvent = xmlSecEventDeque.pop();
100
101 if (xmlSecEvent.isStartElement()) {
102 depth++;
103 } else if (xmlSecEvent.isEndElement()) {
104 depth--;
105 if (depth < 0) {
106 // root-end-element reached
107 xmlSecEventDeque.push(xmlSecEvent);
108 break;
109 }
110 }
111
112 outputProcessorChain.reset();
113 outputProcessorChain.processEvent(xmlSecEvent);
114 }
115 } else {
116 // @see SANTUARIO-405
117 // Enhances SANTUARIO-324
118 // Output the signature at a specific position.
119 // By default, this is just after the root element
120 int signaturePosition = getSecurityProperties().getSignaturePosition();
121 if (signaturePosition < 0) {
122 signaturePosition = 0;
123 }
124 int position = 0;
125 while (position != signaturePosition) {
126 xmlSecEvent = xmlSecEventDeque.pop();
127
128 if (xmlSecEvent.isStartElement()) {
129 depth++;
130 } else if (xmlSecEvent.isEndElement()) {
131 depth--;
132 if (depth == 0) {
133 position++;
134 } else if (depth < 0) {
135 // root-end-element reached
136 xmlSecEventDeque.push(xmlSecEvent);
137 break;
138 }
139 }
140
141 outputProcessorChain.reset();
142 outputProcessorChain.processEvent(xmlSecEvent);
143 }
120144 }
121145
122146 //...then call super to append the signature and flush the rest
5050 */
5151 public class HMACSignatureAlgorithmTest extends org.junit.Assert {
5252
53 private static boolean bcInstalled;
5354 private KeySelector sks;
5455 private CanonicalizationMethod withoutComments;
5556 private DigestMethod sha1;
5657 private SignatureMethod hmacSha1, hmacSha224, hmacSha256, hmacSha384, hmacSha512, ripemd160;
5758 private XMLSignatureFactory fac;
5859 private DocumentBuilder db;
59 private boolean bcInstalled;
6060
6161 static {
6262 Security.insertProviderAt
6363 (new org.apache.jcp.xml.dsig.internal.dom.XMLDSigRI(), 1);
6464 }
6565
66 public HMACSignatureAlgorithmTest() throws Exception {
66 @org.junit.BeforeClass
67 public static void setup() throws Exception {
6768 //
6869 // If the BouncyCastle provider is not installed, then try to load it
6970 // via reflection.
8283 bcInstalled = true;
8384 }
8485 }
86 }
87
88 public HMACSignatureAlgorithmTest() throws Exception {
8589
8690 db = XMLUtils.createDocumentBuilder(false);
8791 // create common objects
4646 import javax.xml.parsers.DocumentBuilder;
4747
4848 import org.apache.xml.security.utils.XMLUtils;
49 import org.junit.BeforeClass;
4950 import org.w3c.dom.Document;
5051 import org.w3c.dom.Element;
5152 import org.w3c.dom.Text;
6667 private KeyPair rsaKeyPair, ecKeyPair;
6768 private KeyInfo rsaki, ecki;
6869 private boolean ecAlgParamsSupport = true;
69 private boolean bcInstalled;
70 private static boolean bcInstalled;
7071
7172 static {
7273 Security.insertProviderAt
7374 (new org.apache.jcp.xml.dsig.internal.dom.XMLDSigRI(), 1);
7475 }
7576
76 public PKSignatureAlgorithmTest() throws Exception {
77 @BeforeClass
78 public static void setup() throws Exception {
7779 //
7880 // If the BouncyCastle provider is not installed, then try to load it
7981 // via reflection.
9294 bcInstalled = true;
9395 }
9496 }
97 }
98
99 public PKSignatureAlgorithmTest() throws Exception {
95100
96101 // check if EC AlgorithmParameters is supported - this is needed
97102 // for marshalling ECKeyValue elements
3232 */
3333 public class DigestAlgorithmTest extends org.junit.Assert {
3434
35 private static boolean bcInstalled;
36
3537 static {
3638 org.apache.xml.security.Init.init();
3739 }
5254 if (cons != null) {
5355 Provider provider = (Provider)cons.newInstance();
5456 Security.insertProviderAt(provider, 2);
57 bcInstalled = true;
5558 }
5659 }
5760 }
171174
172175 @org.junit.Test
173176 public void testRIPEMD160() throws Exception {
174 // This only works with BouncyCastle
175 if (Security.getProvider("BC") == null) {
176 return;
177 }
177 org.junit.Assume.assumeTrue(bcInstalled);
178178 Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
179179
180180 MessageDigestAlgorithm digestAlgorithm =
193193
194194 @org.junit.Test
195195 public void testWhirlpool() throws Exception {
196 // This only works with BouncyCastle
197 if (Security.getProvider("BC") == null) {
198 return;
199 }
196 org.junit.Assume.assumeTrue(bcInstalled);
200197 Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
201198
202199 MessageDigestAlgorithm digestAlgorithm =
215212
216213 @org.junit.Test
217214 public void testSHA3_224() throws Exception {
218 // This only works with BouncyCastle
219 if (Security.getProvider("BC") == null) {
220 return;
221 }
215 org.junit.Assume.assumeTrue(bcInstalled);
222216 Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
223217
224218 MessageDigestAlgorithm digestAlgorithm =
237231
238232 @org.junit.Test
239233 public void testSHA3_256() throws Exception {
240 // This only works with BouncyCastle
241 if (Security.getProvider("BC") == null) {
242 return;
243 }
234 org.junit.Assume.assumeTrue(bcInstalled);
244235 Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
245236
246237 MessageDigestAlgorithm digestAlgorithm =
259250
260251 @org.junit.Test
261252 public void testSHA3_384() throws Exception {
262 // This only works with BouncyCastle
263 if (Security.getProvider("BC") == null) {
264 return;
265 }
253 org.junit.Assume.assumeTrue(bcInstalled);
266254 Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
267255
268256 MessageDigestAlgorithm digestAlgorithm =
281269
282270 @org.junit.Test
283271 public void testSHA3_512() throws Exception {
284 // This only works with BouncyCastle
285 if (Security.getProvider("BC") == null) {
286 return;
287 }
272 org.junit.Assume.assumeTrue(bcInstalled);
288273 Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
289274
290275 MessageDigestAlgorithm digestAlgorithm =
3838 import org.apache.xml.security.transforms.Transforms;
3939 import org.apache.xml.security.utils.XMLUtils;
4040 import org.junit.Assert;
41 import org.junit.BeforeClass;
4142 import org.w3c.dom.Document;
4243 import org.w3c.dom.Element;
4344 import org.w3c.dom.NodeList;
5152 org.apache.xml.security.Init.init();
5253 }
5354
54 private boolean bcInstalled;
55
56 public HMACSignatureAlgorithmTest() throws Exception {
55 private static boolean bcInstalled;
56
57 @BeforeClass
58 public static void setup() throws Exception {
5759 //
5860 // If the BouncyCastle provider is not installed, then try to load it
5961 // via reflection.
4242 import org.apache.xml.security.test.dom.DSNamespaceContext;
4343 import org.apache.xml.security.utils.XMLUtils;
4444 import org.junit.Assert;
45 import org.junit.BeforeClass;
4546 import org.w3c.dom.Document;
4647 import org.w3c.dom.Element;
4748 import org.w3c.dom.NodeList;
5152 */
5253 public class KeyWrapEncryptionAlgorithmTest extends Assert {
5354
54 private KeyPair rsaKeyPair;
55 private boolean bcInstalled;
55 private static KeyPair rsaKeyPair;
56 private static boolean bcInstalled;
5657
5758 static {
5859 org.apache.xml.security.Init.init();
5960 }
6061
61 public KeyWrapEncryptionAlgorithmTest() throws Exception {
62 @BeforeClass
63 public static void setup() throws Exception {
6264 //
6365 // If the BouncyCastle provider is not installed, then try to load it
6466 // via reflection.
3838 import org.apache.xml.security.transforms.Transforms;
3939 import org.apache.xml.security.utils.XMLUtils;
4040 import org.junit.Assert;
41 import org.junit.BeforeClass;
4142 import org.w3c.dom.Document;
4243 import org.w3c.dom.Element;
4344 import org.w3c.dom.NodeList;
4748 */
4849 public class PKSignatureAlgorithmTest extends Assert {
4950
50 private KeyPair rsaKeyPair, ecKeyPair;
51 private boolean bcInstalled;
51 private static KeyPair rsaKeyPair, ecKeyPair;
52 private static boolean bcInstalled;
5253
5354 static {
5455 org.apache.xml.security.Init.init();
5556 }
5657
57 public PKSignatureAlgorithmTest() throws Exception {
58 @BeforeClass
59 public static void setup() throws Exception {
5860 //
5961 // If the BouncyCastle provider is not installed, then try to load it
6062 // via reflection.
309311 }
310312
311313 @org.junit.Test
314 public void testRSA_SHA3_224_MGF1() throws Exception {
315 org.junit.Assume.assumeTrue(bcInstalled);
316
317 // Read in plaintext document
318 InputStream sourceDocument =
319 this.getClass().getClassLoader().getResourceAsStream(
320 "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
321 DocumentBuilder builder = XMLUtils.createDocumentBuilder(false);
322 Document document = builder.parse(sourceDocument);
323
324 List<String> localNames = new ArrayList<String>();
325 localNames.add("PaymentInfo");
326
327 sign(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA3_224_MGF1, document, localNames, rsaKeyPair.getPrivate());
328 // XMLUtils.outputDOM(document, System.out);
329 verify(document, rsaKeyPair.getPublic(), localNames);
330 }
331
332 @org.junit.Test
333 public void testRSA_SHA3_256_MGF1() throws Exception {
334 org.junit.Assume.assumeTrue(bcInstalled);
335
336 // Read in plaintext document
337 InputStream sourceDocument =
338 this.getClass().getClassLoader().getResourceAsStream(
339 "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
340 DocumentBuilder builder = XMLUtils.createDocumentBuilder(false);
341 Document document = builder.parse(sourceDocument);
342
343 List<String> localNames = new ArrayList<String>();
344 localNames.add("PaymentInfo");
345
346 sign(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA3_256_MGF1, document, localNames, rsaKeyPair.getPrivate());
347 // XMLUtils.outputDOM(document, System.out);
348 verify(document, rsaKeyPair.getPublic(), localNames);
349 }
350
351 @org.junit.Test
352 public void testRSA_SHA3_384_MGF1() throws Exception {
353 org.junit.Assume.assumeTrue(bcInstalled);
354
355 // Read in plaintext document
356 InputStream sourceDocument =
357 this.getClass().getClassLoader().getResourceAsStream(
358 "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
359 DocumentBuilder builder = XMLUtils.createDocumentBuilder(false);
360 Document document = builder.parse(sourceDocument);
361
362 List<String> localNames = new ArrayList<String>();
363 localNames.add("PaymentInfo");
364
365 sign(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA3_384_MGF1, document, localNames, rsaKeyPair.getPrivate());
366 // XMLUtils.outputDOM(document, System.out);
367 verify(document, rsaKeyPair.getPublic(), localNames);
368 }
369
370 @org.junit.Test
371 public void testRSA_SHA3_512_MGF1() throws Exception {
372 org.junit.Assume.assumeTrue(bcInstalled);
373
374 // Read in plaintext document
375 InputStream sourceDocument =
376 this.getClass().getClassLoader().getResourceAsStream(
377 "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
378 DocumentBuilder builder = XMLUtils.createDocumentBuilder(false);
379 Document document = builder.parse(sourceDocument);
380
381 List<String> localNames = new ArrayList<String>();
382 localNames.add("PaymentInfo");
383
384 sign(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA3_512_MGF1, document, localNames, rsaKeyPair.getPrivate());
385 // XMLUtils.outputDOM(document, System.out);
386 verify(document, rsaKeyPair.getPublic(), localNames);
387 }
388
389 @org.junit.Test
312390 public void testECDSA_SHA1() throws Exception {
313391 // Read in plaintext document
314392 InputStream sourceDocument =
3737 import org.apache.xml.security.test.dom.DSNamespaceContext;
3838 import org.apache.xml.security.utils.XMLUtils;
3939 import org.junit.Assert;
40 import org.junit.BeforeClass;
4041 import org.w3c.dom.Document;
4142 import org.w3c.dom.Element;
4243 import org.w3c.dom.NodeList;
4647 */
4748 public class SymmetricEncryptionAlgorithmTest extends Assert {
4849
49 private boolean bcInstalled;
50 private static boolean bcInstalled;
5051
5152 static {
5253 org.apache.xml.security.Init.init();
5354 }
5455
55 public SymmetricEncryptionAlgorithmTest() throws Exception {
56 @BeforeClass
57 public static void setup() throws Exception {
5658 //
5759 // If the BouncyCastle provider is not installed, then try to load it
5860 // via reflection.
6264 try {
6365 Class<?> c = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
6466 cons = c.getConstructor(new Class[] {});
65 } catch (Exception e) { //NOPMD
67 } catch (Exception e) {
6668 //ignore
6769 }
6870 if (cons != null) {
6971 Provider provider = (Provider)cons.newInstance();
7072 Security.insertProviderAt(provider, 2);
73 bcInstalled = true;
7174 }
7275 }
7376 }
4949 import org.apache.xml.security.test.stax.utils.XmlReaderToWriter;
5050 import org.apache.xml.security.utils.XMLUtils;
5151 import org.junit.Assert;
52 import org.junit.Before;
52 import org.junit.BeforeClass;
5353 import org.junit.Test;
5454 import org.w3c.dom.Document;
5555 import org.w3c.dom.Element;
6060 */
6161 public class KeyWrapEncryptionCreationTest extends Assert {
6262
63 private static KeyPair rsaKeyPair;
64 private static boolean bcInstalled;
6365 private XMLInputFactory xmlInputFactory;
64 private KeyPair rsaKeyPair;
65 private boolean bcInstalled;
66
67 @Before
68 public void setUp() throws Exception {
69 org.apache.xml.security.Init.init();
70
71 xmlInputFactory = XMLInputFactory.newInstance();
72 xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
73
66
67 @BeforeClass
68 public static void setup() throws Exception {
7469 //
7570 // If the BouncyCastle provider is not installed, then try to load it
7671 // via reflection.
8075 try {
8176 Class<?> c = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
8277 cons = c.getConstructor(new Class[] {});
83 } catch (Exception e) { //NOPMD
78 } catch (Exception e) {
8479 //ignore
8580 }
8681 if (cons != null) {
9388 rsaKeyPair = KeyPairGenerator.getInstance("RSA").genKeyPair();
9489 }
9590
91 public KeyWrapEncryptionCreationTest() throws Exception {
92 org.apache.xml.security.Init.init();
93
94 xmlInputFactory = XMLInputFactory.newInstance();
95 xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
96 }
97
9698 @org.junit.AfterClass
9799 public static void cleanup() throws Exception {
98100 Security.removeProvider("BC");
5555 import org.apache.xml.security.test.stax.utils.XMLSecEventAllocator;
5656 import org.apache.xml.security.utils.XMLUtils;
5757 import org.junit.Assert;
58 import org.junit.Before;
58 import org.junit.BeforeClass;
5959 import org.junit.Test;
6060 import org.w3c.dom.Document;
6161 import org.w3c.dom.Element;
6666 */
6767 public class KeyWrapEncryptionVerificationTest extends Assert {
6868
69 private boolean bcInstalled;
69 private static boolean bcInstalled;
70 private static KeyPair rsaKeyPair;
7071 private XMLInputFactory xmlInputFactory;
7172 private TransformerFactory transformerFactory = TransformerFactory.newInstance();
72 private KeyPair rsaKeyPair;
73
74 @Before
75 public void setUp() throws Exception {
76 org.apache.xml.security.Init.init();
77
78 xmlInputFactory = XMLInputFactory.newInstance();
79 xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
80
73
74 @BeforeClass
75 public static void setup() throws Exception {
8176 //
8277 // If the BouncyCastle provider is not installed, then try to load it
8378 // via reflection.
8782 try {
8883 Class<?> c = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
8984 cons = c.getConstructor(new Class[] {});
90 } catch (Exception e) { //NOPMD
85 } catch (Exception e) {
9186 //ignore
9287 }
9388 if (cons != null) {
9893 }
9994
10095 rsaKeyPair = KeyPairGenerator.getInstance("RSA").genKeyPair();
96 }
97
98 public KeyWrapEncryptionVerificationTest() throws Exception {
99 org.apache.xml.security.Init.init();
100
101 xmlInputFactory = XMLInputFactory.newInstance();
102 xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
101103 }
102104
103105 @org.junit.AfterClass
4444 import org.apache.xml.security.test.stax.utils.XmlReaderToWriter;
4545 import org.apache.xml.security.utils.XMLUtils;
4646 import org.junit.Assert;
47 import org.junit.Before;
47 import org.junit.BeforeClass;
4848 import org.junit.Test;
4949 import org.w3c.dom.Document;
5050 import org.w3c.dom.Element;
5555 */
5656 public class SymmetricEncryptionCreationTest extends Assert {
5757
58 private static boolean bcInstalled;
5859 private XMLInputFactory xmlInputFactory;
59 private boolean bcInstalled;
60
61 @Before
62 public void setUp() throws Exception {
63 org.apache.xml.security.Init.init();
64
65 xmlInputFactory = XMLInputFactory.newInstance();
66 xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
67
60
61 @BeforeClass
62 public static void setup() throws Exception {
6863 //
6964 // If the BouncyCastle provider is not installed, then try to load it
7065 // via reflection.
7469 try {
7570 Class<?> c = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
7671 cons = c.getConstructor(new Class[] {});
77 } catch (Exception e) { //NOPMD
72 } catch (Exception e) {
7873 //ignore
7974 }
8075 if (cons != null) {
8378 bcInstalled = true;
8479 }
8580 }
81 }
82
83 public SymmetricEncryptionCreationTest() throws Exception {
84 org.apache.xml.security.Init.init();
85
86 xmlInputFactory = XMLInputFactory.newInstance();
87 xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
8688 }
8789
8890 @org.junit.AfterClass
5454 import org.apache.xml.security.test.stax.utils.XMLSecEventAllocator;
5555 import org.apache.xml.security.utils.XMLUtils;
5656 import org.junit.Assert;
57 import org.junit.Before;
57 import org.junit.BeforeClass;
5858 import org.junit.Test;
5959 import org.w3c.dom.Document;
6060 import org.w3c.dom.Element;
6565 */
6666 public class SymmetricEncryptionVerificationTest extends Assert {
6767
68 private boolean bcInstalled;
68 private static boolean bcInstalled;
6969 private XMLInputFactory xmlInputFactory;
7070 private TransformerFactory transformerFactory = TransformerFactory.newInstance();
7171
72 @Before
73 public void setUp() throws Exception {
74 org.apache.xml.security.Init.init();
75
76 xmlInputFactory = XMLInputFactory.newInstance();
77 xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
78
72 @BeforeClass
73 public static void setup() throws Exception {
7974 //
8075 // If the BouncyCastle provider is not installed, then try to load it
8176 // via reflection.
8580 try {
8681 Class<?> c = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
8782 cons = c.getConstructor(new Class[] {});
88 } catch (Exception e) { //NOPMD
83 } catch (Exception e) {
8984 //ignore
9085 }
9186 if (cons != null) {
9489 bcInstalled = true;
9590 }
9691 }
92 }
93
94 public SymmetricEncryptionVerificationTest() throws Exception {
95 org.apache.xml.security.Init.init();
96
97 xmlInputFactory = XMLInputFactory.newInstance();
98 xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
9799 }
98100
99101 @org.junit.AfterClass
4040 import org.apache.xml.security.stax.securityToken.SecurityTokenConstants;
4141 import org.apache.xml.security.test.stax.utils.XmlReaderToWriter;
4242 import org.apache.xml.security.utils.XMLUtils;
43 import org.junit.BeforeClass;
4344 import org.junit.Test;
4445 import org.w3c.dom.Document;
4546
4849 */
4950 public class PKSignatureCreationTest extends AbstractSignatureCreationTest {
5051
51 private boolean bcInstalled;
52 private KeyPair rsaKeyPair, ecKeyPair;
53
54 public PKSignatureCreationTest() throws Exception {
52 private static boolean bcInstalled;
53 private static KeyPair rsaKeyPair, ecKeyPair;
54
55 @BeforeClass
56 public static void setup() throws Exception {
5557 //
5658 // If the BouncyCastle provider is not installed, then try to load it
5759 // via reflection.
4242 import org.apache.xml.security.test.stax.utils.StAX2DOM;
4343 import org.apache.xml.security.test.stax.utils.XMLSecEventAllocator;
4444 import org.apache.xml.security.utils.XMLUtils;
45 import org.junit.Before;
45 import org.junit.BeforeClass;
4646 import org.junit.Test;
4747 import org.w3c.dom.Document;
4848
5050 * A set of test-cases for Signature verification with various PublicKey algorithms
5151 */
5252 public class PKSignatureVerificationTest extends AbstractSignatureVerificationTest {
53
54 private boolean bcInstalled;
53 private static KeyPair rsaKeyPair, ecKeyPair;
54 private static boolean bcInstalled;
5555 private XMLInputFactory xmlInputFactory;
5656 private TransformerFactory transformerFactory = TransformerFactory.newInstance();
57 private KeyPair rsaKeyPair, ecKeyPair;
58
59 @Before
60 public void setUp() throws Exception {
61 Init.init(PKSignatureVerificationTest.class.getClassLoader().getResource("security-config.xml").toURI(),
62 this.getClass());
63 org.apache.xml.security.Init.init();
64
65 xmlInputFactory = XMLInputFactory.newInstance();
66 xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
67
57
58 @BeforeClass
59 public static void setup() throws Exception {
6860 //
6961 // If the BouncyCastle provider is not installed, then try to load it
7062 // via reflection.
7466 try {
7567 Class<?> c = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
7668 cons = c.getConstructor(new Class[] {});
77 } catch (Exception e) { //NOPMD
69 } catch (Exception e) {
7870 //ignore
7971 }
8072 if (cons != null) {
9183 ecKeyPair = KeyPairGenerator.getInstance("EC").genKeyPair();
9284 }
9385
86 public PKSignatureVerificationTest() throws Exception {
87 Init.init(PKSignatureVerificationTest.class.getClassLoader().getResource("security-config.xml").toURI(),
88 this.getClass());
89 org.apache.xml.security.Init.init();
90
91 xmlInputFactory = XMLInputFactory.newInstance();
92 xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
93 }
94
9495 @org.junit.AfterClass
9596 public static void cleanup() throws Exception {
9697 Security.removeProvider("BC");
288288 signAtSpecificPosition(999);
289289 }
290290
291 @Test
292 public void testSignAtSpecificPositionViaQName() throws Exception {
293 signAtSpecificPosition(0, new QName("urn:example:po", "PurchaseOrder"), true);
294 signAtSpecificPosition(0, new QName("urn:example:po", "Items"), true);
295 signAtSpecificPosition(0, new QName("urn:example:po", "Items"), false);
296 signAtSpecificPosition(0, new QName("urn:example:po", "ShippingAddress"), true);
297 signAtSpecificPosition(0, new QName("urn:example:po", "ShippingAddress"), false);
298 }
299
291300 private void signAtSpecificPosition(int position) throws Exception {
301 signAtSpecificPosition(position, null, false);
302 }
303
304 private void signAtSpecificPosition(int position, QName positionQName, boolean start) throws Exception {
292305 // Set up the Configuration
293306 XMLSecurityProperties properties = new XMLSecurityProperties();
294307 List<XMLSecurityConstants.Action> actions = new ArrayList<XMLSecurityConstants.Action>();
297310
298311 // Specify the signature position
299312 properties.setSignaturePosition(position);
313 properties.setSignaturePositionQName(positionQName);
314 properties.setSignaturePositionStart(start);
300315
301316 // Set the key up
302317 KeyStore keyStore = KeyStore.getInstance("jks");
340355 //find first child element:
341356 Node childNode = XMLUtils.getNextElement(document.getDocumentElement().getFirstChild());
342357
343 int expectedPosition = position < 0 ? 0 : position;
344 int curPos = 0;
345 while (curPos != expectedPosition) {
346 Node node = XMLUtils.getNextElement(childNode.getNextSibling());
347 curPos++;
348 if (node != null) {
349 childNode = node;
350 } else {
351 break;
358 if (positionQName != null) {
359 // Find the Signature node inside the desired QName
360 String localName = positionQName.getLocalPart();
361 if (!"PurchaseOrder".equals(localName)) {
362 String namespace = positionQName.getNamespaceURI();
363 while (childNode != null && !(childNode.getLocalName().equals(localName)
364 && childNode.getNamespaceURI().equals(namespace))) {
365 childNode = XMLUtils.getNextElement(childNode.getNextSibling());
366 }
367 if (start) {
368 childNode = childNode.getFirstChild();
369 } else {
370 childNode = childNode.getNextSibling();
371 }
372 }
373 } else {
374 int expectedPosition = position < 0 ? 0 : position;
375 int curPos = 0;
376 while (curPos != expectedPosition) {
377 Node node = XMLUtils.getNextElement(childNode.getNextSibling());
378 curPos++;
379 if (node != null) {
380 childNode = node;
381 } else {
382 break;
383 }
352384 }
353385 }
354386
4545 import org.apache.xml.security.test.stax.utils.XmlReaderToWriter;
4646 import org.apache.xml.security.utils.XMLUtils;
4747 import org.junit.Assert;
48 import org.junit.BeforeClass;
4849 import org.junit.Test;
4950
5051 /**
5152 * A set of test-cases for Signature creation with various digest algorithms
5253 */
5354 public class SignatureDigestCreationTest extends AbstractSignatureCreationTest {
54 private boolean bcInstalled;
55
56 public SignatureDigestCreationTest() throws Exception {
55 private static boolean bcInstalled;
56
57 @BeforeClass
58 public static void setup() throws Exception {
5759 //
5860 // If the BouncyCastle provider is not installed, then try to load it
5961 // via reflection.
6365 try {
6466 Class<?> c = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
6567 cons = c.getConstructor(new Class[] {});
66 } catch (Exception e) { //NOPMD
68 } catch (Exception e) {
6769 //ignore
6870 }
6971 if (cons != null) {
3939 import org.apache.xml.security.stax.ext.XMLSecurityProperties;
4040 import org.apache.xml.security.test.stax.utils.XmlReaderToWriter;
4141 import org.apache.xml.security.utils.XMLUtils;
42 import org.junit.BeforeClass;
4243 import org.junit.Test;
4344 import org.w3c.dom.Document;
4445
4748 */
4849 public class SignatureHMACCreationTest extends AbstractSignatureCreationTest {
4950
50 private boolean bcInstalled;
51
52 public SignatureHMACCreationTest() throws Exception {
51 private static boolean bcInstalled;
52
53 @BeforeClass
54 public static void setup() throws Exception {
5355 //
5456 // If the BouncyCastle provider is not installed, then try to load it
5557 // via reflection.
5961 try {
6062 Class<?> c = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
6163 cons = c.getConstructor(new Class[] {});
62 } catch (Exception e) { //NOPMD
64 } catch (Exception e) {
6365 //ignore
6466 }
6567 if (cons != null) {
4242 import org.apache.xml.security.test.stax.utils.StAX2DOM;
4343 import org.apache.xml.security.test.stax.utils.XMLSecEventAllocator;
4444 import org.apache.xml.security.utils.XMLUtils;
45 import org.junit.Before;
45 import org.junit.BeforeClass;
4646 import org.junit.Test;
4747 import org.w3c.dom.Document;
4848
5151 */
5252 public class SignatureHMACVerificationTest extends AbstractSignatureVerificationTest {
5353
54 private boolean bcInstalled;
54 private static boolean bcInstalled;
5555 private XMLInputFactory xmlInputFactory;
5656 private TransformerFactory transformerFactory = TransformerFactory.newInstance();
5757
58 @Before
59 public void setUp() throws Exception {
60 Init.init(SignatureHMACVerificationTest.class.getClassLoader().getResource("security-config.xml").toURI(),
61 this.getClass());
62 org.apache.xml.security.Init.init();
63
64 xmlInputFactory = XMLInputFactory.newInstance();
65 xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
66
58 @BeforeClass
59 public static void setup() throws Exception {
6760 //
6861 // If the BouncyCastle provider is not installed, then try to load it
6962 // via reflection.
7366 try {
7467 Class<?> c = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
7568 cons = c.getConstructor(new Class[] {});
76 } catch (Exception e) { //NOPMD
69 } catch (Exception e) {
7770 //ignore
7871 }
7972 if (cons != null) {
8477 }
8578 }
8679
80 public SignatureHMACVerificationTest() throws Exception {
81 Init.init(SignatureHMACVerificationTest.class.getClassLoader().getResource("security-config.xml").toURI(),
82 this.getClass());
83 org.apache.xml.security.Init.init();
84
85 xmlInputFactory = XMLInputFactory.newInstance();
86 xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
87 }
88
8789 @org.junit.AfterClass
8890 public static void cleanup() throws Exception {
8991 Security.removeProvider("BC");