Ejemplo n.º 1
0
        // * //



        // Invalidate a drive letter (it is no longer valid) //
        public static BooleanResult InvalidateDrive(string drive)
        {
            // Loop through all drives looking for ones matching input
            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("encDrive") != null && key.GetValue("encDrive").ToString().ToLower() == drive.ToLower())
                    {
                        // Found a match!  Invalidate it
                        string guid = Keyname.ToString();
                        Registry.SetValue(Config.CURR_USR_REG_DRIVE_ROOT + guid, "encDrive", string.Empty);
                    }
                }
            }

            return(new BooleanResult()
            {
                Success = true
            });
        }
Ejemplo n.º 2
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
        }
Ejemplo n.º 3
0
        // Return a list of all EncFS instances that are currently mounted //
        public static Dictionary <string, string> GetAllMountedEncFS(string filter = null)
        {
            Dictionary <string, string> ret = new Dictionary <string, string>();

            try
            {
                using (ManagementClass diskClass = new ManagementClass("Win32_LogicalDisk"))
                {
                    using (ManagementObjectCollection mocDisks = diskClass.GetInstances())
                    {
                        // Loop through all of the logical disks
                        foreach (ManagementObject moDisk in mocDisks)
                        {
                            string drive = null, guid = null;


                            // Determine the drive letter
                            string driveRaw = moDisk.GetPropertyValue("DeviceID").ToString();
                            if (driveRaw == null || driveRaw.Length != 2 || !driveRaw.EndsWith(":"))
                            {
                                continue;
                            }
                            drive = driveRaw.Substring(0, 1);


                            // Skip if this isn't the one they want (if specified)
                            if (filter != null && drive.ToLower() != filter.ToLower())
                            {
                                continue;
                            }


                            // If this is not an EncFS mount, skip it
                            string fs = (moDisk.GetPropertyValue("FileSystem") ?? string.Empty).ToString();
                            if (!fs.ToLower().Contains("encfs"))
                            {
                                continue;
                            }


                            // Loop through all saved EncFS drives looking for ones matching this one
                            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("encDrive") != null && key.GetValue("encDrive").ToString().ToLower() == drive.ToLower())
                                    {
                                        // Found a match
                                        guid = Keyname.ToString();
                                        break;
                                    }
                                }
                            }
                            // TODO: above code can be streamlined in future instead of scanning registry each time


                            // Save this result if it is valid
                            // If guid is null, it might be an EncFS not managed by Keenou
                            if (guid != null)
                            {
                                ret.Add(guid, drive);
                            }


                            // If filter was given, we've matched it (so stop!)
                            if (filter != null)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                return(null);
            }

            return(ret);
        }