Example #1
0
        public static bool IsBootVolume(string deviceID, out Exception ex)
        {
            ex = null;
            string bootVolumeDeviceID = BitlockerUtil.GetBootVolumeDeviceID(out ex);

            return(bootVolumeDeviceID != null && bootVolumeDeviceID.Equals(deviceID));
        }
Example #2
0
        public static bool DoesVolumeHaveBadBlocks(string volumeId, out string mountPoint, out Exception ex, out string eventXML)
        {
            bool flag = false;

            mountPoint = null;
            eventXML   = null;
            Dictionary <string, string> mountPointVolumeIDMappings = BitlockerUtil.GetMountPointVolumeIDMappings(out ex);

            if (mountPointVolumeIDMappings == null)
            {
                ex = new MountPointsFindException(ex.Message, ex);
                return(false);
            }
            if (!mountPointVolumeIDMappings.ContainsValue(volumeId))
            {
                ex = new InvalidVolumeIdException(volumeId);
                return(false);
            }
            foreach (string text in mountPointVolumeIDMappings.Keys)
            {
                if (mountPointVolumeIDMappings[text].Equals(volumeId))
                {
                    flag = BitlockerUtil.DoesMountPointHaveBadBlocks(text, out ex, out eventXML);
                    if (flag)
                    {
                        mountPoint = text;
                        break;
                    }
                }
            }
            return(flag);
        }
Example #3
0
        public static ManagementObject GetEncryptableVolume(string deviceId, out Exception ex)
        {
            ManagementObject encryptableVolume = null;

            ex = Util.HandleExceptions(delegate
            {
                ManagementObjectCollection encryptableVolumes = BitlockerUtil.GetEncryptableVolumes();
                if (encryptableVolumes != null)
                {
                    using (encryptableVolumes)
                    {
                        foreach (ManagementBaseObject managementBaseObject in encryptableVolumes)
                        {
                            ManagementObject managementObject = (ManagementObject)managementBaseObject;
                            using (managementObject)
                            {
                                string text = managementObject.GetPropertyValue("DeviceId").ToString();
                                if (text.Equals(deviceId))
                                {
                                    encryptableVolume = managementObject;
                                    break;
                                }
                            }
                        }
                    }
                }
            });
            return(encryptableVolume);
        }
Example #4
0
        public static bool IsVolumeEncryptionPaused(ManagementObject encryptableVolume, out Exception ex)
        {
            int num;

            BitlockerUtil.BitlockerConversionState bitlockerConversionState = BitlockerUtil.GetBitlockerConversionState(encryptableVolume, out num, out ex);
            return(bitlockerConversionState == BitlockerUtil.BitlockerConversionState.EncryptionPaused);
        }
        public static Exception UnlockWithNumericalPassword(ManagementObject encryptableVolume, string numericalPassword, out int returnValueUnlockWithNumericalPassword)
        {
            ManagementBaseObject outParams = null;
            int       returnValue          = -1;
            Exception ex = Util.HandleExceptions(delegate
            {
                string deviceId = BitlockerUtil.GetDeviceId(encryptableVolume);
                Exception ex2;
                if (!BitlockerLockUtil.IsVolumeLocked(encryptableVolume, out ex2))
                {
                    returnValue = 0;
                    throw new VolumeLockedFindException(deviceId, ex2.Message, ex2);
                }
                returnValue = WMIUtil.CallWMIMethod(encryptableVolume, "UnlockWithNumericalPassword", new string[]
                {
                    "NumericalPassword"
                }, new object[]
                {
                    numericalPassword
                }, out outParams);
            });

            returnValueUnlockWithNumericalPassword = returnValue;
            Util.AssertReturnValueExceptionInconsistency(returnValueUnlockWithNumericalPassword, "UnlockWithNumericalPassword", ex);
            return(Util.ReturnWMIErrorExceptionOnExceptionOrError(returnValueUnlockWithNumericalPassword, "UnlockWithNumericalPassword", ex));
        }
        public static Exception LockDataVolume(ManagementObject encryptableVolume, out int returnValueLock)
        {
            ManagementBaseObject outParams = null;
            int       returnValue          = -1;
            Exception ex = Util.HandleExceptions(delegate
            {
                string deviceId = BitlockerUtil.GetDeviceId(encryptableVolume);
                Exception ex2;
                if (BitlockerLockUtil.IsVolumeLocked(encryptableVolume, out ex2))
                {
                    if (ex2 != null)
                    {
                        throw new VolumeLockedFindException(deviceId, ex2.Message, ex2);
                    }
                }
                else
                {
                    returnValue = WMIUtil.CallWMIMethod(encryptableVolume, "Lock", null, null, out outParams);
                    if (BitlockerLockUtil.IsVolumeLocked(encryptableVolume, out ex2) && ex2 != null)
                    {
                        throw new VolumeLockedFindException(deviceId, ex2.Message, ex2);
                    }
                }
            });

            returnValueLock = returnValue;
            Util.AssertReturnValueExceptionInconsistency(returnValueLock, "LockDataVolume", ex);
            return(Util.ReturnWMIErrorExceptionOnExceptionOrError(returnValueLock, "LockDataVolume", ex));
        }
