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.

247 lines
6.2 KiB

  1. // ReplaceChooseCert.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CertWiz.h"
  5. #include "ChooseCertPage.h"
  6. #include "Certificat.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. #define COL_COMMON_NAME 0
  13. #define COL_CA_NAME 1
  14. #define COL_EXPIRATION_DATE 2
  15. #define COL_PURPOSE 3
  16. #define COL_FRIENDLY_NAME 4
  17. #define COL_COMMON_NAME_WID 100
  18. #define COL_CA_NAME_WID 100
  19. #define COL_EXPIRATION_DATE_WID 100
  20. #define COL_PURPOSE_WID 100
  21. #define COL_FRIENDLY_NAME_WID 100
  22. int
  23. CCertListCtrl::GetSelectedIndex()
  24. {
  25. #if _AFX_VER >= 0x0600
  26. POSITION pos = GetFirstSelectedItemPosition();
  27. return pos != NULL ? GetNextSelectedItem(pos) : -1;
  28. #else
  29. // I guess we should do it in a hard way
  30. int count = GetItemCount();
  31. int index = -1;
  32. for (int i = 0; i < count; i++)
  33. {
  34. if (GetItemState(i, LVIS_SELECTED))
  35. {
  36. index = i;
  37. break;
  38. }
  39. }
  40. return index;
  41. #endif
  42. }
  43. void
  44. CCertListCtrl::AdjustStyle()
  45. {
  46. #if _AFX_VER >= 0x0600
  47. DWORD dwStyle = m_CertList.GetExtendedStyle();
  48. m_CertList.SetExtendedStyle(dwStyle | LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP);
  49. #else
  50. ASSERT(m_hWnd != NULL);
  51. DWORD dwStyle = ListView_GetExtendedListViewStyle(m_hWnd);
  52. ListView_SetExtendedListViewStyle(m_hWnd,
  53. dwStyle | LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP);
  54. #endif
  55. }
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CChooseCertPage property page
  58. IMPLEMENT_DYNCREATE(CChooseCertPage, CIISWizardPage)
  59. CChooseCertPage::CChooseCertPage(CCertificate * pCert)
  60. : CIISWizardPage(CChooseCertPage::IDD, IDS_CERTWIZ, TRUE),
  61. m_pCert(pCert)
  62. {
  63. //{{AFX_DATA_INIT(CChooseCertPage)
  64. // NOTE: the ClassWizard will add member initialization here
  65. //}}AFX_DATA_INIT
  66. }
  67. CChooseCertPage::~CChooseCertPage()
  68. {
  69. }
  70. void CChooseCertPage::DoDataExchange(CDataExchange* pDX)
  71. {
  72. CIISWizardPage::DoDataExchange(pDX);
  73. //{{AFX_DATA_MAP(CChooseCertPage)
  74. DDX_Control(pDX, IDC_CERT_LIST, m_CertList);
  75. //}}AFX_DATA_MAP
  76. }
  77. BEGIN_MESSAGE_MAP(CChooseCertPage, CIISWizardPage)
  78. //{{AFX_MSG_MAP(CChooseCertPage)
  79. ON_NOTIFY(NM_CLICK, IDC_CERT_LIST, OnClickCertList)
  80. ON_WM_DESTROY()
  81. //}}AFX_MSG_MAP
  82. END_MESSAGE_MAP()
  83. /////////////////////////////////////////////////////////////////////////////
  84. // CChooseCertPage message handlers
  85. LRESULT CChooseCertPage::OnWizardBack()
  86. {
  87. LRESULT id = 1;
  88. switch (m_pCert->GetStatusCode())
  89. {
  90. case CCertificate::REQUEST_REPLACE_CERT:
  91. id = IDD_PAGE_PREV_REPLACE;
  92. break;
  93. case CCertificate::REQUEST_INSTALL_CERT:
  94. id = IDD_PAGE_PREV_INSTALL;
  95. break;
  96. default:
  97. ASSERT(FALSE);
  98. }
  99. return id;
  100. }
  101. LRESULT CChooseCertPage::OnWizardNext()
  102. {
  103. // get hash pointer for selected cert
  104. int index = m_CertList.GetSelectedIndex();
  105. ASSERT(index != -1);
  106. // find cert in store
  107. CRYPT_HASH_BLOB * pHash = (CRYPT_HASH_BLOB *)m_CertList.GetItemData(index);
  108. ASSERT(pHash != NULL);
  109. m_pCert->m_pSelectedCertHash = pHash;
  110. LRESULT id = 1;
  111. switch (m_pCert->GetStatusCode())
  112. {
  113. case CCertificate::REQUEST_REPLACE_CERT:
  114. id = IDD_PAGE_NEXT_REPLACE;
  115. break;
  116. case CCertificate::REQUEST_INSTALL_CERT:
  117. id = IDD_PAGE_NEXT_INSTALL;
  118. break;
  119. default:
  120. ASSERT(FALSE);
  121. }
  122. return id;
  123. }
  124. BOOL CChooseCertPage::OnSetActive()
  125. {
  126. // If nothing is selected -- stay here
  127. SetWizardButtons(-1 == m_CertList.GetSelectedIndex() ?
  128. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  129. return CIISWizardPage::OnSetActive();
  130. }
  131. BOOL CChooseCertPage::OnInitDialog()
  132. {
  133. ASSERT(m_pCert != NULL);
  134. CIISWizardPage::OnInitDialog();
  135. CString str;
  136. str.LoadString(IDS_ISSUED_TO);
  137. m_CertList.InsertColumn(COL_COMMON_NAME, str, LVCFMT_LEFT, COL_COMMON_NAME_WID);
  138. str.LoadString(IDS_ISSUED_BY);
  139. m_CertList.InsertColumn(COL_CA_NAME, str, LVCFMT_LEFT, COL_CA_NAME_WID);
  140. str.LoadString(IDS_EXPIRATION_DATE);
  141. m_CertList.InsertColumn(COL_EXPIRATION_DATE, str, LVCFMT_LEFT, COL_EXPIRATION_DATE_WID);
  142. str.LoadString(IDS_PURPOSE);
  143. m_CertList.InsertColumn(COL_PURPOSE, str, LVCFMT_LEFT, COL_PURPOSE_WID);
  144. str.LoadString(IDS_FRIENDLY_NAME);
  145. m_CertList.InsertColumn(COL_FRIENDLY_NAME, str, LVCFMT_LEFT, COL_FRIENDLY_NAME_WID);
  146. m_CertList.AdjustStyle();
  147. if (m_pCert->GetCertDescList(m_DescList))
  148. {
  149. int item = 0;
  150. POSITION pos = m_DescList.GetHeadPosition();
  151. LV_ITEMW lvi;
  152. //
  153. // set up the fields in the list view item struct that don't change from item to item
  154. //
  155. memset(&lvi, 0, sizeof(LV_ITEMW));
  156. lvi.mask = LVIF_TEXT;
  157. m_CertList.SetItemCount((int)m_DescList.GetCount());
  158. while (pos != NULL)
  159. {
  160. CERT_DESCRIPTION * pDesc = m_DescList.GetNext(pos);
  161. int i;
  162. lvi.iItem = item;
  163. lvi.iSubItem = 0;
  164. lvi.pszText = (LPTSTR)(LPCTSTR)pDesc->m_CommonName;
  165. lvi.cchTextMax = pDesc->m_CommonName.GetLength();
  166. i = m_CertList.InsertItem(&lvi);
  167. ASSERT(i != -1);
  168. lvi.iItem = i;
  169. lvi.iSubItem = COL_CA_NAME;
  170. lvi.pszText = (LPTSTR)(LPCTSTR)pDesc->m_CAName;
  171. lvi.cchTextMax = pDesc->m_CAName.GetLength();
  172. VERIFY(m_CertList.SetItem(&lvi));
  173. lvi.iSubItem = COL_EXPIRATION_DATE;
  174. lvi.pszText = (LPTSTR)(LPCTSTR)pDesc->m_ExpirationDate;
  175. lvi.cchTextMax = pDesc->m_ExpirationDate.GetLength();
  176. VERIFY(m_CertList.SetItem(&lvi));
  177. lvi.iSubItem = COL_PURPOSE;
  178. lvi.pszText = (LPTSTR)(LPCTSTR)pDesc->m_Usage;
  179. lvi.cchTextMax = pDesc->m_Usage.GetLength();
  180. VERIFY(m_CertList.SetItem(&lvi));
  181. lvi.iSubItem = COL_FRIENDLY_NAME;
  182. lvi.pszText = (LPTSTR)(LPCTSTR)pDesc->m_FriendlyName;
  183. lvi.cchTextMax = pDesc->m_FriendlyName.GetLength();
  184. VERIFY(m_CertList.SetItem(&lvi));
  185. // create CRYPT_HASH_BLOB from desc data and put it to list item
  186. CRYPT_HASH_BLOB * pHashBlob = new CRYPT_HASH_BLOB;
  187. ASSERT(pHashBlob != NULL);
  188. pHashBlob->cbData = pDesc->m_hash_length;
  189. pHashBlob->pbData = pDesc->m_hash;
  190. VERIFY(m_CertList.SetItemData(item, (LONG_PTR)pHashBlob));
  191. item++;
  192. }
  193. }
  194. return TRUE;
  195. }
  196. void CChooseCertPage::OnClickCertList(NMHDR* pNMHDR, LRESULT* pResult)
  197. {
  198. SetWizardButtons(-1 == m_CertList.GetSelectedIndex() ?
  199. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  200. *pResult = 0;
  201. }
  202. void CChooseCertPage::OnDestroy()
  203. {
  204. // before dialog will be desroyed we need to delete all
  205. // the item data pointers
  206. int count = m_CertList.GetItemCount();
  207. for (int index = 0; index < count; index++)
  208. {
  209. CRYPT_HASH_BLOB * pData = (CRYPT_HASH_BLOB *)m_CertList.GetItemData(index);
  210. delete pData;
  211. }
  212. CIISWizardPage::OnDestroy();
  213. }