|
From: Pelle B. <pe...@us...> - 2004-04-14 00:11:32
|
Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4424/src/java/org/neuclear/commons/crypto/signers Modified Files: DefaultSigner.java JCESigner.java ServletSignerFactory.java Log Message: Added a MessageLabel for handling errors, validation and info Save works well now. It's pretty much there I think. Index: JCESigner.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers/JCESigner.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** JCESigner.java 13 Apr 2004 17:32:07 -0000 1.23 --- JCESigner.java 14 Apr 2004 00:10:52 -0000 1.24 *************** *** 2,5 **** --- 2,10 ---- * $Id$ * $Log$ + * Revision 1.24 2004/04/14 00:10:52 pelle + * Added a MessageLabel for handling errors, validation and info + * Save works well now. + * It's pretty much there I think. + * * Revision 1.23 2004/04/13 17:32:07 pelle * Now has save dialog *************** *** 446,450 **** 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) { --- 451,454 ---- *************** *** 467,471 **** } ! public void save() { try { save(filename); --- 471,475 ---- } ! public void save() throws UserCancellationException { try { save(filename); *************** *** 475,479 **** } ! public synchronized final void save(String filename) throws FileNotFoundException { if (Utility.isEmpty(filename)) throw new FileNotFoundException("no keystore filename"); --- 479,487 ---- } ! public synchronized final void save(String filename) throws FileNotFoundException, UserCancellationException { ! save(filename, agent.getPassPhrase(filename)); ! } ! ! public synchronized final void save(String filename, char passphrase[]) throws FileNotFoundException { if (Utility.isEmpty(filename)) throw new FileNotFoundException("no keystore filename"); *************** *** 482,486 **** ksfile.getParentFile().mkdirs(); System.out.println(Thread.currentThread()); ! ks.store(new FileOutputStream(ksfile), agent.getPassPhrase(filename)); } catch (Exception e) { throw new LowLevelException(e); --- 490,494 ---- ksfile.getParentFile().mkdirs(); System.out.println(Thread.currentThread()); ! ks.store(new FileOutputStream(ksfile), passphrase); } catch (Exception e) { throw new LowLevelException(e); *************** *** 509,513 **** private final KeyCache cache; private final PassPhraseAgent agent; - private final KeyPairGenerator kpg; private String filename; --- 517,520 ---- Index: DefaultSigner.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers/DefaultSigner.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** DefaultSigner.java 13 Apr 2004 17:32:07 -0000 1.8 --- DefaultSigner.java 14 Apr 2004 00:10:52 -0000 1.9 *************** *** 1,4 **** --- 1,5 ---- package org.neuclear.commons.crypto.signers; + import org.neuclear.commons.LowLevelException; import org.neuclear.commons.crypto.CryptoException; import org.neuclear.commons.crypto.CryptoTools; *************** *** 6,11 **** import org.neuclear.commons.crypto.passphraseagents.UserCancellationException; ! import java.io.File; ! import java.io.IOException; import java.security.KeyStoreException; import java.security.PublicKey; --- 7,11 ---- import org.neuclear.commons.crypto.passphraseagents.UserCancellationException; ! import java.io.*; import java.security.KeyStoreException; import java.security.PublicKey; *************** *** 34,37 **** --- 34,42 ---- $Id$ $Log$ + Revision 1.9 2004/04/14 00:10:52 pelle + Added a MessageLabel for handling errors, validation and info + Save works well now. + It's pretty much there I think. + Revision 1.8 2004/04/13 17:32:07 pelle Now has save dialog *************** *** 92,95 **** --- 97,109 ---- if (file.exists() && file.length() == 0) file.delete(); // Delete empty file + InputStream is = null; + if (file.exists()) { + passphrase = agent.getPassPhrase(filename); + try { + is = new FileInputStream(file); + } catch (FileNotFoundException e) { + throw new LowLevelException(e); + } + } try { prefs.flush(); *************** *** 97,102 **** e.printStackTrace(); } ! signer = new JCESigner(filename, "jks", "SUN", agent); } --- 111,128 ---- e.printStackTrace(); } ! if (passphrase != null) ! signer = loadSigner(is, agent); ! else ! signer = new JCESigner(filename, is, "jks", "SUN", agent); ! ! ! } + private JCESigner loadSigner(InputStream is, final InteractiveAgent agent) throws InvalidPassphraseException { + try { + return new JCESigner(filename, is, "jks", "SUN", agent, passphrase); + } catch (InvalidPassphraseException e) { + return loadSigner(is, agent); + } } *************** *** 139,142 **** --- 165,178 ---- public void save() { try { + save(false); + } catch (IOException e) { + throw new LowLevelException(e); + } catch (UserCancellationException e) { + throw new LowLevelException(e); + } + } + + public void save(final boolean force) throws IOException, UserCancellationException { + if (force || filename == null) { filename = agent.getSaveToFileName("Save Keys... ", filename).getCanonicalPath(); prefs.put(KEYSTORE, filename); *************** *** 146,155 **** e.printStackTrace(); } - signer.save(filename); - } catch (IOException e) { - e.printStackTrace(); - } catch (UserCancellationException e) { - e.printStackTrace(); } } --- 182,190 ---- e.printStackTrace(); } } + if (force || passphrase == null || passphrase.length == 0) + passphrase = agent.getNewPassPhrase(filename); + System.out.println("Saving " + filename); + signer.save(filename, passphrase); } *************** *** 163,166 **** --- 198,202 ---- private Preferences prefs; private static final String KEYSTORE = "KEYSTORE"; + private char passphrase[] = null; } |