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.

1127 lines
31 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: disputil.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "global.hxx"
  11. #include <dbgdef.h>
  12. extern HINSTANCE HinstDll;
  13. //////////////////////////////////////////////////////////////////////////////////////
  14. // This function will take a HWND for a list view, OID, and an extension in a bufffer,
  15. // it will then format and display the extension in the list view
  16. //////////////////////////////////////////////////////////////////////////////////////
  17. static void DisplayExtension(HWND hWndListView, LPSTR pszObjId, LPBYTE pbData, DWORD cbData, DWORD index)
  18. {
  19. BYTE *pbFormatedExtension = NULL;
  20. DWORD cbFormatedExtension = 0;
  21. //
  22. // format the extension using the installable formatting function
  23. //
  24. CryptFormatObject(
  25. X509_ASN_ENCODING,
  26. 0,
  27. 0,
  28. NULL,
  29. pszObjId,
  30. pbData,
  31. cbData,
  32. NULL,
  33. &cbFormatedExtension
  34. );
  35. if (NULL == (pbFormatedExtension = (BYTE *) malloc(cbFormatedExtension)))
  36. {
  37. return;
  38. }
  39. if (CryptFormatObject(
  40. X509_ASN_ENCODING,
  41. 0,
  42. 0,
  43. NULL,
  44. pszObjId,
  45. pbData,
  46. cbData,
  47. pbFormatedExtension,
  48. &cbFormatedExtension
  49. ))
  50. {
  51. ListView_SetItemTextU(
  52. hWndListView,
  53. index ,
  54. 1,
  55. (LPWSTR)pbFormatedExtension);
  56. }
  57. free (pbFormatedExtension);
  58. }
  59. //////////////////////////////////////////////////////////////////////////////////////
  60. // This function will take a HWND for a list view, an array of extensions and display
  61. // all the extensions in the list view. It will either display the extensions that
  62. // are critical or non-critical (based on the parameter fCritical)
  63. //////////////////////////////////////////////////////////////////////////////////////
  64. void DisplayExtensions(HWND hWndListView, DWORD cExtension, PCERT_EXTENSION rgExtension, BOOL fCritical, DWORD *index)
  65. {
  66. DWORD i;
  67. WCHAR szText[CRYPTUI_MAX_STRING_SIZE];
  68. LV_ITEMW lvI;
  69. WCHAR pwszText;
  70. //
  71. // set up the fields in the list view item struct that don't change from item to item
  72. //
  73. lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
  74. lvI.state = 0;
  75. lvI.stateMask = 0;
  76. lvI.pszText = szText;
  77. lvI.iSubItem = 0;
  78. if (fCritical)
  79. lvI.iImage = IMAGE_CRITICAL_EXTENSION;
  80. else
  81. lvI.iImage = IMAGE_EXTENSION;
  82. lvI.lParam = (LPARAM)NULL;
  83. //
  84. // loop for each extension
  85. //
  86. for (i=0; i<cExtension; i++)
  87. {
  88. // display only critical or non-critical extensions based on fCritical
  89. if (rgExtension[i].fCritical != fCritical)
  90. {
  91. continue;
  92. }
  93. // add the field to the field column of the list view
  94. if (!MyGetOIDInfo(szText, ARRAYSIZE(szText), rgExtension[i].pszObjId))
  95. {
  96. return;
  97. }
  98. pwszText =
  99. lvI.iItem = (*index)++;
  100. lvI.cchTextMax = wcslen(szText);
  101. lvI.lParam = (LPARAM) MakeListDisplayHelperForExtension(
  102. rgExtension[i].pszObjId,
  103. rgExtension[i].Value.pbData,
  104. rgExtension[i].Value.cbData);
  105. ListView_InsertItemU(hWndListView, &lvI);
  106. DisplayExtension(
  107. hWndListView,
  108. rgExtension[i].pszObjId,
  109. rgExtension[i].Value.pbData,
  110. rgExtension[i].Value.cbData,
  111. (*index)-1);
  112. }
  113. }
  114. //////////////////////////////////////////////////////////////////////////////////////
  115. //
  116. //////////////////////////////////////////////////////////////////////////////////////
  117. PLIST_DISPLAY_HELPER MakeListDisplayHelper(BOOL fHexText, LPWSTR pwszDisplayText, BYTE *pbData, DWORD cbData)
  118. {
  119. PLIST_DISPLAY_HELPER pDisplayHelper;
  120. if (NULL == (pDisplayHelper = (PLIST_DISPLAY_HELPER) malloc(sizeof(LIST_DISPLAY_HELPER))))
  121. {
  122. return NULL;
  123. }
  124. pDisplayHelper->fHexText = fHexText;
  125. pDisplayHelper->pwszDisplayText = pwszDisplayText;
  126. pDisplayHelper->pbData = pbData;
  127. pDisplayHelper->cbData = cbData;
  128. return pDisplayHelper;
  129. }
  130. //////////////////////////////////////////////////////////////////////////////////////
  131. //
  132. //////////////////////////////////////////////////////////////////////////////////////
  133. void FreeListDisplayHelper(PLIST_DISPLAY_HELPER pDisplayHelper)
  134. {
  135. if (pDisplayHelper == NULL)
  136. {
  137. return;
  138. }
  139. if (pDisplayHelper->pwszDisplayText)
  140. free(pDisplayHelper->pwszDisplayText);
  141. if (pDisplayHelper->pbData)
  142. free(pDisplayHelper->pbData);
  143. free(pDisplayHelper);
  144. }
  145. //////////////////////////////////////////////////////////////////////////////////////
  146. //
  147. //////////////////////////////////////////////////////////////////////////////////////
  148. PLIST_DISPLAY_HELPER MakeListDisplayHelperForExtension(LPSTR pszObjId, BYTE *pbData, DWORD cbData)
  149. {
  150. BYTE *pbFormatedExtension = NULL;
  151. DWORD cbFormatedExtension = 0;
  152. //
  153. // format the extension using the installable formatting function if possible,
  154. // otherwise set up the helper with a pointer to plain old bytes
  155. //
  156. if (CryptFormatObject(
  157. X509_ASN_ENCODING,
  158. 0,
  159. CRYPT_FORMAT_STR_MULTI_LINE | CRYPT_FORMAT_STR_NO_HEX,
  160. NULL,
  161. pszObjId,
  162. pbData,
  163. cbData,
  164. NULL,
  165. &cbFormatedExtension
  166. ))
  167. {
  168. if (NULL == (pbFormatedExtension = (BYTE *) malloc(cbFormatedExtension)))
  169. {
  170. return NULL;
  171. }
  172. if (CryptFormatObject(
  173. X509_ASN_ENCODING,
  174. 0,
  175. CRYPT_FORMAT_STR_MULTI_LINE | CRYPT_FORMAT_STR_NO_HEX,
  176. NULL,
  177. pszObjId,
  178. pbData,
  179. cbData,
  180. pbFormatedExtension,
  181. &cbFormatedExtension
  182. ))
  183. {
  184. return MakeListDisplayHelper(FALSE, (LPWSTR) pbFormatedExtension, NULL, 0);
  185. }
  186. }
  187. else
  188. {
  189. if (NULL != (pbFormatedExtension = (BYTE *) malloc(cbData)))
  190. {
  191. memcpy(pbFormatedExtension, pbData, cbData);
  192. }
  193. return MakeListDisplayHelper(TRUE, NULL, pbFormatedExtension, cbData);
  194. }
  195. return NULL;
  196. }
  197. //////////////////////////////////////////////////////////////////////////////////////
  198. //
  199. //////////////////////////////////////////////////////////////////////////////////////
  200. void DisplayHelperTextInEdit(HWND hWndListView, HWND hwndDlg, int nIDEdit, int index)
  201. {
  202. int listIndex;
  203. LVITEMW lvI;
  204. LIST_DISPLAY_HELPER *pDisplayHelper;
  205. HWND hWndEdit;
  206. hWndEdit = GetDlgItem(hwndDlg, nIDEdit);
  207. //
  208. // get the selected item if the index was not passed in
  209. //
  210. if (index == -1)
  211. {
  212. listIndex = ListView_GetNextItem(
  213. hWndListView,
  214. -1,
  215. LVNI_SELECTED
  216. );
  217. }
  218. else
  219. {
  220. listIndex = index;
  221. }
  222. memset(&lvI, 0, sizeof(lvI));
  223. lvI.iItem = listIndex;
  224. lvI.mask = LVIF_PARAM;
  225. if ((lvI.iItem == -1) || !ListView_GetItemU(hWndListView, &lvI))
  226. {
  227. return;
  228. }
  229. pDisplayHelper = (PLIST_DISPLAY_HELPER) lvI.lParam;
  230. if (pDisplayHelper == NULL)
  231. {
  232. return;
  233. }
  234. if (pDisplayHelper->fHexText)
  235. {
  236. SetTextFormatHex(hWndEdit);
  237. }
  238. else
  239. {
  240. SetTextFormatInitial(hWndEdit);
  241. }
  242. if ((pDisplayHelper->fHexText) && (pDisplayHelper->pbData != NULL))
  243. {
  244. FormatMemBufToWindow(
  245. hWndEdit,
  246. pDisplayHelper->pbData,
  247. pDisplayHelper->cbData);
  248. }
  249. else if (pDisplayHelper->pwszDisplayText != NULL)
  250. {
  251. //SetDlgItemTextU(hwndDlg, nIDEdit, pDisplayHelper->pwszDisplayText);
  252. CryptUISetRicheditTextW(hwndDlg, nIDEdit, pDisplayHelper->pwszDisplayText);
  253. }
  254. }
  255. //////////////////////////////////////////////////////////////////////////////////////
  256. //
  257. //////////////////////////////////////////////////////////////////////////////////////
  258. //
  259. // these two functions handle modifying the text font in the field view text box
  260. // on the details tab.
  261. //
  262. static BOOL gfInitialFaceNameSet = FALSE;
  263. static char g_szInitialFaceName[LF_FACESIZE];
  264. static char g_szMonoSpaceFaceName[LF_FACESIZE];
  265. void SetTextFormatInitial(HWND hWnd)
  266. {
  267. CHARFORMAT chFormat;
  268. //
  269. // initialize the global string variables that hold the face name for the details text box
  270. //
  271. if (!gfInitialFaceNameSet)
  272. {
  273. memset(&chFormat, 0, sizeof(chFormat));
  274. chFormat.cbSize = sizeof(chFormat);
  275. chFormat.dwMask = CFM_FACE;
  276. SendMessageA(hWnd, EM_GETCHARFORMAT, SCF_ALL, (LPARAM) &chFormat);
  277. strcpy(g_szInitialFaceName, chFormat.szFaceName);
  278. LoadStringA(HinstDll, IDS_FIELD_TEXT_BOX_FONT, g_szMonoSpaceFaceName, ARRAYSIZE(g_szMonoSpaceFaceName));
  279. gfInitialFaceNameSet = TRUE;
  280. }
  281. memset(&chFormat, 0, sizeof(chFormat));
  282. chFormat.cbSize = sizeof(chFormat);
  283. chFormat.dwMask = CFM_FACE;
  284. strcpy(chFormat.szFaceName, g_szInitialFaceName);
  285. SendMessageA(hWnd, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) &chFormat);
  286. }
  287. void SetTextFormatHex(HWND hWnd)
  288. {
  289. CHARFORMAT chFormat;
  290. //
  291. // initialize the global string variables that hold the face name for the details text box
  292. //
  293. if (!gfInitialFaceNameSet)
  294. {
  295. memset(&chFormat, 0, sizeof(chFormat));
  296. chFormat.cbSize = sizeof(chFormat);
  297. chFormat.dwMask = CFM_FACE;
  298. SendMessageA(hWnd, EM_GETCHARFORMAT, SCF_ALL, (LPARAM) &chFormat);
  299. strcpy(g_szInitialFaceName, chFormat.szFaceName);
  300. LoadStringA(HinstDll, IDS_FIELD_TEXT_BOX_FONT, g_szMonoSpaceFaceName, ARRAYSIZE(g_szMonoSpaceFaceName));
  301. gfInitialFaceNameSet = TRUE;
  302. }
  303. memset(&chFormat, 0, sizeof(chFormat));
  304. chFormat.cbSize = sizeof(chFormat);
  305. chFormat.dwMask = CFM_FACE;
  306. strcpy(chFormat.szFaceName, g_szMonoSpaceFaceName);
  307. SendMessageA(hWnd, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) &chFormat);
  308. }
  309. //////////////////////////////////////////////////////////////////////////////////////
  310. //
  311. //////////////////////////////////////////////////////////////////////////////////////
  312. BOOL GetUnknownErrorString(LPWSTR *ppwszErrorString, DWORD dwError)
  313. {
  314. LPVOID pwsz;
  315. DWORD ret = 0;
  316. WCHAR szText[CRYPTUI_MAX_STRING_SIZE];
  317. ret = FormatMessageU (
  318. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  319. NULL,
  320. dwError,
  321. MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  322. (LPWSTR) &pwsz,
  323. 0,
  324. NULL);
  325. if (ret != 0)
  326. {
  327. *ppwszErrorString = AllocAndCopyWStr((LPWSTR) pwsz);
  328. LocalFree(pwsz);
  329. }
  330. else
  331. {
  332. LoadStringU(HinstDll, IDS_UNKNOWN_ERROR, szText, ARRAYSIZE(szText));
  333. *ppwszErrorString = AllocAndCopyWStr(szText);
  334. }
  335. return TRUE;
  336. }
  337. //////////////////////////////////////////////////////////////////////////////////////
  338. //
  339. //////////////////////////////////////////////////////////////////////////////////////
  340. BOOL GetCertErrorString(LPWSTR *ppwszErrorString, PCRYPT_PROVIDER_CERT pCryptProviderCert)
  341. {
  342. WCHAR szErrorString[CRYPTUI_MAX_STRING_SIZE];
  343. //
  344. // if this is true then the cert is OK
  345. //
  346. if ((pCryptProviderCert->dwError == 0) &&
  347. (pCryptProviderCert->dwConfidence & CERT_CONFIDENCE_SIG) &&
  348. (pCryptProviderCert->dwConfidence & CERT_CONFIDENCE_TIME) &&
  349. (pCryptProviderCert->dwConfidence & CERT_CONFIDENCE_TIMENEST) &&
  350. (!pCryptProviderCert->fIsCyclic) &&
  351. !CertHasEmptyEKUProp(pCryptProviderCert->pCert))
  352. {
  353. return FALSE;
  354. }
  355. *ppwszErrorString = NULL;
  356. if ((pCryptProviderCert->dwError == CERT_E_UNTRUSTEDROOT) ||
  357. (pCryptProviderCert->dwError == CERT_E_UNTRUSTEDTESTROOT))
  358. {
  359. LoadStringU(HinstDll, IDS_UNTRUSTEDROOT_ERROR_TREE, szErrorString, ARRAYSIZE(szErrorString));
  360. }
  361. else if (pCryptProviderCert->dwError == CERT_E_REVOKED)
  362. {
  363. LoadStringU(HinstDll, IDS_CERTREVOKED_ERROR, szErrorString, ARRAYSIZE(szErrorString));
  364. }
  365. else if (!(pCryptProviderCert->dwConfidence & CERT_CONFIDENCE_SIG) ||
  366. (pCryptProviderCert->dwError == TRUST_E_CERT_SIGNATURE))
  367. {
  368. LoadStringU(HinstDll, IDS_CERTBADSIGNATURE_ERROR, szErrorString, ARRAYSIZE(szErrorString));
  369. }
  370. else if (!(pCryptProviderCert->dwConfidence & CERT_CONFIDENCE_TIME) ||
  371. (pCryptProviderCert->dwError == CERT_E_EXPIRED))
  372. {
  373. LoadStringU(HinstDll, IDS_CERTEXPIRED_ERROR, szErrorString, ARRAYSIZE(szErrorString));
  374. }
  375. else if (!(pCryptProviderCert->dwConfidence & CERT_CONFIDENCE_TIMENEST) ||
  376. (pCryptProviderCert->dwError == CERT_E_VALIDITYPERIODNESTING))
  377. {
  378. LoadStringU(HinstDll, IDS_TIMENESTING_ERROR, szErrorString, ARRAYSIZE(szErrorString));
  379. }
  380. else if (pCryptProviderCert->dwError == CERT_E_WRONG_USAGE)
  381. {
  382. //
  383. // if state was passed in, then the usage should be there
  384. //
  385. /* if (pviewhelp->pcvp->pCryptProviderData != NULL)
  386. {
  387. pviewhelp->pcvp->pCryptProviderData->pszUsageOID;
  388. }
  389. else
  390. {
  391. //
  392. // otherwise get the usage out of the built up state
  393. //
  394. pviewhelp->sWTD.pPolicyCallbackData = pszUsage;
  395. }*/
  396. LoadStringU(HinstDll, IDS_WRONG_USAGE_ERROR, szErrorString, ARRAYSIZE(szErrorString));
  397. }
  398. else if (pCryptProviderCert->dwError == TRUST_E_BASIC_CONSTRAINTS)
  399. {
  400. LoadStringU(HinstDll, IDS_BASIC_CONSTRAINTS_ERROR, szErrorString, ARRAYSIZE(szErrorString));
  401. }
  402. else if (pCryptProviderCert->dwError == CERT_E_PURPOSE)
  403. {
  404. LoadStringU(HinstDll, IDS_PURPOSE_ERROR, szErrorString, ARRAYSIZE(szErrorString));
  405. }
  406. else if (pCryptProviderCert->dwError == CERT_E_REVOCATION_FAILURE)
  407. {
  408. LoadStringU(HinstDll, IDS_REVOCATION_FAILURE_ERROR, szErrorString, ARRAYSIZE(szErrorString));
  409. }
  410. else if (pCryptProviderCert->dwError == CERT_E_CHAINING)
  411. {
  412. LoadStringU(HinstDll, IDS_CANTBUILDCHAIN_ERROR, szErrorString, ARRAYSIZE(szErrorString));
  413. }
  414. else if (pCryptProviderCert->dwError == TRUST_E_EXPLICIT_DISTRUST)
  415. {
  416. LoadStringU(HinstDll, IDS_EXPLICITDISTRUST_ERROR, szErrorString, ARRAYSIZE(szErrorString));
  417. }
  418. else if ((pCryptProviderCert->dwError == 0) && CertHasEmptyEKUProp(pCryptProviderCert->pCert))
  419. {
  420. LoadStringU(HinstDll, IDS_NO_USAGES_ERROR, szErrorString, ARRAYSIZE(szErrorString));
  421. }
  422. else if (pCryptProviderCert->fIsCyclic)
  423. {
  424. LoadStringU(HinstDll, IDS_CYCLE_ERROR, szErrorString, ARRAYSIZE(szErrorString));
  425. }
  426. else
  427. {
  428. //
  429. // this is not an error we know about, so call the general
  430. // error string function
  431. //
  432. GetUnknownErrorString(ppwszErrorString, pCryptProviderCert->dwError);
  433. }
  434. if (*ppwszErrorString == NULL)
  435. {
  436. if (NULL == (*ppwszErrorString = AllocAndCopyWStr(szErrorString)))
  437. {
  438. return FALSE;
  439. }
  440. }
  441. return TRUE;
  442. }
  443. //////////////////////////////////////////////////////////////////////////////////////
  444. //
  445. //////////////////////////////////////////////////////////////////////////////////////
  446. static void DrawFocusRectangle (HWND hwnd, HDC hdc)
  447. {
  448. RECT rect;
  449. PAINTSTRUCT ps;
  450. BOOL fReleaseDC = FALSE;
  451. if (hdc == NULL)
  452. {
  453. hdc = GetDC(hwnd);
  454. if (hdc == NULL)
  455. {
  456. return;
  457. }
  458. fReleaseDC = TRUE;
  459. }
  460. GetClientRect(hwnd, &rect);
  461. DrawFocusRect(hdc, &rect);
  462. if ( fReleaseDC == TRUE )
  463. {
  464. ReleaseDC(hwnd, hdc);
  465. }
  466. }
  467. //////////////////////////////////////////////////////////////////////////////////////
  468. //
  469. //////////////////////////////////////////////////////////////////////////////////////
  470. LRESULT CALLBACK ArrowCursorSubclassProc (
  471. HWND hwnd,
  472. UINT uMsg,
  473. WPARAM wParam,
  474. LPARAM lParam
  475. )
  476. {
  477. HDC hdc;
  478. WNDPROC wndproc;
  479. PAINTSTRUCT ps;
  480. HWND hWndSubject;
  481. HWND hWndIssuer;
  482. HWND hWndNext;
  483. wndproc = (WNDPROC)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  484. switch ( uMsg )
  485. {
  486. case WM_SETCURSOR:
  487. SetCursor(LoadCursor(NULL, IDC_ARROW));
  488. return( TRUE );
  489. break;
  490. case WM_CHAR:
  491. if ( wParam != (WPARAM)' ' )
  492. {
  493. break;
  494. }
  495. case WM_LBUTTONDOWN:
  496. case WM_LBUTTONDBLCLK:
  497. case WM_MBUTTONDBLCLK:
  498. case WM_RBUTTONDBLCLK:
  499. //case WM_RBUTTONUP:
  500. case WM_MBUTTONUP:
  501. //case WM_RBUTTONDOWN:
  502. case WM_MBUTTONDOWN:
  503. return( TRUE );
  504. break;
  505. case EM_SETSEL:
  506. return( TRUE );
  507. break;
  508. case WM_PAINT:
  509. CallWindowProc(wndproc, hwnd, uMsg, wParam, lParam);
  510. if ( hwnd == GetFocus() )
  511. {
  512. DrawFocusRectangle(hwnd, NULL);
  513. }
  514. return( TRUE );
  515. break;
  516. case WM_SETFOCUS:
  517. hWndSubject = GetDlgItem(GetParent(hwnd), IDC_SUBJECT_EDIT);
  518. hWndIssuer = GetDlgItem(GetParent(hwnd), IDC_ISSUER_EDIT);
  519. //if ((hwnd == hWndSubject) || (hwnd == hWndIssuer))
  520. {
  521. hWndNext = GetNextDlgTabItem(GetParent(hwnd), hwnd, FALSE);
  522. if ((hWndNext == hWndSubject) && (hwnd == hWndIssuer))
  523. {
  524. SetFocus(GetDlgItem(GetParent(GetParent(hwnd)), IDOK));
  525. }
  526. else
  527. {
  528. SetFocus(hWndNext);
  529. }
  530. return( TRUE );
  531. }
  532. /*else
  533. {
  534. InvalidateRect(hwnd, NULL, FALSE);
  535. UpdateWindow(hwnd);
  536. SetCursor(LoadCursor(NULL, IDC_ARROW));
  537. return( TRUE );
  538. }
  539. */
  540. break;
  541. case WM_KILLFOCUS:
  542. InvalidateRect(hwnd, NULL, TRUE);
  543. UpdateWindow(hwnd);
  544. return( TRUE );
  545. }
  546. return(CallWindowProc(wndproc, hwnd, uMsg, wParam, lParam));
  547. }
  548. //////////////////////////////////////////////////////////////////////////////////////
  549. //
  550. //////////////////////////////////////////////////////////////////////////////////////
  551. LRESULT CALLBACK LinkSubclassProc (
  552. HWND hwnd,
  553. UINT uMsg,
  554. WPARAM wParam,
  555. LPARAM lParam
  556. )
  557. {
  558. DWORD cpszURLString = 0;
  559. LPSTR pszURLString = NULL;
  560. PLINK_SUBCLASS_DATA plsd;
  561. plsd = (PLINK_SUBCLASS_DATA)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  562. switch ( uMsg )
  563. {
  564. case WM_SETCURSOR:
  565. // if the mouse hasn't been captured yet, then capture it and set the flag
  566. if (!plsd->fMouseCaptured)
  567. {
  568. SetCapture(hwnd);
  569. plsd->fMouseCaptured = TRUE;
  570. }
  571. if (plsd->fUseArrowInsteadOfHand)
  572. {
  573. SetCursor(LoadCursor(NULL, IDC_ARROW));
  574. }
  575. else
  576. {
  577. SetCursor(LoadCursor((HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE),
  578. MAKEINTRESOURCE(IDC_MYHAND)));
  579. }
  580. return( TRUE );
  581. break;
  582. case WM_CHAR:
  583. if ( wParam != (WPARAM)' ')
  584. {
  585. if ( wParam == 0x1b )
  586. {
  587. SendMessage(GetParent(GetParent(hwnd)), WM_CLOSE, 0, 0);
  588. return TRUE;
  589. }
  590. break;
  591. }
  592. // fall through to wm_lbuttondown....
  593. case WM_LBUTTONDOWN:
  594. if (plsd->fUseArrowInsteadOfHand)
  595. {
  596. return TRUE;
  597. }
  598. SetFocus(hwnd);
  599. switch(plsd->uId)
  600. {
  601. case IDC_SUBJECT_EDIT:
  602. case IDC_ISSUER_EDIT:
  603. CryptuiGoLink(GetParent(plsd->hwndParent), plsd->pszURL, plsd->fNoCOM);
  604. break;
  605. }
  606. return( TRUE );
  607. case WM_LBUTTONDBLCLK:
  608. case WM_MBUTTONDBLCLK:
  609. case WM_RBUTTONDBLCLK:
  610. //case WM_RBUTTONUP:
  611. case WM_MBUTTONUP:
  612. //case WM_RBUTTONDOWN:
  613. case WM_MBUTTONDOWN:
  614. return( TRUE );
  615. case EM_SETSEL:
  616. return( TRUE );
  617. case WM_PAINT:
  618. CallWindowProc(plsd->wpPrev, hwnd, uMsg, wParam, lParam);
  619. if ( hwnd == GetFocus() )
  620. {
  621. DrawFocusRectangle(hwnd, NULL);
  622. }
  623. return( TRUE );
  624. case WM_SETFOCUS:
  625. if ((hwnd == GetDlgItem(GetParent(hwnd), IDC_CERT_PRIVATE_KEY_EDIT)) &&
  626. (plsd->fUseArrowInsteadOfHand))
  627. {
  628. SetFocus(GetNextDlgTabItem(GetParent(hwnd), hwnd, FALSE));
  629. return( TRUE );
  630. }
  631. if ( hwnd == GetFocus() )
  632. {
  633. InvalidateRect(GetParent(hwnd), NULL, FALSE);
  634. UpdateWindow(hwnd);
  635. SetCursor(LoadCursor((HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE),
  636. MAKEINTRESOURCE(IDC_MYHAND)));
  637. return( TRUE );
  638. }
  639. break;
  640. case WM_KILLFOCUS:
  641. InvalidateRect(GetParent(hwnd), NULL, FALSE);
  642. UpdateWindow(hwnd);
  643. SetCursor(LoadCursor(NULL, IDC_ARROW));
  644. return( TRUE );
  645. case WM_MOUSEMOVE:
  646. MSG msg;
  647. DWORD dwCharLine;
  648. RECT rect;
  649. int xPos, yPos;
  650. memset(&msg, 0, sizeof(MSG));
  651. msg.hwnd = hwnd;
  652. msg.message = uMsg;
  653. msg.wParam = wParam;
  654. msg.lParam = lParam;
  655. SendMessage(plsd->hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
  656. // check to see if the mouse is in this windows rect, if not, then reset
  657. // the cursor to an arrow and release the mouse
  658. GetClientRect(hwnd, &rect);
  659. xPos = LOWORD(lParam);
  660. yPos = HIWORD(lParam);
  661. if ((xPos < 0) ||
  662. (yPos < 0) ||
  663. (xPos > (rect.right - rect.left)) ||
  664. (yPos > (rect.bottom - rect.top)))
  665. {
  666. SetCursor(LoadCursor(NULL, IDC_ARROW));
  667. ReleaseCapture();
  668. plsd->fMouseCaptured = FALSE;
  669. }
  670. return( TRUE );
  671. }
  672. return(CallWindowProc(plsd->wpPrev, hwnd, uMsg, wParam, lParam));
  673. }
  674. //////////////////////////////////////////////////////////////////////////////////////
  675. //
  676. //////////////////////////////////////////////////////////////////////////////////////
  677. void CertSubclassEditControlForArrowCursor (HWND hwndEdit)
  678. {
  679. LONG_PTR PrevWndProc;
  680. PrevWndProc = GetWindowLongPtr(hwndEdit, GWLP_WNDPROC);
  681. SetWindowLongPtr(hwndEdit, GWLP_USERDATA, PrevWndProc);
  682. SetWindowLongPtr(hwndEdit, GWLP_WNDPROC, (LONG_PTR)ArrowCursorSubclassProc);
  683. }
  684. //////////////////////////////////////////////////////////////////////////////////////
  685. //
  686. //////////////////////////////////////////////////////////////////////////////////////
  687. void CertSubclassEditControlForLink (
  688. HWND hwndDlg,
  689. HWND hwndEdit,
  690. PLINK_SUBCLASS_DATA plsd
  691. )
  692. {
  693. HWND hwndTip;
  694. plsd->hwndTip = CreateWindowA(
  695. TOOLTIPS_CLASSA,
  696. (LPSTR)NULL,
  697. WS_POPUP | TTS_ALWAYSTIP,
  698. CW_USEDEFAULT,
  699. CW_USEDEFAULT,
  700. CW_USEDEFAULT,
  701. CW_USEDEFAULT,
  702. hwndDlg,
  703. (HMENU)NULL,
  704. HinstDll,
  705. NULL
  706. );
  707. if ( plsd->hwndTip != NULL )
  708. {
  709. TOOLINFOA tia;
  710. memset(&tia, 0, sizeof(TOOLINFOA));
  711. tia.cbSize = sizeof(TOOLINFOA);
  712. tia.hwnd = hwndEdit;
  713. tia.uId = 1;
  714. tia.hinst = HinstDll;
  715. //GetClientRect(hwndEdit, &tia.rect);
  716. SendMessageA(hwndEdit, EM_GETRECT, 0, (LPARAM)&tia.rect);
  717. tia.lpszText = plsd->pszURL;
  718. SendMessageA(plsd->hwndTip, TTM_ADDTOOL, 0, (LPARAM)&tia);
  719. }
  720. plsd->fMouseCaptured = FALSE;
  721. plsd->wpPrev = (WNDPROC)GetWindowLongPtr(hwndEdit, GWLP_WNDPROC);
  722. SetWindowLongPtr(hwndEdit, GWLP_USERDATA, (LONG_PTR)plsd);
  723. SetWindowLongPtr(hwndEdit, GWLP_WNDPROC, (LONG_PTR)LinkSubclassProc);
  724. }
  725. //////////////////////////////////////////////////////////////////////////////////////
  726. //
  727. //////////////////////////////////////////////////////////////////////////////////////
  728. void * GetStoreName(HCERTSTORE hCertStore, BOOL fWideChar)
  729. {
  730. DWORD cbName = 0;
  731. LPWSTR pwszName = NULL;
  732. LPSTR pszName = NULL;
  733. if (!CertGetStoreProperty(
  734. hCertStore,
  735. CERT_STORE_LOCALIZED_NAME_PROP_ID,
  736. NULL,
  737. &cbName))
  738. {
  739. return NULL;
  740. }
  741. if (NULL == (pwszName = (LPWSTR) malloc(cbName)))
  742. {
  743. return NULL;
  744. }
  745. if (!CertGetStoreProperty(
  746. hCertStore,
  747. CERT_STORE_LOCALIZED_NAME_PROP_ID,
  748. pwszName,
  749. &cbName))
  750. {
  751. free(pwszName);
  752. return NULL;
  753. }
  754. if (fWideChar)
  755. {
  756. return pwszName;
  757. }
  758. else
  759. {
  760. pszName = CertUIMkMBStr(pwszName);
  761. free(pwszName);
  762. return pszName;
  763. }
  764. }
  765. //////////////////////////////////////////////////////////////////////////////////////
  766. //
  767. //////////////////////////////////////////////////////////////////////////////////////
  768. static BOOL ValidateItemText(HWND hWndListView, LPWSTR pszText, int index)
  769. {
  770. LVITEMW lvItem;
  771. WCHAR szText[CRYPTUI_MAX_STRING_SIZE];
  772. memset(&lvItem, 0, sizeof(lvItem));
  773. lvItem.iItem = index;
  774. lvItem.mask = LVIF_TEXT;
  775. lvItem.pszText = szText;
  776. lvItem.cchTextMax = ARRAYSIZE(szText);
  777. if (!ListView_GetItemU(hWndListView, &lvItem))
  778. {
  779. return FALSE;
  780. }
  781. return (wcscmp(szText, pszText) == 0);
  782. }
  783. //////////////////////////////////////////////////////////////////////////////////////
  784. //
  785. //////////////////////////////////////////////////////////////////////////////////////
  786. void ModifyOrInsertRow(
  787. HWND hWndListView,
  788. LV_ITEMW *plvI,
  789. LPWSTR pwszValueText,
  790. LPWSTR pwszText,
  791. BOOL fAddRows,
  792. BOOL fHex)
  793. {
  794. LV_ITEMW lvIParam;
  795. memset(&lvIParam, 0, sizeof(lvIParam));
  796. lvIParam.mask = LVIF_PARAM;
  797. lvIParam.iItem = plvI->iItem;
  798. if (fAddRows)
  799. {
  800. ListView_InsertItemU(hWndListView, plvI);
  801. }
  802. else
  803. {
  804. //
  805. // delete the helper that is already there
  806. //
  807. ListView_GetItemU(hWndListView, &lvIParam);
  808. FreeListDisplayHelper((PLIST_DISPLAY_HELPER) lvIParam.lParam);
  809. if (!ValidateItemText(hWndListView, plvI->pszText, plvI->iItem))
  810. {
  811. ListView_DeleteItem(hWndListView, plvI->iItem);
  812. ListView_InsertItemU(hWndListView, plvI);
  813. }
  814. }
  815. ListView_SetItemTextU(hWndListView, plvI->iItem, 1, pwszValueText);
  816. lvIParam.lParam = (LPARAM) MakeListDisplayHelper(fHex, pwszText, NULL, 0);
  817. ListView_SetItem(hWndListView, &lvIParam);
  818. }
  819. //////////////////////////////////////////////////////////////////////////////////////
  820. //
  821. //////////////////////////////////////////////////////////////////////////////////////
  822. int CALLBACK HidePropSheetCancelButtonCallback(
  823. HWND hwndDlg,
  824. UINT uMsg,
  825. LPARAM lParam)
  826. {
  827. RECT rc, parentRect;
  828. int xExtra, yExtra;
  829. if (uMsg == PSCB_INITIALIZED)
  830. {
  831. HWND hwndOk = GetDlgItem(hwndDlg, IDOK);
  832. HWND hwndCancel = GetDlgItem(hwndDlg, IDCANCEL);
  833. GetWindowRect(hwndCancel, &rc);
  834. MapWindowPoints(HWND_DESKTOP, hwndDlg, (LPPOINT) &rc, 2);
  835. ShowWindow(hwndCancel, SW_HIDE);
  836. MoveWindow(
  837. hwndOk,
  838. rc.left,
  839. rc.top,
  840. rc.right - rc.left,
  841. rc.bottom - rc.top,
  842. FALSE);
  843. }
  844. return 0;
  845. }
  846. //////////////////////////////////////////////////////////////////////////////////////
  847. //
  848. //////////////////////////////////////////////////////////////////////////////////////
  849. INT_PTR WINAPI CryptUIPropertySheetA(LPCPROPSHEETHEADERA pHdr)
  850. {
  851. PROPSHEETHEADERA hdr;
  852. PROPSHEETPAGEA *pPropSheetPage;
  853. INT_PTR ret;
  854. UINT i;
  855. memcpy(&hdr, pHdr, sizeof(PROPSHEETHEADERA));
  856. hdr.dwSize = PROPSHEETHEADERA_V1_SIZE;
  857. hdr.ppsp = (PROPSHEETPAGEA *) malloc(pHdr->nPages * PROPSHEETPAGEA_V1_SIZE);
  858. if (hdr.ppsp == NULL)
  859. {
  860. SetLastError(E_OUTOFMEMORY);
  861. return -1;
  862. }
  863. pPropSheetPage = (PROPSHEETPAGEA *) hdr.ppsp;
  864. for (i=0; i<pHdr->nPages; i++)
  865. {
  866. memcpy(pPropSheetPage, &(pHdr->ppsp[i]), PROPSHEETPAGEA_V1_SIZE);
  867. pPropSheetPage->dwSize = PROPSHEETPAGEA_V1_SIZE;
  868. pPropSheetPage = (PROPSHEETPAGEA *) (((LPBYTE) pPropSheetPage) + PROPSHEETPAGEA_V1_SIZE);
  869. }
  870. ret = PropertySheetA(&hdr);
  871. free((void *)hdr.ppsp);
  872. return ret;
  873. }
  874. //////////////////////////////////////////////////////////////////////////////////////
  875. //
  876. //////////////////////////////////////////////////////////////////////////////////////
  877. INT_PTR WINAPI CryptUIPropertySheetW(LPCPROPSHEETHEADERW pHdr)
  878. {
  879. PROPSHEETHEADERW hdr;
  880. PROPSHEETPAGEW *pPropSheetPage;
  881. INT_PTR ret;
  882. UINT i;
  883. memcpy(&hdr, pHdr, sizeof(PROPSHEETHEADERW));
  884. hdr.dwSize = PROPSHEETHEADERW_V1_SIZE;
  885. hdr.ppsp = (PROPSHEETPAGEW *) malloc(pHdr->nPages * PROPSHEETPAGEW_V1_SIZE);
  886. if (hdr.ppsp == NULL)
  887. {
  888. SetLastError(E_OUTOFMEMORY);
  889. return -1;
  890. }
  891. pPropSheetPage = (PROPSHEETPAGEW *) hdr.ppsp;
  892. for (i=0; i<pHdr->nPages; i++)
  893. {
  894. memcpy(pPropSheetPage, &(pHdr->ppsp[i]), PROPSHEETPAGEW_V1_SIZE);
  895. pPropSheetPage->dwSize = PROPSHEETPAGEW_V1_SIZE;
  896. pPropSheetPage = (PROPSHEETPAGEW *) (((LPBYTE) pPropSheetPage) + PROPSHEETPAGEW_V1_SIZE);
  897. }
  898. ret = PropertySheetW(&hdr);
  899. free((void *)hdr.ppsp);
  900. return ret;
  901. }
  902. //////////////////////////////////////////////////////////////////////////////////////
  903. //
  904. //////////////////////////////////////////////////////////////////////////////////////
  905. BOOL IsTrueErrorString(CERT_VIEW_HELPER *pviewhelp)
  906. {
  907. BOOL fRet;
  908. if ( ( ((pviewhelp->dwChainError == CERT_E_UNTRUSTEDROOT) ||
  909. (pviewhelp->dwChainError == CERT_E_UNTRUSTEDTESTROOT)) &&
  910. (pviewhelp->fWarnUntrustedRoot) &&
  911. (pviewhelp->fRootInRemoteStore)) ||
  912. pviewhelp->fWarnRemoteTrust )
  913. {
  914. return FALSE;
  915. }
  916. switch (pviewhelp->dwChainError)
  917. {
  918. case CERT_E_CHAINING:
  919. case TRUST_E_BASIC_CONSTRAINTS:
  920. case CERT_E_PURPOSE:
  921. case CERT_E_WRONG_USAGE:
  922. fRet = FALSE;
  923. break;
  924. case CERT_E_INVALID_NAME:
  925. if (pviewhelp->pcvp->idxCert == 0)
  926. {
  927. fRet = TRUE;
  928. }
  929. else
  930. {
  931. fRet = FALSE;
  932. }
  933. break;
  934. default:
  935. fRet = TRUE;
  936. break;
  937. }
  938. return fRet;
  939. }