Example #7
0
        public static Exception AddCertificateBasedKeyProtectors(ManagementObject encryptableVolume, out int returnValueCertificate)
        {
            int returnValue = -1;

            returnValueCertificate = -1;
            Exception result = null;
            ArrayList bitlockerCertThumbPrints = BitlockerUtil.GetBitlockerCertThumbPrints(out result);

            if (bitlockerCertThumbPrints == null)
            {
                return(new BitlockerCertificatesNotFoundException());
            }
            using (IEnumerator enumerator = bitlockerCertThumbPrints.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    string bitlockerCertThumbPrint = (string)enumerator.Current;
                    result = Util.HandleExceptions(delegate
                    {
                        ManagementBaseObject managementBaseObject = null;
                        returnValue = WMIUtil.CallWMIMethod(encryptableVolume, "ProtectKeyWithCertificateThumbprint", new string[]
                        {
                            "FriendlyName",
                            "CertThumbprint"
                        }, new object[]
                        {
                            bitlockerCertThumbPrint,
                            bitlockerCertThumbPrint
                        }, out managementBaseObject);
                    });
                }
            }
            returnValueCertificate = returnValue;
            return(result);
        }
        public static List <string> GetLockedVolumes(out Exception ex)
        {
            List <string> lockedVolumes = null;

            ex = Util.HandleExceptions(delegate
            {
                ManagementObjectCollection encryptableVolumes = BitlockerUtil.GetEncryptableVolumes();
                if (encryptableVolumes != null)
                {
                    foreach (ManagementBaseObject managementBaseObject in encryptableVolumes)
                    {
                        ManagementObject managementObject = (ManagementObject)managementBaseObject;
                        string item = managementObject.GetPropertyValue("DeviceId").ToString();
                        Exception ex2;
                        bool flag = BitlockerLockUtil.IsVolumeLocked(managementObject, out ex2);
                        Util.ThrowIfNotNull(ex2);
                        if (flag)
                        {
                            if (lockedVolumes == null)
                            {
                                lockedVolumes = new List <string>();
                            }
                            lockedVolumes.Add(item);
                        }
                    }
                }
            });
            return(lockedVolumes);
        }
Example #9
0
        public static bool IsBootVolume(ManagementObject encryptableVolume, out Exception ex)
        {
            ex = null;
            if (encryptableVolume == null)
            {
                return(false);
            }
            string deviceID = encryptableVolume.GetPropertyValue("DeviceID").ToString();

            return(BitlockerUtil.IsBootVolume(deviceID, out ex));
        }
