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.

3118 lines
80 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows NT Security
  4. // Copyright (C) Microsoft Corporation, 1997 - 1999
  5. //
  6. // File: chain.h
  7. //
  8. // Contents: Certificate Chaining Infrastructure
  9. //
  10. // History: 13-Jan-98 kirtd Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #if !defined(__CHAIN_H__)
  14. #define __CHAIN_H__
  15. #include <windows.h>
  16. #include <wincrypt.h>
  17. #include <winchain.h>
  18. #include <lrucache.h>
  19. #include <md5.h>
  20. // All internal chain hashes are MD5 (16 bytes)
  21. #define CHAINHASHLEN MD5DIGESTLEN
  22. //
  23. // Certificate and Path Object Forward class declarations
  24. //
  25. class CCertObject;
  26. class CCertIssuerList;
  27. class CCertObjectCache;
  28. class CCertChainEngine;
  29. class CChainPathObject;
  30. //
  31. // Certificate and Path Object Class pointer typedefs
  32. //
  33. typedef CCertObject* PCCERTOBJECT;
  34. typedef CCertIssuerList* PCCERTISSUERLIST;
  35. typedef CCertObjectCache* PCCERTOBJECTCACHE;
  36. typedef CCertChainEngine* PCCERTCHAINENGINE;
  37. typedef CChainPathObject* PCCHAINPATHOBJECT;
  38. //
  39. // SSCTL Forward class declarations
  40. //
  41. class CSSCtlObject;
  42. class CSSCtlObjectCache;
  43. //
  44. // SSCTL Class pointer typedefs
  45. //
  46. typedef class CSSCtlObject* PCSSCTLOBJECT;
  47. typedef class CSSCtlObjectCache* PCSSCTLOBJECTCACHE;
  48. //
  49. // Call Context Forward class declarations
  50. //
  51. class CChainCallContext;
  52. //
  53. // Call Context class pointer typedefs
  54. //
  55. typedef CChainCallContext* PCCHAINCALLCONTEXT;
  56. //
  57. // Certificate Object Identifier. This is a unique identifier for a certificate
  58. // object and is the MD5 hash of the issuer and serial no.
  59. //
  60. typedef BYTE CERT_OBJECT_IDENTIFIER[ CHAINHASHLEN ];
  61. //
  62. // CCertObject types
  63. //
  64. #define CERT_END_OBJECT_TYPE 1
  65. #define CERT_CACHED_END_OBJECT_TYPE 2
  66. #define CERT_CACHED_ISSUER_OBJECT_TYPE 3
  67. #define CERT_EXTERNAL_ISSUER_OBJECT_TYPE 4
  68. //
  69. // Issuer match types
  70. //
  71. #define CERT_EXACT_ISSUER_MATCH_TYPE 1
  72. #define CERT_KEYID_ISSUER_MATCH_TYPE 2
  73. #define CERT_NAME_ISSUER_MATCH_TYPE 3
  74. #define CERT_PUBKEY_ISSUER_MATCH_TYPE 4
  75. //
  76. // Issuer match flags
  77. //
  78. #define CERT_MATCH_TYPE_TO_FLAG(MatchType) (1 << (MatchType - 1))
  79. #define CERT_EXACT_ISSUER_MATCH_FLAG \
  80. CERT_MATCH_TYPE_TO_FLAG(CERT_EXACT_ISSUER_MATCH_TYPE)
  81. #define CERT_KEYID_ISSUER_MATCH_FLAG \
  82. CERT_MATCH_TYPE_TO_FLAG(CERT_KEYID_ISSUER_MATCH_TYPE)
  83. #define CERT_NAME_ISSUER_MATCH_FLAG \
  84. CERT_MATCH_TYPE_TO_FLAG(CERT_NAME_ISSUER_MATCH_TYPE)
  85. #define CERT_PUBKEY_ISSUER_MATCH_FLAG \
  86. CERT_MATCH_TYPE_TO_FLAG(CERT_PUBKEY_ISSUER_MATCH_TYPE)
  87. //
  88. // Issuer status flags
  89. //
  90. #define CERT_ISSUER_PUBKEY_FLAG 0x00000001
  91. #define CERT_ISSUER_VALID_SIGNATURE_FLAG 0x00000002
  92. #define CERT_ISSUER_URL_FLAG 0x00000004
  93. #define CERT_ISSUER_PUBKEY_PARA_FLAG 0x00000008
  94. #define CERT_ISSUER_SELF_SIGNED_FLAG 0x00000010
  95. #define CERT_ISSUER_TRUSTED_ROOT_FLAG 0x00000020
  96. #define CERT_ISSUER_EXACT_MATCH_HASH_FLAG 0x00000100
  97. #define CERT_ISSUER_NAME_MATCH_HASH_FLAG 0x00000200
  98. //
  99. // Misc info flags
  100. //
  101. #define CHAIN_INVALID_BASIC_CONSTRAINTS_INFO_FLAG 0x00000001
  102. #define CHAIN_INVALID_ISSUER_NAME_CONSTRAINTS_INFO_FLAG 0x00000002
  103. #define CHAIN_INVALID_KEY_USAGE_FLAG 0x00000004
  104. //
  105. // CTL cache entry used for a self signed, untrusted root CCertObject
  106. //
  107. typedef struct _CERT_OBJECT_CTL_CACHE_ENTRY CERT_OBJECT_CTL_CACHE_ENTRY,
  108. *PCERT_OBJECT_CTL_CACHE_ENTRY;
  109. struct _CERT_OBJECT_CTL_CACHE_ENTRY {
  110. PCSSCTLOBJECT pSSCtlObject; // AddRef'ed
  111. PCERT_TRUST_LIST_INFO pTrustListInfo;
  112. PCERT_OBJECT_CTL_CACHE_ENTRY pNext;
  113. };
  114. //
  115. // Chain policies and usage info
  116. //
  117. // Issuance and application policy and usage info
  118. typedef struct _CHAIN_ISS_OR_APP_INFO {
  119. PCERT_POLICIES_INFO pPolicy;
  120. PCERT_POLICY_MAPPINGS_INFO pMappings;
  121. PCERT_POLICY_CONSTRAINTS_INFO pConstraints;
  122. PCERT_ENHKEY_USAGE pUsage; // If NULL, any
  123. DWORD dwFlags;
  124. } CHAIN_ISS_OR_APP_INFO, *PCHAIN_ISS_OR_APP_INFO;
  125. #define CHAIN_INVALID_POLICY_FLAG 0x00000001
  126. #define CHAIN_ANY_POLICY_FLAG 0x00000002
  127. #define CHAIN_ISS_INDEX 0
  128. #define CHAIN_APP_INDEX 1
  129. #define CHAIN_ISS_OR_APP_COUNT 2
  130. typedef struct _CHAIN_POLICIES_INFO {
  131. CHAIN_ISS_OR_APP_INFO rgIssOrAppInfo[CHAIN_ISS_OR_APP_COUNT];
  132. PCERT_ENHKEY_USAGE pPropertyUsage; // If NULL, any
  133. } CHAIN_POLICIES_INFO, *PCHAIN_POLICIES_INFO;
  134. //
  135. // Subject name constraint info
  136. //
  137. typedef struct _CHAIN_SUBJECT_NAME_CONSTRAINTS_INFO {
  138. BOOL fInvalid;
  139. // NULL pointer implies not present in the subject certificate
  140. PCERT_ALT_NAME_INFO pAltNameInfo;
  141. PCERT_NAME_INFO pUnicodeNameInfo;
  142. // If the AltNameInfo doesn't have a RFC822 (email) choice, tries to find
  143. // email attribute (szOID_RSA_emailAddr) in the above pUnicodeNameInfo.
  144. // Note, not re-allocated.
  145. PCERT_RDN_ATTR pEmailAttr;
  146. // Set to TRUE if the pAltNameInfo has a DNS choice.
  147. BOOL fHasDnsAltNameEntry;
  148. } CHAIN_SUBJECT_NAME_CONSTRAINTS_INFO, *PCHAIN_SUBJECT_NAME_CONSTRAINTS_INFO;
  149. //
  150. // CSSCtlObjectCache::EnumObjects callback data structure used to
  151. // create the linked list of CTL cache entries.
  152. //
  153. typedef struct _CERT_OBJECT_CTL_CACHE_ENUM_DATA {
  154. BOOL fResult;
  155. DWORD dwLastError;
  156. PCCERTOBJECT pCertObject;
  157. } CERT_OBJECT_CTL_CACHE_ENUM_DATA, *PCERT_OBJECT_CTL_CACHE_ENUM_DATA;
  158. //
  159. // CCertObject. This is the main object used for caching information
  160. // about a certificate
  161. //
  162. class CCertObject
  163. {
  164. public:
  165. //
  166. // Construction
  167. //
  168. CCertObject (
  169. IN DWORD dwObjectType,
  170. IN PCCHAINCALLCONTEXT pCallContext,
  171. IN PCCERT_CONTEXT pCertContext,
  172. IN BYTE rgbCertHash[CHAINHASHLEN],
  173. OUT BOOL& rfResult
  174. );
  175. ~CCertObject ();
  176. //
  177. // Object type
  178. //
  179. inline DWORD ObjectType();
  180. //
  181. // Convert a CERT_END_OBJECT_TYPE to a CERT_CACHED_END_OBJECT_TYPE.
  182. //
  183. BOOL CacheEndObject(
  184. IN PCCHAINCALLCONTEXT pCallContext
  185. );
  186. //
  187. // Reference counting
  188. //
  189. inline VOID AddRef ();
  190. inline VOID Release ();
  191. //
  192. // Chain engine access
  193. //
  194. inline PCCERTCHAINENGINE ChainEngine ();
  195. //
  196. // Issuer's match and status flags
  197. //
  198. inline DWORD IssuerMatchFlags();
  199. inline DWORD CachedMatchFlags();
  200. inline DWORD IssuerStatusFlags();
  201. inline VOID OrIssuerStatusFlags(IN DWORD dwFlags);
  202. inline VOID OrCachedMatchFlags(IN DWORD dwFlags);
  203. //
  204. // Misc Info status flags
  205. //
  206. inline DWORD InfoFlags();
  207. //
  208. // For CERT_ISSUER_SELF_SIGNED_FLAG && !CERT_ISSUER_TRUSTED_ROOT_FLAG.
  209. //
  210. // List of cached CTLs
  211. //
  212. inline PCERT_OBJECT_CTL_CACHE_ENTRY NextCtlCacheEntry(
  213. IN PCERT_OBJECT_CTL_CACHE_ENTRY pEntry
  214. );
  215. inline VOID InsertCtlCacheEntry(
  216. IN PCERT_OBJECT_CTL_CACHE_ENTRY pEntry
  217. );
  218. //
  219. // Object's certificate context
  220. //
  221. inline PCCERT_CONTEXT CertContext ();
  222. //
  223. // Policies and enhanced key usage obtained from certificate context's
  224. // extensions and property
  225. //
  226. inline PCHAIN_POLICIES_INFO PoliciesInfo ();
  227. //
  228. // Basic constraints obtained from the certificate context's
  229. // extensions (NULL if this extension is omitted)
  230. //
  231. inline PCERT_BASIC_CONSTRAINTS2_INFO BasicConstraintsInfo ();
  232. //
  233. // Key usage obtained from the certificate context's
  234. // extensions (NULL if this extension is omitted)
  235. //
  236. inline PCRYPT_BIT_BLOB KeyUsage ();
  237. //
  238. // Issuer name constraints obtained from the certificate context's
  239. // extensions (NULL if this extension is omitted)
  240. //
  241. inline PCERT_NAME_CONSTRAINTS_INFO IssuerNameConstraintsInfo ();
  242. //
  243. // Subject name constraint info
  244. //
  245. PCHAIN_SUBJECT_NAME_CONSTRAINTS_INFO SubjectNameConstraintsInfo ();
  246. //
  247. // Issuer access
  248. //
  249. inline PCERT_AUTHORITY_KEY_ID_INFO AuthorityKeyIdentifier ();
  250. //
  251. // Hash access
  252. //
  253. inline LPBYTE CertHash ();
  254. //
  255. // Key identifier access
  256. //
  257. inline DWORD KeyIdentifierSize ();
  258. inline LPBYTE KeyIdentifier ();
  259. //
  260. // Public key hash access
  261. //
  262. inline LPBYTE PublicKeyHash ();
  263. // Only valid when CERT_ISSUER_PUBKEY_FLAG is set in m_dwIssuerStatusFlags
  264. inline LPBYTE IssuerPublicKeyHash ();
  265. //
  266. // The index entry handles for cached issuer certificates.
  267. // The primary index entry is the hash index entry. The index entries
  268. // aren't LRU'ed.
  269. //
  270. inline HLRUENTRY HashIndexEntry ();
  271. inline HLRUENTRY IdentifierIndexEntry ();
  272. inline HLRUENTRY SubjectNameIndexEntry ();
  273. inline HLRUENTRY KeyIdIndexEntry ();
  274. inline HLRUENTRY PublicKeyHashIndexEntry ();
  275. //
  276. // The index entry handle for cached end certificates. This is an LRU
  277. // list.
  278. //
  279. inline HLRUENTRY EndHashIndexEntry ();
  280. //
  281. // Issuer match hashes. If match hash doesn't exist,
  282. // returns pMatchHash->cbData = 0
  283. //
  284. VOID GetIssuerExactMatchHash(
  285. OUT PCRYPT_DATA_BLOB pMatchHash
  286. );
  287. VOID GetIssuerKeyMatchHash(
  288. OUT PCRYPT_DATA_BLOB pMatchHash
  289. );
  290. VOID GetIssuerNameMatchHash(
  291. OUT PCRYPT_DATA_BLOB pMatchHash
  292. );
  293. private:
  294. //
  295. // Object's type
  296. //
  297. DWORD m_dwObjectType;
  298. //
  299. // Reference count
  300. //
  301. LONG m_cRefs;
  302. //
  303. // Certificate Chain Engine which owns this certificate object (not
  304. // AddRef'ed)
  305. //
  306. PCCERTCHAINENGINE m_pChainEngine;
  307. //
  308. // Issuer's match and status flags
  309. //
  310. DWORD m_dwIssuerMatchFlags;
  311. DWORD m_dwCachedMatchFlags;
  312. DWORD m_dwIssuerStatusFlags;
  313. //
  314. // Misc Info flags
  315. //
  316. DWORD m_dwInfoFlags;
  317. //
  318. // For CERT_ISSUER_SELF_SIGNED_FLAG && !CERT_ISSUER_TRUSTED_ROOT_FLAG.
  319. // Only set for CERT_CACHED_ISSUER_OBJECT_TYPE.
  320. //
  321. // List of cached CTLs
  322. //
  323. PCERT_OBJECT_CTL_CACHE_ENTRY m_pCtlCacheHead;
  324. //
  325. // Certificate context (duplicated)
  326. //
  327. PCCERT_CONTEXT m_pCertContext;
  328. //
  329. // Policies and usage info
  330. //
  331. CHAIN_POLICIES_INFO m_PoliciesInfo;
  332. //
  333. // Basic constraints info (NULL if this extension is omitted)
  334. //
  335. PCERT_BASIC_CONSTRAINTS2_INFO m_pBasicConstraintsInfo;
  336. //
  337. // Key usage (NULL if this extension is omitted)
  338. //
  339. PCRYPT_BIT_BLOB m_pKeyUsage;
  340. //
  341. // Name constraints obtained from the certificate context's
  342. // extensions (NULL if this extension is omitted)
  343. //
  344. PCERT_NAME_CONSTRAINTS_INFO m_pIssuerNameConstraintsInfo;
  345. //
  346. // Subject name constraint info (deferred get of)
  347. //
  348. BOOL m_fAvailableSubjectNameConstraintsInfo;
  349. CHAIN_SUBJECT_NAME_CONSTRAINTS_INFO m_SubjectNameConstraintsInfo;
  350. //
  351. // Authority Key Identifier. This contains the issuer and serial number
  352. // and/or key identifier of the issuing certificate for this certificate
  353. // object if the m_dwIssuerMatchFlags includes
  354. // CERT_EXACT_ISSUER_MATCH_FLAG and/or CERT_KEYID_ISSUER_MATCH_FLAG
  355. //
  356. PCERT_AUTHORITY_KEY_ID_INFO m_pAuthKeyIdentifier;
  357. //
  358. // Certificate Object Identifier (MD5 hash of issuer and serial number)
  359. //
  360. CERT_OBJECT_IDENTIFIER m_ObjectIdentifier;
  361. //
  362. // MD5 Hash of the certificate
  363. //
  364. BYTE m_rgbCertHash[ CHAINHASHLEN ];
  365. //
  366. // Key Identifier of the certificate
  367. //
  368. DWORD m_cbKeyIdentifier;
  369. LPBYTE m_pbKeyIdentifier;
  370. //
  371. // MD5 Hash of the subject and issuer public keys
  372. //
  373. BYTE m_rgbPublicKeyHash[ CHAINHASHLEN ];
  374. // Only valid when CERT_ISSUER_PUBKEY_FLAG is set in m_dwIssuerStatusFlags
  375. BYTE m_rgbIssuerPublicKeyHash[ CHAINHASHLEN ];
  376. // Only valid when CERT_ISSUER_EXACT_MATCH_HASH_FLAG is set in
  377. // m_dwIssuerStatusFlags
  378. BYTE m_rgbIssuerExactMatchHash[ CHAINHASHLEN ];
  379. // Only valid when CERT_ISSUER_NAME_MATCH_HASH_FLAG is set in
  380. // m_dwIssuerStatusFlags
  381. BYTE m_rgbIssuerNameMatchHash[ CHAINHASHLEN ];
  382. //
  383. // Certificate Object Cache Index entries applicable to
  384. // CERT_CACHED_ISSUER_OBJECT_TYPE.
  385. //
  386. HLRUENTRY m_hHashEntry;
  387. HLRUENTRY m_hIdentifierEntry;
  388. HLRUENTRY m_hSubjectNameEntry;
  389. HLRUENTRY m_hKeyIdEntry;
  390. HLRUENTRY m_hPublicKeyHashEntry;
  391. //
  392. // Certificate Object Cache Index entries applicable to
  393. // CERT_CACHED_END_OBJECT_TYPE.
  394. //
  395. HLRUENTRY m_hEndHashEntry;
  396. };
  397. //
  398. // Chain quality values (ascending order)
  399. //
  400. #define CERT_QUALITY_SIMPLE_CHAIN 0x00000001
  401. #define CERT_QUALITY_CHECK_REVOCATION 0x00000010
  402. #define CERT_QUALITY_ONLINE_REVOCATION 0x00000020
  403. #define CERT_QUALITY_PREFERRED_ISSUER 0x00000040
  404. #define CERT_QUALITY_HAS_APPLICATION_USAGE 0x00000080
  405. #define CERT_QUALITY_HAS_ISSUANCE_CHAIN_POLICY 0x00000100
  406. #define CERT_QUALITY_POLICY_CONSTRAINTS_VALID 0x00000200
  407. #define CERT_QUALITY_BASIC_CONSTRAINTS_VALID 0x00000400
  408. #define CERT_QUALITY_HAS_NAME_CONSTRAINTS 0x00000800
  409. #define CERT_QUALITY_NAME_CONSTRAINTS_VALID 0x00001000
  410. #define CERT_QUALITY_NAME_CONSTRAINTS_MET 0x00002000
  411. #define CERT_QUALITY_NOT_REVOKED 0x00100000
  412. #define CERT_QUALITY_TIME_VALID 0x00200000
  413. #define CERT_QUALITY_MEETS_USAGE_CRITERIA 0x00400000
  414. #define CERT_QUALITY_NOT_CYCLIC 0x00800000
  415. #define CERT_QUALITY_HAS_TIME_VALID_TRUSTED_ROOT 0x01000000
  416. #define CERT_QUALITY_HAS_TRUSTED_ROOT 0x02000000
  417. #define CERT_QUALITY_COMPLETE_CHAIN 0x04000000
  418. #define CERT_QUALITY_SIGNATURE_VALID 0x08000000
  419. #define CERT_TRUST_CERTIFICATE_ONLY_INFO_STATUS ( CERT_TRUST_IS_SELF_SIGNED |\
  420. CERT_TRUST_HAS_EXACT_MATCH_ISSUER |\
  421. CERT_TRUST_HAS_NAME_MATCH_ISSUER |\
  422. CERT_TRUST_HAS_KEY_MATCH_ISSUER )
  423. #define CERT_CHAIN_REVOCATION_CHECK_ALL ( CERT_CHAIN_REVOCATION_CHECK_END_CERT | \
  424. CERT_CHAIN_REVOCATION_CHECK_CHAIN | \
  425. CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT | \
  426. CERT_CHAIN_REVOCATION_CHECK_CACHE_ONLY )
  427. #define CERT_TRUST_ANY_NAME_CONSTRAINT_ERROR_STATUS ( \
  428. CERT_TRUST_INVALID_NAME_CONSTRAINTS | \
  429. CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT | \
  430. CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT | \
  431. CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT | \
  432. CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT )
  433. //
  434. // Internal chain context. Wraps the exposed CERT_CHAIN_CONTEXT.
  435. //
  436. typedef struct _INTERNAL_CERT_CHAIN_CONTEXT INTERNAL_CERT_CHAIN_CONTEXT,
  437. *PINTERNAL_CERT_CHAIN_CONTEXT;
  438. struct _INTERNAL_CERT_CHAIN_CONTEXT {
  439. CERT_CHAIN_CONTEXT ChainContext;
  440. LONG cRefs;
  441. DWORD dwQuality;
  442. PINTERNAL_CERT_CHAIN_CONTEXT pNext;
  443. };
  444. //
  445. // Restricted issuance, application and property usage as we move from the
  446. // top down to the end certificate
  447. //
  448. // Note, NULL PCERT_ENHKEY_USAGE implies any
  449. typedef struct _CHAIN_RESTRICTED_USAGE_INFO {
  450. PCERT_ENHKEY_USAGE pIssuanceRestrictedUsage;
  451. PCERT_ENHKEY_USAGE pIssuanceMappedUsage;
  452. LPDWORD rgdwIssuanceMappedIndex;
  453. BOOL fRequireIssuancePolicy;
  454. PCERT_ENHKEY_USAGE pApplicationRestrictedUsage;
  455. PCERT_ENHKEY_USAGE pApplicationMappedUsage;
  456. LPDWORD rgdwApplicationMappedIndex;
  457. PCERT_ENHKEY_USAGE pPropertyRestrictedUsage;
  458. } CHAIN_RESTRICTED_USAGE_INFO, *PCHAIN_RESTRICTED_USAGE_INFO;
  459. //
  460. // Forward reference to the issuer element
  461. //
  462. typedef struct _CERT_ISSUER_ELEMENT CERT_ISSUER_ELEMENT, *PCERT_ISSUER_ELEMENT;
  463. //
  464. // CChainPathObject. This is the main object used for building the
  465. // chain graph.
  466. //
  467. // Note, since this object isn't persisted across calls, NO REF COUNTING is
  468. // done.
  469. //
  470. class CChainPathObject
  471. {
  472. public:
  473. //
  474. // Construction
  475. //
  476. CChainPathObject (
  477. IN PCCHAINCALLCONTEXT pCallContext,
  478. IN BOOL fCyclic,
  479. IN LPVOID pvObject, // fCyclic : pPathObject ? pCertObject
  480. IN OPTIONAL HCERTSTORE hAdditionalStore,
  481. OUT BOOL& rfResult,
  482. OUT BOOL& rfAddedToCreationCache
  483. );
  484. ~CChainPathObject ();
  485. //
  486. // Certificate Object (AddRef'ed)
  487. //
  488. inline PCCERTOBJECT CertObject ();
  489. //
  490. // Pass 1 quality
  491. //
  492. inline DWORD Pass1Quality ();
  493. inline VOID SetPass1Quality (IN DWORD dwQuality);
  494. //
  495. // Returns TRUE if we have completed the initialization and addition
  496. // of issuers to this object. FALSE would normally indicate a cyclic
  497. // issuer.
  498. //
  499. inline BOOL IsCompleted ();
  500. //
  501. // AdditionalStatus flag and down path object
  502. //
  503. inline BOOL HasAdditionalStatus ();
  504. inline PCCHAINPATHOBJECT DownPathObject ();
  505. //
  506. // Find and add issuers
  507. //
  508. BOOL FindAndAddIssuers (
  509. IN PCCHAINCALLCONTEXT pCallContext,
  510. IN OPTIONAL HCERTSTORE hAdditionalStore,
  511. IN OPTIONAL HCERTSTORE hIssuerUrlStore
  512. );
  513. BOOL FindAndAddIssuersByMatchType(
  514. IN DWORD dwMatchType,
  515. IN PCCHAINCALLCONTEXT pCallContext,
  516. IN OPTIONAL HCERTSTORE hAdditionalStore,
  517. IN OPTIONAL HCERTSTORE hIssuerUrlStore
  518. );
  519. BOOL FindAndAddIssuersFromCacheByMatchType(
  520. IN DWORD dwMatchType,
  521. IN PCCHAINCALLCONTEXT pCallContext,
  522. IN OPTIONAL HCERTSTORE hAdditionalStore
  523. );
  524. BOOL FindAndAddIssuersFromStoreByMatchType(
  525. IN DWORD dwMatchType,
  526. IN PCCHAINCALLCONTEXT pCallContext,
  527. IN BOOL fExternalStore,
  528. IN OPTIONAL HCERTSTORE hAdditionalStore,
  529. IN OPTIONAL HCERTSTORE hIssuerUrlStore
  530. );
  531. BOOL FindAndAddCtlIssuersFromCache (
  532. IN PCCHAINCALLCONTEXT pCallContext,
  533. IN OPTIONAL HCERTSTORE hAdditionalStore
  534. );
  535. BOOL FindAndAddCtlIssuersFromAdditionalStore (
  536. IN PCCHAINCALLCONTEXT pCallContext,
  537. IN HCERTSTORE hAdditionalStore
  538. );
  539. //
  540. // Builds the top down chain graph for the next top object
  541. //
  542. PCCHAINPATHOBJECT NextPath (
  543. IN PCCHAINCALLCONTEXT pCallContext,
  544. IN OPTIONAL PCCHAINPATHOBJECT pPrevTopPathObject
  545. );
  546. VOID CalculateAdditionalStatus (
  547. IN PCCHAINCALLCONTEXT pCallContext,
  548. IN HCERTSTORE hAllStore
  549. );
  550. VOID CalculatePolicyConstraintsStatus ();
  551. VOID CalculateBasicConstraintsStatus ();
  552. VOID CalculateKeyUsageStatus ();
  553. VOID CalculateNameConstraintsStatus (
  554. IN PCERT_USAGE_MATCH pUsageToUse
  555. );
  556. VOID CalculateRevocationStatus (
  557. IN PCCHAINCALLCONTEXT pCallContext,
  558. IN HCERTSTORE hCrlStore,
  559. IN LPFILETIME pTime
  560. );
  561. PINTERNAL_CERT_CHAIN_CONTEXT CreateChainContextFromPath (
  562. IN PCCHAINCALLCONTEXT pCallContext,
  563. IN PCCHAINPATHOBJECT pTopPathObject
  564. );
  565. BOOL UpdateChainContextUsageForPathObject (
  566. IN PCCHAINCALLCONTEXT pCallContext,
  567. IN OUT PCERT_SIMPLE_CHAIN pChain,
  568. IN OUT PCERT_CHAIN_ELEMENT pElement,
  569. IN OUT PCHAIN_RESTRICTED_USAGE_INFO pRestrictedUsageInfo
  570. );
  571. BOOL UpdateChainContextFromPathObject (
  572. IN PCCHAINCALLCONTEXT pCallContext,
  573. IN OUT PCERT_SIMPLE_CHAIN pChain,
  574. IN OUT PCERT_CHAIN_ELEMENT pElement
  575. );
  576. //
  577. // AuthRoot Auto Update CTL Methods
  578. //
  579. BOOL GetAuthRootAutoUpdateUrlStore(
  580. IN PCCHAINCALLCONTEXT pCallContext,
  581. OUT HCERTSTORE *phIssuerUrlStore
  582. );
  583. private:
  584. //
  585. // Certificate Object (AddRef'ed)
  586. //
  587. PCCERTOBJECT m_pCertObject;
  588. //
  589. // Trust Status. This does not represent the full trust status
  590. // for the object. Some of the bits are calculated on demand and placed
  591. // into the ending chain context. The following are the trust status
  592. // bits which can appear here
  593. //
  594. // CERT_TRUST_IS_SELF_SIGNED
  595. // CERT_TRUST_HAS_EXACT_MATCH_ISSUER
  596. // CERT_TRUST_HAS_NAME_MATCH_ISSUER
  597. // CERT_TRUST_HAS_KEY_MATCH_ISSUER
  598. //
  599. // CERT_TRUST_IS_NOT_SIGNATURE_VALID (if the certificate is self-signed)
  600. // CERT_TRUST_IS_UNTRUSTED_ROOT (if the certificate is self-signed)
  601. // CERT_TRUST_HAS_PREFERRED_ISSUER (if the certificate is self-signed)
  602. //
  603. // CERT_TRUST_IS_CYCLIC (for cyclic cert)
  604. //
  605. CERT_TRUST_STATUS m_TrustStatus;
  606. // Pass1 Quality is limited to the following:
  607. // CERT_QUALITY_NOT_CYCLIC
  608. // CERT_QUALITY_HAS_TIME_VALID_TRUSTED_ROOT
  609. // CERT_QUALITY_HAS_TRUSTED_ROOT
  610. // CERT_QUALITY_SIGNATURE_VALID
  611. // CERT_QUALITY_COMPLETE_CHAIN
  612. DWORD m_dwPass1Quality;
  613. //
  614. // The chain context's chain and element indices
  615. //
  616. DWORD m_dwChainIndex;
  617. DWORD m_dwElementIndex;
  618. //
  619. // Down and up path pointers for a chain context
  620. //
  621. PCERT_ISSUER_ELEMENT m_pDownIssuerElement;
  622. PCCHAINPATHOBJECT m_pDownPathObject;
  623. PCERT_ISSUER_ELEMENT m_pUpIssuerElement;
  624. //
  625. // Additional status and revocation info (only applicable to self signed
  626. // certificates or top certificates without any issuers)
  627. //
  628. BOOL m_fHasAdditionalStatus;
  629. CERT_TRUST_STATUS m_AdditionalStatus;
  630. BOOL m_fHasRevocationInfo;
  631. CERT_REVOCATION_INFO m_RevocationInfo;
  632. CERT_REVOCATION_CRL_INFO m_RevocationCrlInfo;
  633. //
  634. // Issuer Chain Path Objects. The list of issuers of this
  635. // certificate object along with information about those issuers
  636. // relevant to this subject.
  637. //
  638. PCCERTISSUERLIST m_pIssuerList;
  639. //
  640. // Supplemental error information is localization formatted and appended.
  641. // Each error line should be terminated with a L'\n'.
  642. //
  643. LPWSTR m_pwszExtendedErrorInfo;
  644. //
  645. // Following flag is set when we have completed the initialization and
  646. // addition of all issuers to this object.
  647. //
  648. BOOL m_fCompleted;
  649. };
  650. //
  651. // CCertIssuerList. List of issuer certificate objects along with related
  652. // issuer information. This is used by the certificate object to cache
  653. // its possible set of issuers
  654. //
  655. // Currently in a self signed certificate object, the issuer elements will
  656. // have CTL issuer data set and pIssuer may be NULL if unable to find
  657. // the CTL signer
  658. typedef struct _CTL_ISSUER_DATA {
  659. PCSSCTLOBJECT pSSCtlObject; // AddRef'ed
  660. PCERT_TRUST_LIST_INFO pTrustListInfo;
  661. } CTL_ISSUER_DATA, *PCTL_ISSUER_DATA;
  662. struct _CERT_ISSUER_ELEMENT {
  663. DWORD dwPass1Quality;
  664. CERT_TRUST_STATUS SubjectStatus;
  665. BOOL fCtlIssuer;
  666. PCCHAINPATHOBJECT pIssuer;
  667. // For a cyclic issuer, the above pIssuer is saved into the following
  668. // before it is updated with the cyclic issuer path object
  669. PCCHAINPATHOBJECT pCyclicSaveIssuer;
  670. PCTL_ISSUER_DATA pCtlIssuerData;
  671. struct _CERT_ISSUER_ELEMENT* pPrevElement;
  672. struct _CERT_ISSUER_ELEMENT* pNextElement;
  673. BOOL fHasRevocationInfo;
  674. CERT_REVOCATION_INFO RevocationInfo;
  675. CERT_REVOCATION_CRL_INFO RevocationCrlInfo;
  676. };
  677. class CCertIssuerList
  678. {
  679. public:
  680. //
  681. // Construction
  682. //
  683. CCertIssuerList (
  684. IN PCCHAINPATHOBJECT pSubject
  685. );
  686. ~CCertIssuerList ();
  687. //
  688. // Issuer management
  689. //
  690. inline BOOL IsEmpty ();
  691. BOOL AddIssuer(
  692. IN PCCHAINCALLCONTEXT pCallContext,
  693. IN OPTIONAL HCERTSTORE hAdditionalStore,
  694. IN PCCERTOBJECT pIssuer
  695. );
  696. BOOL AddCtlIssuer(
  697. IN PCCHAINCALLCONTEXT pCallContext,
  698. IN OPTIONAL HCERTSTORE hAdditionalStore,
  699. IN PCSSCTLOBJECT pSSCtlObject,
  700. IN PCERT_TRUST_LIST_INFO pTrustListInfo
  701. );
  702. //
  703. // Element management
  704. //
  705. BOOL CreateElement(
  706. IN PCCHAINCALLCONTEXT pCallContext,
  707. IN BOOL fCtlIssuer,
  708. IN OPTIONAL PCCHAINPATHOBJECT pIssuer,
  709. IN OPTIONAL HCERTSTORE hAdditionalStore,
  710. IN OPTIONAL PCSSCTLOBJECT pSSCtlObject,
  711. IN OPTIONAL PCERT_TRUST_LIST_INFO pTrustListInfo,
  712. OUT PCERT_ISSUER_ELEMENT* ppElement
  713. );
  714. VOID DeleteElement (
  715. IN PCERT_ISSUER_ELEMENT pElement
  716. );
  717. inline VOID AddElement (
  718. IN PCERT_ISSUER_ELEMENT pElement
  719. );
  720. inline VOID RemoveElement (
  721. IN PCERT_ISSUER_ELEMENT pElement
  722. );
  723. BOOL CheckForDuplicateElement (
  724. IN BYTE rgbHash [ CHAINHASHLEN ],
  725. IN BOOL fCtlIssuer
  726. );
  727. //
  728. // Enumerate the issuers
  729. //
  730. inline PCERT_ISSUER_ELEMENT NextElement (
  731. IN PCERT_ISSUER_ELEMENT pElement
  732. );
  733. private:
  734. //
  735. // Subject chain path object
  736. //
  737. PCCHAINPATHOBJECT m_pSubject;
  738. //
  739. // Issuer List
  740. //
  741. PCERT_ISSUER_ELEMENT m_pHead;
  742. };
  743. //
  744. // CCertObjectCache.
  745. //
  746. // Cache of issuer certificate object references indexed by the following keys:
  747. // Certificate Hash
  748. // Certificate Object Identifier
  749. // Subject Name
  750. // Key Identifier
  751. // Public Key Hash
  752. //
  753. // Cache of end certificate object references indexed by the following keys:
  754. // End Certificate Hash
  755. //
  756. // Only the end certificate is LRU maintained.
  757. //
  758. #define DEFAULT_CERT_OBJECT_CACHE_BUCKETS 127
  759. #define DEFAULT_MAX_INDEX_ENTRIES 256
  760. class CCertObjectCache
  761. {
  762. public:
  763. //
  764. // Construction
  765. //
  766. CCertObjectCache (
  767. IN DWORD MaxIndexEntries,
  768. OUT BOOL& rfResult
  769. );
  770. ~CCertObjectCache ();
  771. //
  772. // Certificate Object Management
  773. //
  774. // Increments engine's touch count
  775. VOID AddIssuerObject (
  776. IN PCCHAINCALLCONTEXT pCallContext,
  777. IN PCCERTOBJECT pCertObject
  778. );
  779. VOID AddEndObject (
  780. IN PCCHAINCALLCONTEXT pCallContext,
  781. IN PCCERTOBJECT pCertObject
  782. );
  783. //
  784. // Access the indexes
  785. //
  786. inline HLRUCACHE HashIndex ();
  787. inline HLRUCACHE IdentifierIndex ();
  788. inline HLRUCACHE SubjectNameIndex ();
  789. inline HLRUCACHE KeyIdIndex ();
  790. inline HLRUCACHE PublicKeyHashIndex ();
  791. inline HLRUCACHE EndHashIndex ();
  792. //
  793. // Certificate Object Searching
  794. //
  795. PCCERTOBJECT FindIssuerObject (
  796. IN HLRUCACHE hIndex,
  797. IN PCRYPT_DATA_BLOB pIdentifier
  798. );
  799. PCCERTOBJECT FindIssuerObjectByHash (
  800. IN BYTE rgbCertHash[ CHAINHASHLEN ]
  801. );
  802. PCCERTOBJECT FindEndObjectByHash (
  803. IN BYTE rgbCertHash[ CHAINHASHLEN ]
  804. );
  805. //
  806. // Certificate Object Enumeration
  807. //
  808. PCCERTOBJECT NextMatchingIssuerObject (
  809. IN HLRUENTRY hObjectEntry,
  810. IN PCCERTOBJECT pCertObject
  811. );
  812. //
  813. // Cache flushing
  814. //
  815. inline VOID FlushObjects (IN PCCHAINCALLCONTEXT pCallContext);
  816. private:
  817. //
  818. // Certificate Hash Index
  819. //
  820. HLRUCACHE m_hHashIndex;
  821. //
  822. // Certificate Object Identifier Index
  823. //
  824. HLRUCACHE m_hIdentifierIndex;
  825. //
  826. // Subject Name Index
  827. //
  828. HLRUCACHE m_hSubjectNameIndex;
  829. //
  830. // Key Identifier Index
  831. //
  832. HLRUCACHE m_hKeyIdIndex;
  833. //
  834. // Public Key Hash Index
  835. //
  836. HLRUCACHE m_hPublicKeyHashIndex;
  837. //
  838. // End Certificate Hash Index
  839. //
  840. HLRUCACHE m_hEndHashIndex;
  841. //
  842. // Private methods
  843. //
  844. };
  845. typedef struct _XCERT_DP_ENTRY XCERT_DP_ENTRY, *PXCERT_DP_ENTRY;
  846. typedef struct _XCERT_DP_LINK XCERT_DP_LINK, *PXCERT_DP_LINK;
  847. //
  848. // Cross Certificate Distribution Point Entry
  849. //
  850. struct _XCERT_DP_ENTRY {
  851. // Seconds between syncs
  852. DWORD dwSyncDeltaTime;
  853. // List of NULL terminated Urls. A successfully retrieved Url
  854. // pointer is moved to the beginning of the list.
  855. DWORD cUrl;
  856. LPWSTR *rgpwszUrl;
  857. // Time of last sync
  858. FILETIME LastSyncTime;
  859. // If dwOfflineCnt == 0, NextSyncTime = LastSyncTime + dwSyncDeltaTime.
  860. // Otherwise, NextSyncTime = CurrentTime +
  861. // rgdwChainOfflineUrlDeltaSeconds[dwOfflineCnt - 1]
  862. FILETIME NextSyncTime;
  863. // Following is incremented when unable to do an online Url retrieval.
  864. // A successful Url retrieval resets.
  865. DWORD dwOfflineCnt;
  866. // Following is incremented for each new scan through the DP entries
  867. DWORD dwResyncIndex;
  868. // Following is set when this entry has already been checked
  869. BOOL fChecked;
  870. PXCERT_DP_LINK pChildCrossCertDPLink;
  871. LONG lRefCnt;
  872. HCERTSTORE hUrlStore;
  873. PXCERT_DP_ENTRY pNext;
  874. PXCERT_DP_ENTRY pPrev;
  875. };
  876. //
  877. // Cross Certificate Distribution Point Link
  878. //
  879. struct _XCERT_DP_LINK {
  880. PXCERT_DP_ENTRY pCrossCertDPEntry;
  881. PXCERT_DP_LINK pNext;
  882. PXCERT_DP_LINK pPrev;
  883. };
  884. //
  885. // AuthRoot Auto Update Info
  886. //
  887. #define AUTH_ROOT_KEY_MATCH_IDX 0
  888. #define AUTH_ROOT_NAME_MATCH_IDX 1
  889. #define AUTH_ROOT_MATCH_CNT 2
  890. #define AUTH_ROOT_MATCH_CACHE_BUCKETS 61
  891. typedef struct _AUTH_ROOT_AUTO_UPDATE_INFO {
  892. // Seconds between syncs
  893. DWORD dwSyncDeltaTime;
  894. // Registry Flags value
  895. DWORD dwFlags;
  896. // URL to the directory containing the AuthRoots
  897. LPWSTR pwszRootDirUrl;
  898. // URL to the CAB containing the CTL containing the complete list of roots
  899. // in the AuthRoot store
  900. LPWSTR pwszCabUrl;
  901. // URL to the SequenceNumber file corresponding to the latest list of
  902. // roots in the AuthRoot store
  903. LPWSTR pwszSeqUrl;
  904. // Time of last sync
  905. FILETIME LastSyncTime;
  906. // NextSyncTime = LastSyncTime + dwSyncDeltaTime.
  907. FILETIME NextSyncTime;
  908. // If nonNull, a validated AuthRoot CTL.
  909. PCCTL_CONTEXT pCtl;
  910. // Cache of CTL entries via their key and name match hashes. The
  911. // Cache entry value is the PCTL_ENTRY pointer.
  912. HLRUCACHE rghMatchCache[AUTH_ROOT_MATCH_CNT];
  913. } AUTH_ROOT_AUTO_UPDATE_INFO, *PAUTH_ROOT_AUTO_UPDATE_INFO;
  914. // 7 days
  915. #define AUTH_ROOT_AUTO_UPDATE_SYNC_DELTA_TIME (60 * 60 * 24 * 7)
  916. #define AUTH_ROOT_AUTO_UPDATE_ROOT_DIR_URL L"http://www.download.windowsupdate.com/msdownload/update/v3/static/trustedr/en"
  917. //
  918. // CCertChainEngine. The chaining engine satisfies requests for chain contexts
  919. // given some set of parameters. In order to make the building of these
  920. // contexts efficient, the chain engine caches trust and chain information
  921. // for certificates
  922. //
  923. class CCertChainEngine
  924. {
  925. public:
  926. //
  927. // Construction
  928. //
  929. CCertChainEngine (
  930. IN PCERT_CHAIN_ENGINE_CONFIG pConfig,
  931. IN BOOL fDefaultEngine,
  932. OUT BOOL& rfResult
  933. );
  934. ~CCertChainEngine ();
  935. //
  936. // Chain Engine Locking
  937. //
  938. inline VOID LockEngine ();
  939. inline VOID UnlockEngine ();
  940. //
  941. // Chain Engine reference counting
  942. //
  943. inline VOID AddRef ();
  944. inline VOID Release ();
  945. //
  946. // Cache access
  947. //
  948. inline PCCERTOBJECTCACHE CertObjectCache ();
  949. inline PCSSCTLOBJECTCACHE SSCtlObjectCache ();
  950. //
  951. // Store access
  952. //
  953. inline HCERTSTORE RootStore ();
  954. inline HCERTSTORE RealRootStore ();
  955. inline HCERTSTORE TrustStore ();
  956. inline HCERTSTORE OtherStore ();
  957. inline HCERTSTORE CAStore ();
  958. //
  959. // Open the HKLM or HKCU "trust" store. Caller must close.
  960. //
  961. inline HCERTSTORE OpenTrustStore ();
  962. //
  963. // Engine's Url retrieval timeout
  964. //
  965. inline DWORD UrlRetrievalTimeout ();
  966. inline BOOL HasDefaultUrlRetrievalTimeout ();
  967. //
  968. // Engine's Flags
  969. //
  970. inline DWORD Flags ();
  971. //
  972. // Engine Touching
  973. //
  974. inline DWORD TouchEngineCount ();
  975. inline DWORD IncrementTouchEngineCount ();
  976. //
  977. // Chain Context Retrieval
  978. //
  979. BOOL GetChainContext (
  980. IN PCCERT_CONTEXT pCertContext,
  981. IN LPFILETIME pTime,
  982. IN HCERTSTORE hAdditionalStore,
  983. IN OPTIONAL PCERT_CHAIN_PARA pChainPara,
  984. IN DWORD dwFlags,
  985. IN LPVOID pvReserved,
  986. OUT PCCERT_CHAIN_CONTEXT* ppChainContext
  987. );
  988. BOOL CreateChainContextFromPathGraph (
  989. IN PCCHAINCALLCONTEXT pCallContext,
  990. IN PCCERT_CONTEXT pCertContext,
  991. IN HCERTSTORE hAdditionalStore,
  992. OUT PCCERT_CHAIN_CONTEXT* ppChainContext
  993. );
  994. // Leaves Engine's lock to do URL fetching
  995. BOOL GetIssuerUrlStore(
  996. IN PCCHAINCALLCONTEXT pCallContext,
  997. IN PCCERT_CONTEXT pSubjectCertContext,
  998. IN DWORD dwRetrievalFlags,
  999. OUT HCERTSTORE *phIssuerUrlStore
  1000. );
  1001. // Engine isn't locked on entry. Only called if online.
  1002. HCERTSTORE GetNewerIssuerUrlStore(
  1003. IN PCCHAINCALLCONTEXT pCallContext,
  1004. IN PCCERT_CONTEXT pSubjectCertContext,
  1005. IN PCCERT_CONTEXT pIssuerCertContext
  1006. );
  1007. //
  1008. // Resync the engine
  1009. //
  1010. BOOL Resync (IN PCCHAINCALLCONTEXT pCallContext, BOOL fForce);
  1011. //
  1012. // Cross Certificate Methods implemented in xcert.cpp
  1013. //
  1014. void
  1015. InsertCrossCertDistPointEntry(
  1016. IN OUT PXCERT_DP_ENTRY pEntry
  1017. );
  1018. void
  1019. RemoveCrossCertDistPointEntry(
  1020. IN OUT PXCERT_DP_ENTRY pEntry
  1021. );
  1022. void
  1023. RepositionOnlineCrossCertDistPointEntry(
  1024. IN OUT PXCERT_DP_ENTRY pEntry,
  1025. IN LPFILETIME pLastSyncTime
  1026. );
  1027. void
  1028. RepositionOfflineCrossCertDistPointEntry(
  1029. IN OUT PXCERT_DP_ENTRY pEntry,
  1030. IN LPFILETIME pCurrentTime
  1031. );
  1032. void
  1033. RepositionNewSyncDeltaTimeCrossCertDistPointEntry(
  1034. IN OUT PXCERT_DP_ENTRY pEntry,
  1035. IN DWORD dwSyncDeltaTime
  1036. );
  1037. PXCERT_DP_ENTRY
  1038. CreateCrossCertDistPointEntry(
  1039. IN DWORD dwSyncDeltaTime,
  1040. IN DWORD cUrl,
  1041. IN LPWSTR *rgpwszUrl
  1042. );
  1043. void
  1044. AddRefCrossCertDistPointEntry(
  1045. IN OUT PXCERT_DP_ENTRY pEntry
  1046. );
  1047. BOOL
  1048. ReleaseCrossCertDistPointEntry(
  1049. IN OUT PXCERT_DP_ENTRY pEntry
  1050. );
  1051. BOOL
  1052. GetCrossCertDistPointsForStore(
  1053. IN HCERTSTORE hStore,
  1054. IN OUT PXCERT_DP_LINK *ppLinkHead
  1055. );
  1056. void
  1057. RemoveCrossCertDistPointOrphanEntry(
  1058. IN PXCERT_DP_ENTRY pOrphanEntry
  1059. );
  1060. void
  1061. FreeCrossCertDistPoints(
  1062. IN OUT PXCERT_DP_LINK *ppLinkHead
  1063. );
  1064. BOOL
  1065. RetrieveCrossCertUrl(
  1066. IN PCCHAINCALLCONTEXT pCallContext,
  1067. IN OUT PXCERT_DP_ENTRY pEntry,
  1068. IN DWORD dwRetrievalFlags,
  1069. IN OUT BOOL *pfTimeValid
  1070. );
  1071. BOOL
  1072. UpdateCrossCerts(
  1073. IN PCCHAINCALLCONTEXT pCallContext
  1074. );
  1075. //
  1076. // AuthRoot Auto Update CTL Methods
  1077. //
  1078. inline PAUTH_ROOT_AUTO_UPDATE_INFO AuthRootAutoUpdateInfo();
  1079. BOOL
  1080. RetrieveAuthRootAutoUpdateObjectByUrlW(
  1081. IN PCCHAINCALLCONTEXT pCallContext,
  1082. IN DWORD dwSuccessEventID,
  1083. IN DWORD dwFailEventID,
  1084. IN LPCWSTR pwszUrl,
  1085. IN LPCSTR pszObjectOid,
  1086. IN DWORD dwRetrievalFlags,
  1087. IN DWORD dwTimeout, // 0 => use default
  1088. OUT LPVOID* ppvObject,
  1089. IN OPTIONAL PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
  1090. );
  1091. BOOL
  1092. GetAuthRootAutoUpdateCtl(
  1093. IN PCCHAINCALLCONTEXT pCallContext,
  1094. OUT PCCTL_CONTEXT *ppCtl
  1095. );
  1096. VOID
  1097. FindAuthRootAutoUpdateMatchingCtlEntries(
  1098. IN CRYPT_DATA_BLOB rgMatchHash[AUTH_ROOT_MATCH_CNT],
  1099. IN OUT PCCTL_CONTEXT *ppCtl,
  1100. OUT DWORD *pcCtlEntry,
  1101. OUT PCTL_ENTRY **prgpCtlEntry
  1102. );
  1103. BOOL
  1104. GetAuthRootAutoUpdateCert(
  1105. IN PCCHAINCALLCONTEXT pCallContext,
  1106. IN PCTL_ENTRY pCtlEntry,
  1107. IN OUT HCERTSTORE hStore
  1108. );
  1109. private:
  1110. //
  1111. // Reference count
  1112. //
  1113. LONG m_cRefs;
  1114. //
  1115. // Engine Lock
  1116. //
  1117. CRITICAL_SECTION m_Lock;
  1118. //
  1119. // Root store ( Certs )
  1120. //
  1121. HCERTSTORE m_hRealRootStore;
  1122. HCERTSTORE m_hRootStore;
  1123. //
  1124. // Trust Store Collection ( CTLs )
  1125. //
  1126. HCERTSTORE m_hTrustStore;
  1127. //
  1128. // Other store collection ( Certs and CRLs )
  1129. //
  1130. HCERTSTORE m_hOtherStore;
  1131. HCERTSTORE m_hCAStore;
  1132. //
  1133. // Engine Store ( Collection of Root, Trust and Other )
  1134. //
  1135. HCERTSTORE m_hEngineStore;
  1136. //
  1137. // Engine Store Change Notification Event
  1138. //
  1139. HANDLE m_hEngineStoreChangeEvent;
  1140. //
  1141. // Engine flags
  1142. //
  1143. DWORD m_dwFlags;
  1144. //
  1145. // Retrieval timeout
  1146. //
  1147. DWORD m_dwUrlRetrievalTimeout;
  1148. BOOL m_fDefaultUrlRetrievalTimeout;
  1149. //
  1150. // Certificate Object Cache
  1151. //
  1152. PCCERTOBJECTCACHE m_pCertObjectCache;
  1153. //
  1154. // Self Signed Certificate Trust List Object Cache
  1155. //
  1156. PCSSCTLOBJECTCACHE m_pSSCtlObjectCache;
  1157. //
  1158. // Engine Touching
  1159. //
  1160. DWORD m_dwTouchEngineCount;
  1161. //
  1162. // Cross Certificate
  1163. //
  1164. // List of all distribution point entries. Ordered according to
  1165. // the entrys' NextSyncTime.
  1166. PXCERT_DP_ENTRY m_pCrossCertDPEntry;
  1167. // List of engine's distribution point links
  1168. PXCERT_DP_LINK m_pCrossCertDPLink;
  1169. // Collection of cross cert stores
  1170. HCERTSTORE m_hCrossCertStore;
  1171. // Following index is advanced for each new scan to find cross cert
  1172. // distribution points to resync
  1173. DWORD m_dwCrossCertDPResyncIndex;
  1174. //
  1175. // AuthRoot Auto Update Info. Created first time we have a partial chain
  1176. // or a untrusted root and auto update has been enabled.
  1177. //
  1178. PAUTH_ROOT_AUTO_UPDATE_INFO m_pAuthRootAutoUpdateInfo;
  1179. };
  1180. //+===========================================================================
  1181. // CCertObject inline methods
  1182. //============================================================================
  1183. //+---------------------------------------------------------------------------
  1184. //
  1185. // Member: CCertObject::ObjectType, public
  1186. //
  1187. // Synopsis: return the object type
  1188. //
  1189. //----------------------------------------------------------------------------
  1190. inline DWORD
  1191. CCertObject::ObjectType ()
  1192. {
  1193. return( m_dwObjectType );
  1194. }
  1195. //+---------------------------------------------------------------------------
  1196. //
  1197. // Member: CCertObject::AddRef, public
  1198. //
  1199. // Synopsis: add a reference to the certificate object
  1200. //
  1201. //----------------------------------------------------------------------------
  1202. inline VOID
  1203. CCertObject::AddRef ()
  1204. {
  1205. InterlockedIncrement( &m_cRefs );
  1206. }
  1207. //+---------------------------------------------------------------------------
  1208. //
  1209. // Member: CCertObject::Release, public
  1210. //
  1211. // Synopsis: remove a reference from the certificate object
  1212. //
  1213. //----------------------------------------------------------------------------
  1214. inline VOID
  1215. CCertObject::Release ()
  1216. {
  1217. if ( InterlockedDecrement( &m_cRefs ) == 0 )
  1218. {
  1219. delete this;
  1220. }
  1221. }
  1222. //+---------------------------------------------------------------------------
  1223. //
  1224. // Member: CCertObject::ChainEngine, public
  1225. //
  1226. // Synopsis: return the chain engine object
  1227. //
  1228. //----------------------------------------------------------------------------
  1229. inline PCCERTCHAINENGINE
  1230. CCertObject::ChainEngine ()
  1231. {
  1232. return( m_pChainEngine );
  1233. }
  1234. //+---------------------------------------------------------------------------
  1235. //
  1236. // Member: CCertObject::IssuerMatchFlags, public
  1237. //
  1238. // Synopsis: return the issuer match flags
  1239. //
  1240. //----------------------------------------------------------------------------
  1241. inline DWORD
  1242. CCertObject::IssuerMatchFlags ()
  1243. {
  1244. return( m_dwIssuerMatchFlags );
  1245. }
  1246. //+---------------------------------------------------------------------------
  1247. //
  1248. // Member: CCertObject::CachedMatchFlags, public
  1249. //
  1250. // Synopsis: return the cached match flags
  1251. //
  1252. //----------------------------------------------------------------------------
  1253. inline DWORD
  1254. CCertObject::CachedMatchFlags ()
  1255. {
  1256. return( m_dwCachedMatchFlags );
  1257. }
  1258. //+---------------------------------------------------------------------------
  1259. //
  1260. // Member: CCertObject::IssuerStatusFlags, public
  1261. //
  1262. // Synopsis: return the issuer status flags
  1263. //
  1264. //----------------------------------------------------------------------------
  1265. inline DWORD
  1266. CCertObject::IssuerStatusFlags ()
  1267. {
  1268. return( m_dwIssuerStatusFlags );
  1269. }
  1270. //+---------------------------------------------------------------------------
  1271. //
  1272. // Member: CCertObject::OrIssuerStatusFlags, public
  1273. //
  1274. // Synopsis: 'or' bits into the issuer status flags.
  1275. //
  1276. //----------------------------------------------------------------------------
  1277. inline VOID
  1278. CCertObject::OrIssuerStatusFlags(
  1279. IN DWORD dwFlags
  1280. )
  1281. {
  1282. m_dwIssuerStatusFlags |= dwFlags;
  1283. }
  1284. //+---------------------------------------------------------------------------
  1285. //
  1286. // Member: CCertObject::OrCachedMatchFlags, public
  1287. //
  1288. // Synopsis: 'or' bits into the cached match flags
  1289. //
  1290. //
  1291. //----------------------------------------------------------------------------
  1292. inline VOID
  1293. CCertObject::OrCachedMatchFlags(
  1294. IN DWORD dwFlags
  1295. )
  1296. {
  1297. m_dwCachedMatchFlags |= dwFlags;
  1298. }
  1299. //+---------------------------------------------------------------------------
  1300. //
  1301. // Member: CCertObject::InfoFlags, public
  1302. //
  1303. // Synopsis: return the misc info flags
  1304. //
  1305. //----------------------------------------------------------------------------
  1306. inline DWORD
  1307. CCertObject::InfoFlags ()
  1308. {
  1309. return( m_dwInfoFlags );
  1310. }
  1311. //+---------------------------------------------------------------------------
  1312. //
  1313. // Member: CCertObject::NextCtlCacheEntry, public
  1314. //
  1315. // Synopsis: return the next entry, if pEntry == NULL the first entry
  1316. // is returned
  1317. //
  1318. //----------------------------------------------------------------------------
  1319. inline PCERT_OBJECT_CTL_CACHE_ENTRY
  1320. CCertObject::NextCtlCacheEntry(
  1321. IN PCERT_OBJECT_CTL_CACHE_ENTRY pEntry
  1322. )
  1323. {
  1324. if (NULL == pEntry)
  1325. return m_pCtlCacheHead;
  1326. else
  1327. return pEntry->pNext;
  1328. }
  1329. //+---------------------------------------------------------------------------
  1330. //
  1331. // Member: CCertObject::InsertCtlCacheEntry, public
  1332. //
  1333. // Synopsis: insert an entry into the Ctl cache
  1334. //
  1335. //----------------------------------------------------------------------------
  1336. inline VOID
  1337. CCertObject::InsertCtlCacheEntry(
  1338. IN PCERT_OBJECT_CTL_CACHE_ENTRY pEntry
  1339. )
  1340. {
  1341. pEntry->pNext = m_pCtlCacheHead;
  1342. m_pCtlCacheHead = pEntry;
  1343. }
  1344. //+---------------------------------------------------------------------------
  1345. //
  1346. // Member: CCertObject::CertContext, public
  1347. //
  1348. // Synopsis: return the certificate context
  1349. //
  1350. //----------------------------------------------------------------------------
  1351. inline PCCERT_CONTEXT
  1352. CCertObject::CertContext ()
  1353. {
  1354. return( m_pCertContext );
  1355. }
  1356. //+---------------------------------------------------------------------------
  1357. //
  1358. // Member: CCertObject::PoliciesInfo, public
  1359. //
  1360. // Synopsis: return pointer to the policies and usage info
  1361. //
  1362. //----------------------------------------------------------------------------
  1363. inline PCHAIN_POLICIES_INFO
  1364. CCertObject::PoliciesInfo ()
  1365. {
  1366. return( &m_PoliciesInfo );
  1367. }
  1368. //+---------------------------------------------------------------------------
  1369. //
  1370. // Member: CCertObject::BasicConstraintsInfo, public
  1371. //
  1372. // Synopsis: return the basic constraints info pointer
  1373. //
  1374. //----------------------------------------------------------------------------
  1375. inline PCERT_BASIC_CONSTRAINTS2_INFO
  1376. CCertObject::BasicConstraintsInfo ()
  1377. {
  1378. return( m_pBasicConstraintsInfo );
  1379. }
  1380. //+---------------------------------------------------------------------------
  1381. //
  1382. // Member: CCertObject::KeyUsage, public
  1383. //
  1384. // Synopsis: return the key usage pointer
  1385. //
  1386. //----------------------------------------------------------------------------
  1387. inline PCRYPT_BIT_BLOB
  1388. CCertObject::KeyUsage ()
  1389. {
  1390. return( m_pKeyUsage );
  1391. }
  1392. //+---------------------------------------------------------------------------
  1393. //
  1394. // Member: CCertObject::IssuerNameConstraintsInfo, public
  1395. //
  1396. // Synopsis: return the issuer name constraints info pointer
  1397. //
  1398. //----------------------------------------------------------------------------
  1399. inline PCERT_NAME_CONSTRAINTS_INFO
  1400. CCertObject::IssuerNameConstraintsInfo ()
  1401. {
  1402. return( m_pIssuerNameConstraintsInfo );
  1403. }
  1404. //+---------------------------------------------------------------------------
  1405. //
  1406. // Member: CCertObject::AuthorityKeyIdentifier, public
  1407. //
  1408. // Synopsis: return the issuer authority key identifier information
  1409. //
  1410. //----------------------------------------------------------------------------
  1411. inline PCERT_AUTHORITY_KEY_ID_INFO
  1412. CCertObject::AuthorityKeyIdentifier ()
  1413. {
  1414. return( m_pAuthKeyIdentifier );
  1415. }
  1416. //+---------------------------------------------------------------------------
  1417. //
  1418. // Member: CCertObject::CertHash, public
  1419. //
  1420. // Synopsis: return the certificate hash
  1421. //
  1422. //----------------------------------------------------------------------------
  1423. inline LPBYTE
  1424. CCertObject::CertHash ()
  1425. {
  1426. return( m_rgbCertHash );
  1427. }
  1428. //+---------------------------------------------------------------------------
  1429. //
  1430. // Member: CCertObject::KeyIdentifierSize, public
  1431. //
  1432. // Synopsis: return the key identifier blob size
  1433. //
  1434. //----------------------------------------------------------------------------
  1435. inline DWORD
  1436. CCertObject::KeyIdentifierSize ()
  1437. {
  1438. return( m_cbKeyIdentifier );
  1439. }
  1440. //+---------------------------------------------------------------------------
  1441. //
  1442. // Member: CCertObject::KeyIdentifier, public
  1443. //
  1444. // Synopsis: return the key identifier
  1445. //
  1446. //----------------------------------------------------------------------------
  1447. inline LPBYTE
  1448. CCertObject::KeyIdentifier ()
  1449. {
  1450. return( m_pbKeyIdentifier );
  1451. }
  1452. //+---------------------------------------------------------------------------
  1453. //
  1454. // Member: CCertObject::PublicKeyHash, public
  1455. //
  1456. // Synopsis: return the cert's public key hash
  1457. //
  1458. //----------------------------------------------------------------------------
  1459. inline LPBYTE
  1460. CCertObject::PublicKeyHash ()
  1461. {
  1462. return( m_rgbPublicKeyHash );
  1463. }
  1464. //+---------------------------------------------------------------------------
  1465. //
  1466. // Member: CCertObject::IssuerPublicKeyHash, public
  1467. //
  1468. // Synopsis: return the public key hash of the cert's issuer
  1469. //
  1470. //----------------------------------------------------------------------------
  1471. inline LPBYTE
  1472. CCertObject::IssuerPublicKeyHash ()
  1473. {
  1474. return( m_rgbIssuerPublicKeyHash );
  1475. }
  1476. //+---------------------------------------------------------------------------
  1477. //
  1478. // Member: CCertObject::HashIndexEntry, public
  1479. //
  1480. // Synopsis: return the hash index entry
  1481. //
  1482. //----------------------------------------------------------------------------
  1483. inline HLRUENTRY
  1484. CCertObject::HashIndexEntry ()
  1485. {
  1486. return( m_hHashEntry );
  1487. }
  1488. //+---------------------------------------------------------------------------
  1489. //
  1490. // Member: CCertObject::IdentifierIndexEntry, public
  1491. //
  1492. // Synopsis: return the identifier index entry
  1493. //
  1494. //----------------------------------------------------------------------------
  1495. inline HLRUENTRY
  1496. CCertObject::IdentifierIndexEntry ()
  1497. {
  1498. return( m_hIdentifierEntry );
  1499. }
  1500. //+---------------------------------------------------------------------------
  1501. //
  1502. // Member: CCertObject::SubjectNameIndexEntry, public
  1503. //
  1504. // Synopsis: return the subject name index entry
  1505. //
  1506. //----------------------------------------------------------------------------
  1507. inline HLRUENTRY
  1508. CCertObject::SubjectNameIndexEntry ()
  1509. {
  1510. return( m_hSubjectNameEntry );
  1511. }
  1512. //+---------------------------------------------------------------------------
  1513. //
  1514. // Member: CCertObject::KeyIdIndexEntry, public
  1515. //
  1516. // Synopsis: return the key identifier index entry
  1517. //
  1518. //----------------------------------------------------------------------------
  1519. inline HLRUENTRY
  1520. CCertObject::KeyIdIndexEntry ()
  1521. {
  1522. return( m_hKeyIdEntry );
  1523. }
  1524. //+---------------------------------------------------------------------------
  1525. //
  1526. // Member: CCertObject::PublicKeyHashIndexEntry, public
  1527. //
  1528. // Synopsis: return the public key hash index entry
  1529. //
  1530. //----------------------------------------------------------------------------
  1531. inline HLRUENTRY
  1532. CCertObject::PublicKeyHashIndexEntry ()
  1533. {
  1534. return( m_hPublicKeyHashEntry );
  1535. }
  1536. //+---------------------------------------------------------------------------
  1537. //
  1538. // Member: CCertObject::EndHashIndexEntry, public
  1539. //
  1540. // Synopsis: return the hash index entry
  1541. //
  1542. //----------------------------------------------------------------------------
  1543. inline HLRUENTRY
  1544. CCertObject::EndHashIndexEntry ()
  1545. {
  1546. return( m_hEndHashEntry );
  1547. }
  1548. //+---------------------------------------------------------------------------
  1549. //
  1550. // Member: CChainPathObject::CertObject, public
  1551. //
  1552. // Synopsis: returns the cert object
  1553. //
  1554. //----------------------------------------------------------------------------
  1555. inline PCCERTOBJECT
  1556. CChainPathObject::CertObject ()
  1557. {
  1558. return( m_pCertObject );
  1559. }
  1560. //+---------------------------------------------------------------------------
  1561. //
  1562. // Member: CChainPathObject::Pass1Quality, public
  1563. //
  1564. // Synopsis: return the quality value determined during the first pass
  1565. //
  1566. //----------------------------------------------------------------------------
  1567. inline DWORD
  1568. CChainPathObject::Pass1Quality ()
  1569. {
  1570. return( m_dwPass1Quality );
  1571. }
  1572. //+---------------------------------------------------------------------------
  1573. //
  1574. // Member: CChainPathObject::SetPass1Quality, public
  1575. //
  1576. // Synopsis: set the first pass quality value
  1577. //
  1578. //----------------------------------------------------------------------------
  1579. inline VOID
  1580. CChainPathObject::SetPass1Quality (IN DWORD dwQuality)
  1581. {
  1582. m_dwPass1Quality = dwQuality;
  1583. }
  1584. //+---------------------------------------------------------------------------
  1585. //
  1586. // Member: CChainPathObject::IsCompleted, public
  1587. //
  1588. // Synopsis: returns TRUE if we have completed object initialization and
  1589. // the addition of all issuers. FALSE normally indicates a
  1590. // cyclic issuer.
  1591. //
  1592. //----------------------------------------------------------------------------
  1593. inline BOOL
  1594. CChainPathObject::IsCompleted ()
  1595. {
  1596. return m_fCompleted;
  1597. }
  1598. //+---------------------------------------------------------------------------
  1599. //
  1600. // Member: CChainPathObject::HasAdditionalStatus, public
  1601. //
  1602. // Synopsis: returns HasAdditionalStatus flag value
  1603. //
  1604. //----------------------------------------------------------------------------
  1605. inline BOOL
  1606. CChainPathObject::HasAdditionalStatus ()
  1607. {
  1608. return( m_fHasAdditionalStatus );
  1609. }
  1610. //+---------------------------------------------------------------------------
  1611. //
  1612. // Member: CChainPathObject::DownPathObject, public
  1613. //
  1614. // Synopsis: returns this object's down path object
  1615. //
  1616. //----------------------------------------------------------------------------
  1617. inline PCCHAINPATHOBJECT
  1618. CChainPathObject::DownPathObject ()
  1619. {
  1620. return( m_pDownPathObject );
  1621. }
  1622. //+---------------------------------------------------------------------------
  1623. //
  1624. // Member: CCertIssuerList::IsEmpty, public
  1625. //
  1626. // Synopsis: is the issuer list empty
  1627. //
  1628. //----------------------------------------------------------------------------
  1629. inline BOOL
  1630. CCertIssuerList::IsEmpty ()
  1631. {
  1632. return( m_pHead == NULL );
  1633. }
  1634. //+---------------------------------------------------------------------------
  1635. //
  1636. // Member: CCertIssuerList::AddElement, public
  1637. //
  1638. // Synopsis: add an element to the list
  1639. //
  1640. //----------------------------------------------------------------------------
  1641. inline VOID
  1642. CCertIssuerList::AddElement (IN PCERT_ISSUER_ELEMENT pElement)
  1643. {
  1644. pElement->pNextElement = m_pHead;
  1645. pElement->pPrevElement = NULL;
  1646. if ( m_pHead != NULL )
  1647. {
  1648. m_pHead->pPrevElement = pElement;
  1649. }
  1650. m_pHead = pElement;
  1651. }
  1652. //+---------------------------------------------------------------------------
  1653. //
  1654. // Member: CCertIssuerList::RemoveElement, public
  1655. //
  1656. // Synopsis: remove an element from the list
  1657. //
  1658. //----------------------------------------------------------------------------
  1659. inline VOID
  1660. CCertIssuerList::RemoveElement (IN PCERT_ISSUER_ELEMENT pElement)
  1661. {
  1662. if ( pElement->pPrevElement != NULL )
  1663. {
  1664. pElement->pPrevElement->pNextElement = pElement->pNextElement;
  1665. }
  1666. if ( pElement->pNextElement != NULL )
  1667. {
  1668. pElement->pNextElement->pPrevElement = pElement->pPrevElement;
  1669. }
  1670. if ( pElement == m_pHead )
  1671. {
  1672. m_pHead = pElement->pNextElement;
  1673. }
  1674. #if DBG
  1675. pElement->pPrevElement = NULL;
  1676. pElement->pNextElement = NULL;
  1677. #endif
  1678. }
  1679. //+---------------------------------------------------------------------------
  1680. //
  1681. // Member: CCertIssuerList::NextElement, public
  1682. //
  1683. // Synopsis: return the next element, if pElement == NULL the first element
  1684. // is returned
  1685. //
  1686. //----------------------------------------------------------------------------
  1687. inline PCERT_ISSUER_ELEMENT
  1688. CCertIssuerList::NextElement (IN PCERT_ISSUER_ELEMENT pElement)
  1689. {
  1690. if ( pElement == NULL )
  1691. {
  1692. return( m_pHead );
  1693. }
  1694. return( pElement->pNextElement );
  1695. }
  1696. //+---------------------------------------------------------------------------
  1697. //
  1698. // Member: CCertObjectCache::HashIndex, public
  1699. //
  1700. // Synopsis: return the hash index
  1701. //
  1702. //----------------------------------------------------------------------------
  1703. inline HLRUCACHE
  1704. CCertObjectCache::HashIndex ()
  1705. {
  1706. return( m_hHashIndex );
  1707. }
  1708. //+---------------------------------------------------------------------------
  1709. //
  1710. // Member: CCertObjectCache::IdentifierIndex, public
  1711. //
  1712. // Synopsis: return the identifier index
  1713. //
  1714. //----------------------------------------------------------------------------
  1715. inline HLRUCACHE
  1716. CCertObjectCache::IdentifierIndex ()
  1717. {
  1718. return( m_hIdentifierIndex );
  1719. }
  1720. //+---------------------------------------------------------------------------
  1721. //
  1722. // Member: CCertObjectCache::SubjectNameIndex, public
  1723. //
  1724. // Synopsis: return the subject name index
  1725. //
  1726. //----------------------------------------------------------------------------
  1727. inline HLRUCACHE
  1728. CCertObjectCache::SubjectNameIndex ()
  1729. {
  1730. return( m_hSubjectNameIndex );
  1731. }
  1732. //+---------------------------------------------------------------------------
  1733. //
  1734. // Member: CCertObjectCache::KeyIdIndex, public
  1735. //
  1736. // Synopsis: return the key identifier index
  1737. //
  1738. //----------------------------------------------------------------------------
  1739. inline HLRUCACHE
  1740. CCertObjectCache::KeyIdIndex ()
  1741. {
  1742. return( m_hKeyIdIndex );
  1743. }
  1744. //+---------------------------------------------------------------------------
  1745. //
  1746. // Member: CCertObjectCache::PublicKeyHashIndex, public
  1747. //
  1748. // Synopsis: return the hash index
  1749. //
  1750. //----------------------------------------------------------------------------
  1751. inline HLRUCACHE
  1752. CCertObjectCache::PublicKeyHashIndex ()
  1753. {
  1754. return( m_hPublicKeyHashIndex );
  1755. }
  1756. //+---------------------------------------------------------------------------
  1757. //
  1758. // Member: CCertObjectCache::EndHashIndex, public
  1759. //
  1760. // Synopsis: return the end hash index
  1761. //
  1762. //----------------------------------------------------------------------------
  1763. inline HLRUCACHE
  1764. CCertObjectCache::EndHashIndex ()
  1765. {
  1766. return( m_hEndHashIndex );
  1767. }
  1768. //+---------------------------------------------------------------------------
  1769. //
  1770. // Member: CCertObjectCache::FlushObjects, public
  1771. //
  1772. // Synopsis: flush the cache of issuer and end objects
  1773. //
  1774. //----------------------------------------------------------------------------
  1775. inline VOID
  1776. CCertObjectCache::FlushObjects (IN PCCHAINCALLCONTEXT pCallContext)
  1777. {
  1778. I_CryptFlushLruCache( m_hHashIndex, 0, pCallContext );
  1779. I_CryptFlushLruCache( m_hEndHashIndex, 0, pCallContext );
  1780. }
  1781. //+---------------------------------------------------------------------------
  1782. //
  1783. // Member: CCertChainEngine::LockEngine, public
  1784. //
  1785. // Synopsis: acquire the engine lock
  1786. //
  1787. //----------------------------------------------------------------------------
  1788. inline VOID
  1789. CCertChainEngine::LockEngine ()
  1790. {
  1791. EnterCriticalSection( &m_Lock );
  1792. }
  1793. //+---------------------------------------------------------------------------
  1794. //
  1795. // Member: CCertChainEngine::UnlockEngine, public
  1796. //
  1797. // Synopsis: release the engine lock
  1798. //
  1799. //----------------------------------------------------------------------------
  1800. inline VOID
  1801. CCertChainEngine::UnlockEngine ()
  1802. {
  1803. LeaveCriticalSection( &m_Lock );
  1804. }
  1805. //+---------------------------------------------------------------------------
  1806. //
  1807. // Member: CCertChainEngine::AddRef, public
  1808. //
  1809. // Synopsis: increment the reference count
  1810. //
  1811. //----------------------------------------------------------------------------
  1812. inline VOID
  1813. CCertChainEngine::AddRef ()
  1814. {
  1815. InterlockedIncrement( &m_cRefs );
  1816. }
  1817. //+---------------------------------------------------------------------------
  1818. //
  1819. // Member: CCertChainEngine::Release, public
  1820. //
  1821. // Synopsis: decrement the reference count
  1822. //
  1823. //----------------------------------------------------------------------------
  1824. inline VOID
  1825. CCertChainEngine::Release ()
  1826. {
  1827. if ( InterlockedDecrement( &m_cRefs ) == 0 )
  1828. {
  1829. delete this;
  1830. }
  1831. }
  1832. //+---------------------------------------------------------------------------
  1833. //
  1834. // Member: CCertChainEngine::CertObjectCache, public
  1835. //
  1836. // Synopsis: return the certificate object cache
  1837. //
  1838. //----------------------------------------------------------------------------
  1839. inline PCCERTOBJECTCACHE
  1840. CCertChainEngine::CertObjectCache ()
  1841. {
  1842. return( m_pCertObjectCache );
  1843. }
  1844. //+---------------------------------------------------------------------------
  1845. //
  1846. // Member: CCertChainEngine::SSCtlObjectCache, public
  1847. //
  1848. // Synopsis: return the self signed certificate trust list object cache
  1849. //
  1850. //----------------------------------------------------------------------------
  1851. inline PCSSCTLOBJECTCACHE
  1852. CCertChainEngine::SSCtlObjectCache ()
  1853. {
  1854. return( m_pSSCtlObjectCache );
  1855. }
  1856. //+---------------------------------------------------------------------------
  1857. //
  1858. // Member: CCertChainEngine::RootStore, public
  1859. //
  1860. // Synopsis: return the configured root store
  1861. //
  1862. //----------------------------------------------------------------------------
  1863. inline HCERTSTORE
  1864. CCertChainEngine::RootStore ()
  1865. {
  1866. return( m_hRootStore );
  1867. }
  1868. //+---------------------------------------------------------------------------
  1869. //
  1870. // Member: CCertChainEngine::RealRootStore, public
  1871. //
  1872. // Synopsis: return the real root store
  1873. //
  1874. //----------------------------------------------------------------------------
  1875. inline HCERTSTORE
  1876. CCertChainEngine::RealRootStore ()
  1877. {
  1878. return( m_hRealRootStore );
  1879. }
  1880. //+---------------------------------------------------------------------------
  1881. //
  1882. // Member: CCertChainEngine::TrustStore, public
  1883. //
  1884. // Synopsis: return the configured trust store
  1885. //
  1886. //----------------------------------------------------------------------------
  1887. inline HCERTSTORE
  1888. CCertChainEngine::TrustStore ()
  1889. {
  1890. return( m_hTrustStore );
  1891. }
  1892. //+---------------------------------------------------------------------------
  1893. //
  1894. // Member: CCertChainEngine::OtherStore, public
  1895. //
  1896. // Synopsis: return the configured other store
  1897. //
  1898. //----------------------------------------------------------------------------
  1899. inline HCERTSTORE
  1900. CCertChainEngine::OtherStore ()
  1901. {
  1902. return( m_hOtherStore );
  1903. }
  1904. //+---------------------------------------------------------------------------
  1905. //
  1906. // Member: CCertChainEngine::CAStore, public
  1907. //
  1908. // Synopsis: return the opened CA store, NOTE: this could be NULL!
  1909. //
  1910. //----------------------------------------------------------------------------
  1911. inline HCERTSTORE
  1912. CCertChainEngine::CAStore ()
  1913. {
  1914. return( m_hCAStore );
  1915. }
  1916. //+---------------------------------------------------------------------------
  1917. //
  1918. // Member: CCertChainEngine::OpenTrustStore, public
  1919. //
  1920. // Synopsis: open's the engine's HKLM or HKCU "trust" store.
  1921. // Caller must close.
  1922. //
  1923. //----------------------------------------------------------------------------
  1924. inline HCERTSTORE
  1925. CCertChainEngine::OpenTrustStore ()
  1926. {
  1927. DWORD dwStoreFlags;
  1928. if ( m_dwFlags & CERT_CHAIN_USE_LOCAL_MACHINE_STORE )
  1929. {
  1930. dwStoreFlags = CERT_SYSTEM_STORE_LOCAL_MACHINE;
  1931. }
  1932. else
  1933. {
  1934. dwStoreFlags = CERT_SYSTEM_STORE_CURRENT_USER;
  1935. }
  1936. return CertOpenStore(
  1937. CERT_STORE_PROV_SYSTEM_W,
  1938. X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  1939. NULL,
  1940. dwStoreFlags |
  1941. CERT_STORE_SHARE_CONTEXT_FLAG |
  1942. CERT_STORE_SHARE_STORE_FLAG |
  1943. CERT_STORE_MAXIMUM_ALLOWED_FLAG,
  1944. L"trust"
  1945. );
  1946. }
  1947. //+---------------------------------------------------------------------------
  1948. //
  1949. // Member: CCertChainEngine::UrlRetrievalTimeout, public
  1950. //
  1951. // Synopsis: return the engine's UrlRetrievalTimeout
  1952. //
  1953. //----------------------------------------------------------------------------
  1954. inline DWORD
  1955. CCertChainEngine::UrlRetrievalTimeout ()
  1956. {
  1957. return( m_dwUrlRetrievalTimeout );
  1958. }
  1959. //+---------------------------------------------------------------------------
  1960. //
  1961. // Member: CCertChainEngine::HasDefaultUrlRetrievalTimeout, public
  1962. //
  1963. // Synopsis: returns TRUE if the engine is using the default timeout
  1964. //
  1965. //----------------------------------------------------------------------------
  1966. inline BOOL
  1967. CCertChainEngine::HasDefaultUrlRetrievalTimeout ()
  1968. {
  1969. return( m_fDefaultUrlRetrievalTimeout );
  1970. }
  1971. //+---------------------------------------------------------------------------
  1972. //
  1973. // Member: CCertChainEngine::Flags, public
  1974. //
  1975. // Synopsis: return the engine's flags
  1976. //
  1977. //----------------------------------------------------------------------------
  1978. inline DWORD
  1979. CCertChainEngine::Flags ()
  1980. {
  1981. return( m_dwFlags );
  1982. }
  1983. //+---------------------------------------------------------------------------
  1984. //
  1985. // Member: CCertChainEngine::TouchEngineCount, public
  1986. //
  1987. // Synopsis: return the engine's touch count
  1988. //
  1989. //----------------------------------------------------------------------------
  1990. inline DWORD
  1991. CCertChainEngine::TouchEngineCount ()
  1992. {
  1993. return( m_dwTouchEngineCount );
  1994. }
  1995. //+---------------------------------------------------------------------------
  1996. //
  1997. // Member: CCertChainEngine::IncrementTouchEngineCount, public
  1998. //
  1999. // Synopsis: increment and return the engine's touch count
  2000. //
  2001. //----------------------------------------------------------------------------
  2002. inline DWORD
  2003. CCertChainEngine::IncrementTouchEngineCount ()
  2004. {
  2005. return( ++m_dwTouchEngineCount );
  2006. }
  2007. //+---------------------------------------------------------------------------
  2008. //
  2009. // Member: CCertChainEngine::AuthRootAutoUpdateInfo, public
  2010. //
  2011. // Synopsis: returns pointer to the engine's AuthRoot Auto Update Info
  2012. //
  2013. //----------------------------------------------------------------------------
  2014. inline PAUTH_ROOT_AUTO_UPDATE_INFO
  2015. CCertChainEngine::AuthRootAutoUpdateInfo()
  2016. {
  2017. return m_pAuthRootAutoUpdateInfo;
  2018. }
  2019. //+===========================================================================
  2020. // CCertObject helper functions
  2021. //============================================================================
  2022. BOOL WINAPI
  2023. ChainCreateCertObject (
  2024. IN DWORD dwObjectType,
  2025. IN PCCHAINCALLCONTEXT pCallContext,
  2026. IN PCCERT_CONTEXT pCertContext,
  2027. IN OPTIONAL LPBYTE pbCertHash,
  2028. OUT PCCERTOBJECT *ppCertObject
  2029. );
  2030. BOOL WINAPI
  2031. ChainFillCertObjectCtlCacheEnumFn(
  2032. IN LPVOID pvParameter,
  2033. IN PCSSCTLOBJECT pSSCtlObject
  2034. );
  2035. VOID WINAPI
  2036. ChainFreeCertObjectCtlCache(
  2037. IN PCERT_OBJECT_CTL_CACHE_ENTRY pCtlCacheHead
  2038. );
  2039. LPVOID WINAPI
  2040. ChainAllocAndDecodeObject(
  2041. IN LPCSTR lpszStructType,
  2042. IN const BYTE *pbEncoded,
  2043. IN DWORD cbEncoded
  2044. );
  2045. VOID WINAPI
  2046. ChainGetIssuerMatchInfo (
  2047. IN PCCERT_CONTEXT pCertContext,
  2048. OUT DWORD *pdwIssuerMatchFlags,
  2049. OUT PCERT_AUTHORITY_KEY_ID_INFO* ppAuthKeyIdentifier
  2050. );
  2051. BOOL WINAPI
  2052. ChainConvertAuthKeyIdentifierFromV2ToV1 (
  2053. IN PCERT_AUTHORITY_KEY_ID2_INFO pAuthKeyIdentifier2,
  2054. OUT PCERT_AUTHORITY_KEY_ID_INFO* ppAuthKeyIdentifier
  2055. );
  2056. VOID WINAPI
  2057. ChainFreeAuthorityKeyIdentifier (
  2058. IN PCERT_AUTHORITY_KEY_ID_INFO pAuthKeyIdInfo
  2059. );
  2060. VOID WINAPI
  2061. ChainProcessSpecialOrDuplicateOIDsInUsage (
  2062. IN OUT PCERT_ENHKEY_USAGE *ppUsage,
  2063. IN OUT DWORD *pdwFlags
  2064. );
  2065. VOID WINAPI
  2066. ChainConvertPoliciesToUsage (
  2067. IN PCERT_POLICIES_INFO pPolicy,
  2068. IN OUT DWORD *pdwFlags,
  2069. OUT PCERT_ENHKEY_USAGE *ppUsage
  2070. );
  2071. VOID WINAPI
  2072. ChainRemoveDuplicatePolicyMappings (
  2073. IN OUT PCERT_POLICY_MAPPINGS_INFO pInfo
  2074. );
  2075. VOID WINAPI
  2076. ChainGetPoliciesInfo (
  2077. IN PCCERT_CONTEXT pCertContext,
  2078. IN OUT PCHAIN_POLICIES_INFO pPoliciesInfo
  2079. );
  2080. VOID WINAPI
  2081. ChainFreePoliciesInfo (
  2082. IN OUT PCHAIN_POLICIES_INFO pPoliciesInfo
  2083. );
  2084. BOOL WINAPI
  2085. ChainGetBasicConstraintsInfo (
  2086. IN PCCERT_CONTEXT pCertContext,
  2087. OUT PCERT_BASIC_CONSTRAINTS2_INFO *ppInfo
  2088. );
  2089. VOID WINAPI
  2090. ChainFreeBasicConstraintsInfo (
  2091. IN OUT PCERT_BASIC_CONSTRAINTS2_INFO pInfo
  2092. );
  2093. BOOL WINAPI
  2094. ChainGetKeyUsage (
  2095. IN PCCERT_CONTEXT pCertContext,
  2096. OUT PCRYPT_BIT_BLOB *ppKeyUsage
  2097. );
  2098. VOID WINAPI
  2099. ChainFreeKeyUsage (
  2100. IN OUT PCRYPT_BIT_BLOB pKeyUsage
  2101. );
  2102. VOID WINAPI
  2103. ChainGetSelfSignedStatus (
  2104. IN PCCHAINCALLCONTEXT pCallContext,
  2105. IN PCCERTOBJECT pCertObject,
  2106. IN OUT DWORD *pdwIssuerStatusFlags
  2107. );
  2108. VOID WINAPI
  2109. ChainGetRootStoreStatus (
  2110. IN HCERTSTORE hRoot,
  2111. IN HCERTSTORE hRealRoot,
  2112. IN BYTE rgbCertHash[ CHAINHASHLEN ],
  2113. IN OUT DWORD *pdwIssuerStatusFlags
  2114. );
  2115. //+===========================================================================
  2116. // CCertObjectCache helper functions
  2117. //============================================================================
  2118. BOOL WINAPI
  2119. ChainCreateCertificateObjectCache (
  2120. IN DWORD MaxIndexEntries,
  2121. OUT PCCERTOBJECTCACHE* ppCertObjectCache
  2122. );
  2123. VOID WINAPI
  2124. ChainFreeCertificateObjectCache (
  2125. IN PCCERTOBJECTCACHE pCertObjectCache
  2126. );
  2127. //
  2128. // Issuer Certificate Object Cache Primary Index Entry Removal Notification
  2129. //
  2130. // This should remove the relevant entries
  2131. // from the other indexes and release the reference on the certificate object
  2132. // maintained by the primary index.
  2133. //
  2134. VOID WINAPI
  2135. CertObjectCacheOnRemovalFromPrimaryIndex (
  2136. IN LPVOID pv,
  2137. IN LPVOID pvRemovalContext
  2138. );
  2139. //
  2140. // End Certificate Object Cache Entry Removal Notification
  2141. //
  2142. VOID WINAPI
  2143. CertObjectCacheOnRemovalFromEndHashIndex (
  2144. IN LPVOID pv,
  2145. IN LPVOID pvRemovalContext
  2146. );
  2147. //
  2148. // Certificate Object Cache Identifier Hashing Functions
  2149. //
  2150. DWORD WINAPI
  2151. CertObjectCacheHashMd5Identifier (
  2152. IN PCRYPT_DATA_BLOB pIdentifier
  2153. );
  2154. DWORD WINAPI
  2155. CertObjectCacheHashNameIdentifier (
  2156. IN PCRYPT_DATA_BLOB pIdentifier
  2157. );
  2158. VOID WINAPI
  2159. ChainCreateCertificateObjectIdentifier (
  2160. IN PCERT_NAME_BLOB pIssuer,
  2161. IN PCRYPT_INTEGER_BLOB pSerialNumber,
  2162. OUT CERT_OBJECT_IDENTIFIER ObjectIdentifier
  2163. );
  2164. //+===========================================================================
  2165. // CChainPathObject helper functions
  2166. //============================================================================
  2167. BOOL WINAPI
  2168. ChainCreatePathObject (
  2169. IN PCCHAINCALLCONTEXT pCallContext,
  2170. IN PCCERTOBJECT pCertObject,
  2171. IN OPTIONAL HCERTSTORE hAdditionalStore,
  2172. OUT PCCHAINPATHOBJECT *ppPathObject
  2173. );
  2174. BOOL WINAPI
  2175. ChainCreateCyclicPathObject (
  2176. IN PCCHAINCALLCONTEXT pCallContext,
  2177. IN PCCHAINPATHOBJECT pPathObject,
  2178. OUT PCCHAINPATHOBJECT *ppCyclicPathObject
  2179. );
  2180. LPSTR WINAPI
  2181. ChainAllocAndCopyOID (
  2182. IN LPSTR pszSrcOID
  2183. );
  2184. VOID WINAPI
  2185. ChainFreeOID (
  2186. IN OUT LPSTR pszOID
  2187. );
  2188. BOOL WINAPI
  2189. ChainAllocAndCopyUsage (
  2190. IN PCERT_ENHKEY_USAGE pSrcUsage,
  2191. OUT PCERT_ENHKEY_USAGE *ppDstUsage
  2192. );
  2193. VOID WINAPI
  2194. ChainFreeUsage (
  2195. IN OUT PCERT_ENHKEY_USAGE pUsage
  2196. );
  2197. BOOL WINAPI
  2198. ChainIsOIDInUsage (
  2199. IN LPSTR pszOID,
  2200. IN PCERT_ENHKEY_USAGE pUsage
  2201. );
  2202. VOID WINAPI
  2203. ChainIntersectUsages (
  2204. IN PCERT_ENHKEY_USAGE pCertUsage,
  2205. IN OUT PCERT_ENHKEY_USAGE pRestrictedUsage
  2206. );
  2207. VOID WINAPI
  2208. ChainFreeAndClearRestrictedUsageInfo(
  2209. IN OUT PCHAIN_RESTRICTED_USAGE_INFO pInfo
  2210. );
  2211. BOOL WINAPI
  2212. ChainCalculateRestrictedUsage (
  2213. IN PCERT_ENHKEY_USAGE pCertUsage,
  2214. IN OPTIONAL PCERT_POLICY_MAPPINGS_INFO pMappings,
  2215. IN OUT PCERT_ENHKEY_USAGE *ppRestrictedUsage,
  2216. IN OUT PCERT_ENHKEY_USAGE *ppMappedUsage,
  2217. IN OUT LPDWORD *ppdwMappedIndex
  2218. );
  2219. VOID WINAPI
  2220. ChainGetUsageStatus (
  2221. IN PCERT_ENHKEY_USAGE pRequestedUsage,
  2222. IN PCERT_ENHKEY_USAGE pAvailableUsage,
  2223. IN DWORD dwMatchType,
  2224. IN OUT PCERT_TRUST_STATUS pStatus
  2225. );
  2226. VOID WINAPI
  2227. ChainOrInStatusBits (
  2228. IN PCERT_TRUST_STATUS pDestStatus,
  2229. IN PCERT_TRUST_STATUS pSourceStatus
  2230. );
  2231. BOOL WINAPI
  2232. ChainGetMatchInfoStatus (
  2233. IN PCCERTOBJECT pIssuerObject,
  2234. IN PCCERTOBJECT pSubjectObject,
  2235. IN OUT DWORD *pdwInfoStatus
  2236. );
  2237. DWORD WINAPI
  2238. ChainGetMatchInfoStatusForNoIssuer (
  2239. IN DWORD dwIssuerMatchFlags
  2240. );
  2241. BOOL WINAPI
  2242. ChainIsValidPubKeyMatchForIssuer (
  2243. IN PCCERTOBJECT pIssuer,
  2244. IN PCCERTOBJECT pSubject
  2245. );
  2246. // Leaves Engine's lock to do signature verification
  2247. BOOL WINAPI
  2248. ChainGetSubjectStatus (
  2249. IN PCCHAINCALLCONTEXT pCallContext,
  2250. IN PCCHAINPATHOBJECT pIssuerPathObject,
  2251. IN PCCHAINPATHOBJECT pSubjectPathObject,
  2252. IN OUT PCERT_TRUST_STATUS pStatus
  2253. );
  2254. VOID WINAPI
  2255. ChainUpdateSummaryStatusByTrustStatus(
  2256. IN OUT PCERT_TRUST_STATUS pSummaryStatus,
  2257. IN PCERT_TRUST_STATUS pTrustStatus
  2258. );
  2259. //+===========================================================================
  2260. // Format and append extended error information helper functions
  2261. //============================================================================
  2262. BOOL WINAPI
  2263. ChainAllocAndEncodeObject(
  2264. IN LPCSTR lpszStructType,
  2265. IN const void *pvStructInfo,
  2266. OUT BYTE **ppbEncoded,
  2267. OUT DWORD *pcbEncoded
  2268. );
  2269. VOID WINAPI
  2270. ChainAppendExtendedErrorInfo(
  2271. IN OUT LPWSTR *ppwszExtErrorInfo,
  2272. IN LPWSTR pwszAppend,
  2273. IN DWORD cchAppend // Includes NULL terminator
  2274. );
  2275. VOID WINAPI
  2276. ChainFormatAndAppendExtendedErrorInfo(
  2277. IN OUT LPWSTR *ppwszExtErrorInfo,
  2278. IN UINT nFormatID,
  2279. ...
  2280. );
  2281. //+===========================================================================
  2282. // Name Constraint helper functions
  2283. //============================================================================
  2284. VOID WINAPI
  2285. ChainRemoveLeadingAndTrailingWhiteSpace(
  2286. IN LPWSTR pwszIn,
  2287. OUT LPWSTR *ppwszOut,
  2288. OUT DWORD *pcchOut
  2289. );
  2290. BOOL WINAPI
  2291. ChainIsRightStringInString(
  2292. IN LPCWSTR pwszRight,
  2293. IN DWORD cchRight,
  2294. IN LPCWSTR pwszString,
  2295. IN DWORD cchString
  2296. );
  2297. BOOL WINAPI
  2298. ChainFixupNameConstraintsUPN(
  2299. IN OUT PCRYPT_OBJID_BLOB pUPN
  2300. );
  2301. BOOL WINAPI
  2302. ChainAllocDecodeAndFixupNameConstraintsDirectoryName(
  2303. IN PCERT_NAME_BLOB pDirName,
  2304. OUT PCERT_NAME_INFO *ppNameInfo
  2305. );
  2306. BOOL WINAPI
  2307. ChainFixupNameConstraintsAltNameEntry(
  2308. IN BOOL fSubjectConstraint,
  2309. IN OUT PCERT_ALT_NAME_ENTRY pEntry
  2310. );
  2311. VOID WINAPI
  2312. ChainFreeNameConstraintsAltNameEntryFixup(
  2313. IN BOOL fSubjectConstraint,
  2314. IN OUT PCERT_ALT_NAME_ENTRY pEntry
  2315. );
  2316. LPWSTR WINAPI
  2317. ChainFormatNameConstraintsAltNameEntryFixup(
  2318. IN PCERT_ALT_NAME_ENTRY pEntry
  2319. );
  2320. VOID WINAPI
  2321. ChainFormatAndAppendNameConstraintsAltNameEntryFixup(
  2322. IN OUT LPWSTR *ppwszExtErrorInfo,
  2323. IN PCERT_ALT_NAME_ENTRY pEntry,
  2324. IN UINT nFormatID,
  2325. IN OPTIONAL DWORD dwSubtreeIndex = 0 // 0 => no subtree parameter
  2326. );
  2327. BOOL WINAPI
  2328. ChainGetIssuerNameConstraintsInfo (
  2329. IN PCCERT_CONTEXT pCertContext,
  2330. IN OUT PCERT_NAME_CONSTRAINTS_INFO *ppInfo
  2331. );
  2332. VOID WINAPI
  2333. ChainFreeIssuerNameConstraintsInfo (
  2334. IN OUT PCERT_NAME_CONSTRAINTS_INFO pInfo
  2335. );
  2336. VOID WINAPI
  2337. ChainGetSubjectNameConstraintsInfo (
  2338. IN PCCERT_CONTEXT pCertContext,
  2339. IN OUT PCHAIN_SUBJECT_NAME_CONSTRAINTS_INFO pSubjectInfo
  2340. );
  2341. VOID WINAPI
  2342. ChainFreeSubjectNameConstraintsInfo (
  2343. IN OUT PCHAIN_SUBJECT_NAME_CONSTRAINTS_INFO pSubjectInfo
  2344. );
  2345. BOOL WINAPI
  2346. ChainCompareNameConstraintsDirectoryName(
  2347. IN PCERT_NAME_INFO pSubjectInfo,
  2348. IN PCERT_NAME_INFO pSubtreeInfo
  2349. );
  2350. BOOL WINAPI
  2351. ChainCompareNameConstraintsIPAddress(
  2352. IN PCRYPT_DATA_BLOB pSubjectIPAddress,
  2353. IN PCRYPT_DATA_BLOB pSubtreeIPAddress
  2354. );
  2355. BOOL WINAPI
  2356. ChainCompareNameConstraintsUPN(
  2357. IN PCRYPT_OBJID_BLOB pSubjectValue,
  2358. IN PCRYPT_OBJID_BLOB pSubtreeValue
  2359. );
  2360. DWORD WINAPI
  2361. ChainCalculateNameConstraintsSubtreeErrorStatusForAltNameEntry(
  2362. IN PCERT_ALT_NAME_ENTRY pSubjectEntry,
  2363. IN BOOL fExcludedSubtree,
  2364. IN DWORD cSubtree,
  2365. IN PCERT_GENERAL_SUBTREE pSubtree,
  2366. IN OUT LPWSTR *ppwszExtErrorInfo
  2367. );
  2368. DWORD WINAPI
  2369. ChainCalculateNameConstraintsErrorStatusForAltNameEntry(
  2370. IN PCERT_ALT_NAME_ENTRY pSubjectEntry,
  2371. IN PCERT_NAME_CONSTRAINTS_INFO pNameConstraintsInfo,
  2372. IN OUT LPWSTR *ppwszExtErrorInfo
  2373. );
  2374. //+===========================================================================
  2375. // CCertIssuerList helper functions
  2376. //============================================================================
  2377. BOOL WINAPI
  2378. ChainCreateIssuerList (
  2379. IN PCCHAINPATHOBJECT pSubject,
  2380. OUT PCCERTISSUERLIST* ppIssuerList
  2381. );
  2382. VOID WINAPI
  2383. ChainFreeIssuerList (
  2384. IN PCCERTISSUERLIST pIssuerList
  2385. );
  2386. VOID WINAPI
  2387. ChainFreeCtlIssuerData (
  2388. IN PCTL_ISSUER_DATA pCtlIssuerData
  2389. );
  2390. //+===========================================================================
  2391. // INTERNAL_CERT_CHAIN_CONTEXT helper functions
  2392. //============================================================================
  2393. VOID WINAPI
  2394. ChainAddRefInternalChainContext (
  2395. IN PINTERNAL_CERT_CHAIN_CONTEXT pChainContext
  2396. );
  2397. VOID WINAPI
  2398. ChainReleaseInternalChainContext (
  2399. IN PINTERNAL_CERT_CHAIN_CONTEXT pChainContext
  2400. );
  2401. VOID WINAPI
  2402. ChainFreeInternalChainContext (
  2403. IN PINTERNAL_CERT_CHAIN_CONTEXT pContext
  2404. );
  2405. VOID
  2406. ChainUpdateEndEntityCertContext(
  2407. IN OUT PINTERNAL_CERT_CHAIN_CONTEXT pChainContext,
  2408. IN OUT PCCERT_CONTEXT pEndCertContext
  2409. );
  2410. //+===========================================================================
  2411. // CERT_REVOCATION_INFO helper functions
  2412. //============================================================================
  2413. VOID WINAPI
  2414. ChainUpdateRevocationInfo (
  2415. IN PCERT_REVOCATION_STATUS pRevStatus,
  2416. IN OUT PCERT_REVOCATION_INFO pRevocationInfo,
  2417. IN OUT PCERT_TRUST_STATUS pTrustStatus
  2418. );
  2419. //+===========================================================================
  2420. // CCertChainEngine helper functions
  2421. //============================================================================
  2422. BOOL WINAPI
  2423. ChainCreateWorldStore (
  2424. IN HCERTSTORE hRoot,
  2425. IN HCERTSTORE hCA,
  2426. IN DWORD cAdditionalStore,
  2427. IN HCERTSTORE* rghAdditionalStore,
  2428. IN DWORD dwStoreFlags,
  2429. OUT HCERTSTORE* phWorld
  2430. );
  2431. BOOL WINAPI
  2432. ChainCreateEngineStore (
  2433. IN HCERTSTORE hRootStore,
  2434. IN HCERTSTORE hTrustStore,
  2435. IN HCERTSTORE hOtherStore,
  2436. IN BOOL fDefaultEngine,
  2437. IN DWORD dwFlags,
  2438. OUT HCERTSTORE* phEngineStore,
  2439. OUT HANDLE* phEngineStoreChangeEvent
  2440. );
  2441. BOOL WINAPI
  2442. ChainIsProperRestrictedRoot (
  2443. IN HCERTSTORE hRealRoot,
  2444. IN HCERTSTORE hRestrictedRoot
  2445. );
  2446. BOOL WINAPI
  2447. ChainCreateCollectionIncludingCtlCertificates (
  2448. IN HCERTSTORE hStore,
  2449. OUT HCERTSTORE* phCollection
  2450. );
  2451. BOOL WINAPI
  2452. ChainCopyToCAStore (
  2453. PCCERTCHAINENGINE pChainEngine,
  2454. HCERTSTORE hStore
  2455. );
  2456. //+===========================================================================
  2457. // URL helper functions
  2458. //============================================================================
  2459. //
  2460. // Cryptnet Thunk Helper API
  2461. //
  2462. typedef BOOL (WINAPI *PFN_GETOBJECTURL) (
  2463. IN LPCSTR pszUrlOid,
  2464. IN LPVOID pvPara,
  2465. IN DWORD dwFlags,
  2466. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  2467. IN OUT DWORD* pcbUrlArray,
  2468. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  2469. IN OUT OPTIONAL DWORD* pcbUrlInfo,
  2470. IN OPTIONAL LPVOID pvReserved
  2471. );
  2472. BOOL WINAPI
  2473. ChainGetObjectUrl (
  2474. IN LPCSTR pszUrlOid,
  2475. IN LPVOID pvPara,
  2476. IN DWORD dwFlags,
  2477. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  2478. IN OUT DWORD* pcbUrlArray,
  2479. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  2480. IN OUT OPTIONAL DWORD* pcbUrlInfo,
  2481. IN OPTIONAL LPVOID pvReserved
  2482. );
  2483. typedef BOOL (WINAPI *PFN_RETRIEVEOBJECTBYURLW) (
  2484. IN LPCWSTR pszUrl,
  2485. IN LPCSTR pszObjectOid,
  2486. IN DWORD dwRetrievalFlags,
  2487. IN DWORD dwTimeout,
  2488. OUT LPVOID* ppvObject,
  2489. IN HCRYPTASYNC hAsyncRetrieve,
  2490. IN PCRYPT_CREDENTIALS pCredentials,
  2491. IN LPVOID pvVerify,
  2492. IN OPTIONAL PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
  2493. );
  2494. BOOL WINAPI
  2495. ChainRetrieveObjectByUrlW (
  2496. IN LPCWSTR pszUrl,
  2497. IN LPCSTR pszObjectOid,
  2498. IN DWORD dwRetrievalFlags,
  2499. IN DWORD dwTimeout,
  2500. OUT LPVOID* ppvObject,
  2501. IN HCRYPTASYNC hAsyncRetrieve,
  2502. IN PCRYPT_CREDENTIALS pCredentials,
  2503. IN LPVOID pvVerify,
  2504. IN OPTIONAL PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
  2505. );
  2506. BOOL WINAPI
  2507. ChainIsConnected();
  2508. BOOL
  2509. WINAPI
  2510. ChainGetHostNameFromUrl (
  2511. IN LPWSTR pwszUrl,
  2512. IN DWORD cchHostName,
  2513. OUT LPWSTR pwszHostName
  2514. );
  2515. HMODULE WINAPI
  2516. ChainGetCryptnetModule ();
  2517. //
  2518. // URL helper
  2519. //
  2520. BOOL WINAPI
  2521. ChainIsFileOrLdapUrl (
  2522. IN LPCWSTR pwszUrl
  2523. );
  2524. //
  2525. // Given the number of unsuccessful attempts to retrieve the Url, returns
  2526. // the number of seconds to wait before the next attempt.
  2527. //
  2528. DWORD
  2529. WINAPI
  2530. ChainGetOfflineUrlDeltaSeconds (
  2531. IN DWORD dwOfflineCnt
  2532. );
  2533. //+===========================================================================
  2534. // AuthRoot Auto Update helper functions (chain.cpp)
  2535. //============================================================================
  2536. PAUTH_ROOT_AUTO_UPDATE_INFO WINAPI
  2537. CreateAuthRootAutoUpdateInfo();
  2538. VOID WINAPI
  2539. FreeAuthRootAutoUpdateInfo(
  2540. IN OUT PAUTH_ROOT_AUTO_UPDATE_INFO pInfo
  2541. );
  2542. BOOL WINAPI
  2543. CreateAuthRootAutoUpdateMatchCaches(
  2544. IN PCCTL_CONTEXT pCtl,
  2545. IN OUT HLRUCACHE rghMatchCache[AUTH_ROOT_MATCH_CNT]
  2546. );
  2547. VOID WINAPI
  2548. FreeAuthRootAutoUpdateMatchCaches(
  2549. IN OUT HLRUCACHE rghMatchCache[AUTH_ROOT_MATCH_CNT]
  2550. );
  2551. #define SHA1_HASH_LEN 20
  2552. #define SHA1_HASH_NAME_LEN (2 * SHA1_HASH_LEN)
  2553. LPWSTR WINAPI
  2554. FormatAuthRootAutoUpdateCertUrl(
  2555. IN BYTE rgbSha1Hash[SHA1_HASH_LEN],
  2556. IN PAUTH_ROOT_AUTO_UPDATE_INFO pInfo
  2557. );
  2558. BOOL WINAPI
  2559. ChainGetAuthRootAutoUpdateStatus (
  2560. IN PCCHAINCALLCONTEXT pCallContext,
  2561. IN PCCERTOBJECT pCertObject,
  2562. IN OUT DWORD *pdwIssuerStatusFlags
  2563. );
  2564. //+===========================================================================
  2565. // AuthRoot Auto Update helper functions (extract.cpp)
  2566. //============================================================================
  2567. PCCTL_CONTEXT WINAPI
  2568. ExtractAuthRootAutoUpdateCtlFromCab (
  2569. IN PCRYPT_BLOB_ARRAY pcbaCab
  2570. );
  2571. #endif