Update of /cvsroot/neuclear/neuclear-xmlsig/src/java/org/neuclear/xml/transforms In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23732/src/java/org/neuclear/xml/transforms Modified Files: TransformerFactory.java XPathTransform.java Added Files: EnvelopedSignatureTransform.java Removed Files: DropSignatureTransform.java Log Message: More improvements on the XMLSignature. Now uses the Transforms properly, References properly. All the major elements have been refactored to be cleaner and more correct. --- NEW FILE: EnvelopedSignatureTransform.java --- package org.neuclear.xml.transforms; /** * (C) 2003 Antilles Software Ventures SA * User: pelleb * Date: Jan 27, 2003 * Time: 10:02:07 AM * $Id: EnvelopedSignatureTransform.java,v 1.1 2004/03/08 23:51:03 pelle Exp $ * $Log: EnvelopedSignatureTransform.java,v $ * Revision 1.1 2004/03/08 23:51:03 pelle * More improvements on the XMLSignature. Now uses the Transforms properly, References properly. * All the major elements have been refactored to be cleaner and more correct. * * Revision 1.4 2004/02/19 19:37:34 pelle * At times IntelliJ IDEA can cause some real hassle. On my last checkin it optimized away all of the dom4j and command line imports. * We'll now, Ive added them all back. * * Revision 1.3 2004/02/19 15:30:08 pelle * Various cleanups and corrections * * Revision 1.2 2003/11/21 04:44:30 pelle * EncryptedFileStore now works. It uses the PBECipher with DES3 afair. * Otherwise You will Finaliate. * Anything that can be final has been made final throughout everyting. We've used IDEA's Inspector tool to find all instance of variables that could be final. * This should hopefully make everything more stable (and secure). * * Revision 1.1.1.1 2003/11/11 16:33:24 pelle * Moved over from neudist.org * Moved remaining common utilities into commons * * Revision 1.3 2003/02/22 16:54:29 pelle * Major structural changes in the whole processing framework. * Verification now supports Enveloping and detached signatures. * The reference element is a lot more important at the moment and handles much of the logic. * Replaced homegrown Base64 with Blackdowns. * Still experiencing problems with decoding foreign signatures. I reall dont understand it. I'm going to have * to reread the specs a lot more and study other implementations sourcecode. * * Revision 1.2 2003/02/11 14:50:09 pelle * Trying onemore time. Added the benchmarking code. * Now generates DigestValue and optionally adds KeyInfo to Signature. * * Revision 1.1 2003/02/01 01:48:17 pelle * Fixed the XPath Transform. * Has the beginning of a processing framework for the Reference class. * */ import org.dom4j.Element; import org.neuclear.xml.xmlsec.XMLSecurityException; public final class EnvelopedSignatureTransform extends XPathTransform { public EnvelopedSignatureTransform() { super(ALGORITHM, XPATH); } public EnvelopedSignatureTransform(final Element elem) throws XMLSecurityException { super(elem); } public static final String ALGORITHM = "http://www.w3.org/2000/09/xmldsig#enveloped-signature"; public static final String XPATH = "(//. | //@* | //namespace::*| self::processing-instruction())[not(self::ds:Signature)]"; { TransformerFactory.registerTransformer(ALGORITHM, EnvelopedSignatureTransform.class); } } Index: TransformerFactory.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-xmlsig/src/java/org/neuclear/xml/transforms/TransformerFactory.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TransformerFactory.java 21 Nov 2003 04:44:30 -0000 1.2 --- TransformerFactory.java 8 Mar 2004 23:51:03 -0000 1.3 *************** *** 5,10 **** import org.neuclear.xml.c14.CanonicalizerWithComments; - import java.lang.reflect.Constructor; - import java.lang.reflect.InvocationTargetException; import java.util.HashMap; --- 5,8 ---- *************** *** 18,55 **** public final class TransformerFactory { ! public static final Transform make(final Element elem) throws XMLTransformNotFoundException{ ! if (elem==null) throw new XMLTransformNotFoundException("The Transform element was emtpy"); ! final String name=elem.attributeValue("Algorithm"); ! final Class imp=(Class)instance().implementations.get(name); ! if (imp==null) ! throw new XMLTransformNotFoundException("The Transform: "+name+" wasnt found"); ! final Class[] params= new Class[] { Element.class}; try { ! final Constructor constructor=imp.getConstructor(params); ! return (Transform)constructor.newInstance(new Element[] {elem}); ! } catch (NoSuchMethodException e) { ! e.printStackTrace(); //To change body of catch statement use Options | File Templates. ! } catch (SecurityException e) { ! e.printStackTrace(); //To change body of catch statement use Options | File Templates. } catch (InstantiationException e) { ! e.printStackTrace(); //To change body of catch statement use Options | File Templates. } catch (IllegalAccessException e) { ! e.printStackTrace(); //To change body of catch statement use Options | File Templates. ! } catch (InvocationTargetException e) { ! e.printStackTrace(); //To change body of catch statement use Options | File Templates. } - return null; } public static final Transform make(final String algorithm) throws XMLTransformNotFoundException { ! final Class imp=(Class)instance().implementations.get(algorithm); ! if (imp==null) { ! throw new XMLTransformNotFoundException("The Transform: "+algorithm+" wasnt found"); } try { ! return (Transform)imp.newInstance(); } catch (SecurityException e) { e.printStackTrace(); //To change body of catch statement use Options | File Templates. --- 16,45 ---- public final class TransformerFactory { ! public static final Transform make(final Element elem) throws XMLTransformNotFoundException { ! if (elem == null) throw new XMLTransformNotFoundException("The Transform element was emtpy"); ! final String name = elem.attributeValue("Algorithm"); ! final Class imp = (Class) instance().implementations.get(name); ! if (imp == null) ! throw new XMLTransformNotFoundException("The Transform: " + name + " wasnt found"); try { ! return (Transform) imp.newInstance(); } catch (InstantiationException e) { ! e.printStackTrace(); } catch (IllegalAccessException e) { ! e.printStackTrace(); } return null; } + public static final Transform make(final String algorithm) throws XMLTransformNotFoundException { ! final Class imp = (Class) instance().implementations.get(algorithm); ! if (imp == null) { ! throw new XMLTransformNotFoundException("The Transform: " + algorithm + " wasnt found"); } try { ! return (Transform) imp.newInstance(); } catch (SecurityException e) { e.printStackTrace(); //To change body of catch statement use Options | File Templates. *************** *** 65,86 **** public static final void registerTransformer(final String algorithm, final Class implementation) { ! instance().implementations.put(algorithm,implementation); } ! private TransformerFactory () { ! implementations=new HashMap(); } private static synchronized TransformerFactory instance() { ! if (singleton==null) { ! singleton=new TransformerFactory(); ! registerTransformer(DropSignatureTransform.ALGORITHM,DropSignatureTransform.class); ! registerTransformer(Canonicalizer.ALGORITHM,Canonicalizer.class); ! registerTransformer(CanonicalizerWithComments.ALGORITHM,CanonicalizerWithComments.class); ! registerTransformer(ClearTransform.ALGORITHM,ClearTransform.class); ! registerTransformer(OpaqueTransform.ALGORITHM,OpaqueTransform.class); } return singleton; } private final HashMap implementations; private static TransformerFactory singleton; --- 55,77 ---- public static final void registerTransformer(final String algorithm, final Class implementation) { ! instance().implementations.put(algorithm, implementation); } ! private TransformerFactory() { ! implementations = new HashMap(); } private static synchronized TransformerFactory instance() { ! if (singleton == null) { ! singleton = new TransformerFactory(); ! registerTransformer(EnvelopedSignatureTransform.ALGORITHM, EnvelopedSignatureTransform.class); ! registerTransformer(Canonicalizer.ALGORITHM, Canonicalizer.class); ! registerTransformer(CanonicalizerWithComments.ALGORITHM, CanonicalizerWithComments.class); ! registerTransformer(ClearTransform.ALGORITHM, ClearTransform.class); ! registerTransformer(OpaqueTransform.ALGORITHM, OpaqueTransform.class); } return singleton; } + private final HashMap implementations; private static TransformerFactory singleton; *************** *** 88,94 **** // This is just to make sure that they register themselves static { ! Class touch=DropSignatureTransform.class; ! touch=Canonicalizer.class; ! touch=CanonicalizerWithComments.class; } --- 79,85 ---- // This is just to make sure that they register themselves static { ! Class touch = EnvelopedSignatureTransform.class; ! touch = Canonicalizer.class; ! touch = CanonicalizerWithComments.class; } Index: XPathTransform.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-xmlsig/src/java/org/neuclear/xml/transforms/XPathTransform.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** XPathTransform.java 19 Feb 2004 19:37:34 -0000 1.4 --- XPathTransform.java 8 Mar 2004 23:51:03 -0000 1.5 *************** *** 1,7 **** package org.neuclear.xml.transforms; import org.neuclear.xml.xmlsec.XMLSecTools; import org.neuclear.xml.xmlsec.XMLSecurityException; ! import org.dom4j.*; import java.util.HashMap; import java.util.List; --- 1,8 ---- package org.neuclear.xml.transforms; + import org.dom4j.*; import org.neuclear.xml.xmlsec.XMLSecTools; import org.neuclear.xml.xmlsec.XMLSecurityException; ! import java.util.HashMap; import java.util.List; *************** *** 30,33 **** --- 31,40 ---- } + protected XPathTransform(final String algorithm, final String xpath) { + super(algorithm); + // this.xpath=xpath; + setXPath(xpath); + } + private void setXPath(final String xpath) { // XPathFilter=DocumentHelper.createXPath(xpath); --- DropSignatureTransform.java DELETED --- |