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.

804 lines
28 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_ENROLL_INFO *RequestInfo);
  388. HRESULT WINAPI CreateRequest(DWORD dwFlags, //IN Required
  389. DWORD dwPurpose, //IN Required: Whether it is enrollment or renew
  390. LPWSTR pwszCAName, //IN Required:
  391. LPWSTR pwszCALocation, //IN Required:
  392. CERT_BLOB *pCertBlob, //IN Required: The renewed certifcate
  393. CERT_REQUEST_PVK_NEW *pRenewKey, //IN Required: The private key on the certificate
  394. BOOL fNewKey, //IN Required: Set the TRUE if new private key is needed
  395. CERT_REQUEST_PVK_NEW *pKeyNew, //IN Required: The private key information
  396. LPWSTR pwszHashAlg, //IN Optional: The hash algorithm
  397. LPWSTR pwszDesStore, //IN Optional: The destination store
  398. DWORD dwStoreFlags, //IN Optional: The store flags
  399. CERT_ENROLL_INFO *pRequestInfo, //IN Required: The information about the cert request
  400. HANDLE *hRequest //OUT Required: A handle to the PKCS10 request created
  401. );
  402. HRESULT WINAPI SubmitRequest(IN HANDLE hRequest,
  403. IN BOOL fKeyService, //IN Required: Whether the function is called remotely
  404. IN DWORD dwPurpose, //IN Required: Whether it is enrollment or renew
  405. IN BOOL fConfirmation, //IN Required: Set the TRUE if confirmation dialogue is needed
  406. IN HWND hwndParent, //IN Optional: The parent window
  407. IN LPWSTR pwszConfirmationTitle, //IN Optional: The title for confirmation dialogue
  408. IN UINT idsConfirmTitle, //IN Optional: The resource ID for the title of the confirmation dialogue
  409. IN LPWSTR pwszCALocation, //IN Required: The ca machine name
  410. IN LPWSTR pwszCAName, //IN Required: The ca name
  411. IN LPWSTR pwszCADisplayName, // IN Optional: The display name of the CA.
  412. OUT CERT_BLOB *pPKCS7Blob, //OUT Optional: The PKCS7 from the CA
  413. OUT CERT_BLOB *pHashBlob, //OUT Optioanl: The SHA1 hash of the enrolled/renewed certificate
  414. OUT DWORD *pdwDisposition, //OUT Optional: The status of the enrollment/renewal
  415. OUT PCCERT_CONTEXT *ppCertContext //OUT Optional: The enrolled certificate
  416. );
  417. void WINAPI FreeRequest(IN HANDLE hRequest);
  418. BOOL WINAPI QueryRequest(IN HANDLE hRequest, OUT CRYPTUI_WIZ_QUERY_CERT_REQUEST_INFO *pQueryInfo);
  419. BOOL WizardInit(BOOL fLoadRichEdit=FALSE);
  420. BOOL CheckPVKInfo( DWORD dwFlags,
  421. PCCRYPTUI_WIZ_CERT_REQUEST_INFO pCertRequestInfo,
  422. CERT_WIZARD_INFO *pCertWizardInfo,
  423. CRYPT_KEY_PROV_INFO **ppKeyProvInfo);
  424. BOOL CheckPVKInfoNoDS(DWORD dwFlags,
  425. DWORD dwPvkChoice,
  426. PCCRYPTUI_WIZ_CERT_REQUEST_PVK_CERT pCertRequestPvkContext,
  427. PCCRYPTUI_WIZ_CERT_REQUEST_PVK_NEW pCertRequestPvkNew,
  428. PCCRYPTUI_WIZ_CERT_REQUEST_PVK_EXISTING pCertRequestPvkExisting,
  429. DWORD dwCertChoice,
  430. CERT_WIZARD_INFO *pCertWizardInfo,
  431. CRYPT_KEY_PROV_INFO **ppKeyProvInfo);
  432. void ResetProperties(PCCERT_CONTEXT pOldCertContext, PCCERT_CONTEXT pNewCertContext);
  433. LRESULT Send_LB_GETTEXT(
  434. HWND hwnd,
  435. WPARAM wParam,
  436. LPARAM lParam);
  437. LRESULT Send_LB_ADDSTRING(
  438. HWND hwnd,
  439. WPARAM wParam,
  440. LPARAM lParam);
  441. void
  442. SetControlFont(
  443. HFONT hFont,
  444. HWND hwnd,
  445. INT nId
  446. );
  447. BOOL
  448. SetupFonts(
  449. HINSTANCE hInstance,
  450. HWND hwnd,
  451. HFONT *pBigBoldFont,
  452. HFONT *pBoldFont
  453. );
  454. void
  455. DestroyFonts(
  456. HFONT hBigBoldFont,
  457. HFONT hBoldFont
  458. );
  459. HRESULT
  460. WizardSZToWSZ
  461. (IN LPCSTR psz,
  462. OUT LPWSTR *ppwsz);
  463. LPVOID WizardAlloc (
  464. ULONG cbSize);
  465. LPVOID WizardRealloc (
  466. LPVOID pv,
  467. ULONG cbSize);
  468. VOID WizardFree (
  469. LPVOID pv);
  470. VOID MyWizardFree (
  471. LPVOID pv);
  472. LPWSTR WizardAllocAndCopyWStr(LPWSTR pwsz);
  473. LPSTR WizardAllocAndCopyStr(LPSTR psz);
  474. BOOL ConfirmToInstall(HWND hwndParent,
  475. LPWSTR pwszConfirmationTitle,
  476. UINT idsConfirmTitle,
  477. PCCERT_CONTEXT pCertContext,
  478. PCRYPT_DATA_BLOB pPKCS7Blob);
  479. BOOL GetValidKeySizes(IN LPCWSTR pwszProvider,
  480. IN DWORD dwProvType,
  481. IN DWORD dwUserKeySpec,
  482. OUT DWORD * pdwMinLen,
  483. OUT DWORD * pdwMaxLen,
  484. OUT DWORD * pdwInc);
  485. BOOL CAUtilAddSMIME(DWORD dwExtensions,
  486. PCERT_EXTENSIONS *prgExtensions);
  487. HRESULT CodeToHR(HRESULT hr);
  488. HRESULT RetrieveBLOBFromFile(LPWSTR pwszFileName,DWORD *pcb,BYTE **ppb);
  489. HRESULT OpenAndWriteToFile(
  490. LPCWSTR pwszFileName,
  491. PBYTE pb,
  492. DWORD cb);
  493. int ListView_InsertItemU_IDS(HWND hwndList,
  494. LV_ITEMW *plvItem,
  495. UINT idsString,
  496. LPWSTR pwszText);
  497. BOOL MyFormatEnhancedKeyUsageString(LPWSTR *ppString, PCCERT_CONTEXT pCertContext, BOOL fPropertiesOnly, BOOL fMultiline);
  498. BOOL WizardFormatDateString(LPWSTR *ppString, FILETIME ft, BOOL fIncludeTime);
  499. void FreePurposeInfo(ENROLL_PURPOSE_INFO **prgPurposeInfo,
  500. DWORD dwOIDCount);
  501. LRESULT
  502. WINAPI
  503. SendDlgItemMessageU_GETLBTEXT
  504. ( HWND hwndDlg,
  505. int nIDDlgItem,
  506. int iIndex,
  507. LPWSTR *ppwsz
  508. );
  509. void WINAPI GetListViewText( HWND hwnd, int iItem,
  510. int iSubItem, LPWSTR *ppwsz );
  511. void FreeProviders( DWORD dwCSPCount,
  512. DWORD *rgdwProviderType,
  513. LPWSTR *rgwszProvider);
  514. //the call back function to compare the certificate
  515. int CALLBACK CompareCertificate(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
  516. BOOL GetCertIssuer(PCCERT_CONTEXT pCertContext, LPWSTR *ppwsz);
  517. BOOL GetCertSubject(PCCERT_CONTEXT pCertContext, LPWSTR *ppwsz);
  518. BOOL GetCertPurpose(PCCERT_CONTEXT pCertContext, LPWSTR *ppwsz);
  519. BOOL GetCertFriendlyName(PCCERT_CONTEXT pCertContext, LPWSTR *ppwsz);
  520. BOOL GetCertLocation (PCCERT_CONTEXT pCertContext, LPWSTR *ppwsz);
  521. BOOL CSPSupported(CERT_WIZARD_INFO *pCertWizardInfo);
  522. BOOL WizGetOpenFileName(LPOPENFILENAMEW pOpenFileName);
  523. BOOL WizGetSaveFileName(LPOPENFILENAMEW pOpenFileName);
  524. BOOL AddChainToStore(
  525. HCERTSTORE hCertStore,
  526. PCCERT_CONTEXT pCertContext,
  527. DWORD cStores,
  528. HCERTSTORE *rghStores,
  529. BOOL fDontAddRootCert,
  530. CERT_TRUST_STATUS *pChainTrustStatus);
  531. BOOL FileExist(LPWSTR pwszFileName);
  532. int LoadFilterString(
  533. HINSTANCE hInstance,
  534. UINT uID,
  535. LPWSTR lpBuffer,
  536. int nBufferMax);
  537. BOOL CASupportSpecifiedCertType(CRYPTUI_WIZ_CERT_CA *pCertCA);
  538. BOOL GetCertTypeName(CERT_WIZARD_INFO *pCertWizardInfo);
  539. BOOL GetCAName(CERT_WIZARD_INFO *pCertWizardInfo);
  540. LPWSTR ExpandAndAllocString(LPCWSTR pwsz);
  541. HANDLE WINAPI ExpandAndCreateFileU (
  542. LPCWSTR lpFileName,
  543. DWORD dwDesiredAccess,
  544. DWORD dwShareMode,
  545. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  546. DWORD dwCreationDisposition,
  547. DWORD dwFlagsAndAttributes,
  548. HANDLE hTemplateFile
  549. );
  550. WINCRYPT32API
  551. BOOL
  552. WINAPI
  553. ExpandAndCryptQueryObject(
  554. DWORD dwObjectType,
  555. const void *pvObject,
  556. DWORD dwExpectedContentTypeFlags,
  557. DWORD dwExpectedFormatTypeFlags,
  558. DWORD dwFlags,
  559. DWORD *pdwMsgAndCertEncodingType,
  560. DWORD *pdwContentType,
  561. DWORD *pdwFormatType,
  562. HCERTSTORE *phCertStore,
  563. HCRYPTMSG *phMsg,
  564. const void **ppvContext
  565. );
  566. #ifdef __cplusplus
  567. } // Balance extern "C" above
  568. #endif
  569. #ifdef __cplusplus
  570. // Define an exportable interface to the EnrollmentCOMObjectFactory class.
  571. extern "C"
  572. {
  573. typedef struct _EnrollmentCOMObjectFactoryContext {
  574. BOOL fIsCOMInitialized;
  575. ICertRequest2 *pICertRequest2;
  576. IDsObjectPicker *pIDsObjectPicker;
  577. } EnrollmentCOMObjectFactoryContext;
  578. HRESULT EnrollmentCOMObjectFactory_getInstance(EnrollmentCOMObjectFactoryContext *pContext,
  579. REFCLSID rclsid,
  580. REFIID riid,
  581. LPUNKNOWN *pUnknown,
  582. LPVOID *ppInstance);
  583. } // extern "C"
  584. class IEnumCSP
  585. {
  586. public:
  587. IEnumCSP(CERT_WIZARD_INFO * pCertWizardInfo);
  588. HRESULT HasNext(BOOL *pfResult);
  589. HRESULT Next(DWORD *pdwNextCSP);
  590. private:
  591. BOOL *m_pfCSPs;
  592. BOOL m_fIsInitialized;
  593. DWORD m_cCSPs;
  594. DWORD m_dwCSPIndex;
  595. HRESULT m_hr;
  596. };
  597. class IEnumCA
  598. {
  599. public:
  600. IEnumCA(CERT_WIZARD_INFO * pCertWizardInfo) : m_pCertWizardInfo(pCertWizardInfo),
  601. m_dwCAIndex(1) { }
  602. HRESULT HasNext(BOOL *pfResult);
  603. HRESULT Next(PCRYPTUI_WIZ_CERT_CA pCertCA);
  604. private:
  605. CERT_WIZARD_INFO *m_pCertWizardInfo;
  606. DWORD m_dwCAIndex;
  607. };
  608. //
  609. // The EnrollmentObjectFactory class provides instances of useful COM interfaces
  610. // in a demand-driven manner. Only one instance of each type is created,
  611. // and it is created only when needed.
  612. //
  613. // NOTE: For efficiency, all COM objects should be instantiated through this
  614. // object factory.
  615. //
  616. class EnrollmentCOMObjectFactory
  617. {
  618. public:
  619. EnrollmentCOMObjectFactory() {
  620. m_context.fIsCOMInitialized = FALSE;
  621. m_context.pICertRequest2 = NULL;
  622. m_context.pIDsObjectPicker = NULL;
  623. }
  624. ~EnrollmentCOMObjectFactory() {
  625. if (m_context.pICertRequest2 != NULL) { m_context.pICertRequest2->Release(); }
  626. if (m_context.pIDsObjectPicker != NULL) { m_context.pIDsObjectPicker->Release(); }
  627. if (m_context.fIsCOMInitialized == TRUE) { CoUninitialize(); }
  628. }
  629. // Returns a pointer to an implementation of ICertRequest2.
  630. // Must release this pointer through ICertRequest2's release() method.
  631. HRESULT getICertRequest2(ICertRequest2 ** ppCertRequest) {
  632. return EnrollmentCOMObjectFactory_getInstance(&(this->m_context),
  633. CLSID_CCertRequest,
  634. IID_ICertRequest2,
  635. (LPUNKNOWN *)&(m_context.pICertRequest2),
  636. (LPVOID *)ppCertRequest);
  637. }
  638. // Returns a pointer to an implementation of IDsObjectPicker.
  639. // Must release this pointer through ICertRequest2's release() method.
  640. HRESULT getIDsObjectPicker(IDsObjectPicker ** ppObjectPicker) {
  641. return EnrollmentCOMObjectFactory_getInstance(&(this->m_context),
  642. CLSID_DsObjectPicker,
  643. IID_IDsObjectPicker,
  644. (LPUNKNOWN *)&(m_context.pIDsObjectPicker),
  645. (LPVOID *)ppObjectPicker);
  646. }
  647. private:
  648. // Disallow copy constructor and assignment operator:
  649. EnrollmentCOMObjectFactory(const EnrollmentCOMObjectFactory &);
  650. const EnrollmentCOMObjectFactory & operator=(const EnrollmentCOMObjectFactory &);
  651. // Helper functions:
  652. HRESULT getInstance(REFCLSID rclsid, REFIID riid, LPUNKNOWN *pUnknown, LPVOID *ppInstance);
  653. // Data:
  654. EnrollmentCOMObjectFactoryContext m_context;
  655. };
  656. #endif // __cplusplus
  657. #endif //WZRDPVK_H