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.

872 lines
31 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: cvdetail.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_SHOW_DETAILS_COMBO, IDH_CERTVIEW_DETAILS_SHOW_COMBO},
  16. {IDC_SAVE_CERTIFICATE_BUTTON, IDH_CERTVIEW_DETAILS_SAVECERT_BUTTON},
  17. {IDC_ITEM_LIST, IDH_CERTVIEW_DETAILS_ITEM_LIST},
  18. {IDC_EDIT_PROPERTIES_BUTTON, IDH_CERTVIEW_GENERAL_EDITPROPERTIES_BUTTON},
  19. {IDC_DETAIL_EDIT, IDH_CERTVIEW_DETAILS_ITEM_EDIT}
  20. };
  21. //////////////////////////////////////////////////////////////////////////////////////
  22. // This function will take a HWND for a list view and a certinfo struct and display
  23. // all the V1 fields of the cert in the list view
  24. //////////////////////////////////////////////////////////////////////////////////////
  25. static void DisplayV1Fields(HWND hWndListView, PCERT_INFO pCertInfo, DWORD *index)
  26. {
  27. LPWSTR pwszText;
  28. LPWSTR pwszPubKey;
  29. WCHAR szFieldText[_MAX_PATH]; // used for calls to LoadString only
  30. WCHAR szKeySize[32];
  31. LV_ITEMW lvI;
  32. DWORD dwKeySize;
  33. char szVersion[32];
  34. void *pTemp;
  35. //
  36. // set up the fields in the list view item struct that don't change from item to item
  37. //
  38. lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
  39. lvI.state = 0;
  40. lvI.stateMask = 0;
  41. lvI.pszText = szFieldText;
  42. lvI.iSubItem = 0;
  43. lvI.iImage = IMAGE_V1;
  44. lvI.lParam = (LPARAM)NULL;
  45. //
  46. // version
  47. //
  48. lvI.iItem = (*index)++;
  49. LoadStringU(HinstDll, IDS_ADV_VERSION, szFieldText, ARRAYSIZE(szFieldText));
  50. lvI.cchTextMax = wcslen(szFieldText);
  51. wsprintfA(szVersion, "V%d", pCertInfo->dwVersion+1);
  52. if (NULL != (pwszText = CertUIMkWStr(szVersion)))
  53. {
  54. lvI.lParam = (LPARAM) MakeListDisplayHelper(FALSE, pwszText, NULL, 0);
  55. ListView_InsertItemU(hWndListView, &lvI);
  56. ListView_SetItemTextU(hWndListView, (*index)-1 , 1, pwszText);
  57. }
  58. //
  59. // serial number
  60. //
  61. if (FormatSerialNoString(&pwszText, &(pCertInfo->SerialNumber)))
  62. {
  63. lvI.iItem = (*index)++;
  64. LoadStringU(HinstDll, IDS_ADV_SER_NUM, szFieldText, ARRAYSIZE(szFieldText));
  65. lvI.cchTextMax = wcslen(szFieldText);
  66. lvI.lParam = (LPARAM) MakeListDisplayHelper(TRUE, pwszText, NULL, 0);
  67. ListView_InsertItemU(hWndListView, &lvI);
  68. ListView_SetItemTextU(hWndListView, (*index)-1 , 1, pwszText);
  69. }
  70. //
  71. // signature algorithm
  72. //
  73. if (FormatAlgorithmString(&pwszText, &(pCertInfo->SignatureAlgorithm)))
  74. {
  75. lvI.iItem = (*index)++;
  76. LoadStringU(HinstDll, IDS_ADV_SIG_ALG, szFieldText, ARRAYSIZE(szFieldText));
  77. lvI.cchTextMax = wcslen(szFieldText);
  78. lvI.lParam = (LPARAM) MakeListDisplayHelper(FALSE, pwszText, NULL, 0);
  79. ListView_InsertItemU(hWndListView, &lvI);
  80. ListView_SetItemTextU(hWndListView, (*index)-1 , 1, pwszText);
  81. }
  82. //
  83. // issuer
  84. //
  85. LoadStringU(HinstDll, IDS_ADV_ISSUER, szFieldText, ARRAYSIZE(szFieldText));
  86. lvI.cchTextMax = wcslen(szFieldText);
  87. if (FormatDNNameString(&pwszText, pCertInfo->Issuer.pbData, pCertInfo->Issuer.cbData, TRUE))
  88. {
  89. lvI.iItem = (*index)++;
  90. lvI.lParam = (LPARAM) MakeListDisplayHelper(FALSE, pwszText, NULL, 0);
  91. ListView_InsertItemU(hWndListView, &lvI);
  92. if (FormatDNNameString(&pwszText, pCertInfo->Issuer.pbData, pCertInfo->Issuer.cbData, FALSE))
  93. {
  94. ListView_SetItemTextU(hWndListView, (*index)-1 , 1, pwszText);
  95. free(pwszText);
  96. }
  97. }
  98. //
  99. // not before
  100. //
  101. if (FormatDateString(&pwszText, pCertInfo->NotBefore, TRUE, TRUE, hWndListView))
  102. {
  103. lvI.iItem = (*index)++;
  104. LoadStringU(HinstDll, IDS_ADV_NOTBEFORE, szFieldText, ARRAYSIZE(szFieldText));
  105. lvI.cchTextMax = wcslen(szFieldText);
  106. lvI.lParam = (LPARAM) MakeListDisplayHelper(FALSE, pwszText, NULL, 0);
  107. ListView_InsertItemU(hWndListView, &lvI);
  108. ListView_SetItemTextU(hWndListView, (*index)-1 , 1, pwszText);
  109. }
  110. //
  111. // not after
  112. //
  113. if (FormatDateString(&pwszText, pCertInfo->NotAfter, TRUE, TRUE, hWndListView))
  114. {
  115. lvI.iItem = (*index)++;
  116. LoadStringU(HinstDll, IDS_ADV_NOTAFTER, szFieldText, ARRAYSIZE(szFieldText));
  117. lvI.cchTextMax = wcslen(szFieldText);
  118. lvI.lParam = (LPARAM) MakeListDisplayHelper(FALSE, pwszText, NULL, 0);
  119. ListView_InsertItemU(hWndListView, &lvI);
  120. ListView_SetItemTextU(hWndListView, (*index)-1 , 1, pwszText);
  121. }
  122. //
  123. // subject
  124. //
  125. LoadStringU(HinstDll, IDS_ADV_SUBJECT, szFieldText, ARRAYSIZE(szFieldText));
  126. lvI.cchTextMax = wcslen(szFieldText);
  127. if (FormatDNNameString(&pwszText, pCertInfo->Subject.pbData, pCertInfo->Subject.cbData, TRUE))
  128. {
  129. lvI.iItem = (*index)++;
  130. lvI.lParam = (LPARAM) MakeListDisplayHelper(FALSE, pwszText, NULL, 0);
  131. ListView_InsertItemU(hWndListView, &lvI);
  132. if (FormatDNNameString(&pwszText, pCertInfo->Subject.pbData, pCertInfo->Subject.cbData, FALSE))
  133. {
  134. ListView_SetItemTextU(hWndListView, (*index)-1 , 1, pwszText);
  135. free(pwszText);
  136. }
  137. }
  138. //
  139. // public key
  140. //
  141. if (FormatAlgorithmString(&pwszText, &(pCertInfo->SubjectPublicKeyInfo.Algorithm)))
  142. {
  143. WCHAR temp[32];
  144. lvI.iItem = (*index)++;
  145. LoadStringU(HinstDll, IDS_ADV_PUBKEY, szFieldText, ARRAYSIZE(szFieldText));
  146. lvI.cchTextMax = wcslen(szFieldText);
  147. dwKeySize = CertGetPublicKeyLength(X509_ASN_ENCODING, &(pCertInfo->SubjectPublicKeyInfo));
  148. _itow(dwKeySize, szKeySize, 10);
  149. wcscpy(temp, L" (");
  150. wcscat(temp, szKeySize);
  151. wcscat(temp, L" Bits)");
  152. pTemp = realloc(pwszText, ((wcslen(pwszText) + wcslen(temp) + 1 ) * sizeof(WCHAR)));
  153. if (pTemp == NULL)
  154. {
  155. free(pwszText);
  156. return;
  157. }
  158. pwszText = (LPWSTR) pTemp;
  159. wcscat(pwszText, temp);
  160. FormatMemBufToString(
  161. &pwszPubKey,
  162. pCertInfo->SubjectPublicKeyInfo.PublicKey.pbData,
  163. pCertInfo->SubjectPublicKeyInfo.PublicKey.cbData);
  164. lvI.lParam = (LPARAM) MakeListDisplayHelper(TRUE, pwszPubKey, NULL, 0);
  165. ListView_InsertItemU(hWndListView, &lvI);
  166. ListView_SetItemTextU(hWndListView, (*index)-1 , 1, pwszText);
  167. free(pwszText);
  168. }
  169. }
  170. //////////////////////////////////////////////////////////////////////////////////////
  171. // This function will take a HWND for a list view and a pointer to a cert contexxt and
  172. // display all the properties tagged to the cert in the list view
  173. //////////////////////////////////////////////////////////////////////////////////////
  174. static void DisplayProperties(HWND hWndListView, PCCERT_CONTEXT pCertContext, DWORD *index)
  175. {
  176. DWORD i;
  177. WCHAR szFieldText[_MAX_PATH]; // used for calls to LoadString only
  178. LPWSTR pwszText;
  179. LV_ITEMW lvI;
  180. BYTE hash[20];
  181. DWORD hashSize = ARRAYSIZE(hash);
  182. DWORD cbText;
  183. CRYPT_KEY_PROV_INFO *pKeyInfo = NULL;
  184. DWORD cbKeyInfo = 0;
  185. HCRYPTPROV hCryptProv;
  186. HCRYPTKEY hCryptKey;
  187. DWORD dwTemp;
  188. PCCRYPT_OID_INFO pThumbprintAlgorithm;
  189. DWORD dwAlgID = CALG_SHA1;
  190. //
  191. // set up the fields in the list view item struct that don't change from item to item
  192. //
  193. lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
  194. lvI.state = 0;
  195. lvI.stateMask = 0;
  196. lvI.pszText = szFieldText;
  197. lvI.iSubItem = 0;
  198. lvI.iImage = IMAGE_PROPERTY;
  199. //
  200. // thumbprint algorithm
  201. //
  202. if (NULL != (pThumbprintAlgorithm = CryptFindOIDInfo(
  203. CRYPT_OID_INFO_ALGID_KEY,
  204. &dwAlgID,
  205. CRYPT_HASH_ALG_OID_GROUP_ID)) &&
  206. (NULL != (pwszText = AllocAndCopyWStr(pThumbprintAlgorithm->pwszName))))
  207. {
  208. lvI.iItem = (*index)++;
  209. LoadStringU(HinstDll, IDS_THUMBPRINT_ALGORITHM, szFieldText, ARRAYSIZE(szFieldText));
  210. lvI.cchTextMax = wcslen(szFieldText);
  211. lvI.lParam = (LPARAM) MakeListDisplayHelper(FALSE, pwszText, NULL, 0);
  212. ListView_InsertItemU(hWndListView, &lvI);
  213. ListView_SetItemTextU(hWndListView, (*index)-1 , 1, pwszText);
  214. }
  215. //
  216. // thumbprint
  217. //
  218. CertGetCertificateContextProperty(
  219. pCertContext,
  220. CERT_SHA1_HASH_PROP_ID,
  221. hash,
  222. &hashSize);
  223. if (FormatMemBufToString(&pwszText, hash, ARRAYSIZE(hash)))
  224. {
  225. lvI.iItem = (*index)++;
  226. LoadStringU(HinstDll, IDS_THUMBPRINT, szFieldText, ARRAYSIZE(szFieldText));
  227. lvI.cchTextMax = wcslen(szFieldText);
  228. lvI.lParam = (LPARAM) MakeListDisplayHelper(TRUE, pwszText, NULL, 0);
  229. ListView_InsertItemU(hWndListView, &lvI);
  230. ListView_SetItemTextU(hWndListView, (*index)-1 , 1, pwszText);
  231. }
  232. //
  233. // friendly name
  234. //
  235. cbText = 0;
  236. if (CertGetCertificateContextProperty( pCertContext,
  237. CERT_FRIENDLY_NAME_PROP_ID,
  238. NULL,
  239. &cbText) &&
  240. (NULL != (pwszText = (LPWSTR) malloc(cbText))))
  241. {
  242. lvI.iItem = (*index)++;
  243. LoadStringU(HinstDll, IDS_CERTIFICATE_NAME, szFieldText, ARRAYSIZE(szFieldText));
  244. lvI.cchTextMax = wcslen(szFieldText);
  245. CertGetCertificateContextProperty( pCertContext,
  246. CERT_FRIENDLY_NAME_PROP_ID,
  247. pwszText,
  248. &cbText);
  249. lvI.lParam = (LPARAM) MakeListDisplayHelper(FALSE, pwszText, NULL, 0);
  250. ListView_InsertItemU(hWndListView, &lvI);
  251. ListView_SetItemTextU(hWndListView, (*index)-1 , 1, pwszText);
  252. }
  253. //
  254. // description
  255. //
  256. cbText = 0;
  257. if (CertGetCertificateContextProperty( pCertContext,
  258. CERT_DESCRIPTION_PROP_ID,
  259. NULL,
  260. &cbText) &&
  261. (NULL != (pwszText = (LPWSTR) malloc(cbText))))
  262. {
  263. lvI.iItem = (*index)++;
  264. LoadStringU(HinstDll, IDS_DESCRIPTION, szFieldText, ARRAYSIZE(szFieldText));
  265. lvI.cchTextMax = wcslen(szFieldText);
  266. CertGetCertificateContextProperty( pCertContext,
  267. CERT_DESCRIPTION_PROP_ID,
  268. pwszText,
  269. &cbText);
  270. lvI.lParam = (LPARAM) MakeListDisplayHelper(FALSE, pwszText, NULL, 0);
  271. ListView_InsertItemU(hWndListView, &lvI);
  272. ListView_SetItemTextU(hWndListView, (*index)-1 , 1, pwszText);
  273. }
  274. //
  275. // enhanced key usage
  276. //
  277. if (FormatEnhancedKeyUsageString(&pwszText, pCertContext, TRUE, TRUE))
  278. {
  279. lvI.iItem = (*index)++;
  280. LoadStringU(HinstDll, IDS_ENHANCED_KEY_USAGE, szFieldText, ARRAYSIZE(szFieldText));
  281. lvI.cchTextMax = wcslen(szFieldText);
  282. lvI.lParam = (LPARAM) MakeListDisplayHelper(FALSE, pwszText, NULL, 0);
  283. ListView_InsertItemU(hWndListView, &lvI);
  284. FormatEnhancedKeyUsageString(&pwszText, pCertContext, TRUE, FALSE);
  285. ListView_SetItemTextU(hWndListView, (*index)-1 , 1, pwszText);
  286. free(pwszText);
  287. }
  288. //
  289. // extended error information
  290. //
  291. cbText = 0;
  292. if (CertGetCertificateContextProperty( pCertContext,
  293. CERT_EXTENDED_ERROR_INFO_PROP_ID,
  294. NULL,
  295. &cbText) &&
  296. (cbText / sizeof(WCHAR) > 1) &&
  297. (NULL != (pwszText = (LPWSTR) malloc(cbText * 2))))
  298. {
  299. DWORD cchText = cbText / sizeof(WCHAR);
  300. if (!CertGetCertificateContextProperty( pCertContext,
  301. CERT_EXTENDED_ERROR_INFO_PROP_ID,
  302. pwszText,
  303. &cbText) ||
  304. (cchText != cbText / sizeof(WCHAR)) ||
  305. (pwszText[cchText - 1] != L'\0'))
  306. {
  307. free(pwszText);
  308. }
  309. else
  310. {
  311. // Force an extra L'\n' between lines by converting L'\r' to L'\n'
  312. //
  313. // Create a duplicate version of the error information where L'\r'
  314. // is converted to L' ' and L'\n' is converted to L','.
  315. LPWSTR pwszSingleLineText = pwszText + cchText;
  316. for (i = 0; i < cchText; i++)
  317. {
  318. if (pwszText[i] == L'\r')
  319. {
  320. pwszText[i] = L'\n';
  321. pwszSingleLineText[i] = L' ';
  322. }
  323. else if (pwszText[i] == L'\n')
  324. {
  325. if (pwszText[i+1] == L'\0')
  326. {
  327. pwszSingleLineText[i] = L'\0';
  328. break;
  329. }
  330. else
  331. {
  332. pwszSingleLineText[i] = L',';
  333. }
  334. }
  335. else
  336. {
  337. pwszSingleLineText[i] = pwszText[i];
  338. }
  339. }
  340. lvI.iItem = (*index)++;
  341. LoadStringU(HinstDll, IDS_EXTENDED_ERROR_INFO, szFieldText, ARRAYSIZE(szFieldText));
  342. lvI.cchTextMax = wcslen(szFieldText);
  343. lvI.lParam = (LPARAM) MakeListDisplayHelper(FALSE, pwszText, NULL, 0);
  344. ListView_InsertItemU(hWndListView, &lvI);
  345. ListView_SetItemTextU(hWndListView, (*index)-1 , 1,
  346. pwszSingleLineText);
  347. }
  348. }
  349. //
  350. // private key
  351. //
  352. /*if (CertGetCertificateContextProperty( pCertContext,
  353. CERT_KEY_PROV_INFO_PROP_ID,
  354. NULL,
  355. &cbKeyInfo))
  356. {
  357. if (NULL == (pKeyInfo = (CRYPT_KEY_PROV_INFO *) malloc(cbKeyInfo)))
  358. {
  359. return;
  360. }
  361. if (!CertGetCertificateContextProperty( pCertContext,
  362. CERT_KEY_PROV_INFO_PROP_ID,
  363. pKeyInfo,
  364. &cbKeyInfo))
  365. {
  366. return;
  367. }
  368. if (CryptAcquireContextU(
  369. &hCryptProv,
  370. pKeyInfo->pwszContainerName,
  371. pKeyInfo->pwszProvName,
  372. pKeyInfo->dwProvType,
  373. pKeyInfo->dwFlags))
  374. {
  375. if (CryptGetUserKey(hCryptProv, pKeyInfo->dwKeySpec, &hCryptKey))
  376. {
  377. }
  378. }
  379. free(pKeyInfo);
  380. }*/
  381. }
  382. //////////////////////////////////////////////////////////////////////////////////////
  383. //
  384. //////////////////////////////////////////////////////////////////////////////////////
  385. INT_PTR APIENTRY ViewPageDetails(HWND hwndDlg, UINT msg, WPARAM wParam,
  386. LPARAM lParam)
  387. {
  388. DWORD i;
  389. PROPSHEETPAGE *ps;
  390. PCCERT_CONTEXT pccert;
  391. CERT_VIEW_HELPER *pviewhelp;
  392. WCHAR rgwch[CRYPTUI_MAX_STRING_SIZE];
  393. HIMAGELIST hIml;
  394. HWND hWndListView;
  395. HWND hwnd;
  396. LV_COLUMNW lvC;
  397. WCHAR szText[CRYPTUI_MAX_STRING_SIZE];
  398. LV_ITEMW lvI;
  399. LPNMLISTVIEW pnmv;
  400. CRYPTUI_WIZ_EXPORT_INFO ExportInfo;
  401. DWORD dwCertAccessProperty;
  402. DWORD cb;
  403. WCHAR errorString[CRYPTUI_MAX_STRING_SIZE];
  404. WCHAR errorTitle[CRYPTUI_MAX_STRING_SIZE];
  405. switch ( msg ) {
  406. case WM_INITDIALOG:
  407. //
  408. // save the pviewhelp struct in DWL_USER so it can always be accessed
  409. //
  410. ps = (PROPSHEETPAGE *) lParam;
  411. pviewhelp = (CERT_VIEW_HELPER *) (ps->lParam);
  412. pccert = pviewhelp->pcvp->pCertContext;
  413. SetWindowLongPtr(hwndDlg, DWLP_USER, (DWORD_PTR) pviewhelp);
  414. pviewhelp->hwndDetailPage = hwndDlg;
  415. //
  416. // clear the text in the detail edit box
  417. //
  418. CryptUISetRicheditTextW(hwndDlg, IDC_DETAIL_EDIT, L"");
  419. //
  420. // initialize the combo box with it's strings
  421. //
  422. LoadStringU(HinstDll, IDS_ALL_FIELDS, szText, ARRAYSIZE(szText));
  423. SendDlgItemMessageU(hwndDlg, IDC_SHOW_DETAILS_COMBO, CB_INSERTSTRING, 0, (LPARAM) szText);
  424. LoadStringU(HinstDll, IDS_V1_FIELDS_ONLY, szText, ARRAYSIZE(szText));
  425. SendDlgItemMessageU(hwndDlg, IDC_SHOW_DETAILS_COMBO, CB_INSERTSTRING, 1, (LPARAM) szText);
  426. LoadStringU(HinstDll, IDS_EXTENSIONS_ONLY, szText, ARRAYSIZE(szText));
  427. SendDlgItemMessageU(hwndDlg, IDC_SHOW_DETAILS_COMBO, CB_INSERTSTRING, 2, (LPARAM) szText);
  428. LoadStringU(HinstDll, IDS_CRITICAL_EXTENSIONS_ONLY, szText, ARRAYSIZE(szText));
  429. SendDlgItemMessageU(hwndDlg, IDC_SHOW_DETAILS_COMBO, CB_INSERTSTRING, 3, (LPARAM) szText);
  430. LoadStringU(HinstDll, IDS_PROPERTIES_ONLY, szText, ARRAYSIZE(szText));
  431. SendDlgItemMessageU(hwndDlg, IDC_SHOW_DETAILS_COMBO, CB_INSERTSTRING, 4, (LPARAM) szText);
  432. SendDlgItemMessageU(hwndDlg, IDC_SHOW_DETAILS_COMBO, CB_SETCURSEL, 0, (LPARAM) NULL);
  433. //
  434. // get the handle of the list view control
  435. //
  436. hWndListView = GetDlgItem(hwndDlg, IDC_ITEM_LIST);
  437. //
  438. // initialize the image list for the list view, load the icons,
  439. // then add the image list to the list view
  440. //
  441. hIml = ImageList_LoadImage(HinstDll, MAKEINTRESOURCE(IDB_PROPLIST), 0, 4, RGB(0,128,128), IMAGE_BITMAP, 0);
  442. if (hIml != NULL)
  443. {
  444. ListView_SetImageList(hWndListView, hIml, LVSIL_SMALL);
  445. }
  446. //
  447. // initialize the columns in the list view
  448. //
  449. lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  450. lvC.fmt = LVCFMT_LEFT; // Left-align the column.
  451. lvC.cx = 171; // Width of the column, in pixels.
  452. lvC.pszText = szText; // The text for the column.
  453. // Add the columns. They are loaded from a string table.
  454. for (i = 0; i <= 1; i++)
  455. {
  456. lvC.iSubItem = i;
  457. LoadStringU(HinstDll, IDS_FIELD + i, szText, ARRAYSIZE(szText));
  458. if (ListView_InsertColumnU(hWndListView, i, &lvC) == -1)
  459. {
  460. // error
  461. }
  462. }
  463. //
  464. // add all the certificate fields to the list box
  465. //
  466. i = 0;
  467. DisplayV1Fields(hWndListView, pccert->pCertInfo, &i);
  468. DisplayExtensions(hWndListView, pccert->pCertInfo->cExtension, pccert->pCertInfo->rgExtension, FALSE, &i);
  469. DisplayExtensions(hWndListView, pccert->pCertInfo->cExtension, pccert->pCertInfo->rgExtension, TRUE, &i);
  470. DisplayProperties(hWndListView, pccert, &i);
  471. //
  472. // set the style in the list view so that it highlights an entire line
  473. //
  474. SendMessageA(hWndListView, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
  475. //
  476. // for the "Edit Properties" button, get the CERT_ACCESS_STATE_PROP_ID
  477. // and check it
  478. //
  479. cb = sizeof(DWORD);
  480. CertGetCertificateContextProperty(
  481. pccert,
  482. CERT_ACCESS_STATE_PROP_ID,
  483. (void *) &dwCertAccessProperty,
  484. &cb);
  485. if (pviewhelp->pcvp->dwFlags & CRYPTUI_ENABLE_EDITPROPERTIES)
  486. {
  487. EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_PROPERTIES_BUTTON), TRUE);
  488. }
  489. else if (pviewhelp->pcvp->dwFlags & CRYPTUI_DISABLE_EDITPROPERTIES)
  490. {
  491. EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_PROPERTIES_BUTTON), FALSE);
  492. }
  493. else
  494. {
  495. EnableWindow(
  496. GetDlgItem(hwndDlg, IDC_EDIT_PROPERTIES_BUTTON),
  497. (dwCertAccessProperty & CERT_ACCESS_STATE_WRITE_PERSIST_FLAG));
  498. }
  499. return TRUE;
  500. case WM_MY_REINITIALIZE:
  501. //
  502. // send a message to the combo box that selection has chaged, it will then
  503. // update everything for us
  504. //
  505. SendMessage(
  506. hwndDlg,
  507. WM_COMMAND,
  508. (WPARAM) MAKELONG(IDC_SHOW_DETAILS_COMBO, LBN_SELCHANGE),
  509. (LPARAM) GetDlgItem(hwndDlg, IDC_SHOW_DETAILS_COMBO));
  510. return TRUE;
  511. case WM_NOTIFY:
  512. pviewhelp = (CERT_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  513. pccert = pviewhelp->pcvp->pCertContext;
  514. switch (((NMHDR FAR *) lParam)->code)
  515. {
  516. case PSN_SETACTIVE:
  517. break;
  518. case PSN_APPLY:
  519. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)TRUE);
  520. break;
  521. case PSN_KILLACTIVE:
  522. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)FALSE);
  523. return TRUE;
  524. case PSN_RESET:
  525. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)FALSE);
  526. break;
  527. case PSN_QUERYCANCEL:
  528. pviewhelp->fCancelled = TRUE;
  529. return FALSE;
  530. case PSN_HELP:
  531. pviewhelp = (CERT_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  532. if (FIsWin95) {
  533. //WinHelpA(hwndDlg, (LPSTR) pviewhelp->pcvp->szHelpFileName,
  534. // HELP_CONTEXT, pviewhelp->pcvp->dwHelpId);
  535. }
  536. else {
  537. //WinHelpW(hwndDlg, pviewhelp->pcvp->szHelpFileName, HELP_CONTEXT,
  538. // pviewhelp->pcvp->dwHelpId);
  539. }
  540. return TRUE;
  541. case LVN_ITEMCHANGING:
  542. if ((((NMHDR FAR *) lParam)->idFrom) != IDC_ITEM_LIST)
  543. {
  544. break;
  545. }
  546. pnmv = (LPNMLISTVIEW) lParam;
  547. if (pnmv->uNewState & LVIS_SELECTED)
  548. {
  549. DisplayHelperTextInEdit(
  550. GetDlgItem(hwndDlg, IDC_ITEM_LIST),
  551. hwndDlg,
  552. IDC_DETAIL_EDIT,
  553. pnmv->iItem);
  554. }
  555. return TRUE;
  556. case NM_CLICK:
  557. if ((((NMHDR FAR *) lParam)->idFrom) != IDC_ITEM_LIST)
  558. {
  559. break;
  560. }
  561. DisplayHelperTextInEdit(
  562. GetDlgItem(hwndDlg, IDC_ITEM_LIST),
  563. hwndDlg,
  564. IDC_DETAIL_EDIT,
  565. -1);
  566. return TRUE;
  567. case NM_SETFOCUS:
  568. switch (((NMHDR FAR *) lParam)->idFrom)
  569. {
  570. case IDC_ITEM_LIST:
  571. if (NULL == (hWndListView = GetDlgItem(hwndDlg, IDC_ITEM_LIST)))
  572. break;
  573. if ((ListView_GetItemCount(hWndListView) != 0) &&
  574. (ListView_GetNextItem(hWndListView, -1, LVNI_SELECTED) == -1))
  575. {
  576. memset(&lvI, 0, sizeof(lvI));
  577. lvI.mask = LVIF_STATE;
  578. lvI.iItem = 0;
  579. lvI.state = LVIS_FOCUSED | LVIS_SELECTED;
  580. lvI.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
  581. ListView_SetItem(hWndListView, &lvI);
  582. }
  583. break;
  584. }
  585. break;
  586. }
  587. break;
  588. case WM_COMMAND:
  589. pviewhelp = (CERT_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  590. pccert = pviewhelp->pcvp->pCertContext;
  591. switch (LOWORD(wParam))
  592. {
  593. case IDC_SAVE_CERTIFICATE_BUTTON:
  594. memset(&ExportInfo, 0, sizeof(ExportInfo));
  595. ExportInfo.dwSize = sizeof(ExportInfo);
  596. ExportInfo.dwSubjectChoice = CRYPTUI_WIZ_EXPORT_CERT_CONTEXT;
  597. ExportInfo.pCertContext = pviewhelp->pcvp->pCertContext;
  598. CryptUIWizExport(0, hwndDlg, NULL, &ExportInfo, NULL);
  599. break;
  600. case IDC_EDIT_PROPERTIES_BUTTON:
  601. if (HIWORD(wParam) == BN_CLICKED)
  602. {
  603. CRYPTUI_VIEWCERTIFICATEPROPERTIES_STRUCT csp;
  604. BOOL fPropertiesChanged;
  605. memset(&csp, 0, sizeof(csp));
  606. csp.dwSize = sizeof(csp);
  607. csp.hwndParent = hwndDlg;
  608. csp.dwFlags = 0;
  609. csp.pCertContext = pviewhelp->pcvp->pCertContext;
  610. csp.cStores = pviewhelp->pcvp->cStores;
  611. csp.rghStores = pviewhelp->pcvp->rghStores;
  612. csp.cPropSheetPages = 0;
  613. csp.rgPropSheetPages = NULL;
  614. CryptUIDlgViewCertificateProperties(&csp, &fPropertiesChanged);
  615. //
  616. // if properties were actually changed, then set the flag
  617. // to our caller, and refresh our state
  618. //
  619. if (fPropertiesChanged)
  620. {
  621. //
  622. // if the WinVerifyTrust state was passed in, then the view
  623. // cannot be refreshed, so alert the user
  624. //
  625. if (pviewhelp->pcvp->pCryptProviderData != NULL)
  626. {
  627. LoadStringU(HinstDll, IDS_NO_REFRESH, errorString, ARRAYSIZE(errorString));
  628. if (pviewhelp->pcvp->szTitle != NULL)
  629. {
  630. MessageBoxU(hwndDlg, errorString, pviewhelp->pcvp->szTitle, MB_OK | MB_ICONWARNING);
  631. }
  632. else
  633. {
  634. LoadStringU(HinstDll, IDS_VIEW_TITLE, errorTitle, ARRAYSIZE(errorTitle));
  635. MessageBoxU(hwndDlg, errorString, errorTitle, MB_OK | MB_ICONWARNING);
  636. }
  637. }
  638. if (pviewhelp->pfPropertiesChanged != NULL)
  639. {
  640. *(pviewhelp->pfPropertiesChanged) = TRUE;
  641. }
  642. //
  643. // since the editing of properties changed major stuff, we need
  644. // to redo the trust work and then reset the display
  645. //
  646. BuildChain(pviewhelp, NULL);
  647. SendMessage(hwndDlg, WM_MY_REINITIALIZE, (WPARAM) 0, (LPARAM) 0);
  648. if (pviewhelp->hwndGeneralPage != NULL)
  649. {
  650. SendMessage(pviewhelp->hwndGeneralPage, WM_MY_REINITIALIZE, (WPARAM) 0, (LPARAM) 0);
  651. }
  652. if (pviewhelp->hwndHierarchyPage != NULL)
  653. {
  654. SendMessage(pviewhelp->hwndHierarchyPage, WM_MY_REINITIALIZE, (WPARAM) 0, (LPARAM) 0);
  655. }
  656. }
  657. return TRUE;
  658. }
  659. break;
  660. case IDC_SHOW_DETAILS_COMBO:
  661. if (HIWORD(wParam) == LBN_SELCHANGE)
  662. {
  663. DWORD curSel = (DWORD)SendDlgItemMessageA(hwndDlg, IDC_SHOW_DETAILS_COMBO, CB_GETCURSEL, 0, (LPARAM) NULL);
  664. hWndListView = GetDlgItem(hwndDlg, IDC_ITEM_LIST);
  665. //
  666. // get all the items in the list view and free the lParam
  667. // associated with each of them (lParam is the helper sruct)
  668. //
  669. memset(&lvI, 0, sizeof(lvI));
  670. lvI.iItem = ListView_GetItemCount(hWndListView) - 1;
  671. lvI.mask = LVIF_PARAM;
  672. while (lvI.iItem >= 0)
  673. {
  674. if (ListView_GetItemU(hWndListView, &lvI))
  675. {
  676. FreeListDisplayHelper((PLIST_DISPLAY_HELPER) lvI.lParam);
  677. }
  678. lvI.iItem--;
  679. }
  680. ListView_DeleteAllItems(hWndListView);
  681. CryptUISetRicheditTextW(hwndDlg, IDC_DETAIL_EDIT, L"");
  682. i = 0;
  683. switch (curSel)
  684. {
  685. case 0:
  686. DisplayV1Fields(hWndListView, pccert->pCertInfo, &i);
  687. DisplayExtensions(hWndListView, pccert->pCertInfo->cExtension, pccert->pCertInfo->rgExtension, FALSE, &i);
  688. DisplayExtensions(hWndListView, pccert->pCertInfo->cExtension, pccert->pCertInfo->rgExtension, TRUE, &i);
  689. DisplayProperties(hWndListView, pccert, &i);
  690. break;
  691. case 1:
  692. DisplayV1Fields(hWndListView, pccert->pCertInfo, &i);
  693. break;
  694. case 2:
  695. DisplayExtensions(hWndListView, pccert->pCertInfo->cExtension, pccert->pCertInfo->rgExtension, FALSE, &i);
  696. DisplayExtensions(hWndListView, pccert->pCertInfo->cExtension, pccert->pCertInfo->rgExtension, TRUE, &i);
  697. break;
  698. case 3:
  699. DisplayExtensions(hWndListView, pccert->pCertInfo->cExtension, pccert->pCertInfo->rgExtension, TRUE, &i);
  700. break;
  701. case 4:
  702. DisplayProperties(hWndListView, pccert, &i);
  703. break;
  704. }
  705. return TRUE;
  706. }
  707. break;
  708. case IDHELP:
  709. pviewhelp = (CERT_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  710. if (FIsWin95) {
  711. //WinHelpA(hwndDlg, (LPSTR) pviewhelp->pcvp->szHelpFileName,
  712. // HELP_CONTEXT, pviewhelp->pcvp->dwHelpId);
  713. }
  714. else {
  715. //WinHelpW(hwndDlg, pviewhelp->pcvp->szHelpFileName, HELP_CONTEXT,
  716. // pviewhelp->pcvp->dwHelpId);
  717. }
  718. return TRUE;
  719. }
  720. break;
  721. case WM_DESTROY:
  722. //
  723. // get all the items in the list view and free the lParam
  724. // associated with each of them (lParam is the helper sruct)
  725. //
  726. hWndListView = GetDlgItem(hwndDlg, IDC_ITEM_LIST);
  727. memset(&lvI, 0, sizeof(lvI));
  728. lvI.iItem = ListView_GetItemCount(hWndListView) - 1;
  729. lvI.mask = LVIF_PARAM;
  730. while (lvI.iItem >= 0)
  731. {
  732. if (ListView_GetItemU(hWndListView, &lvI))
  733. {
  734. FreeListDisplayHelper((PLIST_DISPLAY_HELPER) lvI.lParam);
  735. }
  736. lvI.iItem--;
  737. }
  738. break;
  739. case WM_HELP:
  740. case WM_CONTEXTMENU:
  741. if (msg == WM_HELP)
  742. {
  743. hwnd = GetDlgItem(hwndDlg, ((LPHELPINFO)lParam)->iCtrlId);
  744. }
  745. else
  746. {
  747. hwnd = (HWND) wParam;
  748. }
  749. if ((hwnd != GetDlgItem(hwndDlg, IDC_SHOW_DETAILS_COMBO)) &&
  750. (hwnd != GetDlgItem(hwndDlg, IDC_SAVE_CERTIFICATE_BUTTON)) &&
  751. (hwnd != GetDlgItem(hwndDlg, IDC_ITEM_LIST)) &&
  752. (hwnd != GetDlgItem(hwndDlg, IDC_EDIT_PROPERTIES_BUTTON)) &&
  753. (hwnd != GetDlgItem(hwndDlg, IDC_DETAIL_EDIT)))
  754. {
  755. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)TRUE);
  756. return TRUE;
  757. }
  758. else
  759. {
  760. return OnContextHelp(hwndDlg, msg, wParam, lParam, helpmap);
  761. }
  762. }
  763. return FALSE;
  764. }