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.

636 lines
15 KiB

  1. //
  2. // CertContentsPages.cpp
  3. //
  4. #include "stdafx.h"
  5. #include "resource.h"
  6. #include "CertContentsPages.h"
  7. #include "Certificat.h"
  8. #include "CertUtil.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. ////////////////////// Local helper functions ////////////////////////
  15. static void
  16. AppendField(CString& str, UINT id, const CString& text)
  17. {
  18. CString strName;
  19. if (!text.IsEmpty())
  20. {
  21. if (strName.LoadString(id))
  22. {
  23. str += strName;
  24. str += _T("\t");
  25. str += text;
  26. str += _T("\r\n");
  27. }
  28. }
  29. }
  30. static void
  31. FormatCertDescription(CERT_DESCRIPTION& desc, CString& str)
  32. {
  33. AppendField(str, IDS_ISSUED_TO, desc.m_CommonName);
  34. AppendField(str, IDS_ISSUED_BY, desc.m_CAName);
  35. AppendField(str, IDS_EXPIRATION_DATE, desc.m_ExpirationDate);
  36. AppendField(str, IDS_PURPOSE, desc.m_Usage);
  37. AppendField(str, IDS_FRIENDLY_NAME, desc.m_FriendlyName);
  38. AppendField(str, IDS_COUNTRY, desc.m_Country);
  39. AppendField(str, IDS_STATE, desc.m_State);
  40. AppendField(str, IDS_LOCALITY, desc.m_Locality);
  41. AppendField(str, IDS_ORGANIZATION, desc.m_Organization);
  42. AppendField(str, IDS_ORGANIZATION_UNIT, desc.m_OrganizationUnit);
  43. }
  44. #if 0
  45. static void
  46. FormatCertContactInfo(CCertificate * pCert, CString& str)
  47. {
  48. AppendField(str, IDS_CONTACT_NAME, pCert->m_ContactName);
  49. AppendField(str, IDS_CONTACT_ADDRESS, pCert->m_ContactAddress);
  50. CString strPhone = pCert->m_ContactPhone;
  51. if (!pCert->m_ContactPhoneExt.IsEmpty())
  52. {
  53. strPhone += _T("x");
  54. strPhone += pCert->m_ContactPhoneExt;
  55. }
  56. AppendField(str, IDS_CONTACT_PHONE, strPhone);
  57. }
  58. #endif
  59. static BOOL
  60. ExtractDescription(CCertificate * pCert, CERT_DESCRIPTION& cd)
  61. {
  62. ASSERT(pCert != NULL);
  63. cd.m_CommonName = pCert->m_CommonName;
  64. cd.m_FriendlyName = pCert->m_FriendlyName;
  65. cd.m_Country = pCert->m_Country;
  66. cd.m_State = pCert->m_State;
  67. cd.m_Locality = pCert->m_Locality;
  68. cd.m_Organization = pCert->m_Organization;
  69. cd.m_OrganizationUnit = pCert->m_OrganizationUnit;
  70. return TRUE;
  71. }
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CCertContentsPage base property page
  74. IMPLEMENT_DYNCREATE(CCertContentsPage, CIISWizardPage)
  75. CCertContentsPage::CCertContentsPage(UINT id, CCertificate * pCert)
  76. : CIISWizardPage(id, IDS_CERTWIZ, TRUE),
  77. m_pCert(pCert)
  78. {
  79. ASSERT(id != 0);
  80. }
  81. CCertContentsPage::~CCertContentsPage()
  82. {
  83. }
  84. void CCertContentsPage::DoDataExchange(CDataExchange* pDX)
  85. {
  86. CIISWizardPage::DoDataExchange(pDX);
  87. //{{AFX_DATA_MAP(CCertContentsPage)
  88. //}}AFX_DATA_MAP
  89. }
  90. BEGIN_MESSAGE_MAP(CCertContentsPage, CIISWizardPage)
  91. //{{AFX_MSG_MAP(CCertContentsPage)
  92. //}}AFX_MSG_MAP
  93. END_MESSAGE_MAP()
  94. // OnSetActive we format cert contents and put it to edit
  95. // control with predefined ID. We should do it here, because
  96. // if user will get back and reselect certificate, text should
  97. // also be changed
  98. //
  99. BOOL
  100. CCertContentsPage::OnSetActive()
  101. {
  102. CERT_DESCRIPTION cd;
  103. if (CIISWizardPage::OnSetActive())
  104. {
  105. // If page defines GetCertDescription() then it want this
  106. // data to be displayed
  107. if (GetCertDescription(cd))
  108. {
  109. ASSERT(NULL != GetDlgItem(IDC_CERT_CONTENTS));
  110. CString str;
  111. FormatCertDescription(cd, str);
  112. GetDlgItem(IDC_CERT_CONTENTS)->SetWindowText(str);
  113. }
  114. return TRUE;
  115. }
  116. return FALSE;
  117. }
  118. BOOL CCertContentsPage::OnInitDialog()
  119. {
  120. ASSERT(m_pCert != NULL);
  121. CIISWizardPage::OnInitDialog();
  122. ASSERT(NULL != GetDlgItem(IDC_CERT_CONTENTS));
  123. CEdit * pEdit = (CEdit *)CWnd::FromHandle(GetDlgItem(IDC_CERT_CONTENTS)->m_hWnd);
  124. CRect rcEdit;
  125. pEdit->GetClientRect(&rcEdit);
  126. int baseunitX = LOWORD(GetDialogBaseUnits());
  127. int width_units = MulDiv(rcEdit.Width(), 4, baseunitX);
  128. //pEdit->SetTabStops(MulDiv(45, width_units, 100));
  129. pEdit->SetTabStops(width_units/2);
  130. return TRUE;
  131. }
  132. ////////////////////////////////////////////////////////////////////////////////////////
  133. // CInstallCertPage
  134. IMPLEMENT_DYNCREATE(CInstallCertPage, CCertContentsPage)
  135. BOOL
  136. CInstallCertPage::GetCertDescription(CERT_DESCRIPTION& cd)
  137. {
  138. return GetCertificate()->GetSelectedCertDescription(cd);
  139. }
  140. LRESULT
  141. CInstallCertPage::OnWizardNext()
  142. {
  143. GetCertificate()->InstallSelectedCert();
  144. return IDD_PAGE_NEXT;
  145. }
  146. ////////////////////////////////////////////////////////////////////////////////////////
  147. // CReplaceCertPage
  148. IMPLEMENT_DYNCREATE(CReplaceCertPage, CCertContentsPage)
  149. BOOL
  150. CReplaceCertPage::GetCertDescription(CERT_DESCRIPTION& cd)
  151. {
  152. return GetCertificate()->GetSelectedCertDescription(cd);
  153. }
  154. LRESULT
  155. CReplaceCertPage::OnWizardNext()
  156. {
  157. GetCertificate()->InstallSelectedCert();
  158. return IDD_PAGE_NEXT;
  159. }
  160. ////////////////////////////////////////////////////////////////////////////////////////
  161. // CInstallKeyPage
  162. IMPLEMENT_DYNCREATE(CInstallKeyPage, CCertContentsPage)
  163. BOOL
  164. CInstallKeyPage::OnSetActive()
  165. {
  166. ASSERT(NULL != GetDlgItem(IDC_CERT_CONTENTS));
  167. ASSERT(NULL != GetDlgItem(IDC_FILE_NAME));
  168. if (CCertContentsPage::OnSetActive())
  169. {
  170. CString strPath = GetCertificate()->m_KeyFileName;
  171. CompactPathToWidth(GetDlgItem(IDC_FILE_NAME), strPath);
  172. SetDlgItemText(IDC_FILE_NAME, strPath);
  173. return TRUE;
  174. }
  175. return FALSE;
  176. }
  177. BOOL
  178. CInstallKeyPage::GetCertDescription(CERT_DESCRIPTION& cd)
  179. {
  180. return GetCertificate()->GetKeyCertDescription(cd);
  181. }
  182. LRESULT
  183. CInstallKeyPage::OnWizardNext()
  184. {
  185. GetCertificate()->InstallKeyRingCert();
  186. return IDD_PAGE_NEXT;
  187. }
  188. ////////////////////////////////////////////////////////////////////////////////////////
  189. // CInstallImportPFXPage
  190. IMPLEMENT_DYNCREATE(CInstallImportPFXPage, CCertContentsPage)
  191. BOOL
  192. CInstallImportPFXPage::OnSetActive()
  193. {
  194. ASSERT(NULL != GetDlgItem(IDC_CERT_CONTENTS));
  195. ASSERT(NULL != GetDlgItem(IDC_FILE_NAME));
  196. if (CCertContentsPage::OnSetActive())
  197. {
  198. CString strPath = GetCertificate()->m_KeyFileName;
  199. CompactPathToWidth(GetDlgItem(IDC_FILE_NAME), strPath);
  200. SetDlgItemText(IDC_FILE_NAME, strPath);
  201. return TRUE;
  202. }
  203. return FALSE;
  204. }
  205. BOOL
  206. CInstallImportPFXPage::GetCertDescription(CERT_DESCRIPTION& cd)
  207. {
  208. return GetCertificate()->GetPFXFileCertDescription(cd);
  209. }
  210. LRESULT
  211. CInstallImportPFXPage::OnWizardNext()
  212. {
  213. GetCertificate()->InstallImportPFXCert();
  214. return IDD_PAGE_NEXT;
  215. }
  216. ////////////////////////////////////////////////////////////////////////////////////////
  217. // CInstallExportPFXPage
  218. IMPLEMENT_DYNCREATE(CInstallExportPFXPage, CCertContentsPage)
  219. BOOL
  220. CInstallExportPFXPage::OnSetActive()
  221. {
  222. ASSERT(NULL != GetDlgItem(IDC_CERT_CONTENTS));
  223. ASSERT(NULL != GetDlgItem(IDC_FILE_NAME));
  224. if (CCertContentsPage::OnSetActive())
  225. {
  226. CString strPath = GetCertificate()->m_KeyFileName;
  227. CompactPathToWidth(GetDlgItem(IDC_FILE_NAME), strPath);
  228. SetDlgItemText(IDC_FILE_NAME, strPath);
  229. return TRUE;
  230. }
  231. return FALSE;
  232. }
  233. BOOL
  234. CInstallExportPFXPage::GetCertDescription(CERT_DESCRIPTION& cd)
  235. {
  236. //return GetCertificate()->GetKeyCertDescription(cd);
  237. return GetCertificate()->GetInstalledCertDescription(cd);
  238. }
  239. LRESULT
  240. CInstallExportPFXPage::OnWizardNext()
  241. {
  242. GetCertificate()->InstallExportPFXCert();
  243. return IDD_PAGE_NEXT;
  244. }
  245. ////////////////////////////////////////////////////////////////////////////////////////
  246. // CInstallRespPage
  247. IMPLEMENT_DYNCREATE(CInstallRespPage, CCertContentsPage)
  248. BOOL
  249. CInstallRespPage::OnSetActive()
  250. {
  251. ASSERT(NULL != GetDlgItem(IDC_CERT_CONTENTS));
  252. ASSERT(NULL != GetDlgItem(IDC_FILE_NAME));
  253. if (CCertContentsPage::OnSetActive())
  254. {
  255. CString strPath = GetCertificate()->m_RespFileName;
  256. CompactPathToWidth(GetDlgItem(IDC_FILE_NAME), strPath);
  257. SetDlgItemText(IDC_FILE_NAME, strPath);
  258. return TRUE;
  259. }
  260. return FALSE;
  261. }
  262. BOOL
  263. CInstallRespPage::GetCertDescription(CERT_DESCRIPTION& cd)
  264. {
  265. return GetCertificate()->GetResponseCertDescription(cd);
  266. }
  267. LRESULT
  268. CInstallRespPage::OnWizardNext()
  269. {
  270. GetCertificate()->InstallResponseCert();
  271. return IDD_PAGE_NEXT;
  272. }
  273. ////////////////////////////////////////////////////////////////////////////////////////
  274. // CRemoveCertPage
  275. IMPLEMENT_DYNCREATE(CRemoveCertPage, CCertContentsPage)
  276. static BOOL
  277. AnswerIsYes2(UINT id, CString& file)
  278. {
  279. CString strMessage;
  280. AfxFormatString1(strMessage, id, file);
  281. return (IDYES == AfxMessageBox(strMessage, MB_ICONEXCLAMATION | MB_YESNO));
  282. }
  283. BOOL
  284. CRemoveCertPage::GetCertDescription(CERT_DESCRIPTION& cd)
  285. {
  286. CCertificate * pCert = GetCertificate();
  287. ASSERT(NULL != pCert);
  288. return pCert->GetInstalledCertDescription(cd);
  289. }
  290. LRESULT
  291. CRemoveCertPage::OnWizardNext()
  292. {
  293. CCertificate * pCert = GetCertificate();
  294. ASSERT(NULL != pCert);
  295. int iReallyRemoveCert = FALSE;
  296. int iTheReturn = 1;
  297. CStringList listNodesUsingThisCert;
  298. // check if this cert is being used first...
  299. IsCertUsedBySSLBelowMe(pCert->m_MachineName,pCert->m_WebSiteInstanceName,listNodesUsingThisCert);
  300. if (listNodesUsingThisCert.IsEmpty())
  301. {
  302. iReallyRemoveCert = TRUE;
  303. }
  304. else
  305. {
  306. // if the cert is being used, then
  307. // don't let them remove it
  308. CString csStringCount;
  309. csStringCount.Format(_T("%d"), listNodesUsingThisCert.GetCount());
  310. if (TRUE == AnswerIsYes2(IDS_CERT_BEING_USED, csStringCount))
  311. {
  312. iReallyRemoveCert = TRUE;
  313. }
  314. else
  315. {
  316. iTheReturn = 1;
  317. }
  318. }
  319. if (iReallyRemoveCert)
  320. {
  321. // go ahead and remove the cert
  322. if ( FAILED(pCert->UninstallCert())
  323. || FAILED(ShutdownSSL(pCert->m_MachineName, pCert->m_WebSiteInstanceName))
  324. )
  325. {
  326. GetCertificate()->SetBodyTextID(IDS_REMOVE_CERT_FAILED);
  327. }
  328. iTheReturn = IDD_PAGE_NEXT;
  329. }
  330. return iTheReturn;
  331. }
  332. ////////////////////////////////////////////////////////////////////////////////////////
  333. // CRequestCancelPage
  334. IMPLEMENT_DYNCREATE(CRequestCancelPage, CCertContentsPage)
  335. //
  336. // In this case we should get request from the dummy cert in REQUEST store,
  337. // because we dropping request without any connection to response.
  338. //
  339. BOOL
  340. CRequestCancelPage::GetCertDescription(CERT_DESCRIPTION& cd)
  341. {
  342. return FALSE;
  343. }
  344. LRESULT
  345. CRequestCancelPage::OnWizardNext()
  346. {
  347. GetCertificate()->CancelRequest();
  348. return IDD_PAGE_NEXT;
  349. }
  350. /////////////////////////////////////////////////////////////////////////////
  351. // CRequestToFilePage property page
  352. IMPLEMENT_DYNCREATE(CRequestToFilePage, CCertContentsPage)
  353. // This page prepares and shows contents itself
  354. // We should format contact info first, then description
  355. // default method could do only description
  356. //
  357. BOOL CRequestToFilePage::OnSetActive()
  358. {
  359. if (CCertContentsPage::OnSetActive())
  360. {
  361. ASSERT(GetCertificate() != NULL);
  362. ASSERT(GetDlgItem(IDC_CERT_CONTENTS) != NULL);
  363. ASSERT(GetDlgItem(IDC_FILE_NAME) != NULL);
  364. if (GetCertificate()->GetStatusCode() == CCertificate::REQUEST_RENEW_CERT)
  365. {
  366. GetCertificate()->LoadRenewalData();
  367. }
  368. CString str;
  369. // FormatCertContactInfo(m_pCert, str);
  370. CERT_DESCRIPTION cd;
  371. ExtractDescription(GetCertificate(), cd);
  372. FormatCertDescription(cd, str);
  373. SetDlgItemText(IDC_CERT_CONTENTS, str);
  374. CString strPath = m_pCert->m_ReqFileName;
  375. CompactPathToWidth(GetDlgItem(IDC_FILE_NAME), strPath);
  376. SetDlgItemText(IDC_FILE_NAME, strPath);
  377. return TRUE;
  378. }
  379. return FALSE;
  380. }
  381. LRESULT CRequestToFilePage::OnWizardNext()
  382. {
  383. GetCertificate()->PrepareRequest();
  384. return IDD_PAGE_NEXT;
  385. }
  386. /////////////////////////////////////////////////////////////////////////////
  387. // CRequestToFilePageRenew property page
  388. IMPLEMENT_DYNCREATE(CRequestToFilePageRenew, CCertContentsPage)
  389. // This page prepares and shows contents itself
  390. // We should format contact info first, then description
  391. // default method could do only description
  392. //
  393. BOOL CRequestToFilePageRenew::OnSetActive()
  394. {
  395. if (CCertContentsPage::OnSetActive())
  396. {
  397. ASSERT(GetCertificate() != NULL);
  398. ASSERT(GetDlgItem(IDC_CERT_CONTENTS) != NULL);
  399. ASSERT(GetDlgItem(IDC_FILE_NAME) != NULL);
  400. if (GetCertificate()->GetStatusCode() == CCertificate::REQUEST_RENEW_CERT)
  401. {
  402. GetCertificate()->LoadRenewalData();
  403. }
  404. CString str;
  405. // FormatCertContactInfo(m_pCert, str);
  406. CERT_DESCRIPTION cd;
  407. ExtractDescription(GetCertificate(), cd);
  408. FormatCertDescription(cd, str);
  409. SetDlgItemText(IDC_CERT_CONTENTS, str);
  410. CString strPath = m_pCert->m_ReqFileName;
  411. CompactPathToWidth(GetDlgItem(IDC_FILE_NAME), strPath);
  412. SetDlgItemText(IDC_FILE_NAME, strPath);
  413. return TRUE;
  414. }
  415. return FALSE;
  416. }
  417. LRESULT CRequestToFilePageRenew::OnWizardNext()
  418. {
  419. GetCertificate()->PrepareRequest();
  420. return IDD_PAGE_NEXT;
  421. }
  422. /////////////////////////////////////////////////////////////////////////////
  423. // COnlineRequestSubmit property page
  424. IMPLEMENT_DYNCREATE(COnlineRequestSubmit, CCertContentsPage)
  425. BOOL
  426. COnlineRequestSubmit::GetCertDescription(CERT_DESCRIPTION& cd)
  427. {
  428. // we have all data in CCertificate
  429. return ExtractDescription(GetCertificate(), cd);
  430. }
  431. LRESULT COnlineRequestSubmit::OnWizardNext()
  432. {
  433. LRESULT id = IDD_PAGE_NEXT;
  434. BeginWaitCursor();
  435. if (GetCertificate()->GetStatusCode() == CCertificate::REQUEST_RENEW_CERT)
  436. GetCertificate()->SubmitRenewalRequest();
  437. else if (m_pCert->GetStatusCode() == CCertificate::REQUEST_NEW_CERT)
  438. GetCertificate()->SubmitRequest();
  439. else
  440. id = 1;
  441. EndWaitCursor();
  442. return id;
  443. }
  444. BOOL COnlineRequestSubmit::OnSetActive()
  445. {
  446. ASSERT(GetCertificate() != NULL);
  447. ASSERT(GetDlgItem(IDC_CA_NAME) != NULL);
  448. ASSERT(GetDlgItem(IDC_CA_NAME2) != NULL);
  449. if (CCertContentsPage::OnSetActive())
  450. {
  451. CString csTemp1;
  452. // Make it look good
  453. csTemp1 = GetCertificate()->m_ConfigCA;
  454. int iFind = csTemp1.Find(_T("\\"));
  455. if (iFind != -1)
  456. {
  457. int iLength = csTemp1.GetLength();
  458. CString csTemp2;
  459. csTemp2 = csTemp1.Left(iFind);
  460. SetDlgItemText(IDC_CA_NAME, csTemp2);
  461. csTemp2 = csTemp1.Right(iLength - iFind - 1);
  462. SetDlgItemText(IDC_CA_NAME2, csTemp2);
  463. }
  464. else
  465. {
  466. SetDlgItemText(IDC_CA_NAME, csTemp1);
  467. }
  468. return TRUE;
  469. }
  470. return FALSE;
  471. }
  472. ////////////////////////////////////////////////////////////////////////////////////////
  473. // CInstallCopyFromRemotePage
  474. IMPLEMENT_DYNCREATE(CInstallCopyFromRemotePage, CCertContentsPage)
  475. BOOL
  476. CInstallCopyFromRemotePage::GetCertDescription(CERT_DESCRIPTION& cd)
  477. {
  478. return GetCertificate()->GetPFXFileCertDescription(cd);
  479. }
  480. LRESULT
  481. CInstallCopyFromRemotePage::OnWizardNext()
  482. {
  483. GetCertificate()->InstallCopyMoveFromRemote();
  484. return IDD_PAGE_NEXT;
  485. }
  486. ////////////////////////////////////////////////////////////////////////////////////////
  487. // CInstallMoveFromRemotePage
  488. IMPLEMENT_DYNCREATE(CInstallMoveFromRemotePage, CCertContentsPage)
  489. BOOL
  490. CInstallMoveFromRemotePage::GetCertDescription(CERT_DESCRIPTION& cd)
  491. {
  492. return GetCertificate()->GetPFXFileCertDescription(cd);
  493. }
  494. LRESULT
  495. CInstallMoveFromRemotePage::OnWizardNext()
  496. {
  497. GetCertificate()->InstallCopyMoveFromRemote();
  498. return IDD_PAGE_NEXT;
  499. }
  500. ////////////////////////////////////////////////////////////////////////////////////////
  501. // CInstallCopyFromRemotePage
  502. IMPLEMENT_DYNCREATE(CInstallCopyToRemotePage, CCertContentsPage)
  503. BOOL
  504. CInstallCopyToRemotePage::GetCertDescription(CERT_DESCRIPTION& cd)
  505. {
  506. return GetCertificate()->GetInstalledCertDescription(cd);
  507. }
  508. LRESULT
  509. CInstallCopyToRemotePage::OnWizardNext()
  510. {
  511. GetCertificate()->InstallCopyMoveToRemote();
  512. return IDD_PAGE_NEXT;
  513. }
  514. ////////////////////////////////////////////////////////////////////////////////////////
  515. // CInstallMoveFromRemotePage
  516. IMPLEMENT_DYNCREATE(CInstallMoveToRemotePage, CCertContentsPage)
  517. BOOL
  518. CInstallMoveToRemotePage::GetCertDescription(CERT_DESCRIPTION& cd)
  519. {
  520. return GetCertificate()->GetInstalledCertDescription(cd);
  521. }
  522. LRESULT
  523. CInstallMoveToRemotePage::OnWizardNext()
  524. {
  525. GetCertificate()->InstallCopyMoveToRemote();
  526. return IDD_PAGE_NEXT;
  527. }