|
From: Pelle B. <pe...@us...> - 2004-04-07 17:35:27
|
Update of /cvsroot/neuclear/neuclear-xmlsig/src/java/org/neuclear/xml/xmlsec In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14729/src/java/org/neuclear/xml/xmlsec Modified Files: EnvelopedSignature.java KeyInfo.java SignedInfo.java XMLSignature.java Log Message: Added support for the new improved interactive signing model. A new Agent is also available with SwingAgent. The XMLSig classes have also been updated to support this. Index: KeyInfo.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-xmlsig/src/java/org/neuclear/xml/xmlsec/KeyInfo.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** KeyInfo.java 19 Mar 2004 22:21:51 -0000 1.10 --- KeyInfo.java 7 Apr 2004 17:22:22 -0000 1.11 *************** *** 7,10 **** --- 7,11 ---- import org.neuclear.commons.crypto.CryptoTools; import org.neuclear.commons.crypto.keyresolvers.KeyResolverFactory; + import org.neuclear.commons.crypto.signers.SetPublicKeyCallBack; import java.io.ByteArrayInputStream; *************** *** 213,216 **** --- 214,229 ---- } + public static class CreateKeyInfoCallBack implements SetPublicKeyCallBack { + private PublicKey pub; + + public void setPublicKey(PublicKey pub) { + this.pub = pub; + } + + public KeyInfo createKeyInfo() { + return new KeyInfo(pub); + } + + } private static final String TAG_NAME = "KeyInfo"; Index: EnvelopedSignature.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-xmlsig/src/java/org/neuclear/xml/xmlsec/EnvelopedSignature.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EnvelopedSignature.java 23 Mar 2004 20:51:00 -0000 1.2 --- EnvelopedSignature.java 7 Apr 2004 17:22:22 -0000 1.3 *************** *** 4,7 **** --- 4,8 ---- import org.neuclear.commons.Utility; import org.neuclear.commons.crypto.passphraseagents.UserCancellationException; + import org.neuclear.commons.crypto.signers.BrowsableSigner; import org.neuclear.commons.crypto.signers.NonExistingSignerException; import org.neuclear.commons.crypto.signers.Signer; *************** *** 47,50 **** --- 48,70 ---- /** * Creates a standard Enveloped Signature within the given Element. + * Uses the provided Signer and Alias to sign it. + * + * @param signer + * @param elem + * @throws XMLSecurityException + * @throws UserCancellationException + * @throws NonExistingSignerException + * @see Signer + */ + public EnvelopedSignature(BrowsableSigner signer, Element elem) throws XMLSecurityException, UserCancellationException, NonExistingSignerException { + super(new SignedInfo(SignedInfo.SIG_ALG_RSA, 1)); + si.setEnvelopedReference(elem); + elem.add(getElement()); + sign(signer); + } + + + /** + * Creates a standard Enveloped Signature within the given Element. * Uses the provided KeyPair to sign it. * Index: SignedInfo.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-xmlsig/src/java/org/neuclear/xml/xmlsec/SignedInfo.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** SignedInfo.java 23 Mar 2004 20:51:00 -0000 1.7 --- SignedInfo.java 7 Apr 2004 17:22:22 -0000 1.8 *************** *** 1,4 **** --- 1,8 ---- /* $Id$ * $Log$ + * Revision 1.8 2004/04/07 17:22:22 pelle + * Added support for the new improved interactive signing model. A new Agent is also available with SwingAgent. + * The XMLSig classes have also been updated to support this. + * * Revision 1.7 2004/03/23 20:51:00 pelle * Added ExternalSignature and further Javadocs. *************** *** 129,132 **** --- 133,137 ---- import org.neuclear.commons.crypto.CryptoTools; import org.neuclear.commons.crypto.passphraseagents.UserCancellationException; + import org.neuclear.commons.crypto.signers.BrowsableSigner; import org.neuclear.commons.crypto.signers.NonExistingSignerException; import org.neuclear.commons.crypto.signers.Signer; *************** *** 302,305 **** --- 307,315 ---- } + public final byte[] sign(BrowsableSigner signer, KeyInfo.CreateKeyInfoCallBack cb) throws XMLSecurityException, NonExistingSignerException, UserCancellationException { + return signer.sign(canonicalize(), cb); + } + + public final boolean verify(PublicKey pub, byte[] sig) throws XMLSecurityException { try { Index: XMLSignature.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-xmlsig/src/java/org/neuclear/xml/xmlsec/XMLSignature.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** XMLSignature.java 23 Mar 2004 20:51:00 -0000 1.19 --- XMLSignature.java 7 Apr 2004 17:22:22 -0000 1.20 *************** *** 1,4 **** --- 1,8 ---- /* $Id$ * $Log$ + * Revision 1.20 2004/04/07 17:22:22 pelle + * Added support for the new improved interactive signing model. A new Agent is also available with SwingAgent. + * The XMLSig classes have also been updated to support this. + * * Revision 1.19 2004/03/23 20:51:00 pelle * Added ExternalSignature and further Javadocs. *************** *** 217,220 **** --- 221,225 ---- import org.neuclear.commons.crypto.CryptoTools; import org.neuclear.commons.crypto.passphraseagents.UserCancellationException; + import org.neuclear.commons.crypto.signers.BrowsableSigner; import org.neuclear.commons.crypto.signers.NonExistingSignerException; import org.neuclear.commons.crypto.signers.PublicKeySource; *************** *** 255,264 **** private XMLSignature(final PublicKey pub, final SignedInfo si) { super(XMLSignature.TAG_NAME); this.si = si; addElement(si); sigval = addElement("SignatureValue"); - if (pub != null) - addElement(new KeyInfo(pub)); } --- 260,273 ---- private XMLSignature(final PublicKey pub, final SignedInfo si) { + this(si); + if (pub != null) + addElement(new KeyInfo(pub)); + } + + protected XMLSignature(final SignedInfo si) { super(XMLSignature.TAG_NAME); this.si = si; addElement(si); sigval = addElement("SignatureValue"); } *************** *** 359,363 **** * * @param alias ! * @param signer * @throws XMLSecurityException * @throws NonExistingSignerException --- 368,372 ---- * * @param alias ! * @param signer * @throws XMLSecurityException * @throws NonExistingSignerException *************** *** 368,371 **** --- 377,385 ---- } + protected void sign(BrowsableSigner signer) throws XMLSecurityException, NonExistingSignerException, UserCancellationException { + KeyInfo.CreateKeyInfoCallBack cb = new KeyInfo.CreateKeyInfoCallBack(); + sigval.setText(Base64.encode(si.sign(signer, cb))); + addElement(cb.createKeyInfo()); + } private static PublicKey getPublicKey(final String alias, final Signer signer) throws XMLSecurityException, NonExistingSignerException { |