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.

1696 lines
60 KiB

  1. // AuthCtl.cpp : Implementation of the CCertAuthCtrl OLE control class.
  2. // THIS FEATURE USED TO BE SOMETHING DIFFERENT, now it has meaning of:
  3. // Doing CertificateRequest and Authority Mapping/management.
  4. #include "stdafx.h"
  5. //#include "Util.h"
  6. #include "certmap.h"
  7. #include "AuthCtl.h"
  8. #include "AuthPpg.h"
  9. /*
  10. #include "Reg.h"
  11. #include "nLocEnrl.h"
  12. #ifdef USE_COMPROP_WIZ97
  13. # include "wizard.h" // implement Wizard97 look and feel
  14. #endif
  15. #include <windows.h>
  16. #include <wincrypt.h>
  17. //#include <unicode.h>
  18. //#include <base64.h>
  19. //#include <pvk.h>
  20. //need the CLSID and IID for xEnroll
  21. #include <ole2.h>
  22. #include "xenroll.h"
  23. #include <certrpc.h>
  24. #include <winsock.h>
  25. #include <wintrust.h>
  26. #include "wrapmb.h"
  27. #include "NKWelcom.h" // for class CNKWelcome
  28. #include "NKMuxPg.h" // for class CNKMuxPg -- for new certs
  29. #include "NKMuxPg2.h" // for class CNKMuxPg2 -- for OOB finish ops
  30. #include "NKMuxPg3.h" // for class CNKMuxPg3 -- for Mod Existing ops
  31. #define _CRYPT32_
  32. // persistence and mapping includes
  33. extern "C"
  34. {
  35. #include <wincrypt.h>
  36. #include <sslsp.h>
  37. }
  38. #include "Iismap.hxx"
  39. #include "Iiscmr.hxx"
  40. #include "CrackCrt.h"
  41. #include "ListRow.h"
  42. #include "ChkLstCt.h"
  43. #include "IssueDlg.h"
  44. // include header files for the dialog pages
  45. //
  46. #include "KeyObjs.h"
  47. //#include "WizSheet.h"
  48. #include "NKChseCA.h"
  49. #include "NKDN.h"
  50. #include "NKDN1.h"
  51. #include "NKDN2.h"
  52. #include "NKFlInfo.h"
  53. #include "NKKyInfo.h"
  54. #include "NKUsrInf.h"
  55. #include "CertSel.h"
  56. #include "CompPage.h"
  57. #include "WizError.h"
  58. #include "Creating.h"
  59. #include "CTLWelc.h"
  60. #include "CTLMuxPg.h"
  61. #include "NKChseCA.h"
  62. #include "NKWelcom.h" // for class CNKWelcome
  63. #include "NKMuxPg.h" // for class CNKMuxPg
  64. #include "KeyRImpt.h" // for class CKeyImpt -- the 1st KeyRing Import page
  65. #include "KeyRFile.h" // for the second KeyRing Import page that asks
  66. // the user to confirm they want to do the import
  67. #include "FinCImpt.h" // for the first Cert-Finish an offline-request
  68. // Wizard page -- class CFinCertImport
  69. #include "FinCFin.h" // for the second Cert-Finish an offline-request
  70. // Wizard page -- class CFinCertImport
  71. #include "NKMuxPg3.h"
  72. #include "DelCert.h"
  73. */
  74. #ifdef _DEBUG
  75. #define new DEBUG_NEW
  76. #undef THIS_FILE
  77. static char THIS_FILE[] = __FILE__;
  78. #endif
  79. IMPLEMENT_DYNCREATE(CCertAuthCtrl, COleControl)
  80. /////////////////////////////////////////////////////////////////////////////
  81. // Message map
  82. BEGIN_MESSAGE_MAP(CCertAuthCtrl, COleControl)
  83. //{{AFX_MSG_MAP(CCertAuthCtrl)
  84. // NOTE - ClassWizard will add and remove message map entries
  85. // DO NOT EDIT what you see in these blocks of generated code !
  86. //}}AFX_MSG_MAP
  87. ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
  88. END_MESSAGE_MAP()
  89. /////////////////////////////////////////////////////////////////////////////
  90. // Dispatch map
  91. BEGIN_DISPATCH_MAP(CCertAuthCtrl, COleControl)
  92. //{{AFX_DISPATCH_MAP(CCertAuthCtrl)
  93. DISP_FUNCTION(CCertAuthCtrl, "SetMachineName", SetMachineName, VT_EMPTY, VTS_BSTR)
  94. DISP_FUNCTION(CCertAuthCtrl, "SetServerInstance", SetServerInstance, VT_EMPTY, VTS_BSTR)
  95. DISP_STOCKPROP_FONT()
  96. DISP_STOCKPROP_BORDERSTYLE()
  97. DISP_STOCKPROP_ENABLED()
  98. DISP_STOCKPROP_CAPTION()
  99. DISP_FUNCTION_ID(CCertAuthCtrl, "DoClick", DISPID_DOCLICK, DoClick, VT_EMPTY, VTS_I4)
  100. //}}AFX_DISPATCH_MAP
  101. DISP_FUNCTION_ID(CCertAuthCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
  102. END_DISPATCH_MAP()
  103. /////////////////////////////////////////////////////////////////////////////
  104. // Event map
  105. BEGIN_EVENT_MAP(CCertAuthCtrl, COleControl)
  106. //{{AFX_EVENT_MAP(CCertAuthCtrl)
  107. EVENT_STOCK_CLICK()
  108. //}}AFX_EVENT_MAP
  109. END_EVENT_MAP()
  110. /////////////////////////////////////////////////////////////////////////////
  111. // Property pages
  112. // TODO: Add more property pages as needed. Remember to increase the count!
  113. BEGIN_PROPPAGEIDS(CCertAuthCtrl, 2)
  114. PROPPAGEID(CCertAuthPropPage::guid)
  115. PROPPAGEID(CLSID_CFontPropPage)
  116. END_PROPPAGEIDS(CCertAuthCtrl)
  117. /////////////////////////////////////////////////////////////////////////////
  118. // Initialize class factory and guid
  119. IMPLEMENT_OLECREATE_EX(CCertAuthCtrl, "CERTMAP.CertmapCtrl.2",
  120. 0x996ff6f, 0xb6a1, 0x11d0, 0x92, 0x92, 0, 0xc0, 0x4f, 0xb6, 0x67, 0x8b)
  121. /////////////////////////////////////////////////////////////////////////////
  122. // Type library ID and version
  123. IMPLEMENT_OLETYPELIB(CCertAuthCtrl, _tlid, _wVerMajor, _wVerMinor)
  124. /////////////////////////////////////////////////////////////////////////////
  125. // Interface IDs
  126. const IID BASED_CODE IID_DCertAuth =
  127. { 0x996ff6d, 0xb6a1, 0x11d0, { 0x92, 0x92, 0, 0xc0, 0x4f, 0xb6, 0x67, 0x8b } };
  128. const IID BASED_CODE IID_DCertAuthEvents =
  129. { 0x996ff6e, 0xb6a1, 0x11d0, { 0x92, 0x92, 0, 0xc0, 0x4f, 0xb6, 0x67, 0x8b } };
  130. /////////////////////////////////////////////////////////////////////////////
  131. // Control type information
  132. static const DWORD BASED_CODE _dwCertAuthOleMisc =
  133. OLEMISC_ACTIVATEWHENVISIBLE |
  134. OLEMISC_SETCLIENTSITEFIRST |
  135. OLEMISC_INSIDEOUT |
  136. OLEMISC_CANTLINKINSIDE |
  137. OLEMISC_RECOMPOSEONRESIZE;
  138. IMPLEMENT_OLECTLTYPE(CCertAuthCtrl, IDS_CERTAUTH, _dwCertAuthOleMisc)
  139. /////////////////////////////////////////////////////////////////////////////
  140. // CCertAuthCtrl::CCertAuthCtrlFactory::UpdateRegistry -
  141. // Adds or removes system registry entries for CCertAuthCtrl
  142. BOOL CCertAuthCtrl::CCertAuthCtrlFactory::UpdateRegistry(BOOL bRegister)
  143. {
  144. // TODO: Verify that your control follows apartment-model threading rules.
  145. // Refer to MFC TechNote 64 for more information.
  146. // If your control does not conform to the apartment-model rules, then
  147. // you must modify the code below, changing the 6th parameter from
  148. // afxRegApartmentThreading to 0.
  149. if (bRegister)
  150. return AfxOleRegisterControlClass(
  151. AfxGetInstanceHandle(),
  152. m_clsid,
  153. m_lpszProgID,
  154. IDS_CERTAUTH,
  155. IDB_CERTAUTH,
  156. afxRegApartmentThreading,
  157. _dwCertAuthOleMisc,
  158. _tlid,
  159. _wVerMajor,
  160. _wVerMinor);
  161. else
  162. return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
  163. }
  164. /////////////////////////////////////////////////////////////////////////////
  165. // CCertAuthCtrl::CCertAuthCtrl - Constructor
  166. CCertAuthCtrl::CCertAuthCtrl():
  167. m_fUpdateFont( FALSE ),
  168. m_hAccel( NULL ),
  169. m_cAccel( 0 )
  170. {
  171. InitializeIIDs(&IID_DCertAuth, &IID_DCertAuthEvents);
  172. }
  173. /////////////////////////////////////////////////////////////////////////////
  174. // CCertAuthCtrl::~CCertAuthCtrl - Destructor
  175. CCertAuthCtrl::~CCertAuthCtrl()
  176. {
  177. if ( m_hAccel )
  178. DestroyAcceleratorTable( m_hAccel );
  179. m_hAccel = NULL;
  180. }
  181. /////////////////////////////////////////////////////////////////////////////
  182. // CCertAuthCtrl::OnDraw - Drawing function
  183. void CCertAuthCtrl::OnDraw(
  184. CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
  185. {
  186. CFont* pOldFont;
  187. // select the stock font, recording the old one
  188. pOldFont = SelectStockFont( pdc );
  189. // do the superclass draw
  190. DoSuperclassPaint(pdc, rcBounds);
  191. // restore the old font - sneakily getting the correct font object
  192. pOldFont = pdc->SelectObject(pOldFont);
  193. // we want the button window to continue drawing in the correct font even
  194. // when we are not using OnDraw. i.e. when it is being pushed down. This
  195. // means we need to set the CWnd::SetFont() method.
  196. if ( m_fUpdateFont )
  197. {
  198. m_fUpdateFont = FALSE;
  199. CWnd::SetFont( pOldFont );
  200. }
  201. }
  202. /////////////////////////////////////////////////////////////////////////////
  203. // CCertAuthCtrl::DoPropExchange - Persistence support
  204. void CCertAuthCtrl::DoPropExchange(CPropExchange* pPX)
  205. {
  206. ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
  207. COleControl::DoPropExchange(pPX);
  208. }
  209. /////////////////////////////////////////////////////////////////////////////
  210. // CCertAuthCtrl::OnResetState - Reset control to default state
  211. void CCertAuthCtrl::OnResetState()
  212. {
  213. COleControl::OnResetState(); // Resets defaults found in DoPropExchange
  214. }
  215. /////////////////////////////////////////////////////////////////////////////
  216. // CCertAuthCtrl::AboutBox - Display an "About" box to the user
  217. void CCertAuthCtrl::AboutBox()
  218. {
  219. // CDialog dlgAbout(IDD_ABOUTBOX_CERTAUTH);
  220. // dlgAbout.DoModal();
  221. }
  222. /////////////////////////////////////////////////////////////////////////////
  223. // CCertAuthCtrl message handlers
  224. //---------------------------------------------------------------------------
  225. BOOL CCertAuthCtrl::PreCreateWindow(CREATESTRUCT& cs)
  226. {
  227. if ( cs.style & WS_CLIPSIBLINGS )
  228. cs.style ^= WS_CLIPSIBLINGS;
  229. cs.lpszClass = _T("BUTTON");
  230. return COleControl::PreCreateWindow(cs);
  231. }
  232. /////////////////////////////////////////////////////////////////////////////
  233. // CAppsCtrl::IsSubclassedControl - This is a subclassed control
  234. BOOL CCertAuthCtrl::IsSubclassedControl()
  235. {
  236. return TRUE;
  237. }
  238. /////////////////////////////////////////////////////////////////////////////
  239. // OnOcmCommand - Handle command messages
  240. LRESULT CCertAuthCtrl::OnOcmCommand(WPARAM wParam, LPARAM lParam)
  241. {
  242. #ifdef _WIN32
  243. WORD wNotifyCode = HIWORD(wParam);
  244. #else
  245. WORD wNotifyCode = HIWORD(lParam);
  246. #endif
  247. // TODO: Switch on wNotifyCode here.
  248. return 0;
  249. }
  250. /*dddddddddd
  251. #ifdef FUTURE_USE
  252. HRESULT CCertAuthCtrl::LaunchCommonCTLDialog (CCTL* pCTL)
  253. {
  254. ASSERT (pCTL);
  255. CRYPTUI_VIEWCTL_STRUCT vcs;
  256. HWND hwndParent=0;
  257. // //
  258. // // Success codes defined for HRESULTS:
  259. // //
  260. // #define S_OK ((HRESULT)0x00000000L)
  261. // #define S_FALSE ((HRESULT)0x00000001L)
  262. HRESULT hResult= S_OK;
  263. ::ZeroMemory (&vcs, sizeof (vcs));
  264. vcs.dwSize = sizeof (vcs);
  265. vcs.hwndParent = hwndParent;
  266. vcs.dwFlags = 0;
  267. vcs.pCTLContext = pCTL->GetCTLContext ();
  268. BOOL bResult = ::CryptUIDlgViewCTL (&vcs);
  269. if ( bResult )
  270. {
  271. }
  272. return hResult;
  273. }
  274. #endif
  275. #if defined(DEBUGGING)
  276. //-----------------------------------------------------------------------
  277. // checkSanityMFC is used only for debugging some strange MFC problem
  278. // where MFC loses it state!
  279. //
  280. // Method: 20 times ask MFC to get out application name that
  281. // should be "certmap" --> if we fail we throw assert + return FALSE
  282. // OTHERWISE we return TRUE;
  283. //-----------------------------------------------------------------------
  284. BOOL checkSanityMFC()
  285. {
  286. for (int i=0; i<20; i++) {
  287. CString szCaption = AfxGetAppName(); // for debug, we now print it out
  288. ASSERT( STRICMP(szCaption, _T("certmap"))==0);
  289. return FALSE;
  290. }
  291. return TRUE;
  292. }
  293. #endif
  294. */
  295. //-------------------------------------------------------------------------------
  296. // OnClick - process a click event. This will be called by the IIS admin
  297. // API to launch us! [people get here by clicking on our control]
  298. //
  299. // PARAMS: iButton an IN param. tells what "logical button" fired our control:
  300. //
  301. // value
  302. // ------
  303. // 1 Call CertWiz
  304. // 2 Call CTL Wiz
  305. //-------------------------------------------------------------------------------
  306. extern void test__non2Rons_WizClasses();
  307. void CCertAuthCtrl::OnClick(USHORT iButton)
  308. {
  309. /*ddddddddddddddd
  310. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  311. #if defined(DEBUGGING)
  312. if (DebugTestEnv(_T("MFC")) && YesNoMsgBox(_T("Shall we run: test__non2Rons_WizClasses"))) {
  313. test__non2Rons_WizClasses();
  314. }
  315. #endif
  316. #if defined(DEBUGGING) && defined(SHOW_TRACE_INFO)
  317. Trace t( _T("CCertAuthCtrl::OnClick"));
  318. #endif
  319. #if defined(DEBUGGING)
  320. checkSanityMFC();
  321. #endif
  322. #if defined(DEBUGGING)
  323. (void) ShallWeShowDebugMsgs(); // the purpose of this call is to make sure
  324. // that we properly initialize [if we are
  325. // to emit debug stmts, even though we have
  326. // a debug build]. We currently look in Reg:
  327. // "Software\\Microsoft\\CertMap\\Debug" under
  328. // HKEY_CURRENT_USER for a Key with:
  329. // name: "Enabled" and set to "TRUE".
  330. // If we find that we produce debug stmts.
  331. // See file Debug.cpp and Debug.h for more info
  332. #endif
  333. // m_szMachineName currently has the machine we were told to operate upon
  334. // "We currently do not support remote administration of Web servers."
  335. // ComputerNameMatchesOurMachineName(IN OUT CString& remoteHostname)
  336. //
  337. // After trimming [remoteHostname] see if its naming this
  338. // machine. We look for a direct case-independent match
  339. // or "localhost"
  340. //
  341. // RETURNS: T: iff the name passed in matches the machine we are
  342. // running on.
  343. //
  344. // NOTE: remoteHostname is an IN OUT. OUT since we trim any white
  345. // space off of it.
  346. //------------------------------------------------------------------
  347. if (FALSE == ComputerNameMatchesOurMachineName(m_szMachineName))
  348. {
  349. if (FALSE == m_szMachineName.IsEmpty() ) {
  350. MessageBeep(0);
  351. MsgBox( IDS_WE_CURRENTLY_DONT_SUPPORT_REMOTE_ADMIN_OF_SERVERS );
  352. return ;
  353. }
  354. }
  355. //////////////////////////////////////////////////////////////////////////////
  356. // The following bucnch of code's sole purpose is to set the application's
  357. // name properly
  358. //////////////////////////////////////////////////////////////////////////////
  359. // in case there are any errors, prepare the error string
  360. //
  361. // We store the following in our class: CString m_szOurApplicationTitle;
  362. // set the name of the application correctly
  363. // Use our Fancy Debugging "Load String" found in Easy::CString
  364. Easy::CString::LoadStringInto( m_szOurApplicationTitle, IDS_ERR_CERTWIZ_TITLE );
  365. // tompop: tjp: do we need a different string than
  366. // what CertMap uses? They use: IDS_ERR_CERTMAP_TITLE
  367. // should we use the same? They say "Certificate Mapping"
  368. // as the title; we say "Server Certificate Wizard"
  369. // Testing needs different titles for the error popups.
  370. // IDS_ERR_CERTWIZ_TITLE="Server Certificate Wizard" our std title by design.
  371. // So if somebody has set Env=TitleCertWizError, we give CertWiz as the title
  372. // so that we can pick them off in automatic tests
  373. //----------------------------------------------------------
  374. if (DebugTestEnv(_T("TitleCertWizError"))) {
  375. m_szOurApplicationTitle = _T("CertWiz"); // used in automatic tests
  376. }
  377. // free the existing name, and copy in the new one
  378. // tjp: you should compare if the old name matches the current name
  379. // and only then free and malloc the new name -- chances are that
  380. // the names are the same +++ all the free/malloc can fragment mem.
  381. free((void*)AfxGetApp()->m_pszAppName);
  382. AfxGetApp()->m_pszAppName = _tcsdup(m_szOurApplicationTitle);
  383. //////////////////////////////////////////////////////////////////////////////
  384. //////////////////////////////////////////////////////////////////////////////
  385. // this is why we are here
  386. // this is the whole purpose of the control
  387. //////////////////////////////////////////////////////////////////////////////
  388. RunDialogs4OnClick(iButton);
  389. #if defined(DEBUGGING)
  390. DODBG MsgBox( _T("DBG: finished our call to RunDialogs4OnClick") );
  391. #endif
  392. */
  393. // we are not in the business of telling the host to do
  394. // something here, so just don't fire anything off.
  395. COleControl::OnClick(iButton);
  396. }
  397. /*
  398. ////////////////////////////////////////////////////////////////////////
  399. // main handler for our dialogs:
  400. // 1. setup the metabase and then,
  401. // 2. call the routine that actually handles the dialogs
  402. // trapping exceptions to protect the metaBase
  403. //
  404. // Parms: iButton: tells what "logical button" fired our control:
  405. // 0=Get-Cert 1=Edit
  406. ////////////////////////////////////////////////////////////////////////
  407. BOOL CCertAuthCtrl::RunDialogs4OnClick(USHORT iButton)
  408. {
  409. #if defined(DEBUGGING) && defined(SHOW_TRACE_INFO)
  410. Trace t( _T("CCertAuthCtrl::RunDialogs4OnClick"));
  411. #endif
  412. #if defined(DEBUGGING)
  413. checkSanityMFC();
  414. #endif
  415. ////////////////////////////////////////////////////////////////////
  416. /////////////////////// Do a Boydm style m_szServerInstance //
  417. /////////////////////// normalization operation //
  418. ////////////////////////////////////////////////////////////////////
  419. // if there is nothing in the MB_Path, default to the first instance
  420. if ( m_szServerInstance.IsEmpty() )
  421. {
  422. // we might want to assign a default. We do so in testing.
  423. // otherwise we fail hard!
  424. MsgBox( IDS_NO_SERVER_INSTANCE_SET );
  425. //"The metabase path is not set for the virtual Web server instance. Internal error; exiting"
  426. #if defined(DEBUGGING)
  427. if ( DebugTestEnv() ) // if we are in a debug env, we are forgiving
  428. // if the user forgot to set the instance
  429. {
  430. m_szServerInstance = _T("/LM/W3SVC/1"); // hack!
  431. // let it be the default web site!
  432. } else {
  433. return FALSE;
  434. }
  435. #else
  436. // production env, this instance path needs to be set
  437. return FALSE;
  438. #endif
  439. }
  440. #if defined(DEBUGGING)
  441. DODBG {
  442. /////////////////////////////////////////////////////////////////////////////
  443. // Below we some testing hooks for manipulating the machine/path
  444. // that we operate upon.
  445. /////////////////////////////////////////////////////////////////////////////
  446. CEditDialog dlgMach(m_szMachineName,
  447. _T("Below is the machine name of the server instance; it corresponds"
  448. " to which machine's metabase we will be administrating.\n"
  449. "\nFor testing purposes you"
  450. " can change it to whatever you want, now. BLANK means local machine."));
  451. dlgMach.DoModal();
  452. CEditDialog dlgPath(m_szServerInstance,
  453. _T("Below is the server instance path; it corresponds"
  454. " with the path in the metabase. For testing purposes you"
  455. " can change it to whatever you want, now\n"
  456. "\n"
  457. "Note if it is BLANK we work on \"/LM/W3SVC/1\"" ));
  458. dlgPath.DoModal();
  459. }
  460. #endif
  461. //DebugBreak();
  462. // prepare the machine name pointer
  463. OLECHAR* poch = NULL;
  464. if ( ! m_szMachineName.IsEmpty() )
  465. {
  466. // allocate the name buffer
  467. poch = (OLECHAR*)GlobalAlloc( GPTR, MAX_COMPUTERNAME_LENGTH * 2 );
  468. // unicodize the name into the buffer
  469. if ( poch )
  470. MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, m_szMachineName, -1,
  471. poch, MAX_COMPUTERNAME_LENGTH * 2 );
  472. }
  473. // initialize the metabase wrappings - pass in the name of the target machine
  474. // if one has been specified
  475. IMSAdminBase* pMB = FInitMetabaseWrapper( poch );
  476. if ( !pMB )
  477. {
  478. HRESULT hr = GetLastError(); // the bad hr is in GetLastError()
  479. MessageBeep(0);
  480. if ( poch )
  481. GlobalFree( poch );
  482. const BOOL bDoErrorMsgPopup = TRUE;
  483. if (bDoErrorMsgPopup) {
  484. CString szError;
  485. Easy::Load(szError, IDS_COULD_NOT_ACCESS_THE_METABASE);
  486. // "Could not access the metabase, where we store state information"
  487. AppendMachineName(szError, m_szMachineName );
  488. AppendHResultErrorString(szError, hr);
  489. MsgBox( szError );
  490. }
  491. return FALSE; // <<=== we failed!
  492. }
  493. // clean up
  494. if ( poch )
  495. {
  496. GlobalFree( poch );
  497. poch = NULL;
  498. }
  499. /////////////////////////////////////////////////////////////////////
  500. // prepare the metabase wrapper
  501. /////////////////////////////////////////////////////////////////////
  502. CWrapMetaBase mbWrap;
  503. BOOL f = mbWrap.FInit(pMB);
  504. if ( FALSE == f )
  505. {
  506. return FALSE; // <<=== we failed!
  507. }
  508. /////////////////////////////////////////////////////////////////////
  509. // Things could (potentially maybe) throw here, so better protect the
  510. // metabase
  511. /////////////////////////////////////////////////////////////////////
  512. // //-----------------------------------------------------------------------------
  513. // // here is an example of making a CMetaWrapper call,
  514. // // we will typically use GetData calls and grab the meta data Unicode
  515. // // strings also that way since casting a (CONST WCHAR*) into a CString
  516. // // will give us a FREE conversion from WideChar to MultiByte.
  517. // //-----------------------------------------------------------------------------
  518. // BOOL CAFX_MetaWrapper::GetString( const CHAR* pszPath,
  519. // DWORD dwPropID, DWORD dwUserType,
  520. // CString &sz, DWORD dwFlags )
  521. // {
  522. //
  523. // // first, get the size of the data that we are looking for - it
  524. // // will fail because of the NULL,
  525. // // but, the size we need should be in cbData;
  526. // f = GetData( pszPath, dwPropID, dwUserType, STRING_METADATA, NULL, &cbData );
  527. //
  528. // // check the error - it should be some sort of memory error
  529. //
  530. // }
  531. // //-----------------------------------------------------------------------------
  532. try
  533. {
  534. // I am assuming that the last character is NOT a '/' Thus, if that is what is
  535. // there, we need to remove it. Otherwise, the path gets messed up later
  536. if ( m_szServerInstance.Right(1) == '/' )
  537. m_szServerInstance = m_szServerInstance.Left( m_szServerInstance.GetLength()-1 );
  538. ADMIN_INFO info(mbWrap); // the info object is the central data
  539. // repository. It also has the meta
  540. // base wrapper in it.
  541. info.szMetaBasePath = m_szServerInstance; // need to store the path
  542. // because we need it for generating
  543. // unique Key Container names, will
  544. // be done in file nLocalEnrl.cpp
  545. info.szMachineName_MetaBaseTarget = m_szMachineName;
  546. // NOTE that this routine will either install or DE-install the metabase
  547. // GUID strings based on its decision that CertServer is present.
  548. // If we find GUID strings in the metabase but can not do a
  549. // CoCreateInstance on ICertConfig:
  550. // we remove them so that the rest of CertWizard will see
  551. // MB Guids iff we can use CertServer.
  552. //---------------------------------------------------------------
  553. BOOL bFoundCertServer = MigrateGUIDS( info );
  554. BOOL success = _RunDialogs4OnClick(info,0); // this runs the dialogs
  555. // note that we are passing
  556. // mbWrap not pMB
  557. // save the metabase
  558. mbWrap.Save();
  559. #if 0
  560. // close the base object
  561. // ==> we dont really have to do this -- every time we
  562. // go to the MB we open and close it. If closing it again
  563. // a second time does not hurt we can do it -- tompop ToDo
  564. mbWrap.Close();
  565. #endif
  566. }
  567. catch ( CException e )
  568. {
  569. }
  570. // close the metabase wrappings
  571. FCloseMetabaseWrapper(pMB);
  572. return (TRUE);
  573. }
  574. #if defined(DEBUGGING)
  575. void test_Reg_GetSetName()
  576. {
  577. CString newValue=_T("Tommy Boy");
  578. BOOL bSet =
  579. Reg::HKEYLM::SetNameValue("Software\\Microsoft\\Keyring\\Parameters",
  580. "UserName",
  581. newValue);
  582. ASSERT( bSet==TRUE );
  583. CString readValue;
  584. BOOL bGet =
  585. Reg::HKEYLM::GetNameValue("Software\\Microsoft\\Keyring\\Parameters",
  586. "UserName",
  587. readValue);
  588. ASSERT( bSet==TRUE );
  589. DEBUG_MSGBOX( (buff, "After calling SetNameValue/SetNameValue; val=%s"
  590. "bSet=%d, bGet=%d",
  591. (const char*) readValue, (int)bSet, (int)bGet ));
  592. // the above will test the GetName value and read the
  593. }
  594. #endif
  595. void test__CEasyFileDialog();
  596. void test__itemsWeDependOn(IN OUT ADMIN_INFO& info, USHORT iButton)
  597. {
  598. #if defined(DEBUGGING)
  599. // note that if you need the meta base wrapper directly
  600. // its available as [CWrapMetaBase&] info.mbWrap
  601. #if 0 // ----- use this for testing
  602. BOOL bTest_Reg_GetSetName = FALSE;
  603. if (bTest_Reg_GetSetName)
  604. {
  605. test_Reg_GetSetName();
  606. }
  607. #endif //0 ----- use this for testing
  608. #if 0 // ----- use this for testing
  609. /////////////////// this starts the test of Boydm's MetaBaseWrapper ///
  610. BOOL fAnswer = FALSE;
  611. PVOID pData = NULL;
  612. DWORD cbData = 0;
  613. // attempt to open the object we want to store into
  614. CWrapMetaBase& mbWrap = info.meta.m_mbWrap;
  615. BOOL f = mbWrap.Open( m_szServerInstance, METADATA_PERMISSION_READ );
  616. // if opening the metabase worked, load the data
  617. if ( f )
  618. {
  619. // first, get the size of the data that we are looking for
  620. pData = mbWrap.GetData( "", 1002, IIS_MD_UT_SERVER, STRING_METADATA, &cbData );
  621. // "keytype" is 1002 -- this is just a test
  622. // It uses a BINARY_METADATA is another type
  623. // BINARY_METADATA is another type -- all types are shown
  624. // in the comments below, see file MdDefW.h for details
  625. //
  626. //
  627. // enum METADATATYPES
  628. // { ALL_METADATA = 0,
  629. // DWORD_METADATA = ALL_METADATA + 1,
  630. // STRING_METADATA = DWORD_METADATA + 1,
  631. // BINARY_METADATA = STRING_METADATA + 1,
  632. // EXPANDSZ_METADATA = BINARY_METADATA + 1,
  633. // MULTISZ_METADATA = EXPANDSZ_METADATA + 1,
  634. // INVALID_END_METADATA = MULTISZ_METADATA + 1
  635. // };
  636. // if you want you could use our MBPdata_Wrapper to protect
  637. // it automatically
  638. //
  639. // Util::MBPdata_Wrapper a(mbWrap, pData );
  640. // if we successfully got the data, unserialize it
  641. if ( pData )
  642. {
  643. // === the following stuff + the mbWrap setup code came
  644. // from an example in file 'Issudlg.cpp' see that for
  645. // another example.
  646. //
  647. //PUCHAR pchData = (PUCHAR)pData;
  648. //fAnswer = m_Store.Unserialize( &pchData, &cbData );
  649. }
  650. // close the object
  651. f = mbWrap.Close();
  652. // cleanup
  653. if ( pData )
  654. mbWrap.FreeWrapData( pData );
  655. }
  656. /////////////////// this ends the test of Boydm's MetaBaseWrapper ///
  657. #endif //0 ----- use this for testing
  658. #if 0 // ----- use this for testing
  659. // next we will test our Set/Get Strings on mb prop: MD_SSL_CTL_CONTAINER
  660. { //MD_SSL_CTL_CONTAINER
  661. const TCHAR* szDATA = _T("Tom");
  662. BOOL f1= SetMetaBaseString ( info, MD_SSL_CTL_CONTAINER, szDATA);
  663. CString szReadTom;
  664. BOOL f2= GetMetaBaseString ( info, MD_SSL_CTL_CONTAINER, szReadTom);
  665. BOOL f3= (szReadTom == szDATA);
  666. if ( !( f1 && f2 && f3)) {
  667. DEBUG_MSGBOX( (buff, _T("MD_SSL_CTL_CONTAINER prop get/set failed --"
  668. "you have trouble in the MB; Details: %s %s %s"),
  669. Map::Boolean2String(f1),
  670. Map::Boolean2String(f2),
  671. Map::Boolean2String(f3) ));
  672. }
  673. }
  674. #endif //0 ----- use this for testing
  675. #if 0 // ----- use this for testing
  676. // lets see if IIS is up by looking for the following metabase props:
  677. //
  678. // MD_SECURE_BINDINGS is for SECURE server address/port
  679. // MD_SERVER_BINDINGS is for non secure server address/port
  680. //
  681. {
  682. CString szSecureBindings;
  683. CString szServerBindings;
  684. if ( (TRUE == GetMetaBaseString ( info, MD_SECURE_BINDINGS, szSecureBindings))
  685. && (TRUE == GetMetaBaseString ( info, MD_SERVER_BINDINGS, szServerBindings)))
  686. {
  687. DEBUG_MSGBOX( (buff, _T("Looks like IIS is on the machine since we have"
  688. "SERVER_BINDINGS of [%s] and SECURE_BINDINGS of [%s]"),
  689. szServerBindings, szSecureBindings
  690. //Util::StringOrNil(szServerBindings), Util::StringOrNil(szSecureBindings)
  691. ));
  692. }
  693. }
  694. DODBG if (NoYesMsgBox(_T("Do You Want to CLEAR out the MetaBase History to GROUND ZERO?") ))
  695. {
  696. ClearHistoryState(info);
  697. DisplayInfoStruct(info);
  698. if (NoYesMsgBox(_T("Do You Want to SET ALL the bits in the history that deal"
  699. "with historyStateSSS bits? Then see the info printout?") ))
  700. {
  701. ClearHistoryState(info);
  702. SetCertInstalled(info);
  703. SetOOBCertReq(info);
  704. SetCTLInstalled(info);
  705. SetOutstandingRenewalReq(info);
  706. DisplayInfoStruct(info);
  707. if (NoYesMsgBox(_T("NEXT Do You Want to CLEAR ALL the bits in the history that deal"
  708. "with historyStateSSS bits? Then see the info printout?") ))
  709. {
  710. ClearCertInstalled(info);
  711. ClearOOBCertReq(info);
  712. ClearCTLInstalled(info);
  713. ClearOutstandingRenewalReq(info);
  714. DisplayInfoStruct(info);
  715. }
  716. }
  717. }
  718. BOOL bTest_LoadStrings = FALSE;
  719. if (bTest_LoadStrings) Easy::CString::Test_LoadString();
  720. #endif //0 ----- use this for testing
  721. #if 0 // ----- use this for testing
  722. if (YesNoMsgBox(_T("Do You Want to Run the CTL Wizard") ) )
  723. {
  724. // Run the CTL Wizard
  725. // v--- was setup in the routine that called RunDialogs4OnClick
  726. // info(mbWrap); // main status board in the
  727. // wizards
  728. //run the create CTL wizard. We start by declaring all the pieces of it
  729. CPropertySheet propsheet_mux(IDS_TITLE_CREATE_CTL_WIZ);
  730. CTLWelcome page_welcome;
  731. CTLMuxPg page_multiplexer(info);
  732. CPropertyPage stubTipsPage(IDD_TIPS_BEFORE__CTL_WIZARD);
  733. // clear the help button bits
  734. if ( propsheet_mux.m_psh.dwFlags & PSH_HASHELP )
  735. propsheet_mux.m_psh.dwFlags &= ~PSH_HASHELP;
  736. page_welcome.m_psp.dwFlags &= ~(PSP_HASHELP);
  737. page_multiplexer.m_psp.dwFlags &= ~(PSP_HASHELP);
  738. stubTipsPage.m_psp.dwFlags &= ~(PSP_HASHELP);
  739. // add the pages to the property sheet that says Welcome, and the
  740. // Mux (aka multiplexing) page...
  741. propsheet_mux.AddPage( &page_welcome );
  742. propsheet_mux.AddPage( &page_multiplexer );
  743. propsheet_mux.AddPage( &stubTipsPage );
  744. // set the wizard property
  745. propsheet_mux.SetWizardMode();
  746. // run the property sheet
  747. int i = IDCANCEL;
  748. i = propsheet_mux.DoModal();
  749. if ( i != IDCANCEL )
  750. {
  751. #if defined(DEBUGGING)
  752. DODBG MsgBox( _T("CTL muxer dialog box works and returned OK" ) );
  753. #endif
  754. }
  755. }
  756. // if (bCall_test__CEasyFileDialog) test__CEasyFileDialog();
  757. #endif //0 ----- use this for testing
  758. #endif
  759. }
  760. //------------------------------------------------------------------
  761. // NKAddPageToWizard -- just like WizMngr::AddPageToWizard in that
  762. // it adds CPropertyPage [CNKPages nkpg2Add] to Wizard [psWizard]
  763. // making sure that the [pg2Add] has its help button
  764. // turned OFF!
  765. //
  766. // It also binds the wizard property sheet page [psWizard]
  767. // to member [m_pPropSheet] of the CNKPages object.
  768. //
  769. // This is used to add our pages to the Wizard below
  770. //------------------------------------------------------------------
  771. void CCertAuthCtrl::NKAddPageToWizard(IN ADMIN_INFO& info, IN CNKPages* nkpg2Add, IN OUT CPropertySheet* psWizard)
  772. {
  773. // add the pages to the wizard property sheet AND make no help button
  774. AddPageToWizard(nkpg2Add, psWizard);
  775. nkpg2Add->m_pPropSheet = psWizard;
  776. }
  777. #if defined(DEBUGGING)
  778. void test__Rons_WizClasses(IN ADMIN_INFO& info)
  779. {
  780. CIISWizardSheet propsheet_mux(IDB_BITMAP_STD_LEFT,
  781. IDB_BITMAP_TOP);
  782. CNKWelcome page_welcome(info);
  783. CNKMuxPg page_multiplexer(info);
  784. propsheet_mux.AddPage( &page_welcome );
  785. propsheet_mux.AddPage( &page_multiplexer );
  786. DEBUG_MSGBOX( (buff, _T("Get Ready using real Ron's CIISWizardSheet\n")));
  787. int i = propsheet_mux.GetPageCount();
  788. void* p = propsheet_mux.GetPage(i-1);
  789. DEBUG_MSGBOX( (buff, _T("%s %d -- using real Ron's\n"
  790. " GetPageCount()=%d GetPage(%d)=%#lx"), __FILE__, __LINE__,
  791. i, i-1, (DWORD)p));
  792. }
  793. #endif //defined(DEBUGGING)
  794. #if defined(DEBUGGING)
  795. void test__nonRons_WizClasses(IN ADMIN_INFO& info)
  796. {
  797. CPropertySheet propsheet_mux;
  798. CNKWelcome page_welcome(info);
  799. CNKMuxPg page_multiplexer(info);
  800. propsheet_mux.AddPage( &page_welcome );
  801. propsheet_mux.AddPage( &page_multiplexer );
  802. int i = propsheet_mux.GetPageCount();
  803. void* p = propsheet_mux.GetPage(i-1);
  804. DEBUG_MSGBOX( (buff, _T("%s %d -- using real CPropertySheet\n"
  805. " GetPageCount()=%d GetPage(%d)=%#lx\n"), __FILE__, __LINE__,
  806. i, i-1, (DWORD)p));
  807. }
  808. #endif //defined(DEBUGGING)
  809. #if defined(DEBUGGING)
  810. void test__non2Rons_WizClasses()
  811. {
  812. DEBUG_MSGBOX( (buff, _T("Sizeof CPropertySheet=%d,CPropertyPage=%d\n"),
  813. sizeof(CPropertySheet),sizeof(CPropertyPage)));
  814. CPropertySheet propsheet_mux;
  815. CPropertyPage page_welcome;
  816. CPropertyPage page_multiplexer;
  817. propsheet_mux.AddPage( &page_welcome );
  818. propsheet_mux.AddPage( &page_multiplexer );
  819. int i = propsheet_mux.GetPageCount();
  820. DEBUG_MSGBOX( (buff, _T("Get Ready using real CPropertySheet,CPropertyPage\n")));
  821. void* p = propsheet_mux.GetPage(i-1);
  822. DEBUG_MSGBOX( (buff, _T("%s %d -- using real CPropertySheet,CPropertyPage\n"
  823. " GetPageCount()=%d GetPage(%d)=%#lx\n"), __FILE__, __LINE__,
  824. i, i-1, (DWORD)p));
  825. }
  826. #endif //defined(DEBUGGING)
  827. ////////////////////////////////////////////////////////////////////////
  828. // _RunDialogs4OnClick -- main handler for our dialogs
  829. //
  830. // Parms: mbWrap: ref to a MetaBase Wrapper that is properly initialized
  831. // and points to the SERVER node that we are operating in.
  832. // iButton: tells what "logical button" fired our control:
  833. // 0=Get-Cert 1=Edit
  834. ////////////////////////////////////////////////////////////////////////
  835. BOOL CCertAuthCtrl::_RunDialogs4OnClick(IN OUT ADMIN_INFO& info, USHORT iButton)
  836. {
  837. #if defined(DEBUGGING) && defined(SHOW_TRACE_INFO)
  838. Trace t( _T("CCertAuthCtrl::_RunDialogs4OnClick"));
  839. #endif
  840. #if defined(DEBUGGING)
  841. checkSanityMFC();
  842. #endif
  843. // EnumCertServerObjects is now our std locate-all-cert-servers available method
  844. // it enumerates CertServers the metabase for CertServers
  845. // that are configured correctly and stores a mapping to GUID
  846. // strings in our 'info.map_CertServerNameToGUIDmap' structure
  847. EnumCertServerObjects(info);
  848. // The following will call is used to debug what we depend upon
  849. test__itemsWeDependOn(info, iButton);
  850. #if defined(DEBUGGING)
  851. if (DebugTestEnv(_T("MFC")) && YesNoMsgBox(_T("Shall we run: test__Rons_WizClasses"))) {
  852. test__Rons_WizClasses(info);
  853. }
  854. #endif
  855. // ToDo: we need to change this to buttons
  856. // in a particular call
  857. // we should do something like: if (iButton==1)
  858. // for testing you can do YesNoMsgBox(_T("Do You Want to Run the CertWizard"))
  859. {
  860. #if defined(DEBUGGING) && defined(SHOW_TRACE_INFO)
  861. Trace t( _T("In AuthCtl.cpp -- stack frame launching the propsheet_mux wiz."));
  862. #endif
  863. // v--- was setup in the routine that called RunDialogs4OnClick
  864. //ADMIN_INFO info(mbWrap); // main status board in the
  865. // // wizards
  866. //run the create key wizard. We start by declaring all the pieces of it
  867. #ifdef USE_COMPROP_WIZ97
  868. CIISWizardSheet propsheet_mux(IDB_BITMAP_STD_LEFT,
  869. IDB_BITMAP_TOP);
  870. // CString szIDS_TITLE_CREATE_WIZ;
  871. // Easy::Load(szIDS_TITLE_CREATE_WIZ, IDS_TITLE_CREATE_WIZ);
  872. // propsheet_mux.SetTitle(szIDS_TITLE_CREATE_WIZ);
  873. #else
  874. CPropertySheet propsheet_mux( IDS_TITLE_CREATE_WIZ );
  875. #endif
  876. CNKWelcome page_welcome(info);
  877. CNKMuxPg page_multiplexer(info);
  878. // Living within info is 'wizMngr' -- this manages the Wizard. See
  879. // file WizMngr.cpp for more info. We need to instruct it what the
  880. // property sheet is and also where the error page lives. At this
  881. // time the only valid pages are the Welcome + Completion + Error
  882. WizMngr& wizMngr = info.wizMngr;
  883. wizMngr.Attach( &propsheet_mux );
  884. wizMngr.SetErrorPageIndex( WZ_PAGE__GENERIC_ERROR_PAGE );
  885. wizMngr.SetDonePageIndex( WZ_PAGE__GENERIC_COMPLETION_PAGE );
  886. // then later info.wizMngr.ShowDonePage(); will display this completion pg.
  887. wizMngr.Enable(0,0); // enable welcome page
  888. wizMngr.Enable(WZ_PAGE__GENERIC_COMPLETION_PAGE, // Enable our generic
  889. WZ_PAGE__GENERIC_ERROR_PAGE); // Completion-Error page
  890. // the following define the new Server pages
  891. CNKChooseCA page_Choose_CA(info);
  892. CNKKeyInfo page_Key_Info(info);
  893. CNKDistinguishedName page_DN(info);
  894. CNKDistinguishedName1 page_DN1(info);
  895. CNKDistinguisedName2 page_DN2(info);
  896. CNKUserInfo page_User_Info(info);
  897. CNKFileInfo page_File_Info(info);
  898. // lets warn the user that crytpo is not enabled, GetMaxKeySize will
  899. // return 0 if no ENCRYPTION is ALLOWED
  900. //----------------------------------------------
  901. KeySize keySize; // fncts GetMaxKeySize and ComputeKeyAlgMinMaxStep return
  902. // this as an OUT parameter.
  903. if (0 == page_Key_Info.GetMaxKeySize(OUT keySize) ) {
  904. MsgBox( IDS_ENCRYPTION_NOT_ALLOWED_BASED_ON_THE_MACHINE_CONFIG_DATA );
  905. //"Encryption is not allowed based on the machine configuration data."END
  906. return FALSE;
  907. }
  908. /////////////////////////////////////////////////////////////////////////////
  909. // the following 2 Classes contain PropertyPages for the Finish the offline/OOB
  910. // cert request
  911. //
  912. // class CFinCertImport is the 1st & only Property Sheet for "Finish OOB"
  913. // (gathers data). it also verifies and asks the user:
  914. // are you "ready to "FINISH" and do the conversion
  915. /////////////////////////////////////////////////////////////////////////////
  916. CFinCertImport getFileInfoPage(info);
  917. // End the above list of "all possible wizard pages" with the
  918. // completion page then the Error page. Error always has to be last!
  919. // Note also that this completion page is the "default" completion
  920. // page. Some sub-wizard might have a more appropriate specialized
  921. // page for completion
  922. CCompletionPage page_GenericCompletion(info);
  923. CWizError page_GenericErrorPage(info);
  924. info.wizErrorDlg = &page_GenericErrorPage;
  925. // clear the help button bits on the PropertySheet and all Prop
  926. // pages. We handle the clearing for each page in the funct AddPageToWizard
  927. if ( propsheet_mux.m_psh.dwFlags & PSH_HASHELP )
  928. propsheet_mux.m_psh.dwFlags &= ~PSH_HASHELP;
  929. // add the pages to the property sheet that says Welcome, and the
  930. // Mux (aka multiplexing) page... The AddPageToWizard will do an
  931. // AddPage on the property sheet and also specify that we dont want
  932. // any help buttons
  933. NKAddPageToWizard(info, &page_welcome, &propsheet_mux ); //index:0:WZ_PAGE__WELCOME
  934. //this is for the New Cert Wizard
  935. NKAddPageToWizard(info, &page_multiplexer, &propsheet_mux ); //index:1:WZ_PAGE__CERTMUX
  936. NKAddPageToWizard(info, &page_Choose_CA, &propsheet_mux );
  937. NKAddPageToWizard(info, &page_Key_Info, &propsheet_mux );
  938. NKAddPageToWizard(info, &page_DN, &propsheet_mux );
  939. NKAddPageToWizard(info, &page_DN1, &propsheet_mux );
  940. NKAddPageToWizard(info, &page_DN2, &propsheet_mux );
  941. NKAddPageToWizard(info, &page_User_Info, &propsheet_mux );
  942. NKAddPageToWizard(info, &page_File_Info, &propsheet_mux ); //index:8:WZ_PAGE__SUCCESS_PAGE
  943. //this is for finishing the SELECT_EXISTING_CERT page -- request
  944. CCertSelect page_CertSelect(info);
  945. NKAddPageToWizard(info, &page_CertSelect, &propsheet_mux ); //index:9:WZ_PAGE__SELECT_EXISTING_CERT_PAGE
  946. //this is for finishing the IMPORT_KEYRING page -- request
  947. CKeyImpt gatherData(info);
  948. NKAddPageToWizard(info, &gatherData, &propsheet_mux ); //index:10:WZ_PAGE__IMPORT_KEYRING_CERT_PAGE
  949. //this is for finishing the OOB request
  950. CNKMuxPg2 page_OOBmultiplexer(info);
  951. CNKMuxPg FAKE8page_multiplexer(info);
  952. NKAddPageToWizard(info, &page_OOBmultiplexer, &propsheet_mux );//index:11:WZ_PAGE__OOB_CERTMUX
  953. NKAddPageToWizard(info, &getFileInfoPage, &propsheet_mux ); //index:12:WZ_PAGE__OOB_FINCERT_GETFILENM
  954. NKAddPageToWizard(info, &FAKE8page_multiplexer, &propsheet_mux ); //index:13:WZ_PAGE__OOB_FINCERT_DISREGARD_OOB_REQ
  955. // tompop: we dont need the FAKE8page_multiplexer and need to
  956. // shift everything down
  957. //this is for finishing the MODIFYEXISTING request
  958. CNKMuxPg3 page_modifyExisting_multiplexer(info);
  959. //--- this is part of the 3rd mux page for "ModifyExisting|Renew"
  960. CNKChooseCA renewPage_Choose_CA(info);//reuse a pg from ncw
  961. CNKUserInfo renewPage_User_Info(info);//reuse a pg from ncw
  962. // note that the above page plays double duty as it senses
  963. // that its used to renew a cert and displays a finish
  964. // page behavior.
  965. CNKFileInfo renewPage_File_Info(info);// page:WZ_PAGE__MODIFYEXISTING_CERTRENEW_OOB_INSTRUCTIONS
  966. //--- this is part of 3rd mux page for "ModifyExisting|delete-cert"
  967. CDeleteCert page_deleteCert(info);
  968. //--- the last part of 3rd mux page, enables the new Cert Wizard!
  969. // it does not have any pages
  970. NKAddPageToWizard(info, &page_modifyExisting_multiplexer, &propsheet_mux ); //index:13:WZ_PAGE__MODIFYEXISTING_CERTMUX
  971. NKAddPageToWizard(info, &renewPage_Choose_CA, &propsheet_mux ); //index:14:WZ_PAGE__MODIFYEXISTING_CERTRENEW_CA
  972. NKAddPageToWizard(info, &renewPage_User_Info, &propsheet_mux ); //index:15:WZ_PAGE__MODIFYEXISTING_CERTRENEW_Contact
  973. NKAddPageToWizard(info, &renewPage_File_Info, &propsheet_mux ); //index:15:WZ_PAGE__MODIFYEXISTING_CERTRENEW_Contact
  974. NKAddPageToWizard(info, &page_deleteCert, &propsheet_mux ); //index:16:WZ_PAGE__MODIFYEXISTING_CERTDELETE
  975. NKAddPageToWizard(info, &page_GenericCompletion, &propsheet_mux );//index:17:WZ_PAGE__GENERIC_COMPLETION_PAGE
  976. NKAddPageToWizard(info, &page_GenericErrorPage , &propsheet_mux );//index:18:WZ_PAGE__GENERIC_ERROR_PAGE
  977. // set the wizard property
  978. propsheet_mux.SetWizardMode();
  979. //before we start running the Wizard we need to enable exactly
  980. //one of the possible SubWizards
  981. pick_Correct_SubWizard(info);
  982. // run the property sheet
  983. #define HR_FAIL_SOME_EXCEPTION_HAPPENED 0x666 // very unlikely value
  984. int i = HR_FAIL_SOME_EXCEPTION_HAPPENED;
  985. if ( DebugTestEnv(DebugTestEnv_noTRY) ) {
  986. #if defined(DEBUGGING) && defined(SHOW_TRACE_INFO)
  987. Trace t( _T("propsheet_mux.DoModal() -- running the wizard"));
  988. #endif
  989. i = propsheet_mux.DoModal();
  990. } else {
  991. try {
  992. #if defined(DEBUGGING) && defined(SHOW_TRACE_INFO)
  993. Trace t( _T("propsheet_mux.DoModal() -- running the wizard"));
  994. #endif
  995. i = propsheet_mux.DoModal();
  996. }
  997. catch (...) {
  998. if (i==HR_FAIL_SOME_EXCEPTION_HAPPENED) i=IDCANCEL;
  999. //----------------------------------------------------
  1000. DoDebugBreak(); // see if we should do a debug break
  1001. MsgBox( IDS_CAUGHT_AN_UNKNOWN_EXCEPTION );
  1002. }
  1003. }
  1004. if ( i == IDCANCEL )
  1005. {
  1006. #if defined(DEBUGGING)
  1007. DODBG MsgBox( _T("Cert muxer dialog box works and returned IDCANCEL" ) );
  1008. #endif
  1009. } else if ( i != IDOK )
  1010. {
  1011. #if defined(DEBUGGING)
  1012. DODBG MsgBox( _T("Cert muxer dialog box works and returned OK" ) );
  1013. #endif
  1014. } else
  1015. {
  1016. #if defined(DEBUGGING)
  1017. TCHAR szTmp[200];
  1018. wsprintf(szTmp, _T("Cert muxer dialog box returned strange return value"
  1019. " of %d=%#x"), i, i );
  1020. DODBG MsgBox( szTmp );
  1021. #endif
  1022. }
  1023. //MsgBox( "DBG: done w/ Cert Wiz block");
  1024. // // if we want to do a completion page now... [HOWEVER THIS DOES NOT PRODUCE A GOOD LOOKING COMPL.PG]
  1025. // int dialogID = IDD_COMPLETION_PAGE;
  1026. //
  1027. // {
  1028. // CDialog dlg( dialogID );
  1029. // dlg.DoModal();
  1030. // }
  1031. }
  1032. return TRUE;
  1033. }
  1034. // test the CryptUIWizBuildCTL functions...
  1035. //From CryptUI.h// //-----------------------------------------------------------------------
  1036. //From CryptUI.h// //
  1037. //From CryptUI.h// // CryptUIWizBuildCTL
  1038. //From CryptUI.h// //
  1039. //From CryptUI.h// // Build a new CTL or modify an existing CTL. The UI for wizard will
  1040. //From CryptUI.h// // always show in this case
  1041. //From CryptUI.h// //
  1042. //From CryptUI.h// //
  1043. //From CryptUI.h// // dwFlags: IN Optional: Can be set to the following:
  1044. //From CryptUI.h// // CRYPTUI_WIZ_BUILDCTL_SKIP_DESTINATION. This flag
  1045. //From CryptUI.h// // is valid only when pBuildCTLDest is set
  1046. //From CryptUI.h// // hwndParnet: IN Optional: The parent window handle
  1047. //From CryptUI.h// // pwszWizardTitle: IN Optional: The title of the wizard
  1048. //From CryptUI.h// // If NULL, the default will be IDS_BUILDCTL_WIZARD_TITLE
  1049. //From CryptUI.h// // pBuildCTLSrc: IN Optional: The source from which the CTL will be built
  1050. //From CryptUI.h// // pBuildCTLDest: IN Optional: The desination where the newly
  1051. //From CryptUI.h// // built CTL will be stored
  1052. //From CryptUI.h// // ppCTLContext: OUT Optaionl: The newly build CTL
  1053. //From CryptUI.h// //
  1054. //From CryptUI.h// //------------------------------------------------------------------------
  1055. //From CryptUI.h// BOOL
  1056. //From CryptUI.h// WINAPI
  1057. //From CryptUI.h// CryptUIWizBuildCTL(
  1058. //From CryptUI.h// IN DWORD dwFlags,
  1059. //From CryptUI.h// IN OPTIONAL HWND hwndParent,
  1060. //From CryptUI.h// IN OPTIONAL LPCWSTR pwszWizardTitle,
  1061. //From CryptUI.h// IN OPTIONAL PCCRYPTUI_WIZ_BUILDCTL_SRC_INFO pBuildCTLSrc,
  1062. //From CryptUI.h// IN OPTIONAL PCCRYPTUI_WIZ_BUILDCTL_DEST_INFO pBuildCTLDest,
  1063. //From CryptUI.h// OUT OPTIONAL PCCTL_CONTEXT *ppCTLContext
  1064. //From CryptUI.h// );
  1065. //From CryptUI.h//
  1066. //From CryptUI.h// Bugs:
  1067. //From CryptUI.h//
  1068. //From CryptUI.h// After calling LocalEnroll we get a HRESULT return value of
  1069. //From CryptUI.h// 0x80004005
  1070. //From CryptUI.h//
  1071. // when we finish the enrollment we should see that the Cert gets installed into:
  1072. //
  1073. // HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\SystemCertificates\Trust\CTLs
  1074. class CCertAuthCtrl;
  1075. #if defined(DEBUGGING)
  1076. void test__CEasyFileDialog()
  1077. {
  1078. CString msg(_T("This will test a Reading EASY CFileDialog"));
  1079. AfxMessageBox( msg );
  1080. CEasyFileDialog readDlg(CEasyFileDialog::Reading,
  1081. CEasyFileDialog::FileOpen,
  1082. IDS_KEY_OR_CERT_FILE_FILTER);
  1083. // The IDS_KEY_OR_CERT_FILE_FILTER string is defined as:
  1084. // "Certificate Import or backup file!*.cbk!KeyRing backup!*.krb!Any Certificate File Type!*.*!!"
  1085. // and provides a way to locate a keyRing/Cert file to import.
  1086. // Users could be ad-hock in how they named the files...
  1087. readDlg.SetTitle(_T("This is a test of the CEasyFileDialog:Reading"));
  1088. if (readDlg.DoModal() == IDOK) AfxMessageBox( readDlg.GetPathName() );
  1089. CEasyFileDialog writeDlg(CEasyFileDialog::Writing,
  1090. CEasyFileDialog::FileSaveAs,
  1091. _T("My C Files(*.cpp)!*.cpp!My H Files(*.h)!*.h!!"));
  1092. // ::MessageBox(NULL, "Body-- after we constructed the writeDlg: via msgBox", "title", MB_OK );
  1093. AfxMessageBox( _T("In this test we are calling 'writeDlg.DoModal()' and"
  1094. "have coded it so that it will grab the extension of the first"
  1095. "extension in the list of file specs, i.e. *.cpp so that if you"
  1096. "dont enter an extension it will use .cpp and append this for you"
  1097. "give it a try tjp tompop bug: for some reason the dialog is"
  1098. "not showing the \"Default Extension\" part of the FileDialog box"
  1099. "\n"
  1100. "Note also that the default ext is pretty brain dead in that if"
  1101. "the default extension is *.cpp and you enter a FileName of story.book"
  1102. "the Dialog will return a file name of \"story.book.cpp\"!!!"
  1103. "\n\n"
  1104. "Try picking a .cpp or swich the type and grab a *.h as we use"
  1105. "the following spec for the file types"
  1106. "\n"
  1107. "\t\"My C Files(*.cpp)!*.cpp!My H Files(*.h)!*.h!\""
  1108. "\n"
  1109. "Try entering: foo.h foo.cpp and foo.bak"
  1110. "\n"
  1111. "Try entering: foo.h foo.cpp and foo.bak"
  1112. "\n\n"
  1113. "Then try just foo once with the \"My H Files\" and"
  1114. "once w/ your C files and ALL SHOULD WORK."));
  1115. if (writeDlg.DoModal() == IDOK) AfxMessageBox( writeDlg.GetPathName() );
  1116. }
  1117. #endif //defined(DEBUGGING)
  1118. */
  1119. //---------------------------------------------------------------------------
  1120. void CCertAuthCtrl::SetServerInstance(LPCTSTR szServerInstance)
  1121. {
  1122. m_szServerInstance = szServerInstance;
  1123. //MsgBox( m_szServerInstance, _T("m_szServerInstance") );
  1124. }
  1125. //---------------------------------------------------------------------------
  1126. void CCertAuthCtrl::SetMachineName(LPCTSTR szMachine)
  1127. {
  1128. m_szMachineName = szMachine;
  1129. //MsgBox( m_szMachineName, _T("m_szMachineName") );
  1130. }
  1131. //---------------------------------------------------------------------------
  1132. void CCertAuthCtrl::OnFontChanged()
  1133. {
  1134. m_fUpdateFont = TRUE;
  1135. COleControl::OnFontChanged();
  1136. }
  1137. //---------------------------------------------------------------------------
  1138. void CCertAuthCtrl::OnAmbientPropertyChange(DISPID dispid)
  1139. {
  1140. BOOL flag;
  1141. UINT style;
  1142. // do the right thing depending on the dispid
  1143. switch ( dispid )
  1144. {
  1145. case DISPID_AMBIENT_DISPLAYASDEFAULT:
  1146. if ( GetAmbientProperty( DISPID_AMBIENT_DISPLAYASDEFAULT, VT_BOOL, &flag ) )
  1147. {
  1148. style = GetWindowLong(
  1149. GetSafeHwnd(), // handle of window
  1150. GWL_STYLE // offset of value to retrieve
  1151. );
  1152. if ( flag )
  1153. style |= BS_DEFPUSHBUTTON;
  1154. else
  1155. style ^= BS_DEFPUSHBUTTON;
  1156. SetWindowLong(
  1157. GetSafeHwnd(), // handle of window
  1158. GWL_STYLE, // offset of value to retrieve
  1159. style
  1160. );
  1161. Invalidate(TRUE);
  1162. }
  1163. break;
  1164. };
  1165. COleControl::OnAmbientPropertyChange(dispid);
  1166. }
  1167. //---------------------------------------------------------------------------
  1168. // an important method where we tell the container how to deal with us.
  1169. // pControlInfo is passed in by the container, although we are responsible
  1170. // for maintining the hAccel structure
  1171. void CCertAuthCtrl::OnGetControlInfo(LPCONTROLINFO pControlInfo)
  1172. {
  1173. // do a rudimentary check to see if we understand pControlInfo
  1174. if ( !pControlInfo || pControlInfo->cb < sizeof(CONTROLINFO) )
  1175. return;
  1176. // set the accelerator handle into place
  1177. pControlInfo->hAccel = m_hAccel;
  1178. pControlInfo->cAccel = m_cAccel;
  1179. // when we have focus, we do want the enter key
  1180. pControlInfo->dwFlags = CTRLINFO_EATS_RETURN;
  1181. }
  1182. //---------------------------------------------------------------------------
  1183. // the ole control container object specifically filters out the space
  1184. // key so we do not get it as a OnMnemonic call. Thus we need to look
  1185. // for it ourselves
  1186. void CCertAuthCtrl::OnKeyUpEvent(USHORT nChar, USHORT nShiftState)
  1187. {
  1188. if ( nChar == _T(' ') )
  1189. {
  1190. OnClick((USHORT)GetDlgCtrlID());
  1191. }
  1192. COleControl::OnKeyUpEvent(nChar, nShiftState);
  1193. }
  1194. //---------------------------------------------------------------------------
  1195. void CCertAuthCtrl::OnMnemonic(LPMSG pMsg)
  1196. {
  1197. OnClick((USHORT)GetDlgCtrlID());
  1198. COleControl::OnMnemonic(pMsg);
  1199. }
  1200. //---------------------------------------------------------------------------
  1201. void CCertAuthCtrl::OnTextChanged()
  1202. {
  1203. DWORD i;
  1204. ACCEL accel;
  1205. BOOL f;
  1206. BOOL flag;
  1207. int iAccel;
  1208. // get the new text
  1209. CString sz = InternalGetText();
  1210. sz.MakeLower();
  1211. // if the handle has already been allocated, free it
  1212. if ( m_hAccel )
  1213. {
  1214. DestroyAcceleratorTable( m_hAccel );
  1215. m_hAccel = NULL;
  1216. m_cAccel = 0;
  1217. }
  1218. // if there is a & character, then declare the accelerator
  1219. iAccel = sz.Find(_T('&'));
  1220. if ( iAccel >= 0 )
  1221. {
  1222. // fill in the accererator record
  1223. accel.fVirt = FALT;
  1224. accel.key = sz.GetAt(iAccel + 1);
  1225. accel.cmd = (WORD)GetDlgCtrlID();
  1226. m_hAccel = CreateAcceleratorTable( &accel, 1 );
  1227. if ( m_hAccel )
  1228. m_cAccel = 1;
  1229. }
  1230. // finish with the default handling.
  1231. COleControl::OnTextChanged();
  1232. }
  1233. //////////////////////////////////////////////////////////////////////////////
  1234. // FYI ONLY //
  1235. // This RunAuthoritiesDialog() is Boydm's old starting point for the //
  1236. // original AuthoritiesDialog. //
  1237. // //
  1238. //////////////////////////////////////////////////////////////////////////////
  1239. //
  1240. // //---------------------------------------------------------------------------
  1241. // // run the dialog
  1242. // void CCertAuthCtrl::RunAuthoritiesDialog()
  1243. // {
  1244. // //DebugBreak();
  1245. // // prepare the machine name pointer
  1246. // OLECHAR* poch = NULL;
  1247. // if ( !m_szMachineName.IsEmpty() )
  1248. // {
  1249. // // allocate the name buffer
  1250. // poch = (OLECHAR*)GlobalAlloc( GPTR, MAX_COMPUTERNAME_LENGTH * 2 );
  1251. //
  1252. // // unicodize the name into the buffer
  1253. // if ( poch )
  1254. // MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, m_szMachineName, -1,
  1255. // poch, MAX_COMPUTERNAME_LENGTH * 2 );
  1256. // }
  1257. //
  1258. // // initialize the metabase wrappings - pass in the name of the target machine
  1259. // // if one has been specified
  1260. // IMSAdminBase* pMB = FInitMetabaseWrapper( poch );
  1261. // if ( !pMB )
  1262. // {
  1263. // MessageBeep(0);
  1264. // if ( poch ) GlobalFree( poch );
  1265. // return;
  1266. // }
  1267. //
  1268. // // clean up
  1269. // if ( poch )
  1270. // {
  1271. // GlobalFree( poch );
  1272. // poch = NULL;
  1273. // }
  1274. //
  1275. // // if there is nothing in the MB_Path, default to the first instance
  1276. // if ( m_szServerInstance.IsEmpty() )
  1277. // m_szServerInstance = "/LM/W3SVC/1";
  1278. //
  1279. // // I am assuming that the last character is NOT a '/' Thus, if that is what is
  1280. // // there, we need to remove it. Otherwise, the path gets messed up later
  1281. // if ( m_szServerInstance.Right(1) == '/' )
  1282. // m_szServerInstance = m_szServerInstance.Left( m_szServerInstance.GetLength()-1 );
  1283. //
  1284. // // set up the dialog
  1285. // CSelectIssuersDlg dlg(pMB);
  1286. // dlg.m_pRule = NULL;
  1287. // dlg.m_szMBPath = m_szServerInstance + SZ_NAMESPACE_EXTENTION;
  1288. //
  1289. // // Use our Fancy Debugging "Load String" found in Easy::CString
  1290. // Easy::CString::LoadStringInto(dlg.m_sz_caption, IDS_TRUSTED_AUTHORITIES );
  1291. //
  1292. // // run the propdsheet dialog
  1293. // // let the host container know that we are putting up a modal dialog
  1294. // PreModalDialog();
  1295. // // run the dialog
  1296. // dlg.DoModal();
  1297. // // let the host container know we are done with the modality
  1298. // PostModalDialog();
  1299. //
  1300. // // close the metabase wrappings
  1301. // FCloseMetabaseWrapper(pMB);
  1302. // }
  1303. //
  1304. //---------------------------------------------------------------------------
  1305. //-------------------------------------------------------------------------------
  1306. // DoClick - process a click event. This will be called by the IIS admin
  1307. // API to launch us! [people get here by clicking on our control]
  1308. //
  1309. // PARAMS: dwButtonNumber an IN param. tells what "logical button" fired our control:
  1310. //
  1311. // value
  1312. // ------
  1313. // 1 Call CertWiz
  1314. // 2 Call CTL Wiz
  1315. //-------------------------------------------------------------------------------
  1316. void CCertAuthCtrl::DoClick(IN long dwButtonNumber)
  1317. {
  1318. // TODO: Add your dispatch handler code here
  1319. OnClick( (short) dwButtonNumber );
  1320. }