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.

250 lines
6.6 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. // Whether 'hMasterProv' is an actual CSP or a static library.
  45. DWORD dwCapiFlags;
  46. // Master secret, from which all session keys are derived.
  47. HCRYPTKEY hMasterKey;
  48. ALG_ID aiCipher;
  49. DWORD dwStrength;
  50. ALG_ID aiHash;
  51. DWORD dwCipherSuiteIndex; // used for managing reconnects
  52. ExchSpec SessExchSpec;
  53. DWORD dwExchStrength;
  54. PCERT_CONTEXT pRemoteCert;
  55. PUBLICKEY * pRemotePublic;
  56. struct _SessCacheItem *pClonedItem;
  57. // Server Side Client Auth related items
  58. /* HLOCATOR */
  59. HLOCATOR hLocator;
  60. SECURITY_STATUS LocatorStatus;
  61. // Local credentials.
  62. PSPCredentialGroup pServerCred;
  63. PSPCredential pActiveServerCred;
  64. CRED_THUMBPRINT CredThumbprint; // credential group
  65. CRED_THUMBPRINT CertThumbprint; // local certificate
  66. // Cipher level (domestic, export, sgc, etc);
  67. DWORD dwCF;
  68. // Server certificate (pct only)
  69. DWORD cbServerCertificate;
  70. PBYTE pbServerCertificate;
  71. // cache ID (usually machine name or ip address)
  72. LPWSTR szCacheID;
  73. LUID LogonId;
  74. // Session ID for this session
  75. DWORD cbSessionID;
  76. UCHAR SessionID[SP_MAX_SESSION_ID];
  77. // Clear key (pct only)
  78. DWORD cbClearKey;
  79. UCHAR pClearKey[SP_MAX_MASTER_KEY];
  80. DWORD cbKeyArgs;
  81. UCHAR pKeyArgs[SP_MAX_KEY_ARGS];
  82. // This contains the client certificate that was sent to the server.
  83. PCCERT_CONTEXT pClientCert;
  84. // When a client credential is created automatically, the credential
  85. // information is stored here.
  86. PSPCredential pClientCred;
  87. DWORD cbAppData;
  88. PBYTE pbAppData;
  89. } SessCacheItem, *PSessCacheItem;
  90. typedef struct
  91. {
  92. PLIST_ENTRY SessionCache;
  93. DWORD dwClientLifespan;
  94. DWORD dwServerLifespan;
  95. DWORD dwCleanupInterval;
  96. DWORD dwCacheSize;
  97. DWORD dwMaximumEntries;
  98. DWORD dwUsedEntries;
  99. LIST_ENTRY EntryList;
  100. RTL_RESOURCE Lock;
  101. BOOL LockInitialized;
  102. } SCHANNEL_CACHE;
  103. extern SCHANNEL_CACHE SchannelCache;
  104. #define SP_CACHE_CLIENT_LIFESPAN (10 * 3600 * 1000) // 10 hours
  105. #define SP_CACHE_SERVER_LIFESPAN (10 * 3600 * 1000) // 10 hours
  106. #define SP_CACHE_CLEANUP_INTERVAL (5 * 60 * 1000) // 5 minutes
  107. #define SP_MAXIMUM_CACHE_ELEMENTS 10000
  108. #define SP_MASTER_KEY_CS_COUNT 50
  109. extern BOOL g_fMultipleProcessClientCache;
  110. extern BOOL g_fCacheInitialized;
  111. // Perf counter values.
  112. extern DWORD g_cClientHandshakes;
  113. extern DWORD g_cServerHandshakes;
  114. extern DWORD g_cClientReconnects;
  115. extern DWORD g_cServerReconnects;
  116. #define HasTimeElapsed(StartTime, CurrentTime, Interval) \
  117. (((CurrentTime) > (StartTime) && \
  118. (CurrentTime) - (StartTime) > (Interval)) || \
  119. ((CurrentTime) < (StartTime) && \
  120. (CurrentTime) + (MAXULONG - (StartTime)) >= (Interval)))
  121. /* SPInitSessionCache() */
  122. /* inits the internal cache to CacheSize items */
  123. SP_STATUS SPInitSessionCache(VOID);
  124. SP_STATUS
  125. SPShutdownSessionCache(VOID);
  126. // Reference and dereference cache items
  127. LONG SPCacheReference(PSessCacheItem pItem);
  128. LONG SPCacheDereference(PSessCacheItem pItem);
  129. void
  130. SPCachePurgeCredential(
  131. PSPCredentialGroup pCred);
  132. void
  133. SPCachePurgeProcessId(
  134. ULONG ProcessId);
  135. NTSTATUS
  136. SPCachePurgeEntries(
  137. LUID *LoginId,
  138. ULONG ProcessID,
  139. LPWSTR pwszTargetName,
  140. DWORD Flags);
  141. NTSTATUS
  142. SPCacheGetInfo(
  143. LUID * LogonId,
  144. LPWSTR pszTargetName,
  145. DWORD dwFlags,
  146. PSSL_SESSION_CACHE_INFO_RESPONSE pCacheInfo);
  147. NTSTATUS
  148. SPCacheGetPerfmonInfo(
  149. DWORD dwFlags,
  150. PSSL_PERFMON_INFO_RESPONSE pPerfmonInfo);
  151. /* Retrieve item from cache by SessionID.
  152. * Auto-Reference the item if successful */
  153. BOOL SPCacheRetrieveBySession(
  154. struct _SPContext * pContext,
  155. PBYTE pbSessionID,
  156. DWORD cbSessionID,
  157. PSessCacheItem *ppRetItem);
  158. /* Retrieve item from cache by ID.
  159. * Auto-Reference the item if successful */
  160. BOOL
  161. SPCacheRetrieveByName(
  162. LPWSTR pwszName,
  163. PSPCredentialGroup pCredGroup,
  164. PSessCacheItem *ppRetItem);
  165. /* find an empty cache item for use by a context */
  166. BOOL
  167. SPCacheRetrieveNew(
  168. BOOL fServer,
  169. LPWSTR pszTargetName,
  170. PSessCacheItem * ppRetItem);
  171. /* Locks a recently retrieved item into the cache */
  172. BOOL
  173. SPCacheAdd(
  174. struct _SPContext * pContext);
  175. /* Helper for REDO sessions */
  176. BOOL
  177. SPCacheClone(PSessCacheItem *ppRetItem);
  178. NTSTATUS
  179. SetCacheAppData(
  180. PSessCacheItem pItem,
  181. PBYTE pbAppData,
  182. DWORD cbAppData);
  183. NTSTATUS
  184. GetCacheAppData(
  185. PSessCacheItem pItem,
  186. PBYTE *ppbAppData,
  187. DWORD *pcbAppData);