Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

791 lines
24 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: testprov.cpp
  8. //
  9. // Contents: Microsoft Internet Security Trust Provider
  10. //
  11. // Functions: DllRegisterServer
  12. // DllUnregisterServer
  13. // TestprovInitialize
  14. // TestprovObjectProv
  15. // TestprovSigProv
  16. // TestprovCertCheckProv
  17. // TestprovFinalProv
  18. // TestprovCleanup
  19. // TestprovTester
  20. //
  21. // History: 28-Jul-1997 pberkman created
  22. //
  23. //--------------------------------------------------------------------------
  24. #include <windows.h>
  25. #include <ole2.h>
  26. #include <wincrypt.h>
  27. #include <wintrust.h> // structures and APIs
  28. #include "wintrustp.h" // structures and APIs
  29. #include <softpub.h> // reference for Authenticode
  30. #include <acui.h> // ui module DACUI.DLL
  31. #include "testprov.h" // my stuff
  32. HRESULT CallUI(CRYPT_PROVIDER_DATA *pProvData, DWORD dwError);
  33. DWORD GetErrorBasedOnStepErrors(CRYPT_PROVIDER_DATA *pProvData);
  34. HRESULT CheckCertificateChain(CRYPT_PROVIDER_DATA *pProvData, CRYPT_PROVIDER_SGNR *pProvSgnr);
  35. HRESULT CheckRevocation(CRYPT_PROVIDER_DATA *pProvData, CRYPT_PROVIDER_SGNR *pSgnr);
  36. BOOL CheckCertAnyUnknownCriticalExtensions(CRYPT_PROVIDER_DATA *pProvData, PCERT_INFO pCertInfo);
  37. //////////////////////////////////////////////////////////////////////////////
  38. //
  39. // DllRegisterServer
  40. //----------------------------------------------------------------------------
  41. // Register "my" provider
  42. //
  43. STDAPI DllRegisterServer(void)
  44. {
  45. GUID gTestprov = TESTPROV_ACTION_TEST;
  46. CRYPT_REGISTER_ACTIONID sRegAID;
  47. memset(&sRegAID, 0x00, sizeof(CRYPT_REGISTER_ACTIONID));
  48. sRegAID.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
  49. sRegAID.sInitProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  50. sRegAID.sInitProvider.pwszDLLName = TP_DLL_NAME;
  51. sRegAID.sInitProvider.pwszFunctionName = TP_INIT_FUNCTION;
  52. sRegAID.sObjectProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  53. sRegAID.sObjectProvider.pwszDLLName = TP_DLL_NAME;
  54. sRegAID.sObjectProvider.pwszFunctionName = TP_OBJTRUST_FUNCTION;
  55. sRegAID.sSignatureProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  56. sRegAID.sSignatureProvider.pwszDLLName = TP_DLL_NAME;
  57. sRegAID.sSignatureProvider.pwszFunctionName = TP_SIGTRUST_FUNCTION;
  58. sRegAID.sCertificateProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  59. sRegAID.sCertificateProvider.pwszDLLName = WT_PROVIDER_DLL_NAME; // set to wintrust.dll
  60. sRegAID.sCertificateProvider.pwszFunctionName = WT_PROVIDER_CERTTRUST_FUNCTION; // use wintrust's standard!
  61. sRegAID.sCertificatePolicyProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  62. sRegAID.sCertificatePolicyProvider.pwszDLLName = TP_DLL_NAME;
  63. sRegAID.sCertificatePolicyProvider.pwszFunctionName = TP_CHKCERT_FUNCTION;
  64. sRegAID.sFinalPolicyProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  65. sRegAID.sFinalPolicyProvider.pwszDLLName = TP_DLL_NAME;
  66. sRegAID.sFinalPolicyProvider.pwszFunctionName = TP_FINALPOLICY_FUNCTION;
  67. sRegAID.sCleanupProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  68. sRegAID.sCleanupProvider.pwszDLLName = TP_DLL_NAME;
  69. sRegAID.sCleanupProvider.pwszFunctionName = TP_CLEANUPPOLICY_FUNCTION;
  70. sRegAID.sTestPolicyProvider.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY);
  71. sRegAID.sTestPolicyProvider.pwszDLLName = TP_DLL_NAME;
  72. sRegAID.sTestPolicyProvider.pwszFunctionName = TP_TESTDUMPPOLICY_FUNCTION_TEST;
  73. if (WintrustAddActionID(&gTestprov, 0, &sRegAID))
  74. {
  75. return(S_OK);
  76. }
  77. return(S_FALSE);
  78. }
  79. //////////////////////////////////////////////////////////////////////////////
  80. //
  81. // DllUnregisterServer
  82. //----------------------------------------------------------------------------
  83. // unregisters "my" provider
  84. //
  85. STDAPI DllUnregisterServer(void)
  86. {
  87. GUID gTestprov = TESTPROV_ACTION_TEST;
  88. WintrustRemoveActionID(&gTestprov);
  89. return(S_OK);
  90. }
  91. //////////////////////////////////////////////////////////////////////////////
  92. //
  93. // Initialization Provider function: testprovInitialize
  94. //----------------------------------------------------------------------------
  95. // allocates and sets up "my" data.
  96. //
  97. HRESULT WINAPI TestprovInitialize(CRYPT_PROVIDER_DATA *pProvData)
  98. {
  99. if (!(pProvData->padwTrustStepErrors) ||
  100. (pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_WVTINIT] != ERROR_SUCCESS))
  101. {
  102. return(S_FALSE);
  103. }
  104. //
  105. // add our private data to the array...
  106. //
  107. CRYPT_PROVIDER_PRIVDATA sMyData;
  108. TESTPROV_PRIVATE_DATA *pMyData;
  109. GUID gMyId = TESTPROV_ACTION_TEST;
  110. memset(&sMyData, 0x00, sizeof(CRYPT_PROVIDER_PRIVDATA));
  111. sMyData.cbStruct = sizeof(CRYPT_PROVIDER_PRIVDATA);
  112. memcpy(&sMyData.gProviderID, &gMyId, sizeof(GUID));
  113. if (!(sMyData.pvProvData = pProvData->psPfns->pfnAlloc(sizeof(TESTPROV_PRIVATE_DATA))))
  114. {
  115. pProvData->dwError = GetLastError();
  116. pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_INITPROV] = TRUST_E_SYSTEM_ERROR;
  117. return(S_FALSE);
  118. }
  119. memset(sMyData.pvProvData, 0x00, sizeof(TESTPROV_PRIVATE_DATA));
  120. pMyData = (TESTPROV_PRIVATE_DATA *)sMyData.pvProvData;
  121. pMyData->cbStruct = sizeof(TESTPROV_PRIVATE_DATA);
  122. //
  123. // fill in the Authenticode Functions
  124. //
  125. GUID gSP = WINTRUST_ACTION_TRUSTPROVIDER_TEST;
  126. pMyData->sAuthenticodePfns.cbStruct = sizeof(CRYPT_PROVIDER_FUNCTIONS_ORMORE);
  127. if (!(WintrustLoadFunctionPointers(&gSP, (CRYPT_PROVIDER_FUNCTIONS *)&pMyData->sAuthenticodePfns)))
  128. {
  129. pProvData->psPfns->pfnFree(sMyData.pvProvData);
  130. pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_INITPROV] = TRUST_E_PROVIDER_UNKNOWN;
  131. return(S_FALSE);
  132. }
  133. //
  134. // add my data to the chain!
  135. //
  136. pProvData->psPfns->pfnAddPrivData2Chain(pProvData, &sMyData);
  137. return(pMyData->sAuthenticodePfns.pfnInitialize(pProvData));
  138. }
  139. //////////////////////////////////////////////////////////////////////////////
  140. //
  141. // Object Provider function: TestprovObjectProv
  142. //----------------------------------------------------------------------------
  143. // we don't do anything here -- we're not authenticating a signed object.
  144. //
  145. HRESULT WINAPI TestprovObjectProv(CRYPT_PROVIDER_DATA *pProvData)
  146. {
  147. if (!(pProvData->padwTrustStepErrors) ||
  148. (pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_WVTINIT] != ERROR_SUCCESS) ||
  149. (pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_INITPROV] != ERROR_SUCCESS))
  150. {
  151. return(S_FALSE);
  152. }
  153. CRYPT_PROVIDER_PRIVDATA *pPrivData;
  154. TESTPROV_PRIVATE_DATA *pMyData;
  155. GUID gMyId = TESTPROV_ACTION_TEST;
  156. if (!(pPrivData = WTHelperGetProvPrivateDataFromChain(pProvData, &gMyId)))
  157. {
  158. pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_INITPROV] = ERROR_INVALID_PARAMETER;
  159. return(S_FALSE);
  160. }
  161. pMyData = (TESTPROV_PRIVATE_DATA *)pPrivData->pvProvData;
  162. //
  163. // we are verifying a low-level type choice (eg: cert or signer)
  164. //
  165. switch (pProvData->pWintrustData->dwUnionChoice)
  166. {
  167. case WTD_CHOICE_CERT:
  168. case WTD_CHOICE_SIGNER:
  169. break;
  170. default:
  171. return(pMyData->sAuthenticodePfns.pfnObjectTrust(pProvData));
  172. }
  173. //
  174. // no object to be verified here!
  175. //
  176. return(ERROR_SUCCESS);
  177. }
  178. //////////////////////////////////////////////////////////////////////////////
  179. //
  180. // Signature Provider function: TestprovInitialize
  181. //----------------------------------------------------------------------------
  182. // We are going to let Authenticode take care of most of this stuff!
  183. //
  184. HRESULT WINAPI TestprovSigProv(CRYPT_PROVIDER_DATA *pProvData)
  185. {
  186. if (!(pProvData->padwTrustStepErrors) ||
  187. (pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_WVTINIT] != ERROR_SUCCESS) ||
  188. (pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_INITPROV] != ERROR_SUCCESS) ||
  189. (pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] != ERROR_SUCCESS))
  190. {
  191. return(S_FALSE);
  192. }
  193. CRYPT_PROVIDER_PRIVDATA *pPrivData;
  194. TESTPROV_PRIVATE_DATA *pMyData;
  195. GUID gMyId = TESTPROV_ACTION_TEST;
  196. if (!(pPrivData = WTHelperGetProvPrivateDataFromChain(pProvData, &gMyId)))
  197. {
  198. pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_INITPROV] = ERROR_INVALID_PARAMETER;
  199. return(S_FALSE);
  200. }
  201. pMyData = (TESTPROV_PRIVATE_DATA *)pPrivData->pvProvData;
  202. //
  203. // we are verifying a low-level type choice (eg: cert or signer)
  204. //
  205. switch (pProvData->pWintrustData->dwUnionChoice)
  206. {
  207. case WTD_CHOICE_CERT:
  208. case WTD_CHOICE_SIGNER:
  209. break;
  210. default:
  211. return(pMyData->sAuthenticodePfns.pfnSignatureTrust(pProvData));
  212. }
  213. if (pMyData->sAuthenticodePfns.pfnSignatureTrust)
  214. {
  215. return(pMyData->sAuthenticodePfns.pfnSignatureTrust(pProvData));
  216. }
  217. return(S_FALSE);
  218. }
  219. //////////////////////////////////////////////////////////////////////////////
  220. //
  221. // Certificate Check Provider function: TestprovCertCheckProv
  222. //----------------------------------------------------------------------------
  223. // just check basic stuff about a certificate. return FALSE to stop
  224. // building the chain, TRUE to continue.
  225. //
  226. BOOL WINAPI TestprovCheckCertProv(CRYPT_PROVIDER_DATA *pProvData, DWORD idxSigner,
  227. BOOL fCounterSignerChain, DWORD idxCounterSigner)
  228. {
  229. CRYPT_PROVIDER_SGNR *pSgnr;
  230. CRYPT_PROVIDER_CERT *pCert;
  231. PCCERT_CONTEXT pCertContext;
  232. pSgnr = WTHelperGetProvSignerFromChain(pProvData, idxSigner, fCounterSignerChain, idxCounterSigner);
  233. pCert = WTHelperGetProvCertFromChain(pSgnr, pSgnr->csCertChain - 1);
  234. pCert->fTrustedRoot = FALSE;
  235. //
  236. // only self signed certificates in the root store are "trusted" roots
  237. //
  238. if (pCert->fSelfSigned)
  239. {
  240. pCertContext = pCert->pCert;
  241. if (pCertContext)
  242. {
  243. if (pProvData->chStores > 0)
  244. {
  245. if (pCertContext->hCertStore == pProvData->pahStores[0])
  246. {
  247. //
  248. // it's in the root store!
  249. //
  250. pCert->fTrustedRoot = TRUE;
  251. return(FALSE);
  252. }
  253. }
  254. if (!(pCert->fTrustedRoot))
  255. {
  256. if (pCert->fTestCert)
  257. {
  258. //
  259. // check the policy flags (setreg.exe) to see if we trust
  260. // the test root.
  261. //
  262. if (pProvData->dwRegPolicySettings & WTPF_TRUSTTEST)
  263. {
  264. pCert->fTrustedRoot = TRUE;
  265. return(FALSE);
  266. }
  267. }
  268. }
  269. }
  270. //
  271. // the cert is self-signed... we need to stop regardless
  272. //
  273. return(FALSE);
  274. }
  275. return(TRUE);
  276. }
  277. //////////////////////////////////////////////////////////////////////////////
  278. //
  279. // Final Policy Provider function: TestprovFinalProv
  280. //----------------------------------------------------------------------------
  281. // Check the outcome of the previous functions and display UI based on this.
  282. //
  283. HRESULT WINAPI TestprovFinalProv(CRYPT_PROVIDER_DATA *pProvData)
  284. {
  285. CRYPT_PROVIDER_SGNR *pSigner;
  286. DWORD dwError;
  287. if ((dwError = GetErrorBasedOnStepErrors(pProvData)) != ERROR_SUCCESS)
  288. {
  289. return(CallUI(pProvData, dwError));
  290. }
  291. pSigner = WTHelperGetProvSignerFromChain(pProvData, 0, FALSE, 0);
  292. if ((dwError = CheckCertificateChain(pProvData, pSigner)) != ERROR_SUCCESS)
  293. {
  294. return(CallUI(pProvData, dwError));
  295. }
  296. return(CallUI(pProvData, dwError));
  297. }
  298. //////////////////////////////////////////////////////////////////////////////
  299. //
  300. // Cleanup Provider function: TestprovCleanup
  301. //----------------------------------------------------------------------------
  302. // call all other policy provider cleanup functions, then, free "my" stuff.
  303. //
  304. HRESULT WINAPI TestprovCleanup(CRYPT_PROVIDER_DATA *pProvData)
  305. {
  306. GUID gMyId = TESTPROV_ACTION_TEST;
  307. CRYPT_PROVIDER_PRIVDATA *pPrivData;
  308. TESTPROV_PRIVATE_DATA *pMyData;
  309. //
  310. // we have used the Authenticode Provider. we need to call its
  311. // cleanup routine just in case.... so, get our private data
  312. // which will have the Authenticode functions in our structure..
  313. //
  314. if (!(pPrivData = WTHelperGetProvPrivateDataFromChain(pProvData, &gMyId)))
  315. {
  316. return(S_FALSE);
  317. }
  318. if (!(pPrivData->pvProvData))
  319. {
  320. return(S_FALSE);
  321. }
  322. pMyData = (TESTPROV_PRIVATE_DATA *)pPrivData->pvProvData;
  323. if (pMyData->sAuthenticodePfns.pfnCleanupPolicy)
  324. {
  325. pMyData->sAuthenticodePfns.pfnCleanupPolicy(pProvData);
  326. }
  327. //
  328. // now, we need to delete our private data
  329. //
  330. pProvData->psPfns->pfnFree(pPrivData->pvProvData);
  331. pPrivData->cbProvData = 0;
  332. pPrivData->pvProvData = NULL;
  333. return(ERROR_SUCCESS);
  334. }
  335. //////////////////////////////////////////////////////////////////////////////
  336. //
  337. // Test Provider function: TestprovTester
  338. //----------------------------------------------------------------------------
  339. // In here, we are going to check an environment variable and if set we
  340. // will call Authenticode's "dump" function.
  341. //
  342. HRESULT WINAPI TestprovTester(CRYPT_PROVIDER_DATA *pProvData)
  343. {
  344. BYTE abEnv[MAX_PATH + 1];
  345. CRYPT_PROVIDER_PRIVDATA *pPrivData;
  346. TESTPROV_PRIVATE_DATA *pMyData;
  347. GUID gMyId = TESTPROV_ACTION_TEST;
  348. abEnv[0] = NULL;
  349. if (GetEnvironmentVariable("TestProvUseDump", (char *)&abEnv[0], MAX_PATH) < 1)
  350. {
  351. return(ERROR_SUCCESS);
  352. }
  353. if ((abEnv[0] != '1') && (toupper(abEnv[0]) != 'T'))
  354. {
  355. return(ERROR_SUCCESS);
  356. }
  357. if (!(pPrivData = WTHelperGetProvPrivateDataFromChain(pProvData, &gMyId)))
  358. {
  359. pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_INITPROV] = ERROR_INVALID_PARAMETER;
  360. return(S_FALSE);
  361. }
  362. pMyData = (TESTPROV_PRIVATE_DATA *)pPrivData->pvProvData;
  363. if (pMyData->sAuthenticodePfns.pfnTestFinalPolicy)
  364. {
  365. return(pMyData->sAuthenticodePfns.pfnTestFinalPolicy(pProvData));
  366. }
  367. return(S_FALSE);
  368. }
  369. ///////////////////////////////////////////////////////////////////////////////////
  370. //
  371. // Local Functions
  372. //
  373. ///////////////////////////////////////////////////////////////////////////////////
  374. DWORD GetErrorBasedOnStepErrors(CRYPT_PROVIDER_DATA *pProvData)
  375. {
  376. //
  377. // initial allocation of the step errors?
  378. //
  379. if (!(pProvData->padwTrustStepErrors))
  380. {
  381. return(ERROR_NOT_ENOUGH_MEMORY);
  382. }
  383. //
  384. // did we fail in one of the last steps?
  385. //
  386. if (pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_INITPROV] != 0)
  387. {
  388. return(pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_INITPROV]);
  389. }
  390. if (pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV] != 0)
  391. {
  392. return(pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_OBJPROV]);
  393. }
  394. if (pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_SIGPROV] != 0)
  395. {
  396. return(pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_SIGPROV]);
  397. }
  398. if (pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_CERTPROV] != 0)
  399. {
  400. return(pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_CERTPROV]);
  401. }
  402. if (pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_CERTCHKPROV] != 0)
  403. {
  404. return(pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_CERTCHKPROV]);
  405. }
  406. if (pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_POLICYPROV] != 0)
  407. {
  408. return(pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_POLICYPROV]);
  409. }
  410. return(ERROR_SUCCESS);
  411. }
  412. HRESULT CheckCertificateChain(CRYPT_PROVIDER_DATA *pProvData, CRYPT_PROVIDER_SGNR *pProvSgnr)
  413. {
  414. CRYPT_PROVIDER_CERT *pCert;
  415. for (int i = 0; i < (int)pProvSgnr->csCertChain; i++)
  416. {
  417. pCert = WTHelperGetProvCertFromChain(pProvSgnr, i);
  418. if (!(pProvData->dwRegPolicySettings & WTPF_IGNOREEXPIRATION))
  419. {
  420. //
  421. // this check was done in the Certificate Provider, however, it may not have passed
  422. // because all its looking for is a confidence level and didn't check the end..
  423. //
  424. if (CertVerifyTimeValidity(&pProvSgnr->sftVerifyAsOf, pCert->pCert->pCertInfo) != 0)
  425. {
  426. pCert->dwError = CERT_E_EXPIRED;
  427. return(pCert->dwError);
  428. }
  429. }
  430. //
  431. // check any unknown critical extensions
  432. //
  433. if (!(CheckCertAnyUnknownCriticalExtensions(pProvData, pCert->pCert->pCertInfo)))
  434. {
  435. pCert->dwError = CERT_E_MALFORMED;
  436. return(pCert->dwError);
  437. }
  438. if ((i + 1) < (int)pProvSgnr->csCertChain)
  439. {
  440. //
  441. // check time nesting...
  442. //
  443. if (!(pCert->dwConfidence & CERT_CONFIDENCE_TIMENEST))
  444. {
  445. pCert->dwError = CERT_E_VALIDITYPERIODNESTING;
  446. return(pCert->dwError);
  447. }
  448. }
  449. }
  450. if (!(pProvData->dwRegPolicySettings & WTPF_IGNOREREVOKATION))
  451. {
  452. // root cert is test?
  453. pCert = WTHelperGetProvCertFromChain(pProvSgnr, pProvSgnr->csCertChain - 1);
  454. if (pCert)
  455. {
  456. if (!(pCert->fTestCert))
  457. {
  458. //
  459. // if the caller already told WVT to check, we don't have to!
  460. //
  461. if (pProvData->pWintrustData->fdwRevocationChecks != WTD_REVOKE_NONE)
  462. {
  463. //
  464. // not a test root, check signer cert for revocation
  465. //
  466. pCert = WTHelperGetProvCertFromChain(pProvSgnr, 0);
  467. return(CheckRevocation(pProvData, pProvSgnr));
  468. }
  469. }
  470. }
  471. }
  472. return(ERROR_SUCCESS);
  473. }
  474. HRESULT CallUI(CRYPT_PROVIDER_DATA *pProvData, DWORD dwError)
  475. {
  476. HRESULT hr;
  477. HINSTANCE hModule;
  478. ACUI_INVOKE_INFO aii;
  479. pfnACUIProviderInvokeUI pfn;
  480. DWORD idxSigner;
  481. BOOL fTrusted;
  482. BOOL fCommercial;
  483. DWORD dwUIChoice;
  484. CRYPT_PROVIDER_SGNR *pRootSigner;
  485. CRYPT_PROVIDER_CERT *pPubCert;
  486. hr = E_NOTIMPL;
  487. pfn = NULL;
  488. fTrusted = FALSE;
  489. fCommercial = FALSE;
  490. idxSigner = 0;
  491. dwUIChoice = pProvData->pWintrustData->dwUIChoice;
  492. pRootSigner = WTHelperGetProvSignerFromChain(pProvData, 0, FALSE, 0);
  493. if ((dwUIChoice == WTD_UI_NONE) ||
  494. ((dwUIChoice == WTD_UI_NOBAD) && (dwError != ERROR_SUCCESS)) ||
  495. ((dwUIChoice == WTD_UI_NOGOOD) && (dwError == ERROR_SUCCESS)))
  496. {
  497. return(dwError);
  498. }
  499. //
  500. // Setup the UI invokation
  501. //
  502. memset(&aii, 0x00, sizeof(ACUI_INVOKE_INFO));
  503. aii.cbSize = sizeof(ACUI_INVOKE_INFO);
  504. aii.hDisplay = pProvData->hWndParent;
  505. aii.pProvData = pProvData;
  506. aii.hrInvokeReason = dwError;
  507. aii.pwcsAltDisplayName = WTHelperGetFileName(pProvData->pWintrustData);
  508. //
  509. // Load the default authenticode UI.
  510. //
  511. if (hModule = LoadLibrary("dacui.dll"))
  512. {
  513. pfn = (pfnACUIProviderInvokeUI)GetProcAddress(hModule, "ACUIProviderInvokeUI");
  514. }
  515. //
  516. // Invoke the UI
  517. //
  518. if (pfn)
  519. {
  520. hr = (*pfn)(&aii);
  521. }
  522. else if ((pProvData->pWintrustData->dwUIChoice != WTD_UI_NONE) &&
  523. (pProvData->pWintrustData->dwUIChoice != WTD_UI_NOBAD))
  524. {
  525. //TBDTBD!!!
  526. //
  527. // display error dialog "unable to load UI provider"
  528. //
  529. if (hr == E_NOTIMPL)
  530. {
  531. hr = TRUST_E_PROVIDER_UNKNOWN;
  532. }
  533. pProvData->dwError = hr;
  534. pProvData->padwTrustStepErrors[TRUSTERROR_STEP_FINAL_UIPROV] = hr;
  535. }
  536. //
  537. // free the ui library
  538. //
  539. if (hModule)
  540. {
  541. FreeLibrary(hModule);
  542. }
  543. //
  544. // Return the appropriate code
  545. //
  546. return(hr);
  547. }
  548. static const char *rgpszKnownExtObjId[] =
  549. {
  550. szOID_AUTHORITY_KEY_IDENTIFIER,
  551. szOID_KEY_ATTRIBUTES,
  552. szOID_KEY_USAGE_RESTRICTION,
  553. szOID_SUBJECT_ALT_NAME,
  554. szOID_ISSUER_ALT_NAME,
  555. szOID_BASIC_CONSTRAINTS,
  556. SPC_COMMON_NAME_OBJID,
  557. SPC_SP_AGENCY_INFO_OBJID,
  558. SPC_MINIMAL_CRITERIA_OBJID,
  559. SPC_FINANCIAL_CRITERIA_OBJID,
  560. szOID_CERT_POLICIES,
  561. szOID_POLICY_MAPPINGS,
  562. szOID_SUBJECT_DIR_ATTRS,
  563. NULL
  564. };
  565. BOOL CheckCertAnyUnknownCriticalExtensions(CRYPT_PROVIDER_DATA *pProvData, PCERT_INFO pCertInfo)
  566. {
  567. PCERT_EXTENSION pExt;
  568. DWORD cExt;
  569. const char **ppszObjId;
  570. const char *pszObjId;
  571. cExt = pCertInfo->cExtension;
  572. pExt = pCertInfo->rgExtension;
  573. for ( ; cExt > 0; cExt--, pExt++)
  574. {
  575. if (pExt->fCritical)
  576. {
  577. ppszObjId = (const char **)rgpszKnownExtObjId;
  578. while (pszObjId = *ppszObjId++)
  579. {
  580. if (strcmp(pszObjId, pExt->pszObjId) == 0)
  581. {
  582. break;
  583. }
  584. }
  585. if (!(pszObjId))
  586. {
  587. return(FALSE);
  588. }
  589. }
  590. }
  591. return(TRUE);
  592. }
  593. HRESULT CheckRevocation(CRYPT_PROVIDER_DATA *pProvData, CRYPT_PROVIDER_SGNR *pSgnr)
  594. {
  595. CERT_REVOCATION_PARA sRevPara;
  596. CERT_REVOCATION_STATUS sRevStatus;
  597. PCERT_CONTEXT pasCertContext[1];
  598. CRYPT_PROVIDER_CERT *pCert;
  599. memset(&sRevPara, 0x00, sizeof(CERT_REVOCATION_PARA));
  600. sRevPara.cbSize = sizeof(CERT_REVOCATION_PARA);
  601. // issuer cert = 1
  602. pCert = WTHelperGetProvCertFromChain(pSgnr, 1);
  603. sRevPara.pIssuerCert = pCert->pCert;
  604. memset(&sRevStatus, 0x00, sizeof(CERT_REVOCATION_STATUS));
  605. sRevStatus.cbSize = sizeof(CERT_REVOCATION_STATUS);
  606. // publisher cert = 0
  607. pCert = WTHelperGetProvCertFromChain(pSgnr, 0);
  608. pasCertContext[0] = (PCERT_CONTEXT)pCert->pCert;
  609. if (!(CertVerifyRevocation(pProvData->dwEncoding,
  610. CERT_CONTEXT_REVOCATION_TYPE,
  611. 1,
  612. (void **)pasCertContext,
  613. 0, // CERT_VERIFY_REV_CHAIN_FLAG,
  614. &sRevPara,
  615. &sRevStatus)))
  616. {
  617. pCert->dwRevokedReason = sRevStatus.dwReason;
  618. switch(sRevStatus.dwError)
  619. {
  620. case CRYPT_E_REVOKED:
  621. return(CERT_E_REVOKED);
  622. case CRYPT_E_NOT_IN_REVOCATION_DATABASE:
  623. return(ERROR_SUCCESS);
  624. case CRYPT_E_REVOCATION_OFFLINE:
  625. if ((pProvData->dwRegPolicySettings & WTPF_OFFLINEOK_IND) ||
  626. (pProvData->dwRegPolicySettings & WTPF_OFFLINEOKNBU_IND))
  627. {
  628. return(ERROR_SUCCESS);
  629. }
  630. return(CERT_E_REVOCATION_FAILURE);
  631. default:
  632. return(CERT_E_REVOCATION_FAILURE);
  633. }
  634. }
  635. return(ERROR_SUCCESS);
  636. }