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.

210 lines
6.3 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Microsoft Windows, Copyright (C) Microsoft Corporation, 2000
  3. File: Certificates.h
  4. Content: Declaration of CCertificates.
  5. History: 11-15-99 dsie created
  6. ------------------------------------------------------------------------------*/
  7. #ifndef __CERTIFICATES_H_
  8. #define __CERTIFICATES_H_
  9. #include "Resource.h"
  10. #include "Error.h"
  11. #include "Lock.h"
  12. #include "Debug.h"
  13. #include "CopyItem.h"
  14. #include "Certificate.h"
  15. ////////////////////
  16. //
  17. // Locals
  18. //
  19. //
  20. // typdefs to make life easier.
  21. //
  22. typedef std::map<CComBSTR, CComPtr<ICertificate2> > CertificateMap;
  23. typedef CComEnumOnSTL<IEnumVARIANT, &IID_IEnumVARIANT, VARIANT, _CopyMapItem<ICertificate2>, CertificateMap> CertificateEnum;
  24. typedef ICollectionOnSTLImpl<ICertificates2, CertificateMap, VARIANT, _CopyMapItem<ICertificate2>, CertificateEnum> ICertificatesCollection;
  25. ////////////////////////////////////////////////////////////////////////////////
  26. //
  27. // Exported functions.
  28. //
  29. typedef struct _CapicomCertificatesSource
  30. {
  31. DWORD dwSource;
  32. union
  33. {
  34. PCCERT_CONTEXT pCertContext;
  35. PCCERT_CHAIN_CONTEXT pChainContext;
  36. HCERTSTORE hCertStore;
  37. HCRYPTMSG hCryptMsg;
  38. };
  39. } CAPICOM_CERTIFICATES_SOURCE, * PCAPICOM_CERTIFICATES_SOURCE;
  40. // Values for dwSource of CAPICOM_LOAD_LOCATION
  41. #define CAPICOM_CERTIFICATES_LOAD_FROM_CERT 0
  42. #define CAPICOM_CERTIFICATES_LOAD_FROM_CHAIN 1
  43. #define CAPICOM_CERTIFICATES_LOAD_FROM_STORE 2
  44. #define CAPICOM_CERTIFICATES_LOAD_FROM_MESSAGE 3
  45. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  46. Function : CreateCertificatesObject
  47. Synopsis : Create an ICertificates collection object, and load the object with
  48. certificates from the specified source.
  49. Parameter: CAPICOM_CERTIFICATES_SOURCE ccs - Source where to get the
  50. certificates.
  51. DWORD dwCurrentSafety - Current safety setting.
  52. BOOL bIndexedByThumbprint - TRUE to index by thumbprint.
  53. ICertificates2 ** ppICertificates - Pointer to pointer to
  54. ICertificates to receive the
  55. interface pointer.
  56. Remark :
  57. ------------------------------------------------------------------------------*/
  58. HRESULT CreateCertificatesObject (CAPICOM_CERTIFICATES_SOURCE ccs,
  59. DWORD dwCurrentSafety,
  60. BOOL bIndexedByThumbprint,
  61. ICertificates2 ** ppICertificates);
  62. ////////////////////////////////////////////////////////////////////////////////
  63. //
  64. // CCertificates
  65. //
  66. class ATL_NO_VTABLE CCertificates :
  67. public ICCertificates,
  68. public CComObjectRootEx<CComMultiThreadModel>,
  69. public CComCoClass<CCertificates, &CLSID_Certificates>,
  70. public ICAPICOMError<CCertificates, &IID_ICertificates2>,
  71. public IDispatchImpl<ICertificatesCollection, &IID_ICertificates2, &LIBID_CAPICOM,
  72. CAPICOM_MAJOR_VERSION, CAPICOM_MINOR_VERSION>,
  73. public IObjectSafetyImpl<CCertificates, INTERFACESAFE_FOR_UNTRUSTED_CALLER |
  74. INTERFACESAFE_FOR_UNTRUSTED_DATA>
  75. {
  76. public:
  77. CCertificates()
  78. {
  79. }
  80. HRESULT FinalConstruct()
  81. {
  82. HRESULT hr;
  83. if (FAILED(hr = m_Lock.Initialized()))
  84. {
  85. DebugTrace("Error [%#x]: Critical section could not be created for Certificates object.\n", hr);
  86. return hr;
  87. }
  88. m_dwNextIndex = 0;
  89. m_bIndexedByThumbprint = FALSE;
  90. return S_OK;
  91. }
  92. DECLARE_REGISTRY_RESOURCEID(IDR_CERTIFICATES)
  93. DECLARE_GET_CONTROLLING_UNKNOWN()
  94. DECLARE_PROTECT_FINAL_CONSTRUCT()
  95. BEGIN_COM_MAP(CCertificates)
  96. COM_INTERFACE_ENTRY(ICertificates)
  97. COM_INTERFACE_ENTRY(ICertificates2)
  98. COM_INTERFACE_ENTRY(ICCertificates)
  99. COM_INTERFACE_ENTRY(IDispatch)
  100. COM_INTERFACE_ENTRY(IObjectSafety)
  101. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  102. END_COM_MAP()
  103. BEGIN_CATEGORY_MAP(CCertificates)
  104. IMPLEMENTED_CATEGORY(CATID_SafeForScripting)
  105. IMPLEMENTED_CATEGORY(CATID_SafeForInitializing)
  106. END_CATEGORY_MAP()
  107. //
  108. // ICertificates
  109. //
  110. public:
  111. //
  112. // These are the only ones that we need to implemented, others will be
  113. // handled by ATL ICollectionOnSTLImpl.
  114. //
  115. STDMETHOD(Find)
  116. (/*[in]*/ CAPICOM_CERTIFICATE_FIND_TYPE FindType,
  117. /*[in]*/ VARIANT varCriteria,
  118. /*[in]*/ VARIANT_BOOL bFindValidOnly,
  119. /*[out, retval]*/ ICertificates2 ** pVal);
  120. STDMETHOD(Select)
  121. (/*[in, defaultvalue("")]*/ BSTR Title,
  122. /*[in, defaultvalue("")]*/ BSTR DisplayString,
  123. /*[in, defaultvalue(VARIANT_FALSE)]*/ VARIANT_BOOL bMultiSelect,
  124. /*[out, retval]*/ ICertificates2 ** pVal);
  125. STDMETHOD(Add)
  126. (/*[in]*/ ICertificate2 * pVal);
  127. STDMETHOD(Remove)
  128. (/*[in]*/ VARIANT Index);
  129. STDMETHOD(Clear)
  130. (void);
  131. STDMETHOD(Save)
  132. (/*[in]*/ BSTR FileName,
  133. /*[in, defaultvalue("")]*/ BSTR Password,
  134. /*[in, defaultvalue(CAPICOM_STORE_SAVE_AS_PFX)]*/ CAPICOM_CERTIFICATES_SAVE_AS_TYPE SaveAs,
  135. /*[in, defaultvalue(0)]*/ CAPICOM_EXPORT_FLAG ExportFlag);
  136. //
  137. // ICCertficates custom interface.
  138. //
  139. STDMETHOD(_ExportToStore)
  140. (/*[in]*/ HCERTSTORE hCertStore);
  141. //
  142. // None COM functions.
  143. //
  144. STDMETHOD(AddContext)
  145. (PCCERT_CONTEXT pCertContext);
  146. STDMETHOD(LoadFromCert)
  147. (PCCERT_CONTEXT pCertContext);
  148. STDMETHOD(LoadFromChain)
  149. (PCCERT_CHAIN_CONTEXT pChainContext);
  150. STDMETHOD(LoadFromStore)
  151. (HCERTSTORE hCertStore);
  152. STDMETHOD(LoadFromMessage)
  153. (HCRYPTMSG hMsg);
  154. STDMETHOD(Init)
  155. (CAPICOM_CERTIFICATES_SOURCE ccs,
  156. DWORD dwCurrentSafety,
  157. BOOL bIndexedByThumbprint);
  158. private:
  159. CLock m_Lock;
  160. DWORD m_dwNextIndex;
  161. BOOL m_bIndexedByThumbprint;
  162. };
  163. #endif //__CERTIFICATES_H_