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.

219 lines
5.4 KiB

  1. // NKKyInfo.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "resource.h"
  5. #include "keyring.h"
  6. #include "NKChseCA.h"
  7. #include "NKKyInfo.h"
  8. extern "C"
  9. {
  10. #include <wincrypt.h>
  11. #include <sslsp.h>
  12. }
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CNKKeyInfo dialog
  20. CNKKeyInfo::CNKKeyInfo(CWnd* pParent /*=NULL*/)
  21. : CNKPages(CNKKeyInfo::IDD)
  22. {
  23. //{{AFX_DATA_INIT(CNKKeyInfo)
  24. m_nkki_sz_password = _T("");
  25. m_nkki_sz_password2 = _T("");
  26. m_nkki_sz_name = _T("");
  27. //}}AFX_DATA_INIT
  28. }
  29. void CNKKeyInfo::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CDialog::DoDataExchange(pDX);
  32. //{{AFX_DATA_MAP(CNKKeyInfo)
  33. DDX_Control(pDX, IDC_NEW_NKKI_PASSWORD, m_nkki_cedit_password);
  34. DDX_Control(pDX, IDC_NKKI_BITS, m_nkki_ccombo_bits);
  35. DDX_Text(pDX, IDC_NEW_NKKI_PASSWORD, m_nkki_sz_password);
  36. DDX_Text(pDX, IDC_NEW_NKKI_PASSWORD2, m_nkki_sz_password2);
  37. DDX_Text(pDX, IDC_NKKI_NAME, m_nkki_sz_name);
  38. DDV_MaxChars(pDX, m_nkki_sz_name, 128);
  39. //}}AFX_DATA_MAP
  40. }
  41. BEGIN_MESSAGE_MAP(CNKKeyInfo, CDialog)
  42. //{{AFX_MSG_MAP(CNKKeyInfo)
  43. ON_EN_CHANGE(IDC_NEW_NKKI_PASSWORD, OnChangeNewNkkiPassword)
  44. ON_EN_CHANGE(IDC_NEW_NKKI_PASSWORD2, OnChangeNewNkkiPassword2)
  45. ON_EN_CHANGE(IDC_NKKI_NAME, OnChangeNkkiName)
  46. ON_EN_KILLFOCUS(IDC_NEW_NKKI_PASSWORD2, OnKillfocusNewNkkiPassword2)
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. //----------------------------------------------------------------
  50. BOOL CNKKeyInfo::OnInitDialog( )
  51. {
  52. // give the key a default name
  53. m_nkki_sz_name.LoadString( IDS_CREATE_KEY_NEW_NAME );
  54. // call superclass
  55. CPropertyPage::OnInitDialog();
  56. // to comply with the munitions export laws, we need to limit the max bits available
  57. m_nMaxBits = 1024;
  58. m_nMaxBits = SslGetMaximumKeySize(NULL);
  59. // set the default bit size
  60. m_nBits = m_nMaxBits;
  61. m_nkki_ccombo_bits.SetCurSel( 2 );
  62. // if necessary, remove items from the bits combo box
  63. if ( m_nMaxBits < 1024 )
  64. {
  65. m_nkki_ccombo_bits.DeleteString(2);
  66. m_nkki_ccombo_bits.SetCurSel( 1 );
  67. }
  68. if ( m_nMaxBits < 768 )
  69. {
  70. m_nkki_ccombo_bits.DeleteString(1);
  71. m_nkki_ccombo_bits.SetCurSel( 0 );
  72. }
  73. // return 0 to say we set the default item
  74. // return 1 to just select the default default item
  75. return 1;
  76. }
  77. //----------------------------------------------------------------
  78. BOOL CNKKeyInfo::OnSetActive()
  79. {
  80. ActivateButtons();
  81. return CPropertyPage::OnSetActive();
  82. }
  83. //----------------------------------------------------------------
  84. void CNKKeyInfo::ActivateButtons()
  85. {
  86. DWORD flags = PSWIZB_BACK;
  87. BOOL fCanGoOn = TRUE;
  88. UpdateData(TRUE);
  89. //now make sure there is something in each of the required fields
  90. fCanGoOn &= !m_nkki_sz_name.IsEmpty();
  91. fCanGoOn &= !m_nkki_sz_password.IsEmpty();
  92. fCanGoOn &= !m_nkki_sz_password2.IsEmpty();
  93. // if we can go on, hilite the button
  94. if ( fCanGoOn )
  95. {
  96. flags |= PSWIZB_NEXT;
  97. }
  98. // update the property sheet buttons
  99. m_pPropSheet->SetWizardButtons( flags );
  100. }
  101. //----------------------------------------------------------------
  102. LRESULT CNKKeyInfo::OnWizardNext()
  103. {
  104. // get the data
  105. UpdateData(TRUE);
  106. // start by testing that the passwords match each other
  107. if ( m_nkki_sz_password != m_nkki_sz_password2 )
  108. {
  109. // the fields are not equal. start with the error dialog
  110. AfxMessageBox( IDS_PASSWORD_ERROR );
  111. // blank out both the fields
  112. m_nkki_sz_password.Empty();
  113. m_nkki_sz_password2.Empty();
  114. UpdateData(FALSE);
  115. // set the focus to the first password field
  116. m_nkki_cedit_password.SetFocus();
  117. // return -1 to prevent going to the next pane
  118. return -1;
  119. }
  120. // get the bit size
  121. switch( m_nkki_ccombo_bits.GetCurSel() )
  122. {
  123. case 0: // bits == 512
  124. m_nBits = 512;
  125. break;
  126. case 1: // bits == 768
  127. m_nBits = 768;
  128. break;
  129. case 2: // bits == 1024
  130. m_nBits = 1024;
  131. break;
  132. };
  133. // call the superclass OnWizardNext
  134. return CPropertyPage::OnWizardNext();
  135. }
  136. /////////////////////////////////////////////////////////////////////////////
  137. // CNKKeyInfo message handlers
  138. //----------------------------------------------------------------
  139. void CNKKeyInfo::OnChangeNewNkkiPassword()
  140. {
  141. // let them know they have to confirm, or re-confirm it
  142. UpdateData(TRUE);
  143. m_nkki_sz_password2.Empty();
  144. UpdateData(FALSE);
  145. ActivateButtons();
  146. }
  147. //----------------------------------------------------------------
  148. void CNKKeyInfo::OnChangeNewNkkiPassword2()
  149. {
  150. ActivateButtons();
  151. }
  152. //----------------------------------------------------------------
  153. void CNKKeyInfo::OnChangeNkkiName()
  154. {
  155. ActivateButtons();
  156. }
  157. //----------------------------------------------------------------
  158. // this is the main place we check to see if the passwords are the same.
  159. // if they are not, then we should put up an error dialog and blank out
  160. // both of the password fields, putting the focus into password1
  161. void CNKKeyInfo::OnKillfocusNewNkkiPassword2()
  162. {
  163. /*
  164. // get the data
  165. UpdateData(TRUE);
  166. // if the fields are equal, leave now
  167. if ( m_nkki_sz_password == m_nkki_sz_password2 )
  168. return;
  169. // the fields are not equal. start with the error dialog
  170. AfxMessageBox( IDS_PASSWORD_ERROR );
  171. // blank out both the fields
  172. m_nkki_sz_password.Empty();
  173. m_nkki_sz_password2.Empty();
  174. UpdateData(FALSE);
  175. // set the focus to the first password field
  176. m_nkki_cedit_password.SetFocus();
  177. */
  178. }