|
From: <pe...@us...> - 2003-11-18 19:24:01
|
Update of /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/store
In directory sc8-pr-cvs1:/tmp/cvs-serv11821
Modified Files:
EncryptedFileStore.java FileStore.java
Log Message:
Missed this in latest checkin
Index: EncryptedFileStore.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/store/EncryptedFileStore.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** EncryptedFileStore.java 11 Nov 2003 21:18:44 -0000 1.10
--- EncryptedFileStore.java 18 Nov 2003 19:23:58 -0000 1.11
***************
*** 2,5 ****
--- 2,8 ----
* $Id$
* $Log$
+ * Revision 1.11 2003/11/18 19:23:58 pelle
+ * Missed this in latest checkin
+ *
* Revision 1.10 2003/11/11 21:18:44 pelle
* Further vital reshuffling.
***************
*** 158,166 ****
package org.neuclear.store;
/**
! * We need both a simple FileStore and an encrypted one. The encrypted one stores each object using a filename generated through
! * a Hashing system of some sort. The files themselves are encrypted using perhaps their name and a store specific code. The filetimes would also be set to a
! * uniform time, so if the operator was sopeanad(Spelling) i
*/
public class EncryptedFileStore extends FileStore {
--- 161,179 ----
package org.neuclear.store;
+ import org.neuclear.id.builders.NamedObjectBuilder;
+ import org.neuclear.id.NSTools;
+ import org.neuclear.id.SignedNamedObject;
+ import org.neuclear.commons.crypto.CryptoTools;
+ import org.neuclear.commons.NeuClearException;
+
+ import javax.crypto.CipherOutputStream;
+ import javax.crypto.Cipher;
+ import javax.crypto.NoSuchPaddingException;
+ import java.io.*;
+ import java.security.NoSuchAlgorithmException;
+
/**
! * This EncryptedFileStore stores the objects en encrypted format in a file name based on its path
*/
public class EncryptedFileStore extends FileStore {
***************
*** 169,223 ****
super(base);
}
- /*
! protected void rawStore(SignedNamedObject obj) throws IOException, NeuClearException {
String outputFilename = base + getFileName(obj);
System.out.println("Outputting to: " + outputFilename);
File outputFile = new File(outputFilename);
outputFile.getParentFile().mkdirs();
- // Quick and dirty encryption for now.
- // String xmlData=obj.getElement().asXML();
- //TODO Find alternative byte encrypted[] = CryptoTools.encrypt(obj.getName(), XMLSecTools.getElementBytes(obj.getElement()));
! BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(outputFile));
! //TODO Find alternative os.write(encrypted);
! os.close();
! }
! protected SignedNamedObject fetch(String name) throws NeuClearException {
! String deURLizedName = NSTools.normalizeNameURI(name);
! String inputFilename = base + getFileName(deURLizedName);
System.out.println("Loading from: " + inputFilename);
File fin = new File(inputFilename);
if (!fin.exists())
! return null;
!
! SignedNamedObject ns = null;
! try {
! byte input[] = new byte[(int) fin.length()];
! FileInputStream fis = new FileInputStream(fin);
! fis.read(input, 0, input.length);
! byte clear[] = CryptoTools.decrypt(deURLizedName.getBytes(), input);
! int last = clear.length;
! for (last = clear.length; clear[last - 1] != (byte) '>'; last--) ;
! String clearString = new String(clear, 0, last);
! // System.out.print("Read: ");
! // System.out.println(clearString);
! org.dom4j.Document doc = DocumentHelper.parseText(clearString);
! //TODO Find alternative ns = NamedObjectFactory.createNamedObject(doc);
! // Utility.rethrowException(e);
! } catch (IOException e) {
! Utility.rethrowException(e);
! } catch (DocumentException e) {
! Utility.rethrowException(e);
! // } catch (FileNotFoundException e) {
! // Utility.rethrowException(e);
! }
!
! return ns;
}
! protected static String getFileName(String name) throws NeuClearException {
String deURLizedName = NSTools.normalizeNameURI(name);
byte hash[] = CryptoTools.formatAsURLSafe(CryptoTools.digest512(deURLizedName.getBytes())).getBytes();
--- 182,216 ----
super(base);
}
! protected OutputStream getOutputStream(NamedObjectBuilder obj) throws NeuClearException, FileNotFoundException {
String outputFilename = base + getFileName(obj);
System.out.println("Outputting to: " + outputFilename);
File outputFile = new File(outputFilename);
outputFile.getParentFile().mkdirs();
+ try {
+ Cipher cipher = Cipher.getInstance("AES");
+ //TODO Initialise cipher with key
+ return new CipherOutputStream(new FileOutputStream(outputFile),cipher);
! } catch (NoSuchAlgorithmException e) {
! throw new NeuClearException(e);
! } catch (NoSuchPaddingException e) {
! throw new NeuClearException(e);
! }
! }
! protected FileInputStream 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");
! //TODO add CipherInputStream
! return new FileInputStream(fin);
}
!
! protected String getFileName(String name) throws NeuClearException {
String deURLizedName = NSTools.normalizeNameURI(name);
byte hash[] = CryptoTools.formatAsURLSafe(CryptoTools.digest512(deURLizedName.getBytes())).getBytes();
***************
*** 238,247 ****
return new String(newName);
}
-
- protected static String getFileName(SignedNamedObject obj) throws NeuClearException {
- return getFileName(obj.getName());
- }
-
- */
}
--- 231,234 ----
Index: FileStore.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/store/FileStore.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** FileStore.java 18 Nov 2003 15:45:09 -0000 1.11
--- FileStore.java 18 Nov 2003 19:23:58 -0000 1.12
***************
*** 2,5 ****
--- 2,8 ----
* $Id$
* $Log$
+ * Revision 1.12 2003/11/18 19:23:58 pelle
+ * Missed this in latest checkin
+ *
* Revision 1.11 2003/11/18 15:45:09 pelle
* FileStoreTest now passes. FileStore works again.
***************
*** 172,175 ****
--- 175,184 ----
protected void rawStore(NamedObjectBuilder obj) throws IOException, NeuClearException, XMLException {
+ OutputStream out = getOutputStream(obj);
+ out.write(obj.canonicalize());
+ out.close();
+ }
+
+ protected OutputStream getOutputStream(NamedObjectBuilder obj) throws NeuClearException, FileNotFoundException {
String outputFilename = base + getFileName(obj);
System.out.println("Outputting to: " + outputFilename);
***************
*** 177,182 ****
outputFile.getParentFile().mkdirs();
OutputStream out=new FileOutputStream(outputFile);
! out.write(obj.canonicalize());
! out.close();
}
--- 186,190 ----
outputFile.getParentFile().mkdirs();
OutputStream out=new FileOutputStream(outputFile);
! return out;
}
***************
*** 186,197 ****
SignedNamedObject fetch(String name) throws NeuClearException {
- String inputFilename = base + getFileName(name);
- System.out.println("Loading from: " + inputFilename);
- File fin = new File(inputFilename);
- if (!fin.exists())
- return null;
try {
! return VerifyingReader.getInstance().read(new FileInputStream(fin));
} catch (FileNotFoundException e) {
e.printStackTrace();
--- 194,200 ----
SignedNamedObject fetch(String name) throws NeuClearException {
try {
! return VerifyingReader.getInstance().read(getInputStream(name));
} catch (FileNotFoundException e) {
e.printStackTrace();
***************
*** 202,211 ****
}
! protected static String getFileName(String name) throws NeuClearException {
return NSTools.url2path(name)+"/root.id";
}
! protected static String getFileName(NamedObjectBuilder obj) throws NeuClearException {
return getFileName(obj.getName());
// if (! (obj instanceof Identity))
--- 205,224 ----
}
+ protected FileInputStream 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 FileInputStream(fin);
+ }
+
! protected String getFileName(String name) throws NeuClearException {
return NSTools.url2path(name)+"/root.id";
}
! protected String getFileName(NamedObjectBuilder obj) throws NeuClearException {
return getFileName(obj.getName());
// if (! (obj instanceof Identity))
|