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.

292 lines
8.5 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Microsoft Windows, Copyright (C) Microsoft Corporation, 2000
  3. File: Certificate.h
  4. Content: Declaration of CCertificate.
  5. History: 11-15-99 dsie created
  6. ------------------------------------------------------------------------------*/
  7. #ifndef __CERTIFICATE_H_
  8. #define __CERTIFICATE_H_
  9. #include "Resource.h"
  10. #include "Error.h"
  11. #include "Lock.h"
  12. #include "Debug.h"
  13. #include "KeyUsage.h"
  14. #include "ExtendedKeyUsage.h"
  15. #include "BasicConstraints.h"
  16. #include "Template.h"
  17. #include "CertificateStatus.h"
  18. #include "PublicKey.h"
  19. #include "PrivateKey.h"
  20. #include "Extensions.h"
  21. #include "ExtendedProperties.h"
  22. ////////////////////////////////////////////////////////////////////////////////
  23. //
  24. // Exported functions.
  25. //
  26. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  27. Function : CreateCertificateObject
  28. Synopsis : Create an ICertificate object.
  29. Parameter: PCCERT_CONTEXT pCertContext - Pointer to CERT_CONTEXT to be used
  30. to initialize the ICertificate
  31. object.
  32. DWORD dwCurrentSafety - Current safety setting.
  33. ICertificate2 ** ppICertificate - Pointer to pointer ICertificate
  34. object.
  35. Remark :
  36. ------------------------------------------------------------------------------*/
  37. HRESULT CreateCertificateObject (PCCERT_CONTEXT pCertContext,
  38. DWORD dwCurrentSafety,
  39. ICertificate2 ** ppICertificate);
  40. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  41. Function : GetCertContext
  42. Synopsis : Return the certificate's PCERT_CONTEXT.
  43. Parameter: ICertificate * pICertificate - Pointer to ICertificate for which
  44. the PCERT_CONTEXT is to be returned.
  45. PCCERT_CONTEXT * ppCertContext - Pointer to PCERT_CONTEXT.
  46. Remark :
  47. ------------------------------------------------------------------------------*/
  48. HRESULT GetCertContext (ICertificate * pICertificate,
  49. PCCERT_CONTEXT * ppCertContext);
  50. ////////////////////////////////////////////////////////////////////////////////
  51. //
  52. // CCertificate
  53. //
  54. class ATL_NO_VTABLE CCertificate :
  55. public ICertContext,
  56. public CComObjectRootEx<CComMultiThreadModel>,
  57. public CComCoClass<CCertificate, &CLSID_Certificate>,
  58. public ICAPICOMError<CCertificate, &IID_ICertificate2>,
  59. public IDispatchImpl<ICertificate2, &IID_ICertificate2, &LIBID_CAPICOM,
  60. CAPICOM_MAJOR_VERSION, CAPICOM_MINOR_VERSION>,
  61. public IObjectSafetyImpl<CCertificate, INTERFACESAFE_FOR_UNTRUSTED_CALLER |
  62. INTERFACESAFE_FOR_UNTRUSTED_DATA>
  63. {
  64. public:
  65. CCertificate()
  66. {
  67. }
  68. DECLARE_REGISTRY_RESOURCEID(IDR_CERTIFICATE)
  69. DECLARE_GET_CONTROLLING_UNKNOWN()
  70. DECLARE_PROTECT_FINAL_CONSTRUCT()
  71. BEGIN_COM_MAP(CCertificate)
  72. COM_INTERFACE_ENTRY(ICertificate)
  73. COM_INTERFACE_ENTRY(ICertificate2)
  74. COM_INTERFACE_ENTRY(ICertContext)
  75. COM_INTERFACE_ENTRY(IDispatch)
  76. COM_INTERFACE_ENTRY(IObjectSafety)
  77. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  78. END_COM_MAP()
  79. BEGIN_CATEGORY_MAP(CCertificate)
  80. IMPLEMENTED_CATEGORY(CATID_SafeForScripting)
  81. IMPLEMENTED_CATEGORY(CATID_SafeForInitializing)
  82. END_CATEGORY_MAP()
  83. HRESULT FinalConstruct()
  84. {
  85. HRESULT hr;
  86. if (FAILED(hr = m_Lock.Initialized()))
  87. {
  88. DebugTrace("Error [%#x]: Critical section could not be created for Certificate object.\n", hr);
  89. return hr;
  90. }
  91. m_pCertContext = NULL;
  92. m_pIKeyUsage = NULL;
  93. m_pIExtendedKeyUsage = NULL;
  94. m_pIBasicConstraints = NULL;
  95. m_pICertificateStatus = NULL;
  96. m_pITemplate = NULL;
  97. m_pIPublicKey = NULL;
  98. m_pIExtensions = NULL;
  99. return S_OK;
  100. }
  101. void FinalRelease()
  102. {
  103. m_pIKeyUsage.Release();
  104. m_pIExtendedKeyUsage.Release();
  105. m_pIBasicConstraints.Release();
  106. m_pICertificateStatus.Release();
  107. m_pITemplate.Release();
  108. m_pIPublicKey.Release();
  109. m_pIExtensions.Release();
  110. if (m_pCertContext)
  111. {
  112. ::CertFreeCertificateContext(m_pCertContext);
  113. }
  114. }
  115. //
  116. // ICertificate
  117. //
  118. public:
  119. //
  120. // CAPICOM v1.0
  121. //
  122. STDMETHOD(Display)();
  123. STDMETHOD(Import)
  124. (/*[in]*/ BSTR EncodedCertificate);
  125. STDMETHOD(Export)
  126. (/*[in, defaultvalue(CAPICOM_ENCODE_BASE64)]*/ CAPICOM_ENCODING_TYPE EncodingType,
  127. /*[out, retval]*/ BSTR * pVal);
  128. STDMETHOD(BasicConstraints)
  129. (/*[out, retval]*/ IBasicConstraints ** pVal);
  130. STDMETHOD(ExtendedKeyUsage)
  131. (/*[out, retval]*/ IExtendedKeyUsage ** pVal);
  132. STDMETHOD(KeyUsage)
  133. (/*[out, retval]*/ IKeyUsage ** pVal);
  134. STDMETHOD(IsValid)
  135. (/*[out, retval]*/ ICertificateStatus ** pVal);
  136. STDMETHOD(GetInfo)
  137. (/*[in]*/ CAPICOM_CERT_INFO_TYPE InfoType,
  138. /*[out, retval]*/ BSTR * pVal);
  139. STDMETHOD(HasPrivateKey)
  140. (/*[out, retval]*/ VARIANT_BOOL * pVal);
  141. STDMETHOD(get_Thumbprint)
  142. (/*[out, retval]*/ BSTR * pVal);
  143. STDMETHOD(get_ValidToDate)
  144. (/*[out, retval]*/ DATE * pVal);
  145. STDMETHOD(get_ValidFromDate)
  146. (/*[out, retval]*/ DATE * pVal);
  147. STDMETHOD(get_IssuerName)
  148. (/*[out, retval]*/ BSTR * pVal);
  149. STDMETHOD(get_SubjectName)
  150. (/*[out, retval]*/ BSTR * pVal);
  151. STDMETHOD(get_SerialNumber)
  152. (/*[out, retval]*/ BSTR * pVal);
  153. STDMETHOD(get_Version)
  154. (/*[out, retval]*/ long * pVal);
  155. //
  156. // CAPICOM v2.0
  157. //
  158. STDMETHOD(get_Archived)
  159. (/*[out, retval]*/ VARIANT_BOOL * pVal);
  160. STDMETHOD(put_Archived)
  161. (/*[in]*/ VARIANT_BOOL newVal);
  162. STDMETHOD(Template)
  163. (/*[out, retval]*/ ITemplate ** pVal);
  164. STDMETHOD(PublicKey)
  165. (/*[out, retval]*/ IPublicKey ** pVal);
  166. STDMETHOD(get_PrivateKey)
  167. (/*[out, retval]*/ IPrivateKey ** pVal);
  168. STDMETHOD(put_PrivateKey)
  169. (/*[in]*/ IPrivateKey * newVal);
  170. STDMETHOD(Extensions)
  171. (/*[out, retval]*/ IExtensions ** pVal);
  172. STDMETHOD(ExtendedProperties)
  173. (/*[out, retval]*/ IExtendedProperties ** pVal);
  174. STDMETHOD(Load)
  175. (/*[in]*/ BSTR FileName,
  176. /*[in, defaultvalue("")]*/ BSTR Password,
  177. /*[in, defaultvalue(CAPICOM_KEY_STORAGE_DEFAULT)]*/ CAPICOM_KEY_STORAGE_FLAG KeyStorageFlag,
  178. /*[in, defaultvalue(CAPICOM_CURRENT_USER_KEY)]*/ CAPICOM_KEY_LOCATION KeyLocation);
  179. STDMETHOD(Save)
  180. (/*[in]*/ BSTR FileName,
  181. /*[in, defaultvalue("")]*/ BSTR Password,
  182. /*[in, defaultvalue(CAPICOM_CERTIFICATE_SAVE_AS_CER)]*/ CAPICOM_CERTIFICATE_SAVE_AS_TYPE SaveAs,
  183. /*[in, defaultvalue(CAPICOM_CERTIFICATE_INCLUDE_END_ENTITY_ONLY)]*/ CAPICOM_CERTIFICATE_INCLUDE_OPTION IncludeOption);
  184. //
  185. // ICertContext custom interface.
  186. //
  187. STDMETHOD(get_CertContext)
  188. (/*[out, retval]*/ long * ppCertContext);
  189. STDMETHOD(put_CertContext)
  190. (/*[in]*/ long pCertContext);
  191. STDMETHOD(FreeContext)
  192. (/*[in]*/ long pCertContext);
  193. //
  194. // C++ member function needed to initialize the object.
  195. //
  196. STDMETHOD(ImportBlob)
  197. (DATA_BLOB * pCertBlob,
  198. BOOL bAllowPfx,
  199. CAPICOM_KEY_LOCATION KeyLocation,
  200. BSTR pwszPassword,
  201. CAPICOM_KEY_STORAGE_FLAG KeyStorageFlag);
  202. STDMETHOD(GetContext)
  203. (PCCERT_CONTEXT * ppCertContext);
  204. STDMETHOD(PutContext)
  205. (PCCERT_CONTEXT pCertContext, DWORD dwCurrentSafety);
  206. private:
  207. CLock m_Lock;
  208. PCCERT_CONTEXT m_pCertContext;
  209. CComPtr<IKeyUsage> m_pIKeyUsage;
  210. CComPtr<IExtendedKeyUsage> m_pIExtendedKeyUsage;
  211. CComPtr<IBasicConstraints> m_pIBasicConstraints;
  212. CComPtr<ITemplate> m_pITemplate;
  213. CComPtr<ICertificateStatus> m_pICertificateStatus;
  214. CComPtr<IPublicKey> m_pIPublicKey;
  215. CComPtr<IExtensions> m_pIExtensions;
  216. };
  217. #endif //__CERTIFICATE_H_