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.

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