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.

290 lines
6.1 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. ntlmsspv2.h
  5. Abstract:
  6. NTLM v2 specific stuff
  7. Author:
  8. Larry Zhu (LZhu) 29-August-2001
  9. Environment:
  10. User mode only.
  11. Revision History:
  12. --*/
  13. #ifndef NTLMSSPV2_H
  14. #define NTLMSSPV2_H
  15. #ifndef __MACSSP__
  16. #ifdef BLDR_KERNEL_RUNTIME
  17. #include <bootdefs.h>
  18. #endif
  19. #include <security.h>
  20. #include <ntlmsspi.h>
  21. #include <crypt.h>
  22. #include <cred.h>
  23. #include <debug.h>
  24. #include <string.h>
  25. #include <memory.h>
  26. #include <rc4.h>
  27. #include <md5.h>
  28. #include <hmac.h>
  29. #include <winerror.h>
  30. #include <ntstatus.h>
  31. #else
  32. #include <winerror.h>
  33. #include <bootdefs.h>
  34. #include <ntlmsspi.h>
  35. #include <sspi.h>
  36. #include <crypt.h>
  37. #include <cred.h>
  38. #include <rc4.h>
  39. #include <md5.h>
  40. #include <hmac.h>
  41. #include <macunicode.h>
  42. #endif //__MACSSP__
  43. #include <stdlib.h>
  44. #include <string.h>
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif // __cplusplus
  48. VOID
  49. SspFreeUnicodeString(
  50. IN OUT UNICODE_STRING* pUnicodeString
  51. );
  52. VOID
  53. SspFreeStringEx(
  54. IN OUT STRING* pString
  55. );
  56. NTSTATUS
  57. SspInitUnicodeStringNoAlloc(
  58. IN PCSTR pszSource,
  59. OUT UNICODE_STRING* pDestination
  60. );
  61. NTSTATUS
  62. SspUpcaseUnicodeStringToOemString(
  63. IN UNICODE_STRING* pUnicodeString,
  64. OUT STRING* pOemString
  65. );
  66. VOID
  67. SspCopyStringAsString32(
  68. IN VOID* pMessageBuffer,
  69. IN STRING* pInString,
  70. IN OUT UCHAR** ppWhere,
  71. OUT STRING32* pOutString32
  72. );
  73. NTSTATUS
  74. SspGetSystemTimeAsFileTime(
  75. OUT FILETIME* pSystemTimeAsFileTime
  76. );
  77. NTSTATUS
  78. SspGenerateChallenge(
  79. UCHAR ChallengeFromClient[MSV1_0_CHALLENGE_LENGTH]
  80. );
  81. NTSTATUS
  82. SspConvertRelativeToAbsolute(
  83. IN VOID* pMessageBase,
  84. IN ULONG cbMessageSize,
  85. IN STRING32* pStringToRelocate,
  86. IN BOOLEAN AlignToWchar,
  87. IN BOOLEAN AllowNullString,
  88. OUT STRING* pOutputString
  89. );
  90. VOID
  91. SspUpcaseUnicodeString(
  92. IN OUT UNICODE_STRING* pUnicodeString
  93. );
  94. NTSTATUS
  95. SspLm20GetNtlmv2ChallengeResponse(
  96. IN NT_OWF_PASSWORD* pNtOwfPassword,
  97. IN UNICODE_STRING* pUserName,
  98. IN UNICODE_STRING* pLogonDomainName,
  99. IN UNICODE_STRING* pTargetInfo,
  100. IN UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH],
  101. OUT MSV1_0_NTLMV2_RESPONSE* pNtlmv2Response,
  102. OUT MSV1_0_LMV2_RESPONSE* pLmv2Response,
  103. OUT USER_SESSION_KEY* UserSessionKey,
  104. OUT LM_SESSION_KEY* LmSessionKey
  105. );
  106. VOID
  107. SspGetNtlmv2Response(
  108. IN NT_OWF_PASSWORD* pNtOwfPassword,
  109. IN UNICODE_STRING* pUserName,
  110. IN UNICODE_STRING* pLogonDomainName,
  111. IN ULONG ServerNameLength,
  112. IN UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH],
  113. IN OUT MSV1_0_NTLMV2_RESPONSE* pNtlmv2Response,
  114. OUT USER_SESSION_KEY* pUserSessionKey,
  115. OUT LM_SESSION_KEY* pLmSessionKey
  116. );
  117. // calculate Ntlmv2 OWF from credentials
  118. VOID
  119. SspCalculateNtlmv2Owf(
  120. IN NT_OWF_PASSWORD* pNtOwfPassword,
  121. IN UNICODE_STRING* pUserName,
  122. IN UNICODE_STRING* pLogonDomainName,
  123. OUT UCHAR Ntlmv2Owf[MSV1_0_NTLMV2_OWF_LENGTH]
  124. );
  125. // calculate LMV2 response from credentials
  126. VOID
  127. SspGetLmv2Response(
  128. IN NT_OWF_PASSWORD* pNtOwfPassword,
  129. IN UNICODE_STRING* pUserName,
  130. IN UNICODE_STRING* pLogonDomainName,
  131. IN UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH],
  132. IN UCHAR ChallengeFromClient[MSV1_0_CHALLENGE_LENGTH],
  133. OUT UCHAR Response[MSV1_0_NTLMV2_RESPONSE_LENGTH]
  134. );
  135. NTSTATUS
  136. SspMakeSessionKeys(
  137. IN ULONG NegotiateFlags,
  138. IN STRING* pLmChallengeResponse,
  139. IN USER_SESSION_KEY* pNtUserSessionKey, // from the DC or GetChalResp
  140. IN LM_SESSION_KEY* pLanmanSessionKey, // from the DC of GetChalResp
  141. IN STRING* pDatagramSessionKey,
  142. OUT USER_SESSION_KEY* pContextSessionKey
  143. );
  144. NTSTATUS
  145. SspSignSealHelper(
  146. IN NTLMV2_DERIVED_SKEYS* pNtlmv2Keys,
  147. IN ULONG NegotiateFlags,
  148. IN eSignSealOp Op,
  149. IN ULONG MessageSeqNo,
  150. IN OUT SecBufferDesc* pMessage,
  151. OUT NTLMSSP_MESSAGE_SIGNATURE* pSig,
  152. OUT NTLMSSP_MESSAGE_SIGNATURE** ppSig
  153. );
  154. SECURITY_STATUS
  155. SspNtStatusToSecStatus(
  156. IN NTSTATUS NtStatus,
  157. IN SECURITY_STATUS DefaultStatus
  158. );
  159. NTSTATUS
  160. SsprHandleNtlmv2ChallengeMessage(
  161. IN SSP_CREDENTIAL* pCredential,
  162. IN ULONG cbChallengeMessage,
  163. IN CHALLENGE_MESSAGE* pChallengeMessage,
  164. IN OUT ULONG* pNegotiateFlags,
  165. IN OUT ULONG* pcbAuthenticateMessage,
  166. OUT AUTHENTICATE_MESSAGE* pAuthenticateMessage,
  167. OUT USER_SESSION_KEY* pUserSessionKey
  168. );
  169. VOID
  170. SspMakeNtlmv2SKeys(
  171. IN USER_SESSION_KEY* pUserSessionKey,
  172. IN ULONG NegotiateFlags,
  173. IN ULONG SendNonce,
  174. IN ULONG RecvNonce,
  175. OUT NTLMV2_DERIVED_SKEYS* pNtlmv2Keys
  176. );
  177. SECURITY_STATUS
  178. SspNtlmv2MakeSignature(
  179. IN NTLMV2_DERIVED_SKEYS* pNtlmv2Keys,
  180. IN ULONG NegotiateFlags,
  181. IN ULONG fQOP,
  182. IN ULONG MessageSeqNo,
  183. IN OUT SecBufferDesc* pMessage
  184. );
  185. SECURITY_STATUS
  186. SspNtlmv2VerifySignature(
  187. IN NTLMV2_DERIVED_SKEYS* pNtlmv2Keys,
  188. IN ULONG NegotiateFlags,
  189. IN ULONG MessageSeqNo,
  190. IN OUT SecBufferDesc* pMessage,
  191. OUT ULONG* pfQOP
  192. );
  193. SECURITY_STATUS
  194. SspNtlmv2SealMessage(
  195. IN NTLMV2_DERIVED_SKEYS* pNtlmv2Keys,
  196. IN ULONG NegotiateFlags,
  197. IN ULONG fQOP,
  198. IN ULONG MessageSeqNo,
  199. IN OUT SecBufferDesc* pMessage
  200. );
  201. SECURITY_STATUS
  202. SspNtlmv2UnsealMessage(
  203. IN NTLMV2_DERIVED_SKEYS* pNtlmv2Keys,
  204. IN ULONG NegotiateFlags,
  205. IN ULONG MessageSeqNo,
  206. IN OUT SecBufferDesc* pMessage,
  207. OUT ULONG* pfQOP
  208. );
  209. NTSTATUS
  210. BlGetSystemTimeAsFileTime(
  211. OUT FILETIME* pSystemTimeAsFileTime
  212. );
  213. #ifdef MAC
  214. #define NUM_100ns_PER_SECOND 10000000L
  215. #define WINDOWS_MAC_TIME_DIFFERENCE_IN_SECONDS (159360480*60) //9561628800 seconds
  216. VOID
  217. SspSwapUnicodeString(
  218. IN OUT UNICODE_STRING* pString
  219. );
  220. VOID
  221. SspSwapString32Bytes(
  222. IN STRING32* pString
  223. );
  224. VOID
  225. SspSwapChallengeMessageBytes(
  226. IN CHALLENGE_MESSAGE* pChallengeMessage
  227. );
  228. VOID
  229. SspSwapAuthenticateMessageBytes(
  230. IN AUTHENTICATE_MESSAGE* pAuthenticateMessage
  231. );
  232. LONG
  233. SspMacSecondsFromGMT(void);
  234. #endif //MAC
  235. #ifdef __cplusplus
  236. }
  237. #endif // __cplusplus
  238. #endif // NTLMSSPV2_H