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.

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