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.

165 lines
4.4 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Microsoft Windows, Copyright (C) Microsoft Corporation, 2000
  3. File: Store.h
  4. Content: Declaration of CStore.
  5. History: 11-15-99 dsie created
  6. ------------------------------------------------------------------------------*/
  7. #ifndef __STORE_H_
  8. #define __STORE_H_
  9. #include "Resource.h"
  10. #include "Error.h"
  11. #include "Lock.h"
  12. #include "Debug.h"
  13. #include "DialogUI.h"
  14. ////////////////////////////////////////////////////////////////////////////////
  15. //
  16. // CStore
  17. //
  18. class ATL_NO_VTABLE CStore :
  19. public ICertStore,
  20. public CComObjectRootEx<CComMultiThreadModel>,
  21. public CComCoClass<CStore, &CLSID_Store>,
  22. public ICAPICOMError<CStore, &IID_IStore>,
  23. public IPromptUser<CStore>,
  24. public IDispatchImpl<IStore2, &IID_IStore2, &LIBID_CAPICOM,
  25. CAPICOM_MAJOR_VERSION, CAPICOM_MINOR_VERSION>,
  26. public IObjectSafetyImpl<CStore, INTERFACESAFE_FOR_UNTRUSTED_CALLER |
  27. INTERFACESAFE_FOR_UNTRUSTED_DATA>
  28. {
  29. public:
  30. CStore()
  31. {
  32. }
  33. DECLARE_REGISTRY_RESOURCEID(IDR_STORE)
  34. DECLARE_GET_CONTROLLING_UNKNOWN()
  35. DECLARE_PROTECT_FINAL_CONSTRUCT()
  36. BEGIN_COM_MAP(CStore)
  37. COM_INTERFACE_ENTRY(IStore)
  38. COM_INTERFACE_ENTRY(IStore2)
  39. COM_INTERFACE_ENTRY(ICertStore)
  40. COM_INTERFACE_ENTRY(IDispatch)
  41. COM_INTERFACE_ENTRY(IObjectSafety)
  42. COM_INTERFACE_ENTRY(IObjectWithSite)
  43. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  44. END_COM_MAP()
  45. BEGIN_CATEGORY_MAP(CStore)
  46. IMPLEMENTED_CATEGORY(CATID_SafeForScripting)
  47. IMPLEMENTED_CATEGORY(CATID_SafeForInitializing)
  48. END_CATEGORY_MAP()
  49. HRESULT FinalConstruct()
  50. {
  51. HRESULT hr;
  52. if (FAILED(hr = m_Lock.Initialized()))
  53. {
  54. DebugTrace("Error [%#x]: Critical section could not be created for Store object.\n", hr);
  55. return hr;
  56. }
  57. m_hCertStore = NULL;
  58. m_StoreLocation = CAPICOM_CURRENT_USER_STORE;
  59. m_bIsProtected = TRUE;
  60. m_cKeyProvInfo = 0;
  61. m_rgpKeyProvInfo = NULL;
  62. return S_OK;
  63. }
  64. void FinalRelease()
  65. {
  66. if (m_hCertStore)
  67. {
  68. Close();
  69. }
  70. }
  71. //
  72. // IStore
  73. //
  74. public:
  75. STDMETHOD(Import)
  76. (/*[in]*/ BSTR EncodedStore);
  77. STDMETHOD(Export)
  78. (/*[in, defaultvalue(CAPICOM_STORE_SAVE_AS_SERIALIZED)]*/ CAPICOM_STORE_SAVE_AS_TYPE SaveAs,
  79. /*[in, defaultvalue(CAPICOM_BASE64_ENCODE)]*/ CAPICOM_ENCODING_TYPE EncodingType,
  80. /*[out, retval]*/ BSTR * pVal);
  81. STDMETHOD(Remove)
  82. (/*[in]*/ ICertificate * pVal);
  83. STDMETHOD(Add)
  84. (/*[in]*/ ICertificate * pVal);
  85. STDMETHOD(Open)
  86. (/*[in]*/ CAPICOM_STORE_LOCATION StoreLocation,
  87. /*[in, defaultvalue("My")]*/ BSTR StoreName,
  88. /*[in, defaultvalue(CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED)]*/ CAPICOM_STORE_OPEN_MODE OpenMode);
  89. STDMETHOD(get_Certificates)
  90. (/*[out, retval]*/ ICertificates ** pVal);
  91. //
  92. // v2.0
  93. //
  94. STDMETHOD(Load)
  95. (/*[in]*/ BSTR FileName,
  96. /*[in, defaultvalue("")]*/ BSTR Password,
  97. /*[in, defaultvalue(CAPICOM_KEY_STORAGE_DEFAULT)]*/ CAPICOM_KEY_STORAGE_FLAG KeyStorageFlag);
  98. //
  99. // Custom interfaces.
  100. //
  101. STDMETHOD(get_StoreHandle)
  102. (/*[out, retval]*/ long * phCertStore);
  103. STDMETHOD(put_StoreHandle)
  104. (/*[in]*/ long hCertStore);
  105. STDMETHOD(get_StoreLocation)
  106. (/*[out, retval]*/ CAPICOM_STORE_LOCATION * pStoreLocation);
  107. STDMETHOD(put_StoreLocation)
  108. (/*[in]*/ CAPICOM_STORE_LOCATION StoreLocation);
  109. STDMETHOD(CloseHandle)
  110. (/*[in]*/ long hCertStore);
  111. //
  112. // None COM functions.
  113. //
  114. STDMETHOD(ImportCertObject)
  115. (DWORD dwObjectType,
  116. LPVOID pvObject,
  117. BOOL bAllowPfx,
  118. LPWSTR pwszPassword,
  119. CAPICOM_KEY_STORAGE_FLAG KeyStorageFlag);
  120. STDMETHOD(Close)
  121. (void);
  122. private:
  123. CLock m_Lock;
  124. HCERTSTORE m_hCertStore;
  125. CAPICOM_STORE_LOCATION m_StoreLocation;
  126. BOOL m_bIsProtected;
  127. DWORD m_cKeyProvInfo;
  128. PCRYPT_KEY_PROV_INFO * m_rgpKeyProvInfo;
  129. };
  130. #endif //__STORE_H_