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.

400 lines
9.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: policy.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "certpsam.h"
  11. #include "resource.h"
  12. #ifndef wszATTREMAIL1
  13. # define wszATTREMAIL1 TEXT("E")
  14. # define wszATTREMAIL2 TEXT("EMail")
  15. #endif
  16. #ifndef wszCERTTYPE_SUBORDINATE_CA
  17. # define wszCERTTYPE_SUBORDINATE_CA L"SubCA"
  18. #endif
  19. #ifndef wszCERTTYPE_CROSS_CA
  20. # define wszCERTTYPE_CROSS_CA L"CrossCA"
  21. #endif
  22. extern BOOL fDebug;
  23. HRESULT
  24. ReqInitialize(
  25. IN ICertServerPolicy *pServer);
  26. VOID
  27. ReqCleanup(VOID);
  28. class CRequestInstance;
  29. #ifndef __BSTRC__DEFINED__
  30. #define __BSTRC__DEFINED__
  31. typedef OLECHAR const *BSTRC;
  32. #endif
  33. HRESULT
  34. polGetServerCallbackInterface(
  35. OUT ICertServerPolicy **ppServer,
  36. IN LONG Context);
  37. HRESULT
  38. polGetRequestStringProperty(
  39. IN ICertServerPolicy *pServer,
  40. IN WCHAR const *pwszPropertyName,
  41. OUT BSTR *pstrOut);
  42. HRESULT
  43. polGetCertificateStringProperty(
  44. IN ICertServerPolicy *pServer,
  45. IN WCHAR const *pwszPropertyName,
  46. OUT BSTR *pstrOut);
  47. HRESULT
  48. polGetRequestLongProperty(
  49. IN ICertServerPolicy *pServer,
  50. IN WCHAR const *pwszPropertyName,
  51. OUT LONG *plOut);
  52. HRESULT
  53. polGetCertificateLongProperty(
  54. IN ICertServerPolicy *pServer,
  55. IN WCHAR const *pwszPropertyName,
  56. OUT LONG *plOut);
  57. HRESULT
  58. polGetRequestAttribute(
  59. IN ICertServerPolicy *pServer,
  60. IN WCHAR const *pwszAttributeName,
  61. OUT BSTR *pstrOut);
  62. HRESULT
  63. polGetCertificateExtension(
  64. IN ICertServerPolicy *pServer,
  65. IN WCHAR const *pwszExtensionName,
  66. IN DWORD dwPropType,
  67. IN OUT VARIANT *pvarOut);
  68. HRESULT
  69. polSetCertificateExtension(
  70. IN ICertServerPolicy *pServer,
  71. IN WCHAR const *pwszExtensionName,
  72. IN DWORD dwPropType,
  73. IN DWORD dwExtFlags,
  74. IN VARIANT const *pvarIn);
  75. DWORD
  76. polFindObjIdInList(
  77. IN WCHAR const *pwsz,
  78. IN DWORD count,
  79. IN WCHAR const * const *ppwsz);
  80. //
  81. // Class CCertPolicySample
  82. //
  83. // Actual policy module for a CA Policy
  84. //
  85. //
  86. class CCertPolicySample:
  87. public CComDualImpl<ICertPolicy2, &IID_ICertPolicy2, &LIBID_CERTPOLICYSAMPLELib>,
  88. public ISupportErrorInfo,
  89. public CComObjectRoot,
  90. public CComCoClass<CCertPolicySample, &CLSID_CCertPolicySample>
  91. {
  92. public:
  93. CCertPolicySample()
  94. {
  95. m_strDescription = NULL;
  96. // RevocationExtension variables:
  97. m_dwRevocationFlags = 0;
  98. m_wszASPRevocationURL = NULL;
  99. m_dwDispositionFlags = 0;
  100. m_dwEditFlags = 0;
  101. m_cEnableRequestExtensions = 0;
  102. m_apwszEnableRequestExtensions = NULL;
  103. m_cEnableEnrolleeRequestExtensions = 0;
  104. m_apwszEnableEnrolleeRequestExtensions = NULL;
  105. m_cDisableExtensions = 0;
  106. m_apwszDisableExtensions = NULL;
  107. // CA Name
  108. m_strRegStorageLoc = NULL;
  109. m_strCAName = NULL;
  110. m_strCASanitizedName = NULL;
  111. m_strCASanitizedDSName = NULL;
  112. m_strMachineDNSName = NULL;
  113. // CA and cert type info
  114. m_CAType = ENUM_UNKNOWN_CA;
  115. m_pCert = NULL;
  116. m_iCRL = 0;
  117. }
  118. ~CCertPolicySample();
  119. BEGIN_COM_MAP(CCertPolicySample)
  120. COM_INTERFACE_ENTRY(IDispatch)
  121. COM_INTERFACE_ENTRY(ICertPolicy)
  122. COM_INTERFACE_ENTRY(ICertPolicy2)
  123. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  124. END_COM_MAP()
  125. DECLARE_NOT_AGGREGATABLE(CCertPolicySample)
  126. // Remove the comment from the line above if you don't want your object to
  127. // support aggregation. The default is to support it
  128. DECLARE_REGISTRY(
  129. CCertPolicySample,
  130. wszCLASS_CERTPOLICYSAMPLE TEXT(".1"),
  131. wszCLASS_CERTPOLICYSAMPLE,
  132. IDS_CERTPOLICY_DESC,
  133. THREADFLAGS_BOTH)
  134. // ISupportsErrorInfo
  135. STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
  136. // ICertPolicy
  137. public:
  138. STDMETHOD(Initialize)(
  139. /* [in] */ BSTR const strConfig);
  140. STDMETHOD(VerifyRequest)(
  141. /* [in] */ BSTR const strConfig,
  142. /* [in] */ LONG Context,
  143. /* [in] */ LONG bNewRequest,
  144. /* [in] */ LONG Flags,
  145. /* [out, retval] */ LONG __RPC_FAR *pDisposition);
  146. STDMETHOD(GetDescription)(
  147. /* [out, retval] */ BSTR __RPC_FAR *pstrDescription);
  148. STDMETHOD(ShutDown)();
  149. // ICertPolicy2
  150. public:
  151. STDMETHOD(GetManageModule)(
  152. /* [out, retval] */ ICertManageModule **ppManageModule);
  153. public:
  154. HRESULT AddBasicConstraintsCommon(
  155. IN ICertServerPolicy *pServer,
  156. IN CERT_EXTENSION const *pExtension,
  157. IN BOOL fCA,
  158. IN BOOL fEnableExtension);
  159. BSTRC GetPolicyDescription() { return(m_strDescription); }
  160. HRESULT AddV1TemplateNameExtension(
  161. IN ICertServerPolicy *pServer,
  162. OPTIONAL IN WCHAR const *pwszTemplateName);
  163. private:
  164. CERT_CONTEXT const *_GetIssuer(
  165. IN ICertServerPolicy *pServer);
  166. HRESULT _EnumerateExtensions(
  167. IN ICertServerPolicy *pServer,
  168. IN LONG bNewRequest,
  169. IN BOOL fFirstPass,
  170. IN BOOL fEnableEnrolleeExtensions,
  171. IN DWORD cCriticalExtensions,
  172. IN WCHAR const * const *apwszCriticalExtensions);
  173. #if DBG_CERTSRV
  174. VOID _DumpStringArray(
  175. IN char const *pszType,
  176. IN DWORD count,
  177. IN LPWSTR const *apwsz);
  178. #else
  179. #define _DumpStringArray(pszType, count, apwsz)
  180. #endif
  181. VOID _FreeStringArray(
  182. IN OUT DWORD *pcString,
  183. IN OUT LPWSTR **papwsz);
  184. VOID _Cleanup();
  185. HRESULT _SetSystemStringProp(
  186. IN ICertServerPolicy *pServer,
  187. IN WCHAR const *pwszName,
  188. OPTIONAL IN WCHAR const *pwszValue);
  189. HRESULT _AddStringArray(
  190. IN WCHAR const *pwszzValue,
  191. IN BOOL fURL,
  192. IN OUT DWORD *pcStrings,
  193. IN OUT LPWSTR **papwszRegValues);
  194. HRESULT _ReadRegistryString(
  195. IN HKEY hkey,
  196. IN BOOL fURL,
  197. IN WCHAR const *pwszRegName,
  198. IN WCHAR const *pwszSuffix,
  199. OUT LPWSTR *pwszRegValue);
  200. HRESULT _ReadRegistryStringArray(
  201. IN HKEY hkey,
  202. IN BOOL fURL,
  203. IN DWORD dwFlags,
  204. IN DWORD cRegNames,
  205. IN DWORD *aFlags,
  206. IN WCHAR const * const *apwszRegNames,
  207. IN OUT DWORD *pcStrings,
  208. IN OUT LPWSTR **papwszRegValues);
  209. VOID _InitRevocationExtension(
  210. IN HKEY hkey);
  211. VOID _InitRequestExtensionList(
  212. IN HKEY hkey);
  213. VOID _InitDisableExtensionList(
  214. IN HKEY hkey);
  215. HRESULT _AddRevocationExtension(
  216. IN ICertServerPolicy *pServer);
  217. HRESULT _AddOldCertTypeExtension(
  218. IN ICertServerPolicy *pServer,
  219. IN BOOL fCA);
  220. HRESULT _AddAuthorityKeyId(
  221. IN ICertServerPolicy *pServer);
  222. HRESULT _AddDefaultKeyUsageExtension(
  223. IN ICertServerPolicy *pServer,
  224. IN BOOL fCA);
  225. HRESULT _AddEnhancedKeyUsageExtension(
  226. IN ICertServerPolicy *pServer);
  227. HRESULT _AddDefaultBasicConstraintsExtension(
  228. IN ICertServerPolicy *pServer,
  229. IN BOOL fCA);
  230. HRESULT _SetValidityPeriod(
  231. IN ICertServerPolicy *pServer);
  232. private:
  233. // RevocationExtension variables:
  234. CERT_CONTEXT const *m_pCert;
  235. BSTR m_strDescription;
  236. DWORD m_dwRevocationFlags;
  237. LPWSTR m_wszASPRevocationURL;
  238. DWORD m_dwDispositionFlags;
  239. DWORD m_dwEditFlags;
  240. DWORD m_CAPathLength;
  241. DWORD m_cEnableRequestExtensions;
  242. LPWSTR *m_apwszEnableRequestExtensions;
  243. DWORD m_cEnableEnrolleeRequestExtensions;
  244. LPWSTR *m_apwszEnableEnrolleeRequestExtensions;
  245. DWORD m_cDisableExtensions;
  246. LPWSTR *m_apwszDisableExtensions;
  247. // CertTypeExtension variables:
  248. BSTR m_strRegStorageLoc;
  249. BSTR m_strCAName;
  250. BSTR m_strCASanitizedName;
  251. BSTR m_strCASanitizedDSName;
  252. BSTR m_strMachineDNSName;
  253. // CA and cert type info
  254. ENUM_CATYPES m_CAType;
  255. DWORD m_iCert;
  256. DWORD m_iCRL;
  257. };
  258. //
  259. // Class CRequestInstance
  260. //
  261. // Instance data for a certificate that is being created.
  262. //
  263. class CRequestInstance
  264. {
  265. public:
  266. CRequestInstance()
  267. {
  268. m_strTemplateName = NULL;
  269. m_strTemplateObjId = NULL;
  270. m_pPolicy = NULL;
  271. }
  272. ~CRequestInstance();
  273. HRESULT Initialize(
  274. IN CCertPolicySample *pPolicy,
  275. IN ICertServerPolicy *pServer,
  276. OUT BOOL *pfEnableEnrolleeExtensions);
  277. HRESULT SetTemplateName(
  278. IN ICertServerPolicy *pServer,
  279. IN OPTIONAL WCHAR const *pwszTemplateName,
  280. IN OPTIONAL WCHAR const *pwszTemplateObjId);
  281. BSTRC GetTemplateName() { return(m_strTemplateName); }
  282. BSTRC GetTemplateObjId() { return(m_strTemplateObjId); }
  283. BOOL IsCARequest() { return(m_fCA); }
  284. CCertPolicySample *GetPolicy() { return(m_pPolicy); }
  285. private:
  286. HRESULT _SetFlagsProperty(
  287. IN ICertServerPolicy *pServer,
  288. IN WCHAR const *pwszPropName,
  289. IN DWORD dwFlags);
  290. BOOL _TemplateNamesMatch(
  291. IN WCHAR const *pwszTemplateName1,
  292. IN WCHAR const *pwszTemplateName2,
  293. OUT BOOL *pfTemplateMissing);
  294. VOID _Cleanup();
  295. private:
  296. CCertPolicySample *m_pPolicy;
  297. BSTR m_strTemplateName; // certificate type requested
  298. BSTR m_strTemplateObjId; // certificate type requested
  299. DWORD m_dwTemplateMajorVersion;
  300. DWORD m_dwTemplateMinorVersion;
  301. BOOL m_fCA;
  302. };