|
From: <pe...@us...> - 2003-11-21 04:45:26
|
Update of /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/store In directory sc8-pr-cvs1:/tmp/cvs-serv10855/src/java/org/neuclear/store Modified Files: EncryptedFileStore.java FileStore.java Store.java StoreFactory.java Log Message: EncryptedFileStore now works. It uses the PBECipher with DES3 afair. Otherwise You will Finaliate. Anything that can be final has been made final throughout everyting. We've used IDEA's Inspector tool to find all instance of variables that could be final. This should hopefully make everything more stable (and secure). Index: EncryptedFileStore.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/store/EncryptedFileStore.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** EncryptedFileStore.java 19 Nov 2003 23:34:00 -0000 1.13 --- EncryptedFileStore.java 21 Nov 2003 04:45:14 -0000 1.14 *************** *** 2,5 **** --- 2,11 ---- * $Id$ * $Log$ + * Revision 1.14 2003/11/21 04:45:14 pelle + * EncryptedFileStore now works. It uses the PBECipher with DES3 afair. + * Otherwise You will Finaliate. + * Anything that can be final has been made final throughout everyting. We've used IDEA's Inspector tool to find all instance of variables that could be final. + * This should hopefully make everything more stable (and secure). + * * Revision 1.13 2003/11/19 23:34:00 pelle * Signers now can generatekeys via the generateKey() method. *************** *** 175,178 **** --- 181,185 ---- import org.neuclear.commons.NeuClearException; import org.neuclear.commons.crypto.CryptoTools; + import org.neuclear.commons.crypto.CryptoException; import org.neuclear.id.NSTools; import org.neuclear.id.SignedNamedObject; *************** *** 180,183 **** --- 187,191 ---- import javax.crypto.CipherInputStream; import javax.crypto.CipherOutputStream; + import javax.crypto.Cipher; import java.io.*; *************** *** 186,219 **** * This EncryptedFileStore stores the objects en encrypted format in a file name based on its path */ ! public class EncryptedFileStore extends FileStore { ! public EncryptedFileStore(String base) { super(base); } ! protected OutputStream getOutputStream(SignedNamedObject obj) throws NeuClearException, FileNotFoundException { ! String outputFilename = base + getFileName(obj); System.out.println("Outputting to: " + outputFilename); ! File outputFile = new File(outputFilename); outputFile.getParentFile().mkdirs(); ! return new CipherOutputStream(new FileOutputStream(outputFile), CryptoTools.getCipher(CryptoTools.digest256(obj.getName().getBytes()), true)); } ! protected InputStream getInputStream(String name) throws FileNotFoundException, NeuClearException { ! String inputFilename = base + getFileName(name); System.out.println("Loading from: " + inputFilename); ! File fin = new File(inputFilename); if (!fin.exists()) throw new NeuClearException("NeuClear: " + name + " doesnt exist"); ! return new CipherInputStream(new FileInputStream(fin), CryptoTools.getCipher(CryptoTools.digest256(name.getBytes()), false)); } ! protected String getFileName(String name) throws NeuClearException { ! String deURLizedName = NSTools.normalizeNameURI(name); ! byte hash[] = CryptoTools.formatAsURLSafe(CryptoTools.digest512(deURLizedName.getBytes())).getBytes(); //if (true) return new String(hash); ! int partlength = hash.length / 8; ! byte newName[] = new byte[hash.length + 8]; for (int i = 0; i < 8; i++) { newName[i * (partlength + 1)] = (byte) '/'; --- 194,235 ---- * This EncryptedFileStore stores the objects en encrypted format in a file name based on its path */ ! public final class EncryptedFileStore extends FileStore { ! public EncryptedFileStore(final String base) { super(base); } ! protected final OutputStream getOutputStream(final SignedNamedObject obj) throws NeuClearException, FileNotFoundException { ! final String outputFilename = base + getFileName(obj); System.out.println("Outputting to: " + outputFilename); ! final File outputFile = new File(outputFilename); outputFile.getParentFile().mkdirs(); ! try { ! return new CipherOutputStream(new FileOutputStream(outputFile), CryptoTools.makePBECipher(Cipher.ENCRYPT_MODE,obj.getName().toCharArray())); ! } catch (Exception e) { ! throw new CryptoException(e); ! } } ! protected final InputStream getInputStream(final String name) throws FileNotFoundException, NeuClearException { ! final String inputFilename = base + getFileName(name); System.out.println("Loading from: " + inputFilename); ! final File fin = new File(inputFilename); if (!fin.exists()) throw new NeuClearException("NeuClear: " + name + " doesnt exist"); ! try { ! return new CipherInputStream(new FileInputStream(fin), CryptoTools.makePBECipher(Cipher.DECRYPT_MODE,name.toCharArray())); ! } catch (Exception e) { ! throw new CryptoException(e); ! } } ! protected final String getFileName(final String name) throws NeuClearException { ! final String deURLizedName = NSTools.normalizeNameURI(name); ! final byte[] hash = CryptoTools.formatAsURLSafe(CryptoTools.digest256(deURLizedName.getBytes())).getBytes(); //if (true) return new String(hash); ! final int partlength = hash.length / 8; ! final byte[] newName = new byte[hash.length + 8]; for (int i = 0; i < 8; i++) { newName[i * (partlength + 1)] = (byte) '/'; Index: FileStore.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/store/FileStore.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** FileStore.java 19 Nov 2003 23:34:00 -0000 1.14 --- FileStore.java 21 Nov 2003 04:45:16 -0000 1.15 *************** *** 2,5 **** --- 2,11 ---- * $Id$ * $Log$ + * Revision 1.15 2003/11/21 04:45:16 pelle + * EncryptedFileStore now works. It uses the PBECipher with DES3 afair. + * Otherwise You will Finaliate. + * Anything that can be final has been made final throughout everyting. We've used IDEA's Inspector tool to find all instance of variables that could be final. + * This should hopefully make everything more stable (and secure). + * * Revision 1.14 2003/11/19 23:34:00 pelle * Signers now can generatekeys via the generateKey() method. *************** *** 179,198 **** */ public class FileStore extends Store { ! public FileStore(String base) { this.base = base; } ! protected void rawStore(SignedNamedObject obj) throws IOException, NeuClearException, XMLException { ! OutputStream out = getOutputStream(obj); out.write(obj.getEncoded().getBytes("UTF-8")); out.close(); } ! protected OutputStream getOutputStream(SignedNamedObject obj) throws NeuClearException, FileNotFoundException { ! String outputFilename = base + getFileName(obj); System.out.println("Outputting to: " + outputFilename); ! File outputFile = new File(outputFilename); outputFile.getParentFile().mkdirs(); ! OutputStream out = new FileOutputStream(outputFile); return out; } --- 185,204 ---- */ public class FileStore extends Store { ! public FileStore(final String base) { this.base = base; } ! protected final void rawStore(final SignedNamedObject obj) throws IOException, NeuClearException, XMLException { ! final OutputStream out = getOutputStream(obj); out.write(obj.getEncoded().getBytes("UTF-8")); out.close(); } ! protected OutputStream getOutputStream(final SignedNamedObject obj) throws NeuClearException, FileNotFoundException { ! final String outputFilename = base + getFileName(obj); System.out.println("Outputting to: " + outputFilename); ! final File outputFile = new File(outputFilename); outputFile.getParentFile().mkdirs(); ! final OutputStream out = new FileOutputStream(outputFile); return out; } *************** *** 202,206 **** // } ! SignedNamedObject fetch(String name) throws NeuClearException { try { --- 208,212 ---- // } ! final SignedNamedObject fetch(final String name) throws NeuClearException { try { *************** *** 214,221 **** } ! protected InputStream getInputStream(String name) throws FileNotFoundException, NeuClearException { ! String inputFilename = base + getFileName(name); System.out.println("Loading from: " + inputFilename); ! File fin = new File(inputFilename); if (!fin.exists()) throw new NeuClearException("NeuClear: " + name + " doesnt exist"); --- 220,227 ---- } ! protected InputStream getInputStream(final String name) throws FileNotFoundException, NeuClearException { ! final String inputFilename = base + getFileName(name); System.out.println("Loading from: " + inputFilename); ! final File fin = new File(inputFilename); if (!fin.exists()) throw new NeuClearException("NeuClear: " + name + " doesnt exist"); *************** *** 225,233 **** ! protected String getFileName(String name) throws NeuClearException { return NSTools.url2path(name) + "/root.id"; } ! protected String getFileName(SignedNamedObject obj) throws NeuClearException { return getFileName(obj.getName()); // if (! (obj instanceof Identity)) --- 231,239 ---- ! protected String getFileName(final String name) throws NeuClearException { return NSTools.url2path(name) + "/root.id"; } ! protected final String getFileName(final SignedNamedObject obj) throws NeuClearException { return getFileName(obj.getName()); // if (! (obj instanceof Identity)) Index: Store.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/store/Store.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Store.java 19 Nov 2003 23:34:00 -0000 1.14 --- Store.java 21 Nov 2003 04:45:16 -0000 1.15 *************** *** 2,5 **** --- 2,11 ---- * $Id$ * $Log$ + * Revision 1.15 2003/11/21 04:45:16 pelle + * EncryptedFileStore now works. It uses the PBECipher with DES3 afair. + * Otherwise You will Finaliate. + * Anything that can be final has been made final throughout everyting. We've used IDEA's Inspector tool to find all instance of variables that could be final. + * This should hopefully make everything more stable (and secure). + * * Revision 1.14 2003/11/19 23:34:00 pelle * Signers now can generatekeys via the generateKey() method. *************** *** 188,192 **** * This handles the Identity checking on the object. */ ! public final org.neuclear.xml.ElementProxy receive(SignedNamedObject obj) throws NeuClearException { try { rawStore(obj); --- 194,198 ---- * This handles the Identity checking on the object. */ ! public final org.neuclear.xml.ElementProxy receive(final SignedNamedObject obj) throws NeuClearException { try { rawStore(obj); *************** *** 202,206 **** * Override this for each specific Store type */ ! protected void rawStore(SignedNamedObject obj) throws IOException, NeuClearException, XMLException { ; } --- 208,212 ---- * Override this for each specific Store type */ ! protected void rawStore(final SignedNamedObject obj) throws IOException, NeuClearException, XMLException { ; } Index: StoreFactory.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/store/StoreFactory.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** StoreFactory.java 11 Nov 2003 21:18:44 -0000 1.3 --- StoreFactory.java 21 Nov 2003 04:45:16 -0000 1.4 *************** *** 2,5 **** --- 2,11 ---- * $Id$ * $Log$ + * Revision 1.4 2003/11/21 04:45:16 pelle + * EncryptedFileStore now works. It uses the PBECipher with DES3 afair. + * Otherwise You will Finaliate. + * Anything that can be final has been made final throughout everyting. We've used IDEA's Inspector tool to find all instance of variables that could be final. + * This should hopefully make everything more stable (and secure). + * * Revision 1.3 2003/11/11 21:18:44 pelle * Further vital reshuffling. *************** *** 69,78 **** ! public class StoreFactory { private StoreFactory() { } ! public synchronized Store getStoreInstance(String path) { // synchronized (store) { if (store==null) --- 75,84 ---- ! public final class StoreFactory { private StoreFactory() { } ! public final synchronized Store getStoreInstance(final String path) { // synchronized (store) { if (store==null) |