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.

2335 lines
79 KiB

  1. //-------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation, 1996 - 1999
  3. //
  4. // File: export.cpp
  5. //
  6. // Contents: The cpp file to implement the export wizard
  7. //
  8. // History: 11-19-1997 reidk created
  9. //
  10. //--------------------------------------------------------------
  11. #include "wzrdpvk.h"
  12. #define EXPORT_PAGE_NUM 6
  13. #define MAX_PASSWORD 512
  14. #define MAX_STORES 20
  15. //
  16. // these are the defines for the state of a private key
  17. //
  18. #define PRIVATE_KEY_UNKNOWN_STATE 0
  19. #define PRIVATE_KEY_CORRUPT 1
  20. #define PRIVATE_KEY_NOT_EXPORTABLE 2
  21. #define PRIVATE_KEY_EXPORTABLE 3
  22. typedef struct {
  23. PCCRYPTUI_WIZ_EXPORT_INFO pExportInfo;
  24. PCCRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO pExportCertInfo;
  25. LPWSTR pwszExportFileName;
  26. LPWSTR pwszExportFileNameToCheck;
  27. DWORD dwExportFormat;
  28. BOOL fExportChain;
  29. BOOL fExportPrivateKeys;
  30. BOOL fStrongEncryption;
  31. BOOL fDeletePrivateKey;
  32. DWORD dwExportablePrivateKeyStatus;
  33. BOOL fPrivateKeysExist;
  34. BOOL fDontCheckFileName;
  35. BOOL fNextPage;
  36. LPWSTR pwszPassword;
  37. HFONT hBigBold;
  38. HFONT hBold;
  39. // DSIE: Added 04/03/2002 for DCR bug 531006.
  40. DWORD dwFlags;
  41. // DSIE: Added 05/06/2002 for bug 613485.
  42. DWORD dwErrorCode;
  43. } EXPORT_HELPER_STRUCT, *PEXPORT_HELPER_STRUCT;
  44. //////////////////////////////////////////////////////////////////////////////////////
  45. //
  46. //////////////////////////////////////////////////////////////////////////////////////
  47. static BOOL Validpvoid(PCCRYPTUI_WIZ_EXPORT_INFO pExportInfo, void *pvoid)
  48. {
  49. // the only type that needs to be validated at this point is for CERT_CONTEXT
  50. switch (pExportInfo->dwSubjectChoice)
  51. {
  52. case CRYPTUI_WIZ_EXPORT_CERT_CONTEXT:
  53. PCCRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO pExportCertInfo = (PCCRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO) pvoid;
  54. return (pExportCertInfo->dwSize == sizeof(CRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO));
  55. break;
  56. }
  57. return TRUE;
  58. }
  59. //////////////////////////////////////////////////////////////////////////////////////
  60. //
  61. //////////////////////////////////////////////////////////////////////////////////////
  62. BOOL AddChainToStore(
  63. HCERTSTORE hCertStore,
  64. PCCERT_CONTEXT pCertContext,
  65. DWORD cStores,
  66. HCERTSTORE *rghStores,
  67. BOOL fDontAddRootCert,
  68. CERT_TRUST_STATUS *pChainTrustStatus)
  69. {
  70. FILETIME fileTime;
  71. DWORD i;
  72. CERT_CHAIN_ENGINE_CONFIG CertChainEngineConfig;
  73. HCERTCHAINENGINE hCertChainEngine = NULL;
  74. PCCERT_CHAIN_CONTEXT pCertChainContext = NULL;
  75. CERT_CHAIN_PARA CertChainPara;
  76. BOOL fRet = TRUE;
  77. PCCERT_CONTEXT pTempCertContext = NULL;
  78. //
  79. // create a new chain engine, then build the chain
  80. //
  81. memset(&CertChainEngineConfig, 0, sizeof(CertChainEngineConfig));
  82. CertChainEngineConfig.cbSize = sizeof(CertChainEngineConfig);
  83. CertChainEngineConfig.cAdditionalStore = cStores;
  84. CertChainEngineConfig.rghAdditionalStore = rghStores;
  85. if (!CertCreateCertificateChainEngine(&CertChainEngineConfig, &hCertChainEngine))
  86. {
  87. goto ErrorReturn;
  88. }
  89. memset(&CertChainPara, 0, sizeof(CertChainPara));
  90. CertChainPara.cbSize = sizeof(CertChainPara);
  91. if (!CertGetCertificateChain(
  92. hCertChainEngine,
  93. pCertContext,
  94. NULL,
  95. NULL,
  96. &CertChainPara,
  97. 0,
  98. NULL,
  99. &pCertChainContext))
  100. {
  101. goto ErrorReturn;
  102. }
  103. //
  104. // make sure there is atleast 1 simple chain
  105. //
  106. if (pCertChainContext->cChain != 0)
  107. {
  108. i = 0;
  109. while (i < pCertChainContext->rgpChain[0]->cElement)
  110. {
  111. //
  112. // if we are supposed to skip the root cert,
  113. // and we are on the root cert, then continue
  114. //
  115. if (fDontAddRootCert &&
  116. (pCertChainContext->rgpChain[0]->rgpElement[i]->TrustStatus.dwInfoStatus & CERT_TRUST_IS_SELF_SIGNED))
  117. {
  118. i++;
  119. continue;
  120. }
  121. CertAddCertificateContextToStore(
  122. hCertStore,
  123. pCertChainContext->rgpChain[0]->rgpElement[i]->pCertContext,
  124. CERT_STORE_ADD_REPLACE_EXISTING,
  125. &pTempCertContext);
  126. //
  127. // remove any private key property the certcontext may have on it.
  128. //
  129. if (pTempCertContext)
  130. {
  131. CertSetCertificateContextProperty(
  132. pTempCertContext,
  133. CERT_KEY_PROV_INFO_PROP_ID,
  134. 0,
  135. NULL);
  136. CertFreeCertificateContext(pTempCertContext);
  137. }
  138. i++;
  139. }
  140. }
  141. else
  142. {
  143. goto ErrorReturn;
  144. }
  145. //
  146. // if the caller wants the status, then set it
  147. //
  148. if (pChainTrustStatus != NULL)
  149. {
  150. pChainTrustStatus->dwErrorStatus = pCertChainContext->TrustStatus.dwErrorStatus;
  151. pChainTrustStatus->dwInfoStatus = pCertChainContext->TrustStatus.dwInfoStatus;
  152. }
  153. Ret:
  154. if (pCertChainContext != NULL)
  155. {
  156. CertFreeCertificateChain(pCertChainContext);
  157. }
  158. if (hCertChainEngine != NULL)
  159. {
  160. CertFreeCertificateChainEngine(hCertChainEngine);
  161. }
  162. return fRet;
  163. ErrorReturn:
  164. fRet = FALSE;
  165. goto Ret;
  166. }
  167. //////////////////////////////////////////////////////////////////////////////////////
  168. //
  169. //////////////////////////////////////////////////////////////////////////////////////
  170. HRESULT CreateDirectory(LPWSTR pwszExportFileName)
  171. {
  172. int index;
  173. BOOL ret;
  174. HRESULT hr;
  175. index = wcslen(pwszExportFileName) - 1;
  176. // find the first '\' by parsing backwards
  177. while ((pwszExportFileName[index] != L'\\') && (index >= 0))
  178. {
  179. index--;
  180. }
  181. if (index <= 0)
  182. {
  183. return TRUE;
  184. }
  185. // if there us a ':' to the left of the first '\' then
  186. // a file name has been entered in the form "c:\filename.ext"
  187. // which means of course that we need not try to create the
  188. // directory
  189. if (pwszExportFileName[index-1] == L':')
  190. {
  191. return S_OK;
  192. }
  193. pwszExportFileName[index] = 0;
  194. ret = CreateDirectoryU(pwszExportFileName, NULL);
  195. pwszExportFileName[index] = L'\\';
  196. if (ret)
  197. {
  198. return S_OK;
  199. }
  200. else
  201. {
  202. hr = GetLastError();
  203. if (hr == ERROR_ALREADY_EXISTS)
  204. {
  205. return S_OK;
  206. }
  207. else
  208. {
  209. return hr;
  210. }
  211. }
  212. }
  213. //////////////////////////////////////////////////////////////////////////////////////
  214. //
  215. //////////////////////////////////////////////////////////////////////////////////////
  216. static HRESULT DoExport(PEXPORT_HELPER_STRUCT pExportHelper)
  217. {
  218. HCERTSTORE hTempStore;
  219. HRESULT hr = E_FAIL;
  220. BYTE *pbBase64 = NULL;
  221. DWORD cchBase64 = 0;
  222. CRYPT_KEY_PROV_INFO *pCryptKeyProvInfo = NULL;
  223. DWORD cbCryptKeyProvInfo = 0;
  224. HCRYPTPROV hCryptProv = NULL;
  225. /*if (S_OK != (hr = CreateDirectory(pExportHelper->pwszExportFileName)))
  226. {
  227. return hr;
  228. }*/
  229. switch (pExportHelper->pExportInfo->dwSubjectChoice)
  230. {
  231. case CRYPTUI_WIZ_EXPORT_CTL_CONTEXT:
  232. if (S_OK != (hr = OpenAndWriteToFile(
  233. pExportHelper->pwszExportFileName,
  234. pExportHelper->pExportInfo->pCTLContext->pbCtlEncoded,
  235. pExportHelper->pExportInfo->pCTLContext->cbCtlEncoded)))
  236. {
  237. return hr;
  238. }
  239. break;
  240. case CRYPTUI_WIZ_EXPORT_CRL_CONTEXT:
  241. if (S_OK != (hr = OpenAndWriteToFile(
  242. pExportHelper->pwszExportFileName,
  243. pExportHelper->pExportInfo->pCRLContext->pbCrlEncoded,
  244. pExportHelper->pExportInfo->pCRLContext->cbCrlEncoded)))
  245. {
  246. return hr;
  247. }
  248. break;
  249. case CRYPTUI_WIZ_EXPORT_CERT_STORE:
  250. if (!CertSaveStore(
  251. pExportHelper->pExportInfo->hCertStore,
  252. 0,
  253. CERT_STORE_SAVE_AS_STORE,
  254. CERT_STORE_SAVE_TO_FILENAME_W,
  255. (void *) pExportHelper->pwszExportFileName,
  256. 0))
  257. {
  258. return GetLastError();
  259. }
  260. else
  261. {
  262. hr = S_OK;
  263. }
  264. break;
  265. case CRYPTUI_WIZ_EXPORT_CERT_STORE_CERTIFICATES_ONLY:
  266. if (!CertSaveStore(
  267. pExportHelper->pExportInfo->hCertStore,
  268. PKCS_7_ASN_ENCODING | X509_ASN_ENCODING,
  269. CERT_STORE_SAVE_AS_PKCS7,
  270. CERT_STORE_SAVE_TO_FILENAME_W,
  271. (void *) pExportHelper->pwszExportFileName,
  272. 0))
  273. {
  274. return GetLastError();
  275. }
  276. else
  277. {
  278. hr = S_OK;
  279. }
  280. break;
  281. case CRYPTUI_WIZ_EXPORT_CERT_CONTEXT:
  282. switch (pExportHelper->dwExportFormat)
  283. {
  284. case CRYPTUI_WIZ_EXPORT_FORMAT_DER:
  285. if (S_OK != (hr = OpenAndWriteToFile(
  286. pExportHelper->pwszExportFileName,
  287. pExportHelper->pExportInfo->pCertContext->pbCertEncoded,
  288. pExportHelper->pExportInfo->pCertContext->cbCertEncoded)))
  289. {
  290. return hr;
  291. }
  292. break;
  293. case CRYPTUI_WIZ_EXPORT_FORMAT_BASE64:
  294. if (!CryptBinaryToString(
  295. pExportHelper->pExportInfo->pCertContext->pbCertEncoded,
  296. pExportHelper->pExportInfo->pCertContext->cbCertEncoded,
  297. CRYPT_STRING_BASE64HEADER,
  298. NULL,
  299. &cchBase64))
  300. {
  301. return HRESULT_FROM_WIN32(GetLastError());
  302. }
  303. if (NULL == (pbBase64 = (BYTE *) malloc(cchBase64 * sizeof(TCHAR))))
  304. {
  305. return E_OUTOFMEMORY;
  306. }
  307. if (!CryptBinaryToString(
  308. pExportHelper->pExportInfo->pCertContext->pbCertEncoded,
  309. pExportHelper->pExportInfo->pCertContext->cbCertEncoded,
  310. CRYPT_STRING_BASE64HEADER,
  311. (LPSTR) pbBase64,
  312. &cchBase64))
  313. {
  314. free(pbBase64);
  315. return HRESULT_FROM_WIN32(GetLastError());
  316. }
  317. hr = OpenAndWriteToFile(
  318. pExportHelper->pwszExportFileName,
  319. pbBase64,
  320. cchBase64);
  321. free(pbBase64);
  322. return hr;
  323. break;
  324. case CRYPTUI_WIZ_EXPORT_FORMAT_PFX:
  325. CRYPT_DATA_BLOB pfxBlob;
  326. pfxBlob.cbData = 0;
  327. pfxBlob.pbData = NULL;
  328. //
  329. // open a temporary memory store that the PFXExport will be done from
  330. //
  331. hTempStore = CertOpenStore(
  332. CERT_STORE_PROV_MEMORY,
  333. X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  334. 0,
  335. CERT_STORE_ENUM_ARCHIVED_FLAG,
  336. NULL);
  337. if (hTempStore == NULL)
  338. {
  339. return GetLastError();
  340. }
  341. //
  342. // get all the certs in the chain if we need to
  343. //
  344. if (pExportHelper->fExportChain)
  345. {
  346. AddChainToStore(
  347. hTempStore,
  348. pExportHelper->pExportInfo->pCertContext,
  349. pExportHelper->pExportInfo->cStores,
  350. pExportHelper->pExportInfo->rghStores,
  351. FALSE,
  352. NULL);
  353. }
  354. CertAddCertificateContextToStore(
  355. hTempStore,
  356. pExportHelper->pExportInfo->pCertContext,
  357. CERT_STORE_ADD_REPLACE_EXISTING,
  358. NULL);
  359. //
  360. // call pfx to export the store to a blob, use the pExportHelper->fStrongEncryption
  361. // flag to call the appropriate PFX API
  362. //
  363. if (pExportHelper->fStrongEncryption)
  364. {
  365. if (!PFXExportCertStoreEx(
  366. hTempStore,
  367. &pfxBlob,
  368. pExportHelper->pwszPassword,
  369. NULL,
  370. (pExportHelper->fExportPrivateKeys ? EXPORT_PRIVATE_KEYS : 0) | REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY))
  371. {
  372. hr = GetLastError();
  373. CertCloseStore(hTempStore, 0);
  374. return hr;
  375. }
  376. if (NULL == (pfxBlob.pbData = (BYTE *) malloc(pfxBlob.cbData)))
  377. {
  378. CertCloseStore(hTempStore, 0);
  379. SetLastError(E_OUTOFMEMORY);
  380. return E_OUTOFMEMORY;
  381. }
  382. if (!PFXExportCertStoreEx(
  383. hTempStore,
  384. &pfxBlob,
  385. pExportHelper->pwszPassword,
  386. NULL,
  387. (pExportHelper->fExportPrivateKeys ? EXPORT_PRIVATE_KEYS : 0) | REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY))
  388. {
  389. hr = GetLastError();
  390. CertCloseStore(hTempStore, 0);
  391. free(pfxBlob.pbData);
  392. return hr;
  393. }
  394. }
  395. else
  396. {
  397. if (!PFXExportCertStore(
  398. hTempStore,
  399. &pfxBlob,
  400. pExportHelper->pwszPassword,
  401. (pExportHelper->fExportPrivateKeys ? EXPORT_PRIVATE_KEYS : 0) | REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY))
  402. {
  403. hr = GetLastError();
  404. CertCloseStore(hTempStore, 0);
  405. return hr;
  406. }
  407. if (NULL == (pfxBlob.pbData = (BYTE *) malloc(pfxBlob.cbData)))
  408. {
  409. CertCloseStore(hTempStore, 0);
  410. SetLastError(E_OUTOFMEMORY);
  411. return E_OUTOFMEMORY;
  412. }
  413. if (!PFXExportCertStore(
  414. hTempStore,
  415. &pfxBlob,
  416. pExportHelper->pwszPassword,
  417. (pExportHelper->fExportPrivateKeys ? EXPORT_PRIVATE_KEYS : 0) | REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY))
  418. {
  419. hr = GetLastError();
  420. CertCloseStore(hTempStore, 0);
  421. free(pfxBlob.pbData);
  422. return hr;
  423. }
  424. }
  425. CertCloseStore(hTempStore, 0);
  426. if (S_OK != (hr = OpenAndWriteToFile(
  427. pExportHelper->pwszExportFileName,
  428. pfxBlob.pbData,
  429. pfxBlob.cbData)))
  430. {
  431. free(pfxBlob.pbData);
  432. return hr;
  433. }
  434. free(pfxBlob.pbData);
  435. if (pExportHelper->fDeletePrivateKey)
  436. {
  437. if (!CertGetCertificateContextProperty(
  438. pExportHelper->pExportInfo->pCertContext,
  439. CERT_KEY_PROV_INFO_PROP_ID,
  440. NULL,
  441. &cbCryptKeyProvInfo))
  442. {
  443. return GetLastError();
  444. }
  445. if (NULL == (pCryptKeyProvInfo = (CRYPT_KEY_PROV_INFO *) malloc(cbCryptKeyProvInfo)))
  446. {
  447. return E_OUTOFMEMORY;
  448. }
  449. if (!CertGetCertificateContextProperty(
  450. pExportHelper->pExportInfo->pCertContext,
  451. CERT_KEY_PROV_INFO_PROP_ID,
  452. pCryptKeyProvInfo,
  453. &cbCryptKeyProvInfo))
  454. {
  455. free(pCryptKeyProvInfo);
  456. return GetLastError();
  457. }
  458. // acquire the HCRYPTPROV so we can export the private key in that puppy
  459. if (!CryptAcquireContextU(
  460. &hCryptProv,
  461. pCryptKeyProvInfo->pwszContainerName,
  462. pCryptKeyProvInfo->pwszProvName,
  463. pCryptKeyProvInfo->dwProvType,
  464. pCryptKeyProvInfo->dwFlags | CRYPT_DELETEKEYSET))
  465. {
  466. free(pCryptKeyProvInfo);
  467. return GetLastError();
  468. }
  469. free(pCryptKeyProvInfo);
  470. CertSetCertificateContextProperty(
  471. pExportHelper->pExportInfo->pCertContext,
  472. CERT_KEY_PROV_INFO_PROP_ID,
  473. 0,
  474. NULL);
  475. }
  476. return S_OK;
  477. break;
  478. case CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7:
  479. case CRYPTUI_WIZ_EXPORT_FORMAT_SERIALIZED_CERT_STORE:
  480. //
  481. // open a temporary memory store that the serialized export will be done from
  482. //
  483. hTempStore = CertOpenStore(
  484. CERT_STORE_PROV_MEMORY,
  485. X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  486. 0,
  487. CERT_STORE_ENUM_ARCHIVED_FLAG,
  488. NULL);
  489. if (hTempStore == NULL)
  490. {
  491. return GetLastError();
  492. }
  493. //
  494. // get all the certs in the chain if we need to
  495. //
  496. if (pExportHelper->fExportChain)
  497. {
  498. AddChainToStore(
  499. hTempStore,
  500. pExportHelper->pExportInfo->pCertContext,
  501. pExportHelper->pExportInfo->cStores,
  502. pExportHelper->pExportInfo->rghStores,
  503. FALSE,
  504. NULL);
  505. }
  506. CertAddCertificateContextToStore(
  507. hTempStore,
  508. pExportHelper->pExportInfo->pCertContext,
  509. CERT_STORE_ADD_REPLACE_EXISTING,
  510. NULL);
  511. if (!CertSaveStore(
  512. hTempStore,
  513. X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  514. (pExportHelper->dwExportFormat == CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7) ? CERT_STORE_SAVE_AS_PKCS7 : CERT_STORE_SAVE_AS_STORE,
  515. CERT_STORE_SAVE_TO_FILENAME_W,
  516. (void *) pExportHelper->pwszExportFileName,
  517. 0))
  518. {
  519. hr = GetLastError();
  520. CertCloseStore(hTempStore, 0);
  521. return hr;
  522. }
  523. CertCloseStore(hTempStore, 0);
  524. return S_OK;
  525. break;
  526. }
  527. break;
  528. }
  529. return hr;
  530. }
  531. //////////////////////////////////////////////////////////////////////////////////////
  532. //
  533. //////////////////////////////////////////////////////////////////////////////////////
  534. static INT_PTR APIENTRY ExportWelcomePageProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  535. {
  536. PEXPORT_HELPER_STRUCT pExportHelper = NULL;
  537. PROPSHEETPAGE *pPropSheet = NULL;
  538. switch (msg)
  539. {
  540. case WM_INITDIALOG:
  541. //set the wizard information so that it can be shared
  542. pPropSheet = (PROPSHEETPAGE *) lParam;
  543. pExportHelper = (PEXPORT_HELPER_STRUCT) (pPropSheet->lParam);
  544. SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pExportHelper);
  545. SetControlFont(pExportHelper->hBigBold, hwndDlg,IDC_WELCOME_STATIC);
  546. SetControlFont(pExportHelper->hBold, hwndDlg, IDC_WHATISCERT_STATIC);
  547. SetControlFont(pExportHelper->hBold, hwndDlg, IDC_WHATISSTORE_STATIC);
  548. break;
  549. case WM_NOTIFY:
  550. pExportHelper = (PEXPORT_HELPER_STRUCT) GetWindowLongPtr(hwndDlg, DWLP_USER);
  551. switch (((NMHDR FAR *) lParam)->code)
  552. {
  553. case PSN_QUERYCANCEL:
  554. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  555. pExportHelper->dwErrorCode = ERROR_CANCELLED;
  556. return TRUE;
  557. case PSN_KILLACTIVE:
  558. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  559. return TRUE;
  560. case PSN_RESET:
  561. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  562. break;
  563. case PSN_SETACTIVE:
  564. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT);
  565. break;
  566. case PSN_WIZBACK:
  567. break;
  568. case PSN_WIZNEXT:
  569. //
  570. // if this isn't a cert, then the only page is the file name
  571. //
  572. if (pExportHelper->pExportInfo->dwSubjectChoice != CRYPTUI_WIZ_EXPORT_CERT_CONTEXT)
  573. {
  574. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_EXPORTWIZARD_FILENAME);
  575. }
  576. //
  577. // if there are no private keys then skip the page that asks if they are to be exported
  578. //
  579. else if (!pExportHelper->fPrivateKeysExist)
  580. {
  581. pExportHelper->fExportPrivateKeys = FALSE;
  582. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_EXPORTWIZARD_FORMAT);
  583. }
  584. else if (CRYPTUI_WIZ_EXPORT_PRIVATE_KEY & pExportHelper->dwFlags)
  585. {
  586. //
  587. // Skip the page if explictly asked to export the private key.
  588. //
  589. pExportHelper->fExportPrivateKeys = TRUE;
  590. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_EXPORTWIZARD_FORMAT);
  591. }
  592. break;
  593. default:
  594. return FALSE;
  595. }
  596. break;
  597. default:
  598. return FALSE;
  599. }
  600. return TRUE;
  601. }
  602. //////////////////////////////////////////////////////////////////////////////////////
  603. //
  604. //////////////////////////////////////////////////////////////////////////////////////
  605. static INT_PTR APIENTRY ExportPrivateKeysPageProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  606. {
  607. PEXPORT_HELPER_STRUCT pExportHelper = NULL;
  608. PROPSHEETPAGE *pPropSheet = NULL;
  609. WCHAR szNoteString[MAX_STRING_SIZE];
  610. switch (msg)
  611. {
  612. case WM_INITDIALOG:
  613. //
  614. //set the wizard information so that it can be shared
  615. //
  616. pPropSheet = (PROPSHEETPAGE *) lParam;
  617. pExportHelper = (PEXPORT_HELPER_STRUCT) (pPropSheet->lParam);
  618. SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pExportHelper);
  619. SetControlFont(pExportHelper->hBold, hwndDlg, IDC_EPKWC_STATIC);
  620. switch (pExportHelper->dwExportablePrivateKeyStatus)
  621. {
  622. case PRIVATE_KEY_UNKNOWN_STATE:
  623. #if (0) // DSIE: Bug 284895
  624. if (pExportHelper->pExportCertInfo != NULL)
  625. {
  626. SendDlgItemMessage(
  627. hwndDlg,
  628. IDC_YESPKEYS_RADIO,
  629. BM_SETCHECK,
  630. pExportHelper->pExportCertInfo->fExportPrivateKeys ? 1 : 0,
  631. (LPARAM) 0);
  632. }
  633. else
  634. {
  635. SendDlgItemMessage(hwndDlg, IDC_NOPKEYS_RADIO, BM_SETCHECK, 1, (LPARAM) 0);
  636. }
  637. #else
  638. SendDlgItemMessage(hwndDlg, IDC_NOPKEYS_RADIO, BM_SETCHECK, 1, (LPARAM) 0);
  639. #endif
  640. LoadStringU(g_hmodThisDll, IDS_KEY_STATE_UNKNOWN, szNoteString, ARRAYSIZE(szNoteString));
  641. SetDlgItemTextU(hwndDlg, IDC_EXPORT_PKEY_NOTE, szNoteString);
  642. break;
  643. case PRIVATE_KEY_CORRUPT:
  644. LoadStringU(g_hmodThisDll, IDS_KEY_CORRUPT, szNoteString, ARRAYSIZE(szNoteString));
  645. SetDlgItemTextU(hwndDlg, IDC_EXPORT_PKEY_NOTE, szNoteString);
  646. EnableWindow(GetDlgItem(hwndDlg, IDC_YESPKEYS_RADIO), FALSE);
  647. SendDlgItemMessage(hwndDlg, IDC_NOPKEYS_RADIO, BM_SETCHECK, 1, (LPARAM) 0);
  648. break;
  649. case PRIVATE_KEY_NOT_EXPORTABLE:
  650. LoadStringU(g_hmodThisDll, IDS_KEY_NOT_EXPORTABLE, szNoteString, ARRAYSIZE(szNoteString));
  651. SetDlgItemTextU(hwndDlg, IDC_EXPORT_PKEY_NOTE, szNoteString);
  652. EnableWindow(GetDlgItem(hwndDlg, IDC_YESPKEYS_RADIO), FALSE);
  653. SendDlgItemMessage(hwndDlg, IDC_NOPKEYS_RADIO, BM_SETCHECK, 1, (LPARAM) 0);
  654. break;
  655. case PRIVATE_KEY_EXPORTABLE:
  656. #if (0) // DSIE: Bug 284895
  657. if (pExportHelper->pExportCertInfo != NULL)
  658. {
  659. SendDlgItemMessage(
  660. hwndDlg,
  661. IDC_YESPKEYS_RADIO,
  662. BM_SETCHECK,
  663. pExportHelper->pExportCertInfo->fExportPrivateKeys ? 1 : 0,
  664. (LPARAM) 0);
  665. }
  666. else
  667. {
  668. SendDlgItemMessage(hwndDlg, IDC_YESPKEYS_RADIO, BM_SETCHECK, 1, (LPARAM) 0);
  669. }
  670. #else
  671. SendDlgItemMessage(hwndDlg, IDC_NOPKEYS_RADIO, BM_SETCHECK, 1, (LPARAM) 0);
  672. #endif
  673. break;
  674. }
  675. break;
  676. case WM_NOTIFY:
  677. pExportHelper = (PEXPORT_HELPER_STRUCT) GetWindowLongPtr(hwndDlg, DWLP_USER);
  678. switch (((NMHDR FAR *) lParam)->code)
  679. {
  680. case PSN_QUERYCANCEL:
  681. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  682. pExportHelper->dwErrorCode = ERROR_CANCELLED;
  683. return TRUE;
  684. case PSN_KILLACTIVE:
  685. pExportHelper->fExportPrivateKeys =
  686. (int)SendDlgItemMessage(hwndDlg, IDC_YESPKEYS_RADIO, BM_GETCHECK, 0, (LPARAM) 0);
  687. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  688. return TRUE;
  689. case PSN_RESET:
  690. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  691. break;
  692. case PSN_SETACTIVE:
  693. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT | PSWIZB_BACK);
  694. break;
  695. case PSN_WIZBACK:
  696. break;
  697. case PSN_WIZNEXT:
  698. break;
  699. default:
  700. return FALSE;
  701. }
  702. break;
  703. default:
  704. return FALSE;
  705. }
  706. return TRUE;
  707. }
  708. //////////////////////////////////////////////////////////////////////////////////////
  709. //
  710. //////////////////////////////////////////////////////////////////////////////////////
  711. static INT_PTR APIENTRY ExportFormatPageProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  712. {
  713. PEXPORT_HELPER_STRUCT pExportHelper = NULL;
  714. PROPSHEETPAGE *pPropSheet = NULL;
  715. WCHAR szErrorTitle[MAX_STRING_SIZE];
  716. WCHAR szErrorString[MAX_STRING_SIZE];
  717. switch (msg)
  718. {
  719. case WM_INITDIALOG:
  720. //set the wizard information so that it can be shared
  721. pPropSheet = (PROPSHEETPAGE *) lParam;
  722. pExportHelper = (PEXPORT_HELPER_STRUCT) (pPropSheet->lParam);
  723. SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pExportHelper);
  724. SetControlFont(pExportHelper->hBold, hwndDlg, IDC_EFF_STATIC);
  725. if (pExportHelper->pExportCertInfo != NULL)
  726. {
  727. if (pExportHelper->pExportCertInfo->fExportChain)
  728. {
  729. SendDlgItemMessageA(hwndDlg, IDC_INCLUDECHAIN_PFX_CHECK, BM_SETCHECK, 1, 0);
  730. SendDlgItemMessageA(hwndDlg, IDC_INCLUDECHAIN_PKCS7_CHECK, BM_SETCHECK, 1, 0);
  731. }
  732. else
  733. {
  734. SendDlgItemMessageA(hwndDlg, IDC_INCLUDECHAIN_PFX_CHECK, BM_SETCHECK, 0, 0);
  735. SendDlgItemMessageA(hwndDlg, IDC_INCLUDECHAIN_PKCS7_CHECK, BM_SETCHECK, 0, 0);
  736. }
  737. if (!(pExportHelper->fExportPrivateKeys))
  738. {
  739. switch (pExportHelper->pExportCertInfo->dwExportFormat)
  740. {
  741. case CRYPTUI_WIZ_EXPORT_FORMAT_DER:
  742. SendDlgItemMessageA(hwndDlg, IDC_DER_RADIO, BM_SETCHECK, 1, 0);
  743. break;
  744. case CRYPTUI_WIZ_EXPORT_FORMAT_BASE64:
  745. SendDlgItemMessageA(hwndDlg, IDC_BASE64_RADIO, BM_SETCHECK, 1, 0);
  746. break;
  747. case CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7:
  748. SendDlgItemMessageA(hwndDlg, IDC_PKCS7_RADIO, BM_SETCHECK, 1, 0);
  749. break;
  750. default:
  751. SendDlgItemMessageA(hwndDlg, IDC_DER_RADIO, BM_SETCHECK, 1, 0);
  752. break;
  753. }
  754. }
  755. }
  756. else
  757. {
  758. if (!pExportHelper->fExportPrivateKeys)
  759. {
  760. SendDlgItemMessageA(hwndDlg, IDC_DER_RADIO, BM_SETCHECK, 1, 0);
  761. }
  762. }
  763. break;
  764. case WM_COMMAND:
  765. pExportHelper = (PEXPORT_HELPER_STRUCT) GetWindowLongPtr(hwndDlg, DWLP_USER);
  766. switch (LOWORD(wParam))
  767. {
  768. case IDC_DER_RADIO:
  769. case IDC_BASE64_RADIO:
  770. if (HIWORD(wParam) == BN_CLICKED)
  771. {
  772. EnableWindow(GetDlgItem(hwndDlg, IDC_INCLUDECHAIN_PFX_CHECK), FALSE);
  773. EnableWindow(GetDlgItem(hwndDlg, IDC_INCLUDECHAIN_PKCS7_CHECK), FALSE);
  774. return TRUE;
  775. }
  776. break;
  777. case IDC_PFX_RADIO:
  778. if (HIWORD(wParam) == BN_CLICKED)
  779. {
  780. EnableWindow(GetDlgItem(hwndDlg, IDC_INCLUDECHAIN_PFX_CHECK), TRUE);
  781. EnableWindow(GetDlgItem(hwndDlg, IDC_INCLUDECHAIN_PKCS7_CHECK), FALSE);
  782. return TRUE;
  783. }
  784. break;
  785. case IDC_PKCS7_RADIO:
  786. if (HIWORD(wParam) == BN_CLICKED)
  787. {
  788. EnableWindow(GetDlgItem(hwndDlg, IDC_INCLUDECHAIN_PFX_CHECK), FALSE);
  789. EnableWindow(GetDlgItem(hwndDlg, IDC_INCLUDECHAIN_PKCS7_CHECK), TRUE);
  790. return TRUE;
  791. }
  792. break;
  793. }
  794. break;
  795. case WM_NOTIFY:
  796. pExportHelper = (PEXPORT_HELPER_STRUCT) GetWindowLongPtr(hwndDlg, DWLP_USER);
  797. switch (((NMHDR FAR *) lParam)->code)
  798. {
  799. case PSN_QUERYCANCEL:
  800. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  801. pExportHelper->dwErrorCode = ERROR_CANCELLED;
  802. return TRUE;
  803. case PSN_KILLACTIVE:
  804. if (SendDlgItemMessageA(hwndDlg, IDC_PKCS7_RADIO, BM_GETCHECK, 0, 0))
  805. {
  806. pExportHelper->dwExportFormat = CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7;
  807. pExportHelper->fExportChain = (int)SendDlgItemMessageA(hwndDlg, IDC_INCLUDECHAIN_PKCS7_CHECK, BM_GETCHECK, 0, 0);
  808. }
  809. else if (SendDlgItemMessageA(hwndDlg, IDC_PFX_RADIO, BM_GETCHECK, 0, 0))
  810. {
  811. pExportHelper->dwExportFormat = CRYPTUI_WIZ_EXPORT_FORMAT_PFX;
  812. pExportHelper->fExportChain = (int)SendDlgItemMessageA(hwndDlg, IDC_INCLUDECHAIN_PFX_CHECK, BM_GETCHECK, 0, 0);
  813. pExportHelper->fStrongEncryption = (int)SendDlgItemMessageA(hwndDlg, IDC_STRONG_ENCRYPTION_CHECK, BM_GETCHECK, 0, 0);
  814. pExportHelper->fDeletePrivateKey = (int)SendDlgItemMessageA(hwndDlg, IDC_DELETE_PRIVATE_KEY_CHECK, BM_GETCHECK, 0, 0);
  815. }
  816. else if (SendDlgItemMessageA(hwndDlg, IDC_DER_RADIO, BM_GETCHECK, 0, 0))
  817. {
  818. pExportHelper->dwExportFormat = CRYPTUI_WIZ_EXPORT_FORMAT_DER;
  819. pExportHelper->fExportChain = FALSE;
  820. }
  821. else if (SendDlgItemMessageA(hwndDlg, IDC_BASE64_RADIO, BM_GETCHECK, 0, 0))
  822. {
  823. pExportHelper->dwExportFormat = CRYPTUI_WIZ_EXPORT_FORMAT_BASE64;
  824. pExportHelper->fExportChain = FALSE;
  825. }
  826. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  827. return TRUE;
  828. case PSN_RESET:
  829. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  830. break;
  831. case PSN_SETACTIVE:
  832. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT | PSWIZB_BACK);
  833. if (pExportHelper->fExportPrivateKeys)
  834. {
  835. SendDlgItemMessageA(hwndDlg, IDC_PFX_RADIO, BM_SETCHECK, 1, 0);
  836. SendDlgItemMessageA(hwndDlg, IDC_PKCS7_RADIO, BM_SETCHECK, 0, 0);
  837. SendDlgItemMessageA(hwndDlg, IDC_DER_RADIO, BM_SETCHECK, 0, 0);
  838. SendDlgItemMessageA(hwndDlg, IDC_BASE64_RADIO, BM_SETCHECK, 0, 0);
  839. SendDlgItemMessageA(hwndDlg,
  840. IDC_STRONG_ENCRYPTION_CHECK,
  841. BM_SETCHECK,
  842. pExportHelper->fStrongEncryption,
  843. 0);
  844. SendDlgItemMessageA(hwndDlg,
  845. IDC_DELETE_PRIVATE_KEY_CHECK,
  846. BM_SETCHECK,
  847. pExportHelper->fDeletePrivateKey,
  848. 0);
  849. EnableWindow(GetDlgItem(hwndDlg, IDC_PFX_RADIO), TRUE);
  850. EnableWindow(GetDlgItem(hwndDlg, IDC_PKCS7_RADIO), FALSE);
  851. EnableWindow(GetDlgItem(hwndDlg, IDC_DER_RADIO), FALSE);
  852. EnableWindow(GetDlgItem(hwndDlg, IDC_BASE64_RADIO), FALSE);
  853. EnableWindow(GetDlgItem(hwndDlg, IDC_INCLUDECHAIN_PFX_CHECK), TRUE);
  854. EnableWindow(GetDlgItem(hwndDlg, IDC_STRONG_ENCRYPTION_CHECK), TRUE);
  855. EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_PRIVATE_KEY_CHECK),
  856. CRYPTUI_WIZ_EXPORT_NO_DELETE_PRIVATE_KEY & pExportHelper->dwFlags ? FALSE : TRUE);
  857. EnableWindow(GetDlgItem(hwndDlg, IDC_INCLUDECHAIN_PKCS7_CHECK), FALSE);
  858. }
  859. else
  860. {
  861. SendDlgItemMessageA(hwndDlg, IDC_PFX_RADIO, BM_SETCHECK, 0, 0);
  862. EnableWindow(GetDlgItem(hwndDlg, IDC_PFX_RADIO), FALSE);
  863. EnableWindow(GetDlgItem(hwndDlg, IDC_PKCS7_RADIO), TRUE);
  864. EnableWindow(GetDlgItem(hwndDlg, IDC_DER_RADIO), TRUE);
  865. EnableWindow(GetDlgItem(hwndDlg, IDC_BASE64_RADIO), TRUE);
  866. EnableWindow(GetDlgItem(hwndDlg, IDC_INCLUDECHAIN_PFX_CHECK), FALSE);
  867. EnableWindow(GetDlgItem(hwndDlg, IDC_STRONG_ENCRYPTION_CHECK), FALSE);
  868. EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_PRIVATE_KEY_CHECK), FALSE);
  869. if (SendDlgItemMessageA(hwndDlg, IDC_PKCS7_RADIO, BM_GETCHECK, 0, 0))
  870. {
  871. EnableWindow(GetDlgItem(hwndDlg, IDC_INCLUDECHAIN_PKCS7_CHECK), TRUE);
  872. }
  873. else
  874. {
  875. EnableWindow(GetDlgItem(hwndDlg, IDC_INCLUDECHAIN_PKCS7_CHECK), FALSE);
  876. }
  877. if (!SendDlgItemMessageA(hwndDlg, IDC_DER_RADIO, BM_GETCHECK, 0, 0) &&
  878. !SendDlgItemMessageA(hwndDlg, IDC_PKCS7_RADIO, BM_GETCHECK, 0, 0) &&
  879. !SendDlgItemMessageA(hwndDlg, IDC_BASE64_RADIO, BM_GETCHECK, 0, 0))
  880. {
  881. SendDlgItemMessageA(hwndDlg, IDC_DER_RADIO, BM_SETCHECK, 1, 0);
  882. }
  883. }
  884. break;
  885. case PSN_WIZBACK:
  886. if (!pExportHelper->fPrivateKeysExist ||
  887. (CRYPTUI_WIZ_EXPORT_PRIVATE_KEY & pExportHelper->dwFlags))
  888. {
  889. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_EXPORTWIZARD_WELCOME);
  890. }
  891. break;
  892. case PSN_WIZNEXT:
  893. if (!SendDlgItemMessageA(hwndDlg, IDC_PKCS7_RADIO, BM_GETCHECK, 0, 0) &&
  894. !SendDlgItemMessageA(hwndDlg, IDC_PFX_RADIO, BM_GETCHECK, 0, 0) &&
  895. !SendDlgItemMessageA(hwndDlg, IDC_DER_RADIO, BM_GETCHECK, 0, 0) &&
  896. !SendDlgItemMessageA(hwndDlg, IDC_BASE64_RADIO, BM_GETCHECK, 0, 0))
  897. {
  898. I_MessageBox(hwndDlg, IDS_SELECT_FORMAT, IDS_EXPORT_WIZARD_TITLE, NULL, MB_OK | MB_ICONWARNING);
  899. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
  900. break;
  901. }
  902. if (!SendDlgItemMessageA(hwndDlg, IDC_PFX_RADIO, BM_GETCHECK, 0, 0))
  903. {
  904. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_EXPORTWIZARD_FILENAME);
  905. return TRUE;
  906. }
  907. break;
  908. default:
  909. return FALSE;
  910. }
  911. break;
  912. default:
  913. return FALSE;
  914. }
  915. return TRUE;
  916. }
  917. //////////////////////////////////////////////////////////////////////////////////////
  918. //
  919. //////////////////////////////////////////////////////////////////////////////////////
  920. static INT_PTR APIENTRY ExportPasswordPageProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  921. {
  922. PEXPORT_HELPER_STRUCT pExportHelper = NULL;
  923. PROPSHEETPAGE *pPropSheet = NULL;
  924. LPWSTR pwszPassword1;
  925. LPWSTR pwszPassword2;
  926. DWORD cch1, cch2;
  927. WCHAR szErrorTitle[MAX_STRING_SIZE];
  928. WCHAR szErrorString[MAX_STRING_SIZE];
  929. switch (msg)
  930. {
  931. case WM_INITDIALOG:
  932. //set the wizard information so that it can be shared
  933. pPropSheet = (PROPSHEETPAGE *) lParam;
  934. pExportHelper = (PEXPORT_HELPER_STRUCT) (pPropSheet->lParam);
  935. SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pExportHelper);
  936. SetControlFont(pExportHelper->hBold, hwndDlg, IDC_PPPK_STATIC);
  937. #if (1) //DSIE: Bug 333621
  938. SendDlgItemMessage(hwndDlg, IDC_PASSWORD1_EDIT, EM_LIMITTEXT, (WPARAM) 32, (LPARAM) 0);
  939. SendDlgItemMessage(hwndDlg, IDC_PASSWORD2_EDIT, EM_LIMITTEXT, (WPARAM) 32, (LPARAM) 0);
  940. #endif
  941. SetDlgItemTextU(hwndDlg, IDC_PASSWORD1_EDIT, L"");
  942. SetDlgItemTextU(hwndDlg, IDC_PASSWORD2_EDIT, L"");
  943. break;
  944. /*case WM_COMMAND:
  945. pExportHelper = (PEXPORT_HELPER_STRUCT) GetWindowLongPtr(hwndDlg, DWLP_USER);
  946. switch (LOWORD(wParam))
  947. {
  948. case IDC_PASSWORD1_EDIT:
  949. if (HIWORD(wParam) == EN_SETFOCUS)
  950. {
  951. SendDlgItemMessageA(hwndDlg, IDC_PASSWORD1_EDIT, EM_SETSEL, 0, -1);
  952. return TRUE;
  953. }
  954. break;
  955. case IDC_PASSWORD2_EDIT:
  956. if (HIWORD(wParam) == EN_SETFOCUS)
  957. {
  958. SendDlgItemMessageA(hwndDlg, IDC_PASSWORD2_EDIT, EM_SETSEL, 0, -1);
  959. return TRUE;
  960. }
  961. break;
  962. }
  963. break;*/
  964. case WM_NOTIFY:
  965. pExportHelper = (PEXPORT_HELPER_STRUCT) GetWindowLongPtr(hwndDlg, DWLP_USER);
  966. switch (((NMHDR FAR *) lParam)->code)
  967. {
  968. case PSN_QUERYCANCEL:
  969. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  970. pExportHelper->dwErrorCode = ERROR_CANCELLED;
  971. return TRUE;
  972. case PSN_KILLACTIVE:
  973. if (pExportHelper->pwszPassword != NULL)
  974. {
  975. // DSIE: Bug 534689.
  976. SecureZeroMemory(pExportHelper->pwszPassword, lstrlenW(pExportHelper->pwszPassword) * sizeof(WCHAR));
  977. free(pExportHelper->pwszPassword);
  978. pExportHelper->pwszPassword = NULL;
  979. }
  980. cch1 = (DWORD)SendDlgItemMessage(hwndDlg, IDC_PASSWORD1_EDIT, WM_GETTEXTLENGTH, 0, 0);
  981. if (NULL == (pwszPassword1 = (LPWSTR) malloc((cch1+1)*sizeof(WCHAR))))
  982. {
  983. return FALSE;
  984. }
  985. cch2 = (DWORD)SendDlgItemMessage(hwndDlg, IDC_PASSWORD2_EDIT, WM_GETTEXTLENGTH, 0, 0);
  986. if (NULL == (pwszPassword2 = (LPWSTR) malloc((cch2+1)*sizeof(WCHAR))))
  987. {
  988. free(pwszPassword1);
  989. return FALSE;
  990. }
  991. GetDlgItemTextU(hwndDlg, IDC_PASSWORD1_EDIT, pwszPassword1, cch1+1);
  992. GetDlgItemTextU(hwndDlg, IDC_PASSWORD2_EDIT, pwszPassword2, cch2+1);
  993. if ((cch1 == 0) && (cch2 == 0))
  994. {
  995. // DSIE: Bug 563670.
  996. SecureZeroMemory(pwszPassword1, lstrlenW(pwszPassword1) * sizeof(WCHAR));
  997. SecureZeroMemory(pwszPassword2, lstrlenW(pwszPassword2) * sizeof(WCHAR));
  998. free(pwszPassword1);
  999. free(pwszPassword2);
  1000. pExportHelper->pwszPassword = NULL;
  1001. }
  1002. else if (wcscmp(pwszPassword1, pwszPassword2) != 0)
  1003. {
  1004. I_MessageBox(hwndDlg, IDS_MISMATCH_PASSWORDS, IDS_EXPORT_WIZARD_TITLE, NULL, MB_OK | MB_ICONWARNING);
  1005. SetFocus(GetDlgItem(hwndDlg, IDC_PASSWORD1_EDIT));
  1006. //SendDlgItemMessageA(hwndDlg, IDC_PASSWORD1_EDIT, EM_SETSEL, 0, -1);
  1007. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
  1008. SecureZeroMemory(pwszPassword1, lstrlenW(pwszPassword1) * sizeof(WCHAR));
  1009. SecureZeroMemory(pwszPassword2, lstrlenW(pwszPassword2) * sizeof(WCHAR));
  1010. free(pwszPassword1);
  1011. free(pwszPassword2);
  1012. break;
  1013. }
  1014. else
  1015. {
  1016. pExportHelper->pwszPassword = pwszPassword1;
  1017. // DSIE: Bug 534689.
  1018. SecureZeroMemory(pwszPassword2, lstrlenW(pwszPassword2) * sizeof(WCHAR));
  1019. free(pwszPassword2);
  1020. }
  1021. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  1022. return TRUE;
  1023. case PSN_RESET:
  1024. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  1025. break;
  1026. case PSN_SETACTIVE:
  1027. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT | PSWIZB_BACK);
  1028. break;
  1029. case PSN_WIZBACK:
  1030. break;
  1031. case PSN_WIZNEXT:
  1032. break;
  1033. default:
  1034. return FALSE;
  1035. }
  1036. break;
  1037. default:
  1038. return FALSE;
  1039. }
  1040. return TRUE;
  1041. }
  1042. //////////////////////////////////////////////////////////////////////////////////////
  1043. //
  1044. //////////////////////////////////////////////////////////////////////////////////////
  1045. static LPWSTR
  1046. BrowseForFileName(
  1047. HWND hwndDlg,
  1048. PEXPORT_HELPER_STRUCT pExportHelper,
  1049. LPWSTR pwszInitialDir)
  1050. {
  1051. OPENFILENAMEW openFileName;
  1052. WCHAR saveFileName[_MAX_PATH];
  1053. WCHAR filterString[MAX_STRING_SIZE];
  1054. memset(&openFileName, 0, sizeof(OPENFILENAMEW));
  1055. openFileName.lStructSize = sizeof(openFileName);
  1056. openFileName.hwndOwner = hwndDlg;
  1057. openFileName.hInstance = NULL;
  1058. switch (pExportHelper->pExportInfo->dwSubjectChoice)
  1059. {
  1060. case CRYPTUI_WIZ_EXPORT_CERT_STORE:
  1061. LoadFilterString(g_hmodThisDll, IDS_SERIALIZED_STORE_SAVE, filterString, ARRAYSIZE(filterString)-1);
  1062. openFileName.lpstrDefExt = L"sst";
  1063. break;
  1064. case CRYPTUI_WIZ_EXPORT_CERT_STORE_CERTIFICATES_ONLY:
  1065. LoadFilterString(g_hmodThisDll, IDS_PKCS7_SAVE, filterString, ARRAYSIZE(filterString)-1);
  1066. openFileName.lpstrDefExt = L"p7b";
  1067. break;
  1068. case CRYPTUI_WIZ_EXPORT_CRL_CONTEXT:
  1069. LoadFilterString(g_hmodThisDll, IDS_CRL_SAVE, filterString, ARRAYSIZE(filterString)-1);
  1070. openFileName.lpstrDefExt = L"crl";
  1071. break;
  1072. case CRYPTUI_WIZ_EXPORT_CTL_CONTEXT:
  1073. LoadFilterString(g_hmodThisDll, IDS_CTL_SAVE, filterString, ARRAYSIZE(filterString)-1);
  1074. openFileName.lpstrDefExt = L"stl";
  1075. break;
  1076. case CRYPTUI_WIZ_EXPORT_CERT_CONTEXT:
  1077. switch (pExportHelper->dwExportFormat)
  1078. {
  1079. case CRYPTUI_WIZ_EXPORT_FORMAT_DER:
  1080. LoadFilterString(g_hmodThisDll, IDS_DER_SAVE, filterString, ARRAYSIZE(filterString)-1);
  1081. openFileName.lpstrDefExt = L"cer";
  1082. break;
  1083. case CRYPTUI_WIZ_EXPORT_FORMAT_BASE64:
  1084. LoadFilterString(g_hmodThisDll, IDS_BASE64_SAVE, filterString, ARRAYSIZE(filterString)-1);
  1085. openFileName.lpstrDefExt = L"cer";
  1086. break;
  1087. case CRYPTUI_WIZ_EXPORT_FORMAT_PFX:
  1088. LoadFilterString(g_hmodThisDll, IDS_PFX_SAVE, filterString, ARRAYSIZE(filterString)-1);
  1089. openFileName.lpstrDefExt = L"pfx";
  1090. break;
  1091. case CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7:
  1092. LoadFilterString(g_hmodThisDll, IDS_PKCS7_SAVE, filterString, ARRAYSIZE(filterString)-1);
  1093. openFileName.lpstrDefExt = L"p7b";
  1094. break;
  1095. }
  1096. break;
  1097. }
  1098. openFileName.lpstrFilter = filterString;
  1099. openFileName.lpstrCustomFilter = NULL;
  1100. openFileName.nMaxCustFilter = 0;
  1101. openFileName.nFilterIndex = 1;
  1102. saveFileName[0] = 0;
  1103. openFileName.lpstrFile = saveFileName;
  1104. openFileName.nMaxFile = ARRAYSIZE(saveFileName);
  1105. openFileName.lpstrFileTitle = NULL;
  1106. openFileName.nMaxFileTitle = 0;
  1107. openFileName.lpstrInitialDir = pwszInitialDir;
  1108. openFileName.lpstrTitle = NULL;
  1109. openFileName.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
  1110. openFileName.nFileOffset = 0;
  1111. openFileName.nFileExtension = 0;
  1112. openFileName.lCustData = NULL;
  1113. openFileName.lpfnHook = NULL;
  1114. openFileName.lpTemplateName = NULL;
  1115. if (!WizGetSaveFileName(&openFileName))
  1116. {
  1117. return NULL;
  1118. }
  1119. return (AllocAndCopyWStr(saveFileName));
  1120. }
  1121. //////////////////////////////////////////////////////////////////////////////////////
  1122. //
  1123. //////////////////////////////////////////////////////////////////////////////////////
  1124. static HRESULT CheckAndAddExtension(PEXPORT_HELPER_STRUCT pExportHelper, LPWSTR pwszExt)
  1125. {
  1126. void *pTemp;
  1127. if ((wcslen(pExportHelper->pwszExportFileName) < 4) ||
  1128. (_wcsicmp(pwszExt, &(pExportHelper->pwszExportFileName[wcslen(pExportHelper->pwszExportFileName)-4])) != 0))
  1129. {
  1130. pTemp = realloc(pExportHelper->pwszExportFileName,
  1131. (wcslen(pExportHelper->pwszExportFileName) + 4 + 1) * sizeof(WCHAR));
  1132. if (pTemp != NULL)
  1133. {
  1134. pExportHelper->pwszExportFileName = (LPWSTR) pTemp;
  1135. wcscat(pExportHelper->pwszExportFileName, pwszExt);
  1136. }
  1137. else
  1138. {
  1139. // pExportHelper->pwszExportFileName will be free'd later
  1140. return E_OUTOFMEMORY;
  1141. }
  1142. }
  1143. return S_OK;
  1144. }
  1145. //////////////////////////////////////////////////////////////////////////////////////
  1146. //
  1147. //////////////////////////////////////////////////////////////////////////////////////
  1148. static HRESULT ValidateExtension(PEXPORT_HELPER_STRUCT pExportHelper)
  1149. {
  1150. switch (pExportHelper->pExportInfo->dwSubjectChoice)
  1151. {
  1152. case CRYPTUI_WIZ_EXPORT_CTL_CONTEXT:
  1153. return CheckAndAddExtension(pExportHelper, L".stl");
  1154. break;
  1155. case CRYPTUI_WIZ_EXPORT_CRL_CONTEXT:
  1156. return CheckAndAddExtension(pExportHelper, L".crl");
  1157. break;
  1158. case CRYPTUI_WIZ_EXPORT_CERT_STORE_CERTIFICATES_ONLY:
  1159. return CheckAndAddExtension(pExportHelper, L".p7b");
  1160. break;
  1161. case CRYPTUI_WIZ_EXPORT_CERT_STORE:
  1162. return CheckAndAddExtension(pExportHelper, L".sst");
  1163. break;
  1164. case CRYPTUI_WIZ_EXPORT_CERT_CONTEXT:
  1165. switch (pExportHelper->dwExportFormat)
  1166. {
  1167. case CRYPTUI_WIZ_EXPORT_FORMAT_DER:
  1168. case CRYPTUI_WIZ_EXPORT_FORMAT_BASE64:
  1169. return CheckAndAddExtension(pExportHelper, L".cer");
  1170. break;
  1171. case CRYPTUI_WIZ_EXPORT_FORMAT_PFX:
  1172. return CheckAndAddExtension(pExportHelper, L".pfx");
  1173. break;
  1174. case CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7:
  1175. return CheckAndAddExtension(pExportHelper, L".p7b");
  1176. break;
  1177. case CRYPTUI_WIZ_EXPORT_FORMAT_SERIALIZED_CERT_STORE:
  1178. return CheckAndAddExtension(pExportHelper, L".sst");
  1179. break;
  1180. }
  1181. break;
  1182. }
  1183. return S_OK;
  1184. }
  1185. //////////////////////////////////////////////////////////////////////////////////////
  1186. //
  1187. //////////////////////////////////////////////////////////////////////////////////////
  1188. static BOOL FileNameOK(HWND hwndDlg, LPWSTR pwszExportFileName)
  1189. {
  1190. WCHAR szErrorTitle[MAX_STRING_SIZE];
  1191. WCHAR szErrorString[MAX_STRING_SIZE];
  1192. LPWSTR psz;
  1193. HANDLE hTestFile;
  1194. int i;
  1195. hTestFile = ExpandAndCreateFileU(
  1196. pwszExportFileName,
  1197. GENERIC_READ,
  1198. FILE_SHARE_READ | FILE_SHARE_WRITE,
  1199. NULL,
  1200. OPEN_EXISTING,
  1201. 0,
  1202. 0);
  1203. if (hTestFile == INVALID_HANDLE_VALUE)
  1204. {
  1205. hTestFile = ExpandAndCreateFileU(
  1206. pwszExportFileName,
  1207. GENERIC_WRITE,
  1208. FILE_SHARE_READ | FILE_SHARE_WRITE,
  1209. NULL,
  1210. CREATE_NEW,
  1211. 0,
  1212. 0);
  1213. if (hTestFile == INVALID_HANDLE_VALUE)
  1214. {
  1215. LoadStringU(g_hmodThisDll, IDS_EXPORT_WIZARD_TITLE, szErrorTitle, ARRAYSIZE(szErrorTitle));
  1216. LoadStringU(g_hmodThisDll, IDS_PATH_NOT_FOUND, szErrorString, ARRAYSIZE(szErrorString));
  1217. MessageBoxExW(hwndDlg, szErrorString, szErrorTitle, MB_OK | MB_ICONWARNING, 0);
  1218. return (FALSE);
  1219. }
  1220. CloseHandle(hTestFile);
  1221. DeleteFileU(pwszExportFileName);
  1222. return TRUE;
  1223. }
  1224. else
  1225. {
  1226. CloseHandle(hTestFile);
  1227. LoadStringU(g_hmodThisDll, IDS_EXPORT_WIZARD_TITLE, szErrorTitle, ARRAYSIZE(szErrorTitle));
  1228. LoadStringU(g_hmodThisDll, IDS_OVERWRITE_FILE_NAME, szErrorString, ARRAYSIZE(szErrorString));
  1229. psz = (LPWSTR) malloc((wcslen(szErrorString) + wcslen(pwszExportFileName) + 1) * sizeof(WCHAR));
  1230. if (psz == NULL)
  1231. {
  1232. return FALSE;
  1233. }
  1234. swprintf(psz, szErrorString, pwszExportFileName);
  1235. i = MessageBoxExW(hwndDlg, psz, szErrorTitle, MB_YESNO | MB_ICONWARNING, 0);
  1236. free(psz);
  1237. return (i == IDYES);
  1238. }
  1239. }
  1240. //////////////////////////////////////////////////////////////////////////////////////
  1241. //
  1242. //////////////////////////////////////////////////////////////////////////////////////
  1243. static void AddDefaultPath(PEXPORT_HELPER_STRUCT pExportHelper)
  1244. {
  1245. int i;
  1246. BOOL fAdd = TRUE;
  1247. DWORD dwSize = 0;
  1248. LPWSTR pwszCurrentDir = NULL;
  1249. //
  1250. // check to see if there are any ':' or '\'
  1251. //
  1252. i = 0;
  1253. while (i<wcslen(pExportHelper->pwszExportFileName))
  1254. {
  1255. if ((pExportHelper->pwszExportFileName[i] == ':') ||
  1256. (pExportHelper->pwszExportFileName[i] == '\\'))
  1257. {
  1258. fAdd = FALSE;
  1259. }
  1260. i++;
  1261. }
  1262. if (fAdd)
  1263. {
  1264. dwSize = GetCurrentDirectoryU(0, NULL);
  1265. if (NULL != (pwszCurrentDir = (LPWSTR) malloc((wcslen(pExportHelper->pwszExportFileName) + dwSize + 1) * sizeof(WCHAR))))
  1266. {
  1267. GetCurrentDirectoryU(dwSize, pwszCurrentDir);
  1268. if (pwszCurrentDir[wcslen(pwszCurrentDir)-1] != '\\')
  1269. {
  1270. wcscat(pwszCurrentDir, L"\\");
  1271. }
  1272. wcscat(pwszCurrentDir, pExportHelper->pwszExportFileName);
  1273. free(pExportHelper->pwszExportFileName);
  1274. pExportHelper->pwszExportFileName = pwszCurrentDir;
  1275. }
  1276. }
  1277. }
  1278. //////////////////////////////////////////////////////////////////////////////////////
  1279. //
  1280. //////////////////////////////////////////////////////////////////////////////////////
  1281. static INT_PTR APIENTRY ExportFileNamePageProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  1282. {
  1283. PEXPORT_HELPER_STRUCT pExportHelper = NULL;
  1284. PROPSHEETPAGE *pPropSheet = NULL;
  1285. DWORD cch;
  1286. LPWSTR pwszTempFileName;
  1287. LPWSTR pwszInitialDir = NULL;
  1288. switch (msg)
  1289. {
  1290. case WM_INITDIALOG:
  1291. //set the wizard information so that it can be shared
  1292. pPropSheet = (PROPSHEETPAGE *) lParam;
  1293. pExportHelper = (PEXPORT_HELPER_STRUCT) (pPropSheet->lParam);
  1294. SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pExportHelper);
  1295. SetControlFont(pExportHelper->hBold, hwndDlg, IDC_EFN_STATIC);
  1296. if (pExportHelper->pExportInfo->pwszExportFileName != NULL)
  1297. {
  1298. SetDlgItemTextU(hwndDlg, IDC_NAME_EDIT, pExportHelper->pExportInfo->pwszExportFileName);
  1299. }
  1300. else
  1301. {
  1302. SetDlgItemTextU(hwndDlg, IDC_NAME_EDIT, L"");
  1303. }
  1304. break;
  1305. case WM_COMMAND:
  1306. pExportHelper = (PEXPORT_HELPER_STRUCT) GetWindowLongPtr(hwndDlg, DWLP_USER);
  1307. switch (LOWORD(wParam))
  1308. {
  1309. case IDC_NAME_EDIT:
  1310. {
  1311. if (EN_CHANGE == HIWORD(wParam))
  1312. {
  1313. if (SendDlgItemMessage(hwndDlg, IDC_NAME_EDIT, WM_GETTEXTLENGTH, 0, 0))
  1314. {
  1315. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT | PSWIZB_BACK);
  1316. }
  1317. else
  1318. {
  1319. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK);
  1320. }
  1321. return TRUE;
  1322. }
  1323. break;
  1324. }
  1325. case IDC_BROWSE_BUTTON:
  1326. {
  1327. if (HIWORD(wParam) == BN_CLICKED)
  1328. {
  1329. cch = (DWORD)SendDlgItemMessage(hwndDlg, IDC_NAME_EDIT, WM_GETTEXTLENGTH, 0, 0);
  1330. if (NULL != (pwszInitialDir = (LPWSTR) malloc((cch+1)*sizeof(WCHAR))))
  1331. {
  1332. GetDlgItemTextU(hwndDlg, IDC_NAME_EDIT, pwszInitialDir, cch+1);
  1333. }
  1334. pwszTempFileName = BrowseForFileName(hwndDlg, pExportHelper, pwszInitialDir);
  1335. if (pwszTempFileName != NULL)
  1336. {
  1337. SetDlgItemTextU(hwndDlg, IDC_NAME_EDIT, pwszTempFileName);
  1338. free(pwszTempFileName);
  1339. // SendDlgItemMessageA(hwndDlg, IDC_NAME_EDIT, EM_SETSEL, 0, -1);
  1340. pExportHelper->fDontCheckFileName = TRUE;
  1341. }
  1342. if (pwszInitialDir != NULL)
  1343. {
  1344. free(pwszInitialDir);
  1345. pwszInitialDir = NULL;
  1346. }
  1347. return TRUE;
  1348. }
  1349. break;
  1350. }
  1351. }
  1352. break;
  1353. case WM_NOTIFY:
  1354. pExportHelper = (PEXPORT_HELPER_STRUCT) GetWindowLongPtr(hwndDlg, DWLP_USER);
  1355. switch (((NMHDR FAR *) lParam)->code)
  1356. {
  1357. case PSN_QUERYCANCEL:
  1358. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  1359. pExportHelper->dwErrorCode = ERROR_CANCELLED;
  1360. return TRUE;
  1361. case PSN_KILLACTIVE:
  1362. if (pExportHelper->pwszExportFileName != NULL)
  1363. {
  1364. free(pExportHelper->pwszExportFileName);
  1365. pExportHelper->pwszExportFileName = NULL;
  1366. }
  1367. cch = (DWORD)SendDlgItemMessage(hwndDlg, IDC_NAME_EDIT, WM_GETTEXTLENGTH, 0, 0);
  1368. if (NULL == (pExportHelper->pwszExportFileName = (LPWSTR) malloc((cch+1)*sizeof(WCHAR))))
  1369. {
  1370. return FALSE;
  1371. }
  1372. GetDlgItemTextU(hwndDlg, IDC_NAME_EDIT, pExportHelper->pwszExportFileName, cch+1);
  1373. if (pExportHelper->fNextPage)
  1374. {
  1375. if (ValidateExtension(pExportHelper) != S_OK)
  1376. {
  1377. return FALSE;
  1378. }
  1379. }
  1380. if (pExportHelper->fNextPage)
  1381. {
  1382. AddDefaultPath(pExportHelper);
  1383. }
  1384. if (!(pExportHelper->fDontCheckFileName) &&
  1385. pExportHelper->fNextPage &&
  1386. ((pExportHelper->pwszExportFileNameToCheck == NULL) ||
  1387. (wcscmp(pExportHelper->pwszExportFileNameToCheck, pExportHelper->pwszExportFileName) != 0)))
  1388. {
  1389. if (!FileNameOK(hwndDlg, pExportHelper->pwszExportFileName))
  1390. {
  1391. SetFocus(GetDlgItem(hwndDlg, IDC_NAME_EDIT));
  1392. //SendDlgItemMessage(hwndDlg, IDC_NAME_EDIT, EM_SETSEL, 0, -1);
  1393. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
  1394. break;
  1395. }
  1396. }
  1397. if ((pExportHelper->pwszExportFileNameToCheck != NULL) &&
  1398. (pExportHelper->fNextPage == TRUE))
  1399. {
  1400. free(pExportHelper->pwszExportFileNameToCheck);
  1401. pExportHelper->pwszExportFileNameToCheck = NULL;
  1402. }
  1403. SetDlgItemTextU(hwndDlg, IDC_NAME_EDIT, pExportHelper->pwszExportFileName);
  1404. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  1405. return TRUE;
  1406. case PSN_RESET:
  1407. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  1408. break;
  1409. case PSN_SETACTIVE:
  1410. pExportHelper->fDontCheckFileName = FALSE;
  1411. if (pExportHelper->fNextPage == TRUE)
  1412. {
  1413. cch = (DWORD)SendDlgItemMessage(hwndDlg, IDC_NAME_EDIT, WM_GETTEXTLENGTH, 0, 0);
  1414. if (NULL == (pExportHelper->pwszExportFileNameToCheck = (LPWSTR) malloc((cch+1)*sizeof(WCHAR))))
  1415. {
  1416. pExportHelper->pwszExportFileNameToCheck = NULL;
  1417. }
  1418. else
  1419. {
  1420. GetDlgItemTextU(hwndDlg, IDC_NAME_EDIT, pExportHelper->pwszExportFileNameToCheck, cch+1);
  1421. }
  1422. }
  1423. if (SendDlgItemMessage(hwndDlg, IDC_NAME_EDIT, WM_GETTEXTLENGTH, 0, 0))
  1424. {
  1425. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT | PSWIZB_BACK);
  1426. }
  1427. else
  1428. {
  1429. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK);
  1430. }
  1431. break;
  1432. case PSN_WIZBACK:
  1433. if (pExportHelper->pExportInfo->dwSubjectChoice != CRYPTUI_WIZ_EXPORT_CERT_CONTEXT)
  1434. {
  1435. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_EXPORTWIZARD_WELCOME);
  1436. }
  1437. else if (!(pExportHelper->fExportPrivateKeys))
  1438. {
  1439. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_EXPORTWIZARD_FORMAT);
  1440. }
  1441. pExportHelper->fNextPage = FALSE;
  1442. break;
  1443. case PSN_WIZNEXT:
  1444. cch = (DWORD)SendDlgItemMessage(hwndDlg, IDC_NAME_EDIT, WM_GETTEXTLENGTH, 0, 0);
  1445. if (cch == 0)
  1446. {
  1447. I_MessageBox(hwndDlg, IDS_INPUT_FILENAME, IDS_EXPORT_WIZARD_TITLE, NULL, MB_OK | MB_ICONWARNING);
  1448. SetFocus(GetDlgItem(hwndDlg, IDC_NAME_EDIT));
  1449. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
  1450. break;
  1451. }
  1452. pExportHelper->fNextPage = TRUE;
  1453. break;
  1454. default:
  1455. return FALSE;
  1456. }
  1457. break;
  1458. default:
  1459. return FALSE;
  1460. }
  1461. return TRUE;
  1462. }
  1463. //////////////////////////////////////////////////////////////////////////////////////
  1464. //
  1465. //////////////////////////////////////////////////////////////////////////////////////
  1466. void DisplayUnknownError(HWND hwndDlg, UINT idsCaption, UINT idsInitialString, DWORD dwError)
  1467. {
  1468. WCHAR wszTitle[256];
  1469. WCHAR wszInitialString[512];
  1470. LPWSTR pwszFinalString = NULL;
  1471. LPWSTR pwszError = NULL;
  1472. GetUnknownErrorString(&pwszError, dwError);
  1473. if (pwszError != NULL)
  1474. {
  1475. LoadStringU(g_hmodThisDll, idsCaption, wszTitle, ARRAYSIZE(wszTitle));
  1476. LoadStringU(g_hmodThisDll, idsInitialString, wszInitialString, ARRAYSIZE(wszInitialString));
  1477. pwszFinalString = (LPWSTR) malloc((wcslen(wszInitialString) + wcslen(pwszError) + 3) * sizeof(WCHAR));
  1478. if (pwszFinalString == NULL)
  1479. {
  1480. free(pwszError);
  1481. return;
  1482. }
  1483. wcscpy(pwszFinalString, wszInitialString);
  1484. wcscat(pwszFinalString, L"\n");
  1485. wcscat(pwszFinalString, pwszError);
  1486. MessageBoxExW(hwndDlg, pwszFinalString, wszTitle, MB_OK | MB_ICONERROR, 0);
  1487. free(pwszError);
  1488. free(pwszFinalString);
  1489. }
  1490. }
  1491. //////////////////////////////////////////////////////////////////////////////////////
  1492. //
  1493. //////////////////////////////////////////////////////////////////////////////////////
  1494. static INT_PTR APIENTRY ExportCompletionPageProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  1495. {
  1496. PEXPORT_HELPER_STRUCT pExportHelper = NULL;
  1497. PROPSHEETPAGE *pPropSheet = NULL;
  1498. WCHAR szSummaryItem[MAX_STRING_SIZE];
  1499. HDC hdc = NULL;
  1500. COLORREF colorRefBack;
  1501. COLORREF colorRefText;
  1502. LV_COLUMNW lvC;
  1503. LV_ITEMW lvItem;
  1504. HWND hWndListView;
  1505. LPNMLISTVIEW pnmv;
  1506. HRESULT hr;
  1507. switch (msg)
  1508. {
  1509. case WM_INITDIALOG:
  1510. //set the wizard information so that it can be shared
  1511. pPropSheet = (PROPSHEETPAGE *) lParam;
  1512. pExportHelper = (PEXPORT_HELPER_STRUCT) (pPropSheet->lParam);
  1513. SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pExportHelper);
  1514. SetControlFont(pExportHelper->hBigBold, hwndDlg, IDC_COMPLETING_STATIC);
  1515. //
  1516. // add two columns to the summary list
  1517. //
  1518. hWndListView = GetDlgItem(hwndDlg, IDC_SUMMARY_LIST);
  1519. memset(&lvC, 0, sizeof(LV_COLUMNW));
  1520. lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  1521. lvC.fmt = LVCFMT_LEFT;
  1522. lvC.cx = 2;
  1523. lvC.pszText = L"";
  1524. lvC.iSubItem=0;
  1525. if (ListView_InsertColumnU(hWndListView, 0, &lvC) == -1)
  1526. {
  1527. return FALSE;
  1528. }
  1529. lvC.cx = 2;
  1530. lvC.iSubItem= 1;
  1531. if (ListView_InsertColumnU(hWndListView, 1, &lvC) == -1)
  1532. {
  1533. return FALSE;
  1534. }
  1535. #if (1) //DSIE: BUg 481641.
  1536. ListView_SetExtendedListViewStyle(hWndListView,
  1537. ListView_GetExtendedListViewStyle(hWndListView) | LVS_EX_FULLROWSELECT);
  1538. #endif
  1539. //
  1540. // set the background color of the summary list
  1541. //
  1542. /*if (hdc = GetWindowDC(hwndDlg))
  1543. {
  1544. if ((CLR_INVALID != (colorRefBack = GetBkColor(hdc))) &&
  1545. (CLR_INVALID != (colorRefText = GetTextColor(hdc))))
  1546. {
  1547. ListView_SetBkColor(GetDlgItem(hwndDlg, IDC_SUMMARY_LIST), CLR_NONE);
  1548. ListView_SetTextBkColor(GetDlgItem(hwndDlg, IDC_SUMMARY_LIST), CLR_NONE);
  1549. }
  1550. }*/
  1551. break;
  1552. case WM_NOTIFY:
  1553. pExportHelper = (PEXPORT_HELPER_STRUCT) GetWindowLongPtr(hwndDlg, DWLP_USER);
  1554. switch (((NMHDR FAR *) lParam)->code)
  1555. {
  1556. case PSN_QUERYCANCEL:
  1557. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  1558. pExportHelper->dwErrorCode = ERROR_CANCELLED;
  1559. return TRUE;
  1560. case PSN_KILLACTIVE:
  1561. return TRUE;
  1562. case PSN_RESET:
  1563. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  1564. break;
  1565. case PSN_SETACTIVE:
  1566. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_FINISH | PSWIZB_BACK);
  1567. hWndListView = GetDlgItem(hwndDlg, IDC_SUMMARY_LIST);
  1568. ListView_DeleteAllItems(hWndListView);
  1569. memset(&lvItem, 0, sizeof(LV_ITEMW));
  1570. lvItem.mask = LVIF_TEXT | LVIF_STATE ;
  1571. lvItem.state = 0;
  1572. lvItem.stateMask = 0;
  1573. lvItem.iItem = 0;
  1574. lvItem.iSubItem = 0;
  1575. //
  1576. // file name
  1577. //
  1578. ListView_InsertItemU_IDS(hWndListView, &lvItem, IDS_FILE_NAME, NULL);
  1579. ListView_SetItemTextU(hWndListView, lvItem.iItem, 1, pExportHelper->pwszExportFileName);
  1580. if (pExportHelper->pExportInfo->dwSubjectChoice == CRYPTUI_WIZ_EXPORT_CERT_CONTEXT)
  1581. {
  1582. //
  1583. // export keys
  1584. //
  1585. if (pExportHelper->fExportPrivateKeys)
  1586. {
  1587. LoadStringU(g_hmodThisDll, IDS_YES, szSummaryItem, ARRAYSIZE(szSummaryItem));
  1588. }
  1589. else
  1590. {
  1591. LoadStringU(g_hmodThisDll, IDS_NO, szSummaryItem, ARRAYSIZE(szSummaryItem));
  1592. }
  1593. lvItem.iItem++;
  1594. ListView_InsertItemU_IDS(hWndListView, &lvItem, IDS_EXPORT_KEYS, NULL);
  1595. ListView_SetItemTextU(hWndListView, lvItem.iItem, 1, szSummaryItem);
  1596. //
  1597. // export chain
  1598. //
  1599. if (pExportHelper->fExportChain)
  1600. {
  1601. LoadStringU(g_hmodThisDll, IDS_YES, szSummaryItem, ARRAYSIZE(szSummaryItem));
  1602. }
  1603. else
  1604. {
  1605. LoadStringU(g_hmodThisDll, IDS_NO, szSummaryItem, ARRAYSIZE(szSummaryItem));
  1606. }
  1607. lvItem.iItem++;
  1608. ListView_InsertItemU_IDS(hWndListView, &lvItem, IDS_EXPORT_CHAIN, NULL);
  1609. ListView_SetItemTextU(hWndListView, lvItem.iItem, 1, szSummaryItem);
  1610. }
  1611. //
  1612. // file format
  1613. //
  1614. switch (pExportHelper->pExportInfo->dwSubjectChoice)
  1615. {
  1616. case CRYPTUI_WIZ_EXPORT_CERT_STORE:
  1617. LoadStringU(g_hmodThisDll, IDS_MYSERIALIZED_STORE, szSummaryItem, ARRAYSIZE(szSummaryItem));
  1618. break;
  1619. case CRYPTUI_WIZ_EXPORT_CERT_STORE_CERTIFICATES_ONLY:
  1620. LoadStringU(g_hmodThisDll, IDS_PKCS7, szSummaryItem, ARRAYSIZE(szSummaryItem));
  1621. break;
  1622. case CRYPTUI_WIZ_EXPORT_CRL_CONTEXT:
  1623. LoadStringU(g_hmodThisDll, IDS_CRL, szSummaryItem, ARRAYSIZE(szSummaryItem));
  1624. break;
  1625. case CRYPTUI_WIZ_EXPORT_CTL_CONTEXT:
  1626. LoadStringU(g_hmodThisDll, IDS_CTL, szSummaryItem, ARRAYSIZE(szSummaryItem));
  1627. break;
  1628. case CRYPTUI_WIZ_EXPORT_CERT_CONTEXT:
  1629. switch (pExportHelper->dwExportFormat)
  1630. {
  1631. case CRYPTUI_WIZ_EXPORT_FORMAT_DER:
  1632. LoadStringU(g_hmodThisDll, IDS_DER, szSummaryItem, ARRAYSIZE(szSummaryItem));
  1633. break;
  1634. case CRYPTUI_WIZ_EXPORT_FORMAT_BASE64:
  1635. LoadStringU(g_hmodThisDll, IDS_BASE64, szSummaryItem, ARRAYSIZE(szSummaryItem));
  1636. break;
  1637. case CRYPTUI_WIZ_EXPORT_FORMAT_PFX:
  1638. LoadStringU(g_hmodThisDll, IDS_PFX, szSummaryItem, ARRAYSIZE(szSummaryItem));
  1639. break;
  1640. case CRYPTUI_WIZ_EXPORT_FORMAT_PKCS7:
  1641. LoadStringU(g_hmodThisDll, IDS_PKCS7, szSummaryItem, ARRAYSIZE(szSummaryItem));
  1642. break;
  1643. }
  1644. break;
  1645. }
  1646. lvItem.iItem++;
  1647. ListView_InsertItemU_IDS(hWndListView, &lvItem, IDS_FILE_FORMAT, NULL);
  1648. ListView_SetItemTextU(hWndListView, lvItem.iItem, 1, szSummaryItem);
  1649. ListView_SetColumnWidth(hWndListView, 0, LVSCW_AUTOSIZE);
  1650. ListView_SetColumnWidth(hWndListView, 1, LVSCW_AUTOSIZE);
  1651. #if (1) //DSIE: Bug 481641.
  1652. ListView_SetItemState(hWndListView,
  1653. 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  1654. #endif
  1655. break;
  1656. case PSN_WIZBACK:
  1657. break;
  1658. case PSN_WIZNEXT:
  1659. break;
  1660. case PSN_WIZFINISH:
  1661. hr = DoExport(pExportHelper);
  1662. if (hr == S_OK)
  1663. {
  1664. I_MessageBox(hwndDlg, IDS_EXPORT_SUCCESSFULL, IDS_EXPORT_WIZARD_TITLE, NULL, MB_OK);
  1665. }
  1666. else if ((hr == NTE_BAD_KEYSET) || (hr == NTE_BAD_KEY))
  1667. {
  1668. I_MessageBox(hwndDlg, IDS_EXPORT_BADKEYS, IDS_EXPORT_WIZARD_TITLE, NULL, MB_OK | MB_ICONERROR);
  1669. }
  1670. else if (hr == ERROR_UNSUPPORTED_TYPE)
  1671. {
  1672. I_MessageBox(hwndDlg, IDS_EXPORT_UNSUPPORTED, IDS_EXPORT_WIZARD_TITLE, NULL, MB_OK | MB_ICONERROR);
  1673. }
  1674. else
  1675. {
  1676. DisplayUnknownError(hwndDlg, IDS_EXPORT_WIZARD_TITLE, IDS_EXPORT_FAILED, (DWORD)hr);
  1677. }
  1678. break;
  1679. #if (0) //DSIE: Bug 481641.
  1680. case LVN_ITEMCHANGING:
  1681. pnmv = (LPNMLISTVIEW) lParam;
  1682. if (pnmv->uNewState & LVIS_SELECTED)
  1683. {
  1684. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
  1685. ListView_SetItemState(pnmv->hdr.hwndFrom, 0, LVIS_FOCUSED, LVIS_FOCUSED);
  1686. }
  1687. return TRUE;
  1688. #endif
  1689. default:
  1690. return FALSE;
  1691. }
  1692. break;
  1693. default:
  1694. return FALSE;
  1695. }
  1696. return TRUE;
  1697. }
  1698. //////////////////////////////////////////////////////////////////////////////////////
  1699. //
  1700. //////////////////////////////////////////////////////////////////////////////////////
  1701. static BOOL CheckPrivateKeysExist(PCCRYPTUI_WIZ_EXPORT_INFO pExportInfo)
  1702. {
  1703. DWORD cbData = 0;
  1704. if (pExportInfo->dwSubjectChoice == CRYPTUI_WIZ_EXPORT_CERT_CONTEXT)
  1705. {
  1706. if (CertGetCertificateContextProperty(pExportInfo->pCertContext, CERT_KEY_PROV_INFO_PROP_ID, NULL, &cbData))
  1707. {
  1708. return TRUE;
  1709. }
  1710. }
  1711. return FALSE;
  1712. }
  1713. //////////////////////////////////////////////////////////////////////////////////////
  1714. //
  1715. //////////////////////////////////////////////////////////////////////////////////////
  1716. static DWORD CheckPrivateKeyStatus(PCCRYPTUI_WIZ_EXPORT_INFO pExportInfo)
  1717. {
  1718. HCRYPTPROV hCryptProv = NULL;
  1719. DWORD dwKeySpec = 0;
  1720. BOOL fCallerFreeProv = FALSE;
  1721. BOOL dwRet = PRIVATE_KEY_UNKNOWN_STATE;
  1722. HCRYPTKEY hKey = NULL;
  1723. DWORD dwPermissions = 0;
  1724. DWORD dwSize = 0;
  1725. if (pExportInfo->dwSubjectChoice == CRYPTUI_WIZ_EXPORT_CERT_CONTEXT)
  1726. {
  1727. //
  1728. // first get the private key context
  1729. //
  1730. if (!CryptAcquireCertificatePrivateKey(
  1731. pExportInfo->pCertContext,
  1732. CRYPT_ACQUIRE_USE_PROV_INFO_FLAG | CRYPT_ACQUIRE_COMPARE_KEY_FLAG,
  1733. NULL,
  1734. &hCryptProv,
  1735. &dwKeySpec,
  1736. &fCallerFreeProv))
  1737. {
  1738. DWORD dw = GetLastError();
  1739. dwRet = PRIVATE_KEY_CORRUPT;
  1740. goto ErrorReturn;
  1741. }
  1742. //
  1743. // get the handle to the key
  1744. //
  1745. if (!CryptGetUserKey(hCryptProv, dwKeySpec, &hKey))
  1746. {
  1747. dwRet = PRIVATE_KEY_CORRUPT;
  1748. goto ErrorReturn;
  1749. }
  1750. //
  1751. // finally, get the permissions on the key and check if it is exportable
  1752. //
  1753. dwSize = sizeof(dwPermissions);
  1754. if (!CryptGetKeyParam(hKey, KP_PERMISSIONS, (PBYTE)&dwPermissions, &dwSize, 0))
  1755. {
  1756. goto ErrorReturn;
  1757. }
  1758. dwRet = (dwPermissions & CRYPT_EXPORT) ? PRIVATE_KEY_EXPORTABLE : PRIVATE_KEY_NOT_EXPORTABLE;
  1759. }
  1760. CleanUp:
  1761. if (hKey != NULL)
  1762. {
  1763. CryptDestroyKey(hKey);
  1764. }
  1765. if (fCallerFreeProv)
  1766. {
  1767. CryptReleaseContext(hCryptProv, 0);
  1768. }
  1769. return dwRet;
  1770. ErrorReturn:
  1771. goto CleanUp;
  1772. }
  1773. //////////////////////////////////////////////////////////////////////////////////////
  1774. //
  1775. //////////////////////////////////////////////////////////////////////////////////////
  1776. BOOL
  1777. WINAPI
  1778. CryptUIWizExport(
  1779. DWORD dwFlags,
  1780. HWND hwndParent,
  1781. LPCWSTR pwszWizardTitle,
  1782. PCCRYPTUI_WIZ_EXPORT_INFO pExportInfo,
  1783. void *pvoid
  1784. )
  1785. {
  1786. EXPORT_HELPER_STRUCT ExportHelper;
  1787. PROPSHEETPAGEW rgPropSheets[EXPORT_PAGE_NUM];
  1788. PROPSHEETHEADERW PropSheetHeader;
  1789. int i;
  1790. WCHAR szTitle[MAX_TITLE_LENGTH];
  1791. BOOL fRet = FALSE;
  1792. HRESULT hr;
  1793. //
  1794. // make sure if UI less option is set, all required information is provided
  1795. //
  1796. if (dwFlags & CRYPTUI_WIZ_NO_UI)
  1797. {
  1798. if (!Validpvoid(pExportInfo, pvoid))
  1799. {
  1800. SetLastError(E_INVALIDARG);
  1801. return FALSE;
  1802. }
  1803. }
  1804. memset(&ExportHelper, 0, sizeof(ExportHelper));
  1805. ExportHelper.pExportInfo = pExportInfo;
  1806. if (pExportInfo->dwSubjectChoice == CRYPTUI_WIZ_EXPORT_CERT_CONTEXT)
  1807. {
  1808. ExportHelper.pExportCertInfo = (PCCRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO) pvoid;
  1809. }
  1810. //
  1811. // if this is UI less then just copy over the pExportCertInfo and do the export
  1812. //
  1813. if (dwFlags & CRYPTUI_WIZ_NO_UI)
  1814. {
  1815. // BOOL fRet2 = FALSE;
  1816. if (NULL == (ExportHelper.pwszExportFileName = AllocAndCopyWStr(pExportInfo->pwszExportFileName)))
  1817. {
  1818. return FALSE;
  1819. }
  1820. ExportHelper.dwExportFormat = ExportHelper.pExportCertInfo->dwExportFormat;
  1821. ExportHelper.fExportChain = ExportHelper.pExportCertInfo->fExportChain;
  1822. ExportHelper.fExportPrivateKeys = ExportHelper.pExportCertInfo->fExportPrivateKeys;
  1823. if (ExportHelper.fExportPrivateKeys)
  1824. {
  1825. if (ExportHelper.pExportCertInfo->pwszPassword != NULL)
  1826. {
  1827. ExportHelper.pwszPassword = AllocAndCopyWStr(ExportHelper.pExportCertInfo->pwszPassword);
  1828. }
  1829. else
  1830. {
  1831. ExportHelper.pwszPassword = NULL;
  1832. }
  1833. }
  1834. if (offsetof(CRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO, fStrongEncryption) < ExportHelper.pExportCertInfo->dwSize)
  1835. {
  1836. ExportHelper.fStrongEncryption = ExportHelper.pExportCertInfo->fStrongEncryption;
  1837. }
  1838. hr = DoExport(&ExportHelper);
  1839. free(ExportHelper.pwszExportFileName);
  1840. if (ExportHelper.fExportPrivateKeys)
  1841. {
  1842. if (ExportHelper.pwszPassword != NULL)
  1843. {
  1844. // memset the password to zero so that it is not around in memory
  1845. SecureZeroMemory(ExportHelper.pwszPassword, wcslen(ExportHelper.pwszPassword)*sizeof(WCHAR));
  1846. free(ExportHelper.pwszPassword);
  1847. }
  1848. }
  1849. if (hr != S_OK)
  1850. {
  1851. SetLastError(hr);
  1852. return FALSE;
  1853. }
  1854. else
  1855. {
  1856. return TRUE;
  1857. }
  1858. }
  1859. //
  1860. //set up the fonts
  1861. //
  1862. if(!SetupFonts(g_hmodThisDll, NULL, &(ExportHelper.hBigBold), &(ExportHelper.hBold)))
  1863. {
  1864. return FALSE;
  1865. }
  1866. //
  1867. // init the common controls
  1868. //
  1869. WizardInit(TRUE);
  1870. //
  1871. // check to see if private keys exist, and whether it is exportable (only for exporting cert contexts)
  1872. //
  1873. ExportHelper.fPrivateKeysExist = CheckPrivateKeysExist(pExportInfo);
  1874. if (ExportHelper.fPrivateKeysExist)
  1875. {
  1876. ExportHelper.dwExportablePrivateKeyStatus = CheckPrivateKeyStatus(pExportInfo);
  1877. }
  1878. ExportHelper.fStrongEncryption = TRUE;
  1879. #if (1) //DSIE: DCR bug 531006.
  1880. //
  1881. // Check to see if export flag is set?
  1882. //
  1883. if (CRYPTUI_WIZ_EXPORT_PRIVATE_KEY & dwFlags)
  1884. {
  1885. if (!ExportHelper.fPrivateKeysExist)
  1886. {
  1887. SetLastError(NTE_NO_KEY);
  1888. return FALSE;
  1889. }
  1890. if (PRIVATE_KEY_EXPORTABLE != ExportHelper.dwExportablePrivateKeyStatus)
  1891. {
  1892. SetLastError(NTE_BAD_KEY_STATE);
  1893. return FALSE;
  1894. }
  1895. ExportHelper.fExportPrivateKeys = TRUE;
  1896. }
  1897. //
  1898. // Store flags.
  1899. //
  1900. ExportHelper.dwFlags = dwFlags;
  1901. #endif
  1902. //
  1903. // set up the property pages structures
  1904. //
  1905. memset(rgPropSheets, 0, sizeof(rgPropSheets));
  1906. for (i=0; i<EXPORT_PAGE_NUM; i++)
  1907. {
  1908. rgPropSheets[i].dwSize = sizeof(rgPropSheets[0]);
  1909. rgPropSheets[i].hInstance = g_hmodThisDll;
  1910. rgPropSheets[i].lParam = (LPARAM) &ExportHelper;
  1911. }
  1912. rgPropSheets[0].pszTemplate = (LPWSTR) MAKEINTRESOURCE(IDD_EXPORTWIZARD_WELCOME);
  1913. rgPropSheets[0].pfnDlgProc = ExportWelcomePageProc;
  1914. rgPropSheets[1].pszTemplate = (LPWSTR) MAKEINTRESOURCE(IDD_EXPORTWIZARD_PRIVATEKEYS);
  1915. rgPropSheets[1].pfnDlgProc = ExportPrivateKeysPageProc;
  1916. rgPropSheets[2].pszTemplate = (LPWSTR) MAKEINTRESOURCE(IDD_EXPORTWIZARD_FORMAT);
  1917. rgPropSheets[2].pfnDlgProc = ExportFormatPageProc;
  1918. rgPropSheets[3].pszTemplate = (LPWSTR) MAKEINTRESOURCE(IDD_EXPORTWIZARD_PASSWORD);
  1919. rgPropSheets[3].pfnDlgProc = ExportPasswordPageProc;
  1920. rgPropSheets[4].pszTemplate = (LPWSTR) MAKEINTRESOURCE(IDD_EXPORTWIZARD_FILENAME);
  1921. rgPropSheets[4].pfnDlgProc = ExportFileNamePageProc;
  1922. rgPropSheets[5].pszTemplate = (LPWSTR) MAKEINTRESOURCE(IDD_EXPORTWIZARD_COMPLETION);
  1923. rgPropSheets[5].pfnDlgProc = ExportCompletionPageProc;
  1924. //
  1925. // set up the property sheet header
  1926. //
  1927. memset(&PropSheetHeader, 0, sizeof(PropSheetHeader));
  1928. PropSheetHeader.dwSize = sizeof(PropSheetHeader);
  1929. PropSheetHeader.dwFlags = PSH_PROPSHEETPAGE | PSH_WIZARD | PSH_NOAPPLYNOW;
  1930. PropSheetHeader.hwndParent = hwndParent;
  1931. PropSheetHeader.hInstance = g_hmodThisDll;
  1932. if (pwszWizardTitle != NULL)
  1933. PropSheetHeader.pszCaption = pwszWizardTitle;
  1934. else
  1935. {
  1936. if(LoadStringU(g_hmodThisDll, IDS_EXPORT_WIZARD_TITLE, szTitle, sizeof(szTitle)/sizeof(szTitle[0])))
  1937. {
  1938. PropSheetHeader.pszCaption = szTitle;
  1939. }
  1940. }
  1941. PropSheetHeader.nPages = EXPORT_PAGE_NUM;
  1942. PropSheetHeader.nStartPage = 0;
  1943. PropSheetHeader.ppsp = rgPropSheets;
  1944. fRet = (PropertySheetU(&PropSheetHeader) != 0);
  1945. #if (1) // DSIE: Bug 664006.
  1946. if (NULL != ExportHelper.pwszPassword)
  1947. {
  1948. // memset the password to zero so that it is not around in memory
  1949. SecureZeroMemory(ExportHelper.pwszPassword, wcslen(ExportHelper.pwszPassword)*sizeof(WCHAR));
  1950. free(ExportHelper.pwszPassword);
  1951. }
  1952. if (NULL != ExportHelper.pwszExportFileName)
  1953. {
  1954. free(ExportHelper.pwszExportFileName);
  1955. }
  1956. #endif
  1957. DestroyFonts(ExportHelper.hBigBold, ExportHelper.hBold);
  1958. if (0 != ExportHelper.dwErrorCode)
  1959. {
  1960. SetLastError(ExportHelper.dwErrorCode);
  1961. }
  1962. return fRet;
  1963. }