public static bool SaveSession(WipeSession session, string path) { // check the parameters if(session == null || path == null) { throw new ArgumentNullException("session | path"); } try { // create the store FileStore.FileStore store = new FileStore.FileStore(); store.Encrypt = true; store.UseDPAPI = true; // add the file FileStore.StoreFile file = store.CreateFile("session.dat"); byte[] data = SerializeSession(session); if(data == null) { return false; } // write the file contents store.WriteFile(file, data, FileStore.StoreMode.Encrypted); return store.Save(path); } catch(Exception e) { Debug.ReportError("Error while saving session. Exception: {0}", e.Message); return false; } }
private void ImportPath_TextChanged(object sender, EventArgs e) { string file = ImportPath.Text; if(File.Exists(file)) { // load store store = new FileStore.FileStore(); if(store.Load(file) == false) { NextButton.Enabled = false; } else { PasswordGroup.Visible = store.Encrypt; NextButton.Enabled = true; } } else { PasswordGroup.Visible = false; NextButton.Enabled = false; } }
private void Export() { FileStore.FileStore store = new FileStore.FileStore(); FileStore.StoreFile file = null; FileStore.StoreMode storeMode = FileStore.StoreMode.Normal; if(EncryptCheckbox.Checked) { SHA256Managed passwordHash = new SHA256Managed(); store.Encrypt = true; store.EncryptionKey = passwordHash.ComputeHash(Encoding.ASCII.GetBytes(PasswordTextbox.Text)); storeMode = FileStore.StoreMode.Encrypted; } // general settings if(GeneralCheckbox.Checked) { file = store.CreateFile("options.dat"); store.WriteFile(file, SDOptionsFile.SerializeOptions(_options), storeMode); } // default plugin settings if(PluginCheckbox.Checked) { file = store.CreateFile("pluginSettings.dat"); if(store.WriteFile(file, SecureDeleteLocations.GetPluginDefaultSettingsFilePath(), storeMode) == false) { actionErrors.Add("Failed to export default plugin settings"); } } // add methods if(MethodsCheckbox.Checked) { store.CreateFolder("methods"); Dictionary<int, string> methodList = new Dictionary<int, string>(); // add methods foreach(ListViewItem item in MethodList.Items) { if(item.Checked) { int id = (int)item.Tag; string methodFile = Path.Combine(SecureDeleteLocations.GetMethodsFolder(), id.ToString() + WipeMethodManager.MethodFileExtension); file = store.CreateFile("methods\\" + Path.GetFileName(methodFile)); if(store.WriteFile(file, methodFile, storeMode) == false) { actionErrors.Add("Failed to export wipe method " + item.Text); } // add to methd list methodList.Add(id, item.Text); } } // store the method list file = store.CreateFile("methods\\list.dat"); store.WriteFile(file, SerializeMethodList(methodList), storeMode); } // scheduled tasks if(TasksCheckbox.Checked) { store.CreateFolder("tasks"); // add task list file = store.CreateFile("tasks\\list.dat"); store.WriteFile(file, SerializeTaskList(_options.SessionNames), storeMode); foreach(ListViewItem item in TaskList.Items) { if(item.Checked) { Guid taskId = (Guid)item.Tag; string taskFile = SecureDeleteLocations.GetTaskFile(taskId); string sessionFile = SecureDeleteLocations.GetSessionFile(taskId); file = store.CreateFile("tasks\\" + Path.GetFileName(taskFile)); ScheduledTask task = new ScheduledTask(); TaskManager.LoadTask(taskFile, out task); store.WriteFile(file, TaskManager.SerializeTask(task), storeMode); file = store.CreateFile("tasks\\" + Path.GetFileName(sessionFile)); WipeSession session = new WipeSession(); SessionLoader.LoadSession(sessionFile, out session); store.WriteFile(file, SessionSaver.SerializeSession(session), storeMode); } } } // save if(store.Save(ExportPath.Text) == false) { actionErrors.Add("Failed to export to file " + ExportPath.Text); } }
public static bool LoadSession(string path, out WipeSession session) { // check the parameters if(path == null) { throw new ArgumentNullException("path"); } session = null; try { // create the store FileStore.FileStore store = new FileStore.FileStore(); store.Encrypt = true; // use encryption store.UseDPAPI = true; // use default encryption // load store if(store.Load(path) == false) { Debug.ReportError("Error while loading store from path {0}", path); return false; } // deserialize session = DeserializeSession(store.ReadFile("session.dat")); return true; } catch(Exception e) { Debug.ReportError("Error while loading session. Exception: {0}", e.Message); return false; } }
public static bool LoadTask(string path, out ScheduledTask task) { // check the parameters if(path == null) { throw new ArgumentNullException("path"); } task = null; try { // create the store FileStore.FileStore store = new FileStore.FileStore(); store.Encrypt = true; store.UseDPAPI = true; // load store if(store.Load(path) == false) { Debug.ReportError("Error while loading store from path {0}", path); return false; } // deserialize task = DeserializeTask(store.ReadFile("task.dat")); return true; } catch(Exception e) { Debug.ReportError("Error while loading task. Exception: {0}", e.Message); return false; } }
/// <summary> /// Save the history database to disk. /// </summary> public bool SaveHistory(string path) { if(path == null) { throw new ArgumentNullException("path"); } try { // create the store FileStore.FileStore store = new FileStore.FileStore(); store.Encrypt = true; store.UseDPAPI = true; // add the file FileStore.StoreFile file = store.CreateFile("history.dat"); byte[] data = SerializeHistory(_categories); if(data == null) { return false; } // write the file contents store.WriteFile(file, data, FileStore.StoreMode.Encrypted); return store.Save(path); } catch(Exception e) { Debug.ReportError("Error while saving task history. Exception: {0}", e.Message); return false; } }
/// <summary> /// Load the report database from disk. /// </summary> public bool LoadHistory(string path) { // check if the file exists if(File.Exists(path) == false) { Debug.ReportWarning("History file not found. Path: {0}", path); return false; } try { // create the store FileStore.FileStore store = new FileStore.FileStore(); store.Encrypt = true; store.UseDPAPI = true; // load store if(store.Load(path) == false) { Debug.ReportError("Error while loading store from path {0}", path); return false; } // deserialize _categories = DeserializeHistory(store.ReadFile("history.dat")); if(_categories == null) { // load failed, allocate history categories _categories = new Dictionary<Guid, HistoryCategory>(); return false; } return true; } catch(Exception e) { Debug.ReportError("Error while loading task history. Exception: {0}", e.Message); return false; } }
public static bool SaveOptions(SDOptions options, string path) { Debug.AssertNotNull(options, "Options is null"); Debug.AssertNotNull(path, "Path is null"); try { // create the store FileStore.FileStore store = new FileStore.FileStore(); store.Encrypt = _encrypt; // set encryption key if(_password != null) { SHA256Managed sha = new SHA256Managed(); store.EncryptionKey = sha.ComputeHash(Encoding.ASCII.GetBytes(_password)); store.UseDPAPI = false; } else { store.UseDPAPI = true; } // add the file FileStore.StoreFile file = store.CreateFile("options.dat"); byte[] data = SerializeOptions(options); if(data == null) { return false; } // write the file contents store.WriteFile(file, data, FileStore.StoreMode.Encrypted); return store.Save(path); } catch(Exception e) { Debug.ReportError("Error while saving options. Exception: {0}", e.Message); return false; } }
public static bool LoadOptions(string path, ref SDOptions options) { // check the parameters if(path == null) { throw new ArgumentNullException("path"); } options = null; try { // create the store FileStore.FileStore store = new FileStore.FileStore(); // set encryption key if(_password != null) { SHA256Managed sha = new SHA256Managed(); store.EncryptionKey = sha.ComputeHash(Encoding.ASCII.GetBytes(_password)); } // load store if(store.Load(path) == false) { Debug.ReportError("Error while loading store from path {0}", path); return false; } // deserialize options = DeserializeOptions(store.ReadFile("options.dat")); return options != null; } catch(Exception e) { Debug.ReportError("Error while loading session. Exception: {0}", e.Message); return false; } }