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.

186 lines
5.2 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Microsoft Windows
  3. Copyright (C) Microsoft Corporation, 1995 - 1999.
  4. File: PrivateKey.h
  5. Content: Declaration of CPrivateKey.
  6. History: 06-15-2001 dsie created
  7. ------------------------------------------------------------------------------*/
  8. #ifndef __PRIVATEKEY_H_
  9. #define __PRIVATEKEY_H_
  10. #include "Resource.h"
  11. #include "Error.h"
  12. #include "Lock.h"
  13. #include "Debug.h"
  14. ////////////////////////////////////////////////////////////////////////////////
  15. //
  16. // Exported functions.
  17. //
  18. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  19. Function : CreatePrivateKeyObject
  20. Synopsis : Create and initialize an CPrivateKey object.
  21. Parameter: PCCERT_CONTEXT pCertContext - Pointer to CERT_CONTEXT to be used
  22. to initialize the IPrivateKey object.
  23. BOOL bReadOnly - TRUE if read-only, else FALSE.
  24. IPrivateKey ** ppIPrivateKey - Pointer to receive IPrivateKey.
  25. Remark :
  26. ------------------------------------------------------------------------------*/
  27. HRESULT CreatePrivateKeyObject (PCCERT_CONTEXT pCertContext,
  28. BOOL bReadOnly,
  29. IPrivateKey ** ppIPrivateKey);
  30. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  31. Function : GetKeyProvInfo
  32. Synopsis : Return pointer to key prov info of a private key object.
  33. Parameter: IPrivateKey * pIPrivateKey - Pointer to private key object.
  34. PCRYPT_KEY_PROV_INFO * ppKeyProvInfo - Pointer to
  35. PCRYPT_KEY_PROV_INFO.
  36. Remark : Caller must NOT free the structure.
  37. ------------------------------------------------------------------------------*/
  38. HRESULT GetKeyProvInfo (IPrivateKey * pIPrivateKey,
  39. PCRYPT_KEY_PROV_INFO * ppKeyProvInfo);
  40. ////////////////////////////////////////////////////////////////////////////////
  41. //
  42. // CPrivateKey
  43. //
  44. class ATL_NO_VTABLE CPrivateKey : ICPrivateKey,
  45. public CComObjectRootEx<CComMultiThreadModel>,
  46. public CComCoClass<CPrivateKey, &CLSID_PrivateKey>,
  47. public ICAPICOMError<CPrivateKey, &IID_IPrivateKey>,
  48. public IDispatchImpl<IPrivateKey, &IID_IPrivateKey, &LIBID_CAPICOM,
  49. CAPICOM_MAJOR_VERSION, CAPICOM_MINOR_VERSION>
  50. {
  51. public:
  52. CPrivateKey()
  53. {
  54. }
  55. DECLARE_REGISTRY_RESOURCEID(IDR_PRIVATEKEY)
  56. DECLARE_PROTECT_FINAL_CONSTRUCT()
  57. BEGIN_COM_MAP(CPrivateKey)
  58. COM_INTERFACE_ENTRY(IPrivateKey)
  59. COM_INTERFACE_ENTRY(ICPrivateKey)
  60. COM_INTERFACE_ENTRY(IDispatch)
  61. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  62. END_COM_MAP()
  63. HRESULT FinalConstruct()
  64. {
  65. HRESULT hr;
  66. if (FAILED(hr = m_Lock.Initialized()))
  67. {
  68. DebugTrace("Error [%#x]: Critical section could not be created for PrivateKey object.\n", hr);
  69. return hr;
  70. }
  71. m_bReadOnly = FALSE;
  72. m_cbKeyProvInfo = 0;
  73. m_pKeyProvInfo = NULL;
  74. return S_OK;
  75. }
  76. void FinalRelease()
  77. {
  78. if (m_pKeyProvInfo)
  79. {
  80. ::CoTaskMemFree((LPVOID) m_pKeyProvInfo);
  81. }
  82. }
  83. //
  84. // IPrivateKey
  85. //
  86. public:
  87. STDMETHOD(get_ContainerName)
  88. (/*[out, retval]*/ BSTR * pVal);
  89. STDMETHOD(get_UniqueContainerName)
  90. (/*[out, retval]*/ BSTR * pVal);
  91. STDMETHOD(get_ProviderName)
  92. (/*[out, retval]*/ BSTR * pVal);
  93. STDMETHOD(get_ProviderType)
  94. (/*[out, retval]*/ CAPICOM_PROV_TYPE * pVal);
  95. STDMETHOD(get_KeySpec)
  96. (/*[out, retval]*/ CAPICOM_KEY_SPEC * pVal);
  97. STDMETHOD(IsAccessible)
  98. (/*[out, retval]*/ VARIANT_BOOL * pVal);
  99. STDMETHOD(IsProtected)
  100. (/*[out, retval]*/ VARIANT_BOOL * pVal);
  101. STDMETHOD(IsExportable)
  102. (/*[out, retval]*/ VARIANT_BOOL * pVal);
  103. STDMETHOD(IsRemovable)
  104. (/*[out, retval]*/ VARIANT_BOOL * pVal);
  105. STDMETHOD(IsMachineKeyset)
  106. (/*[out, retval]*/ VARIANT_BOOL * pVal);
  107. STDMETHOD(IsHardwareDevice)
  108. (/*[out, retval]*/ VARIANT_BOOL * pVal);
  109. STDMETHOD(Open)
  110. (/*[in]*/ BSTR ContainerName,
  111. /*[in, defaultvalue(CAPICOM_PROV_MS_ENHANCED_PROV]*/ BSTR ProviderName,
  112. /*[in, defaultvalue(CAPICOM_PROV_RSA_FULL)]*/ CAPICOM_PROV_TYPE ProviderType,
  113. /*[in, defaultvalue(CAPICOM_KEY_SPEC_SIGNATURE)]*/ CAPICOM_KEY_SPEC KeySpec,
  114. /*[in, defaultvalue(CAPICOM_CURRENT_USER_STORE)]*/ CAPICOM_STORE_LOCATION StoreLocation,
  115. /*[in, defaultvalue(0)]*/ VARIANT_BOOL bCheckExistence);
  116. STDMETHOD(Delete)();
  117. //
  118. // Custom inferfaces.
  119. //
  120. STDMETHOD(_GetKeyProvInfo)
  121. (PCRYPT_KEY_PROV_INFO * ppKeyProvInfo);
  122. //
  123. // None COM functions.
  124. //
  125. STDMETHOD(Init)
  126. (PCCERT_CONTEXT pCertContext,
  127. BOOL bReadOnly);
  128. private:
  129. CLock m_Lock;
  130. BOOL m_bReadOnly;
  131. DWORD m_cbKeyProvInfo;
  132. PCRYPT_KEY_PROV_INFO m_pKeyProvInfo;
  133. };
  134. #endif //__PRIVATEKEY_H_