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.

564 lines
16 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: initcert.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef __INITCERT_H__
  11. #define __INITCERT_H__
  12. typedef enum {
  13. CS_UPGRADE_UNKNOWN = 0,
  14. CS_UPGRADE_NO, // install
  15. //CS_UPGRADE_NT4SP4 =2, // upgrade from NT4 certsrv v10 or SP4 with certsrv // upg unsupported
  16. //CS_UPGRADE_NT5BETA2 =3, // upgrade from NT5 Beta 2 // upg unsupported
  17. //CS_UPGRADE_NT5BETA3 =4, // upgrade from NT5 Beta 3 // upg unsupported
  18. CS_UPGRADE_WIN2000 =5, // upgrade from Win2K
  19. CS_UPGRADE_UNSUPPORTED, // upgrade is not supported
  20. CS_UPGRADE_WHISTLER, // upgrade from build to build
  21. } CS_ENUM_UPGRADE;
  22. typedef enum {
  23. ENUM_WIZ_UNKNOWN = 0,
  24. ENUM_WIZ_OCM,
  25. ENUM_WIZ_CATYPE,
  26. ENUM_WIZ_ADVANCE,
  27. ENUM_WIZ_IDINFO,
  28. ENUM_WIZ_KEYGEN,
  29. ENUM_WIZ_STORE,
  30. ENUM_WIZ_REQUEST,
  31. } ENUM_WIZPAGE;
  32. typedef struct csp_hash_tag
  33. {
  34. ALG_ID idAlg;
  35. WCHAR *pwszName;
  36. struct csp_hash_tag *next;
  37. struct csp_hash_tag *last;
  38. } CSP_HASH;
  39. typedef struct csp_info_tag {
  40. DWORD dwProvType;
  41. WCHAR *pwszProvName;
  42. BOOL fMachineKeyset;
  43. struct csp_info_tag *next;
  44. struct csp_info_tag *last;
  45. CSP_HASH *pHashList;
  46. } CSP_INFO;
  47. typedef struct key_list_tag
  48. {
  49. WCHAR *pwszName;
  50. struct key_list_tag *next;
  51. struct key_list_tag *last;
  52. } KEY_LIST;
  53. // reasons why enterprise CA cannot be installed
  54. typedef enum {
  55. ENUM_ENTERPRISE_UNAVAIL_REASON_AVAILABLE = 0, // enterprise can be installed
  56. ENUM_ENTERPRISE_UNAVAIL_REASON_DOMAIN_NOT_JOINED, // machine not joined to a domain
  57. ENUM_ENTERPRISE_UNAVAIL_REASON_DS_UNAVAILABLE, // no DC available
  58. ENUM_ENTERPRISE_UNAVAIL_REASON_NO_INSTALL_RIGHTS, // current user doesn't have the rights to install
  59. ENUM_ENTERPRISE_UNAVAIL_REASON_OLD_DS_VERSION, // DS version is too old, needs to be upgraded
  60. } ENUM_ENTERPRISE_UNAVAIL_REASON;
  61. typedef struct tagCAServerSetupInfo
  62. {
  63. // setup attributes
  64. // 0x0000
  65. ENUM_CATYPES CAType;
  66. WCHAR *pwszCACommonName;
  67. // 0x0020
  68. BOOL fAdvance;
  69. CSP_INFO *pCSPInfo; // currently selected CSP
  70. CSP_HASH *pHashInfo; // currently selected hash algorithm
  71. DWORD dwKeyLength;
  72. ENUM_PERIOD enumValidityPeriod;
  73. DWORD dwValidityPeriodCount;
  74. BOOL fUseDS;
  75. // 0x0040
  76. WCHAR *pwszSharedFolder;
  77. WCHAR *pwszDBDirectory;
  78. WCHAR *pwszLogDirectory;
  79. BOOL fSaveRequestAsFile;
  80. BOOL fCAsExist;
  81. WCHAR *pwszRequestFile;
  82. WCHAR *pwszParentCAMachine;
  83. WCHAR *pwszParentCAName;
  84. // 0x0060
  85. BOOL fPreserveDB;
  86. BOOL fInteractiveService; // allow service to interact
  87. // with the desktop
  88. // setup intermediate attributes
  89. ENUM_WIZPAGE LastWiz;
  90. WCHAR *pwszSanitizedName;
  91. CSP_INFO *pCSPInfoList; // list of all available CSPs
  92. CSP_INFO *pDefaultCSPInfo; // obj representing default CSP,
  93. // not a CSP in pCSPInfoList
  94. CSP_HASH *pDefaultHashInfo; // object representing default
  95. // hash algorithm, not a hash
  96. // algorighm in the currently
  97. // selected CSP
  98. KEY_LIST *pKeyList; // list of key containers for
  99. // 0x0080
  100. DWORD dwKeyLenMin; // minumum key length for the
  101. // currently selected CSP
  102. DWORD dwKeyLenMax; // maximum key length for the
  103. // currently selected CSP
  104. WCHAR *pwszValidityPeriodCount;
  105. LONG lExistingValidity;
  106. WCHAR *pwszCACertFile;
  107. HCERTSTORE hMyStore;
  108. CHAR *pszAlgId;
  109. BOOL fCertSrvWasRunning;
  110. // 0x00a0
  111. FILETIME NotBefore;
  112. FILETIME NotAfter;
  113. DWORD dwRevocationFlags;
  114. // setup intermediate attributes for unattended
  115. WCHAR *pwszCAType;
  116. WCHAR *pwszValidityPeriodString;
  117. WCHAR *pwszHashAlgorithm;
  118. // 0x00c0
  119. WCHAR *pwszKeyLength;
  120. BOOL fValidatedHashAndKey;
  121. WCHAR *pwszUseExistingCert;
  122. WCHAR *pwszPreserveDB;
  123. WCHAR *pwszPFXFile;
  124. WCHAR *pwszPFXPassword;
  125. WCHAR *pwszInteractiveService;
  126. // upgrade attributes
  127. DWORD dwUpgradeEditFlags;
  128. // 0x00e0
  129. BOOL fSavedCAInDS;
  130. BOOL fCreatedShare;
  131. WCHAR *pwszCustomPolicy;
  132. WCHAR *pwszzCustomExit;
  133. // * The following 2 variables replace these 5 variables:
  134. // fCreatedKey,
  135. // pwszRevertKey,
  136. // pwszImportKey,
  137. // pwszExistingKey,
  138. // fUseExistingKey
  139. //
  140. // * Invariant: fUseExistingKey == (NULL != pwszKeyContainerName)
  141. //
  142. // * pwszKeyContainerName should always contains the name of an existing
  143. // key container, or be NULL if a new key container needs to be created.
  144. // Once the new container is created, the variable holds the name of the
  145. // container.
  146. //
  147. // * Always use SetKeyContainerName() and ClearKeyContainerName() to modify
  148. // these variables. This makes sure that pwszDesanitizedKeyContainerName
  149. // is always in sync.
  150. WCHAR *pwszKeyContainerName; // exact name of the container
  151. // used by the CSP
  152. WCHAR *pwszDesanitizedKeyContainerName; // name displayed
  153. // to the user
  154. BOOL fDeletableNewKey; // TRUE iff the
  155. // KeyContainerName points to a
  156. // key container that we should
  157. // delete if we don't use.
  158. BOOL fKeyGenFailed; // TRUE if KeyGen failed
  159. // * The following 1 variable replace these 4 variables:
  160. // fUseExistingCert,
  161. // fFoundMatchedCertInStore,
  162. // fMatchedCertType,
  163. // pSCertContextFromStore
  164. //
  165. // * Invariant: fUseExistingCert==(NULL!=pccExistingCert)
  166. //
  167. // * pccExistingCert should always be a pointer to an existing cert context,
  168. // or be NULL if we are not using an existing cert
  169. //
  170. // * Always use SetExistingCertToUse() and ClearExistingCertToUse() to
  171. // modify these variables. This makes sure that pccExistingCert is
  172. // properly freed.
  173. // 0x0100
  174. CERT_CONTEXT const *pccExistingCert; // an open cert context
  175. CERT_CONTEXT const *pccUpgradeCert; // CA Cert context for upgrade
  176. DWORD dwCertNameId; // CA Cert NameId
  177. BOOL fUNCPathNotFound; // flag for default shared folder
  178. WCHAR *pwszDNSuffix; // CN=%1, DC=x, DC=y, DC=z -- dynamically generated template
  179. // 0x0114
  180. WCHAR *pwszFullCADN;
  181. ENUM_ENTERPRISE_UNAVAIL_REASON EnterpriseUnavailReason; // reason why can't install enterprise CA
  182. } CASERVERSETUPINFO;
  183. typedef struct tagCAWebClientSetupInfo
  184. {
  185. WCHAR *pwszWebCAMachine;
  186. WCHAR *pwszWebCAName;
  187. WCHAR *pwszSanitizedWebCAName;
  188. BOOL fUseDS;
  189. WCHAR *pwszSharedFolder;
  190. ENUM_CATYPES WebCAType;
  191. } CAWEBCLIENTSETUPINFO;
  192. typedef struct tagCASetupInfo
  193. {
  194. CASERVERSETUPINFO *pServer;
  195. CAWEBCLIENTSETUPINFO *pClient;
  196. } CASETUPINFO;
  197. typedef struct _PER_COMPONENT_DATA
  198. {
  199. // component generic
  200. WCHAR *pwszComponent; // Component name from OCM
  201. HINF MyInfHandle; // Open inf handle to per-component inf
  202. DWORDLONG Flags; // Operation flags from SETUP_DATA structure
  203. OCMANAGER_ROUTINES HelperRoutines;
  204. // setup related
  205. HINSTANCE hInstance;
  206. HRESULT hrContinue; // set code if fatal error
  207. WCHAR *pwszCustomMessage;
  208. int iErrMsg; // set msg id for fatal error pop up
  209. BOOL fShownErr; // set to TRUE if pop up earlier so avoid double
  210. BOOL fUnattended;
  211. BOOL fPostBase;
  212. WCHAR *pwszUnattendedFile;
  213. WCHAR *pwszServerName;
  214. WCHAR *pwszServerNameOld;
  215. WCHAR *pwszSystem32;
  216. HINF hinfCAPolicy;
  217. // CA related
  218. DWORD dwInstallStatus;
  219. CASETUPINFO CA;
  220. CS_ENUM_UPGRADE UpgradeFlag;
  221. BOOL fCreatedVRoot;
  222. DWORD dwVersion;
  223. } PER_COMPONENT_DATA;
  224. //+--------------------------------------------------------------------------
  225. // Prototypes:
  226. HRESULT
  227. csiGetKeyList(
  228. IN DWORD dwProvType,
  229. IN WCHAR const *pwszProvName,
  230. IN BOOL fMachineKeySet,
  231. IN BOOL fSilent,
  232. OUT KEY_LIST **ppKeyList);
  233. VOID
  234. csiFreeKeyList(
  235. IN OUT KEY_LIST *pKeyList);
  236. HRESULT
  237. csiBuildRequest(
  238. OPTIONAL IN HINF hInf,
  239. OPTIONAL IN CERT_CONTEXT const *pccPrevious,
  240. IN BYTE const *pbSubjectEncoded,
  241. IN DWORD cbSubjectEncoded,
  242. IN char const *pszAlgId,
  243. IN BOOL fNewKey,
  244. IN DWORD iCert,
  245. IN DWORD iKey,
  246. IN HCRYPTPROV hProv,
  247. IN HWND hwnd,
  248. IN HINSTANCE hInstance,
  249. IN BOOL fUnattended,
  250. OUT BYTE **ppbEncode,
  251. OUT DWORD *pcbEncode);
  252. HRESULT
  253. csiBuildFileName(
  254. IN WCHAR const *pwszDirPath,
  255. IN WCHAR const *pwszSanitizedName,
  256. IN WCHAR const *pwszExt,
  257. IN DWORD iCert,
  258. OUT WCHAR **ppszOut,
  259. HINSTANCE hInstance,
  260. BOOL fUnattended,
  261. IN HWND hwnd);
  262. HRESULT
  263. csiBuildCACertFileName(
  264. IN HINSTANCE hInstance,
  265. IN HWND hwnd,
  266. IN BOOL fUnattended,
  267. OPTIONAL IN WCHAR const *pwszSharedFolder,
  268. IN WCHAR const *pwszSanitizedName,
  269. IN WCHAR const *pwszExt,
  270. IN DWORD iCert,
  271. OUT WCHAR **ppwszCACertFile);
  272. HRESULT
  273. csiGetCARequestFileName(
  274. IN HINSTANCE hInstance,
  275. IN HWND hwnd,
  276. IN WCHAR const *pwszSanitizedCAName,
  277. IN DWORD iCertNew,
  278. IN DWORD iKey,
  279. OUT WCHAR **ppwszRequestFile);
  280. BOOL
  281. csiWriteDERToFile(
  282. IN WCHAR const *pwszFileName,
  283. IN BYTE const *pbDER,
  284. IN DWORD cbDER,
  285. IN HINSTANCE hInstance,
  286. IN BOOL fUnattended,
  287. IN HWND hwnd);
  288. HRESULT
  289. csiBuildAndWriteCert(
  290. IN HCRYPTPROV hCryptProv,
  291. IN CASERVERSETUPINFO const *pServer,
  292. OPTIONAL IN WCHAR const *pwszFile,
  293. IN WCHAR const *pwszEnrollFile,
  294. OPTIONAL IN CERT_CONTEXT const *pCertContextFromStore,
  295. OPTIONAL OUT CERT_CONTEXT const **ppCertContextOut,
  296. IN WCHAR const *pwszCAType,
  297. IN HINSTANCE hInstance,
  298. IN BOOL fUnattended,
  299. IN HWND hwnd);
  300. VOID
  301. csiFreeCertNameInfo(
  302. IN OUT CERT_NAME_INFO *pNameInfo);
  303. HRESULT
  304. csiGetCRLPublicationURLTemplates(
  305. IN BOOL fUseDS,
  306. IN WCHAR const *pwszSystem32,
  307. OUT WCHAR **ppwszz);
  308. HRESULT
  309. csiGetCACertPublicationURLTemplates(
  310. IN BOOL fUseDS,
  311. IN WCHAR const *pwszSystem32,
  312. OUT WCHAR **ppwszz);
  313. HRESULT
  314. csiSetupCAInDS(
  315. IN WCHAR const *pwszCAServer,
  316. IN WCHAR const *pwszSanitizedCAName,
  317. IN WCHAR const *pwszCADisplayName,
  318. IN BOOL fLoadDefaultTemplates,
  319. IN ENUM_CATYPES caType,
  320. IN DWORD iCert,
  321. IN DWORD iCRL,
  322. IN BOOL fRenew,
  323. IN CERT_CONTEXT const *pCert);
  324. HRESULT
  325. csiFillKeyProvInfo(
  326. IN WCHAR const *pwszContainerName,
  327. IN WCHAR const *pwszProvName,
  328. IN DWORD dwProvType,
  329. IN BOOL const fMachineKeyset,
  330. OUT CRYPT_KEY_PROV_INFO *pKeyProvInfo);
  331. VOID
  332. csiFreeKeyProvInfo(
  333. IN OUT CRYPT_KEY_PROV_INFO *pKeyProvInfo);
  334. BOOL
  335. csiIsAnyDSCAAvailable(VOID);
  336. HRESULT
  337. csiSubmitCARequest(
  338. IN HINSTANCE hInstance,
  339. IN BOOL fUnattended,
  340. IN HWND hwnd,
  341. IN BOOL fRenew,
  342. IN DWORD iCert,
  343. IN BOOL fRetrievePending,
  344. IN WCHAR const *pwszSanitizedCAName,
  345. IN WCHAR const *pwszParentCAMachine,
  346. IN WCHAR const *pwszParentCAName,
  347. IN BYTE const *pbRequest,
  348. IN DWORD cbRequest,
  349. OUT BSTR *pbStrChain);
  350. HRESULT
  351. csiFinishInstallationFromPKCS7(
  352. IN HINSTANCE hInstance,
  353. IN BOOL fUnattended,
  354. IN HWND hwnd,
  355. IN WCHAR const *pwszSanitizedCAName,
  356. IN WCHAR const *pwszCACommonName,
  357. IN CRYPT_KEY_PROV_INFO const *pKeyProvInfo,
  358. IN ENUM_CATYPES CAType,
  359. IN DWORD iCert,
  360. IN DWORD iCRL,
  361. IN BOOL fUseDS,
  362. IN BOOL fRenew,
  363. IN WCHAR const *pwszServerName,
  364. IN BYTE const *pbChainOrCert,
  365. IN DWORD cbChainOrCert,
  366. OPTIONAL IN WCHAR const *pwszCACertFile);
  367. HRESULT
  368. csiSaveCertAndKeys(
  369. IN CERT_CONTEXT const *pCert,
  370. IN HCERTSTORE hAdditionalStore,
  371. IN CRYPT_KEY_PROV_INFO const *pkpi,
  372. IN ENUM_CATYPES CAType);
  373. HRESULT
  374. csiInitializeCertSrvSecurity(
  375. IN WCHAR const *pwszSanitizedCAName,
  376. IN BOOL fUseEnterpriseACL, // which ACL to use
  377. IN BOOL fSetDsSecurity); // whether to set DS security
  378. HRESULT
  379. csiGenerateCAKeys(
  380. IN WCHAR const *pwszContainer,
  381. IN WCHAR const *pwszProvName,
  382. IN DWORD dwProvType,
  383. IN BOOL fMachineKeyset,
  384. IN DWORD dwKeyLength,
  385. IN HINSTANCE hInstance,
  386. IN BOOL fUnattended,
  387. IN BOOL fEnableKeyCounting,
  388. IN HWND hwnd,
  389. OUT BOOL *pfKeyGenFailed);
  390. HRESULT
  391. csiGenerateKeysOnly(
  392. IN WCHAR const *pwszContainer,
  393. IN WCHAR const *pwszProvName,
  394. IN DWORD dwProvType,
  395. IN BOOL fMachineKeyset,
  396. IN DWORD dwKeyLength,
  397. IN BOOL fUnattended,
  398. IN BOOL fEnableKeyCounting,
  399. OUT HCRYPTPROV *phProv,
  400. OUT int *piMsg);
  401. HRESULT
  402. csiSetKeyContainerSecurity(
  403. IN HCRYPTPROV hProv);
  404. HRESULT
  405. csiSetAdminOnlyFolderSecurity(
  406. IN LPCWSTR szFolderPath,
  407. IN BOOL fAllowEveryoneRead,
  408. IN BOOL fUseDS);
  409. VOID
  410. csiLogOpen(
  411. IN char const *pszFile);
  412. VOID
  413. csiLogClose();
  414. VOID
  415. csiLog(
  416. IN DWORD dwFile,
  417. IN DWORD dwLine,
  418. IN HRESULT hrMsg,
  419. IN UINT idMsg,
  420. OPTIONAL IN WCHAR const *pwsz1,
  421. OPTIONAL IN WCHAR const *pwsz2,
  422. OPTIONAL IN DWORD const *pdw);
  423. VOID
  424. csiLogFileVersion(
  425. IN DWORD dwFile,
  426. IN DWORD dwLine,
  427. IN UINT idMsg,
  428. IN WCHAR const *pwszFile,
  429. IN char const *pszVersion);
  430. VOID
  431. csiLogTime(
  432. IN DWORD dwFile,
  433. IN DWORD dwLine,
  434. IN UINT idMsg);
  435. VOID
  436. csiLogDWord(
  437. IN DWORD dwFile,
  438. IN DWORD dwLine,
  439. IN UINT idMsg,
  440. IN DWORD dwVal);
  441. VOID
  442. csiLogInfError(
  443. IN HINF hInf,
  444. IN HRESULT hr);
  445. HRESULT
  446. csiGetProviderTypeFromProviderName(
  447. IN WCHAR const *pwszName,
  448. OUT DWORD *pdwType);
  449. HRESULT
  450. csiUpgradeCertSrvSecurity(
  451. IN WCHAR const *pwszSanitizedCAName,
  452. BOOL fUseEnterpriseACL, // which ACL to use
  453. BOOL fSetDsSecurity, // whether to set security on DS object
  454. CS_ENUM_UPGRADE UpgradeType);
  455. HRESULT
  456. csiGetCRLPublicationParams(
  457. BOOL fBaseCRL,
  458. WCHAR **ppwszCRLPeriodString,
  459. DWORD *pdwCRLPeriodCount);
  460. HRESULT AddCNAndEncode(
  461. LPCWSTR pcwszName,
  462. LPCWSTR pcwszDNSuffix,
  463. BYTE** ppbEncodedDN,
  464. DWORD *pcbEncodedDN);
  465. HRESULT
  466. AddCAMachineToCertPublishers(VOID);
  467. HRESULT
  468. RemoveCAMachineFromCertPublishers(VOID);
  469. HRESULT
  470. AddCAMachineToPreWin2kGroup(VOID);
  471. HRESULT
  472. RemoveCAMachineFromPreWin2kGroup(VOID);
  473. #define CSILOG(hr, idMsg, pwsz1, pwsz2, pdw) \
  474. csiLog(__dwFILE__, __LINE__, (hr), (idMsg), (pwsz1), (pwsz2), (pdw))
  475. #define CSILOGFILEVERSION(idMsg, pwszFile, pszVersion) \
  476. csiLogFileVersion(__dwFILE__, __LINE__, (idMsg), (pwszFile), (pszVersion))
  477. #define CSILOGTIME(idMsg) \
  478. csiLogTime(__dwFILE__, __LINE__, (idMsg))
  479. #define CSILOGDWORD(idMsg, dw) \
  480. csiLogDWord(__dwFILE__, __LINE__, (idMsg), (dw))
  481. #endif //__INITCERT_H__