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.

2081 lines
58 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: wiz.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "wiz.h"
  12. #include <rpc.h>
  13. // sddl.h requires this value to be at least
  14. // 0x0500. Bump it up if necessary. NOTE: This
  15. // 'bump' comes after all other H files that may
  16. // be sensitive to this value.
  17. #if(_WIN32_WINNT < 0x500)
  18. #undef _WIN32_WINNT
  19. #define _WIN32_WINNT 0x0500
  20. #endif
  21. #include <sddl.h>
  22. UINT g_aidFont[] =
  23. {
  24. IDS_LARGEFONTNAME,
  25. IDS_LARGEFONTSIZE,
  26. IDS_SMALLFONTNAME,
  27. IDS_SMALLFONTSIZE,
  28. };
  29. static BOOL IsDisallowedOID(LPCSTR pszOID)
  30. {
  31. if ((strcmp(pszOID, szOID_SGC_NETSCAPE) == 0) ||
  32. (strcmp(pszOID, szOID_SERVER_GATED_CRYPTO) == 0) ||
  33. (strcmp(pszOID, szOID_WHQL_CRYPTO) == 0) ||
  34. (strcmp(pszOID, szOID_NT5_CRYPTO) == 0) ||
  35. (strcmp(pszOID, szOID_KP_TIME_STAMP_SIGNING) == 0))
  36. {
  37. return TRUE;
  38. }
  39. return FALSE;
  40. }
  41. HRESULT
  42. SetupFonts(
  43. HINSTANCE hInstance,
  44. HWND hwnd,
  45. CFont *pBigBoldFont,
  46. CFont *pBoldFont
  47. )
  48. {
  49. HRESULT hr = S_OK;
  50. //
  51. // Create the fonts we need based on the dialog font
  52. //
  53. NONCLIENTMETRICS ncm = {0};
  54. ncm.cbSize = sizeof(ncm);
  55. SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
  56. LOGFONT BigBoldLogFont = ncm.lfMessageFont;
  57. LOGFONT BoldLogFont = ncm.lfMessageFont;
  58. //
  59. // Create Big Bold Font and Bold Font
  60. //
  61. BigBoldLogFont.lfWeight = FW_BOLD;
  62. BoldLogFont.lfWeight = FW_BOLD;
  63. TCHAR FontSizeString[MAX_PATH];
  64. INT BigBoldFontSize;
  65. INT BoldFontSize;
  66. //
  67. // Load size and name from resources, since these may change
  68. // from locale to locale based on the size of the system font, etc.
  69. //
  70. if(!LoadString(hInstance,IDS_LARGEFONTNAME,BigBoldLogFont.lfFaceName,LF_FACESIZE))
  71. {
  72. lstrcpy(BigBoldLogFont.lfFaceName,TEXT("MS Shell Dlg"));
  73. }
  74. if(LoadString(hInstance,IDS_LARGEFONTSIZE,FontSizeString,sizeof(FontSizeString)/sizeof(TCHAR)))
  75. {
  76. BigBoldFontSize = _tcstoul( FontSizeString, NULL, 10 );
  77. }
  78. else
  79. {
  80. BigBoldFontSize = 12;
  81. }
  82. if(LoadString(hInstance,IDS_FONTSIZE,FontSizeString,sizeof(FontSizeString)/sizeof(TCHAR)))
  83. {
  84. BoldFontSize = _tcstoul( FontSizeString, NULL, 10 );
  85. }
  86. else
  87. {
  88. BoldFontSize = 10;
  89. }
  90. HDC hdc = GetDC(hwnd);
  91. if (hdc)
  92. {
  93. BigBoldLogFont.lfHeight = 0 - (GetDeviceCaps(hdc,LOGPIXELSY) * BigBoldFontSize / 72);
  94. BoldLogFont.lfHeight = 0 - (GetDeviceCaps(hdc,LOGPIXELSY) * BoldFontSize / 72);
  95. if (!pBigBoldFont->CreateFontIndirect(&BigBoldLogFont) ||
  96. !pBoldFont->CreateFontIndirect(&BoldLogFont))
  97. {
  98. hr = GetLastError();
  99. hr = HRESULT_FROM_WIN32(hr);
  100. }
  101. ReleaseDC(hwnd,hdc);
  102. }
  103. else
  104. {
  105. hr = GetLastError();
  106. hr = HRESULT_FROM_WIN32(hr);
  107. }
  108. return hr;
  109. }
  110. void CleanUpCertTypeInfo(PWIZARD_HELPER pwizHelp)
  111. {
  112. unsigned int i;
  113. if (pwizHelp->pKeyUsage != NULL)
  114. {
  115. delete(pwizHelp->pKeyUsage);
  116. pwizHelp->pKeyUsage = NULL;
  117. }
  118. ZeroMemory(pwizHelp->KeyUsageBytes, 2);
  119. pwizHelp->fMarkKeyUsageCritical = FALSE;
  120. if (pwizHelp->EnhancedKeyUsage.cUsageIdentifier != 0)
  121. {
  122. for (i=0; i<pwizHelp->EnhancedKeyUsage.cUsageIdentifier; i++)
  123. {
  124. delete(pwizHelp->EnhancedKeyUsage.rgpszUsageIdentifier[i]);
  125. }
  126. delete(pwizHelp->EnhancedKeyUsage.rgpszUsageIdentifier);
  127. pwizHelp->EnhancedKeyUsage.rgpszUsageIdentifier = NULL;
  128. pwizHelp->EnhancedKeyUsage.cUsageIdentifier = 0;
  129. }
  130. pwizHelp->fMarkEKUCritical = FALSE;
  131. pwizHelp->BasicConstraints2.fCA = FALSE;
  132. pwizHelp->BasicConstraints2.fPathLenConstraint = FALSE;
  133. pwizHelp->BasicConstraints2.dwPathLenConstraint = 0;
  134. pwizHelp->fAllowCAtoFillInInfo = FALSE;
  135. pwizHelp->fIncludeEmail = FALSE;
  136. pwizHelp->fAllowAutoEnroll = FALSE;
  137. pwizHelp->fMachine = FALSE;
  138. pwizHelp->fPublishToDS = FALSE;
  139. pwizHelp->fAddTemplateName = FALSE;
  140. pwizHelp->fAddDirectoryPath = FALSE;
  141. if(pwizHelp->pSD)
  142. {
  143. LocalFree(pwizHelp->pSD);
  144. pwizHelp->pSD = NULL;
  145. }
  146. if (pwizHelp->rgszCSPList != NULL)
  147. {
  148. delete[](pwizHelp->rgszCSPList);
  149. pwizHelp->rgszCSPList = NULL;
  150. pwizHelp->cCSPs = 0;
  151. }
  152. pwizHelp->fPrivateKeyExportable = FALSE;
  153. pwizHelp->fDigitalSignatureContainer = TRUE;
  154. pwizHelp->fKeyExchangeContainer = FALSE;
  155. }
  156. void FillInCertTypeInfo(HCERTTYPE hCertType, PWIZARD_HELPER pwizHelp)
  157. {
  158. DWORD cNumUsages;
  159. CString **aszUsages = NULL;
  160. unsigned int i;
  161. WCHAR **pszNameArray;
  162. DWORD dwFlags, dwKeySpec;
  163. LPWSTR *rgpwszSupportedCSPs;
  164. CleanUpCertTypeInfo(pwizHelp);
  165. //
  166. // key usage
  167. //
  168. if (MyGetKeyUsages(hCertType, &(pwizHelp->pKeyUsage), &(pwizHelp->fMarkKeyUsageCritical)))
  169. {
  170. // copy the key usage bits to the local byte array that has two bytes for sure
  171. ZeroMemory(pwizHelp->KeyUsageBytes, 2);
  172. CopyMemory(pwizHelp->KeyUsageBytes, pwizHelp->pKeyUsage->pbData, pwizHelp->pKeyUsage->cbData);
  173. pwizHelp->pKeyUsage->cUnusedBits = 7; // there are currently 9 key usage bits defined
  174. pwizHelp->pKeyUsage->pbData = pwizHelp->KeyUsageBytes;
  175. pwizHelp->pKeyUsage->cbData = 2;
  176. }
  177. //
  178. // enhanced key usage count
  179. //
  180. if(!MyGetEnhancedKeyUsages(
  181. hCertType,
  182. NULL,
  183. &cNumUsages,
  184. &(pwizHelp->fMarkEKUCritical),
  185. TRUE))
  186. {
  187. return;
  188. }
  189. if (cNumUsages == 0)
  190. {
  191. pwizHelp->EnhancedKeyUsage.cUsageIdentifier = 0;
  192. pwizHelp->EnhancedKeyUsage.rgpszUsageIdentifier = NULL;
  193. }
  194. else
  195. {
  196. aszUsages = new CString*[cNumUsages];
  197. if(!aszUsages)
  198. return;
  199. if(!MyGetEnhancedKeyUsages(
  200. hCertType,
  201. aszUsages,
  202. &cNumUsages,
  203. &(pwizHelp->fMarkEKUCritical),
  204. TRUE))
  205. {
  206. delete[] aszUsages;
  207. return;
  208. }
  209. pwizHelp->EnhancedKeyUsage.cUsageIdentifier = cNumUsages;
  210. pwizHelp->EnhancedKeyUsage.rgpszUsageIdentifier = (LPSTR *) new (LPSTR[cNumUsages]);
  211. if(pwizHelp->EnhancedKeyUsage.rgpszUsageIdentifier == NULL)
  212. {
  213. delete[] aszUsages;
  214. return;
  215. }
  216. for (i=0; i<cNumUsages; i++)
  217. {
  218. pwizHelp->EnhancedKeyUsage.rgpszUsageIdentifier[i] = MyMkMBStr((LPCTSTR)*(aszUsages[i]));
  219. delete(aszUsages[i]);
  220. }
  221. }
  222. //
  223. // basic constraints
  224. //
  225. if(!MyGetBasicConstraintInfo(
  226. hCertType,
  227. &(pwizHelp->BasicConstraints2.fCA),
  228. &(pwizHelp->BasicConstraints2.fPathLenConstraint),
  229. &(pwizHelp->BasicConstraints2.dwPathLenConstraint)))
  230. {
  231. delete[] aszUsages;
  232. return;
  233. }
  234. // if the fInEditCertTypeMode flag is set, then we need to initialize the
  235. // cert template name
  236. if (pwizHelp->fInEditCertTypeMode)
  237. {
  238. CAGetCertTypeProperty(hCertType, CERTTYPE_PROP_FRIENDLY_NAME, &pszNameArray);
  239. if (pszNameArray != NULL)
  240. {
  241. *(pwizHelp->pcstrFriendlyName) = pszNameArray[0];
  242. CAFreeCertTypeProperty(hCertType, pszNameArray);
  243. }
  244. }
  245. //
  246. // ACL info
  247. //
  248. CACertTypeGetSecurity(hCertType, &pwizHelp->pSD);
  249. CAGetCertTypeFlags(hCertType, &dwFlags);
  250. pwizHelp->fAllowCAtoFillInInfo =
  251. ((dwFlags & CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT) == 0);
  252. pwizHelp->fAllowAutoEnroll =
  253. ((dwFlags & CT_FLAG_AUTO_ENROLLMENT) == 0);
  254. pwizHelp->fMachine =
  255. ((dwFlags & CT_FLAG_MACHINE_TYPE) == 0);
  256. pwizHelp->fPublishToDS =
  257. ((dwFlags & CT_FLAG_PUBLISH_TO_DS) == 0);
  258. pwizHelp->fIncludeEmail =
  259. ((dwFlags & CT_FLAG_ADD_EMAIL) != 0);
  260. pwizHelp->fAddTemplateName =
  261. ((dwFlags & CT_FLAG_ADD_TEMPLATE_NAME) == 0);
  262. pwizHelp->fAddDirectoryPath =
  263. ((dwFlags & CT_FLAG_ADD_DIRECTORY_PATH) == 0);
  264. //
  265. // CSP info
  266. //
  267. if ((CAGetCertTypeProperty(hCertType, CERTTYPE_PROP_CSP_LIST, &rgpwszSupportedCSPs) == S_OK) &&
  268. (rgpwszSupportedCSPs != NULL))
  269. {
  270. //
  271. // count number of CSPs
  272. //
  273. i = 0;
  274. while (rgpwszSupportedCSPs[i++] != NULL);
  275. pwizHelp->cCSPs = i-1;
  276. //
  277. // allocate array and copy CSP names to it
  278. //
  279. if (NULL != (pwizHelp->rgszCSPList = (CString *) new(CString[pwizHelp->cCSPs])))
  280. {
  281. i = 0;
  282. while (rgpwszSupportedCSPs[i] != NULL)
  283. {
  284. pwizHelp->rgszCSPList[i] = rgpwszSupportedCSPs[i];
  285. i++;
  286. }
  287. }
  288. CAFreeCertTypeProperty(hCertType, rgpwszSupportedCSPs);
  289. }
  290. pwizHelp->fPrivateKeyExportable = dwFlags & CT_FLAG_EXPORTABLE_KEY;
  291. CAGetCertTypeKeySpec(hCertType, &dwKeySpec);
  292. if (dwKeySpec == AT_KEYEXCHANGE)
  293. {
  294. pwizHelp->fDigitalSignatureContainer = FALSE;
  295. pwizHelp->fKeyExchangeContainer = TRUE;
  296. }
  297. else
  298. {
  299. pwizHelp->fDigitalSignatureContainer = TRUE;
  300. pwizHelp->fKeyExchangeContainer = FALSE;
  301. }
  302. delete[] aszUsages;
  303. }
  304. /////////////////////////////////////////////////////////////////////////////
  305. // CNewCertTypeWelcome property page
  306. CNewCertTypeWelcome::CNewCertTypeWelcome() :
  307. CWizard97PropertyPage(
  308. g_hInstance,
  309. CNewCertTypeWelcome::IDD,
  310. g_aidFont)
  311. {
  312. InitWizard97 (TRUE);
  313. }
  314. CNewCertTypeWelcome::~CNewCertTypeWelcome()
  315. {
  316. }
  317. // replacement for DoDataExchange
  318. BOOL CNewCertTypeWelcome::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  319. {
  320. if (fSuckFromDlg)
  321. {
  322. // m_cstrModuleName.FromWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  323. }
  324. else
  325. {
  326. // m_cstrModuleName.ToWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  327. }
  328. return TRUE;
  329. }
  330. // replacement for BEGIN_MESSAGE_MAP
  331. BOOL CNewCertTypeWelcome::OnCommand(WPARAM wParam, LPARAM lParam)
  332. {
  333. /*
  334. switch(LOWORD(wParam))
  335. {
  336. default:
  337. return FALSE;
  338. break;
  339. }
  340. */
  341. return TRUE;
  342. }
  343. /////////////////////////////////////////////////////////////////////////////
  344. // CNewCertTypeWelcome message handlers
  345. LRESULT CNewCertTypeWelcome::OnWizardNext()
  346. {
  347. if (m_pwizHelp->fInEditCertTypeMode)
  348. return (IDD_NEWCERTTYPE_INFORMATION);
  349. else
  350. return 0;
  351. }
  352. BOOL CNewCertTypeWelcome::OnInitDialog()
  353. {
  354. CWizard97PropertyPage::OnInitDialog();
  355. CString szPropSheetTitle;
  356. szPropSheetTitle.LoadString(IDS_CERTIFICATE_TEMPLATE_WIZARD);
  357. SetWindowText(m_hWnd, szPropSheetTitle);
  358. SendMessage(GetDlgItem(IDC_WELCOME_BIGBOLD_STATIC), WM_SETFONT, (WPARAM)GetBigBoldFont(), MAKELPARAM(TRUE, 0));
  359. SendMessage(GetDlgItem(IDC_WELCOM_BOLD_STATIC), WM_SETFONT, (WPARAM)GetBigBoldFont(), MAKELPARAM(TRUE, 0));
  360. return TRUE; // return TRUE unless you set the focus to a control
  361. // EXCEPTION: OCX Property Pages should return FALSE
  362. }
  363. BOOL CNewCertTypeWelcome::OnSetActive()
  364. {
  365. PropSheet_SetWizButtons(GetParent(), PSWIZB_NEXT);
  366. return CWizard97PropertyPage::OnSetActive();
  367. }
  368. /////////////////////////////////////////////////////////////////////////////
  369. // CNewCertTypeBaseType property page
  370. CNewCertTypeBaseType::CNewCertTypeBaseType() :
  371. CWizard97PropertyPage(
  372. g_hInstance,
  373. CNewCertTypeBaseType::IDD,
  374. g_aidFont)
  375. {
  376. m_szHeaderTitle.LoadString(IDS_BASE_TYPE_TITLE);
  377. m_szHeaderSubTitle.LoadString(IDS_BASE_TYPE_SUB_TITLE);
  378. InitWizard97 (FALSE);
  379. m_hLastSelectedCertType = NULL;
  380. }
  381. CNewCertTypeBaseType::~CNewCertTypeBaseType()
  382. {
  383. }
  384. // replacement for DoDataExchange
  385. BOOL CNewCertTypeBaseType::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  386. {
  387. if (fSuckFromDlg)
  388. {
  389. // m_cstrModuleName.FromWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  390. }
  391. else
  392. {
  393. // m_cstrModuleName.ToWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  394. }
  395. return TRUE;
  396. }
  397. // replacement for BEGIN_MESSAGE_MAP
  398. BOOL CNewCertTypeBaseType::OnCommand(WPARAM wParam, LPARAM lParam)
  399. {
  400. /*
  401. switch(LOWORD(wParam))
  402. {
  403. default:
  404. return FALSE;
  405. break;
  406. }
  407. */
  408. return TRUE;
  409. }
  410. BOOL CNewCertTypeBaseType::OnNotify(UINT idCtrl, NMHDR* pnmh)
  411. {
  412. switch(idCtrl)
  413. {
  414. case IDC_BASE_CERT_TYPE_LIST:
  415. if (LVN_ITEMCHANGED == pnmh->code)
  416. {
  417. OnSelChange(pnmh);
  418. break;
  419. }
  420. default:
  421. return FALSE;
  422. }
  423. return TRUE;
  424. }
  425. /////////////////////////////////////////////////////////////////////////////
  426. // CNewCertTypeBaseType message handlers
  427. LRESULT CNewCertTypeBaseType::OnWizardBack()
  428. {
  429. return CWizard97PropertyPage::OnWizardBack();
  430. }
  431. LRESULT CNewCertTypeBaseType::OnWizardNext()
  432. {
  433. if (m_hSelectedCertType != m_hLastSelectedCertType)
  434. {
  435. if (m_hSelectedCertType == NULL)
  436. {
  437. m_pwizHelp->fBaseCertTypeUsed = FALSE;
  438. CleanUpCertTypeInfo(m_pwizHelp);
  439. m_pwizHelp->fCleanupOIDCheckBoxes = TRUE;
  440. // since there is no base type the key usage structure will not be initialized
  441. // with date, therefore we need to initialize the key usage structure with 0's
  442. m_pwizHelp->pKeyUsage = new(CRYPT_BIT_BLOB);
  443. if(m_pwizHelp->pKeyUsage == NULL)
  444. {
  445. return CWizard97PropertyPage::OnWizardNext();
  446. }
  447. m_pwizHelp->pKeyUsage->cbData = 2;
  448. m_pwizHelp->pKeyUsage->pbData = m_pwizHelp->KeyUsageBytes;
  449. m_pwizHelp->pKeyUsage->cUnusedBits = 7;
  450. }
  451. else
  452. {
  453. m_pwizHelp->fBaseCertTypeUsed = TRUE;
  454. FillInCertTypeInfo(m_hSelectedCertType, m_pwizHelp);
  455. }
  456. m_pwizHelp->fKeyUsageInitialized = FALSE;
  457. m_hLastSelectedCertType = m_hSelectedCertType;
  458. }
  459. ListView_GetItemText(m_hBaseCertTypeList, m_selectedIndex, 0, m_pwizHelp->pcstrBaseCertName->GetBuffer(MAX_PATH), MAX_PATH*sizeof(WCHAR));
  460. return CWizard97PropertyPage::OnWizardNext();
  461. }
  462. BOOL CNewCertTypeBaseType::OnSetActive()
  463. {
  464. PropSheet_SetWizButtons(GetParent(), PSWIZB_BACK | PSWIZB_NEXT);
  465. return CWizard97PropertyPage::OnSetActive();
  466. }
  467. void CNewCertTypeBaseType::OnSelChange(NMHDR * pNotifyStruct)
  468. {
  469. LPNMLISTVIEW pListItem = (LPNMLISTVIEW) pNotifyStruct;
  470. if (pListItem->uNewState & LVIS_SELECTED)
  471. {
  472. m_hSelectedCertType = (HCERTTYPE) ListView_GetItemData(m_hBaseCertTypeList, pListItem->iItem);
  473. m_selectedIndex = pListItem->iItem;
  474. }
  475. }
  476. BOOL CNewCertTypeBaseType::OnInitDialog()
  477. {
  478. CWizard97PropertyPage::OnInitDialog();
  479. m_hBaseCertTypeList = GetDlgItem(m_hWnd, IDC_BASE_CERT_TYPE_LIST);
  480. HRESULT hr;
  481. HCERTTYPE hCertTypeNext;
  482. HCERTTYPE hCertTypePrev;
  483. WCHAR ** aszCertTypeName;
  484. CString szUsageString;
  485. int i = 0;
  486. CString szColumnHeading;
  487. CString szNoBaseType;
  488. szColumnHeading.LoadString(IDS_COLUMN_NAME);
  489. ListView_NewColumn(m_hBaseCertTypeList, 0, 200, szColumnHeading, LVCFMT_LEFT);
  490. szColumnHeading.LoadString(IDS_COLUMN_INTENDED_PURPOSE);
  491. ListView_NewColumn(m_hBaseCertTypeList, 1, 200, szColumnHeading, LVCFMT_LEFT);
  492. // initialize the list with the <No Base Type> string selected
  493. szNoBaseType.LoadString(IDS_NO_BASE_TYPE);
  494. ListView_NewItem(m_hBaseCertTypeList, i++, szNoBaseType);
  495. ListView_SetItemState(m_hBaseCertTypeList, 0, LVIS_SELECTED, LVIS_SELECTED);
  496. m_selectedIndex = 0;
  497. // since there is no base type selected we need to initialize
  498. // the key usage structure
  499. m_pwizHelp->pKeyUsage = new(CRYPT_BIT_BLOB);
  500. if(m_pwizHelp->pKeyUsage == NULL)
  501. {
  502. return FALSE;
  503. }
  504. m_pwizHelp->pKeyUsage->cbData = 2;
  505. m_pwizHelp->pKeyUsage->pbData = m_pwizHelp->KeyUsageBytes;
  506. m_pwizHelp->pKeyUsage->cUnusedBits = 7;
  507. hr = CAEnumCertTypes(CT_ENUM_MACHINE_TYPES | CT_ENUM_USER_TYPES,
  508. &hCertTypeNext);
  509. while ((hCertTypeNext != NULL) && (!FAILED(hr)))
  510. {
  511. //
  512. // add the cert type to the list of choices
  513. //
  514. hr = CAGetCertTypeProperty(
  515. hCertTypeNext,
  516. CERTTYPE_PROP_FRIENDLY_NAME,
  517. &aszCertTypeName);
  518. ListView_NewItem(m_hBaseCertTypeList, i, aszCertTypeName[0], (LPARAM)hCertTypeNext);
  519. GetIntendedUsagesString(hCertTypeNext, &szUsageString);
  520. if (szUsageString == L"")
  521. {
  522. szUsageString.LoadString(IDS_ALL);
  523. }
  524. ListView_SetItemText(m_hBaseCertTypeList, i++, 1, (LPWSTR)(LPCTSTR)szUsageString);
  525. CAFreeCertTypeProperty(
  526. hCertTypeNext,
  527. aszCertTypeName);
  528. hCertTypePrev = hCertTypeNext;
  529. hCertTypeNext = NULL;
  530. hr = CAEnumNextCertType(hCertTypePrev, &hCertTypeNext);
  531. }
  532. ListView_SetColumnWidth(m_hBaseCertTypeList, 0, LVSCW_AUTOSIZE);
  533. ListView_SetColumnWidth(m_hBaseCertTypeList, 1, LVSCW_AUTOSIZE);
  534. return TRUE; // return TRUE unless you set the focus to a control
  535. // EXCEPTION: OCX Property Pages should return FALSE
  536. }
  537. void CNewCertTypeBaseType::OnDestroy()
  538. {
  539. CWizard97PropertyPage::OnDestroy();
  540. int i = 0;
  541. HCERTTYPE hCertType;
  542. int iCount = ListView_GetItemCount(m_hBaseCertTypeList);
  543. for (i=0; i<iCount; i++)
  544. {
  545. hCertType = (HCERTTYPE) ListView_GetItemData(m_hBaseCertTypeList, i);
  546. if (hCertType != NULL)
  547. CACloseCertType(hCertType);
  548. }
  549. }
  550. /////////////////////////////////////////////////////////////////////////////
  551. // CNewCertTypeBasicInformation property page
  552. CNewCertTypeBasicInformation::CNewCertTypeBasicInformation() :
  553. CWizard97PropertyPage(
  554. g_hInstance,
  555. CNewCertTypeBasicInformation::IDD,
  556. g_aidFont)
  557. {
  558. m_szHeaderTitle.LoadString(IDS_BASIC_INFORMATION_TITLE);
  559. m_szHeaderSubTitle.LoadString(IDS_BASIC_INFORMATION_SUB_TITLE);
  560. InitWizard97 (FALSE);
  561. }
  562. CNewCertTypeBasicInformation::~CNewCertTypeBasicInformation()
  563. {
  564. }
  565. // replacement for DoDataExchange
  566. BOOL CNewCertTypeBasicInformation::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  567. {
  568. if (fSuckFromDlg)
  569. {
  570. // m_cstrModuleName.FromWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  571. }
  572. else
  573. {
  574. // m_cstrModuleName.ToWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  575. }
  576. return TRUE;
  577. }
  578. // replacement for BEGIN_MESSAGE_MAP
  579. BOOL CNewCertTypeBasicInformation::OnCommand(WPARAM wParam, LPARAM lParam)
  580. {
  581. switch(LOWORD(wParam))
  582. {
  583. case IDC_NEW_PURPOSE_BUTTON:
  584. if (HIWORD(wParam) == BN_CLICKED)
  585. {
  586. OnNewPurposeButton();
  587. break;
  588. }
  589. default:
  590. return FALSE;
  591. break;
  592. }
  593. return TRUE;
  594. }
  595. /////////////////////////////////////////////////////////////////////////////
  596. // CNewCertTypeBasicInformation message handlers
  597. BOOL WINAPI EnumCallback(PCCRYPT_OID_INFO pInfo, void *pvArg)
  598. {
  599. CNewCertTypeBasicInformation *pDlg = (CNewCertTypeBasicInformation *) pvArg;
  600. pDlg->AddEnumedEKU(pInfo);
  601. return TRUE;
  602. }
  603. void CNewCertTypeBasicInformation::AddEnumedEKU(PCCRYPT_OID_INFO pInfo)
  604. {
  605. LPSTR pszOIDCopy;
  606. //
  607. // don't allow SGC oids
  608. //
  609. if (IsDisallowedOID(pInfo->pszOID))
  610. {
  611. return;
  612. }
  613. pszOIDCopy = (LPSTR) new(BYTE[strlen(pInfo->pszOID)+1]);
  614. if (pszOIDCopy != NULL)
  615. {
  616. strcpy(pszOIDCopy, pInfo->pszOID);
  617. ListView_NewItem(m_hPurposeList, 0, pInfo->pwszName, (LPARAM)pszOIDCopy);
  618. }
  619. }
  620. void CNewCertTypeBasicInformation::UpdateWizHelp()
  621. {
  622. unsigned int i;
  623. int cNumUsages;
  624. CString szName;
  625. szName.FromWindow(GetDlgItem(this->m_hWnd, IDC_CERTIFICATE_TEMPLATE_EDIT));
  626. *(m_pwizHelp->pcstrFriendlyName) = szName;
  627. m_pwizHelp->fAllowCAtoFillInInfo = (SendMessage(m_hButtonCAFillIn, BM_GETCHECK, 0, 0) == BST_CHECKED);
  628. m_pwizHelp->fAllowCAtoFillInInfo = (SendMessage(m_hButtonCritical, BM_GETCHECK, 0, 0) == BST_CHECKED);
  629. m_pwizHelp->fAllowCAtoFillInInfo = (SendMessage(m_hButtonIncludeEmail, BM_GETCHECK, 0, 0) == BST_CHECKED);
  630. m_pwizHelp->fAllowCAtoFillInInfo = (SendMessage(m_hButtonAllowAutoEnroll, BM_GETCHECK, 0, 0) == BST_CHECKED);
  631. m_pwizHelp->fAllowCAtoFillInInfo = (SendMessage(m_hButtonAdvanced, BM_GETCHECK, 0, 0) == BST_CHECKED);
  632. // clean up any EKU that alraedy exists
  633. for (i=0; i<m_pwizHelp->EnhancedKeyUsage.cUsageIdentifier; i++)
  634. {
  635. delete(m_pwizHelp->EnhancedKeyUsage.rgpszUsageIdentifier[i]);
  636. }
  637. if (m_pwizHelp->EnhancedKeyUsage.rgpszUsageIdentifier != NULL)
  638. delete(m_pwizHelp->EnhancedKeyUsage.rgpszUsageIdentifier);
  639. cNumUsages = ListView_GetSelectedCount(m_hPurposeList);
  640. // allocate memory and copy the oids
  641. m_pwizHelp->EnhancedKeyUsage.cUsageIdentifier = cNumUsages;
  642. m_pwizHelp->EnhancedKeyUsage.rgpszUsageIdentifier = (LPSTR *) new (LPSTR[cNumUsages]);
  643. if(m_pwizHelp->EnhancedKeyUsage.rgpszUsageIdentifier == NULL)
  644. {
  645. return;
  646. }
  647. i = -1;
  648. while(-1 != (i = ListView_GetNextItem(m_hPurposeList, i, LVNI_SELECTED)) )
  649. {
  650. LPCSTR sz = (LPCSTR)ListView_GetItemData(m_hPurposeList, i);
  651. m_pwizHelp->EnhancedKeyUsage.rgpszUsageIdentifier[cNumUsages++] = AllocAndCopyStr(sz);
  652. }
  653. }
  654. LRESULT CNewCertTypeBasicInformation::OnWizardBack()
  655. {
  656. UpdateWizHelp();
  657. if (m_pwizHelp->fInEditCertTypeMode)
  658. return (IDD_NEWCERTTYPE_WELCOME);
  659. else
  660. return 0;
  661. }
  662. LRESULT CNewCertTypeBasicInformation::OnWizardNext()
  663. {
  664. CString szText0;
  665. szText0.FromWindow(GetDlgItem(m_hWnd, IDC_CERTIFICATE_TEMPLATE_EDIT));
  666. if (szText0 == L"")
  667. {
  668. CString szCaption;
  669. CString szText;
  670. szCaption.LoadString(IDS_CERTIFICATE_TEMPLATE_WIZARD);
  671. szText.LoadString(IDS_ENTER_CERTTYPE_NAME);
  672. MessageBox(m_hWnd, szText, szCaption, MB_OK | MB_ICONEXCLAMATION);
  673. SetFocus(GetDlgItem(m_hWnd, IDC_CERTIFICATE_TEMPLATE_EDIT));
  674. return -1;
  675. }
  676. UpdateWizHelp();
  677. return CWizard97PropertyPage::OnWizardNext();
  678. }
  679. BOOL CNewCertTypeBasicInformation::OnInitDialog()
  680. {
  681. CWizard97PropertyPage::OnInitDialog();
  682. m_hPurposeList = GetDlgItem(m_hWnd, IDC_PURPOSE_LIST);
  683. m_hButtonCAFillIn = GetDlgItem(m_hWnd, IDC_CA_FILL_IN_CHECK);
  684. m_hButtonCritical = GetDlgItem(m_hWnd, IDC_CRITICAL_CHECK);
  685. m_hButtonIncludeEmail = GetDlgItem(m_hWnd, IDC_INCLUDE_EMAIL_CHECK);
  686. m_hButtonAllowAutoEnroll = GetDlgItem(m_hWnd, IDC_ALLOW_AUTOENROLL_CHECK);
  687. m_hButtonAdvanced = GetDlgItem(m_hWnd, IDC_ADVANCED_OPTIONS_CHECK);
  688. CString szNewCertName;
  689. // set the name if we are in cert type edit mode
  690. if (m_pwizHelp->fInEditCertTypeMode)
  691. {
  692. SetDlgItemText(m_hWnd, IDC_CERTIFICATE_TEMPLATE_EDIT, *(m_pwizHelp->pcstrFriendlyName));
  693. }
  694. else
  695. {
  696. szNewCertName.LoadString(IDS_NEW_CERTIFICATE_TEMPLATE2);
  697. SetDlgItemText(m_hWnd, IDC_CERTIFICATE_TEMPLATE_EDIT, szNewCertName);
  698. }
  699. SendMessage(m_hButtonAdvanced, BM_SETCHECK, FALSE, 0);
  700. ListView_NewColumn(m_hPurposeList, 0, 0);
  701. ListView_SetExtendedListViewStyle(m_hPurposeList, LVS_EX_CHECKBOXES);
  702. ListView_SetColumnWidth(m_hPurposeList, 0, LVSCW_AUTOSIZE);
  703. CryptEnumOIDInfo(CRYPT_ENHKEY_USAGE_OID_GROUP_ID, 0, (void *) this, EnumCallback);
  704. // set focus to the name edit
  705. SetFocus(GetDlgItem(m_hWnd, IDC_CERTIFICATE_TEMPLATE_EDIT));
  706. return TRUE; // return TRUE unless you set the focus to a control
  707. // EXCEPTION: OCX Property Pages should return FALSE
  708. }
  709. void CNewCertTypeBasicInformation::OnDestroy()
  710. {
  711. CWizard97PropertyPage::OnDestroy();
  712. int i, iCount;
  713. // clean up the OID strings that were set as the LPARAM's of each item
  714. iCount = ListView_GetItemCount(m_hPurposeList);
  715. for (i=0; i<iCount; i++)
  716. {
  717. delete (LPSTR) ListView_GetItemData(m_hPurposeList, i);
  718. }
  719. }
  720. void CNewCertTypeBasicInformation::InitializeOIDList()
  721. {
  722. unsigned int i,j;
  723. LPSTR pszOID;
  724. BOOL bFound;
  725. WCHAR szOIDName[MAX_PATH];
  726. LPSTR pszNewOID;
  727. // this means all usages are supported
  728. if (m_pwizHelp->EnhancedKeyUsage.cUsageIdentifier == 0)
  729. {
  730. unsigned int iCount = ListView_GetItemCount(m_hPurposeList);
  731. for (i=0; i<iCount; i++)
  732. ListView_SetCheckState(m_hPurposeList, i, TRUE);
  733. }
  734. else
  735. {
  736. // loop for each EKU that this certificate template supports
  737. for (i=0; i<m_pwizHelp->EnhancedKeyUsage.cUsageIdentifier; i++)
  738. {
  739. unsigned int iCount = ListView_GetItemCount(m_hPurposeList);
  740. bFound = FALSE;
  741. // see if this EKU is in the global list
  742. for (j=0; j<iCount; j++)
  743. {
  744. pszOID = (LPSTR)ListView_GetItemData(m_hPurposeList, j);
  745. if (strcmp(pszOID, m_pwizHelp->EnhancedKeyUsage.rgpszUsageIdentifier[i]) == 0)
  746. {
  747. // if the EKU is in the global list, then just set the check box,
  748. // and set the flag that it was found
  749. ListView_SetCheckState(m_hPurposeList, j, TRUE);
  750. bFound = TRUE;
  751. }
  752. }
  753. // if the EKU was not in the global list then insert it into the list view,
  754. // and set its check box
  755. if (!bFound)
  756. {
  757. if (!MyGetOIDInfo(szOIDName, ARRAYSIZE(szOIDName), m_pwizHelp->EnhancedKeyUsage.rgpszUsageIdentifier[i]))
  758. {
  759. continue;
  760. }
  761. pszNewOID = (LPSTR) new(BYTE[strlen(m_pwizHelp->EnhancedKeyUsage.rgpszUsageIdentifier[i])+1]);
  762. if (pszNewOID == NULL)
  763. {
  764. continue;
  765. }
  766. strcpy(pszNewOID, m_pwizHelp->EnhancedKeyUsage.rgpszUsageIdentifier[i]);
  767. ListView_NewItem(m_hPurposeList, 0, szOIDName, (LPARAM)pszNewOID);
  768. ListView_SetCheckState(m_hPurposeList, 0, TRUE);
  769. }
  770. }
  771. }
  772. }
  773. BOOL CNewCertTypeBasicInformation::OnSetActive()
  774. {
  775. int i;
  776. LPSTR pszOID;
  777. PropSheet_SetWizButtons(GetParent(), PSWIZB_BACK | PSWIZB_NEXT);
  778. SendMessage(m_hButtonCAFillIn, BM_SETCHECK, m_pwizHelp->fAllowCAtoFillInInfo, 0);
  779. SendMessage(m_hButtonCritical, BM_SETCHECK, m_pwizHelp->fMarkEKUCritical, 0);
  780. SendMessage(m_hButtonIncludeEmail, BM_SETCHECK, m_pwizHelp->fIncludeEmail, 0);
  781. SendMessage(m_hButtonAllowAutoEnroll, BM_SETCHECK, m_pwizHelp->fAllowAutoEnroll, 0);
  782. if (m_pwizHelp->fBaseCertTypeUsed || m_pwizHelp->fInEditCertTypeMode)
  783. {
  784. InitializeOIDList();
  785. }
  786. else
  787. {
  788. if (m_pwizHelp->fCleanupOIDCheckBoxes)
  789. {
  790. int iCount = ListView_GetItemCount(m_hPurposeList);
  791. for (i=0; i<iCount; i++)
  792. {
  793. ListView_SetCheckState(m_hPurposeList, i, FALSE);
  794. }
  795. m_pwizHelp->fCleanupOIDCheckBoxes = FALSE;
  796. }
  797. }
  798. return CWizard97PropertyPage::OnSetActive();
  799. }
  800. #include <richedit.h>
  801. INT_PTR APIENTRY NewOIDDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  802. {
  803. DWORD i;
  804. char szText[256];
  805. WCHAR errorString[256];
  806. WCHAR errorTitle[256];
  807. LPSTR pszText = NULL;
  808. switch ( msg ) {
  809. case WM_INITDIALOG:
  810. SendDlgItemMessage(hwndDlg, IDC_EDIT1, EM_EXLIMITTEXT, 0, (LPARAM) 255);
  811. SetDlgItemText(hwndDlg, IDC_EDIT1, L"");
  812. SetFocus(GetDlgItem(hwndDlg, IDC_EDIT1));
  813. break;
  814. case WM_COMMAND:
  815. switch (LOWORD(wParam))
  816. {
  817. case IDOK:
  818. if (GetDlgItemTextA(
  819. hwndDlg,
  820. IDC_EDIT1,
  821. szText,
  822. ARRAYSIZE(szText)))
  823. {
  824. BOOL fError = FALSE;
  825. CERT_ENHKEY_USAGE KeyUsage;
  826. DWORD cbData = 0;
  827. LPSTR pszCheckOID;
  828. //
  829. // make sure there are not weird characters
  830. //
  831. for (i=0; i<strlen(szText); i++)
  832. {
  833. if (((szText[i] < '0') || (szText[i] > '9')) && (szText[i] != '.'))
  834. {
  835. fError = TRUE;
  836. break;
  837. }
  838. }
  839. //
  840. // check the first and last chars, and for the empty string
  841. //
  842. if (!fError)
  843. {
  844. if ((szText[0] == '.') || (szText[strlen(szText)-1] == '.') || (strcmp(szText, "") == 0))
  845. {
  846. fError = TRUE;
  847. }
  848. }
  849. //
  850. // finally, make sure that it encodes properly
  851. //
  852. if (!fError)
  853. {
  854. pszCheckOID = szText;
  855. KeyUsage.rgpszUsageIdentifier = &pszCheckOID;
  856. KeyUsage.cUsageIdentifier = 1;
  857. if (!CryptEncodeObject(
  858. X509_ASN_ENCODING,
  859. szOID_ENHANCED_KEY_USAGE,
  860. &KeyUsage,
  861. NULL,
  862. &cbData))
  863. {
  864. fError = TRUE;
  865. }
  866. }
  867. //
  868. // if an error has occurred then display error
  869. //
  870. if (fError)
  871. {
  872. LoadString(g_hInstance, IDS_ERRORINOID, errorString, ARRAYSIZE(errorString));
  873. LoadString(g_hInstance, IDS_CERTIFICATE_TEMPLATE_WIZARD, errorTitle, ARRAYSIZE(errorTitle));
  874. MessageBox(hwndDlg, errorString, errorTitle, MB_OK | MB_ICONERROR);
  875. SendDlgItemMessage(hwndDlg, IDC_EDIT1, EM_SETSEL, 0, -1);
  876. SetFocus(GetDlgItem(hwndDlg, IDC_EDIT1));
  877. return FALSE;
  878. }
  879. //
  880. // don't allow SGC oids
  881. //
  882. if (IsDisallowedOID(szText))
  883. {
  884. LoadString(g_hInstance, IDS_NOSPECIALOID, errorString, ARRAYSIZE(errorString));
  885. LoadString(g_hInstance, IDS_CERTIFICATE_TEMPLATE_WIZARD, errorTitle, ARRAYSIZE(errorTitle));
  886. MessageBox(hwndDlg, errorString, errorTitle, MB_OK | MB_ICONERROR);
  887. SendDlgItemMessage(hwndDlg, IDC_EDIT1, EM_SETSEL, 0, -1);
  888. SetFocus(GetDlgItem(hwndDlg, IDC_EDIT1));
  889. return FALSE;
  890. }
  891. //
  892. // allocate space for the string and pass the string back
  893. //
  894. pszText = (LPSTR) new(BYTE[strlen(szText)+1]);
  895. if (pszText != NULL)
  896. {
  897. strcpy(pszText, szText);
  898. }
  899. }
  900. EndDialog(hwndDlg, (INT_PTR) pszText);
  901. break;
  902. case IDCANCEL:
  903. EndDialog(hwndDlg, NULL);
  904. break;
  905. }
  906. break;
  907. }
  908. return FALSE;
  909. }
  910. BOOL CNewCertTypeBasicInformation::OIDAlreadyExist(LPSTR pszNewOID)
  911. {
  912. int i;
  913. LPSTR pszOID;
  914. int iCount = ListView_GetItemCount(m_hPurposeList);
  915. for (i=0; i<iCount; i++)
  916. {
  917. pszOID = (LPSTR) ListView_GetItemData(m_hPurposeList, i);
  918. if (strcmp(pszOID, pszNewOID) == 0)
  919. {
  920. ListView_SetItemState(m_hPurposeList, i, LVIS_SELECTED, LVIS_SELECTED);
  921. ListView_SetCheckState(m_hPurposeList, i, TRUE);
  922. ListView_EnsureVisible(m_hPurposeList, i, FALSE);
  923. return TRUE;
  924. }
  925. }
  926. return FALSE;
  927. }
  928. void CNewCertTypeBasicInformation::OnNewPurposeButton()
  929. {
  930. LPSTR pszNewOID;
  931. WCHAR szOIDName[MAX_PATH];
  932. pszNewOID = (LPSTR) ::DialogBox(
  933. g_hInstance,
  934. MAKEINTRESOURCE(IDD_USER_PURPOSE),
  935. m_hWnd,
  936. NewOIDDialogProc);
  937. if (pszNewOID != NULL)
  938. {
  939. DWORD chStores = 0;
  940. HCERTSTORE *phStores = NULL;
  941. //
  942. // if the OID already exists then don't add it
  943. //
  944. if (!OIDAlreadyExist(pszNewOID))
  945. {
  946. if (!MyGetOIDInfo(szOIDName, ARRAYSIZE(szOIDName), pszNewOID))
  947. {
  948. delete[](pszNewOID);
  949. return;
  950. }
  951. ListView_NewItem(m_hPurposeList, 0, szOIDName, (LPARAM)pszNewOID);
  952. ListView_SetCheckState(m_hPurposeList, 0, TRUE);
  953. ListView_EnsureVisible(m_hPurposeList, 0, FALSE);
  954. }
  955. }
  956. }
  957. /////////////////////////////////////////////////////////////////////////////
  958. // CNewCertTypeKeyUsage property page
  959. CNewCertTypeKeyUsage::CNewCertTypeKeyUsage() :
  960. CWizard97PropertyPage(
  961. g_hInstance,
  962. CNewCertTypeKeyUsage::IDD,
  963. g_aidFont)
  964. {
  965. m_szHeaderTitle.LoadString(IDS_KEY_USAGE_TITLE);
  966. m_szHeaderSubTitle.LoadString(IDS_KEY_USAGE_SUB_TITLE);
  967. InitWizard97 (FALSE);
  968. }
  969. CNewCertTypeKeyUsage::~CNewCertTypeKeyUsage()
  970. {
  971. }
  972. // replacement for DoDataExchange
  973. BOOL CNewCertTypeKeyUsage::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  974. {
  975. if (fSuckFromDlg)
  976. {
  977. // m_cstrModuleName.FromWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  978. }
  979. else
  980. {
  981. // m_cstrModuleName.ToWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  982. }
  983. return TRUE;
  984. }
  985. // replacement for BEGIN_MESSAGE_MAP
  986. BOOL CNewCertTypeKeyUsage::OnCommand(WPARAM wParam, LPARAM lParam)
  987. {
  988. /*
  989. switch(LOWORD(wParam))
  990. {
  991. default:
  992. return FALSE;
  993. break;
  994. }
  995. */
  996. return TRUE;
  997. }
  998. /////////////////////////////////////////////////////////////////////////////
  999. // CNewCertTypeKeyUsage message handlers
  1000. void CNewCertTypeKeyUsage::UpdateWizHelp()
  1001. {
  1002. if (BST_CHECKED == SendMessage(m_hButtonDataEncryption, BM_GETCHECK, 0, 0))
  1003. m_pwizHelp->KeyUsageBytes[0] |= CERT_DATA_ENCIPHERMENT_KEY_USAGE;
  1004. else
  1005. m_pwizHelp->KeyUsageBytes[0] &= ~CERT_DATA_ENCIPHERMENT_KEY_USAGE;
  1006. if (BST_CHECKED == SendMessage(m_hButtonDigitalSignature, BM_GETCHECK, 0, 0))
  1007. m_pwizHelp->KeyUsageBytes[0] |= CERT_DIGITAL_SIGNATURE_KEY_USAGE;
  1008. else
  1009. m_pwizHelp->KeyUsageBytes[0] &= ~CERT_DIGITAL_SIGNATURE_KEY_USAGE;
  1010. if (BST_CHECKED == SendMessage(m_hButtonEncipherOnly, BM_GETCHECK, 0, 0))
  1011. m_pwizHelp->KeyUsageBytes[0] |= CERT_ENCIPHER_ONLY_KEY_USAGE;
  1012. else
  1013. m_pwizHelp->KeyUsageBytes[0] &= ~CERT_ENCIPHER_ONLY_KEY_USAGE;
  1014. if (BST_CHECKED == SendMessage(m_hButtonKeyAgreement, BM_GETCHECK, 0, 0))
  1015. m_pwizHelp->KeyUsageBytes[0] |= CERT_KEY_AGREEMENT_KEY_USAGE;
  1016. else
  1017. m_pwizHelp->KeyUsageBytes[0] &= ~CERT_KEY_AGREEMENT_KEY_USAGE;
  1018. if (BST_CHECKED == SendMessage(m_hButtonKeyEncryption, BM_GETCHECK, 0, 0))
  1019. m_pwizHelp->KeyUsageBytes[0] |= CERT_KEY_ENCIPHERMENT_KEY_USAGE;
  1020. else
  1021. m_pwizHelp->KeyUsageBytes[0] &= ~CERT_KEY_ENCIPHERMENT_KEY_USAGE;
  1022. if (BST_CHECKED == SendMessage(m_hButtonPrevent, BM_GETCHECK, 0, 0))
  1023. m_pwizHelp->KeyUsageBytes[0] |= CERT_NON_REPUDIATION_KEY_USAGE;
  1024. else
  1025. m_pwizHelp->KeyUsageBytes[0] &= ~CERT_NON_REPUDIATION_KEY_USAGE;
  1026. if (BST_CHECKED == SendMessage(m_hButtonDecipherOnly, BM_GETCHECK, 0, 0))
  1027. m_pwizHelp->KeyUsageBytes[1] |= CERT_DECIPHER_ONLY_KEY_USAGE;
  1028. else
  1029. m_pwizHelp->KeyUsageBytes[1] &= ~CERT_DECIPHER_ONLY_KEY_USAGE;
  1030. m_pwizHelp->fMarkKeyUsageCritical = (BST_CHECKED == SendMessage(m_hButtonKeyUsageCritical, BM_GETCHECK, 0, 0));
  1031. }
  1032. LRESULT CNewCertTypeKeyUsage::OnWizardBack()
  1033. {
  1034. UpdateWizHelp();
  1035. return CWizard97PropertyPage::OnWizardBack();
  1036. }
  1037. LRESULT CNewCertTypeKeyUsage::OnWizardNext()
  1038. {
  1039. UpdateWizHelp();
  1040. //if (m_pwizHelp->BasicConstraints2.fCA)
  1041. // return (IDD_NEWCERTTYPE_CA_CERTIFICATE);
  1042. //else
  1043. return 0;
  1044. }
  1045. BOOL CNewCertTypeKeyUsage::OnInitDialog()
  1046. {
  1047. CWizard97PropertyPage::OnInitDialog();
  1048. m_hButtonDataEncryption = GetDlgItem(m_hWnd, IDC_DATA_ENCRYPTION_CHECK);
  1049. m_hButtonDecipherOnly = GetDlgItem(m_hWnd, IDC_DECIPHER_ONLY_CHECK);
  1050. m_hButtonDigitalSignature = GetDlgItem(m_hWnd, IDC_DIGITAL_SIGNATURE_CHECK);
  1051. m_hButtonEncipherOnly = GetDlgItem(m_hWnd, IDC_ENCIPHER_ONLY_CHECK);
  1052. m_hButtonKeyAgreement = GetDlgItem(m_hWnd, IDC_KEY_AGREEMENT_CHECK);
  1053. m_hButtonKeyEncryption = GetDlgItem(m_hWnd, IDC_KEY_ENCRYPTION_CHECK);
  1054. m_hButtonKeyUsageCritical = GetDlgItem(m_hWnd, IDC_KEYUSAGE_CRITICAL_CHECK);
  1055. m_hButtonPrevent = GetDlgItem(m_hWnd, IDC_PREVENT_CHECK);
  1056. SendMessage(m_hButtonKeyUsageCritical, BM_SETCHECK, 0, 0);
  1057. return TRUE; // return TRUE unless you set the focus to a control
  1058. // EXCEPTION: OCX Property Pages should return FALSE
  1059. }
  1060. void CNewCertTypeKeyUsage::OnDestroy()
  1061. {
  1062. CWizard97PropertyPage::OnDestroy();
  1063. }
  1064. BOOL CNewCertTypeKeyUsage::OnSetActive()
  1065. {
  1066. PropSheet_SetWizButtons(GetParent(), PSWIZB_BACK | PSWIZB_NEXT);
  1067. SendMessage(m_hButtonDataEncryption, BM_SETCHECK, ((m_pwizHelp->KeyUsageBytes[0] & CERT_DATA_ENCIPHERMENT_KEY_USAGE) != 0), 0);
  1068. if (!m_pwizHelp->fKeyUsageInitialized && m_pwizHelp->fDigitalSignatureContainer && !m_pwizHelp->fBaseCertTypeUsed)
  1069. {
  1070. SendMessage(m_hButtonDigitalSignature, BM_SETCHECK, TRUE, 0);
  1071. m_pwizHelp->fKeyUsageInitialized = TRUE;
  1072. }
  1073. else
  1074. {
  1075. SendMessage(m_hButtonDigitalSignature, BM_SETCHECK, ((m_pwizHelp->KeyUsageBytes[0] & CERT_DIGITAL_SIGNATURE_KEY_USAGE) != 0), 0);
  1076. }
  1077. SendMessage(m_hButtonEncipherOnly, BM_SETCHECK, ((m_pwizHelp->KeyUsageBytes[0] & CERT_ENCIPHER_ONLY_KEY_USAGE) != 0), 0);
  1078. SendMessage(m_hButtonKeyAgreement, BM_SETCHECK, ((m_pwizHelp->KeyUsageBytes[0] & CERT_KEY_AGREEMENT_KEY_USAGE) != 0), 0);
  1079. SendMessage(m_hButtonKeyEncryption, BM_SETCHECK, ((m_pwizHelp->KeyUsageBytes[0] & CERT_KEY_ENCIPHERMENT_KEY_USAGE) != 0), 0);
  1080. SendMessage(m_hButtonPrevent, BM_SETCHECK, ((m_pwizHelp->KeyUsageBytes[0] & CERT_NON_REPUDIATION_KEY_USAGE) != 0), 0);
  1081. SendMessage(m_hButtonDecipherOnly, BM_SETCHECK, ((m_pwizHelp->KeyUsageBytes[1] & CERT_DECIPHER_ONLY_KEY_USAGE) != 0), 0);
  1082. SendMessage(m_hButtonKeyUsageCritical, BM_SETCHECK, m_pwizHelp->fMarkKeyUsageCritical, 0);
  1083. //
  1084. // now set the enable/disable state
  1085. //
  1086. if (m_pwizHelp->fDigitalSignatureContainer)
  1087. {
  1088. EnableWindow(m_hButtonDataEncryption, FALSE);
  1089. EnableWindow(m_hButtonDigitalSignature, TRUE);
  1090. EnableWindow(m_hButtonEncipherOnly, FALSE);
  1091. EnableWindow(m_hButtonKeyAgreement, FALSE);
  1092. EnableWindow(m_hButtonKeyEncryption, FALSE);
  1093. EnableWindow(m_hButtonPrevent, TRUE);
  1094. EnableWindow(m_hButtonDecipherOnly, FALSE);
  1095. }
  1096. else
  1097. {
  1098. EnableWindow(m_hButtonDataEncryption, TRUE);
  1099. EnableWindow(m_hButtonDigitalSignature, TRUE);
  1100. EnableWindow(m_hButtonEncipherOnly, TRUE);
  1101. EnableWindow(m_hButtonKeyAgreement, TRUE);
  1102. EnableWindow(m_hButtonKeyEncryption, TRUE);
  1103. EnableWindow(m_hButtonPrevent, TRUE);
  1104. EnableWindow(m_hButtonDecipherOnly, TRUE);
  1105. }
  1106. return CWizard97PropertyPage::OnSetActive();
  1107. }
  1108. /////////////////////////////////////////////////////////////////////////////
  1109. // CNewCertTypeCACertificate property page
  1110. CNewCertTypeCACertificate::CNewCertTypeCACertificate() :
  1111. CWizard97PropertyPage(
  1112. g_hInstance,
  1113. CNewCertTypeCACertificate::IDD,
  1114. g_aidFont)
  1115. {
  1116. m_szHeaderTitle.LoadString(IDS_CA_CERTIFICATE_TITLE);
  1117. m_szHeaderSubTitle.LoadString(IDS_CA_CERTIFICATE_SUB_TITLE);
  1118. InitWizard97 (FALSE);
  1119. }
  1120. CNewCertTypeCACertificate::~CNewCertTypeCACertificate()
  1121. {
  1122. }
  1123. // replacement for DoDataExchange
  1124. BOOL CNewCertTypeCACertificate::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  1125. {
  1126. if (fSuckFromDlg)
  1127. {
  1128. // m_cstrModuleName.FromWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  1129. }
  1130. else
  1131. {
  1132. // m_cstrModuleName.ToWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  1133. }
  1134. return TRUE;
  1135. }
  1136. // replacement for BEGIN_MESSAGE_MAP
  1137. BOOL CNewCertTypeCACertificate::OnCommand(WPARAM wParam, LPARAM lParam)
  1138. {
  1139. /*
  1140. switch(LOWORD(wParam))
  1141. {
  1142. default:
  1143. return FALSE;
  1144. break;
  1145. }
  1146. */
  1147. return TRUE;
  1148. }
  1149. /////////////////////////////////////////////////////////////////////////////
  1150. // CNewCertTypeCACertificate message handlers
  1151. void CNewCertTypeCACertificate::UpdateWizHelp()
  1152. {
  1153. if (BST_CHECKED == SendMessage(m_hButtonVerifySignature, BM_GETCHECK, 0, 0))
  1154. m_pwizHelp->KeyUsageBytes[0] |= CERT_KEY_CERT_SIGN_KEY_USAGE;
  1155. else
  1156. m_pwizHelp->KeyUsageBytes[0] &= ~CERT_KEY_CERT_SIGN_KEY_USAGE;
  1157. if (BST_CHECKED == SendMessage(m_hButtonIssueCRL, BM_GETCHECK, 0, 0))
  1158. m_pwizHelp->KeyUsageBytes[0] |= CERT_CRL_SIGN_KEY_USAGE;
  1159. else
  1160. m_pwizHelp->KeyUsageBytes[0] &= ~CERT_CRL_SIGN_KEY_USAGE;
  1161. }
  1162. LRESULT CNewCertTypeCACertificate::OnWizardBack()
  1163. {
  1164. UpdateWizHelp();
  1165. return CWizard97PropertyPage::OnWizardBack();
  1166. }
  1167. LRESULT CNewCertTypeCACertificate::OnWizardNext()
  1168. {
  1169. UpdateWizHelp();
  1170. return CWizard97PropertyPage::OnWizardNext();
  1171. }
  1172. BOOL CNewCertTypeCACertificate::OnInitDialog()
  1173. {
  1174. CWizard97PropertyPage::OnInitDialog();
  1175. m_hButtonVerifySignature = GetDlgItem(m_hWnd, IDC_VERIFY_SIGNATURE_CHECK);
  1176. m_hButtonIssueCRL = GetDlgItem(m_hWnd, IDC_ISSUE_CRL_CHECK);
  1177. return TRUE; // return TRUE unless you set the focus to a control
  1178. // EXCEPTION: OCX Property Pages should return FALSE
  1179. }
  1180. void CNewCertTypeCACertificate::OnDestroy()
  1181. {
  1182. CWizard97PropertyPage::OnDestroy();
  1183. }
  1184. BOOL CNewCertTypeCACertificate::OnSetActive()
  1185. {
  1186. PropSheet_SetWizButtons(GetParent(), PSWIZB_BACK | PSWIZB_NEXT);
  1187. SendMessage(m_hButtonIssueCRL, BM_SETCHECK, ((m_pwizHelp->KeyUsageBytes[0] & CERT_KEY_CERT_SIGN_KEY_USAGE) != 0), 0);
  1188. SendMessage(m_hButtonIssueCRL, BM_SETCHECK, ((m_pwizHelp->KeyUsageBytes[0] & CERT_CRL_SIGN_KEY_USAGE) != 0), 0);
  1189. return CWizard97PropertyPage::OnSetActive();
  1190. }
  1191. /////////////////////////////////////////////////////////////////////////////
  1192. // CNewCertTypeCompletion property page
  1193. CNewCertTypeCompletion::CNewCertTypeCompletion() :
  1194. CWizard97PropertyPage(
  1195. g_hInstance,
  1196. CNewCertTypeCompletion::IDD,
  1197. g_aidFont)
  1198. {
  1199. InitWizard97 (TRUE);
  1200. }
  1201. CNewCertTypeCompletion::~CNewCertTypeCompletion()
  1202. {
  1203. }
  1204. // replacement for DoDataExchange
  1205. BOOL CNewCertTypeCompletion::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  1206. {
  1207. if (fSuckFromDlg)
  1208. {
  1209. // m_cstrModuleName.FromWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  1210. }
  1211. else
  1212. {
  1213. // m_cstrModuleName.ToWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  1214. }
  1215. return TRUE;
  1216. }
  1217. // replacement for BEGIN_MESSAGE_MAP
  1218. BOOL CNewCertTypeCompletion::OnCommand(WPARAM wParam, LPARAM lParam)
  1219. {
  1220. /*
  1221. switch(LOWORD(wParam))
  1222. {
  1223. default:
  1224. return FALSE;
  1225. break;
  1226. }
  1227. */
  1228. return TRUE;
  1229. }
  1230. /////////////////////////////////////////////////////////////////////////////
  1231. // CNewCertTypeCompletion message handlers
  1232. BOOL CNewCertTypeCompletion::OnWizardFinish()
  1233. {
  1234. return CWizard97PropertyPage::OnWizardFinish();
  1235. }
  1236. LRESULT CNewCertTypeCompletion::OnWizardBack()
  1237. {
  1238. if (!m_pwizHelp->fShowAdvanced)
  1239. return (IDD_NEWCERTTYPE_CONTROL);
  1240. else if (m_pwizHelp->BasicConstraints2.fCA)
  1241. return (IDD_NEWCERTTYPE_KEY_USAGE);
  1242. else
  1243. return 0;
  1244. }
  1245. void CNewCertTypeCompletion::AddResultsToSummaryList()
  1246. {
  1247. int i = 0;
  1248. unsigned int j;
  1249. int listIndex = 0;
  1250. CString szItemName;
  1251. CString szItemText;
  1252. PCCRYPT_OID_INFO pOIDInfo;
  1253. LPWSTR pszOIDName;
  1254. BOOL bKeyUsageFirstItem = TRUE;
  1255. WCHAR szNumberString[256];
  1256. // friendly name of cert template
  1257. szItemName.LoadString(IDS_CERTIFICATE_TEMPLATE);
  1258. ListView_NewItem(m_hSummaryList, i, szItemName);
  1259. ListView_SetItemText(m_hSummaryList, i++, 1, (LPWSTR)(LPCTSTR) (*(m_pwizHelp->pcstrFriendlyName)) );
  1260. // the base cert template that was used
  1261. if (!m_pwizHelp->fInEditCertTypeMode)
  1262. {
  1263. szItemName.LoadString(IDS_BASE_CERTIFICATE_TEMPLATE);
  1264. ListView_NewItem(m_hSummaryList, i, szItemName);
  1265. ListView_SetItemText(m_hSummaryList, i++, 1, (LPWSTR)(LPCTSTR) (*(m_pwizHelp->pcstrBaseCertName)) );
  1266. }
  1267. // enhanced key usage list
  1268. szItemName.LoadString(IDS_CERTIFICATE_PURPOSE_LIST);
  1269. ListView_NewItem(m_hSummaryList, i, szItemName);
  1270. if (m_pwizHelp->EnhancedKeyUsage.cUsageIdentifier == 0)
  1271. {
  1272. szItemText.LoadString(IDS_NONE);
  1273. ListView_SetItemText(m_hSummaryList, i++, 1, (LPWSTR)(LPCTSTR)szItemText );
  1274. }
  1275. for (j=0; j<m_pwizHelp->EnhancedKeyUsage.cUsageIdentifier; j++)
  1276. {
  1277. if (j != 0)
  1278. {
  1279. ListView_NewItem(m_hSummaryList, i, L"");
  1280. }
  1281. pOIDInfo = CryptFindOIDInfo(
  1282. CRYPT_OID_INFO_OID_KEY,
  1283. m_pwizHelp->EnhancedKeyUsage.rgpszUsageIdentifier[j],
  1284. CRYPT_ENHKEY_USAGE_OID_GROUP_ID);
  1285. if (pOIDInfo == NULL)
  1286. {
  1287. pszOIDName = MyMkWStr(m_pwizHelp->EnhancedKeyUsage.rgpszUsageIdentifier[j]);
  1288. ListView_SetItemText(m_hSummaryList, i++, 1, pszOIDName);
  1289. delete(pszOIDName);
  1290. }
  1291. else
  1292. {
  1293. ListView_SetItemText(m_hSummaryList, i++, 1, (LPWSTR)(LPCWSTR)pOIDInfo->pwszName);
  1294. }
  1295. }
  1296. // enhanced key usage critical
  1297. szItemName.LoadString(IDS_CERTIFICATE_PURPOSES_CRITICAL);
  1298. ListView_NewItem(m_hSummaryList, i, szItemName);
  1299. if (m_pwizHelp->fMarkEKUCritical)
  1300. szItemText.LoadString(IDS_YES);
  1301. else
  1302. szItemText.LoadString(IDS_NO);
  1303. ListView_SetItemText(m_hSummaryList, i++, 1, (LPWSTR)(LPCWSTR)szItemText);
  1304. // include email address
  1305. szItemName.LoadString(IDS_INCLUDE_EMAIL_ADDRESS);
  1306. ListView_NewItem(m_hSummaryList, i, szItemName);
  1307. if (m_pwizHelp->fIncludeEmail)
  1308. szItemText.LoadString(IDS_YES);
  1309. else
  1310. szItemText.LoadString(IDS_NO);
  1311. ListView_SetItemText(m_hSummaryList, i++, 1, (LPWSTR)(LPCWSTR)szItemText);
  1312. // allow CA to fill in info
  1313. szItemName.LoadString(IDS_ALLOW_CA_TO_FILL_IN);
  1314. ListView_NewItem(m_hSummaryList, i, szItemName);
  1315. if (m_pwizHelp->fAllowCAtoFillInInfo)
  1316. szItemText.LoadString(IDS_YES);
  1317. else
  1318. szItemText.LoadString(IDS_NO);
  1319. ListView_SetItemText(m_hSummaryList, i++, 1, (LPWSTR)(LPCWSTR)szItemText);
  1320. // enabled for auto enroll
  1321. szItemName.LoadString(IDS_ENABLED_FOR_AUTOENROLL);
  1322. ListView_NewItem(m_hSummaryList, i, szItemName);
  1323. if (m_pwizHelp->fAllowAutoEnroll)
  1324. szItemText.LoadString(IDS_YES);
  1325. else
  1326. szItemText.LoadString(IDS_NO);
  1327. ListView_SetItemText(m_hSummaryList, i++, 1, (LPWSTR)(LPCWSTR)szItemText);
  1328. // KeyUsage
  1329. szItemName.LoadString(IDS_PUBLIC_KEY_USAGE_LIST);
  1330. ListView_NewItem(m_hSummaryList, i, szItemName);
  1331. SetItemTextWrapper(
  1332. IDS_DIGITAL_SIGNATURE_KEY_USAGE,
  1333. &i,
  1334. m_pwizHelp->KeyUsageBytes[0] & CERT_DIGITAL_SIGNATURE_KEY_USAGE,
  1335. &bKeyUsageFirstItem);
  1336. SetItemTextWrapper(
  1337. IDS_NON_REPUDIATION_KEY_USAGE,
  1338. &i,
  1339. m_pwizHelp->KeyUsageBytes[0] & CERT_NON_REPUDIATION_KEY_USAGE,
  1340. &bKeyUsageFirstItem);
  1341. SetItemTextWrapper(
  1342. IDS_DATA_ENCIPHERMENT_KEY_USAGE,
  1343. &i,
  1344. m_pwizHelp->KeyUsageBytes[0] & CERT_DATA_ENCIPHERMENT_KEY_USAGE,
  1345. &bKeyUsageFirstItem);
  1346. SetItemTextWrapper(
  1347. IDS_KEY_ENCIPHERMENT_KEY_USAGE,
  1348. &i,
  1349. m_pwizHelp->KeyUsageBytes[0] & CERT_KEY_ENCIPHERMENT_KEY_USAGE,
  1350. &bKeyUsageFirstItem);
  1351. SetItemTextWrapper(
  1352. IDS_KEY_AGREEMENT_KEY_USAGE,
  1353. &i,
  1354. m_pwizHelp->KeyUsageBytes[0] & CERT_KEY_AGREEMENT_KEY_USAGE,
  1355. &bKeyUsageFirstItem);
  1356. SetItemTextWrapper(
  1357. IDS_KEY_CERT_SIGN_KEY_USAGE,
  1358. &i,
  1359. m_pwizHelp->KeyUsageBytes[0] & CERT_KEY_CERT_SIGN_KEY_USAGE,
  1360. &bKeyUsageFirstItem);
  1361. SetItemTextWrapper(
  1362. IDS_OFFLINE_CRL_SIGN_KEY_USAGE,
  1363. &i,
  1364. m_pwizHelp->KeyUsageBytes[0] & CERT_CRL_SIGN_KEY_USAGE,
  1365. &bKeyUsageFirstItem);
  1366. SetItemTextWrapper(
  1367. IDS_ENCIPHER_ONLY_KEY_USAGE,
  1368. &i,
  1369. m_pwizHelp->KeyUsageBytes[0] & CERT_ENCIPHER_ONLY_KEY_USAGE,
  1370. &bKeyUsageFirstItem);
  1371. SetItemTextWrapper(
  1372. IDS_DECIPHER_ONLY_KEY_USAGE,
  1373. &i,
  1374. m_pwizHelp->KeyUsageBytes[1] & CERT_DECIPHER_ONLY_KEY_USAGE,
  1375. &bKeyUsageFirstItem);
  1376. // KeyUsage critical
  1377. szItemName.LoadString(IDS_PUBLIC_KEY_USAGE_CRITICAL);
  1378. ListView_NewItem(m_hSummaryList, i, szItemName);
  1379. if (m_pwizHelp->fMarkKeyUsageCritical)
  1380. szItemText.LoadString(IDS_YES);
  1381. else
  1382. szItemText.LoadString(IDS_NO);
  1383. ListView_SetItemText(m_hSummaryList, i++, 1, (LPWSTR)(LPCWSTR)szItemText);
  1384. ListView_SetColumnWidth(m_hSummaryList, 0, LVSCW_AUTOSIZE);
  1385. ListView_SetColumnWidth(m_hSummaryList, 1, LVSCW_AUTOSIZE);
  1386. }
  1387. BOOL CNewCertTypeCompletion::OnInitDialog()
  1388. {
  1389. CWizard97PropertyPage::OnInitDialog();
  1390. m_hSummaryList = GetDlgItem(m_hWnd, IDC_SUMMARY_LIST);
  1391. // firstlast page
  1392. SendMessage(GetDlgItem(IDC_COMPLETION_BIGBOLD_STATIC), WM_SETFONT, (WPARAM)GetBigBoldFont(), MAKELPARAM(TRUE, 0));
  1393. ListView_NewColumn(m_hSummaryList, 0, 50);
  1394. ListView_NewColumn(m_hSummaryList, 1, 50);
  1395. return TRUE; // return TRUE unless you set the focus to a control
  1396. // EXCEPTION: OCX Property Pages should return FALSE
  1397. }
  1398. void CNewCertTypeCompletion::SetItemTextWrapper(UINT nID, int *piItem, BOOL fDoInsert, BOOL *pfFirstUsageItem)
  1399. {
  1400. CString szOtherInfoName;
  1401. if (fDoInsert)
  1402. {
  1403. szOtherInfoName.LoadString(nID);
  1404. if (!(*pfFirstUsageItem))
  1405. {
  1406. LVITEM lvItem;
  1407. lvItem.iItem = *piItem;
  1408. lvItem.iSubItem = 0;
  1409. ListView_InsertItem(m_hSummaryList, &lvItem);
  1410. }
  1411. else
  1412. {
  1413. *pfFirstUsageItem = FALSE;
  1414. }
  1415. ListView_SetItemText(m_hSummaryList, *piItem, 1, (LPWSTR)(LPCTSTR)szOtherInfoName);
  1416. (*piItem)++;
  1417. }
  1418. }
  1419. BOOL CNewCertTypeCompletion::OnSetActive()
  1420. {
  1421. PropSheet_SetWizButtons(GetParent(), PSWIZB_BACK | PSWIZB_FINISH);
  1422. ListView_DeleteAllItems(m_hSummaryList);
  1423. AddResultsToSummaryList();
  1424. return CWizard97PropertyPage::OnSetActive();
  1425. }
  1426. HRESULT UpdateCertType(HCERTTYPE hCertType,
  1427. PWIZARD_HELPER pwizHelp)
  1428. {
  1429. HRESULT hr;
  1430. LPWSTR aszCertName[2];
  1431. LPWSTR *aszCSPList = NULL;
  1432. DWORD dwFlags;
  1433. BOOL fUseKeyUsage;
  1434. BOOL fUseBasicConstraints;
  1435. unsigned int i;
  1436. //
  1437. // get the flags for the cert type, then modify those, and reset the
  1438. // flags at the end of this function
  1439. //
  1440. hr = CAGetCertTypeFlags(hCertType, &dwFlags);
  1441. _JumpIfError(hr, error, "CAGetCertTypeFlags");
  1442. //
  1443. // key usage
  1444. //
  1445. fUseKeyUsage = (pwizHelp->KeyUsageBytes[0] != 0) || (pwizHelp->KeyUsageBytes[1] != 0);
  1446. hr = CASetCertTypeExtension(
  1447. hCertType,
  1448. TEXT(szOID_KEY_USAGE),
  1449. pwizHelp->fMarkKeyUsageCritical ? CA_EXT_FLAG_CRITICAL : 0,
  1450. fUseKeyUsage ? pwizHelp->pKeyUsage : NULL);
  1451. _JumpIfError(hr, error, "CASetCertTypeExtension");
  1452. //
  1453. // enhanced key usage
  1454. //
  1455. hr = CASetCertTypeExtension(
  1456. hCertType,
  1457. TEXT(szOID_ENHANCED_KEY_USAGE),
  1458. pwizHelp->fMarkEKUCritical ? CA_EXT_FLAG_CRITICAL : 0,
  1459. &(pwizHelp->EnhancedKeyUsage));
  1460. _JumpIfError(hr, error, "CASetCertTypeExtension");
  1461. //
  1462. // basic constraints
  1463. //
  1464. fUseBasicConstraints = pwizHelp->BasicConstraints2.fCA;
  1465. hr = CASetCertTypeExtension(
  1466. hCertType,
  1467. TEXT(szOID_BASIC_CONSTRAINTS2),
  1468. 0,
  1469. fUseBasicConstraints ? &(pwizHelp->BasicConstraints2) : NULL);
  1470. _JumpIfError(hr, error, "CASetCertTypeExtension");
  1471. //
  1472. // friendly name
  1473. //
  1474. aszCertName[0] = (LPWSTR) ((LPCTSTR) *(pwizHelp->pcstrFriendlyName));
  1475. aszCertName[1] = NULL;
  1476. hr = CASetCertTypeProperty(
  1477. hCertType,
  1478. CERTTYPE_PROP_FRIENDLY_NAME,
  1479. aszCertName);
  1480. _JumpIfError(hr, error, "CASetCertTypeProperty");
  1481. //
  1482. // digsig/exchange
  1483. //
  1484. if (pwizHelp->fDigitalSignatureContainer)
  1485. {
  1486. hr = CASetCertTypeKeySpec(hCertType, AT_SIGNATURE);
  1487. }
  1488. else
  1489. {
  1490. hr = CASetCertTypeKeySpec(hCertType, AT_KEYEXCHANGE);
  1491. }
  1492. _JumpIfError(hr, error, "CASetCertTypeKeySpec");
  1493. //
  1494. // csp list
  1495. //
  1496. aszCSPList = (LPWSTR *) new(LPWSTR[pwizHelp->cCSPs+1]);
  1497. if(aszCSPList == NULL)
  1498. {
  1499. hr = E_OUTOFMEMORY;
  1500. _JumpIfError(hr, error, "new");
  1501. }
  1502. ZeroMemory(aszCSPList, sizeof(LPWSTR)*(pwizHelp->cCSPs+1));
  1503. //
  1504. // copy each the array of CStrings to an array of LPWSTRs
  1505. //
  1506. for (i=0; i<pwizHelp->cCSPs; i++)
  1507. {
  1508. aszCSPList[i] = new(WCHAR[wcslen((LPCTSTR)pwizHelp->rgszCSPList[i])+1]);
  1509. if (aszCSPList[i] == NULL)
  1510. {
  1511. hr = E_OUTOFMEMORY;
  1512. _JumpIfError(hr, error, "new");
  1513. break;
  1514. }
  1515. wcscpy(aszCSPList[i], (LPCTSTR)pwizHelp->rgszCSPList[i]);
  1516. }
  1517. //
  1518. // NULL terminate the LPWSTR array and set the CSPlist property
  1519. //
  1520. if (i == pwizHelp->cCSPs)
  1521. {
  1522. aszCSPList[i] = NULL;
  1523. hr = CASetCertTypeProperty(
  1524. hCertType,
  1525. CERTTYPE_PROP_CSP_LIST,
  1526. aszCSPList);
  1527. _JumpIfError(hr, error, "CASetCertTypeProperty");
  1528. }
  1529. //
  1530. // Acls
  1531. //
  1532. if(pwizHelp->pSD)
  1533. {
  1534. hr = CACertTypeSetSecurity(hCertType, pwizHelp->pSD);
  1535. _JumpIfError(hr, error, "CACertTypeSetSecurity");
  1536. }
  1537. //
  1538. // private key exportable, include email, allow CA to fill in name
  1539. //
  1540. if (pwizHelp->fPrivateKeyExportable)
  1541. {
  1542. dwFlags |= CT_FLAG_EXPORTABLE_KEY;
  1543. }
  1544. else
  1545. {
  1546. dwFlags &= ~CT_FLAG_EXPORTABLE_KEY;
  1547. }
  1548. if (pwizHelp->fIncludeEmail)
  1549. {
  1550. dwFlags |= CT_FLAG_ADD_EMAIL;
  1551. }
  1552. else
  1553. {
  1554. dwFlags &= ~CT_FLAG_ADD_EMAIL;
  1555. }
  1556. if (pwizHelp->fAllowAutoEnroll)
  1557. {
  1558. dwFlags |= CT_FLAG_AUTO_ENROLLMENT;
  1559. }
  1560. else
  1561. {
  1562. dwFlags &= ~CT_FLAG_AUTO_ENROLLMENT;
  1563. }
  1564. if (!pwizHelp->fAllowCAtoFillInInfo)
  1565. {
  1566. dwFlags |= CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT;
  1567. }
  1568. else
  1569. {
  1570. dwFlags &= ~CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT;
  1571. }
  1572. if (pwizHelp->fMachine)
  1573. {
  1574. dwFlags |= CT_FLAG_MACHINE_TYPE;
  1575. }
  1576. else
  1577. {
  1578. dwFlags &= ~CT_FLAG_MACHINE_TYPE;
  1579. }
  1580. if (pwizHelp->fPublishToDS)
  1581. {
  1582. dwFlags |= CT_FLAG_PUBLISH_TO_DS;
  1583. }
  1584. else
  1585. {
  1586. dwFlags &= ~CT_FLAG_PUBLISH_TO_DS;
  1587. }
  1588. if (pwizHelp->fAddTemplateName)
  1589. {
  1590. dwFlags |= CT_FLAG_ADD_TEMPLATE_NAME;
  1591. }
  1592. else
  1593. {
  1594. dwFlags &= ~CT_FLAG_ADD_TEMPLATE_NAME;
  1595. }
  1596. if (pwizHelp->fAddDirectoryPath)
  1597. {
  1598. dwFlags |= CT_FLAG_ADD_DIRECTORY_PATH;
  1599. }
  1600. else
  1601. {
  1602. dwFlags &= ~CT_FLAG_ADD_DIRECTORY_PATH;
  1603. }
  1604. hr = CASetCertTypeFlags(hCertType, dwFlags);
  1605. _JumpIfError(hr, error, "CASetCertTypeFlags");
  1606. //
  1607. // make the call that actually writes the cached information
  1608. //
  1609. hr = CAUpdateCertType(hCertType);
  1610. // So we can get logging
  1611. _JumpIfError(hr, error, "CAUpdateCertType");
  1612. error:
  1613. if(aszCSPList)
  1614. {
  1615. for (i=0; i<pwizHelp->cCSPs; i++)
  1616. {
  1617. if(aszCSPList[i])
  1618. {
  1619. delete[](aszCSPList[i]);
  1620. }
  1621. }
  1622. delete[](aszCSPList);
  1623. }
  1624. return hr;
  1625. }
  1626. // returns the new certtype if a new one is being created, returns NULL
  1627. // if the hEditCertType parameter is non-NULL which means it is in edit mode
  1628. HCERTTYPE InvokeCertTypeWizard(HCERTTYPE hEditCertType,
  1629. HWND hwndConsole)
  1630. {
  1631. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1632. WIZARD_HELPER wizHelp;
  1633. ZeroMemory(&wizHelp, sizeof(wizHelp));
  1634. int i;
  1635. HCERTTYPE hNewCertType;
  1636. HCERTTYPE hRetCertType;
  1637. HRESULT hr;
  1638. CWizard97PropertySheet PropSheet(
  1639. g_hInstance,
  1640. IDS_CERTIFICATE_TEMPLATE_WIZARD,
  1641. IDB_WIZ_WATERMARK,
  1642. IDB_WIZ_BANNER,
  1643. TRUE);
  1644. CString szPropSheetTitle;
  1645. CNewCertTypeWelcome WelcomePage;
  1646. CNewCertTypeBaseType BaseTypePage;
  1647. CNewCertTypeBasicInformation BasicInformationPage;
  1648. CNewCertTypeKeyUsage KeyUsagePage;
  1649. CNewCertTypeCACertificate CACertificatePage;
  1650. CNewCertTypeCompletion CompletionPage;
  1651. wizHelp.pcstrFriendlyName = new(CString);
  1652. if (wizHelp.pcstrFriendlyName == NULL)
  1653. return NULL;
  1654. wizHelp.pcstrBaseCertName = new(CString);
  1655. if(wizHelp.pcstrBaseCertName == NULL)
  1656. return NULL;
  1657. hr = SetupFonts(g_hInstance, NULL, &wizHelp.BigBoldFont, &wizHelp.BoldFont);
  1658. if (hEditCertType != NULL)
  1659. {
  1660. wizHelp.fInEditCertTypeMode = TRUE;
  1661. FillInCertTypeInfo(hEditCertType, &wizHelp);
  1662. }
  1663. WelcomePage.m_pwizHelp = &wizHelp;
  1664. WelcomePage.m_pWiz = &PropSheet;
  1665. PropSheet.AddPage(&WelcomePage);
  1666. BaseTypePage.m_pwizHelp = &wizHelp;
  1667. BaseTypePage.m_pWiz = &PropSheet;
  1668. PropSheet.AddPage(&BaseTypePage);
  1669. BasicInformationPage.m_pwizHelp = &wizHelp;
  1670. BasicInformationPage.m_pWiz = &PropSheet;
  1671. PropSheet.AddPage(&BasicInformationPage);
  1672. KeyUsagePage.m_pwizHelp = &wizHelp;
  1673. KeyUsagePage.m_pWiz = &PropSheet;
  1674. PropSheet.AddPage(&KeyUsagePage);
  1675. CACertificatePage.m_pwizHelp = &wizHelp;
  1676. CACertificatePage.m_pWiz = &PropSheet;
  1677. PropSheet.AddPage(&CACertificatePage);
  1678. CompletionPage.m_pwizHelp = &wizHelp;
  1679. CompletionPage.m_pWiz = &PropSheet;
  1680. PropSheet.AddPage(&CompletionPage);
  1681. if (PropSheet.DoWizard(hwndConsole))
  1682. {
  1683. if (hEditCertType != NULL)
  1684. {
  1685. hr = UpdateCertType(hEditCertType, &wizHelp);
  1686. hRetCertType = NULL;
  1687. }
  1688. else
  1689. {
  1690. GUID guidContainerName;
  1691. WCHAR *sz = NULL;
  1692. // generate a CN name for the new certtype
  1693. RPC_STATUS rpcs = UuidCreate(&guidContainerName);
  1694. rpcs = UuidToStringW(&guidContainerName, &sz);
  1695. ASSERT(sz != NULL);
  1696. hr = CACreateCertType(sz, NULL, 0, &hNewCertType);
  1697. RpcStringFree(&sz);
  1698. hr = UpdateCertType(hNewCertType, &wizHelp);
  1699. hRetCertType = hNewCertType;
  1700. }
  1701. }
  1702. else
  1703. {
  1704. hRetCertType = NULL;
  1705. }
  1706. CleanUpCertTypeInfo(&wizHelp);
  1707. delete(wizHelp.pcstrFriendlyName);
  1708. delete(wizHelp.pcstrBaseCertName);
  1709. return hRetCertType;
  1710. }