Пример #1
0
        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));
        }
Пример #2
0
        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));
        }
Пример #3
0
        public static Exception Resume(ManagementObject encryptableVolume, out int returnValueResume)
        {
            Exception ex          = null;
            int       returnValue = -1;

            returnValueResume = -1;
            if (encryptableVolume == null)
            {
                return(new EncryptableVolumeArgNullException("Resume"));
            }
            string volume = encryptableVolume.GetPropertyValue("DeviceId").ToString();

            if (BitlockerLockUtil.IsVolumeLocked(encryptableVolume, out ex))
            {
                ex = new VolumeLockedException(volume);
                return(ex);
            }
            ex = Util.HandleExceptions(delegate
            {
                ManagementBaseObject managementBaseObject = null;
                returnValue = WMIUtil.CallWMIMethod(encryptableVolume, "ResumeConversion", null, null, out managementBaseObject);
            });
            returnValueResume = returnValue;
            Util.AssertReturnValueExceptionInconsistency(returnValueResume, "Resume", ex);
            return(Util.ReturnWMIErrorExceptionOnExceptionOrError(returnValueResume, "Resume", ex));
        }
Пример #4
0
        public static Exception AddNumericalPassword(ManagementObject encryptableVolume, string numericalPassword, out int returnValueNumericalPassword)
        {
            Exception ex = null;

            if (BitlockerLockUtil.IsVolumeLocked(encryptableVolume, out ex))
            {
                returnValueNumericalPassword = 0;
                return(ex);
            }
            int returnValue = -1;
            ManagementBaseObject outParams = null;

            ex = Util.HandleExceptions(delegate
            {
                returnValue = WMIUtil.CallWMIMethod(encryptableVolume, "ProtectKeyWithNumericalPassword", new string[]
                {
                    "FriendlyName",
                    "NumericalPassword"
                }, new object[]
                {
                    "FriendlyName",
                    numericalPassword
                }, out outParams);
            });
            returnValueNumericalPassword = returnValue;
            Util.AssertReturnValueExceptionInconsistency(returnValueNumericalPassword, "AddNumericalPassword", ex);
            return(Util.ReturnWMIErrorExceptionOnExceptionOrError(returnValueNumericalPassword, "AddNumericalPassword", ex));
        }
Пример #5
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);
        }
Пример #6
0
        public static Exception Decrypt(ManagementObject encryptableVolume, out int returnValueDecrypt)
        {
            ManagementBaseObject outParams = null;
            int       returnValue          = -1;
            Exception ex = Util.HandleExceptions(delegate
            {
                returnValue = WMIUtil.CallWMIMethod(encryptableVolume, "Decrypt", null, null, out outParams);
            });

            returnValueDecrypt = returnValue;
            Util.AssertReturnValueExceptionInconsistency(returnValueDecrypt, "Decrypt", ex);
            return(Util.ReturnWMIErrorExceptionOnExceptionOrError(returnValueDecrypt, "Decrypt", ex));
        }
Пример #7
0
        public static int GetBitlockerEncryptionPercentage(ManagementObject encryptableVolume, out int returnValueEncryptionPercentage, out Exception ex)
        {
            ManagementBaseObject outParams         = null;
            int encryptionPercentageWMIReturnValue = -1;
            int returnValue = -1;

            ex = null;
            ex = Util.HandleExceptions(delegate
            {
                returnValue = WMIUtil.CallWMIMethod(encryptableVolume, "GetConversionStatus", null, null, out outParams);
                if (returnValue == 0)
                {
                    int.TryParse(outParams["EncryptionPercentage"].ToString(), out encryptionPercentageWMIReturnValue);
                }
            });
            returnValueEncryptionPercentage = returnValue;
            return(encryptionPercentageWMIReturnValue);
        }
Пример #8
0
        public static bool IsVolumeLocked(ManagementObject encryptableVolume, out Exception ex)
        {
            ManagementBaseObject outParams = null;
            bool success = false;

            ex = Util.HandleExceptions(delegate
            {
                if (WMIUtil.CallWMIMethod(encryptableVolume, "GetLockStatus", null, null, out outParams) == 0)
                {
                    int num = Convert.ToInt32(outParams["LockStatus"]);
                    if (Enum.IsDefined(typeof(BitlockerLockUtil.LockStatus), num))
                    {
                        BitlockerLockUtil.LockStatus lockStatus = (BitlockerLockUtil.LockStatus)num;
                        success = (lockStatus == BitlockerLockUtil.LockStatus.Locked);
                    }
                }
            });
            Util.ThrowIfNotNull(ex);
            return(success);
        }
Пример #9
0
        public static Exception Encrypt(ManagementObject encryptableVolume, bool usedOnly, out int returnValueEncrypt)
        {
            Exception ex          = null;
            int       returnValue = -1;

            if (BitlockerLockUtil.IsVolumeLocked(encryptableVolume, out ex))
            {
                returnValueEncrypt = 0;
                return(ex);
            }
            ex = Util.HandleExceptions(delegate
            {
                ManagementBaseObject managementBaseObject = null;
                if (Util.IsOperatingSystemWin8OrHigher() && usedOnly)
                {
                    returnValue = WMIUtil.CallWMIMethod(encryptableVolume, "Encrypt", new string[]
                    {
                        "EncryptionMethod",
                        "EncryptionFlags"
                    }, new object[]
                    {
                        4,
                        1
                    }, out managementBaseObject);
                    return;
                }
                returnValue = WMIUtil.CallWMIMethod(encryptableVolume, "Encrypt", new string[]
                {
                    "EncryptionMethod"
                }, new object[]
                {
                    4
                }, out managementBaseObject);
            });
            returnValueEncrypt = returnValue;
            Util.AssertReturnValueExceptionInconsistency(returnValueEncrypt, "Encrypt", ex);
            return(Util.ReturnWMIErrorExceptionOnExceptionOrError(returnValueEncrypt, "Encrypt", ex));
        }
Пример #10
0
        public static BitlockerUtil.BitlockerConversionState GetBitlockerConversionState(ManagementObject encryptableVolume, out int returnValueConversionState, out Exception ex)
        {
            BitlockerUtil.BitlockerConversionState bitlockerConversionState = BitlockerUtil.BitlockerConversionState.Unknown;
            ManagementBaseObject outParams = null;

            ex = null;
            int returnValue = -1;

            ex = Util.HandleExceptions(delegate
            {
                returnValue = WMIUtil.CallWMIMethod(encryptableVolume, "GetConversionStatus", null, null, out outParams);
                if (returnValue == 0)
                {
                    int num = Convert.ToInt32(outParams["ConversionStatus"]);
                    if (Enum.IsDefined(typeof(BitlockerUtil.BitlockerConversionState), num))
                    {
                        bitlockerConversionState = (BitlockerUtil.BitlockerConversionState)num;
                    }
                }
            });
            returnValueConversionState = returnValue;
            return(bitlockerConversionState);
        }