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.

347 lines
8.0 KiB

  1. // KeyPasswordPage.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CertWiz.h"
  5. #include "KeyPasswordPage.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. /////////////////////////////////////////////////////////////////////////////
  13. // CKeyPasswordPage property page
  14. IMPLEMENT_DYNCREATE(CKeyPasswordPage, CIISWizardPage)
  15. CKeyPasswordPage::CKeyPasswordPage(CCertificate * pCert)
  16. : CIISWizardPage(CKeyPasswordPage::IDD, IDS_CERTWIZ, TRUE),
  17. m_pCert(pCert)
  18. {
  19. //{{AFX_DATA_INIT(CKeyPasswordPage)
  20. m_Password = _T("");
  21. //}}AFX_DATA_INIT
  22. }
  23. CKeyPasswordPage::~CKeyPasswordPage()
  24. {
  25. }
  26. void CKeyPasswordPage::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CIISWizardPage::DoDataExchange(pDX);
  29. //{{AFX_DATA_MAP(CKeyPasswordPage)
  30. DDX_Text(pDX, IDC_KEYPASSWORD, m_Password);
  31. DDV_MaxChars(pDX, m_Password, 64);
  32. //}}AFX_DATA_MAP
  33. }
  34. LRESULT
  35. CKeyPasswordPage::OnWizardBack()
  36. /*++
  37. Routine Description:
  38. Prev button handler
  39. Arguments:
  40. None
  41. Return Value:
  42. 0 to automatically advance to the prev page;
  43. 1 to prevent the page from changing.
  44. To jump to a page other than the prev one,
  45. return the identifier of the dialog to be displayed.
  46. --*/
  47. {
  48. return IDD_PAGE_PREV;
  49. }
  50. LRESULT
  51. CKeyPasswordPage::OnWizardNext()
  52. {
  53. UpdateData(TRUE);
  54. if (0 != m_Password.Compare(m_pCert->m_KeyPassword))
  55. {
  56. m_pCert->DeleteKeyRingCert();
  57. m_pCert->m_KeyPassword = m_Password;
  58. }
  59. if (NULL == m_pCert->GetKeyRingCert())
  60. {
  61. // probably password was wrong
  62. CString txt;
  63. txt.LoadString(IDS_FAILED_IMPORT_KEY_FILE);
  64. ASSERT(GetDlgItem(IDC_ERROR_TEXT) != NULL);
  65. SetDlgItemText(IDC_ERROR_TEXT, txt);
  66. GetDlgItem(IDC_KEYPASSWORD)->SetFocus();
  67. GetDlgItem(IDC_KEYPASSWORD)->SendMessage(EM_SETSEL, 0, -1);
  68. SetWizardButtons(PSWIZB_BACK);
  69. return 1;
  70. }
  71. return IDD_PAGE_NEXT;
  72. }
  73. BOOL
  74. CKeyPasswordPage::OnSetActive()
  75. {
  76. ASSERT(m_pCert != NULL);
  77. m_Password = m_pCert->m_KeyPassword;
  78. UpdateData(FALSE);
  79. SetWizardButtons(m_Password.IsEmpty() || m_pCert->GetKeyRingCert() == NULL ?
  80. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  81. return CIISWizardPage::OnSetActive();
  82. }
  83. BOOL
  84. CKeyPasswordPage::OnKillActive()
  85. {
  86. UpdateData();
  87. m_pCert->m_KeyPassword = m_Password;
  88. return CIISWizardPage::OnKillActive();
  89. }
  90. BEGIN_MESSAGE_MAP(CKeyPasswordPage, CIISWizardPage)
  91. //{{AFX_MSG_MAP(CKeyPasswordPage)
  92. ON_EN_CHANGE(IDC_KEYPASSWORD, OnEditchangePassword)
  93. //}}AFX_MSG_MAP
  94. END_MESSAGE_MAP()
  95. /////////////////////////////////////////////////////////////////////////////
  96. // CSiteNamePage message handlers
  97. void CKeyPasswordPage::OnEditchangePassword()
  98. {
  99. UpdateData(TRUE);
  100. SetWizardButtons(m_Password.IsEmpty() ?
  101. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  102. CString str;
  103. SetDlgItemText(IDC_ERROR_TEXT, str);
  104. }
  105. /////////////////////////////////////////////////////////////////////////////
  106. // CKeyPasswordPage property page
  107. IMPLEMENT_DYNCREATE(CImportPFXPasswordPage, CIISWizardPage)
  108. CImportPFXPasswordPage::CImportPFXPasswordPage(CCertificate * pCert)
  109. : CIISWizardPage(CImportPFXPasswordPage::IDD, IDS_CERTWIZ, TRUE),
  110. m_pCert(pCert)
  111. {
  112. //{{AFX_DATA_INIT(CImportPFXPasswordPage)
  113. m_Password = _T("");
  114. //}}AFX_DATA_INIT
  115. }
  116. CImportPFXPasswordPage::~CImportPFXPasswordPage()
  117. {
  118. }
  119. void CImportPFXPasswordPage::DoDataExchange(CDataExchange* pDX)
  120. {
  121. CIISWizardPage::DoDataExchange(pDX);
  122. //{{AFX_DATA_MAP(CImportPFXPasswordPage)
  123. DDX_Text(pDX, IDC_KEYPASSWORD, m_Password);
  124. DDV_MaxChars(pDX, m_Password, 64);
  125. //}}AFX_DATA_MAP
  126. }
  127. LRESULT
  128. CImportPFXPasswordPage::OnWizardBack()
  129. /*++
  130. Routine Description:
  131. Prev button handler
  132. Arguments:
  133. None
  134. Return Value:
  135. 0 to automatically advance to the prev page;
  136. 1 to prevent the page from changing.
  137. To jump to a page other than the prev one,
  138. return the identifier of the dialog to be displayed.
  139. --*/
  140. {
  141. return IDD_PAGE_PREV;
  142. }
  143. LRESULT
  144. CImportPFXPasswordPage::OnWizardNext()
  145. {
  146. UpdateData(TRUE);
  147. if (0 != m_Password.Compare(m_pCert->m_KeyPassword))
  148. {
  149. m_pCert->DeleteKeyRingCert();
  150. m_pCert->m_KeyPassword = m_Password;
  151. }
  152. if (NULL == m_pCert->GetPFXFileCert())
  153. {
  154. // probably password was wrong
  155. CString txt;
  156. txt.LoadString(IDS_FAILED_IMPORT_PFX_FILE);
  157. ASSERT(GetDlgItem(IDC_ERROR_TEXT) != NULL);
  158. SetDlgItemText(IDC_ERROR_TEXT, txt);
  159. GetDlgItem(IDC_KEYPASSWORD)->SetFocus();
  160. GetDlgItem(IDC_KEYPASSWORD)->SendMessage(EM_SETSEL, 0, -1);
  161. SetWizardButtons(PSWIZB_BACK);
  162. return 1;
  163. }
  164. return IDD_PAGE_NEXT;
  165. }
  166. BOOL
  167. CImportPFXPasswordPage::OnSetActive()
  168. {
  169. ASSERT(m_pCert != NULL);
  170. m_Password = m_pCert->m_KeyPassword;
  171. UpdateData(FALSE);
  172. SetWizardButtons(m_Password.IsEmpty() || m_pCert->GetKeyRingCert() == NULL ?
  173. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  174. return CIISWizardPage::OnSetActive();
  175. }
  176. BOOL
  177. CImportPFXPasswordPage::OnKillActive()
  178. {
  179. UpdateData();
  180. m_pCert->m_KeyPassword = m_Password;
  181. return CIISWizardPage::OnKillActive();
  182. }
  183. BEGIN_MESSAGE_MAP(CImportPFXPasswordPage, CIISWizardPage)
  184. //{{AFX_MSG_MAP(CImportPFXPasswordPage)
  185. ON_EN_CHANGE(IDC_KEYPASSWORD, OnEditchangePassword)
  186. //}}AFX_MSG_MAP
  187. END_MESSAGE_MAP()
  188. /////////////////////////////////////////////////////////////////////////////
  189. // CSiteNamePage message handlers
  190. void CImportPFXPasswordPage::OnEditchangePassword()
  191. {
  192. UpdateData(TRUE);
  193. SetWizardButtons(m_Password.IsEmpty() ?
  194. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  195. CString str;
  196. SetDlgItemText(IDC_ERROR_TEXT, str);
  197. }
  198. /////////////////////////////////////////////////////////////////////////////
  199. // CExportPFXPasswordPage property page
  200. IMPLEMENT_DYNCREATE(CExportPFXPasswordPage, CIISWizardPage)
  201. CExportPFXPasswordPage::CExportPFXPasswordPage(CCertificate * pCert)
  202. : CIISWizardPage(CExportPFXPasswordPage::IDD, IDS_CERTWIZ, TRUE),
  203. m_pCert(pCert)
  204. {
  205. //{{AFX_DATA_INIT(CExportPFXPasswordPage)
  206. m_Password = _T("");
  207. m_Export_Private_key = FALSE;
  208. //}}AFX_DATA_INIT
  209. }
  210. CExportPFXPasswordPage::~CExportPFXPasswordPage()
  211. {
  212. }
  213. void CExportPFXPasswordPage::DoDataExchange(CDataExchange* pDX)
  214. {
  215. CIISWizardPage::DoDataExchange(pDX);
  216. //{{AFX_DATA_MAP(CExportPFXPasswordPage)
  217. DDX_Text(pDX, IDC_KEYPASSWORD, m_Password);
  218. DDV_MaxChars(pDX, m_Password, 64);
  219. DDX_Check(pDX, IDC_CHK_EXPORT_PRIVATE, m_Export_Private_key);
  220. //}}AFX_DATA_MAP
  221. }
  222. LRESULT
  223. CExportPFXPasswordPage::OnWizardBack()
  224. /*++
  225. Routine Description:
  226. Prev button handler
  227. Arguments:
  228. None
  229. Return Value:
  230. 0 to automatically advance to the prev page;
  231. 1 to prevent the page from changing.
  232. To jump to a page other than the prev one,
  233. return the identifier of the dialog to be displayed.
  234. --*/
  235. {
  236. return IDD_PAGE_PREV;
  237. }
  238. LRESULT
  239. CExportPFXPasswordPage::OnWizardNext()
  240. {
  241. UpdateData(TRUE);
  242. if (0 != m_Password.Compare(m_pCert->m_KeyPassword))
  243. {
  244. m_pCert->DeleteKeyRingCert();
  245. m_pCert->m_KeyPassword = m_Password;
  246. m_pCert->m_ExportPFXPrivateKey = m_Export_Private_key;
  247. m_pCert->m_ExportPFXPrivateKey = TRUE;
  248. }
  249. /*
  250. if (NULL == m_pCert->GetKeyRingCert())
  251. {
  252. // probably password was wrong
  253. CString txt;
  254. txt.LoadString(IDS_FAILED_IMPORT_KEY_FILE);
  255. ASSERT(GetDlgItem(IDC_ERROR_TEXT) != NULL);
  256. SetDlgItemText(IDC_ERROR_TEXT, txt);
  257. GetDlgItem(IDC_KEYPASSWORD)->SetFocus();
  258. GetDlgItem(IDC_KEYPASSWORD)->SendMessage(EM_SETSEL, 0, -1);
  259. SetWizardButtons(PSWIZB_BACK);
  260. return 1;
  261. }
  262. */
  263. return IDD_PAGE_NEXT;
  264. }
  265. BOOL
  266. CExportPFXPasswordPage::OnSetActive()
  267. {
  268. ASSERT(m_pCert != NULL);
  269. m_Password = m_pCert->m_KeyPassword;
  270. UpdateData(FALSE);
  271. SetWizardButtons(m_Password.IsEmpty() || m_pCert->GetKeyRingCert() == NULL ?
  272. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  273. return CIISWizardPage::OnSetActive();
  274. }
  275. BOOL
  276. CExportPFXPasswordPage::OnKillActive()
  277. {
  278. UpdateData();
  279. m_pCert->m_KeyPassword = m_Password;
  280. return CIISWizardPage::OnKillActive();
  281. }
  282. BEGIN_MESSAGE_MAP(CExportPFXPasswordPage, CIISWizardPage)
  283. //{{AFX_MSG_MAP(CExportPFXPasswordPage)
  284. ON_EN_CHANGE(IDC_KEYPASSWORD, OnEditchangePassword)
  285. //}}AFX_MSG_MAP
  286. END_MESSAGE_MAP()
  287. void CExportPFXPasswordPage::OnEditchangePassword()
  288. {
  289. UpdateData(TRUE);
  290. SetWizardButtons(m_Password.IsEmpty() ?
  291. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  292. CString str;
  293. SetDlgItemText(IDC_ERROR_TEXT, str);
  294. }