Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers
In directory sc8-pr-cvs1:/tmp/cvs-serv18953/src/java/org/neuclear/commons/crypto/signers
Modified Files:
DefaultSigner.java JCESigner.java ServletSignerFactory.java
SimpleSigner.java TestCaseSigner.java
Log Message:
Lots of usability changes through out all the passphrase agents and end user tools.
Index: DefaultSigner.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers/DefaultSigner.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** DefaultSigner.java 21 Nov 2003 04:43:41 -0000 1.3
--- DefaultSigner.java 19 Dec 2003 00:31:15 -0000 1.4
***************
*** 3,7 ****
--- 3,9 ----
import org.neuclear.commons.NeuClearException;
import org.neuclear.commons.crypto.CryptoTools;
+ import org.neuclear.commons.crypto.CryptoException;
import org.neuclear.commons.crypto.passphraseagents.PassPhraseAgent;
+ import org.neuclear.commons.crypto.passphraseagents.UserCancellationException;
import java.io.FileNotFoundException;
***************
*** 28,31 ****
--- 30,36 ----
$Id$
$Log$
+ Revision 1.4 2003/12/19 00:31:15 pelle
+ Lots of usability changes through out all the passphrase agents and end user tools.
+
Revision 1.3 2003/11/21 04:43:41 pelle
EncryptedFileStore now works. It uses the PBECipher with DES3 afair.
***************
*** 63,67 ****
*/
public final class DefaultSigner extends JCESigner {
! public DefaultSigner(final PassPhraseAgent agent) throws NeuClearException, GeneralSecurityException, FileNotFoundException {
super(CryptoTools.DEFAULT_KEYSTORE, "jks", "SUN", agent);
--- 68,72 ----
*/
public final class DefaultSigner extends JCESigner {
! public DefaultSigner(final PassPhraseAgent agent) throws UserCancellationException,InvalidPassphraseException {
super(CryptoTools.DEFAULT_KEYSTORE, "jks", "SUN", agent);
Index: JCESigner.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers/JCESigner.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** JCESigner.java 18 Dec 2003 17:40:07 -0000 1.12
--- JCESigner.java 19 Dec 2003 00:31:15 -0000 1.13
***************
*** 2,5 ****
--- 2,8 ----
* $Id$
* $Log$
+ * Revision 1.13 2003/12/19 00:31:15 pelle
+ * Lots of usability changes through out all the passphrase agents and end user tools.
+ *
* Revision 1.12 2003/12/18 17:40:07 pelle
* You can now create keys that get stored with a X509 certificate in the keystore. These can be saved as well.
***************
*** 136,144 ****
import org.neuclear.commons.NeuClearException;
import org.neuclear.commons.Utility;
import org.neuclear.commons.crypto.CryptoException;
import org.neuclear.commons.crypto.CryptoTools;
import org.neuclear.commons.crypto.jce.RawCertificate;
import org.neuclear.commons.crypto.passphraseagents.PassPhraseAgent;
! import org.neuclear.commons.crypto.passphraseagents.UserCancelsException;
import java.io.*;
--- 139,149 ----
import org.neuclear.commons.NeuClearException;
import org.neuclear.commons.Utility;
+ import org.neuclear.commons.LowLevelException;
import org.neuclear.commons.crypto.CryptoException;
import org.neuclear.commons.crypto.CryptoTools;
import org.neuclear.commons.crypto.jce.RawCertificate;
import org.neuclear.commons.crypto.passphraseagents.PassPhraseAgent;
! import org.neuclear.commons.crypto.passphraseagents.UserCancellationException;
! import org.neuclear.commons.crypto.passphraseagents.InteractiveAgent;
import java.io.*;
***************
*** 160,168 ****
* @param provider
* @param agent
! * @throws NeuClearException
! * @throws GeneralSecurityException
! * @throws FileNotFoundException
*/
! public JCESigner(final String filename, final String type, final String provider, final PassPhraseAgent agent) throws NeuClearException, GeneralSecurityException, FileNotFoundException {
this(filename, createInputStream(filename), type, provider, agent);
this.filename=filename;
--- 165,172 ----
* @param provider
* @param agent
! * @throws InvalidPassphraseException If the given passphrase is incorrect
! * @throws UserCancellationException If the user choses to cancel the process in the passphrase agent, this should cancel the loading process
*/
! public JCESigner(final String filename, final String type, final String provider, final PassPhraseAgent agent) throws UserCancellationException,InvalidPassphraseException {
this(filename, createInputStream(filename), type, provider, agent);
this.filename=filename;
***************
*** 175,183 ****
* @param agent
* @param initialpassphrase
! * @throws NeuClearException
! * @throws GeneralSecurityException
! * @throws FileNotFoundException
*/
! public JCESigner(final String filename, final String type, final String provider, final PassPhraseAgent agent,final char[] initialpassphrase) throws NeuClearException, GeneralSecurityException, FileNotFoundException {
this(filename, createInputStream(filename), type, provider, agent,initialpassphrase);
this.filename=filename;
--- 179,186 ----
* @param agent
* @param initialpassphrase
! * @throws InvalidPassphraseException If the given passphrase is incorrect
*/
! public JCESigner(final String filename, final String type, final String provider, final PassPhraseAgent agent,final char[] initialpassphrase) throws InvalidPassphraseException
! {
this(filename, createInputStream(filename), type, provider, agent,initialpassphrase);
this.filename=filename;
***************
*** 189,195 ****
* @param filename
* @return
- * @throws FileNotFoundException
*/
! private static InputStream createInputStream(final String filename) throws FileNotFoundException {
if (Utility.isEmpty(filename))
return null;
--- 192,197 ----
* @param filename
* @return
*/
! private static InputStream createInputStream(final String filename) {
if (Utility.isEmpty(filename))
return null;
***************
*** 197,201 ****
if (!file.exists())
return null;
! return new FileInputStream(file);
}
--- 199,208 ----
if (!file.exists())
return null;
! try {
! return new FileInputStream(file);
! } catch (FileNotFoundException e) {
! System.err.println(e.getLocalizedMessage());
! throw new LowLevelException(e);
! }
}
***************
*** 207,213 ****
* @param provider
* @param agent
! * @throws NeuClearException
*/
! protected JCESigner(final String name, final InputStream in, final String type, final String provider, final PassPhraseAgent agent) throws NeuClearException {
this(loadKeyStore(provider, type, in, agent, name), agent);
}
--- 214,221 ----
* @param provider
* @param agent
! * @throws InvalidPassphraseException If the given passphrase is incorrect
! * @throws UserCancellationException If the user choses to cancel the process in the passphrase agent, this should cancel the loading process
*/
! protected JCESigner(final String name, final InputStream in, final String type, final String provider, final PassPhraseAgent agent) throws UserCancellationException, InvalidPassphraseException {
this(loadKeyStore(provider, type, in, agent, name), agent);
}
***************
*** 220,234 ****
* @param agent
* @param initpassphrase
! * @throws NeuClearException
*/
! protected JCESigner(final String name, final InputStream in, final String type, final String provider, final PassPhraseAgent agent, final char[] initpassphrase) throws NeuClearException {
this(loadKeyStore(provider, type, in, initpassphrase), agent);
}
!
! private static KeyStore loadKeyStore(final String provider, final String type, final InputStream in, final PassPhraseAgent agent, final String name) throws NeuClearException {
// System.out.println("Loading JCESigner: "+name);
return loadKeyStore(provider,type,in,agent.getPassPhrase("Keystore password for: "+name));
}
! private static KeyStore loadKeyStore(final String provider, final String type, final InputStream in, final char[] passphrase) throws NeuClearException {
// System.out.println("Loading JCESigner using passphrase: "+new String(passphrase));
try {
--- 228,261 ----
* @param agent
* @param initpassphrase
! * @throws InvalidPassphraseException If the given passphrase is incorrect
*/
! protected JCESigner(final String name, final InputStream in, final String type, final String provider, final PassPhraseAgent agent, final char[] initpassphrase) throws InvalidPassphraseException {
this(loadKeyStore(provider, type, in, initpassphrase), agent);
}
! /**
! *
! * @param provider
! * @param type
! * @param in
! * @param agent
! * @param name
! * @return
! * @throws InvalidPassphraseException
! * @throws UserCancellationException
! */
! private static KeyStore loadKeyStore(final String provider, final String type, final InputStream in, final PassPhraseAgent agent, final String name) throws InvalidPassphraseException,UserCancellationException {
// System.out.println("Loading JCESigner: "+name);
return loadKeyStore(provider,type,in,agent.getPassPhrase("Keystore password for: "+name));
}
! /**
! *
! * @param provider
! * @param type
! * @param in
! * @param passphrase
! * @return
! * @throws InvalidPassphraseException
! */
! private static KeyStore loadKeyStore(final String provider, final String type, final InputStream in, final char[] passphrase) throws InvalidPassphraseException {
// System.out.println("Loading JCESigner using passphrase: "+new String(passphrase));
try {
***************
*** 241,257 ****
return ki;
} catch (KeyStoreException e) {
! throw new NeuClearException(e);
} catch (NoSuchProviderException e) {
! throw new NeuClearException(e);
} catch (IOException e) {
! throw new NeuClearException(e);
} catch (NoSuchAlgorithmException e) {
! throw new NeuClearException(e);
} catch (CertificateException e) {
! throw new NeuClearException(e);
}
}
! public JCESigner(final KeyStore ks, final PassPhraseAgent agent) throws CryptoException {
this.agent = agent;
this.ks = ks;
--- 268,290 ----
return ki;
} catch (KeyStoreException e) {
! throw new LowLevelException(e);
} catch (NoSuchProviderException e) {
! throw new LowLevelException(e);
} catch (IOException e) {
! System.err.println("Incorrect Passphrase");
! throw new InvalidPassphraseException("entered passphrase was invalid");
} catch (NoSuchAlgorithmException e) {
! throw new LowLevelException(e);
} catch (CertificateException e) {
! throw new LowLevelException(e);
}
}
! /**
! * Creates a signer based on a fully loaded keystore
! * @param ks
! * @param agent
! */
! public JCESigner(final KeyStore ks, final PassPhraseAgent agent) {
this.agent = agent;
this.ks = ks;
***************
*** 261,270 ****
kpg.initialize(1024, SecureRandom.getInstance("SHA1PRNG"));
} catch (NoSuchAlgorithmException e) {
! throw new CryptoException(e);
}
}
! private PrivateKey getKey(final String name, final char[] passphrase) throws InvalidPassphraseException, NonExistingSignerException, IOException {
try {
final PrivateKey key = (PrivateKey) cache.getKey(name, passphrase);
--- 294,303 ----
kpg.initialize(1024, SecureRandom.getInstance("SHA1PRNG"));
} catch (NoSuchAlgorithmException e) {
! throw new LowLevelException(e);
}
}
! private PrivateKey getKey(final String name, final char[] passphrase) throws UnrecoverableKeyException, NonExistingSignerException, NoSuchAlgorithmException, KeyStoreException {
try {
final PrivateKey key = (PrivateKey) cache.getKey(name, passphrase);
***************
*** 274,279 ****
} catch (ClassCastException e) {
throw new NonExistingSignerException("Incorrect Key type found");
- } catch (GeneralSecurityException e) {
- throw new InvalidPassphraseException(e.getLocalizedMessage());
}
--- 307,310 ----
***************
*** 290,299 ****
*/
public final byte[] sign(final String name, final byte[] data) throws CryptoException {
!
try {
! return CryptoTools.sign(getKey(name, agent.getPassPhrase(name)), data);
! } catch (IOException e) {
! throw new CryptoException(e);
}
}
--- 321,345 ----
*/
public final byte[] sign(final String name, final byte[] data) throws CryptoException {
! return sign(name,data,false);
! }
! public final byte[] sign(final String name, final byte[] data,boolean incorrect) throws UserCancellationException, NonExistingSignerException,CryptoException {
try {
! final char[] pass = getPassPhrase(name,incorrect);
! return CryptoTools.sign(getKey(name, pass), data);
! } catch (UnrecoverableKeyException e) {
! System.err.println("Incorrect Passphrase Attemt on: "+name);
! return sign(name,data,true);
! } 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);
}
+ }
+
+ private char[] getPassPhrase(final String name,boolean incorrect) throws UserCancellationException {
+ if (incorrect&&(agent instanceof InteractiveAgent))
+ ((InteractiveAgent)agent).getPassPhrase(name,true);
+ return agent.getPassPhrase(name);
}
Index: ServletSignerFactory.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers/ServletSignerFactory.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** ServletSignerFactory.java 16 Dec 2003 23:16:40 -0000 1.4
--- ServletSignerFactory.java 19 Dec 2003 00:31:15 -0000 1.5
***************
*** 57,61 ****
}
! private static final PassPhraseAgent createWrapperAgent(final String keeppassphrase, final PassPhraseAgent coreagent, final String serviceid) throws UserCancelsException {
if (!Utility.isEmpty(keeppassphrase)&&keeppassphrase.equals("1")&&coreagent instanceof InteractiveAgent)
return new AskAtStartupAgent((InteractiveAgent)coreagent,serviceid);
--- 57,61 ----
}
! private static final PassPhraseAgent createWrapperAgent(final String keeppassphrase, final PassPhraseAgent coreagent, final String serviceid) throws UserCancellationException {
if (!Utility.isEmpty(keeppassphrase)&&keeppassphrase.equals("1")&&coreagent instanceof InteractiveAgent)
return new AskAtStartupAgent((InteractiveAgent)coreagent,serviceid);
***************
*** 77,81 ****
if (!Utility.isEmpty(agenttype)){
if (agenttype.toLowerCase().equals("console"))
! return new CommandLineAgent();
if (agenttype.toLowerCase().equals("servlet"))
return new ServletPassPhraseAgent();
--- 77,81 ----
if (!Utility.isEmpty(agenttype)){
if (agenttype.toLowerCase().equals("console"))
! return new ConsoleAgent();
if (agenttype.toLowerCase().equals("servlet"))
return new ServletPassPhraseAgent();
Index: SimpleSigner.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers/SimpleSigner.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** SimpleSigner.java 18 Dec 2003 17:40:07 -0000 1.7
--- SimpleSigner.java 19 Dec 2003 00:31:15 -0000 1.8
***************
*** 2,5 ****
--- 2,8 ----
* $Id$
* $Log$
+ * Revision 1.8 2003/12/19 00:31:15 pelle
+ * Lots of usability changes through out all the passphrase agents and end user tools.
+ *
* Revision 1.7 2003/12/18 17:40:07 pelle
* You can now create keys that get stored with a X509 certificate in the keystore. These can be saved as well.
***************
*** 12,16 ****
* The screen has also been cleaned up and displays the xml to be signed.
* The GuiDialogueAgent now optionally remembers passphrases and has a checkbox to support this.
! * The PassPhraseAgent's now have a UserCancelsException, which allows the agent to tell the application if the user specifically
* cancels the signing process.
*
--- 15,19 ----
* The screen has also been cleaned up and displays the xml to be signed.
* The GuiDialogueAgent now optionally remembers passphrases and has a checkbox to support this.
! * The PassPhraseAgent's now have a UserCancellationException, which allows the agent to tell the application if the user specifically
* cancels the signing process.
*
Index: TestCaseSigner.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers/TestCaseSigner.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** TestCaseSigner.java 14 Dec 2003 20:52:54 -0000 1.8
--- TestCaseSigner.java 19 Dec 2003 00:31:16 -0000 1.9
***************
*** 2,5 ****
--- 2,6 ----
import org.neuclear.commons.NeuClearException;
+ import org.neuclear.commons.LowLevelException;
import org.neuclear.commons.crypto.passphraseagents.AlwaysTheSamePassphraseAgent;
import org.neuclear.commons.crypto.passphraseagents.PassPhraseAgent;
***************
*** 29,32 ****
--- 30,36 ----
$Id$
$Log$
+ Revision 1.9 2003/12/19 00:31:16 pelle
+ Lots of usability changes through out all the passphrase agents and end user tools.
+
Revision 1.8 2003/12/14 20:52:54 pelle
Added ServletPassPhraseAgent which uses ThreadLocal to transfer the passphrase to the signer.
***************
*** 83,95 ****
* <tt>src/testdata/keys/testkeys.jks</tt><br>
* The password for all keys should be "neuclear"
- *
- * @throws NeuClearException
- * @throws GeneralSecurityException
*/
! public TestCaseSigner() throws NeuClearException, GeneralSecurityException {
! this(KEYSTORE, getKeyStore(), "neuclear");
}
! public TestCaseSigner(final PassPhraseAgent agent) throws GeneralSecurityException, NeuClearException {
this(KEYSTORE, getKeyStore(), agent);
}
--- 87,96 ----
* <tt>src/testdata/keys/testkeys.jks</tt><br>
* The password for all keys should be "neuclear"
*/
! public TestCaseSigner() throws InvalidPassphraseException {
! this(KEYSTORE, getKeyStore(), "neuclear");
}
! public TestCaseSigner(final PassPhraseAgent agent) throws InvalidPassphraseException {
this(KEYSTORE, getKeyStore(), agent);
}
***************
*** 102,113 ****
* @param in InputStream
* @param passphrase The passphrase to use
! * @throws NeuClearException
! * @throws GeneralSecurityException
*/
! public TestCaseSigner(final String name, final InputStream in, final String passphrase) throws NeuClearException, GeneralSecurityException {
this(name, in, new AlwaysTheSamePassphraseAgent(passphrase));
}
! public TestCaseSigner(final String name, final InputStream in, final PassPhraseAgent agent) throws NeuClearException, GeneralSecurityException {
super(name,
in,
--- 103,113 ----
* @param in InputStream
* @param passphrase The passphrase to use
! * @throws InvalidPassphraseException
*/
! public TestCaseSigner(final String name, final InputStream in, final String passphrase) throws InvalidPassphraseException {
this(name, in, new AlwaysTheSamePassphraseAgent(passphrase));
}
! public TestCaseSigner(final String name, final InputStream in, final PassPhraseAgent agent) throws InvalidPassphraseException {
super(name,
in,
|