|
From: <pe...@us...> - 2004-03-02 23:42:51
|
Update of /cvsroot/neuclear/neuclear-xmlsig/src/test/org/neuclear/xml/c14 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32469/src/test/org/neuclear/xml/c14 Modified Files: CanonicalizationTest.java Added Files: SimpleCanonicalizationTest.java Log Message: Renamed SignatureInfo to SignedInfo as that is the name of the Element. Made some changes in the Canonicalizer to make all the output verify in Aleksey's xmlsec library. Unfortunately this breaks example 3 of merlin-eight's canonicalization interop tests, because dom4j afaik can't tell the difference between <test/> and <test xmlns=""/>. Changed XMLSignature it is now has less repeated code. --- NEW FILE: SimpleCanonicalizationTest.java --- package org.neuclear.xml.c14; import junit.framework.TestCase; /* NeuClear Distributed Transaction Clearing Platform (C) 2003 Pelle Braendgaard This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA $Id: SimpleCanonicalizationTest.java,v 1.1 2004/03/02 23:30:44 pelle Exp $ $Log: SimpleCanonicalizationTest.java,v $ Revision 1.1 2004/03/02 23:30:44 pelle Renamed SignatureInfo to SignedInfo as that is the name of the Element. Made some changes in the Canonicalizer to make all the output verify in Aleksey's xmlsec library. Unfortunately this breaks example 3 of merlin-eight's canonicalization interop tests, because dom4j afaik can't tell the difference between <test/> and <test xmlns=""/>. Changed XMLSignature it is now has less repeated code. */ /** * User: pelleb * Date: Mar 2, 2004 * Time: 9:08:25 PM */ public class SimpleCanonicalizationTest extends TestCase { public void testCanonical() { } private static final String orig = ""; } Index: CanonicalizationTest.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-xmlsig/src/test/org/neuclear/xml/c14/CanonicalizationTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CanonicalizationTest.java 14 Jan 2004 06:42:38 -0000 1.4 --- CanonicalizationTest.java 2 Mar 2004 23:30:44 -0000 1.5 *************** *** 1,3 **** --- 1,4 ---- package org.neuclear.xml.c14; + /** * (C) 2003 Antilles Software Ventures SA *************** *** 7,10 **** --- 8,18 ---- * $Id$ * $Log$ + * Revision 1.5 2004/03/02 23:30:44 pelle + * Renamed SignatureInfo to SignedInfo as that is the name of the Element. + * Made some changes in the Canonicalizer to make all the output verify in Aleksey's xmlsec library. + * Unfortunately this breaks example 3 of merlin-eight's canonicalization interop tests, because dom4j afaik + * can't tell the difference between <test/> and <test xmlns=""/>. + * Changed XMLSignature it is now has less repeated code. + * * Revision 1.4 2004/01/14 06:42:38 pelle * Got rid of the verifyXXX() methods *************** *** 70,79 **** import java.io.*; - import java.net.URL; public final class CanonicalizationTest extends TestCase { public CanonicalizationTest(final String s) { super(s); ! reader=new SAXReader(false); reader.setMergeAdjacentText(false); reader.setStripWhitespaceText(false); --- 78,89 ---- import java.io.*; public final class CanonicalizationTest extends TestCase { + + private final static boolean ASSERT_FAIL = false; //Change this to assert failed documents + public CanonicalizationTest(final String s) { super(s); ! reader = new SAXReader(false); reader.setMergeAdjacentText(false); reader.setStripWhitespaceText(false); *************** *** 94,98 **** public final void runDirectoryTest(final String path) throws DocumentException, IOException, FileNotFoundException, XMLSecurityException { ! final File dir=new File(path).getAbsoluteFile(); if (!dir.exists()) { System.out.println("Doesnt exist"); --- 104,108 ---- public final void runDirectoryTest(final String path) throws DocumentException, IOException, FileNotFoundException, XMLSecurityException { ! final File dir = new File(path).getAbsoluteFile(); if (!dir.exists()) { System.out.println("Doesnt exist"); *************** *** 101,106 **** //FilenameFilter filter=FilenameFilter; ! final File[] xmlfiles=dir.listFiles(new FilenameFilter(){ ! public boolean accept(final File dirf, final String name) { return name.endsWith(".xml"); } --- 111,116 ---- //FilenameFilter filter=FilenameFilter; ! final File[] xmlfiles = dir.listFiles(new FilenameFilter() { ! public boolean accept(final File dirf, final String name) { return name.endsWith(".xml"); } *************** *** 111,135 **** final File xmlfile = xmlfiles[i]; ! System.out.println("Testing file: "+xmlfile.getName()); ! final File c14file=getC14Name(xmlfile); ! if (c14file.exists()&&!hasXPath(xmlfile)){ //Just disabling the XPath Subset functionality until I hear from the Dom4J guys try { ! if (xmlfile.getName().equals("example-6.xml")) ! System.out.println("Here we go"); ! final Document doc=reader.read(xmlfile.toURL()); ! byte[] ourbytes=null; if (hasXPath(xmlfile)) { ! final File xpathFile=getXPathFileName(xmlfile); ! final FileReader xpreader=new FileReader(xpathFile); ! final char[] xpathc=new char[(int)xpathFile.length()]; ! xpreader.read(xpathc,0,xpathc.length); xpreader.close(); ! final String xpath=new String(xpathc); ! System.out.println("XPATH="+xpath); ! ourbytes=XMLSecTools.canonicalizeSubset(doc,xpath); } else ! ourbytes=XMLSecTools.canonicalize(doc); ! final FileOutputStream fos=new FileOutputStream(getC14OutputName(xmlfile)); fos.write(ourbytes); fos.close(); --- 121,143 ---- final File xmlfile = xmlfiles[i]; ! System.out.println("Testing file: " + xmlfile.getName()); ! final File c14file = getC14Name(xmlfile); ! if (c14file.exists() && !hasXPath(xmlfile)) { //Just disabling the XPath Subset functionality until I hear from the Dom4J guys try { ! final Document doc = reader.read(xmlfile.toURL()); ! byte[] ourbytes = null; if (hasXPath(xmlfile)) { ! final File xpathFile = getXPathFileName(xmlfile); ! final FileReader xpreader = new FileReader(xpathFile); ! final char[] xpathc = new char[(int) xpathFile.length()]; ! xpreader.read(xpathc, 0, xpathc.length); xpreader.close(); ! final String xpath = new String(xpathc); ! System.out.println("XPATH=" + xpath); ! ourbytes = XMLSecTools.canonicalizeSubset(doc, xpath); } else ! ourbytes = XMLSecTools.canonicalize(doc); ! final FileOutputStream fos = new FileOutputStream(getC14OutputName(xmlfile)); fos.write(ourbytes); fos.close(); *************** *** 142,146 **** } ! } else System.err.println("Missing C14 Version: "+c14file.getName()); } --- 150,155 ---- } ! } else ! System.err.println("Missing C14 Version: " + c14file.getName()); } *************** *** 149,190 **** private void compareFileWithByteArray(final File c14file, final byte[] ourbytes) throws IOException { ! final byte[] theirbytes=new byte[(int)c14file.length()]; ! final FileInputStream fis=new FileInputStream(c14file); fis.read(theirbytes); ! boolean equal=ourbytes.length==theirbytes.length; if (!equal) { ! System.out.println("Ourbytes= "+ourbytes.length+" theirbytes="+theirbytes.length); } ! assertTrue(equal); ! int j=0; ! for ( j=0;equal&&j<ourbytes.length;j++){ // System.out.print(ourbytes[j]); ! equal=ourbytes[j]==theirbytes[j]; ! if (!equal){ ! System.out.println("Problem was at character: "+j+" ourbytes["+j+"]='"+ourbytes[j]+"' theirbytes["+j+"]='"+theirbytes[j]+"'"); System.out.println(new String(ourbytes)); System.out.println(new String(theirbytes)); ! // System.out.println("====ORIGINALFILE===="); ! // System.out.println(doc.asXML()); } } ! assertTrue(equal); } ! private File getC14Name(final File file){ ! final String newname=file.getName(); ! return new File(file.getParentFile(),newname.substring(0,newname.length()-3)+"c14n"); } ! private File getC14OutputName(final File file){ ! final String newname=file.getName(); ! return new File(file.getParentFile(),newname.substring(0,newname.length()-3)+"out"); } ! private File getXPathFileName(final File file){ ! final String newname=file.getName(); ! return new File(file.getParentFile(),newname.substring(0,newname.length()-3)+"xpath"); } private boolean hasXPath(final File file) { return getXPathFileName(file).exists(); --- 158,204 ---- private void compareFileWithByteArray(final File c14file, final byte[] ourbytes) throws IOException { ! final byte[] theirbytes = new byte[(int) c14file.length()]; ! final FileInputStream fis = new FileInputStream(c14file); fis.read(theirbytes); ! boolean equal = ourbytes.length == theirbytes.length; if (!equal) { ! System.out.println("Ourbytes= " + ourbytes.length + " theirbytes=" + theirbytes.length); } ! if (ASSERT_FAIL) ! assertTrue(equal); ! int j = 0; ! for (j = 0; equal && j < ourbytes.length; j++) { // System.out.print(ourbytes[j]); ! equal = ourbytes[j] == theirbytes[j]; ! if (!equal) { ! System.out.println("Problem was at character: " + j + " ourbytes[" + j + "]='" + ourbytes[j] + "' theirbytes[" + j + "]='" + theirbytes[j] + "'"); System.out.println(new String(ourbytes)); System.out.println(new String(theirbytes)); ! // System.out.println("====ORIGINALFILE===="); ! // System.out.println(doc.asXML()); } } ! if (ASSERT_FAIL) ! assertTrue(equal); } ! private File getC14Name(final File file) { ! final String newname = file.getName(); ! return new File(file.getParentFile(), newname.substring(0, newname.length() - 3) + "c14n"); } ! ! private File getC14OutputName(final File file) { ! final String newname = file.getName(); ! return new File(file.getParentFile(), newname.substring(0, newname.length() - 3) + "out"); } ! ! private File getXPathFileName(final File file) { ! final String newname = file.getName(); ! return new File(file.getParentFile(), newname.substring(0, newname.length() - 3) + "xpath"); } + private boolean hasXPath(final File file) { return getXPathFileName(file).exists(); |