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.

989 lines
33 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: ctltlist.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_CTL_TRUSTLIST_CERTIFICATE_LIST, IDH_CTLVIEW_TRUSTLIST_CERTIFICATE_LIST},
  16. {IDC_CTL_TRUSTLIST_CERTVALUE_LIST, IDH_CTLVIEW_TRUSTLIST_CERTVALUE_LIST},
  17. {IDC_CTL_TRUSTLIST_DETAIL_EDIT, IDH_CTLVIEW_TRUSTLIST_VALUE_DETAIL_EDIT},
  18. {IDC_CTL_TRUSTLIST_VIEW_BUTTON, IDH_CTLVIEW_TRUSTLIST_VIEWCERT_BUTTON}
  19. };
  20. //////////////////////////////////////////////////////////////////////////////////////
  21. //
  22. //////////////////////////////////////////////////////////////////////////////////////
  23. #define INDENT_STRING L" "
  24. #define TERMINATING_CHAR L""
  25. static void DisplayCertificateValues(HWND hWndListView, PCCERT_CONTEXT pCertContext, PCTL_ENTRY pctlEntry)
  26. {
  27. LPWSTR pwszText;
  28. WCHAR szFieldText[_MAX_PATH]; // used for calls to LoadString only
  29. WCHAR szValueText[CRYPTUI_MAX_STRING_SIZE];
  30. LV_ITEMW lvI;
  31. LV_ITEMW lvIDelete;
  32. int index = 0;
  33. PCERT_INFO pCertInfo;
  34. BYTE hash[20];
  35. DWORD hashSize = ARRAYSIZE(hash);
  36. BOOL fAddRows;
  37. DWORD cChars;
  38. DWORD cbFormatedAttribute;
  39. BYTE *pbFormatedAttribute;
  40. DWORD i;
  41. if (pCertContext == NULL)
  42. {
  43. while(ListView_DeleteItem(hWndListView, 0));
  44. return;
  45. }
  46. pCertInfo = pCertContext->pCertInfo;
  47. //
  48. // set up the fields in the list view item struct that don't change from item to item
  49. //
  50. memset(&lvI, 0, sizeof(lvI));
  51. lvI.mask = LVIF_TEXT | LVIF_STATE | LVIF_PARAM;
  52. lvI.lParam = NULL;
  53. lvI.state = 0;
  54. lvI.stateMask = 0;
  55. lvI.pszText = szFieldText;
  56. lvI.iSubItem = 0;
  57. //
  58. // if the rows have already been added, then don't add them again, just
  59. // set the text in the subitem
  60. //
  61. fAddRows = ListView_GetItemCount(hWndListView) == 0;
  62. //
  63. // subject
  64. //
  65. cChars = CertGetNameStringW(
  66. pCertContext,
  67. CERT_NAME_SIMPLE_DISPLAY_TYPE,
  68. 0,//CERT_NAME_ISSUER_FLAG,
  69. NULL,
  70. NULL,
  71. 0);
  72. if ((cChars != 1) && (NULL != (pwszText = (LPWSTR) malloc(cChars * sizeof(WCHAR)))))
  73. {
  74. CertGetNameStringW(
  75. pCertContext,
  76. CERT_NAME_SIMPLE_DISPLAY_TYPE,
  77. 0,//CERT_NAME_ISSUER_FLAG,
  78. NULL,
  79. pwszText,
  80. cChars);
  81. LoadStringU(HinstDll, IDS_ADV_ISSUEDTO, szFieldText, ARRAYSIZE(szFieldText));
  82. lvI.iItem = index++;
  83. lvI.cchTextMax = wcslen(szFieldText);
  84. lvI.iImage = IMAGE_V1;
  85. ModifyOrInsertRow(
  86. hWndListView,
  87. &lvI,
  88. pwszText,
  89. pwszText,
  90. fAddRows,
  91. FALSE);
  92. }
  93. //
  94. // issuer
  95. //
  96. cChars = CertGetNameStringW(
  97. pCertContext,
  98. CERT_NAME_SIMPLE_DISPLAY_TYPE,
  99. CERT_NAME_ISSUER_FLAG,
  100. NULL,
  101. NULL,
  102. 0);
  103. if ((cChars != 1) && (NULL != (pwszText = (LPWSTR) malloc(cChars * sizeof(WCHAR)))))
  104. {
  105. CertGetNameStringW(
  106. pCertContext,
  107. CERT_NAME_SIMPLE_DISPLAY_TYPE,
  108. CERT_NAME_ISSUER_FLAG,
  109. NULL,
  110. pwszText,
  111. cChars);
  112. LoadStringU(HinstDll, IDS_ADV_ISSUEDFROM, szFieldText, ARRAYSIZE(szFieldText));
  113. lvI.iItem = index++;
  114. lvI.cchTextMax = wcslen(szFieldText);
  115. lvI.iImage = IMAGE_V1;
  116. ModifyOrInsertRow(
  117. hWndListView,
  118. &lvI,
  119. pwszText,
  120. pwszText,
  121. fAddRows,
  122. FALSE);
  123. }
  124. //
  125. // serial number
  126. //
  127. if (FormatSerialNoString(&pwszText, &(pCertInfo->SerialNumber)))
  128. {
  129. LoadStringU(HinstDll, IDS_ADV_SER_NUM, szFieldText, ARRAYSIZE(szFieldText));
  130. lvI.iItem = index++;
  131. lvI.cchTextMax = wcslen(szFieldText);
  132. lvI.iImage = IMAGE_V1;
  133. ModifyOrInsertRow(
  134. hWndListView,
  135. &lvI,
  136. pwszText,
  137. pwszText,
  138. fAddRows,
  139. TRUE);
  140. }
  141. //
  142. // not after
  143. //
  144. if (FormatDateString(&pwszText, pCertInfo->NotAfter, TRUE, TRUE, hWndListView))
  145. {
  146. LoadStringU(HinstDll, IDS_ADV_NOTAFTER, szFieldText, ARRAYSIZE(szFieldText));
  147. lvI.iItem = index++;
  148. lvI.cchTextMax = wcslen(szFieldText);
  149. lvI.iImage = IMAGE_V1;
  150. ModifyOrInsertRow(
  151. hWndListView,
  152. &lvI,
  153. pwszText,
  154. pwszText,
  155. fAddRows,
  156. FALSE);
  157. }
  158. //
  159. // thumbprint
  160. //
  161. if (FormatMemBufToString(
  162. &pwszText,
  163. pctlEntry->SubjectIdentifier.pbData,
  164. pctlEntry->SubjectIdentifier.cbData))
  165. {
  166. LoadStringU(HinstDll, IDS_THUMBPRINT, szFieldText, ARRAYSIZE(szFieldText));
  167. lvI.iItem = index++;
  168. lvI.cchTextMax = wcslen(szFieldText);
  169. lvI.iImage = IMAGE_PROPERTY;
  170. ModifyOrInsertRow(
  171. hWndListView,
  172. &lvI,
  173. pwszText,
  174. pwszText,
  175. fAddRows,
  176. TRUE);
  177. }
  178. //
  179. // Attributes
  180. //
  181. //
  182. // delete any existing attributes
  183. //
  184. memset(&lvIDelete, 0, sizeof(lvIDelete));
  185. lvIDelete.iItem = ListView_GetItemCount(hWndListView) - 1;
  186. lvIDelete.mask = LVIF_PARAM;
  187. while (lvIDelete.iItem >= index)
  188. {
  189. if (ListView_GetItemU(hWndListView, &lvIDelete))
  190. {
  191. FreeListDisplayHelper((PLIST_DISPLAY_HELPER) lvIDelete.lParam);
  192. }
  193. ListView_DeleteItem(hWndListView, lvIDelete.iItem);
  194. lvIDelete.iItem--;
  195. }
  196. if (pctlEntry->cAttribute > 0)
  197. {
  198. //
  199. // display the header
  200. //
  201. LoadStringU(HinstDll, IDS_ADDITIONAL_ATTRIBUTES, szFieldText, ARRAYSIZE(szFieldText));
  202. lvI.cchTextMax = wcslen(szFieldText);
  203. lvI.iItem = index++;
  204. ListView_InsertItemU(hWndListView, &lvI);
  205. //
  206. // display each attribute
  207. //
  208. for (i=0; i<pctlEntry->cAttribute; i++)
  209. {
  210. //
  211. // get the field column string
  212. //
  213. wcscpy(szFieldText, INDENT_STRING);
  214. if (!MyGetOIDInfo(
  215. &szFieldText[0] + ((sizeof(INDENT_STRING) - sizeof(TERMINATING_CHAR)) / sizeof(WCHAR)),
  216. ARRAYSIZE(szFieldText) - ((sizeof(INDENT_STRING) - sizeof(TERMINATING_CHAR)) / sizeof(WCHAR)),
  217. pctlEntry->rgAttribute[i].pszObjId))
  218. {
  219. return;
  220. }
  221. //
  222. // get the value column string
  223. //
  224. cbFormatedAttribute = 0;
  225. pbFormatedAttribute = NULL;
  226. CryptFormatObject(
  227. X509_ASN_ENCODING,
  228. 0,
  229. 0,
  230. NULL,
  231. pctlEntry->rgAttribute[i].pszObjId,
  232. pctlEntry->rgAttribute[i].rgValue[0].pbData,
  233. pctlEntry->rgAttribute[i].rgValue[0].cbData,
  234. NULL,
  235. &cbFormatedAttribute
  236. );
  237. if (NULL == (pbFormatedAttribute = (BYTE *) malloc(cbFormatedAttribute)))
  238. {
  239. return;
  240. }
  241. if (CryptFormatObject(
  242. X509_ASN_ENCODING,
  243. 0,
  244. 0,
  245. NULL,
  246. pctlEntry->rgAttribute[i].pszObjId,
  247. pctlEntry->rgAttribute[i].rgValue[0].pbData,
  248. pctlEntry->rgAttribute[i].rgValue[0].cbData,
  249. pbFormatedAttribute,
  250. &cbFormatedAttribute
  251. ))
  252. {
  253. lvI.iItem = index++;
  254. lvI.cchTextMax = wcslen(szFieldText);
  255. lvI.lParam = (LPARAM) MakeListDisplayHelperForExtension(
  256. pctlEntry->rgAttribute[i].pszObjId,
  257. pctlEntry->rgAttribute[i].rgValue[0].pbData,
  258. pctlEntry->rgAttribute[i].rgValue[0].cbData);
  259. ListView_InsertItemU(hWndListView, &lvI);
  260. ListView_SetItemTextU(
  261. hWndListView,
  262. index-1,
  263. 1,
  264. (LPWSTR)pbFormatedAttribute);
  265. }
  266. free (pbFormatedAttribute);
  267. }
  268. }
  269. }
  270. //////////////////////////////////////////////////////////////////////////////////////
  271. //
  272. //////////////////////////////////////////////////////////////////////////////////////
  273. static PCCERT_CONTEXT FindCertContextInStores(
  274. PCTL_ENTRY pCtlEntry,
  275. DWORD chStores1,
  276. HCERTSTORE *rghStores1,
  277. DWORD chStores2,
  278. HCERTSTORE *rghStores2,
  279. HCERTSTORE hExtraStore,
  280. DWORD dwFindType)
  281. {
  282. DWORD i;
  283. PCCERT_CONTEXT pCertContext = NULL;
  284. if (dwFindType == 0)
  285. {
  286. return NULL;
  287. }
  288. i = 0;
  289. while ((i<chStores1) && (pCertContext == NULL))
  290. {
  291. pCertContext = CertFindCertificateInStore(
  292. rghStores1[i++],
  293. X509_ASN_ENCODING,
  294. 0,
  295. dwFindType,
  296. (void *)&(pCtlEntry->SubjectIdentifier),
  297. NULL);
  298. }
  299. i = 0;
  300. while ((i<chStores2) && (pCertContext == NULL))
  301. {
  302. pCertContext = CertFindCertificateInStore(
  303. rghStores2[i++],
  304. X509_ASN_ENCODING,
  305. 0,
  306. dwFindType,
  307. (void *)&(pCtlEntry->SubjectIdentifier),
  308. NULL);
  309. }
  310. if (pCertContext == NULL)
  311. {
  312. pCertContext = CertFindCertificateInStore(
  313. hExtraStore,
  314. X509_ASN_ENCODING,
  315. 0,
  316. dwFindType,
  317. (void *)&(pCtlEntry->SubjectIdentifier),
  318. NULL);
  319. }
  320. return pCertContext;
  321. }
  322. //////////////////////////////////////////////////////////////////////////////////////
  323. //
  324. //////////////////////////////////////////////////////////////////////////////////////
  325. static void AddCertificatesToList(HWND hWndListView, CTL_VIEW_HELPER *pviewhelp)
  326. {
  327. LPWSTR pwszText;
  328. WCHAR szText[CRYPTUI_MAX_STRING_SIZE];
  329. LV_ITEMW lvI;
  330. DWORD i;
  331. PCCTL_CONTEXT pctl;
  332. DWORD dwFindType;
  333. ALG_ID algID;
  334. PCCRYPT_OID_INFO pOIDInfo;
  335. PCCERT_CONTEXT pCertContext;
  336. int index = 0;
  337. BOOL fDisplayed;
  338. HCERTSTORE hExtraStore;
  339. pctl = pviewhelp->pcvctl->pCTLContext;
  340. //
  341. // set up the fields in the list view item struct that don't change from item to item
  342. //
  343. lvI.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
  344. lvI.state = 0;
  345. lvI.stateMask = 0;
  346. lvI.pszText = szText;
  347. lvI.iSubItem = 0;
  348. lvI.lParam = (LPARAM)NULL;
  349. //
  350. // determine what type of hash the CTL uses, if it isn't anything
  351. // we know about then dont try to find any certs
  352. //
  353. pOIDInfo = CryptFindOIDInfo(
  354. CRYPT_OID_INFO_OID_KEY,
  355. pctl->pCtlInfo->SubjectAlgorithm.pszObjId,
  356. CRYPT_HASH_ALG_OID_GROUP_ID);
  357. if ((pOIDInfo != NULL) && (pOIDInfo->Algid == CALG_SHA1))
  358. {
  359. dwFindType = CERT_FIND_SHA1_HASH;
  360. }
  361. else if ((pOIDInfo != NULL) && (pOIDInfo->Algid == CALG_MD5))
  362. {
  363. dwFindType = CERT_FIND_MD5_HASH;
  364. }
  365. else
  366. {
  367. dwFindType = 0;
  368. }
  369. //
  370. // loop for each cert and try to find it
  371. //
  372. for (i=0; i<pctl->pCtlInfo->cCTLEntry; i++)
  373. {
  374. fDisplayed = FALSE;
  375. if (dwFindType != 0)
  376. {
  377. pCertContext = FindCertContextInStores(
  378. &(pctl->pCtlInfo->rgCTLEntry[i]),
  379. pviewhelp->chStores,
  380. pviewhelp->phStores,
  381. pviewhelp->pcvctl->cCertSearchStores,
  382. pviewhelp->pcvctl->rghCertSearchStores,
  383. pviewhelp->hExtraStore,
  384. dwFindType);
  385. }
  386. else
  387. {
  388. pCertContext = NULL;
  389. }
  390. //
  391. // if we found a cert to go with the hash, then get a display name for it
  392. // and display that along with the hash
  393. //
  394. if (pCertContext != NULL)
  395. {
  396. //
  397. // subject algorithm
  398. //
  399. if (CertGetNameStringW(
  400. pCertContext,
  401. CERT_NAME_SIMPLE_DISPLAY_TYPE,
  402. 0,//CERT_NAME_ISSUER_FLAG,
  403. NULL,
  404. szText,
  405. ARRAYSIZE(szText)))
  406. {
  407. if (FormatMemBufToString(
  408. &pwszText,
  409. pctl->pCtlInfo->rgCTLEntry[i].SubjectIdentifier.pbData,
  410. pctl->pCtlInfo->rgCTLEntry[i].SubjectIdentifier.cbData))
  411. {
  412. lvI.lParam = (LPARAM) pCertContext;
  413. lvI.iItem = index++;
  414. lvI.cchTextMax = wcslen(szText);
  415. ListView_InsertItemU(hWndListView, &lvI);
  416. ListView_SetItemTextU(hWndListView, index-1 , 1, pwszText);
  417. free(pwszText);
  418. fDisplayed = TRUE;
  419. }
  420. }
  421. }
  422. //
  423. // if the cert hasn't been displayed, that means no cert could be found based
  424. // on the hash, or a simple name could not be acquired, in any case, just
  425. // display the hash without a name
  426. //
  427. if (!fDisplayed)
  428. {
  429. if (FormatMemBufToString(
  430. &pwszText,
  431. pctl->pCtlInfo->rgCTLEntry[i].SubjectIdentifier.pbData,
  432. pctl->pCtlInfo->rgCTLEntry[i].SubjectIdentifier.cbData))
  433. {
  434. lvI.lParam = (LPARAM) pCertContext;
  435. lvI.iItem = index++;
  436. LoadStringU(HinstDll, IDS_NOTAVAILABLE, szText, ARRAYSIZE(szText));
  437. lvI.cchTextMax = wcslen(szText);
  438. ListView_InsertItemU(hWndListView, &lvI);
  439. ListView_SetItemTextU(hWndListView, index-1 , 1, pwszText);
  440. free(pwszText);
  441. fDisplayed = TRUE;
  442. }
  443. }
  444. //
  445. // if for some strange reason we have not displayed the cert and we have
  446. // a context for it, then free it so there is no memory leak
  447. //
  448. if ((fDisplayed == FALSE) && (pCertContext != NULL))
  449. {
  450. CertFreeCertificateContext(pCertContext);
  451. }
  452. }
  453. }
  454. //////////////////////////////////////////////////////////////////////////////////////
  455. //
  456. //////////////////////////////////////////////////////////////////////////////////////
  457. INT_PTR APIENTRY ViewPageCTLTrustList(HWND hwndDlg, UINT msg, WPARAM wParam,
  458. LPARAM lParam)
  459. {
  460. DWORD i;
  461. PROPSHEETPAGE *ps;
  462. PCCTL_CONTEXT pctl;
  463. CTL_VIEW_HELPER *pviewhelp;
  464. HWND hWndListView;
  465. HWND hwnd;
  466. LV_COLUMNW lvC;
  467. WCHAR szText[CRYPTUI_MAX_STRING_SIZE];
  468. WCHAR szCompareText[CRYPTUI_MAX_STRING_SIZE];
  469. PCTL_INFO pCtlInfo;
  470. PCCERT_CONTEXT pCertContext;
  471. LPWSTR pwszText;
  472. int listIndex;
  473. LVITEMW lvI;
  474. LPNMLISTVIEW pnmv;
  475. NMLISTVIEW nmv;
  476. switch ( msg ) {
  477. case WM_INITDIALOG:
  478. //
  479. // save the pviewhelp struct in DWL_USER so it can always be accessed
  480. //
  481. ps = (PROPSHEETPAGE *) lParam;
  482. pviewhelp = (CTL_VIEW_HELPER *) (ps->lParam);
  483. pctl = pviewhelp->pcvctl->pCTLContext;
  484. SetWindowLongPtr(hwndDlg, DWLP_USER, (DWORD_PTR) pviewhelp);
  485. pviewhelp->previousSelection = -1;
  486. pviewhelp->currentSelection = -1;
  487. //
  488. // open the know stores that we will be extracting the cert contexts from
  489. //
  490. if (!AllocAndOpenKnownStores(&(pviewhelp->chStores), &(pviewhelp->phStores)))
  491. {
  492. pviewhelp->chStores = 0;
  493. pviewhelp->phStores = NULL;
  494. }
  495. //
  496. // clear the text in the detail edit box
  497. //
  498. CryptUISetRicheditTextW(hwndDlg, IDC_CTL_TRUSTLIST_DETAIL_EDIT, L"");
  499. //
  500. // since there is no cert selected initially disable the "view cert button"
  501. //
  502. EnableWindow(GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_VIEW_BUTTON), FALSE);
  503. //
  504. // initialize the columns in the list view
  505. //
  506. lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  507. lvC.fmt = LVCFMT_LEFT; // Left-align the column.
  508. lvC.pszText = szText; // The text for the column.
  509. // Add the columns. They are loaded from a string table.
  510. lvC.iSubItem = 0;
  511. lvC.cx = 115;
  512. LoadStringU(HinstDll, IDS_ISSUEDTO2, szText, ARRAYSIZE(szText));
  513. if (ListView_InsertColumnU(GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_CERTIFICATE_LIST), 0, &lvC) == -1)
  514. {
  515. // error
  516. }
  517. lvC.cx = 230;
  518. LoadStringU(HinstDll, IDS_THUMBPRINT, szText, ARRAYSIZE(szText));
  519. if (ListView_InsertColumnU(GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_CERTIFICATE_LIST), 1, &lvC) == -1)
  520. {
  521. // error
  522. }
  523. // Add the columns. They are loaded from a string table.
  524. lvC.iSubItem = 0;
  525. lvC.cx = 121;
  526. LoadStringU(HinstDll, IDS_FIELD, szText, ARRAYSIZE(szText));
  527. if (ListView_InsertColumnU(GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_CERTVALUE_LIST), 0, &lvC) == -1)
  528. {
  529. // error
  530. }
  531. lvC.cx = 200;
  532. LoadStringU(HinstDll, IDS_VALUE, szText, ARRAYSIZE(szText));
  533. if (ListView_InsertColumnU(GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_CERTVALUE_LIST), 1, &lvC) == -1)
  534. {
  535. // error
  536. }
  537. //
  538. // set the styles in the list views so that they highlight an entire line and
  539. // so they alway show their selection
  540. //
  541. SendDlgItemMessageA(
  542. hwndDlg,
  543. IDC_CTL_TRUSTLIST_CERTIFICATE_LIST,
  544. LVM_SETEXTENDEDLISTVIEWSTYLE,
  545. 0,
  546. LVS_EX_FULLROWSELECT);
  547. SendDlgItemMessageA(
  548. hwndDlg,
  549. IDC_CTL_TRUSTLIST_CERTVALUE_LIST,
  550. LVM_SETEXTENDEDLISTVIEWSTYLE,
  551. 0,
  552. LVS_EX_FULLROWSELECT);
  553. //
  554. // add all the certificates to the certificate list box
  555. //
  556. AddCertificatesToList(GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_CERTIFICATE_LIST), pviewhelp);
  557. return TRUE;
  558. case WM_NOTIFY:
  559. pviewhelp = (CTL_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  560. pctl = pviewhelp->pcvctl->pCTLContext;
  561. pCtlInfo = pctl->pCtlInfo;
  562. switch (((NMHDR FAR *) lParam)->code)
  563. {
  564. case PSN_SETACTIVE:
  565. break;
  566. case PSN_APPLY:
  567. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)TRUE);
  568. break;
  569. case PSN_KILLACTIVE:
  570. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)FALSE);
  571. return TRUE;
  572. case PSN_RESET:
  573. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)FALSE);
  574. break;
  575. case PSN_QUERYCANCEL:
  576. pviewhelp->fCancelled = TRUE;
  577. return FALSE;
  578. case PSN_HELP:
  579. if (FIsWin95) {
  580. //WinHelpA(hwndDlg, (LPSTR) pviewhelp->pcvctl->szHelpFileName,
  581. // HELP_CONTEXT, pviewhelp->pcvctl->dwHelpId);
  582. }
  583. else {
  584. //WinHelpW(hwndDlg, pviewhelp->pcvctl->szHelpFileName, HELP_CONTEXT,
  585. // pviewhelp->pcvctl->dwHelpId);
  586. }
  587. return TRUE;
  588. case LVN_ITEMCHANGING:
  589. pnmv = (LPNMLISTVIEW) lParam;
  590. switch(((NMHDR FAR *) lParam)->idFrom)
  591. {
  592. case IDC_CTL_TRUSTLIST_CERTVALUE_LIST:
  593. hWndListView = GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_CERTVALUE_LIST);
  594. //
  595. // if this item is being de-selected, then save it's index incase we need to
  596. // re-select it
  597. if ((pnmv->uOldState & LVIS_SELECTED) || (pnmv->uOldState & LVIS_FOCUSED))
  598. {
  599. pviewhelp->previousSelection = pnmv->iItem;
  600. }
  601. //
  602. //
  603. // if the new item selected is the "Additional Attributes" header, then
  604. // don't allow it to be selected
  605. //
  606. if (pnmv->uNewState & LVIS_SELECTED)
  607. {
  608. memset(&lvI, 0, sizeof(lvI));
  609. lvI.iItem = pnmv->iItem;
  610. lvI.mask = LVIF_TEXT;
  611. lvI.pszText = szText;
  612. lvI.cchTextMax = ARRAYSIZE(szText);
  613. if (!ListView_GetItemU(hWndListView, &lvI))
  614. {
  615. return FALSE;
  616. }
  617. LoadStringU(HinstDll, IDS_ADDITIONAL_ATTRIBUTES, szCompareText, ARRAYSIZE(szCompareText));
  618. if (wcscmp(szCompareText, szText) == 0)
  619. {
  620. if (pnmv->iItem == pviewhelp->previousSelection-1)
  621. {
  622. pviewhelp->currentSelection = pviewhelp->previousSelection-2;
  623. }
  624. else if (pnmv->iItem == pviewhelp->previousSelection+1)
  625. {
  626. pviewhelp->currentSelection = pviewhelp->previousSelection+2;
  627. }
  628. else
  629. {
  630. pviewhelp->currentSelection = pviewhelp->previousSelection;
  631. }
  632. ListView_SetItemState(
  633. GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_CERTVALUE_LIST),
  634. pviewhelp->currentSelection,
  635. LVIS_SELECTED | LVIS_FOCUSED,
  636. LVIS_SELECTED | LVIS_FOCUSED);
  637. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)TRUE);
  638. }
  639. else
  640. {
  641. pviewhelp->currentSelection = pnmv->iItem;
  642. }
  643. DisplayHelperTextInEdit(
  644. GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_CERTVALUE_LIST),
  645. hwndDlg,
  646. IDC_CTL_TRUSTLIST_DETAIL_EDIT,
  647. pviewhelp->currentSelection);
  648. }
  649. break;
  650. case IDC_CTL_TRUSTLIST_CERTIFICATE_LIST:
  651. if (pnmv->uNewState & LVIS_SELECTED)
  652. {
  653. //memcpy(&nmv, pnmv, sizeof(nmv));
  654. //nmv.hdr.code = NM_CLICK;
  655. //SendMessage(hwndDlg, WM_NOTIFY, 0, (LPARAM) &nmv);
  656. hWndListView = GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_CERTIFICATE_LIST);
  657. //
  658. // get the selected item and its corresponding cert context
  659. //
  660. memset(&lvI, 0, sizeof(lvI));
  661. lvI.iItem = pnmv->iItem;
  662. lvI.mask = LVIF_PARAM;
  663. if (!ListView_GetItemU(hWndListView, &lvI))
  664. {
  665. return FALSE;
  666. }
  667. DisplayCertificateValues(
  668. GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_CERTVALUE_LIST),
  669. (PCCERT_CONTEXT) lvI.lParam,
  670. &(pctl->pCtlInfo->rgCTLEntry[pnmv->iItem]));
  671. //
  672. // clear the text in the detail edit box
  673. //
  674. CryptUISetRicheditTextW(hwndDlg, IDC_CTL_TRUSTLIST_DETAIL_EDIT, L"");
  675. //
  676. // enable the "view cert button" based on whether the cert is available or not
  677. //
  678. if (((PCCERT_CONTEXT) lvI.lParam) == NULL)
  679. {
  680. EnableWindow(GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_VIEW_BUTTON), FALSE);
  681. }
  682. else
  683. {
  684. EnableWindow(GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_VIEW_BUTTON), TRUE);
  685. }
  686. DisplayHelperTextInEdit(
  687. GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_CERTVALUE_LIST),
  688. hwndDlg,
  689. IDC_CTL_TRUSTLIST_DETAIL_EDIT,
  690. pviewhelp->currentSelection);
  691. }
  692. break;
  693. }
  694. return TRUE;
  695. case NM_DBLCLK:
  696. switch (((NMHDR FAR *) lParam)->idFrom)
  697. {
  698. case IDC_CTL_TRUSTLIST_CERTIFICATE_LIST:
  699. if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_VIEW_BUTTON)))
  700. {
  701. SendMessage(
  702. hwndDlg,
  703. WM_COMMAND,
  704. MAKELONG(IDC_CTL_GENERAL_VIEW_BUTTON, BN_CLICKED),
  705. (LPARAM) GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_VIEW_BUTTON));
  706. }
  707. break;
  708. }
  709. break;
  710. case NM_CLICK:
  711. pnmv = (LPNMLISTVIEW) lParam;
  712. switch (((NMHDR FAR *) lParam)->idFrom)
  713. {
  714. case IDC_CTL_TRUSTLIST_CERTIFICATE_LIST:
  715. // FALL THROUGH!! - do this so everything gets updated
  716. // break;
  717. case IDC_CTL_TRUSTLIST_CERTVALUE_LIST:
  718. ListView_SetItemState(
  719. GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_CERTVALUE_LIST),
  720. pviewhelp->currentSelection,
  721. LVIS_SELECTED | LVIS_FOCUSED,
  722. LVIS_SELECTED | LVIS_FOCUSED);
  723. DisplayHelperTextInEdit(
  724. GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_CERTVALUE_LIST),
  725. hwndDlg,
  726. IDC_CTL_TRUSTLIST_DETAIL_EDIT,
  727. pviewhelp->currentSelection);
  728. break;
  729. }
  730. break;
  731. case NM_SETFOCUS:
  732. switch (((NMHDR FAR *) lParam)->idFrom)
  733. {
  734. case IDC_CTL_TRUSTLIST_CERTIFICATE_LIST:
  735. hWndListView = GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_CERTIFICATE_LIST);
  736. if ((ListView_GetItemCount(hWndListView) != 0) &&
  737. (ListView_GetNextItem(hWndListView, -1, LVNI_SELECTED) == -1))
  738. {
  739. memset(&lvI, 0, sizeof(lvI));
  740. lvI.mask = LVIF_STATE;
  741. lvI.iItem = 0;
  742. lvI.state = LVIS_FOCUSED;
  743. lvI.stateMask = LVIS_FOCUSED;
  744. ListView_SetItem(hWndListView, &lvI);
  745. }
  746. break;
  747. case IDC_CTL_TRUSTLIST_CERTVALUE_LIST:
  748. hWndListView = GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_CERTVALUE_LIST);
  749. if ((ListView_GetItemCount(hWndListView) != 0) &&
  750. (ListView_GetNextItem(hWndListView, -1, LVNI_SELECTED) == -1))
  751. {
  752. memset(&lvI, 0, sizeof(lvI));
  753. lvI.mask = LVIF_STATE;
  754. lvI.iItem = 0;
  755. lvI.state = LVIS_SELECTED | LVIS_FOCUSED;
  756. lvI.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  757. ListView_SetItem(hWndListView, &lvI);
  758. }
  759. break;
  760. }
  761. break;
  762. }
  763. break;
  764. case WM_COMMAND:
  765. pviewhelp = (CTL_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  766. pctl = pviewhelp->pcvctl->pCTLContext;
  767. pCtlInfo = pctl->pCtlInfo;
  768. switch (LOWORD(wParam))
  769. {
  770. case IDC_CTL_GENERAL_VIEW_BUTTON:
  771. if (HIWORD(wParam) == BN_CLICKED)
  772. {
  773. CRYPTUI_VIEWCERTIFICATE_STRUCTW cvps;
  774. hWndListView = GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_CERTIFICATE_LIST);
  775. //
  776. // get the selected item and its corresponding cert context
  777. //
  778. listIndex = ListView_GetNextItem(
  779. hWndListView,
  780. -1,
  781. LVNI_SELECTED
  782. );
  783. memset(&lvI, 0, sizeof(lvI));
  784. lvI.iItem = listIndex;
  785. lvI.mask = LVIF_PARAM;
  786. if (!ListView_GetItemU(hWndListView, &lvI))
  787. {
  788. return FALSE;
  789. }
  790. memset(&cvps, 0, sizeof(cvps));
  791. cvps.dwSize = sizeof(cvps);
  792. cvps.hwndParent = hwndDlg;
  793. cvps.pCertContext = (PCCERT_CONTEXT) lvI.lParam;
  794. cvps.cStores = pviewhelp->pcvctl->cStores;
  795. cvps.rghStores = pviewhelp->pcvctl->rghStores;
  796. //cvps.dwFlags = CRYPTUI_IGNORE_UNTRUSTED_ROOT;
  797. CryptUIDlgViewCertificateW(&cvps, NULL);
  798. }
  799. break;
  800. case IDHELP:
  801. if (FIsWin95) {
  802. //WinHelpA(hwndDlg, (LPSTR) pviewhelp->pcvctl->szHelpFileName,
  803. // HELP_CONTEXT, pviewhelp->pcvctl->dwHelpId);
  804. }
  805. else {
  806. //WinHelpW(hwndDlg, pviewhelp->pcvctl->szHelpFileName, HELP_CONTEXT,
  807. // pviewhelp->pcvctl->dwHelpId);
  808. }
  809. return TRUE;
  810. }
  811. break;
  812. case WM_DESTROY:
  813. pviewhelp = (CTL_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  814. if (pviewhelp->chStores != 0)
  815. {
  816. FreeAndCloseKnownStores(pviewhelp->chStores, pviewhelp->phStores);
  817. }
  818. //
  819. // get all the items in the list view and free the lParam
  820. // associated with each of them (lParam is the helper sruct)
  821. //
  822. hWndListView = GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_CERTVALUE_LIST);
  823. memset(&lvI, 0, sizeof(lvI));
  824. lvI.iItem = ListView_GetItemCount(hWndListView) - 1;
  825. lvI.mask = LVIF_PARAM;
  826. while (lvI.iItem >= 0)
  827. {
  828. if (ListView_GetItemU(hWndListView, &lvI))
  829. {
  830. FreeListDisplayHelper((PLIST_DISPLAY_HELPER) lvI.lParam);
  831. }
  832. lvI.iItem--;
  833. }
  834. break;
  835. case WM_HELP:
  836. case WM_CONTEXTMENU:
  837. if (msg == WM_HELP)
  838. {
  839. hwnd = GetDlgItem(hwndDlg, ((LPHELPINFO)lParam)->iCtrlId);
  840. }
  841. else
  842. {
  843. hwnd = (HWND) wParam;
  844. }
  845. if ((hwnd != GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_CERTIFICATE_LIST)) &&
  846. (hwnd != GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_CERTVALUE_LIST)) &&
  847. (hwnd != GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_DETAIL_EDIT)) &&
  848. (hwnd != GetDlgItem(hwndDlg, IDC_CTL_TRUSTLIST_VIEW_BUTTON)))
  849. {
  850. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)TRUE);
  851. return TRUE;
  852. }
  853. else
  854. {
  855. return OnContextHelp(hwndDlg, msg, wParam, lParam, helpmap);
  856. }
  857. }
  858. return FALSE;
  859. }