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.

229 lines
6.6 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Microsoft Windows, Copyright (C) Microsoft Corporation, 2000
  3. File: Signer.h
  4. Content: Declaration of the CSigner.
  5. History: 11-15-99 dsie created
  6. ------------------------------------------------------------------------------*/
  7. #ifndef __SIGNER_H_
  8. #define __SIGNER_H_
  9. #include "Resource.h"
  10. #include "Error.h"
  11. #include "Lock.h"
  12. #include "Debug.h"
  13. #include "Attributes.h"
  14. #include "PFXHlpr.h"
  15. ////////////////////////////////////////////////////////////////////////////////
  16. //
  17. // Exported functions.
  18. //
  19. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  20. Function : CreateSignerObject
  21. Synopsis : Create a ISigner object and initialize the object with the
  22. specified certificate.
  23. Parameter: PCCERT_CONTEXT pCertContext - Pointer to CERT_CONTEXT.
  24. CRYPT_ATTRIBUTES * pAuthAttrs - Pointer to CRYPT_ATTRIBUTES
  25. of authenticated attributes.
  26. PCCERT_CHAIN_CONTEXT pChainContext - Chain context.
  27. DWORD dwCurrentSafety - Current safety setting.
  28. ISigner2 ** ppISigner2 - Pointer to pointer to ISigner object to
  29. receive the interface pointer.
  30. Remark :
  31. ------------------------------------------------------------------------------*/
  32. HRESULT CreateSignerObject (PCCERT_CONTEXT pCertContext,
  33. CRYPT_ATTRIBUTES * pAuthAttrs,
  34. PCCERT_CHAIN_CONTEXT pChainContext,
  35. DWORD dwCurrentSafety,
  36. ISigner2 ** ppISigner2);
  37. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  38. Function : GetSignerAdditionalStore
  39. Synopsis : Return the additional store, if any.
  40. Parameter: ISigner2 * pISigner - Pointer to signer object.
  41. HCERTSTORE * phCertStore - Pointer to HCERTSOTRE.
  42. Remark : Caller must call CertCloseStore() for the handle returned.
  43. ------------------------------------------------------------------------------*/
  44. HRESULT GetSignerAdditionalStore (ISigner2 * pISigner,
  45. HCERTSTORE * phCertStore);
  46. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  47. Function : PutSignerAdditionalStore
  48. Synopsis : Set the additional store.
  49. Parameter: ISigner2 * pISigner - Pointer to signer object.
  50. HCERTSTORE hCertStore - Additional store handle.
  51. Remark :
  52. ------------------------------------------------------------------------------*/
  53. HRESULT PutSignerAdditionalStore (ISigner2 * pISigner,
  54. HCERTSTORE hCertStore);
  55. ///////////////////////////////////////////////////////////////////////////////
  56. //
  57. // CSigner
  58. //
  59. class ATL_NO_VTABLE CSigner : ICSigner,
  60. public CComObjectRootEx<CComMultiThreadModel>,
  61. public CComCoClass<CSigner, &CLSID_Signer>,
  62. public ICAPICOMError<CSigner, &IID_ISigner>,
  63. public IDispatchImpl<ISigner2, &IID_ISigner2, &LIBID_CAPICOM,
  64. CAPICOM_MAJOR_VERSION, CAPICOM_MINOR_VERSION>,
  65. public IObjectSafetyImpl<CSigner, INTERFACESAFE_FOR_UNTRUSTED_CALLER |
  66. INTERFACESAFE_FOR_UNTRUSTED_DATA>
  67. {
  68. public:
  69. CSigner()
  70. {
  71. }
  72. DECLARE_REGISTRY_RESOURCEID(IDR_SIGNER)
  73. DECLARE_GET_CONTROLLING_UNKNOWN()
  74. DECLARE_PROTECT_FINAL_CONSTRUCT()
  75. BEGIN_COM_MAP(CSigner)
  76. COM_INTERFACE_ENTRY(ISigner)
  77. COM_INTERFACE_ENTRY(ISigner2)
  78. COM_INTERFACE_ENTRY(ICSigner)
  79. COM_INTERFACE_ENTRY(IDispatch)
  80. COM_INTERFACE_ENTRY(IObjectSafety)
  81. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  82. END_COM_MAP()
  83. BEGIN_CATEGORY_MAP(CSigner)
  84. IMPLEMENTED_CATEGORY(CATID_SafeForScripting)
  85. IMPLEMENTED_CATEGORY(CATID_SafeForInitializing)
  86. END_CATEGORY_MAP()
  87. HRESULT FinalConstruct()
  88. {
  89. HRESULT hr;
  90. CRYPT_ATTRIBUTES attributes = {0, NULL};
  91. if (FAILED(hr = m_Lock.Initialized()))
  92. {
  93. DebugTrace("Error [%#x]: Critical section could not be created for Signer object.\n", hr);
  94. return hr;
  95. }
  96. //
  97. // Create the embeded IAttributes collection object.
  98. //
  99. if (FAILED(hr = ::CreateAttributesObject(&attributes, &m_pIAttributes)))
  100. {
  101. DebugTrace("Error [%#x]: CreateAttributesObject() failed.\n", hr);
  102. return hr;
  103. }
  104. m_pICertificate = NULL;
  105. m_hCertStore = NULL;
  106. m_dwIncludeOption = 0;
  107. m_bPFXStore = FALSE;
  108. return S_OK;
  109. }
  110. void FinalRelease()
  111. {
  112. m_pICertificate.Release();
  113. m_pIAttributes.Release();
  114. m_pIChain.Release();
  115. if (m_hCertStore)
  116. {
  117. if (m_bPFXStore)
  118. {
  119. ::PFXFreeStore(m_hCertStore);
  120. }
  121. else
  122. {
  123. ::CertCloseStore(m_hCertStore, 0);
  124. }
  125. }
  126. }
  127. //
  128. // ISigner
  129. //
  130. public:
  131. STDMETHOD(get_Certificate)
  132. (/*[out, retval]*/ ICertificate ** pVal);
  133. STDMETHOD(put_Certificate)
  134. (/*[in]*/ ICertificate * newVal);
  135. STDMETHOD(get_AuthenticatedAttributes)
  136. (/*[out, retval]*/ IAttributes ** pVal);
  137. STDMETHOD(get_Chain)
  138. (/*[out, retval]*/ IChain ** pVal);
  139. STDMETHOD(get_Options)
  140. (/*[out, retval]*/ CAPICOM_CERTIFICATE_INCLUDE_OPTION * pVal);
  141. STDMETHOD(put_Options)
  142. (/*[in, defaultvalue(CAPICOM_CERTIFICATE_INCLUDE_CHAIN_EXCEPT_ROOT)]*/ CAPICOM_CERTIFICATE_INCLUDE_OPTION IncludeOption);
  143. STDMETHOD(Load)
  144. (/*[in]*/ BSTR FileName,
  145. /*[in, defaultvalue("")]*/ BSTR Password);
  146. //
  147. // Custom inferfaces.
  148. //
  149. STDMETHOD(get_AdditionalStore)
  150. (/*[out, retval]*/ long * phAdditionalStore);
  151. STDMETHOD(put_AdditionalStore)
  152. (/*[in]*/ long hAdditionalStore);
  153. //
  154. // None COM functions.
  155. //
  156. STDMETHOD(Init)
  157. (PCCERT_CONTEXT pCertContext,
  158. CRYPT_ATTRIBUTES * pAttributes,
  159. PCCERT_CHAIN_CONTEXT pChainContext,
  160. DWORD dwCurrentSafety);
  161. private:
  162. CLock m_Lock;
  163. CComPtr<ICertificate> m_pICertificate;
  164. CComPtr<IAttributes> m_pIAttributes;
  165. CComPtr<IChain> m_pIChain;
  166. HCERTSTORE m_hCertStore;
  167. BOOL m_bPFXStore;
  168. DWORD m_dwIncludeOption;
  169. };
  170. #endif //__SIGNER_H_