You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by mu...@apache.org on 2007/12/20 20:01:18 UTC

svn commit: r605998 - /xml/security/trunk/src_unitTests/org/apache/xml/security/test/encryption/XMLCipherTester.java

Author: mullan
Date: Thu Dec 20 11:01:16 2007
New Revision: 605998

URL: http://svn.apache.org/viewvc?rev=605998&view=rev
Log:
Add test for bug 44102: XMLCipher loadEncryptedKey error

Modified:
    xml/security/trunk/src_unitTests/org/apache/xml/security/test/encryption/XMLCipherTester.java

Modified: xml/security/trunk/src_unitTests/org/apache/xml/security/test/encryption/XMLCipherTester.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src_unitTests/org/apache/xml/security/test/encryption/XMLCipherTester.java?rev=605998&r1=605997&r2=605998&view=diff
==============================================================================
--- xml/security/trunk/src_unitTests/org/apache/xml/security/test/encryption/XMLCipherTester.java (original)
+++ xml/security/trunk/src_unitTests/org/apache/xml/security/test/encryption/XMLCipherTester.java Thu Dec 20 11:01:16 2007
@@ -1,5 +1,5 @@
 /*
- * Copyright  1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2007 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -53,7 +53,7 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
-
+import org.w3c.dom.NodeList;
 
 /**
  *
@@ -62,7 +62,7 @@
  */
 public class XMLCipherTester extends TestCase {
 
-	/** {@link org.apache.commons.logging} logging facility */
+    /** {@link org.apache.commons.logging} logging facility */
     static org.apache.commons.logging.Log log = 
         org.apache.commons.logging.LogFactory.getLog(XMLCipherTester.class.getName());
     
@@ -70,18 +70,17 @@
     private String elementName;
     private String elementIndex;
     private XMLCipher cipher;
-
-	private boolean haveISOPadding;
-	private boolean haveKeyWraps;
-
-	private String tstBase64EncodedString;
+    private String basedir;
+    private boolean haveISOPadding;
+    private boolean haveKeyWraps;
+    private String tstBase64EncodedString;
 
     public XMLCipherTester(String test) {
        super(test);
     }
 
     protected void setUp() {
-        String basedir = System.getProperty("basedir",".");
+        basedir = System.getProperty("basedir",".");
         documentName = System.getProperty("org.apache.xml.enc.test.doc",
             basedir + "/build.xml");
         elementName = System.getProperty("org.apache.xml.enc.test.elem",
@@ -709,23 +708,49 @@
             (d, null, new ByteArrayInputStream(serialized));
     }
 
-	private String toString (Node n)
-		throws Exception {
+    public void testEncryptedKeyWithRecipient() throws Exception {
 
-		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		Canonicalizer c14n = Canonicalizer.getInstance
-			(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
-
-		byte[] serBytes = c14n.canonicalizeSubtree(n);
-		baos.write(serBytes);
-		baos.close();
+	String filename = 
+	    "data/org/apache/xml/security/encryption/encryptedKey.xml";
+        if (basedir != null && !"".equals(basedir)) {
+            filename = basedir + "/" + filename;
+        }
+        File f = new File(filename);
+        
+        DocumentBuilderFactory builderFactory = 
+	    DocumentBuilderFactory.newInstance();
+        builderFactory.setNamespaceAware (true);
+        DocumentBuilder builder = builderFactory.newDocumentBuilder();
+        Document document = builder.parse(f); 
+        
+        XMLCipher keyCipher = XMLCipher.getInstance();
+        keyCipher.init(XMLCipher.UNWRAP_MODE, null);
+        
+        NodeList ekList = document.getElementsByTagNameNS
+	    (EncryptionConstants.EncryptionSpecNS, 
+	     EncryptionConstants._TAG_ENCRYPTEDKEY);
+        for (int i = 0; i < ekList.getLength(); i++) {
+            EncryptedKey ek = keyCipher.loadEncryptedKey
+		(document, (Element) ekList.item(i));
+	    assertNotNull(ek.getRecipient());
+        }
+    }
 
-		return baos.toString("UTF-8");
+    private String toString (Node n) throws Exception {
 
-	}
-		
-   static {
-      org.apache.xml.security.Init.init();
-   }
+	ByteArrayOutputStream baos = new ByteArrayOutputStream();
+	Canonicalizer c14n = Canonicalizer.getInstance
+	    (Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
+
+	byte[] serBytes = c14n.canonicalizeSubtree(n);
+	baos.write(serBytes);
+	baos.close();
+
+	return baos.toString("UTF-8");
 
+    }
+		
+    static {
+	org.apache.xml.security.Init.init();
+    }
 }