Exemplo n.º 1
0
        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
            });
        }
Exemplo n.º 2
0
        private BooleanResult mountCloud(string guid, Config.Clouds cloudSelected, string cloudPath)
        {
            // Get password from user //
            var promptPassword = new PromptPassword();

            if (promptPassword.ShowDialog() != DialogResult.OK)
            {
                // Cancelled
                return(new BooleanResult()
                {
                    Success = true
                });
            }
            string password = promptPassword.CloudPassword;
            // * //


            // GET NEXT FREE DRIVE LETTER
            string targetDrive = Toolbox.GetNextFreeDriveLetter();

            if (targetDrive == null)
            {
                return(new BooleanResult()
                {
                    Success = false, Message = "ERROR: Cannot find a free drive letter!"
                });
            }
            // * //


            // Helper result object
            BooleanResult res = null;



            // Check to see if it is already 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 appears to already be mounted!"
                });
            }
            // * //



            // Get and decrypt user's master key (using user password) //
            string masterKey = null;
            string encHeader = (string)Registry.GetValue(Config.CURR_USR_REG_DRIVE_ROOT + guid, "encHeader", null);

            if (string.IsNullOrEmpty(encHeader))
            {
                return(new BooleanResult()
                {
                    Success = false, Message = "ERROR: User's header information could not be found!"
                });
            }

            masterKey = Toolbox.PasswordDecryptKey(encHeader, password);

            // Make sure we got a key back
            if (masterKey == null)
            {
                return(new BooleanResult()
                {
                    Success = false, Message = "ERROR: Failed to decrypt master key!"
                });
            }
            // * //



            // Mount their freshly-created encrypted drive
            res = EncryptFS.MountEncryptedFS(guid, targetDrive, masterKey, "Secure " + cloudSelected.ToString());
            if (res == null || !res.Success)
            {
                return(res);
            }
            // * //


            return(new BooleanResult()
            {
                Success = true
            });
        }
Exemplo n.º 3
0
        private void b_cloudAction_Click(object sender, EventArgs e)
        {
            // Determine which type of cloud service they want to perform action on
            Config.Clouds cloudSelected;
            if (rb_cloud_Google.Checked)
            {
                cloudSelected = Config.Clouds.GoogleDrive;
            }
            else if (rb_cloud_OneDrive.Checked)
            {
                cloudSelected = Config.Clouds.OneDrive;
            }
            else if (rb_cloud_Dropbox.Checked)
            {
                cloudSelected = Config.Clouds.Dropbox;
            }
            else
            {
                ReportEncryptCloudError(new BooleanResult()
                {
                    Success = false, Message = "ERROR: Unsupported cloud type selected!"
                });
                return;
            }
            // * //



            // Figure out where the cloud's folder is on this computer //
            string cloudPath = EncryptFS.GetCloudServicePath(cloudSelected);

            if (cloudPath == null)
            {
                ReportEncryptCloudError(new BooleanResult()
                {
                    Success = false, Message = "ERROR: Cannot determine the location of your cloud service!"
                });
                return;
            }
            // * //



            // Find guid of desired cloud folder //
            string      guid   = null;
            RegistryKey OurKey = Registry.CurrentUser;

            OurKey = OurKey.OpenSubKey(@"Software\Keenou\drives");
            if (OurKey != null)
            {
                foreach (string Keyname in OurKey.GetSubKeyNames())
                {
                    RegistryKey key = OurKey.OpenSubKey(Keyname);
                    if (key.GetValue("encContainerLoc") != null && key.GetValue("encContainerLoc").ToString() == cloudPath)
                    {
                        guid = Keyname.ToString();
                    }
                }
            }
            // * //


            // Helper result object
            BooleanResult res = null;


            // If there is no registered guid yet, then it's the first time (set up) //
            if (guid == null)
            {
                res = this.encryptCloud(cloudSelected, cloudPath);
                if (res == null || !res.Success)
                {
                    ReportEncryptCloudError(res);
                    return;
                }
                return;
            }
            // * //



            // Check to see if it is mounted //
            Dictionary <string, string> mounts = EncryptFS.GetAllMountedEncFS();

            if (mounts == null)
            {
                ReportEncryptCloudError(new BooleanResult()
                {
                    Success = false, Message = "ERROR: Cannot figure out which EncFS instances are mounted!"
                });
                return;
            }
            if (mounts.ContainsKey(guid))
            {
                // already mounted -- unmount
                res = this.unmountCloud(guid);
                if (res == null || !res.Success)
                {
                    ReportEncryptCloudError(res);
                    return;
                }
                return;
            }
            else
            {
                // not yet mounted -- mount
                res = this.mountCloud(guid, cloudSelected, cloudPath);
                if (res == null || !res.Success)
                {
                    ReportEncryptCloudError(res);
                    return;
                }
                return;
            }
            // * //


            // We should never make it to here
        }