|
From: <pe...@us...> - 2003-12-18 17:40:11
|
Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers In directory sc8-pr-cvs1:/tmp/cvs-serv29525/src/java/org/neuclear/commons/crypto/signers Modified Files: JCESigner.java Signer.java SimpleSigner.java Log Message: You can now create keys that get stored with a X509 certificate in the keystore. These can be saved as well. IdentityCreator has been modified to allow creation of keys. Note The actual Creation of Certificates still have a problem that will be resolved later today. Index: JCESigner.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers/JCESigner.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** JCESigner.java 16 Dec 2003 21:09:22 -0000 1.11 --- JCESigner.java 18 Dec 2003 17:40:07 -0000 1.12 *************** *** 2,5 **** --- 2,10 ---- * $Id$ * $Log$ + * 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. + * IdentityCreator has been modified to allow creation of keys. + * Note The actual Creation of Certificates still have a problem that will be resolved later today. + * * Revision 1.11 2003/12/16 21:09:22 pelle * The Sample Web App is semi stable for now. *************** *** 130,137 **** import org.neuclear.commons.NeuClearException; import org.neuclear.commons.crypto.CryptoException; import org.neuclear.commons.crypto.CryptoTools; ! import org.neuclear.commons.crypto.RawCertificate; import org.neuclear.commons.crypto.passphraseagents.PassPhraseAgent; import java.io.*; --- 135,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.*; *************** *** 158,162 **** */ public JCESigner(final String filename, final String type, final String provider, final PassPhraseAgent agent) throws NeuClearException, GeneralSecurityException, FileNotFoundException { ! this(filename, new FileInputStream(new File(filename)), type, provider, agent); } /** --- 165,170 ---- */ 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; } /** *************** *** 172,176 **** */ public JCESigner(final String filename, final String type, final String provider, final PassPhraseAgent agent,final char[] initialpassphrase) throws NeuClearException, GeneralSecurityException, FileNotFoundException { ! this(filename, new FileInputStream(new File(filename)), type, provider, agent,initialpassphrase); } --- 180,201 ---- */ 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; ! ! } ! /** ! * The purpose of this method is to either return an InputStream or Null. The reason being that the Keystore accepts null ! * to create a new KeyStore in memory. ! * @param filename ! * @return ! * @throws FileNotFoundException ! */ ! private static InputStream createInputStream(final String filename) throws FileNotFoundException { ! if (Utility.isEmpty(filename)) ! return null; ! final File file = new File(filename); ! if (!file.exists()) ! return null; ! return new FileInputStream(file); } *************** *** 304,323 **** } ! /** ! * Creates a new KeyPair, stores the PrivateKey using the given alias ! * and returns the PublicKey. ! * ! * @param alias ! * @return Generated PublicKey ! * @throws org.neuclear.commons.crypto.CryptoException ! * ! */ public final PublicKey generateKey(final String alias) throws CryptoException { try { final KeyPair kp = kpg.generateKeyPair(); ! ks.setKeyEntry(alias, kp.getPrivate(), agent.getPassPhrase(alias), new Certificate[]{new RawCertificate(kp.getPublic())}); return kp.getPublic(); } catch (KeyStoreException e) { throw new CryptoException(e); } } --- 329,344 ---- } ! public final PublicKey generateKey(final String alias) throws CryptoException { try { final KeyPair kp = kpg.generateKeyPair(); ! ks.setKeyEntry(alias, kp.getPrivate(), agent.getPassPhrase(alias), new Certificate[]{CryptoTools.createCertificate(alias,kp)}); return kp.getPublic(); } catch (KeyStoreException e) { throw new CryptoException(e); + } catch (SignatureException e) { + throw new CryptoException(e); + } catch (InvalidKeyException e) { + throw new CryptoException(e); } } *************** *** 331,334 **** --- 352,369 ---- } + public void save() throws CryptoException { + save(filename); + } + public synchronized final void save(String filename) throws CryptoException{ + if (Utility.isEmpty(filename)) + throw new CryptoException("We dont have a filename"); + try { + File ksfile=new File(filename); + ksfile.getParentFile().mkdirs(); + ks.store(new FileOutputStream(ksfile),agent.getPassPhrase(filename)); + } catch (Exception e) { + throw new CryptoException(e); + } + } private final KeyStore ks; private final KeyCache cache; *************** *** 336,338 **** --- 371,374 ---- private final KeyPairGenerator kpg; + private String filename; } Index: Signer.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers/Signer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Signer.java 10 Dec 2003 23:55:45 -0000 1.3 --- Signer.java 18 Dec 2003 17:40:07 -0000 1.4 *************** *** 2,5 **** --- 2,10 ---- * $Id$ * $Log$ + * Revision 1.4 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. + * IdentityCreator has been modified to allow creation of keys. + * Note The actual Creation of Certificates still have a problem that will be resolved later today. + * * Revision 1.3 2003/12/10 23:55:45 pelle * Did some cleaning up in the builders *************** *** 87,90 **** --- 92,96 ---- import java.security.PublicKey; + import java.security.cert.Certificate; *************** *** 138,145 **** * Creates a new KeyPair, stores the PrivateKey using the given alias * and returns the PublicKey. ! * ! * @param alias * @return Generated PublicKey ! * @throws CryptoException */ public PublicKey generateKey(String alias) throws CryptoException; --- 144,151 ---- * Creates a new KeyPair, stores the PrivateKey using the given alias * and returns the PublicKey. ! * ! * @param alias * @return Generated PublicKey ! * @throws CryptoException */ public PublicKey generateKey(String alias) throws CryptoException; *************** *** 149,152 **** --- 155,160 ---- final public static int KEY_DSA = 2; final public static int KEY_OTHER = -1; + + void save() throws CryptoException; } Index: SimpleSigner.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers/SimpleSigner.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** SimpleSigner.java 16 Dec 2003 23:16:40 -0000 1.6 --- SimpleSigner.java 18 Dec 2003 17:40:07 -0000 1.7 *************** *** 2,5 **** --- 2,10 ---- * $Id$ * $Log$ + * 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. + * IdentityCreator has been modified to allow creation of keys. + * Note The actual Creation of Certificates still have a problem that will be resolved later today. + * * Revision 1.6 2003/12/16 23:16:40 pelle * Work done on the SigningServlet. The two phase web model is now only an option. *************** *** 121,124 **** --- 126,131 ---- import java.io.*; import java.security.*; + import java.security.cert.*; + import java.security.cert.Certificate; import java.security.spec.KeySpec; import java.security.spec.PKCS8EncodedKeySpec; *************** *** 245,256 **** } ! public final void save() throws IOException { if (signerFile.getParent() != null) signerFile.getParentFile().mkdirs(); ! final FileOutputStream f = new FileOutputStream(signerFile); ! final ObjectOutput s = new ObjectOutputStream(f); ! s.writeObject(ks); ! s.flush(); } --- 252,267 ---- } ! public final void save() throws CryptoException { if (signerFile.getParent() != null) signerFile.getParentFile().mkdirs(); ! try { ! final FileOutputStream f = new FileOutputStream(signerFile); ! final ObjectOutput s = new ObjectOutputStream(f); ! s.writeObject(ks); ! s.flush(); ! } catch (IOException e) { ! throw new CryptoException(e); ! } } *************** *** 269,282 **** return CryptoTools.sign(getKey(name, agent.getPassPhrase(name)), data); } - - /** - * Creates a new KeyPair, stores the PrivateKey using the given alias - * and returns the PublicKey. - * - * @param alias - * @return Generated PublicKey - * @throws org.neuclear.commons.crypto.CryptoException - * - */ public final PublicKey generateKey(final String alias) throws CryptoException { try { --- 280,283 ---- |