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.

942 lines
33 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: signgen.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_SIGNER_GENERAL_SIGNER_NAME, IDH_SIGNERINFO_GENERAL_SIGNERNAME},
  16. {IDC_SIGNER_GENERAL_EMAIL, IDH_SIGNERINFO_GENERAL_SIGNEREMAIL},
  17. {IDC_SIGNER_GENERAL_SIGNING_TIME, IDH_SIGNERINFO_GENERAL_SIGNETIME},
  18. {IDC_SIGNER_GENERAL_VIEW_CERTIFICATE, IDH_SIGNERINFO_GENERAL_VIEW_CERTIFICATE},
  19. {IDC_SIGNER_GENERAL_COUNTER_SIGS, IDH_SIGNERINFO_GENERAL_COUNTERSIG_LIST},
  20. {IDC_SIGNER_GENERAL_DETAILS, IDH_SIGNERINFO_GENERAL_COUNTERSIG_DETAILS}
  21. };
  22. //////////////////////////////////////////////////////////////////////////////////////
  23. //
  24. //////////////////////////////////////////////////////////////////////////////////////
  25. static void AddCounterSignersToList(HWND hWndListView, SIGNER_VIEW_HELPER *pviewhelp)
  26. {
  27. CMSG_SIGNER_INFO const *pSignerInfo;
  28. PCMSG_SIGNER_INFO pCounterSignerInfo;
  29. DWORD cbCounterSignerInfo;
  30. PCCERT_CONTEXT pCertContext = NULL;
  31. DWORD i;
  32. WCHAR szNameText[CRYPTUI_MAX_STRING_SIZE];
  33. WCHAR szEmailText[CRYPTUI_MAX_STRING_SIZE];
  34. LV_ITEMW lvI;
  35. int itemIndex = 0;
  36. LPWSTR pszTimeText;
  37. pSignerInfo = pviewhelp->pcvsi->pSignerInfo;
  38. //
  39. // set up the fields in the list view item struct that don't change from item to item
  40. //
  41. memset(&lvI, 0, sizeof(lvI));
  42. lvI.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
  43. lvI.state = 0;
  44. lvI.stateMask = 0;
  45. //
  46. // loop for each unauthenticated attribute and see if it is a counter sig
  47. //
  48. for (i=0; i<pSignerInfo->UnauthAttrs.cAttr; i++)
  49. {
  50. if (!(strcmp(pSignerInfo->UnauthAttrs.rgAttr[i].pszObjId, szOID_RSA_counterSign) == 0))
  51. {
  52. continue;
  53. }
  54. assert(pSignerInfo->UnauthAttrs.rgAttr[i].cValue == 1);
  55. //
  56. // decode the EncodedSigner info
  57. //
  58. cbCounterSignerInfo = 0;
  59. pCounterSignerInfo = NULL;
  60. if(!CryptDecodeObject(PKCS_7_ASN_ENCODING|CRYPT_ASN_ENCODING,
  61. PKCS7_SIGNER_INFO,
  62. pSignerInfo->UnauthAttrs.rgAttr[i].rgValue[0].pbData,
  63. pSignerInfo->UnauthAttrs.rgAttr[i].rgValue[0].cbData,
  64. 0,
  65. NULL,
  66. &cbCounterSignerInfo))
  67. {
  68. return;
  69. }
  70. if (NULL == (pCounterSignerInfo = (PCMSG_SIGNER_INFO)malloc(cbCounterSignerInfo)))
  71. {
  72. return;
  73. }
  74. if(!CryptDecodeObject(PKCS_7_ASN_ENCODING|CRYPT_ASN_ENCODING,
  75. PKCS7_SIGNER_INFO,
  76. pSignerInfo->UnauthAttrs.rgAttr[i].rgValue[0].pbData,
  77. pSignerInfo->UnauthAttrs.rgAttr[i].rgValue[0].cbData,
  78. 0,
  79. pCounterSignerInfo,
  80. &cbCounterSignerInfo))
  81. {
  82. free(pCounterSignerInfo);
  83. return;
  84. }
  85. //
  86. // find the signers cert
  87. //
  88. pCertContext = GetSignersCert(
  89. pCounterSignerInfo,
  90. pviewhelp->hExtraStore,
  91. pviewhelp->pcvsi->cStores,
  92. pviewhelp->pcvsi->rghStores);
  93. //
  94. // get the signers name
  95. //
  96. if (!(pCertContext && CertGetNameStringW(
  97. pCertContext,
  98. CERT_NAME_SIMPLE_DISPLAY_TYPE,
  99. 0,//CERT_NAME_ISSUER_FLAG,
  100. NULL,
  101. szNameText,
  102. ARRAYSIZE(szNameText))))
  103. {
  104. LoadStringU(HinstDll, IDS_NOTAVAILABLE, szNameText, ARRAYSIZE(szNameText));
  105. }
  106. //
  107. // get the signers email
  108. //
  109. if (!(pCertContext && (CertGetNameStringW(
  110. pCertContext,
  111. CERT_NAME_EMAIL_TYPE,
  112. 0,//CERT_NAME_ISSUER_FLAG,
  113. NULL,
  114. szEmailText,
  115. ARRAYSIZE(szEmailText)) != 1)))
  116. {
  117. LoadStringU(HinstDll, IDS_NOTAVAILABLE, szEmailText, ARRAYSIZE(szEmailText));
  118. }
  119. pszTimeText = AllocAndReturnSignTime(pCounterSignerInfo, NULL, hWndListView);
  120. //
  121. // add the item to the list view
  122. //
  123. lvI.iSubItem = 0;
  124. lvI.pszText = szNameText;
  125. lvI.cchTextMax = wcslen(szNameText);
  126. lvI.lParam = (LPARAM) pCounterSignerInfo;
  127. lvI.iItem = itemIndex++;
  128. ListView_InsertItemU(hWndListView, &lvI);
  129. ListView_SetItemTextU(hWndListView, itemIndex-1 , 1, szEmailText);
  130. if (pszTimeText != NULL)
  131. {
  132. ListView_SetItemTextU(hWndListView, itemIndex-1 , 2, pszTimeText);
  133. free(pszTimeText);
  134. }
  135. else
  136. {
  137. LoadStringU(HinstDll, IDS_NOTAVAILABLE, szEmailText, ARRAYSIZE(szEmailText));
  138. ListView_SetItemTextU(hWndListView, itemIndex-1 , 2, szEmailText);
  139. }
  140. }
  141. }
  142. //////////////////////////////////////////////////////////////////////////////////////
  143. //
  144. //////////////////////////////////////////////////////////////////////////////////////
  145. static BOOL ValidateCertForUsageWrapper(
  146. PCCERT_CONTEXT pCertContext,
  147. DWORD cStores,
  148. HCERTSTORE * rghStores,
  149. HCERTSTORE hExtraStore,
  150. LPCSTR pszOID)
  151. {
  152. if ((pszOID == NULL) ||
  153. (!((strcmp(pszOID, szOID_PKIX_KP_TIMESTAMP_SIGNING) == 0) ||
  154. (strcmp(pszOID, szOID_KP_TIME_STAMP_SIGNING) == 0))))
  155. {
  156. return (ValidateCertForUsage(
  157. pCertContext,
  158. NULL,
  159. cStores,
  160. rghStores,
  161. hExtraStore,
  162. pszOID));
  163. }
  164. else
  165. {
  166. return (ValidateCertForUsage(
  167. pCertContext,
  168. NULL,
  169. cStores,
  170. rghStores,
  171. hExtraStore,
  172. szOID_PKIX_KP_TIMESTAMP_SIGNING) ||
  173. ValidateCertForUsage(
  174. pCertContext,
  175. NULL,
  176. cStores,
  177. rghStores,
  178. hExtraStore,
  179. szOID_KP_TIME_STAMP_SIGNING));
  180. }
  181. }
  182. //////////////////////////////////////////////////////////////////////////////////////
  183. //
  184. //////////////////////////////////////////////////////////////////////////////////////
  185. static BOOL GetWinVTrustState(SIGNER_VIEW_HELPER *pviewhelp)
  186. {
  187. HCERTSTORE *rghLocalStoreArray;
  188. DWORD i;
  189. //
  190. // if the private data was passed in that means WinVerifyTrust has already
  191. // been called so just use that state to see if the cert is OK, otherwise
  192. // call BuildWinVTrustState to build up the state
  193. //
  194. if (pviewhelp->pPrivate == NULL)
  195. {
  196. //
  197. // make one array out of the array of hCertStores plus the extra hCertStore
  198. //
  199. if (NULL == (rghLocalStoreArray = (HCERTSTORE *) malloc(sizeof(HCERTSTORE) * (pviewhelp->pcvsi->cStores+1))))
  200. {
  201. return FALSE;
  202. }
  203. i=0;
  204. while (i<pviewhelp->pcvsi->cStores)
  205. {
  206. rghLocalStoreArray[i] = pviewhelp->pcvsi->rghStores[i];
  207. i++;
  208. }
  209. rghLocalStoreArray[i] = pviewhelp->hExtraStore;
  210. if (NULL == (pviewhelp->pPrivate = (CERT_VIEWSIGNERINFO_PRIVATE *) malloc(sizeof(CERT_VIEWSIGNERINFO_PRIVATE))))
  211. {
  212. free(rghLocalStoreArray);
  213. return FALSE;
  214. }
  215. if (BuildWinVTrustState(
  216. NULL,
  217. pviewhelp->pcvsi->pSignerInfo,
  218. pviewhelp->pcvsi->cStores+1,
  219. rghLocalStoreArray,
  220. pviewhelp->pcvsi->pszOID,
  221. pviewhelp->pPrivate,
  222. &(pviewhelp->CryptProviderDefUsage),
  223. &(pviewhelp->WTD)))
  224. {
  225. pviewhelp->fPrivateAllocated = TRUE;
  226. pviewhelp->pPrivate->idxSigner = 0;
  227. pviewhelp->pPrivate->fCounterSigner = FALSE;
  228. pviewhelp->pPrivate->idxCounterSigner = 0;
  229. pviewhelp->pPrivate->dwInheritedError = 0;
  230. }
  231. else
  232. {
  233. free(pviewhelp->pPrivate);
  234. pviewhelp->pPrivate = NULL;
  235. }
  236. free(rghLocalStoreArray);
  237. }
  238. if (pviewhelp->pPrivate != NULL)
  239. {
  240. return TRUE;
  241. }
  242. else
  243. {
  244. return FALSE;
  245. }
  246. }
  247. //////////////////////////////////////////////////////////////////////////////////////
  248. //
  249. //////////////////////////////////////////////////////////////////////////////////////
  250. INT_PTR APIENTRY ViewPageSignerGeneral(HWND hwndDlg, UINT msg, WPARAM wParam,
  251. LPARAM lParam)
  252. {
  253. DWORD i;
  254. PROPSHEETPAGE *ps;
  255. SIGNER_VIEW_HELPER *pviewhelp;
  256. HWND hWndListView;
  257. LV_COLUMNW lvC;
  258. WCHAR szText[CRYPTUI_MAX_STRING_SIZE];
  259. HANDLE hGraphic;
  260. DWORD cbText;
  261. LPWSTR pwszText;
  262. CMSG_SIGNER_INFO const *pSignerInfo;
  263. LPWSTR pszTimeText;
  264. LVITEMW lvI;
  265. int listIndex;
  266. CHARFORMAT chFormat;
  267. HWND hwnd;
  268. CRYPT_PROVIDER_DATA const *pProvData = NULL;
  269. LPWSTR pwszErrorString;
  270. LPNMLISTVIEW pnmv;
  271. switch ( msg ) {
  272. case WM_INITDIALOG:
  273. //
  274. // save the pviewhelp struct in DWL_USER so it can always be accessed
  275. //
  276. ps = (PROPSHEETPAGE *) lParam;
  277. pviewhelp = (SIGNER_VIEW_HELPER *) (ps->lParam);
  278. pSignerInfo = pviewhelp->pcvsi->pSignerInfo;
  279. SetWindowLongPtr(hwndDlg, DWLP_USER, (DWORD_PTR) pviewhelp);
  280. //
  281. // extract the signers cert from the list of stores
  282. //
  283. pviewhelp->pSignersCert = GetSignersCert(
  284. pviewhelp->pcvsi->pSignerInfo,
  285. pviewhelp->hExtraStore,
  286. pviewhelp->pcvsi->cStores,
  287. pviewhelp->pcvsi->rghStores);
  288. if (!GetWinVTrustState(pviewhelp))
  289. {
  290. return FALSE;
  291. }
  292. switch (pviewhelp->pPrivate->pCryptProviderData->dwFinalError)
  293. {
  294. case TRUST_E_NO_SIGNER_CERT:
  295. pviewhelp->hIcon = LoadIcon(HinstDll, MAKEINTRESOURCE(IDI_EXCLAMATION_SIGN));
  296. LoadStringU(HinstDll, IDS_SIGNER_UNAVAILABLE_CERT, (LPWSTR)szText, ARRAYSIZE(szText));
  297. break;
  298. case TRUST_E_CERT_SIGNATURE:
  299. pviewhelp->hIcon = LoadIcon(HinstDll, MAKEINTRESOURCE(IDI_REVOKED_SIGN));
  300. LoadStringU(HinstDll, IDS_BAD_SIGNER_CERT_SIGNATURE, (LPWSTR)szText, ARRAYSIZE(szText));
  301. break;
  302. case TRUST_E_BAD_DIGEST:
  303. pviewhelp->hIcon = LoadIcon(HinstDll, MAKEINTRESOURCE(IDI_REVOKED_SIGN));
  304. LoadStringU(HinstDll, IDS_SIGNER_INVALID_SIGNATURE, (LPWSTR)szText, ARRAYSIZE(szText));
  305. break;
  306. case CERT_E_CHAINING:
  307. pviewhelp->hIcon = LoadIcon(HinstDll, MAKEINTRESOURCE(IDI_REVOKED_SIGN));
  308. LoadStringU(HinstDll, IDS_SIGNER_CERT_NO_VERIFY, (LPWSTR)szText, ARRAYSIZE(szText));
  309. break;
  310. case TRUST_E_COUNTER_SIGNER:
  311. case TRUST_E_TIME_STAMP:
  312. pviewhelp->hIcon = LoadIcon(HinstDll, MAKEINTRESOURCE(IDI_REVOKED_SIGN));
  313. //
  314. // if the over-all error is a counter signer signer error, then we need to check
  315. // whether we are currently viewing the counter signer of the original signer
  316. //
  317. if (pviewhelp->pPrivate->fCounterSigner)
  318. {
  319. PCRYPT_PROVIDER_SGNR pSigner;
  320. //
  321. // if we are looking at the counter signer, then get the specific error
  322. // out of the signer structure
  323. //
  324. pSigner = WTHelperGetProvSignerFromChain(
  325. pviewhelp->pPrivate->pCryptProviderData,
  326. pviewhelp->pPrivate->idxSigner,
  327. pviewhelp->pPrivate->fCounterSigner,
  328. pviewhelp->pPrivate->idxCounterSigner);
  329. if (pSigner == NULL)
  330. {
  331. LoadStringU(HinstDll, IDS_UKNOWN_ERROR, (LPWSTR)szText, ARRAYSIZE(szText));
  332. }
  333. else
  334. {
  335. switch (pSigner->dwError)
  336. {
  337. case TRUST_E_NO_SIGNER_CERT:
  338. pviewhelp->hIcon = LoadIcon(HinstDll, MAKEINTRESOURCE(IDI_EXCLAMATION_SIGN));
  339. LoadStringU(HinstDll, IDS_SIGNER_UNAVAILABLE_CERT, (LPWSTR)szText, ARRAYSIZE(szText));
  340. break;
  341. case TRUST_E_CERT_SIGNATURE:
  342. LoadStringU(HinstDll, IDS_BAD_SIGNER_CERT_SIGNATURE, (LPWSTR)szText, ARRAYSIZE(szText));
  343. break;
  344. case TRUST_E_BAD_DIGEST:
  345. case NTE_BAD_SIGNATURE:
  346. LoadStringU(HinstDll, IDS_SIGNER_INVALID_SIGNATURE, (LPWSTR)szText, ARRAYSIZE(szText));
  347. break;
  348. default:
  349. GetUnknownErrorString(&pwszErrorString, pSigner->dwError);
  350. if ((pwszErrorString != NULL) && (wcslen(pwszErrorString)+1 < ARRAYSIZE(szText)))
  351. {
  352. wcscpy(szText, pwszErrorString);
  353. }
  354. else
  355. {
  356. LoadStringU(HinstDll, IDS_UKNOWN_ERROR, (LPWSTR)szText, ARRAYSIZE(szText));
  357. }
  358. free(pwszErrorString);
  359. break;
  360. }
  361. }
  362. }
  363. else
  364. {
  365. //
  366. // since we are viewing the original signer, just set the generic counter signer
  367. // error problem
  368. //
  369. LoadStringU(HinstDll, IDS_COUNTER_SIGNER_INVALID, (LPWSTR)szText, ARRAYSIZE(szText));
  370. }
  371. break;
  372. case 0:
  373. //
  374. // even if there is no error from the wintrust call, there may be ar
  375. // inherited error, if that is that case then fall through to the default
  376. // error processing
  377. //
  378. if ((pviewhelp->dwInheritedError == 0) && (pviewhelp->pPrivate->dwInheritedError == 0))
  379. {
  380. pviewhelp->hIcon = LoadIcon(HinstDll, MAKEINTRESOURCE(IDI_SIGN));
  381. LoadStringU(HinstDll, IDS_SIGNER_VALID, (LPWSTR)szText, ARRAYSIZE(szText));
  382. break;
  383. }
  384. // fall through if dwInheritedError is not 0
  385. default:
  386. if (pviewhelp->pPrivate->pCryptProviderData->dwFinalError != 0)
  387. {
  388. GetUnknownErrorString(&pwszErrorString, pviewhelp->pPrivate->pCryptProviderData->dwFinalError);
  389. }
  390. else
  391. {
  392. if (pviewhelp->dwInheritedError != 0)
  393. {
  394. GetUnknownErrorString(&pwszErrorString, pviewhelp->dwInheritedError);
  395. }
  396. else
  397. {
  398. GetUnknownErrorString(&pwszErrorString, pviewhelp->pPrivate->dwInheritedError);
  399. }
  400. }
  401. pviewhelp->hIcon = LoadIcon(HinstDll, MAKEINTRESOURCE(IDI_REVOKED_SIGN));
  402. if ((pwszErrorString != NULL) && (wcslen(pwszErrorString)+1 < ARRAYSIZE(szText)))
  403. {
  404. wcscpy(szText, pwszErrorString);
  405. }
  406. else
  407. {
  408. LoadStringU(HinstDll, IDS_UKNOWN_ERROR, (LPWSTR)szText, ARRAYSIZE(szText));
  409. }
  410. free(pwszErrorString);
  411. break;
  412. }
  413. CryptUISetRicheditTextW(hwndDlg, IDC_SIGNER_GENERAL_VALIDITY_EDIT, szText);
  414. LoadStringU(HinstDll, IDS_SIGNER_INFORMATION, (LPWSTR)szText, ARRAYSIZE(szText));
  415. //
  416. // set the header text and subclass the edit controls so they display an
  417. // arrow cursor in their window
  418. //
  419. CryptUISetRicheditTextW(hwndDlg, IDC_SIGNER_GENERAL_HEADER_EDIT, szText);
  420. CertSubclassEditControlForArrowCursor(GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_VALIDITY_EDIT));
  421. CertSubclassEditControlForArrowCursor(GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_HEADER_EDIT));
  422. //
  423. // disable the "View Certificate" button if the cert was not found
  424. //
  425. if (pviewhelp->pSignersCert == NULL)
  426. {
  427. EnableWindow(GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_VIEW_CERTIFICATE), FALSE);
  428. }
  429. //
  430. // get the signers name and display it
  431. //
  432. if (!((pviewhelp->pSignersCert) && (CertGetNameStringW(
  433. pviewhelp->pSignersCert,
  434. CERT_NAME_SIMPLE_DISPLAY_TYPE,
  435. 0,//CERT_NAME_ISSUER_FLAG,
  436. NULL,
  437. szText,
  438. ARRAYSIZE(szText)))))
  439. {
  440. LoadStringU(HinstDll, IDS_NOTAVAILABLE, szText, ARRAYSIZE(szText));
  441. }
  442. CryptUISetRicheditTextW(hwndDlg, IDC_SIGNER_GENERAL_SIGNER_NAME, szText);
  443. //
  444. // get the signers email and display it
  445. //
  446. if (!((pviewhelp->pSignersCert) && (CertGetNameStringW(
  447. pviewhelp->pSignersCert,
  448. CERT_NAME_EMAIL_TYPE,
  449. 0,//CERT_NAME_ISSUER_FLAG,
  450. NULL,
  451. szText,
  452. ARRAYSIZE(szText)) != 1)))
  453. {
  454. LoadStringU(HinstDll, IDS_NOTAVAILABLE, szText, ARRAYSIZE(szText));
  455. }
  456. CryptUISetRicheditTextW(hwndDlg, IDC_SIGNER_GENERAL_EMAIL, szText);
  457. //
  458. // get the signing time and display it
  459. //
  460. pszTimeText = AllocAndReturnTimeStampersTimes(
  461. pviewhelp->pcvsi->pSignerInfo,
  462. NULL,
  463. GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_SIGNING_TIME));
  464. if (pszTimeText != NULL)
  465. {
  466. CryptUISetRicheditTextW(hwndDlg, IDC_SIGNER_GENERAL_SIGNING_TIME, pszTimeText);
  467. free(pszTimeText);
  468. }
  469. else
  470. {
  471. LoadStringU(HinstDll, IDS_NOTAVAILABLE, szText, ARRAYSIZE(szText));
  472. CryptUISetRicheditTextW(hwndDlg, IDC_SIGNER_GENERAL_SIGNING_TIME, szText);
  473. }
  474. //
  475. // disable the view details button since nothing is currently selected
  476. //
  477. EnableWindow(GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_DETAILS), FALSE);
  478. //
  479. // create and set the font for the signer info header information
  480. //
  481. memset(&chFormat, 0, sizeof(chFormat));
  482. chFormat.cbSize = sizeof(chFormat);
  483. chFormat.dwMask = CFM_BOLD;
  484. chFormat.dwEffects = CFE_BOLD;
  485. SendMessageA(GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_HEADER_EDIT), EM_SETCHARFORMAT, SCF_ALL, (LPARAM) &chFormat);
  486. //
  487. // get the handle of the list view control
  488. //
  489. hWndListView = GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_COUNTER_SIGS);
  490. //
  491. // initialize the columns in the list view
  492. //
  493. lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  494. lvC.fmt = LVCFMT_LEFT; // Left-align the column.
  495. lvC.pszText = szText; // The text for the column.
  496. // Add the columns. They are loaded from a string table.
  497. lvC.iSubItem = 0;
  498. lvC.cx = 100;
  499. LoadStringU(HinstDll, IDS_NAME, szText, ARRAYSIZE(szText));
  500. if (ListView_InsertColumnU(hWndListView, 0, &lvC) == -1)
  501. {
  502. // error
  503. }
  504. lvC.cx = 100;
  505. LoadStringU(HinstDll, IDS_EMAIL, szText, ARRAYSIZE(szText));
  506. if (ListView_InsertColumnU(hWndListView, 1, &lvC) == -1)
  507. {
  508. // error
  509. }
  510. lvC.cx = 125;
  511. LoadStringU(HinstDll, IDS_TIMESTAMP_TIME, szText, ARRAYSIZE(szText));
  512. if (ListView_InsertColumnU(hWndListView, 2, &lvC) == -1)
  513. {
  514. // error
  515. }
  516. //
  517. // set the style in the list view so that it highlights an entire line
  518. //
  519. SendMessageA(hWndListView, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
  520. //
  521. // add all of the counter signers to the list box
  522. //
  523. AddCounterSignersToList(GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_COUNTER_SIGS), pviewhelp);
  524. return TRUE;
  525. case WM_NOTIFY:
  526. pviewhelp = (SIGNER_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  527. pSignerInfo = pviewhelp->pcvsi->pSignerInfo;
  528. switch (((NMHDR FAR *) lParam)->code)
  529. {
  530. case PSN_SETACTIVE:
  531. break;
  532. case PSN_APPLY:
  533. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)TRUE);
  534. break;
  535. case PSN_KILLACTIVE:
  536. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)FALSE);
  537. return TRUE;
  538. case PSN_RESET:
  539. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)FALSE);
  540. break;
  541. case PSN_QUERYCANCEL:
  542. pviewhelp->fCancelled = TRUE;
  543. return FALSE;
  544. case PSN_HELP:
  545. pviewhelp = (SIGNER_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  546. if (FIsWin95) {
  547. //WinHelpA(hwndDlg, (LPSTR) pviewhelp->pcvsi->szHelpFileName,
  548. // HELP_CONTEXT, pviewhelp->pcvsi->dwHelpId);
  549. }
  550. else {
  551. //WinHelpW(hwndDlg, pviewhelp->pcvsi->szHelpFileName, HELP_CONTEXT,
  552. // pviewhelp->pcvsi->dwHelpId);
  553. }
  554. return TRUE;
  555. case NM_DBLCLK:
  556. switch (((NMHDR FAR *) lParam)->idFrom)
  557. {
  558. case IDC_SIGNER_GENERAL_COUNTER_SIGS:
  559. if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_DETAILS)))
  560. {
  561. SendMessage(
  562. hwndDlg,
  563. WM_COMMAND,
  564. MAKELONG(IDC_SIGNER_GENERAL_DETAILS, BN_CLICKED),
  565. (LPARAM) GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_DETAILS));
  566. }
  567. break;
  568. }
  569. break;
  570. case LVN_ITEMCHANGED:
  571. if ((((NMHDR FAR *) lParam)->idFrom) != IDC_SIGNER_GENERAL_COUNTER_SIGS)
  572. {
  573. break;
  574. }
  575. //
  576. // if an item is selected, then enable the details button, otherwise
  577. // disable it
  578. //
  579. EnableWindow(
  580. GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_DETAILS),
  581. (ListView_GetSelectedCount(
  582. GetDlgItem(hwndDlg,IDC_SIGNER_GENERAL_COUNTER_SIGS)) == 0) ? FALSE : TRUE);
  583. break;
  584. case NM_CLICK:
  585. if ((((NMHDR FAR *) lParam)->idFrom) != IDC_SIGNER_GENERAL_COUNTER_SIGS)
  586. {
  587. break;
  588. }
  589. hWndListView = GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_COUNTER_SIGS);
  590. //
  591. // make sure something is selected by getting the current selection
  592. //
  593. listIndex = ListView_GetNextItem(
  594. hWndListView,
  595. -1,
  596. LVNI_SELECTED
  597. );
  598. break;
  599. case NM_SETFOCUS:
  600. switch (((NMHDR FAR *) lParam)->idFrom)
  601. {
  602. case IDC_SIGNER_GENERAL_COUNTER_SIGS:
  603. hWndListView = GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_COUNTER_SIGS);
  604. if ((ListView_GetItemCount(hWndListView) != 0) &&
  605. (ListView_GetNextItem(hWndListView, -1, LVNI_SELECTED) == -1))
  606. {
  607. memset(&lvI, 0, sizeof(lvI));
  608. lvI.mask = LVIF_STATE;
  609. lvI.iItem = 0;
  610. lvI.state = LVIS_FOCUSED;
  611. lvI.stateMask = LVIS_FOCUSED;
  612. ListView_SetItem(hWndListView, &lvI);
  613. }
  614. break;
  615. }
  616. break;
  617. }
  618. break;
  619. case WM_COMMAND:
  620. pviewhelp = (SIGNER_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  621. pSignerInfo = pviewhelp->pcvsi->pSignerInfo;
  622. switch (LOWORD(wParam))
  623. {
  624. case IDC_SIGNER_GENERAL_VIEW_CERTIFICATE:
  625. if (HIWORD(wParam) == BN_CLICKED)
  626. {
  627. CRYPTUI_VIEWCERTIFICATE_STRUCTW cvps;
  628. memset(&cvps,0, sizeof(cvps));
  629. cvps.dwSize = sizeof(cvps);
  630. cvps.pCryptProviderData = NULL;
  631. cvps.hwndParent = hwndDlg;
  632. cvps.pCertContext = pviewhelp->pSignersCert;
  633. cvps.cPurposes = 1;
  634. cvps.rgszPurposes = (LPCSTR *) &(pviewhelp->pcvsi->pszOID);
  635. cvps.cStores = pviewhelp->pcvsi->cStores;
  636. cvps.rghStores = pviewhelp->pcvsi->rghStores;
  637. if (pviewhelp->pPrivate != NULL)
  638. {
  639. cvps.pCryptProviderData = pviewhelp->pPrivate->pCryptProviderData;
  640. cvps.fpCryptProviderDataTrustedUsage =
  641. pviewhelp->pPrivate->fpCryptProviderDataTrustedUsage;
  642. cvps.idxSigner = pviewhelp->pPrivate->idxSigner;
  643. cvps.fCounterSigner = pviewhelp->pPrivate->fCounterSigner;
  644. cvps.idxCounterSigner = pviewhelp->pPrivate->idxCounterSigner;
  645. }
  646. CryptUIDlgViewCertificateW(&cvps, NULL);
  647. }
  648. break;
  649. case IDC_SIGNER_GENERAL_DETAILS:
  650. if (HIWORD(wParam) == BN_CLICKED)
  651. {
  652. hWndListView = GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_COUNTER_SIGS);
  653. //
  654. // get the selected item and its lParam which is a signer info
  655. //
  656. listIndex = ListView_GetNextItem(
  657. hWndListView,
  658. -1,
  659. LVNI_SELECTED
  660. );
  661. memset(&lvI, 0, sizeof(lvI));
  662. lvI.iItem = listIndex;
  663. lvI.mask = LVIF_PARAM;
  664. if (!ListView_GetItemU(hWndListView, &lvI))
  665. {
  666. return FALSE;
  667. }
  668. CRYPTUI_VIEWSIGNERINFO_STRUCTW cvsi;
  669. CERT_VIEWSIGNERINFO_PRIVATE cvsiPrivate;
  670. memcpy(&cvsi, pviewhelp->pcvsi, sizeof(cvsi));
  671. cvsi.pSignerInfo = (PCMSG_SIGNER_INFO) lvI.lParam;
  672. cvsi.pszOID = szOID_KP_TIME_STAMP_SIGNING;
  673. cvsi.hwndParent = hwndDlg;
  674. if (pviewhelp->pPrivate != NULL)
  675. {
  676. cvsiPrivate.pCryptProviderData = pviewhelp->pPrivate->pCryptProviderData;
  677. cvsiPrivate.fpCryptProviderDataTrustedUsage =
  678. pviewhelp->pPrivate->fpCryptProviderDataTrustedUsage;
  679. cvsiPrivate.idxSigner = pviewhelp->pPrivate->idxSigner;
  680. cvsiPrivate.fCounterSigner = TRUE;
  681. cvsiPrivate.idxCounterSigner = listIndex;
  682. cvsi.dwFlags |= CRYPTUI_VIEWSIGNERINFO_RESERVED_FIELD_IS_SIGNERINFO_PRIVATE;
  683. cvsi.dwFlags &= ~CRYPTUI_VIEWSIGNERINFO_RESERVED_FIELD_IS_ERROR_CODE;
  684. cvsi.dwReserved = (DWORD_PTR) &cvsiPrivate;
  685. //
  686. // it is possible that there is no error when validating the original
  687. // signer info and that an error was inherited, so to allow the counter
  688. // signer dialog to again inherit the error it must be filled in in the
  689. // private struct
  690. //
  691. if (pviewhelp->pcvsi->dwFlags & CRYPTUI_VIEWSIGNERINFO_RESERVED_FIELD_IS_ERROR_CODE)
  692. {
  693. cvsiPrivate.dwInheritedError = (DWORD) pviewhelp->pcvsi->dwReserved;
  694. }
  695. else
  696. {
  697. cvsiPrivate.dwInheritedError = 0;
  698. }
  699. }
  700. else if (pviewhelp->pcvsi->dwFlags & CRYPTUI_VIEWSIGNERINFO_RESERVED_FIELD_IS_ERROR_CODE)
  701. {
  702. cvsi.dwFlags |= CRYPTUI_VIEWSIGNERINFO_RESERVED_FIELD_IS_ERROR_CODE;
  703. cvsi.dwFlags &= ~CRYPTUI_VIEWSIGNERINFO_RESERVED_FIELD_IS_SIGNERINFO_PRIVATE;
  704. cvsi.dwReserved = pviewhelp->pcvsi->dwReserved;
  705. }
  706. CryptUIDlgViewSignerInfoW(&cvsi);
  707. }
  708. break;
  709. case IDHELP:
  710. if (FIsWin95) {
  711. //WinHelpA(hwndDlg, (LPSTR) pviewhelp->pcvsi->szHelpFileName,
  712. // HELP_CONTEXT, pviewhelp->pcvsi->dwHelpId);
  713. }
  714. else {
  715. //WinHelpW(hwndDlg, pviewhelp->pcvsi->szHelpFileName, HELP_CONTEXT,
  716. // pviewhelp->pcvsi->dwHelpId);
  717. }
  718. return TRUE;
  719. }
  720. break;
  721. case WM_PAINT:
  722. RECT rect;
  723. PAINTSTRUCT paintstruct;
  724. HDC hdc;
  725. COLORREF colorRef;
  726. pviewhelp = (SIGNER_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  727. if (GetUpdateRect(hwndDlg, &rect, FALSE))
  728. {
  729. hdc = BeginPaint(hwndDlg, &paintstruct);
  730. if (hdc == NULL)
  731. {
  732. EndPaint(hwndDlg, &paintstruct);
  733. break;
  734. }
  735. colorRef = GetBkColor(hdc);
  736. SendMessageA(GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_VALIDITY_EDIT), EM_SETBKGNDCOLOR , 0, (LPARAM) colorRef);
  737. SendMessageA(GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_HEADER_EDIT), EM_SETBKGNDCOLOR, 0, (LPARAM) colorRef);
  738. if (pviewhelp->hIcon != NULL)
  739. {
  740. DrawIcon(
  741. hdc,
  742. ICON_X_POS,
  743. ICON_Y_POS,
  744. pviewhelp->hIcon);
  745. }
  746. EndPaint(hwndDlg, &paintstruct);
  747. }
  748. break;
  749. case WM_DESTROY:
  750. pviewhelp = (SIGNER_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  751. if (pviewhelp->pSignersCert)
  752. {
  753. CertFreeCertificateContext(pviewhelp->pSignersCert);
  754. pviewhelp->pSignersCert = NULL;
  755. }
  756. if (pviewhelp->hIcon != NULL)
  757. {
  758. DeleteObject(pviewhelp->hIcon);
  759. pviewhelp->hIcon = NULL;
  760. }
  761. if (pviewhelp->fPrivateAllocated)
  762. {
  763. FreeWinVTrustState(
  764. NULL,
  765. pviewhelp->pcvsi->pSignerInfo,
  766. 0,
  767. NULL,
  768. pviewhelp->pcvsi->pszOID,
  769. &(pviewhelp->CryptProviderDefUsage),
  770. &(pviewhelp->WTD));//,
  771. //&(pviewhelp->fUseDefaultProvider));
  772. free(pviewhelp->pPrivate);
  773. }
  774. //
  775. // get all the items in the list view and free the lParam
  776. // associated with each of them (lParam is the helper sruct)
  777. //
  778. hWndListView = GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_COUNTER_SIGS);
  779. memset(&lvI, 0, sizeof(lvI));
  780. lvI.iItem = ListView_GetItemCount(hWndListView) - 1;
  781. lvI.mask = LVIF_PARAM;
  782. while (lvI.iItem >= 0)
  783. {
  784. if (ListView_GetItemU(hWndListView, &lvI))
  785. {
  786. if (((void *) lvI.lParam) != NULL)
  787. {
  788. free((void *) lvI.lParam);
  789. }
  790. }
  791. lvI.iItem--;
  792. }
  793. break;
  794. case WM_HELP:
  795. case WM_CONTEXTMENU:
  796. if (msg == WM_HELP)
  797. {
  798. hwnd = GetDlgItem(hwndDlg, ((LPHELPINFO)lParam)->iCtrlId);
  799. }
  800. else
  801. {
  802. hwnd = (HWND) wParam;
  803. }
  804. if ((hwnd != GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_SIGNER_NAME)) &&
  805. (hwnd != GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_EMAIL)) &&
  806. (hwnd != GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_SIGNING_TIME)) &&
  807. (hwnd != GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_VIEW_CERTIFICATE)) &&
  808. (hwnd != GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_COUNTER_SIGS)) &&
  809. (hwnd != GetDlgItem(hwndDlg, IDC_SIGNER_GENERAL_DETAILS)))
  810. {
  811. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)TRUE);
  812. return TRUE;
  813. }
  814. else
  815. {
  816. return OnContextHelp(hwndDlg, msg, wParam, lParam, helpmap);
  817. }
  818. }
  819. return FALSE;
  820. }