|
From: <pe...@us...> - 2003-09-22 19:24:14
|
Update of /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/store In directory sc8-pr-cvs1:/tmp/cvs-serv4908/src/java/org/neuclear/store Modified Files: EncryptedFileStore.java FileStore.java Store.java Log Message: More fixes throughout to problems caused by renaming. Index: EncryptedFileStore.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/store/EncryptedFileStore.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** EncryptedFileStore.java 19 Sep 2003 14:41:22 -0000 1.1.1.1 --- EncryptedFileStore.java 22 Sep 2003 19:24:02 -0000 1.2 *************** *** 2,5 **** --- 2,8 ---- * $Id$ * $Log$ + * Revision 1.2 2003/09/22 19:24:02 pelle + * More fixes throughout to problems caused by renaming. + * * Revision 1.1.1.1 2003/09/19 14:41:22 pelle * First import into the neuclear project. This was originally under the SF neudist *************** *** 116,128 **** import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; - import org.neuclear.crypto.CryptoTools; import org.neuclear.id.NSTools; import org.neuclear.id.NamedObject; import org.neuclear.id.NamedObjectFactory; ! import org.neuclear.utils.NeudistException; ! import org.neuclear.utils.Utility; ! import org.neuclear.xml.xmlsec.XMLSecTools; import java.io.*; /** * We need both a simple FileStore and an encrypted one. The encrypted one stores each object using a filename generated through --- 119,132 ---- import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.neuclear.id.NSTools; import org.neuclear.id.NamedObject; import org.neuclear.id.NamedObjectFactory; ! import org.neudist.crypto.CryptoTools; ! import org.neudist.utils.NeudistException; ! import org.neudist.utils.Utility; ! import org.neudist.xml.xmlsec.XMLSecTools; import java.io.*; + /** * We need both a simple FileStore and an encrypted one. The encrypted one stores each object using a filename generated through *************** *** 131,173 **** * */ ! public class EncryptedFileStore extends FileStore { public EncryptedFileStore(String base) { super(base); } ! protected void rawStore(NamedObject obj) throws IOException,NeudistException { ! 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(); ! byte encrypted[]=CryptoTools.encrypt(obj.getName(),XMLSecTools.getElementBytes(obj.getElement())); ! BufferedOutputStream os=new BufferedOutputStream(new FileOutputStream(outputFile)); os.write(encrypted); os.close(); ! } ! protected NamedObject fetch(String name) throws NeudistException { ! 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; ! NamedObject 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); ! ns=NamedObjectFactory.createNamedObject(doc); // Utility.rethrowException(e); } catch (IOException e) { --- 135,179 ---- * */ ! public class EncryptedFileStore extends FileStore { public EncryptedFileStore(String base) { super(base); } ! ! protected void rawStore(NamedObject obj) throws IOException, NeudistException { ! 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(); ! byte encrypted[] = CryptoTools.encrypt(obj.getName(), XMLSecTools.getElementBytes(obj.getElement())); ! BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(outputFile)); os.write(encrypted); os.close(); ! } ! ! protected NamedObject fetch(String name) throws NeudistException { ! 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; ! NamedObject 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); ! ns = NamedObjectFactory.createNamedObject(doc); // Utility.rethrowException(e); } catch (IOException e) { *************** *** 182,204 **** } ! protected static String getFileName(String name) throws NeudistException{ ! 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)'/'; ! System.arraycopy(hash,(i*partlength),newName,(i*(partlength+1))+1,partlength); } try { ! if (hash.length%8!=0) ! System.arraycopy(hash,8*partlength,newName,(8*(partlength+1)),hash.length%8); } catch (ArrayIndexOutOfBoundsException e) { ! System.err.println("hash.length="+hash.length+", newName.length="+newName.length+", partlength="+partlength); ! System.err.println("System.arraycopy(hash,"+9*partlength+",newName,"+(9*(partlength+1))+","+hash.length%8+");"); } return new String(newName); } protected static String getFileName(NamedObject obj) throws NeudistException { return getFileName(obj.getName()); --- 188,211 ---- } ! protected static String getFileName(String name) throws NeudistException { ! 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) '/'; ! System.arraycopy(hash, (i * partlength), newName, (i * (partlength + 1)) + 1, partlength); } try { ! if (hash.length % 8 != 0) ! System.arraycopy(hash, 8 * partlength, newName, (8 * (partlength + 1)), hash.length % 8); } catch (ArrayIndexOutOfBoundsException e) { ! System.err.println("hash.length=" + hash.length + ", newName.length=" + newName.length + ", partlength=" + partlength); ! System.err.println("System.arraycopy(hash," + 9 * partlength + ",newName," + (9 * (partlength + 1)) + "," + hash.length % 8 + ");"); } return new String(newName); } + protected static String getFileName(NamedObject obj) throws NeudistException { return getFileName(obj.getName()); Index: FileStore.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/store/FileStore.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** FileStore.java 19 Sep 2003 14:41:19 -0000 1.1.1.1 --- FileStore.java 22 Sep 2003 19:24:02 -0000 1.2 *************** *** 2,5 **** --- 2,8 ---- * $Id$ * $Log$ + * Revision 1.2 2003/09/22 19:24:02 pelle + * More fixes throughout to problems caused by renaming. + * * Revision 1.1.1.1 2003/09/19 14:41:19 pelle * First import into the neuclear project. This was originally under the SF neudist *************** *** 100,109 **** //import org.neuclear.id.NSDLObject; import org.dom4j.Document; import org.neuclear.id.NSTools; import org.neuclear.id.NamedObject; import org.neuclear.id.NamedObjectFactory; ! import org.neuclear.utils.NeudistException; ! import org.neuclear.xml.XMLTools; import java.io.File; --- 103,113 ---- //import org.neuclear.id.NSDLObject; + import org.dom4j.Document; import org.neuclear.id.NSTools; import org.neuclear.id.NamedObject; import org.neuclear.id.NamedObjectFactory; ! import org.neudist.utils.NeudistException; ! import org.neudist.xml.XMLTools; import java.io.File; *************** *** 111,114 **** --- 115,119 ---- import java.io.FileNotFoundException; import java.io.IOException; + /** * We need both a simple FileStore and an encrypted one. The encrypted one stores each object using a filename generated through *************** *** 117,131 **** * */ ! public class FileStore extends Store { public FileStore(String base) { ! this.base=base; } ! protected void rawStore(NamedObject obj) throws IOException,NeudistException { ! String outputFilename=base+getFileName(obj); ! System.out.println("Outputting to: "+outputFilename); ! File outputFile=new File(outputFilename); outputFile.getParentFile().mkdirs(); ! XMLTools.writeFile(outputFile,obj.getElement()); ! } // public void store(Document doc) throws InvalidNameSpaceException,IOException { --- 122,137 ---- * */ ! public class FileStore extends Store { public FileStore(String base) { ! this.base = base; } ! ! protected void rawStore(NamedObject obj) throws IOException, NeudistException { ! String outputFilename = base + getFileName(obj); ! System.out.println("Outputting to: " + outputFilename); ! File outputFile = new File(outputFilename); outputFile.getParentFile().mkdirs(); ! XMLTools.writeFile(outputFile, obj.getElement()); ! } // public void store(Document doc) throws InvalidNameSpaceException,IOException { *************** *** 133,147 **** // } ! protected NamedObject fetch(String name) throws NeudistException { ! String inputFilename=base+getFileName(NSTools.normalizeNameURI(name)); ! System.out.println("Loading from: "+inputFilename); ! File fin=new File(inputFilename); if (!fin.exists()) return null; ! NamedObject ns=null; try { ! Document doc=XMLTools.loadDocument(new FileInputStream(fin)); ! ns=NamedObjectFactory.createNamedObject(doc); // System.out.println("NEUDIST: Fetched NamedObject tag:"+rootName.getName()+" URI:"+rootName.getNamespaceURI()); // } catch (ParserConfigurationException e) { --- 139,153 ---- // } ! protected NamedObject fetch(String name) throws NeudistException { ! String inputFilename = base + getFileName(NSTools.normalizeNameURI(name)); ! System.out.println("Loading from: " + inputFilename); ! File fin = new File(inputFilename); if (!fin.exists()) return null; ! NamedObject ns = null; try { ! Document doc = XMLTools.loadDocument(new FileInputStream(fin)); ! ns = NamedObjectFactory.createNamedObject(doc); // System.out.println("NEUDIST: Fetched NamedObject tag:"+rootName.getName()+" URI:"+rootName.getNamespaceURI()); // } catch (ParserConfigurationException e) { *************** *** 156,168 **** ! protected static String getFileName(String name) throws NeudistException{ if (name.startsWith("neu://")) ! name=name.substring(5); ! if (name.equals("/")||name.equals("")) return "/root.id"; else ! return name+".id"; } ! protected static String getFileName(NamedObject obj) throws NeudistException{ return getFileName(obj.getName()); // if (! (obj instanceof NameSpace)) --- 162,175 ---- ! protected static String getFileName(String name) throws NeudistException { if (name.startsWith("neu://")) ! name = name.substring(5); ! if (name.equals("/") || name.equals("")) return "/root.id"; else ! return name + ".id"; } ! ! protected static String getFileName(NamedObject obj) throws NeudistException { return getFileName(obj.getName()); // if (! (obj instanceof NameSpace)) Index: Store.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/store/Store.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Store.java 19 Sep 2003 14:41:16 -0000 1.1.1.1 --- Store.java 22 Sep 2003 19:24:02 -0000 1.2 *************** *** 2,5 **** --- 2,8 ---- * $Id$ * $Log$ + * Revision 1.2 2003/09/22 19:24:02 pelle + * More fixes throughout to problems caused by renaming. + * * Revision 1.1.1.1 2003/09/19 14:41:16 pelle * First import into the neuclear project. This was originally under the SF neudist *************** *** 115,119 **** import org.neuclear.id.verifier.NSVerifier; import org.neuclear.receiver.Receiver; ! import org.neuclear.utils.NeudistException; import java.io.IOException; --- 118,122 ---- import org.neuclear.id.verifier.NSVerifier; import org.neuclear.receiver.Receiver; ! import org.neudist.utils.NeudistException; import java.io.IOException; *************** *** 126,130 **** * This handles the NameSpace checking on the object. */ ! public final void receive(NamedObject obj) throws InvalidNameSpaceException, NeudistException { try { // Dont allow overwrites --- 129,133 ---- * This handles the NameSpace checking on the object. */ ! public final void receive(NamedObject obj) throws InvalidNameSpaceException, NeudistException { try { // Dont allow overwrites *************** *** 134,140 **** if (!NSVerifier.isNameValid(obj)) ! throw new InvalidNameSpaceException("The name: "+obj.getName()+" is not allowed"); rawStore(obj); ! if (next!=null) next.receive(obj); --- 137,143 ---- if (!NSVerifier.isNameValid(obj)) ! throw new InvalidNameSpaceException("The name: " + obj.getName() + " is not allowed"); rawStore(obj); ! if (next != null) next.receive(obj); *************** *** 154,158 **** * Override this for each specific Store type */ ! protected void rawStore(NamedObject obj) throws IOException,NeudistException { ; } --- 157,161 ---- * Override this for each specific Store type */ ! protected void rawStore(NamedObject obj) throws IOException, NeudistException { ; } |