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.

198 lines
5.5 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
  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. #ifdef FULL_OBJECT
  84. CIISCertObj() :
  85. m_bInitDone(FALSE),
  86. m_pEnroll(NULL)
  87. #else
  88. CIISCertObj()
  89. #endif
  90. {
  91. }
  92. ~CIISCertObj()
  93. {
  94. #ifdef FULL_OBJECT
  95. if (m_pEnroll != NULL)
  96. m_pEnroll->Release();
  97. #endif
  98. }
  99. DECLARE_REGISTRY_RESOURCEID(IDR_IISCERTOBJ)
  100. DECLARE_NOT_AGGREGATABLE(CIISCertObj)
  101. DECLARE_PROTECT_FINAL_CONSTRUCT()
  102. BEGIN_COM_MAP(CIISCertObj)
  103. COM_INTERFACE_ENTRY(IIISCertObj)
  104. COM_INTERFACE_ENTRY(IDispatch)
  105. END_COM_MAP()
  106. // IIISCertObj
  107. public:
  108. STDMETHOD(Import)(BSTR FileName, BSTR InstanceName, BSTR Password);
  109. STDMETHOD(ImportFromBlob)(BSTR InstanceName, BSTR Password, BOOL bBase64Encoded, DWORD pcbSize, char * pBlobBinary);
  110. STDMETHOD(RemoveCert)(BSTR InstanceName, BOOL bPrivateKey);
  111. STDMETHOD(Export)(BSTR FileName, BSTR InstanceName, BSTR Password, BOOL bPrivateKey, BOOL bCertChain, BOOL bRemoveCert);
  112. STDMETHOD(ExportToBlob)(BSTR InstanceName, BSTR Password, BOOL bPrivateKey, BOOL bCertChain, BOOL bBase64Encoded, DWORD * pcbSize, char * pBlobBinary);
  113. STDMETHOD(Copy)(BSTR DestinationServerName, BSTR DestinationServerInstance, BSTR CertificatePassword, VARIANT DestinationServerUserName OPTIONAL, VARIANT DestinationServerPassword OPTIONAL);
  114. STDMETHOD(Move)(BSTR DestinationServerName, BSTR DestinationServerInstance, BSTR CertificatePassword, VARIANT DestinationServerUserName OPTIONAL, VARIANT DestinationServerPassword OPTIONAL);
  115. STDMETHOD(IsInstalled)(BSTR InstanceName, VARIANT_BOOL * retval);
  116. STDMETHOD(IsInstalledRemote)(BSTR InstanceName, VARIANT_BOOL * retval);
  117. #ifdef FULL_OBJECT
  118. STDMETHOD(CreateRequest)(BSTR FileName);
  119. STDMETHOD(ProcessResponse)(BSTR FileName);
  120. STDMETHOD(RequestCert)(BSTR CertAuthority);
  121. STDMETHOD(LoadSettings)(BSTR ApplicationKey, BSTR SettingsKey);
  122. STDMETHOD(SaveSettings)(BSTR ApplicationKey, BSTR SettingsKey);
  123. STDMETHOD(put_SGC_Cert)(/*[in]*/ BOOL newVal);
  124. STDMETHOD(put_KeySize)(/*[in]*/ int newVal);
  125. STDMETHOD(put_CertTemplate)(/*[in]*/ BSTR newVal);
  126. STDMETHOD(put_CertAuthority)(/*[in]*/ BSTR newVal);
  127. STDMETHOD(put_Country)(/*[in]*/ BSTR newVal);
  128. STDMETHOD(put_State)(/*[in]*/ BSTR newVal);
  129. STDMETHOD(put_Locality)(/*[in]*/ BSTR newVal);
  130. STDMETHOD(put_OrganizationUnit)(/*[in]*/ BSTR newVal);
  131. STDMETHOD(put_Organization)(/*[in]*/ BSTR newVal);
  132. STDMETHOD(put_FriendlyName)(/*[in]*/ BSTR newVal);
  133. STDMETHOD(put_CommonName)(/*[in]*/ BSTR newVal);
  134. STDMETHOD(put_Password)(/*[in]*/ BSTR newVal);
  135. #endif
  136. STDMETHOD(put_InstanceName)(/*[in]*/ BSTR newVal);
  137. STDMETHOD(put_UserName)(/*[in]*/ BSTR newVal);
  138. STDMETHOD(put_UserPassword)(/*[in]*/ BSTR newVal);
  139. STDMETHOD(put_ServerName)(/*[in]*/ BSTR newVal);
  140. private:
  141. IIISCertObj * GetObject(HRESULT * phr);
  142. IIISCertObj * GetObject(HRESULT * phr, CString csServerName,CString csUserName OPTIONAL,CString csUserPassword OPTIONAL);
  143. #ifdef FULL_OBJECT
  144. STDMETHOD(Init)();
  145. STDMETHOD(CreateDNString)(CString& str);
  146. IEnroll * GetEnroll();
  147. #endif
  148. CERT_CONTEXT * GetInstalledCert(HRESULT * phResult);
  149. HRESULT UninstallCert();
  150. HRESULT ExportToBlobProxy(IIISCertObj * pObj,BSTR InstanceName,BSTR Password,BOOL bPrivateKey,BOOL bCertChain,BOOL * bBase64Encoded,DWORD * pcbSize,char ** pBlobBinary);
  151. HRESULT ImportFromBlobProxy(IIISCertObj * pObj,BSTR InstanceName,BSTR Password,DWORD count,BYTE *pData);
  152. HRESULT CopyOrMove(BOOL bRemoveFromCertAfterCopy,BSTR bstrDestinationServerName,BSTR bstrDestinationServerInstance,BSTR bstrCertificatePassword,VARIANT varDestinationServerUserName, VARIANT varDestinationServerPassword);
  153. private:
  154. CComPtr<IIISCertObj> m_pObj;
  155. CString m_InstanceName;
  156. CString m_ServerName;
  157. CString m_UserName;
  158. CString m_UserPassword;
  159. #ifdef FULL_OBJECT
  160. CString m_Password;
  161. CString m_CommonName;
  162. CString m_FriendlyName;
  163. CString m_Organization;
  164. CString m_OrganizationUnit;
  165. CString m_Locality;
  166. CString m_State;
  167. CString m_Country;
  168. CString m_CertAuthority;
  169. CString m_CertTemplate;
  170. int m_KeySize;
  171. BOOL m_SGC_Cert;
  172. BOOL m_bInitDone;
  173. IEnroll * m_pEnroll;
  174. #endif
  175. };
  176. #endif //__IISCERTOBJ_H_