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.

964 lines
29 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: viewsigs.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "global.hxx"
  11. #include <dbgdef.h>
  12. extern HINSTANCE HinstDll;
  13. extern HMODULE HmodRichEdit;
  14. static const HELPMAP helpmap[] = {
  15. {IDC_SIGNATURES_SIG_LIST, IDH_DIGSIG_PROPSHEET_LIST},
  16. {IDC_SIGNATURES_DETAILS_BUTTON, IDH_DIGSIG_PROPSHEET_DETAIL}
  17. };
  18. //////////////////////////////////////////////////////////////////////////////////////
  19. //
  20. //////////////////////////////////////////////////////////////////////////////////////
  21. static PCRYPTUI_VIEWSIGNATURES_STRUCTW AllocAndCopyViewSignaturesStruct(PCCRYPTUI_VIEWSIGNATURES_STRUCTW pcvs)
  22. {
  23. PCRYPTUI_VIEWSIGNATURES_STRUCTW pStruct;
  24. DWORD i;
  25. if (NULL == (pStruct = (PCRYPTUI_VIEWSIGNATURES_STRUCTW) malloc(sizeof(CRYPTUI_VIEWSIGNATURES_STRUCTW))))
  26. {
  27. return NULL;
  28. }
  29. memcpy(pStruct, pcvs, sizeof(CRYPTUI_VIEWSIGNATURES_STRUCTW));
  30. if (pcvs->szFileName != NULL)
  31. {
  32. if (NULL == (pStruct->szFileName = AllocAndCopyWStr((LPWSTR) pcvs->szFileName)))
  33. {
  34. free(pStruct);
  35. return NULL;
  36. }
  37. }
  38. if (NULL == (pStruct->rghStores = (HCERTSTORE *) malloc(sizeof(HCERTSTORE)*pcvs->cStores)))
  39. {
  40. if (pStruct->szFileName)
  41. {
  42. free((void *) pStruct->szFileName);
  43. }
  44. free(pStruct);
  45. return NULL;
  46. }
  47. if (pcvs->choice == EncodedMessage_Chosen)
  48. {
  49. if (NULL == (pStruct->u.EncodedMessage.pbData = (BYTE *) malloc(pcvs->u.EncodedMessage.cbData)))
  50. {
  51. free(pStruct->rghStores);
  52. if (pStruct->szFileName)
  53. {
  54. free((void *) pStruct->szFileName);
  55. }
  56. free(pStruct);
  57. return NULL;
  58. }
  59. memcpy(
  60. pStruct->u.EncodedMessage.pbData,
  61. pcvs->u.EncodedMessage.pbData,
  62. pcvs->u.EncodedMessage.cbData);
  63. }
  64. else
  65. {
  66. pStruct->u.hMsg = CryptMsgDuplicate(pcvs->u.hMsg);
  67. }
  68. pStruct->cPropSheetPages = 0;
  69. pStruct->rgPropSheetPages = NULL;
  70. for (i=0; i<pcvs->cStores; i++)
  71. {
  72. pStruct->rghStores[i] = CertDuplicateStore(pcvs->rghStores[i]);
  73. }
  74. return pStruct;
  75. }
  76. //////////////////////////////////////////////////////////////////////////////////////
  77. //
  78. //////////////////////////////////////////////////////////////////////////////////////
  79. static void FreeViewSignaturesStruct(PCRYPTUI_VIEWSIGNATURES_STRUCTW pcvs)
  80. {
  81. DWORD i;
  82. if (pcvs->choice == EncodedMessage_Chosen)
  83. {
  84. free(pcvs->u.EncodedMessage.pbData);
  85. }
  86. else
  87. {
  88. CryptMsgClose(pcvs->u.hMsg);
  89. }
  90. if (pcvs->szFileName)
  91. {
  92. free((void *) pcvs->szFileName);
  93. }
  94. for (i=0; i<pcvs->cStores; i++)
  95. {
  96. CertCloseStore(pcvs->rghStores[i], 0);
  97. }
  98. free(pcvs->rghStores);
  99. free(pcvs);
  100. }
  101. //////////////////////////////////////////////////////////////////////////////////////
  102. //
  103. //////////////////////////////////////////////////////////////////////////////////////
  104. static PCMSG_SIGNER_INFO GetSignerInfo(HCRYPTMSG hMsg, DWORD index)
  105. {
  106. DWORD cbEncodedSigner = 0;
  107. BYTE *pbEncodedSigner = NULL;
  108. PCMSG_SIGNER_INFO pSignerInfo = NULL;
  109. DWORD cbSignerInfo = 0;
  110. //
  111. // get the encoded signer BLOB
  112. //
  113. CryptMsgGetParam(hMsg,
  114. CMSG_ENCODED_SIGNER,
  115. index,
  116. NULL,
  117. &cbEncodedSigner);
  118. if (cbEncodedSigner == 0)
  119. {
  120. return NULL;
  121. }
  122. if (NULL == (pbEncodedSigner = (PBYTE) malloc(cbEncodedSigner)))
  123. {
  124. return NULL;
  125. }
  126. if (!CryptMsgGetParam(hMsg,
  127. CMSG_ENCODED_SIGNER,
  128. index,
  129. pbEncodedSigner,
  130. &cbEncodedSigner))
  131. {
  132. free(pbEncodedSigner);
  133. return NULL;
  134. }
  135. //
  136. // decode the EncodedSigner info
  137. //
  138. if(!CryptDecodeObject(PKCS_7_ASN_ENCODING|CRYPT_ASN_ENCODING,
  139. PKCS7_SIGNER_INFO,
  140. pbEncodedSigner,
  141. cbEncodedSigner,
  142. 0,
  143. NULL,
  144. &cbSignerInfo))
  145. {
  146. free(pbEncodedSigner);
  147. return NULL;
  148. }
  149. if (NULL == (pSignerInfo = (PCMSG_SIGNER_INFO) malloc(cbSignerInfo)))
  150. {
  151. free(pbEncodedSigner);
  152. return NULL;
  153. }
  154. if (!CryptDecodeObject(PKCS_7_ASN_ENCODING|CRYPT_ASN_ENCODING,
  155. PKCS7_SIGNER_INFO,
  156. pbEncodedSigner,
  157. cbEncodedSigner,
  158. 0,
  159. pSignerInfo,
  160. &cbSignerInfo))
  161. {
  162. free(pbEncodedSigner);
  163. free(pSignerInfo);
  164. return NULL;
  165. }
  166. free(pbEncodedSigner);
  167. return(pSignerInfo);
  168. }
  169. //////////////////////////////////////////////////////////////////////////////////////
  170. //
  171. //////////////////////////////////////////////////////////////////////////////////////
  172. static void DisplaySignatures(HWND hWndListView, PCERT_VIEWSIGNATURES_HELPER pviewhelp)
  173. {
  174. PCMSG_SIGNER_INFO pSignerInfo;
  175. DWORD cbCounterSignerInfo;
  176. PCCERT_CONTEXT pCertContext = NULL;
  177. DWORD i;
  178. WCHAR szNameText[CRYPTUI_MAX_STRING_SIZE];
  179. WCHAR szEmailText[CRYPTUI_MAX_STRING_SIZE];
  180. LV_ITEMW lvI;
  181. int itemIndex = 0;
  182. LPWSTR pszTimeText;
  183. HCRYPTMSG hMsg;
  184. //
  185. // set up the fields in the list view item struct that don't change from item to item
  186. //
  187. memset(&lvI, 0, sizeof(lvI));
  188. lvI.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
  189. lvI.state = 0;
  190. lvI.stateMask = 0;
  191. lvI.pszText = szNameText;
  192. //
  193. // If the encoded message was passed in the use CryptMsg to crack the encoded PKCS7 Signed Message
  194. //
  195. if (pviewhelp->pcvs->choice == EncodedMessage_Chosen)
  196. {
  197. if (!(hMsg = CryptMsgOpenToDecode(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  198. 0,
  199. 0,
  200. 0,
  201. NULL,
  202. NULL)))
  203. {
  204. return;
  205. }
  206. if (!CryptMsgUpdate(hMsg,
  207. pviewhelp->pcvs->u.EncodedMessage.pbData,
  208. pviewhelp->pcvs->u.EncodedMessage.cbData,
  209. TRUE)) // fFinal
  210. {
  211. CryptMsgClose(hMsg);
  212. return;
  213. }
  214. }
  215. else
  216. {
  217. hMsg = pviewhelp->pcvs->u.hMsg;
  218. }
  219. //
  220. // get the signer info struct for each signer
  221. //
  222. i = 0;
  223. while (NULL != (pSignerInfo = GetSignerInfo(hMsg, i++)))
  224. {
  225. //
  226. // find the signers cert
  227. //
  228. pCertContext = GetSignersCert(
  229. pSignerInfo,
  230. pviewhelp->hExtraStore,
  231. pviewhelp->pcvs->cStores,
  232. pviewhelp->pcvs->rghStores);
  233. //
  234. // get the signers name
  235. //
  236. if (!(pCertContext && CertGetNameStringW(
  237. pCertContext,
  238. CERT_NAME_SIMPLE_DISPLAY_TYPE,
  239. 0,//CERT_NAME_ISSUER_FLAG,
  240. NULL,
  241. szNameText,
  242. ARRAYSIZE(szNameText))))
  243. {
  244. LoadStringU(HinstDll, IDS_NOTAVAILABLE, szNameText, ARRAYSIZE(szNameText));
  245. }
  246. //
  247. // get the signers email
  248. //
  249. if (!(pCertContext && (CertGetNameStringW(
  250. pCertContext,
  251. CERT_NAME_EMAIL_TYPE,
  252. 0,//CERT_NAME_ISSUER_FLAG,
  253. NULL,
  254. szEmailText,
  255. ARRAYSIZE(szEmailText)) != 1)))
  256. {
  257. LoadStringU(HinstDll, IDS_NOTAVAILABLE, szEmailText, ARRAYSIZE(szEmailText));
  258. }
  259. pszTimeText = AllocAndReturnTimeStampersTimes(pSignerInfo, NULL, hWndListView);
  260. //
  261. // add the item to the list view
  262. //
  263. lvI.iSubItem = 0;
  264. lvI.cchTextMax = wcslen(szNameText);
  265. lvI.lParam = (LPARAM) pSignerInfo;
  266. lvI.iItem = itemIndex++;
  267. ListView_InsertItemU(hWndListView, &lvI);
  268. ListView_SetItemTextU(hWndListView, itemIndex-1 , 1, szEmailText);
  269. if (pszTimeText != NULL)
  270. {
  271. ListView_SetItemTextU(hWndListView, itemIndex-1 , 2, pszTimeText);
  272. free(pszTimeText);
  273. }
  274. else
  275. {
  276. LoadStringU(HinstDll, IDS_NOTAVAILABLE, szEmailText, ARRAYSIZE(szEmailText));
  277. ListView_SetItemTextU(hWndListView, itemIndex-1 , 2, szEmailText);
  278. }
  279. }
  280. if (pviewhelp->pcvs->choice == EncodedMessage_Chosen)
  281. {
  282. CryptMsgClose(hMsg);
  283. }
  284. }
  285. //////////////////////////////////////////////////////////////////////////////////////
  286. //
  287. //////////////////////////////////////////////////////////////////////////////////////
  288. BOOL fUseCTLSigning(PCERT_VIEWSIGNATURES_HELPER pviewhelp)
  289. {
  290. BOOL fCTL = FALSE;
  291. CERT_BLOB blob;
  292. PCCTL_CONTEXT pCTLContext=NULL;
  293. if (pviewhelp->pcvs->choice == EncodedMessage_Chosen)
  294. {
  295. blob.cbData = pviewhelp->pcvs->u.EncodedMessage.cbData;
  296. blob.pbData = pviewhelp->pcvs->u.EncodedMessage.pbData;
  297. if (CryptQueryObject(
  298. CERT_QUERY_OBJECT_BLOB,
  299. &blob,
  300. CERT_QUERY_CONTENT_FLAG_CTL,
  301. CERT_QUERY_FORMAT_FLAG_ALL,
  302. 0,
  303. NULL,
  304. NULL,
  305. NULL,
  306. NULL,
  307. NULL,
  308. (const void **)&pCTLContext) &&
  309. !fIsCatalogFile(&(pCTLContext->pCtlInfo->SubjectUsage)))
  310. {
  311. fCTL = TRUE;
  312. }
  313. }
  314. else
  315. {
  316. if (CryptQueryObject(
  317. CERT_QUERY_OBJECT_FILE,
  318. pviewhelp->pcvs->szFileName,
  319. CERT_QUERY_CONTENT_FLAG_CTL,
  320. CERT_QUERY_FORMAT_FLAG_ALL,
  321. 0,
  322. NULL,
  323. NULL,
  324. NULL,
  325. NULL,
  326. NULL,
  327. (const void **)&pCTLContext) &&
  328. !fIsCatalogFile(&(pCTLContext->pCtlInfo->SubjectUsage)))
  329. {
  330. fCTL = TRUE;
  331. }
  332. }
  333. if(pCTLContext)
  334. {
  335. CertFreeCTLContext(pCTLContext);
  336. }
  337. return fCTL;
  338. }
  339. //////////////////////////////////////////////////////////////////////////////////////
  340. //
  341. //////////////////////////////////////////////////////////////////////////////////////
  342. INT_PTR APIENTRY ViewPageViewSignatures(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  343. {
  344. PROPSHEETPAGE * ps;
  345. PCRYPTUI_VIEWSIGNATURES_STRUCTW pcvs = NULL;
  346. HWND hWndListView;
  347. LV_COLUMNW lvC;
  348. LPNMLISTVIEW pnmv;
  349. PCERT_VIEWSIGNATURES_HELPER pviewhelp;
  350. WCHAR szText[CRYPTUI_MAX_STRING_SIZE];
  351. int listIndex;
  352. LV_ITEMW lvI;
  353. DWORD i;
  354. HWND hwnd;
  355. switch ( msg ) {
  356. case WM_INITDIALOG:
  357. //
  358. // save the pviewhelp struct in DWLP_USER so it can always be accessed
  359. //
  360. ps = (PROPSHEETPAGE *) lParam;
  361. pviewhelp = (PCERT_VIEWSIGNATURES_HELPER) ps->lParam;
  362. pcvs = (PCRYPTUI_VIEWSIGNATURES_STRUCTW) pviewhelp->pcvs;
  363. SetWindowLongPtr(hwndDlg, DWLP_USER, (DWORD_PTR) pviewhelp);
  364. //
  365. // initially nothing is selected, so disable the details button
  366. //
  367. EnableWindow(GetDlgItem(hwndDlg, IDC_SIGNATURES_DETAILS_BUTTON), FALSE);
  368. //
  369. // get the handle of the list view control
  370. //
  371. hWndListView = GetDlgItem(hwndDlg, IDC_SIGNATURES_SIG_LIST);
  372. //
  373. // initialize the columns in the list view
  374. //
  375. lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  376. lvC.fmt = LVCFMT_LEFT; // Left-align the column.
  377. lvC.pszText = szText; // The text for the column.
  378. lvC.iSubItem = 0;
  379. // Add the columns. They are loaded from a string table.
  380. lvC.cx = 100;
  381. LoadStringU(HinstDll, IDS_NAME, szText, ARRAYSIZE(szText));
  382. if (ListView_InsertColumnU(hWndListView, 0, &lvC) == -1)
  383. {
  384. // error
  385. }
  386. lvC.cx = 100;
  387. LoadStringU(HinstDll, IDS_EMAIL, szText, ARRAYSIZE(szText));
  388. if (ListView_InsertColumnU(hWndListView, 1, &lvC) == -1)
  389. {
  390. // error
  391. }
  392. lvC.cx = 125;
  393. LoadStringU(HinstDll, IDS_TIMESTAMP_TIME, szText, ARRAYSIZE(szText));
  394. if (ListView_InsertColumnU(hWndListView, 2, &lvC) == -1)
  395. {
  396. // error
  397. }
  398. //
  399. // set the style in the list view so that it highlights an entire line
  400. //
  401. SendMessageA(hWndListView, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
  402. DisplaySignatures(hWndListView, pviewhelp);
  403. return TRUE;
  404. case WM_NOTIFY:
  405. pviewhelp = (PCERT_VIEWSIGNATURES_HELPER) GetWindowLongPtr(hwndDlg, DWLP_USER);
  406. pcvs = (PCRYPTUI_VIEWSIGNATURES_STRUCTW) pviewhelp->pcvs;
  407. switch (((NMHDR FAR *) lParam)->code)
  408. {
  409. case PSN_SETACTIVE:
  410. break;
  411. case PSN_APPLY:
  412. break;
  413. case PSN_KILLACTIVE:
  414. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)FALSE);
  415. return TRUE;
  416. case PSN_RESET:
  417. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)FALSE);
  418. break;
  419. case PSN_HELP:
  420. if (FIsWin95) {
  421. //WinHelpA(hwndDlg, (LPSTR) pcvs->szHelpFileName,
  422. // HELP_CONTEXT, pcvs->dwHelpId);
  423. }
  424. else {
  425. //WinHelpW(hwndDlg, pcvs->szHelpFileName, HELP_CONTEXT,
  426. // pcvs->dwHelpId);
  427. }
  428. return TRUE;
  429. case NM_DBLCLK:
  430. switch (((NMHDR FAR *) lParam)->idFrom)
  431. {
  432. case IDC_SIGNATURES_SIG_LIST:
  433. if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_SIGNATURES_DETAILS_BUTTON)))
  434. {
  435. SendMessage(
  436. hwndDlg,
  437. WM_COMMAND,
  438. MAKELONG(IDC_SIGNATURES_DETAILS_BUTTON, BN_CLICKED),
  439. (LPARAM) GetDlgItem(hwndDlg, IDC_SIGNATURES_DETAILS_BUTTON));
  440. }
  441. break;
  442. }
  443. break;
  444. case LVN_ITEMCHANGED:
  445. if ((((NMHDR FAR *) lParam)->idFrom) != IDC_SIGNATURES_SIG_LIST)
  446. {
  447. break;
  448. }
  449. //
  450. // if an item is selected, then enable the details button, otherwise
  451. // disable it
  452. //
  453. EnableWindow(
  454. GetDlgItem(hwndDlg, IDC_SIGNATURES_DETAILS_BUTTON),
  455. (ListView_GetSelectedCount(
  456. GetDlgItem(hwndDlg,IDC_SIGNATURES_SIG_LIST)) == 0) ? FALSE : TRUE);
  457. break;
  458. case NM_CLICK:
  459. if ((((NMHDR FAR *) lParam)->idFrom) != IDC_SIGNATURES_SIG_LIST)
  460. {
  461. break;
  462. }
  463. hWndListView = GetDlgItem(hwndDlg, IDC_SIGNATURES_SIG_LIST);
  464. //
  465. // make sure something is selected by getting the current selection
  466. //
  467. listIndex = ListView_GetNextItem(
  468. hWndListView,
  469. -1,
  470. LVNI_SELECTED
  471. );
  472. break;
  473. case NM_SETFOCUS:
  474. switch (((NMHDR FAR *) lParam)->idFrom)
  475. {
  476. case IDC_SIGNATURES_SIG_LIST:
  477. hWndListView = GetDlgItem(hwndDlg, IDC_SIGNATURES_SIG_LIST);
  478. if ((ListView_GetItemCount(hWndListView) != 0) &&
  479. (ListView_GetNextItem(hWndListView, -1, LVNI_SELECTED) == -1))
  480. {
  481. memset(&lvI, 0, sizeof(lvI));
  482. lvI.mask = LVIF_STATE;
  483. lvI.iItem = 0;
  484. lvI.state = LVIS_FOCUSED;
  485. lvI.stateMask = LVIS_FOCUSED;
  486. ListView_SetItem(hWndListView, &lvI);
  487. }
  488. break;
  489. }
  490. break;
  491. }
  492. break;
  493. case WM_COMMAND:
  494. pviewhelp = (PCERT_VIEWSIGNATURES_HELPER) GetWindowLongPtr(hwndDlg, DWLP_USER);
  495. pcvs = (PCRYPTUI_VIEWSIGNATURES_STRUCTW) pviewhelp->pcvs;
  496. switch (LOWORD(wParam))
  497. {
  498. case IDHELP:
  499. if (FIsWin95)
  500. {
  501. //WinHelpA(hwndDlg, (LPSTR) pcvs->szHelpFileName,
  502. // HELP_CONTEXT, pcvs->dwHelpId);
  503. }
  504. else
  505. {
  506. //WinHelpW(hwndDlg, pcvs->szHelpFileName, HELP_CONTEXT,
  507. // pcvs->dwHelpId);
  508. }
  509. return TRUE;
  510. case IDC_SIGNATURES_DETAILS_BUTTON:
  511. if (HIWORD(wParam) == BN_CLICKED)
  512. {
  513. CRYPTUI_VIEWSIGNERINFO_STRUCTW cvsi;
  514. CERT_VIEWSIGNERINFO_PRIVATE cvsiPrivate;
  515. CRYPT_PROVIDER_DEFUSAGE cryptProviderDefUsage;
  516. WINTRUST_DATA WTD;
  517. //BOOL fDefault;
  518. HCRYPTMSG hMsg;
  519. hWndListView = GetDlgItem(hwndDlg, IDC_SIGNATURES_SIG_LIST);
  520. //
  521. // get the selected item and its lParam which is a signer info
  522. //
  523. listIndex = ListView_GetNextItem(
  524. hWndListView,
  525. -1,
  526. LVNI_SELECTED
  527. );
  528. memset(&lvI, 0, sizeof(lvI));
  529. lvI.iItem = listIndex;
  530. lvI.mask = LVIF_PARAM;
  531. if (!ListView_GetItemU(hWndListView, &lvI))
  532. {
  533. return FALSE;
  534. }
  535. //
  536. // If the encoded message was passed in the use CryptMsg to crack the encoded PKCS7 Signed Message
  537. //
  538. if (pviewhelp->pcvs->choice == EncodedMessage_Chosen)
  539. {
  540. if (!(hMsg = CryptMsgOpenToDecode(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  541. 0,
  542. 0,
  543. 0,
  544. NULL,
  545. NULL)))
  546. {
  547. return TRUE;
  548. }
  549. if (!CryptMsgUpdate(hMsg,
  550. pviewhelp->pcvs->u.EncodedMessage.pbData,
  551. pviewhelp->pcvs->u.EncodedMessage.cbData,
  552. TRUE)) // fFinal
  553. {
  554. CryptMsgClose(hMsg);
  555. return TRUE;
  556. }
  557. }
  558. else
  559. {
  560. hMsg = pviewhelp->pcvs->u.hMsg;
  561. }
  562. memset(&cvsi, 0, sizeof(cvsi));
  563. cvsi.dwSize = sizeof(cvsi);
  564. cvsi.pSignerInfo = (PCMSG_SIGNER_INFO) lvI.lParam;
  565. cvsi.hwndParent = hwndDlg;
  566. cvsi.hMsg = hMsg;
  567. cvsi.pszOID = fUseCTLSigning(pviewhelp) ? szOID_KP_CTL_USAGE_SIGNING : szOID_PKIX_KP_CODE_SIGNING;
  568. cvsi.cStores = pcvs->cStores;
  569. cvsi.rghStores = pcvs->rghStores;
  570. //
  571. // if there was a file name passed in then fill out the
  572. // information in the private struct about which signer to display
  573. //
  574. if (pcvs->szFileName != NULL)
  575. {
  576. BuildWinVTrustState(
  577. pcvs->szFileName,
  578. NULL,
  579. 0,
  580. NULL,
  581. fUseCTLSigning(pviewhelp) ? szOID_KP_CTL_USAGE_SIGNING : szOID_PKIX_KP_CODE_SIGNING,
  582. &cvsiPrivate,
  583. &cryptProviderDefUsage,
  584. &WTD);//,
  585. //&fDefault);
  586. cvsiPrivate.idxSigner = listIndex;
  587. cvsiPrivate.fCounterSigner = FALSE;
  588. cvsiPrivate.idxCounterSigner = 0;
  589. cvsiPrivate.dwInheritedError = 0;
  590. cvsi.dwFlags |= CRYPTUI_VIEWSIGNERINFO_RESERVED_FIELD_IS_SIGNERINFO_PRIVATE;
  591. cvsi.dwReserved = (DWORD_PTR) &cvsiPrivate;
  592. }
  593. CryptUIDlgViewSignerInfoW(&cvsi);
  594. if (pcvs->szFileName != NULL)
  595. {
  596. FreeWinVTrustState(
  597. pcvs->szFileName,
  598. NULL,
  599. 0,
  600. NULL,
  601. szOID_PKIX_KP_CODE_SIGNING,
  602. &cryptProviderDefUsage,
  603. &WTD);//,
  604. //&fDefault);
  605. }
  606. if (pviewhelp->pcvs->choice == EncodedMessage_Chosen)
  607. {
  608. CryptMsgClose(hMsg);
  609. }
  610. }
  611. break;
  612. }
  613. break;
  614. case WM_DESTROY:
  615. LVITEMW lvItem;
  616. pviewhelp = (PCERT_VIEWSIGNATURES_HELPER) GetWindowLongPtr(hwndDlg, DWLP_USER);
  617. //
  618. // get all the items in the list view and free the lParam
  619. // associated with each of them (lParam is the helper sruct)
  620. //
  621. hWndListView = GetDlgItem(hwndDlg, IDC_SIGNATURES_SIG_LIST);
  622. memset(&lvI, 0, sizeof(lvI));
  623. lvI.iItem = ListView_GetItemCount(hWndListView) - 1;
  624. lvI.mask = LVIF_PARAM;
  625. while (lvI.iItem >= 0)
  626. {
  627. if (ListView_GetItemU(hWndListView, &lvI))
  628. {
  629. free((void *) lvI.lParam);
  630. }
  631. lvI.iItem--;
  632. }
  633. break;
  634. case WM_HELP:
  635. case WM_CONTEXTMENU:
  636. if (msg == WM_HELP)
  637. {
  638. hwnd = GetDlgItem(hwndDlg, ((LPHELPINFO)lParam)->iCtrlId);
  639. }
  640. else
  641. {
  642. hwnd = (HWND) wParam;
  643. }
  644. if ((hwnd != GetDlgItem(hwndDlg, IDC_SIGNATURES_SIG_LIST)) &&
  645. (hwnd != GetDlgItem(hwndDlg, IDC_SIGNATURES_DETAILS_BUTTON)))
  646. {
  647. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)TRUE);
  648. return TRUE;
  649. }
  650. else
  651. {
  652. return OnContextHelp(hwndDlg, msg, wParam, lParam, helpmap);
  653. }
  654. break;
  655. }
  656. return FALSE;
  657. }
  658. //////////////////////////////////////////////////////////////////////////////////////
  659. //
  660. //////////////////////////////////////////////////////////////////////////////////////
  661. UINT
  662. CALLBACK
  663. ViewSigsPropPageCallback(
  664. HWND hWnd,
  665. UINT uMsg,
  666. LPPROPSHEETPAGEW ppsp)
  667. {
  668. CERT_VIEWSIGNATURES_HELPER *pviewhelp = (CERT_VIEWSIGNATURES_HELPER *) ppsp->lParam;
  669. if (pviewhelp->pcvs->pPropPageCallback != NULL)
  670. {
  671. (*(pviewhelp->pcvs->pPropPageCallback))(hWnd, uMsg, pviewhelp->pcvs->pvCallbackData);
  672. }
  673. if (uMsg == PSPCB_RELEASE)
  674. {
  675. if (pviewhelp->fSelfCleanup)
  676. {
  677. if (pviewhelp->hExtraStore)
  678. CertCloseStore(pviewhelp->hExtraStore, 0);
  679. FreeViewSignaturesStruct(pviewhelp->pcvs);
  680. free(pviewhelp);
  681. }
  682. }
  683. return TRUE;
  684. }
  685. //////////////////////////////////////////////////////////////////////////////////////
  686. //
  687. //////////////////////////////////////////////////////////////////////////////////////
  688. BOOL
  689. WINAPI
  690. CryptUIGetViewSignaturesPagesW(
  691. PCCRYPTUI_VIEWSIGNATURES_STRUCTW pcvs,
  692. PROPSHEETPAGEW **prghPropPages,
  693. DWORD *pcPropPages
  694. )
  695. {
  696. BOOL fRetValue = TRUE;
  697. HRESULT hr;
  698. WCHAR rgwch[CRYPTUI_MAX_STRING_SIZE];
  699. char rgch[CRYPTUI_MAX_STRING_SIZE];
  700. CERT_VIEWSIGNATURES_HELPER *pviewhelp;
  701. PCRYPTUI_VIEWSIGNATURES_STRUCTW pNewcvs;
  702. CRYPT_DATA_BLOB EncodedMsg;
  703. if (pcvs->dwSize != sizeof(CRYPTUI_VIEWSIGNATURES_STRUCTW)) {
  704. SetLastError(E_INVALIDARG);
  705. return FALSE;
  706. }
  707. if (!CommonInit())
  708. {
  709. return FALSE;
  710. }
  711. if (NULL == (pNewcvs = AllocAndCopyViewSignaturesStruct(pcvs)))
  712. {
  713. return FALSE;
  714. }
  715. if (NULL == (pviewhelp = (CERT_VIEWSIGNATURES_HELPER *) malloc(sizeof(CERT_VIEWSIGNATURES_HELPER))))
  716. {
  717. FreeViewSignaturesStruct(pNewcvs);
  718. return FALSE;
  719. }
  720. *pcPropPages = 1;
  721. //
  722. // initialize the helper struct
  723. //
  724. memset (pviewhelp, 0, sizeof(CERT_VIEWSIGNATURES_HELPER));
  725. pviewhelp->pcvs = pNewcvs;
  726. pviewhelp->fSelfCleanup = TRUE;
  727. if (pcvs->choice == EncodedMessage_Chosen)
  728. {
  729. EncodedMsg.pbData = pcvs->u.EncodedMessage.pbData;
  730. EncodedMsg.cbData = pcvs->u.EncodedMessage.cbData;
  731. pviewhelp->hExtraStore = CertOpenStore(
  732. CERT_STORE_PROV_PKCS7,
  733. X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  734. NULL,
  735. NULL,
  736. (const void *) &EncodedMsg);
  737. }
  738. else
  739. {
  740. pviewhelp->hExtraStore = CertOpenStore(
  741. CERT_STORE_PROV_MSG,
  742. X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  743. NULL,
  744. NULL,
  745. (const void *) pcvs->u.hMsg);
  746. }
  747. //
  748. // Build up the list of pages we are going to use in the dialog
  749. //
  750. *prghPropPages = (PROPSHEETPAGEW *) malloc((*pcPropPages) * sizeof(PROPSHEETPAGEW));
  751. if (*prghPropPages == NULL)
  752. {
  753. FreeViewSignaturesStruct(pNewcvs);
  754. return FALSE;
  755. }
  756. memset(*prghPropPages, 0, (*pcPropPages) * sizeof(PROPSHEETPAGEW));
  757. (*prghPropPages)[0].dwSize = sizeof((*prghPropPages)[0]);
  758. (*prghPropPages)[0].dwFlags = PSP_USECALLBACK;
  759. (*prghPropPages)[0].hInstance = HinstDll;
  760. (*prghPropPages)[0].pszTemplate = (LPWSTR) MAKEINTRESOURCE(IDD_SIGNATURES_GENERAL_DIALOG);
  761. (*prghPropPages)[0].hIcon = 0;
  762. (*prghPropPages)[0].pszTitle = NULL;
  763. (*prghPropPages)[0].pfnDlgProc = ViewPageViewSignatures;
  764. (*prghPropPages)[0].lParam = (LPARAM) pviewhelp;
  765. (*prghPropPages)[0].pfnCallback = ViewSigsPropPageCallback;
  766. (*prghPropPages)[0].pcRefParent = NULL;
  767. *pcPropPages = 1;
  768. return fRetValue;
  769. }
  770. //////////////////////////////////////////////////////////////////////////////////////
  771. //
  772. //////////////////////////////////////////////////////////////////////////////////////
  773. BOOL
  774. WINAPI
  775. CryptUIGetViewSignaturesPagesA(
  776. PCCRYPTUI_VIEWSIGNATURES_STRUCTA pcvs,
  777. PROPSHEETPAGEA **prghPropPages,
  778. DWORD *pcPropPages
  779. )
  780. {
  781. CRYPTUI_VIEWSIGNATURES_STRUCTW cvsW;
  782. BOOL fRet;
  783. memcpy(&cvsW, pcvs, sizeof(cvsW));
  784. if (pcvs->szFileName != NULL)
  785. {
  786. cvsW.szFileName = CertUIMkWStr(pcvs->szFileName);
  787. }
  788. fRet = (CryptUIGetViewSignaturesPagesW(
  789. &cvsW,
  790. (PROPSHEETPAGEW**) prghPropPages,
  791. pcPropPages));
  792. if (cvsW.szFileName != NULL)
  793. {
  794. free((void *) cvsW.szFileName);
  795. }
  796. return(fRet);
  797. }
  798. //////////////////////////////////////////////////////////////////////////////////////
  799. //
  800. //////////////////////////////////////////////////////////////////////////////////////
  801. BOOL
  802. WINAPI
  803. CryptUIFreeViewSignaturesPagesW(
  804. PROPSHEETPAGEW *rghPropPages,
  805. DWORD cPropPages
  806. )
  807. {
  808. free(rghPropPages);
  809. return TRUE;
  810. }
  811. //////////////////////////////////////////////////////////////////////////////////////
  812. //
  813. //////////////////////////////////////////////////////////////////////////////////////
  814. BOOL WINAPI CryptUIFreeViewSignaturesPagesA(
  815. PROPSHEETPAGEA *rghPropPages,
  816. DWORD cPropPages
  817. )
  818. {
  819. return (CryptUIFreeViewSignaturesPagesW((PROPSHEETPAGEW *) rghPropPages, cPropPages));
  820. }