Example #10
0
        public static Exception ValidateAndEncryptEmptyWin8Volume(ManagementObject encryptableVolume, bool fipsCompliant, out int returnValueEncrypt)
        {
            int returnValue = -1;

            returnValueEncrypt = -1;
            if (encryptableVolume == null)
            {
                return(new EncryptableVolumeArgNullException("ValidateAndEncryptEmptyWin8Volume"));
            }
            string deviceID = encryptableVolume.GetPropertyValue("DeviceId").ToString();

            if (!Util.IsOperatingSystemWin8OrHigher())
            {
                return(new UsedOnlyEncryptionOnNonWin8ServerException(deviceID));
            }
            Exception ex = Util.HandleExceptions(delegate
            {
                Exception ex = null;
                if (!BitlockerUtil.IsVolumeEmpty(deviceID, out ex))
                {
                    Util.ThrowIfNotNull(ex);
                    throw new UsedOnlySpaceEncryptionAttemptOnANonEmptyVolumeException(deviceID);
                }
                if (!fipsCompliant)
                {
                    ex = BitlockerUtil.AddNumericalPassword(encryptableVolume, "563563-218372-416746-433752-541937-608069-594110-446754", out returnValue);
                    Util.ThrowIfNotNull(ex);
                }
                ex = BitlockerUtil.AddCertificateBasedKeyProtectors(encryptableVolume, out returnValue);
                Util.ThrowIfNotNull(ex);
                ex = BitlockerUtil.Encrypt(encryptableVolume, true, out returnValue);
                Util.ThrowIfNotNull(ex);
                TimeSpan timeSpan = TimeSpan.FromSeconds(300.0);
                BitlockerUtil.BitlockerConversionState bitlockerConversionState;
                while ((bitlockerConversionState = BitlockerUtil.GetBitlockerConversionState(encryptableVolume, out returnValue, out ex)) != BitlockerUtil.BitlockerConversionState.FullyEncrypted)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(1.0));
                    timeSpan = timeSpan.Subtract(TimeSpan.FromSeconds(1.0));
                    if (timeSpan.CompareTo(TimeSpan.Zero) < 0)
                    {
                        break;
                    }
                }
                if (bitlockerConversionState != BitlockerUtil.BitlockerConversionState.FullyEncrypted)
                {
                    throw new Win8EmptyVolumeNotFullyEncryptedAfterWaitException(deviceID, 300, bitlockerConversionState.ToString());
                }
            });

            returnValueEncrypt = returnValue;
            return(Util.ReturnWMIErrorExceptionOnExceptionOrError(returnValueEncrypt, "ValidateAndEncryptEmptyWin8Volume", ex));
        }
Example #11
0
        public static Exception ValidateAndEncryptEmptyWin7Volume(ManagementObject encryptableVolume, bool fipsCompliant, out int returnValueEncrypt)
        {
            int returnValue = -1;

            returnValueEncrypt = -1;
            if (encryptableVolume == null)
            {
                return(new EncryptableVolumeArgNullException("ValidateAndEncryptEmptyWin7Volume"));
            }
            string deviceID = encryptableVolume.GetPropertyValue("DeviceId").ToString();

            if (Util.IsOperatingSystemWin8OrHigher())
            {
                return(new FullVolumeEncryptionOnWin8ServerException(deviceID));
            }
            Exception ex = Util.HandleExceptions(delegate
            {
                Exception ex = null;
                if (!BitlockerUtil.IsVolumeEmpty(deviceID, out ex))
                {
                    Util.ThrowIfNotNull(ex);
                    throw new FullVolumeEncryptionAttemptOnANonEmptyVolumeException(deviceID);
                }
                string mountPoint;
                string eventXML;
                bool flag = BitlockerUtil.DoesVolumeHaveBadBlocks(deviceID, out mountPoint, out ex, out eventXML);
                if (flag)
                {
                    throw new Win7EmptyVolumeNotStartedDueToPreviousFailureBadBlocksException(deviceID, mountPoint, eventXML);
                }
                if (!fipsCompliant)
                {
                    ex = BitlockerUtil.AddNumericalPassword(encryptableVolume, "563563-218372-416746-433752-541937-608069-594110-446754", out returnValue);
                    Util.ThrowIfNotNull(ex);
                }
                ex = BitlockerUtil.AddCertificateBasedKeyProtectors(encryptableVolume, out returnValue);
                Util.ThrowIfNotNull(ex);
                ex = BitlockerUtil.Encrypt(encryptableVolume, false, out returnValue);
                Util.ThrowIfNotNull(ex);
                BitlockerUtil.BitlockerConversionState bitlockerConversionState = BitlockerUtil.GetBitlockerConversionState(encryptableVolume, out returnValue, out ex);
                Util.ThrowIfNotNull(ex);
                if (bitlockerConversionState != BitlockerUtil.BitlockerConversionState.EncryptionInProgress)
                {
                    throw new Win7EmptyVolumeNotEncryptingAfterStartingEncryptionException(deviceID, bitlockerConversionState.ToString());
                }
            });

            returnValueEncrypt = returnValue;
            return(Util.ReturnWMIErrorExceptionOnExceptionOrError(returnValueEncrypt, "ValidateAndEncryptEmptyWin7Volume", ex));
        }
Example #12
0
        public static bool IsEncryptionPausedDueToBadBlocks(string deviceId, out Exception ex, out string mountPoint, out string eventXML)
        {
            mountPoint = null;
            eventXML   = null;
            ManagementObject encryptableVolume = BitlockerUtil.GetEncryptableVolume(deviceId, out ex);

            if (encryptableVolume == null)
            {
                return(false);
            }
            bool flag = BitlockerUtil.IsVolumeEncryptionPaused(encryptableVolume, out ex);

            if (!flag)
            {
                return(flag);
            }
            return(BitlockerUtil.DoesVolumeHaveBadBlocks(deviceId, out mountPoint, out ex, out eventXML));
        }
