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.

436 lines
11 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows NT Security
  4. // Copyright (C) Microsoft Corporation, 1997 - 1999
  5. //
  6. // File: tvo.h
  7. //
  8. // Contents: Get Time Valid Object Definitions and Prototypes
  9. //
  10. // History: 25-Sep-97 kirtd Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #if !defined(__TVO_H__)
  14. #define __TVO_H__
  15. #include <origin.h>
  16. #include <lrucache.h>
  17. #include <offurl.h>
  18. //
  19. // CryptGetTimeValidObject provider prototypes
  20. //
  21. typedef BOOL (WINAPI *PFN_GET_TIME_VALID_OBJECT_FUNC) (
  22. IN LPCSTR pszTimeValidOid,
  23. IN LPVOID pvPara,
  24. IN PCCERT_CONTEXT pIssuer,
  25. IN LPFILETIME pftValidFor,
  26. IN DWORD dwFlags,
  27. IN DWORD dwTimeout,
  28. OUT OPTIONAL LPVOID* ppvObject,
  29. IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  30. IN OPTIONAL LPVOID pvReserved
  31. );
  32. BOOL WINAPI
  33. CtlGetTimeValidObject (
  34. IN LPCSTR pszTimeValidOid,
  35. IN LPVOID pvPara,
  36. IN PCCERT_CONTEXT pIssuer,
  37. IN LPFILETIME pftValidFor,
  38. IN DWORD dwFlags,
  39. IN DWORD dwTimeout,
  40. OUT OPTIONAL LPVOID* ppvObject,
  41. IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  42. IN OPTIONAL LPVOID pvReserved
  43. );
  44. BOOL WINAPI
  45. CrlGetTimeValidObject (
  46. IN LPCSTR pszTimeValidOid,
  47. IN LPVOID pvPara,
  48. IN PCCERT_CONTEXT pIssuer,
  49. IN LPFILETIME pftValidFor,
  50. IN DWORD dwFlags,
  51. IN DWORD dwTimeout,
  52. OUT OPTIONAL LPVOID* ppvObject,
  53. IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  54. IN OPTIONAL LPVOID pvReserved
  55. );
  56. BOOL WINAPI
  57. CrlFromCertGetTimeValidObject (
  58. IN LPCSTR pszTimeValidOid,
  59. IN LPVOID pvPara,
  60. IN PCCERT_CONTEXT pIssuer,
  61. IN LPFILETIME pftValidFor,
  62. IN DWORD dwFlags,
  63. IN DWORD dwTimeout,
  64. OUT OPTIONAL LPVOID* ppvObject,
  65. IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  66. IN OPTIONAL LPVOID pvReserved
  67. );
  68. BOOL WINAPI
  69. FreshestCrlFromCertGetTimeValidObject (
  70. IN LPCSTR pszTimeValidOid,
  71. IN LPVOID pvPara,
  72. IN PCCERT_CONTEXT pIssuer,
  73. IN LPFILETIME pftValidFor,
  74. IN DWORD dwFlags,
  75. IN DWORD dwTimeout,
  76. OUT OPTIONAL LPVOID* ppvObject,
  77. IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  78. IN OPTIONAL LPVOID pvReserved
  79. );
  80. BOOL WINAPI
  81. FreshestCrlFromCrlGetTimeValidObject (
  82. IN LPCSTR pszTimeValidOid,
  83. IN LPVOID pvPara,
  84. IN PCCERT_CONTEXT pIssuer,
  85. IN LPFILETIME pftValidFor,
  86. IN DWORD dwFlags,
  87. IN DWORD dwTimeout,
  88. OUT OPTIONAL LPVOID* ppvObject,
  89. IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  90. IN OPTIONAL LPVOID pvReserved
  91. );
  92. //
  93. // CryptFlushTimeValidObject provider prototypes
  94. //
  95. typedef BOOL (WINAPI *PFN_FLUSH_TIME_VALID_OBJECT_FUNC) (
  96. IN LPCSTR pszFlushTimeValidOid,
  97. IN LPVOID pvPara,
  98. IN PCCERT_CONTEXT pIssuer,
  99. IN DWORD dwFlags,
  100. IN LPVOID pvReserved
  101. );
  102. BOOL WINAPI
  103. CtlFlushTimeValidObject (
  104. IN LPCSTR pszFlushTimeValidOid,
  105. IN LPVOID pvPara,
  106. IN PCCERT_CONTEXT pIssuer,
  107. IN DWORD dwFlags,
  108. IN LPVOID pvReserved
  109. );
  110. BOOL WINAPI
  111. CrlFlushTimeValidObject (
  112. IN LPCSTR pszFlushTimeValidOid,
  113. IN LPVOID pvPara,
  114. IN PCCERT_CONTEXT pIssuer,
  115. IN DWORD dwFlags,
  116. IN LPVOID pvReserved
  117. );
  118. BOOL WINAPI
  119. CrlFromCertFlushTimeValidObject (
  120. IN LPCSTR pszFlushTimeValidOid,
  121. IN LPVOID pvPara,
  122. IN PCCERT_CONTEXT pIssuer,
  123. IN DWORD dwFlags,
  124. IN LPVOID pvReserved
  125. );
  126. BOOL WINAPI
  127. FreshestCrlFromCertFlushTimeValidObject (
  128. IN LPCSTR pszFlushTimeValidOid,
  129. IN LPVOID pvPara,
  130. IN PCCERT_CONTEXT pIssuer,
  131. IN DWORD dwFlags,
  132. IN LPVOID pvReserved
  133. );
  134. BOOL WINAPI
  135. FreshestCrlFromCrlFlushTimeValidObject (
  136. IN LPCSTR pszFlushTimeValidOid,
  137. IN LPVOID pvPara,
  138. IN PCCERT_CONTEXT pIssuer,
  139. IN DWORD dwFlags,
  140. IN LPVOID pvReserved
  141. );
  142. //
  143. // Provider table externs
  144. //
  145. extern HCRYPTOIDFUNCSET hGetTimeValidObjectFuncSet;
  146. extern HCRYPTOIDFUNCSET hFlushTimeValidObjectFuncSet;
  147. //
  148. // The TVO Cache. This is a cache of time valid objects by origin identifier
  149. // which is used to support the CryptGetTimeValidObject process. It is
  150. // used by a process wide TVO agent with each cache entry consisting of
  151. // the following information:
  152. //
  153. // Object Origin Identifier
  154. // Object Context Oid
  155. // Object Context
  156. // Object Retrieval URL
  157. // Object Expire Time
  158. // Object Offline URL Time Information
  159. //
  160. typedef struct _TVO_CACHE_ENTRY {
  161. CRYPT_ORIGIN_IDENTIFIER OriginIdentifier;
  162. LPCSTR pszContextOid;
  163. LPVOID pvContext;
  164. DWORD cbUrlArrayThis;
  165. PCRYPT_URL_ARRAY pUrlArrayThis;
  166. DWORD UrlIndexThis;
  167. DWORD cbUrlArrayNext;
  168. PCRYPT_URL_ARRAY pUrlArrayNext;
  169. DWORD UrlIndexNext;
  170. FILETIME CreateTime;
  171. FILETIME ExpireTime;
  172. HLRUENTRY hLruEntry;
  173. OFFLINE_URL_TIME_INFO OfflineUrlTimeInfo;
  174. } TVO_CACHE_ENTRY, *PTVO_CACHE_ENTRY;
  175. class CTVOCache
  176. {
  177. public:
  178. //
  179. // Construction
  180. //
  181. CTVOCache (
  182. DWORD cCacheBuckets,
  183. DWORD MaxCacheEntries,
  184. BOOL& rfResult
  185. );
  186. ~CTVOCache ();
  187. //
  188. // Direct cache entry manipulation
  189. //
  190. VOID InsertCacheEntry (PTVO_CACHE_ENTRY pEntry);
  191. VOID RemoveCacheEntry (PTVO_CACHE_ENTRY pEntry, BOOL fSuppressFree = FALSE);
  192. VOID TouchCacheEntry (PTVO_CACHE_ENTRY pEntry);
  193. //
  194. // Origin identifier based cache entry manipulation
  195. //
  196. // For CONTEXT_OID_CRL, pvSubject is the certificate that the CRL is
  197. // valid for. Skips CRL entries that aren't valid for the certificate.
  198. //
  199. PTVO_CACHE_ENTRY FindCacheEntry (
  200. CRYPT_ORIGIN_IDENTIFIER OriginIdentifier,
  201. LPCSTR pszContextOid,
  202. LPVOID pvSubject
  203. );
  204. //
  205. // Remove all cache entries
  206. //
  207. VOID RemoveAllCacheEntries ();
  208. //
  209. // Access to the cache handle
  210. //
  211. inline HLRUCACHE LruCacheHandle ();
  212. private:
  213. //
  214. // Cache handle
  215. //
  216. HLRUCACHE m_hCache;
  217. };
  218. DWORD WINAPI TVOCacheHashOriginIdentifier (PCRYPT_DATA_BLOB pIdentifier);
  219. VOID WINAPI TVOCacheOnRemoval (LPVOID pvData, LPVOID pvRemovalContext);
  220. //
  221. // The TVO Agent. This per process service takes care of the retrieval of
  222. // time valid CAPI2 objects. It allows this to be done on-demand or with
  223. // auto-update
  224. //
  225. class CTVOAgent
  226. {
  227. public:
  228. //
  229. // Construction
  230. //
  231. CTVOAgent (
  232. DWORD cCacheBuckets,
  233. DWORD MaxCacheEntries,
  234. BOOL& rfResult
  235. );
  236. ~CTVOAgent ();
  237. //
  238. // Get Time Valid Object methods
  239. //
  240. BOOL GetTimeValidObject (
  241. IN LPCSTR pszTimeValidOid,
  242. IN LPVOID pvPara,
  243. IN LPCSTR pszContextOid,
  244. IN PCCERT_CONTEXT pIssuer,
  245. IN LPFILETIME pftValidFor,
  246. IN DWORD dwFlags,
  247. IN DWORD dwTimeout,
  248. OUT OPTIONAL LPVOID* ppvObject,
  249. IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  250. IN OPTIONAL LPVOID pvReserved
  251. );
  252. BOOL GetTimeValidObjectByUrl (
  253. IN DWORD cbUrlArray,
  254. IN PCRYPT_URL_ARRAY pUrlArray,
  255. IN DWORD PreferredUrlIndex,
  256. IN LPCSTR pszContextOid,
  257. IN PCCERT_CONTEXT pIssuer,
  258. IN LPVOID pvSubject,
  259. IN CRYPT_ORIGIN_IDENTIFIER OriginIdentifier,
  260. IN LPFILETIME pftValidFor,
  261. IN DWORD dwFlags,
  262. IN DWORD dwTimeout,
  263. OUT OPTIONAL LPVOID* ppvObject,
  264. IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  265. IN OPTIONAL LPWSTR pwszUrlExtra,
  266. OUT BOOL* pfArrayOwned,
  267. IN OPTIONAL LPVOID pvReserved
  268. );
  269. BOOL FlushTimeValidObject (
  270. IN LPCSTR pszFlushTimeValidOid,
  271. IN LPVOID pvPara,
  272. IN LPCSTR pszFlushContextOid,
  273. IN PCCERT_CONTEXT pIssuer,
  274. IN DWORD dwFlags,
  275. IN LPVOID pvReserved
  276. );
  277. private:
  278. //
  279. // Object lock
  280. //
  281. CRITICAL_SECTION m_Lock;
  282. //
  283. // TVO cache
  284. //
  285. CTVOCache m_Cache;
  286. };
  287. //
  288. // Utility functions
  289. //
  290. BOOL WINAPI
  291. IsValidCreateOrExpireTime (
  292. IN BOOL fCheckFreshnessTime,
  293. IN LPFILETIME pftValidFor,
  294. IN LPFILETIME pftCreateTime,
  295. IN LPFILETIME pftExpireTime
  296. );
  297. BOOL WINAPI
  298. ObjectContextCreateTVOCacheEntry (
  299. IN HLRUCACHE hCache,
  300. IN LPCSTR pszContextOid,
  301. IN LPVOID pvContext,
  302. IN CRYPT_ORIGIN_IDENTIFIER OriginIdentifier,
  303. IN DWORD cbUrlArrayThis,
  304. IN PCRYPT_URL_ARRAY pUrlArrayThis,
  305. IN DWORD UrlIndexThis,
  306. IN PCCERT_CONTEXT pIssuer,
  307. OUT PTVO_CACHE_ENTRY* ppEntry
  308. );
  309. VOID WINAPI
  310. ObjectContextFreeTVOCacheEntry (
  311. IN PTVO_CACHE_ENTRY pEntry
  312. );
  313. BOOL WINAPI
  314. CertificateGetCrlDistPointUrl (
  315. IN LPCSTR pszUrlOid,
  316. IN LPVOID pvPara,
  317. IN LPWSTR pwszUrlHint,
  318. OUT PCRYPT_URL_ARRAY* ppUrlArray,
  319. OUT DWORD* pcbUrlArray,
  320. OUT DWORD* pPreferredUrlIndex,
  321. OUT BOOL* pfHintInArray
  322. );
  323. BOOL WINAPI
  324. RetrieveTimeValidObjectByUrl (
  325. IN LPWSTR pwszUrl,
  326. IN LPCSTR pszContextOid,
  327. IN LPFILETIME pftValidFor,
  328. IN DWORD dwFlags,
  329. IN DWORD dwTimeout,
  330. IN PCRYPT_CREDENTIALS pCredentials,
  331. IN PCCERT_CONTEXT pSigner,
  332. IN LPVOID pvSubject,
  333. IN CRYPT_ORIGIN_IDENTIFIER OriginIdentifier,
  334. OUT LPVOID* ppvObject,
  335. IN OPTIONAL LPVOID pvReserved
  336. );
  337. #define TVO_KEY_NAME "Software\\Microsoft\\Cryptography\\TVO"
  338. #define TVO_CACHE_BUCKETS_VALUE_NAME "DefaultProcessCacheBuckets"
  339. #define TVO_MAX_CACHE_ENTRIES_VALUE_NAME "DefaultProcessMaxCacheEntries"
  340. #define TVO_DEFAULT_CACHE_BUCKETS 32
  341. #define TVO_DEFAULT_MAX_CACHE_ENTRIES 128
  342. BOOL WINAPI
  343. CreateProcessTVOAgent (
  344. OUT CTVOAgent** ppAgent
  345. );
  346. //
  347. // Extern for process global agent
  348. //
  349. extern CTVOAgent* g_pProcessTVOAgent;
  350. //
  351. // Inline functions
  352. //
  353. //+---------------------------------------------------------------------------
  354. //
  355. // Member: CTVOCache::LruCacheHandle, public
  356. //
  357. // Synopsis: return the HLRUCACHE
  358. //
  359. //----------------------------------------------------------------------------
  360. inline HLRUCACHE
  361. CTVOCache::LruCacheHandle ()
  362. {
  363. return( m_hCache );
  364. }
  365. #endif