Leaked source code of windows server 2003
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.

416 lines
17 KiB

  1. /****************************************************************************/
  2. /* asmint.h */
  3. /* */
  4. /* Security Manager Internal Functions */
  5. /* */
  6. /* Copyright (C) 1997-1999 Microsoft Corp. */
  7. /****************************************************************************/
  8. #ifndef _H_ASMINT
  9. #define _H_ASMINT
  10. /****************************************************************************/
  11. /* Include required system headers */
  12. /* And some prototypes for which I can't use the system header because it */
  13. /* also has icky user mode stuff */
  14. /****************************************************************************/
  15. #include <ntnls.h>
  16. #include <fipsapi.h>
  17. NTSYSAPI
  18. VOID
  19. NTAPI
  20. RtlGetDefaultCodePage(
  21. OUT PUSHORT AnsiCodePage,
  22. OUT PUSHORT OemCodePage
  23. );
  24. NTSYSAPI
  25. NTSTATUS
  26. NTAPI
  27. RtlMultiByteToUnicodeN(
  28. PWSTR UnicodeString,
  29. ULONG MaxBytesInUnicodeString,
  30. PULONG BytesInUnicodeString,
  31. PCHAR MultiByteString,
  32. ULONG BytesInMultiByteString
  33. );
  34. NTSYSAPI
  35. NTSTATUS
  36. NTAPI
  37. RtlUnicodeToMultiByteN(
  38. PCHAR MultiByteString,
  39. ULONG MaxBytesInMultiByteString,
  40. PULONG BytesInMultiByteString,
  41. PWSTR UnicodeString,
  42. ULONG BytesInUnicodeString
  43. );
  44. NTSYSAPI
  45. VOID
  46. NTAPI
  47. RtlInitCodePageTable(
  48. IN PUSHORT TableBase,
  49. OUT PCPTABLEINFO CodePageTable
  50. );
  51. NTSYSAPI
  52. NTSTATUS
  53. NTAPI
  54. RtlCustomCPToUnicodeN(
  55. IN PCPTABLEINFO CustomCP,
  56. OUT PWCH UnicodeString,
  57. IN ULONG MaxBytesInUnicodeString,
  58. OUT PULONG BytesInUnicodeString OPTIONAL,
  59. IN PCH CustomCPString,
  60. IN ULONG BytesInCustomCPString
  61. );
  62. NTSYSAPI
  63. NTSTATUS
  64. NTAPI
  65. RtlUnicodeToCustomCPN(
  66. IN PCPTABLEINFO CustomCP,
  67. OUT PCH CustomCPString,
  68. IN ULONG MaxBytesInCustomCPString,
  69. OUT PULONG BytesInCustomCPString OPTIONAL,
  70. IN PWCH UnicodeString,
  71. IN ULONG BytesInUnicodeString
  72. );
  73. /****************************************************************************/
  74. /* Include T.120 headers */
  75. /****************************************************************************/
  76. #include <at128.h>
  77. #include "license.h"
  78. #include <tssec.h>
  79. #include <at120ex.h>
  80. /****************************************************************************/
  81. /* Include SM API */
  82. /****************************************************************************/
  83. #include <asmapi.h>
  84. /****************************************************************************/
  85. /* Include other Share APIs */
  86. /****************************************************************************/
  87. #include <nwdwapi.h>
  88. /****************************************************************************/
  89. /* Constants */
  90. /****************************************************************************/
  91. #define WIN_DONTDISPLAYLASTUSERNAME_DFLT 0
  92. /****************************************************************************/
  93. /* Security config defaults */
  94. /****************************************************************************/
  95. #define WIN_MINENCRYPTIONLEVEL_DFLT 1
  96. #define WIN_DISABLEENCRYPTION_DFLT FALSE
  97. /****************************************************************************/
  98. /* SM States */
  99. /****************************************************************************/
  100. #define SM_STATE_STARTED 0
  101. #define SM_STATE_INITIALIZED 1
  102. #define SM_STATE_NM_CONNECTING 2
  103. #define SM_STATE_SM_CONNECTING 3
  104. #define SM_STATE_LICENSING 4
  105. #define SM_STATE_CONNECTED 5
  106. #define SM_STATE_SC_REGISTERED 6
  107. #define SM_STATE_DISCONNECTING 7
  108. #define SM_NUM_STATES 8
  109. /****************************************************************************/
  110. /* SM Events */
  111. /****************************************************************************/
  112. #define SM_EVT_INIT 0
  113. #define SM_EVT_TERM 1
  114. #define SM_EVT_REGISTER 2
  115. #define SM_EVT_CONNECT 3
  116. #define SM_EVT_DISCONNECT 4
  117. #define SM_EVT_CONNECTED 5
  118. #define SM_EVT_DISCONNECTED 6
  119. #define SM_EVT_DATA_PACKET 7
  120. // Note that Alloc & Send have the same event ID, as the conditions
  121. // under which these may be called are identical.
  122. #define SM_EVT_ALLOCBUFFER 8
  123. #define SM_EVT_SENDDATA 8
  124. #define SM_EVT_SEC_PACKET 9
  125. #define SM_EVT_LIC_PACKET 10
  126. #define SM_EVT_ALIVE 11
  127. #define SM_NUM_EVENTS 12
  128. /****************************************************************************/
  129. /* Values in the state table */
  130. /****************************************************************************/
  131. #define SM_TABLE_OK 0
  132. #define SM_TABLE_WARN 1
  133. #define SM_TABLE_ERROR 2
  134. /****************************************************************************/
  135. /* SM_CHECK_STATE checks whether we have violated the SM state table. */
  136. /* */
  137. /* smStateTable is filled in in ASMDATA.C. */
  138. /* */
  139. /* Possible values of STATE are defined in ASMINT.H. */
  140. /* Possible events are defined in ASMINT.H */
  141. /****************************************************************************/
  142. #define SM_CHECK_STATE(event) \
  143. { \
  144. if (smStateTable[event][pRealSMHandle->state] != SM_TABLE_OK) \
  145. { \
  146. if (smStateTable[event][pRealSMHandle->state] == SM_TABLE_WARN) \
  147. { \
  148. TRC_ALT((TB, "Unusual event %s in state %s", \
  149. smEventName[event], smStateName[pRealSMHandle->state]));\
  150. } \
  151. else \
  152. { \
  153. TRC_ABORT((TB, "Invalid event %s in state %s", \
  154. smEventName[event], smStateName[pRealSMHandle->state]));\
  155. } \
  156. DC_QUIT; \
  157. } \
  158. }
  159. // Query version which supports properly predicting branches.
  160. // Assumes that the "else" case will be the end of the function.
  161. #ifdef DC_DEBUG
  162. #define SM_CHECK_STATE_Q(event) SMCheckState(pRealSMHandle, event)
  163. #else
  164. #define SM_CHECK_STATE_Q(event) \
  165. (smStateTable[event][pRealSMHandle->state] == SM_TABLE_OK)
  166. #endif
  167. /****************************************************************************/
  168. /* SM_SET_STATE - set the SLCstate */
  169. /****************************************************************************/
  170. #define SM_SET_STATE(newstate) \
  171. { \
  172. TRC_NRM((TB, "Set state from %s to %s", \
  173. smStateName[pRealSMHandle->state], smStateName[newstate])); \
  174. pRealSMHandle->state = newstate; \
  175. }
  176. typedef struct tagSM_CONSOLE_BUFFER
  177. {
  178. LIST_ENTRY links;
  179. PVOID buffer;
  180. UINT32 length;
  181. } SM_CONSOLE_BUFFER, *PSM_CONSOLE_BUFFER;
  182. //
  183. // Instrumentation enabled to track discarded packets
  184. // (to help track VC decompression break).
  185. //
  186. #define INSTRUM_TRACK_DISCARDED 1
  187. typedef struct _SM_FIPS_Data {
  188. BYTE bEncKey[MAX_FIPS_SESSION_KEY_SIZE];
  189. BYTE bDecKey[MAX_FIPS_SESSION_KEY_SIZE];
  190. DES3TABLE EncTable;
  191. DES3TABLE DecTable;
  192. BYTE bEncIv[FIPS_BLOCK_LEN];
  193. BYTE bDecIv[FIPS_BLOCK_LEN];
  194. BYTE bSignKey[MAX_SIGNKEY_SIZE];
  195. PDEVICE_OBJECT pDeviceObject;
  196. PFILE_OBJECT pFileObject;
  197. FIPS_FUNCTION_TABLE FipsFunctionTable;
  198. } SM_FIPS_Data, FAR * PSM_FIPS_Data;
  199. /****************************************************************************/
  200. /* Structure: SM_HANDLE_DATA */
  201. /* */
  202. /* Description: Structure of context-specific data maintained by SM */
  203. /****************************************************************************/
  204. typedef struct tagSM_HANDLE_DATA
  205. {
  206. /************************************************************************/
  207. /* winstation encryption level. */
  208. /************************************************************************/
  209. UINT32 encryptionLevel;
  210. UINT32 encryptionMethodsSupported;
  211. UINT32 encryptionMethodSelected;
  212. BOOLEAN frenchClient;
  213. BOOLEAN encryptAfterLogon;
  214. /************************************************************************/
  215. /* Are we encrypting? */
  216. /************************************************************************/
  217. BOOLEAN encrypting; // Whether the client is encrypting input.
  218. BOOLEAN encryptDisplayData; // Whether server is encrypting output.
  219. BOOLEAN encryptingLicToClient; // Whether S->C license data is encrypted
  220. //
  221. // whether server should send data using safe checksum style
  222. //
  223. BOOLEAN useSafeChecksumMethod;
  224. /************************************************************************/
  225. /* State information */
  226. /************************************************************************/
  227. BOOLEAN bDisconnectWorkerSent;
  228. BOOLEAN dead;
  229. UINT32 state;
  230. #ifdef INSTRUM_TRACK_DISCARDED
  231. //
  232. // Debug information
  233. //
  234. UINT32 nDiscardVCDataWhenDead;
  235. UINT32 nDiscardPDUBadState;
  236. UINT32 nDiscardNonVCPDUWhenDead;
  237. #endif
  238. /************************************************************************/
  239. /* User data to pass back to Client */
  240. /************************************************************************/
  241. PRNS_UD_SC_SEC pUserData;
  242. /************************************************************************/
  243. /* WDW handle, passed back on WDW_SMCallback calls */
  244. /************************************************************************/
  245. PTSHARE_WD pWDHandle;
  246. #ifdef USE_LICENSE
  247. /************************************************************************/
  248. /* License Manager handle */
  249. /************************************************************************/
  250. PVOID pLicenseHandle;
  251. #endif
  252. /************************************************************************/
  253. /* MCS User and Channel IDs */
  254. /************************************************************************/
  255. UINT32 userID;
  256. UINT16 channelID;
  257. /************************************************************************/
  258. /* Max size of a PDU reported by NM */
  259. /************************************************************************/
  260. UINT32 maxPDUSize;
  261. /************************************************************************/
  262. /* The type of certificate that is used in the security key exchange. */
  263. /************************************************************************/
  264. CERT_TYPE CertType;
  265. /************************************************************************/
  266. /* Client and server random keys that make the client/server session */
  267. /* keys. */
  268. /************************************************************************/
  269. PBYTE pEncClientRandom;
  270. UINT32 encClientRandomLen;
  271. BOOLEAN recvdClientRandom;
  272. // state of whether share class is ready for data forwarding or not
  273. BOOLEAN bForwardDataToSC;
  274. /************************************************************************/
  275. /* encrypt/decrypt session keys. key length is 8 for 40 bit encryption */
  276. /* and 16 for 128 encryption. */
  277. /************************************************************************/
  278. BOOLEAN bSessionKeysMade;
  279. UINT32 keyLength;
  280. UINT32 encryptCount;
  281. UINT32 totalEncryptCount;
  282. UINT32 encryptHeaderLen;
  283. // Used if encryptDisplayData is FALSE, but we want to encrypt this particular S->C packet
  284. UINT32 encryptHeaderLenIfForceEncrypt;
  285. BYTE startEncryptKey[MAX_SESSION_KEY_SIZE];
  286. BYTE currentEncryptKey[MAX_SESSION_KEY_SIZE];
  287. struct RC4_KEYSTRUCT rc4EncryptKey;
  288. UINT32 decryptCount;
  289. UINT32 totalDecryptCount;
  290. BYTE startDecryptKey[MAX_SESSION_KEY_SIZE];
  291. BYTE currentDecryptKey[MAX_SESSION_KEY_SIZE];
  292. struct RC4_KEYSTRUCT rc4DecryptKey;
  293. BYTE macSaltKey[MAX_SESSION_KEY_SIZE];
  294. LIST_ENTRY consoleBufferList;
  295. UINT32 consoleBufferCount;
  296. SM_FIPS_Data FIPSData;
  297. } SM_HANDLE_DATA, * PSM_HANDLE_DATA;
  298. /****************************************************************************/
  299. /* Functions */
  300. /****************************************************************************/
  301. BOOL RDPCALL SMDecryptPacket(PSM_HANDLE_DATA pRealSMHandle,
  302. PVOID pData,
  303. unsigned dataLen,
  304. BOOL fUseSafeChecksum);
  305. BOOLEAN RDPCALL SMContinueSecurityExchange(PSM_HANDLE_DATA pRealSMHandle,
  306. PVOID pData,
  307. UINT32 dataLen);
  308. BOOLEAN RDPCALL SMSecurityExchangeInfo(PSM_HANDLE_DATA pRealSMHandle,
  309. PVOID pData,
  310. UINT32 dataLen);
  311. BOOLEAN RDPCALL SMSecurityExchangeKey(PSM_HANDLE_DATA pRealSMHandle,
  312. PVOID pData,
  313. UINT32 dataLen);
  314. void RDPCALL SMFreeInitResources(PSM_HANDLE_DATA pRealSMHandle);
  315. void RDPCALL SMFreeConnectResources(PSM_HANDLE_DATA pRealSMHandle);
  316. INT ConvertToAndFromWideChar(PSM_HANDLE_DATA pRealSMHandle,
  317. UINT CodePage, LPWSTR WideCharString,
  318. INT BytesInWideCharString, LPSTR MultiByteString,
  319. INT BytesInMultiByteString, BOOL ConvertToWideChar);
  320. BOOL RDPCALL SMCheckState(PSM_HANDLE_DATA, unsigned);
  321. BOOL TSFIPS_Init(PSM_FIPS_Data pFipsData);
  322. void TSFIPS_Term(PSM_FIPS_Data pFipsData);
  323. UINT32 TSFIPS_AdjustDataLen(UINT32 dataLen);
  324. BOOL TSFIPS_MakeSessionKeys(PSM_FIPS_Data pFipsData, LPRANDOM_KEYS_PAIR pRandomKey, CryptMethod *pEnumMethod, BOOL bPassThroughStack);
  325. BOOL TSFIPS_EncryptData(
  326. PSM_FIPS_Data pFipsData,
  327. LPBYTE pbData,
  328. DWORD dwDataLen,
  329. DWORD dwPadLen,
  330. LPBYTE pbSignature,
  331. DWORD dwEncryptionCount);
  332. BOOL TSFIPS_DecryptData(
  333. PSM_FIPS_Data pFipsData,
  334. LPBYTE pbData,
  335. DWORD dwDataLen,
  336. DWORD dwPadLen,
  337. LPBYTE pbSignature,
  338. DWORD dwDecryptionCount);
  339. // Win16 code page driver-global caching data.
  340. extern FAST_MUTEX fmCodePage;
  341. extern ULONG LastCodePageTranslated;
  342. extern PVOID LastNlsTableBuffer;
  343. extern CPTABLEINFO LastCPTableInfo;
  344. extern UINT NlsTableUseCount;
  345. #endif /* _H_ASMINT */