Example #13
0
        public static bool IsVolumeEmpty(string deviceID, out Exception ex)
        {
            bool             isEmpty     = false;
            ManagementObject win32Volume = BitlockerUtil.GetWin32Volume(deviceID, out ex);

            if (win32Volume != null)
            {
                win32Volume.GetPropertyValue("Name").ToString();
                ex = Util.HandleExceptions(delegate
                {
                    long num = Convert.ToInt64(win32Volume.GetPropertyValue("Capacity").ToString()) - Convert.ToInt64(win32Volume.GetPropertyValue("FreeSpace").ToString());
                    if (num <= 524288000L)
                    {
                        isEmpty = true;
                    }
                });
            }
            return(isEmpty);
        }
Example #14
0
        public static Exception IsVolumeEncryptedOrEncrypting(string deviceId, out bool isVolumeEncrypting, out bool isVolumeEncrypted)
        {
            isVolumeEncrypting = false;
            isVolumeEncrypted  = false;
            Exception ex  = null;
            Exception ex2 = null;
            Exception ex3 = null;

            if (!BitlockerUtil.IsSystemVolume(deviceId, out ex) && !BitlockerUtil.IsBootVolume(deviceId, out ex2))
            {
                if (ex != null)
                {
                    return(ex);
                }
                if (ex2 != null)
                {
                    return(ex2);
                }
                ManagementObject encryptableVolume = BitlockerUtil.GetEncryptableVolume(deviceId, out ex3);
                if (encryptableVolume == null)
                {
                    return(ex3);
                }
                int num;
                BitlockerUtil.BitlockerConversionState bitlockerConversionState = BitlockerUtil.GetBitlockerConversionState(encryptableVolume, out num, out ex3);
                if (ex3 != null)
                {
                    return(ex3);
                }
                if (bitlockerConversionState != BitlockerUtil.BitlockerConversionState.FullyDecrypted && bitlockerConversionState != BitlockerUtil.BitlockerConversionState.FullyEncrypted && bitlockerConversionState != BitlockerUtil.BitlockerConversionState.EncryptionPaused && bitlockerConversionState != BitlockerUtil.BitlockerConversionState.Unknown)
                {
                    isVolumeEncrypting = true;
                }
                if (bitlockerConversionState == BitlockerUtil.BitlockerConversionState.FullyEncrypted)
                {
                    isVolumeEncrypted = true;
                }
                ExAssert.RetailAssert(!isVolumeEncrypting || !isVolumeEncrypted, DiskManagementStrings.VolumeCannotBeBothEncryptingAndEncrypted(deviceId));
            }
            return(ex3);
        }
Example #15
0
        public static bool IsFilePathOnLockedVolume(string filePath, out Exception ex)
        {
            ex = null;
            List <string> lockedVolumes = BitlockerLockUtil.GetLockedVolumes(out ex);

            if (ex != null)
            {
                ex = new LockedVolumesFindException(ex.Message, ex);
                return(false);
            }
            if (lockedVolumes == null || lockedVolumes.Count == 0)
            {
                return(false);
            }
            Dictionary <string, string> mountPointVolumeIDMappings = BitlockerUtil.GetMountPointVolumeIDMappings(out ex);

            if (mountPointVolumeIDMappings == null)
            {
                ex = new MountPointsFindException(ex.Message, ex);
                return(false);
            }
            bool flag = false;

            foreach (string text in mountPointVolumeIDMappings.Keys)
            {
                if (filePath.StartsWith(text))
                {
                    flag = true;
                    if (lockedVolumes.Contains(mountPointVolumeIDMappings[text]))
                    {
                        return(true);
                    }
                }
            }
            if (!flag)
            {
                ex = new InvalidFilePathException(filePath);
            }
            return(false);
        }
Example #16
0
        public static bool IsVolumeFullyEncrypted(ManagementObject encryptableVolume, out Exception ex)
        {
            int num;

            return(BitlockerUtil.GetBitlockerConversionState(encryptableVolume, out num, out ex) == BitlockerUtil.BitlockerConversionState.FullyEncrypted);
        }
Example #17
0
        public static bool IsSystemVolume(string deviceID, out Exception ex)
        {
            string systemVolumeDeviceID = BitlockerUtil.GetSystemVolumeDeviceID(out ex);

            return(systemVolumeDeviceID != null && systemVolumeDeviceID.Equals(deviceID));
        }