You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2012/12/07 19:10:51 UTC
svn commit: r1418419 [1/2] - in
/santuario/xml-security-java/branches/1.5.x-fixes/src:
main/java/org/apache/xml/security/c14n/implementations/
main/java/org/apache/xml/security/encryption/
main/java/org/apache/xml/security/keys/content/ main/java/org/a...
Author: coheigea
Date: Fri Dec 7 18:10:49 2012
New Revision: 1418419
URL: http://svn.apache.org/viewvc?rev=1418419&view=rev
Log:
Removing tabs
Modified:
santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/c14n/implementations/CanonicalizerPhysical.java
santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/encryption/XMLCipher.java
santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/content/DEREncodedKeyValue.java
santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/content/KeyInfoReference.java
santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/content/x509/XMLX509Digest.java
santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/DEREncodedKeyValueResolver.java
santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/KeyInfoReferenceResolver.java
santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/X509DigestResolver.java
santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/utils/resolver/ResourceResolverSpi.java
santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/utils/resolver/implementations/ResolverAnonymous.java
santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/DEREncodedKeyValueTest.java
santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/KeyInfoReferenceTest.java
santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509DigestTest.java
santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/keyresolver/DEREncodedKeyValueResolverTest.java
santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/keyresolver/KeyInfoReferenceResolverTest.java
santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/keyresolver/X509DigestResolverTest.java
santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/encryption/XMLCipherTest.java
Modified: santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/c14n/implementations/CanonicalizerPhysical.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/c14n/implementations/CanonicalizerPhysical.java?rev=1418419&r1=1418418&r2=1418419&view=diff
==============================================================================
--- santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/c14n/implementations/CanonicalizerPhysical.java (original)
+++ santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/c14n/implementations/CanonicalizerPhysical.java Fri Dec 7 18:10:49 2012
@@ -49,7 +49,7 @@ import org.xml.sax.SAXException;
* as the original XML content that was encrypted.
*/
public class CanonicalizerPhysical extends CanonicalizerBase {
-
+
private final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
/**
@@ -58,7 +58,7 @@ public class CanonicalizerPhysical exten
public CanonicalizerPhysical() {
super(true);
}
-
+
/**
* Always throws a CanonicalizationException.
*
@@ -109,7 +109,7 @@ public class CanonicalizerPhysical exten
if (!element.hasAttributes()) {
return null;
}
-
+
// result will contain all the attrs declared directly on that element
final SortedSet<Attr> result = this.result;
result.clear();
@@ -117,7 +117,7 @@ public class CanonicalizerPhysical exten
if (element.hasAttributes()) {
NamedNodeMap attrs = element.getAttributes();
int attrsLength = attrs.getLength();
-
+
for (int i = 0; i < attrsLength; i++) {
Attr attribute = (Attr) attrs.item(i);
result.add(attribute);
@@ -142,15 +142,15 @@ public class CanonicalizerPhysical exten
/** $todo$ well, should we throw UnsupportedOperationException ? */
throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
}
-
+
protected void circumventBugIfNeeded(XMLSignatureInput input)
throws CanonicalizationException, ParserConfigurationException, IOException, SAXException {
- // nothing to do
+ // nothing to do
}
@Override
protected void handleParent(Element e, NameSpaceSymbTable ns) {
- // nothing to do
+ // nothing to do
}
/** @inheritDoc */
@@ -163,18 +163,18 @@ public class CanonicalizerPhysical exten
return true;
}
- @Override
- protected void outputPItoWriter(ProcessingInstruction currentPI,
- OutputStream writer, int position) throws IOException {
- // Processing Instructions before or after the document element are not treated specially
- super.outputPItoWriter(currentPI, writer, NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT);
- }
-
- @Override
- protected void outputCommentToWriter(Comment currentComment,
- OutputStream writer, int position) throws IOException {
- // Comments before or after the document element are not treated specially
- super.outputCommentToWriter(currentComment, writer, NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT);
- }
-
+ @Override
+ protected void outputPItoWriter(ProcessingInstruction currentPI,
+ OutputStream writer, int position) throws IOException {
+ // Processing Instructions before or after the document element are not treated specially
+ super.outputPItoWriter(currentPI, writer, NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT);
+ }
+
+ @Override
+ protected void outputCommentToWriter(Comment currentComment,
+ OutputStream writer, int position) throws IOException {
+ // Comments before or after the document element are not treated specially
+ super.outputCommentToWriter(currentComment, writer, NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT);
+ }
+
}
Modified: santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/encryption/XMLCipher.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/encryption/XMLCipher.java?rev=1418419&r1=1418418&r2=1418419&view=diff
==============================================================================
--- santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/encryption/XMLCipher.java (original)
+++ santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/encryption/XMLCipher.java Fri Dec 7 18:10:49 2012
@@ -633,9 +633,9 @@ public class XMLCipher {
* @param keyResolver
*/
public void registerInternalKeyResolver(KeyResolverSpi keyResolver) {
- if (internalKeyResolvers == null) {
- internalKeyResolvers = new ArrayList<KeyResolverSpi>();
- }
+ if (internalKeyResolvers == null) {
+ internalKeyResolvers = new ArrayList<KeyResolverSpi>();
+ }
internalKeyResolvers.add(keyResolver);
}
@@ -1680,10 +1680,10 @@ public class XMLCipher {
String encMethodAlgorithm = encryptedData.getEncryptionMethod().getAlgorithm();
EncryptedKeyResolver resolver = new EncryptedKeyResolver(encMethodAlgorithm, kek);
if (internalKeyResolvers != null) {
- int size = internalKeyResolvers.size();
- for (int i = 0; i < size; i++) {
- resolver.registerInternalKeyResolver(internalKeyResolvers.get(i));
- }
+ int size = internalKeyResolvers.size();
+ for (int i = 0; i < size; i++) {
+ resolver.registerInternalKeyResolver(internalKeyResolvers.get(i));
+ }
}
ki.registerInternalKeyResolver(resolver);
ki.setSecureValidation(secureValidation);
Modified: santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/content/DEREncodedKeyValue.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/content/DEREncodedKeyValue.java?rev=1418419&r1=1418418&r2=1418419&view=diff
==============================================================================
--- santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/content/DEREncodedKeyValue.java (original)
+++ santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/content/DEREncodedKeyValue.java Fri Dec 7 18:10:49 2012
@@ -36,9 +36,9 @@ import org.w3c.dom.Element;
* @author Brent Putman (putmanb@georgetown.edu)
*/
public class DEREncodedKeyValue extends Signature11ElementProxy implements KeyInfoContent {
-
- /** JCA algorithm key types supported by this implementation. */
- public static final String supportedKeyTypes[] = { "RSA", "DSA", "EC"};
+
+ /** JCA algorithm key types supported by this implementation. */
+ public static final String supportedKeyTypes[] = { "RSA", "DSA", "EC"};
/**
* Constructor DEREncodedKeyValue
@@ -63,7 +63,7 @@ public class DEREncodedKeyValue extends
this.addBase64Text(getEncodedDER(publicKey));
}
-
+
/**
* Constructor DEREncodedKeyValue
*
@@ -75,8 +75,8 @@ public class DEREncodedKeyValue extends
this.addBase64Text(encodedKey);
}
-
- /**
+
+ /**
* Sets the <code>Id</code> attribute
*
* @param Id ID
@@ -89,7 +89,7 @@ public class DEREncodedKeyValue extends
this.constructionElement.removeAttributeNS(null, Constants._ATT_ID);
}
}
-
+
/**
* Returns the <code>Id</code> attribute
*
@@ -99,11 +99,11 @@ public class DEREncodedKeyValue extends
return this.constructionElement.getAttributeNS(null, Constants._ATT_ID);
}
- /** @inheritDoc */
+ /** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_DERENCODEDKEYVALUE;
}
-
+
/**
* Method getPublicKey
*
@@ -111,26 +111,26 @@ public class DEREncodedKeyValue extends
* @throws XMLSecurityException
*/
public PublicKey getPublicKey() throws XMLSecurityException {
- byte[] encodedKey = getBytesFromTextChild();
-
- // Iterate over the supported key types until one produces a public key.
- for (String keyType : supportedKeyTypes) {
- try {
- KeyFactory keyFactory = KeyFactory.getInstance(keyType);
- X509EncodedKeySpec keySpec = new X509EncodedKeySpec(encodedKey);
- PublicKey publicKey = keyFactory.generatePublic(keySpec);
- if (publicKey != null) {
- return publicKey;
- }
- } catch (NoSuchAlgorithmException e) {
- // Do nothing, try the next type
- } catch (InvalidKeySpecException e) {
- // Do nothing, try the next type
- }
- }
- throw new XMLSecurityException("DEREncodedKeyValue.UnsupportedEncodedKey");
+ byte[] encodedKey = getBytesFromTextChild();
+
+ // Iterate over the supported key types until one produces a public key.
+ for (String keyType : supportedKeyTypes) {
+ try {
+ KeyFactory keyFactory = KeyFactory.getInstance(keyType);
+ X509EncodedKeySpec keySpec = new X509EncodedKeySpec(encodedKey);
+ PublicKey publicKey = keyFactory.generatePublic(keySpec);
+ if (publicKey != null) {
+ return publicKey;
+ }
+ } catch (NoSuchAlgorithmException e) {
+ // Do nothing, try the next type
+ } catch (InvalidKeySpecException e) {
+ // Do nothing, try the next type
+ }
+ }
+ throw new XMLSecurityException("DEREncodedKeyValue.UnsupportedEncodedKey");
}
-
+
/**
* Method getEncodedDER
*
@@ -138,17 +138,17 @@ public class DEREncodedKeyValue extends
* @throws XMLSecurityException
*/
protected byte[] getEncodedDER(PublicKey publicKey) throws XMLSecurityException {
- try {
- KeyFactory keyFactory = KeyFactory.getInstance(publicKey.getAlgorithm());
- X509EncodedKeySpec keySpec = keyFactory.getKeySpec(publicKey, X509EncodedKeySpec.class);
- return keySpec.getEncoded();
- } catch (NoSuchAlgorithmException e) {
- Object exArgs[] = { publicKey.getAlgorithm(), publicKey.getFormat(), publicKey.getClass().getName() };
- throw new XMLSecurityException("DEREncodedKeyValue.UnsupportedPublicKey", exArgs, e);
- } catch (InvalidKeySpecException e) {
- Object exArgs[] = { publicKey.getAlgorithm(), publicKey.getFormat(), publicKey.getClass().getName() };
- throw new XMLSecurityException("DEREncodedKeyValue.UnsupportedPublicKey", exArgs, e);
- }
- }
+ try {
+ KeyFactory keyFactory = KeyFactory.getInstance(publicKey.getAlgorithm());
+ X509EncodedKeySpec keySpec = keyFactory.getKeySpec(publicKey, X509EncodedKeySpec.class);
+ return keySpec.getEncoded();
+ } catch (NoSuchAlgorithmException e) {
+ Object exArgs[] = { publicKey.getAlgorithm(), publicKey.getFormat(), publicKey.getClass().getName() };
+ throw new XMLSecurityException("DEREncodedKeyValue.UnsupportedPublicKey", exArgs, e);
+ } catch (InvalidKeySpecException e) {
+ Object exArgs[] = { publicKey.getAlgorithm(), publicKey.getFormat(), publicKey.getClass().getName() };
+ throw new XMLSecurityException("DEREncodedKeyValue.UnsupportedPublicKey", exArgs, e);
+ }
+ }
}
Modified: santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/content/KeyInfoReference.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/content/KeyInfoReference.java?rev=1418419&r1=1418418&r2=1418419&view=diff
==============================================================================
--- santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/content/KeyInfoReference.java (original)
+++ santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/content/KeyInfoReference.java Fri Dec 7 18:10:49 2012
@@ -72,8 +72,8 @@ public class KeyInfoReference extends Si
public String getURI() {
return this.getURIAttr().getNodeValue();
}
-
- /**
+
+ /**
* Sets the <code>Id</code> attribute
*
* @param Id ID
@@ -83,10 +83,10 @@ public class KeyInfoReference extends Si
this.constructionElement.setAttributeNS(null, Constants._ATT_ID, id);
this.constructionElement.setIdAttributeNS(null, Constants._ATT_ID, true);
} else {
- this.constructionElement.removeAttributeNS(null, Constants._ATT_ID);
+ this.constructionElement.removeAttributeNS(null, Constants._ATT_ID);
}
}
-
+
/**
* Returns the <code>Id</code> attribute
*
Modified: santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/content/x509/XMLX509Digest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/content/x509/XMLX509Digest.java?rev=1418419&r1=1418418&r2=1418419&view=diff
==============================================================================
--- santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/content/x509/XMLX509Digest.java (original)
+++ santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/content/x509/XMLX509Digest.java Fri Dec 7 18:10:49 2012
@@ -46,7 +46,7 @@ public class XMLX509Digest extends Signa
public XMLX509Digest(Element element, String BaseURI) throws XMLSecurityException {
super(element, BaseURI);
}
-
+
/**
* Constructor XMLX509Digest
*
@@ -73,7 +73,7 @@ public class XMLX509Digest extends Signa
this.addBase64Text(getDigestBytesFromCert(x509certificate, algorithmURI));
this.constructionElement.setAttributeNS(null, Constants._ATT_ALGORITHM, algorithmURI);
}
-
+
/**
* Method getAlgorithmAttr
*
@@ -112,20 +112,20 @@ public class XMLX509Digest extends Signa
* @throws XMLSecurityException
*/
public static byte[] getDigestBytesFromCert(X509Certificate cert, String algorithmURI) throws XMLSecurityException {
- String jcaDigestAlgorithm = JCEMapper.translateURItoJCEID(algorithmURI);
- if (jcaDigestAlgorithm == null) {
- Object exArgs[] = { algorithmURI };
- throw new XMLSecurityException("XMLX509Digest.UnknownDigestAlgorithm", exArgs);
- }
-
- try {
- MessageDigest md = MessageDigest.getInstance(jcaDigestAlgorithm);
- return md.digest(cert.getEncoded());
- } catch (Exception e) {
- Object exArgs[] = { jcaDigestAlgorithm };
- throw new XMLSecurityException("XMLX509Digest.FailedDigest", exArgs);
- }
-
+ String jcaDigestAlgorithm = JCEMapper.translateURItoJCEID(algorithmURI);
+ if (jcaDigestAlgorithm == null) {
+ Object exArgs[] = { algorithmURI };
+ throw new XMLSecurityException("XMLX509Digest.UnknownDigestAlgorithm", exArgs);
+ }
+
+ try {
+ MessageDigest md = MessageDigest.getInstance(jcaDigestAlgorithm);
+ return md.digest(cert.getEncoded());
+ } catch (Exception e) {
+ Object exArgs[] = { jcaDigestAlgorithm };
+ throw new XMLSecurityException("XMLX509Digest.FailedDigest", exArgs);
+ }
+
}
/** @inheritDoc */
Modified: santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/DEREncodedKeyValueResolver.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/DEREncodedKeyValueResolver.java?rev=1418419&r1=1418418&r2=1418419&view=diff
==============================================================================
--- santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/DEREncodedKeyValueResolver.java (original)
+++ santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/DEREncodedKeyValueResolver.java Fri Dec 7 18:10:49 2012
@@ -22,26 +22,26 @@ import org.w3c.dom.Element;
* @author Brent Putman (putmanb@georgetown.edu)
*/
public class DEREncodedKeyValueResolver extends KeyResolverSpi {
-
+
/** {@link org.apache.commons.logging} logging facility */
private static org.apache.commons.logging.Log log =
org.apache.commons.logging.LogFactory.getLog(DEREncodedKeyValueResolver.class);
- /** {@inheritDoc}. */
- public boolean engineCanResolve(Element element, String baseURI, StorageResolver storage) {
- return XMLUtils.elementIsInSignature11Space(element, Constants._TAG_DERENCODEDKEYVALUE);
- }
-
- /** {@inheritDoc}. */
- public PublicKey engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage)
- throws KeyResolverException {
-
+ /** {@inheritDoc}. */
+ public boolean engineCanResolve(Element element, String baseURI, StorageResolver storage) {
+ return XMLUtils.elementIsInSignature11Space(element, Constants._TAG_DERENCODEDKEYVALUE);
+ }
+
+ /** {@inheritDoc}. */
+ public PublicKey engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage)
+ throws KeyResolverException {
+
if (log.isDebugEnabled()) {
log.debug("Can I resolve " + element.getTagName());
}
-
+
if (!engineCanResolve(element, baseURI, storage)) {
- return null;
+ return null;
}
try {
@@ -54,26 +54,26 @@ public class DEREncodedKeyValueResolver
}
return null;
- }
+ }
+
+ /** {@inheritDoc}. */
+ public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage)
+ throws KeyResolverException {
+ return null;
+ }
+
+ /** {@inheritDoc}. */
+ public SecretKey engineLookupAndResolveSecretKey(Element element, String baseURI, StorageResolver storage)
+ throws KeyResolverException {
+ return null;
+ }
+
+ /** {@inheritDoc}. */
+ public PrivateKey engineLookupAndResolvePrivateKey(Element element, String baseURI, StorageResolver storage)
+ throws KeyResolverException {
+ return null;
+ }
+
- /** {@inheritDoc}. */
- public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage)
- throws KeyResolverException {
- return null;
- }
-
- /** {@inheritDoc}. */
- public SecretKey engineLookupAndResolveSecretKey(Element element, String baseURI, StorageResolver storage)
- throws KeyResolverException {
- return null;
- }
-
- /** {@inheritDoc}. */
- public PrivateKey engineLookupAndResolvePrivateKey(Element element, String baseURI, StorageResolver storage)
- throws KeyResolverException {
- return null;
- }
-
-
}
Modified: santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/KeyInfoReferenceResolver.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/KeyInfoReferenceResolver.java?rev=1418419&r1=1418418&r2=1418419&view=diff
==============================================================================
--- santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/KeyInfoReferenceResolver.java (original)
+++ santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/KeyInfoReferenceResolver.java Fri Dec 7 18:10:49 2012
@@ -36,33 +36,33 @@ import org.xml.sax.SAXException;
* @author Brent Putman (putmanb@georgetown.edu)
*/
public class KeyInfoReferenceResolver extends KeyResolverSpi {
-
+
/** {@link org.apache.commons.logging} logging facility */
private static org.apache.commons.logging.Log log =
org.apache.commons.logging.LogFactory.getLog(KeyInfoReferenceResolver.class);
- /** {@inheritDoc}. */
- public boolean engineCanResolve(Element element, String baseURI, StorageResolver storage) {
- return XMLUtils.elementIsInSignature11Space(element, Constants._TAG_KEYINFOREFERENCE);
- }
-
- /** {@inheritDoc}. */
- public PublicKey engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage)
- throws KeyResolverException {
-
+ /** {@inheritDoc}. */
+ public boolean engineCanResolve(Element element, String baseURI, StorageResolver storage) {
+ return XMLUtils.elementIsInSignature11Space(element, Constants._TAG_KEYINFOREFERENCE);
+ }
+
+ /** {@inheritDoc}. */
+ public PublicKey engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage)
+ throws KeyResolverException {
+
if (log.isDebugEnabled()) {
log.debug("Can I resolve " + element.getTagName());
}
-
+
if (!engineCanResolve(element, baseURI, storage)) {
- return null;
+ return null;
}
try {
- KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
- if (referent != null) {
- return referent.getPublicKey();
- }
+ KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
+ if (referent != null) {
+ return referent.getPublicKey();
+ }
} catch (XMLSecurityException e) {
if (log.isDebugEnabled()) {
log.debug("XMLSecurityException", e);
@@ -70,25 +70,25 @@ public class KeyInfoReferenceResolver ex
}
return null;
- }
+ }
+
+ /** {@inheritDoc}. */
+ public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage)
+ throws KeyResolverException {
- /** {@inheritDoc}. */
- public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage)
- throws KeyResolverException {
-
if (log.isDebugEnabled()) {
log.debug("Can I resolve " + element.getTagName());
}
-
+
if (!engineCanResolve(element, baseURI, storage)) {
- return null;
+ return null;
}
try {
- KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
- if (referent != null) {
- return referent.getX509Certificate();
- }
+ KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
+ if (referent != null) {
+ return referent.getX509Certificate();
+ }
} catch (XMLSecurityException e) {
if (log.isDebugEnabled()) {
log.debug("XMLSecurityException", e);
@@ -96,25 +96,25 @@ public class KeyInfoReferenceResolver ex
}
return null;
- }
+ }
+
+ /** {@inheritDoc}. */
+ public SecretKey engineLookupAndResolveSecretKey(Element element, String baseURI, StorageResolver storage)
+ throws KeyResolverException {
- /** {@inheritDoc}. */
- public SecretKey engineLookupAndResolveSecretKey(Element element, String baseURI, StorageResolver storage)
- throws KeyResolverException {
-
if (log.isDebugEnabled()) {
log.debug("Can I resolve " + element.getTagName());
}
-
+
if (!engineCanResolve(element, baseURI, storage)) {
- return null;
+ return null;
}
try {
- KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
- if (referent != null) {
- return referent.getSecretKey();
- }
+ KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
+ if (referent != null) {
+ return referent.getSecretKey();
+ }
} catch (XMLSecurityException e) {
if (log.isDebugEnabled()) {
log.debug("XMLSecurityException", e);
@@ -122,25 +122,25 @@ public class KeyInfoReferenceResolver ex
}
return null;
- }
+ }
+
+ /** {@inheritDoc}. */
+ public PrivateKey engineLookupAndResolvePrivateKey(Element element, String baseURI, StorageResolver storage)
+ throws KeyResolverException {
- /** {@inheritDoc}. */
- public PrivateKey engineLookupAndResolvePrivateKey(Element element, String baseURI, StorageResolver storage)
- throws KeyResolverException {
-
if (log.isDebugEnabled()) {
log.debug("Can I resolve " + element.getTagName());
}
-
+
if (!engineCanResolve(element, baseURI, storage)) {
- return null;
+ return null;
}
try {
- KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
- if (referent != null) {
- return referent.getPrivateKey();
- }
+ KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
+ if (referent != null) {
+ return referent.getPrivateKey();
+ }
} catch (XMLSecurityException e) {
if (log.isDebugEnabled()) {
log.debug("XMLSecurityException", e);
@@ -148,45 +148,45 @@ public class KeyInfoReferenceResolver ex
}
return null;
- }
-
- /**
- * Resolve the KeyInfoReference Element's URI attribute into a KeyInfo instance.
- *
- * @param element
- * @param baseURI
- * @param storage
- * @return the KeyInfo which is referred to by this KeyInfoReference, or null if can not be resolved
- * @throws XMLSecurityException
- */
- private KeyInfo resolveReferentKeyInfo(Element element, String baseURI, StorageResolver storage) throws XMLSecurityException {
- KeyInfoReference reference = new KeyInfoReference(element, baseURI);
- Attr uriAttr = reference.getURIAttr();
-
- XMLSignatureInput resource = resolveInput(uriAttr, baseURI, secureValidation);
-
- Element referentElement = null;
- try {
- referentElement = obtainReferenceElement(resource);
- } catch (Exception e) {
+ }
+
+ /**
+ * Resolve the KeyInfoReference Element's URI attribute into a KeyInfo instance.
+ *
+ * @param element
+ * @param baseURI
+ * @param storage
+ * @return the KeyInfo which is referred to by this KeyInfoReference, or null if can not be resolved
+ * @throws XMLSecurityException
+ */
+ private KeyInfo resolveReferentKeyInfo(Element element, String baseURI, StorageResolver storage) throws XMLSecurityException {
+ KeyInfoReference reference = new KeyInfoReference(element, baseURI);
+ Attr uriAttr = reference.getURIAttr();
+
+ XMLSignatureInput resource = resolveInput(uriAttr, baseURI, secureValidation);
+
+ Element referentElement = null;
+ try {
+ referentElement = obtainReferenceElement(resource);
+ } catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug("XMLSecurityException", e);
}
- return null;
- }
-
- if (referentElement == null) {
- log.debug("De-reference of KeyInfoReference URI returned null: " + uriAttr.getValue());
- return null;
- }
-
- validateReference(referentElement);
-
- KeyInfo referent = new KeyInfo(referentElement, baseURI);
- referent.addStorageResolver(storage);
- return referent;
- }
-
+ return null;
+ }
+
+ if (referentElement == null) {
+ log.debug("De-reference of KeyInfoReference URI returned null: " + uriAttr.getValue());
+ return null;
+ }
+
+ validateReference(referentElement);
+
+ KeyInfo referent = new KeyInfo(referentElement, baseURI);
+ referent.addStorageResolver(storage);
+ return referent;
+ }
+
/**
* Validate the Element referred to by the KeyInfoReference.
*
@@ -195,26 +195,26 @@ public class KeyInfoReferenceResolver ex
* @throws XMLSecurityException
*/
private void validateReference(Element referentElement) throws XMLSecurityException {
- if (!XMLUtils.elementIsInSignatureSpace(referentElement, Constants._TAG_KEYINFO)) {
- Object exArgs[] = { new QName(referentElement.getNamespaceURI(), referentElement.getLocalName()) };
- throw new XMLSecurityException("KeyInfoReferenceResolver.InvalidReferentElement.WrongType", exArgs);
- }
-
- KeyInfo referent = new KeyInfo(referentElement, "");
- if (referent.containsKeyInfoReference()) {
- if (secureValidation) {
- throw new XMLSecurityException("KeyInfoReferenceResolver.InvalidReferentElement.ReferenceWithSecure");
- } else {
- // Don't support chains of references at this time. If do support in the future, this is where the code
- // would go to validate that don't have a cycle, resulting in an infinite loop. This may be unrealistic
- // to implement, and/or very expensive given remote URI references.
- throw new XMLSecurityException("KeyInfoReferenceResolver.InvalidReferentElement.ReferenceWithoutSecure");
- }
- }
-
- }
+ if (!XMLUtils.elementIsInSignatureSpace(referentElement, Constants._TAG_KEYINFO)) {
+ Object exArgs[] = { new QName(referentElement.getNamespaceURI(), referentElement.getLocalName()) };
+ throw new XMLSecurityException("KeyInfoReferenceResolver.InvalidReferentElement.WrongType", exArgs);
+ }
- /**
+ KeyInfo referent = new KeyInfo(referentElement, "");
+ if (referent.containsKeyInfoReference()) {
+ if (secureValidation) {
+ throw new XMLSecurityException("KeyInfoReferenceResolver.InvalidReferentElement.ReferenceWithSecure");
+ } else {
+ // Don't support chains of references at this time. If do support in the future, this is where the code
+ // would go to validate that don't have a cycle, resulting in an infinite loop. This may be unrealistic
+ // to implement, and/or very expensive given remote URI references.
+ throw new XMLSecurityException("KeyInfoReferenceResolver.InvalidReferentElement.ReferenceWithoutSecure");
+ }
+ }
+
+ }
+
+ /**
* Resolve the XML signature input represented by the specified URI.
*
* @param uri
@@ -223,13 +223,13 @@ public class KeyInfoReferenceResolver ex
* @return
* @throws XMLSecurityException
*/
- private XMLSignatureInput resolveInput(Attr uri, String baseURI, boolean secureValidation)
- throws XMLSecurityException {
+ private XMLSignatureInput resolveInput(Attr uri, String baseURI, boolean secureValidation)
+ throws XMLSecurityException {
ResourceResolver resRes = ResourceResolver.getInstance(uri, baseURI, secureValidation);
XMLSignatureInput resource = resRes.resolve(uri, baseURI);
return resource;
}
-
+
/**
* Resolve the Element effectively represented by the XML signature input source.
*
@@ -242,23 +242,23 @@ public class KeyInfoReferenceResolver ex
* @throws KeyResolverException
*/
private Element obtainReferenceElement(XMLSignatureInput resource)
- throws CanonicalizationException, ParserConfigurationException,
- IOException, SAXException, KeyResolverException {
-
- Element e;
- if (resource.isElement()){
- e = (Element) resource.getSubNode();
- } else if (resource.isNodeSet()) {
- log.debug("De-reference of KeyInfoReference returned an unsupported NodeSet");
- return null;
- } else {
- // Retrieved resource is a byte stream
- byte inputBytes[] = resource.getBytes();
- e = getDocFromBytes(inputBytes);
- }
- return e;
+ throws CanonicalizationException, ParserConfigurationException,
+ IOException, SAXException, KeyResolverException {
+
+ Element e;
+ if (resource.isElement()){
+ e = (Element) resource.getSubNode();
+ } else if (resource.isNodeSet()) {
+ log.debug("De-reference of KeyInfoReference returned an unsupported NodeSet");
+ return null;
+ } else {
+ // Retrieved resource is a byte stream
+ byte inputBytes[] = resource.getBytes();
+ e = getDocFromBytes(inputBytes);
+ }
+ return e;
}
-
+
/**
* Parses a byte array and returns the parsed Element.
*
@@ -282,5 +282,5 @@ public class KeyInfoReferenceResolver ex
throw new KeyResolverException("empty", ex);
}
}
-
+
}
Modified: santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/X509DigestResolver.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/X509DigestResolver.java?rev=1418419&r1=1418418&r2=1418419&view=diff
==============================================================================
--- santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/X509DigestResolver.java (original)
+++ santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/keys/keyresolver/implementations/X509DigestResolver.java Fri Dec 7 18:10:49 2012
@@ -25,52 +25,52 @@ import org.w3c.dom.Element;
* @author Brent Putman (putmanb@georgetown.edu)
*/
public class X509DigestResolver extends KeyResolverSpi {
-
+
/** {@link org.apache.commons.logging} logging facility */
private static org.apache.commons.logging.Log log =
org.apache.commons.logging.LogFactory.getLog(X509DigestResolver.class);
- /** {@inheritDoc}. */
- public boolean engineCanResolve(Element element, String baseURI, StorageResolver storage) {
- if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_X509DATA)) {
- try {
- X509Data x509Data = new X509Data(element, baseURI);
- return x509Data.containsDigest();
- } catch (XMLSecurityException e) {
- return false;
- }
- } else {
- return false;
- }
- }
-
- /** {@inheritDoc}. */
- public PublicKey engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage)
- throws KeyResolverException {
-
- X509Certificate cert = this.engineLookupResolveX509Certificate(element, baseURI, storage);
-
- if (cert != null) {
- return cert.getPublicKey();
- }
-
- return null;
- }
-
- /** {@inheritDoc}. */
- public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage)
- throws KeyResolverException {
-
+ /** {@inheritDoc}. */
+ public boolean engineCanResolve(Element element, String baseURI, StorageResolver storage) {
+ if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_X509DATA)) {
+ try {
+ X509Data x509Data = new X509Data(element, baseURI);
+ return x509Data.containsDigest();
+ } catch (XMLSecurityException e) {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ /** {@inheritDoc}. */
+ public PublicKey engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage)
+ throws KeyResolverException {
+
+ X509Certificate cert = this.engineLookupResolveX509Certificate(element, baseURI, storage);
+
+ if (cert != null) {
+ return cert.getPublicKey();
+ }
+
+ return null;
+ }
+
+ /** {@inheritDoc}. */
+ public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage)
+ throws KeyResolverException {
+
if (log.isDebugEnabled()) {
log.debug("Can I resolve " + element.getTagName());
}
-
+
if (!engineCanResolve(element, baseURI, storage)) {
- return null;
+ return null;
}
try {
- return resolveCertificate(element, baseURI, storage);
+ return resolveCertificate(element, baseURI, storage);
} catch (XMLSecurityException e) {
if (log.isDebugEnabled()) {
log.debug("XMLSecurityException", e);
@@ -78,26 +78,26 @@ public class X509DigestResolver extends
}
return null;
- }
+ }
+
+ /** {@inheritDoc}. */
+ public SecretKey engineLookupAndResolveSecretKey(Element element, String baseURI, StorageResolver storage)
+ throws KeyResolverException {
+ return null;
+ }
+
+ /**
+ * Resolves from the storage resolver the actual certificate represented by the digest.
+ *
+ * @param element
+ * @param baseURI
+ * @param storage
+ * @return
+ * @throws XMLSecurityException
+ */
+ private X509Certificate resolveCertificate(Element element, String baseURI, StorageResolver storage)
+ throws XMLSecurityException {
- /** {@inheritDoc}. */
- public SecretKey engineLookupAndResolveSecretKey(Element element, String baseURI, StorageResolver storage)
- throws KeyResolverException {
- return null;
- }
-
- /**
- * Resolves from the storage resolver the actual certificate represented by the digest.
- *
- * @param element
- * @param baseURI
- * @param storage
- * @return
- * @throws XMLSecurityException
- */
- private X509Certificate resolveCertificate(Element element, String baseURI, StorageResolver storage)
- throws XMLSecurityException {
-
XMLX509Digest x509Digests[] = null;
Element x509childNodes[] = XMLUtils.selectDs11Nodes(element.getFirstChild(), Constants._TAG_X509DIGEST);
@@ -105,7 +105,7 @@ public class X509DigestResolver extends
if (x509childNodes == null || x509childNodes.length <= 0) {
return null;
}
-
+
try {
checkStorage(storage);
@@ -120,41 +120,41 @@ public class X509DigestResolver extends
X509Certificate cert = (X509Certificate) storageIterator.next();
for (int i = 0; i < x509Digests.length; i++) {
- XMLX509Digest keyInfoDigest = x509Digests[i];
- byte[] certDigestBytes = XMLX509Digest.getDigestBytesFromCert(cert, keyInfoDigest.getAlgorithm());
-
+ XMLX509Digest keyInfoDigest = x509Digests[i];
+ byte[] certDigestBytes = XMLX509Digest.getDigestBytesFromCert(cert, keyInfoDigest.getAlgorithm());
+
if (Arrays.equals(keyInfoDigest.getDigestBytes(), certDigestBytes)) {
if (log.isDebugEnabled()) {
log.debug("Found certificate with: " + cert.getSubjectX500Principal().getName());
}
return cert;
}
-
+
}
}
-
+
} catch (XMLSecurityException ex) {
throw new KeyResolverException("empty", ex);
}
-
+
return null;
- }
+ }
- /**
- * Method checkSrorage
- *
- * @param storage
- * @throws KeyResolverException
- */
- private void checkStorage(StorageResolver storage) throws KeyResolverException {
- if (storage == null) {
- Object exArgs[] = { Constants._TAG_X509DIGEST };
- KeyResolverException ex = new KeyResolverException("KeyResolver.needStorageResolver", exArgs);
- if (log.isDebugEnabled()) {
- log.debug("", ex);
- }
- throw ex;
- }
- }
+ /**
+ * Method checkSrorage
+ *
+ * @param storage
+ * @throws KeyResolverException
+ */
+ private void checkStorage(StorageResolver storage) throws KeyResolverException {
+ if (storage == null) {
+ Object exArgs[] = { Constants._TAG_X509DIGEST };
+ KeyResolverException ex = new KeyResolverException("KeyResolver.needStorageResolver", exArgs);
+ if (log.isDebugEnabled()) {
+ log.debug("", ex);
+ }
+ throw ex;
+ }
+ }
}
Modified: santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/utils/resolver/ResourceResolverSpi.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/utils/resolver/ResourceResolverSpi.java?rev=1418419&r1=1418418&r2=1418419&view=diff
==============================================================================
--- santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/utils/resolver/ResourceResolverSpi.java (original)
+++ santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/utils/resolver/ResourceResolverSpi.java Fri Dec 7 18:10:49 2012
@@ -37,7 +37,7 @@ public abstract class ResourceResolverSp
/** Field properties */
protected java.util.Map<String, String> properties = null;
-
+
/**
* Deprecated - used to carry state about whether resolution was being done in a secure fashion,
* but was not thread safe, so the resolution information is now passed as parameters to methods.
@@ -58,8 +58,8 @@ public abstract class ResourceResolverSp
* @deprecated New clients should override {@link #engineResolveURI(ResourceResolverContext)}
*/
public XMLSignatureInput engineResolve(Attr uri, String BaseURI)
- throws ResourceResolverException {
- throw new UnsupportedOperationException();
+ throws ResourceResolverException {
+ throw new UnsupportedOperationException();
}
/**
@@ -71,10 +71,10 @@ public abstract class ResourceResolverSp
* @throws ResourceResolverException
*/
public XMLSignatureInput engineResolveURI(ResourceResolverContext context)
- throws ResourceResolverException {
- // The default implementation, to preserve backwards compatibility in the
- // test cases, calls the old resolver API.
- return engineResolve(context.attr, context.baseUri);
+ throws ResourceResolverException {
+ // The default implementation, to preserve backwards compatibility in the
+ // test cases, calls the old resolver API.
+ return engineResolve(context.attr, context.baseUri);
}
/**
@@ -115,7 +115,7 @@ public abstract class ResourceResolverSp
properties.putAll(newProperties);
}
}
-
+
/**
* Tells if the implementation does can be reused by several threads safely.
* It normally means that the implementation does not have any member, or there is
@@ -125,7 +125,7 @@ public abstract class ResourceResolverSp
public boolean engineIsThreadSafe() {
return false;
}
-
+
/**
* This method helps the {@link ResourceResolver} to decide whether a
* {@link ResourceResolverSpi} is able to perform the requested action.
@@ -153,7 +153,7 @@ public abstract class ResourceResolverSp
public boolean engineCanResolveURI(ResourceResolverContext context) {
// To preserve backward compatibility with existing resolvers that might override the old method,
// call the old deprecated API.
- return engineCanResolve( (Attr) context.attr, context.baseUri );
+ return engineCanResolve( (Attr) context.attr, context.baseUri );
}
/**
Modified: santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/utils/resolver/implementations/ResolverAnonymous.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/utils/resolver/implementations/ResolverAnonymous.java?rev=1418419&r1=1418418&r2=1418419&view=diff
==============================================================================
--- santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/utils/resolver/implementations/ResolverAnonymous.java (original)
+++ santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/utils/resolver/implementations/ResolverAnonymous.java Fri Dec 7 18:10:49 2012
@@ -34,7 +34,7 @@ import org.apache.xml.security.utils.res
public class ResolverAnonymous extends ResourceResolverSpi {
private InputStream inStream = null;
-
+
@Override
public boolean engineIsThreadSafe() {
return true;
@@ -59,7 +59,7 @@ public class ResolverAnonymous extends R
/** @inheritDoc */
@Override
public XMLSignatureInput engineResolveURI(ResourceResolverContext context) {
- return new XMLSignatureInput(inStream);
+ return new XMLSignatureInput(inStream);
}
/**
Modified: santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/DEREncodedKeyValueTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/DEREncodedKeyValueTest.java?rev=1418419&r1=1418418&r2=1418419&view=diff
==============================================================================
--- santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/DEREncodedKeyValueTest.java (original)
+++ santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/DEREncodedKeyValueTest.java Fri Dec 7 18:10:49 2012
@@ -39,24 +39,24 @@ import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
public class DEREncodedKeyValueTest extends Assert {
-
+
private static final String BASEDIR = System.getProperty("basedir") == null ? "./": System.getProperty("basedir");
private static final String SEP = System.getProperty("file.separator");
-
+
private DocumentBuilder documentBuilder;
-
- private PublicKey rsaKeyControl;
- private PublicKey dsaKeyControl;
- private PublicKey ecKeyControl;
-
- private final String idControl = "abc123";
-
- public DEREncodedKeyValueTest() throws Exception {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+
+ private PublicKey rsaKeyControl;
+ private PublicKey dsaKeyControl;
+ private PublicKey ecKeyControl;
+
+ private final String idControl = "abc123";
+
+ public DEREncodedKeyValueTest() throws Exception {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
documentBuilder = dbf.newDocumentBuilder();
-
- //
+
+ //
// If the BouncyCastle provider is not installed, then try to load it
// via reflection.
//
@@ -74,42 +74,42 @@ public class DEREncodedKeyValueTest exte
ecKeyControl = loadPublicKey("ec.key", "EC");
}
}
-
- rsaKeyControl = loadPublicKey("rsa.key", "RSA");
- dsaKeyControl = loadPublicKey("dsa.key", "DSA");
- }
-
+
+ rsaKeyControl = loadPublicKey("rsa.key", "RSA");
+ dsaKeyControl = loadPublicKey("dsa.key", "DSA");
+ }
+
@org.junit.Test
public void testSchema() throws Exception {
- DEREncodedKeyValue derEncodedKeyValue = new DEREncodedKeyValue(documentBuilder.newDocument(), rsaKeyControl);
- Element element = derEncodedKeyValue.getElement();
-
- assertEquals("http://www.w3.org/2009/xmldsig11#", element.getNamespaceURI());
- assertEquals("DEREncodedKeyValue", element.getLocalName());
+ DEREncodedKeyValue derEncodedKeyValue = new DEREncodedKeyValue(documentBuilder.newDocument(), rsaKeyControl);
+ Element element = derEncodedKeyValue.getElement();
+
+ assertEquals("http://www.w3.org/2009/xmldsig11#", element.getNamespaceURI());
+ assertEquals("DEREncodedKeyValue", element.getLocalName());
}
-
+
@org.junit.Test
public void testRSAPublicKeyFromElement() throws Exception {
- Document doc = loadXML("DEREncodedKeyValue-RSA.xml");
- NodeList nl = doc.getElementsByTagNameNS(Constants.SignatureSpec11NS, Constants._TAG_DERENCODEDKEYVALUE);
- Element element = (Element) nl.item(0);
-
- DEREncodedKeyValue derEncodedKeyValue = new DEREncodedKeyValue(element, "");
- assertEquals(rsaKeyControl, derEncodedKeyValue.getPublicKey());
- assertArrayEquals(rsaKeyControl.getEncoded(), derEncodedKeyValue.getBytesFromTextChild());
- assertEquals(idControl, derEncodedKeyValue.getId());
+ Document doc = loadXML("DEREncodedKeyValue-RSA.xml");
+ NodeList nl = doc.getElementsByTagNameNS(Constants.SignatureSpec11NS, Constants._TAG_DERENCODEDKEYVALUE);
+ Element element = (Element) nl.item(0);
+
+ DEREncodedKeyValue derEncodedKeyValue = new DEREncodedKeyValue(element, "");
+ assertEquals(rsaKeyControl, derEncodedKeyValue.getPublicKey());
+ assertArrayEquals(rsaKeyControl.getEncoded(), derEncodedKeyValue.getBytesFromTextChild());
+ assertEquals(idControl, derEncodedKeyValue.getId());
}
- @org.junit.Test
+ @org.junit.Test
public void testDSAPublicKeyFromElement() throws Exception {
- Document doc = loadXML("DEREncodedKeyValue-DSA.xml");
- NodeList nl = doc.getElementsByTagNameNS(Constants.SignatureSpec11NS, Constants._TAG_DERENCODEDKEYVALUE);
- Element element = (Element) nl.item(0);
-
- DEREncodedKeyValue derEncodedKeyValue = new DEREncodedKeyValue(element, "");
- assertEquals(dsaKeyControl, derEncodedKeyValue.getPublicKey());
- assertArrayEquals(dsaKeyControl.getEncoded(), derEncodedKeyValue.getBytesFromTextChild());
- assertEquals(idControl, derEncodedKeyValue.getId());
+ Document doc = loadXML("DEREncodedKeyValue-DSA.xml");
+ NodeList nl = doc.getElementsByTagNameNS(Constants.SignatureSpec11NS, Constants._TAG_DERENCODEDKEYVALUE);
+ Element element = (Element) nl.item(0);
+
+ DEREncodedKeyValue derEncodedKeyValue = new DEREncodedKeyValue(element, "");
+ assertEquals(dsaKeyControl, derEncodedKeyValue.getPublicKey());
+ assertArrayEquals(dsaKeyControl.getEncoded(), derEncodedKeyValue.getBytesFromTextChild());
+ assertEquals(idControl, derEncodedKeyValue.getId());
}
@org.junit.Test
@@ -117,29 +117,29 @@ public class DEREncodedKeyValueTest exte
if (ecKeyControl == null) {
return;
}
-
- Document doc = loadXML("DEREncodedKeyValue-EC.xml");
- NodeList nl = doc.getElementsByTagNameNS(Constants.SignatureSpec11NS, Constants._TAG_DERENCODEDKEYVALUE);
- Element element = (Element) nl.item(0);
-
- DEREncodedKeyValue derEncodedKeyValue = new DEREncodedKeyValue(element, "");
- assertEquals(ecKeyControl, derEncodedKeyValue.getPublicKey());
- assertArrayEquals(ecKeyControl.getEncoded(), derEncodedKeyValue.getBytesFromTextChild());
- assertEquals(idControl, derEncodedKeyValue.getId());
+
+ Document doc = loadXML("DEREncodedKeyValue-EC.xml");
+ NodeList nl = doc.getElementsByTagNameNS(Constants.SignatureSpec11NS, Constants._TAG_DERENCODEDKEYVALUE);
+ Element element = (Element) nl.item(0);
+
+ DEREncodedKeyValue derEncodedKeyValue = new DEREncodedKeyValue(element, "");
+ assertEquals(ecKeyControl, derEncodedKeyValue.getPublicKey());
+ assertArrayEquals(ecKeyControl.getEncoded(), derEncodedKeyValue.getBytesFromTextChild());
+ assertEquals(idControl, derEncodedKeyValue.getId());
}
@org.junit.Test
public void testRSAPublicKeyFromKey() throws Exception {
- DEREncodedKeyValue derEncodedKeyValue = new DEREncodedKeyValue(documentBuilder.newDocument(), rsaKeyControl);
- assertEquals(rsaKeyControl, derEncodedKeyValue.getPublicKey());
- assertArrayEquals(rsaKeyControl.getEncoded(), derEncodedKeyValue.getBytesFromTextChild());
+ DEREncodedKeyValue derEncodedKeyValue = new DEREncodedKeyValue(documentBuilder.newDocument(), rsaKeyControl);
+ assertEquals(rsaKeyControl, derEncodedKeyValue.getPublicKey());
+ assertArrayEquals(rsaKeyControl.getEncoded(), derEncodedKeyValue.getBytesFromTextChild());
}
@org.junit.Test
public void testDSAPublicKeyFromKey() throws Exception {
- DEREncodedKeyValue derEncodedKeyValue = new DEREncodedKeyValue(documentBuilder.newDocument(), dsaKeyControl);
- assertEquals(dsaKeyControl, derEncodedKeyValue.getPublicKey());
- assertArrayEquals(dsaKeyControl.getEncoded(), derEncodedKeyValue.getBytesFromTextChild());
+ DEREncodedKeyValue derEncodedKeyValue = new DEREncodedKeyValue(documentBuilder.newDocument(), dsaKeyControl);
+ assertEquals(dsaKeyControl, derEncodedKeyValue.getPublicKey());
+ assertArrayEquals(dsaKeyControl.getEncoded(), derEncodedKeyValue.getBytesFromTextChild());
}
@org.junit.Test
@@ -147,46 +147,46 @@ public class DEREncodedKeyValueTest exte
if (ecKeyControl == null) {
return;
}
-
- DEREncodedKeyValue derEncodedKeyValue = new DEREncodedKeyValue(documentBuilder.newDocument(), ecKeyControl);
- assertEquals(ecKeyControl, derEncodedKeyValue.getPublicKey());
- assertArrayEquals(ecKeyControl.getEncoded(), derEncodedKeyValue.getBytesFromTextChild());
+
+ DEREncodedKeyValue derEncodedKeyValue = new DEREncodedKeyValue(documentBuilder.newDocument(), ecKeyControl);
+ assertEquals(ecKeyControl, derEncodedKeyValue.getPublicKey());
+ assertArrayEquals(ecKeyControl.getEncoded(), derEncodedKeyValue.getBytesFromTextChild());
}
-
- @org.junit.Test
+
+ @org.junit.Test
public void testId() throws Exception {
- DEREncodedKeyValue derEncodedKeyValue = new DEREncodedKeyValue(documentBuilder.newDocument(), rsaKeyControl);
- assertEquals("", derEncodedKeyValue.getId());
- assertNull(derEncodedKeyValue.getElement().getAttributeNodeNS(null, Constants._ATT_ID));
-
- derEncodedKeyValue.setId(idControl);
- assertEquals(idControl, derEncodedKeyValue.getId());
- assertTrue(derEncodedKeyValue.getElement().getAttributeNodeNS(null, Constants._ATT_ID).isId());
-
- derEncodedKeyValue.setId(null);
- assertEquals("", derEncodedKeyValue.getId());
- assertNull(derEncodedKeyValue.getElement().getAttributeNodeNS(null, Constants._ATT_ID));
+ DEREncodedKeyValue derEncodedKeyValue = new DEREncodedKeyValue(documentBuilder.newDocument(), rsaKeyControl);
+ assertEquals("", derEncodedKeyValue.getId());
+ assertNull(derEncodedKeyValue.getElement().getAttributeNodeNS(null, Constants._ATT_ID));
+
+ derEncodedKeyValue.setId(idControl);
+ assertEquals(idControl, derEncodedKeyValue.getId());
+ assertTrue(derEncodedKeyValue.getElement().getAttributeNodeNS(null, Constants._ATT_ID).isId());
+
+ derEncodedKeyValue.setId(null);
+ assertEquals("", derEncodedKeyValue.getId());
+ assertNull(derEncodedKeyValue.getElement().getAttributeNodeNS(null, Constants._ATT_ID));
}
-
+
// Utility methods
-
+
private String getControlFilePath(String fileName) {
return BASEDIR + SEP + "src" + SEP + "test" + SEP + "resources" +
- SEP + "org" + SEP + "apache" + SEP + "xml" + SEP + "security" +
- SEP + "keys" + SEP + "content" +
- SEP + fileName;
- }
-
+ SEP + "org" + SEP + "apache" + SEP + "xml" + SEP + "security" +
+ SEP + "keys" + SEP + "content" +
+ SEP + fileName;
+ }
+
private Document loadXML(String fileName) throws Exception {
- return documentBuilder.parse(new FileInputStream(getControlFilePath(fileName)));
+ return documentBuilder.parse(new FileInputStream(getControlFilePath(fileName)));
}
private PublicKey loadPublicKey(String filePath, String algorithm) throws Exception {
- String fileData = new String(JavaUtils.getBytesFromFile(getControlFilePath(filePath)));
- byte[] keyBytes = Base64.decode(fileData);
- KeyFactory kf = KeyFactory.getInstance(algorithm);
- X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
- return kf.generatePublic(keySpec);
+ String fileData = new String(JavaUtils.getBytesFromFile(getControlFilePath(filePath)));
+ byte[] keyBytes = Base64.decode(fileData);
+ KeyFactory kf = KeyFactory.getInstance(algorithm);
+ X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
+ return kf.generatePublic(keySpec);
}
}
Modified: santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/KeyInfoReferenceTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/KeyInfoReferenceTest.java?rev=1418419&r1=1418418&r2=1418419&view=diff
==============================================================================
--- santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/KeyInfoReferenceTest.java (original)
+++ santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/KeyInfoReferenceTest.java Fri Dec 7 18:10:49 2012
@@ -31,73 +31,73 @@ import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
public class KeyInfoReferenceTest extends Assert {
-
+
private static final String BASEDIR = System.getProperty("basedir") == null ? "./": System.getProperty("basedir");
private static final String SEP = System.getProperty("file.separator");
-
+
private DocumentBuilder documentBuilder;
-
+
private final String idControl = "abc123";
private final String uriControl = "http://www.example.org/keyinfo.xml";
-
+
public KeyInfoReferenceTest() throws Exception {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(true);
- documentBuilder = dbf.newDocumentBuilder();
- }
-
- @org.junit.Test
- public void testSchema() throws Exception {
- KeyInfoReference keyInfoReference = new KeyInfoReference(documentBuilder.newDocument(), uriControl);
- Element element = keyInfoReference.getElement();
-
- assertEquals("http://www.w3.org/2009/xmldsig11#", element.getNamespaceURI());
- assertEquals("KeyInfoReference", element.getLocalName());
- }
-
- @org.junit.Test
- public void testURIFromElement() throws Exception {
- Document doc = loadXML("KeyInfoReference.xml");
- NodeList nl = doc.getElementsByTagNameNS(Constants.SignatureSpec11NS, Constants._TAG_KEYINFOREFERENCE);
- Element element = (Element) nl.item(0);
-
- KeyInfoReference keyInfoReference = new KeyInfoReference(element, "");
- assertEquals(uriControl, keyInfoReference.getURI());
- assertEquals(idControl, keyInfoReference.getId());
- }
-
- @org.junit.Test
- public void testURIOnConstruction() throws Exception {
- KeyInfoReference keyInfoReference = new KeyInfoReference(documentBuilder.newDocument(), uriControl);
- assertEquals(uriControl, keyInfoReference.getURI());
- }
-
- @org.junit.Test
- public void testId() throws Exception {
- KeyInfoReference keyInfoReference = new KeyInfoReference(documentBuilder.newDocument(), uriControl);
- assertEquals("", keyInfoReference.getId());
- assertNull(keyInfoReference.getElement().getAttributeNodeNS(null, Constants._ATT_ID));
-
- keyInfoReference.setId(idControl);
- assertEquals(idControl, keyInfoReference.getId());
- assertTrue(keyInfoReference.getElement().getAttributeNodeNS(null, Constants._ATT_ID).isId());
-
- keyInfoReference.setId(null);
- assertEquals("", keyInfoReference.getId());
- assertNull(keyInfoReference.getElement().getAttributeNodeNS(null, Constants._ATT_ID));
- }
-
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ documentBuilder = dbf.newDocumentBuilder();
+ }
+
+ @org.junit.Test
+ public void testSchema() throws Exception {
+ KeyInfoReference keyInfoReference = new KeyInfoReference(documentBuilder.newDocument(), uriControl);
+ Element element = keyInfoReference.getElement();
+
+ assertEquals("http://www.w3.org/2009/xmldsig11#", element.getNamespaceURI());
+ assertEquals("KeyInfoReference", element.getLocalName());
+ }
+
+ @org.junit.Test
+ public void testURIFromElement() throws Exception {
+ Document doc = loadXML("KeyInfoReference.xml");
+ NodeList nl = doc.getElementsByTagNameNS(Constants.SignatureSpec11NS, Constants._TAG_KEYINFOREFERENCE);
+ Element element = (Element) nl.item(0);
+
+ KeyInfoReference keyInfoReference = new KeyInfoReference(element, "");
+ assertEquals(uriControl, keyInfoReference.getURI());
+ assertEquals(idControl, keyInfoReference.getId());
+ }
+
+ @org.junit.Test
+ public void testURIOnConstruction() throws Exception {
+ KeyInfoReference keyInfoReference = new KeyInfoReference(documentBuilder.newDocument(), uriControl);
+ assertEquals(uriControl, keyInfoReference.getURI());
+ }
+
+ @org.junit.Test
+ public void testId() throws Exception {
+ KeyInfoReference keyInfoReference = new KeyInfoReference(documentBuilder.newDocument(), uriControl);
+ assertEquals("", keyInfoReference.getId());
+ assertNull(keyInfoReference.getElement().getAttributeNodeNS(null, Constants._ATT_ID));
+
+ keyInfoReference.setId(idControl);
+ assertEquals(idControl, keyInfoReference.getId());
+ assertTrue(keyInfoReference.getElement().getAttributeNodeNS(null, Constants._ATT_ID).isId());
+
+ keyInfoReference.setId(null);
+ assertEquals("", keyInfoReference.getId());
+ assertNull(keyInfoReference.getElement().getAttributeNodeNS(null, Constants._ATT_ID));
+ }
+
// Utility methods
-
+
private String getControlFilePath(String fileName) {
return BASEDIR + SEP + "src" + SEP + "test" + SEP + "resources" +
- SEP + "org" + SEP + "apache" + SEP + "xml" + SEP + "security" +
- SEP + "keys" + SEP + "content" +
- SEP + fileName;
- }
-
+ SEP + "org" + SEP + "apache" + SEP + "xml" + SEP + "security" +
+ SEP + "keys" + SEP + "content" +
+ SEP + fileName;
+ }
+
private Document loadXML(String fileName) throws Exception {
- return documentBuilder.parse(new FileInputStream(getControlFilePath(fileName)));
+ return documentBuilder.parse(new FileInputStream(getControlFilePath(fileName)));
}
}
Modified: santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509DigestTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509DigestTest.java?rev=1418419&r1=1418418&r2=1418419&view=diff
==============================================================================
--- santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509DigestTest.java (original)
+++ santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509DigestTest.java Fri Dec 7 18:10:49 2012
@@ -35,90 +35,90 @@ import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
public class XMLX509DigestTest extends Assert {
-
+
private static final String BASEDIR = System.getProperty("basedir") == null ? "./": System.getProperty("basedir");
private static final String SEP = System.getProperty("file.separator");
-
+
private DocumentBuilder documentBuilder;
-
+
private X509Certificate certControl;
-
+
private final String algorithmURIControl = "http://www.w3.org/2001/04/xmlenc#sha256";
-
+
private final String digestBase64Control = "jToLQ/K7aaLHy/aXLFnjEfCwSQd9z0MrBOH6Ru/aJyY=";
private final byte[] digestControl;
-
+
public XMLX509DigestTest() throws Exception {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(true);
- documentBuilder = dbf.newDocumentBuilder();
-
- certControl = loadCertificate("cert-X509Digest.crt");
-
- digestControl = Base64.decode(digestBase64Control);
-
- if (!Init.isInitialized()) {
- Init.init();
- }
- }
-
- @org.junit.Test
- public void testSchema() throws Exception {
- XMLX509Digest x509Digest = new XMLX509Digest(documentBuilder.newDocument(), digestControl, algorithmURIControl);
- Element element = x509Digest.getElement();
-
- assertEquals("http://www.w3.org/2009/xmldsig11#", element.getNamespaceURI());
- assertEquals("X509Digest", element.getLocalName());
- }
-
- @org.junit.Test
- public void testDigestFromElement() throws Exception {
- Document doc = loadXML("X509Digest.xml");
- NodeList nl = doc.getElementsByTagNameNS(Constants.SignatureSpec11NS, Constants._TAG_X509DIGEST);
- Element element = (Element) nl.item(0);
-
- XMLX509Digest x509Digest = new XMLX509Digest(element, "");
- assertEquals(algorithmURIControl, x509Digest.getAlgorithm());
- assertArrayEquals(digestControl, x509Digest.getDigestBytes());
- }
-
- @org.junit.Test
- public void testDigestOnConstructionWithCert() throws Exception {
- XMLX509Digest x509Digest = new XMLX509Digest(documentBuilder.newDocument(), certControl, algorithmURIControl);
- assertEquals(algorithmURIControl, x509Digest.getAlgorithm());
- assertArrayEquals(digestControl, x509Digest.getDigestBytes());
- }
-
- @org.junit.Test
- public void testDigestOnConstructionWithBytes() throws Exception {
- XMLX509Digest x509Digest = new XMLX509Digest(documentBuilder.newDocument(), digestControl, algorithmURIControl);
- assertEquals(algorithmURIControl, x509Digest.getAlgorithm());
- assertArrayEquals(digestControl, x509Digest.getDigestBytes());
- }
-
- @org.junit.Test
- public void testGetDigestBytesFromCert() throws Exception {
- assertArrayEquals(digestControl, XMLX509Digest.getDigestBytesFromCert(certControl, algorithmURIControl));
- }
-
-
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ documentBuilder = dbf.newDocumentBuilder();
+
+ certControl = loadCertificate("cert-X509Digest.crt");
+
+ digestControl = Base64.decode(digestBase64Control);
+
+ if (!Init.isInitialized()) {
+ Init.init();
+ }
+ }
+
+ @org.junit.Test
+ public void testSchema() throws Exception {
+ XMLX509Digest x509Digest = new XMLX509Digest(documentBuilder.newDocument(), digestControl, algorithmURIControl);
+ Element element = x509Digest.getElement();
+
+ assertEquals("http://www.w3.org/2009/xmldsig11#", element.getNamespaceURI());
+ assertEquals("X509Digest", element.getLocalName());
+ }
+
+ @org.junit.Test
+ public void testDigestFromElement() throws Exception {
+ Document doc = loadXML("X509Digest.xml");
+ NodeList nl = doc.getElementsByTagNameNS(Constants.SignatureSpec11NS, Constants._TAG_X509DIGEST);
+ Element element = (Element) nl.item(0);
+
+ XMLX509Digest x509Digest = new XMLX509Digest(element, "");
+ assertEquals(algorithmURIControl, x509Digest.getAlgorithm());
+ assertArrayEquals(digestControl, x509Digest.getDigestBytes());
+ }
+
+ @org.junit.Test
+ public void testDigestOnConstructionWithCert() throws Exception {
+ XMLX509Digest x509Digest = new XMLX509Digest(documentBuilder.newDocument(), certControl, algorithmURIControl);
+ assertEquals(algorithmURIControl, x509Digest.getAlgorithm());
+ assertArrayEquals(digestControl, x509Digest.getDigestBytes());
+ }
+
+ @org.junit.Test
+ public void testDigestOnConstructionWithBytes() throws Exception {
+ XMLX509Digest x509Digest = new XMLX509Digest(documentBuilder.newDocument(), digestControl, algorithmURIControl);
+ assertEquals(algorithmURIControl, x509Digest.getAlgorithm());
+ assertArrayEquals(digestControl, x509Digest.getDigestBytes());
+ }
+
+ @org.junit.Test
+ public void testGetDigestBytesFromCert() throws Exception {
+ assertArrayEquals(digestControl, XMLX509Digest.getDigestBytesFromCert(certControl, algorithmURIControl));
+ }
+
+
// Utility methods
-
+
private String getControlFilePath(String fileName) {
return BASEDIR + SEP + "src" + SEP + "test" + SEP + "resources" +
- SEP + "org" + SEP + "apache" + SEP + "xml" + SEP + "security" +
- SEP + "keys" + SEP + "content" + SEP + "x509" +
- SEP + fileName;
- }
-
+ SEP + "org" + SEP + "apache" + SEP + "xml" + SEP + "security" +
+ SEP + "keys" + SEP + "content" + SEP + "x509" +
+ SEP + fileName;
+ }
+
private Document loadXML(String fileName) throws Exception {
- return documentBuilder.parse(new FileInputStream(getControlFilePath(fileName)));
+ return documentBuilder.parse(new FileInputStream(getControlFilePath(fileName)));
}
- private X509Certificate loadCertificate(String fileName) throws Exception {
- FileInputStream fis = new FileInputStream(getControlFilePath(fileName));
- CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
- return (X509Certificate) certFactory.generateCertificate(fis);
- }
+ private X509Certificate loadCertificate(String fileName) throws Exception {
+ FileInputStream fis = new FileInputStream(getControlFilePath(fileName));
+ CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
+ return (X509Certificate) certFactory.generateCertificate(fis);
+ }
}
Modified: santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/keyresolver/DEREncodedKeyValueResolverTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/keyresolver/DEREncodedKeyValueResolverTest.java?rev=1418419&r1=1418418&r2=1418419&view=diff
==============================================================================
--- santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/keyresolver/DEREncodedKeyValueResolverTest.java (original)
+++ santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/keyresolver/DEREncodedKeyValueResolverTest.java Fri Dec 7 18:10:49 2012
@@ -38,22 +38,22 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class DEREncodedKeyValueResolverTest extends Assert {
-
+
private static final String BASEDIR = System.getProperty("basedir") == null ? "./": System.getProperty("basedir");
private static final String SEP = System.getProperty("file.separator");
-
+
private DocumentBuilder documentBuilder;
-
- private PublicKey rsaKeyControl;
- private PublicKey dsaKeyControl;
- private PublicKey ecKeyControl;
-
- public DEREncodedKeyValueResolverTest() throws Exception {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(true);
- documentBuilder = dbf.newDocumentBuilder();
-
- //
+
+ private PublicKey rsaKeyControl;
+ private PublicKey dsaKeyControl;
+ private PublicKey ecKeyControl;
+
+ public DEREncodedKeyValueResolverTest() throws Exception {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ documentBuilder = dbf.newDocumentBuilder();
+
+ //
// If the BouncyCastle provider is not installed, then try to load it
// via reflection.
//
@@ -71,31 +71,31 @@ public class DEREncodedKeyValueResolverT
ecKeyControl = loadPublicKey("ec.key", "EC");
}
}
-
- rsaKeyControl = loadPublicKey("rsa.key", "RSA");
- dsaKeyControl = loadPublicKey("dsa.key", "DSA");
-
- if (!Init.isInitialized()) {
- Init.init();
- }
- }
-
+
+ rsaKeyControl = loadPublicKey("rsa.key", "RSA");
+ dsaKeyControl = loadPublicKey("dsa.key", "DSA");
+
+ if (!Init.isInitialized()) {
+ Init.init();
+ }
+ }
+
@org.junit.Test
public void testRSAPublicKey() throws Exception {
- Document doc = loadXML("DEREncodedKeyValue-RSA.xml");
- Element element = doc.getDocumentElement();
-
- KeyInfo keyInfo = new KeyInfo(element, "");
- assertEquals(rsaKeyControl, keyInfo.getPublicKey());
+ Document doc = loadXML("DEREncodedKeyValue-RSA.xml");
+ Element element = doc.getDocumentElement();
+
+ KeyInfo keyInfo = new KeyInfo(element, "");
+ assertEquals(rsaKeyControl, keyInfo.getPublicKey());
}
- @org.junit.Test
+ @org.junit.Test
public void testDSAPublicKey() throws Exception {
- Document doc = loadXML("DEREncodedKeyValue-DSA.xml");
- Element element = doc.getDocumentElement();
-
- KeyInfo keyInfo = new KeyInfo(element, "");
- assertEquals(dsaKeyControl, keyInfo.getPublicKey());
+ Document doc = loadXML("DEREncodedKeyValue-DSA.xml");
+ Element element = doc.getDocumentElement();
+
+ KeyInfo keyInfo = new KeyInfo(element, "");
+ assertEquals(dsaKeyControl, keyInfo.getPublicKey());
}
@org.junit.Test
@@ -103,33 +103,33 @@ public class DEREncodedKeyValueResolverT
if (ecKeyControl == null) {
return;
}
-
- Document doc = loadXML("DEREncodedKeyValue-EC.xml");
- Element element = doc.getDocumentElement();
-
- KeyInfo keyInfo = new KeyInfo(element, "");
- assertEquals(ecKeyControl, keyInfo.getPublicKey());
+
+ Document doc = loadXML("DEREncodedKeyValue-EC.xml");
+ Element element = doc.getDocumentElement();
+
+ KeyInfo keyInfo = new KeyInfo(element, "");
+ assertEquals(ecKeyControl, keyInfo.getPublicKey());
}
-
+
// Utility methods
-
+
private String getControlFilePath(String fileName) {
return BASEDIR + SEP + "src" + SEP + "test" + SEP + "resources" +
- SEP + "org" + SEP + "apache" + SEP + "xml" + SEP + "security" +
- SEP + "keys" + SEP + "content" +
- SEP + fileName;
- }
-
+ SEP + "org" + SEP + "apache" + SEP + "xml" + SEP + "security" +
+ SEP + "keys" + SEP + "content" +
+ SEP + fileName;
+ }
+
private Document loadXML(String fileName) throws Exception {
- return documentBuilder.parse(new FileInputStream(getControlFilePath(fileName)));
+ return documentBuilder.parse(new FileInputStream(getControlFilePath(fileName)));
}
private PublicKey loadPublicKey(String filePath, String algorithm) throws Exception {
- String fileData = new String(JavaUtils.getBytesFromFile(getControlFilePath(filePath)));
- byte[] keyBytes = Base64.decode(fileData);
- KeyFactory kf = KeyFactory.getInstance(algorithm);
- X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
- return kf.generatePublic(keySpec);
+ String fileData = new String(JavaUtils.getBytesFromFile(getControlFilePath(filePath)));
+ byte[] keyBytes = Base64.decode(fileData);
+ KeyFactory kf = KeyFactory.getInstance(algorithm);
+ X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
+ return kf.generatePublic(keySpec);
}
}
Modified: santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/keyresolver/KeyInfoReferenceResolverTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/keyresolver/KeyInfoReferenceResolverTest.java?rev=1418419&r1=1418418&r2=1418419&view=diff
==============================================================================
--- santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/keyresolver/KeyInfoReferenceResolverTest.java (original)
+++ santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/dom/keys/keyresolver/KeyInfoReferenceResolverTest.java Fri Dec 7 18:10:49 2012
@@ -39,130 +39,130 @@ import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
public class KeyInfoReferenceResolverTest extends Assert {
-
+
private static final String BASEDIR = System.getProperty("basedir") == null ? "./": System.getProperty("basedir");
private static final String SEP = System.getProperty("file.separator");
-
+
private DocumentBuilder documentBuilder;
-
- public KeyInfoReferenceResolverTest() throws Exception {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(true);
- documentBuilder = dbf.newDocumentBuilder();
-
- if (!Init.isInitialized()) {
- Init.init();
- }
- }
-
+
+ public KeyInfoReferenceResolverTest() throws Exception {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ documentBuilder = dbf.newDocumentBuilder();
+
+ if (!Init.isInitialized()) {
+ Init.init();
+ }
+ }
+
@org.junit.Test
public void testRSAPublicKey() throws Exception {
- PublicKey rsaKeyControl = loadPublicKey("rsa-KeyInfoReference.key", "RSA");
-
- Document doc = loadXML("KeyInfoReference-RSA.xml");
- markKeyInfoIdAttrs(doc);
-
- Element referenceElement = doc.getElementById("theReference");
- assertNotNull(referenceElement);
-
- KeyInfo keyInfo = new KeyInfo(referenceElement, "");
- assertEquals(rsaKeyControl, keyInfo.getPublicKey());
+ PublicKey rsaKeyControl = loadPublicKey("rsa-KeyInfoReference.key", "RSA");
+
+ Document doc = loadXML("KeyInfoReference-RSA.xml");
+ markKeyInfoIdAttrs(doc);
+
+ Element referenceElement = doc.getElementById("theReference");
+ assertNotNull(referenceElement);
+
+ KeyInfo keyInfo = new KeyInfo(referenceElement, "");
+ assertEquals(rsaKeyControl, keyInfo.getPublicKey());
}
-
+
@org.junit.Test
public void testX509Certificate() throws Exception {
- X509Certificate certControl = loadCertificate("cert-KeyInfoReference.crt");
-
- Document doc = loadXML("KeyInfoReference-X509Certificate.xml");
- markKeyInfoIdAttrs(doc);
-
- Element referenceElement = doc.getElementById("theReference");
- assertNotNull(referenceElement);
-
- KeyInfo keyInfo = new KeyInfo(referenceElement, "");
- assertEquals(certControl, keyInfo.getX509Certificate());
- assertEquals(certControl.getPublicKey(), keyInfo.getPublicKey());
+ X509Certificate certControl = loadCertificate("cert-KeyInfoReference.crt");
+
+ Document doc = loadXML("KeyInfoReference-X509Certificate.xml");
+ markKeyInfoIdAttrs(doc);
+
+ Element referenceElement = doc.getElementById("theReference");
+ assertNotNull(referenceElement);
+
+ KeyInfo keyInfo = new KeyInfo(referenceElement, "");
+ assertEquals(certControl, keyInfo.getX509Certificate());
+ assertEquals(certControl.getPublicKey(), keyInfo.getPublicKey());
}
-
+
@org.junit.Test
public void testWrongReferentType() throws Exception {
- Document doc = loadXML("KeyInfoReference-WrongReferentType.xml");
- markKeyInfoIdAttrs(doc);
-
- // Mark the ID-ness of the bogus element so can be resolved
- NodeList nl = doc.getElementsByTagNameNS("http://www.example.org/test", "KeyInfo");
- for (int i = 0; i < nl.getLength(); i++) {
- Element keyInfoElement = (Element) nl.item(i);
- keyInfoElement.setIdAttributeNS(null, Constants._ATT_ID, true);
- }
-
- Element referenceElement = doc.getElementById("theReference");
- assertNotNull(referenceElement);
-
- KeyInfo keyInfo = new KeyInfo(referenceElement, "");
- assertNull(keyInfo.getPublicKey());
+ Document doc = loadXML("KeyInfoReference-WrongReferentType.xml");
+ markKeyInfoIdAttrs(doc);
+
+ // Mark the ID-ness of the bogus element so can be resolved
+ NodeList nl = doc.getElementsByTagNameNS("http://www.example.org/test", "KeyInfo");
+ for (int i = 0; i < nl.getLength(); i++) {
+ Element keyInfoElement = (Element) nl.item(i);
+ keyInfoElement.setIdAttributeNS(null, Constants._ATT_ID, true);
+ }
+
+ Element referenceElement = doc.getElementById("theReference");
+ assertNotNull(referenceElement);
+
+ KeyInfo keyInfo = new KeyInfo(referenceElement, "");
+ assertNull(keyInfo.getPublicKey());
}
-
+
@org.junit.Test
public void testSameDocumentReferenceChain() throws Exception {
- Document doc = loadXML("KeyInfoReference-ReferenceChain.xml");
- markKeyInfoIdAttrs(doc);
-
- Element referenceElement = doc.getElementById("theReference");
- assertNotNull(referenceElement);
-
- KeyInfo keyInfo = new KeyInfo(referenceElement, "");
- // Chains of references are not supported at this time
- assertNull(keyInfo.getPublicKey());
+ Document doc = loadXML("KeyInfoReference-ReferenceChain.xml");
+ markKeyInfoIdAttrs(doc);
+
+ Element referenceElement = doc.getElementById("theReference");
+ assertNotNull(referenceElement);
+
+ KeyInfo keyInfo = new KeyInfo(referenceElement, "");
+ // Chains of references are not supported at this time
+ assertNull(keyInfo.getPublicKey());
}
-
+
@org.junit.Test
public void testSameDocumentReferenceChainWithSecureValidation() throws Exception {
- Document doc = loadXML("KeyInfoReference-ReferenceChain.xml");
- markKeyInfoIdAttrs(doc);
-
- Element referenceElement = doc.getElementById("theReference");
- assertNotNull(referenceElement);
-
- KeyInfo keyInfo = new KeyInfo(referenceElement, "");
- keyInfo.setSecureValidation(true);
- // Chains of references are not supported at this time
- assertNull(keyInfo.getPublicKey());
+ Document doc = loadXML("KeyInfoReference-ReferenceChain.xml");
+ markKeyInfoIdAttrs(doc);
+
+ Element referenceElement = doc.getElementById("theReference");
+ assertNotNull(referenceElement);
+
+ KeyInfo keyInfo = new KeyInfo(referenceElement, "");
+ keyInfo.setSecureValidation(true);
+ // Chains of references are not supported at this time
+ assertNull(keyInfo.getPublicKey());
}
-
+
// Utility methods
-
+
private String getControlFilePath(String fileName) {
return BASEDIR + SEP + "src" + SEP + "test" + SEP + "resources" +
- SEP + "org" + SEP + "apache" + SEP + "xml" + SEP + "security" +
- SEP + "keyresolver" +
- SEP + fileName;
- }
-
+ SEP + "org" + SEP + "apache" + SEP + "xml" + SEP + "security" +
+ SEP + "keyresolver" +
+ SEP + fileName;
+ }
+
private Document loadXML(String fileName) throws Exception {
- return documentBuilder.parse(new FileInputStream(getControlFilePath(fileName)));
+ return documentBuilder.parse(new FileInputStream(getControlFilePath(fileName)));
}
private PublicKey loadPublicKey(String filePath, String algorithm) throws Exception {
- String fileData = new String(JavaUtils.getBytesFromFile(getControlFilePath(filePath)));
- byte[] keyBytes = Base64.decode(fileData);
- KeyFactory kf = KeyFactory.getInstance(algorithm);
- X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
- return kf.generatePublic(keySpec);
- }
-
- private X509Certificate loadCertificate(String fileName) throws Exception {
- FileInputStream fis = new FileInputStream(getControlFilePath(fileName));
- CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
- return (X509Certificate) certFactory.generateCertificate(fis);
- }
-
+ String fileData = new String(JavaUtils.getBytesFromFile(getControlFilePath(filePath)));
+ byte[] keyBytes = Base64.decode(fileData);
+ KeyFactory kf = KeyFactory.getInstance(algorithm);
+ X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
+ return kf.generatePublic(keySpec);
+ }
+
+ private X509Certificate loadCertificate(String fileName) throws Exception {
+ FileInputStream fis = new FileInputStream(getControlFilePath(fileName));
+ CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
+ return (X509Certificate) certFactory.generateCertificate(fis);
+ }
+
private void markKeyInfoIdAttrs(Document doc) {
- NodeList nl = doc.getElementsByTagNameNS(Constants.SignatureSpecNS, Constants._TAG_KEYINFO);
- for (int i = 0; i < nl.getLength(); i++) {
- Element keyInfoElement = (Element) nl.item(i);
- keyInfoElement.setIdAttributeNS(null, Constants._ATT_ID, true);
- }
+ NodeList nl = doc.getElementsByTagNameNS(Constants.SignatureSpecNS, Constants._TAG_KEYINFO);
+ for (int i = 0; i < nl.getLength(); i++) {
+ Element keyInfoElement = (Element) nl.item(i);
+ keyInfoElement.setIdAttributeNS(null, Constants._ATT_ID, true);
+ }
}
}