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.

376 lines
9.1 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. return TRUE;
  130. }
  131. ////////////////////////////////////////////////////////////////////////////////////////
  132. // CInstallCertPage
  133. IMPLEMENT_DYNCREATE(CInstallCertPage, CCertContentsPage)
  134. BOOL
  135. CInstallCertPage::GetCertDescription(CERT_DESCRIPTION& cd)
  136. {
  137. return GetCertificate()->GetSelectedCertDescription(cd);
  138. }
  139. LRESULT
  140. CInstallCertPage::OnWizardNext()
  141. {
  142. GetCertificate()->InstallSelectedCert();
  143. return IDD_PAGE_NEXT;
  144. }
  145. ////////////////////////////////////////////////////////////////////////////////////////
  146. // CReplaceCertPage
  147. IMPLEMENT_DYNCREATE(CReplaceCertPage, CCertContentsPage)
  148. BOOL
  149. CReplaceCertPage::GetCertDescription(CERT_DESCRIPTION& cd)
  150. {
  151. return GetCertificate()->GetSelectedCertDescription(cd);
  152. }
  153. LRESULT
  154. CReplaceCertPage::OnWizardNext()
  155. {
  156. GetCertificate()->InstallSelectedCert();
  157. return IDD_PAGE_NEXT;
  158. }
  159. ////////////////////////////////////////////////////////////////////////////////////////
  160. // CInstallKeyPage
  161. IMPLEMENT_DYNCREATE(CInstallKeyPage, CCertContentsPage)
  162. BOOL
  163. CInstallKeyPage::OnSetActive()
  164. {
  165. ASSERT(NULL != GetDlgItem(IDC_CERT_CONTENTS));
  166. ASSERT(NULL != GetDlgItem(IDC_FILE_NAME));
  167. if (CCertContentsPage::OnSetActive())
  168. {
  169. CString strPath = GetCertificate()->m_KeyFileName;
  170. CompactPathToWidth(GetDlgItem(IDC_FILE_NAME), strPath);
  171. SetDlgItemText(IDC_FILE_NAME, strPath);
  172. return TRUE;
  173. }
  174. return FALSE;
  175. }
  176. BOOL
  177. CInstallKeyPage::GetCertDescription(CERT_DESCRIPTION& cd)
  178. {
  179. return GetCertificate()->GetKeyCertDescription(cd);
  180. }
  181. LRESULT
  182. CInstallKeyPage::OnWizardNext()
  183. {
  184. GetCertificate()->InstallKeyRingCert();
  185. return IDD_PAGE_NEXT;
  186. }
  187. ////////////////////////////////////////////////////////////////////////////////////////
  188. // CInstallRespPage
  189. IMPLEMENT_DYNCREATE(CInstallRespPage, CCertContentsPage)
  190. BOOL
  191. CInstallRespPage::OnSetActive()
  192. {
  193. ASSERT(NULL != GetDlgItem(IDC_CERT_CONTENTS));
  194. ASSERT(NULL != GetDlgItem(IDC_FILE_NAME));
  195. if (CCertContentsPage::OnSetActive())
  196. {
  197. CString strPath = GetCertificate()->m_RespFileName;
  198. CompactPathToWidth(GetDlgItem(IDC_FILE_NAME), strPath);
  199. SetDlgItemText(IDC_FILE_NAME, strPath);
  200. return TRUE;
  201. }
  202. return FALSE;
  203. }
  204. BOOL
  205. CInstallRespPage::GetCertDescription(CERT_DESCRIPTION& cd)
  206. {
  207. return GetCertificate()->GetResponseCertDescription(cd);
  208. }
  209. LRESULT
  210. CInstallRespPage::OnWizardNext()
  211. {
  212. GetCertificate()->InstallResponseCert();
  213. return IDD_PAGE_NEXT;
  214. }
  215. ////////////////////////////////////////////////////////////////////////////////////////
  216. // CRemoveCertPage
  217. IMPLEMENT_DYNCREATE(CRemoveCertPage, CCertContentsPage)
  218. BOOL
  219. CRemoveCertPage::GetCertDescription(CERT_DESCRIPTION& cd)
  220. {
  221. CCertificate * pCert = GetCertificate();
  222. ASSERT(NULL != pCert);
  223. return pCert->GetInstalledCertDescription(cd);
  224. }
  225. LRESULT
  226. CRemoveCertPage::OnWizardNext()
  227. {
  228. CCertificate * pCert = GetCertificate();
  229. ASSERT(NULL != pCert);
  230. if ( FAILED(pCert->UninstallCert())
  231. || FAILED(ShutdownSSL(pCert->m_MachineName, pCert->m_WebSiteInstanceName))
  232. )
  233. GetCertificate()->SetBodyTextID(IDS_REMOVE_CERT_FAILED);
  234. return IDD_PAGE_NEXT;
  235. }
  236. ////////////////////////////////////////////////////////////////////////////////////////
  237. // CRequestCancelPage
  238. IMPLEMENT_DYNCREATE(CRequestCancelPage, CCertContentsPage)
  239. //
  240. // In this case we should get request from the dummy cert in REQUEST store,
  241. // because we dropping request without any connection to response.
  242. //
  243. BOOL
  244. CRequestCancelPage::GetCertDescription(CERT_DESCRIPTION& cd)
  245. {
  246. return FALSE;
  247. }
  248. LRESULT
  249. CRequestCancelPage::OnWizardNext()
  250. {
  251. GetCertificate()->CancelRequest();
  252. return IDD_PAGE_NEXT;
  253. }
  254. /////////////////////////////////////////////////////////////////////////////
  255. // CRequestToFilePage property page
  256. IMPLEMENT_DYNCREATE(CRequestToFilePage, CCertContentsPage)
  257. // This page prepares and shows contents itself
  258. // We should format contact info first, then description
  259. // default method could do only description
  260. //
  261. BOOL CRequestToFilePage::OnSetActive()
  262. {
  263. if (CCertContentsPage::OnSetActive())
  264. {
  265. ASSERT(GetCertificate() != NULL);
  266. ASSERT(GetDlgItem(IDC_CERT_CONTENTS) != NULL);
  267. ASSERT(GetDlgItem(IDC_FILE_NAME) != NULL);
  268. if (GetCertificate()->GetStatusCode() == CCertificate::REQUEST_RENEW_CERT)
  269. {
  270. GetCertificate()->LoadRenewalData();
  271. }
  272. CString str;
  273. // FormatCertContactInfo(m_pCert, str);
  274. CERT_DESCRIPTION cd;
  275. ExtractDescription(GetCertificate(), cd);
  276. FormatCertDescription(cd, str);
  277. SetDlgItemText(IDC_CERT_CONTENTS, str);
  278. CString strPath = m_pCert->m_ReqFileName;
  279. CompactPathToWidth(GetDlgItem(IDC_FILE_NAME), strPath);
  280. SetDlgItemText(IDC_FILE_NAME, strPath);
  281. return TRUE;
  282. }
  283. return FALSE;
  284. }
  285. LRESULT CRequestToFilePage::OnWizardNext()
  286. {
  287. GetCertificate()->PrepareRequest();
  288. return IDD_PAGE_NEXT;
  289. }
  290. /////////////////////////////////////////////////////////////////////////////
  291. // COnlineRequestSubmit property page
  292. IMPLEMENT_DYNCREATE(COnlineRequestSubmit, CCertContentsPage)
  293. BOOL
  294. COnlineRequestSubmit::GetCertDescription(CERT_DESCRIPTION& cd)
  295. {
  296. // we have all data in CCertificate
  297. return ExtractDescription(GetCertificate(), cd);
  298. }
  299. LRESULT COnlineRequestSubmit::OnWizardNext()
  300. {
  301. LRESULT id = IDD_PAGE_NEXT;
  302. BeginWaitCursor();
  303. if (GetCertificate()->GetStatusCode() == CCertificate::REQUEST_RENEW_CERT)
  304. GetCertificate()->SubmitRenewalRequest();
  305. else if (m_pCert->GetStatusCode() == CCertificate::REQUEST_NEW_CERT)
  306. GetCertificate()->SubmitRequest();
  307. else
  308. id = 1;
  309. EndWaitCursor();
  310. return id;
  311. }
  312. BOOL COnlineRequestSubmit::OnSetActive()
  313. {
  314. ASSERT(GetCertificate() != NULL);
  315. ASSERT(GetDlgItem(IDC_CA_NAME) != NULL);
  316. if (CCertContentsPage::OnSetActive())
  317. {
  318. SetDlgItemText(IDC_CA_NAME, GetCertificate()->m_ConfigCA);
  319. return TRUE;
  320. }
  321. return FALSE;
  322. }