Source code of Windows XP (NT5)
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.

227 lines
6.9 KiB

  1. // IISCertObj.h : Declaration of the CIISCertObj
  2. #ifndef __IISCERTOBJ_H_
  3. #define __IISCERTOBJ_H_
  4. #include "resource.h" // main symbols
  5. #ifdef FULL_OBJECT
  6. class CCryptBlob
  7. {
  8. public:
  9. CCryptBlob()
  10. {
  11. m_blob.cbData = 0;
  12. m_blob.pbData = NULL;
  13. }
  14. virtual ~CCryptBlob()
  15. {
  16. }
  17. DWORD GetSize() {return m_blob.cbData;}
  18. BYTE * GetData() {return m_blob.pbData;}
  19. void Set(DWORD cb, BYTE * pb)
  20. {
  21. Destroy();
  22. m_blob.cbData = cb;
  23. m_blob.pbData = pb;
  24. }
  25. BOOL Resize(DWORD cb);
  26. operator CRYPT_DATA_BLOB *()
  27. {
  28. return &m_blob;
  29. }
  30. protected:
  31. void Destroy()
  32. {
  33. if (m_blob.pbData != NULL)
  34. Free(m_blob.pbData);
  35. }
  36. virtual BYTE * Realloc(BYTE * pb, DWORD cb) = 0;
  37. virtual void Free(BYTE * pb) = 0;
  38. CRYPT_DATA_BLOB m_blob;
  39. };
  40. class CCryptBlobIMalloc : public CCryptBlob
  41. {
  42. public:
  43. virtual ~CCryptBlobIMalloc()
  44. {
  45. CCryptBlob::Destroy();
  46. }
  47. protected:
  48. virtual BYTE * Realloc(BYTE * pb, DWORD cb)
  49. {
  50. return (BYTE *)CoTaskMemRealloc(pb, cb);
  51. }
  52. virtual void Free(BYTE * pb)
  53. {
  54. CoTaskMemFree(pb);
  55. }
  56. };
  57. class CCryptBlobLocal : public CCryptBlob
  58. {
  59. public:
  60. virtual ~CCryptBlobLocal()
  61. {
  62. CCryptBlob::Destroy();
  63. }
  64. protected:
  65. virtual BYTE * Realloc(BYTE * pb, DWORD cb)
  66. {
  67. return (BYTE *)realloc(pb, cb);
  68. }
  69. virtual void Free(BYTE * pb)
  70. {
  71. free(pb);
  72. }
  73. };
  74. #endif // FULL_OBJECT
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CIISCertObj
  77. class ATL_NO_VTABLE CIISCertObj :
  78. public CComObjectRootEx<CComSingleThreadModel>,
  79. public CComCoClass<CIISCertObj, &CLSID_IISCertObj>,
  80. public IDispatchImpl<IIISCertObj, &IID_IIISCertObj, &LIBID_CERTOBJLib>
  81. {
  82. public:
  83. CIISCertObj(){}
  84. ~CIISCertObj(){}
  85. DECLARE_REGISTRY_RESOURCEID(IDR_IISCERTOBJ)
  86. DECLARE_NOT_AGGREGATABLE(CIISCertObj)
  87. DECLARE_PROTECT_FINAL_CONSTRUCT()
  88. BEGIN_COM_MAP(CIISCertObj)
  89. COM_INTERFACE_ENTRY(IIISCertObj)
  90. COM_INTERFACE_ENTRY(IDispatch)
  91. END_COM_MAP()
  92. // IIISCertObj
  93. public:
  94. STDMETHOD(put_InstanceName)(BSTR newVal);
  95. STDMETHOD(put_UserName)(BSTR newVal);
  96. STDMETHOD(put_UserPassword)(BSTR newVal);
  97. STDMETHOD(put_ServerName)(BSTR newVal);
  98. STDMETHOD(IsInstalled)(VARIANT_BOOL * retval);
  99. STDMETHOD(IsInstalledRemote)(VARIANT_BOOL * retval);
  100. STDMETHOD(IsExportable)(VARIANT_BOOL * retval);
  101. STDMETHOD(IsExportableRemote)(VARIANT_BOOL * retval);
  102. STDMETHOD(GetCertInfo)(VARIANT * pVtArray);
  103. STDMETHOD(GetCertInfoRemote)(VARIANT * pVtArray);
  104. STDMETHOD(Copy)(BOOL bAllowExport, BSTR DestinationServerName, BSTR DestinationServerInstance, VARIANT DestinationServerUserName OPTIONAL, VARIANT DestinationServerPassword OPTIONAL);
  105. STDMETHOD(CopyToCertStore)(BOOL bAllowExport, BSTR bstrDestinationServerName,VARIANT varDestinationServerUserName,VARIANT varDestinationServerPassword,VARIANT * pVtArray);
  106. STDMETHOD(Move)(BOOL bAllowExport,BSTR DestinationServerName, BSTR DestinationServerInstance, VARIANT DestinationServerUserName OPTIONAL, VARIANT DestinationServerPassword OPTIONAL);
  107. STDMETHOD(RemoveCert)(BOOL bPrivateKey);
  108. STDMETHOD(Import)(BSTR FileName, BSTR Password, BOOL bAllowExport);
  109. STDMETHOD(ImportToCertStore)(BSTR FileName, BSTR Password, BOOL bAllowExport, VARIANT* BinaryVariant);
  110. STDMETHOD(ImportFromBlob)(BSTR InstanceName, BSTR Password, BOOL bInstallToMetabase, BOOL bAllowExport, DWORD pcbSize, char * pBlobBinary);
  111. STDMETHOD(ImportFromBlobGetHash)(BSTR InstanceName, BSTR Password, BOOL bInstallToMetabase, BOOL bAllowExport, DWORD pcbSize, char * pBlobBinary, DWORD * pcbCertHashSize, char ** bCertHash);
  112. STDMETHOD(Export)(BSTR FileName, BSTR Password, BOOL bPrivateKey, BOOL bCertChain, BOOL bRemoveCert);
  113. STDMETHOD(ExportToBlob)(BSTR InstanceName, BSTR Password, BOOL bPrivateKey, BOOL bCertChain, DWORD * pcbSize, char ** pBlobBinary);
  114. private:
  115. CString m_ServerName;
  116. CString m_UserName;
  117. CString m_UserPassword;
  118. CString m_InstanceName;
  119. CComPtr<IIISCertObj> m_pObj;
  120. IIISCertObj * GetObject(HRESULT * phr);
  121. IIISCertObj * GetObject(HRESULT * phr, CString csServerName,CString csUserName OPTIONAL,CString csUserPassword OPTIONAL);
  122. HRESULT CopyOrMove(BOOL bRemoveFromCertAfterCopy,BOOL bCopyCertDontInstallRetHash,BOOL bAllowExport,VARIANT * pVtArray,BSTR bstrDestinationServerName,BSTR bstrDestinationServerInstance,VARIANT varDestinationServerUserName, VARIANT varDestinationServerPassword);
  123. };
  124. HRESULT RemoveCertProxy(IIISCertObj * pObj,BSTR InstanceName, BOOL bPrivateKey);
  125. HRESULT ImportFromBlobProxy(IIISCertObj * pObj,BSTR InstanceName,BSTR Password,BOOL bInstallToMetabase,BOOL bAllowExport,DWORD actual,BYTE *pData,DWORD *cbHashBufferSize,char **pbHashBuffer);
  126. HRESULT ExportToBlobProxy(IIISCertObj * pObj,BSTR InstanceName,BSTR Password,BOOL bPrivateKey,BOOL bCertChain,DWORD * pcbSize,char ** pBlobBinary);
  127. #ifdef FULL_OBJECT
  128. class ATL_NO_VTABLE CIISCertificate :
  129. public CComObjectRootEx<CComSingleThreadModel>,
  130. public CComCoClass<CIISCertObj, &CLSID_IISCertObj>,
  131. public IDispatchImpl<IIISCertObj, &IID_IIISCertObj, &LIBID_CERTOBJLib>
  132. {
  133. public:
  134. CIISCertificate() :m_bInitDone(FALSE),m_pEnroll(NULL)
  135. {
  136. }
  137. ~CIISCertificate()
  138. {
  139. if (m_pEnroll != NULL)
  140. {
  141. m_pEnroll->Release();
  142. }
  143. }
  144. DECLARE_REGISTRY_RESOURCEID(IDR_IISCERTOBJ)
  145. DECLARE_NOT_AGGREGATABLE(CIISCertificate)
  146. DECLARE_PROTECT_FINAL_CONSTRUCT()
  147. // IIISCertificate
  148. public:
  149. STDMETHOD(CreateRequest)(BSTR FileName);
  150. STDMETHOD(ProcessResponse)(BSTR FileName);
  151. STDMETHOD(RequestCert)(BSTR CertAuthority);
  152. STDMETHOD(LoadSettings)(BSTR ApplicationKey, BSTR SettingsKey);
  153. STDMETHOD(SaveSettings)(BSTR ApplicationKey, BSTR SettingsKey);
  154. STDMETHOD(put_SGC_Cert)(BOOL newVal);
  155. STDMETHOD(put_KeySize)(int newVal);
  156. STDMETHOD(put_CertTemplate)(BSTR newVal);
  157. STDMETHOD(put_CertAuthority)(BSTR newVal);
  158. STDMETHOD(put_Country)(BSTR newVal);
  159. STDMETHOD(put_State)(BSTR newVal);
  160. STDMETHOD(put_Locality)(BSTR newVal);
  161. STDMETHOD(put_OrganizationUnit)(BSTR newVal);
  162. STDMETHOD(put_Organization)(BSTR newVal);
  163. STDMETHOD(put_FriendlyName)(BSTR newVal);
  164. STDMETHOD(put_CommonName)(BSTR newVal);
  165. STDMETHOD(put_Password)(BSTR newVal);
  166. STDMETHOD(put_InstanceName)(BSTR newVal);
  167. STDMETHOD(put_UserName)(BSTR newVal);
  168. STDMETHOD(put_UserPassword)(BSTR newVal);
  169. STDMETHOD(put_ServerName)(BSTR newVal);
  170. private:
  171. CComPtr<IIISCertObj> m_pObj;
  172. CString m_InstanceName;
  173. CString m_ServerName;
  174. CString m_UserName;
  175. CString m_UserPassword;
  176. CString m_Password;
  177. CString m_CommonName;
  178. CString m_FriendlyName;
  179. CString m_Organization;
  180. CString m_OrganizationUnit;
  181. CString m_Locality;
  182. CString m_State;
  183. CString m_Country;
  184. CString m_CertAuthority;
  185. CString m_CertTemplate;
  186. int m_KeySize;
  187. BOOL m_SGC_Cert;
  188. BOOL m_bInitDone;
  189. IEnroll * m_pEnroll;
  190. IIISCertObj * GetObject(HRESULT * phr);
  191. IIISCertObj * GetObject(HRESULT * phr, CString csServerName,CString csUserName OPTIONAL,CString csUserPassword OPTIONAL);
  192. STDMETHOD(Init)();
  193. STDMETHOD(CreateDNString)(CString& str);
  194. IEnroll * GetEnroll();
  195. };
  196. #endif // FULL_OBJECT
  197. #endif //__IISCERTOBJ_H_