Annotation of truecrypt/common/bootencryption.h, revision 1.1.1.11

1.1       root        1: /*
1.1.1.10  root        2:  Copyright (c) 2008-2010 TrueCrypt Developers Association. All rights reserved.
1.1       root        3: 
1.1.1.10  root        4:  Governed by the TrueCrypt License 3.0 the full text of which is contained in
1.1.1.9   root        5:  the file License.txt included in TrueCrypt binary and source code distribution
                      6:  packages.
1.1       root        7: */
                      8: 
1.1.1.5   root        9: #ifndef TC_HEADER_Common_BootEncryption
                     10: #define TC_HEADER_Common_BootEncryption
1.1       root       11: 
                     12: #include "Tcdefs.h"
                     13: #include "Dlgcode.h"
1.1.1.5   root       14: #include "Exception.h"
1.1       root       15: #include "Platform/PlatformBase.h"
1.1.1.4   root       16: #include "Volumes.h"
1.1       root       17: 
                     18: using namespace std;
                     19: 
                     20: namespace TrueCrypt
                     21: {
                     22:        class File
                     23:        {
                     24:        public:
                     25:                File () : FileOpen (false) { }
                     26:                File (string path, bool readOnly = false, bool create = false);
                     27:                ~File () { Close(); }
                     28: 
                     29:                void Close ();
                     30:                DWORD Read (byte *buffer, DWORD size);
                     31:                void Write (byte *buffer, DWORD size);
                     32:                void SeekAt (int64 position);
                     33: 
                     34:        protected:
                     35:                bool Elevated;
                     36:                bool FileOpen;
                     37:                uint64 FilePointerPosition;
                     38:                HANDLE Handle;
                     39:                bool IsDevice;
                     40:                string Path;
                     41:        };
                     42: 
                     43: 
                     44:        class Device : public File
                     45:        {
                     46:        public:
                     47:                Device (string path, bool readOnly = false);
                     48:        };
                     49: 
                     50: 
                     51:        class Buffer
                     52:        {
                     53:        public:
                     54:                Buffer (size_t size) : DataSize (size)
                     55:                {
                     56:                        DataPtr = new byte[size];
                     57:                        if (!DataPtr)
                     58:                                throw bad_alloc();
                     59:                }
                     60: 
1.1.1.10  root       61:                ~Buffer () { delete[] DataPtr; }
1.1       root       62:                byte *Ptr () const { return DataPtr; }
                     63:                size_t Size () const { return DataSize; }
                     64: 
                     65:        protected:
                     66:                byte *DataPtr;
                     67:                size_t DataSize;
                     68:        };
                     69: 
                     70: 
                     71:        struct Partition
                     72:        {
                     73:                string DevicePath;
                     74:                PARTITION_INFORMATION Info;
                     75:                string MountPoint;
1.1.1.8   root       76:                size_t Number;
1.1       root       77:                BOOL IsGPT;
1.1.1.6   root       78:                wstring VolumeNameId;
1.1       root       79:        };
                     80: 
                     81:        typedef list <Partition> PartitionList;
                     82: 
1.1.1.2   root       83: #pragma pack (push)
                     84: #pragma pack(1)
                     85: 
                     86:        struct PartitionEntryMBR
                     87:        {
                     88:                byte BootIndicator;
                     89: 
                     90:                byte StartHead;
                     91:                byte StartCylSector;
                     92:                byte StartCylinder;
                     93: 
                     94:                byte Type;
                     95: 
                     96:                byte EndHead;
                     97:                byte EndSector;
                     98:                byte EndCylinder;
                     99: 
                    100:                uint32 StartLBA;
                    101:                uint32 SectorCountLBA;
                    102:        };
                    103: 
                    104:        struct MBR
                    105:        {
                    106:                byte Code[446];
                    107:                PartitionEntryMBR Partitions[4];
                    108:                uint16 Signature;
                    109:        };
                    110: 
                    111: #pragma pack (pop)
1.1       root      112: 
                    113:        struct SystemDriveConfiguration
                    114:        {
1.1.1.4   root      115:                string DeviceKernelPath;
1.1       root      116:                string DevicePath;
                    117:                int DriveNumber;
                    118:                Partition DrivePartition;
1.1.1.8   root      119:                bool ExtraBootPartitionPresent;
1.1       root      120:                int64 InitialUnallocatedSpace;
                    121:                PartitionList Partitions;
                    122:                Partition SystemPartition;
                    123:                int64 TotalUnallocatedSpace;
                    124:                bool SystemLoaderPresent;
                    125:        };
                    126: 
                    127:        class BootEncryption
                    128:        {
                    129:        public:
1.1.1.5   root      130:                BootEncryption (HWND parent);
1.1       root      131:                ~BootEncryption ();
                    132: 
1.1.1.10  root      133:                enum FilterType
                    134:                {
                    135:                        DriveFilter,
                    136:                        VolumeFilter,
                    137:                        DumpFilter
                    138:                };
                    139: 
1.1.1.5   root      140:                void AbortDecoyOSWipe ();
1.1       root      141:                void AbortSetup ();
                    142:                void AbortSetupWait ();
                    143:                void CallDriver (DWORD ioctl, void *input = nullptr, DWORD inputSize = 0, void *output = nullptr, DWORD outputSize = 0);
                    144:                int ChangePassword (Password *oldPassword, Password *newPassword, int pkcs5);
1.1.1.5   root      145:                void CheckDecoyOSWipeResult ();
1.1       root      146:                void CheckEncryptionSetupResult ();
                    147:                void CheckRequirements ();
1.1.1.4   root      148:                void CheckRequirementsHiddenOS ();
1.1.1.8   root      149:                void CopyFileAdmin (const string &sourceFile, const string &destinationFile);
1.1       root      150:                void CreateRescueIsoImage (bool initialSetup, const string &isoImagePath);
1.1.1.11! root      151:                void Deinstall (bool displayWaitDialog = false);
1.1.1.8   root      152:                void DeleteFileAdmin (const string &file);
1.1.1.5   root      153:                DecoySystemWipeStatus GetDecoyOSWipeStatus ();
1.1       root      154:                DWORD GetDriverServiceStartType ();
1.1.1.4   root      155:                unsigned int GetHiddenOSCreationPhase ();
1.1       root      156:                uint16 GetInstalledBootLoaderVersion ();
1.1.1.4   root      157:                Partition GetPartitionForHiddenOS ();
1.1.1.3   root      158:                bool IsBootLoaderOnDrive (char *devicePath);
1.1       root      159:                BootEncryptionStatus GetStatus ();
1.1.1.5   root      160:                string GetTempPath ();
1.1       root      161:                void GetVolumeProperties (VOLUME_PROPERTIES_STRUCT *properties);
                    162:                SystemDriveConfiguration GetSystemDriveConfiguration ();
1.1.1.5   root      163:                void Install (bool hiddenSystem);
                    164:                void InstallBootLoader (bool preserveUserConfig = false, bool hiddenOSCreation = false);
1.1.1.4   root      165:                void InvalidateCachedSysDriveProperties ();
1.1.1.10  root      166:                bool IsCDDrivePresent ();
1.1.1.4   root      167:                bool IsHiddenSystemRunning ();
1.1.1.5   root      168:                bool IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly);
                    169:                void PrepareHiddenOSCreation (int ea, int mode, int pkcs5);
1.1       root      170:                void PrepareInstallation (bool systemPartitionOnly, Password &password, int ea, int mode, int pkcs5, const string &rescueIsoImagePath);
                    171:                void ProbeRealSystemDriveSize ();
1.1.1.6   root      172:                void ReadBootSectorConfig (byte *config, size_t bufLength, byte *userConfig = nullptr, string *customUserMessage = nullptr, uint16 *bootLoaderVersion = nullptr);
1.1.1.8   root      173:                uint32 ReadDriverConfigurationFlags ();
1.1.1.5   root      174:                void RegisterBootDriver (bool hiddenSystem);
1.1.1.10  root      175:                void RegisterFilterDriver (bool registerDriver, FilterType filterType);
1.1.1.8   root      176:                void RegisterSystemFavoritesService (BOOL registerService);
1.1.1.4   root      177:                void RenameDeprecatedSystemLoaderBackup ();
1.1       root      178:                bool RestartComputer (void);
1.1.1.5   root      179:                void InitialSecurityChecksForHiddenOS ();
1.1.1.6   root      180:                void RestrictPagingFilesToSystemPartition ();
1.1.1.8   root      181:                void SetDriverConfigurationFlag (uint32 flag, bool state);
1.1       root      182:                void SetDriverServiceStartType (DWORD startType);
1.1.1.4   root      183:                void SetHiddenOSCreationPhase (unsigned int newPhase);
1.1.1.6   root      184:                void StartDecryption (BOOL discardUnreadableEncryptedSectors);
1.1.1.5   root      185:                void StartDecoyOSWipe (WipeAlgorithmId wipeAlgorithm);
                    186:                void StartEncryption (WipeAlgorithmId wipeAlgorithm, bool zeroUnreadableSectors);
1.1.1.2   root      187:                bool SystemDriveContainsPartitionType (byte type);
                    188:                bool SystemDriveContainsExtendedPartition ();
1.1       root      189:                bool SystemPartitionCoversWholeDrive ();
1.1.1.2   root      190:                bool SystemDriveIsDynamic ();
1.1       root      191:                bool VerifyRescueDisk ();
1.1.1.5   root      192:                void WipeHiddenOSCreationConfig ();
                    193:                void WriteBootDriveSector (uint64 offset, byte *data);
1.1.1.4   root      194:                void WriteBootSectorConfig (const byte newConfig[]);
1.1.1.5   root      195:                void WriteBootSectorUserConfig (byte userConfig, const string &customUserMessage);
1.1.1.4   root      196:                void WriteLocalMachineRegistryDwordValue (char *keyPath, char *valueName, DWORD value);
1.1       root      197: 
                    198:        protected:
                    199:                static const uint32 RescueIsoImageSize = 1835008; // Size of ISO9660 image with bootable emulated 1.44MB floppy disk image
                    200: 
                    201:                void BackupSystemLoader ();
1.1.1.5   root      202:                void CreateBootLoaderInMemory (byte *buffer, size_t bufferSize, bool rescueDisk, bool hiddenOSCreation = false);
1.1       root      203:                void CreateVolumeHeader (uint64 volumeSize, uint64 encryptedAreaStart, Password *password, int ea, int mode, int pkcs5);
                    204:                string GetSystemLoaderBackupPath ();
1.1.1.3   root      205:                uint32 GetChecksum (byte *data, size_t size);
1.1       root      206:                DISK_GEOMETRY GetDriveGeometry (int driveNumber);
                    207:                PartitionList GetDrivePartitions (int driveNumber);
1.1.1.4   root      208:                wstring GetRemarksOnHiddenOS ();
1.1       root      209:                string GetWindowsDirectory ();
1.1.1.10  root      210:                void RegisterFilter (bool registerFilter, FilterType filterType, const GUID *deviceClassGuid = nullptr);
1.1       root      211:                void RestoreSystemLoader ();
                    212:                void InstallVolumeHeader ();
                    213: 
                    214:                HWND ParentWindow;
                    215:                SystemDriveConfiguration DriveConfig;
1.1.1.3   root      216:                int SelectedEncryptionAlgorithmId;
1.1.1.5   root      217:                Partition HiddenOSCandidatePartition;
1.1       root      218:                byte *RescueIsoImage;
1.1.1.4   root      219:                byte RescueVolumeHeader[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
                    220:                byte VolumeHeader[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
1.1       root      221:                bool DriveConfigValid;
                    222:                bool RealSystemDriveSizeValid;
                    223:                bool RescueVolumeHeaderValid;
                    224:                bool VolumeHeaderValid;
                    225:        };
                    226: }
                    227: 
                    228: #define TC_ABORT_TRANSFORM_WAIT_INTERVAL       10
                    229: 
1.1.1.4   root      230: #define MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_NTFS   2.1
                    231: #define MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_FAT            1.05
                    232: 
                    233: #define TC_SYS_BOOT_LOADER_BACKUP_NAME                 "Original System Loader"
                    234: #define TC_SYS_BOOT_LOADER_BACKUP_NAME_LEGACY  "Original System Loader.bak"    // Deprecated to prevent removal by some "cleaners"
1.1       root      235: 
1.1.1.8   root      236: #define TC_SYSTEM_FAVORITES_SERVICE_NAME                               TC_APP_NAME "SystemFavorites"
                    237: #define        TC_SYSTEM_FAVORITES_SERVICE_LOAD_ORDER_GROUP    "Event Log"
                    238: #define TC_SYSTEM_FAVORITES_SERVICE_CMDLINE_OPTION             "/systemFavoritesService"
                    239: 
1.1.1.5   root      240: #endif // TC_HEADER_Common_BootEncryption

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.