View Javadoc
1 /* 2 * $Id: AbstractElementProxy.java,v 1.14 2004/04/17 19:21:28 pelle Exp $ 3 * $Log: AbstractElementProxy.java,v $ 4 * Revision 1.14 2004/04/17 19:21:28 pelle 5 * HTMLSignature can now process an Dom4j document as well. 6 * SignedElement is now ensured that it has a Document 7 * SignedElement also now automatically uses HTMLSignature if it senses the document is html. 8 * 9 * Revision 1.13 2004/03/22 20:09:17 pelle 10 * Added simple ledger for unit testing and in memory use 11 * 12 * Revision 1.12 2004/03/19 22:21:51 pelle 13 * Changes in the XMLSignature class, which is now Abstract there are currently 3 implementations for: 14 * - Enveloped 15 * - DataObjects - (Enveloping) 16 * - Any for interop testing mainly. 17 * 18 * Revision 1.11 2004/03/02 23:30:43 pelle 19 * Renamed SignatureInfo to SignedInfo as that is the name of the Element. 20 * Made some changes in the Canonicalizer to make all the output verify in Aleksey's xmlsec library. 21 * Unfortunately this breaks example 3 of merlin-eight's canonicalization interop tests, because dom4j afaik 22 * can't tell the difference between <test/> and <test xmlns=""/>. 23 * Changed XMLSignature it is now has less repeated code. 24 * 25 * Revision 1.10 2004/02/19 00:27:59 pelle 26 * Discovered several incompatabilities with the xmlsig implementation. Have been working on getting it working. 27 * Currently there is still a problem with enveloping signatures and it seems enveloped signatures done via signers. 28 * 29 * Revision 1.9 2004/02/18 00:13:49 pelle 30 * Many, many clean ups. I've readded Targets in a new method. 31 * Gotten rid of NamedObjectBuilder and revamped Identity and Resolvers 32 * 33 * Revision 1.8 2003/12/16 15:04:49 pelle 34 * Added SignedMessage contract for signing simple textual contracts. 35 * Added NeuSender, updated SmtpSender and Sender to take plain email addresses (without the mailto:) 36 * Added AbstractObjectCreationTest to make it quicker to write unit tests to verify 37 * NamedObjectBuilder/SignedNamedObject Pairs. 38 * Sample application has been expanded with a basic email application. 39 * Updated docs for simple web app. 40 * Added missing LGPL LICENSE.txt files to signer and simple app 41 * 42 * Revision 1.7 2003/12/11 23:56:53 pelle 43 * Trying to test the ReceiverServlet with cactus. Still no luck. Need to return a ElementProxy of some sort. 44 * Cleaned up some missing fluff in the ElementProxy interface. getTagName(), getQName() and getNameSpace() have been killed. 45 * 46 * Revision 1.6 2003/12/11 16:29:19 pelle 47 * Updated various builders to use the new helper methods in AbstractElementProxy hopefully making them more readable. 48 * 49 * Revision 1.5 2003/12/11 16:16:05 pelle 50 * Some changes to make the xml a bit more readable. 51 * Also added some helper methods in AbstractElementProxy to make it easier to build objects. 52 * 53 * Revision 1.4 2003/12/10 23:57:05 pelle 54 * Did some cleaning up in the builders 55 * Fixed some stuff in IdentityCreator 56 * New maven goal to create executable jarapp 57 * We are close to 0.8 final of ID, 0.11 final of XMLSIG and 0.5 of commons. 58 * Will release shortly. 59 * 60 * Revision 1.3 2003/11/21 04:44:31 pelle 61 * EncryptedFileStore now works. It uses the PBECipher with DES3 afair. 62 * Otherwise You will Finaliate. 63 * 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. 64 * This should hopefully make everything more stable (and secure). 65 * 66 * Revision 1.2 2003/11/19 23:33:17 pelle 67 * Signers now can generatekeys via the generateKey() method. 68 * Refactored the relationship between SignedNamedObject and NamedObjectBuilder a bit. 69 * SignedNamedObject now contains the full xml which is returned with getEncoded() 70 * This means that it is now possible to further receive on or process a SignedNamedObject, leaving 71 * NamedObjectBuilder for its original purposes of purely generating new Contracts. 72 * NamedObjectBuilder.sign() now returns a SignedNamedObject which is the prefered way of processing it. 73 * Updated all major interfaces that used the old model to use the new model. 74 * 75 * Revision 1.1.1.1 2003/11/11 16:33:20 pelle 76 * Moved over from neudist.org 77 * Moved remaining common utilities into commons 78 * 79 * Revision 1.7 2003/11/09 03:27:09 pelle 80 * More house keeping and shuffling about mainly pay 81 * 82 * Revision 1.6 2003/09/26 23:52:47 pelle 83 * Changes mainly in receiver and related fun. 84 * First real neuclear stuff in the payment package. Added TransferContract and AssetControllerReceiver. 85 * 86 * Revision 1.5 2003/02/24 13:32:23 pelle 87 * Final doc changes for 0.8 88 * 89 * Revision 1.4 2003/02/24 03:26:20 pelle 90 * XMLSignature class has been tested as working for Enveloped Signatures. 91 * It is still failing verification on home grown Enveloping Signatures. 92 * It failes while checking reference validity. This means there is something strange about the Digest is initially 93 * calculated for Enveloping signatures. 94 * 95 * Revision 1.3 2003/02/14 21:13:59 pelle 96 * The AbstractElementProxy has a new final method .asXML() 97 * which is similar to DOM4J's but it outputs the xml in the compact format and not the pretty format, thus not causing problems with Canonicalization. 98 * You can now also easily get the digest of a SignedElement with the new .getEncoded() value. 99 * 100 * Revision 1.2 2003/02/11 14:47:02 pelle 101 * Added benchmarking code. 102 * DigestValue is now a required part. 103 * If you pass a keypair when you sign, you get the PublicKey included as a KeyInfo block within the signature. 104 * 105 * Revision 1.1 2003/01/18 18:12:31 pelle 106 * First Independent commit of the Independent XML-Signature API for NeuDist. 107 * 108 * Revision 1.5 2002/12/17 21:41:02 pelle 109 * First part of refactoring of SignedNamedObject and SignedObject Interface/Class parings. 110 * 111 * Revision 1.4 2002/12/17 20:34:43 pelle 112 * Lots of changes to core functionality. 113 * First of all I've refactored most of the Resolving and verification code. I have a few more things to do 114 * on it before I'm happy. 115 * There is now a NSResolver class, which handles all the namespace resolution. I took most of the functionality 116 * for this out of SignedNamedObject. 117 * Then there is the veriifer, which verifies a given SignedNamedObject using the NSResolver. 118 * This has simplified the SignedNamedObject classes drastically, leaving them as mainly data objects, which is what they 119 * should be. 120 * I have also gone around and tightened up security on many different classes, making clases and/or methods final where appropriate. 121 * NSCache now operates using http://www.waterken.com's fantastic ADT collections library. 122 * Something important has been added, which is a SignRequest named object. This signed object, embeds an unsigned 123 * named object for signing by an end users' signing service. 124 * Now were almost ready to start seriously implementing AssetIssuers and Transfers, which will be the most important 125 * part of the framework. 126 * 127 * Revision 1.3 2002/10/10 21:29:31 pelle 128 * Oops. XML-Signature's SignedInfo element I had coded as SignedInfo 129 * As I thought Canonicalisation doesnt seem to be standard. 130 * Updated the SignedServlet to default to using ~/.neuclear/signers.ks 131 * 132 * Revision 1.2 2002/09/21 23:11:16 pelle 133 * A bunch of clean ups. Got rid of as many hard coded URL's as I could. 134 * 135 * User: pelleb 136 * Date: Sep 10, 2002 137 * Time: 11:49:42 AM 138 * TODO: Replace ElementProxy Interface with AbstractElementProxy 139 140 */ 141 package org.neuclear.xml; 142 143 import org.dom4j.DocumentHelper; 144 import org.dom4j.Element; 145 import org.dom4j.Namespace; 146 import org.dom4j.QName; 147 import org.neuclear.xml.xmlsec.XMLSecTools; 148 import org.neuclear.xml.xmlsec.XMLSecurityException; 149 150 public abstract class AbstractElementProxy implements ElementProxy { 151 protected AbstractElementProxy(final String name, final String prefix, final String nsURI) { 152 this(name, DocumentHelper.createNamespace(prefix, nsURI)); 153 } 154 155 protected AbstractElementProxy(final String name, final Namespace ns) { 156 this(DocumentHelper.createQName(name, ns)); 157 } 158 159 protected AbstractElementProxy(final String name) { 160 this.element = DocumentHelper.createElement(name); 161 } 162 163 protected AbstractElementProxy(final QName qname) { 164 this.element = DocumentHelper.createElement(qname); 165 } 166 167 protected AbstractElementProxy(final Element elem) { 168 element = elem; 169 } 170 171 private final Element element; 172 173 public final Element getElement() { 174 return element; 175 } 176 177 /*** 178 * Adds another AbstractElementProxy as a child element to this Element 179 * 180 * @param child 181 */ 182 protected final Element addElement(final AbstractElementProxy child) { 183 addElement(child.getElement()); 184 return child.getElement(); 185 } 186 187 /*** 188 * Adds another Element as a child element to this Element 189 * 190 * @param child 191 */ 192 protected final Element addElement(final Element child) { 193 element.add(child); 194 addLineBreak(); 195 return element; 196 } 197 198 /*** 199 * Adds another Element with the given QName to this Element 200 * 201 * @param child 202 */ 203 protected final Element addElement(final QName child) { 204 Element element = DocumentHelper.createElement(child); 205 addElement(element); 206 return element; 207 } 208 209 /*** 210 * Adds another Element with the given name and the same Namespace as this element to this element. 211 * 212 * @param child 213 */ 214 protected final Element addElement(final String child) { 215 Element element = DocumentHelper.createElement(createQName(child)); 216 addElement(element); 217 return element; 218 } 219 220 /*** 221 * Adds another Element with the given name and the same Namespace as this element to this element. 222 * 223 * @param child 224 */ 225 protected final Element addElement(final String child, final String text) { 226 Element elem = addElement(child); 227 elem.addText(text); 228 return elem; 229 } 230 231 /*** 232 * Creates a QName in this object namespace 233 * 234 * @param child 235 * @return 236 */ 237 protected final QName createQName(final String child) { 238 return DocumentHelper.createQName(child, this.element.getNamespace()); 239 } 240 241 /*** 242 * Adds a linebreak to the xml, making it easier to read for humans 243 */ 244 protected final void addLineBreak() { 245 element.addText("\n"); 246 } 247 248 /*** 249 * Adds an attribute with the same namespace as the elment 250 * 251 * @param name 252 * @param value 253 */ 254 protected final void createAttribute(String name, String value) { 255 element.addAttribute(createQName(name), value); 256 } 257 258 /* 259 public final QName getQName() { 260 return element.getQName(); 261 } 262 */ 263 264 public final String asXML() throws XMLException { 265 return XMLTools.asXML(element); 266 } 267 268 public byte[] canonicalize() throws XMLSecurityException { 269 return XMLSecTools.canonicalize(element); 270 } 271 /* 272 273 public final String getTagName() { 274 return element.getName(); 275 } 276 277 public final Namespace getNS() { 278 return element.getNamespace(); 279 } 280 */ 281 282 static final Namespace XMLNS = DocumentHelper.createNamespace("xmlns", "http://www.w3.org/XML/1998/namespace"); 283 284 }

This page was automatically generated by Maven