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.

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