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.

473 lines
14 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 1992 - 1996
  6. //
  7. // File: digestsspi.h
  8. //
  9. // Contents: credential and context structures
  10. //
  11. //
  12. // History: KDamour 15Mar00 Stolen from msv_sspi\ntlmsspi.h
  13. //
  14. //------------------------------------------------------------------------
  15. #ifndef NTDIGEST_DIGESTSSPI_H
  16. #define NTDIGEST_DIGESTSSPI_H
  17. #include <time.h>
  18. #include <wincrypt.h>
  19. #include "auth.h"
  20. ////////////////////////////////////////////////////////////////////////
  21. //
  22. // Global Definitions
  23. //
  24. ////////////////////////////////////////////////////////////////////////
  25. //
  26. // Description of a logon session - stores the username, domain, password.
  27. // Notation used for LogonSession is LogSess
  28. //
  29. typedef struct _DIGEST_LOGONSESSION {
  30. // Global list of all LogonSessions.
  31. // (Serialized by SspLogonSessionCritSect)
  32. LIST_ENTRY Next;
  33. // This is the Handle for this LogonSession - same as its memory address - no need to ref count
  34. ULONG_PTR LogonSessionHandle;
  35. // Ref Counter Used to prevent this LogonSession from being deleted prematurely.
  36. // Two cases for initial value
  37. // AcceptCredential sets to one and enters it into active logon list. Call to ApLogonTerminate
  38. // decrements count and removes it from list.
  39. // In both cases, a refcount of zero causes the logonsession to be deleted from memory
  40. LONG lReferences;
  41. // Logon ID of the client
  42. LUID LogonId;
  43. // Default credentials on client context, on server context UserName
  44. // Gathered from calls to SpAcceptCredentials
  45. SECURITY_LOGON_TYPE LogonType;
  46. UNICODE_STRING ustrAccountName;
  47. UNICODE_STRING ustrDomainName; // Netbios domain name where account is located
  48. // IMPORTANT NOTE - you must use CredHandlerPasswdSet and CredHandlerPasswdGet once the
  49. // credential is placed into the list. The main reason for this is that multiple threads
  50. // will be utilizing the same memory and this value can change as updates come in from
  51. // SpAcceptCredential
  52. // It is encrypted with LsaFunctions->LsaProtectMemory( Password->Buffer, (ULONG)Password->Length );
  53. // Need to decrypt with LsaFunctions->LsaUnprotectMemory( HiddenPassword->Buffer, (ULONG)HiddenPassword->Length );
  54. // Stores the current plaintext password (if available) with reversible encryption
  55. UNICODE_STRING ustrPassword;
  56. UNICODE_STRING ustrDnsDomainName; // DNS domain name where account is located (if known)
  57. UNICODE_STRING ustrUpn; // UPN of account (if known)
  58. } DIGEST_LOGONSESSION, *PDIGEST_LOGONSESSION;
  59. //
  60. // Description of a credential.
  61. // We use this for a combined list of logon sessions and credentials
  62. //
  63. typedef struct _DIGEST_CREDENTIAL {
  64. //
  65. // Global list of all Credentials.
  66. // (Serialized by SspCredentialCritSect)
  67. //
  68. LIST_ENTRY Next;
  69. //
  70. // Used to prevent this Credential from being deleted prematurely.
  71. //
  72. LONG lReferences;
  73. //
  74. // Flag to indicate that Credential is not attached to CredentialList
  75. // once References is 0 and Unlinked is True - this record can be removed from list
  76. BOOL Unlinked;
  77. //
  78. // This is the Handle for this credential - same as its memory address
  79. //
  80. ULONG_PTR CredentialHandle;
  81. //
  82. // Flag of how credential may be used.
  83. //
  84. // SECPKG_CRED_* flags
  85. //
  86. ULONG CredentialUseFlags;
  87. //
  88. // Default credentials on client context, on server context UserName
  89. // Gathered from calls to SpAcceptCredentials
  90. //
  91. SECURITY_LOGON_TYPE LogonType;
  92. UNICODE_STRING ustrAccountName;
  93. LUID LogonId; // Logon ID of the client
  94. UNICODE_STRING ustrDomainName; // Netbios domain name where account is located
  95. // Stores the current plaintext (if available) version of the logon users account
  96. // IMPORTANT NOTE - you must use CredHandlerPasswdSet and CredHandlerPasswdGet once the
  97. // credential is placed into the list. The main reason for this is that multiple threads
  98. // will be utilizing the same memory and this value can change as updates come in from
  99. // SpAcceptCredential
  100. // Password will be encryped with LSAFunction as in LogonSession
  101. UNICODE_STRING ustrPassword;
  102. UNICODE_STRING ustrDomain; // NetBios or DNS domain name where account is located will be used in realm directive
  103. UNICODE_STRING ustrUpn; // UPN of account (if known)
  104. //
  105. // Process Id of client
  106. //
  107. ULONG ClientProcessID;
  108. } DIGEST_CREDENTIAL, *PDIGEST_CREDENTIAL;
  109. //
  110. // Description of a Context
  111. //
  112. typedef struct _DIGEST_CONTEXT {
  113. // Global list of all Contexts
  114. // (Serialized by SspContextCritSect)
  115. LIST_ENTRY Next;
  116. // This is the Handle for this context - same as its memory address
  117. ULONG_PTR ContextHandle;
  118. // Used to prevent this Context from being deleted prematurely.
  119. // (Serialized by SspContextCritSect)
  120. LONG lReferences;
  121. // Flag to indicate that Context is not attached to List
  122. BOOL bUnlinked;
  123. // Maintain the context requirements
  124. ULONG ContextReq;
  125. // Flags for context
  126. // FLAG_CONTEXT_AUTHZID_PROVIDED
  127. ULONG ulFlags;
  128. // Digest Parameters for this context
  129. DIGEST_TYPE typeDigest;
  130. // Digest Parameters for this context
  131. QOP_TYPE typeQOP;
  132. // Digest Parameters for this context
  133. ALGORITHM_TYPE typeAlgorithm;
  134. // Cipher to use for encrypt/decrypt
  135. CIPHER_TYPE typeCipher;
  136. // Charset used for digest directive values
  137. CHARSET_TYPE typeCharset;
  138. // Server generated Nonce for Context
  139. STRING strNonce;
  140. // Client generated CNonce for Context
  141. STRING strCNonce;
  142. // Nonce count for replay prevention
  143. ULONG ulNC;
  144. // Maximum size for the buffers to send and receive data for auth-int and auth-conf (SASL mode)
  145. ULONG ulSendMaxBuf;
  146. ULONG ulRecvMaxBuf;
  147. // Unique Reference for this Context BinHex(rand[128])
  148. // Utilize the First N chars of this as the CNONCE for InitializeSecurityContect
  149. STRING strOpaque;
  150. // BinHex(H(A1)) sent from DC and stored in context for future
  151. // auth without going to the DC
  152. STRING strSessionKey;
  153. // Client only - calculated response auth to be returned from server
  154. STRING strResponseAuth;
  155. // Copy of directive values from auth - used for rspauth support
  156. STRING strDirective[MD5_AUTH_LAST];
  157. // Only valid after ASC has successfully authenticated and converted AuthData to Token
  158. // Token Handle of authenticated user
  159. HANDLE TokenHandle;
  160. // LogonID used in the Token
  161. LUID LoginID;
  162. //
  163. // Information from Credentials
  164. //
  165. //
  166. // Maintain a copy of the credential UseFlags (we can tell if inbound or outbound)
  167. //
  168. ULONG CredentialUseFlags;
  169. // Copy of the account info
  170. UNICODE_STRING ustrDomain;
  171. UNICODE_STRING ustrPassword; // Encrypted
  172. UNICODE_STRING ustrAccountName;
  173. // Set time when Context is to Expire
  174. TimeStamp ExpirationTime;
  175. } DIGEST_CONTEXT, *PDIGEST_CONTEXT;
  176. // This structure contains the state info for the User mode
  177. // security context. It is passwd between the LSAMode and the UserMode address spaces
  178. // In UserMode, this is unpacked into the DIGEST_USERCONTEXT struct
  179. typedef struct _DIGEST_PACKED_USERCONTEXT{
  180. ULONG ulFlags; // Flags to control processing of packed UserContext
  181. //
  182. // Timeout the context after awhile.
  183. //
  184. TimeStamp ExpirationTime; // Time inwhich session key expires
  185. //
  186. // Maintain the context requirements
  187. //
  188. ULONG ContextReq;
  189. //
  190. // Maintain a copy of the credential UseFlags (we can tell if inbound or outbound)
  191. //
  192. ULONG CredentialUseFlags;
  193. //
  194. // Digest Parameters for this context
  195. //
  196. ULONG typeDigest;
  197. //
  198. // Digest Parameters for this context
  199. //
  200. ULONG typeQOP;
  201. //
  202. // Digest Parameters for this context
  203. //
  204. ULONG typeAlgorithm;
  205. //
  206. // Cipher to use for encrypt/decrypt
  207. //
  208. ULONG typeCipher;
  209. //
  210. // Charset used for digest directive values
  211. //
  212. ULONG typeCharset;
  213. //
  214. // Max-size of message buffer to allow for auth-int & auth-conf processing
  215. // This is the combined size of (HEADER + Data + Trailer)
  216. // in SASL Header is zero length, max Trailer size if padding+HMAC
  217. //
  218. ULONG ulSendMaxBuf;
  219. ULONG ulRecvMaxBuf;
  220. //
  221. // Token Handle of authenticated user
  222. // Only valid when in AuthenticatedState.
  223. // Filled in only by AcceptSecurityContext
  224. // It will be NULL is struct is from InitializeSecurityContext
  225. // Must cast this to a HANDLE once back into the usermode context
  226. //
  227. ULONG ClientTokenHandle;
  228. // Size of each component set over
  229. ULONG uSessionKeyLen;
  230. ULONG uAccountNameLen;
  231. ULONG uDigestLen[MD5_AUTH_LAST];
  232. // All directive data will be passed as single byte charaters
  233. // Order is the same as in auth.h (MD5_AUTH_NAME)
  234. // username, realm, nonce, cnonce ... then sessionkey
  235. UCHAR ucData;
  236. } DIGEST_PACKED_USERCONTEXT, * PDIGEST_PACKED_USERCONTEXT;
  237. // This structure contains the state info for the User mode
  238. // security context.
  239. typedef struct _DIGEST_USERCONTEXT{
  240. //
  241. // Global list of all Contexts
  242. // (Serialized by UserContextCritSect)
  243. //
  244. LIST_ENTRY Next;
  245. //
  246. // Handle to the LsaContext
  247. // This will have the handle to the context in LSAMode Address space
  248. //
  249. ULONG_PTR LsaContext;
  250. //
  251. // Timeout the context after awhile.
  252. //
  253. TimeStamp ExpirationTime; // Time inwhich session key expires
  254. //
  255. // Used to prevent this Context from being deleted prematurely.
  256. // This is used ONLY for internal SSP pointer references. For application handles
  257. // lReferenceHandles is used. This was necessary to do to keep the count separate for
  258. // internal pointer references and handles that are passed to the application. This will
  259. // prevent the application from calling DeleteSecurityContext() too many times and accidently
  260. // dereferencing an internal pointer.
  261. //
  262. LONG lReferences; // ref count on SSP pointers issued
  263. LONG lReferenceHandles; // ref count on application securityContext handles issued
  264. //
  265. // Flag to indicate that Context is not attached to List - skip when scanning list
  266. //
  267. BOOL bUnlinked;
  268. //
  269. // Digest Parameters for this context
  270. //
  271. DIGEST_TYPE typeDigest;
  272. //
  273. // QOP selected for this context
  274. //
  275. QOP_TYPE typeQOP;
  276. //
  277. // Digest Parameters for this context
  278. //
  279. ALGORITHM_TYPE typeAlgorithm;
  280. //
  281. // Cipher to use for encrypt/decrypt
  282. //
  283. CIPHER_TYPE typeCipher;
  284. //
  285. // Charset used for digest directive values
  286. //
  287. CHARSET_TYPE typeCharset;
  288. //
  289. // Token Handle of authenticated user
  290. // Only valid when in AuthenticatedState.
  291. // Filled in only by AcceptSecurityContext - so we are the server
  292. // Mapped to UserMode Client space from LSA TokenHandle
  293. // It will be NULL is struct is from InitializeSecurityContext - so we are client
  294. //
  295. HANDLE ClientTokenHandle;
  296. //
  297. // Maintain the context requirements
  298. //
  299. ULONG ContextReq;
  300. //
  301. // Maintain a copy of the credential UseFlags (we can tell if inbound or outbound)
  302. //
  303. ULONG CredentialUseFlags;
  304. // Flags
  305. // FLAG_CONTEXT_AUTHZID_PROVIDED
  306. ULONG ulFlags;
  307. // Nonce Count
  308. ULONG ulNC;
  309. // Maxbuffer for auth-int and auth-conf processing
  310. ULONG ulSendMaxBuf;
  311. ULONG ulRecvMaxBuf;
  312. // SASL sequence numbering
  313. DWORD dwSendSeqNum; // Makesignature/verifysignature server to client sequence number
  314. DWORD dwRecvSeqNum; // Makesignature/verifysignature server to client sequence number
  315. // SASL Sign and Seal Keys. Save calculated values on sequence number = 0
  316. BYTE bKcSealHashData[MD5_HASH_BYTESIZE];
  317. BYTE bKiSignHashData[MD5_HASH_BYTESIZE];
  318. BYTE bKcUnsealHashData[MD5_HASH_BYTESIZE];
  319. BYTE bKiVerifyHashData[MD5_HASH_BYTESIZE];
  320. BYTE bSealKey[MD5_HASH_BYTESIZE];
  321. BYTE bUnsealKey[MD5_HASH_BYTESIZE];
  322. HCRYPTKEY hSealCryptKey; // Handle to Cryptkey based on Byte keys
  323. HCRYPTKEY hUnsealCryptKey;
  324. //
  325. // Hex(H(A1)) sent from DC and stored in context for future
  326. // auth without going to the DC. Binary version is derived from HEX(H(A1))
  327. // and is used in SASL mode for integrity protection and encryption
  328. //
  329. STRING strSessionKey;
  330. BYTE bSessionKey[MD5_HASH_BYTESIZE];
  331. // Account name used in token creation for securityContext session
  332. UNICODE_STRING ustrAccountName;
  333. //
  334. // Values utilized in the Initial Digest Auth ChallResponse
  335. //
  336. STRING strParam[MD5_AUTH_LAST]; // points to owned memory - will need to free up!
  337. } DIGEST_USERCONTEXT, * PDIGEST_USERCONTEXT;
  338. #endif // ifndef NTDIGEST_DIGESTSSPI_H