public static void Main(string[] args) { #if DEBUG args = new string[]{"SafeBox", "Repo", "watchTest", "Bob"}; #else if (args.Length != 4) { Console.WriteLine ("Usage: Watcher.exe <directory path> <repo> <prefix> <recipient key>"); return; } #endif string path = args [0]; Repo repo = Repo.Create (args [1]); string prefix = args [2]; string recipientName = args [3]; Directory.CreateDirectory (path); KeyStorage keyStorage = KeyStorage.Default; PublicKey recipientKey = null; if (recipientName != null) { recipientKey = keyStorage.GetPublic (recipientName); EncryptedRepo er = new EncryptedRepo (repo, keyStorage); er.AddKey (recipientKey); repo = er; } DirectoryWatcher dw = new DirectoryWatcher (path, repo, prefix); dw.Run (); }
public static void Main(string[] args, KeyStorage keyStorage) { //Usage if (args.Length != 4) throw new HelpException ("Missing arguments"); string sourcePath = args [1]; string repoPath = args [2]; string receipientName = args [3]; //Source if (Directory.Exists (sourcePath) == false) throw new HelpException ("Source directory not found: " + sourcePath); //Repo Repo repo = Repo.Create (repoPath); //Sender and Recipient keys PrivateKey senderKey = keyStorage.DefaultKey; PublicKey recipientKey = keyStorage.GetPublic (receipientName); //Prepare Route message recording of ChunkID RouteRepo rr = new RouteRepo (repo); //Prepare Encryption EncryptedRepo er = new EncryptedRepo (rr, null); er.AddKey (recipientKey); Console.Write ("Generating Tree..."); //Send Tree ChunkHash tree = TreeChunk.GenerateChunk (sourcePath, er); //TreeMessage TreeMessage tm = new TreeMessage (tree, Path.GetDirectoryName (sourcePath)); Chunk tmc = Message.ToChunk (tm, senderKey); ChunkHash tmch = er.WriteChunk (tmc); er.StoreMessage ("file", tmch); //RouteMessage RouteMessage rm = rr.RouteMessage; rm.MessageChunkHash = tmch.bytes; rm.To = receipientName; //Store unencrypted RouteMessage Chunk rmChunk = Message.ToChunk (rm); repo.WriteChunk (rmChunk); repo.StoreMessage ("route", rmChunk.ChunkHash); Console.WriteLine ("RouteMessage Stored"); }
/// <summary> /// Test reading and writing to repo /// </summary> public static void Main(string[] args, KeyStorage keyStorage) { //Test buffer to transmit byte[] buffer = new byte[4096]; Random r = new Random (); r.NextBytes (buffer); string recipientName = null; if (args.Length == 3) recipientName = args [2]; if (args.Length > 3 || args.Length < 2) throw new HelpException ("Missing arguments"); string repoPath = args [1]; //Repository Repo repo = Repo.Create (repoPath); //Sender and Recipient keys PublicKey recipientKey = null; if (recipientName != null) { recipientKey = keyStorage.GetPublic (recipientName); EncryptedRepo er = new EncryptedRepo (repo, keyStorage); er.AddKey (recipientKey); repo = er; } Chunk c = new Chunk (buffer); var ch = repo.WriteChunk (c); Chunk c2 = repo.ReadChunk (ch); for (int n = 0; n < buffer.Length; n++) if (buffer [n] != c2.Data [n]) throw new InvalidDataException ("Failed at byte " + n); Console.WriteLine ("Test succeded"); }