|
From: Pelle B. <pe...@us...> - 2004-04-13 17:46:09
|
Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18861/src/java/org/neuclear/commons/crypto/signers Modified Files: DefaultSigner.java JCESigner.java ServletSignerFactory.java Log Message: Now has save dialog Remembers passphrases Index: JCESigner.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers/JCESigner.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** JCESigner.java 12 Apr 2004 23:50:08 -0000 1.22 --- JCESigner.java 13 Apr 2004 17:32:07 -0000 1.23 *************** *** 2,5 **** --- 2,9 ---- * $Id$ * $Log$ + * Revision 1.23 2004/04/13 17:32:07 pelle + * Now has save dialog + * Remembers passphrases + * * Revision 1.22 2004/04/12 23:50:08 pelle * implemented the queue and improved the DefaultSigner *************** *** 453,457 **** final KeyPair kp = kpg.generateKeyPair(); ks.setKeyEntry(alias, kp.getPrivate(), passphrase, new Certificate[]{CryptoTools.createCertificate(alias, kp)}); ! if (!Utility.isEmpty(filename)) save(); } catch (KeyStoreException e) { throw new LowLevelException(e); --- 457,461 ---- final KeyPair kp = kpg.generateKeyPair(); ks.setKeyEntry(alias, kp.getPrivate(), passphrase, new Certificate[]{CryptoTools.createCertificate(alias, kp)}); ! // if (!Utility.isEmpty(filename)) save(); } catch (KeyStoreException e) { throw new LowLevelException(e); *************** *** 477,480 **** --- 481,485 ---- File ksfile = new File(filename); ksfile.getParentFile().mkdirs(); + System.out.println(Thread.currentThread()); ks.store(new FileOutputStream(ksfile), agent.getPassPhrase(filename)); } catch (Exception e) { Index: ServletSignerFactory.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers/ServletSignerFactory.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ServletSignerFactory.java 12 Apr 2004 15:37:01 -0000 1.8 --- ServletSignerFactory.java 13 Apr 2004 17:32:07 -0000 1.9 *************** *** 52,56 **** final PassPhraseAgent agent = createWrapperAgent(keeppassphrase, coreagent, serviceid); // If keystore is "test" setup the TestCaseSigner otherwise use the JCESigner ! final Signer signer = createSigner(keystore, agent); map.put(hash, signer); return signer; --- 52,56 ---- final PassPhraseAgent agent = createWrapperAgent(keeppassphrase, coreagent, serviceid); // If keystore is "test" setup the TestCaseSigner otherwise use the JCESigner ! final Signer signer = createSigner(keystore, (InteractiveAgent) agent); map.put(hash, signer); return signer; *************** *** 63,67 **** } ! private static final BrowsableSigner createSigner(final String keystore, final PassPhraseAgent agent) throws GeneralSecurityException, NeuClearException, FileNotFoundException { if (!Utility.isEmpty(keystore)) { if (keystore.toLowerCase().equals("test")) --- 63,67 ---- } ! private static final BrowsableSigner createSigner(final String keystore, final InteractiveAgent agent) throws GeneralSecurityException, NeuClearException, FileNotFoundException { if (!Utility.isEmpty(keystore)) { if (keystore.toLowerCase().equals("test")) Index: DefaultSigner.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers/DefaultSigner.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DefaultSigner.java 12 Apr 2004 23:50:07 -0000 1.7 --- DefaultSigner.java 13 Apr 2004 17:32:07 -0000 1.8 *************** *** 3,12 **** import org.neuclear.commons.crypto.CryptoException; import org.neuclear.commons.crypto.CryptoTools; ! import org.neuclear.commons.crypto.passphraseagents.PassPhraseAgent; import org.neuclear.commons.crypto.passphraseagents.UserCancellationException; import java.security.KeyStoreException; import java.security.PublicKey; import java.util.Iterator; import java.util.prefs.Preferences; --- 3,15 ---- import org.neuclear.commons.crypto.CryptoException; import org.neuclear.commons.crypto.CryptoTools; ! import org.neuclear.commons.crypto.passphraseagents.InteractiveAgent; import org.neuclear.commons.crypto.passphraseagents.UserCancellationException; + import java.io.File; + import java.io.IOException; import java.security.KeyStoreException; import java.security.PublicKey; import java.util.Iterator; + import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; *************** *** 31,34 **** --- 34,41 ---- $Id$ $Log$ + Revision 1.8 2004/04/13 17:32:07 pelle + Now has save dialog + Remembers passphrases + Revision 1.7 2004/04/12 23:50:07 pelle implemented the queue and improved the DefaultSigner *************** *** 78,84 **** */ public final class DefaultSigner implements BrowsableSigner { ! public DefaultSigner(final PassPhraseAgent agent) throws UserCancellationException, InvalidPassphraseException { ! Preferences prefs = Preferences.userNodeForPackage(DefaultSigner.class); ! final String filename = prefs.get("KEYSTORE", CryptoTools.DEFAULT_KEYSTORE); signer = new JCESigner(filename, "jks", "SUN", agent); --- 85,100 ---- */ public final class DefaultSigner implements BrowsableSigner { ! public DefaultSigner(final InteractiveAgent agent) throws UserCancellationException, InvalidPassphraseException { ! prefs = Preferences.userNodeForPackage(DefaultSigner.class); ! this.agent = agent; ! filename = prefs.get(KEYSTORE, CryptoTools.DEFAULT_KEYSTORE); ! File file = new File(filename); ! if (file.exists() && file.length() == 0) ! file.delete(); // Delete empty file ! try { ! prefs.flush(); ! } catch (BackingStoreException e) { ! e.printStackTrace(); ! } signer = new JCESigner(filename, "jks", "SUN", agent); *************** *** 110,114 **** public byte[] sign(byte data[], SetPublicKeyCallBack callback) throws UserCancellationException { ! return signer.sign(data, callback); } --- 126,130 ---- public byte[] sign(byte data[], SetPublicKeyCallBack callback) throws UserCancellationException { ! return ((InteractiveAgent) agent).sign(this, data, callback); } *************** *** 122,126 **** public void save() { ! signer.save(); } --- 138,155 ---- public void save() { ! try { ! filename = agent.getSaveToFileName("Save Keys... ", filename).getCanonicalPath(); ! prefs.put(KEYSTORE, filename); ! try { ! prefs.flush(); ! } catch (BackingStoreException e) { ! e.printStackTrace(); ! } ! signer.save(filename); ! } catch (IOException e) { ! e.printStackTrace(); ! } catch (UserCancellationException e) { ! e.printStackTrace(); ! } } *************** *** 129,133 **** --- 158,166 ---- } + private String filename; private final JCESigner signer; + private final InteractiveAgent agent; + private Preferences prefs; + private static final String KEYSTORE = "KEYSTORE"; } |