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.

806 lines
29 KiB

  1. //--------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation, 1996 - 1999
  3. //
  4. // File: wzrdpvk.h
  5. //
  6. // Contents: The private include file for cryptext.dll.
  7. //
  8. // History: 16-09-1997 xiaohs created
  9. //
  10. //--------------------------------------------------------------
  11. #ifndef WZRDPVK_H
  12. #define WZRDPVK_H
  13. #include <windows.h>
  14. #include <stddef.h>
  15. #include <malloc.h>
  16. #include <shellapi.h>
  17. #include <shlobj.h>
  18. #include <string.h>
  19. #include <objbase.h>
  20. #include <windowsx.h>
  21. #include <lmcons.h>
  22. #include <prsht.h>
  23. #include <stdlib.h>
  24. #include <search.h>
  25. #include <commctrl.h>
  26. #include <rpc.h>
  27. #include <commdlg.h>
  28. #include <objsel.h>
  29. #include "wincrypt.h"
  30. #include "unicode.h"
  31. #include "unicode5.h"
  32. #include "crtem.h"
  33. #include "certcli.h"
  34. #include "certrpc.h"
  35. #include "cryptui.h"
  36. #include "lenroll.h"
  37. #include "pfx.h"
  38. #include "wintrust.h"
  39. #include "signer.h"
  40. #include "dbgdef.h"
  41. #include "keysvc.h"
  42. #include "keysvcc.h"
  43. #include "certsrv.h"
  44. #include "resource.h"
  45. #include "internal.h"
  46. #include "certca.h"
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. //global data
  51. extern HINSTANCE g_hmodThisDll;
  52. #define MAX_STRING_SIZE 512
  53. #define MAX_TITLE_LENGTH 200
  54. #define g_dwMsgAndCertEncodingType PKCS_7_ASN_ENCODING | X509_ASN_ENCODING
  55. #define g_wszTimeStamp L"http://timestamp.verisign.com/scripts/timstamp.dll"
  56. // Macros to allow for easier definition of locally scoped functions
  57. // and data. In the example below, observe that the helper function
  58. // "functionHelper" does not pollute the gobal namespace, yet still
  59. // provides a procedural abstraction for use within "function".
  60. //
  61. // Example:
  62. //
  63. // void function() {
  64. // LocalScope(HelperScope):
  65. // void functionHelper() {
  66. // // Do something here.
  67. // }
  68. // EndLocalScope;
  69. //
  70. // while (...) {
  71. // ...
  72. // local.functionHelper();
  73. // }
  74. // }
  75. //
  76. #define LocalScope(ScopeName) struct ScopeName##TheLocalScope { public
  77. #define EndLocalScope } local
  78. // Simple error-handling macros.
  79. //
  80. // Same as _JumpCondition, but with a third parameter, expr.
  81. // Expr is not used in the macro, and is executed for side effects only.
  82. #define _JumpConditionWithExpr(condition, label, expr) if (condition) { expr; goto label; } else { }
  83. // A macro for the common test & goto instruction combination:
  84. #define _JumpCondition(condition, label) if (condition) { goto label; } else { }
  85. //-----------------------------------------------------------------------
  86. // ENROLL_PURPOSE_INFO
  87. //
  88. //------------------------------------------------------------------------
  89. typedef struct _ENROLL_PURPOSE_INFO
  90. {
  91. LPSTR pszOID;
  92. LPWSTR pwszName;
  93. BOOL fSelected;
  94. BOOL fFreeOID;
  95. BOOL fFreeName;
  96. }ENROLL_PURPOSE_INFO;
  97. //-----------------------------------------------------------------------
  98. // ENROLL_OID_INFO
  99. //
  100. //------------------------------------------------------------------------
  101. typedef struct _ENROLL_OID_INFO
  102. {
  103. LPWSTR pwszName;
  104. BOOL fSelected;
  105. LPSTR pszOID;
  106. }ENROLL_OID_INFO;
  107. //-----------------------------------------------------------------------
  108. // ENROLL_CERT_TYPE_INFO
  109. //
  110. //------------------------------------------------------------------------
  111. typedef struct _ENROLL_CERT_TYPE_INFO
  112. {
  113. LPWSTR pwszDNName; //the fully distinguished DN name of the cert type
  114. LPWSTR pwszCertTypeName;
  115. BOOL fSelected;
  116. PCERT_EXTENSIONS pCertTypeExtensions;
  117. DWORD dwKeySpec;
  118. DWORD dwMinKeySize;
  119. DWORD dwRASignature;
  120. DWORD dwCSPCount; //the count of CSP list
  121. DWORD *rgdwCSP; //the array of CSP list
  122. DWORD dwEnrollmentFlags;
  123. DWORD dwSubjectNameFlags;
  124. DWORD dwPrivateKeyFlags;
  125. DWORD dwGeneralFlags;
  126. }ENROLL_CERT_TYPE_INFO;
  127. //-----------------------------------------------------------------------
  128. // PURPOSE_INFO_CALL_BACK
  129. //
  130. //------------------------------------------------------------------------
  131. typedef struct _PURPOSE_INFO_CALL_BACK
  132. {
  133. DWORD *pdwCount;
  134. ENROLL_PURPOSE_INFO ***pprgPurpose;
  135. }PURPOSE_INFO_CALL_BACK;
  136. //-----------------------------------------------------------------------
  137. // PURPOSE_INFO_CALL_BACK
  138. //
  139. //------------------------------------------------------------------------
  140. typedef struct _OID_INFO_CALL_BACK
  141. {
  142. DWORD *pdwOIDCount;
  143. ENROLL_OID_INFO **pprgOIDInfo;
  144. }OID_INFO_CALL_BACK;
  145. ///-----------------------------------------------------------------------
  146. // CRYPT_WIZ_CERT_CA
  147. //
  148. //------------------------------------------------------------------------
  149. typedef struct _CRYPTUI_WIZ_CERT_CA
  150. {
  151. DWORD dwSize;
  152. LPWSTR pwszCALocation;
  153. LPWSTR pwszCAName;
  154. BOOL fSelected;
  155. DWORD dwOIDInfo;
  156. ENROLL_OID_INFO *rgOIDInfo;
  157. DWORD dwCertTypeInfo;
  158. ENROLL_CERT_TYPE_INFO *rgCertTypeInfo;
  159. }CRYPTUI_WIZ_CERT_CA, *PCRYPTUI_WIZ_CERT_CA;
  160. typedef const CRYPTUI_WIZ_CERT_CA *PCCRYPTUI_WIZ_CERT_CA;
  161. ///-----------------------------------------------------------------------
  162. // CRYPTUI_WIZ_CERT_CA_INFO
  163. //
  164. //------------------------------------------------------------------------
  165. typedef struct _CRYPTUI_WIZ_CERT_CA_INFO
  166. {
  167. DWORD dwSize;
  168. DWORD dwCA;
  169. PCRYPTUI_WIZ_CERT_CA rgCA;
  170. }CRYPTUI_WIZ_CERT_CA_INFO, *PCRYPTUI_WIZ_CERT_CA_INFO;
  171. typedef const CRYPTUI_WIZ_CERT_CA_INFO *PCCRYPTUI_WIZ_CERT_CA_INFO;
  172. typedef void * HCERTREQUESTER;
  173. #define CRYPTUI_WIZ_CERT_REQUEST_STATUS_INSTALL_FAILED 10
  174. #define CRYPTUI_WIZ_CERT_REQUEST_STATUS_INSTALL_CANCELLED 11
  175. #define CRYPTUI_WIZ_CERT_REQUEST_STATUS_KEYSVC_FAILED 12
  176. #define CRYPTUI_WIZ_CERT_REQUEST_STATUS_REQUEST_CREATED 13
  177. //-----------------------------------------------------------------------
  178. // CERT_WIZARD_INFO
  179. //
  180. //
  181. // This struct contains everything you will ever need to enroll(renew)
  182. // a certificate. This struct is private to the dll
  183. //------------------------------------------------------------------------
  184. typedef struct _CERT_WIZARD_INFO
  185. {
  186. DWORD dwFlags;
  187. DWORD dwPurpose;
  188. HWND hwndParent;
  189. BOOL fConfirmation;
  190. LPCWSTR pwszConfirmationTitle;
  191. UINT idsConfirmTitle;
  192. UINT idsText; //the ids for message box
  193. HRESULT hr; //the hresult of I_EnrollCertificate
  194. BOOL fNewKey;
  195. DWORD dwPostOption;
  196. PCCERT_CONTEXT pCertContext;
  197. BOOL fLocal;
  198. LPCWSTR pwszMachineName;
  199. LPCWSTR pwszAccountName;
  200. DWORD dwStoreFlags;
  201. void *pAuthentication;
  202. LPCWSTR pwszRequestString;
  203. LPWSTR pwszCALocation;
  204. LPWSTR pwszCAName;
  205. PCRYPTUI_WIZ_CERT_CA_INFO pCertCAInfo;
  206. DWORD dwCAIndex;
  207. LPCWSTR pwszDesStore;
  208. LPCWSTR pwszCertDNName;
  209. LPCSTR pszHashAlg;
  210. LPWSTR pwszFriendlyName;
  211. LPWSTR pwszDescription;
  212. DWORD dwProviderType;
  213. LPWSTR pwszProvider;
  214. DWORD dwProviderFlags;
  215. LPCWSTR pwszKeyContainer;
  216. DWORD dwKeySpec;
  217. DWORD dwGenKeyFlags;
  218. DWORD dwMinKeySize;
  219. DWORD dwEnrollmentFlags;
  220. DWORD dwSubjectNameFlags;
  221. DWORD dwPrivateKeyFlags;
  222. DWORD dwGeneralFlags;
  223. HFONT hBigBold;
  224. HFONT hBold;
  225. DWORD dwCSPCount;
  226. DWORD *rgdwProviderType;
  227. LPWSTR *rgwszProvider;
  228. BOOL fCertTypeChanged; //Whether user has changed the cert type selection:
  229. DWORD dwStatus;
  230. PCERT_EXTENSIONS pCertRequestExtensions;
  231. PCCERT_CONTEXT pNewCertContext;
  232. LPWSTR pwszSelectedCertTypeDN; //the DN name of the selected cert type
  233. BOOL fUICSP; //fCSPPage: whether we need to show the CSP page in the UI
  234. BOOL fUIAdv; //whether we need to show the advanced options in the UI
  235. BOOL fCAInput; //whether user has passed me the CA information
  236. int iOrgCertType; //mark the original selected CertType index
  237. int iOrgCSP; //mark the original selected CSP index
  238. DWORD dwOrgCA; //mark the original selected CA. This CA has priority when we make our CA selection
  239. BOOL fMachine;
  240. BOOL fIgnore; //whether we ignore the dwKeySpec and exportable GenKeyFlags.
  241. BOOL fKnownCSP; //whether the CSP was selected by the API
  242. DWORD dwOrgCSPType; //the orignal CSP type
  243. LPWSTR pwszOrgCSPName; //the orignal CSP name
  244. LPWSTR *awszAllowedCertTypes; //Allowed cert types for remote enrollment or local machin enrollment
  245. LPWSTR *awszValidCA; //Allowed cert types for remote enrollment or local machin enrollment
  246. HCURSOR hPrevCursor; //the privous cursor before we change it to the hour glass
  247. HCURSOR hWinPrevCursor; //the privous cursor before we change it to the hour glass
  248. BOOL fCursorChanged; //keep track if the cursor has been changed
  249. LPWSTR pwszCADisplayName; //the cached CA display name.
  250. HCERTREQUESTER hRequester;
  251. }CERT_WIZARD_INFO;
  252. //-----------------------------------------------------------------------
  253. // ENROLL_PAGE_INFO
  254. //
  255. //------------------------------------------------------------------------
  256. typedef struct _ENROLL_PAGE_INFO
  257. {
  258. LPCWSTR pszTemplate;
  259. DLGPROC pfnDlgProc;
  260. }ENROLL_PAGE_INFO;
  261. //-----------------------------------------------------------------------
  262. // Constats
  263. //
  264. //------------------------------------------------------------------------
  265. #define ENROLL_PROP_SHEET 6
  266. #define RENEW_PROP_SHEET 5
  267. #define IMPORT_PROP_SHEET 5
  268. #define BUILDCTL_PROP_SHEET 6
  269. #define SIGN_PROP_SHEET 10
  270. //flags for the column sorting function's lParamSort
  271. #define SORT_COLUMN_ISSUER 0x0001
  272. #define SORT_COLUMN_SUBJECT 0x0002
  273. #define SORT_COLUMN_EXPIRATION 0x0004
  274. #define SORT_COLUMN_PURPOSE 0x0008
  275. #define SORT_COLUMN_NAME 0x0010
  276. #define SORT_COLUMN_LOCATION 0x0020
  277. #define SORT_COLUMN_ASCEND 0x00010000
  278. #define SORT_COLUMN_DESCEND 0x00020000
  279. //-----------------------------------------------------------------------
  280. // Function Prototypes
  281. //
  282. //------------------------------------------------------------------------
  283. BOOL InitCertCAOID(PCCRYPTUI_WIZ_CERT_REQUEST_INFO pCertRequestInfo,
  284. DWORD *pdwOIDInfo,
  285. ENROLL_OID_INFO **pprgOIDInfo);
  286. BOOL FreeCertCAOID(DWORD dwOIDInfo,
  287. ENROLL_OID_INFO *pOIDInfo);
  288. BOOL InitCertCA(CERT_WIZARD_INFO *pCertWizardInfo,
  289. PCRYPTUI_WIZ_CERT_CA pCertCA,
  290. LPWSTR pwszCALocation,
  291. LPWSTR pwszCAName,
  292. BOOL fCASelected,
  293. PCCRYPTUI_WIZ_CERT_REQUEST_INFO pCertRequestInfo,
  294. DWORD dwOIDInfo,
  295. ENROLL_OID_INFO *pOIDInfo,
  296. BOOL fSearchForCertType);
  297. BOOL FreeCertCACertType(DWORD dwCertTypeInfo,
  298. ENROLL_CERT_TYPE_INFO *rgCertTypeInfo);
  299. BOOL AddCertTypeToCertCA(DWORD *pdwCertTypeInfo,
  300. ENROLL_CERT_TYPE_INFO **ppCertTypeInfo,
  301. LPWSTR pwszDNName,
  302. LPWSTR pwszCertType,
  303. PCERT_EXTENSIONS pCertExtensions,
  304. BOOL fSelected,
  305. DWORD dwKeySpec,
  306. DWORD dwCertTypeFlag,
  307. DWORD dwCSPCount,
  308. DWORD *pdwCSPList,
  309. DWORD dwRASignatures,
  310. DWORD dwEnrollmentFlags,
  311. DWORD dwSubjectNameFlags,
  312. DWORD dwPrivateKeyFlags,
  313. DWORD dwGeneralFlags
  314. );
  315. BOOL
  316. WINAPI
  317. CertRequestNoSearchCA(
  318. BOOL fSearchCertType,
  319. CERT_WIZARD_INFO *pCertWizardInfo,
  320. DWORD dwFlags,
  321. HWND hwndParent,
  322. LPCWSTR pwszWizardTitle,
  323. PCCRYPTUI_WIZ_CERT_REQUEST_INFO pCertRequestInfo,
  324. PCCERT_CONTEXT *ppCertContext,
  325. DWORD *pCAdwStatus,
  326. UINT *pIds);
  327. BOOL
  328. WINAPI
  329. CreateCertRequestNoSearchCANoDS
  330. (IN CERT_WIZARD_INFO *pCertWizardInfo,
  331. IN DWORD dwFlags,
  332. IN HCERTTYPE hCertType,
  333. OUT HANDLE *pResult);
  334. BOOL
  335. WINAPI
  336. CertRequestSearchCA(
  337. CERT_WIZARD_INFO *pCertWizardInfo,
  338. DWORD dwFlags,
  339. HWND hwndParent,
  340. LPCWSTR pwszWizardTitle,
  341. PCCRYPTUI_WIZ_CERT_REQUEST_INFO pCertRequestInfo,
  342. PCCERT_CONTEXT *ppCertContext,
  343. DWORD *pCAdwStatus,
  344. UINT *pIds);
  345. BOOL
  346. WINAPI
  347. SubmitCertRequestNoSearchCANoDS
  348. (IN HANDLE hRequest,
  349. IN LPCWSTR pwszCAName,
  350. IN LPCWSTR pwszCALocation,
  351. OUT DWORD *pdwStatus,
  352. OUT PCCERT_CONTEXT *ppCertContext);
  353. void
  354. WINAPI
  355. FreeCertRequestNoSearchCANoDS
  356. (IN HANDLE hRequest);
  357. BOOL
  358. WINAPI
  359. QueryCertRequestNoSearchCANoDS
  360. (IN HANDLE hRequest, OUT CRYPTUI_WIZ_QUERY_CERT_REQUEST_INFO *pQueryInfo);
  361. BOOL
  362. WINAPI
  363. CryptUIWizCertRequestWithCAInfo(
  364. CERT_WIZARD_INFO *pCertWizardInfo,
  365. DWORD dwFlags,
  366. HWND hwndParent,
  367. LPCWSTR pwszWizardTitle,
  368. PCCRYPTUI_WIZ_CERT_REQUEST_INFO pCertRequestInfo,
  369. PCCRYPTUI_WIZ_CERT_CA_INFO pCertRequestCAInfo,
  370. PCCERT_CONTEXT *ppCertContext,
  371. DWORD *pdwStatus,
  372. UINT *pIds);
  373. int I_MessageBox(
  374. HWND hWnd,
  375. UINT idsText,
  376. UINT idsCaption,
  377. LPCWSTR pwszCaption,
  378. UINT uType);
  379. HRESULT MarshallRequestParameters(IN DWORD dwCSPIndex,
  380. IN CERT_WIZARD_INFO *pCertWizardInfo,
  381. IN OUT CERT_BLOB *pCertBlob,
  382. IN OUT CERT_REQUEST_PVK_NEW *pCertRequestPvkNew,
  383. IN OUT CERT_REQUEST_PVK_NEW *pCertRenewPvk,
  384. IN OUT LPWSTR *ppwszHashAlg,
  385. IN OUT CERT_ENROLL_INFO *pRequestInfo);
  386. void FreeRequestParameters(IN LPWSTR *ppwszHashAlg,
  387. IN CERT_REQUEST_PVK_NEW *pCertRenewPvk,
  388. IN CERT_ENROLL_INFO *RequestInfo);
  389. HRESULT WINAPI CreateRequest(DWORD dwFlags, //IN Required
  390. DWORD dwPurpose, //IN Required: Whether it is enrollment or renew
  391. LPWSTR pwszCAName, //IN Required:
  392. LPWSTR pwszCALocation, //IN Required:
  393. CERT_BLOB *pCertBlob, //IN Required: The renewed certifcate
  394. CERT_REQUEST_PVK_NEW *pRenewKey, //IN Required: The private key on the certificate
  395. BOOL fNewKey, //IN Required: Set the TRUE if new private key is needed
  396. CERT_REQUEST_PVK_NEW *pKeyNew, //IN Required: The private key information
  397. LPWSTR pwszHashAlg, //IN Optional: The hash algorithm
  398. LPWSTR pwszDesStore, //IN Optional: The destination store
  399. DWORD dwStoreFlags, //IN Optional: The store flags
  400. CERT_ENROLL_INFO *pRequestInfo, //IN Required: The information about the cert request
  401. HANDLE *hRequest //OUT Required: A handle to the PKCS10 request created
  402. );
  403. HRESULT WINAPI SubmitRequest(IN HANDLE hRequest,
  404. IN BOOL fKeyService, //IN Required: Whether the function is called remotely
  405. IN DWORD dwPurpose, //IN Required: Whether it is enrollment or renew
  406. IN BOOL fConfirmation, //IN Required: Set the TRUE if confirmation dialogue is needed
  407. IN HWND hwndParent, //IN Optional: The parent window
  408. IN LPWSTR pwszConfirmationTitle, //IN Optional: The title for confirmation dialogue
  409. IN UINT idsConfirmTitle, //IN Optional: The resource ID for the title of the confirmation dialogue
  410. IN LPWSTR pwszCALocation, //IN Required: The ca machine name
  411. IN LPWSTR pwszCAName, //IN Required: The ca name
  412. IN LPWSTR pwszCADisplayName, // IN Optional: The display name of the CA.
  413. OUT CERT_BLOB *pPKCS7Blob, //OUT Optional: The PKCS7 from the CA
  414. OUT CERT_BLOB *pHashBlob, //OUT Optioanl: The SHA1 hash of the enrolled/renewed certificate
  415. OUT DWORD *pdwDisposition, //OUT Optional: The status of the enrollment/renewal
  416. OUT PCCERT_CONTEXT *ppCertContext //OUT Optional: The enrolled certificate
  417. );
  418. void WINAPI FreeRequest(IN HANDLE hRequest);
  419. BOOL WINAPI QueryRequest(IN HANDLE hRequest, OUT CRYPTUI_WIZ_QUERY_CERT_REQUEST_INFO *pQueryInfo);
  420. BOOL WizardInit(BOOL fLoadRichEdit=FALSE);
  421. BOOL CheckPVKInfo( DWORD dwFlags,
  422. PCCRYPTUI_WIZ_CERT_REQUEST_INFO pCertRequestInfo,
  423. CERT_WIZARD_INFO *pCertWizardInfo,
  424. CRYPT_KEY_PROV_INFO **ppKeyProvInfo);
  425. BOOL CheckPVKInfoNoDS(DWORD dwFlags,
  426. DWORD dwPvkChoice,
  427. PCCRYPTUI_WIZ_CERT_REQUEST_PVK_CERT pCertRequestPvkContext,
  428. PCCRYPTUI_WIZ_CERT_REQUEST_PVK_NEW pCertRequestPvkNew,
  429. PCCRYPTUI_WIZ_CERT_REQUEST_PVK_EXISTING pCertRequestPvkExisting,
  430. DWORD dwCertChoice,
  431. CERT_WIZARD_INFO *pCertWizardInfo,
  432. CRYPT_KEY_PROV_INFO **ppKeyProvInfo);
  433. void ResetProperties(PCCERT_CONTEXT pOldCertContext, PCCERT_CONTEXT pNewCertContext);
  434. LRESULT Send_LB_GETTEXT(
  435. HWND hwnd,
  436. WPARAM wParam,
  437. LPARAM lParam);
  438. LRESULT Send_LB_ADDSTRING(
  439. HWND hwnd,
  440. WPARAM wParam,
  441. LPARAM lParam);
  442. void
  443. SetControlFont(
  444. HFONT hFont,
  445. HWND hwnd,
  446. INT nId
  447. );
  448. BOOL
  449. SetupFonts(
  450. HINSTANCE hInstance,
  451. HWND hwnd,
  452. HFONT *pBigBoldFont,
  453. HFONT *pBoldFont
  454. );
  455. void
  456. DestroyFonts(
  457. HFONT hBigBoldFont,
  458. HFONT hBoldFont
  459. );
  460. HRESULT
  461. WizardSZToWSZ
  462. (IN LPCSTR psz,
  463. OUT LPWSTR *ppwsz);
  464. LPVOID WizardAlloc (
  465. ULONG cbSize);
  466. LPVOID WizardRealloc (
  467. LPVOID pv,
  468. ULONG cbSize);
  469. VOID WizardFree (
  470. LPVOID pv);
  471. VOID MyWizardFree (
  472. LPVOID pv);
  473. LPWSTR WizardAllocAndCopyWStr(LPWSTR pwsz);
  474. LPSTR WizardAllocAndCopyStr(LPSTR psz);
  475. BOOL ConfirmToInstall(HWND hwndParent,
  476. LPWSTR pwszConfirmationTitle,
  477. UINT idsConfirmTitle,
  478. PCCERT_CONTEXT pCertContext,
  479. PCRYPT_DATA_BLOB pPKCS7Blob);
  480. BOOL GetValidKeySizes(IN LPCWSTR pwszProvider,
  481. IN DWORD dwProvType,
  482. IN DWORD dwUserKeySpec,
  483. OUT DWORD * pdwMinLen,
  484. OUT DWORD * pdwMaxLen,
  485. OUT DWORD * pdwInc);
  486. BOOL CAUtilAddSMIME(DWORD dwExtensions,
  487. PCERT_EXTENSIONS *prgExtensions);
  488. HRESULT CodeToHR(HRESULT hr);
  489. HRESULT RetrieveBLOBFromFile(LPWSTR pwszFileName,DWORD *pcb,BYTE **ppb);
  490. HRESULT OpenAndWriteToFile(
  491. LPCWSTR pwszFileName,
  492. PBYTE pb,
  493. DWORD cb);
  494. int ListView_InsertItemU_IDS(HWND hwndList,
  495. LV_ITEMW *plvItem,
  496. UINT idsString,
  497. LPWSTR pwszText);
  498. BOOL MyFormatEnhancedKeyUsageString(LPWSTR *ppString, PCCERT_CONTEXT pCertContext, BOOL fPropertiesOnly, BOOL fMultiline);
  499. BOOL WizardFormatDateString(LPWSTR *ppString, FILETIME ft, BOOL fIncludeTime);
  500. void FreePurposeInfo(ENROLL_PURPOSE_INFO **prgPurposeInfo,
  501. DWORD dwOIDCount);
  502. LRESULT
  503. WINAPI
  504. SendDlgItemMessageU_GETLBTEXT
  505. ( HWND hwndDlg,
  506. int nIDDlgItem,
  507. int iIndex,
  508. LPWSTR *ppwsz
  509. );
  510. void WINAPI GetListViewText( HWND hwnd, int iItem,
  511. int iSubItem, LPWSTR *ppwsz );
  512. void FreeProviders( DWORD dwCSPCount,
  513. DWORD *rgdwProviderType,
  514. LPWSTR *rgwszProvider);
  515. //the call back function to compare the certificate
  516. int CALLBACK CompareCertificate(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
  517. BOOL GetCertIssuer(PCCERT_CONTEXT pCertContext, LPWSTR *ppwsz);
  518. BOOL GetCertSubject(PCCERT_CONTEXT pCertContext, LPWSTR *ppwsz);
  519. BOOL GetCertPurpose(PCCERT_CONTEXT pCertContext, LPWSTR *ppwsz);
  520. BOOL GetCertFriendlyName(PCCERT_CONTEXT pCertContext, LPWSTR *ppwsz);
  521. BOOL GetCertLocation (PCCERT_CONTEXT pCertContext, LPWSTR *ppwsz);
  522. BOOL CSPSupported(CERT_WIZARD_INFO *pCertWizardInfo);
  523. BOOL WizGetOpenFileName(LPOPENFILENAMEW pOpenFileName);
  524. BOOL WizGetSaveFileName(LPOPENFILENAMEW pOpenFileName);
  525. BOOL AddChainToStore(
  526. HCERTSTORE hCertStore,
  527. PCCERT_CONTEXT pCertContext,
  528. DWORD cStores,
  529. HCERTSTORE *rghStores,
  530. BOOL fDontAddRootCert,
  531. CERT_TRUST_STATUS *pChainTrustStatus);
  532. BOOL FileExist(LPWSTR pwszFileName);
  533. int LoadFilterString(
  534. HINSTANCE hInstance,
  535. UINT uID,
  536. LPWSTR lpBuffer,
  537. int nBufferMax);
  538. BOOL CASupportSpecifiedCertType(CRYPTUI_WIZ_CERT_CA *pCertCA);
  539. BOOL GetCertTypeName(CERT_WIZARD_INFO *pCertWizardInfo);
  540. BOOL GetCAName(CERT_WIZARD_INFO *pCertWizardInfo);
  541. LPWSTR ExpandAndAllocString(LPCWSTR pwsz);
  542. HANDLE WINAPI ExpandAndCreateFileU (
  543. LPCWSTR lpFileName,
  544. DWORD dwDesiredAccess,
  545. DWORD dwShareMode,
  546. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  547. DWORD dwCreationDisposition,
  548. DWORD dwFlagsAndAttributes,
  549. HANDLE hTemplateFile
  550. );
  551. WINCRYPT32API
  552. BOOL
  553. WINAPI
  554. ExpandAndCryptQueryObject(
  555. DWORD dwObjectType,
  556. const void *pvObject,
  557. DWORD dwExpectedContentTypeFlags,
  558. DWORD dwExpectedFormatTypeFlags,
  559. DWORD dwFlags,
  560. DWORD *pdwMsgAndCertEncodingType,
  561. DWORD *pdwContentType,
  562. DWORD *pdwFormatType,
  563. HCERTSTORE *phCertStore,
  564. HCRYPTMSG *phMsg,
  565. const void **ppvContext
  566. );
  567. #ifdef __cplusplus
  568. } // Balance extern "C" above
  569. #endif
  570. #ifdef __cplusplus
  571. // Define an exportable interface to the EnrollmentCOMObjectFactory class.
  572. extern "C"
  573. {
  574. typedef struct _EnrollmentCOMObjectFactoryContext {
  575. BOOL fIsCOMInitialized;
  576. ICertRequest2 *pICertRequest2;
  577. IDsObjectPicker *pIDsObjectPicker;
  578. } EnrollmentCOMObjectFactoryContext;
  579. HRESULT EnrollmentCOMObjectFactory_getInstance(EnrollmentCOMObjectFactoryContext *pContext,
  580. REFCLSID rclsid,
  581. REFIID riid,
  582. LPUNKNOWN *pUnknown,
  583. LPVOID *ppInstance);
  584. } // extern "C"
  585. class IEnumCSP
  586. {
  587. public:
  588. IEnumCSP(CERT_WIZARD_INFO * pCertWizardInfo);
  589. HRESULT HasNext(BOOL *pfResult);
  590. HRESULT Next(DWORD *pdwNextCSP);
  591. private:
  592. BOOL *m_pfCSPs;
  593. BOOL m_fIsInitialized;
  594. DWORD m_cCSPs;
  595. DWORD m_dwCSPIndex;
  596. HRESULT m_hr;
  597. };
  598. class IEnumCA
  599. {
  600. public:
  601. IEnumCA(CERT_WIZARD_INFO * pCertWizardInfo) : m_pCertWizardInfo(pCertWizardInfo),
  602. m_dwCAIndex(1) { }
  603. HRESULT HasNext(BOOL *pfResult);
  604. HRESULT Next(PCRYPTUI_WIZ_CERT_CA pCertCA);
  605. private:
  606. CERT_WIZARD_INFO *m_pCertWizardInfo;
  607. DWORD m_dwCAIndex;
  608. };
  609. //
  610. // The EnrollmentObjectFactory class provides instances of useful COM interfaces
  611. // in a demand-driven manner. Only one instance of each type is created,
  612. // and it is created only when needed.
  613. //
  614. // NOTE: For efficiency, all COM objects should be instantiated through this
  615. // object factory.
  616. //
  617. class EnrollmentCOMObjectFactory
  618. {
  619. public:
  620. EnrollmentCOMObjectFactory() {
  621. m_context.fIsCOMInitialized = FALSE;
  622. m_context.pICertRequest2 = NULL;
  623. m_context.pIDsObjectPicker = NULL;
  624. }
  625. ~EnrollmentCOMObjectFactory() {
  626. if (m_context.pICertRequest2 != NULL) { m_context.pICertRequest2->Release(); }
  627. if (m_context.pIDsObjectPicker != NULL) { m_context.pIDsObjectPicker->Release(); }
  628. if (m_context.fIsCOMInitialized == TRUE) { CoUninitialize(); }
  629. }
  630. // Returns a pointer to an implementation of ICertRequest2.
  631. // Must release this pointer through ICertRequest2's release() method.
  632. HRESULT getICertRequest2(ICertRequest2 ** ppCertRequest) {
  633. return EnrollmentCOMObjectFactory_getInstance(&(this->m_context),
  634. CLSID_CCertRequest,
  635. IID_ICertRequest2,
  636. (LPUNKNOWN *)&(m_context.pICertRequest2),
  637. (LPVOID *)ppCertRequest);
  638. }
  639. // Returns a pointer to an implementation of IDsObjectPicker.
  640. // Must release this pointer through ICertRequest2's release() method.
  641. HRESULT getIDsObjectPicker(IDsObjectPicker ** ppObjectPicker) {
  642. return EnrollmentCOMObjectFactory_getInstance(&(this->m_context),
  643. CLSID_DsObjectPicker,
  644. IID_IDsObjectPicker,
  645. (LPUNKNOWN *)&(m_context.pIDsObjectPicker),
  646. (LPVOID *)ppObjectPicker);
  647. }
  648. private:
  649. // Disallow copy constructor and assignment operator:
  650. EnrollmentCOMObjectFactory(const EnrollmentCOMObjectFactory &);
  651. const EnrollmentCOMObjectFactory & operator=(const EnrollmentCOMObjectFactory &);
  652. // Helper functions:
  653. HRESULT getInstance(REFCLSID rclsid, REFIID riid, LPUNKNOWN *pUnknown, LPVOID *ppInstance);
  654. // Data:
  655. EnrollmentCOMObjectFactoryContext m_context;
  656. };
  657. #endif // __cplusplus
  658. #endif //WZRDPVK_H