|
|
1.1 root 1: /*
2: Copyright (c) 2008 TrueCrypt Foundation. All rights reserved.
3:
1.1.1.5 ! root 4: Governed by the TrueCrypt License 2.6 the full text of which is contained
1.1 root 5: in the file License.txt included in TrueCrypt binary and source code
6: distribution packages.
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;
76: int Number;
77: BOOL IsGPT;
78: };
79:
80: typedef list <Partition> PartitionList;
81:
1.1.1.2 root 82: #pragma pack (push)
83: #pragma pack(1)
84:
85: struct PartitionEntryMBR
86: {
87: byte BootIndicator;
88:
89: byte StartHead;
90: byte StartCylSector;
91: byte StartCylinder;
92:
93: byte Type;
94:
95: byte EndHead;
96: byte EndSector;
97: byte EndCylinder;
98:
99: uint32 StartLBA;
100: uint32 SectorCountLBA;
101: };
102:
103: struct MBR
104: {
105: byte Code[446];
106: PartitionEntryMBR Partitions[4];
107: uint16 Signature;
108: };
109:
110: #pragma pack (pop)
1.1 root 111:
112: struct SystemDriveConfiguration
113: {
1.1.1.4 root 114: string DeviceKernelPath;
1.1 root 115: string DevicePath;
116: int DriveNumber;
117: Partition DrivePartition;
118: int64 InitialUnallocatedSpace;
119: PartitionList Partitions;
120: Partition SystemPartition;
121: int64 TotalUnallocatedSpace;
122: bool SystemLoaderPresent;
123: };
124:
125: class BootEncryption
126: {
127: public:
1.1.1.5 ! root 128: BootEncryption (HWND parent);
1.1 root 129: ~BootEncryption ();
130:
1.1.1.5 ! root 131: void AbortDecoyOSWipe ();
1.1 root 132: void AbortSetup ();
133: void AbortSetupWait ();
134: void CallDriver (DWORD ioctl, void *input = nullptr, DWORD inputSize = 0, void *output = nullptr, DWORD outputSize = 0);
135: int ChangePassword (Password *oldPassword, Password *newPassword, int pkcs5);
1.1.1.5 ! root 136: void CheckDecoyOSWipeResult ();
1.1 root 137: void CheckEncryptionSetupResult ();
138: void CheckRequirements ();
1.1.1.4 root 139: void CheckRequirementsHiddenOS ();
1.1 root 140: void CreateRescueIsoImage (bool initialSetup, const string &isoImagePath);
141: void Deinstall ();
1.1.1.5 ! root 142: DecoySystemWipeStatus GetDecoyOSWipeStatus ();
1.1 root 143: DWORD GetDriverServiceStartType ();
1.1.1.4 root 144: unsigned int GetHiddenOSCreationPhase ();
1.1 root 145: uint16 GetInstalledBootLoaderVersion ();
1.1.1.4 root 146: Partition GetPartitionForHiddenOS ();
1.1.1.3 root 147: bool IsBootLoaderOnDrive (char *devicePath);
1.1 root 148: BootEncryptionStatus GetStatus ();
1.1.1.5 ! root 149: string GetTempPath ();
1.1 root 150: void GetVolumeProperties (VOLUME_PROPERTIES_STRUCT *properties);
151: SystemDriveConfiguration GetSystemDriveConfiguration ();
1.1.1.5 ! root 152: void Install (bool hiddenSystem);
! 153: void InstallBootLoader (bool preserveUserConfig = false, bool hiddenOSCreation = false);
1.1.1.4 root 154: void InvalidateCachedSysDriveProperties ();
155: bool IsHiddenSystemRunning ();
1.1.1.5 ! root 156: bool IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly);
! 157: void PrepareHiddenOSCreation (int ea, int mode, int pkcs5);
1.1 root 158: void PrepareInstallation (bool systemPartitionOnly, Password &password, int ea, int mode, int pkcs5, const string &rescueIsoImagePath);
159: void ProbeRealSystemDriveSize ();
1.1.1.5 ! root 160: void ReadBootSectorConfig (byte *config, size_t bufLength, byte *userConfig = nullptr, string *customUserMessage = nullptr);
! 161: void RegisterBootDriver (bool hiddenSystem);
1.1.1.4 root 162: void RegisterFilterDriver (bool registerDriver, bool volumeClass);
163: void RenameDeprecatedSystemLoaderBackup ();
1.1 root 164: bool RestartComputer (void);
1.1.1.5 ! root 165: void InitialSecurityChecksForHiddenOS ();
1.1 root 166: void SetDriverServiceStartType (DWORD startType);
1.1.1.4 root 167: void SetHiddenOSCreationPhase (unsigned int newPhase);
1.1 root 168: void StartDecryption ();
1.1.1.5 ! root 169: void StartDecoyOSWipe (WipeAlgorithmId wipeAlgorithm);
! 170: void StartEncryption (WipeAlgorithmId wipeAlgorithm, bool zeroUnreadableSectors);
1.1.1.2 root 171: bool SystemDriveContainsPartitionType (byte type);
172: bool SystemDriveContainsExtendedPartition ();
1.1 root 173: bool SystemPartitionCoversWholeDrive ();
1.1.1.2 root 174: bool SystemDriveIsDynamic ();
1.1 root 175: bool VerifyRescueDisk ();
1.1.1.5 ! root 176: void WipeHiddenOSCreationConfig ();
! 177: void WriteBootDriveSector (uint64 offset, byte *data);
1.1.1.4 root 178: void WriteBootSectorConfig (const byte newConfig[]);
1.1.1.5 ! root 179: void WriteBootSectorUserConfig (byte userConfig, const string &customUserMessage);
1.1.1.4 root 180: void WriteLocalMachineRegistryDwordValue (char *keyPath, char *valueName, DWORD value);
1.1 root 181:
182: protected:
183: static const uint32 RescueIsoImageSize = 1835008; // Size of ISO9660 image with bootable emulated 1.44MB floppy disk image
184:
185: void BackupSystemLoader ();
1.1.1.5 ! root 186: void CreateBootLoaderInMemory (byte *buffer, size_t bufferSize, bool rescueDisk, bool hiddenOSCreation = false);
1.1 root 187: void CreateVolumeHeader (uint64 volumeSize, uint64 encryptedAreaStart, Password *password, int ea, int mode, int pkcs5);
188: string GetSystemLoaderBackupPath ();
1.1.1.3 root 189: uint32 GetChecksum (byte *data, size_t size);
1.1 root 190: DISK_GEOMETRY GetDriveGeometry (int driveNumber);
191: PartitionList GetDrivePartitions (int driveNumber);
1.1.1.4 root 192: wstring GetRemarksOnHiddenOS ();
1.1 root 193: string GetWindowsDirectory ();
1.1.1.4 root 194: void RegisterDeviceClassFilter (bool registerFilter, const GUID *deviceClassGuid);
1.1 root 195: void RestoreSystemLoader ();
196: void InstallVolumeHeader ();
197:
198: HWND ParentWindow;
199: SystemDriveConfiguration DriveConfig;
1.1.1.3 root 200: int SelectedEncryptionAlgorithmId;
1.1.1.5 ! root 201: Partition HiddenOSCandidatePartition;
1.1 root 202: byte *RescueIsoImage;
1.1.1.4 root 203: byte RescueVolumeHeader[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
204: byte VolumeHeader[TC_BOOT_ENCRYPTION_VOLUME_HEADER_SIZE];
1.1 root 205: bool DriveConfigValid;
206: bool RealSystemDriveSizeValid;
207: bool RescueVolumeHeaderValid;
208: bool VolumeHeaderValid;
209: };
210: }
211:
212: #define TC_ABORT_TRANSFORM_WAIT_INTERVAL 10
213:
1.1.1.4 root 214: #define MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_NTFS 2.1
215: #define MIN_HIDDENOS_DECOY_PARTITION_SIZE_RATIO_FAT 1.05
216:
217: #define TC_SYS_BOOT_LOADER_BACKUP_NAME "Original System Loader"
218: #define TC_SYS_BOOT_LOADER_BACKUP_NAME_LEGACY "Original System Loader.bak" // Deprecated to prevent removal by some "cleaners"
1.1 root 219:
1.1.1.5 ! root 220: #endif // TC_HEADER_Common_BootEncryption
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.