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.

771 lines
27 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: cvhrchy.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "global.hxx"
  11. #include <dbgdef.h>
  12. // Fix a Win95 problem
  13. /*#undef TVM_SETITEM
  14. #define TVM_SETITEM TVM_SETITEMA
  15. #undef TVM_GETITEM
  16. #define TVM_GETITEM TVM_GETITEMA*/
  17. extern HINSTANCE HinstDll;
  18. extern HMODULE HmodRichEdit;
  19. #define MY_TREE_IMAGE_STATE_VALIDCERT 0
  20. #define MY_TREE_IMAGE_STATE_INVALIDCERT 1
  21. #define MY_TREE_IMAGE_STATE_VALIDCTL 2
  22. #define MY_TREE_IMAGE_STATE_INVALIDCTL 3
  23. #define MY_TREE_IMAGE_STATE_EXCLAMATION_CERT 4
  24. static const HELPMAP helpmap[] = {
  25. {IDC_TRUST_TREE, IDH_CERTVIEW_HIERARCHY_TRUST_TREE},
  26. {IDC_TRUST_VIEW, IDH_CERTVIEW_HIERARCHY_SHOW_DETAILS_BUTTON},
  27. {IDC_HIERARCHY_EDIT, IDH_CERTVIEW_HIERARCHY_ERROR_EDIT}
  28. };
  29. typedef struct {
  30. PCCERT_CONTEXT pCert;
  31. PCCTL_CONTEXT pCTL;
  32. LPWSTR pwszErrorString;
  33. } TREEVIEW_HELPER, *PTREEVIEW_HELPER;
  34. //////////////////////////////////////////////////////////////////////////////////////
  35. //
  36. //////////////////////////////////////////////////////////////////////////////////////
  37. static PTREEVIEW_HELPER MakeHelperStruct(void *pVoid, LPWSTR pwszErrorString, BOOL fCTL)
  38. {
  39. PTREEVIEW_HELPER pHelper;
  40. if (NULL == (pHelper = (PTREEVIEW_HELPER) malloc(sizeof(TREEVIEW_HELPER))))
  41. {
  42. return NULL;
  43. }
  44. memset(pHelper, 0, sizeof(TREEVIEW_HELPER));
  45. if (fCTL)
  46. {
  47. pHelper->pCTL = (PCCTL_CONTEXT) pVoid;
  48. }
  49. else
  50. {
  51. pHelper->pCert = (PCCERT_CONTEXT) pVoid;
  52. }
  53. pHelper->pwszErrorString = pwszErrorString;
  54. return(pHelper);
  55. }
  56. //////////////////////////////////////////////////////////////////////////////////////
  57. //
  58. //////////////////////////////////////////////////////////////////////////////////////
  59. static void FreeHelperStruct(PTREEVIEW_HELPER pHelper)
  60. {
  61. free(pHelper->pwszErrorString);
  62. free(pHelper);
  63. }
  64. //////////////////////////////////////////////////////////////////////////////////////
  65. //
  66. //////////////////////////////////////////////////////////////////////////////////////
  67. static BOOL GetTreeCTLErrorString(
  68. DWORD dwError,
  69. LPWSTR *ppwszErrorString)
  70. {
  71. WCHAR szErrorString[CRYPTUI_MAX_STRING_SIZE];
  72. BOOL fRet = FALSE;
  73. *ppwszErrorString = NULL;
  74. if (dwError == TRUST_E_CERT_SIGNATURE)
  75. {
  76. LoadStringU(HinstDll, IDS_SIGNATURE_ERROR_CTL, szErrorString, ARRAYSIZE(szErrorString));
  77. if (NULL != (*ppwszErrorString = AllocAndCopyWStr(szErrorString)))
  78. {
  79. fRet = TRUE;
  80. }
  81. }
  82. else if (dwError == CERT_E_EXPIRED)
  83. {
  84. LoadStringU(HinstDll, IDS_EXPIRED_ERROR_CTL, szErrorString, ARRAYSIZE(szErrorString));
  85. if (NULL != (*ppwszErrorString = AllocAndCopyWStr(szErrorString)))
  86. {
  87. fRet = TRUE;
  88. }
  89. }
  90. else if (dwError == CERT_E_WRONG_USAGE)
  91. {
  92. LoadStringU(HinstDll, IDS_WRONG_USAGE_ERROR_CTL, szErrorString, ARRAYSIZE(szErrorString));
  93. if (NULL != (*ppwszErrorString = AllocAndCopyWStr(szErrorString)))
  94. {
  95. fRet = TRUE;
  96. }
  97. }
  98. //
  99. // if there wasn't an error string set, then hand back the "CTL is OK" string
  100. //
  101. if (*ppwszErrorString == NULL)
  102. {
  103. LoadStringU(HinstDll, IDS_CTLOK, szErrorString, ARRAYSIZE(szErrorString));
  104. *ppwszErrorString = AllocAndCopyWStr(szErrorString);
  105. }
  106. return fRet;
  107. }
  108. //////////////////////////////////////////////////////////////////////////////////////
  109. //
  110. //////////////////////////////////////////////////////////////////////////////////////
  111. static int GetErrorIcon(PCRYPT_PROVIDER_CERT pCryptProviderCert)
  112. {
  113. int iRet;
  114. switch (pCryptProviderCert->dwError)
  115. {
  116. case CERT_E_CHAINING:
  117. case TRUST_E_BASIC_CONSTRAINTS:
  118. case CERT_E_PURPOSE:
  119. case CERT_E_WRONG_USAGE:
  120. case CERT_E_REVOCATION_FAILURE:
  121. case CERT_E_INVALID_NAME:
  122. iRet = MY_TREE_IMAGE_STATE_EXCLAMATION_CERT;
  123. break;
  124. default:
  125. if ((pCryptProviderCert->dwError == 0) && CertHasEmptyEKUProp(pCryptProviderCert->pCert))
  126. {
  127. iRet = MY_TREE_IMAGE_STATE_EXCLAMATION_CERT;
  128. }
  129. else
  130. {
  131. iRet = MY_TREE_IMAGE_STATE_INVALIDCERT;
  132. }
  133. break;
  134. }
  135. return iRet;
  136. }
  137. //////////////////////////////////////////////////////////////////////////////////////
  138. //
  139. //////////////////////////////////////////////////////////////////////////////////////
  140. static BOOL GetTreeCertErrorStringAndImage(
  141. PCRYPT_PROVIDER_CERT pCryptProviderCert,
  142. LPWSTR *ppwszErrorString,
  143. int *piImage,
  144. BOOL fWarnUntrustedRoot,
  145. BOOL fRootInRemoteStore,
  146. BOOL fLeafCert,
  147. BOOL fAllUsagesFailed)
  148. {
  149. WCHAR szErrorString[CRYPTUI_MAX_STRING_SIZE];
  150. BOOL fRet = FALSE;
  151. BOOL fAllUsagesFailedAndLeafCert = fAllUsagesFailed && fLeafCert;
  152. *ppwszErrorString = NULL;
  153. //
  154. // if this is a self signed cert
  155. //
  156. if ((pCryptProviderCert->fSelfSigned))
  157. {
  158. //
  159. // if it is in a trust list, AND there is no error, then it is OK
  160. //
  161. if ((pCryptProviderCert->pCtlContext != NULL) && (pCryptProviderCert->dwError == 0) && !CertHasEmptyEKUProp(pCryptProviderCert->pCert))
  162. {
  163. *ppwszErrorString = NULL;
  164. }
  165. //
  166. // else, if is not marked as a trusted root, and we in fWarnUntrustedRoot mode and
  167. // the root cert is in the root store of the remote machine, then give warning
  168. //
  169. else if (((pCryptProviderCert->dwError == CERT_E_UNTRUSTEDROOT) ||
  170. (pCryptProviderCert->dwError == CERT_E_UNTRUSTEDTESTROOT)) &&
  171. fWarnUntrustedRoot &&
  172. fRootInRemoteStore)
  173. {
  174. //
  175. // this is a special case where there is an error, but it is the untrusted
  176. // root error and we were told to by the caller to just warn the user
  177. //
  178. LoadStringU(HinstDll, IDS_WARNUNTRUSTEDROOT_ERROR_ROOTCERT, szErrorString, ARRAYSIZE(szErrorString));
  179. if (NULL != (*ppwszErrorString = AllocAndCopyWStr(szErrorString)))
  180. {
  181. fRet = TRUE;
  182. *piImage = MY_TREE_IMAGE_STATE_EXCLAMATION_CERT;
  183. }
  184. }
  185. //
  186. // else, if it is not marked as a trusted root it is an untrusted root error
  187. //
  188. else if ((pCryptProviderCert->dwError == CERT_E_UNTRUSTEDROOT)
  189. || (pCryptProviderCert->dwError == CERT_E_UNTRUSTEDTESTROOT))
  190. {
  191. LoadStringU(HinstDll, IDS_UNTRUSTEDROOT_ERROR, szErrorString, ARRAYSIZE(szErrorString));
  192. if (NULL != (*ppwszErrorString = AllocAndCopyWStr(szErrorString)))
  193. {
  194. fRet = TRUE;
  195. *piImage = MY_TREE_IMAGE_STATE_INVALIDCERT;
  196. }
  197. }
  198. else if (GetCertErrorString(ppwszErrorString, pCryptProviderCert))
  199. {
  200. fRet = TRUE;
  201. *piImage = GetErrorIcon(pCryptProviderCert);
  202. }
  203. }
  204. else
  205. {
  206. if (GetCertErrorString(ppwszErrorString, pCryptProviderCert))
  207. {
  208. fRet = TRUE;
  209. *piImage = GetErrorIcon(pCryptProviderCert);
  210. }
  211. }
  212. //
  213. // if there wasn't an error string set, then hand back the "cert is OK" string
  214. //
  215. if (*ppwszErrorString == NULL)
  216. {
  217. LoadStringU(HinstDll, IDS_CERTIFICATEOK_TREE, szErrorString, ARRAYSIZE(szErrorString));
  218. *ppwszErrorString = AllocAndCopyWStr(szErrorString);
  219. *piImage = MY_TREE_IMAGE_STATE_VALIDCERT;
  220. }
  221. return fRet;
  222. }
  223. //////////////////////////////////////////////////////////////////////////////////////
  224. //
  225. //////////////////////////////////////////////////////////////////////////////////////
  226. static void DeleteChainViewItems(HWND hwndDlg, PCERT_VIEW_HELPER pviewhelp)
  227. {
  228. HTREEITEM hItem;
  229. TV_ITEM tvi;
  230. HWND hWndTreeView = GetDlgItem(hwndDlg, IDC_TRUST_TREE);
  231. hItem = TreeView_GetNextItem(
  232. hWndTreeView,
  233. NULL,
  234. TVGN_ROOT);
  235. tvi.mask = TVIF_HANDLE | TVIF_PARAM;
  236. while (hItem != NULL)
  237. {
  238. tvi.hItem = hItem;
  239. TreeView_GetItem(hWndTreeView, &tvi);
  240. FreeHelperStruct((PTREEVIEW_HELPER) tvi.lParam);
  241. hItem = TreeView_GetNextItem(
  242. hWndTreeView,
  243. hItem,
  244. TVGN_CHILD);
  245. }
  246. pviewhelp->fDeletingChain = TRUE;
  247. TreeView_DeleteAllItems(hWndTreeView);
  248. pviewhelp->fDeletingChain = FALSE;
  249. }
  250. //////////////////////////////////////////////////////////////////////////////////////
  251. //
  252. //////////////////////////////////////////////////////////////////////////////////////
  253. static void PopulateChainView(HWND hwndDlg, PCERT_VIEW_HELPER pviewhelp)
  254. {
  255. HTREEITEM hItem;
  256. int i;
  257. TV_ITEM tvi;
  258. TVINSERTSTRUCTW tvins;
  259. LPSTR psz;
  260. LPWSTR pwszErrorString;
  261. WCHAR rgwch[CRYPTUI_MAX_STRING_SIZE];
  262. //
  263. // if there is an old tree in the view then clean it up
  264. //
  265. DeleteChainViewItems(hwndDlg, pviewhelp);
  266. //
  267. // loop for each cert and add it to the chain view
  268. //
  269. tvins.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
  270. hItem = TVI_ROOT;
  271. pviewhelp->fAddingToChain = TRUE;
  272. for (i=pviewhelp->cpCryptProviderCerts-1; i>= 0; i--) {
  273. tvins.hParent = hItem;
  274. tvins.hInsertAfter = TVI_FIRST;
  275. //
  276. // if this cert has a CTL context on it, then display that as the
  277. // parent of this cert
  278. //
  279. if (pviewhelp->rgpCryptProviderCerts[i]->pCtlContext != NULL)
  280. {
  281. LoadStringU(HinstDll, IDS_CTLVIEW_TITLE, rgwch, ARRAYSIZE(rgwch));
  282. psz = CertUIMkMBStr(rgwch);
  283. tvins.item.pszText = rgwch;
  284. tvins.item.cchTextMax = wcslen(rgwch);
  285. //
  286. // display the proper image based on whether there is a CTL error or not
  287. //
  288. if (GetTreeCTLErrorString(
  289. pviewhelp->rgpCryptProviderCerts[i]->dwCtlError,
  290. &pwszErrorString))
  291. {
  292. tvins.item.iImage = MY_TREE_IMAGE_STATE_INVALIDCTL;
  293. }
  294. else
  295. {
  296. tvins.item.iImage = MY_TREE_IMAGE_STATE_VALIDCTL;
  297. }
  298. tvins.item.iSelectedImage = tvins.item.iImage;
  299. tvins.item.lParam = (LPARAM) MakeHelperStruct(
  300. (void *)pviewhelp->rgpCryptProviderCerts[i]->pCtlContext,
  301. pwszErrorString,
  302. TRUE);
  303. hItem = (HTREEITEM) SendMessage(GetDlgItem(hwndDlg, IDC_TRUST_TREE), TVM_INSERTITEMW, 0, (LPARAM) &tvins);
  304. if (i != (int) (pviewhelp->cpCryptProviderCerts-1))
  305. {
  306. TreeView_Expand(GetDlgItem(hwndDlg, IDC_TRUST_TREE),
  307. tvins.hParent, TVE_EXPAND);
  308. }
  309. //
  310. // set up the parent to insert the cert
  311. //
  312. tvins.hParent = hItem;
  313. free(psz);
  314. }
  315. //
  316. // get the display string for the tree view item
  317. //
  318. tvins.item.pszText = PrettySubject(pviewhelp->rgpCryptProviderCerts[i]->pCert);
  319. if (tvins.item.pszText == NULL)
  320. {
  321. LPWSTR pwszNone = NULL;
  322. if (NULL == (pwszNone = (LPWSTR) malloc((MAX_TITLE_LENGTH + 1) * sizeof(WCHAR))))
  323. {
  324. break;
  325. }
  326. // load the string for NONE
  327. if(!LoadStringU(g_hmodThisDll, IDS_NONE, pwszNone, MAX_TITLE_LENGTH))
  328. {
  329. free(pwszNone);
  330. break;
  331. }
  332. tvins.item.pszText = pwszNone;
  333. }
  334. tvins.item.cchTextMax = wcslen(tvins.item.pszText);
  335. //
  336. // check if the cert is trusted by trying to get an error string for the cert,
  337. // set the the tree view image for the cert based on that
  338. //
  339. GetTreeCertErrorStringAndImage(
  340. pviewhelp->rgpCryptProviderCerts[i],
  341. &pwszErrorString,
  342. &(tvins.item.iImage),
  343. pviewhelp->fWarnUntrustedRoot,
  344. pviewhelp->fRootInRemoteStore,
  345. (i == 0),
  346. (pviewhelp->cUsages == 0));
  347. tvins.item.iSelectedImage = tvins.item.iImage;
  348. tvins.item.lParam = (LPARAM) MakeHelperStruct(
  349. (void *)pviewhelp->rgpCryptProviderCerts[i]->pCert,
  350. pwszErrorString,
  351. FALSE);
  352. hItem = (HTREEITEM) SendMessage(GetDlgItem(hwndDlg, IDC_TRUST_TREE), TVM_INSERTITEMW, 0, (LPARAM) &tvins);
  353. if ((i != (int) (pviewhelp->cpCryptProviderCerts-1)) ||
  354. (pviewhelp->rgpCryptProviderCerts[i]->pCtlContext != NULL))
  355. {
  356. TreeView_Expand(GetDlgItem(hwndDlg, IDC_TRUST_TREE),
  357. tvins.hParent, TVE_EXPAND);
  358. }
  359. TreeView_SelectItem(GetDlgItem(hwndDlg, IDC_TRUST_TREE), hItem);
  360. free(tvins.item.pszText);
  361. tvins.item.pszText = NULL;
  362. }
  363. pviewhelp->fAddingToChain = FALSE;
  364. pviewhelp->hItem = hItem;
  365. }
  366. //////////////////////////////////////////////////////////////////////////////////////
  367. //
  368. //////////////////////////////////////////////////////////////////////////////////////
  369. INT_PTR APIENTRY ViewPageHierarchy(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  370. {
  371. DWORD cb;
  372. HIMAGELIST hIml;
  373. HTREEITEM hItem;
  374. int i;
  375. PCCERT_CONTEXT pccert;
  376. PROPSHEETPAGE * ps;
  377. CERT_VIEW_HELPER *pviewhelp;
  378. LPWSTR pwsz;
  379. TV_ITEM tvi;
  380. LPNMTREEVIEW pnmtv;
  381. LPWSTR pwszErrorString;
  382. HWND hwnd;
  383. WCHAR szViewButton[CRYPTUI_MAX_STRING_SIZE];
  384. LPNMHDR pnm;
  385. switch ( msg ) {
  386. case WM_INITDIALOG:
  387. // Pick up the parameter so we have all of the data
  388. ps = (PROPSHEETPAGE *) lParam;
  389. pviewhelp = (CERT_VIEW_HELPER *) (ps->lParam);
  390. pccert = pviewhelp->pcvp->pCertContext;
  391. SetWindowLongPtr(hwndDlg, DWLP_USER, (DWORD_PTR) pviewhelp);
  392. pviewhelp->hwndHierarchyPage = hwndDlg;
  393. //
  394. // Build up the image list for the control
  395. //
  396. hIml = ImageList_LoadImage(HinstDll, MAKEINTRESOURCE(IDB_TRUSTTREE_BITMAP), 16, 5, RGB(255,0,255), IMAGE_BITMAP, 0);
  397. if (hIml != NULL)
  398. {
  399. TreeView_SetImageList(GetDlgItem(hwndDlg, IDC_TRUST_TREE), hIml, TVSIL_NORMAL);
  400. }
  401. //
  402. // Populate the tree control
  403. //
  404. PopulateChainView(hwndDlg, pviewhelp);
  405. EnableWindow(GetDlgItem(hwndDlg, IDC_TRUST_VIEW), FALSE);
  406. // Init of state var
  407. pviewhelp->fDblClk = FALSE;
  408. return TRUE;
  409. case WM_MY_REINITIALIZE:
  410. pviewhelp = (CERT_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  411. //
  412. // Re-Populate the tree control
  413. //
  414. PopulateChainView(hwndDlg, pviewhelp);
  415. TreeView_SelectItem(GetDlgItem(hwndDlg, IDC_TRUST_TREE), NULL);
  416. EnableWindow(GetDlgItem(hwndDlg, IDC_TRUST_VIEW), FALSE);
  417. //
  418. // clear out the error detail edit box
  419. //
  420. CryptUISetRicheditTextW(hwndDlg, IDC_HIERARCHY_EDIT, L"");
  421. return TRUE;
  422. case WM_NOTIFY:
  423. pviewhelp = (CERT_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  424. switch (((NMHDR FAR *) lParam)->code) {
  425. case PSN_SETACTIVE:
  426. break;
  427. case PSN_APPLY:
  428. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)FALSE);
  429. break;
  430. case PSN_KILLACTIVE:
  431. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)FALSE);
  432. return TRUE;
  433. case PSN_RESET:
  434. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)FALSE);
  435. break;
  436. case PSN_QUERYCANCEL:
  437. pviewhelp->fCancelled = TRUE;
  438. return FALSE;
  439. case TVN_SELCHANGEDA:
  440. case TVN_SELCHANGEDW:
  441. pviewhelp = (CERT_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  442. if ((!pviewhelp->fDeletingChain) &&
  443. (((NM_TREEVIEW *) lParam)->itemNew.hItem != NULL))
  444. {
  445. EnableWindow(GetDlgItem(hwndDlg, IDC_TRUST_VIEW),
  446. ((NM_TREEVIEW *) lParam)->itemNew.hItem != pviewhelp->hItem);
  447. tvi.mask = TVIF_HANDLE | TVIF_PARAM;
  448. tvi.hItem = ((NM_TREEVIEW *) lParam)->itemNew.hItem;
  449. TreeView_GetItem(GetDlgItem(hwndDlg, IDC_TRUST_TREE), &tvi);
  450. CryptUISetRicheditTextW(hwndDlg, IDC_HIERARCHY_EDIT, ((PTREEVIEW_HELPER) tvi.lParam)->pwszErrorString);
  451. //
  452. // set the text on the button based on whether a cert or CTL is selected
  453. //
  454. if (((PTREEVIEW_HELPER) tvi.lParam)->pCTL == NULL)
  455. {
  456. LoadStringU(HinstDll, IDS_VIEW_CERTIFICATE, szViewButton, ARRAYSIZE(szViewButton));
  457. }
  458. else
  459. {
  460. LoadStringU(HinstDll, IDS_VIEW_CTL, szViewButton, ARRAYSIZE(szViewButton));
  461. }
  462. SetDlgItemTextU(hwndDlg, IDC_TRUST_VIEW, szViewButton);
  463. }
  464. break;
  465. case PSN_HELP:
  466. pviewhelp = (CERT_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  467. if (FIsWin95) {
  468. //WinHelpA(hwndDlg, (LPSTR) pviewhelp->pcvp->szHelpFileName,
  469. // HELP_CONTEXT, pviewhelp->pcvp->dwHelpId);
  470. }
  471. else {
  472. //WinHelpW(hwndDlg, pviewhelp->pcvp->szHelpFileName, HELP_CONTEXT,
  473. // pviewhelp->pcvp->dwHelpId);
  474. }
  475. return TRUE;
  476. case TVN_ITEMEXPANDINGA:
  477. case TVN_ITEMEXPANDINGW:
  478. pnmtv = (LPNMTREEVIEW) lParam;
  479. if (!pviewhelp->fAddingToChain)
  480. {
  481. if (pnmtv->action == TVE_COLLAPSE)
  482. {
  483. HTREEITEM hParentItem = TreeView_GetParent(GetDlgItem(hwndDlg, IDC_TRUST_TREE), pnmtv->itemNew.hItem);
  484. if ((hParentItem != NULL) && (!pviewhelp->fDblClk))
  485. {
  486. TreeView_SelectItem(GetDlgItem(hwndDlg, IDC_TRUST_TREE), hParentItem);
  487. }
  488. else
  489. {
  490. pviewhelp->fDblClk = FALSE;
  491. }
  492. }
  493. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)TRUE);
  494. }
  495. return TRUE;
  496. case NM_DBLCLK:
  497. pnm = (LPNMHDR) lParam;
  498. hItem = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_TRUST_TREE));
  499. if (TreeView_GetChild(GetDlgItem(hwndDlg, IDC_TRUST_TREE), hItem) != NULL)
  500. {
  501. SendMessage(hwndDlg, WM_COMMAND, MAKELONG(IDC_TRUST_VIEW, BN_CLICKED), (LPARAM) GetDlgItem(hwndDlg, IDC_TRUST_VIEW));
  502. }
  503. if (hItem != pviewhelp->hItem)
  504. {
  505. pviewhelp->fDblClk = TRUE;
  506. }
  507. break;
  508. }
  509. break;
  510. case WM_COMMAND:
  511. switch (LOWORD(wParam)) {
  512. case IDC_TRUST_VIEW:
  513. if (HIWORD(wParam) == BN_CLICKED)
  514. {
  515. CRYPTUI_VIEWCERTIFICATE_STRUCTW cvps;
  516. CRYPTUI_VIEWCTL_STRUCTW cvctl;
  517. BOOL fPropertiesChanged;
  518. PTREEVIEW_HELPER pTreeViewHelper;
  519. pviewhelp = (CERT_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  520. hItem = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_TRUST_TREE));
  521. tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_CHILDREN;
  522. tvi.hItem = hItem;
  523. TreeView_GetItem(GetDlgItem(hwndDlg, IDC_TRUST_TREE), &tvi);
  524. pTreeViewHelper = (PTREEVIEW_HELPER) tvi.lParam;
  525. //
  526. // check to see if we are viewing a cert or a ctl
  527. //
  528. if (pTreeViewHelper->pCTL != NULL)
  529. {
  530. memset(&cvctl, 0, sizeof(CRYPTUI_VIEWCTL_STRUCTW));
  531. cvctl.dwSize = sizeof(CRYPTUI_VIEWCTL_STRUCTW);
  532. cvctl.hwndParent = hwndDlg;
  533. cvctl.pCTLContext = pTreeViewHelper->pCTL;
  534. cvctl.cCertSearchStores = pviewhelp->pcvp->cStores;
  535. cvctl.rghCertSearchStores = pviewhelp->pcvp->rghStores;
  536. cvctl.cStores = pviewhelp->pcvp->cStores;
  537. cvctl.rghStores = pviewhelp->pcvp->rghStores;
  538. CryptUIDlgViewCTLW(&cvctl);
  539. }
  540. else
  541. {
  542. memcpy(&cvps, pviewhelp->pcvp, sizeof(cvps));
  543. cvps.hwndParent = hwndDlg;
  544. cvps.pCertContext = pTreeViewHelper->pCert;
  545. // Set this flag to inhibit the deletion of the
  546. // CERT_EXTENDED_ERROR_INFO_PROP_ID property which is
  547. // set on the CA certs when building the original chain
  548. // for the end certificate.
  549. //
  550. cvps.dwFlags |= CRYPTUI_TREEVIEW_PAGE_FLAG;
  551. #if (0) // DSIE: Do not carry the state over. People get so confused when the state is carried
  552. // over. So, always rebuild the state, and treat it as new context. Beside, by
  553. // carrying the state over, it will have problem showing when there is more
  554. // than one policy OID, as WinVerifyTrust can only handle one policy OID to be
  555. // passed in.
  556. //
  557. // Use the proper WinVerifyTrust state... either the one passed
  558. // in or the one built internally if one was not passed in
  559. //
  560. if (pviewhelp->pcvp->hWVTStateData == NULL)
  561. {
  562. cvps.hWVTStateData = pviewhelp->sWTD.hWVTStateData;
  563. }
  564. #endif
  565. //
  566. // see where this item is in the chain
  567. //
  568. while (NULL != (hItem = TreeView_GetChild(GetDlgItem(hwndDlg, IDC_TRUST_TREE), hItem)))
  569. {
  570. //
  571. // get the TreeViewHelper and make sure this item is a cert,
  572. // if it is, then increase the count, otherwise if it is a CTL
  573. // don't count it because CTL's hang off the CryptProviderCert
  574. // structure, so they don't take up an index themselves
  575. //
  576. tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_CHILDREN;
  577. tvi.hItem = hItem;
  578. TreeView_GetItem(GetDlgItem(hwndDlg, IDC_TRUST_TREE), &tvi);
  579. pTreeViewHelper = (PTREEVIEW_HELPER) tvi.lParam;
  580. if (pTreeViewHelper->pCert != NULL)
  581. {
  582. cvps.idxCert++;
  583. }
  584. }
  585. //cvps.pCryptProviderData = NULL;
  586. i = CryptUIDlgViewCertificateW(&cvps, &fPropertiesChanged);
  587. //
  588. // if properties changed whiled editing the parent, then
  589. // we need to let our caller know, and we need to refresh
  590. //
  591. if (fPropertiesChanged)
  592. {
  593. if (pviewhelp->pfPropertiesChanged != NULL)
  594. {
  595. *(pviewhelp->pfPropertiesChanged) = TRUE;
  596. }
  597. //
  598. // since the properties of one of our parents changed, we need
  599. // to redo the trust work and then reset the display
  600. //
  601. BuildChain(pviewhelp, NULL);
  602. if (pviewhelp->hwndGeneralPage != NULL)
  603. {
  604. SendMessage(pviewhelp->hwndGeneralPage, WM_MY_REINITIALIZE, (WPARAM) 0, (LPARAM) 0);
  605. }
  606. SendMessage(hwndDlg, WM_MY_REINITIALIZE, (WPARAM) 0, (LPARAM) 0);
  607. }
  608. }
  609. }
  610. return TRUE;
  611. case IDHELP:
  612. pviewhelp = (CERT_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  613. if (FIsWin95) {
  614. //WinHelpA(hwndDlg, (LPSTR) pviewhelp->pcvp->szHelpFileName,
  615. // HELP_CONTEXT, pviewhelp->pcvp->dwHelpId);
  616. }
  617. else {
  618. //WinHelpW(hwndDlg, pviewhelp->pcvp->szHelpFileName, HELP_CONTEXT,
  619. // pviewhelp->pcvp->dwHelpId);
  620. }
  621. return TRUE;
  622. }
  623. break;
  624. case WM_DESTROY:
  625. pviewhelp = (CERT_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  626. DeleteChainViewItems(hwndDlg, pviewhelp);
  627. ImageList_Destroy(TreeView_GetImageList(GetDlgItem(hwndDlg, IDC_TRUST_TREE), TVSIL_NORMAL));
  628. break;
  629. case WM_HELP:
  630. case WM_CONTEXTMENU:
  631. if (msg == WM_HELP)
  632. {
  633. hwnd = GetDlgItem(hwndDlg, ((LPHELPINFO)lParam)->iCtrlId);
  634. }
  635. else
  636. {
  637. hwnd = (HWND) wParam;
  638. }
  639. if ((hwnd != GetDlgItem(hwndDlg, IDC_TRUST_TREE)) &&
  640. (hwnd != GetDlgItem(hwndDlg, IDC_TRUST_VIEW)) &&
  641. (hwnd != GetDlgItem(hwndDlg, IDC_HIERARCHY_EDIT)))
  642. {
  643. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)TRUE);
  644. return TRUE;
  645. }
  646. else
  647. {
  648. return OnContextHelp(hwndDlg, msg, wParam, lParam, helpmap);
  649. }
  650. }
  651. return FALSE;
  652. }