|
From: <pe...@us...> - 2003-11-19 23:34:00
|
Update of /cvsroot/neuclear/neuclear-xmlsig/src/java/org/neuclear/xml/xmlsec In directory sc8-pr-cvs1:/tmp/cvs-serv12757/src/java/org/neuclear/xml/xmlsec Modified Files: Reference.java SignedElement.java XMLSignature.java Log Message: Signers now can generatekeys via the generateKey() method. Refactored the relationship between SignedNamedObject and NamedObjectBuilder a bit. SignedNamedObject now contains the full xml which is returned with getEncoded() This means that it is now possible to further send on or process a SignedNamedObject, leaving NamedObjectBuilder for its original purposes of purely generating new Contracts. NamedObjectBuilder.sign() now returns a SignedNamedObject which is the prefered way of processing it. Updated all major interfaces that used the old model to use the new model. Index: Reference.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-xmlsig/src/java/org/neuclear/xml/xmlsec/Reference.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Reference.java 11 Nov 2003 16:33:26 -0000 1.1.1.1 --- Reference.java 19 Nov 2003 23:33:17 -0000 1.2 *************** *** 1,4 **** --- 1,13 ---- /* $Id$ * $Log$ + * Revision 1.2 2003/11/19 23:33:17 pelle + * Signers now can generatekeys via the generateKey() method. + * Refactored the relationship between SignedNamedObject and NamedObjectBuilder a bit. + * SignedNamedObject now contains the full xml which is returned with getEncoded() + * This means that it is now possible to further send on or process a SignedNamedObject, leaving + * NamedObjectBuilder for its original purposes of purely generating new Contracts. + * NamedObjectBuilder.sign() now returns a SignedNamedObject which is the prefered way of processing it. + * Updated all major interfaces that used the old model to use the new model. + * * Revision 1.1.1.1 2003/11/11 16:33:26 pelle * Moved over from neudist.org *************** *** 43,47 **** * * Revision 1.7 2003/02/16 00:24:21 pelle ! * getDigest() was broken in Reference.java * * Revision 1.6 2003/02/11 14:50:24 pelle --- 52,56 ---- * * Revision 1.7 2003/02/16 00:24:21 pelle ! * getEncoded() was broken in Reference.java * * Revision 1.6 2003/02/11 14:50:24 pelle *************** *** 93,100 **** import org.dom4j.Element; import org.neuclear.commons.crypto.Base64; - import org.neuclear.commons.crypto.CryptoTools; import org.neuclear.commons.crypto.CryptoException; ! import org.neuclear.commons.Utility; import org.neuclear.xml.XMLException; import org.neuclear.xml.XMLTools; --- 102,109 ---- import org.dom4j.Element; + import org.neuclear.commons.Utility; import org.neuclear.commons.crypto.Base64; import org.neuclear.commons.crypto.CryptoException; ! import org.neuclear.commons.crypto.CryptoTools; import org.neuclear.xml.XMLException; import org.neuclear.xml.XMLTools; *************** *** 102,108 **** import org.neuclear.xml.c14.CanonicalizerWithComments; import org.neuclear.xml.c14.CanonicalizerWithoutSignature; - import org.neuclear.xml.transforms.ClearTransform; import org.neuclear.xml.transforms.Transform; - import org.neuclear.xml.transforms.TransformerFactory; import java.io.File; --- 111,115 ---- *************** *** 116,132 **** * Currently only RSA */ ! public Reference(Element root, String uri,SignatureInfo si,int sigtype) throws XMLException { super(Reference.TAG_NAME); this.root = root; ! this.si=si; ! xmlsigType=sigtype; // findRefElement(); ! if (root==null) loadReference(uri); ! if (getSigType()==XMLSIGTYPE_ENVELOPED) addTransform("http://www.w3.org/2000/09/xmldsig#enveloped-signature"); ! else if (getSigType()==XMLSIGTYPE_ENVELOPING) { ! root=si.getSig().getElement().element("Object"); // System.out.println(new String(canonicalizeReference()));// Just debugging here } --- 123,139 ---- * Currently only RSA */ ! public Reference(Element root, String uri, SignatureInfo si, int sigtype) throws XMLException { super(Reference.TAG_NAME); this.root = root; ! this.si = si; ! xmlsigType = sigtype; // findRefElement(); ! if (root == null) loadReference(uri); ! if (getSigType() == XMLSIGTYPE_ENVELOPED) addTransform("http://www.w3.org/2000/09/xmldsig#enveloped-signature"); ! else if (getSigType() == XMLSIGTYPE_ENVELOPING) { ! root = si.getSig().getElement().element("Object"); // System.out.println(new String(canonicalizeReference()));// Just debugging here } *************** *** 139,147 **** } ! public Reference(Element elem,SignatureInfo si) throws XMLSecurityException { super(elem); if (!elem.getQName().getName().equals(TAG_NAME)) throw new XMLSecurityException("Element: " + elem.getQualifiedName() + " is not a valid: " + XMLSecTools.NS_DS.getPrefix() + ":" + TAG_NAME); ! this.si=si; // Here we will try to get work out Root findRefElement(); --- 146,154 ---- } ! public Reference(Element elem, SignatureInfo si) throws XMLSecurityException { super(elem); if (!elem.getQName().getName().equals(TAG_NAME)) throw new XMLSecurityException("Element: " + elem.getQualifiedName() + " is not a valid: " + XMLSecTools.NS_DS.getPrefix() + ":" + TAG_NAME); ! this.si = si; // Here we will try to get work out Root findRefElement(); *************** *** 153,169 **** Element objectElem = sigElement.element(XMLSecTools.createQName("Object")); ! if (objectElem!=null) { // Enveloping ! xmlsigType=XMLSIGTYPE_ENVELOPING; ! List contents=objectElem.content(); ! if (contents.size()==1) ! root=contents.get(0); else ! root=contents; ! root=objectElem; } else if (sigElement.getParent() != null) { // Enveloped ! xmlsigType=XMLSIGTYPE_ENVELOPED; root = getElement().getDocument(); ! } else {// Detached ! xmlsigType=XMLSIGTYPE_DETACHED; loadReference(getElement().attributeValue("URI")); } --- 160,176 ---- Element objectElem = sigElement.element(XMLSecTools.createQName("Object")); ! if (objectElem != null) { // Enveloping ! xmlsigType = XMLSIGTYPE_ENVELOPING; ! List contents = objectElem.content(); ! if (contents.size() == 1) ! root = contents.get(0); else ! root = contents; ! root = objectElem; } else if (sigElement.getParent() != null) { // Enveloped ! xmlsigType = XMLSIGTYPE_ENVELOPED; root = getElement().getDocument(); ! } else {// Detached ! xmlsigType = XMLSIGTYPE_DETACHED; loadReference(getElement().attributeValue("URI")); } *************** *** 174,178 **** throw new XMLSecurityException("XMLSignature is not linked to Document"); try { ! root=XMLTools.loadDocument(new File(refuri)).getRootElement(); } catch (XMLException e) { XMLSecTools.rethrowException(e); --- 181,185 ---- throw new XMLSecurityException("XMLSignature is not linked to Document"); try { ! root = XMLTools.loadDocument(new File(refuri)).getRootElement(); } catch (XMLException e) { XMLSecTools.rethrowException(e); *************** *** 194,205 **** // } // transforms.add(tran); ! transformsElement.addElement(XMLSecTools.createQName("Transform")).addAttribute("Algorithm",algorithm); } /** ! * Method getDigest * This returns the Digest ! * @return ! * @throws XMLSecurityException */ public byte[] getDigest() throws XMLSecurityException, CryptoException { --- 201,213 ---- // } // transforms.add(tran); ! transformsElement.addElement(XMLSecTools.createQName("Transform")).addAttribute("Algorithm", algorithm); } /** ! * Method getEncoded * This returns the Digest ! * ! * @return ! * @throws XMLSecurityException */ public byte[] getDigest() throws XMLSecurityException, CryptoException { *************** *** 209,217 **** return null; } void setDigest() throws XMLSecurityException { Element sv = (Element) getElement().element(XMLSecTools.createQName("DigestValue")); ! byte dig[]=generateRefenceDigest(); ! if (sv==null) ! getElement().add(XMLSecTools.base64ToElement("DigestValue",dig)); else sv.addText(Base64.encode(dig)); --- 217,226 ---- return null; } + void setDigest() throws XMLSecurityException { Element sv = (Element) getElement().element(XMLSecTools.createQName("DigestValue")); ! byte dig[] = generateRefenceDigest(); ! if (sv == null) ! getElement().add(XMLSecTools.base64ToElement("DigestValue", dig)); else sv.addText(Base64.encode(dig)); *************** *** 221,225 **** private final Object performTransforms() { // Element subject = root;//(Element) root.clone(); ! Object subject=root; Iterator iter = transforms.iterator(); while (iter.hasNext() && root != null) { --- 230,234 ---- private final Object performTransforms() { // Element subject = root;//(Element) root.clone(); ! Object subject = root; Iterator iter = transforms.iterator(); while (iter.hasNext() && root != null) { *************** *** 231,237 **** private Canonicalizer getCanonicalizer() { ! if (getSigType()==Reference.XMLSIGTYPE_ENVELOPED) return new CanonicalizerWithoutSignature(); ! else if (c14nType==Canonicalizer.C14NTYPE_WITH_COMMENTS) return new CanonicalizerWithComments(); return new Canonicalizer(); --- 240,246 ---- private Canonicalizer getCanonicalizer() { ! if (getSigType() == Reference.XMLSIGTYPE_ENVELOPED) return new CanonicalizerWithoutSignature(); ! else if (c14nType == Canonicalizer.C14NTYPE_WITH_COMMENTS) return new CanonicalizerWithComments(); return new Canonicalizer(); *************** *** 243,248 **** protected final byte[] canonicalizeReference() { ! return XMLSecTools.canonicalize(getCanonicalizer(),getReferenceElement()); } protected final byte[] generateRefenceDigest() { return CryptoTools.digest(canonicalizeReference()); --- 252,258 ---- protected final byte[] canonicalizeReference() { ! return XMLSecTools.canonicalize(getCanonicalizer(), getReferenceElement()); } + protected final byte[] generateRefenceDigest() { return CryptoTools.digest(canonicalizeReference()); *************** *** 250,254 **** public final boolean verifyReferences() throws XMLSecurityException, CryptoException { ! return CryptoTools.equalByteArrays(generateRefenceDigest(),getDigest()); } --- 260,264 ---- public final boolean verifyReferences() throws XMLSecurityException, CryptoException { ! return CryptoTools.equalByteArrays(generateRefenceDigest(), getDigest()); } *************** *** 267,275 **** private List transforms; private Element transformsElement; ! private int xmlsigType=0; ! public final static int XMLSIGTYPE_ENVELOPED=0; ! public final static int XMLSIGTYPE_ENVELOPING=1; ! public final static int XMLSIGTYPE_DETACHED=2; private int c14nType; --- 277,285 ---- private List transforms; private Element transformsElement; ! private int xmlsigType = 0; ! public final static int XMLSIGTYPE_ENVELOPED = 0; ! public final static int XMLSIGTYPE_ENVELOPING = 1; ! public final static int XMLSIGTYPE_DETACHED = 2; private int c14nType; Index: SignedElement.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-xmlsig/src/java/org/neuclear/xml/xmlsec/SignedElement.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SignedElement.java 11 Nov 2003 21:18:07 -0000 1.2 --- SignedElement.java 19 Nov 2003 23:33:17 -0000 1.3 *************** *** 1,4 **** --- 1,13 ---- /* $Id$ * $Log$ + * Revision 1.3 2003/11/19 23:33:17 pelle + * Signers now can generatekeys via the generateKey() method. + * Refactored the relationship between SignedNamedObject and NamedObjectBuilder a bit. + * SignedNamedObject now contains the full xml which is returned with getEncoded() + * This means that it is now possible to further send on or process a SignedNamedObject, leaving + * NamedObjectBuilder for its original purposes of purely generating new Contracts. + * NamedObjectBuilder.sign() now returns a SignedNamedObject which is the prefered way of processing it. + * Updated all major interfaces that used the old model to use the new model. + * * Revision 1.2 2003/11/11 21:18:07 pelle * Further vital reshuffling. *************** *** 28,32 **** * The AbstractElementProxy has a new final method .asXML() * 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. ! * You can now also easily get the digest of a SignedElement with the new .getDigest() value. * * Revision 1.2 2003/02/08 18:48:37 pelle --- 37,41 ---- * The AbstractElementProxy has a new final method .asXML() * 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. ! * You can now also easily get the digest of a SignedElement with the new .getEncoded() value. * * Revision 1.2 2003/02/08 18:48:37 pelle *************** *** 91,96 **** import org.dom4j.Namespace; import org.dom4j.QName; - import org.neuclear.commons.crypto.signers.Signer; import org.neuclear.commons.crypto.CryptoException; import org.neuclear.xml.AbstractElementProxy; import org.neuclear.xml.XMLException; --- 100,105 ---- import org.dom4j.Namespace; import org.dom4j.QName; import org.neuclear.commons.crypto.CryptoException; + import org.neuclear.commons.crypto.signers.Signer; import org.neuclear.xml.AbstractElementProxy; import org.neuclear.xml.XMLException; Index: XMLSignature.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-xmlsig/src/java/org/neuclear/xml/xmlsec/XMLSignature.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** XMLSignature.java 11 Nov 2003 16:33:27 -0000 1.1.1.1 --- XMLSignature.java 19 Nov 2003 23:33:17 -0000 1.2 *************** *** 1,4 **** --- 1,13 ---- /* $Id$ * $Log$ + * Revision 1.2 2003/11/19 23:33:17 pelle + * Signers now can generatekeys via the generateKey() method. + * Refactored the relationship between SignedNamedObject and NamedObjectBuilder a bit. + * SignedNamedObject now contains the full xml which is returned with getEncoded() + * This means that it is now possible to further send on or process a SignedNamedObject, leaving + * NamedObjectBuilder for its original purposes of purely generating new Contracts. + * NamedObjectBuilder.sign() now returns a SignedNamedObject which is the prefered way of processing it. + * Updated all major interfaces that used the old model to use the new model. + * * Revision 1.1.1.1 2003/11/11 16:33:27 pelle * Moved over from neudist.org *************** *** 61,65 **** * The AbstractElementProxy has a new final method .asXML() * 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. ! * You can now also easily get the digest of a SignedElement with the new .getDigest() value. * * Revision 1.6 2003/02/11 14:50:24 pelle --- 70,74 ---- * The AbstractElementProxy has a new final method .asXML() * 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. ! * You can now also easily get the digest of a SignedElement with the new .getEncoded() value. * * Revision 1.6 2003/02/11 14:50:24 pelle *************** *** 119,125 **** import org.dom4j.DocumentHelper; import org.dom4j.Element; - import org.neuclear.commons.crypto.Base64; - import org.neuclear.commons.crypto.CryptoTools; import org.neuclear.commons.crypto.CryptoException; import org.neuclear.xml.XMLException; --- 128,133 ---- import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.neuclear.commons.crypto.CryptoException; + import org.neuclear.commons.crypto.CryptoTools; import org.neuclear.xml.XMLException; *************** *** 136,143 **** /** * Creates an Enveloped (Embedded) Signature object based on the given element root ! * @param key ! * @param root ! * @param uri ! * @throws XMLSecurityException */ public XMLSignature(PrivateKey key, Element root, String uri) throws XMLSecurityException, CryptoException { --- 144,152 ---- /** * Creates an Enveloped (Embedded) Signature object based on the given element root ! * ! * @param key ! * @param root ! * @param uri ! * @throws XMLSecurityException */ public XMLSignature(PrivateKey key, Element root, String uri) throws XMLSecurityException, CryptoException { *************** *** 147,154 **** /** * Creates an Enveloped (Embedded) Signature object based on the given element root ! * @param keypair ! * @param root ! * @param uri ! * @throws XMLSecurityException */ public XMLSignature(KeyPair keypair, Element root, String uri) throws XMLSecurityException, CryptoException { --- 156,164 ---- /** * Creates an Enveloped (Embedded) Signature object based on the given element root ! * ! * @param keypair ! * @param root ! * @param uri ! * @throws XMLSecurityException */ public XMLSignature(KeyPair keypair, Element root, String uri) throws XMLSecurityException, CryptoException { *************** *** 158,167 **** /** * Creates a Signature object based on given element root. ! * ! * @param keypair ! * @param root ! * @param uri ! * @param type Reference.XMLSIGTYPE_ENVELOPED,Reference.XMLSIGTYPE_ENVELOPING or Reference.XMLSIGTYPE_DETACHED ! * @throws XMLSecurityException */ public XMLSignature(KeyPair keypair, Element root, String uri, int type) throws XMLSecurityException, CryptoException { --- 168,177 ---- /** * Creates a Signature object based on given element root. ! * ! * @param keypair ! * @param root ! * @param uri ! * @param type Reference.XMLSIGTYPE_ENVELOPED,Reference.XMLSIGTYPE_ENVELOPING or Reference.XMLSIGTYPE_DETACHED ! * @throws XMLSecurityException */ public XMLSignature(KeyPair keypair, Element root, String uri, int type) throws XMLSecurityException, CryptoException { *************** *** 210,216 **** /** * Method getPublicKey ! * ! * @return ! * @throws XMLSecurityException */ public byte[] getSignature() throws XMLSecurityException, CryptoException { --- 220,226 ---- /** * Method getPublicKey ! * ! * @return ! * @throws XMLSecurityException */ public byte[] getSignature() throws XMLSecurityException, CryptoException { |