private BooleanResult unmountCloud(string guid) { // Helper result object BooleanResult res = null; // Check to see if it is mounted // Dictionary <string, string> mounts = EncryptFS.GetAllMountedEncFS(); if (mounts == null) { return(new BooleanResult() { Success = false, Message = "ERROR: Cannot figure out which EncFS instances are mounted!" }); } if (!mounts.ContainsKey(guid)) { return(new BooleanResult() { Success = false, Message = "This encrypted folder does not appear to be mounted!" }); } // * // // Determine where this cloud is mounted to // string targetDrive = (string)Registry.GetValue(Config.CURR_USR_REG_DRIVE_ROOT + guid, "encDrive", null); if (string.IsNullOrEmpty(targetDrive)) { return(new BooleanResult() { Success = false, Message = "ERROR: Target drive not found! Is cloud mounted?" }); } // * // // Unmount encrypted drive res = EncryptFS.UnmountEncryptedFS(targetDrive); if (res == null || !res.Success) { return(res); } // * // return(new BooleanResult() { Success = true }); }
// * // // Create new encrypted filesystem // public static BooleanResult CreateEncryptedFS(string guid, string volumeLoc, string targetDrive, string masterKey, string label, bool keepMounted = false) { // Path cannot end with a slash due to CMD usage volumeLoc = volumeLoc.TrimEnd(new[] { '/', '\\' }); // GET EncFS DIRECTORY string programDir = Toolbox.GetSoftwareDirectory(Config.Software.EncFS); if (programDir == null) { return(new BooleanResult() { Success = false, Message = "ERROR: EncFS inaccessible!" }); } // GET Dokan DIRECTORY string dokanDir = Toolbox.GetSoftwareDirectory(Config.Software.Dokan); if (dokanDir == null) { return(new BooleanResult() { Success = false, Message = "ERROR: Dokan inaccessible!" }); } // Determine Keenou config file location for this volume string configLoc = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\Keenou\" + guid + @"\"; if (Directory.Exists(configLoc)) { // TODO: auto-recovery? return(new BooleanResult() { Success = false, Message = "ERROR: Possible GUID collision!" }); } // Create config file directory for this FS Directory.CreateDirectory(configLoc); // Save setting values to registry Registry.SetValue(Config.CURR_USR_REG_DRIVE_ROOT + guid, "encContainerLoc", volumeLoc); Registry.SetValue(Config.CURR_USR_REG_DRIVE_ROOT + guid, "configLoc", configLoc); using (Process process = new Process()) { // MOUNT ENCRYPTED CONTAINER ProcessStartInfo startInfo = new ProcessStartInfo(); try { //.\encfs.exe "C:\Users\jetwhiz\Desktop\encfs4win\testing" "Z:" --stdinpass -o volname="Secure Dropbox" startInfo.WindowStyle = ProcessWindowStyle.Hidden; startInfo.CreateNoWindow = true; startInfo.RedirectStandardInput = true; startInfo.UseShellExecute = false; startInfo.FileName = "cmd.exe"; startInfo.EnvironmentVariables["ENCFS6_CONFIG"] = configLoc + Config.ENCFS_CONFIG_FILENAME; startInfo.Arguments = "/C \"\"" + programDir + "encfs.exe\" --stdinpass -o volname=\"" + label + "\" \"" + volumeLoc + "\" \"" + targetDrive + ":\"\""; process.StartInfo = startInfo; process.Start(); // Send stdin inputs to program StreamWriter myStreamWriter = process.StandardInput; myStreamWriter.WriteLine("p"); // paranoia mode myStreamWriter.WriteLine(masterKey); // user's password myStreamWriter.Close(); // Give it a few seconds to finish // TODO: Figure out better way to determine when EncFS has finished process.WaitForExit(10000); // Unmount drive (forcing the closing of encfs process) if not already exited if (!process.HasExited) { // Auto-unmount unless they asked us not to if (!keepMounted) { BooleanResult res = EncryptFS.UnmountEncryptedFS(targetDrive); if (res == null || !res.Success) { return(res); } } else { // Invalidate all other EncFS instances that still claim to be using this drive EncryptFS.InvalidateDrive(targetDrive); // Save where we mounted the encrypted volume Registry.SetValue(Config.CURR_USR_REG_DRIVE_ROOT + guid, "encDrive", targetDrive); } } else { // If it exited by itself, it was in error return(new BooleanResult() { Success = false, Message = "ERROR: Error while creating encrypted FS! " + process.ExitCode }); } // Process will block indefinitely (until unmount called), so just return //process.WaitForExit(); } catch (Exception err) { return(new BooleanResult() { Success = false, Message = "ERROR: Failed to create encrypted FS! " + err.Message }); } } return(new BooleanResult() { Success = true }); }