Leaked source code of windows server 2003
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.

142 lines
4.2 KiB

  1. /////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000-2001.
  5. //
  6. // File: ExtendedKeyUsagePropertyPage.cpp
  7. //
  8. // Contents: Implementation of CExtendedKeyUsagePropertyPage
  9. //
  10. //----------------------------------------------------------------------------
  11. // ExtendedKeyUsagePropertyPage.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "ExtendedKeyUsagePropertyPage.h"
  15. #include "NewOIDDlg.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CExtendedKeyUsagePropertyPage dialog
  23. CExtendedKeyUsagePropertyPage::CExtendedKeyUsagePropertyPage(
  24. CCertTemplate& rCertTemplate,
  25. PCERT_EXTENSION pCertExtension)
  26. : CPropertyPage(CExtendedKeyUsagePropertyPage::IDD),
  27. m_rCertTemplate (rCertTemplate),
  28. m_pCertExtension (pCertExtension)
  29. {
  30. //{{AFX_DATA_INIT(CExtendedKeyUsagePropertyPage)
  31. // NOTE: the ClassWizard will add member initialization here
  32. //}}AFX_DATA_INIT
  33. }
  34. void CExtendedKeyUsagePropertyPage::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CPropertyPage::DoDataExchange(pDX);
  37. //{{AFX_DATA_MAP(CExtendedKeyUsagePropertyPage)
  38. DDX_Control(pDX, IDC_EKU_LIST, m_EKUList);
  39. //}}AFX_DATA_MAP
  40. }
  41. BEGIN_MESSAGE_MAP(CExtendedKeyUsagePropertyPage, CPropertyPage)
  42. //{{AFX_MSG_MAP(CExtendedKeyUsagePropertyPage)
  43. ON_BN_CLICKED(IDC_NEW_EKU, OnNewEku)
  44. //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CExtendedKeyUsagePropertyPage message handlers
  48. void CExtendedKeyUsagePropertyPage::OnNewEku()
  49. {
  50. CNewOIDDlg oidDlg;
  51. CThemeContextActivator activator;
  52. oidDlg.DoModal ();
  53. }
  54. BOOL CExtendedKeyUsagePropertyPage::OnInitDialog()
  55. {
  56. _TRACE (1, L"Entering CExtendedKeyUsagePropertyPage::OnInitDialog ()\n");
  57. CPropertyPage::OnInitDialog();
  58. ASSERT (m_pCertExtension);
  59. if ( m_pCertExtension )
  60. {
  61. DWORD cbEnhKeyUsage = 0;
  62. if ( ::CryptDecodeObject(CRYPT_ASN_ENCODING,
  63. szOID_ENHANCED_KEY_USAGE,
  64. m_pCertExtension->Value.pbData,
  65. m_pCertExtension->Value.cbData,
  66. 0, NULL, &cbEnhKeyUsage) )
  67. {
  68. PCERT_ENHKEY_USAGE pEnhKeyUsage = (PCERT_ENHKEY_USAGE)
  69. ::LocalAlloc (LPTR, cbEnhKeyUsage);
  70. if ( pEnhKeyUsage )
  71. {
  72. if ( ::CryptDecodeObject (CRYPT_ASN_ENCODING,
  73. szOID_ENHANCED_KEY_USAGE,
  74. m_pCertExtension->Value.pbData,
  75. m_pCertExtension->Value.cbData,
  76. 0, pEnhKeyUsage, &cbEnhKeyUsage) )
  77. {
  78. CString usageName;
  79. for (DWORD dwIndex = 0;
  80. dwIndex < pEnhKeyUsage->cUsageIdentifier;
  81. dwIndex++)
  82. {
  83. if ( MyGetOIDInfoA (usageName,
  84. pEnhKeyUsage->rgpszUsageIdentifier[dwIndex]) )
  85. {
  86. int nIndex = m_EKUList.AddString (usageName);
  87. if ( nIndex >= 0 )
  88. {
  89. m_EKUList.SetCheck (nIndex, BST_CHECKED);
  90. m_EKUList.SetItemDataPtr (nIndex,
  91. pEnhKeyUsage->rgpszUsageIdentifier[dwIndex]);
  92. }
  93. }
  94. }
  95. }
  96. else
  97. {
  98. DWORD dwErr = GetLastError ();
  99. _TRACE (0, L"CryptDecodeObject (szOID_ENHANCED_KEY_USAGE) failed: 0x%x\n", dwErr);
  100. DisplaySystemError (NULL, dwErr);
  101. }
  102. ::LocalFree (pEnhKeyUsage);
  103. }
  104. }
  105. else
  106. {
  107. DWORD dwErr = GetLastError ();
  108. _TRACE (0, L"CryptDecodeObject (szOID_ENHANCED_KEY_USAGE) failed: 0x%x\n", dwErr);
  109. DisplaySystemError (NULL, dwErr);
  110. }
  111. }
  112. if ( 1 == m_rCertTemplate.GetType () )
  113. {
  114. int nCnt = m_EKUList.GetCount ();
  115. for (int nIndex = 0; nIndex < nCnt; nIndex++)
  116. m_EKUList.Enable (nIndex, FALSE);
  117. GetDlgItem (IDC_NEW_EKU)->EnableWindow (FALSE);
  118. }
  119. _TRACE (-1, L"Leaving CExtendedKeyUsagePropertyPage::OnInitDialog ()\n");
  120. return TRUE; // return TRUE unless you set the focus to a control
  121. // EXCEPTION: OCX Property Pages should return FALSE
  122. }