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.

215 lines
6.2 KiB

  1. /////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000-2001.
  5. //
  6. // File: BasicConstraintsDlg.cpp
  7. //
  8. // Contents: Implementation of CBasicConstraintsDlg
  9. //
  10. //----------------------------------------------------------------------------
  11. // BasicConstraintsDlg.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "BasicConstraintsDlg.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CBasicConstraintsDlg property page
  22. CBasicConstraintsDlg::CBasicConstraintsDlg(CWnd* pParent,
  23. CCertTemplate& rCertTemplate,
  24. PCERT_EXTENSION pCertExtension)
  25. : CHelpDialog(CBasicConstraintsDlg::IDD, pParent),
  26. m_rCertTemplate (rCertTemplate),
  27. m_pCertExtension (pCertExtension),
  28. m_bModified (false),
  29. m_pBCInfo (0),
  30. m_cbInfo (0)
  31. {
  32. //{{AFX_DATA_INIT(CBasicConstraintsDlg)
  33. // NOTE: the ClassWizard will add member initialization here
  34. //}}AFX_DATA_INIT
  35. m_rCertTemplate.AddRef ();
  36. }
  37. CBasicConstraintsDlg::~CBasicConstraintsDlg()
  38. {
  39. if ( m_pBCInfo )
  40. LocalFree (m_pBCInfo);
  41. m_rCertTemplate.Release ();
  42. }
  43. void CBasicConstraintsDlg::DoDataExchange(CDataExchange* pDX)
  44. {
  45. CHelpDialog::DoDataExchange(pDX);
  46. //{{AFX_DATA_MAP(CBasicConstraintsDlg)
  47. // NOTE: the ClassWizard will add DDX and DDV calls here
  48. //}}AFX_DATA_MAP
  49. }
  50. BEGIN_MESSAGE_MAP(CBasicConstraintsDlg, CHelpDialog)
  51. //{{AFX_MSG_MAP(CBasicConstraintsDlg)
  52. ON_WM_CANCELMODE()
  53. ON_BN_CLICKED(IDC_BASIC_CONSTRAINTS_CRITICAL, OnBasicConstraintsCritical)
  54. ON_BN_CLICKED(IDC_ONLY_ISSUE_END_ENTITIES, OnOnlyIssueEndEntities)
  55. //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CBasicConstraintsDlg message handlers
  59. BOOL CBasicConstraintsDlg::OnInitDialog()
  60. {
  61. _TRACE (1, L"Entering CBasicConstraintsDlg::OnInitDialog\n");
  62. CHelpDialog::OnInitDialog();
  63. if ( m_pCertExtension->fCritical )
  64. SendDlgItemMessage (IDC_BASIC_CONSTRAINTS_CRITICAL, BM_SETCHECK, BST_CHECKED);
  65. if ( 1 == m_rCertTemplate.GetType () )
  66. {
  67. GetDlgItem (IDC_BASIC_CONSTRAINTS_CRITICAL)->EnableWindow (FALSE);
  68. GetDlgItem (IDC_ONLY_ISSUE_END_ENTITIES)->EnableWindow (FALSE);
  69. }
  70. if ( CryptDecodeObject (
  71. X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  72. szOID_BASIC_CONSTRAINTS2,
  73. m_pCertExtension->Value.pbData,
  74. m_pCertExtension->Value.cbData,
  75. 0,
  76. 0,
  77. &m_cbInfo) )
  78. {
  79. m_pBCInfo = (PCERT_BASIC_CONSTRAINTS2_INFO) ::LocalAlloc (
  80. LPTR, m_cbInfo);
  81. if ( m_pBCInfo )
  82. {
  83. if ( CryptDecodeObject (
  84. X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  85. szOID_BASIC_CONSTRAINTS2,
  86. m_pCertExtension->Value.pbData,
  87. m_pCertExtension->Value.cbData,
  88. 0,
  89. m_pBCInfo,
  90. &m_cbInfo) )
  91. {
  92. if ( m_pBCInfo->fPathLenConstraint )
  93. SendDlgItemMessage (IDC_ONLY_ISSUE_END_ENTITIES, BM_SETCHECK, BST_CHECKED);
  94. }
  95. else
  96. {
  97. _TRACE (0, L"CryptDecodeObjectEx (szOID_BASIC_CONSTRAINTS2) failed: 0x%x\n", GetLastError ());
  98. }
  99. }
  100. }
  101. else
  102. {
  103. DWORD dwErr = GetLastError ();
  104. CString text;
  105. CString caption;
  106. CThemeContextActivator activator;
  107. VERIFY (caption.LoadString (IDS_CERTTMPL));
  108. text.FormatMessage (IDS_CANNOT_READ_BASIC_CONSTRAINTS, GetSystemMessage (dwErr));
  109. MessageBox (text, caption, MB_ICONWARNING);
  110. _TRACE (0, L"CryptDecodeObjectEx (szOID_BASIC_CONSTRAINTS2) failed: 0x%x\n", dwErr);
  111. }
  112. EnableControls ();
  113. _TRACE (-1, L"Leaving CBasicConstraintsDlg::OnInitDialog\n");
  114. return TRUE; // return TRUE unless you set the focus to a control
  115. // EXCEPTION: OCX Property Pages should return FALSE
  116. }
  117. void CBasicConstraintsDlg::OnBasicConstraintsCritical()
  118. {
  119. m_pCertExtension->fCritical = BST_CHECKED == SendDlgItemMessage (IDC_BASIC_CONSTRAINTS_CRITICAL, BM_GETCHECK);
  120. m_bModified = true;
  121. EnableControls ();
  122. }
  123. void CBasicConstraintsDlg::EnableControls()
  124. {
  125. if ( 1 == m_rCertTemplate.GetType () )
  126. {
  127. GetDlgItem (IDOK)->EnableWindow (FALSE);
  128. GetDlgItem (IDC_BASIC_CONSTRAINTS_CRITICAL)->EnableWindow (FALSE);
  129. GetDlgItem (IDC_ONLY_ISSUE_END_ENTITIES)->EnableWindow (FALSE);
  130. }
  131. else
  132. {
  133. GetDlgItem (IDOK)->EnableWindow (m_bModified && !m_rCertTemplate.ReadOnly ());
  134. GetDlgItem (IDC_BASIC_CONSTRAINTS_CRITICAL)->EnableWindow (!m_rCertTemplate.ReadOnly ());
  135. GetDlgItem (IDC_ONLY_ISSUE_END_ENTITIES)->EnableWindow (!m_rCertTemplate.ReadOnly ());
  136. }
  137. }
  138. void CBasicConstraintsDlg::OnOnlyIssueEndEntities()
  139. {
  140. m_bModified = true;
  141. EnableControls ();
  142. }
  143. void CBasicConstraintsDlg::DoContextHelp (HWND hWndControl)
  144. {
  145. _TRACE(1, L"Entering CBasicConstraintsDlg::DoContextHelp\n");
  146. switch (::GetDlgCtrlID (hWndControl))
  147. {
  148. case IDC_STATIC:
  149. break;
  150. default:
  151. // Display context help for a control
  152. if ( !::WinHelp (
  153. hWndControl,
  154. GetContextHelpFile (),
  155. HELP_WM_HELP,
  156. (DWORD_PTR) g_aHelpIDs_IDD_BASIC_CONSTRAINTS) )
  157. {
  158. _TRACE(0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  159. }
  160. break;
  161. }
  162. _TRACE(-1, L"Leaving CBasicConstraintsDlg::DoContextHelp\n");
  163. }
  164. void CBasicConstraintsDlg::OnOK()
  165. {
  166. if ( m_pBCInfo )
  167. {
  168. if ( BST_CHECKED == SendDlgItemMessage (IDC_ONLY_ISSUE_END_ENTITIES, BM_GETCHECK) )
  169. {
  170. m_pBCInfo->dwPathLenConstraint = 0;
  171. m_pBCInfo->fPathLenConstraint = TRUE;
  172. }
  173. else
  174. {
  175. m_pBCInfo->dwPathLenConstraint = (DWORD) -1;
  176. m_pBCInfo->fPathLenConstraint = FALSE;
  177. }
  178. bool bCritical = BST_CHECKED == SendDlgItemMessage (
  179. IDC_BASIC_CONSTRAINTS_CRITICAL, BM_GETCHECK);
  180. HRESULT hr = m_rCertTemplate.SetBasicConstraints (m_pBCInfo, bCritical);
  181. if ( FAILED (hr) )
  182. return;
  183. }
  184. else
  185. return;
  186. CHelpDialog::OnOK();
  187. }