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 2014/10/15 11:29:05 UTC
svn commit: r1631979 - 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/
test/java/org/apache/xml/security/test/encryption/
Author: coheigea
Date: Wed Oct 15 09:29:04 2014
New Revision: 1631979
URL: http://svn.apache.org/r1631979
Log:
[SANTUARIO-403] - Support EncryptionProperty child elements
Modified:
santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/c14n/implementations/CanonicalizerBase.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/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/CanonicalizerBase.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/CanonicalizerBase.java?rev=1631979&r1=1631978&r2=1631979&view=diff
==============================================================================
--- santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/c14n/implementations/CanonicalizerBase.java (original)
+++ santuario/xml-security-java/branches/1.5.x-fixes/src/main/java/org/apache/xml/security/c14n/implementations/CanonicalizerBase.java Wed Oct 15 09:29:04 2014
@@ -239,7 +239,7 @@ public abstract class CanonicalizerBase
protected final void canonicalizeSubTree(
Node currentNode, NameSpaceSymbTable ns, Node endnode, int documentLevel
) throws CanonicalizationException, IOException {
- if (isVisibleInt(currentNode) == -1) {
+ if (currentNode == null || isVisibleInt(currentNode) == -1) {
return;
}
Node sibling = null;
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=1631979&r1=1631978&r2=1631979&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 Wed Oct 15 09:29:04 2014
@@ -2286,7 +2286,6 @@ public class XMLCipher {
result.setKeyInfo(ki);
}
- // TODO: Implement
Element encryptionPropertiesElement =
(Element) element.getElementsByTagNameNS(
EncryptionConstants.EncryptionSpecNS,
@@ -3368,8 +3367,19 @@ public class XMLCipher {
if (null != id) {
result.setAttributeNS(null, EncryptionConstants._ATT_ID, id);
}
- // TODO: figure out the anyAttribyte stuff...
- // TODO: figure out the any stuff...
+
+ if (!attributeMap.isEmpty()) {
+ for (String attribute : attributeMap.keySet()) {
+ result.setAttributeNS(Constants.XML_LANG_SPACE_SpecNS,
+ attribute, attributeMap.get(attribute));
+ }
+ }
+
+ if (!encryptionInformation.isEmpty()) {
+ for (Element element : encryptionInformation) {
+ result.appendChild(element);
+ }
+ }
return result;
}
Modified: santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/encryption/XMLCipherTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/encryption/XMLCipherTest.java?rev=1631979&r1=1631978&r2=1631979&view=diff
==============================================================================
--- santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/encryption/XMLCipherTest.java (original)
+++ santuario/xml-security-java/branches/1.5.x-fixes/src/test/java/org/apache/xml/security/test/encryption/XMLCipherTest.java Wed Oct 15 09:29:04 2014
@@ -39,6 +39,8 @@ import javax.xml.parsers.DocumentBuilder
import org.apache.xml.security.algorithms.JCEMapper;
import org.apache.xml.security.c14n.Canonicalizer;
+import org.apache.xml.security.encryption.EncryptionProperties;
+import org.apache.xml.security.encryption.EncryptionProperty;
import org.apache.xml.security.encryption.XMLCipher;
import org.apache.xml.security.encryption.EncryptedData;
import org.apache.xml.security.encryption.EncryptedKey;
@@ -555,6 +557,64 @@ public class XMLCipherTest extends org.j
);
}
}
+
+ @org.junit.Test
+ public void testEncryptionProperties() throws Exception {
+ Document d = document(); // source
+ Document ed = null; // target
+ Document dd = null; // target
+ Element e = d.getDocumentElement();
+ Element ee = null;
+
+ String source = null;
+ String target = null;
+
+ if (haveISOPadding) {
+ source = toString(d);
+
+ // prepare for encryption
+ byte[] passPhrase = "24 Bytes per DESede key!".getBytes();
+ DESedeKeySpec keySpec = new DESedeKeySpec(passPhrase);
+ SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
+ SecretKey key = keyFactory.generateSecret(keySpec);
+
+ // encrypt
+ cipher = XMLCipher.getInstance(XMLCipher.TRIPLEDES);
+ cipher.init(XMLCipher.ENCRYPT_MODE, key);
+
+ // Add EncryptionProperties
+ Element elem = d.createElement("CustomInformation");
+ elem.setTextContent("Some text content");
+
+ EncryptionProperties eps = cipher.createEncryptionProperties();
+ EncryptionProperty ep = cipher.createEncryptionProperty();
+ ep.addEncryptionInformation(elem);
+ ep.setId("_124124");
+ ep.setTarget("http://localhost/");
+ ep.setAttribute("xml:lang", "en");
+ eps.addEncryptionProperty(ep);
+
+ EncryptedData encData = cipher.getEncryptedData();
+ encData.setEncryptionProperties(eps);
+
+ ed = cipher.doFinal(d, e);
+ // XMLUtils.outputDOM(ed, System.out);
+
+ //decrypt
+ cipher = XMLCipher.getInstance(XMLCipher.TRIPLEDES);
+ cipher.init(XMLCipher.DECRYPT_MODE, key);
+ ee = (Element) ed.getElementsByTagName("xenc:EncryptedData").item(0);
+ dd = cipher.doFinal(ed, ee);
+
+ target = toString(dd);
+ assertEquals(source, target);
+ } else {
+ log.warn(
+ "Test testTripleDesDocumentCipher skipped as "
+ + "necessary algorithms not available"
+ );
+ }
+ }
/*
* Test a Cipher Reference