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.

251 lines
6.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: cache.h
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 09-23-97 jbanes Ported over SGC stuff from NT 4 tree.
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <sslcache.h>
  18. #define SP_CACHE_MAGIC 0xCACE
  19. #define SP_CACHE_FLAG_EMPTY 0x00000001
  20. #define SP_CACHE_FLAG_READONLY 0x00000002
  21. #define SP_CACHE_FLAG_MASTER_EPHEM 0x00000004
  22. #define SP_CACHE_FLAG_USE_VALIDATED 0x00000010 // Whether user has validated client credential.
  23. struct _SPContext;
  24. typedef struct _SessCacheItem {
  25. DWORD Magic;
  26. DWORD dwFlags;
  27. LONG cRef;
  28. DWORD ZombieJuju;
  29. DWORD fProtocol;
  30. DWORD CreationTime;
  31. DWORD Lifespan;
  32. DWORD DeferredJuju;
  33. // List of cache entries assigned to a particular cache index.
  34. LIST_ENTRY IndexEntryList;
  35. // Global list of cache entries sorted by creation time.
  36. LIST_ENTRY EntryList;
  37. // Process ID of process that owns this cache entry.
  38. ULONG ProcessID;
  39. HMAPPER * phMapper;
  40. // Handle to "Schannel" key container used to store the server's master
  41. // secret. This will either be the one corresponding to the server's
  42. // credentials or the 512-bit ephemeral key.
  43. HCRYPTPROV hMasterProv;
  44. // Master secret, from which all session keys are derived.
  45. HCRYPTKEY hMasterKey;
  46. ALG_ID aiCipher;
  47. DWORD dwStrength;
  48. ALG_ID aiHash;
  49. DWORD dwCipherSuiteIndex; // used for managing reconnects
  50. ExchSpec SessExchSpec;
  51. DWORD dwExchStrength;
  52. PCERT_CONTEXT pRemoteCert;
  53. PUBLICKEY * pRemotePublic;
  54. struct _SessCacheItem *pClonedItem;
  55. // Server Side Client Auth related items
  56. /* HLOCATOR */
  57. HLOCATOR hLocator;
  58. SECURITY_STATUS LocatorStatus;
  59. // Local credentials.
  60. PSPCredentialGroup pServerCred;
  61. PSPCredential pActiveServerCred;
  62. CRED_THUMBPRINT CredThumbprint; // credential group
  63. CRED_THUMBPRINT CertThumbprint; // local certificate
  64. // Cipher level (domestic, export, sgc, etc);
  65. DWORD dwCF;
  66. // Server certificate (pct only)
  67. DWORD cbServerCertificate;
  68. PBYTE pbServerCertificate;
  69. // cache ID (usually machine name or ip address)
  70. LPWSTR szCacheID;
  71. LUID LogonId;
  72. // Session ID for this session
  73. DWORD cbSessionID;
  74. UCHAR SessionID[SP_MAX_SESSION_ID];
  75. // Clear key (pct only)
  76. DWORD cbClearKey;
  77. UCHAR pClearKey[SP_MAX_MASTER_KEY];
  78. DWORD cbKeyArgs;
  79. UCHAR pKeyArgs[SP_MAX_KEY_ARGS];
  80. // This contains the client certificate that was sent to the server.
  81. PCCERT_CONTEXT pClientCert;
  82. // When a client credential is created automatically, the credential
  83. // information is stored here.
  84. PSPCredential pClientCred;
  85. DWORD cbAppData;
  86. PBYTE pbAppData;
  87. } SessCacheItem, *PSessCacheItem;
  88. typedef struct
  89. {
  90. PLIST_ENTRY SessionCache;
  91. DWORD dwClientLifespan;
  92. DWORD dwServerLifespan;
  93. DWORD dwCleanupInterval;
  94. DWORD dwCacheSize;
  95. DWORD dwMaximumEntries;
  96. DWORD dwUsedEntries;
  97. LIST_ENTRY EntryList;
  98. RTL_RESOURCE Lock;
  99. BOOL LockInitialized;
  100. } SCHANNEL_CACHE;
  101. extern SCHANNEL_CACHE SchannelCache;
  102. #define SP_CACHE_CLIENT_LIFESPAN (10 * 3600 * 1000) // 10 hours
  103. #define SP_CACHE_SERVER_LIFESPAN (10 * 3600 * 1000) // 10 hours
  104. #define SP_CACHE_CLEANUP_INTERVAL (5 * 60 * 1000) // 5 minutes
  105. #define SP_MAXIMUM_CACHE_ELEMENTS 10000
  106. #define SP_MASTER_KEY_CS_COUNT 50
  107. extern BOOL g_fMultipleProcessClientCache;
  108. extern BOOL g_fCacheInitialized;
  109. // Perf counter values.
  110. extern LONG g_cClientHandshakes;
  111. extern LONG g_cServerHandshakes;
  112. extern LONG g_cClientReconnects;
  113. extern LONG g_cServerReconnects;
  114. #define HasTimeElapsed(StartTime, CurrentTime, Interval) \
  115. (((CurrentTime) > (StartTime) && \
  116. (CurrentTime) - (StartTime) > (Interval)) || \
  117. ((CurrentTime) < (StartTime) && \
  118. (CurrentTime) + (MAXULONG - (StartTime)) >= (Interval)))
  119. /* SPInitSessionCache() */
  120. /* inits the internal cache to CacheSize items */
  121. SP_STATUS SPInitSessionCache(VOID);
  122. SP_STATUS
  123. SPShutdownSessionCache(VOID);
  124. // Reference and dereference cache items
  125. LONG SPCacheReference(PSessCacheItem pItem);
  126. LONG SPCacheDereference(PSessCacheItem pItem);
  127. void
  128. SPCachePurgeCredential(
  129. PSPCredentialGroup pCred);
  130. void
  131. SPCachePurgeProcessId(
  132. ULONG ProcessId);
  133. NTSTATUS
  134. SPCachePurgeEntries(
  135. LUID *LoginId,
  136. ULONG ProcessID,
  137. LPWSTR pwszTargetName,
  138. DWORD Flags);
  139. NTSTATUS
  140. SPCacheGetInfo(
  141. LUID * LogonId,
  142. LPWSTR pszTargetName,
  143. DWORD dwFlags,
  144. PSSL_SESSION_CACHE_INFO_RESPONSE pCacheInfo);
  145. NTSTATUS
  146. SPCacheGetPerfmonInfo(
  147. DWORD dwFlags,
  148. PSSL_PERFMON_INFO_RESPONSE pPerfmonInfo);
  149. /* Retrieve item from cache by SessionID.
  150. * Auto-Reference the item if successful */
  151. BOOL SPCacheRetrieveBySession(
  152. struct _SPContext * pContext,
  153. PBYTE pbSessionID,
  154. DWORD cbSessionID,
  155. PSessCacheItem *ppRetItem);
  156. /* Retrieve item from cache by ID.
  157. * Auto-Reference the item if successful */
  158. BOOL
  159. SPCacheRetrieveByName(
  160. LPWSTR pwszName,
  161. PSPCredentialGroup pCredGroup,
  162. PSessCacheItem *ppRetItem);
  163. /* find an empty cache item for use by a context */
  164. BOOL
  165. SPCacheRetrieveNew(
  166. BOOL fServer,
  167. LPWSTR pszTargetName,
  168. PSessCacheItem * ppRetItem);
  169. /* Locks a recently retrieved item into the cache */
  170. BOOL
  171. SPCacheAdd(
  172. struct _SPContext * pContext);
  173. void
  174. SPCacheAssignNewServerCredential(
  175. PSessCacheItem pItem,
  176. PSPCredentialGroup pCred);
  177. /* Helper for REDO sessions */
  178. BOOL
  179. SPCacheClone(PSessCacheItem *ppRetItem);
  180. NTSTATUS
  181. SetCacheAppData(
  182. PSessCacheItem pItem,
  183. PBYTE pbAppData,
  184. DWORD cbAppData);
  185. NTSTATUS
  186. GetCacheAppData(
  187. PSessCacheItem pItem,
  188. PBYTE *ppbAppData,
  189. DWORD *pcbAppData);