|
From: Pelle B. <pe...@us...> - 2004-03-31 19:00:55
|
Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6205/src/java/org/neuclear/commons/crypto/passphraseagents Modified Files: ConsoleAgent.java ServletPassPhraseAgent.java Log Message: Added various Streams for simplified crypto operations. Index: ConsoleAgent.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/ConsoleAgent.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ConsoleAgent.java 19 Jan 2004 17:53:14 -0000 1.2 --- ConsoleAgent.java 31 Mar 2004 18:48:23 -0000 1.3 *************** *** 2,5 **** --- 2,6 ---- import org.neuclear.commons.Utility; + import org.neuclear.commons.crypto.signers.Signer; import java.io.BufferedReader; *************** *** 29,32 **** --- 30,36 ---- $Id$ $Log$ + Revision 1.3 2004/03/31 18:48:23 pelle + Added various Streams for simplified crypto operations. + Revision 1.2 2004/01/19 17:53:14 pelle Various clean ups *************** *** 82,109 **** public char[] getPassPhrase(String name) throws UserCancellationException { ! return getPassPhrase(name,false); //To change body of implemented methods use Options | File Templates. ! } public final synchronized char[] getPassPhrase(final String name, boolean incorrect) throws UserCancellationException { ! if (!incorrect&&cache.containsKey(name)) ! return ((String)cache.get(name)).toCharArray(); final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); if (incorrect) System.out.println("entered passphrase was incorrect please try again"); ! System.out.println("Please enter passphrase for: " + name+" ('q' to quit)"); System.out.print(": "); try { ! final String line = new jline.ConsoleReader().readLine(new Character((char)'*')); if (line.equals("q")) throw new UserCancellationException(name); if (firstrun) { System.out.println("Do you wish to remember your entered passphrases for this sesson?"); ! if(Utility.getAffirmative(false)) { ! remember=true; } ! firstrun=false; } if (remember) ! cache.put(name,line); return line.toCharArray(); } catch (IOException e) { --- 86,113 ---- public char[] getPassPhrase(String name) throws UserCancellationException { ! return getPassPhrase(name, false); //To change body of implemented methods use Options | File Templates. ! } public final synchronized char[] getPassPhrase(final String name, boolean incorrect) throws UserCancellationException { ! if (!incorrect && cache.containsKey(name)) ! return ((String) cache.get(name)).toCharArray(); final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); if (incorrect) System.out.println("entered passphrase was incorrect please try again"); ! System.out.println("Please enter passphrase for: " + name + " ('q' to quit)"); System.out.print(": "); try { ! final String line = new jline.ConsoleReader().readLine(new Character((char) '*')); if (line.equals("q")) throw new UserCancellationException(name); if (firstrun) { System.out.println("Do you wish to remember your entered passphrases for this sesson?"); ! if (Utility.getAffirmative(false)) { ! remember = true; } ! firstrun = false; } if (remember) ! cache.put(name, line); return line.toCharArray(); } catch (IOException e) { *************** *** 112,118 **** } } private final Map cache; ! private boolean remember=false; ! private boolean firstrun=true; public static void main(final String[] args) { --- 116,123 ---- } } + private final Map cache; ! private boolean remember = false; ! private boolean firstrun = true; public static void main(final String[] args) { *************** *** 122,128 **** System.out.println("Getting passphrase... " + new String(dia.getPassPhrase("neu://pelle@test"))); System.out.println("Getting passphrase... " + new String(dia.getPassPhrase("neu://pelle@test"))); ! System.out.println("Getting passphrase... " + new String(dia.getPassPhrase("neu://pelle@test",true))); } catch (UserCancellationException e) { ! System.out.println("user cancelled"); } --- 127,133 ---- System.out.println("Getting passphrase... " + new String(dia.getPassPhrase("neu://pelle@test"))); System.out.println("Getting passphrase... " + new String(dia.getPassPhrase("neu://pelle@test"))); ! System.out.println("Getting passphrase... " + new String(dia.getPassPhrase("neu://pelle@test", true))); } catch (UserCancellationException e) { ! System.out.println("user cancelled"); } *************** *** 130,132 **** --- 135,148 ---- } + /** + * The User is asked to pick a name by the PassPhraseAgent. The PassPhraseAgent can query the given signer for + * a list of included aliases or even create a new keypair. + * + * @return + * @throws UserCancellationException + */ + public char[] getPassPhrase(Signer signer) throws UserCancellationException { + return new char[0]; + } + } Index: ServletPassPhraseAgent.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/passphraseagents/ServletPassPhraseAgent.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ServletPassPhraseAgent.java 2 Mar 2004 18:58:44 -0000 1.3 --- ServletPassPhraseAgent.java 31 Mar 2004 18:48:23 -0000 1.4 *************** *** 1,4 **** --- 1,6 ---- package org.neuclear.commons.crypto.passphraseagents; + import org.neuclear.commons.crypto.signers.Signer; + import javax.servlet.http.HttpServletRequest; *************** *** 15,18 **** --- 17,21 ---- * Note, the above assumes that a <tt>Signer</tt> with the name signer was initialised in <tt>init()</tt> with a * <tt>ServletPassPhraseAgent</tt> called <tt>agent</tt>. + * * @see org.neuclear.commons.crypto.signers.Signer */ *************** *** 21,42 **** /** * Set the passphrase from the request object. * @param request */ ! public void setRequest(HttpServletRequest request){ set(request.getParameter("passphrase")); } /** * Gets the passphrase if set or null * @param name * @return */ public char[] getPassPhrase(String name) { ! return (get()==null?null:((String)get()).toCharArray()); } /** * Clears the passphrase. (Important, you have to manually call this at the end of the request code, or better yet * immediately after using your Signer). */ ! public void clear(){ set(null); } --- 24,49 ---- /** * Set the passphrase from the request object. + * * @param request */ ! public void setRequest(HttpServletRequest request) { set(request.getParameter("passphrase")); } + /** * Gets the passphrase if set or null + * * @param name * @return */ public char[] getPassPhrase(String name) { ! return (get() == null ? null : ((String) get()).toCharArray()); } + /** * Clears the passphrase. (Important, you have to manually call this at the end of the request code, or better yet * immediately after using your Signer). */ ! public void clear() { set(null); } *************** *** 45,47 **** --- 52,65 ---- return getPassPhrase(name); } + + /** + * The User is asked to pick a name by the PassPhraseAgent. The PassPhraseAgent can query the given signer for + * a list of included aliases or even create a new keypair. + * + * @return + * @throws UserCancellationException + */ + public char[] getPassPhrase(Signer signer) throws UserCancellationException { + return new char[0]; + } } |