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.

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