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.

414 lines
8.7 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // blob.h
  8. //
  9. // SYNOPSIS
  10. //
  11. // This file declares structs for extracting blobs from IAS_OCTET_STRING's.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 08/24/1998 Original version.
  16. // 11/10/1998 Added isLmPresent().
  17. // 01/25/1999 MS-CHAP v2
  18. // 05/21/1999 Remove MSChapChallenge.
  19. //
  20. ///////////////////////////////////////////////////////////////////////////////
  21. #ifndef _BLOB_H_
  22. #define _BLOB_H_
  23. #include <iaspolcy.h>
  24. #include <iaslsa.h>
  25. #include <iastlutl.h>
  26. #include <iasutil.h>
  27. using namespace IASTL;
  28. // nonstandard extension used : zero-sized array in struct/union
  29. #pragma warning(disable:4200)
  30. //////////
  31. // Safely extracts a blob from an IASATTRIBUTE.
  32. //////////
  33. template <class T>
  34. T& blob_cast(PIASATTRIBUTE a)
  35. {
  36. T& blob = (T&)(a->Value.OctetString);
  37. if (a->Value.itType != IASTYPE_OCTET_STRING || !blob.isValid())
  38. {
  39. _com_issue_error(IAS_MALFORMED_REQUEST);
  40. }
  41. return blob;
  42. }
  43. ///////////////////////////////////////////////////////////////////////////////
  44. //
  45. // STRUCT
  46. //
  47. // (BLOB)
  48. //
  49. // DESCRIPTION
  50. //
  51. // Each blob struct inherits from IAS_OCTET_STRING. It in turn has a nested
  52. // struct called 'Layout' which defines the wire format of the bytes. It
  53. // also defines an isValid method that tests whether the IAS_OCTET_STRING
  54. // can be safely downcast.
  55. //
  56. ///////////////////////////////////////////////////////////////////////////////
  57. struct MSChapResponse : IAS_OCTET_STRING
  58. {
  59. struct Layout
  60. {
  61. BYTE ident;
  62. BYTE flags;
  63. BYTE lmResponse[_LM_RESPONSE_LENGTH];
  64. BYTE ntResponse[_NT_RESPONSE_LENGTH];
  65. };
  66. Layout& get() throw ()
  67. { return *(Layout*)lpValue; }
  68. const Layout& get() const throw ()
  69. { return *(Layout*)lpValue; }
  70. bool isValid() const throw ()
  71. {
  72. return dwLength == sizeof(Layout);
  73. }
  74. bool isLmPresent() const throw ();
  75. bool isNtPresent() const throw ()
  76. {
  77. return (get().flags & 0x1) != 0;
  78. }
  79. };
  80. struct MSChapCPW1 : IAS_OCTET_STRING
  81. {
  82. struct Layout
  83. {
  84. BYTE code;
  85. BYTE ident;
  86. BYTE lmOldPwd[_ENCRYPTED_LM_OWF_PASSWORD_LENGTH];
  87. BYTE lmNewPwd[_ENCRYPTED_LM_OWF_PASSWORD_LENGTH];
  88. BYTE ntOldPwd[_ENCRYPTED_NT_OWF_PASSWORD_LENGTH];
  89. BYTE ntNewPwd[_ENCRYPTED_NT_OWF_PASSWORD_LENGTH];
  90. BYTE newLmPwdLen[2];
  91. BYTE flags[2];
  92. };
  93. Layout& get() throw ()
  94. { return *(Layout*)lpValue; }
  95. const Layout& get() const throw ()
  96. { return *(Layout*)lpValue; }
  97. bool isValid() const throw ()
  98. {
  99. return (dwLength == sizeof(Layout)) && (get().code == 5);
  100. }
  101. WORD getNewLmPwdLen() const throw ()
  102. {
  103. return IASExtractWORD(get().newLmPwdLen);
  104. }
  105. bool isNtPresent() const throw ()
  106. {
  107. return (get().flags[1] & 0x1) != 0;
  108. }
  109. };
  110. struct MSChapCPW2 : IAS_OCTET_STRING
  111. {
  112. struct Layout
  113. {
  114. BYTE code;
  115. BYTE ident;
  116. BYTE oldNtHash[_ENCRYPTED_NT_OWF_PASSWORD_LENGTH];
  117. BYTE oldLmHash[_ENCRYPTED_LM_OWF_PASSWORD_LENGTH];
  118. BYTE lmResponse[_LM_RESPONSE_LENGTH];
  119. BYTE ntResponse[_NT_RESPONSE_LENGTH];
  120. BYTE flags[2];
  121. };
  122. Layout& get() throw ()
  123. { return *(Layout*)lpValue; }
  124. const Layout& get() const throw ()
  125. { return *(Layout*)lpValue; }
  126. bool isValid() const throw ()
  127. {
  128. return (dwLength == sizeof(Layout)) && (get().code == 6);
  129. }
  130. bool isLmPresent() const throw ();
  131. bool isLmHashValid() const throw ()
  132. {
  133. return (get().flags[1] & 0x2) != 0;
  134. }
  135. bool isNtResponseValid() const throw ()
  136. {
  137. return (get().flags[1] & 0x1) != 0;
  138. }
  139. };
  140. struct MSChapEncPW : IAS_OCTET_STRING
  141. {
  142. struct Layout
  143. {
  144. BYTE code;
  145. BYTE ident;
  146. BYTE sequence[2];
  147. BYTE string[0];
  148. };
  149. Layout& get() throw ()
  150. { return *(Layout*)lpValue; }
  151. const Layout& get() const throw ()
  152. { return *(Layout*)lpValue; }
  153. bool isValid() const throw ()
  154. {
  155. return (dwLength >= sizeof(Layout)) && (get().code == 6);
  156. }
  157. DWORD getStringLength() const throw ()
  158. {
  159. return dwLength - FIELD_OFFSET(Layout, string);
  160. }
  161. WORD getSequence() const throw ()
  162. {
  163. return IASExtractWORD(get().sequence);
  164. }
  165. bool operator<(const MSChapEncPW& pw) const throw ()
  166. {
  167. return getSequence() < pw.getSequence();
  168. }
  169. static BOOL getEncryptedPassword(
  170. IASRequest& request,
  171. DWORD dwId,
  172. PBYTE buf
  173. );
  174. };
  175. struct MSChapDomain : IAS_OCTET_STRING
  176. {
  177. struct Layout
  178. {
  179. BYTE ident;
  180. BYTE string[0];
  181. };
  182. static void insert(
  183. IASRequest& request,
  184. BYTE ident,
  185. PCWSTR domain
  186. );
  187. };
  188. struct MSChapError : IAS_OCTET_STRING
  189. {
  190. struct Layout
  191. {
  192. BYTE ident;
  193. BYTE string[0];
  194. };
  195. static void insert(
  196. IASRequest& request,
  197. BYTE ident,
  198. DWORD errorCode
  199. );
  200. };
  201. struct MSChapMPPEKeys : IAS_OCTET_STRING
  202. {
  203. struct Layout
  204. {
  205. BYTE lmKey[8];
  206. BYTE ntKey[16];
  207. BYTE challenge[8];
  208. };
  209. static void insert(
  210. IASRequest& request,
  211. PBYTE lmKey,
  212. PBYTE ntKey,
  213. PBYTE challenge
  214. );
  215. };
  216. struct MSChap2Response : IAS_OCTET_STRING
  217. {
  218. struct Layout
  219. {
  220. BYTE ident;
  221. BYTE flags;
  222. BYTE peerChallenge[16];
  223. BYTE reserved[8];
  224. BYTE response[_NT_RESPONSE_LENGTH];
  225. };
  226. Layout& get() throw ()
  227. { return *(Layout*)lpValue; }
  228. const Layout& get() const throw ()
  229. { return *(Layout*)lpValue; }
  230. bool isValid() const throw ()
  231. {
  232. return dwLength == sizeof(Layout);
  233. }
  234. };
  235. struct MSChap2Success : IAS_OCTET_STRING
  236. {
  237. struct Layout
  238. {
  239. BYTE ident;
  240. BYTE string[42];
  241. };
  242. static void insert(
  243. IASRequest& request,
  244. BYTE ident,
  245. PBYTE authenticatorResponse
  246. );
  247. };
  248. struct MSMPPEKey : IAS_OCTET_STRING
  249. {
  250. struct Layout
  251. {
  252. BYTE salt[2];
  253. BYTE keyLength;
  254. BYTE key[0];
  255. };
  256. static void insert(
  257. IASRequest& request,
  258. ULONG keyLength,
  259. PBYTE key,
  260. BOOL isSendKey
  261. );
  262. };
  263. struct MSChap2CPW : IAS_OCTET_STRING
  264. {
  265. struct Layout
  266. {
  267. BYTE code;
  268. BYTE ident;
  269. BYTE encryptedHash[_ENCRYPTED_NT_OWF_PASSWORD_LENGTH];
  270. BYTE peerChallenge[16];
  271. BYTE reserved[8];
  272. BYTE response[_NT_RESPONSE_LENGTH];
  273. BYTE flags[2];
  274. };
  275. Layout& get() throw ()
  276. { return *(Layout*)lpValue; }
  277. const Layout& get() const throw ()
  278. { return *(Layout*)lpValue; }
  279. bool isValid() const throw ()
  280. {
  281. return (dwLength == sizeof(Layout)) && (get().code == 7);
  282. }
  283. };
  284. struct ArapChallenge : IAS_OCTET_STRING
  285. {
  286. struct Layout
  287. {
  288. DWORD ntChallenge1;
  289. DWORD ntChallenge2;
  290. };
  291. Layout& get() throw ()
  292. { return *(Layout*)lpValue; }
  293. const Layout& get() const throw ()
  294. { return *(Layout*)lpValue; }
  295. bool isValid() const throw ()
  296. {
  297. return dwLength == sizeof(Layout);
  298. }
  299. };
  300. struct ArapPassword : IAS_OCTET_STRING
  301. {
  302. struct Layout
  303. {
  304. DWORD macChallenge1;
  305. DWORD macChallenge2;
  306. DWORD macResponse1;
  307. DWORD macResponse2;
  308. };
  309. Layout& get() throw ()
  310. { return *(Layout*)lpValue; }
  311. const Layout& get() const throw ()
  312. { return *(Layout*)lpValue; }
  313. bool isValid() const throw ()
  314. {
  315. return dwLength == sizeof(Layout);
  316. }
  317. };
  318. struct ArapChallengeResponse : IAS_OCTET_STRING
  319. {
  320. struct Layout
  321. {
  322. BYTE ntResponse1[4];
  323. BYTE ntResponse2[4];
  324. };
  325. static void insert(
  326. IASRequest& request,
  327. DWORD NTResponse1,
  328. DWORD NTResponse2
  329. );
  330. };
  331. struct ArapFeatures : IAS_OCTET_STRING
  332. {
  333. struct Layout
  334. {
  335. BYTE changePasswordAllowed;
  336. BYTE minPasswordLength;
  337. BYTE pwdCreationDate[4];
  338. BYTE pwdExpiryDelta[4];
  339. BYTE currentTime[4];
  340. };
  341. static void insert(
  342. IASRequest& request,
  343. DWORD PwdCreationDate,
  344. DWORD PwdExpiryDelta,
  345. DWORD CurrentTime
  346. );
  347. };
  348. #endif // _BLOB_H_