|
|
1.1 root 1: /*
2: Copyright (c) 2008 TrueCrypt Foundation. All rights reserved.
3:
4: Governed by the TrueCrypt License 2.4 the full text of which is contained
5: in the file License.txt included in TrueCrypt binary and source code
6: distribution packages.
7: */
8:
9: #ifndef TC_HEADER_Mount_BootEncryption
10: #define TC_HEADER_Mount_BootEncryption
11:
12: #include "Tcdefs.h"
13: #include "Dlgcode.h"
14: #include "Platform/PlatformBase.h"
15:
16: using namespace std;
17:
18: namespace TrueCrypt
19: {
20: struct Exception
21: {
22: virtual void Show (HWND parent) = 0;
23: };
24:
25: struct SystemException : public Exception
26: {
27: SystemException () : ErrorCode (GetLastError()) { }
28:
29: void Show (HWND parent)
30: {
31: SetLastError (ErrorCode);
32: handleWin32Error (parent);
33: }
34:
35: DWORD ErrorCode;
36: };
37:
38: struct ErrorException : public Exception
39: {
40: ErrorException (char *langId) : ErrLangId (langId) { }
41:
42: void Show (HWND parent)
43: {
44: ::Error (ErrLangId);
45: }
46:
47: char *ErrLangId;
48: };
49:
50: struct ParameterIncorrect : public Exception
51: {
52: ParameterIncorrect (const char *srcPos) : SrcPos (srcPos) { }
53:
54: void Show (HWND parent)
55: {
56: string msgBody = "Parameter incorrect.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + ")";
57: MessageBox (parent, msgBody.c_str(), "TrueCrypt", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST);
58: }
59:
60: const char *SrcPos;
61: };
62:
1.1.1.3 ! root 63: struct TimeOut : public Exception
! 64: {
! 65: TimeOut (const char *srcPos) { }
! 66: void Show (HWND parent) { MessageBox (parent, "Timeout", "TrueCrypt", MB_ICONERROR); }
! 67: };
! 68:
1.1 root 69: struct UserAbort : public Exception
70: {
71: UserAbort (const char *srcPos) { }
72: void Show (HWND parent) { }
73: };
74:
75: #define throw_sys_if(condition) do { if (condition) throw SystemException(); } while (false)
76:
77:
78: class File
79: {
80: public:
81: File () : FileOpen (false) { }
82: File (string path, bool readOnly = false, bool create = false);
83: ~File () { Close(); }
84:
85: void Close ();
86: DWORD Read (byte *buffer, DWORD size);
87: void Write (byte *buffer, DWORD size);
88: void SeekAt (int64 position);
89:
90: protected:
91: bool Elevated;
92: bool FileOpen;
93: uint64 FilePointerPosition;
94: HANDLE Handle;
95: bool IsDevice;
96: string Path;
97: };
98:
99:
100: class Device : public File
101: {
102: public:
103: Device (string path, bool readOnly = false);
104: };
105:
106:
107: class Buffer
108: {
109: public:
110: Buffer (size_t size) : DataSize (size)
111: {
112: DataPtr = new byte[size];
113: if (!DataPtr)
114: throw bad_alloc();
115: }
116:
117: ~Buffer () { delete DataPtr; }
118: byte *Ptr () const { return DataPtr; }
119: size_t Size () const { return DataSize; }
120:
121: protected:
122: byte *DataPtr;
123: size_t DataSize;
124: };
125:
126:
127: struct Partition
128: {
129: string DevicePath;
130: PARTITION_INFORMATION Info;
131: string MountPoint;
132: int Number;
133: BOOL IsGPT;
134: };
135:
136: typedef list <Partition> PartitionList;
137:
1.1.1.2 root 138: #pragma pack (push)
139: #pragma pack(1)
140:
141: struct PartitionEntryMBR
142: {
143: byte BootIndicator;
144:
145: byte StartHead;
146: byte StartCylSector;
147: byte StartCylinder;
148:
149: byte Type;
150:
151: byte EndHead;
152: byte EndSector;
153: byte EndCylinder;
154:
155: uint32 StartLBA;
156: uint32 SectorCountLBA;
157: };
158:
159: struct MBR
160: {
161: byte Code[446];
162: PartitionEntryMBR Partitions[4];
163: uint16 Signature;
164: };
165:
166: #pragma pack (pop)
1.1 root 167:
168: struct SystemDriveConfiguration
169: {
170: string DevicePath;
171: int DriveNumber;
172: Partition DrivePartition;
173: int64 InitialUnallocatedSpace;
174: PartitionList Partitions;
175: Partition SystemPartition;
176: int64 TotalUnallocatedSpace;
177: bool SystemLoaderPresent;
178: };
179:
180: class BootEncryption
181: {
182: public:
183: BootEncryption (HWND parent)
184: : DriveConfigValid (false),
185: ParentWindow (parent),
186: RealSystemDriveSizeValid (false),
187: RescueIsoImage (nullptr),
188: RescueVolumeHeaderValid (false),
1.1.1.3 ! root 189: SelectedEncryptionAlgorithmId (0),
1.1 root 190: VolumeHeaderValid (false)
191: {
192: }
193:
194: ~BootEncryption ();
195:
196: void AbortSetup ();
197: void AbortSetupWait ();
198: void CallDriver (DWORD ioctl, void *input = nullptr, DWORD inputSize = 0, void *output = nullptr, DWORD outputSize = 0);
199: int ChangePassword (Password *oldPassword, Password *newPassword, int pkcs5);
200: void CheckEncryptionSetupResult ();
201: void CheckRequirements ();
202: void CreateRescueIsoImage (bool initialSetup, const string &isoImagePath);
203: void Deinstall ();
204: DWORD GetDriverServiceStartType ();
205: uint16 GetInstalledBootLoaderVersion ();
1.1.1.3 ! root 206: bool IsBootLoaderOnDrive (char *devicePath);
1.1 root 207: BootEncryptionStatus GetStatus ();
208: void GetVolumeProperties (VOLUME_PROPERTIES_STRUCT *properties);
209: SystemDriveConfiguration GetSystemDriveConfiguration ();
210: void Install ();
1.1.1.2 root 211: void InstallBootLoader ();
1.1 root 212: void PrepareInstallation (bool systemPartitionOnly, Password &password, int ea, int mode, int pkcs5, const string &rescueIsoImagePath);
213: void ProbeRealSystemDriveSize ();
1.1.1.3 ! root 214: void RegisterBootDriver ();
1.1 root 215: void RegisterFilterDriver (bool registerDriver);
216: bool RestartComputer (void);
217: void SetDriverServiceStartType (DWORD startType);
218: void StartDecryption ();
219: void StartEncryption (WipeAlgorithmId wipeAlgorithm);
1.1.1.2 root 220: bool SystemDriveContainsPartitionType (byte type);
221: bool SystemDriveContainsExtendedPartition ();
1.1 root 222: bool SystemPartitionCoversWholeDrive ();
1.1.1.2 root 223: bool SystemDriveIsDynamic ();
1.1 root 224: bool VerifyRescueDisk ();
225:
226: protected:
227: static const uint32 RescueIsoImageSize = 1835008; // Size of ISO9660 image with bootable emulated 1.44MB floppy disk image
228:
229: void BackupSystemLoader ();
230: void CreateVolumeHeader (uint64 volumeSize, uint64 encryptedAreaStart, Password *password, int ea, int mode, int pkcs5);
231: string GetSystemLoaderBackupPath ();
1.1.1.3 ! root 232: void GetBootLoader (byte *buffer, size_t bufferSize, bool rescueDisk);
! 233: uint32 GetChecksum (byte *data, size_t size);
1.1 root 234: DISK_GEOMETRY GetDriveGeometry (int driveNumber);
235: PartitionList GetDrivePartitions (int driveNumber);
236: string GetWindowsDirectory ();
237: void RestoreSystemLoader ();
238: void InstallVolumeHeader ();
239: void UpdateSystemDriveConfiguration ();
240:
241: HWND ParentWindow;
242: SystemDriveConfiguration DriveConfig;
1.1.1.3 ! root 243: int SelectedEncryptionAlgorithmId;
1.1 root 244: byte *RescueIsoImage;
245: byte RescueVolumeHeader[HEADER_SIZE];
246: byte VolumeHeader[HEADER_SIZE];
247: bool DriveConfigValid;
248: bool RealSystemDriveSizeValid;
249: bool RescueVolumeHeaderValid;
250: bool VolumeHeaderValid;
251: };
252: }
253:
254: #define TC_ABORT_TRANSFORM_WAIT_INTERVAL 10
255:
256: #define TC_SYS_BOOT_LOADER_BACKUP_NAME "Original System Loader.bak"
257:
258: #endif // TC_HEADER_Mount_BootEncryption
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.