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.

423 lines
13 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name :
  4. comobj.hxx
  5. Abstract:
  6. This module defines DCOM Admin Ex APIs used for Certificate information replication.
  7. Author:
  8. Philippe Choquier ( Phillich ) 23-Jun-97
  9. Alex Mallet (amallet) 17-Feb-1998
  10. --*/
  11. #ifndef _CERTCOMOBJ_HXX_
  12. #define _CERTCOMOBJ_HXX_
  13. #include <wincrypt.h>
  14. #include <iadmw.h>
  15. #define RANDOM_SEED_SIZE 16 //size of random bits used to generate session key, in bytes
  16. typedef BOOL
  17. (WINAPI * PFN_SSLGETDEFAULTISSUERS)
  18. (
  19. PBYTE,
  20. LPDWORD
  21. ) ;
  22. //
  23. // Structure used to hold information to open a cert store - basically, all the parameters
  24. // you need to call CertOpenSystemStore()
  25. //
  26. typedef struct OpenCertStoreInfo
  27. {
  28. //
  29. // Parameters used in call to CryptAcquireContext() to get handle to crypt provider
  30. //
  31. LPWSTR pszContainer;
  32. LPWSTR pszProvider;
  33. DWORD dwProvType;
  34. DWORD dwFlags;
  35. LPWSTR pszStoreName;
  36. HCERTSTORE hCertStore;
  37. } OPEN_CERT_STORE_INFO, *POPEN_CERT_STORE_INFO;
  38. OPEN_CERT_STORE_INFO* AllocateCertStoreInfo();
  39. VOID DeallocateCertStoreInfo( IN OPEN_CERT_STORE_INFO *pInfo );
  40. struct _CertChainEntry {
  41. PCCERT_CONTEXT pcCert; //certificate context for this entry
  42. LPWSTR pszStoreName; //store the certificate came from
  43. BOOL fDynName; //whether store name was allocated dynamically or not
  44. LIST_ENTRY ListEntry;
  45. };
  46. void FreeCertChain( LIST_ENTRY *pChain );
  47. typedef struct _CertChainEntry CertChainEntry;
  48. class CADMEXCOM_IMSAdminReplication;
  49. class CADMEXCOM_IMSAdminCryptoCapabilities;
  50. class CADMEXCOM : public IUnknown {
  51. public:
  52. CADMEXCOM();
  53. ~CADMEXCOM();
  54. HRESULT _stdcall
  55. QueryInterface(REFIID riid, void **ppObject);
  56. ULONG _stdcall
  57. AddRef();
  58. ULONG _stdcall
  59. Release();
  60. private:
  61. ULONG m_dwRefCount;
  62. CADMEXCOM_IMSAdminReplication* m_pIMSAdminReplication;
  63. CADMEXCOM_IMSAdminCryptoCapabilities* m_pIMSAdminCryptoCapabilities;
  64. } ;
  65. class CADMEXCOM_IMSAdminReplication : public IMSAdminReplication {
  66. public:
  67. CADMEXCOM_IMSAdminReplication( CADMEXCOM*pAdmExCom );
  68. ~CADMEXCOM_IMSAdminReplication();
  69. HRESULT STDMETHODCALLTYPE GetSignature(
  70. /* [in] */ DWORD dwBufferSize,
  71. /* [size_is][out] */ unsigned char __RPC_FAR *pbBuffer,
  72. /* [out] */ DWORD __RPC_FAR *pdwMDRequiredBufferSize);
  73. HRESULT STDMETHODCALLTYPE Propagate(
  74. /* [in] */ DWORD dwBufferSize,
  75. /* [size_is][in] */ unsigned char __RPC_FAR *pszBuffer);
  76. HRESULT STDMETHODCALLTYPE Propagate2(
  77. /* [in] */ DWORD dwBufferSize,
  78. /* [size_is][in] */ unsigned char __RPC_FAR *pszBuffer,
  79. /* [in] */ DWORD dwSignatureMismatch );
  80. HRESULT STDMETHODCALLTYPE Serialize(
  81. /* [in] */ DWORD dwBufferSize,
  82. /* [size_is][out] */ unsigned char __RPC_FAR *pbBuffer,
  83. /* [out] */ DWORD __RPC_FAR *pdwMDRequiredBufferSize);
  84. HRESULT STDMETHODCALLTYPE DeSerialize(
  85. /* [in] */ DWORD dwBufferSize,
  86. /* [size_is][in] */ unsigned char __RPC_FAR *pbBuffer);
  87. HRESULT _stdcall
  88. QueryInterface(REFIID riid, void **ppObject)
  89. { return m_pAdmExCom->QueryInterface( riid, ppObject ); }
  90. ULONG _stdcall
  91. AddRef()
  92. { return m_pAdmExCom->AddRef(); }
  93. ULONG _stdcall
  94. Release()
  95. { return m_pAdmExCom->Release(); }
  96. private:
  97. CADMEXCOM* m_pAdmExCom;
  98. IMSAdminBase *m_pMB;
  99. BYTE m_rgbSeed[RANDOM_SEED_SIZE];
  100. BOOL m_fGotSeed;
  101. } ;
  102. class CADMEXCOM_IMSAdminCryptoCapabilities : public IMSAdminCryptoCapabilities {
  103. public:
  104. CADMEXCOM_IMSAdminCryptoCapabilities( CADMEXCOM*pAdmExCom );
  105. ~CADMEXCOM_IMSAdminCryptoCapabilities();
  106. BOOL LoadSchannel();
  107. HRESULT _stdcall GetProtocols(
  108. /* [in] */ DWORD dwBufferSize,
  109. /* [size_is][out] */ unsigned char __RPC_FAR *pbBuffer,
  110. /* [out] */ DWORD __RPC_FAR *pdwMDRequiredBufferSize);
  111. HRESULT _stdcall GetMaximumCipherStrength(
  112. /* [out] */ LPDWORD pdwMaximumCipherStrength );
  113. HRESULT _stdcall GetRootCertificates(
  114. /* [in] */ DWORD dwBufferSize,
  115. /* [size_is][out] */ unsigned char __RPC_FAR *pbBuffer,
  116. /* [out] */ DWORD __RPC_FAR *pdwMDRequiredBufferSize);
  117. HRESULT _stdcall GetSupportedAlgs(
  118. /* [in] */ DWORD dwBufferSize,
  119. /* [size_is][out] */ DWORD __RPC_FAR *pbBuffer,
  120. /* [out] */ DWORD __RPC_FAR *pdwMDRequiredBufferSize);
  121. HRESULT _stdcall SetCAList(
  122. /*[in] */ DWORD dwBufferSize,
  123. /*[in, size_is(dwBufferSize)] */ unsigned char __RPC_FAR *pbBuffer );
  124. HRESULT _stdcall
  125. QueryInterface(REFIID riid, void **ppObject)
  126. { return m_pAdmExCom->QueryInterface( riid, ppObject ); }
  127. ULONG _stdcall
  128. AddRef()
  129. { return m_pAdmExCom->AddRef(); }
  130. ULONG _stdcall
  131. Release()
  132. { return m_pAdmExCom->Release(); }
  133. private:
  134. CADMEXCOM* m_pAdmExCom;
  135. HINSTANCE m_hSchannel;
  136. PFN_SSLGETDEFAULTISSUERS m_pfnGetDefaultIssuers;
  137. //
  138. // sspi entrypoints
  139. //
  140. ACQUIRE_CREDENTIALS_HANDLE_FN_W m_pfnAcquireCredentialsHandle;
  141. FREE_CONTEXT_BUFFER_FN m_pfnFreeContextBuffer;
  142. FREE_CREDENTIALS_HANDLE_FN m_pfnFreeCredentialsHandle;
  143. QUERY_CREDENTIALS_ATTRIBUTES_FN m_pfnQueryCredentialsAttributes;
  144. HINSTANCE m_hSspi;
  145. CredHandle m_hCred;
  146. BOOL m_fHasCredHandle;
  147. } ;
  148. class CADMEXCOMSrvFactory : public IClassFactory {
  149. public:
  150. CADMEXCOMSrvFactory();
  151. ~CADMEXCOMSrvFactory();
  152. HRESULT _stdcall
  153. QueryInterface(REFIID riid, void** ppObject);
  154. ULONG _stdcall
  155. AddRef();
  156. ULONG _stdcall
  157. Release();
  158. HRESULT _stdcall
  159. CreateInstance(IUnknown *pUnkOuter, REFIID riid,
  160. void ** pObject);
  161. HRESULT _stdcall
  162. LockServer(BOOL fLock);
  163. private:
  164. ULONG m_dwRefCount;
  165. };
  166. HRESULT
  167. GetConfigurationInformation( DWORD dwInfoType,
  168. HCRYPTKEY *phKey,
  169. IMSAdminBase *pMB,
  170. unsigned char __RPC_FAR *pbBuffer,
  171. DWORD dwBufferSize,
  172. DWORD __RPC_FAR *pdwMDRequiredBufferSize );
  173. HRESULT ReadServerCert( IN IMSAdminBase *pMB,
  174. IN METADATA_HANDLE hHandle,
  175. IN LPCWSTR pszPath,
  176. OUT PCCERT_CONTEXT *ppcCertContext,
  177. OUT OPEN_CERT_STORE_INFO **ppStoreInfo );
  178. HRESULT ReadServerCTL( IN IMSAdminBase *pMB,
  179. IN METADATA_HANDLE hHandle,
  180. IN LPCWSTR pszPath,
  181. OUT PCCTL_CONTEXT *ppcCTL );
  182. HRESULT GetInstanceReplicationInfo( IN DWORD dwInfoType,
  183. IN LPCWSTR pszInstanceNum,
  184. IN IMSAdminBase *pMB,
  185. IN METADATA_HANDLE hHandle,
  186. OUT BYTE **ppbReplicationInfo,
  187. IN OUT DWORD *pdwBufferSize,
  188. IN OUT DWORD *pdwPosition );
  189. HRESULT GetCertReplicationInfo( IN DWORD dwInfoType,
  190. IN IMSAdminBase *pMB,
  191. IN METADATA_HANDLE hHandle,
  192. IN LPCWSTR pszPath,
  193. OUT BYTE **ppbReplicationInfo,
  194. IN OUT DWORD *pdwBufferSize,
  195. IN OUT DWORD *pdwPosition ) ;
  196. HRESULT GetCTLReplicationInfo( DWORD dwInfoType,
  197. IN IMSAdminBase *pMB,
  198. IN METADATA_HANDLE hHandle,
  199. IN LPCWSTR pszPath,
  200. OUT BYTE **ppbReplicationBuffer,
  201. IN OUT DWORD *pdwBufferSize,
  202. IN OUT DWORD *pdwPosition );
  203. HRESULT RetrieveBlobFromMetabase( IN IMSAdminBase *pMB,
  204. IN METADATA_HANDLE hHandle,
  205. IN LPCWSTR pszPath,
  206. IN OUT PMETADATA_RECORD pMDR,
  207. IN DWORD dwSizeHint OPTIONAL = 0);
  208. OPEN_CERT_STORE_INFO* ReadCertStoreInfoFromMB( IN IMSAdminBase *pMB,
  209. IN METADATA_HANDLE hHandle,
  210. IN LPCWSTR pszPath,
  211. IN BOOL fCTL );
  212. HRESULT ConstructCertChain( PCCERT_CONTEXT pcLeafCert,
  213. LPWSTR pszLeafCertStore,
  214. LIST_ENTRY *pCertChain,
  215. PBOOL pfCompleteChain );
  216. HRESULT BuildCTLDescription( IN PCCTL_CONTEXT pcCTL,
  217. OUT LIST_ENTRY *pCTLCerts,
  218. OUT PCCERT_CONTEXT *ppcSigner );
  219. HRESULT GetCertChainSignature( IN LIST_ENTRY *pChain,
  220. OUT PBYTE *ppbSignature,
  221. IN OUT DWORD *pdwBufferSize,
  222. IN OUT DWORD *pdwPosition );
  223. HRESULT GetCTLSignature( PCCTL_CONTEXT pcCTL,
  224. LIST_ENTRY *pCTLCertsChain,
  225. PCCERT_CONTEXT pcSignerCert,
  226. PBYTE *ppbReplicationBuffer,
  227. DWORD *pdwBufferSize,
  228. DWORD *pdwPosition );
  229. HRESULT SerializeCertChain( IN LIST_ENTRY *pChain,
  230. IN OPEN_CERT_STORE_INFO *pStoreInfo,
  231. OUT PBYTE *ppbChainBuffer,
  232. IN OUT DWORD *pdwBufferSize,
  233. IN OUT DWORD *pdwPosition );
  234. HRESULT SerializeCTL( PCCTL_CONTEXT pcCTL,
  235. LIST_ENTRY *pCTLCertChain,
  236. PCCERT_CONTEXT pcSigner,
  237. PBYTE *ppbReplicationBuffer,
  238. DWORD *pdwBufferSize,
  239. DWORD *pdwPosition );
  240. HRESULT DeserializeInstanceInfo( IN OUT BYTE **ppbPosition,
  241. IN BYTE *pbEnd,
  242. OUT DWORD *pdwInstance );
  243. HRESULT DeserializeServerCert( IN OUT BYTE **ppbBuffer,
  244. IN BYTE *pbEnd );
  245. HRESULT DeserializeServerCTL( IN OUT BYTE **ppbBuffer,
  246. IN BYTE *pbEnd );
  247. BOOL ResizeBuffer( IN OUT BYTE **ppbBuffer,
  248. IN DWORD dwMinResize,
  249. IN OUT DWORD *pdwPresentSize );
  250. BOOL MBPathHasCAPIInfo( IN IMSAdminBase *pMB,
  251. METADATA_HANDLE hHandle,
  252. IN LPCWSTR pszPath,
  253. IN DWORD *adwProperties,
  254. IN DWORD cProperties );
  255. HRESULT GenerateHash( IN OPTIONAL HCRYPTPROV *phProv,
  256. IN ALG_ID aiAlg,
  257. IN BYTE *pbData,
  258. IN DWORD cbData,
  259. OUT BYTE **ppbHashBuffer,
  260. IN OUT DWORD *pcbHashSize,
  261. OUT OPTIONAL HCRYPTHASH *phHash );
  262. BOOL IsSelfSignedCert( IN PCCERT_CONTEXT pCertContext );
  263. HRESULT ExportAndSerializeServerPK( IN PCCERT_CONTEXT pcCert,
  264. IN OUT BYTE **ppbChainBuffer,
  265. IN OUT DWORD *pdwBufferSize,
  266. IN OUT DWORD *pdwPosition );
  267. HRESULT DeserializeAndImportServerPK( IN OUT BYTE **ppbBuffer,
  268. IN BYTE *pbEnd,
  269. OUT HCRYPTKEY *phKey,
  270. OUT PCRYPT_KEY_PROV_INFO pCKPI );
  271. HRESULT GenerateSessionKey( IN IMSAdminBase *pMB,
  272. OUT HCRYPTKEY *phKey,
  273. OUT BYTE *rgbRandom );
  274. VOID DeleteKey( IN HCRYPTKEY *phKey,
  275. IN LPCWSTR pszKeyContainer );
  276. VOID DeleteSessionKey( IN HCRYPTKEY *phKey );
  277. DWORD SizeOfCKPI( IN CRYPT_KEY_PROV_INFO *pInfo );
  278. VOID SerializeCKPI( OUT BYTE *pbBuffer,
  279. IN CRYPT_KEY_PROV_INFO *pInfo,
  280. OUT DWORD *pdwPosition );
  281. BOOL DeserializeCKPI( IN OUT BYTE **ppbBuffer,
  282. OUT CRYPT_KEY_PROV_INFO *pInfo );
  283. HRESULT DistributeCerts( IN HCERTSTORE hMemStore,
  284. IN BYTE *rgbCertHash,
  285. IN PCRYPT_KEY_PROV_INFO pCKPI );
  286. HRESULT ReadSessionKeySeed( IN IMSAdminBase *pMB,
  287. OUT BYTE **ppbbSeed,
  288. OUT DWORD *pcbSeed );
  289. HRESULT RegenerateSessionKey( IN IMSAdminBase *pMB,
  290. OUT HCRYPTKEY *phSessionKey );
  291. HRESULT EncryptBuffer( IN HCRYPTKEY hKey,
  292. IN OUT PBYTE *ppbReplicationInfo,
  293. IN OUT DWORD *pdwBufferSize,
  294. IN OUT DWORD *pdwPosition );
  295. HRESULT DecryptBuffer( IN HCRYPTKEY hKey,
  296. IN PBYTE pbEncrypted,
  297. IN DWORD cbEncrypted,
  298. OUT BYTE **ppbDecrypted,
  299. OUT BYTE **ppbEndDecrypted );
  300. HRESULT DeleteMBSessionKeyInfo ( IN IMSAdminBase *pMB );
  301. BOOL CertMatchesHash( IN PCCERT_CONTEXT pCert,
  302. IN BYTE *rgbHash,
  303. OUT BOOL *pfMatch);
  304. BOOL IsReplicableCert( IN PCCERT_CONTEXT pCert );
  305. BOOL SetLocalSystemSecurityOnKeyContainer( IN HCRYPTPROV hProv );
  306. BOOL IsFortezzaCert( IN PCCERT_CONTEXT pCert );
  307. LPWSTR mystrdup(LPWSTR pszIn IN);
  308. BOOL IsNumber( LPCWSTR pszName );
  309. #endif // _CERTCOMOBJ_HXX_