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.

420 lines
11 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. /* Prototypes.
  208. */
  209. DWORD
  210. ChapInit(
  211. IN BOOL fInitialize
  212. );
  213. DWORD ChapSMakeMessage( CHAPWB*, PPP_CONFIG*, PPP_CONFIG*, DWORD, PPPAP_RESULT*,
  214. PPPAP_INPUT* );
  215. DWORD
  216. MakeAuthenticationRequestAttributes(
  217. IN CHAPWB* pwb,
  218. IN BOOL fMSChap,
  219. IN BYTE bAlgorithm,
  220. IN CHAR* szUserName,
  221. IN BYTE* pbChallenge,
  222. IN DWORD cbChallenge,
  223. IN BYTE* pbResponse,
  224. IN DWORD cbResponse,
  225. IN BYTE bId
  226. );
  227. DWORD
  228. GetErrorCodeFromAttributes(
  229. IN CHAPWB* pwb
  230. );
  231. DWORD
  232. LoadChapHelperFunctions(
  233. VOID
  234. );
  235. DWORD ChapCMakeMessage( CHAPWB*, PPP_CONFIG*, PPP_CONFIG*, DWORD, PPPAP_RESULT*,
  236. PPPAP_INPUT* );
  237. DWORD ChapBegin( VOID**, VOID* );
  238. DWORD ChapEnd( VOID* );
  239. DWORD ChapMakeMessage( VOID*, PPP_CONFIG*, PPP_CONFIG*, DWORD, PPPAP_RESULT*,
  240. PPPAP_INPUT* );
  241. DWORD GetChallengeFromChallenge( CHAPWB*, PPP_CONFIG* );
  242. DWORD MakeChangePw1Message( CHAPWB*, PPP_CONFIG*, DWORD );
  243. DWORD MakeChangePw2Message( CHAPWB*, PPP_CONFIG*, DWORD );
  244. DWORD MakeChangePw3Message( CHAPWB*, PPP_CONFIG*, DWORD, BOOL );
  245. DWORD GetCredentialsFromResponse( PPP_CONFIG*, BYTE, CHAR*, BYTE* );
  246. DWORD GetInfoFromChangePw1( PPP_CONFIG*, CHANGEPW1* );
  247. DWORD GetInfoFromChangePw2( PPP_CONFIG*, CHANGEPW2*, BYTE* );
  248. DWORD GetInfoFromChangePw3( PPP_CONFIG*, CHANGEPW3*, BYTE* );
  249. VOID GetInfoFromFailure( CHAPWB*, PPP_CONFIG*, DWORD*, BOOL*, DWORD* );
  250. BYTE HexCharValue( CHAR );
  251. DWORD MakeChallengeMessage( CHAPWB*, PPP_CONFIG*, DWORD );
  252. DWORD MakeResponseMessage( CHAPWB*, PPP_CONFIG*, DWORD, BOOL );
  253. VOID ChapMakeResultMessage( CHAPWB*, DWORD, BOOL, PPP_CONFIG*, DWORD );
  254. DWORD StoreCredentials( CHAPWB*, PPPAP_INPUT* );
  255. DWORD
  256. ChapChangeNotification(
  257. VOID
  258. );
  259. DWORD
  260. GetChallenge(
  261. OUT PBYTE pChallenge
  262. );
  263. VOID
  264. EndLSA(
  265. VOID
  266. );
  267. DWORD
  268. InitLSA(
  269. VOID
  270. );
  271. DWORD
  272. MakeChangePasswordV1RequestAttributes(
  273. IN CHAPWB* pwb,
  274. IN BYTE bId,
  275. IN PCHAR pchIdentity,
  276. IN PBYTE Challenge,
  277. IN PENCRYPTED_LM_OWF_PASSWORD pEncryptedLmOwfOldPassword,
  278. IN PENCRYPTED_LM_OWF_PASSWORD pEncryptedLmOwfNewPassword,
  279. IN PENCRYPTED_NT_OWF_PASSWORD pEncryptedNtOwfOldPassword,
  280. IN PENCRYPTED_NT_OWF_PASSWORD pEncryptedNtOwfNewPassword,
  281. IN WORD LenPassword,
  282. IN WORD wFlags,
  283. IN DWORD cbChallenge,
  284. IN BYTE * pbChallenge
  285. );
  286. DWORD
  287. MakeChangePasswordV2RequestAttributes(
  288. IN CHAPWB* pwb,
  289. IN BYTE bId,
  290. IN CHAR* pchIdentity,
  291. IN SAMPR_ENCRYPTED_USER_PASSWORD* pNewEncryptedWithOldNtOwf,
  292. IN ENCRYPTED_NT_OWF_PASSWORD* pOldNtOwfEncryptedWithNewNtOwf,
  293. IN SAMPR_ENCRYPTED_USER_PASSWORD* pNewEncryptedWithOldLmOwf,
  294. IN ENCRYPTED_NT_OWF_PASSWORD* pOldLmOwfEncryptedWithNewNtOwf,
  295. IN DWORD cbChallenge,
  296. IN BYTE * pbChallenge,
  297. IN BYTE * pbResponse,
  298. IN WORD wFlags
  299. );
  300. DWORD
  301. MakeChangePasswordV3RequestAttributes(
  302. IN CHAPWB* pwb,
  303. IN BYTE bId,
  304. IN CHAR* pchIdentity,
  305. IN CHANGEPW3* pchangepw3,
  306. IN DWORD cbChallenge,
  307. IN BYTE * pbChallenge
  308. );
  309. DWORD
  310. GetEncryptedPasswordsForChangePassword2(
  311. IN CHAR* pszOldPassword,
  312. IN CHAR* pszNewPassword,
  313. OUT SAMPR_ENCRYPTED_USER_PASSWORD* pNewEncryptedWithOldNtOwf,
  314. OUT ENCRYPTED_NT_OWF_PASSWORD* pOldNtOwfEncryptedWithNewNtOwf,
  315. OUT SAMPR_ENCRYPTED_USER_PASSWORD* pNewEncryptedWithOldLmOwf,
  316. OUT ENCRYPTED_NT_OWF_PASSWORD* pOldLmOwfEncryptedWithNewNtOwf,
  317. OUT BOOLEAN* pfLmPresent
  318. );
  319. /* Globals.
  320. */
  321. #ifdef RASCHAPGLOBALS
  322. #define GLOBALS
  323. #define EXTERN
  324. #else
  325. #define EXTERN extern
  326. #endif
  327. EXTERN DWORD g_dwTraceIdChap
  328. #ifdef GLOBALS
  329. = INVALID_TRACEID;
  330. #endif
  331. ;
  332. EXTERN DWORD g_dwRefCount
  333. #ifdef GLOBALS
  334. = 0;
  335. #endif
  336. ;
  337. EXTERN HANDLE g_hLsa
  338. #ifdef GLOBALS
  339. = INVALID_HANDLE_VALUE;
  340. #endif
  341. ;
  342. EXTERN
  343. CHAR
  344. szComputerName[CNLEN+1];
  345. #undef EXTERN
  346. #undef GLOBALS
  347. #endif // _RASCHAP_H_