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.

272 lines
8.4 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Microsoft Windows
  3. Copyright (C) Microsoft Corporation, 1995 - 1999.
  4. File: Chain.h
  5. Content: Declaration of CChain.
  6. History: 11-15-99 dsie created
  7. ------------------------------------------------------------------------------*/
  8. #ifndef __CHAIN_H_
  9. #define __CHAIN_H_
  10. #include "Resource.h"
  11. #include "Error.h"
  12. #include "Lock.h"
  13. #include "Debug.h"
  14. //
  15. // Chain policy error status.
  16. //
  17. typedef enum CAPICOM_CHAIN_STATUS
  18. {
  19. CAPICOM_CHAIN_STATUS_OK = 0x00000000,
  20. CAPICOM_CHAIN_STATUS_REVOKED = 0x80092010,
  21. CAPICOM_CHAIN_STATUS_REVOCATION_NO_CHECK = 0x80092012,
  22. CAPICOM_CHAIN_STATUS_REVOCATION_OFFLINE = 0x80092013,
  23. CAPICOM_CHAIN_STATUS_INVALID_BASIC_CONSTRAINTS = 0x80096019,
  24. CAPICOM_CHAIN_STATUS_INVALID_SIGNATURE = 0x80096004,
  25. CAPICOM_CHAIN_STATUS_EXPIRED = 0x800B0101,
  26. CAPICOM_CHAIN_STATUS_NESTED_VALIDITY_PERIOD = 0x800B0102,
  27. CAPICOM_CHAIN_STATUS_UNTRUSTEDROOT = 0x800B0109,
  28. CAPICOM_CHAIN_STATUS_PARTIAL_CHAINING = 0x800B010A,
  29. CAPICOM_CHAIN_STATUS_INVALID_USAGE = 0x800B0110,
  30. CAPICOM_CHAIN_STATUS_INVALID_POLICY = 0x800B0113,
  31. CAPICOM_CHAIN_STATUS_INVALID_NAME = 0x800B0114,
  32. } CAPICOM_CHAIN_STATUS;
  33. ////////////////////////////////////////////////////////////////////////////////
  34. //
  35. // Exported functions.
  36. //
  37. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  38. Function : CreateChainObject
  39. Synopsis : Create and initialize an IChain object by building the chain
  40. of a specified certificate and policy.
  41. Parameter: PCCERT_CONTEXT pCertContext - Pointer to CERT_CONTEXT.
  42. ICertificateStatus * pIStatus - Pointer to ICertificateStatus
  43. object.
  44. HCERTSTORE hAdditionalStore - Additional store handle.
  45. VARIANT_BOOL * pVal - Pointer to VARIANT_BOOL to receive chain
  46. overall validity result.
  47. IChain ** ppIChain - Pointer to pointer to IChain object.
  48. Remark :
  49. ------------------------------------------------------------------------------*/
  50. HRESULT CreateChainObject (PCCERT_CONTEXT pCertContext,
  51. ICertificateStatus * pIStatus,
  52. HCERTSTORE hAdditionalStore,
  53. VARIANT_BOOL * pbResult,
  54. IChain ** ppIChain);
  55. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  56. Function : CreateChainObject
  57. Synopsis : Create and initialize an IChain object by building the chain
  58. of a specified certificate and policy.
  59. Parameter: ICertificate * pICertificate - Poitner to ICertificate.
  60. HCERTSTORE hAdditionalStore - Additional store handle.
  61. VARIANT_BOOL * pVal - Pointer to VARIANT_BOOL to receive chain
  62. overall validity result.
  63. IChain ** ppIChain - Pointer to pointer to IChain object.
  64. Remark :
  65. ------------------------------------------------------------------------------*/
  66. HRESULT CreateChainObject (ICertificate * pICertificate,
  67. HCERTSTORE hAdditionalStore,
  68. VARIANT_BOOL * pbResult,
  69. IChain ** ppIChain);
  70. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  71. Function : CreateChainObject
  72. Synopsis : Create and initialize an IChain object from a built chain.
  73. Parameter: PCCERT_CHAIN_CONTEXT pChainContext - Chain context.
  74. IChain ** ppIChain - Pointer to pointer to IChain object.
  75. Remark :
  76. ------------------------------------------------------------------------------*/
  77. HRESULT CreateChainObject (PCCERT_CHAIN_CONTEXT pChainContext,
  78. IChain ** ppIChain);
  79. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  80. Function : GetChainContext
  81. Synopsis : Return an array of PCCERT_CONTEXT from the chain.
  82. Parameter: IChain * pIChain - Pointer to IChain.
  83. CRYPT_DATA_BLOB * pChainBlob - Pointer to blob to recevie the
  84. size and array of PCERT_CONTEXT
  85. for the chain.
  86. Remark :
  87. ------------------------------------------------------------------------------*/
  88. STDMETHODIMP GetChainContext (IChain * pIChain,
  89. CRYPT_DATA_BLOB * pChainBlob);
  90. ////////////////////////////////////////////////////////////////////////////////
  91. //
  92. // CChain
  93. //
  94. class ATL_NO_VTABLE CChain :
  95. public IChainContext,
  96. public CComObjectRootEx<CComMultiThreadModel>,
  97. public CComCoClass<CChain, &CLSID_Chain>,
  98. public ICAPICOMError<CChain, &IID_IChain2>,
  99. public IDispatchImpl<IChain2, &IID_IChain2, &LIBID_CAPICOM,
  100. CAPICOM_MAJOR_VERSION, CAPICOM_MINOR_VERSION>,
  101. public IObjectSafetyImpl<CChain, INTERFACESAFE_FOR_UNTRUSTED_CALLER |
  102. INTERFACESAFE_FOR_UNTRUSTED_DATA>
  103. {
  104. public:
  105. CChain()
  106. {
  107. m_pUnkMarshaler = NULL;
  108. }
  109. DECLARE_REGISTRY_RESOURCEID(IDR_CHAIN)
  110. DECLARE_GET_CONTROLLING_UNKNOWN()
  111. DECLARE_PROTECT_FINAL_CONSTRUCT()
  112. BEGIN_COM_MAP(CChain)
  113. COM_INTERFACE_ENTRY(IChain)
  114. COM_INTERFACE_ENTRY(IChain2)
  115. COM_INTERFACE_ENTRY(IChainContext)
  116. COM_INTERFACE_ENTRY(IDispatch)
  117. COM_INTERFACE_ENTRY(IObjectSafety)
  118. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  119. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  120. END_COM_MAP()
  121. BEGIN_CATEGORY_MAP(CChain)
  122. IMPLEMENTED_CATEGORY(CATID_SafeForScripting)
  123. IMPLEMENTED_CATEGORY(CATID_SafeForInitializing)
  124. END_CATEGORY_MAP()
  125. HRESULT FinalConstruct()
  126. {
  127. HRESULT hr;
  128. if (FAILED(hr = m_Lock.Initialized()))
  129. {
  130. DebugTrace("Error [%#x]: Critical section could not be created for Chain object.\n", hr);
  131. return hr;
  132. }
  133. m_dwStatus = 0;
  134. m_pChainContext = NULL;
  135. return CoCreateFreeThreadedMarshaler(
  136. GetControllingUnknown(), &m_pUnkMarshaler.p);
  137. }
  138. void FinalRelease()
  139. {
  140. if (m_pChainContext)
  141. {
  142. ::CertFreeCertificateChain(m_pChainContext);
  143. }
  144. m_pUnkMarshaler.Release();
  145. }
  146. CComPtr<IUnknown> m_pUnkMarshaler;
  147. //
  148. // IChain
  149. //
  150. public:
  151. STDMETHOD(get_Certificates)
  152. (/*[out, retval]*/ ICertificates ** pVal);
  153. STDMETHOD(get_Status)
  154. (/*[in, defaultvalue(0)]*/ long Index,
  155. /*[out,retval]*/ long * pVal);
  156. STDMETHOD(Build)
  157. (/*[in]*/ ICertificate * pICertificate,
  158. /*[out, retval]*/ VARIANT_BOOL * pVal);
  159. STDMETHOD(CertificatePolicies)
  160. (/*[out, retval]*/ IOIDs ** pVal);
  161. STDMETHOD(ApplicationPolicies)
  162. (/*[out, retval]*/ IOIDs ** pVal);
  163. STDMETHOD(ExtendedErrorInfo)
  164. (/*[in, defaultvalue(1)]*/ long Index,
  165. /*[out, retval]*/ BSTR * pVal);
  166. //
  167. // Custom interfaces.
  168. //
  169. STDMETHOD(get_ChainContext)
  170. (/*[out, retval]*/ long * pChainContext);
  171. STDMETHOD(put_ChainContext)
  172. (/*[in]*/ long pChainContext);
  173. STDMETHOD(FreeContext)
  174. (/*[in]*/ long pChainContext);
  175. //
  176. // Non COM functions.
  177. //
  178. STDMETHOD(Init)
  179. (PCCERT_CONTEXT pCertContext,
  180. ICertificateStatus * pIStatus,
  181. HCERTSTORE hAdditionalStore,
  182. VARIANT_BOOL * pbResult);
  183. STDMETHOD(Verify)
  184. (CAPICOM_CHECK_FLAG CheckFlag,
  185. CAPICOM_CHAIN_STATUS * pVal);
  186. STDMETHOD(GetContext)
  187. (PCCERT_CHAIN_CONTEXT * ppChainContext);
  188. STDMETHOD(PutContext)
  189. (PCCERT_CHAIN_CONTEXT pChainContext);
  190. private:
  191. CLock m_Lock;
  192. DWORD m_dwStatus;
  193. PCCERT_CHAIN_CONTEXT m_pChainContext;
  194. };
  195. #endif //__CHAIN_H_