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

1.1       root        1: /*
1.1.1.9 ! root        2:  Copyright (c) 2008-2009 TrueCrypt Developers Association. All rights reserved.
1.1       root        3: 
1.1.1.9 ! root        4:  Governed by the TrueCrypt License 2.8 the full text of which is contained in
        !             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: 
                     61:                ~Buffer () { delete DataPtr; }
                     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.5   root      133:                void AbortDecoyOSWipe ();
1.1       root      134:                void AbortSetup ();
                    135:                void AbortSetupWait ();
                    136:                void CallDriver (DWORD ioctl, void *input = nullptr, DWORD inputSize = 0, void *output = nullptr, DWORD outputSize = 0);
                    137:                int ChangePassword (Password *oldPassword, Password *newPassword, int pkcs5);
1.1.1.5   root      138:                void CheckDecoyOSWipeResult ();
1.1       root      139:                void CheckEncryptionSetupResult ();
                    140:                void CheckRequirements ();
1.1.1.4   root      141:                void CheckRequirementsHiddenOS ();
1.1.1.8   root      142:                void CopyFileAdmin (const string &sourceFile, const string &destinationFile);
1.1       root      143:                void CreateRescueIsoImage (bool initialSetup, const string &isoImagePath);
                    144:                void Deinstall ();
1.1.1.8   root      145:                void DeleteFileAdmin (const string &file);
1.1.1.5   root      146:                DecoySystemWipeStatus GetDecoyOSWipeStatus ();
1.1       root      147:                DWORD GetDriverServiceStartType ();
1.1.1.4   root      148:                unsigned int GetHiddenOSCreationPhase ();
1.1       root      149:                uint16 GetInstalledBootLoaderVersion ();
1.1.1.4   root      150:                Partition GetPartitionForHiddenOS ();
1.1.1.3   root      151:                bool IsBootLoaderOnDrive (char *devicePath);
1.1       root      152:                BootEncryptionStatus GetStatus ();
1.1.1.5   root      153:                string GetTempPath ();
1.1       root      154:                void GetVolumeProperties (VOLUME_PROPERTIES_STRUCT *properties);
                    155:                SystemDriveConfiguration GetSystemDriveConfiguration ();
1.1.1.5   root      156:                void Install (bool hiddenSystem);
                    157:                void InstallBootLoader (bool preserveUserConfig = false, bool hiddenOSCreation = false);
1.1.1.4   root      158:                void InvalidateCachedSysDriveProperties ();
                    159:                bool IsHiddenSystemRunning ();
1.1.1.5   root      160:                bool IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly);
                    161:                void PrepareHiddenOSCreation (int ea, int mode, int pkcs5);
1.1       root      162:                void PrepareInstallation (bool systemPartitionOnly, Password &password, int ea, int mode, int pkcs5, const string &rescueIsoImagePath);
                    163:                void ProbeRealSystemDriveSize ();
1.1.1.6   root      164:                void ReadBootSectorConfig (byte *config, size_t bufLength, byte *userConfig = nullptr, string *customUserMessage = nullptr, uint16 *bootLoaderVersion = nullptr);
1.1.1.8   root      165:                uint32 ReadDriverConfigurationFlags ();
1.1.1.5   root      166:                void RegisterBootDriver (bool hiddenSystem);
1.1.1.4   root      167:                void RegisterFilterDriver (bool registerDriver, bool volumeClass);
1.1.1.8   root      168:                void RegisterSystemFavoritesService (BOOL registerService);
1.1.1.4   root      169:                void RenameDeprecatedSystemLoaderBackup ();
1.1       root      170:                bool RestartComputer (void);
1.1.1.5   root      171:                void InitialSecurityChecksForHiddenOS ();
1.1.1.6   root      172:                void RestrictPagingFilesToSystemPartition ();
1.1.1.8   root      173:                void SetDriverConfigurationFlag (uint32 flag, bool state);
1.1       root      174:                void SetDriverServiceStartType (DWORD startType);
1.1.1.4   root      175:                void SetHiddenOSCreationPhase (unsigned int newPhase);
1.1.1.6   root      176:                void StartDecryption (BOOL discardUnreadableEncryptedSectors);
1.1.1.5   root      177:                void StartDecoyOSWipe (WipeAlgorithmId wipeAlgorithm);
                    178:                void StartEncryption (WipeAlgorithmId wipeAlgorithm, bool zeroUnreadableSectors);
1.1.1.2   root      179:                bool SystemDriveContainsPartitionType (byte type);
                    180:                bool SystemDriveContainsExtendedPartition ();
1.1       root      181:                bool SystemPartitionCoversWholeDrive ();
1.1.1.2   root      182:                bool SystemDriveIsDynamic ();
1.1       root      183:                bool VerifyRescueDisk ();
1.1.1.5   root      184:                void WipeHiddenOSCreationConfig ();
                    185:                void WriteBootDriveSector (uint64 offset, byte *data);
1.1.1.4   root      186:                void WriteBootSectorConfig (const byte newConfig[]);
1.1.1.5   root      187:                void WriteBootSectorUserConfig (byte userConfig, const string &customUserMessage);
1.1.1.4   root      188:                void WriteLocalMachineRegistryDwordValue (char *keyPath, char *valueName, DWORD value);
1.1       root      189: 
                    190:        protected:
                    191:                static const uint32 RescueIsoImageSize = 1835008; // Size of ISO9660 image with bootable emulated 1.44MB floppy disk image
                    192: 
                    193:                void BackupSystemLoader ();
1.1.1.5   root      194:                void CreateBootLoaderInMemory (byte *buffer, size_t bufferSize, bool rescueDisk, bool hiddenOSCreation = false);
1.1       root      195:                void CreateVolumeHeader (uint64 volumeSize, uint64 encryptedAreaStart, Password *password, int ea, int mode, int pkcs5);
                    196:                string GetSystemLoaderBackupPath ();
1.1.1.3   root      197:                uint32 GetChecksum (byte *data, size_t size);
1.1       root      198:                DISK_GEOMETRY GetDriveGeometry (int driveNumber);
                    199:                PartitionList GetDrivePartitions (int driveNumber);
1.1.1.4   root      200:                wstring GetRemarksOnHiddenOS ();
1.1       root      201:                string GetWindowsDirectory ();
1.1.1.4   root      202:                void RegisterDeviceClassFilter (bool registerFilter, const GUID *deviceClassGuid);
1.1       root      203:                void RestoreSystemLoader ();
                    204:                void InstallVolumeHeader ();
                    205: 
                    206:                HWND ParentWindow;
                    207:                SystemDriveConfiguration DriveConfig;
1.1.1.3   root      208:                int SelectedEncryptionAlgorithmId;
1.1.1.5   root      209:                Partition HiddenOSCandidatePartition;
1.1       root      210:                byte *RescueIsoImage;
1.1.1.4   root      211:                byte RescueVolumeHeader[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
                    212:                byte VolumeHeader[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
1.1       root      213:                bool DriveConfigValid;
                    214:                bool RealSystemDriveSizeValid;
                    215:                bool RescueVolumeHeaderValid;
                    216:                bool VolumeHeaderValid;
                    217:        };
                    218: }
                    219: 
                    220: #define TC_ABORT_TRANSFORM_WAIT_INTERVAL       10
                    221: 
1.1.1.4   root      222: #define MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_NTFS   2.1
                    223: #define MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_FAT            1.05
                    224: 
                    225: #define TC_SYS_BOOT_LOADER_BACKUP_NAME                 "Original System Loader"
                    226: #define TC_SYS_BOOT_LOADER_BACKUP_NAME_LEGACY  "Original System Loader.bak"    // Deprecated to prevent removal by some "cleaners"
1.1       root      227: 
1.1.1.8   root      228: #define TC_SYSTEM_FAVORITES_SERVICE_NAME                               TC_APP_NAME "SystemFavorites"
                    229: #define        TC_SYSTEM_FAVORITES_SERVICE_LOAD_ORDER_GROUP    "Event Log"
                    230: #define TC_SYSTEM_FAVORITES_SERVICE_CMDLINE_OPTION             "/systemFavoritesService"
                    231: 
1.1.1.5   root      232: #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.