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.

431 lines
12 KiB

  1. /* Copyright (c) 1993, Microsoft Corporation, all rights reserved
  2. **
  3. ** raschap.h
  4. ** Remote Access PPP Challenge Handshake Authentication Protocol
  5. **
  6. ** 11/05/93 Steve Cobb
  7. */
  8. #ifndef _RASCHAP_H_
  9. #define _RASCHAP_H_
  10. #include "md5.h"
  11. #include <ntsamp.h>
  12. #define TRACE_RASCHAP (0x00010000|TRACE_USE_MASK|TRACE_USE_MSEC|TRACE_USE_DATE)
  13. #define TRACE(a) TracePrintfExA(g_dwTraceIdChap,TRACE_RASCHAP,a )
  14. #define TRACE1(a,b) TracePrintfExA(g_dwTraceIdChap,TRACE_RASCHAP,a,b )
  15. #define TRACE2(a,b,c) TracePrintfExA(g_dwTraceIdChap,TRACE_RASCHAP,a,b,c )
  16. #define TRACE3(a,b,c,d) TracePrintfExA(g_dwTraceIdChap,TRACE_RASCHAP,a,b,c,d )
  17. #define DUMPW(X,Y) TraceDumpExA(g_dwTraceIdChap,1,(LPBYTE)X,Y,4,1,NULL)
  18. #define DUMPB(X,Y) TraceDumpExA(g_dwTraceIdChap,1,(LPBYTE)X,Y,1,1,NULL)
  19. //General macros
  20. #define GEN_RAND_ENCODE_SEED ((CHAR) ( 1 + rand() % 250 ))
  21. /* CHAP packet codes from CHAP spec except ChangePw.
  22. */
  23. #define CHAPCODE_Challenge 1
  24. #define CHAPCODE_Response 2
  25. #define CHAPCODE_Success 3
  26. #define CHAPCODE_Failure 4
  27. #define CHAPCODE_ChangePw1 5
  28. #define CHAPCODE_ChangePw2 6
  29. #define CHAPCODE_ChangePw3 7
  30. #define MAXCHAPCODE 7
  31. /* Returned by receive buffer parsing routines that discover the packet is
  32. ** corrupt, usually because the length fields don't make sense.
  33. */
  34. #define ERRORBADPACKET (DWORD )-1
  35. /* Maximum challenge and response lengths.
  36. */
  37. #define MAXCHALLENGELEN 255
  38. #define MSRESPONSELEN (LM_RESPONSE_LENGTH + NT_RESPONSE_LENGTH + 1)
  39. #define MD5RESPONSELEN MD5_LEN
  40. #define MAXRESPONSELEN max( MSRESPONSELEN, MD5RESPONSELEN )
  41. #define MAXINFOLEN 1500
  42. /* Defines states within the CHAP protocol.
  43. */
  44. #define CHAPSTATE enum tagCHAPSTATE
  45. CHAPSTATE
  46. {
  47. CS_Initial,
  48. CS_WaitForChallenge,
  49. CS_ChallengeSent,
  50. CS_ResponseSent,
  51. CS_Retry,
  52. CS_ChangePw,
  53. CS_ChangePw1,
  54. CS_ChangePw2,
  55. CS_ChangePw1Sent,
  56. CS_ChangePw2Sent,
  57. CS_WaitForAuthenticationToComplete1,
  58. CS_WaitForAuthenticationToComplete2,
  59. CS_Done
  60. };
  61. /* Defines the change password version 1 (NT 3.5) response data buffer.
  62. */
  63. #define CHANGEPW1 struct tagCHANGEPW1
  64. CHANGEPW1
  65. {
  66. BYTE abEncryptedLmOwfOldPw[ ENCRYPTED_LM_OWF_PASSWORD_LENGTH ];
  67. BYTE abEncryptedLmOwfNewPw[ ENCRYPTED_LM_OWF_PASSWORD_LENGTH ];
  68. BYTE abEncryptedNtOwfOldPw[ ENCRYPTED_NT_OWF_PASSWORD_LENGTH ];
  69. BYTE abEncryptedNtOwfNewPw[ ENCRYPTED_NT_OWF_PASSWORD_LENGTH ];
  70. BYTE abPasswordLength[ 2 ];
  71. BYTE abFlags[ 2 ];
  72. };
  73. /* CHANGEPW1.abFlags bit definitions.
  74. */
  75. #define CPW1F_UseNtResponse 0x00000001
  76. /* Define the change password version 2 (NT 3.51) response data buffer.
  77. */
  78. #define CHANGEPW2 struct tagCHANGEPW2
  79. CHANGEPW2
  80. {
  81. BYTE abNewEncryptedWithOldNtOwf[ sizeof(SAMPR_ENCRYPTED_USER_PASSWORD) ];
  82. BYTE abOldNtOwfEncryptedWithNewNtOwf[ ENCRYPTED_NT_OWF_PASSWORD_LENGTH ];
  83. BYTE abNewEncryptedWithOldLmOwf[ sizeof(SAMPR_ENCRYPTED_USER_PASSWORD) ];
  84. BYTE abOldLmOwfEncryptedWithNewNtOwf[ ENCRYPTED_NT_OWF_PASSWORD_LENGTH ];
  85. BYTE abLmResponse[ LM_RESPONSE_LENGTH ];
  86. BYTE abNtResponse[ NT_RESPONSE_LENGTH ];
  87. BYTE abFlags[ 2 ];
  88. };
  89. /* CHANGEPW2.abFlags bit definitions.
  90. */
  91. #define CPW2F_UseNtResponse 0x00000001
  92. #define CPW2F_LmPasswordPresent 0x00000002
  93. /* Define the change password for new MS-CHAP
  94. */
  95. #define CHANGEPW3 struct tagCHANGEPW3
  96. CHANGEPW3
  97. {
  98. BYTE abEncryptedPassword[ 516 ];
  99. BYTE abEncryptedHash[ 16 ];
  100. BYTE abPeerChallenge[ 24 ];
  101. BYTE abNTResponse[ 24 ];
  102. BYTE abFlags[ 2 ];
  103. };
  104. /* Union for storage effieciency (never need both formats at same time).
  105. */
  106. #define CHANGEPW union tagCHANGEPW
  107. CHANGEPW
  108. {
  109. /* This dummy field is included so the MIPS compiler will align the
  110. ** structure on a DWORD boundary. Normally, MIPS does not force alignment
  111. ** if the structure contains only BYTEs or BYTE arrays. This protects us
  112. ** from alignment faults should SAM or LSA interpret the byte arrays as
  113. ** containing some necessarily aligned type, though currently they do not.
  114. */
  115. DWORD dwAlign;
  116. CHANGEPW1 v1;
  117. CHANGEPW2 v2;
  118. CHANGEPW3 v3;
  119. };
  120. /* Defines the WorkBuf stored for us by the PPP engine.
  121. */
  122. #define CHAPWB struct tagCHAPWB
  123. CHAPWB
  124. {
  125. /* CHAP encryption method negotiated (MD5 or Microsoft extended). Note
  126. ** that server does not support MD5.
  127. */
  128. BYTE bAlgorithm;
  129. /* True if role is server, false if client.
  130. */
  131. BOOL fServer;
  132. /* The port handle on which the protocol is active.
  133. */
  134. HPORT hport;
  135. /* Number of authentication attempts left before we shut down. (Microsoft
  136. ** extended CHAP only)
  137. */
  138. DWORD dwTriesLeft;
  139. /* Client's credentials.
  140. */
  141. CHAR szUserName[ UNLEN + DNLEN + 2 ];
  142. CHAR szOldPassword[ PWLEN + 1 ];
  143. CHAR szPassword[ PWLEN + 1 ];
  144. CHAR szDomain[ DNLEN + 1 ];
  145. /* The LUID is a logon ID required by LSA to determine the response. It
  146. ** must be determined in calling app's context and is therefore passed
  147. ** down. (client only)
  148. */
  149. LUID Luid;
  150. /* The challenge sent or received in the Challenge Packet and the length
  151. ** in bytes of same. Note that LUID above keeps this DWORD aligned.
  152. */
  153. BYTE abChallenge[ MAXCHALLENGELEN ];
  154. BYTE cbChallenge;
  155. BYTE abComputedChallenge[ MAXCHALLENGELEN ];
  156. /* Indicates whether a new challenge was provided in the last Failure
  157. ** packet. (client only)
  158. */
  159. BOOL fNewChallengeProvided;
  160. /* The response sent or received in the Response packet and the length in
  161. ** bytes of same. Note the BOOL above keeps this DWORD aligned.
  162. */
  163. BYTE abResponse[ MAXRESPONSELEN ];
  164. BYTE cbResponse;
  165. /* The change password response sent or received in the ChangePw or
  166. ** ChangePw2 packets.
  167. */
  168. CHANGEPW changepw;
  169. /* The LM and user session keys retrieved when credentials are successfully
  170. ** authenticated.
  171. */
  172. LM_SESSION_KEY keyLm;
  173. USER_SESSION_KEY keyUser;
  174. /* This flag indicates that the session key has been calculated
  175. ** from the password or retrieved from LSA.
  176. */
  177. BOOL fSessionKeysObtained;
  178. /* On the client, this contains the pointer to the MPPE keys. On the server
  179. ** this field is not used.
  180. */
  181. RAS_AUTH_ATTRIBUTE * pMPPEKeys;
  182. /* The current state in the CHAP protocol.
  183. */
  184. CHAPSTATE state;
  185. /* Sequencing ID expected on next packet received on this port and the
  186. ** value to send on the next outgoing packet.
  187. */
  188. BYTE bIdExpected;
  189. BYTE bIdToSend;
  190. /* The final result, used to duplicate the original response in subsequent
  191. ** response packets. This is per CHAP spec to cover lost Success/Failure
  192. ** case without allowing malicious client to discover alternative
  193. ** identities under the covers during a connection. (applies to server
  194. ** only)
  195. */
  196. PPPAP_RESULT result;
  197. HPORT hPort;
  198. DWORD dwInitialPacketId;
  199. DWORD fConfigInfo;
  200. RAS_AUTH_ATTRIBUTE * pAttributesFromAuthenticator;
  201. //
  202. // Used to send authentication request to backend server
  203. //
  204. RAS_AUTH_ATTRIBUTE * pUserAttributes;
  205. // CHAR chSeed; //Seed for encoding password.
  206. //
  207. // Data Blob information for password
  208. //
  209. DATA_BLOB DBPassword;
  210. //
  211. // Data Blob information for oldpassword
  212. //
  213. DATA_BLOB DBOldPassword;
  214. };
  215. /* Prototypes.
  216. */
  217. DWORD
  218. ChapInit(
  219. IN BOOL fInitialize
  220. );
  221. DWORD ChapSMakeMessage( CHAPWB*, PPP_CONFIG*, PPP_CONFIG*, DWORD, PPPAP_RESULT*,
  222. PPPAP_INPUT* );
  223. DWORD
  224. MakeAuthenticationRequestAttributes(
  225. IN CHAPWB* pwb,
  226. IN BOOL fMSChap,
  227. IN BYTE bAlgorithm,
  228. IN CHAR* szUserName,
  229. IN BYTE* pbChallenge,
  230. IN DWORD cbChallenge,
  231. IN BYTE* pbResponse,
  232. IN DWORD cbResponse,
  233. IN BYTE bId
  234. );
  235. DWORD
  236. GetErrorCodeFromAttributes(
  237. IN CHAPWB* pwb
  238. );
  239. DWORD
  240. LoadChapHelperFunctions(
  241. VOID
  242. );
  243. DWORD ChapCMakeMessage( CHAPWB*, PPP_CONFIG*, PPP_CONFIG*, DWORD, PPPAP_RESULT*,
  244. PPPAP_INPUT* );
  245. DWORD ChapBegin( VOID**, VOID* );
  246. DWORD ChapEnd( VOID* );
  247. DWORD ChapMakeMessage( VOID*, PPP_CONFIG*, PPP_CONFIG*, DWORD, PPPAP_RESULT*,
  248. PPPAP_INPUT* );
  249. DWORD GetChallengeFromChallenge( CHAPWB*, PPP_CONFIG* );
  250. DWORD MakeChangePw1Message( CHAPWB*, PPP_CONFIG*, DWORD );
  251. DWORD MakeChangePw2Message( CHAPWB*, PPP_CONFIG*, DWORD );
  252. DWORD MakeChangePw3Message( CHAPWB*, PPP_CONFIG*, DWORD, BOOL );
  253. DWORD GetCredentialsFromResponse( PPP_CONFIG*, BYTE, CHAR*, BYTE* );
  254. DWORD GetInfoFromChangePw1( PPP_CONFIG*, CHANGEPW1* );
  255. DWORD GetInfoFromChangePw2( PPP_CONFIG*, CHANGEPW2*, BYTE* );
  256. DWORD GetInfoFromChangePw3( PPP_CONFIG*, CHANGEPW3*, BYTE* );
  257. VOID GetInfoFromFailure( CHAPWB*, PPP_CONFIG*, DWORD*, BOOL*, DWORD* );
  258. BYTE HexCharValue( CHAR );
  259. DWORD MakeChallengeMessage( CHAPWB*, PPP_CONFIG*, DWORD );
  260. DWORD MakeResponseMessage( CHAPWB*, PPP_CONFIG*, DWORD, BOOL );
  261. VOID ChapMakeResultMessage( CHAPWB*, DWORD, BOOL, PPP_CONFIG*, DWORD );
  262. DWORD StoreCredentials( CHAPWB*, PPPAP_INPUT* );
  263. DWORD
  264. ChapChangeNotification(
  265. VOID
  266. );
  267. DWORD
  268. GetChallenge(
  269. OUT PBYTE pChallenge
  270. );
  271. VOID
  272. EndLSA(
  273. VOID
  274. );
  275. DWORD
  276. InitLSA(
  277. VOID
  278. );
  279. DWORD
  280. MakeChangePasswordV1RequestAttributes(
  281. IN CHAPWB* pwb,
  282. IN BYTE bId,
  283. IN PCHAR pchIdentity,
  284. IN PBYTE Challenge,
  285. IN PENCRYPTED_LM_OWF_PASSWORD pEncryptedLmOwfOldPassword,
  286. IN PENCRYPTED_LM_OWF_PASSWORD pEncryptedLmOwfNewPassword,
  287. IN PENCRYPTED_NT_OWF_PASSWORD pEncryptedNtOwfOldPassword,
  288. IN PENCRYPTED_NT_OWF_PASSWORD pEncryptedNtOwfNewPassword,
  289. IN WORD LenPassword,
  290. IN WORD wFlags,
  291. IN DWORD cbChallenge,
  292. IN BYTE * pbChallenge
  293. );
  294. DWORD
  295. MakeChangePasswordV2RequestAttributes(
  296. IN CHAPWB* pwb,
  297. IN BYTE bId,
  298. IN CHAR* pchIdentity,
  299. IN SAMPR_ENCRYPTED_USER_PASSWORD* pNewEncryptedWithOldNtOwf,
  300. IN ENCRYPTED_NT_OWF_PASSWORD* pOldNtOwfEncryptedWithNewNtOwf,
  301. IN SAMPR_ENCRYPTED_USER_PASSWORD* pNewEncryptedWithOldLmOwf,
  302. IN ENCRYPTED_NT_OWF_PASSWORD* pOldLmOwfEncryptedWithNewNtOwf,
  303. IN DWORD cbChallenge,
  304. IN BYTE * pbChallenge,
  305. IN BYTE * pbResponse,
  306. IN WORD wFlags
  307. );
  308. DWORD
  309. MakeChangePasswordV3RequestAttributes(
  310. IN CHAPWB* pwb,
  311. IN BYTE bId,
  312. IN CHAR* pchIdentity,
  313. IN CHANGEPW3* pchangepw3,
  314. IN DWORD cbChallenge,
  315. IN BYTE * pbChallenge
  316. );
  317. DWORD
  318. GetEncryptedPasswordsForChangePassword2(
  319. IN CHAR* pszOldPassword,
  320. IN CHAR* pszNewPassword,
  321. OUT SAMPR_ENCRYPTED_USER_PASSWORD* pNewEncryptedWithOldNtOwf,
  322. OUT ENCRYPTED_NT_OWF_PASSWORD* pOldNtOwfEncryptedWithNewNtOwf,
  323. OUT SAMPR_ENCRYPTED_USER_PASSWORD* pNewEncryptedWithOldLmOwf,
  324. OUT ENCRYPTED_NT_OWF_PASSWORD* pOldLmOwfEncryptedWithNewNtOwf,
  325. OUT BOOLEAN* pfLmPresent
  326. );
  327. /* Globals.
  328. */
  329. #ifdef RASCHAPGLOBALS
  330. #define GLOBALS
  331. #define EXTERN
  332. #else
  333. #define EXTERN extern
  334. #endif
  335. EXTERN DWORD g_dwTraceIdChap
  336. #ifdef GLOBALS
  337. = INVALID_TRACEID;
  338. #endif
  339. ;
  340. EXTERN DWORD g_dwRefCount
  341. #ifdef GLOBALS
  342. = 0;
  343. #endif
  344. ;
  345. EXTERN HANDLE g_hLsa
  346. #ifdef GLOBALS
  347. = INVALID_HANDLE_VALUE;
  348. #endif
  349. ;
  350. EXTERN
  351. CHAR
  352. szComputerName[CNLEN+1];
  353. #undef EXTERN
  354. #undef GLOBALS
  355. #endif // _RASCHAP_H_