|
From: Pelle B. <pe...@us...> - 2004-04-07 17:35:11
|
Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14664/src/java/org/neuclear/commons/crypto/signers Modified Files: BrowsableSigner.java JCESigner.java Added Files: SetPublicKeyCallBack.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: JCESigner.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers/JCESigner.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** JCESigner.java 22 Mar 2004 20:09:05 -0000 1.18 --- JCESigner.java 7 Apr 2004 17:22:10 -0000 1.19 *************** *** 2,5 **** --- 2,9 ---- * $Id$ * $Log$ + * Revision 1.19 2004/04/07 17:22:10 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.18 2004/03/22 20:09:05 pelle * Added simple ledger for unit testing and in memory use *************** *** 171,179 **** import java.security.interfaces.DSAPublicKey; import java.security.interfaces.RSAPublicKey; /** * Wrapper around JCE KeyStore */ ! public class JCESigner implements org.neuclear.commons.crypto.signers.Signer, PublicKeySource { /** --- 175,185 ---- import java.security.interfaces.DSAPublicKey; import java.security.interfaces.RSAPublicKey; + import java.util.Enumeration; + import java.util.Iterator; /** * Wrapper around JCE KeyStore */ ! public class JCESigner implements org.neuclear.commons.crypto.signers.Signer, BrowsableSigner, PublicKeySource { /** *************** *** 421,424 **** --- 427,451 ---- } + public byte[] sign(byte data[], SetPublicKeyCallBack callback) throws UserCancellationException { + return ((InteractiveAgent) agent).sign(this, data, callback); + } + + public byte[] sign(String name, char pass[], byte data[], SetPublicKeyCallBack callback) throws InvalidPassphraseException { + try { + if (callback != null) + callback.setPublicKey(getPublicKey(name)); + return CryptoTools.sign(getKey(name, pass), data); + } catch (UnrecoverableKeyException e) { + throw new InvalidPassphraseException(name); + } catch (NoSuchAlgorithmException e) { + throw new LowLevelException(e); + } catch (KeyStoreException e) { + // Could try to reload it here but I wont for now + throw new LowLevelException(e); + } catch (CryptoException e) { + throw new LowLevelException(e); + } + } + public void save() { try { *************** *** 441,444 **** --- 468,489 ---- } + public Iterator iterator() throws KeyStoreException { + final Enumeration enum = ks.aliases(); + return new Iterator() { + public void remove() { + + } + + public boolean hasNext() { + return enum.hasMoreElements(); + } + + public Object next() { + return enum.nextElement(); + } + + }; + } + private final KeyStore ks; private final KeyCache cache; --- NEW FILE: SetPublicKeyCallBack.java --- package org.neuclear.commons.crypto.signers; import java.security.PublicKey; /* $Id: SetPublicKeyCallBack.java,v 1.1 2004/04/07 17:22:10 pelle Exp $ $Log: SetPublicKeyCallBack.java,v $ Revision 1.1 2004/04/07 17:22:10 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. */ /** * User: pelleb * Date: Apr 7, 2004 * Time: 11:23:55 AM */ public interface SetPublicKeyCallBack { public void setPublicKey(PublicKey pub); } Index: BrowsableSigner.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers/BrowsableSigner.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** BrowsableSigner.java 29 Mar 2004 23:48:33 -0000 1.1 --- BrowsableSigner.java 7 Apr 2004 17:22:10 -0000 1.2 *************** *** 1,5 **** --- 1,8 ---- package org.neuclear.commons.crypto.signers; + import org.neuclear.commons.crypto.passphraseagents.UserCancellationException; + import java.security.KeyStoreException; + import java.security.PublicKey; import java.util.Iterator; *************** *** 24,27 **** --- 27,34 ---- $Id$ $Log$ + Revision 1.2 2004/04/07 17:22:10 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.1 2004/03/29 23:48:33 pelle InteractiveAgent now has a new method which allows signers to ask for a passphrase without specifying alias. *************** *** 38,40 **** --- 45,54 ---- public interface BrowsableSigner { Iterator iterator() throws KeyStoreException; + + PublicKey getPublicKey(String name) throws NonExistingSignerException; + + byte[] sign(byte data[], SetPublicKeyCallBack callback) throws UserCancellationException; + + byte[] sign(String alias, char passphrase[], byte data[], SetPublicKeyCallBack callback) throws InvalidPassphraseException; + } |