Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

403 lines
8.3 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Abstract:
  4. This module contains the common header information for the EFS
  5. file system filter driver.
  6. Author:
  7. Robert Gu (robertg) 29-Oct-1996
  8. Enviroment:
  9. Kernel Mode Only
  10. Revision History:
  11. --*/
  12. #ifndef EFS_H
  13. #define EFS_H
  14. #include "ntifs.h"
  15. //
  16. // BYTE is required by des.h
  17. // PBYTE is required by des3.h
  18. //
  19. typedef unsigned char BYTE;
  20. typedef unsigned long DWORD;
  21. typedef unsigned char *PBYTE;
  22. #include "fipsapi.h"
  23. //#include "des.h"
  24. //#include "tripldes.h"
  25. #include "aes.h"
  26. #include "ntfsexp.h"
  27. #include "efsstruc.h"
  28. #if DBG
  29. #define EFSTRACEALL 0x00000001
  30. #define EFSTRACELIGHT 0x00000002
  31. #define EFSTRACEMED 0x00000004
  32. #define EFSSTOPALL 0x00000010
  33. #define EFSSTOPLIGHT 0x00000020
  34. #define EFSSTOPMED 0x00000040
  35. #endif // DBG
  36. #ifndef CALG_DES
  37. //
  38. // Definition from sdk\inc\wincrypt.h
  39. // Including wincrypt.h causes too much work.
  40. //
  41. #define ALG_CLASS_DATA_ENCRYPT (3 << 13)
  42. #define ALG_TYPE_BLOCK (3 << 9)
  43. #define ALG_SID_DES 1
  44. #define ALG_SID_3DES 3
  45. #define ALG_SID_DESX 4
  46. #define ALG_SID_AES_256 16
  47. #define ALG_SID_AES 17
  48. #define CALG_DES (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_DES)
  49. #define CALG_DESX (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_DESX)
  50. #define CALG_3DES (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_3DES)
  51. #define CALG_AES_256 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES_256)
  52. #define CALG_AES (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES)
  53. #endif
  54. //
  55. // Define the device extension structure for this driver's extensions.
  56. //
  57. #define EFSFILTER_DEVICE_TYPE 0x1309
  58. #define EFS_EVENTDEPTH 3
  59. #define EFS_CONTEXTDEPTH 5
  60. #define EFS_KEYDEPTH 30
  61. #define EFS_ALGDEPTH 3
  62. //
  63. // Define the constants used in Open Cache
  64. //
  65. #define DefaultTimeExpirePeriod 5 * 10000000 // 5 seconds
  66. #define MINCACHEPERIOD 2
  67. #define MAXCACHEPERIOD 30
  68. #define EFS_CACHEDEPTH 5
  69. #define EFS_STREAM_NORMAL 0
  70. #define EFS_STREAM_TRANSITION 1
  71. #define EFS_STRNAME_LENGTH 6
  72. #define EFS_FSCTL_HEADER_LENGTH 3 * sizeof( ULONG )
  73. //
  74. // Define test MACRO
  75. //
  76. #define CheckValidKeyBlock(PContext, Msg)
  77. /*
  78. #define CheckValidKeyBlock(PContext, Msg) { \
  79. if (PContext) { \
  80. if (((PKEY_BLOB) PContext)->KeyLength != DESX_KEY_BLOB_LENGTH){ \
  81. DbgPrint(Msg); \
  82. } \
  83. ASSERT(((PKEY_BLOB) PContext)->KeyLength == DESX_KEY_BLOB_LENGTH); \
  84. } \
  85. }
  86. */
  87. #define FreeMemoryBlock(PContext) { \
  88. ExFreeToNPagedLookasideList(((PKEY_BLOB)(*PContext))->MemSource, *PContext); \
  89. *PContext = NULL; \
  90. }
  91. /*
  92. #define FreeMemoryBlock(PContext) { \
  93. PNPAGED_LOOKASIDE_LIST MemSource; \
  94. MemSource = ((PKEY_BLOB)(*PContext))->MemSource; \
  95. RtlFillMemory(*PContext, DESX_KEY_BLOB_LENGTH, 0x45);\
  96. ExFreeToNPagedLookasideList(MemSource, *PContext); \
  97. *PContext = NULL; \
  98. }
  99. */
  100. typedef CSHORT NODE_TYPE_CODE, *PNODE_TYPE_CODE;
  101. typedef CSHORT NODE_BYTE_SIZE, *PNODE_BYTE_SIZE;
  102. #define NTC_UNDEFINED ((NODE_TYPE_CODE)0x0000)
  103. #define EFS_NTC_DATA_HEADER ((NODE_TYPE_CODE)0x0E04)
  104. #define DES_KEY_BLOB_LENGTH (2 * sizeof(ULONG) + sizeof(PNPAGED_LOOKASIDE_LIST) + DES_TABLESIZE)
  105. #define DESX_KEY_BLOB_LENGTH (2 * sizeof(ULONG) + sizeof(PNPAGED_LOOKASIDE_LIST) + DESX_TABLESIZE)
  106. #define DES3_KEY_BLOB_LENGTH (2 * sizeof(ULONG) + sizeof(PNPAGED_LOOKASIDE_LIST) + DES3_TABLESIZE)
  107. #define AES_KEY_BLOB_LENGTH_256 (2 * sizeof(ULONG) + sizeof(PNPAGED_LOOKASIDE_LIST) + AES_TABLESIZE_256)
  108. //
  109. // EFS device object extension
  110. //
  111. typedef struct _DEVICE_EXTENSION {
  112. CSHORT Type;
  113. CSHORT Size;
  114. PDEVICE_OBJECT FileSystemDeviceObject;
  115. PDEVICE_OBJECT RealDeviceObject;
  116. BOOLEAN Attached;
  117. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
  118. //
  119. // EFS context block. Attached to CREATE Irp
  120. //
  121. typedef struct _EFS_CONTEXT {
  122. //
  123. // Status information
  124. //
  125. ULONG Status;
  126. ULONG Flags;
  127. PVOID EfsStreamData;
  128. KEVENT FinishEvent;
  129. } EFS_CONTEXT, *PEFS_CONTEXT;
  130. //
  131. // The keyBlob.
  132. //
  133. typedef struct _KEY_BLOB {
  134. ULONG KeyLength;
  135. //
  136. // Indicate what kind of encryption used
  137. //
  138. ULONG AlgorithmID;
  139. //
  140. // Where the memory comes from
  141. //
  142. PNPAGED_LOOKASIDE_LIST MemSource;
  143. UCHAR Key[1];
  144. } KEY_BLOB, *PKEY_BLOB;
  145. typedef struct _KEY_BLOB_RAMPOOL {
  146. ULONG AlgorithmID;
  147. PNPAGED_LOOKASIDE_LIST MemSourceList;
  148. LIST_ENTRY MemSourceChain;
  149. } KEY_BLOB_RAMPOOL, *PKEY_BLOB_RAMPOOL;
  150. //
  151. // EFS Open Cache Node
  152. //
  153. typedef struct _OPEN_CACHE {
  154. GUID EfsId;
  155. PTOKEN_USER UserId;
  156. LARGE_INTEGER TimeStamp;
  157. LIST_ENTRY CacheChain;
  158. } OPEN_CACHE, *POPEN_CACHE;
  159. //
  160. // The EFS_DATA keeps global data in the EFS file system in-memory
  161. // This structure must be allocated from non-paged pool.
  162. //
  163. typedef struct _EFS_DATA {
  164. //
  165. // The type and size of this record (must be EFS_NTC_DATA_HEADER)
  166. //
  167. NODE_TYPE_CODE NodeTypeCode;
  168. NODE_BYTE_SIZE NodeByteSize;
  169. DWORD EfsDriverCacheLength; // Cache valid length 2 - 30 seconds
  170. //
  171. // A Lookaside List for event object
  172. // The event object are used in synchronization.
  173. //
  174. NPAGED_LOOKASIDE_LIST EfsEventPool;
  175. //
  176. // A Lookaside List for EFS context
  177. // The EFS context is used in Create Irp.
  178. //
  179. NPAGED_LOOKASIDE_LIST EfsContextPool;
  180. //
  181. // A lookaside list for open operation cache
  182. //
  183. PAGED_LOOKASIDE_LIST EfsOpenCachePool;
  184. LIST_ENTRY EfsOpenCacheList;
  185. FAST_MUTEX EfsOpenCacheMutex;
  186. //
  187. // Lookaside Lists for key blob
  188. //
  189. LIST_ENTRY EfsKeyLookAsideList;
  190. FAST_MUTEX EfsKeyBlobMemSrcMutex;
  191. PAGED_LOOKASIDE_LIST EfsMemSourceItem;
  192. NPAGED_LOOKASIDE_LIST EfsLookAside;
  193. //
  194. // Session key.
  195. // Used to decrypt the FSCTL input buffer.
  196. //
  197. UCHAR SessionKey[DES_KEYSIZE];
  198. UCHAR SessionDesTable[DES_TABLESIZE];
  199. PRKPROCESS LsaProcess;
  200. //
  201. // Flag indicate EFS is ready
  202. //
  203. BOOLEAN EfsInitialized;
  204. BOOLEAN AllocMaxBuffer;
  205. HANDLE InitEventHandle;
  206. //PDEVICE_OBJECT FipsDeviceObject;
  207. PFILE_OBJECT FipsFileObject;
  208. FIPS_FUNCTION_TABLE FipsFunctionTable;
  209. //
  210. // Efs special attribute name
  211. //
  212. UNICODE_STRING EfsName;
  213. } EFS_DATA, *PEFS_DATA;
  214. //
  215. // This macro returns TRUE if a flag in a set of flags is on and FALSE
  216. // otherwise
  217. //
  218. //#ifndef BooleanFlagOn
  219. //#define BooleanFlagOn(F,SF) ( \
  220. // (BOOLEAN)(((F) & (SF)) != 0) \
  221. //)
  222. //#endif
  223. //#ifndef SetFlag
  224. //#define SetFlag(Flags,SingleFlag) { \
  225. // (Flags) |= (SingleFlag); \
  226. //}
  227. //#endif
  228. //#ifndef ClearFlag
  229. //#define ClearFlag(Flags,SingleFlag) { \
  230. // (Flags) &= ~(SingleFlag); \
  231. //}
  232. //#endif
  233. //
  234. // Function prototypes
  235. //
  236. //
  237. // Define driver entry routine.
  238. //
  239. NTSTATUS
  240. EfsInitialization(
  241. void
  242. );
  243. NTSTATUS
  244. EFSCreate(
  245. IN PDEVICE_OBJECT DeviceObject,
  246. IN PIRP Irp,
  247. IN PFILE_OBJECT FileObject
  248. );
  249. DWORD
  250. GetKeyBlobLength(
  251. ULONG AlgID
  252. );
  253. PKEY_BLOB
  254. GetKeyBlobBuffer(
  255. ULONG AlgID
  256. );
  257. BOOLEAN
  258. SetKeyTable(
  259. PKEY_BLOB KeyBlob,
  260. PEFS_KEY EfsKey
  261. );
  262. NTSTATUS
  263. EFSFsControl(
  264. IN PDEVICE_OBJECT DeviceObject,
  265. IN PIRP Irp,
  266. IN PFILE_OBJECT FileObject
  267. );
  268. NTSTATUS
  269. EFSPostCreate(
  270. IN PDEVICE_OBJECT DeviceObject,
  271. IN PIRP Irp,
  272. IN PEFS_CONTEXT EfsContext,
  273. IN ULONG OpenType
  274. );
  275. NTSTATUS
  276. EFSFilePostCreate(
  277. IN PDEVICE_OBJECT VolDo,
  278. IN PIRP Irp,
  279. IN PFILE_OBJECT FileObject,
  280. IN NTSTATUS Status,
  281. IN OUT PVOID *PCreateContext
  282. );
  283. VOID
  284. EfsGetSessionKey(
  285. IN PVOID StartContext
  286. );
  287. BOOLEAN
  288. EfsInitFips(
  289. VOID
  290. );
  291. //
  292. // private PS kernel funtions (this should REALLY be including ntos.h or ps.h)
  293. //
  294. NTKERNELAPI
  295. VOID
  296. PsRevertToSelf(
  297. VOID
  298. );
  299. NTKERNELAPI
  300. NTSTATUS
  301. PsLookupProcessByProcessId(
  302. IN HANDLE ProcessId,
  303. OUT PEPROCESS *Process
  304. );
  305. #endif